@onerjs/core 8.50.7 → 8.50.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -43,6 +43,7 @@ export declare function CreatePolygon(name: string, options: {
43
43
  frontUVs?: Vector4;
44
44
  backUVs?: Vector4;
45
45
  wrap?: boolean;
46
+ instance?: Mesh;
46
47
  }, scene?: Nullable<Scene>, earcutInjection?: any): Mesh;
47
48
  /**
48
49
  * Creates an extruded polygon mesh, with depth in the Y direction.
@@ -139,29 +139,36 @@ export function CreatePolygon(name, options, scene = null, earcutInjection = ear
139
139
  const holes = options.holes || [];
140
140
  const depth = options.depth || 0;
141
141
  const smoothingThreshold = options.smoothingThreshold || 2;
142
- const contours = [];
143
- let hole;
144
- for (let i = 0; i < shape.length; i++) {
145
- contours[i] = new Vector2(shape[i].x, shape[i].z);
142
+ if (options.instance) {
143
+ const vertexData = CreatePolygonVertexData(options.instance, options.sideOrientation, options.faceUV, options.faceColors, options.frontUVs, options.backUVs, options.wrap);
144
+ vertexData.applyToMesh(options.instance, options.updatable);
145
+ return options.instance;
146
146
  }
147
- const epsilon = 0.00000001;
148
- if (contours[0].equalsWithEpsilon(contours[contours.length - 1], epsilon)) {
149
- contours.pop();
150
- }
151
- const polygonTriangulation = new PolygonMeshBuilder(name, contours, scene || EngineStore.LastCreatedScene, earcutInjection);
152
- for (let hNb = 0; hNb < holes.length; hNb++) {
153
- hole = [];
154
- for (let hPoint = 0; hPoint < holes[hNb].length; hPoint++) {
155
- hole.push(new Vector2(holes[hNb][hPoint].x, holes[hNb][hPoint].z));
147
+ else {
148
+ const contours = [];
149
+ let hole;
150
+ for (let i = 0; i < shape.length; i++) {
151
+ contours[i] = new Vector2(shape[i].x, shape[i].z);
152
+ }
153
+ const epsilon = 0.00000001;
154
+ if (contours[0].equalsWithEpsilon(contours[contours.length - 1], epsilon)) {
155
+ contours.pop();
156
+ }
157
+ const polygonTriangulation = new PolygonMeshBuilder(name, contours, scene || EngineStore.LastCreatedScene, earcutInjection);
158
+ for (let hNb = 0; hNb < holes.length; hNb++) {
159
+ hole = [];
160
+ for (let hPoint = 0; hPoint < holes[hNb].length; hPoint++) {
161
+ hole.push(new Vector2(holes[hNb][hPoint].x, holes[hNb][hPoint].z));
162
+ }
163
+ polygonTriangulation.addHole(hole);
156
164
  }
157
- polygonTriangulation.addHole(hole);
165
+ //updatability is set during applyToMesh; setting to true in triangulation build produces errors
166
+ const polygon = polygonTriangulation.build(false, depth, smoothingThreshold);
167
+ polygon._originalBuilderSideOrientation = options.sideOrientation;
168
+ const vertexData = CreatePolygonVertexData(polygon, options.sideOrientation, options.faceUV, options.faceColors, options.frontUVs, options.backUVs, options.wrap);
169
+ vertexData.applyToMesh(polygon, options.updatable);
170
+ return polygon;
158
171
  }
159
- //updatability is set during applyToMesh; setting to true in triangulation build produces errors
160
- const polygon = polygonTriangulation.build(false, depth, smoothingThreshold);
161
- polygon._originalBuilderSideOrientation = options.sideOrientation;
162
- const vertexData = CreatePolygonVertexData(polygon, options.sideOrientation, options.faceUV, options.faceColors, options.frontUVs, options.backUVs, options.wrap);
163
- vertexData.applyToMesh(polygon, options.updatable);
164
- return polygon;
165
172
  }
166
173
  /**
167
174
  * Creates an extruded polygon mesh, with depth in the Y direction.
@@ -1 +1 @@
1
- {"version":3,"file":"polygonBuilder.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Builders/polygonBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAA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,EAAE,SAAS;QACpB,eAAe,EAAE,eAAe;KACnC,CAAC;IACF,OAAO,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC;AAChE,CAAC,CAAC;AAEF,IAAI,CAAC,cAAc,GAAG,CAClB,IAAY,EACZ,KAAgB,EAChB,KAAa,EACb,KAAY,EACZ,KAAmB,EACnB,SAAmB,EACnB,eAAwB,EACxB,eAAe,GAAG,MAAM,EACpB,EAAE;IACN,MAAM,OAAO,GAAG;QACZ,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,KAAK;QACZ,SAAS,EAAE,SAAS;QACpB,eAAe,EAAE,eAAe;KACnC,CAAC;IACF,OAAO,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC;AACjE,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { type Scene } from \"../../scene\";\r\nimport { type Vector3, Vector2, Vector4 } from \"../../Maths/math.vector\";\r\nimport { Color4 } from \"../../Maths/math.color\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport { PolygonMeshBuilder } from \"../polygonMesh\";\r\nimport { type FloatArray, type IndicesArray, type Nullable } from \"../../types\";\r\nimport { VertexBuffer } from \"../../Buffers/buffer\";\r\nimport { EngineStore } from \"../../Engines/engineStore\";\r\nimport { useOpenGLOrientationForUV } from \"../../Compat/compatibilityOptions\";\r\n\r\ndeclare let earcut: any;\r\n\r\n/**\r\n * Creates the VertexData for an irregular Polygon in the XoZ plane using a mesh built by polygonTriangulation.build()\r\n * All parameters are provided by CreatePolygon as needed\r\n * @param polygon a mesh built from polygonTriangulation.build()\r\n * @param sideOrientation takes the values Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * @param fUV an array of Vector4 elements used to set different images to the top, rings and bottom respectively\r\n * @param fColors an array of Color3 elements used to set different colors to the top, rings and bottom respectively\r\n * @param frontUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * @param backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param wrp a boolean, default false, when true and fUVs used texture is wrapped around all sides, when false texture is applied side\r\n * @returns the VertexData of the Polygon\r\n */\r\nexport function CreatePolygonVertexData(polygon: Mesh, sideOrientation: number, fUV?: Vector4[], fColors?: Color4[], frontUVs?: Vector4, backUVs?: Vector4, wrp?: boolean) {\r\n const faceUV: Vector4[] = fUV || new Array<Vector4>(3);\r\n const faceColors = fColors;\r\n const colors = [];\r\n const wrap: boolean = wrp || false;\r\n\r\n // default face colors and UV if undefined\r\n for (let f = 0; f < 3; f++) {\r\n if (faceUV[f] === undefined) {\r\n faceUV[f] = new Vector4(0, 0, 1, 1);\r\n }\r\n if (faceColors && faceColors[f] === undefined) {\r\n faceColors[f] = new Color4(1, 1, 1, 1);\r\n }\r\n }\r\n\r\n const positions = <FloatArray>polygon.getVerticesData(VertexBuffer.PositionKind);\r\n const normals = <FloatArray>polygon.getVerticesData(VertexBuffer.NormalKind);\r\n const uvs = <FloatArray>polygon.getVerticesData(VertexBuffer.UVKind);\r\n const indices = <IndicesArray>polygon.getIndices();\r\n const startIndex = positions.length / 9;\r\n let disp: number;\r\n let distX: number;\r\n let distZ: number;\r\n let dist: number;\r\n let totalLen = 0;\r\n const cumulate = [0];\r\n if (wrap) {\r\n for (let idx = startIndex; idx < positions.length / 3; idx += 4) {\r\n distX = positions[3 * (idx + 2)] - positions[3 * idx];\r\n distZ = positions[3 * (idx + 2) + 2] - positions[3 * idx + 2];\r\n dist = Math.sqrt(distX * distX + distZ * distZ);\r\n totalLen += dist;\r\n cumulate.push(totalLen);\r\n }\r\n }\r\n // set face colours and textures\r\n let idx: number;\r\n let face: number = 0;\r\n for (let index = 0; index < normals.length; index += 3) {\r\n //Edge Face no. 1\r\n if (Math.abs(normals[index + 1]) < 0.001) {\r\n face = 1;\r\n }\r\n //Top Face no. 0\r\n if (Math.abs(normals[index + 1] - 1) < 0.001) {\r\n face = 0;\r\n }\r\n //Bottom Face no. 2\r\n if (Math.abs(normals[index + 1] + 1) < 0.001) {\r\n face = 2;\r\n }\r\n idx = index / 3;\r\n if (face === 1) {\r\n disp = idx - startIndex;\r\n if (disp % 4 < 1.5) {\r\n if (wrap) {\r\n uvs[2 * idx] = faceUV[face].x + ((faceUV[face].z - faceUV[face].x) * cumulate[Math.floor(disp / 4)]) / totalLen;\r\n } else {\r\n uvs[2 * idx] = faceUV[face].x;\r\n }\r\n } else {\r\n if (wrap) {\r\n uvs[2 * idx] = faceUV[face].x + ((faceUV[face].z - faceUV[face].x) * cumulate[Math.floor(disp / 4) + 1]) / totalLen;\r\n } else {\r\n uvs[2 * idx] = faceUV[face].z;\r\n }\r\n }\r\n if (disp % 2 === 0) {\r\n uvs[2 * idx + 1] = useOpenGLOrientationForUV ? 1.0 - faceUV[face].w : faceUV[face].w;\r\n } else {\r\n uvs[2 * idx + 1] = useOpenGLOrientationForUV ? 1.0 - faceUV[face].y : faceUV[face].y;\r\n }\r\n } else {\r\n uvs[2 * idx] = (1 - uvs[2 * idx]) * faceUV[face].x + uvs[2 * idx] * faceUV[face].z;\r\n uvs[2 * idx + 1] = (1 - uvs[2 * idx + 1]) * faceUV[face].y + uvs[2 * idx + 1] * faceUV[face].w;\r\n\r\n if (useOpenGLOrientationForUV) {\r\n uvs[2 * idx + 1] = 1.0 - uvs[2 * idx + 1];\r\n }\r\n }\r\n if (faceColors) {\r\n colors.push(faceColors[face].r, faceColors[face].g, faceColors[face].b, faceColors[face].a);\r\n }\r\n }\r\n\r\n // sides\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, frontUVs, backUVs);\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n if (faceColors) {\r\n const totalColors = sideOrientation === VertexData.DOUBLESIDE ? colors.concat(colors) : colors;\r\n vertexData.colors = totalColors;\r\n }\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates a polygon mesh\r\n * The polygon's shape will depend on the input parameters and is constructed parallel to a ground mesh\r\n * * The parameter `shape` is a required array of successive Vector3 representing the corners of the polygon in th XoZ plane, that is y = 0 for all vectors\r\n * * You can set the mesh side orientation with the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4)\r\n * * Remember you can only change the shape positions, not their number when updating a polygon\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param scene defines the hosting scene\r\n * @param earcutInjection can be used to inject your own earcut reference\r\n * @returns the polygon mesh\r\n */\r\nexport function CreatePolygon(\r\n name: string,\r\n options: {\r\n shape: Vector3[];\r\n holes?: Vector3[][];\r\n depth?: number;\r\n smoothingThreshold?: number;\r\n faceUV?: Vector4[];\r\n faceColors?: Color4[];\r\n updatable?: boolean;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n wrap?: boolean;\r\n },\r\n scene: Nullable<Scene> = null,\r\n earcutInjection = earcut\r\n): Mesh {\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n const shape = options.shape;\r\n const holes = options.holes || [];\r\n const depth = options.depth || 0;\r\n const smoothingThreshold = options.smoothingThreshold || 2;\r\n const contours: Array<Vector2> = [];\r\n let hole: Array<Vector2>;\r\n\r\n for (let i = 0; i < shape.length; i++) {\r\n contours[i] = new Vector2(shape[i].x, shape[i].z);\r\n }\r\n const epsilon = 0.00000001;\r\n if (contours[0].equalsWithEpsilon(contours[contours.length - 1], epsilon)) {\r\n contours.pop();\r\n }\r\n\r\n const polygonTriangulation = new PolygonMeshBuilder(name, contours, scene || EngineStore.LastCreatedScene!, earcutInjection);\r\n for (let hNb = 0; hNb < holes.length; hNb++) {\r\n hole = [];\r\n for (let hPoint = 0; hPoint < holes[hNb].length; hPoint++) {\r\n hole.push(new Vector2(holes[hNb][hPoint].x, holes[hNb][hPoint].z));\r\n }\r\n polygonTriangulation.addHole(hole);\r\n }\r\n //updatability is set during applyToMesh; setting to true in triangulation build produces errors\r\n const polygon = polygonTriangulation.build(false, depth, smoothingThreshold);\r\n polygon._originalBuilderSideOrientation = options.sideOrientation;\r\n const vertexData = CreatePolygonVertexData(polygon, options.sideOrientation, options.faceUV, options.faceColors, options.frontUVs, options.backUVs, options.wrap);\r\n vertexData.applyToMesh(polygon, options.updatable);\r\n\r\n return polygon;\r\n}\r\n\r\n/**\r\n * Creates an extruded polygon mesh, with depth in the Y direction.\r\n * * You can set different colors and different images to the top, bottom and extruded side by using the parameters `faceColors` (an array of 3 Color3 elements) and `faceUV` (an array of 3 Vector4 elements)\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/texturePerBoxFace\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param scene defines the hosting scene\r\n * @param earcutInjection can be used to inject your own earcut reference\r\n * @returns the polygon mesh\r\n */\r\nexport function ExtrudePolygon(\r\n name: string,\r\n options: {\r\n shape: Vector3[];\r\n holes?: Vector3[][];\r\n depth?: number;\r\n faceUV?: Vector4[];\r\n faceColors?: Color4[];\r\n updatable?: boolean;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n wrap?: boolean;\r\n },\r\n scene: Nullable<Scene> = null,\r\n earcutInjection = earcut\r\n): Mesh {\r\n return CreatePolygon(name, options, scene, earcutInjection);\r\n}\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use the functions directly from the module\r\n */\r\nexport const PolygonBuilder = {\r\n ExtrudePolygon,\r\n CreatePolygon,\r\n};\r\n\r\nVertexData.CreatePolygon = CreatePolygonVertexData;\r\nMesh.CreatePolygon = (name: string, shape: Vector3[], scene: Scene, holes?: Vector3[][], updatable?: boolean, sideOrientation?: number, earcutInjection = earcut): Mesh => {\r\n const options = {\r\n shape: shape,\r\n holes: holes,\r\n updatable: updatable,\r\n sideOrientation: sideOrientation,\r\n };\r\n return CreatePolygon(name, options, scene, earcutInjection);\r\n};\r\n\r\nMesh.ExtrudePolygon = (\r\n name: string,\r\n shape: Vector3[],\r\n depth: number,\r\n scene: Scene,\r\n holes?: Vector3[][],\r\n updatable?: boolean,\r\n sideOrientation?: number,\r\n earcutInjection = earcut\r\n): Mesh => {\r\n const options = {\r\n shape: shape,\r\n holes: holes,\r\n depth: depth,\r\n updatable: updatable,\r\n sideOrientation: sideOrientation,\r\n };\r\n return ExtrudePolygon(name, options, scene, earcutInjection);\r\n};\r\n"]}
1
+ {"version":3,"file":"polygonBuilder.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Builders/polygonBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAI9E;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAAa,EAAE,eAAuB,EAAE,GAAe,EAA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,CAAC;AACnD,IAAI,CAAC,aAAa,GAAG,CAAC,IAAY,EAAE,KAAgB,EAAE,KAAY,EAAE,KAAmB,EAAE,SAAmB,EAAE,eAAwB,EAAE,eAAe,GAAG,MAAM,EAAQ,EAAE;IACtK,MAAM,OAAO,GAAG;QACZ,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,KAAK;QACZ,SAAS,EAAE,SAAS;QACpB,eAAe,EAAE,eAAe;KACnC,CAAC;IACF,OAAO,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC;AAChE,CAAC,CAAC;AAEF,IAAI,CAAC,cAAc,GAAG,CAClB,IAAY,EACZ,KAAgB,EAChB,KAAa,EACb,KAAY,EACZ,KAAmB,EACnB,SAAmB,EACnB,eAAwB,EACxB,eAAe,GAAG,MAAM,EACpB,EAAE;IACN,MAAM,OAAO,GAAG;QACZ,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,KAAK;QACZ,SAAS,EAAE,SAAS;QACpB,eAAe,EAAE,eAAe;KACnC,CAAC;IACF,OAAO,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC;AACjE,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { type Scene } from \"../../scene\";\r\nimport { type Vector3, Vector2, Vector4 } from \"../../Maths/math.vector\";\r\nimport { Color4 } from \"../../Maths/math.color\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport { PolygonMeshBuilder } from \"../polygonMesh\";\r\nimport { type FloatArray, type IndicesArray, type Nullable } from \"../../types\";\r\nimport { VertexBuffer } from \"../../Buffers/buffer\";\r\nimport { EngineStore } from \"../../Engines/engineStore\";\r\nimport { useOpenGLOrientationForUV } from \"../../Compat/compatibilityOptions\";\r\n\r\ndeclare let earcut: any;\r\n\r\n/**\r\n * Creates the VertexData for an irregular Polygon in the XoZ plane using a mesh built by polygonTriangulation.build()\r\n * All parameters are provided by CreatePolygon as needed\r\n * @param polygon a mesh built from polygonTriangulation.build()\r\n * @param sideOrientation takes the values Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * @param fUV an array of Vector4 elements used to set different images to the top, rings and bottom respectively\r\n * @param fColors an array of Color3 elements used to set different colors to the top, rings and bottom respectively\r\n * @param frontUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * @param backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param wrp a boolean, default false, when true and fUVs used texture is wrapped around all sides, when false texture is applied side\r\n * @returns the VertexData of the Polygon\r\n */\r\nexport function CreatePolygonVertexData(polygon: Mesh, sideOrientation: number, fUV?: Vector4[], fColors?: Color4[], frontUVs?: Vector4, backUVs?: Vector4, wrp?: boolean) {\r\n const faceUV: Vector4[] = fUV || new Array<Vector4>(3);\r\n const faceColors = fColors;\r\n const colors = [];\r\n const wrap: boolean = wrp || false;\r\n\r\n // default face colors and UV if undefined\r\n for (let f = 0; f < 3; f++) {\r\n if (faceUV[f] === undefined) {\r\n faceUV[f] = new Vector4(0, 0, 1, 1);\r\n }\r\n if (faceColors && faceColors[f] === undefined) {\r\n faceColors[f] = new Color4(1, 1, 1, 1);\r\n }\r\n }\r\n\r\n const positions = <FloatArray>polygon.getVerticesData(VertexBuffer.PositionKind);\r\n const normals = <FloatArray>polygon.getVerticesData(VertexBuffer.NormalKind);\r\n const uvs = <FloatArray>polygon.getVerticesData(VertexBuffer.UVKind);\r\n const indices = <IndicesArray>polygon.getIndices();\r\n const startIndex = positions.length / 9;\r\n let disp: number;\r\n let distX: number;\r\n let distZ: number;\r\n let dist: number;\r\n let totalLen = 0;\r\n const cumulate = [0];\r\n if (wrap) {\r\n for (let idx = startIndex; idx < positions.length / 3; idx += 4) {\r\n distX = positions[3 * (idx + 2)] - positions[3 * idx];\r\n distZ = positions[3 * (idx + 2) + 2] - positions[3 * idx + 2];\r\n dist = Math.sqrt(distX * distX + distZ * distZ);\r\n totalLen += dist;\r\n cumulate.push(totalLen);\r\n }\r\n }\r\n // set face colours and textures\r\n let idx: number;\r\n let face: number = 0;\r\n for (let index = 0; index < normals.length; index += 3) {\r\n //Edge Face no. 1\r\n if (Math.abs(normals[index + 1]) < 0.001) {\r\n face = 1;\r\n }\r\n //Top Face no. 0\r\n if (Math.abs(normals[index + 1] - 1) < 0.001) {\r\n face = 0;\r\n }\r\n //Bottom Face no. 2\r\n if (Math.abs(normals[index + 1] + 1) < 0.001) {\r\n face = 2;\r\n }\r\n idx = index / 3;\r\n if (face === 1) {\r\n disp = idx - startIndex;\r\n if (disp % 4 < 1.5) {\r\n if (wrap) {\r\n uvs[2 * idx] = faceUV[face].x + ((faceUV[face].z - faceUV[face].x) * cumulate[Math.floor(disp / 4)]) / totalLen;\r\n } else {\r\n uvs[2 * idx] = faceUV[face].x;\r\n }\r\n } else {\r\n if (wrap) {\r\n uvs[2 * idx] = faceUV[face].x + ((faceUV[face].z - faceUV[face].x) * cumulate[Math.floor(disp / 4) + 1]) / totalLen;\r\n } else {\r\n uvs[2 * idx] = faceUV[face].z;\r\n }\r\n }\r\n if (disp % 2 === 0) {\r\n uvs[2 * idx + 1] = useOpenGLOrientationForUV ? 1.0 - faceUV[face].w : faceUV[face].w;\r\n } else {\r\n uvs[2 * idx + 1] = useOpenGLOrientationForUV ? 1.0 - faceUV[face].y : faceUV[face].y;\r\n }\r\n } else {\r\n uvs[2 * idx] = (1 - uvs[2 * idx]) * faceUV[face].x + uvs[2 * idx] * faceUV[face].z;\r\n uvs[2 * idx + 1] = (1 - uvs[2 * idx + 1]) * faceUV[face].y + uvs[2 * idx + 1] * faceUV[face].w;\r\n\r\n if (useOpenGLOrientationForUV) {\r\n uvs[2 * idx + 1] = 1.0 - uvs[2 * idx + 1];\r\n }\r\n }\r\n if (faceColors) {\r\n colors.push(faceColors[face].r, faceColors[face].g, faceColors[face].b, faceColors[face].a);\r\n }\r\n }\r\n\r\n // sides\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, frontUVs, backUVs);\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n if (faceColors) {\r\n const totalColors = sideOrientation === VertexData.DOUBLESIDE ? colors.concat(colors) : colors;\r\n vertexData.colors = totalColors;\r\n }\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates a polygon mesh\r\n * The polygon's shape will depend on the input parameters and is constructed parallel to a ground mesh\r\n * * The parameter `shape` is a required array of successive Vector3 representing the corners of the polygon in th XoZ plane, that is y = 0 for all vectors\r\n * * You can set the mesh side orientation with the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4)\r\n * * Remember you can only change the shape positions, not their number when updating a polygon\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param scene defines the hosting scene\r\n * @param earcutInjection can be used to inject your own earcut reference\r\n * @returns the polygon mesh\r\n */\r\nexport function CreatePolygon(\r\n name: string,\r\n options: {\r\n shape: Vector3[];\r\n holes?: Vector3[][];\r\n depth?: number;\r\n smoothingThreshold?: number;\r\n faceUV?: Vector4[];\r\n faceColors?: Color4[];\r\n updatable?: boolean;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n wrap?: boolean;\r\n instance?: Mesh;\r\n },\r\n scene: Nullable<Scene> = null,\r\n earcutInjection = earcut\r\n): Mesh {\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n const shape = options.shape;\r\n const holes = options.holes || [];\r\n const depth = options.depth || 0;\r\n const smoothingThreshold = options.smoothingThreshold || 2;\r\n if (options.instance) {\r\n const vertexData = CreatePolygonVertexData(options.instance, options.sideOrientation, options.faceUV, options.faceColors, options.frontUVs, options.backUVs, options.wrap);\r\n vertexData.applyToMesh(options.instance, options.updatable);\r\n return options.instance;\r\n } else {\r\n const contours: Array<Vector2> = [];\r\n let hole: Array<Vector2>;\r\n\r\n for (let i = 0; i < shape.length; i++) {\r\n contours[i] = new Vector2(shape[i].x, shape[i].z);\r\n }\r\n const epsilon = 0.00000001;\r\n if (contours[0].equalsWithEpsilon(contours[contours.length - 1], epsilon)) {\r\n contours.pop();\r\n }\r\n\r\n const polygonTriangulation = new PolygonMeshBuilder(name, contours, scene || EngineStore.LastCreatedScene!, earcutInjection);\r\n for (let hNb = 0; hNb < holes.length; hNb++) {\r\n hole = [];\r\n for (let hPoint = 0; hPoint < holes[hNb].length; hPoint++) {\r\n hole.push(new Vector2(holes[hNb][hPoint].x, holes[hNb][hPoint].z));\r\n }\r\n polygonTriangulation.addHole(hole);\r\n }\r\n //updatability is set during applyToMesh; setting to true in triangulation build produces errors\r\n const polygon = polygonTriangulation.build(false, depth, smoothingThreshold);\r\n polygon._originalBuilderSideOrientation = options.sideOrientation;\r\n const vertexData = CreatePolygonVertexData(polygon, options.sideOrientation, options.faceUV, options.faceColors, options.frontUVs, options.backUVs, options.wrap);\r\n vertexData.applyToMesh(polygon, options.updatable);\r\n return polygon;\r\n }\r\n}\r\n\r\n/**\r\n * Creates an extruded polygon mesh, with depth in the Y direction.\r\n * * You can set different colors and different images to the top, bottom and extruded side by using the parameters `faceColors` (an array of 3 Color3 elements) and `faceUV` (an array of 3 Vector4 elements)\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/texturePerBoxFace\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param scene defines the hosting scene\r\n * @param earcutInjection can be used to inject your own earcut reference\r\n * @returns the polygon mesh\r\n */\r\nexport function ExtrudePolygon(\r\n name: string,\r\n options: {\r\n shape: Vector3[];\r\n holes?: Vector3[][];\r\n depth?: number;\r\n faceUV?: Vector4[];\r\n faceColors?: Color4[];\r\n updatable?: boolean;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n wrap?: boolean;\r\n },\r\n scene: Nullable<Scene> = null,\r\n earcutInjection = earcut\r\n): Mesh {\r\n return CreatePolygon(name, options, scene, earcutInjection);\r\n}\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use the functions directly from the module\r\n */\r\nexport const PolygonBuilder = {\r\n ExtrudePolygon,\r\n CreatePolygon,\r\n};\r\n\r\nVertexData.CreatePolygon = CreatePolygonVertexData;\r\nMesh.CreatePolygon = (name: string, shape: Vector3[], scene: Scene, holes?: Vector3[][], updatable?: boolean, sideOrientation?: number, earcutInjection = earcut): Mesh => {\r\n const options = {\r\n shape: shape,\r\n holes: holes,\r\n updatable: updatable,\r\n sideOrientation: sideOrientation,\r\n };\r\n return CreatePolygon(name, options, scene, earcutInjection);\r\n};\r\n\r\nMesh.ExtrudePolygon = (\r\n name: string,\r\n shape: Vector3[],\r\n depth: number,\r\n scene: Scene,\r\n holes?: Vector3[][],\r\n updatable?: boolean,\r\n sideOrientation?: number,\r\n earcutInjection = earcut\r\n): Mesh => {\r\n const options = {\r\n shape: shape,\r\n holes: holes,\r\n depth: depth,\r\n updatable: updatable,\r\n sideOrientation: sideOrientation,\r\n };\r\n return ExtrudePolygon(name, options, scene, earcutInjection);\r\n};\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onerjs/core",
3
- "version": "8.50.7",
3
+ "version": "8.50.8",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
6
  "types": "index.d.ts",