@babylonjs/core 6.21.4 → 6.22.1

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.
Files changed (110) hide show
  1. package/Behaviors/Meshes/pointerDragBehavior.d.ts +4 -3
  2. package/Behaviors/Meshes/pointerDragBehavior.js +4 -3
  3. package/Behaviors/Meshes/pointerDragBehavior.js.map +1 -1
  4. package/Engines/thinEngine.js +2 -2
  5. package/Engines/thinEngine.js.map +1 -1
  6. package/FlowGraph/Blocks/Data/Math/flowGraphMatrixBlocks.d.ts +167 -0
  7. package/FlowGraph/Blocks/Data/Math/flowGraphMatrixBlocks.js +198 -0
  8. package/FlowGraph/Blocks/Data/Math/flowGraphMatrixBlocks.js.map +1 -0
  9. package/FlowGraph/Blocks/Data/Math/flowGraphVector2MathBlocks.d.ts +63 -1
  10. package/FlowGraph/Blocks/Data/Math/flowGraphVector2MathBlocks.js +54 -0
  11. package/FlowGraph/Blocks/Data/Math/flowGraphVector2MathBlocks.js.map +1 -1
  12. package/FlowGraph/Blocks/Data/Math/flowGraphVector3MathBlocks.d.ts +85 -0
  13. package/FlowGraph/Blocks/Data/Math/flowGraphVector3MathBlocks.js +70 -2
  14. package/FlowGraph/Blocks/Data/Math/flowGraphVector3MathBlocks.js.map +1 -1
  15. package/FlowGraph/Blocks/Data/Math/flowGraphVector4MathBlocks.d.ts +61 -1
  16. package/FlowGraph/Blocks/Data/Math/flowGraphVector4MathBlocks.js +45 -0
  17. package/FlowGraph/Blocks/Data/Math/flowGraphVector4MathBlocks.js.map +1 -1
  18. package/FlowGraph/Blocks/Data/Math/index.d.ts +1 -0
  19. package/FlowGraph/Blocks/Data/Math/index.js +1 -0
  20. package/FlowGraph/Blocks/Data/Math/index.js.map +1 -1
  21. package/FlowGraph/Blocks/Data/flowGraphConstantBlock.d.ts +26 -0
  22. package/FlowGraph/Blocks/Data/flowGraphConstantBlock.js +17 -0
  23. package/FlowGraph/Blocks/Data/flowGraphConstantBlock.js.map +1 -0
  24. package/FlowGraph/Blocks/Data/flowGraphCoordinateTransformBlock.d.ts +32 -0
  25. package/FlowGraph/Blocks/Data/flowGraphCoordinateTransformBlock.js +37 -0
  26. package/FlowGraph/Blocks/Data/flowGraphCoordinateTransformBlock.js.map +1 -0
  27. package/FlowGraph/Blocks/Data/index.d.ts +3 -1
  28. package/FlowGraph/Blocks/Data/index.js +4 -2
  29. package/FlowGraph/Blocks/Data/index.js.map +1 -1
  30. package/FlowGraph/Blocks/Event/flowGraphReceiveCustomEventBlock.js +2 -2
  31. package/FlowGraph/Blocks/Event/flowGraphReceiveCustomEventBlock.js.map +1 -1
  32. package/FlowGraph/Blocks/Execution/Audio/flowGraphPlayAudioBlock.d.ts +17 -0
  33. package/FlowGraph/Blocks/Execution/Audio/flowGraphPlayAudioBlock.js +21 -0
  34. package/FlowGraph/Blocks/Execution/Audio/flowGraphPlayAudioBlock.js.map +1 -0
  35. package/FlowGraph/Blocks/Execution/Audio/flowGraphStopAudioBlock.d.ts +17 -0
  36. package/FlowGraph/Blocks/Execution/Audio/flowGraphStopAudioBlock.js +20 -0
  37. package/FlowGraph/Blocks/Execution/Audio/flowGraphStopAudioBlock.js.map +1 -0
  38. package/FlowGraph/Blocks/Execution/Audio/index.d.ts +2 -0
  39. package/FlowGraph/Blocks/Execution/Audio/index.js +3 -0
  40. package/FlowGraph/Blocks/Execution/Audio/index.js.map +1 -0
  41. package/FlowGraph/Blocks/Execution/ControlFlow/{flowGraphConditionalBlock.js → flowGraphBranchBlock.js} +1 -1
  42. package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphBranchBlock.js.map +1 -0
  43. package/FlowGraph/Blocks/Execution/ControlFlow/index.d.ts +1 -1
  44. package/FlowGraph/Blocks/Execution/ControlFlow/index.js +1 -1
  45. package/FlowGraph/Blocks/Execution/ControlFlow/index.js.map +1 -1
  46. package/FlowGraph/Blocks/Execution/flowGraphCustomFunctionBlock.d.ts +23 -0
  47. package/FlowGraph/Blocks/Execution/flowGraphCustomFunctionBlock.js +18 -0
  48. package/FlowGraph/Blocks/Execution/flowGraphCustomFunctionBlock.js.map +1 -0
  49. package/FlowGraph/Blocks/Execution/index.d.ts +1 -0
  50. package/FlowGraph/Blocks/Execution/index.js +2 -0
  51. package/FlowGraph/Blocks/Execution/index.js.map +1 -1
  52. package/FlowGraph/flowGraph.d.ts +14 -0
  53. package/FlowGraph/flowGraph.js +23 -0
  54. package/FlowGraph/flowGraph.js.map +1 -1
  55. package/FlowGraph/flowGraphCoordinator.d.ts +45 -0
  56. package/FlowGraph/flowGraphCoordinator.js +73 -0
  57. package/FlowGraph/flowGraphCoordinator.js.map +1 -0
  58. package/FlowGraph/flowGraphDataConnection.d.ts +11 -0
  59. package/FlowGraph/flowGraphDataConnection.js +17 -0
  60. package/FlowGraph/flowGraphDataConnection.js.map +1 -1
  61. package/FlowGraph/flowGraphRichTypes.d.ts +8 -1
  62. package/FlowGraph/flowGraphRichTypes.js +44 -1
  63. package/FlowGraph/flowGraphRichTypes.js.map +1 -1
  64. package/FlowGraph/index.d.ts +1 -0
  65. package/FlowGraph/index.js +1 -0
  66. package/FlowGraph/index.js.map +1 -1
  67. package/Gizmos/boundingBoxGizmo.js +13 -11
  68. package/Gizmos/boundingBoxGizmo.js.map +1 -1
  69. package/Gizmos/gizmo.js +3 -1
  70. package/Gizmos/gizmo.js.map +1 -1
  71. package/Gizmos/planeRotationGizmo.js +5 -0
  72. package/Gizmos/planeRotationGizmo.js.map +1 -1
  73. package/Gizmos/positionGizmo.d.ts +4 -0
  74. package/Gizmos/positionGizmo.js +6 -0
  75. package/Gizmos/positionGizmo.js.map +1 -1
  76. package/Gizmos/rotationGizmo.d.ts +4 -0
  77. package/Gizmos/rotationGizmo.js +6 -0
  78. package/Gizmos/rotationGizmo.js.map +1 -1
  79. package/Gizmos/scaleGizmo.d.ts +4 -0
  80. package/Gizmos/scaleGizmo.js +6 -0
  81. package/Gizmos/scaleGizmo.js.map +1 -1
  82. package/Maths/math.path.d.ts +1 -1
  83. package/Maths/math.path.js +1 -1
  84. package/Maths/math.path.js.map +1 -1
  85. package/Maths/math.vector.js +3 -3
  86. package/Maths/math.vector.js.map +1 -1
  87. package/Meshes/Node/Blocks/booleanGeometryBlock.d.ts +58 -0
  88. package/Meshes/Node/Blocks/booleanGeometryBlock.js +135 -0
  89. package/Meshes/Node/Blocks/booleanGeometryBlock.js.map +1 -0
  90. package/Meshes/Node/Blocks/geometryCollectionBlock.js +3 -0
  91. package/Meshes/Node/Blocks/geometryCollectionBlock.js.map +1 -1
  92. package/Meshes/Node/Blocks/mappingBlock.d.ts +4 -0
  93. package/Meshes/Node/Blocks/mappingBlock.js +23 -14
  94. package/Meshes/Node/Blocks/mappingBlock.js.map +1 -1
  95. package/Meshes/Node/Blocks/mergeGeometryBlock.js +0 -2
  96. package/Meshes/Node/Blocks/mergeGeometryBlock.js.map +1 -1
  97. package/Meshes/Node/index.d.ts +1 -0
  98. package/Meshes/Node/index.js +1 -0
  99. package/Meshes/Node/index.js.map +1 -1
  100. package/Meshes/csg.d.ts +169 -1
  101. package/Meshes/csg.js +107 -43
  102. package/Meshes/csg.js.map +1 -1
  103. package/Misc/textureTools.d.ts +24 -0
  104. package/Misc/textureTools.js +86 -0
  105. package/Misc/textureTools.js.map +1 -1
  106. package/Rendering/depthPeelingRenderer.js +6 -0
  107. package/Rendering/depthPeelingRenderer.js.map +1 -1
  108. package/package.json +1 -1
  109. package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphConditionalBlock.js.map +0 -1
  110. /package/FlowGraph/Blocks/Execution/ControlFlow/{flowGraphConditionalBlock.d.ts → flowGraphBranchBlock.d.ts} +0 -0
package/Meshes/csg.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"csg.js","sourceRoot":"","sources":["../../../../dev/core/src/Meshes/csg.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC5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AAC,QAAQ,CAAC,CAAC;QACtC,IAAI,IAAI,CAAC,kBAAkB,EAAE;YACzB,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAC;SAC7D;QACD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAE9B,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ","sourcesContent":["import type { Nullable, FloatArray, IndicesArray } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Quaternion, Matrix, Vector3, Vector2 } from \"../Maths/math.vector\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { SubMesh } from \"../Meshes/subMesh\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport type { Material } from \"../Materials/material\";\r\nimport { Color4 } from \"../Maths/math.color\";\r\nimport { Constants } from \"../Engines/constants\";\r\n/**\r\n * Unique ID when we import meshes from Babylon to CSG\r\n */\r\nlet currentCSGMeshId = 0;\r\n\r\n/**\r\n * Represents a vertex of a polygon. Use your own vertex class instead of this\r\n * one to provide additional features like texture coordinates and vertex\r\n * colors. Custom vertex classes need to provide a `pos` property and `clone()`,\r\n * `flip()`, and `interpolate()` methods that behave analogous to the ones\r\n * defined by `BABYLON.CSG.Vertex`. This class provides `normal` so convenience\r\n * functions like `BABYLON.CSG.sphere()` can return a smooth vertex normal, but `normal`\r\n * is not used anywhere else.\r\n * Same goes for uv, it allows to keep the original vertex uv coordinates of the 2 meshes\r\n */\r\nclass Vertex {\r\n /**\r\n * Initializes the vertex\r\n * @param pos The position of the vertex\r\n * @param normal The normal of the vertex\r\n * @param uv The texture coordinate of the vertex\r\n * @param vertColor The RGBA color of the vertex\r\n */\r\n constructor(\r\n /**\r\n * The position of the vertex\r\n */\r\n public pos: Vector3,\r\n /**\r\n * The normal of the vertex\r\n */\r\n public normal: Vector3,\r\n /**\r\n * The texture coordinate of the vertex\r\n */\r\n public uv?: Vector2,\r\n /**\r\n * The texture coordinate of the vertex\r\n */\r\n public vertColor?: Color4\r\n ) {}\r\n\r\n /**\r\n * Make a clone, or deep copy, of the vertex\r\n * @returns A new Vertex\r\n */\r\n public clone(): Vertex {\r\n return new Vertex(this.pos.clone(), this.normal.clone(), this.uv?.clone(), this.vertColor?.clone());\r\n }\r\n\r\n /**\r\n * Invert all orientation-specific data (e.g. vertex normal). Called when the\r\n * orientation of a polygon is flipped.\r\n */\r\n public flip(): void {\r\n this.normal = this.normal.scale(-1);\r\n }\r\n\r\n /**\r\n * Create a new vertex between this vertex and `other` by linearly\r\n * interpolating all properties using a parameter of `t`. Subclasses should\r\n * override this to interpolate additional properties.\r\n * @param other the vertex to interpolate against\r\n * @param t The factor used to linearly interpolate between the vertices\r\n */\r\n public interpolate(other: Vertex, t: number): Vertex {\r\n return new Vertex(\r\n Vector3.Lerp(this.pos, other.pos, t),\r\n Vector3.Lerp(this.normal, other.normal, t),\r\n this.uv && other.uv ? Vector2.Lerp(this.uv, other.uv, t) : undefined,\r\n this.vertColor && other.vertColor ? Color4.Lerp(this.vertColor, other.vertColor, t) : undefined\r\n );\r\n }\r\n}\r\n\r\n/**\r\n * Represents a plane in 3D space.\r\n */\r\nclass Plane {\r\n /**\r\n * Initializes the plane\r\n * @param normal The normal for the plane\r\n * @param w\r\n */\r\n constructor(public normal: Vector3, public w: number) {}\r\n\r\n /**\r\n * `CSG.Plane.EPSILON` is the tolerance used by `splitPolygon()` to decide if a\r\n * point is on the plane\r\n */\r\n static EPSILON = 1e-5;\r\n\r\n /**\r\n * Construct a plane from three points\r\n * @param a Point a\r\n * @param b Point b\r\n * @param c Point c\r\n */\r\n public static FromPoints(a: Vector3, b: Vector3, c: Vector3): Nullable<Plane> {\r\n const v0 = c.subtract(a);\r\n const v1 = b.subtract(a);\r\n\r\n if (v0.lengthSquared() === 0 || v1.lengthSquared() === 0) {\r\n return null;\r\n }\r\n\r\n const n = Vector3.Normalize(Vector3.Cross(v0, v1));\r\n return new Plane(n, Vector3.Dot(n, a));\r\n }\r\n\r\n /**\r\n * Clone, or make a deep copy of the plane\r\n * @returns a new Plane\r\n */\r\n public clone(): Plane {\r\n return new Plane(this.normal.clone(), this.w);\r\n }\r\n\r\n /**\r\n * Flip the face of the plane\r\n */\r\n public flip() {\r\n this.normal.scaleInPlace(-1);\r\n this.w = -this.w;\r\n }\r\n\r\n /**\r\n * Split `polygon` by this plane if needed, then put the polygon or polygon\r\n * fragments in the appropriate lists. Coplanar polygons go into either\r\n `* coplanarFront` or `coplanarBack` depending on their orientation with\r\n * respect to this plane. Polygons in front or in back of this plane go into\r\n * either `front` or `back`\r\n * @param polygon The polygon to be split\r\n * @param coplanarFront Will contain polygons coplanar with the plane that are oriented to the front of the plane\r\n * @param coplanarBack Will contain polygons coplanar with the plane that are oriented to the back of the plane\r\n * @param front Will contain the polygons in front of the plane\r\n * @param back Will contain the polygons begind the plane\r\n */\r\n public splitPolygon(polygon: Polygon, coplanarFront: Polygon[], coplanarBack: Polygon[], front: Polygon[], back: Polygon[]): void {\r\n const COPLANAR = 0;\r\n const FRONT = 1;\r\n const BACK = 2;\r\n const SPANNING = 3;\r\n\r\n // Classify each point as well as the entire polygon into one of the above\r\n // four classes.\r\n let polygonType = 0;\r\n const types = [];\r\n let i: number;\r\n let t: number;\r\n for (i = 0; i < polygon.vertices.length; i++) {\r\n t = Vector3.Dot(this.normal, polygon.vertices[i].pos) - this.w;\r\n const type = t < -Plane.EPSILON ? BACK : t > Plane.EPSILON ? FRONT : COPLANAR;\r\n polygonType |= type;\r\n types.push(type);\r\n }\r\n\r\n // Put the polygon in the correct list, splitting it when necessary\r\n switch (polygonType) {\r\n case COPLANAR:\r\n (Vector3.Dot(this.normal, polygon.plane.normal) > 0 ? coplanarFront : coplanarBack).push(polygon);\r\n break;\r\n case FRONT:\r\n front.push(polygon);\r\n break;\r\n case BACK:\r\n back.push(polygon);\r\n break;\r\n case SPANNING: {\r\n const f = [],\r\n b = [];\r\n for (i = 0; i < polygon.vertices.length; i++) {\r\n const j = (i + 1) % polygon.vertices.length;\r\n const ti = types[i],\r\n tj = types[j];\r\n const vi = polygon.vertices[i],\r\n vj = polygon.vertices[j];\r\n if (ti !== BACK) {\r\n f.push(vi);\r\n }\r\n if (ti !== FRONT) {\r\n b.push(ti !== BACK ? vi.clone() : vi);\r\n }\r\n if ((ti | tj) === SPANNING) {\r\n t = (this.w - Vector3.Dot(this.normal, vi.pos)) / Vector3.Dot(this.normal, vj.pos.subtract(vi.pos));\r\n const v = vi.interpolate(vj, t);\r\n f.push(v);\r\n b.push(v.clone());\r\n }\r\n }\r\n let poly: Polygon;\r\n if (f.length >= 3) {\r\n poly = new Polygon(f, polygon.shared);\r\n if (poly.plane) {\r\n front.push(poly);\r\n }\r\n }\r\n\r\n if (b.length >= 3) {\r\n poly = new Polygon(b, polygon.shared);\r\n\r\n if (poly.plane) {\r\n back.push(poly);\r\n }\r\n }\r\n\r\n break;\r\n }\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Represents a convex polygon. The vertices used to initialize a polygon must\r\n * be coplanar and form a convex loop.\r\n *\r\n * Each convex polygon has a `shared` property, which is shared between all\r\n * polygons that are clones of each other or were split from the same polygon.\r\n * This can be used to define per-polygon properties (such as surface color)\r\n */\r\nclass Polygon {\r\n /**\r\n * Vertices of the polygon\r\n */\r\n public vertices: Vertex[];\r\n /**\r\n * Properties that are shared across all polygons\r\n */\r\n public shared: any;\r\n /**\r\n * A plane formed from the vertices of the polygon\r\n */\r\n public plane: Plane;\r\n\r\n /**\r\n * Initializes the polygon\r\n * @param vertices The vertices of the polygon\r\n * @param shared The properties shared across all polygons\r\n */\r\n constructor(vertices: Vertex[], shared: any) {\r\n this.vertices = vertices;\r\n this.shared = shared;\r\n this.plane = <Plane>Plane.FromPoints(vertices[0].pos, vertices[1].pos, vertices[2].pos);\r\n }\r\n\r\n /**\r\n * Clones, or makes a deep copy, or the polygon\r\n */\r\n public clone(): Polygon {\r\n const vertices = this.vertices.map((v) => v.clone());\r\n return new Polygon(vertices, this.shared);\r\n }\r\n\r\n /**\r\n * Flips the faces of the polygon\r\n */\r\n public flip() {\r\n this.vertices.reverse().map((v) => {\r\n v.flip();\r\n });\r\n this.plane.flip();\r\n }\r\n}\r\n\r\n/**\r\n * Holds a node in a BSP tree. A BSP tree is built from a collection of polygons\r\n * by picking a polygon to split along. That polygon (and all other coplanar\r\n * polygons) are added directly to that node and the other polygons are added to\r\n * the front and/or back subtrees. This is not a leafy BSP tree since there is\r\n * no distinction between internal and leaf nodes\r\n */\r\nclass Node {\r\n private _plane: Nullable<Plane> = null;\r\n private _front: Nullable<Node> = null;\r\n private _back: Nullable<Node> = null;\r\n private _polygons = new Array<Polygon>();\r\n\r\n /**\r\n * Initializes the node\r\n * @param polygons A collection of polygons held in the node\r\n */\r\n constructor(polygons?: Array<Polygon>) {\r\n if (polygons) {\r\n this.build(polygons);\r\n }\r\n }\r\n\r\n /**\r\n * Clones, or makes a deep copy, of the node\r\n * @returns The cloned node\r\n */\r\n public clone(): Node {\r\n const node = new Node();\r\n node._plane = this._plane && this._plane.clone();\r\n node._front = this._front && this._front.clone();\r\n node._back = this._back && this._back.clone();\r\n node._polygons = this._polygons.map((p) => p.clone());\r\n return node;\r\n }\r\n\r\n /**\r\n * Convert solid space to empty space and empty space to solid space\r\n */\r\n public invert(): void {\r\n for (let i = 0; i < this._polygons.length; i++) {\r\n this._polygons[i].flip();\r\n }\r\n if (this._plane) {\r\n this._plane.flip();\r\n }\r\n if (this._front) {\r\n this._front.invert();\r\n }\r\n if (this._back) {\r\n this._back.invert();\r\n }\r\n const temp = this._front;\r\n this._front = this._back;\r\n this._back = temp;\r\n }\r\n\r\n /**\r\n * Recursively remove all polygons in `polygons` that are inside this BSP\r\n * tree.\r\n * @param polygons Polygons to remove from the BSP\r\n * @returns Polygons clipped from the BSP\r\n */\r\n clipPolygons(polygons: Polygon[]): Polygon[] {\r\n if (!this._plane) {\r\n return polygons.slice();\r\n }\r\n let front = new Array<Polygon>(),\r\n back = new Array<Polygon>();\r\n for (let i = 0; i < polygons.length; i++) {\r\n this._plane.splitPolygon(polygons[i], front, back, front, back);\r\n }\r\n if (this._front) {\r\n front = this._front.clipPolygons(front);\r\n }\r\n if (this._back) {\r\n back = this._back.clipPolygons(back);\r\n } else {\r\n back = [];\r\n }\r\n return front.concat(back);\r\n }\r\n\r\n /**\r\n * Remove all polygons in this BSP tree that are inside the other BSP tree\r\n * `bsp`.\r\n * @param bsp BSP containing polygons to remove from this BSP\r\n */\r\n clipTo(bsp: Node): void {\r\n this._polygons = bsp.clipPolygons(this._polygons);\r\n if (this._front) {\r\n this._front.clipTo(bsp);\r\n }\r\n if (this._back) {\r\n this._back.clipTo(bsp);\r\n }\r\n }\r\n\r\n /**\r\n * Return a list of all polygons in this BSP tree\r\n * @returns List of all polygons in this BSP tree\r\n */\r\n allPolygons(): Polygon[] {\r\n let polygons = this._polygons.slice();\r\n if (this._front) {\r\n polygons = polygons.concat(this._front.allPolygons());\r\n }\r\n if (this._back) {\r\n polygons = polygons.concat(this._back.allPolygons());\r\n }\r\n return polygons;\r\n }\r\n\r\n /**\r\n * Build a BSP tree out of `polygons`. When called on an existing tree, the\r\n * new polygons are filtered down to the bottom of the tree and become new\r\n * nodes there. Each set of polygons is partitioned using the first polygon\r\n * (no heuristic is used to pick a good split)\r\n * @param polygons Polygons used to construct the BSP tree\r\n */\r\n build(polygons: Polygon[]): void {\r\n if (!polygons.length) {\r\n return;\r\n }\r\n if (!this._plane) {\r\n this._plane = polygons[0].plane.clone();\r\n }\r\n const front = new Array<Polygon>(),\r\n back = new Array<Polygon>();\r\n for (let i = 0; i < polygons.length; i++) {\r\n this._plane.splitPolygon(polygons[i], this._polygons, this._polygons, front, back);\r\n }\r\n if (front.length) {\r\n if (!this._front) {\r\n this._front = new Node();\r\n }\r\n this._front.build(front);\r\n }\r\n if (back.length) {\r\n if (!this._back) {\r\n this._back = new Node();\r\n }\r\n this._back.build(back);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Class for building Constructive Solid Geometry\r\n */\r\nexport class CSG {\r\n private _polygons = new Array<Polygon>();\r\n /**\r\n * The world matrix\r\n */\r\n public matrix: Matrix;\r\n /**\r\n * Stores the position\r\n */\r\n public position: Vector3;\r\n /**\r\n * Stores the rotation\r\n */\r\n public rotation: Vector3;\r\n /**\r\n * Stores the rotation quaternion\r\n */\r\n public rotationQuaternion: Nullable<Quaternion>;\r\n /**\r\n * Stores the scaling vector\r\n */\r\n public scaling: Vector3;\r\n\r\n /**\r\n * Convert the Mesh to CSG\r\n * @param mesh The Mesh to convert to CSG\r\n * @param absolute If true, the final (local) matrix transformation is set to the identity and not to that of `mesh`. It can help when dealing with right-handed meshes (default: false)\r\n * @returns A new CSG from the Mesh\r\n */\r\n public static FromMesh(mesh: Mesh, absolute = false): CSG {\r\n let vertex: Vertex,\r\n normal: Vector3,\r\n uv: Vector2 | undefined = undefined,\r\n position: Vector3,\r\n vertColor: Color4 | undefined = undefined,\r\n polygon: Polygon,\r\n vertices;\r\n const polygons = new Array<Polygon>();\r\n let matrix: Matrix,\r\n meshPosition: Vector3,\r\n meshRotation: Vector3,\r\n meshRotationQuaternion: Nullable<Quaternion> = null,\r\n meshScaling: Vector3;\r\n\r\n let invertWinding = false;\r\n if (mesh instanceof Mesh) {\r\n mesh.computeWorldMatrix(true);\r\n matrix = mesh.getWorldMatrix();\r\n meshPosition = mesh.position.clone();\r\n meshRotation = mesh.rotation.clone();\r\n if (mesh.rotationQuaternion) {\r\n meshRotationQuaternion = mesh.rotationQuaternion.clone();\r\n }\r\n meshScaling = mesh.scaling.clone();\r\n if (mesh.material && absolute) {\r\n invertWinding = mesh.material.sideOrientation === Constants.MATERIAL_ClockWiseSideOrientation;\r\n }\r\n } else {\r\n throw \"BABYLON.CSG: Wrong Mesh type, must be BABYLON.Mesh\";\r\n }\r\n\r\n const indices = <IndicesArray>mesh.getIndices(),\r\n positions = <FloatArray>mesh.getVerticesData(VertexBuffer.PositionKind),\r\n normals = <FloatArray>mesh.getVerticesData(VertexBuffer.NormalKind),\r\n uvs = <FloatArray>mesh.getVerticesData(VertexBuffer.UVKind),\r\n vertColors = <FloatArray>mesh.getVerticesData(VertexBuffer.ColorKind);\r\n\r\n const subMeshes = mesh.subMeshes;\r\n\r\n for (let sm = 0, sml = subMeshes.length; sm < sml; sm++) {\r\n for (let i = subMeshes[sm].indexStart, il = subMeshes[sm].indexCount + subMeshes[sm].indexStart; i < il; i += 3) {\r\n vertices = [];\r\n for (let j = 0; j < 3; j++) {\r\n const indexIndices = j === 0 ? i + j : invertWinding ? i + 3 - j : i + j;\r\n const sourceNormal = new Vector3(normals[indices[indexIndices] * 3], normals[indices[indexIndices] * 3 + 1], normals[indices[indexIndices] * 3 + 2]);\r\n if (uvs) {\r\n uv = new Vector2(uvs[indices[indexIndices] * 2], uvs[indices[indexIndices] * 2 + 1]);\r\n }\r\n if (vertColors) {\r\n vertColor = new Color4(\r\n vertColors[indices[indexIndices] * 4],\r\n vertColors[indices[indexIndices] * 4 + 1],\r\n vertColors[indices[indexIndices] * 4 + 2],\r\n vertColors[indices[indexIndices] * 4 + 3]\r\n );\r\n }\r\n const sourcePosition = new Vector3(positions[indices[indexIndices] * 3], positions[indices[indexIndices] * 3 + 1], positions[indices[indexIndices] * 3 + 2]);\r\n position = Vector3.TransformCoordinates(sourcePosition, matrix);\r\n normal = Vector3.TransformNormal(sourceNormal, matrix);\r\n\r\n vertex = new Vertex(position, normal, uv, vertColor);\r\n vertices.push(vertex);\r\n }\r\n\r\n polygon = new Polygon(vertices, { subMeshId: sm, meshId: currentCSGMeshId, materialIndex: subMeshes[sm].materialIndex });\r\n\r\n // To handle the case of degenerated triangle\r\n // polygon.plane == null <=> the polygon does not represent 1 single plane <=> the triangle is degenerated\r\n if (polygon.plane) {\r\n polygons.push(polygon);\r\n }\r\n }\r\n }\r\n\r\n const csg = CSG._FromPolygons(polygons);\r\n csg.matrix = absolute ? Matrix.Identity() : matrix;\r\n csg.position = absolute ? Vector3.Zero() : meshPosition;\r\n csg.rotation = absolute ? Vector3.Zero() : meshRotation;\r\n csg.scaling = absolute ? Vector3.One() : meshScaling;\r\n csg.rotationQuaternion = absolute && meshRotationQuaternion ? Quaternion.Identity() : meshRotationQuaternion;\r\n currentCSGMeshId++;\r\n\r\n return csg;\r\n }\r\n\r\n /**\r\n * Construct a CSG solid from a list of `CSG.Polygon` instances.\r\n * @param polygons Polygons used to construct a CSG solid\r\n */\r\n private static _FromPolygons(polygons: Polygon[]): CSG {\r\n const csg = new CSG();\r\n csg._polygons = polygons;\r\n return csg;\r\n }\r\n\r\n /**\r\n * Clones, or makes a deep copy, of the CSG\r\n * @returns A new CSG\r\n */\r\n public clone(): CSG {\r\n const csg = new CSG();\r\n csg._polygons = this._polygons.map((p) => p.clone());\r\n csg.copyTransformAttributes(this);\r\n return csg;\r\n }\r\n\r\n /**\r\n * Unions this CSG with another CSG\r\n * @param csg The CSG to union against this CSG\r\n * @returns The unioned CSG\r\n */\r\n public union(csg: CSG): CSG {\r\n const a = new Node(this.clone()._polygons);\r\n const b = new Node(csg.clone()._polygons);\r\n a.clipTo(b);\r\n b.clipTo(a);\r\n b.invert();\r\n b.clipTo(a);\r\n b.invert();\r\n a.build(b.allPolygons());\r\n return CSG._FromPolygons(a.allPolygons()).copyTransformAttributes(this);\r\n }\r\n\r\n /**\r\n * Unions this CSG with another CSG in place\r\n * @param csg The CSG to union against this CSG\r\n */\r\n public unionInPlace(csg: CSG): void {\r\n const a = new Node(this._polygons);\r\n const b = new Node(csg._polygons);\r\n\r\n a.clipTo(b);\r\n b.clipTo(a);\r\n b.invert();\r\n b.clipTo(a);\r\n b.invert();\r\n a.build(b.allPolygons());\r\n\r\n this._polygons = a.allPolygons();\r\n }\r\n\r\n /**\r\n * Subtracts this CSG with another CSG\r\n * @param csg The CSG to subtract against this CSG\r\n * @returns A new CSG\r\n */\r\n public subtract(csg: CSG): CSG {\r\n const a = new Node(this.clone()._polygons);\r\n const b = new Node(csg.clone()._polygons);\r\n a.invert();\r\n a.clipTo(b);\r\n b.clipTo(a);\r\n b.invert();\r\n b.clipTo(a);\r\n b.invert();\r\n a.build(b.allPolygons());\r\n a.invert();\r\n return CSG._FromPolygons(a.allPolygons()).copyTransformAttributes(this);\r\n }\r\n\r\n /**\r\n * Subtracts this CSG with another CSG in place\r\n * @param csg The CSG to subtract against this CSG\r\n */\r\n public subtractInPlace(csg: CSG): void {\r\n const a = new Node(this._polygons);\r\n const b = new Node(csg._polygons);\r\n\r\n a.invert();\r\n a.clipTo(b);\r\n b.clipTo(a);\r\n b.invert();\r\n b.clipTo(a);\r\n b.invert();\r\n a.build(b.allPolygons());\r\n a.invert();\r\n\r\n this._polygons = a.allPolygons();\r\n }\r\n\r\n /**\r\n * Intersect this CSG with another CSG\r\n * @param csg The CSG to intersect against this CSG\r\n * @returns A new CSG\r\n */\r\n public intersect(csg: CSG): CSG {\r\n const a = new Node(this.clone()._polygons);\r\n const b = new Node(csg.clone()._polygons);\r\n a.invert();\r\n b.clipTo(a);\r\n b.invert();\r\n a.clipTo(b);\r\n b.clipTo(a);\r\n a.build(b.allPolygons());\r\n a.invert();\r\n return CSG._FromPolygons(a.allPolygons()).copyTransformAttributes(this);\r\n }\r\n\r\n /**\r\n * Intersects this CSG with another CSG in place\r\n * @param csg The CSG to intersect against this CSG\r\n */\r\n public intersectInPlace(csg: CSG): void {\r\n const a = new Node(this._polygons);\r\n const b = new Node(csg._polygons);\r\n\r\n a.invert();\r\n b.clipTo(a);\r\n b.invert();\r\n a.clipTo(b);\r\n b.clipTo(a);\r\n a.build(b.allPolygons());\r\n a.invert();\r\n\r\n this._polygons = a.allPolygons();\r\n }\r\n\r\n /**\r\n * Return a new CSG solid with solid and empty space switched. This solid is\r\n * not modified.\r\n * @returns A new CSG solid with solid and empty space switched\r\n */\r\n public inverse(): CSG {\r\n const csg = this.clone();\r\n csg.inverseInPlace();\r\n return csg;\r\n }\r\n\r\n /**\r\n * Inverses the CSG in place\r\n */\r\n public inverseInPlace(): void {\r\n this._polygons.map((p) => {\r\n p.flip();\r\n });\r\n }\r\n\r\n /**\r\n * This is used to keep meshes transformations so they can be restored\r\n * when we build back a Babylon Mesh\r\n * NB : All CSG operations are performed in world coordinates\r\n * @param csg The CSG to copy the transform attributes from\r\n * @returns This CSG\r\n */\r\n public copyTransformAttributes(csg: CSG): CSG {\r\n this.matrix = csg.matrix;\r\n this.position = csg.position;\r\n this.rotation = csg.rotation;\r\n this.scaling = csg.scaling;\r\n this.rotationQuaternion = csg.rotationQuaternion;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Build Raw mesh from CSG\r\n * Coordinates here are in world space\r\n * @param name The name of the mesh geometry\r\n * @param scene The Scene\r\n * @param keepSubMeshes Specifies if the submeshes should be kept\r\n * @returns A new Mesh\r\n */\r\n public buildMeshGeometry(name: string, scene?: Scene, keepSubMeshes?: boolean): Mesh {\r\n const matrix = this.matrix.clone();\r\n matrix.invert();\r\n\r\n const mesh = new Mesh(name, scene);\r\n const vertices = [];\r\n const indices = [];\r\n const normals = [];\r\n let uvs: Nullable<number[]> = null;\r\n let vertColors: Nullable<number[]> = null;\r\n const vertex = Vector3.Zero();\r\n const normal = Vector3.Zero();\r\n const uv = Vector2.Zero();\r\n const vertColor = new Color4(0, 0, 0, 0);\r\n const polygons = this._polygons;\r\n const polygonIndices = [0, 0, 0];\r\n let polygon;\r\n const vertice_dict = {};\r\n let vertex_idx;\r\n let currentIndex = 0;\r\n const subMeshDict = {};\r\n let subMeshObj;\r\n\r\n if (keepSubMeshes) {\r\n // Sort Polygons, since subMeshes are indices range\r\n polygons.sort((a, b) => {\r\n if (a.shared.meshId === b.shared.meshId) {\r\n return a.shared.subMeshId - b.shared.subMeshId;\r\n } else {\r\n return a.shared.meshId - b.shared.meshId;\r\n }\r\n });\r\n }\r\n\r\n for (let i = 0, il = polygons.length; i < il; i++) {\r\n polygon = polygons[i];\r\n\r\n // Building SubMeshes\r\n if (!(<any>subMeshDict)[polygon.shared.meshId]) {\r\n (<any>subMeshDict)[polygon.shared.meshId] = {};\r\n }\r\n if (!(<any>subMeshDict)[polygon.shared.meshId][polygon.shared.subMeshId]) {\r\n (<any>subMeshDict)[polygon.shared.meshId][polygon.shared.subMeshId] = {\r\n indexStart: +Infinity,\r\n indexEnd: -Infinity,\r\n materialIndex: polygon.shared.materialIndex,\r\n };\r\n }\r\n subMeshObj = (<any>subMeshDict)[polygon.shared.meshId][polygon.shared.subMeshId];\r\n\r\n for (let j = 2, jl = polygon.vertices.length; j < jl; j++) {\r\n polygonIndices[0] = 0;\r\n polygonIndices[1] = j - 1;\r\n polygonIndices[2] = j;\r\n\r\n for (let k = 0; k < 3; k++) {\r\n vertex.copyFrom(polygon.vertices[polygonIndices[k]].pos);\r\n normal.copyFrom(polygon.vertices[polygonIndices[k]].normal);\r\n if (polygon.vertices[polygonIndices[k]].uv) {\r\n if (!uvs) {\r\n uvs = [];\r\n }\r\n uv.copyFrom(polygon.vertices[polygonIndices[k]].uv!);\r\n }\r\n\r\n if (polygon.vertices[polygonIndices[k]].vertColor) {\r\n if (!vertColors) {\r\n vertColors = [];\r\n }\r\n vertColor.copyFrom(polygon.vertices[polygonIndices[k]].vertColor!);\r\n }\r\n const localVertex = Vector3.TransformCoordinates(vertex, matrix);\r\n const localNormal = Vector3.TransformNormal(normal, matrix);\r\n\r\n vertex_idx = (<any>vertice_dict)[localVertex.x + \",\" + localVertex.y + \",\" + localVertex.z];\r\n\r\n let areUvsDifferent = false;\r\n\r\n if (uvs && !(uvs[vertex_idx * 2] === uv.x || uvs[vertex_idx * 2 + 1] === uv.y)) {\r\n areUvsDifferent = true;\r\n }\r\n\r\n let areColorsDifferent = false;\r\n\r\n if (\r\n vertColors &&\r\n !(\r\n vertColors[vertex_idx * 4] === vertColor.r ||\r\n vertColors[vertex_idx * 4 + 1] === vertColor.g ||\r\n vertColors[vertex_idx * 4 + 2] === vertColor.b ||\r\n vertColors[vertex_idx * 4 + 3] === vertColor.a\r\n )\r\n ) {\r\n areColorsDifferent = true;\r\n }\r\n\r\n // Check if 2 points can be merged\r\n if (\r\n !(\r\n typeof vertex_idx !== \"undefined\" &&\r\n normals[vertex_idx * 3] === localNormal.x &&\r\n normals[vertex_idx * 3 + 1] === localNormal.y &&\r\n normals[vertex_idx * 3 + 2] === localNormal.z\r\n ) ||\r\n areUvsDifferent ||\r\n areColorsDifferent\r\n ) {\r\n vertices.push(localVertex.x, localVertex.y, localVertex.z);\r\n if (uvs) {\r\n uvs.push(uv.x, uv.y);\r\n }\r\n normals.push(normal.x, normal.y, normal.z);\r\n if (vertColors) {\r\n vertColors.push(vertColor.r, vertColor.g, vertColor.b, vertColor.a);\r\n }\r\n vertex_idx = (<any>vertice_dict)[localVertex.x + \",\" + localVertex.y + \",\" + localVertex.z] = vertices.length / 3 - 1;\r\n }\r\n\r\n indices.push(vertex_idx);\r\n\r\n subMeshObj.indexStart = Math.min(currentIndex, subMeshObj.indexStart);\r\n subMeshObj.indexEnd = Math.max(currentIndex, subMeshObj.indexEnd);\r\n currentIndex++;\r\n }\r\n }\r\n }\r\n\r\n mesh.setVerticesData(VertexBuffer.PositionKind, vertices);\r\n mesh.setVerticesData(VertexBuffer.NormalKind, normals);\r\n if (uvs) {\r\n mesh.setVerticesData(VertexBuffer.UVKind, uvs);\r\n }\r\n if (vertColors) {\r\n mesh.setVerticesData(VertexBuffer.ColorKind, vertColors);\r\n }\r\n mesh.setIndices(indices, null);\r\n\r\n if (keepSubMeshes) {\r\n // We offset the materialIndex by the previous number of materials in the CSG mixed meshes\r\n let materialIndexOffset = 0,\r\n materialMaxIndex;\r\n\r\n mesh.subMeshes = new Array<SubMesh>();\r\n\r\n for (const m in subMeshDict) {\r\n materialMaxIndex = -1;\r\n for (const sm in (<any>subMeshDict)[m]) {\r\n subMeshObj = (<any>subMeshDict)[m][sm];\r\n SubMesh.CreateFromIndices(\r\n subMeshObj.materialIndex + materialIndexOffset,\r\n subMeshObj.indexStart,\r\n subMeshObj.indexEnd - subMeshObj.indexStart + 1,\r\n <AbstractMesh>mesh\r\n );\r\n materialMaxIndex = Math.max(subMeshObj.materialIndex, materialMaxIndex);\r\n }\r\n materialIndexOffset += ++materialMaxIndex;\r\n }\r\n }\r\n\r\n return mesh;\r\n }\r\n\r\n /**\r\n * Build Mesh from CSG taking material and transforms into account\r\n * @param name The name of the Mesh\r\n * @param material The material of the Mesh\r\n * @param scene The Scene\r\n * @param keepSubMeshes Specifies if submeshes should be kept\r\n * @returns The new Mesh\r\n */\r\n public toMesh(name: string, material: Nullable<Material> = null, scene?: Scene, keepSubMeshes?: boolean): Mesh {\r\n const mesh = this.buildMeshGeometry(name, scene, keepSubMeshes);\r\n\r\n mesh.material = material;\r\n\r\n mesh.position.copyFrom(this.position);\r\n mesh.rotation.copyFrom(this.rotation);\r\n if (this.rotationQuaternion) {\r\n mesh.rotationQuaternion = this.rotationQuaternion.clone();\r\n }\r\n mesh.scaling.copyFrom(this.scaling);\r\n mesh.computeWorldMatrix(true);\r\n\r\n return mesh;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"csg.js","sourceRoot":"","sources":["../../../../dev/core/src/Meshes/csg.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C;;GAEG;AACH,IAAI,gBAAgB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OAAO,CAAC,CAAC;QACpC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAE9B,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ","sourcesContent":["import type { Nullable, FloatArray, IndicesArray } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Quaternion, Matrix, Vector3, Vector2 } from \"../Maths/math.vector\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { SubMesh } from \"../Meshes/subMesh\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport type { Material } from \"../Materials/material\";\r\nimport { Color4 } from \"../Maths/math.color\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { VertexData } from \"./mesh.vertexData\";\r\n/**\r\n * Unique ID when we import meshes from Babylon to CSG\r\n */\r\nlet currentCSGMeshId = 0;\r\n\r\n/**\r\n * Represents a vertex of a polygon. Use your own vertex class instead of this\r\n * one to provide additional features like texture coordinates and vertex\r\n * colors. Custom vertex classes need to provide a `pos` property and `clone()`,\r\n * `flip()`, and `interpolate()` methods that behave analogous to the ones\r\n * defined by `BABYLON.CSG.Vertex`. This class provides `normal` so convenience\r\n * functions like `BABYLON.CSG.sphere()` can return a smooth vertex normal, but `normal`\r\n * is not used anywhere else.\r\n * Same goes for uv, it allows to keep the original vertex uv coordinates of the 2 meshes\r\n */\r\nclass Vertex {\r\n /**\r\n * Initializes the vertex\r\n * @param pos The position of the vertex\r\n * @param normal The normal of the vertex\r\n * @param uv The texture coordinate of the vertex\r\n * @param vertColor The RGBA color of the vertex\r\n */\r\n constructor(\r\n /**\r\n * The position of the vertex\r\n */\r\n public pos: Vector3,\r\n /**\r\n * The normal of the vertex\r\n */\r\n public normal: Vector3,\r\n /**\r\n * The texture coordinate of the vertex\r\n */\r\n public uv?: Vector2,\r\n /**\r\n * The texture coordinate of the vertex\r\n */\r\n public vertColor?: Color4\r\n ) {}\r\n\r\n /**\r\n * Make a clone, or deep copy, of the vertex\r\n * @returns A new Vertex\r\n */\r\n public clone(): Vertex {\r\n return new Vertex(this.pos.clone(), this.normal.clone(), this.uv?.clone(), this.vertColor?.clone());\r\n }\r\n\r\n /**\r\n * Invert all orientation-specific data (e.g. vertex normal). Called when the\r\n * orientation of a polygon is flipped.\r\n */\r\n public flip(): void {\r\n this.normal = this.normal.scale(-1);\r\n }\r\n\r\n /**\r\n * Create a new vertex between this vertex and `other` by linearly\r\n * interpolating all properties using a parameter of `t`. Subclasses should\r\n * override this to interpolate additional properties.\r\n * @param other the vertex to interpolate against\r\n * @param t The factor used to linearly interpolate between the vertices\r\n */\r\n public interpolate(other: Vertex, t: number): Vertex {\r\n return new Vertex(\r\n Vector3.Lerp(this.pos, other.pos, t),\r\n Vector3.Lerp(this.normal, other.normal, t),\r\n this.uv && other.uv ? Vector2.Lerp(this.uv, other.uv, t) : undefined,\r\n this.vertColor && other.vertColor ? Color4.Lerp(this.vertColor, other.vertColor, t) : undefined\r\n );\r\n }\r\n}\r\n\r\n/**\r\n * Represents a plane in 3D space.\r\n */\r\nclass Plane {\r\n /**\r\n * Initializes the plane\r\n * @param normal The normal for the plane\r\n * @param w\r\n */\r\n constructor(public normal: Vector3, public w: number) {}\r\n\r\n /**\r\n * `CSG.Plane.EPSILON` is the tolerance used by `splitPolygon()` to decide if a\r\n * point is on the plane\r\n */\r\n static EPSILON = 1e-5;\r\n\r\n /**\r\n * Construct a plane from three points\r\n * @param a Point a\r\n * @param b Point b\r\n * @param c Point c\r\n */\r\n public static FromPoints(a: Vector3, b: Vector3, c: Vector3): Nullable<Plane> {\r\n const v0 = c.subtract(a);\r\n const v1 = b.subtract(a);\r\n\r\n if (v0.lengthSquared() === 0 || v1.lengthSquared() === 0) {\r\n return null;\r\n }\r\n\r\n const n = Vector3.Normalize(Vector3.Cross(v0, v1));\r\n return new Plane(n, Vector3.Dot(n, a));\r\n }\r\n\r\n /**\r\n * Clone, or make a deep copy of the plane\r\n * @returns a new Plane\r\n */\r\n public clone(): Plane {\r\n return new Plane(this.normal.clone(), this.w);\r\n }\r\n\r\n /**\r\n * Flip the face of the plane\r\n */\r\n public flip() {\r\n this.normal.scaleInPlace(-1);\r\n this.w = -this.w;\r\n }\r\n\r\n /**\r\n * Split `polygon` by this plane if needed, then put the polygon or polygon\r\n * fragments in the appropriate lists. Coplanar polygons go into either\r\n `* coplanarFront` or `coplanarBack` depending on their orientation with\r\n * respect to this plane. Polygons in front or in back of this plane go into\r\n * either `front` or `back`\r\n * @param polygon The polygon to be split\r\n * @param coplanarFront Will contain polygons coplanar with the plane that are oriented to the front of the plane\r\n * @param coplanarBack Will contain polygons coplanar with the plane that are oriented to the back of the plane\r\n * @param front Will contain the polygons in front of the plane\r\n * @param back Will contain the polygons begind the plane\r\n */\r\n public splitPolygon(polygon: Polygon, coplanarFront: Polygon[], coplanarBack: Polygon[], front: Polygon[], back: Polygon[]): void {\r\n const COPLANAR = 0;\r\n const FRONT = 1;\r\n const BACK = 2;\r\n const SPANNING = 3;\r\n\r\n // Classify each point as well as the entire polygon into one of the above\r\n // four classes.\r\n let polygonType = 0;\r\n const types = [];\r\n let i: number;\r\n let t: number;\r\n for (i = 0; i < polygon.vertices.length; i++) {\r\n t = Vector3.Dot(this.normal, polygon.vertices[i].pos) - this.w;\r\n const type = t < -Plane.EPSILON ? BACK : t > Plane.EPSILON ? FRONT : COPLANAR;\r\n polygonType |= type;\r\n types.push(type);\r\n }\r\n\r\n // Put the polygon in the correct list, splitting it when necessary\r\n switch (polygonType) {\r\n case COPLANAR:\r\n (Vector3.Dot(this.normal, polygon.plane.normal) > 0 ? coplanarFront : coplanarBack).push(polygon);\r\n break;\r\n case FRONT:\r\n front.push(polygon);\r\n break;\r\n case BACK:\r\n back.push(polygon);\r\n break;\r\n case SPANNING: {\r\n const f = [],\r\n b = [];\r\n for (i = 0; i < polygon.vertices.length; i++) {\r\n const j = (i + 1) % polygon.vertices.length;\r\n const ti = types[i],\r\n tj = types[j];\r\n const vi = polygon.vertices[i],\r\n vj = polygon.vertices[j];\r\n if (ti !== BACK) {\r\n f.push(vi);\r\n }\r\n if (ti !== FRONT) {\r\n b.push(ti !== BACK ? vi.clone() : vi);\r\n }\r\n if ((ti | tj) === SPANNING) {\r\n t = (this.w - Vector3.Dot(this.normal, vi.pos)) / Vector3.Dot(this.normal, vj.pos.subtract(vi.pos));\r\n const v = vi.interpolate(vj, t);\r\n f.push(v);\r\n b.push(v.clone());\r\n }\r\n }\r\n let poly: Polygon;\r\n if (f.length >= 3) {\r\n poly = new Polygon(f, polygon.shared);\r\n if (poly.plane) {\r\n front.push(poly);\r\n }\r\n }\r\n\r\n if (b.length >= 3) {\r\n poly = new Polygon(b, polygon.shared);\r\n\r\n if (poly.plane) {\r\n back.push(poly);\r\n }\r\n }\r\n\r\n break;\r\n }\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Represents a convex polygon. The vertices used to initialize a polygon must\r\n * be coplanar and form a convex loop.\r\n *\r\n * Each convex polygon has a `shared` property, which is shared between all\r\n * polygons that are clones of each other or were split from the same polygon.\r\n * This can be used to define per-polygon properties (such as surface color)\r\n */\r\nclass Polygon {\r\n /**\r\n * Vertices of the polygon\r\n */\r\n public vertices: Vertex[];\r\n /**\r\n * Properties that are shared across all polygons\r\n */\r\n public shared: any;\r\n /**\r\n * A plane formed from the vertices of the polygon\r\n */\r\n public plane: Plane;\r\n\r\n /**\r\n * Initializes the polygon\r\n * @param vertices The vertices of the polygon\r\n * @param shared The properties shared across all polygons\r\n */\r\n constructor(vertices: Vertex[], shared: any) {\r\n this.vertices = vertices;\r\n this.shared = shared;\r\n this.plane = <Plane>Plane.FromPoints(vertices[0].pos, vertices[1].pos, vertices[2].pos);\r\n }\r\n\r\n /**\r\n * Clones, or makes a deep copy, or the polygon\r\n */\r\n public clone(): Polygon {\r\n const vertices = this.vertices.map((v) => v.clone());\r\n return new Polygon(vertices, this.shared);\r\n }\r\n\r\n /**\r\n * Flips the faces of the polygon\r\n */\r\n public flip() {\r\n this.vertices.reverse().map((v) => {\r\n v.flip();\r\n });\r\n this.plane.flip();\r\n }\r\n}\r\n\r\n/**\r\n * Holds a node in a BSP tree. A BSP tree is built from a collection of polygons\r\n * by picking a polygon to split along. That polygon (and all other coplanar\r\n * polygons) are added directly to that node and the other polygons are added to\r\n * the front and/or back subtrees. This is not a leafy BSP tree since there is\r\n * no distinction between internal and leaf nodes\r\n */\r\nclass Node {\r\n private _plane: Nullable<Plane> = null;\r\n private _front: Nullable<Node> = null;\r\n private _back: Nullable<Node> = null;\r\n private _polygons = new Array<Polygon>();\r\n\r\n /**\r\n * Initializes the node\r\n * @param polygons A collection of polygons held in the node\r\n */\r\n constructor(polygons?: Array<Polygon>) {\r\n if (polygons) {\r\n this.build(polygons);\r\n }\r\n }\r\n\r\n /**\r\n * Clones, or makes a deep copy, of the node\r\n * @returns The cloned node\r\n */\r\n public clone(): Node {\r\n const node = new Node();\r\n node._plane = this._plane && this._plane.clone();\r\n node._front = this._front && this._front.clone();\r\n node._back = this._back && this._back.clone();\r\n node._polygons = this._polygons.map((p) => p.clone());\r\n return node;\r\n }\r\n\r\n /**\r\n * Convert solid space to empty space and empty space to solid space\r\n */\r\n public invert(): void {\r\n for (let i = 0; i < this._polygons.length; i++) {\r\n this._polygons[i].flip();\r\n }\r\n if (this._plane) {\r\n this._plane.flip();\r\n }\r\n if (this._front) {\r\n this._front.invert();\r\n }\r\n if (this._back) {\r\n this._back.invert();\r\n }\r\n const temp = this._front;\r\n this._front = this._back;\r\n this._back = temp;\r\n }\r\n\r\n /**\r\n * Recursively remove all polygons in `polygons` that are inside this BSP\r\n * tree.\r\n * @param polygons Polygons to remove from the BSP\r\n * @returns Polygons clipped from the BSP\r\n */\r\n clipPolygons(polygons: Polygon[]): Polygon[] {\r\n if (!this._plane) {\r\n return polygons.slice();\r\n }\r\n let front = new Array<Polygon>(),\r\n back = new Array<Polygon>();\r\n for (let i = 0; i < polygons.length; i++) {\r\n this._plane.splitPolygon(polygons[i], front, back, front, back);\r\n }\r\n if (this._front) {\r\n front = this._front.clipPolygons(front);\r\n }\r\n if (this._back) {\r\n back = this._back.clipPolygons(back);\r\n } else {\r\n back = [];\r\n }\r\n return front.concat(back);\r\n }\r\n\r\n /**\r\n * Remove all polygons in this BSP tree that are inside the other BSP tree\r\n * `bsp`.\r\n * @param bsp BSP containing polygons to remove from this BSP\r\n */\r\n clipTo(bsp: Node): void {\r\n this._polygons = bsp.clipPolygons(this._polygons);\r\n if (this._front) {\r\n this._front.clipTo(bsp);\r\n }\r\n if (this._back) {\r\n this._back.clipTo(bsp);\r\n }\r\n }\r\n\r\n /**\r\n * Return a list of all polygons in this BSP tree\r\n * @returns List of all polygons in this BSP tree\r\n */\r\n allPolygons(): Polygon[] {\r\n let polygons = this._polygons.slice();\r\n if (this._front) {\r\n polygons = polygons.concat(this._front.allPolygons());\r\n }\r\n if (this._back) {\r\n polygons = polygons.concat(this._back.allPolygons());\r\n }\r\n return polygons;\r\n }\r\n\r\n /**\r\n * Build a BSP tree out of `polygons`. When called on an existing tree, the\r\n * new polygons are filtered down to the bottom of the tree and become new\r\n * nodes there. Each set of polygons is partitioned using the first polygon\r\n * (no heuristic is used to pick a good split)\r\n * @param polygons Polygons used to construct the BSP tree\r\n */\r\n build(polygons: Polygon[]): void {\r\n if (!polygons.length) {\r\n return;\r\n }\r\n if (!this._plane) {\r\n this._plane = polygons[0].plane.clone();\r\n }\r\n const front = new Array<Polygon>(),\r\n back = new Array<Polygon>();\r\n for (let i = 0; i < polygons.length; i++) {\r\n this._plane.splitPolygon(polygons[i], this._polygons, this._polygons, front, back);\r\n }\r\n if (front.length) {\r\n if (!this._front) {\r\n this._front = new Node();\r\n }\r\n this._front.build(front);\r\n }\r\n if (back.length) {\r\n if (!this._back) {\r\n this._back = new Node();\r\n }\r\n this._back.build(back);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Class for building Constructive Solid Geometry\r\n */\r\nexport class CSG {\r\n private _polygons = new Array<Polygon>();\r\n /**\r\n * The world matrix\r\n */\r\n public matrix: Matrix;\r\n /**\r\n * Stores the position\r\n */\r\n public position: Vector3;\r\n /**\r\n * Stores the rotation\r\n */\r\n public rotation: Vector3;\r\n /**\r\n * Stores the rotation quaternion\r\n */\r\n public rotationQuaternion: Nullable<Quaternion>;\r\n /**\r\n * Stores the scaling vector\r\n */\r\n public scaling: Vector3;\r\n\r\n /**\r\n * Convert a VertexData to CSG\r\n * @param mesh defines the VertexData to convert to CSG\r\n * @returns the new CSG\r\n */\r\n public static FromVertexData(data: VertexData): CSG {\r\n let vertex: Vertex, polygon: Polygon, vertices: Vertex[];\r\n const polygons = new Array<Polygon>();\r\n\r\n const indices = data.indices;\r\n const positions = data.positions;\r\n const normals = data.normals;\r\n const uvs = data.uvs;\r\n const vertColors = data.colors;\r\n\r\n if (!indices || !positions) {\r\n throw \"BABYLON.CSG: VertexData must at least contain positions and indices\";\r\n }\r\n\r\n for (let i = 0; i < indices.length; i += 3) {\r\n vertices = [];\r\n for (let j = 0; j < 3; j++) {\r\n const indexIndices = i + j;\r\n const offset = indices[indexIndices];\r\n\r\n const normal = normals ? Vector3.FromArray(normals, offset * 3) : Vector3.Zero();\r\n const uv = uvs ? Vector2.FromArray(uvs, offset * 2) : undefined;\r\n const vertColor = vertColors ? Color4.FromArray(vertColors, offset * 4) : undefined;\r\n\r\n const position = Vector3.FromArray(positions, offset * 3);\r\n\r\n vertex = new Vertex(position, normal, uv, vertColor);\r\n vertices.push(vertex);\r\n }\r\n\r\n polygon = new Polygon(vertices, { subMeshId: 0, meshId: currentCSGMeshId, materialIndex: 0 });\r\n\r\n // To handle the case of degenerated triangle\r\n // polygon.plane == null <=> the polygon does not represent 1 single plane <=> the triangle is degenerated\r\n if (polygon.plane) {\r\n polygons.push(polygon);\r\n }\r\n }\r\n\r\n const csg = CSG._FromPolygons(polygons);\r\n csg.matrix = Matrix.Identity();\r\n csg.position = Vector3.Zero();\r\n csg.rotation = Vector3.Zero();\r\n csg.scaling = Vector3.One();\r\n csg.rotationQuaternion = Quaternion.Identity();\r\n currentCSGMeshId++;\r\n\r\n return csg;\r\n }\r\n\r\n /**\r\n * Convert the Mesh to CSG\r\n * @param mesh The Mesh to convert to CSG\r\n * @param absolute If true, the final (local) matrix transformation is set to the identity and not to that of `mesh`. It can help when dealing with right-handed meshes (default: false)\r\n * @returns A new CSG from the Mesh\r\n */\r\n public static FromMesh(mesh: Mesh, absolute = false): CSG {\r\n let vertex: Vertex,\r\n normal: Vector3,\r\n uv: Vector2 | undefined = undefined,\r\n position: Vector3,\r\n vertColor: Color4 | undefined = undefined,\r\n polygon: Polygon,\r\n vertices: Vertex[];\r\n const polygons = new Array<Polygon>();\r\n let matrix: Matrix,\r\n meshPosition: Vector3,\r\n meshRotation: Vector3,\r\n meshRotationQuaternion: Nullable<Quaternion> = null,\r\n meshScaling: Vector3;\r\n\r\n let invertWinding = false;\r\n if (mesh instanceof Mesh) {\r\n mesh.computeWorldMatrix(true);\r\n matrix = mesh.getWorldMatrix();\r\n meshPosition = mesh.position.clone();\r\n meshRotation = mesh.rotation.clone();\r\n if (mesh.rotationQuaternion) {\r\n meshRotationQuaternion = mesh.rotationQuaternion.clone();\r\n }\r\n meshScaling = mesh.scaling.clone();\r\n if (mesh.material && absolute) {\r\n invertWinding = mesh.material.sideOrientation === Constants.MATERIAL_ClockWiseSideOrientation;\r\n }\r\n } else {\r\n throw \"BABYLON.CSG: Wrong Mesh type, must be BABYLON.Mesh\";\r\n }\r\n\r\n const indices = <IndicesArray>mesh.getIndices(),\r\n positions = <FloatArray>mesh.getVerticesData(VertexBuffer.PositionKind),\r\n normals = <FloatArray>mesh.getVerticesData(VertexBuffer.NormalKind),\r\n uvs = <FloatArray>mesh.getVerticesData(VertexBuffer.UVKind),\r\n vertColors = <FloatArray>mesh.getVerticesData(VertexBuffer.ColorKind);\r\n\r\n const subMeshes = mesh.subMeshes;\r\n\r\n for (let sm = 0, sml = subMeshes.length; sm < sml; sm++) {\r\n for (let i = subMeshes[sm].indexStart, il = subMeshes[sm].indexCount + subMeshes[sm].indexStart; i < il; i += 3) {\r\n vertices = [];\r\n for (let j = 0; j < 3; j++) {\r\n const indexIndices = j === 0 ? i + j : invertWinding ? i + 3 - j : i + j;\r\n const sourceNormal = new Vector3(normals[indices[indexIndices] * 3], normals[indices[indexIndices] * 3 + 1], normals[indices[indexIndices] * 3 + 2]);\r\n if (uvs) {\r\n uv = new Vector2(uvs[indices[indexIndices] * 2], uvs[indices[indexIndices] * 2 + 1]);\r\n }\r\n if (vertColors) {\r\n vertColor = new Color4(\r\n vertColors[indices[indexIndices] * 4],\r\n vertColors[indices[indexIndices] * 4 + 1],\r\n vertColors[indices[indexIndices] * 4 + 2],\r\n vertColors[indices[indexIndices] * 4 + 3]\r\n );\r\n }\r\n const sourcePosition = new Vector3(positions[indices[indexIndices] * 3], positions[indices[indexIndices] * 3 + 1], positions[indices[indexIndices] * 3 + 2]);\r\n position = Vector3.TransformCoordinates(sourcePosition, matrix);\r\n normal = Vector3.TransformNormal(sourceNormal, matrix);\r\n\r\n vertex = new Vertex(position, normal, uv, vertColor);\r\n vertices.push(vertex);\r\n }\r\n\r\n polygon = new Polygon(vertices, { subMeshId: sm, meshId: currentCSGMeshId, materialIndex: subMeshes[sm].materialIndex });\r\n\r\n // To handle the case of degenerated triangle\r\n // polygon.plane == null <=> the polygon does not represent 1 single plane <=> the triangle is degenerated\r\n if (polygon.plane) {\r\n polygons.push(polygon);\r\n }\r\n }\r\n }\r\n\r\n const csg = CSG._FromPolygons(polygons);\r\n csg.matrix = absolute ? Matrix.Identity() : matrix;\r\n csg.position = absolute ? Vector3.Zero() : meshPosition;\r\n csg.rotation = absolute ? Vector3.Zero() : meshRotation;\r\n csg.scaling = absolute ? Vector3.One() : meshScaling;\r\n csg.rotationQuaternion = absolute && meshRotationQuaternion ? Quaternion.Identity() : meshRotationQuaternion;\r\n currentCSGMeshId++;\r\n\r\n return csg;\r\n }\r\n\r\n /**\r\n * Construct a CSG solid from a list of `CSG.Polygon` instances.\r\n * @param polygons Polygons used to construct a CSG solid\r\n */\r\n private static _FromPolygons(polygons: Polygon[]): CSG {\r\n const csg = new CSG();\r\n csg._polygons = polygons;\r\n return csg;\r\n }\r\n\r\n /**\r\n * Clones, or makes a deep copy, of the CSG\r\n * @returns A new CSG\r\n */\r\n public clone(): CSG {\r\n const csg = new CSG();\r\n csg._polygons = this._polygons.map((p) => p.clone());\r\n csg.copyTransformAttributes(this);\r\n return csg;\r\n }\r\n\r\n /**\r\n * Unions this CSG with another CSG\r\n * @param csg The CSG to union against this CSG\r\n * @returns The unioned CSG\r\n */\r\n public union(csg: CSG): CSG {\r\n const a = new Node(this.clone()._polygons);\r\n const b = new Node(csg.clone()._polygons);\r\n a.clipTo(b);\r\n b.clipTo(a);\r\n b.invert();\r\n b.clipTo(a);\r\n b.invert();\r\n a.build(b.allPolygons());\r\n return CSG._FromPolygons(a.allPolygons()).copyTransformAttributes(this);\r\n }\r\n\r\n /**\r\n * Unions this CSG with another CSG in place\r\n * @param csg The CSG to union against this CSG\r\n */\r\n public unionInPlace(csg: CSG): void {\r\n const a = new Node(this._polygons);\r\n const b = new Node(csg._polygons);\r\n\r\n a.clipTo(b);\r\n b.clipTo(a);\r\n b.invert();\r\n b.clipTo(a);\r\n b.invert();\r\n a.build(b.allPolygons());\r\n\r\n this._polygons = a.allPolygons();\r\n }\r\n\r\n /**\r\n * Subtracts this CSG with another CSG\r\n * @param csg The CSG to subtract against this CSG\r\n * @returns A new CSG\r\n */\r\n public subtract(csg: CSG): CSG {\r\n const a = new Node(this.clone()._polygons);\r\n const b = new Node(csg.clone()._polygons);\r\n a.invert();\r\n a.clipTo(b);\r\n b.clipTo(a);\r\n b.invert();\r\n b.clipTo(a);\r\n b.invert();\r\n a.build(b.allPolygons());\r\n a.invert();\r\n return CSG._FromPolygons(a.allPolygons()).copyTransformAttributes(this);\r\n }\r\n\r\n /**\r\n * Subtracts this CSG with another CSG in place\r\n * @param csg The CSG to subtract against this CSG\r\n */\r\n public subtractInPlace(csg: CSG): void {\r\n const a = new Node(this._polygons);\r\n const b = new Node(csg._polygons);\r\n\r\n a.invert();\r\n a.clipTo(b);\r\n b.clipTo(a);\r\n b.invert();\r\n b.clipTo(a);\r\n b.invert();\r\n a.build(b.allPolygons());\r\n a.invert();\r\n\r\n this._polygons = a.allPolygons();\r\n }\r\n\r\n /**\r\n * Intersect this CSG with another CSG\r\n * @param csg The CSG to intersect against this CSG\r\n * @returns A new CSG\r\n */\r\n public intersect(csg: CSG): CSG {\r\n const a = new Node(this.clone()._polygons);\r\n const b = new Node(csg.clone()._polygons);\r\n a.invert();\r\n b.clipTo(a);\r\n b.invert();\r\n a.clipTo(b);\r\n b.clipTo(a);\r\n a.build(b.allPolygons());\r\n a.invert();\r\n return CSG._FromPolygons(a.allPolygons()).copyTransformAttributes(this);\r\n }\r\n\r\n /**\r\n * Intersects this CSG with another CSG in place\r\n * @param csg The CSG to intersect against this CSG\r\n */\r\n public intersectInPlace(csg: CSG): void {\r\n const a = new Node(this._polygons);\r\n const b = new Node(csg._polygons);\r\n\r\n a.invert();\r\n b.clipTo(a);\r\n b.invert();\r\n a.clipTo(b);\r\n b.clipTo(a);\r\n a.build(b.allPolygons());\r\n a.invert();\r\n\r\n this._polygons = a.allPolygons();\r\n }\r\n\r\n /**\r\n * Return a new CSG solid with solid and empty space switched. This solid is\r\n * not modified.\r\n * @returns A new CSG solid with solid and empty space switched\r\n */\r\n public inverse(): CSG {\r\n const csg = this.clone();\r\n csg.inverseInPlace();\r\n return csg;\r\n }\r\n\r\n /**\r\n * Inverses the CSG in place\r\n */\r\n public inverseInPlace(): void {\r\n this._polygons.map((p) => {\r\n p.flip();\r\n });\r\n }\r\n\r\n /**\r\n * This is used to keep meshes transformations so they can be restored\r\n * when we build back a Babylon Mesh\r\n * NB : All CSG operations are performed in world coordinates\r\n * @param csg The CSG to copy the transform attributes from\r\n * @returns This CSG\r\n */\r\n public copyTransformAttributes(csg: CSG): CSG {\r\n this.matrix = csg.matrix;\r\n this.position = csg.position;\r\n this.rotation = csg.rotation;\r\n this.scaling = csg.scaling;\r\n this.rotationQuaternion = csg.rotationQuaternion;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Build vertex data from CSG\r\n * Coordinates here are in world space\r\n * @returns the final vertex data\r\n */\r\n public toVertexData(onBeforePolygonProcessing: Nullable<(polygon: Polygon) => void> = null, onAfterPolygonProcessing: Nullable<() => void> = null): VertexData {\r\n const matrix = this.matrix.clone();\r\n matrix.invert();\r\n\r\n const polygons = this._polygons;\r\n const vertices = [];\r\n const indices = [];\r\n const normals = [];\r\n let uvs: Nullable<number[]> = null;\r\n let vertColors: Nullable<number[]> = null;\r\n const vertex = Vector3.Zero();\r\n const normal = Vector3.Zero();\r\n const uv = Vector2.Zero();\r\n const vertColor = new Color4(0, 0, 0, 0);\r\n const polygonIndices = [0, 0, 0];\r\n const vertice_dict = {};\r\n let vertex_idx;\r\n\r\n for (let i = 0, il = polygons.length; i < il; i++) {\r\n const polygon = polygons[i];\r\n\r\n if (onBeforePolygonProcessing) {\r\n onBeforePolygonProcessing(polygon);\r\n }\r\n\r\n for (let j = 2, jl = polygon.vertices.length; j < jl; j++) {\r\n polygonIndices[0] = 0;\r\n polygonIndices[1] = j - 1;\r\n polygonIndices[2] = j;\r\n\r\n for (let k = 0; k < 3; k++) {\r\n vertex.copyFrom(polygon.vertices[polygonIndices[k]].pos);\r\n normal.copyFrom(polygon.vertices[polygonIndices[k]].normal);\r\n if (polygon.vertices[polygonIndices[k]].uv) {\r\n if (!uvs) {\r\n uvs = [];\r\n }\r\n uv.copyFrom(polygon.vertices[polygonIndices[k]].uv!);\r\n }\r\n\r\n if (polygon.vertices[polygonIndices[k]].vertColor) {\r\n if (!vertColors) {\r\n vertColors = [];\r\n }\r\n vertColor.copyFrom(polygon.vertices[polygonIndices[k]].vertColor!);\r\n }\r\n const localVertex = Vector3.TransformCoordinates(vertex, matrix);\r\n const localNormal = Vector3.TransformNormal(normal, matrix);\r\n\r\n vertex_idx = (<any>vertice_dict)[localVertex.x + \",\" + localVertex.y + \",\" + localVertex.z];\r\n\r\n let areUvsDifferent = false;\r\n\r\n if (uvs && !(uvs[vertex_idx * 2] === uv.x || uvs[vertex_idx * 2 + 1] === uv.y)) {\r\n areUvsDifferent = true;\r\n }\r\n\r\n let areColorsDifferent = false;\r\n\r\n if (\r\n vertColors &&\r\n !(\r\n vertColors[vertex_idx * 4] === vertColor.r ||\r\n vertColors[vertex_idx * 4 + 1] === vertColor.g ||\r\n vertColors[vertex_idx * 4 + 2] === vertColor.b ||\r\n vertColors[vertex_idx * 4 + 3] === vertColor.a\r\n )\r\n ) {\r\n areColorsDifferent = true;\r\n }\r\n\r\n // Check if 2 points can be merged\r\n if (\r\n !(\r\n typeof vertex_idx !== \"undefined\" &&\r\n normals[vertex_idx * 3] === localNormal.x &&\r\n normals[vertex_idx * 3 + 1] === localNormal.y &&\r\n normals[vertex_idx * 3 + 2] === localNormal.z\r\n ) ||\r\n areUvsDifferent ||\r\n areColorsDifferent\r\n ) {\r\n vertices.push(localVertex.x, localVertex.y, localVertex.z);\r\n if (uvs) {\r\n uvs.push(uv.x, uv.y);\r\n }\r\n normals.push(normal.x, normal.y, normal.z);\r\n if (vertColors) {\r\n vertColors.push(vertColor.r, vertColor.g, vertColor.b, vertColor.a);\r\n }\r\n vertex_idx = (<any>vertice_dict)[localVertex.x + \",\" + localVertex.y + \",\" + localVertex.z] = vertices.length / 3 - 1;\r\n }\r\n\r\n indices.push(vertex_idx);\r\n\r\n if (onAfterPolygonProcessing) {\r\n onAfterPolygonProcessing();\r\n }\r\n }\r\n }\r\n }\r\n\r\n const result = new VertexData();\r\n result.positions = vertices;\r\n result.normals = normals;\r\n if (uvs) {\r\n result.uvs = uvs;\r\n }\r\n if (vertColors) {\r\n result.colors = vertColors;\r\n }\r\n result.indices = indices;\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Build Raw mesh from CSG\r\n * Coordinates here are in world space\r\n * @param name The name of the mesh geometry\r\n * @param scene The Scene\r\n * @param keepSubMeshes Specifies if the submeshes should be kept\r\n * @returns A new Mesh\r\n */\r\n public buildMeshGeometry(name: string, scene?: Scene, keepSubMeshes?: boolean): Mesh {\r\n const mesh = new Mesh(name, scene);\r\n const polygons = this._polygons;\r\n let currentIndex = 0;\r\n const subMeshDict = {};\r\n let subMeshObj: {\r\n materialIndex: number;\r\n indexStart: number;\r\n indexEnd: number;\r\n };\r\n\r\n if (keepSubMeshes) {\r\n // Sort Polygons, since subMeshes are indices range\r\n polygons.sort((a, b) => {\r\n if (a.shared.meshId === b.shared.meshId) {\r\n return a.shared.subMeshId - b.shared.subMeshId;\r\n } else {\r\n return a.shared.meshId - b.shared.meshId;\r\n }\r\n });\r\n }\r\n\r\n const vertexData = this.toVertexData(\r\n (polygon) => {\r\n // Building SubMeshes\r\n if (!(<any>subMeshDict)[polygon.shared.meshId]) {\r\n (<any>subMeshDict)[polygon.shared.meshId] = {};\r\n }\r\n if (!(<any>subMeshDict)[polygon.shared.meshId][polygon.shared.subMeshId]) {\r\n (<any>subMeshDict)[polygon.shared.meshId][polygon.shared.subMeshId] = {\r\n indexStart: +Infinity,\r\n indexEnd: -Infinity,\r\n materialIndex: polygon.shared.materialIndex,\r\n };\r\n }\r\n subMeshObj = (<any>subMeshDict)[polygon.shared.meshId][polygon.shared.subMeshId];\r\n },\r\n () => {\r\n subMeshObj.indexStart = Math.min(currentIndex, subMeshObj.indexStart);\r\n subMeshObj.indexEnd = Math.max(currentIndex, subMeshObj.indexEnd);\r\n currentIndex++;\r\n }\r\n );\r\n\r\n vertexData.applyToMesh(mesh);\r\n\r\n if (keepSubMeshes) {\r\n // We offset the materialIndex by the previous number of materials in the CSG mixed meshes\r\n let materialIndexOffset = 0,\r\n materialMaxIndex;\r\n\r\n mesh.subMeshes = new Array<SubMesh>();\r\n\r\n for (const m in subMeshDict) {\r\n materialMaxIndex = -1;\r\n for (const sm in (<any>subMeshDict)[m]) {\r\n subMeshObj = (<any>subMeshDict)[m][sm];\r\n SubMesh.CreateFromIndices(\r\n subMeshObj.materialIndex + materialIndexOffset,\r\n subMeshObj.indexStart,\r\n subMeshObj.indexEnd - subMeshObj.indexStart + 1,\r\n <AbstractMesh>mesh\r\n );\r\n materialMaxIndex = Math.max(subMeshObj.materialIndex, materialMaxIndex);\r\n }\r\n materialIndexOffset += ++materialMaxIndex;\r\n }\r\n }\r\n\r\n return mesh;\r\n }\r\n\r\n /**\r\n * Build Mesh from CSG taking material and transforms into account\r\n * @param name The name of the Mesh\r\n * @param material The material of the Mesh\r\n * @param scene The Scene\r\n * @param keepSubMeshes Specifies if submeshes should be kept\r\n * @returns The new Mesh\r\n */\r\n public toMesh(name: string, material: Nullable<Material> = null, scene?: Scene, keepSubMeshes?: boolean): Mesh {\r\n const mesh = this.buildMeshGeometry(name, scene, keepSubMeshes);\r\n\r\n mesh.material = material;\r\n\r\n mesh.position.copyFrom(this.position);\r\n mesh.rotation.copyFrom(this.rotation);\r\n if (this.rotationQuaternion) {\r\n mesh.rotationQuaternion = this.rotationQuaternion.clone();\r\n }\r\n mesh.scaling.copyFrom(this.scaling);\r\n mesh.computeWorldMatrix(true);\r\n\r\n return mesh;\r\n }\r\n}\r\n"]}
@@ -1,3 +1,4 @@
1
+ import type { BaseTexture } from "../Materials/Textures/baseTexture.js";
1
2
  import type { InternalTexture } from "../Materials/Textures/internalTexture";
2
3
  import { Texture } from "../Materials/Textures/texture";
3
4
  import type { Scene } from "../scene";
@@ -33,6 +34,17 @@ export declare function ToHalfFloat(value: number): number;
33
34
  * @returns converted half float
34
35
  */
35
36
  export declare function FromHalfFloat(value: number): number;
37
+ /**
38
+ * Gets the data of the specified texture by rendering it to an intermediate RGBA texture and retrieving the bytes from it.
39
+ * This is convienent to get 8-bit RGBA values for a texture in a GPU compressed format.
40
+ * @param texture the source texture
41
+ * @param width the width of the result, which does not have to match the source texture width
42
+ * @param height the height of the result, which does not have to match the source texture height
43
+ * @param face if the texture has multiple faces, the face index to use for the source
44
+ * @param lod if the texture has multiple LODs, the lod index to use for the source
45
+ * @returns the 8-bit texture data
46
+ */
47
+ export declare function GetTextureDataAsync(texture: BaseTexture, width: number, height: number, face?: number, lod?: number): Promise<Uint8Array>;
36
48
  /**
37
49
  * Class used to host texture specific utilities
38
50
  */
@@ -69,4 +81,16 @@ export declare const TextureTools: {
69
81
  * @returns converted half float
70
82
  */
71
83
  FromHalfFloat: typeof FromHalfFloat;
84
+ /**
85
+ * Gets the data of the specified texture by rendering it to an intermediate RGBA texture and retrieving the bytes from it.
86
+ * This is convienent to get 8-bit RGBA values for a texture in a GPU compressed format.
87
+ * @param texture the source texture
88
+ * @param width the width of the result, which does not have to match the source texture width
89
+ * @param height the height of the result, which does not have to match the source texture height
90
+ * @param face if the texture has multiple faces, the face index to use for the source
91
+ * @param channels a filter for which of the RGBA channels to return in the result
92
+ * @param lod if the texture has multiple LODs, the lod index to use for the source
93
+ * @returns the 8-bit texture data
94
+ */
95
+ GetTextureDataAsync: typeof GetTextureDataAsync;
72
96
  };
@@ -165,6 +165,80 @@ export function FromHalfFloat(value) {
165
165
  }
166
166
  return (s ? -1 : 1) * Math.pow(2, e - 15) * (1 + f / Math.pow(2, 10));
167
167
  }
168
+ const ProcessAsync = async (texture, width, height, face, lod) => {
169
+ const scene = texture.getScene();
170
+ const engine = scene.getEngine();
171
+ let lodPostProcess;
172
+ if (!texture.isCube) {
173
+ lodPostProcess = new PostProcess("lod", "lod", ["lod", "gamma"], null, 1.0, null, Texture.NEAREST_NEAREST_MIPNEAREST, engine);
174
+ }
175
+ else {
176
+ const faceDefines = ["#define POSITIVEX", "#define NEGATIVEX", "#define POSITIVEY", "#define NEGATIVEY", "#define POSITIVEZ", "#define NEGATIVEZ"];
177
+ lodPostProcess = new PostProcess("lodCube", "lodCube", ["lod", "gamma"], null, 1.0, null, Texture.NEAREST_NEAREST_MIPNEAREST, engine, false, faceDefines[face]);
178
+ }
179
+ await new Promise((resolve) => {
180
+ lodPostProcess.getEffect().executeWhenCompiled(() => {
181
+ resolve(0);
182
+ });
183
+ });
184
+ const rtt = new RenderTargetTexture("temp", { width: width, height: height }, scene, false);
185
+ lodPostProcess.onApply = function (effect) {
186
+ effect.setTexture("textureSampler", texture);
187
+ effect.setFloat("lod", lod);
188
+ effect.setBool("gamma", texture.gammaSpace);
189
+ };
190
+ const internalTexture = texture.getInternalTexture();
191
+ try {
192
+ if (rtt.renderTarget && internalTexture) {
193
+ const samplingMode = internalTexture.samplingMode;
194
+ if (lod !== 0) {
195
+ texture.updateSamplingMode(Texture.NEAREST_NEAREST_MIPNEAREST);
196
+ }
197
+ else {
198
+ texture.updateSamplingMode(Texture.NEAREST_NEAREST);
199
+ }
200
+ scene.postProcessManager.directRender([lodPostProcess], rtt.renderTarget, true);
201
+ texture.updateSamplingMode(samplingMode);
202
+ //Reading datas from WebGL
203
+ const bufferView = await engine.readPixels(0, 0, width, height);
204
+ const data = new Uint8Array(bufferView.buffer, 0, bufferView.byteLength);
205
+ // Unbind
206
+ engine.unBindFramebuffer(rtt.renderTarget);
207
+ return data;
208
+ }
209
+ else {
210
+ throw Error("Render to texture failed.");
211
+ }
212
+ }
213
+ finally {
214
+ rtt.dispose();
215
+ lodPostProcess.dispose();
216
+ }
217
+ };
218
+ /**
219
+ * Gets the data of the specified texture by rendering it to an intermediate RGBA texture and retrieving the bytes from it.
220
+ * This is convienent to get 8-bit RGBA values for a texture in a GPU compressed format.
221
+ * @param texture the source texture
222
+ * @param width the width of the result, which does not have to match the source texture width
223
+ * @param height the height of the result, which does not have to match the source texture height
224
+ * @param face if the texture has multiple faces, the face index to use for the source
225
+ * @param lod if the texture has multiple LODs, the lod index to use for the source
226
+ * @returns the 8-bit texture data
227
+ */
228
+ export async function GetTextureDataAsync(texture, width, height, face = 0, lod = 0) {
229
+ if (!texture.isReady() && texture._texture) {
230
+ await new Promise((resolve, reject) => {
231
+ if (texture._texture === null) {
232
+ reject(0);
233
+ return;
234
+ }
235
+ texture._texture.onLoadedObservable.addOnce(() => {
236
+ resolve(0);
237
+ });
238
+ });
239
+ }
240
+ return await ProcessAsync(texture, width, height, face, lod);
241
+ }
168
242
  /**
169
243
  * Class used to host texture specific utilities
170
244
  */
@@ -201,5 +275,17 @@ export const TextureTools = {
201
275
  * @returns converted half float
202
276
  */
203
277
  FromHalfFloat,
278
+ /**
279
+ * Gets the data of the specified texture by rendering it to an intermediate RGBA texture and retrieving the bytes from it.
280
+ * This is convienent to get 8-bit RGBA values for a texture in a GPU compressed format.
281
+ * @param texture the source texture
282
+ * @param width the width of the result, which does not have to match the source texture width
283
+ * @param height the height of the result, which does not have to match the source texture height
284
+ * @param face if the texture has multiple faces, the face index to use for the source
285
+ * @param channels a filter for which of the RGBA channels to return in the result
286
+ * @param lod if the texture has multiple LODs, the lod index to use for the source
287
+ * @returns the 8-bit texture data
288
+ */
289
+ GetTextureDataAsync,
204
290
  };
205
291
  //# sourceMappingURL=textureTools.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"textureTools.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/textureTools.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAG3D;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAgB,EAAE,KAAa,EAAE,MAAc,EAAE,kBAA2B,IAAI;IAC9G,MAAM,KAAK,GAAU,OAAO,CAAC,QAAQ,EAAE,CAAC;IACxC,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;IAEjC,MAAM,GAAG,GAAG,IAAI,mBAAmB,CAC/B,SAAS,GAAG,OAAO,CAAC,IAAI,EACxB,EAAE,KAAK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AAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC;KAC5C;IAED,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAC1E,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IACxB;;;;;;;OAOG;IACH,iBAAiB;IAEjB;;;;;;;;;OASG;IACH,gBAAgB;IAChB;;;;OAIG;IACH,WAAW;IAEX;;;;OAIG;IACH,aAAa;CAChB,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { InternalTexture } from \"../Materials/Textures/internalTexture\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport { PassPostProcess } from \"../PostProcesses/passPostProcess\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { Scene } from \"../scene\";\r\nimport { PostProcess } from \"../PostProcesses/postProcess\";\r\nimport type { Engine } from \"../Engines/engine\";\r\n\r\n/**\r\n * Uses the GPU to create a copy texture rescaled at a given size\r\n * @param texture Texture to copy from\r\n * @param width defines the desired width\r\n * @param height defines the desired height\r\n * @param useBilinearMode defines if bilinear mode has to be used\r\n * @returns the generated texture\r\n */\r\nexport function CreateResizedCopy(texture: Texture, width: number, height: number, useBilinearMode: boolean = true): Texture {\r\n const scene = <Scene>texture.getScene();\r\n const engine = scene.getEngine();\r\n\r\n const rtt = new RenderTargetTexture(\r\n \"resized\" + texture.name,\r\n { width: width, height: height },\r\n scene,\r\n !texture.noMipmap,\r\n true,\r\n (<InternalTexture>texture._texture).type,\r\n false,\r\n texture.samplingMode,\r\n false\r\n );\r\n\r\n rtt.wrapU = texture.wrapU;\r\n rtt.wrapV = texture.wrapV;\r\n rtt.uOffset = texture.uOffset;\r\n rtt.vOffset = texture.vOffset;\r\n rtt.uScale = texture.uScale;\r\n rtt.vScale = texture.vScale;\r\n rtt.uAng = texture.uAng;\r\n rtt.vAng = texture.vAng;\r\n rtt.wAng = texture.wAng;\r\n rtt.coordinatesIndex = texture.coordinatesIndex;\r\n rtt.level = texture.level;\r\n rtt.anisotropicFilteringLevel = texture.anisotropicFilteringLevel;\r\n (<InternalTexture>rtt._texture).isReady = false;\r\n\r\n texture.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n texture.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n\r\n const passPostProcess = new PassPostProcess(\r\n \"pass\",\r\n 1,\r\n null,\r\n useBilinearMode ? Texture.BILINEAR_SAMPLINGMODE : Texture.NEAREST_SAMPLINGMODE,\r\n engine,\r\n false,\r\n Constants.TEXTURETYPE_UNSIGNED_INT\r\n );\r\n passPostProcess.externalTextureSamplerBinding = true;\r\n passPostProcess.getEffect().executeWhenCompiled(() => {\r\n passPostProcess.onApply = function (effect) {\r\n effect.setTexture(\"textureSampler\", texture);\r\n };\r\n\r\n const internalTexture = rtt.renderTarget;\r\n\r\n if (internalTexture) {\r\n scene.postProcessManager.directRender([passPostProcess], internalTexture);\r\n\r\n engine.unBindFramebuffer(internalTexture);\r\n rtt.disposeFramebufferObjects();\r\n passPostProcess.dispose();\r\n\r\n rtt.getInternalTexture()!.isReady = true;\r\n }\r\n });\r\n\r\n return rtt;\r\n}\r\n\r\n/**\r\n * Apply a post process to a texture\r\n * @param postProcessName name of the fragment post process\r\n * @param internalTexture the texture to encode\r\n * @param scene the scene hosting the texture\r\n * @param type type of the output texture. If not provided, use the one from internalTexture\r\n * @param samplingMode sampling mode to use to sample the source texture. If not provided, use the one from internalTexture\r\n * @param format format of the output texture. If not provided, use the one from internalTexture\r\n * @returns a promise with the internalTexture having its texture replaced by the result of the processing\r\n */\r\nexport function ApplyPostProcess(\r\n postProcessName: string,\r\n internalTexture: InternalTexture,\r\n scene: Scene,\r\n type?: number,\r\n samplingMode?: number,\r\n format?: number,\r\n width?: number,\r\n height?: number\r\n): Promise<InternalTexture> {\r\n // Gets everything ready.\r\n const engine = internalTexture.getEngine() as Engine;\r\n\r\n internalTexture.isReady = false;\r\n\r\n samplingMode = samplingMode ?? internalTexture.samplingMode;\r\n type = type ?? internalTexture.type;\r\n format = format ?? internalTexture.format;\r\n width = width ?? internalTexture.width;\r\n height = height ?? internalTexture.height;\r\n\r\n if (type === -1) {\r\n type = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n }\r\n\r\n return new Promise((resolve) => {\r\n // Create the post process\r\n const postProcess = new PostProcess(\"postprocess\", postProcessName, null, null, 1, null, samplingMode, engine, false, undefined, type, undefined, null, false, format);\r\n postProcess.externalTextureSamplerBinding = true;\r\n\r\n // Hold the output of the decoding.\r\n const encodedTexture = engine.createRenderTargetTexture(\r\n { width: width as number, height: height as number },\r\n {\r\n generateDepthBuffer: false,\r\n generateMipMaps: false,\r\n generateStencilBuffer: false,\r\n samplingMode,\r\n type,\r\n format,\r\n }\r\n );\r\n\r\n postProcess.getEffect().executeWhenCompiled(() => {\r\n // PP Render Pass\r\n postProcess.onApply = (effect) => {\r\n effect._bindTexture(\"textureSampler\", internalTexture);\r\n effect.setFloat2(\"scale\", 1, 1);\r\n };\r\n scene.postProcessManager.directRender([postProcess!], encodedTexture, true);\r\n\r\n // Cleanup\r\n engine.restoreDefaultFramebuffer();\r\n engine._releaseTexture(internalTexture);\r\n if (postProcess) {\r\n postProcess.dispose();\r\n }\r\n\r\n // Internal Swap\r\n encodedTexture._swapAndDie(internalTexture);\r\n\r\n // Ready to get rolling again.\r\n internalTexture.type = type!;\r\n internalTexture.format = Constants.TEXTUREFORMAT_RGBA;\r\n internalTexture.isReady = true;\r\n\r\n resolve(internalTexture);\r\n });\r\n });\r\n}\r\n\r\n// ref: http://stackoverflow.com/questions/32633585/how-do-you-convert-to-half-floats-in-javascript\r\nlet floatView: Float32Array;\r\nlet int32View: Int32Array;\r\n/**\r\n * Converts a number to half float\r\n * @param value number to convert\r\n * @returns converted number\r\n */\r\nexport function ToHalfFloat(value: number): number {\r\n if (!floatView) {\r\n floatView = new Float32Array(1);\r\n int32View = new Int32Array(floatView.buffer);\r\n }\r\n\r\n floatView[0] = value;\r\n const x = int32View[0];\r\n\r\n let bits = (x >> 16) & 0x8000; /* Get the sign */\r\n let m = (x >> 12) & 0x07ff; /* Keep one extra bit for rounding */\r\n const e = (x >> 23) & 0xff; /* Using int is faster here */\r\n\r\n /* If zero, or denormal, or exponent underflows too much for a denormal\r\n * half, return signed zero. */\r\n if (e < 103) {\r\n return bits;\r\n }\r\n\r\n /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */\r\n if (e > 142) {\r\n bits |= 0x7c00;\r\n /* If exponent was 0xff and one mantissa bit was set, it means NaN,\r\n * not Inf, so make sure we set one mantissa bit too. */\r\n bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;\r\n return bits;\r\n }\r\n\r\n /* If exponent underflows but not too much, return a denormal */\r\n if (e < 113) {\r\n m |= 0x0800;\r\n /* Extra rounding may overflow and set mantissa to 0 and exponent\r\n * to 1, which is OK. */\r\n bits |= (m >> (114 - e)) + ((m >> (113 - e)) & 1);\r\n return bits;\r\n }\r\n\r\n bits |= ((e - 112) << 10) | (m >> 1);\r\n bits += m & 1;\r\n return bits;\r\n}\r\n\r\n/**\r\n * Converts a half float to a number\r\n * @param value half float to convert\r\n * @returns converted half float\r\n */\r\nexport function FromHalfFloat(value: number): number {\r\n const s = (value & 0x8000) >> 15;\r\n const e = (value & 0x7c00) >> 10;\r\n const f = value & 0x03ff;\r\n\r\n if (e === 0) {\r\n return (s ? -1 : 1) * Math.pow(2, -14) * (f / Math.pow(2, 10));\r\n } else if (e == 0x1f) {\r\n return f ? NaN : (s ? -1 : 1) * Infinity;\r\n }\r\n\r\n return (s ? -1 : 1) * Math.pow(2, e - 15) * (1 + f / Math.pow(2, 10));\r\n}\r\n\r\n/**\r\n * Class used to host texture specific utilities\r\n */\r\nexport const TextureTools = {\r\n /**\r\n * Uses the GPU to create a copy texture rescaled at a given size\r\n * @param texture Texture to copy from\r\n * @param width defines the desired width\r\n * @param height defines the desired height\r\n * @param useBilinearMode defines if bilinear mode has to be used\r\n * @returns the generated texture\r\n */\r\n CreateResizedCopy,\r\n\r\n /**\r\n * Apply a post process to a texture\r\n * @param postProcessName name of the fragment post process\r\n * @param internalTexture the texture to encode\r\n * @param scene the scene hosting the texture\r\n * @param type type of the output texture. If not provided, use the one from internalTexture\r\n * @param samplingMode sampling mode to use to sample the source texture. If not provided, use the one from internalTexture\r\n * @param format format of the output texture. If not provided, use the one from internalTexture\r\n * @returns a promise with the internalTexture having its texture replaced by the result of the processing\r\n */\r\n ApplyPostProcess,\r\n /**\r\n * Converts a number to half float\r\n * @param value number to convert\r\n * @returns converted number\r\n */\r\n ToHalfFloat,\r\n\r\n /**\r\n * Converts a half float to a number\r\n * @param value half float to convert\r\n * @returns converted half float\r\n */\r\n FromHalfFloat,\r\n};\r\n"]}
1
+ {"version":3,"file":"textureTools.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/textureTools.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAG3D;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAgB,EAAE,KAAa,EAAE,MAAc,EAAE,kBAA2B,IAAI;IAC9G,MAAM,KAAK,GAAU,OAAO,CAAC,QAAQ,EAAE,CAAC;I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AIG;IACH,WAAW;IAEX;;;;OAIG;IACH,aAAa;IAEb;;;;;;;;;;OAUG;IACH,mBAAmB;CACtB,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { InternalTexture } from \"../Materials/Textures/internalTexture\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport { PassPostProcess } from \"../PostProcesses/passPostProcess\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { Scene } from \"../scene\";\r\nimport { PostProcess } from \"../PostProcesses/postProcess\";\r\nimport type { Engine } from \"../Engines/engine\";\r\n\r\n/**\r\n * Uses the GPU to create a copy texture rescaled at a given size\r\n * @param texture Texture to copy from\r\n * @param width defines the desired width\r\n * @param height defines the desired height\r\n * @param useBilinearMode defines if bilinear mode has to be used\r\n * @returns the generated texture\r\n */\r\nexport function CreateResizedCopy(texture: Texture, width: number, height: number, useBilinearMode: boolean = true): Texture {\r\n const scene = <Scene>texture.getScene();\r\n const engine = scene.getEngine();\r\n\r\n const rtt = new RenderTargetTexture(\r\n \"resized\" + texture.name,\r\n { width: width, height: height },\r\n scene,\r\n !texture.noMipmap,\r\n true,\r\n (<InternalTexture>texture._texture).type,\r\n false,\r\n texture.samplingMode,\r\n false\r\n );\r\n\r\n rtt.wrapU = texture.wrapU;\r\n rtt.wrapV = texture.wrapV;\r\n rtt.uOffset = texture.uOffset;\r\n rtt.vOffset = texture.vOffset;\r\n rtt.uScale = texture.uScale;\r\n rtt.vScale = texture.vScale;\r\n rtt.uAng = texture.uAng;\r\n rtt.vAng = texture.vAng;\r\n rtt.wAng = texture.wAng;\r\n rtt.coordinatesIndex = texture.coordinatesIndex;\r\n rtt.level = texture.level;\r\n rtt.anisotropicFilteringLevel = texture.anisotropicFilteringLevel;\r\n (<InternalTexture>rtt._texture).isReady = false;\r\n\r\n texture.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n texture.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n\r\n const passPostProcess = new PassPostProcess(\r\n \"pass\",\r\n 1,\r\n null,\r\n useBilinearMode ? Texture.BILINEAR_SAMPLINGMODE : Texture.NEAREST_SAMPLINGMODE,\r\n engine,\r\n false,\r\n Constants.TEXTURETYPE_UNSIGNED_INT\r\n );\r\n passPostProcess.externalTextureSamplerBinding = true;\r\n passPostProcess.getEffect().executeWhenCompiled(() => {\r\n passPostProcess.onApply = function (effect) {\r\n effect.setTexture(\"textureSampler\", texture);\r\n };\r\n\r\n const internalTexture = rtt.renderTarget;\r\n\r\n if (internalTexture) {\r\n scene.postProcessManager.directRender([passPostProcess], internalTexture);\r\n\r\n engine.unBindFramebuffer(internalTexture);\r\n rtt.disposeFramebufferObjects();\r\n passPostProcess.dispose();\r\n\r\n rtt.getInternalTexture()!.isReady = true;\r\n }\r\n });\r\n\r\n return rtt;\r\n}\r\n\r\n/**\r\n * Apply a post process to a texture\r\n * @param postProcessName name of the fragment post process\r\n * @param internalTexture the texture to encode\r\n * @param scene the scene hosting the texture\r\n * @param type type of the output texture. If not provided, use the one from internalTexture\r\n * @param samplingMode sampling mode to use to sample the source texture. If not provided, use the one from internalTexture\r\n * @param format format of the output texture. If not provided, use the one from internalTexture\r\n * @returns a promise with the internalTexture having its texture replaced by the result of the processing\r\n */\r\nexport function ApplyPostProcess(\r\n postProcessName: string,\r\n internalTexture: InternalTexture,\r\n scene: Scene,\r\n type?: number,\r\n samplingMode?: number,\r\n format?: number,\r\n width?: number,\r\n height?: number\r\n): Promise<InternalTexture> {\r\n // Gets everything ready.\r\n const engine = internalTexture.getEngine() as Engine;\r\n\r\n internalTexture.isReady = false;\r\n\r\n samplingMode = samplingMode ?? internalTexture.samplingMode;\r\n type = type ?? internalTexture.type;\r\n format = format ?? internalTexture.format;\r\n width = width ?? internalTexture.width;\r\n height = height ?? internalTexture.height;\r\n\r\n if (type === -1) {\r\n type = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n }\r\n\r\n return new Promise((resolve) => {\r\n // Create the post process\r\n const postProcess = new PostProcess(\"postprocess\", postProcessName, null, null, 1, null, samplingMode, engine, false, undefined, type, undefined, null, false, format);\r\n postProcess.externalTextureSamplerBinding = true;\r\n\r\n // Hold the output of the decoding.\r\n const encodedTexture = engine.createRenderTargetTexture(\r\n { width: width as number, height: height as number },\r\n {\r\n generateDepthBuffer: false,\r\n generateMipMaps: false,\r\n generateStencilBuffer: false,\r\n samplingMode,\r\n type,\r\n format,\r\n }\r\n );\r\n\r\n postProcess.getEffect().executeWhenCompiled(() => {\r\n // PP Render Pass\r\n postProcess.onApply = (effect) => {\r\n effect._bindTexture(\"textureSampler\", internalTexture);\r\n effect.setFloat2(\"scale\", 1, 1);\r\n };\r\n scene.postProcessManager.directRender([postProcess!], encodedTexture, true);\r\n\r\n // Cleanup\r\n engine.restoreDefaultFramebuffer();\r\n engine._releaseTexture(internalTexture);\r\n if (postProcess) {\r\n postProcess.dispose();\r\n }\r\n\r\n // Internal Swap\r\n encodedTexture._swapAndDie(internalTexture);\r\n\r\n // Ready to get rolling again.\r\n internalTexture.type = type!;\r\n internalTexture.format = Constants.TEXTUREFORMAT_RGBA;\r\n internalTexture.isReady = true;\r\n\r\n resolve(internalTexture);\r\n });\r\n });\r\n}\r\n\r\n// ref: http://stackoverflow.com/questions/32633585/how-do-you-convert-to-half-floats-in-javascript\r\nlet floatView: Float32Array;\r\nlet int32View: Int32Array;\r\n/**\r\n * Converts a number to half float\r\n * @param value number to convert\r\n * @returns converted number\r\n */\r\nexport function ToHalfFloat(value: number): number {\r\n if (!floatView) {\r\n floatView = new Float32Array(1);\r\n int32View = new Int32Array(floatView.buffer);\r\n }\r\n\r\n floatView[0] = value;\r\n const x = int32View[0];\r\n\r\n let bits = (x >> 16) & 0x8000; /* Get the sign */\r\n let m = (x >> 12) & 0x07ff; /* Keep one extra bit for rounding */\r\n const e = (x >> 23) & 0xff; /* Using int is faster here */\r\n\r\n /* If zero, or denormal, or exponent underflows too much for a denormal\r\n * half, return signed zero. */\r\n if (e < 103) {\r\n return bits;\r\n }\r\n\r\n /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */\r\n if (e > 142) {\r\n bits |= 0x7c00;\r\n /* If exponent was 0xff and one mantissa bit was set, it means NaN,\r\n * not Inf, so make sure we set one mantissa bit too. */\r\n bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;\r\n return bits;\r\n }\r\n\r\n /* If exponent underflows but not too much, return a denormal */\r\n if (e < 113) {\r\n m |= 0x0800;\r\n /* Extra rounding may overflow and set mantissa to 0 and exponent\r\n * to 1, which is OK. */\r\n bits |= (m >> (114 - e)) + ((m >> (113 - e)) & 1);\r\n return bits;\r\n }\r\n\r\n bits |= ((e - 112) << 10) | (m >> 1);\r\n bits += m & 1;\r\n return bits;\r\n}\r\n\r\n/**\r\n * Converts a half float to a number\r\n * @param value half float to convert\r\n * @returns converted half float\r\n */\r\nexport function FromHalfFloat(value: number): number {\r\n const s = (value & 0x8000) >> 15;\r\n const e = (value & 0x7c00) >> 10;\r\n const f = value & 0x03ff;\r\n\r\n if (e === 0) {\r\n return (s ? -1 : 1) * Math.pow(2, -14) * (f / Math.pow(2, 10));\r\n } else if (e == 0x1f) {\r\n return f ? NaN : (s ? -1 : 1) * Infinity;\r\n }\r\n\r\n return (s ? -1 : 1) * Math.pow(2, e - 15) * (1 + f / Math.pow(2, 10));\r\n}\r\n\r\nconst ProcessAsync = async (texture: BaseTexture, width: number, height: number, face: number, lod: number): Promise<Uint8Array> => {\r\n const scene = texture.getScene()!;\r\n const engine = scene.getEngine();\r\n\r\n let lodPostProcess: PostProcess;\r\n\r\n if (!texture.isCube) {\r\n lodPostProcess = new PostProcess(\"lod\", \"lod\", [\"lod\", \"gamma\"], null, 1.0, null, Texture.NEAREST_NEAREST_MIPNEAREST, engine);\r\n } else {\r\n const faceDefines = [\"#define POSITIVEX\", \"#define NEGATIVEX\", \"#define POSITIVEY\", \"#define NEGATIVEY\", \"#define POSITIVEZ\", \"#define NEGATIVEZ\"];\r\n lodPostProcess = new PostProcess(\"lodCube\", \"lodCube\", [\"lod\", \"gamma\"], null, 1.0, null, Texture.NEAREST_NEAREST_MIPNEAREST, engine, false, faceDefines[face]);\r\n }\r\n\r\n await new Promise((resolve) => {\r\n lodPostProcess.getEffect().executeWhenCompiled(() => {\r\n resolve(0);\r\n });\r\n });\r\n\r\n const rtt = new RenderTargetTexture(\"temp\", { width: width, height: height }, scene, false);\r\n\r\n lodPostProcess.onApply = function (effect) {\r\n effect.setTexture(\"textureSampler\", texture);\r\n effect.setFloat(\"lod\", lod);\r\n effect.setBool(\"gamma\", texture.gammaSpace);\r\n };\r\n\r\n const internalTexture = texture.getInternalTexture();\r\n\r\n try {\r\n if (rtt.renderTarget && internalTexture) {\r\n const samplingMode = internalTexture.samplingMode;\r\n if (lod !== 0) {\r\n texture.updateSamplingMode(Texture.NEAREST_NEAREST_MIPNEAREST);\r\n } else {\r\n texture.updateSamplingMode(Texture.NEAREST_NEAREST);\r\n }\r\n\r\n scene.postProcessManager.directRender([lodPostProcess], rtt.renderTarget, true);\r\n texture.updateSamplingMode(samplingMode);\r\n\r\n //Reading datas from WebGL\r\n const bufferView = await engine.readPixels(0, 0, width, height);\r\n const data = new Uint8Array(bufferView.buffer, 0, bufferView.byteLength);\r\n\r\n // Unbind\r\n engine.unBindFramebuffer(rtt.renderTarget);\r\n\r\n return data;\r\n } else {\r\n throw Error(\"Render to texture failed.\");\r\n }\r\n } finally {\r\n rtt.dispose();\r\n lodPostProcess.dispose();\r\n }\r\n};\r\n\r\n/**\r\n * Gets the data of the specified texture by rendering it to an intermediate RGBA texture and retrieving the bytes from it.\r\n * This is convienent to get 8-bit RGBA values for a texture in a GPU compressed format.\r\n * @param texture the source texture\r\n * @param width the width of the result, which does not have to match the source texture width\r\n * @param height the height of the result, which does not have to match the source texture height\r\n * @param face if the texture has multiple faces, the face index to use for the source\r\n * @param lod if the texture has multiple LODs, the lod index to use for the source\r\n * @returns the 8-bit texture data\r\n */\r\nexport async function GetTextureDataAsync(texture: BaseTexture, width: number, height: number, face: number = 0, lod: number = 0): Promise<Uint8Array> {\r\n if (!texture.isReady() && texture._texture) {\r\n await new Promise((resolve, reject) => {\r\n if (texture._texture === null) {\r\n reject(0);\r\n return;\r\n }\r\n texture._texture.onLoadedObservable.addOnce(() => {\r\n resolve(0);\r\n });\r\n });\r\n }\r\n return await ProcessAsync(texture, width, height, face, lod);\r\n}\r\n\r\n/**\r\n * Class used to host texture specific utilities\r\n */\r\nexport const TextureTools = {\r\n /**\r\n * Uses the GPU to create a copy texture rescaled at a given size\r\n * @param texture Texture to copy from\r\n * @param width defines the desired width\r\n * @param height defines the desired height\r\n * @param useBilinearMode defines if bilinear mode has to be used\r\n * @returns the generated texture\r\n */\r\n CreateResizedCopy,\r\n\r\n /**\r\n * Apply a post process to a texture\r\n * @param postProcessName name of the fragment post process\r\n * @param internalTexture the texture to encode\r\n * @param scene the scene hosting the texture\r\n * @param type type of the output texture. If not provided, use the one from internalTexture\r\n * @param samplingMode sampling mode to use to sample the source texture. If not provided, use the one from internalTexture\r\n * @param format format of the output texture. If not provided, use the one from internalTexture\r\n * @returns a promise with the internalTexture having its texture replaced by the result of the processing\r\n */\r\n ApplyPostProcess,\r\n /**\r\n * Converts a number to half float\r\n * @param value number to convert\r\n * @returns converted number\r\n */\r\n ToHalfFloat,\r\n\r\n /**\r\n * Converts a half float to a number\r\n * @param value half float to convert\r\n * @returns converted half float\r\n */\r\n FromHalfFloat,\r\n\r\n /**\r\n * Gets the data of the specified texture by rendering it to an intermediate RGBA texture and retrieving the bytes from it.\r\n * This is convienent to get 8-bit RGBA values for a texture in a GPU compressed format.\r\n * @param texture the source texture\r\n * @param width the width of the result, which does not have to match the source texture width\r\n * @param height the height of the result, which does not have to match the source texture height\r\n * @param face if the texture has multiple faces, the face index to use for the source\r\n * @param channels a filter for which of the RGBA channels to return in the result\r\n * @param lod if the texture has multiple LODs, the lod index to use for the source\r\n * @returns the 8-bit texture data\r\n */\r\n GetTextureDataAsync,\r\n};\r\n"]}
@@ -339,6 +339,9 @@ export class DepthPeelingRenderer {
339
339
  !this._updateTextures()) {
340
340
  return this._excludedSubMeshes;
341
341
  }
342
+ if (this._scene.activeCamera) {
343
+ this._engine.setViewport(this._scene.activeCamera.viewport);
344
+ }
342
345
  for (let i = 0; i < transparentSubMeshes.length; i++) {
343
346
  const subMesh = transparentSubMeshes.data[i];
344
347
  const material = subMesh.getMaterial();
@@ -405,6 +408,9 @@ export class DepthPeelingRenderer {
405
408
  if (this._useRenderPasses) {
406
409
  this._engine.currentRenderPassId = this._renderPassIds[i + 1];
407
410
  }
411
+ if (this._scene.activeCamera) {
412
+ this._engine.setViewport(this._scene.activeCamera.viewport);
413
+ }
408
414
  // Clears
409
415
  this._engine.bindFramebuffer(this._depthMrts[writeId].renderTarget);
410
416
  this._engine.bindAttachments(this._layoutCache[0]);