@babylonjs/core 5.16.0 → 5.18.0

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 (175) hide show
  1. package/Animations/animatable.js +1 -1
  2. package/Animations/animatable.js.map +1 -1
  3. package/Animations/animation.d.ts +8 -1
  4. package/Animations/animation.js +8 -1
  5. package/Animations/animation.js.map +1 -1
  6. package/Animations/animationGroup.js +5 -4
  7. package/Animations/animationGroup.js.map +1 -1
  8. package/Bones/skeleton.js +1 -1
  9. package/Bones/skeleton.js.map +1 -1
  10. package/Cameras/Inputs/arcRotateCameraKeyboardMoveInput.js +2 -2
  11. package/Cameras/Inputs/arcRotateCameraKeyboardMoveInput.js.map +1 -1
  12. package/Cameras/Inputs/flyCameraKeyboardInput.js +3 -3
  13. package/Cameras/Inputs/flyCameraKeyboardInput.js.map +1 -1
  14. package/Cameras/Inputs/followCameraKeyboardMoveInput.js +2 -2
  15. package/Cameras/Inputs/followCameraKeyboardMoveInput.js.map +1 -1
  16. package/Cameras/Inputs/freeCameraKeyboardMoveInput.js +3 -3
  17. package/Cameras/Inputs/freeCameraKeyboardMoveInput.js.map +1 -1
  18. package/Cameras/Inputs/freeCameraTouchInput.js +1 -1
  19. package/Cameras/Inputs/freeCameraTouchInput.js.map +1 -1
  20. package/Cameras/VR/vrExperienceHelper.js +1 -1
  21. package/Cameras/VR/vrExperienceHelper.js.map +1 -1
  22. package/Cameras/VR/webVRCamera.js +1 -1
  23. package/Cameras/VR/webVRCamera.js.map +1 -1
  24. package/Cameras/camera.js +3 -3
  25. package/Cameras/camera.js.map +1 -1
  26. package/Engines/Extensions/engine.views.d.ts +13 -0
  27. package/Engines/Extensions/engine.views.js +16 -1
  28. package/Engines/Extensions/engine.views.js.map +1 -1
  29. package/Engines/Processors/shaderCodeCursor.js +2 -1
  30. package/Engines/Processors/shaderCodeCursor.js.map +1 -1
  31. package/Engines/WebGPU/webgpuOcclusionQuery.js +1 -1
  32. package/Engines/WebGPU/webgpuOcclusionQuery.js.map +1 -1
  33. package/Engines/engine.d.ts +2 -10
  34. package/Engines/engine.js +0 -14
  35. package/Engines/engine.js.map +1 -1
  36. package/Engines/engineFeatures.d.ts +2 -0
  37. package/Engines/engineFeatures.js.map +1 -1
  38. package/Engines/nativeEngine.d.ts +6 -2
  39. package/Engines/nativeEngine.js +13 -6
  40. package/Engines/nativeEngine.js.map +1 -1
  41. package/Engines/nullEngine.js +1 -0
  42. package/Engines/nullEngine.js.map +1 -1
  43. package/Engines/thinEngine.d.ts +10 -0
  44. package/Engines/thinEngine.js +26 -6
  45. package/Engines/thinEngine.js.map +1 -1
  46. package/Engines/webgpuEngine.js +1 -0
  47. package/Engines/webgpuEngine.js.map +1 -1
  48. package/Gizmos/axisDragGizmo.d.ts +11 -8
  49. package/Gizmos/axisDragGizmo.js.map +1 -1
  50. package/Gizmos/axisScaleGizmo.d.ts +20 -13
  51. package/Gizmos/axisScaleGizmo.js.map +1 -1
  52. package/Gizmos/boundingBoxGizmo.d.ts +27 -18
  53. package/Gizmos/boundingBoxGizmo.js +6 -0
  54. package/Gizmos/boundingBoxGizmo.js.map +1 -1
  55. package/Gizmos/cameraGizmo.d.ts +8 -5
  56. package/Gizmos/cameraGizmo.js.map +1 -1
  57. package/Gizmos/gizmo.d.ts +48 -6
  58. package/Gizmos/gizmo.js.map +1 -1
  59. package/Gizmos/gizmoManager.d.ts +17 -9
  60. package/Gizmos/gizmoManager.js.map +1 -1
  61. package/Gizmos/lightGizmo.d.ts +12 -7
  62. package/Gizmos/lightGizmo.js.map +1 -1
  63. package/Gizmos/planeDragGizmo.d.ts +10 -8
  64. package/Gizmos/planeDragGizmo.js.map +1 -1
  65. package/Gizmos/planeRotationGizmo.d.ts +23 -14
  66. package/Gizmos/planeRotationGizmo.js.map +1 -1
  67. package/Gizmos/positionGizmo.d.ts +9 -7
  68. package/Gizmos/positionGizmo.js +1 -1
  69. package/Gizmos/positionGizmo.js.map +1 -1
  70. package/Gizmos/rotationGizmo.d.ts +6 -4
  71. package/Gizmos/rotationGizmo.js.map +1 -1
  72. package/Gizmos/scaleGizmo.d.ts +15 -12
  73. package/Gizmos/scaleGizmo.js.map +1 -1
  74. package/Inputs/scene.inputManager.js +0 -3
  75. package/Inputs/scene.inputManager.js.map +1 -1
  76. package/Loading/sceneLoader.js +5 -5
  77. package/Loading/sceneLoader.js.map +1 -1
  78. package/Materials/Node/Blocks/Fragment/TBNBlock.d.ts +12 -0
  79. package/Materials/Node/Blocks/Fragment/TBNBlock.js +50 -0
  80. package/Materials/Node/Blocks/Fragment/TBNBlock.js.map +1 -1
  81. package/Materials/Node/Blocks/Vertex/lightInformationBlock.d.ts +18 -0
  82. package/Materials/Node/Blocks/Vertex/lightInformationBlock.js +85 -1
  83. package/Materials/Node/Blocks/Vertex/lightInformationBlock.js.map +1 -1
  84. package/Materials/Node/Blocks/gradientBlock.js +1 -1
  85. package/Materials/Node/Blocks/gradientBlock.js.map +1 -1
  86. package/Materials/Node/nodeMaterial.d.ts +18 -2
  87. package/Materials/Node/nodeMaterial.js +56 -27
  88. package/Materials/Node/nodeMaterial.js.map +1 -1
  89. package/Materials/Textures/baseTexture.d.ts +2 -1
  90. package/Materials/Textures/baseTexture.js +4 -1
  91. package/Materials/Textures/baseTexture.js.map +1 -1
  92. package/Materials/Textures/prePassRenderTarget.js +1 -1
  93. package/Materials/Textures/prePassRenderTarget.js.map +1 -1
  94. package/Materials/Textures/renderTargetTexture.js +11 -3
  95. package/Materials/Textures/renderTargetTexture.js.map +1 -1
  96. package/Materials/materialDefines.js +3 -1
  97. package/Materials/materialDefines.js.map +1 -1
  98. package/Materials/shaderMaterial.d.ts +10 -1
  99. package/Materials/shaderMaterial.js +10 -1
  100. package/Materials/shaderMaterial.js.map +1 -1
  101. package/Maths/math.color.d.ts +9 -1
  102. package/Maths/math.color.js +13 -1
  103. package/Maths/math.color.js.map +1 -1
  104. package/Maths/math.vector.d.ts +2 -2
  105. package/Maths/math.vector.js +18 -30
  106. package/Maths/math.vector.js.map +1 -1
  107. package/Meshes/Builders/icoSphereBuilder.js +2 -2
  108. package/Meshes/Builders/icoSphereBuilder.js.map +1 -1
  109. package/Meshes/Compression/dracoCompression.js +1 -1
  110. package/Meshes/Compression/dracoCompression.js.map +1 -1
  111. package/Meshes/abstractMesh.js +1 -1
  112. package/Meshes/abstractMesh.js.map +1 -1
  113. package/Meshes/geometry.js +1 -2
  114. package/Meshes/geometry.js.map +1 -1
  115. package/Meshes/thinInstanceMesh.js +5 -0
  116. package/Meshes/thinInstanceMesh.js.map +1 -1
  117. package/Misc/basis.js +3 -0
  118. package/Misc/basis.js.map +1 -1
  119. package/Misc/fileTools.js +2 -2
  120. package/Misc/fileTools.js.map +1 -1
  121. package/Misc/khronosTextureContainer2.js +1 -1
  122. package/Misc/khronosTextureContainer2.js.map +1 -1
  123. package/Misc/smartArray.js +0 -1
  124. package/Misc/smartArray.js.map +1 -1
  125. package/Misc/tools.d.ts +2 -2
  126. package/Misc/tools.js +4 -1
  127. package/Misc/tools.js.map +1 -1
  128. package/Offline/database.js +6 -8
  129. package/Offline/database.js.map +1 -1
  130. package/Particles/computeShaderParticleSystem.js +2 -2
  131. package/Particles/computeShaderParticleSystem.js.map +1 -1
  132. package/Particles/particleHelper.d.ts +12 -1
  133. package/Particles/particleHelper.js +12 -1
  134. package/Particles/particleHelper.js.map +1 -1
  135. package/Particles/particleSystem.js +2 -2
  136. package/Particles/particleSystem.js.map +1 -1
  137. package/Particles/particleSystemSet.js +1 -1
  138. package/Particles/particleSystemSet.js.map +1 -1
  139. package/Particles/solidParticleSystem.d.ts +3 -0
  140. package/Particles/solidParticleSystem.js +3 -0
  141. package/Particles/solidParticleSystem.js.map +1 -1
  142. package/Particles/webgl2ParticleSystem.js +2 -2
  143. package/Particles/webgl2ParticleSystem.js.map +1 -1
  144. package/Physics/Plugins/ammoJSPlugin.d.ts +2 -2
  145. package/Physics/Plugins/ammoJSPlugin.js +29 -29
  146. package/Physics/Plugins/ammoJSPlugin.js.map +1 -1
  147. package/Physics/Plugins/cannonJSPlugin.d.ts +2 -2
  148. package/Physics/Plugins/cannonJSPlugin.js +26 -26
  149. package/Physics/Plugins/cannonJSPlugin.js.map +1 -1
  150. package/Physics/Plugins/oimoJSPlugin.js +9 -11
  151. package/Physics/Plugins/oimoJSPlugin.js.map +1 -1
  152. package/Physics/physicsImpostor.d.ts +6 -6
  153. package/Physics/physicsImpostor.js +7 -6
  154. package/Physics/physicsImpostor.js.map +1 -1
  155. package/PostProcesses/RenderPipeline/Pipelines/standardRenderingPipeline.js +3 -3
  156. package/PostProcesses/RenderPipeline/Pipelines/standardRenderingPipeline.js.map +1 -1
  157. package/Rendering/utilityLayerRenderer.js +1 -1
  158. package/Rendering/utilityLayerRenderer.js.map +1 -1
  159. package/Shaders/sprites.fragment.js +1 -1
  160. package/Shaders/sprites.fragment.js.map +1 -1
  161. package/Sprites/spriteManager.d.ts +10 -1
  162. package/Sprites/spriteManager.js +10 -1
  163. package/Sprites/spriteManager.js.map +1 -1
  164. package/Sprites/spriteRenderer.js +1 -1
  165. package/Sprites/spriteRenderer.js.map +1 -1
  166. package/XR/features/WebXRLayers.js +1 -1
  167. package/XR/features/WebXRLayers.js.map +1 -1
  168. package/assetContainer.js +12 -12
  169. package/assetContainer.js.map +1 -1
  170. package/node.js +1 -1
  171. package/node.js.map +1 -1
  172. package/package.json +1 -1
  173. package/scene.d.ts +2 -0
  174. package/scene.js +15 -8
  175. package/scene.js.map +1 -1
@@ -19,6 +19,10 @@ var LightInformationBlock = /** @class */ (function (_super) {
19
19
  _this.registerOutput("direction", NodeMaterialBlockConnectionPointTypes.Vector3);
20
20
  _this.registerOutput("color", NodeMaterialBlockConnectionPointTypes.Color3);
21
21
  _this.registerOutput("intensity", NodeMaterialBlockConnectionPointTypes.Float);
22
+ _this.registerOutput("shadowBias", NodeMaterialBlockConnectionPointTypes.Float);
23
+ _this.registerOutput("shadowNormalBias", NodeMaterialBlockConnectionPointTypes.Float);
24
+ _this.registerOutput("shadowDepthScale", NodeMaterialBlockConnectionPointTypes.Float);
25
+ _this.registerOutput("shadowDepthRange", NodeMaterialBlockConnectionPointTypes.Vector2);
22
26
  return _this;
23
27
  }
24
28
  /**
@@ -68,11 +72,51 @@ var LightInformationBlock = /** @class */ (function (_super) {
68
72
  enumerable: false,
69
73
  configurable: true
70
74
  });
75
+ Object.defineProperty(LightInformationBlock.prototype, "shadowBias", {
76
+ /**
77
+ * Gets the shadow bias output component
78
+ */
79
+ get: function () {
80
+ return this._outputs[3];
81
+ },
82
+ enumerable: false,
83
+ configurable: true
84
+ });
85
+ Object.defineProperty(LightInformationBlock.prototype, "shadowNormalBias", {
86
+ /**
87
+ * Gets the shadow normal bias output component
88
+ */
89
+ get: function () {
90
+ return this._outputs[4];
91
+ },
92
+ enumerable: false,
93
+ configurable: true
94
+ });
95
+ Object.defineProperty(LightInformationBlock.prototype, "shadowDepthScale", {
96
+ /**
97
+ * Gets the shadow depth scale component
98
+ */
99
+ get: function () {
100
+ return this._outputs[5];
101
+ },
102
+ enumerable: false,
103
+ configurable: true
104
+ });
105
+ Object.defineProperty(LightInformationBlock.prototype, "shadowDepthRange", {
106
+ /**
107
+ * Gets the shadow depth range component
108
+ */
109
+ get: function () {
110
+ return this._outputs[6];
111
+ },
112
+ enumerable: false,
113
+ configurable: true
114
+ });
71
115
  LightInformationBlock.prototype.bind = function (effect, nodeMaterial, mesh) {
72
116
  if (!mesh) {
73
117
  return;
74
118
  }
75
- if (this.light && this.light.isDisposed) {
119
+ if (this.light && this.light.isDisposed()) {
76
120
  this.light = null;
77
121
  }
78
122
  var light = this.light;
@@ -88,6 +132,24 @@ var LightInformationBlock = /** @class */ (function (_super) {
88
132
  }
89
133
  light.transferToNodeMaterialEffect(effect, this._lightDataUniformName);
90
134
  effect.setColor4(this._lightColorUniformName, light.diffuse, light.intensity);
135
+ var generator = light.getShadowGenerator();
136
+ if (this.shadowBias.hasEndpoints || this.shadowNormalBias.hasEndpoints || this.shadowDepthScale.hasEndpoints) {
137
+ if (generator) {
138
+ effect.setFloat3(this._lightShadowUniformName, generator.bias, generator.normalBias, generator.depthScale);
139
+ }
140
+ else {
141
+ effect.setFloat3(this._lightShadowUniformName, 0, 0, 0);
142
+ }
143
+ }
144
+ if (this.shadowDepthRange) {
145
+ if (generator && scene.activeCamera) {
146
+ var shadowLight = light;
147
+ effect.setFloat2(this._lightShadowExtraUniformName, shadowLight.getDepthMinZ(scene.activeCamera), shadowLight.getDepthMinZ(scene.activeCamera) + shadowLight.getDepthMaxZ(scene.activeCamera));
148
+ }
149
+ else {
150
+ effect.setFloat2(this._lightShadowExtraUniformName, 0, 0);
151
+ }
152
+ }
91
153
  };
92
154
  LightInformationBlock.prototype.prepareDefines = function (mesh, nodeMaterial, defines) {
93
155
  if (!defines._areLightsDirty && !this._forcePrepareDefines) {
@@ -104,8 +166,14 @@ var LightInformationBlock = /** @class */ (function (_super) {
104
166
  var direction = this.direction;
105
167
  var color = this.color;
106
168
  var intensity = this.intensity;
169
+ var shadowBias = this.shadowBias;
170
+ var shadowNormalBias = this.shadowNormalBias;
171
+ var shadowDepthScale = this.shadowDepthScale;
172
+ var shadowDepthRange = this.shadowDepthRange;
107
173
  this._lightDataUniformName = state._getFreeVariableName("lightData");
108
174
  this._lightColorUniformName = state._getFreeVariableName("lightColor");
175
+ this._lightShadowUniformName = state._getFreeVariableName("shadowData");
176
+ this._lightShadowExtraUniformName = state._getFreeVariableName("shadowExtraData");
109
177
  this._lightTypeDefineName = state._getFreeDefineName("LIGHTPOINTTYPE");
110
178
  state._emitUniformFromString(this._lightDataUniformName, "vec3");
111
179
  state._emitUniformFromString(this._lightColorUniformName, "vec4");
@@ -116,6 +184,22 @@ var LightInformationBlock = /** @class */ (function (_super) {
116
184
  state.compilationString += "#endif\r\n";
117
185
  state.compilationString += this._declareOutput(color, state) + " = ".concat(this._lightColorUniformName, ".rgb;\r\n");
118
186
  state.compilationString += this._declareOutput(intensity, state) + " = ".concat(this._lightColorUniformName, ".a;\r\n");
187
+ if (shadowBias.hasEndpoints || shadowNormalBias.hasEndpoints || shadowDepthScale.hasEndpoints) {
188
+ state._emitUniformFromString(this._lightShadowUniformName, "vec3");
189
+ if (shadowBias.hasEndpoints) {
190
+ state.compilationString += this._declareOutput(shadowBias, state) + " = ".concat(this._lightShadowUniformName, ".x;\r\n");
191
+ }
192
+ if (shadowNormalBias.hasEndpoints) {
193
+ state.compilationString += this._declareOutput(shadowNormalBias, state) + " = ".concat(this._lightShadowUniformName, ".y;\r\n");
194
+ }
195
+ if (shadowDepthScale.hasEndpoints) {
196
+ state.compilationString += this._declareOutput(shadowDepthScale, state) + " = ".concat(this._lightShadowUniformName, ".z;\r\n");
197
+ }
198
+ }
199
+ if (shadowDepthRange.hasEndpoints) {
200
+ state._emitUniformFromString(this._lightShadowExtraUniformName, "vec2");
201
+ state.compilationString += this._declareOutput(shadowDepthRange, state) + " = ".concat(this._lightShadowUniformName, ";\r\n");
202
+ }
119
203
  return this;
120
204
  };
121
205
  LightInformationBlock.prototype.serialize = function () {
@@ -1 +1 @@
1
- {"version":3,"file":"lightInformationBlock.js","sourceRoot":"","sources":["../../../../../../../../lts/core/generated/Materials/Node/Blocks/Vertex/lightInformationBlock.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,qCAAqC,EAAE,MAAM,mDAAmD,CAAC;AAG1G,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAO3D,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D;;GAEG;AACH;IAA2C,yCAAiB;IAWxD;;;OAGG;IACH,+BAAmB,IAAY;QAA/B,YACI,kBAAM,IAAI,EAAE,wBAAwB,CAAC,MAAM,CAAC,SAM/C;QAJG,KAAI,CAAC,aAAa,CAAC,eAAe,EAAE,qCAAqC,CAAC,OA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AI,CAAC,sBAAsB,YAAS,CAAC;QAE9G,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,yCAAS,GAAhB;QACI,IAAM,mBAAmB,GAAG,iBAAM,SAAS,WAAE,CAAC;QAE9C,IAAI,IAAI,CAAC,KAAK,EAAE;YACZ,mBAAmB,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;SAC/C;QAED,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAEM,4CAAY,GAAnB,UAAoB,mBAAwB,EAAE,KAAY,EAAE,OAAe;QACvE,iBAAM,YAAY,YAAC,mBAAmB,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAExD,IAAI,mBAAmB,CAAC,OAAO,EAAE;YAC7B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,YAAY,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;SAChE;IACL,CAAC;IACL,4BAAC;AAAD,CAAC,AAjJD,CAA2C,iBAAiB,GAiJ3D;;AAED,aAAa,CAAC,+BAA+B,EAAE,qBAAqB,CAAC,CAAC","sourcesContent":["import { NodeMaterialBlock } from \"../../nodeMaterialBlock\";\r\nimport { NodeMaterialBlockConnectionPointTypes } from \"../../Enums/nodeMaterialBlockConnectionPointTypes\";\r\nimport type { NodeMaterialBuildState } from \"../../nodeMaterialBuildState\";\r\nimport type { NodeMaterialConnectionPoint } from \"../../nodeMaterialBlockConnectionPoint\";\r\nimport { NodeMaterialBlockTargets } from \"../../Enums/nodeMaterialBlockTargets\";\r\nimport { RegisterClass } from \"../../../../Misc/typeStore\";\r\nimport type { Nullable } from \"../../../../types\";\r\nimport type { Scene } from \"../../../../scene\";\r\nimport type { Effect } from \"../../../effect\";\r\nimport type { NodeMaterial, NodeMaterialDefines } from \"../../nodeMaterial\";\r\nimport type { Mesh } from \"../../../../Meshes/mesh\";\r\nimport type { Light } from \"../../../../Lights/light\";\r\nimport { PointLight } from \"../../../../Lights/pointLight\";\r\nimport type { AbstractMesh } from \"../../../../Meshes/abstractMesh\";\r\n/**\r\n * Block used to get data information from a light\r\n */\r\nexport class LightInformationBlock extends NodeMaterialBlock {\r\n private _lightDataUniformName: string;\r\n private _lightColorUniformName: string;\r\n private _lightTypeDefineName: string;\r\n private _forcePrepareDefines: boolean;\r\n\r\n /**\r\n * Gets or sets the light associated with this block\r\n */\r\n public light: Nullable<Light>;\r\n\r\n /**\r\n * Creates a new LightInformationBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name, NodeMaterialBlockTargets.Vertex);\r\n\r\n this.registerInput(\"worldPosition\", NodeMaterialBlockConnectionPointTypes.Vector4, false, NodeMaterialBlockTargets.Vertex);\r\n this.registerOutput(\"direction\", NodeMaterialBlockConnectionPointTypes.Vector3);\r\n this.registerOutput(\"color\", NodeMaterialBlockConnectionPointTypes.Color3);\r\n this.registerOutput(\"intensity\", NodeMaterialBlockConnectionPointTypes.Float);\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"LightInformationBlock\";\r\n }\r\n\r\n /**\r\n * Gets the world position input component\r\n */\r\n public get worldPosition(): NodeMaterialConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the direction output component\r\n */\r\n public get direction(): NodeMaterialConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n /**\r\n * Gets the direction output component\r\n */\r\n public get color(): NodeMaterialConnectionPoint {\r\n return this._outputs[1];\r\n }\r\n\r\n /**\r\n * Gets the direction output component\r\n */\r\n public get intensity(): NodeMaterialConnectionPoint {\r\n return this._outputs[2];\r\n }\r\n\r\n public bind(effect: Effect, nodeMaterial: NodeMaterial, mesh?: Mesh) {\r\n if (!mesh) {\r\n return;\r\n }\r\n\r\n if (this.light && this.light.isDisposed) {\r\n this.light = null;\r\n }\r\n\r\n let light = this.light;\r\n const scene = nodeMaterial.getScene();\r\n\r\n if (!light && scene.lights.length) {\r\n light = this.light = scene.lights[0];\r\n this._forcePrepareDefines = true;\r\n }\r\n\r\n if (!light || !light.isEnabled) {\r\n effect.setFloat3(this._lightDataUniformName, 0, 0, 0);\r\n effect.setFloat4(this._lightColorUniformName, 0, 0, 0, 0);\r\n return;\r\n }\r\n\r\n light.transferToNodeMaterialEffect(effect, this._lightDataUniformName);\r\n\r\n effect.setColor4(this._lightColorUniformName, light.diffuse, light.intensity);\r\n }\r\n\r\n public prepareDefines(mesh: AbstractMesh, nodeMaterial: NodeMaterial, defines: NodeMaterialDefines) {\r\n if (!defines._areLightsDirty && !this._forcePrepareDefines) {\r\n return;\r\n }\r\n\r\n this._forcePrepareDefines = false;\r\n\r\n const light = this.light;\r\n defines.setValue(this._lightTypeDefineName, light && light instanceof PointLight ? true : false, true);\r\n }\r\n\r\n protected _buildBlock(state: NodeMaterialBuildState) {\r\n super._buildBlock(state);\r\n\r\n state.sharedData.bindableBlocks.push(this);\r\n state.sharedData.blocksWithDefines.push(this);\r\n\r\n const direction = this.direction;\r\n const color = this.color;\r\n const intensity = this.intensity;\r\n\r\n this._lightDataUniformName = state._getFreeVariableName(\"lightData\");\r\n this._lightColorUniformName = state._getFreeVariableName(\"lightColor\");\r\n this._lightTypeDefineName = state._getFreeDefineName(\"LIGHTPOINTTYPE\");\r\n\r\n state._emitUniformFromString(this._lightDataUniformName, \"vec3\");\r\n state._emitUniformFromString(this._lightColorUniformName, \"vec4\");\r\n\r\n state.compilationString += `#ifdef ${this._lightTypeDefineName}\\r\\n`;\r\n state.compilationString += this._declareOutput(direction, state) + ` = normalize(${this.worldPosition.associatedVariableName}.xyz - ${this._lightDataUniformName});\\r\\n`;\r\n state.compilationString += `#else\\r\\n`;\r\n state.compilationString += this._declareOutput(direction, state) + ` = ${this._lightDataUniformName};\\r\\n`;\r\n state.compilationString += `#endif\\r\\n`;\r\n\r\n state.compilationString += this._declareOutput(color, state) + ` = ${this._lightColorUniformName}.rgb;\\r\\n`;\r\n state.compilationString += this._declareOutput(intensity, state) + ` = ${this._lightColorUniformName}.a;\\r\\n`;\r\n\r\n return this;\r\n }\r\n\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n if (this.light) {\r\n serializationObject.lightId = this.light.id;\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n public _deserialize(serializationObject: any, scene: Scene, rootUrl: string) {\r\n super._deserialize(serializationObject, scene, rootUrl);\r\n\r\n if (serializationObject.lightId) {\r\n this.light = scene.getLightById(serializationObject.lightId);\r\n }\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.LightInformationBlock\", LightInformationBlock);\r\n"]}
1
+ {"version":3,"file":"lightInformationBlock.js","sourceRoot":"","sources":["../../../../../../../../lts/core/generated/Materials/Node/Blocks/Vertex/lightInformationBlock.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,qCAAqC,EAAE,MAAM,mDAAmD,CAAC;AAG1G,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAO3D,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAK3D;;GAEG;AACH;IAA2C,yCAAiB;IAaxD;;;OAGG;IACH,+BAAmB,IAAY;QAA/B,YACI,kBAAM,IAAI,EAAE,wBAAwB,CAAC,MAAM,CAAC,SAU/C;QARG,KAAI,CAAC,aAAa,CAAC,eAAe,EAAE,qCAAqC,CAAC,OAAO,EAAE,KAAK,EAAE,wBAAwB,CAAC,MAAM,CAAC,CAAC;QAC3H,KAAI,CAAC,cAAc,CAAC,WAAW,EAAE,qCAAqC,CAAC,OAAO,CAAC,CAAC;QAChF,KAAI,CAAC,cAAc,CAAC,OAAO,EAAE,qCAAqC,CAAC,MAAM,CAAC,CAAC;QAC3E,KAAI,CAAC,cAAc,CAAC,WAAW,EAAE,qCAAqC,CAAC,KAAK,CAAC,CAAC;QAC9E,KAAI,C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I,CAAC,uBAAuB,YAAS,CAAC;aACzH;SACJ;QAED,IAAI,gBAAgB,CAAC,YAAY,EAAE;YAC/B,KAAK,CAAC,sBAAsB,CAAC,IAAI,CAAC,4BAA4B,EAAE,MAAM,CAAC,CAAC;YACxE,KAAK,CAAC,iBAAiB,IAAI,IAAI,CAAC,cAAc,CAAC,gBAAgB,EAAE,KAAK,CAAC,GAAG,aAAM,IAAI,CAAC,uBAAuB,UAAO,CAAC;SACvH;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,yCAAS,GAAhB;QACI,IAAM,mBAAmB,GAAG,iBAAM,SAAS,WAAE,CAAC;QAE9C,IAAI,IAAI,CAAC,KAAK,EAAE;YACZ,mBAAmB,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;SAC/C;QAED,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAEM,4CAAY,GAAnB,UAAoB,mBAAwB,EAAE,KAAY,EAAE,OAAe;QACvE,iBAAM,YAAY,YAAC,mBAAmB,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAExD,IAAI,mBAAmB,CAAC,OAAO,EAAE;YAC7B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,YAAY,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;SAChE;IACL,CAAC;IACL,4BAAC;AAAD,CAAC,AAjOD,CAA2C,iBAAiB,GAiO3D;;AAED,aAAa,CAAC,+BAA+B,EAAE,qBAAqB,CAAC,CAAC","sourcesContent":["import { NodeMaterialBlock } from \"../../nodeMaterialBlock\";\r\nimport { NodeMaterialBlockConnectionPointTypes } from \"../../Enums/nodeMaterialBlockConnectionPointTypes\";\r\nimport type { NodeMaterialBuildState } from \"../../nodeMaterialBuildState\";\r\nimport type { NodeMaterialConnectionPoint } from \"../../nodeMaterialBlockConnectionPoint\";\r\nimport { NodeMaterialBlockTargets } from \"../../Enums/nodeMaterialBlockTargets\";\r\nimport { RegisterClass } from \"../../../../Misc/typeStore\";\r\nimport type { Nullable } from \"../../../../types\";\r\nimport type { Scene } from \"../../../../scene\";\r\nimport type { Effect } from \"../../../effect\";\r\nimport type { NodeMaterial, NodeMaterialDefines } from \"../../nodeMaterial\";\r\nimport type { Mesh } from \"../../../../Meshes/mesh\";\r\nimport type { Light } from \"../../../../Lights/light\";\r\nimport { PointLight } from \"../../../../Lights/pointLight\";\r\nimport type { AbstractMesh } from \"../../../../Meshes/abstractMesh\";\r\nimport type { ShadowGenerator } from \"../../../../Lights/Shadows/shadowGenerator\";\r\nimport type { ShadowLight } from \"../../../../Lights\";\r\n\r\n/**\r\n * Block used to get data information from a light\r\n */\r\nexport class LightInformationBlock extends NodeMaterialBlock {\r\n private _lightDataUniformName: string;\r\n private _lightColorUniformName: string;\r\n private _lightShadowUniformName: string;\r\n private _lightShadowExtraUniformName: string;\r\n private _lightTypeDefineName: string;\r\n private _forcePrepareDefines: boolean;\r\n\r\n /**\r\n * Gets or sets the light associated with this block\r\n */\r\n public light: Nullable<Light>;\r\n\r\n /**\r\n * Creates a new LightInformationBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name, NodeMaterialBlockTargets.Vertex);\r\n\r\n this.registerInput(\"worldPosition\", NodeMaterialBlockConnectionPointTypes.Vector4, false, NodeMaterialBlockTargets.Vertex);\r\n this.registerOutput(\"direction\", NodeMaterialBlockConnectionPointTypes.Vector3);\r\n this.registerOutput(\"color\", NodeMaterialBlockConnectionPointTypes.Color3);\r\n this.registerOutput(\"intensity\", NodeMaterialBlockConnectionPointTypes.Float);\r\n this.registerOutput(\"shadowBias\", NodeMaterialBlockConnectionPointTypes.Float);\r\n this.registerOutput(\"shadowNormalBias\", NodeMaterialBlockConnectionPointTypes.Float);\r\n this.registerOutput(\"shadowDepthScale\", NodeMaterialBlockConnectionPointTypes.Float);\r\n this.registerOutput(\"shadowDepthRange\", NodeMaterialBlockConnectionPointTypes.Vector2);\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"LightInformationBlock\";\r\n }\r\n\r\n /**\r\n * Gets the world position input component\r\n */\r\n public get worldPosition(): NodeMaterialConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the direction output component\r\n */\r\n public get direction(): NodeMaterialConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n /**\r\n * Gets the direction output component\r\n */\r\n public get color(): NodeMaterialConnectionPoint {\r\n return this._outputs[1];\r\n }\r\n\r\n /**\r\n * Gets the direction output component\r\n */\r\n public get intensity(): NodeMaterialConnectionPoint {\r\n return this._outputs[2];\r\n }\r\n\r\n /**\r\n * Gets the shadow bias output component\r\n */\r\n public get shadowBias(): NodeMaterialConnectionPoint {\r\n return this._outputs[3];\r\n }\r\n\r\n /**\r\n * Gets the shadow normal bias output component\r\n */\r\n public get shadowNormalBias(): NodeMaterialConnectionPoint {\r\n return this._outputs[4];\r\n }\r\n\r\n /**\r\n * Gets the shadow depth scale component\r\n */\r\n public get shadowDepthScale(): NodeMaterialConnectionPoint {\r\n return this._outputs[5];\r\n }\r\n\r\n /**\r\n * Gets the shadow depth range component\r\n */\r\n public get shadowDepthRange(): NodeMaterialConnectionPoint {\r\n return this._outputs[6];\r\n }\r\n\r\n public bind(effect: Effect, nodeMaterial: NodeMaterial, mesh?: Mesh) {\r\n if (!mesh) {\r\n return;\r\n }\r\n\r\n if (this.light && this.light.isDisposed()) {\r\n this.light = null;\r\n }\r\n\r\n let light = this.light;\r\n const scene = nodeMaterial.getScene();\r\n\r\n if (!light && scene.lights.length) {\r\n light = this.light = scene.lights[0];\r\n this._forcePrepareDefines = true;\r\n }\r\n\r\n if (!light || !light.isEnabled) {\r\n effect.setFloat3(this._lightDataUniformName, 0, 0, 0);\r\n effect.setFloat4(this._lightColorUniformName, 0, 0, 0, 0);\r\n return;\r\n }\r\n\r\n light.transferToNodeMaterialEffect(effect, this._lightDataUniformName);\r\n\r\n effect.setColor4(this._lightColorUniformName, light.diffuse, light.intensity);\r\n\r\n const generator = light.getShadowGenerator() as ShadowGenerator;\r\n if (this.shadowBias.hasEndpoints || this.shadowNormalBias.hasEndpoints || this.shadowDepthScale.hasEndpoints) {\r\n if (generator) {\r\n effect.setFloat3(this._lightShadowUniformName, generator.bias, generator.normalBias, generator.depthScale);\r\n } else {\r\n effect.setFloat3(this._lightShadowUniformName, 0, 0, 0);\r\n }\r\n }\r\n\r\n if (this.shadowDepthRange) {\r\n if (generator && scene.activeCamera) {\r\n const shadowLight = light as ShadowLight;\r\n effect.setFloat2(\r\n this._lightShadowExtraUniformName,\r\n shadowLight.getDepthMinZ(scene.activeCamera),\r\n shadowLight.getDepthMinZ(scene.activeCamera) + shadowLight.getDepthMaxZ(scene.activeCamera)\r\n );\r\n } else {\r\n effect.setFloat2(this._lightShadowExtraUniformName, 0, 0);\r\n }\r\n }\r\n }\r\n\r\n public prepareDefines(mesh: AbstractMesh, nodeMaterial: NodeMaterial, defines: NodeMaterialDefines) {\r\n if (!defines._areLightsDirty && !this._forcePrepareDefines) {\r\n return;\r\n }\r\n\r\n this._forcePrepareDefines = false;\r\n\r\n const light = this.light;\r\n defines.setValue(this._lightTypeDefineName, light && light instanceof PointLight ? true : false, true);\r\n }\r\n\r\n protected _buildBlock(state: NodeMaterialBuildState) {\r\n super._buildBlock(state);\r\n\r\n state.sharedData.bindableBlocks.push(this);\r\n state.sharedData.blocksWithDefines.push(this);\r\n\r\n const direction = this.direction;\r\n const color = this.color;\r\n const intensity = this.intensity;\r\n const shadowBias = this.shadowBias;\r\n const shadowNormalBias = this.shadowNormalBias;\r\n const shadowDepthScale = this.shadowDepthScale;\r\n const shadowDepthRange = this.shadowDepthRange;\r\n\r\n this._lightDataUniformName = state._getFreeVariableName(\"lightData\");\r\n this._lightColorUniformName = state._getFreeVariableName(\"lightColor\");\r\n this._lightShadowUniformName = state._getFreeVariableName(\"shadowData\");\r\n this._lightShadowExtraUniformName = state._getFreeVariableName(\"shadowExtraData\");\r\n this._lightTypeDefineName = state._getFreeDefineName(\"LIGHTPOINTTYPE\");\r\n\r\n state._emitUniformFromString(this._lightDataUniformName, \"vec3\");\r\n state._emitUniformFromString(this._lightColorUniformName, \"vec4\");\r\n\r\n state.compilationString += `#ifdef ${this._lightTypeDefineName}\\r\\n`;\r\n state.compilationString += this._declareOutput(direction, state) + ` = normalize(${this.worldPosition.associatedVariableName}.xyz - ${this._lightDataUniformName});\\r\\n`;\r\n state.compilationString += `#else\\r\\n`;\r\n state.compilationString += this._declareOutput(direction, state) + ` = ${this._lightDataUniformName};\\r\\n`;\r\n state.compilationString += `#endif\\r\\n`;\r\n\r\n state.compilationString += this._declareOutput(color, state) + ` = ${this._lightColorUniformName}.rgb;\\r\\n`;\r\n state.compilationString += this._declareOutput(intensity, state) + ` = ${this._lightColorUniformName}.a;\\r\\n`;\r\n\r\n if (shadowBias.hasEndpoints || shadowNormalBias.hasEndpoints || shadowDepthScale.hasEndpoints) {\r\n state._emitUniformFromString(this._lightShadowUniformName, \"vec3\");\r\n if (shadowBias.hasEndpoints) {\r\n state.compilationString += this._declareOutput(shadowBias, state) + ` = ${this._lightShadowUniformName}.x;\\r\\n`;\r\n }\r\n if (shadowNormalBias.hasEndpoints) {\r\n state.compilationString += this._declareOutput(shadowNormalBias, state) + ` = ${this._lightShadowUniformName}.y;\\r\\n`;\r\n }\r\n if (shadowDepthScale.hasEndpoints) {\r\n state.compilationString += this._declareOutput(shadowDepthScale, state) + ` = ${this._lightShadowUniformName}.z;\\r\\n`;\r\n }\r\n }\r\n\r\n if (shadowDepthRange.hasEndpoints) {\r\n state._emitUniformFromString(this._lightShadowExtraUniformName, \"vec2\");\r\n state.compilationString += this._declareOutput(shadowDepthRange, state) + ` = ${this._lightShadowUniformName};\\r\\n`;\r\n }\r\n\r\n return this;\r\n }\r\n\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n if (this.light) {\r\n serializationObject.lightId = this.light.id;\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n public _deserialize(serializationObject: any, scene: Scene, rootUrl: string) {\r\n super._deserialize(serializationObject, scene, rootUrl);\r\n\r\n if (serializationObject.lightId) {\r\n this.light = scene.getLightById(serializationObject.lightId);\r\n }\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.LightInformationBlock\", LightInformationBlock);\r\n"]}
@@ -156,7 +156,7 @@ var GradientBlock = /** @class */ (function (_super) {
156
156
  };
157
157
  GradientBlock.prototype._deserialize = function (serializationObject, scene, rootUrl) {
158
158
  _super.prototype._deserialize.call(this, serializationObject, scene, rootUrl);
159
- this.colorSteps = [];
159
+ this.colorSteps.length = 0;
160
160
  for (var _i = 0, _a = serializationObject.colorSteps; _i < _a.length; _i++) {
161
161
  var step = _a[_i];
162
162
  this.colorSteps.push(new GradientBlockColorStep(step.step, new Color3(step.color.r, step.color.g, step.color.b)));
@@ -1 +1 @@
1
- {"version":3,"file":"gradientBlock.js","sourceRoot":"","sources":["../../../../../../../lts/core/generated/Materials/Node/Blocks/gradientBlock.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,qCAAqC,EAAE,MAAM,gDAAgD,CAAC;AAGvG,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD;;GAEG;AACH;IAgCI;;;;OAIG;IACH,gCAAmB,IAAY,EAAE,KAAa;QAC1C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAnCD,sBAAW,wCAAI;QAHf;;WAEG;aACH;YACI,OAAO,IAAI,CAAC,KAAK,CAAC;QACtB,CAAC;QAED;;WAEG;aACH,U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C,UAAU,IAAI,UAAG,IAAI,CAAC,iBAAiB,0BAAuB,CAAC;QAE/D,KAAwB,UAAe,EAAf,KAAA,IAAI,CAAC,UAAU,EAAf,cAAe,EAAf,IAAe,EAAE;YAApC,IAAM,SAAS,SAAA;YAChB,UAAU,IAAI,UAAG,IAAI,CAAC,iBAAiB,iEAAuD,SAAS,CAAC,IAAI,kCAAwB,SAAS,CAAC,KAAK,CAAC,CAAC,eAAK,SAAS,CAAC,KAAK,CAAC,CAAC,eAAK,SAAS,CAAC,KAAK,CAAC,CAAC,aAAU,CAAC;SAC/M;QAED,OAAO,UAAU,CAAC;IACtB,CAAC;IACL,oBAAC;AAAD,CAAC,AApID,CAAmC,iBAAiB,GAoInD;;AAED,aAAa,CAAC,uBAAuB,EAAE,aAAa,CAAC,CAAC","sourcesContent":["import { NodeMaterialBlock } from \"../nodeMaterialBlock\";\r\nimport { NodeMaterialBlockConnectionPointTypes } from \"../Enums/nodeMaterialBlockConnectionPointTypes\";\r\nimport type { NodeMaterialBuildState } from \"../nodeMaterialBuildState\";\r\nimport type { NodeMaterialConnectionPoint } from \"../nodeMaterialBlockConnectionPoint\";\r\nimport { NodeMaterialBlockTargets } from \"../Enums/nodeMaterialBlockTargets\";\r\nimport { RegisterClass } from \"../../../Misc/typeStore\";\r\nimport { Color3 } from \"../../../Maths/math.color\";\r\nimport type { Scene } from \"../../../scene\";\r\nimport { Observable } from \"../../../Misc/observable\";\r\n\r\n/**\r\n * Class used to store a color step for the GradientBlock\r\n */\r\nexport class GradientBlockColorStep {\r\n private _step: number;\r\n /**\r\n * Gets value indicating which step this color is associated with (between 0 and 1)\r\n */\r\n public get step(): number {\r\n return this._step;\r\n }\r\n\r\n /**\r\n * Sets a value indicating which step this color is associated with (between 0 and 1)\r\n */\r\n public set step(val: number) {\r\n this._step = val;\r\n }\r\n\r\n private _color: Color3;\r\n\r\n /**\r\n * Gets the color associated with this step\r\n */\r\n public get color(): Color3 {\r\n return this._color;\r\n }\r\n\r\n /**\r\n * Sets the color associated with this step\r\n */\r\n public set color(val: Color3) {\r\n this._color = val;\r\n }\r\n\r\n /**\r\n * Creates a new GradientBlockColorStep\r\n * @param step defines a value indicating which step this color is associated with (between 0 and 1)\r\n * @param color defines the color associated with this step\r\n */\r\n public constructor(step: number, color: Color3) {\r\n this.step = step;\r\n this.color = color;\r\n }\r\n}\r\n\r\n/**\r\n * Block used to return a color from a gradient based on an input value between 0 and 1\r\n */\r\nexport class GradientBlock extends NodeMaterialBlock {\r\n /**\r\n * Gets or sets the list of color steps\r\n */\r\n public colorSteps: GradientBlockColorStep[] = [new GradientBlockColorStep(0, Color3.Black()), new GradientBlockColorStep(1.0, Color3.White())];\r\n\r\n /** Gets an observable raised when the value is changed */\r\n public onValueChangedObservable = new Observable<GradientBlock>();\r\n\r\n /** calls observable when the value is changed*/\r\n public colorStepsUpdated() {\r\n this.onValueChangedObservable.notifyObservers(this);\r\n }\r\n /**\r\n * Creates a new GradientBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name, NodeMaterialBlockTargets.Neutral);\r\n\r\n this.registerInput(\"gradient\", NodeMaterialBlockConnectionPointTypes.Float);\r\n this.registerOutput(\"output\", NodeMaterialBlockConnectionPointTypes.Color3);\r\n\r\n this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector2);\r\n this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector3);\r\n this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector4);\r\n this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Color3);\r\n this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Color4);\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"GradientBlock\";\r\n }\r\n\r\n /**\r\n * Gets the gradient input component\r\n */\r\n public get gradient(): NodeMaterialConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the output component\r\n */\r\n public get output(): NodeMaterialConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n private _writeColorConstant(index: number) {\r\n const step = this.colorSteps[index];\r\n return `vec3(${step.color.r}, ${step.color.g}, ${step.color.b})`;\r\n }\r\n\r\n protected _buildBlock(state: NodeMaterialBuildState) {\r\n super._buildBlock(state);\r\n\r\n const output = this._outputs[0];\r\n\r\n if (!this.colorSteps.length || !this.gradient.connectedPoint) {\r\n state.compilationString += this._declareOutput(output, state) + ` = vec3(0., 0., 0.);\\r\\n`;\r\n return;\r\n }\r\n\r\n const tempColor = state._getFreeVariableName(\"gradientTempColor\");\r\n const tempPosition = state._getFreeVariableName(\"gradientTempPosition\");\r\n\r\n state.compilationString += `vec3 ${tempColor} = ${this._writeColorConstant(0)};\\r\\n`;\r\n state.compilationString += `float ${tempPosition};\\r\\n`;\r\n\r\n let gradientSource = this.gradient.associatedVariableName;\r\n\r\n if (this.gradient.connectedPoint!.type !== NodeMaterialBlockConnectionPointTypes.Float) {\r\n gradientSource += \".x\";\r\n }\r\n\r\n for (let index = 1; index < this.colorSteps.length; index++) {\r\n const step = this.colorSteps[index];\r\n const previousStep = this.colorSteps[index - 1];\r\n state.compilationString += `${tempPosition} = clamp((${gradientSource} - ${state._emitFloat(previousStep.step)}) / (${state._emitFloat(\r\n step.step\r\n )} - ${state._emitFloat(previousStep.step)}), 0.0, 1.0) * step(${state._emitFloat(index)}, ${state._emitFloat(this.colorSteps.length - 1)});\\r\\n`;\r\n state.compilationString += `${tempColor} = mix(${tempColor}, ${this._writeColorConstant(index)}, ${tempPosition});\\r\\n`;\r\n }\r\n state.compilationString += this._declareOutput(output, state) + ` = ${tempColor};\\r\\n`;\r\n\r\n return this;\r\n }\r\n\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.colorSteps = [];\r\n\r\n for (const step of this.colorSteps) {\r\n serializationObject.colorSteps.push({\r\n step: step.step,\r\n color: {\r\n r: step.color.r,\r\n g: step.color.g,\r\n b: step.color.b,\r\n },\r\n });\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n public _deserialize(serializationObject: any, scene: Scene, rootUrl: string) {\r\n super._deserialize(serializationObject, scene, rootUrl);\r\n\r\n this.colorSteps = [];\r\n\r\n for (const step of serializationObject.colorSteps) {\r\n this.colorSteps.push(new GradientBlockColorStep(step.step, new Color3(step.color.r, step.color.g, step.color.b)));\r\n }\r\n }\r\n\r\n protected _dumpPropertiesCode() {\r\n let codeString = super._dumpPropertiesCode();\r\n\r\n codeString += `${this._codeVariableName}.colorSteps = [];\\r\\n`;\r\n\r\n for (const colorStep of this.colorSteps) {\r\n codeString += `${this._codeVariableName}.colorSteps.push(new BABYLON.GradientBlockColorStep(${colorStep.step}, new BABYLON.Color3(${colorStep.color.r}, ${colorStep.color.g}, ${colorStep.color.b})));\\r\\n`;\r\n }\r\n\r\n return codeString;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.GradientBlock\", GradientBlock);\r\n"]}
1
+ {"version":3,"file":"gradientBlock.js","sourceRoot":"","sources":["../../../../../../../lts/core/generated/Materials/Node/Blocks/gradientBlock.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,qCAAqC,EAAE,MAAM,gDAAgD,CAAC;AAGvG,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD;;GAEG;AACH;IAgCI;;;;OAIG;IACH,gCAAmB,IAAY,EAAE,KAAa;QAC1C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GA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AAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SACrH;IACL,CAAC;IAES,2CAAmB,GAA7B;QACI,IAAI,UAAU,GAAG,iBAAM,mBAAmB,WAAE,CAAC;QAE7C,UAAU,IAAI,UAAG,IAAI,CAAC,iBAAiB,0BAAuB,CAAC;QAE/D,KAAwB,UAAe,EAAf,KAAA,IAAI,CAAC,UAAU,EAAf,cAAe,EAAf,IAAe,EAAE;YAApC,IAAM,SAAS,SAAA;YAChB,UAAU,IAAI,UAAG,IAAI,CAAC,iBAAiB,iEAAuD,SAAS,CAAC,IAAI,kCAAwB,SAAS,CAAC,KAAK,CAAC,CAAC,eAAK,SAAS,CAAC,KAAK,CAAC,CAAC,eAAK,SAAS,CAAC,KAAK,CAAC,CAAC,aAAU,CAAC;SAC/M;QAED,OAAO,UAAU,CAAC;IACtB,CAAC;IACL,oBAAC;AAAD,CAAC,AApID,CAAmC,iBAAiB,GAoInD;;AAED,aAAa,CAAC,uBAAuB,EAAE,aAAa,CAAC,CAAC","sourcesContent":["import { NodeMaterialBlock } from \"../nodeMaterialBlock\";\r\nimport { NodeMaterialBlockConnectionPointTypes } from \"../Enums/nodeMaterialBlockConnectionPointTypes\";\r\nimport type { NodeMaterialBuildState } from \"../nodeMaterialBuildState\";\r\nimport type { NodeMaterialConnectionPoint } from \"../nodeMaterialBlockConnectionPoint\";\r\nimport { NodeMaterialBlockTargets } from \"../Enums/nodeMaterialBlockTargets\";\r\nimport { RegisterClass } from \"../../../Misc/typeStore\";\r\nimport { Color3 } from \"../../../Maths/math.color\";\r\nimport type { Scene } from \"../../../scene\";\r\nimport { Observable } from \"../../../Misc/observable\";\r\n\r\n/**\r\n * Class used to store a color step for the GradientBlock\r\n */\r\nexport class GradientBlockColorStep {\r\n private _step: number;\r\n /**\r\n * Gets value indicating which step this color is associated with (between 0 and 1)\r\n */\r\n public get step(): number {\r\n return this._step;\r\n }\r\n\r\n /**\r\n * Sets a value indicating which step this color is associated with (between 0 and 1)\r\n */\r\n public set step(val: number) {\r\n this._step = val;\r\n }\r\n\r\n private _color: Color3;\r\n\r\n /**\r\n * Gets the color associated with this step\r\n */\r\n public get color(): Color3 {\r\n return this._color;\r\n }\r\n\r\n /**\r\n * Sets the color associated with this step\r\n */\r\n public set color(val: Color3) {\r\n this._color = val;\r\n }\r\n\r\n /**\r\n * Creates a new GradientBlockColorStep\r\n * @param step defines a value indicating which step this color is associated with (between 0 and 1)\r\n * @param color defines the color associated with this step\r\n */\r\n public constructor(step: number, color: Color3) {\r\n this.step = step;\r\n this.color = color;\r\n }\r\n}\r\n\r\n/**\r\n * Block used to return a color from a gradient based on an input value between 0 and 1\r\n */\r\nexport class GradientBlock extends NodeMaterialBlock {\r\n /**\r\n * Gets or sets the list of color steps\r\n */\r\n public colorSteps: GradientBlockColorStep[] = [new GradientBlockColorStep(0, Color3.Black()), new GradientBlockColorStep(1.0, Color3.White())];\r\n\r\n /** Gets an observable raised when the value is changed */\r\n public onValueChangedObservable = new Observable<GradientBlock>();\r\n\r\n /** calls observable when the value is changed*/\r\n public colorStepsUpdated() {\r\n this.onValueChangedObservable.notifyObservers(this);\r\n }\r\n /**\r\n * Creates a new GradientBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name, NodeMaterialBlockTargets.Neutral);\r\n\r\n this.registerInput(\"gradient\", NodeMaterialBlockConnectionPointTypes.Float);\r\n this.registerOutput(\"output\", NodeMaterialBlockConnectionPointTypes.Color3);\r\n\r\n this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector2);\r\n this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector3);\r\n this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector4);\r\n this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Color3);\r\n this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Color4);\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"GradientBlock\";\r\n }\r\n\r\n /**\r\n * Gets the gradient input component\r\n */\r\n public get gradient(): NodeMaterialConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the output component\r\n */\r\n public get output(): NodeMaterialConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n private _writeColorConstant(index: number) {\r\n const step = this.colorSteps[index];\r\n return `vec3(${step.color.r}, ${step.color.g}, ${step.color.b})`;\r\n }\r\n\r\n protected _buildBlock(state: NodeMaterialBuildState) {\r\n super._buildBlock(state);\r\n\r\n const output = this._outputs[0];\r\n\r\n if (!this.colorSteps.length || !this.gradient.connectedPoint) {\r\n state.compilationString += this._declareOutput(output, state) + ` = vec3(0., 0., 0.);\\r\\n`;\r\n return;\r\n }\r\n\r\n const tempColor = state._getFreeVariableName(\"gradientTempColor\");\r\n const tempPosition = state._getFreeVariableName(\"gradientTempPosition\");\r\n\r\n state.compilationString += `vec3 ${tempColor} = ${this._writeColorConstant(0)};\\r\\n`;\r\n state.compilationString += `float ${tempPosition};\\r\\n`;\r\n\r\n let gradientSource = this.gradient.associatedVariableName;\r\n\r\n if (this.gradient.connectedPoint!.type !== NodeMaterialBlockConnectionPointTypes.Float) {\r\n gradientSource += \".x\";\r\n }\r\n\r\n for (let index = 1; index < this.colorSteps.length; index++) {\r\n const step = this.colorSteps[index];\r\n const previousStep = this.colorSteps[index - 1];\r\n state.compilationString += `${tempPosition} = clamp((${gradientSource} - ${state._emitFloat(previousStep.step)}) / (${state._emitFloat(\r\n step.step\r\n )} - ${state._emitFloat(previousStep.step)}), 0.0, 1.0) * step(${state._emitFloat(index)}, ${state._emitFloat(this.colorSteps.length - 1)});\\r\\n`;\r\n state.compilationString += `${tempColor} = mix(${tempColor}, ${this._writeColorConstant(index)}, ${tempPosition});\\r\\n`;\r\n }\r\n state.compilationString += this._declareOutput(output, state) + ` = ${tempColor};\\r\\n`;\r\n\r\n return this;\r\n }\r\n\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.colorSteps = [];\r\n\r\n for (const step of this.colorSteps) {\r\n serializationObject.colorSteps.push({\r\n step: step.step,\r\n color: {\r\n r: step.color.r,\r\n g: step.color.g,\r\n b: step.color.b,\r\n },\r\n });\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n public _deserialize(serializationObject: any, scene: Scene, rootUrl: string) {\r\n super._deserialize(serializationObject, scene, rootUrl);\r\n\r\n this.colorSteps.length = 0;\r\n\r\n for (const step of serializationObject.colorSteps) {\r\n this.colorSteps.push(new GradientBlockColorStep(step.step, new Color3(step.color.r, step.color.g, step.color.b)));\r\n }\r\n }\r\n\r\n protected _dumpPropertiesCode() {\r\n let codeString = super._dumpPropertiesCode();\r\n\r\n codeString += `${this._codeVariableName}.colorSteps = [];\\r\\n`;\r\n\r\n for (const colorStep of this.colorSteps) {\r\n codeString += `${this._codeVariableName}.colorSteps.push(new BABYLON.GradientBlockColorStep(${colorStep.step}, new BABYLON.Color3(${colorStep.color.r}, ${colorStep.color.g}, ${colorStep.color.b})));\\r\\n`;\r\n }\r\n\r\n return codeString;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.GradientBlock\", GradientBlock);\r\n"]}
@@ -26,6 +26,7 @@ import { NodeMaterialModes } from "./Enums/nodeMaterialModes";
26
26
  import type { IParticleSystem } from "../../Particles/IParticleSystem";
27
27
  import { ProceduralTexture } from "../Textures/Procedurals/proceduralTexture";
28
28
  import type { ImageSourceBlock } from "./Blocks/Dual/imageSourceBlock";
29
+ import type { Material } from "../material";
29
30
  /**
30
31
  * Interface used to configure the node material editor
31
32
  */
@@ -318,6 +319,11 @@ export declare class NodeMaterial extends PushMaterial {
318
319
  * @param onError defines a function to call when the effect creation has failed
319
320
  */
320
321
  createEffectForParticles(particleSystem: IParticleSystem, onCompiled?: (effect: Effect) => void, onError?: (effect: Effect, errors: string) => void): void;
322
+ /**
323
+ * Use this material as the shadow depth wrapper of a target material
324
+ * @param targetMaterial defines the target material
325
+ */
326
+ createAsShadowDepthWrapper(targetMaterial: Material): void;
321
327
  private _processDefines;
322
328
  /**
323
329
  * Get if the submesh is ready to be used and all its information available.
@@ -397,11 +403,12 @@ export declare class NodeMaterial extends PushMaterial {
397
403
  setToDefaultParticle(): void;
398
404
  /**
399
405
  * Loads the current Node Material from a url pointing to a file save by the Node Material Editor
406
+ * @deprecated Please use NodeMaterial.ParseFromFileAsync instead
400
407
  * @param url defines the url to load from
401
408
  * @param rootUrl defines the root URL for nested url in the node material
402
409
  * @returns a promise that will fulfil when the material is fully loaded
403
410
  */
404
- loadAsync(url: string, rootUrl?: string): Promise<void>;
411
+ loadAsync(url: string, rootUrl?: string): Promise<NodeMaterial>;
405
412
  private _gatherBlocks;
406
413
  /**
407
414
  * Generate a string containing the code declaration required to create an equivalent of this material
@@ -421,6 +428,14 @@ export declare class NodeMaterial extends PushMaterial {
421
428
  * @param rootUrl defines the root URL to use to load textures and relative dependencies
422
429
  * @param merge defines whether or not the source must be merged or replace the current content
423
430
  */
431
+ parseSerializedObject(source: any, rootUrl?: string, merge?: boolean): void;
432
+ /**
433
+ * Clear the current graph and load a new one from a serialization object
434
+ * @param source defines the JSON representation of the material
435
+ * @param rootUrl defines the root URL to use to load textures and relative dependencies
436
+ * @param merge defines whether or not the source must be merged or replace the current content
437
+ * @deprecated Please use the parseSerializedObject method instead
438
+ */
424
439
  loadFromSerialization(source: any, rootUrl?: string, merge?: boolean): void;
425
440
  /**
426
441
  * Makes a duplicate of the current material.
@@ -443,9 +458,10 @@ export declare class NodeMaterial extends PushMaterial {
443
458
  * @param scene defines the hosting scene
444
459
  * @param rootUrl defines the root URL for nested url in the node material
445
460
  * @param skipBuild defines whether to build the node material
461
+ * @param targetMaterial defines a material to use instead of creating a new one
446
462
  * @returns a promise that will resolve to the new node material
447
463
  */
448
- static ParseFromFileAsync(name: string, url: string, scene: Scene, rootUrl?: string, skipBuild?: boolean): Promise<NodeMaterial>;
464
+ static ParseFromFileAsync(name: string, url: string, scene: Scene, rootUrl?: string, skipBuild?: boolean, targetMaterial?: NodeMaterial): Promise<NodeMaterial>;
449
465
  /**
450
466
  * Creates a node material from a snippet saved by the node material editor
451
467
  * @param snippetId defines the snippet to load
@@ -1,4 +1,4 @@
1
- import { __assign, __decorate, __extends } from "tslib";
1
+ import { __assign, __awaiter, __decorate, __extends, __generator } from "tslib";
2
2
  import { PushMaterial } from "../pushMaterial.js";
3
3
  import { AbstractMesh } from "../../Meshes/abstractMesh.js";
4
4
  import { Matrix, Vector2 } from "../../Maths/math.vector.js";
@@ -846,6 +846,17 @@ var NodeMaterial = /** @class */ (function (_super) {
846
846
  this._createEffectForParticles(particleSystem, BaseParticleSystem.BLENDMODE_ONEONE, onCompiled, onError);
847
847
  this._createEffectForParticles(particleSystem, BaseParticleSystem.BLENDMODE_MULTIPLY, onCompiled, onError);
848
848
  };
849
+ /**
850
+ * Use this material as the shadow depth wrapper of a target material
851
+ * @param targetMaterial defines the target material
852
+ */
853
+ NodeMaterial.prototype.createAsShadowDepthWrapper = function (targetMaterial) {
854
+ if (this.mode !== NodeMaterialModes.Material) {
855
+ console.log("Incompatible material mode");
856
+ return;
857
+ }
858
+ targetMaterial.shadowDepthWrapper = new BABYLON.ShadowDepthWrapper(this, this.getScene());
859
+ };
849
860
  NodeMaterial.prototype._processDefines = function (mesh, defines, useInstances, subMesh) {
850
861
  var _this = this;
851
862
  if (useInstances === void 0) { useInstances = false; }
@@ -1128,7 +1139,7 @@ var NodeMaterial = /** @class */ (function (_super) {
1128
1139
  var block = _c[_b];
1129
1140
  block.dispose();
1130
1141
  }
1131
- this.attachedBlocks = [];
1142
+ this.attachedBlocks.length = 0;
1132
1143
  this._sharedData = null;
1133
1144
  this._vertexCompilationState = null;
1134
1145
  this._fragmentCompilationState = null;
@@ -1174,9 +1185,9 @@ var NodeMaterial = /** @class */ (function (_super) {
1174
1185
  * Clear the current material
1175
1186
  */
1176
1187
  NodeMaterial.prototype.clear = function () {
1177
- this._vertexOutputNodes = [];
1178
- this._fragmentOutputNodes = [];
1179
- this.attachedBlocks = [];
1188
+ this._vertexOutputNodes.length = 0;
1189
+ this._fragmentOutputNodes.length = 0;
1190
+ this.attachedBlocks.length = 0;
1180
1191
  };
1181
1192
  /**
1182
1193
  * Clear the current material and set it to a default state
@@ -1317,18 +1328,17 @@ var NodeMaterial = /** @class */ (function (_super) {
1317
1328
  };
1318
1329
  /**
1319
1330
  * Loads the current Node Material from a url pointing to a file save by the Node Material Editor
1331
+ * @deprecated Please use NodeMaterial.ParseFromFileAsync instead
1320
1332
  * @param url defines the url to load from
1321
1333
  * @param rootUrl defines the root URL for nested url in the node material
1322
1334
  * @returns a promise that will fulfil when the material is fully loaded
1323
1335
  */
1324
1336
  NodeMaterial.prototype.loadAsync = function (url, rootUrl) {
1325
- var _this = this;
1326
1337
  if (rootUrl === void 0) { rootUrl = ""; }
1327
- return this.getScene()
1328
- ._loadFileAsync(url)
1329
- .then(function (data) {
1330
- var serializationObject = JSON.parse(data);
1331
- _this.loadFromSerialization(serializationObject, rootUrl);
1338
+ return __awaiter(this, void 0, void 0, function () {
1339
+ return __generator(this, function (_a) {
1340
+ return [2 /*return*/, NodeMaterial.ParseFromFileAsync("", url, this.getScene(), rootUrl, true, this)];
1341
+ });
1332
1342
  });
1333
1343
  };
1334
1344
  NodeMaterial.prototype._gatherBlocks = function (rootNode, list) {
@@ -1480,7 +1490,7 @@ var NodeMaterial = /** @class */ (function (_super) {
1480
1490
  * @param rootUrl defines the root URL to use to load textures and relative dependencies
1481
1491
  * @param merge defines whether or not the source must be merged or replace the current content
1482
1492
  */
1483
- NodeMaterial.prototype.loadFromSerialization = function (source, rootUrl, merge) {
1493
+ NodeMaterial.prototype.parseSerializedObject = function (source, rootUrl, merge) {
1484
1494
  var _a;
1485
1495
  if (rootUrl === void 0) { rootUrl = ""; }
1486
1496
  if (merge === void 0) { merge = false; }
@@ -1553,6 +1563,18 @@ var NodeMaterial = /** @class */ (function (_super) {
1553
1563
  this._mode = (_a = source.mode) !== null && _a !== void 0 ? _a : NodeMaterialModes.Material;
1554
1564
  }
1555
1565
  };
1566
+ /**
1567
+ * Clear the current graph and load a new one from a serialization object
1568
+ * @param source defines the JSON representation of the material
1569
+ * @param rootUrl defines the root URL to use to load textures and relative dependencies
1570
+ * @param merge defines whether or not the source must be merged or replace the current content
1571
+ * @deprecated Please use the parseSerializedObject method instead
1572
+ */
1573
+ NodeMaterial.prototype.loadFromSerialization = function (source, rootUrl, merge) {
1574
+ if (rootUrl === void 0) { rootUrl = ""; }
1575
+ if (merge === void 0) { merge = false; }
1576
+ this.parseSerializedObject(source, rootUrl, merge);
1577
+ };
1556
1578
  /**
1557
1579
  * Makes a duplicate of the current material.
1558
1580
  * @param name defines the name to use for the new material
@@ -1565,7 +1587,7 @@ var NodeMaterial = /** @class */ (function (_super) {
1565
1587
  var clone = SerializationHelper.Clone(function () { return new NodeMaterial(name, _this.getScene(), _this.options); }, this);
1566
1588
  clone.id = name;
1567
1589
  clone.name = name;
1568
- clone.loadFromSerialization(serializationObject);
1590
+ clone.parseSerializedObject(serializationObject);
1569
1591
  clone._buildId = this._buildId;
1570
1592
  clone.build(false, !shareEffect);
1571
1593
  return clone;
@@ -1580,7 +1602,7 @@ var NodeMaterial = /** @class */ (function (_super) {
1580
1602
  NodeMaterial.Parse = function (source, scene, rootUrl) {
1581
1603
  if (rootUrl === void 0) { rootUrl = ""; }
1582
1604
  var nodeMaterial = SerializationHelper.Parse(function () { return new NodeMaterial(source.name, scene); }, source, scene, rootUrl);
1583
- nodeMaterial.loadFromSerialization(source, rootUrl);
1605
+ nodeMaterial.parseSerializedObject(source, rootUrl);
1584
1606
  nodeMaterial.build();
1585
1607
  return nodeMaterial;
1586
1608
  };
@@ -1591,22 +1613,29 @@ var NodeMaterial = /** @class */ (function (_super) {
1591
1613
  * @param scene defines the hosting scene
1592
1614
  * @param rootUrl defines the root URL for nested url in the node material
1593
1615
  * @param skipBuild defines whether to build the node material
1616
+ * @param targetMaterial defines a material to use instead of creating a new one
1594
1617
  * @returns a promise that will resolve to the new node material
1595
1618
  */
1596
- NodeMaterial.ParseFromFileAsync = function (name, url, scene, rootUrl, skipBuild) {
1619
+ NodeMaterial.ParseFromFileAsync = function (name, url, scene, rootUrl, skipBuild, targetMaterial) {
1597
1620
  if (rootUrl === void 0) { rootUrl = ""; }
1598
1621
  if (skipBuild === void 0) { skipBuild = false; }
1599
- var material = new NodeMaterial(name, scene);
1600
- return new Promise(function (resolve, reject) {
1601
- return material
1602
- .loadAsync(url, rootUrl)
1603
- .then(function () {
1604
- if (!skipBuild) {
1605
- material.build();
1622
+ return __awaiter(this, void 0, void 0, function () {
1623
+ var material, data, serializationObject;
1624
+ return __generator(this, function (_a) {
1625
+ switch (_a.label) {
1626
+ case 0:
1627
+ material = targetMaterial !== null && targetMaterial !== void 0 ? targetMaterial : new NodeMaterial(name, scene);
1628
+ return [4 /*yield*/, scene._loadFileAsync(url)];
1629
+ case 1:
1630
+ data = _a.sent();
1631
+ serializationObject = JSON.parse(data);
1632
+ material.parseSerializedObject(serializationObject, rootUrl);
1633
+ if (!skipBuild) {
1634
+ material.build();
1635
+ }
1636
+ return [2 /*return*/, material];
1606
1637
  }
1607
- resolve(material);
1608
- })
1609
- .catch(reject);
1638
+ });
1610
1639
  });
1611
1640
  };
1612
1641
  /**
@@ -1624,7 +1653,7 @@ var NodeMaterial = /** @class */ (function (_super) {
1624
1653
  if (rootUrl === void 0) { rootUrl = ""; }
1625
1654
  if (skipBuild === void 0) { skipBuild = false; }
1626
1655
  if (snippetId === "_BLANK") {
1627
- return Promise.resolve(this.CreateDefault("blank", scene));
1656
+ return Promise.resolve(NodeMaterial.CreateDefault("blank", scene));
1628
1657
  }
1629
1658
  return new Promise(function (resolve, reject) {
1630
1659
  var request = new WebRequest();
@@ -1637,7 +1666,7 @@ var NodeMaterial = /** @class */ (function (_super) {
1637
1666
  nodeMaterial = SerializationHelper.Parse(function () { return new NodeMaterial(snippetId, scene); }, serializationObject, scene, rootUrl);
1638
1667
  nodeMaterial.uniqueId = scene.getUniqueId();
1639
1668
  }
1640
- nodeMaterial.loadFromSerialization(serializationObject);
1669
+ nodeMaterial.parseSerializedObject(serializationObject);
1641
1670
  nodeMaterial.snippetId = snippetId;
1642
1671
  try {
1643
1672
  if (!skipBuild) {