Skip to content

Commit

Permalink
feat(Polygons): allow room to be specified when adding a mesh to the …
Browse files Browse the repository at this point in the history
…map with addThreeJsMesh()
  • Loading branch information
meszaros-lajos-gyorgy committed Dec 20, 2023
1 parent eb69c0d commit e72ee09
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { ArxVertexWithColor } from '@src/types.js'

export type TransparencyType = 'multiplicative' | 'additive' | 'blended' | 'subtractive'

const DEFAULT_ROOM_ID = 1

type PolygonConfig = {
/** setting this to true will prevent calculation of norm, norm2 and normals properties */
areNormalsCalculated: boolean
Expand Down Expand Up @@ -64,7 +66,7 @@ export class Polygon {
this.normals = props.normals
this.transval = props.transval ?? 0
this.area = props.area ?? 0
this.room = props.room ?? 1
this.room = props.room ?? DEFAULT_ROOM_ID
this.paddy = props.paddy
this.config = { ...this.config, ...(props.config ?? {}) }
}
Expand Down
7 changes: 6 additions & 1 deletion src/Polygons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export type MeshImportProps = {
tryToQuadify?: typeof QUADIFY | typeof DONT_QUADIFY
shading?: typeof SHADING_FLAT | typeof SHADING_SMOOTH
flags?: ArxPolygonFlags
/**
* room id - used when a map has portals, default value is undefined (the Polygon constructor will handle it)
*/
room?: number
}

type TextureContainer = ArxTextureContainer & { remaining: number; maxRemaining: number }
Expand Down Expand Up @@ -140,7 +144,7 @@ export class Polygons extends Array<Polygon> {
applyTransformations(threeJsObj)
}

const { tryToQuadify = QUADIFY, shading = SHADING_FLAT, flags = ArxPolygonFlags.None } = meshImportProps
const { tryToQuadify = QUADIFY, shading = SHADING_FLAT, flags = ArxPolygonFlags.None, room } = meshImportProps
const polygons = new Polygons()

if (threeJsObj instanceof Mesh) {
Expand Down Expand Up @@ -221,6 +225,7 @@ export class Polygons extends Array<Polygon> {
texture: currentTexture,
flags: currentTexture instanceof Material ? currentTexture.flags | flags : flags,
isQuad: true,
room,
})
if (currentTexture instanceof Material && currentTexture.opacity !== 100) {
polygon.setOpacity(currentTexture.opacity, currentTexture.opacityMode)
Expand Down

0 comments on commit e72ee09

Please sign in to comment.