@babylonjs/core 5.44.0 → 5.45.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 (61) hide show
  1. package/Audio/sound.d.ts +0 -1
  2. package/Audio/sound.js +10 -10
  3. package/Audio/sound.js.map +1 -1
  4. package/Culling/ray.js +8 -2
  5. package/Culling/ray.js.map +1 -1
  6. package/Engines/WebGPU/Extensions/engine.renderTarget.js +1 -1
  7. package/Engines/WebGPU/Extensions/engine.renderTarget.js.map +1 -1
  8. package/Engines/engine.js +11 -2
  9. package/Engines/engine.js.map +1 -1
  10. package/Engines/thinEngine.js +3 -3
  11. package/Engines/thinEngine.js.map +1 -1
  12. package/Loading/Plugins/babylonFileLoader.js +3 -0
  13. package/Loading/Plugins/babylonFileLoader.js.map +1 -1
  14. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.d.ts +7 -0
  15. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js +30 -1
  16. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js.map +1 -1
  17. package/Materials/Textures/index.d.ts +1 -0
  18. package/Materials/Textures/index.js +1 -0
  19. package/Materials/Textures/index.js.map +1 -1
  20. package/Materials/Textures/ktx2decoderTypes.d.ts +215 -0
  21. package/Materials/Textures/ktx2decoderTypes.js +35 -0
  22. package/Materials/Textures/ktx2decoderTypes.js.map +1 -0
  23. package/Materials/Textures/texture.d.ts +3 -3
  24. package/Materials/Textures/texture.js +2 -2
  25. package/Materials/Textures/texture.js.map +1 -1
  26. package/Materials/clipPlaneMaterialHelper.js +22 -19
  27. package/Materials/clipPlaneMaterialHelper.js.map +1 -1
  28. package/Maths/math.vector.js +155 -120
  29. package/Maths/math.vector.js.map +1 -1
  30. package/Meshes/mesh.js +9 -0
  31. package/Meshes/mesh.js.map +1 -1
  32. package/Meshes/transformNode.d.ts +9 -1
  33. package/Meshes/transformNode.js +22 -7
  34. package/Meshes/transformNode.js.map +1 -1
  35. package/Misc/khronosTextureContainer2.d.ts +68 -2
  36. package/Misc/khronosTextureContainer2.js +147 -1
  37. package/Misc/khronosTextureContainer2.js.map +1 -1
  38. package/Morph/morphTargetManager.d.ts +2 -0
  39. package/Morph/morphTargetManager.js +8 -0
  40. package/Morph/morphTargetManager.js.map +1 -1
  41. package/Physics/v2/IPhysicsEnginePlugin.d.ts +6 -0
  42. package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
  43. package/Physics/v2/physicsAggregate.d.ts +21 -19
  44. package/Physics/v2/physicsAggregate.js +18 -4
  45. package/Physics/v2/physicsAggregate.js.map +1 -1
  46. package/Physics/v2/physicsBody.d.ts +15 -0
  47. package/Physics/v2/physicsBody.js +17 -0
  48. package/Physics/v2/physicsBody.js.map +1 -1
  49. package/Physics/v2/physicsShape.d.ts +30 -44
  50. package/Physics/v2/physicsShape.js +30 -44
  51. package/Physics/v2/physicsShape.js.map +1 -1
  52. package/Shaders/ShadersInclude/bumpFragment.js +1 -0
  53. package/Shaders/ShadersInclude/bumpFragment.js.map +1 -1
  54. package/Shaders/ShadersInclude/bumpFragmentMainFunctions.js +1 -1
  55. package/Shaders/ShadersInclude/bumpFragmentMainFunctions.js.map +1 -1
  56. package/Shaders/sprites.fragment.js +1 -1
  57. package/Shaders/sprites.fragment.js.map +1 -1
  58. package/assetContainer.d.ts +16 -1
  59. package/assetContainer.js +198 -41
  60. package/assetContainer.js.map +1 -1
  61. package/package.json +1 -1
@@ -121,114 +121,100 @@ export class PhysicsShape {
121
121
  }
122
122
  }
123
123
  /**
124
- *
124
+ * Helper object to create a sphere shape
125
125
  */
126
- /** @internal */
127
126
  export class PhysicsShapeSphere extends PhysicsShape {
128
127
  /** @internal */
129
128
  /**
130
- *
131
- * @param center
132
- * @param radius
133
- * @param scene
129
+ * Constructor for the Sphere Shape
130
+ * @param center local center of the sphere
131
+ * @param radius radius
132
+ * @param scene scene to attach to
134
133
  */
135
134
  constructor(center, radius, scene) {
136
135
  super(ShapeType.SPHERE, { center: center, radius: radius }, scene);
137
136
  }
138
137
  }
139
138
  /***
140
- *
139
+ * Helper object to create a capsule shape
141
140
  */
142
- /** @internal */
143
141
  export class PhysicsShapeCapsule extends PhysicsShape {
144
- /** @internal */
145
142
  /**
146
143
  *
147
- * @param pointA
148
- * @param pointB
149
- * @param radius
150
- * @param scene
144
+ * @param pointA Starting point that defines the capsule segment
145
+ * @param pointB ending point of that same segment
146
+ * @param radius radius
147
+ * @param scene scene to attach to
151
148
  */
152
149
  constructor(pointA, pointB, radius, scene) {
153
150
  super(ShapeType.CAPSULE, { pointA: pointA, pointB: pointB, radius: radius }, scene);
154
151
  }
155
152
  }
156
153
  /**
157
- *
154
+ * Helper object to create a cylinder shape
158
155
  */
159
- /** @internal */
160
156
  export class PhysicsShapeCylinder extends PhysicsShape {
161
- /** @internal */
162
157
  /**
163
158
  *
164
- * @param pointA
165
- * @param pointB
166
- * @param radius
167
- * @param scene
159
+ * @param pointA Starting point that defines the cylinder segment
160
+ * @param pointB ending point of that same segment
161
+ * @param radius radius
162
+ * @param scene scene to attach to
168
163
  */
169
164
  constructor(pointA, pointB, radius, scene) {
170
165
  super(ShapeType.CYLINDER, { pointA: pointA, pointB: pointB, radius: radius }, scene);
171
166
  }
172
167
  }
173
168
  /**
174
- *
169
+ * Helper object to create a box shape
175
170
  */
176
- /** @internal */
177
171
  export class PhysicsShapeBox extends PhysicsShape {
178
- /** @internal */
179
172
  /**
180
173
  *
181
- * @param center
182
- * @param rotation
183
- * @param extents
184
- * @param scene
174
+ * @param center local center of the sphere
175
+ * @param rotation local orientation
176
+ * @param extents size of the box in each direction
177
+ * @param scene scene to attach to
185
178
  */
186
179
  constructor(center, rotation, extents, scene) {
187
180
  super(ShapeType.BOX, { center: center, rotation: rotation, extents: extents }, scene);
188
181
  }
189
182
  }
190
183
  /**
191
- *
184
+ * Helper object to create a convex hull shape
192
185
  */
193
- /** @internal */
194
186
  export class PhysicsShapeConvexHull extends PhysicsShape {
195
- /** @internal */
196
187
  /**
197
188
  *
198
- * @param mesh
199
- * @param scene
189
+ * @param mesh the mesh to be used as topology infos for the convex hull
190
+ * @param scene scene to attach to
200
191
  */
201
192
  constructor(mesh, scene) {
202
193
  super(ShapeType.CONVEX_HULL, { mesh: mesh }, scene);
203
194
  }
204
195
  }
205
196
  /**
206
- *
197
+ * Helper object to create a mesh shape
207
198
  */
208
- /** @internal */
209
199
  export class PhysicsShapeMesh extends PhysicsShape {
210
- /** @internal */
211
200
  /**
212
201
  *
213
- * @param mesh
214
- * @param scene
202
+ * @param mesh the mesh topology that will be used to create the shape
203
+ * @param scene scene to attach to
215
204
  */
216
205
  constructor(mesh, scene) {
217
206
  super(ShapeType.MESH, { mesh: mesh }, scene);
218
207
  }
219
208
  }
220
209
  /**
221
- *
210
+ * A shape container holds a variable number of shapes. Use AddChild to append to newly created parent container.
222
211
  */
223
- /** @internal */
224
212
  export class PhysicsShapeContainer extends PhysicsShape {
225
- /** @internal */
226
213
  /**
227
- *
228
- * @param mesh
229
- * @param scene
214
+ * Constructor of the Shape container
215
+ * @param scene scene to attach to
230
216
  */
231
- constructor(mesh, scene) {
217
+ constructor(scene) {
232
218
  super(ShapeType.CONTAINER, {}, scene);
233
219
  }
234
220
  }
@@ -1 +1 @@
1
- {"version":3,"file":"physicsShape.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsShape.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAQnD;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAYrB;;;;;;;;;OASG;IACH,YAAY,IAAY,EAAE,UAAkC,EAAE,EAAE,KAAY;QArB5E;;WAEG;QACI,gBAAW,GAAQ,SAAS,CAAC;QAmBhC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,KAAK,EAAE;YACR,OAAO;SACV;QAED,MAAM,aAAa,GAAG,KAAK,CAAC,gBAAgB,EAAE,CAAC;QAC/C,IAAI,CAAC,aAAa,E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esContent":["import type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport type { BoundingBox } from \"../../Culling/boundingBox\";\r\nimport { ShapeType } from \"./IPhysicsEnginePlugin\";\r\nimport type { IPhysicsEnginePluginV2, PhysicsShapeParameters } from \"./IPhysicsEnginePlugin\";\r\nimport type { PhysicsMaterial } from \"./physicsMaterial\";\r\nimport type { Vector3 } from \"../../Maths/math.vector\";\r\nimport type { Quaternion } from \"../../Maths/math.vector\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport type { Scene } from \"../../scene\";\r\n\r\n/**\r\n * PhysicsShape class.\r\n * This class is useful for creating a physics shape that can be used in a physics engine.\r\n * A Physic Shape determine how collision are computed. It must be attached to a body.\r\n */\r\nexport class PhysicsShape {\r\n /**\r\n * V2 Physics plugin private data for single shape\r\n */\r\n public _pluginData: any = undefined;\r\n /**\r\n * The V2 plugin used to create and manage this Physics Body\r\n */\r\n private _physicsPlugin: IPhysicsEnginePluginV2;\r\n\r\n private _type: ShapeType;\r\n\r\n /**\r\n * Constructs a new physics shape.\r\n * @param type The type of the shape.\r\n * @param options The options of the shape.\r\n * @param scene The scene the shape belongs to.\r\n *\r\n * This code is useful for creating a new physics shape with the given type, options, and scene.\r\n * It also checks that the physics engine and plugin version are correct.\r\n * If not, it throws an error. This ensures that the shape is created with the correct parameters and is compatible with the physics engine.\r\n */\r\n constructor(type: number, options: PhysicsShapeParameters = {}, scene: Scene) {\r\n this._type = type;\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n const physicsEngine = scene.getPhysicsEngine();\r\n if (!physicsEngine) {\r\n throw new Error(\"No Physics Engine available.\");\r\n }\r\n if (physicsEngine.getPluginVersion() != 2) {\r\n throw new Error(\"Plugin version is incorrect. Expected version 2.\");\r\n }\r\n const physicsPlugin = physicsEngine.getPhysicsPlugin();\r\n if (!physicsPlugin) {\r\n throw new Error(\"No Physics Plugin available.\");\r\n }\r\n\r\n this._physicsPlugin = physicsPlugin as IPhysicsEnginePluginV2;\r\n this._physicsPlugin.initShape(this, type, options);\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public get type(): ShapeType {\r\n return this._type;\r\n }\r\n\r\n /**\r\n *\r\n * @param layer\r\n */\r\n public setFilterLayer(layer: number): void {\r\n this._physicsPlugin.setFilterLayer(this, layer);\r\n }\r\n\r\n /**\r\n *\r\n * @returns\r\n */\r\n public getFilterLayer(): number {\r\n return this._physicsPlugin.getFilterLayer(this);\r\n }\r\n\r\n /**\r\n *\r\n * @param materialId\r\n */\r\n public setMaterial(material: PhysicsMaterial): void {\r\n this._physicsPlugin.setMaterial(this, material);\r\n }\r\n\r\n /**\r\n *\r\n * @returns\r\n */\r\n public getMaterial(): PhysicsMaterial | undefined {\r\n return this._physicsPlugin.getMaterial(this);\r\n }\r\n\r\n /**\r\n *\r\n * @param density\r\n */\r\n public setDensity(density: number): void {\r\n this._physicsPlugin.setDensity(this, density);\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public getDensity(): number {\r\n return this._physicsPlugin.getDensity(this);\r\n }\r\n\r\n /**\r\n *\r\n * @param newChild\r\n * @param childTransform\r\n */\r\n public addChild(newChild: PhysicsShape, childTransform: TransformNode): void {\r\n this._physicsPlugin.addChild(this, newChild, childTransform);\r\n }\r\n\r\n /**\r\n *\r\n * @param childIndex\r\n */\r\n public removeChild(childIndex: number): void {\r\n this._physicsPlugin.removeChild(this, childIndex);\r\n }\r\n\r\n /**\r\n *\r\n * @returns\r\n */\r\n public getNumChildren(): number {\r\n return this._physicsPlugin.getNumChildren(this);\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public getBoundingBox(): BoundingBox {\r\n return this._physicsPlugin.getBoundingBox(this);\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public dispose() {\r\n this._physicsPlugin.disposeShape(this);\r\n }\r\n}\r\n\r\n/**\r\n *\r\n */\r\n/** @internal */\r\nexport class PhysicsShapeSphere extends PhysicsShape {\r\n /** @internal */\r\n /**\r\n *\r\n * @param center\r\n * @param radius\r\n * @param scene\r\n */\r\n constructor(center: Vector3, radius: number, scene: Scene) {\r\n super(ShapeType.SPHERE, { center: center, radius: radius }, scene);\r\n }\r\n}\r\n\r\n/***\r\n *\r\n */\r\n/** @internal */\r\nexport class PhysicsShapeCapsule extends PhysicsShape {\r\n /** @internal */\r\n /**\r\n *\r\n * @param pointA\r\n * @param pointB\r\n * @param radius\r\n * @param scene\r\n */\r\n constructor(pointA: Vector3, pointB: Vector3, radius: number, scene: Scene) {\r\n super(ShapeType.CAPSULE, { pointA: pointA, pointB: pointB, radius: radius }, scene);\r\n }\r\n}\r\n\r\n/**\r\n *\r\n */\r\n/** @internal */\r\nexport class PhysicsShapeCylinder extends PhysicsShape {\r\n /** @internal */\r\n /**\r\n *\r\n * @param pointA\r\n * @param pointB\r\n * @param radius\r\n * @param scene\r\n */\r\n constructor(pointA: Vector3, pointB: Vector3, radius: number, scene: Scene) {\r\n super(ShapeType.CYLINDER, { pointA: pointA, pointB: pointB, radius: radius }, scene);\r\n }\r\n}\r\n\r\n/**\r\n *\r\n */\r\n/** @internal */\r\nexport class PhysicsShapeBox extends PhysicsShape {\r\n /** @internal */\r\n /**\r\n *\r\n * @param center\r\n * @param rotation\r\n * @param extents\r\n * @param scene\r\n */\r\n constructor(center: Vector3, rotation: Quaternion, extents: Vector3, scene: Scene) {\r\n super(ShapeType.BOX, { center: center, rotation: rotation, extents: extents }, scene);\r\n }\r\n}\r\n\r\n/**\r\n *\r\n */\r\n/** @internal */\r\nexport class PhysicsShapeConvexHull extends PhysicsShape {\r\n /** @internal */\r\n /**\r\n *\r\n * @param mesh\r\n * @param scene\r\n */\r\n constructor(mesh: Mesh, scene: Scene) {\r\n super(ShapeType.CONVEX_HULL, { mesh: mesh }, scene);\r\n }\r\n}\r\n\r\n/**\r\n *\r\n */\r\n/** @internal */\r\nexport class PhysicsShapeMesh extends PhysicsShape {\r\n /** @internal */\r\n /**\r\n *\r\n * @param mesh\r\n * @param scene\r\n */\r\n constructor(mesh: Mesh, scene: Scene) {\r\n super(ShapeType.MESH, { mesh: mesh }, scene);\r\n }\r\n}\r\n\r\n/**\r\n *\r\n */\r\n/** @internal */\r\nexport class PhysicsShapeContainer extends PhysicsShape {\r\n /** @internal */\r\n /**\r\n *\r\n * @param mesh\r\n * @param scene\r\n */\r\n constructor(mesh: Mesh, scene: Scene) {\r\n super(ShapeType.CONTAINER, {}, scene);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"physicsShape.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsShape.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAQnD;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAYrB;;;;;;;;;OASG;IACH,YAAY,IAAY,EAAE,UAAkC,EAAE,EAAE,KAAY;QArB5E;;WAEG;QACI,gBAAW,GAAQ,SAAS,CAAC;QAmBhC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,KAAK,EAAE;YACR,OAAO;SACV;QAED,MAAM,aAAa,GAAG,KAAK,CAAC,gBAAgB,EAAE,CAAC;QAC/C,IAAI,CAAC,aAAa,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SACnD;QACD,IAAI,aAAa,CAAC,gBAAgB,EAAE,IAAI,CAAC,EAAE;YACvC,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;SACvE;QACD,MAAM,aAAa,GAAG,aAAa,CAAC,gBAAgB,EAAE,CAAC;QACvD,IAAI,CAAC,aAAa,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SACnD;QAED,IAAI,CAAC,cAAc,GAAG,aAAuC,CAAC;QAC9D,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACvD,CAAC;IAED;;OAEG;IACH,IAAW,IAAI;QACX,OAAO,IAAI,CAA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,YAAY,IAAU,EAAE,KAAY;QAChC,KAAK,CAAC,SAAS,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC;IACxD,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,YAAY;IAC9C;;;;OAIG;IACH,YAAY,IAAU,EAAE,KAAY;QAChC,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC;IACjD,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,YAAY;IACnD;;;OAGG;IACH,YAAY,KAAY;QACpB,KAAK,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;IAC1C,CAAC;CACJ","sourcesContent":["import type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport type { BoundingBox } from \"../../Culling/boundingBox\";\r\nimport { ShapeType } from \"./IPhysicsEnginePlugin\";\r\nimport type { IPhysicsEnginePluginV2, PhysicsShapeParameters } from \"./IPhysicsEnginePlugin\";\r\nimport type { PhysicsMaterial } from \"./physicsMaterial\";\r\nimport type { Vector3 } from \"../../Maths/math.vector\";\r\nimport type { Quaternion } from \"../../Maths/math.vector\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport type { Scene } from \"../../scene\";\r\n\r\n/**\r\n * PhysicsShape class.\r\n * This class is useful for creating a physics shape that can be used in a physics engine.\r\n * A Physic Shape determine how collision are computed. It must be attached to a body.\r\n */\r\nexport class PhysicsShape {\r\n /**\r\n * V2 Physics plugin private data for single shape\r\n */\r\n public _pluginData: any = undefined;\r\n /**\r\n * The V2 plugin used to create and manage this Physics Body\r\n */\r\n private _physicsPlugin: IPhysicsEnginePluginV2;\r\n\r\n private _type: ShapeType;\r\n\r\n /**\r\n * Constructs a new physics shape.\r\n * @param type The type of the shape.\r\n * @param options The options of the shape.\r\n * @param scene The scene the shape belongs to.\r\n *\r\n * This code is useful for creating a new physics shape with the given type, options, and scene.\r\n * It also checks that the physics engine and plugin version are correct.\r\n * If not, it throws an error. This ensures that the shape is created with the correct parameters and is compatible with the physics engine.\r\n */\r\n constructor(type: number, options: PhysicsShapeParameters = {}, scene: Scene) {\r\n this._type = type;\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n const physicsEngine = scene.getPhysicsEngine();\r\n if (!physicsEngine) {\r\n throw new Error(\"No Physics Engine available.\");\r\n }\r\n if (physicsEngine.getPluginVersion() != 2) {\r\n throw new Error(\"Plugin version is incorrect. Expected version 2.\");\r\n }\r\n const physicsPlugin = physicsEngine.getPhysicsPlugin();\r\n if (!physicsPlugin) {\r\n throw new Error(\"No Physics Plugin available.\");\r\n }\r\n\r\n this._physicsPlugin = physicsPlugin as IPhysicsEnginePluginV2;\r\n this._physicsPlugin.initShape(this, type, options);\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public get type(): ShapeType {\r\n return this._type;\r\n }\r\n\r\n /**\r\n *\r\n * @param layer\r\n */\r\n public setFilterLayer(layer: number): void {\r\n this._physicsPlugin.setFilterLayer(this, layer);\r\n }\r\n\r\n /**\r\n *\r\n * @returns\r\n */\r\n public getFilterLayer(): number {\r\n return this._physicsPlugin.getFilterLayer(this);\r\n }\r\n\r\n /**\r\n *\r\n * @param materialId\r\n */\r\n public setMaterial(material: PhysicsMaterial): void {\r\n this._physicsPlugin.setMaterial(this, material);\r\n }\r\n\r\n /**\r\n *\r\n * @returns\r\n */\r\n public getMaterial(): PhysicsMaterial | undefined {\r\n return this._physicsPlugin.getMaterial(this);\r\n }\r\n\r\n /**\r\n *\r\n * @param density\r\n */\r\n public setDensity(density: number): void {\r\n this._physicsPlugin.setDensity(this, density);\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public getDensity(): number {\r\n return this._physicsPlugin.getDensity(this);\r\n }\r\n\r\n /**\r\n *\r\n * @param newChild\r\n * @param childTransform\r\n */\r\n public addChild(newChild: PhysicsShape, childTransform: TransformNode): void {\r\n this._physicsPlugin.addChild(this, newChild, childTransform);\r\n }\r\n\r\n /**\r\n *\r\n * @param childIndex\r\n */\r\n public removeChild(childIndex: number): void {\r\n this._physicsPlugin.removeChild(this, childIndex);\r\n }\r\n\r\n /**\r\n *\r\n * @returns\r\n */\r\n public getNumChildren(): number {\r\n return this._physicsPlugin.getNumChildren(this);\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public getBoundingBox(): BoundingBox {\r\n return this._physicsPlugin.getBoundingBox(this);\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public dispose() {\r\n this._physicsPlugin.disposeShape(this);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a sphere shape\r\n */\r\nexport class PhysicsShapeSphere extends PhysicsShape {\r\n /** @internal */\r\n /**\r\n * Constructor for the Sphere Shape\r\n * @param center local center of the sphere\r\n * @param radius radius\r\n * @param scene scene to attach to\r\n */\r\n constructor(center: Vector3, radius: number, scene: Scene) {\r\n super(ShapeType.SPHERE, { center: center, radius: radius }, scene);\r\n }\r\n}\r\n\r\n/***\r\n * Helper object to create a capsule shape\r\n */\r\nexport class PhysicsShapeCapsule extends PhysicsShape {\r\n /**\r\n *\r\n * @param pointA Starting point that defines the capsule segment\r\n * @param pointB ending point of that same segment\r\n * @param radius radius\r\n * @param scene scene to attach to\r\n */\r\n constructor(pointA: Vector3, pointB: Vector3, radius: number, scene: Scene) {\r\n super(ShapeType.CAPSULE, { pointA: pointA, pointB: pointB, radius: radius }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a cylinder shape\r\n */\r\nexport class PhysicsShapeCylinder extends PhysicsShape {\r\n /**\r\n *\r\n * @param pointA Starting point that defines the cylinder segment\r\n * @param pointB ending point of that same segment\r\n * @param radius radius\r\n * @param scene scene to attach to\r\n */\r\n constructor(pointA: Vector3, pointB: Vector3, radius: number, scene: Scene) {\r\n super(ShapeType.CYLINDER, { pointA: pointA, pointB: pointB, radius: radius }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a box shape\r\n */\r\nexport class PhysicsShapeBox extends PhysicsShape {\r\n /**\r\n *\r\n * @param center local center of the sphere\r\n * @param rotation local orientation\r\n * @param extents size of the box in each direction\r\n * @param scene scene to attach to\r\n */\r\n constructor(center: Vector3, rotation: Quaternion, extents: Vector3, scene: Scene) {\r\n super(ShapeType.BOX, { center: center, rotation: rotation, extents: extents }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a convex hull shape\r\n */\r\nexport class PhysicsShapeConvexHull extends PhysicsShape {\r\n /**\r\n *\r\n * @param mesh the mesh to be used as topology infos for the convex hull\r\n * @param scene scene to attach to\r\n */\r\n constructor(mesh: Mesh, scene: Scene) {\r\n super(ShapeType.CONVEX_HULL, { mesh: mesh }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a mesh shape\r\n */\r\nexport class PhysicsShapeMesh extends PhysicsShape {\r\n /**\r\n *\r\n * @param mesh the mesh topology that will be used to create the shape\r\n * @param scene scene to attach to\r\n */\r\n constructor(mesh: Mesh, scene: Scene) {\r\n super(ShapeType.MESH, { mesh: mesh }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * A shape container holds a variable number of shapes. Use AddChild to append to newly created parent container.\r\n */\r\nexport class PhysicsShapeContainer extends PhysicsShape {\r\n /**\r\n * Constructor of the Shape container\r\n * @param scene scene to attach to\r\n */\r\n constructor(scene: Scene) {\r\n super(ShapeType.CONTAINER, {}, scene);\r\n }\r\n}\r\n"]}
@@ -24,6 +24,7 @@ uvOffset=parallaxOffset(invTBN*viewDirectionW,vBumpInfos.z);
24
24
  vec4 detailColor=texture2D(detailSampler,vDetailUV+uvOffset);
25
25
  #ifdef BUMP
26
26
  #ifdef OBJECTSPACE_NORMALMAP
27
+ #define CUSTOM_FRAGMENT_BUMP_FRAGMENT
27
28
  normalW=normalize(texture2D(bumpSampler,vBumpUV).xyz *2.0-1.0);
28
29
  normalW=perturbNormal(TBN,texture2D(bumpSampler,vBumpUV+uvOffset).xyz,vBumpInfos.y);
29
30
  vec3 bumpNormal=texture2D(bumpSampler,vBumpUV+uvOffset).xyz*2.0-1.0;
@@ -1 +1 @@
1
- {"version":3,"file":"bumpFragment.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Shaders/ShadersInclude/bumpFragment.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,MAAM,IAAI,GAAG,cAAc,CAAC;AAC5B,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+Dd,CAAC;AACF,aAAa;AACb,WAAW,CAAC,oBAAoB,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AAChD,gBAAgB;AAChB,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"bumpFragment\";\nconst shader = `vec2 uvOffset=vec2(0.0,0.0);\r#if defined(BUMP) || defined(PARALLAX) || defined(DETAIL)\n#ifdef NORMALXYSCALE\nfloat normalScale=1.0;\r#elif defined(BUMP)\nfloat normalScale=vBumpInfos.y;\r#else\nfloat normalScale=1.0;\r#endif\n#if defined(TANGENT) && defined(NORMAL)\nmat3 TBN=vTBN;\r#elif defined(BUMP)\nvec2 TBNUV=gl_FrontFacing ? vBumpUV : -vBumpUV;\rmat3 TBN=cotangent_frame(normalW*normalScale,vPositionW,TBNUV,vTangentSpaceParams);\r#else\nvec2 TBNUV=gl_FrontFacing ? vDetailUV : -vDetailUV;\rmat3 TBN=cotangent_frame(normalW*normalScale,vPositionW,TBNUV,vec2(1.,1.));\r#endif\n#elif defined(ANISOTROPIC)\n#if defined(TANGENT) && defined(NORMAL)\nmat3 TBN=vTBN;\r#else\nvec2 TBNUV=gl_FrontFacing ? vMainUV1 : -vMainUV1;\rmat3 TBN=cotangent_frame(normalW,vPositionW,TBNUV,vec2(1.,1.));\r#endif\n#endif\n#ifdef PARALLAX\nmat3 invTBN=transposeMat3(TBN);\r#ifdef PARALLAXOCCLUSION\nuvOffset=parallaxOcclusion(invTBN*-viewDirectionW,invTBN*normalW,vBumpUV,vBumpInfos.z);\r#else\nuvOffset=parallaxOffset(invTBN*viewDirectionW,vBumpInfos.z);\r#endif\n#endif\n#ifdef DETAIL\nvec4 detailColor=texture2D(detailSampler,vDetailUV+uvOffset);\rvec2 detailNormalRG=detailColor.wy*2.0-1.0;\rfloat detailNormalB=sqrt(1.-saturate(dot(detailNormalRG,detailNormalRG)));\rvec3 detailNormal=vec3(detailNormalRG,detailNormalB);\r#endif\n#ifdef BUMP\n#ifdef OBJECTSPACE_NORMALMAP\nnormalW=normalize(texture2D(bumpSampler,vBumpUV).xyz *2.0-1.0);\rnormalW=normalize(mat3(normalMatrix)*normalW);\r#elif !defined(DETAIL)\nnormalW=perturbNormal(TBN,texture2D(bumpSampler,vBumpUV+uvOffset).xyz,vBumpInfos.y);\r#else\nvec3 bumpNormal=texture2D(bumpSampler,vBumpUV+uvOffset).xyz*2.0-1.0;\r#if DETAIL_NORMALBLENDMETHOD==0 \ndetailNormal.xy*=vDetailInfos.z;\rvec3 blendedNormal=normalize(vec3(bumpNormal.xy+detailNormal.xy,bumpNormal.z*detailNormal.z));\r#elif DETAIL_NORMALBLENDMETHOD==1 \ndetailNormal.xy*=vDetailInfos.z;\rbumpNormal+=vec3(0.0,0.0,1.0);\rdetailNormal*=vec3(-1.0,-1.0,1.0);\rvec3 blendedNormal=bumpNormal*dot(bumpNormal,detailNormal)/bumpNormal.z-detailNormal;\r#endif\nnormalW=perturbNormalBase(TBN,blendedNormal,vBumpInfos.y);\r#endif\n#elif defined(DETAIL)\ndetailNormal.xy*=vDetailInfos.z;\rnormalW=perturbNormalBase(TBN,detailNormal,vDetailInfos.z);\r#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const bumpFragment = { name, shader };\n"]}
1
+ {"version":3,"file":"bumpFragment.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Shaders/ShadersInclude/bumpFragment.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,MAAM,IAAI,GAAG,cAAc,CAAC;AAC5B,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgEd,CAAC;AACF,aAAa;AACb,WAAW,CAAC,oBAAoB,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AAChD,gBAAgB;AAChB,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"bumpFragment\";\nconst shader = `vec2 uvOffset=vec2(0.0,0.0);\r#if defined(BUMP) || defined(PARALLAX) || defined(DETAIL)\n#ifdef NORMALXYSCALE\nfloat normalScale=1.0;\r#elif defined(BUMP)\nfloat normalScale=vBumpInfos.y;\r#else\nfloat normalScale=1.0;\r#endif\n#if defined(TANGENT) && defined(NORMAL)\nmat3 TBN=vTBN;\r#elif defined(BUMP)\nvec2 TBNUV=gl_FrontFacing ? vBumpUV : -vBumpUV;\rmat3 TBN=cotangent_frame(normalW*normalScale,vPositionW,TBNUV,vTangentSpaceParams);\r#else\nvec2 TBNUV=gl_FrontFacing ? vDetailUV : -vDetailUV;\rmat3 TBN=cotangent_frame(normalW*normalScale,vPositionW,TBNUV,vec2(1.,1.));\r#endif\n#elif defined(ANISOTROPIC)\n#if defined(TANGENT) && defined(NORMAL)\nmat3 TBN=vTBN;\r#else\nvec2 TBNUV=gl_FrontFacing ? vMainUV1 : -vMainUV1;\rmat3 TBN=cotangent_frame(normalW,vPositionW,TBNUV,vec2(1.,1.));\r#endif\n#endif\n#ifdef PARALLAX\nmat3 invTBN=transposeMat3(TBN);\r#ifdef PARALLAXOCCLUSION\nuvOffset=parallaxOcclusion(invTBN*-viewDirectionW,invTBN*normalW,vBumpUV,vBumpInfos.z);\r#else\nuvOffset=parallaxOffset(invTBN*viewDirectionW,vBumpInfos.z);\r#endif\n#endif\n#ifdef DETAIL\nvec4 detailColor=texture2D(detailSampler,vDetailUV+uvOffset);\rvec2 detailNormalRG=detailColor.wy*2.0-1.0;\rfloat detailNormalB=sqrt(1.-saturate(dot(detailNormalRG,detailNormalRG)));\rvec3 detailNormal=vec3(detailNormalRG,detailNormalB);\r#endif\n#ifdef BUMP\n#ifdef OBJECTSPACE_NORMALMAP\n#define CUSTOM_FRAGMENT_BUMP_FRAGMENT\nnormalW=normalize(texture2D(bumpSampler,vBumpUV).xyz *2.0-1.0);\rnormalW=normalize(mat3(normalMatrix)*normalW);\r#elif !defined(DETAIL)\nnormalW=perturbNormal(TBN,texture2D(bumpSampler,vBumpUV+uvOffset).xyz,vBumpInfos.y);\r#else\nvec3 bumpNormal=texture2D(bumpSampler,vBumpUV+uvOffset).xyz*2.0-1.0;\r#if DETAIL_NORMALBLENDMETHOD==0 \ndetailNormal.xy*=vDetailInfos.z;\rvec3 blendedNormal=normalize(vec3(bumpNormal.xy+detailNormal.xy,bumpNormal.z*detailNormal.z));\r#elif DETAIL_NORMALBLENDMETHOD==1 \ndetailNormal.xy*=vDetailInfos.z;\rbumpNormal+=vec3(0.0,0.0,1.0);\rdetailNormal*=vec3(-1.0,-1.0,1.0);\rvec3 blendedNormal=bumpNormal*dot(bumpNormal,detailNormal)/bumpNormal.z-detailNormal;\r#endif\nnormalW=perturbNormalBase(TBN,blendedNormal,vBumpInfos.y);\r#endif\n#elif defined(DETAIL)\ndetailNormal.xy*=vDetailInfos.z;\rnormalW=perturbNormalBase(TBN,detailNormal,vDetailInfos.z);\r#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const bumpFragment = { name, shader };\n"]}
@@ -5,7 +5,7 @@ const shader = `#if defined(BUMP) || defined(CLEARCOAT_BUMP) || defined(ANISOTRO
5
5
  #if defined(TANGENT) && defined(NORMAL)
6
6
  varying mat3 vTBN;
7
7
  #ifdef OBJECTSPACE_NORMALMAP
8
- uniform mat4 normalMatrix;
8
+ uniform mat4 normalMatrix;
9
9
  vec3 perturbNormalBase(mat3 cotangentFrame,vec3 normal,float scale)
10
10
  normal=normalize(normal*vec3(scale,scale,1.0));
11
11
  return normalize(cotangentFrame*normal);
@@ -1 +1 @@
1
- {"version":3,"file":"bumpFragmentMainFunctions.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Shaders/ShadersInclude/bumpFragmentMainFunctions.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,MAAM,IAAI,GAAG,2BAA2B,CAAC;AACzC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmCd,CAAC;AACF,aAAa;AACb,WAAW,CAAC,oBAAoB,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AAChD,gBAAgB;AAChB,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"bumpFragmentMainFunctions\";\nconst shader = `#if defined(BUMP) || defined(CLEARCOAT_BUMP) || defined(ANISOTROPIC) || defined(DETAIL)\n#if defined(TANGENT) && defined(NORMAL) \nvarying mat3 vTBN;\r#endif\n#ifdef OBJECTSPACE_NORMALMAP\nuniform mat4 normalMatrix;\r#endif\nvec3 perturbNormalBase(mat3 cotangentFrame,vec3 normal,float scale)\r{\r#ifdef NORMALXYSCALE\nnormal=normalize(normal*vec3(scale,scale,1.0));\r#endif\nreturn normalize(cotangentFrame*normal);\r}\rvec3 perturbNormal(mat3 cotangentFrame,vec3 textureSample,float scale)\r{\rreturn perturbNormalBase(cotangentFrame,textureSample*2.0-1.0,scale);\r}\rmat3 cotangent_frame(vec3 normal,vec3 p,vec2 uv,vec2 tangentSpaceParams)\r{\rvec3 dp1=dFdx(p);\rvec3 dp2=dFdy(p);\rvec2 duv1=dFdx(uv);\rvec2 duv2=dFdy(uv);\rvec3 dp2perp=cross(dp2,normal);\rvec3 dp1perp=cross(normal,dp1);\rvec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;\rvec3 bitangent=dp2perp*duv1.y+dp1perp*duv2.y;\rtangent*=tangentSpaceParams.x;\rbitangent*=tangentSpaceParams.y;\rfloat det=max(dot(tangent,tangent),dot(bitangent,bitangent));\rfloat invmax=det==0.0 ? 0.0 : inversesqrt(det);\rreturn mat3(tangent*invmax,bitangent*invmax,normal);\r}\r#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const bumpFragmentMainFunctions = { name, shader };\n"]}
1
+ {"version":3,"file":"bumpFragmentMainFunctions.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Shaders/ShadersInclude/bumpFragmentMainFunctions.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,MAAM,IAAI,GAAG,2BAA2B,CAAC;AACzC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6Cd,CAAC;AACF,aAAa;AACb,WAAW,CAAC,oBAAoB,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AAChD,gBAAgB;AAChB,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"bumpFragmentMainFunctions\";\nconst shader = `#if defined(BUMP) || defined(CLEARCOAT_BUMP) || defined(ANISOTROPIC) || defined(DETAIL)\n#if defined(TANGENT) && defined(NORMAL) \nvarying mat3 vTBN;\r#endif\n#ifdef OBJECTSPACE_NORMALMAP\nuniform mat4 normalMatrix;\rmat4 toNormalMatrix(mat4 wMatrix)\r{\rmat4 ret=inverse(wMatrix);\rret=transpose(ret);\rret[0][3]=0.;\rret[1][3]=0.;\rret[2][3]=0.;\rret[3]=vec4(0.,0.,0.,1.);\rreturn ret;\r}\r#endif\nvec3 perturbNormalBase(mat3 cotangentFrame,vec3 normal,float scale)\r{\r#ifdef NORMALXYSCALE\nnormal=normalize(normal*vec3(scale,scale,1.0));\r#endif\nreturn normalize(cotangentFrame*normal);\r}\rvec3 perturbNormal(mat3 cotangentFrame,vec3 textureSample,float scale)\r{\rreturn perturbNormalBase(cotangentFrame,textureSample*2.0-1.0,scale);\r}\rmat3 cotangent_frame(vec3 normal,vec3 p,vec2 uv,vec2 tangentSpaceParams)\r{\rvec3 dp1=dFdx(p);\rvec3 dp2=dFdy(p);\rvec2 duv1=dFdx(uv);\rvec2 duv2=dFdy(uv);\rvec3 dp2perp=cross(dp2,normal);\rvec3 dp1perp=cross(normal,dp1);\rvec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;\rvec3 bitangent=dp2perp*duv1.y+dp1perp*duv2.y;\rtangent*=tangentSpaceParams.x;\rbitangent*=tangentSpaceParams.y;\rfloat det=max(dot(tangent,tangent),dot(bitangent,bitangent));\rfloat invmax=det==0.0 ? 0.0 : inversesqrt(det);\rreturn mat3(tangent*invmax,bitangent*invmax,normal);\r}\r#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const bumpFragmentMainFunctions = { name, shader };\n"]}
@@ -7,7 +7,7 @@ const name = "spritesPixelShader";
7
7
  const shader = `uniform bool alphaTest;
8
8
  #define CUSTOM_FRAGMENT_DEFINITIONS
9
9
  void main(void) {
10
- vec4 color=texture2D(diffuseSampler,vUV);
10
+ vec4 color=texture2D(diffuseSampler,vUV);
11
11
  gl_FragColor=color;
12
12
  #define CUSTOM_FRAGMENT_MAIN_END
13
13
  }`;
@@ -1 +1 @@
1
- {"version":3,"file":"sprites.fragment.js","sourceRoot":"","sources":["../../../../lts/core/generated/Shaders/sprites.fragment.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,yCAAyC,CAAC;AACjD,OAAO,8BAA8B,CAAC;AACtC,OAAO,+CAA+C,CAAC;AAEvD,MAAM,IAAI,GAAG,oBAAoB,CAAC;AAClC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;EAmBb,CAAC;AACH,aAAa;AACb,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AACxC,gBAAgB;AAChB,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/fogFragmentDeclaration\";\nimport \"./ShadersInclude/fogFragment\";\nimport \"./ShadersInclude/imageProcessingCompatibility\";\n\nconst name = \"spritesPixelShader\";\nconst shader = `uniform bool alphaTest;\rvarying vec4 vColor;\rvarying vec2 vUV;\runiform sampler2D diffuseSampler;\r#include<fogFragmentDeclaration>\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\r#define CUSTOM_FRAGMENT_MAIN_BEGIN\nvec4 color=texture2D(diffuseSampler,vUV);\rif (float(alphaTest) != 0.)\r{\rif (color.a<0.95)\rdiscard;\r}\rcolor*=vColor;\r#include<fogFragment>\ngl_FragColor=color;\r#include<imageProcessingCompatibility>\n#define CUSTOM_FRAGMENT_MAIN_END\n}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const spritesPixelShader = { name, shader };\n"]}
1
+ {"version":3,"file":"sprites.fragment.js","sourceRoot":"","sources":["../../../../lts/core/generated/Shaders/sprites.fragment.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,yCAAyC,CAAC;AACjD,OAAO,8BAA8B,CAAC;AACtC,OAAO,+CAA+C,CAAC;AAEvD,MAAM,IAAI,GAAG,oBAAoB,CAAC;AAClC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;EAoBb,CAAC;AACH,aAAa;AACb,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AACxC,gBAAgB;AAChB,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/fogFragmentDeclaration\";\nimport \"./ShadersInclude/fogFragment\";\nimport \"./ShadersInclude/imageProcessingCompatibility\";\n\nconst name = \"spritesPixelShader\";\nconst shader = `uniform bool alphaTest;\rvarying vec4 vColor;\rvarying vec2 vUV;\runiform sampler2D diffuseSampler;\r#include<fogFragmentDeclaration>\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\r#define CUSTOM_FRAGMENT_MAIN_BEGIN\nvec4 color=texture2D(diffuseSampler,vUV);\rfloat fAlphaTest=float(alphaTest);\rif (fAlphaTest != 0.)\r{\rif (color.a<0.95)\rdiscard;\r}\rcolor*=vColor;\r#include<fogFragment>\ngl_FragColor=color;\r#include<imageProcessingCompatibility>\n#define CUSTOM_FRAGMENT_MAIN_END\n}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const spritesPixelShader = { name, shader };\n"]}
@@ -1,7 +1,7 @@
1
1
  import { AbstractScene } from "./abstractScene";
2
2
  import type { Scene } from "./scene";
3
3
  import { Mesh } from "./Meshes/mesh";
4
- import type { TransformNode } from "./Meshes/transformNode";
4
+ import { TransformNode } from "./Meshes/transformNode";
5
5
  import type { Skeleton } from "./Bones/skeleton";
6
6
  import type { AnimationGroup } from "./Animations/animationGroup";
7
7
  import type { Animatable } from "./Animations/animatable";
@@ -48,6 +48,21 @@ export declare class AssetContainer extends AbstractScene {
48
48
  * @param scene The scene the AssetContainer belongs to.
49
49
  */
50
50
  constructor(scene?: Nullable<Scene>);
51
+ /**
52
+ * Given a list of nodes, return a topological sorting of them.
53
+ * @param nodes
54
+ */
55
+ private _topologicalSort;
56
+ private _addNodeAndDescendantsToList;
57
+ /**
58
+ * Check if a specific node is contained in this asset container.
59
+ * @param node
60
+ */
61
+ private _isNodeInContainer;
62
+ /**
63
+ * For every node in the scene, check if its parent node is also in the scene.
64
+ */
65
+ private _isValidHierarchy;
51
66
  /**
52
67
  * Instantiate or clone all meshes and add the new ones to the scene.
53
68
  * Skeletons and animation groups will all be cloned
package/assetContainer.js CHANGED
@@ -1,7 +1,12 @@
1
1
  import { AbstractScene } from "./abstractScene.js";
2
2
  import { Mesh } from "./Meshes/mesh.js";
3
+ import { TransformNode } from "./Meshes/transformNode.js";
3
4
  import { Logger } from "./Misc/logger.js";
4
5
  import { EngineStore } from "./Engines/engineStore.js";
6
+ import { InstancedMesh } from "./Meshes/instancedMesh.js";
7
+ import { Light } from "./Lights/light.js";
8
+ import { Camera } from "./Cameras/camera.js";
9
+ import { Tools } from "./Misc/tools.js";
5
10
  /**
6
11
  * Set of assets to keep when moving a scene into an asset container.
7
12
  */
@@ -85,6 +90,145 @@ export class AssetContainer extends AbstractScene {
85
90
  }
86
91
  });
87
92
  }
93
+ /**
94
+ * Given a list of nodes, return a topological sorting of them.
95
+ * @param nodes
96
+ */
97
+ _topologicalSort(nodes) {
98
+ const nodesUidMap = new Map();
99
+ for (const node of nodes) {
100
+ nodesUidMap.set(node.uniqueId, node);
101
+ }
102
+ const dependencyGraph = {
103
+ dependsOn: new Map(),
104
+ dependedBy: new Map(), // given a node id, what are the ids of the nodes that depend on it
105
+ };
106
+ // Build the dependency graph given the list of nodes
107
+ // First pass: Initialize the empty dependency graph
108
+ for (const node of nodes) {
109
+ const nodeId = node.uniqueId;
110
+ dependencyGraph.dependsOn.set(nodeId, new Set());
111
+ dependencyGraph.dependedBy.set(nodeId, new Set());
112
+ }
113
+ // Second pass: Populate the dependency graph. We assume that we
114
+ // don't need to check for cycles here, as the scene graph cannot
115
+ // contain cycles. Our graph also already contains all transitive
116
+ // dependencies because getDescendants returns the transitive
117
+ // dependencies by default.
118
+ for (const node of nodes) {
119
+ const nodeId = node.uniqueId;
120
+ const dependsOn = dependencyGraph.dependsOn.get(nodeId);
121
+ if (node instanceof InstancedMesh) {
122
+ const masterMesh = node.sourceMesh;
123
+ if (nodesUidMap.has(masterMesh.uniqueId)) {
124
+ dependsOn.add(masterMesh.uniqueId);
125
+ dependencyGraph.dependedBy.get(masterMesh.uniqueId).add(nodeId);
126
+ }
127
+ }
128
+ const dependedBy = dependencyGraph.dependedBy.get(nodeId);
129
+ for (const child of node.getDescendants()) {
130
+ const childId = child.uniqueId;
131
+ if (nodesUidMap.has(childId)) {
132
+ dependedBy.add(childId);
133
+ const childDependsOn = dependencyGraph.dependsOn.get(childId);
134
+ childDependsOn.add(nodeId);
135
+ }
136
+ }
137
+ }
138
+ // Third pass: Topological sort
139
+ const sortedNodes = [];
140
+ // First: Find all nodes that have no dependencies
141
+ const leaves = [];
142
+ for (const node of nodes) {
143
+ const nodeId = node.uniqueId;
144
+ if (dependencyGraph.dependsOn.get(nodeId).size === 0) {
145
+ leaves.push(node);
146
+ nodesUidMap.delete(nodeId);
147
+ }
148
+ }
149
+ const visitList = leaves;
150
+ while (visitList.length > 0) {
151
+ const nodeToVisit = visitList.shift();
152
+ sortedNodes.push(nodeToVisit);
153
+ // Remove the node from the dependency graph
154
+ // When a node is visited, we know that dependsOn is empty.
155
+ // So we only need to remove the node from dependedBy.
156
+ const dependedByVisitedNode = dependencyGraph.dependedBy.get(nodeToVisit.uniqueId);
157
+ // Array.from(x.values()) is to make the TS compiler happy
158
+ for (const dependedByVisitedNodeId of Array.from(dependedByVisitedNode.values())) {
159
+ const dependsOnDependedByVisitedNode = dependencyGraph.dependsOn.get(dependedByVisitedNodeId);
160
+ dependsOnDependedByVisitedNode.delete(nodeToVisit.uniqueId);
161
+ if (dependsOnDependedByVisitedNode.size === 0 && nodesUidMap.get(dependedByVisitedNodeId)) {
162
+ visitList.push(nodesUidMap.get(dependedByVisitedNodeId));
163
+ nodesUidMap.delete(dependedByVisitedNodeId);
164
+ }
165
+ }
166
+ }
167
+ if (nodesUidMap.size > 0) {
168
+ console.error("SceneSerializer._topologicalSort: There were unvisited nodes:");
169
+ nodesUidMap.forEach((node) => console.error(node.name));
170
+ }
171
+ return sortedNodes;
172
+ }
173
+ _addNodeAndDescendantsToList(list, addedIds, rootNode, predicate) {
174
+ if ((predicate && !predicate(rootNode)) || addedIds.has(rootNode.uniqueId)) {
175
+ return;
176
+ }
177
+ list.push(rootNode);
178
+ addedIds.add(rootNode.uniqueId);
179
+ for (const child of rootNode.getDescendants(true)) {
180
+ this._addNodeAndDescendantsToList(list, addedIds, child, predicate);
181
+ }
182
+ }
183
+ /**
184
+ * Check if a specific node is contained in this asset container.
185
+ * @param node
186
+ */
187
+ _isNodeInContainer(node) {
188
+ if (node instanceof Mesh && this.meshes.indexOf(node) !== -1) {
189
+ return true;
190
+ }
191
+ if (node instanceof TransformNode && this.transformNodes.indexOf(node) !== -1) {
192
+ return true;
193
+ }
194
+ if (node instanceof Light && this.lights.indexOf(node) !== -1) {
195
+ return true;
196
+ }
197
+ if (node instanceof Camera && this.cameras.indexOf(node) !== -1) {
198
+ return true;
199
+ }
200
+ return false;
201
+ }
202
+ /**
203
+ * For every node in the scene, check if its parent node is also in the scene.
204
+ */
205
+ _isValidHierarchy() {
206
+ for (const node of this.meshes) {
207
+ if (node.parent && !this._isNodeInContainer(node.parent)) {
208
+ Logger.Warn(`Node ${node.name} has a parent that is not in the container.`);
209
+ return false;
210
+ }
211
+ }
212
+ for (const node of this.transformNodes) {
213
+ if (node.parent && !this._isNodeInContainer(node.parent)) {
214
+ Logger.Warn(`Node ${node.name} has a parent that is not in the container.`);
215
+ return false;
216
+ }
217
+ }
218
+ for (const node of this.lights) {
219
+ if (node.parent && !this._isNodeInContainer(node.parent)) {
220
+ Logger.Warn(`Node ${node.name} has a parent that is not in the container.`);
221
+ return false;
222
+ }
223
+ }
224
+ for (const node of this.cameras) {
225
+ if (node.parent && !this._isNodeInContainer(node.parent)) {
226
+ Logger.Warn(`Node ${node.name} has a parent that is not in the container.`);
227
+ return false;
228
+ }
229
+ }
230
+ return true;
231
+ }
88
232
  /**
89
233
  * Instantiate or clone all meshes and add the new ones to the scene.
90
234
  * Skeletons and animation groups will all be cloned
@@ -96,6 +240,9 @@ export class AssetContainer extends AbstractScene {
96
240
  * @returns a list of rootNodes, skeletons and animation groups that were duplicated
97
241
  */
98
242
  instantiateModelsToScene(nameFunction, cloneMaterials = false, options) {
243
+ if (!this._isValidHierarchy()) {
244
+ Tools.Warn("SceneSerializer.InstantiateModelsToScene: The Asset Container hierarchy is not valid.");
245
+ }
99
246
  const conversionMap = {};
100
247
  const storeMap = {};
101
248
  const result = new InstantiatedEntries();
@@ -129,24 +276,36 @@ export class AssetContainer extends AbstractScene {
129
276
  }
130
277
  }
131
278
  };
132
- this.transformNodes.forEach((o) => {
133
- if (localOptions.predicate && !localOptions.predicate(o)) {
134
- return;
279
+ const nodesToSort = [];
280
+ const idsOnSortList = new Set();
281
+ for (const transformNode of this.transformNodes) {
282
+ if (transformNode.parent === null) {
283
+ this._addNodeAndDescendantsToList(nodesToSort, idsOnSortList, transformNode, localOptions.predicate);
135
284
  }
136
- if (!o.parent) {
137
- const newOne = o.instantiateHierarchy(null, localOptions, (source, clone) => {
138
- onClone(source, clone);
139
- });
140
- if (newOne) {
141
- result.rootNodes.push(newOne);
142
- }
285
+ }
286
+ for (const mesh of this.meshes) {
287
+ if (mesh.parent === null) {
288
+ this._addNodeAndDescendantsToList(nodesToSort, idsOnSortList, mesh, localOptions.predicate);
143
289
  }
144
- });
145
- // check if there are instanced meshes in the array, to set their new source mesh
146
- const instancesExist = this.meshes.some((m) => m.getClassName() === "InstancedMesh");
147
- const instanceSourceMap = [];
290
+ }
291
+ // Topologically sort nodes by parenting/instancing relationships so that all resources are in place
292
+ // when a given node is instantiated.
293
+ const sortedNodes = this._topologicalSort(nodesToSort);
148
294
  const onNewCreated = (source, clone) => {
149
295
  onClone(source, clone);
296
+ if (source.parent) {
297
+ const replicatedParentId = conversionMap[source.parent.uniqueId];
298
+ const replicatedParent = storeMap[replicatedParentId];
299
+ if (replicatedParent) {
300
+ clone.parent = replicatedParent;
301
+ }
302
+ else {
303
+ clone.parent = source.parent;
304
+ }
305
+ }
306
+ clone.position.copyFrom(source.position);
307
+ clone.rotation.copyFrom(source.rotation);
308
+ clone.scaling.copyFrom(source.scaling);
150
309
  if (clone.material) {
151
310
  const mesh = clone;
152
311
  if (mesh.material) {
@@ -189,35 +348,27 @@ export class AssetContainer extends AbstractScene {
189
348
  }
190
349
  }
191
350
  }
192
- };
193
- this.meshes.forEach((o, idx) => {
194
- if (localOptions.predicate && !localOptions.predicate(o)) {
195
- return;
351
+ if (clone.parent === null) {
352
+ result.rootNodes.push(clone);
196
353
  }
197
- if (!o.parent) {
198
- const isInstance = o.getClassName() === "InstancedMesh";
199
- let sourceMap = undefined;
200
- if (isInstance) {
201
- const oInstance = o;
202
- // find the right index for the source mesh
203
- const sourceMesh = oInstance.sourceMesh;
204
- const sourceMeshIndex = this.meshes.indexOf(sourceMesh);
205
- if (sourceMeshIndex !== -1 && instanceSourceMap[sourceMeshIndex]) {
206
- sourceMap = instanceSourceMap[sourceMeshIndex];
207
- }
208
- }
209
- const newOne = isInstance
210
- ? o.instantiateHierarchy(null, {
211
- ...localOptions,
212
- newSourcedMesh: sourceMap,
213
- }, onNewCreated)
214
- : o.instantiateHierarchy(null, localOptions, onNewCreated);
215
- if (newOne) {
216
- if (instancesExist && newOne.getClassName() !== "InstancedMesh") {
217
- instanceSourceMap[idx] = newOne;
218
- }
219
- result.rootNodes.push(newOne);
354
+ };
355
+ sortedNodes.forEach((node) => {
356
+ if (node.getClassName() === "InstancedMesh") {
357
+ const instancedNode = node;
358
+ const sourceMesh = instancedNode.sourceMesh;
359
+ const replicatedSourceId = conversionMap[sourceMesh.uniqueId];
360
+ const replicatedSource = typeof replicatedSourceId === "number" ? storeMap[replicatedSourceId] : sourceMesh;
361
+ const replicatedInstancedNode = replicatedSource.createInstance(instancedNode.name);
362
+ onNewCreated(instancedNode, replicatedInstancedNode);
363
+ }
364
+ else {
365
+ // Mesh or TransformNode
366
+ const canInstance = !(localOptions === null || localOptions === void 0 ? void 0 : localOptions.doNotInstantiate) && node.getTotalVertices() > 0;
367
+ const replicatedNode = canInstance ? node.createInstance(`instance of ${node.name}`) : node.clone(`Clone of ${node.name}`, null, true);
368
+ if (!replicatedNode) {
369
+ throw new Error(`Could not clone or instantiate node on Asset Container ${node.name}`);
220
370
  }
371
+ onNewCreated(node, replicatedNode);
221
372
  }
222
373
  });
223
374
  this.skeletons.forEach((s) => {
@@ -265,6 +416,9 @@ export class AssetContainer extends AbstractScene {
265
416
  if (this._wasAddedToScene) {
266
417
  return;
267
418
  }
419
+ if (!this._isValidHierarchy()) {
420
+ Tools.Warn("SceneSerializer.addAllToScene: The Asset Container hierarchy is not valid.");
421
+ }
268
422
  this._wasAddedToScene = true;
269
423
  this.addToScene(null);
270
424
  if (this.environmentTexture) {
@@ -370,6 +524,9 @@ export class AssetContainer extends AbstractScene {
370
524
  * Removes all the assets in the container from the scene
371
525
  */
372
526
  removeAllFromScene() {
527
+ if (!this._isValidHierarchy()) {
528
+ Tools.Warn("SceneSerializer.removeAllFromScene: The Asset Container hierarchy is not valid.");
529
+ }
373
530
  this._wasAddedToScene = false;
374
531
  this.removeFromScene(null);
375
532
  if (this.environmentTexture === this.scene.environmentTexture) {