@babylonjs/materials 5.0.0-rc.5 → 5.0.0-rc.9

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 (153) hide show
  1. package/cell/cell.fragment.d.ts +17 -17
  2. package/cell/cell.fragment.js +20 -20
  3. package/cell/cell.vertex.d.ts +18 -18
  4. package/cell/cell.vertex.js +21 -21
  5. package/cell/cellMaterial.d.ts +37 -37
  6. package/cell/cellMaterial.js +304 -304
  7. package/cell/index.d.ts +1 -1
  8. package/cell/index.js +1 -1
  9. package/custom/customMaterial.d.ts +69 -69
  10. package/custom/customMaterial.js +216 -216
  11. package/custom/index.d.ts +2 -2
  12. package/custom/index.js +2 -2
  13. package/custom/pbrCustomMaterial.d.ts +71 -71
  14. package/custom/pbrCustomMaterial.js +241 -241
  15. package/fire/fire.fragment.d.ts +11 -11
  16. package/fire/fire.fragment.js +14 -14
  17. package/fire/fire.vertex.d.ts +15 -15
  18. package/fire/fire.vertex.js +18 -18
  19. package/fire/fireMaterial.d.ts +38 -38
  20. package/fire/fireMaterial.js +342 -342
  21. package/fire/index.d.ts +1 -1
  22. package/fire/index.js +1 -1
  23. package/fur/fur.fragment.d.ts +17 -17
  24. package/fur/fur.fragment.js +20 -20
  25. package/fur/fur.vertex.d.ts +18 -18
  26. package/fur/fur.vertex.js +21 -21
  27. package/fur/furMaterial.d.ts +56 -56
  28. package/fur/furMaterial.js +500 -500
  29. package/fur/index.d.ts +1 -1
  30. package/fur/index.js +1 -1
  31. package/gradient/gradient.fragment.d.ts +17 -17
  32. package/gradient/gradient.fragment.js +20 -20
  33. package/gradient/gradient.vertex.d.ts +18 -18
  34. package/gradient/gradient.vertex.js +21 -21
  35. package/gradient/gradientMaterial.d.ts +37 -37
  36. package/gradient/gradientMaterial.js +275 -275
  37. package/gradient/index.d.ts +1 -1
  38. package/gradient/index.js +1 -1
  39. package/grid/grid.fragment.d.ts +8 -8
  40. package/grid/grid.fragment.js +11 -11
  41. package/grid/grid.vertex.d.ts +9 -9
  42. package/grid/grid.vertex.js +12 -12
  43. package/grid/gridMaterial.d.ts +77 -77
  44. package/grid/gridMaterial.js +276 -276
  45. package/grid/index.d.ts +1 -1
  46. package/grid/index.js +1 -1
  47. package/index.d.ts +15 -15
  48. package/index.js +15 -15
  49. package/lava/index.d.ts +1 -1
  50. package/lava/index.js +1 -1
  51. package/lava/lava.fragment.d.ts +17 -17
  52. package/lava/lava.fragment.js +20 -20
  53. package/lava/lava.vertex.d.ts +18 -18
  54. package/lava/lava.vertex.js +21 -21
  55. package/lava/lavaMaterial.d.ts +45 -45
  56. package/lava/lavaMaterial.js +394 -394
  57. package/legacy/legacy-cell.d.ts +1 -1
  58. package/legacy/legacy-cell.js +12 -12
  59. package/legacy/legacy-custom.d.ts +1 -1
  60. package/legacy/legacy-custom.js +12 -12
  61. package/legacy/legacy-fire.d.ts +1 -1
  62. package/legacy/legacy-fire.js +12 -12
  63. package/legacy/legacy-fur.d.ts +1 -1
  64. package/legacy/legacy-fur.js +12 -12
  65. package/legacy/legacy-gradient.d.ts +1 -1
  66. package/legacy/legacy-gradient.js +12 -12
  67. package/legacy/legacy-grid.d.ts +1 -1
  68. package/legacy/legacy-grid.js +12 -12
  69. package/legacy/legacy-lava.d.ts +1 -1
  70. package/legacy/legacy-lava.js +12 -12
  71. package/legacy/legacy-mix.d.ts +1 -1
  72. package/legacy/legacy-mix.js +12 -12
  73. package/legacy/legacy-normal.d.ts +1 -1
  74. package/legacy/legacy-normal.js +12 -12
  75. package/legacy/legacy-shadowOnly.d.ts +1 -1
  76. package/legacy/legacy-shadowOnly.js +12 -12
  77. package/legacy/legacy-simple.d.ts +1 -1
  78. package/legacy/legacy-simple.js +12 -12
  79. package/legacy/legacy-sky.d.ts +1 -1
  80. package/legacy/legacy-sky.js +12 -12
  81. package/legacy/legacy-terrain.d.ts +1 -1
  82. package/legacy/legacy-terrain.js +12 -12
  83. package/legacy/legacy-triPlanar.d.ts +1 -1
  84. package/legacy/legacy-triPlanar.js +12 -12
  85. package/legacy/legacy-water.d.ts +1 -1
  86. package/legacy/legacy-water.js +12 -12
  87. package/legacy/legacy.d.ts +1 -1
  88. package/legacy/legacy.js +15 -15
  89. package/mix/index.d.ts +1 -1
  90. package/mix/index.js +1 -1
  91. package/mix/mix.fragment.d.ts +17 -17
  92. package/mix/mix.fragment.js +20 -20
  93. package/mix/mix.vertex.d.ts +18 -18
  94. package/mix/mix.vertex.js +21 -21
  95. package/mix/mixMaterial.d.ts +65 -65
  96. package/mix/mixMaterial.js +510 -510
  97. package/normal/index.d.ts +1 -1
  98. package/normal/index.js +1 -1
  99. package/normal/normal.fragment.d.ts +17 -17
  100. package/normal/normal.fragment.js +20 -20
  101. package/normal/normal.vertex.d.ts +18 -18
  102. package/normal/normal.vertex.js +21 -21
  103. package/normal/normalMaterial.d.ts +36 -36
  104. package/normal/normalMaterial.js +336 -336
  105. package/package.json +2 -2
  106. package/shadowOnly/index.d.ts +1 -1
  107. package/shadowOnly/index.js +1 -1
  108. package/shadowOnly/shadowOnly.fragment.d.ts +16 -16
  109. package/shadowOnly/shadowOnly.fragment.js +19 -19
  110. package/shadowOnly/shadowOnly.vertex.d.ts +18 -18
  111. package/shadowOnly/shadowOnly.vertex.js +21 -21
  112. package/shadowOnly/shadowOnlyMaterial.d.ts +30 -30
  113. package/shadowOnly/shadowOnlyMaterial.js +254 -254
  114. package/simple/index.d.ts +1 -1
  115. package/simple/index.js +1 -1
  116. package/simple/simple.fragment.d.ts +17 -17
  117. package/simple/simple.fragment.js +20 -20
  118. package/simple/simple.vertex.d.ts +18 -18
  119. package/simple/simple.vertex.js +21 -21
  120. package/simple/simpleMaterial.d.ts +35 -35
  121. package/simple/simpleMaterial.js +295 -295
  122. package/sky/index.d.ts +1 -1
  123. package/sky/index.js +1 -1
  124. package/sky/sky.fragment.d.ts +10 -10
  125. package/sky/sky.fragment.js +13 -13
  126. package/sky/sky.vertex.d.ts +9 -9
  127. package/sky/sky.vertex.js +12 -12
  128. package/sky/skyMaterial.d.ts +146 -146
  129. package/sky/skyMaterial.js +359 -359
  130. package/terrain/index.d.ts +1 -1
  131. package/terrain/index.js +1 -1
  132. package/terrain/terrain.fragment.d.ts +17 -17
  133. package/terrain/terrain.fragment.js +20 -20
  134. package/terrain/terrain.vertex.d.ts +18 -18
  135. package/terrain/terrain.vertex.js +21 -21
  136. package/terrain/terrainMaterial.d.ts +50 -50
  137. package/terrain/terrainMaterial.js +426 -426
  138. package/triPlanar/index.d.ts +1 -1
  139. package/triPlanar/index.js +1 -1
  140. package/triPlanar/triPlanarMaterial.d.ts +49 -49
  141. package/triPlanar/triPlanarMaterial.js +403 -403
  142. package/triPlanar/triplanar.fragment.d.ts +17 -17
  143. package/triPlanar/triplanar.fragment.js +20 -20
  144. package/triPlanar/triplanar.vertex.d.ts +18 -18
  145. package/triPlanar/triplanar.vertex.js +21 -21
  146. package/water/index.d.ts +1 -1
  147. package/water/index.js +1 -1
  148. package/water/water.fragment.d.ts +19 -19
  149. package/water/water.fragment.js +22 -22
  150. package/water/water.vertex.d.ts +20 -20
  151. package/water/water.vertex.js +23 -23
  152. package/water/waterMaterial.d.ts +135 -135
  153. package/water/waterMaterial.js +736 -736
@@ -1,501 +1,501 @@
1
- import { __decorate, __extends } from "tslib";
2
- import { serializeAsVector3, serializeAsTexture, serialize, expandToProperty, serializeAsColor3, SerializationHelper } from "@babylonjs/core/Misc/decorators.js";
3
- import { Vector3 } from "@babylonjs/core/Maths/math.vector.js";
4
- import { Color3 } from "@babylonjs/core/Maths/math.color.js";
5
- import { Tags } from "@babylonjs/core/Misc/tags.js";
6
- import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
7
- import { DynamicTexture } from "@babylonjs/core/Materials/Textures/dynamicTexture.js";
8
- import { MaterialDefines } from "@babylonjs/core/Materials/materialDefines.js";
9
- import { MaterialHelper } from "@babylonjs/core/Materials/materialHelper.js";
10
- import { PushMaterial } from "@babylonjs/core/Materials/pushMaterial.js";
11
- import { MaterialFlags } from "@babylonjs/core/Materials/materialFlags.js";
12
- import { VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
13
- import { Scene } from "@babylonjs/core/scene.js";
14
- import { RegisterClass } from "@babylonjs/core/Misc/typeStore.js";
15
- import { EffectFallbacks } from "@babylonjs/core/Materials/effectFallbacks.js";
16
- import "./fur.fragment.js";
17
- import "./fur.vertex.js";
18
- var FurMaterialDefines = /** @class */ (function (_super) {
19
- __extends(FurMaterialDefines, _super);
20
- function FurMaterialDefines() {
21
- var _this = _super.call(this) || this;
22
- _this.DIFFUSE = false;
23
- _this.HEIGHTMAP = false;
24
- _this.CLIPPLANE = false;
25
- _this.CLIPPLANE2 = false;
26
- _this.CLIPPLANE3 = false;
27
- _this.CLIPPLANE4 = false;
28
- _this.CLIPPLANE5 = false;
29
- _this.CLIPPLANE6 = false;
30
- _this.ALPHATEST = false;
31
- _this.DEPTHPREPASS = false;
32
- _this.POINTSIZE = false;
33
- _this.FOG = false;
34
- _this.NORMAL = false;
35
- _this.UV1 = false;
36
- _this.UV2 = false;
37
- _this.VERTEXCOLOR = false;
38
- _this.VERTEXALPHA = false;
39
- _this.NUM_BONE_INFLUENCERS = 0;
40
- _this.BonesPerMesh = 0;
41
- _this.INSTANCES = false;
42
- _this.INSTANCESCOLOR = false;
43
- _this.HIGHLEVEL = false;
44
- _this.IMAGEPROCESSINGPOSTPROCESS = false;
45
- _this.SKIPFINALCOLORCLAMP = false;
46
- _this.rebuild();
47
- return _this;
48
- }
49
- return FurMaterialDefines;
50
- }(MaterialDefines));
51
- var FurMaterial = /** @class */ (function (_super) {
52
- __extends(FurMaterial, _super);
53
- function FurMaterial(name, scene) {
54
- var _this = _super.call(this, name, scene) || this;
55
- _this.diffuseColor = new Color3(1, 1, 1);
56
- _this.furLength = 1;
57
- _this.furAngle = 0;
58
- _this.furColor = new Color3(0.44, 0.21, 0.02);
59
- _this.furOffset = 0.0;
60
- _this.furSpacing = 12;
61
- _this.furGravity = new Vector3(0, 0, 0);
62
- _this.furSpeed = 100;
63
- _this.furDensity = 20;
64
- _this.furOcclusion = 0.0;
65
- _this._disableLighting = false;
66
- _this._maxSimultaneousLights = 4;
67
- _this.highLevelFur = true;
68
- _this._furTime = 0;
69
- return _this;
70
- }
71
- Object.defineProperty(FurMaterial.prototype, "furTime", {
72
- get: function () {
73
- return this._furTime;
74
- },
75
- set: function (furTime) {
76
- this._furTime = furTime;
77
- },
78
- enumerable: false,
79
- configurable: true
80
- });
81
- FurMaterial.prototype.needAlphaBlending = function () {
82
- return this.alpha < 1.0;
83
- };
84
- FurMaterial.prototype.needAlphaTesting = function () {
85
- return false;
86
- };
87
- FurMaterial.prototype.getAlphaTestTexture = function () {
88
- return null;
89
- };
90
- FurMaterial.prototype.updateFur = function () {
91
- for (var i = 1; i < this._meshes.length; i++) {
92
- var offsetFur = this._meshes[i].material;
93
- offsetFur.furLength = this.furLength;
94
- offsetFur.furAngle = this.furAngle;
95
- offsetFur.furGravity = this.furGravity;
96
- offsetFur.furSpacing = this.furSpacing;
97
- offsetFur.furSpeed = this.furSpeed;
98
- offsetFur.furColor = this.furColor;
99
- offsetFur.diffuseTexture = this.diffuseTexture;
100
- offsetFur.furTexture = this.furTexture;
101
- offsetFur.highLevelFur = this.highLevelFur;
102
- offsetFur.furTime = this.furTime;
103
- offsetFur.furDensity = this.furDensity;
104
- }
105
- };
106
- // Methods
107
- FurMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
108
- if (this.isFrozen) {
109
- if (subMesh.effect && subMesh.effect._wasPreviouslyReady) {
110
- return true;
111
- }
112
- }
113
- if (!subMesh.materialDefines) {
114
- subMesh.materialDefines = new FurMaterialDefines();
115
- }
116
- var defines = subMesh.materialDefines;
117
- var scene = this.getScene();
118
- if (this._isReadyForSubMesh(subMesh)) {
119
- return true;
120
- }
121
- var engine = scene.getEngine();
122
- // Textures
123
- if (defines._areTexturesDirty) {
124
- if (scene.texturesEnabled) {
125
- if (this.diffuseTexture && MaterialFlags.DiffuseTextureEnabled) {
126
- if (!this.diffuseTexture.isReady()) {
127
- return false;
128
- }
129
- else {
130
- defines._needUVs = true;
131
- defines.DIFFUSE = true;
132
- }
133
- }
134
- if (this.heightTexture && engine.getCaps().maxVertexTextureImageUnits) {
135
- if (!this.heightTexture.isReady()) {
136
- return false;
137
- }
138
- else {
139
- defines._needUVs = true;
140
- defines.HEIGHTMAP = true;
141
- }
142
- }
143
- }
144
- }
145
- // High level
146
- if (this.highLevelFur !== defines.HIGHLEVEL) {
147
- defines.HIGHLEVEL = true;
148
- defines.markAsUnprocessed();
149
- }
150
- // Misc.
151
- MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
152
- // Lights
153
- defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
154
- // Values that need to be evaluated on every frame
155
- MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
156
- // Attribs
157
- MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
158
- // Get correct effect
159
- if (defines.isDirty) {
160
- defines.markAsProcessed();
161
- scene.resetCachedMaterial();
162
- // Fallbacks
163
- var fallbacks = new EffectFallbacks();
164
- if (defines.FOG) {
165
- fallbacks.addFallback(1, "FOG");
166
- }
167
- MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
168
- if (defines.NUM_BONE_INFLUENCERS > 0) {
169
- fallbacks.addCPUSkinningFallback(0, mesh);
170
- }
171
- defines.IMAGEPROCESSINGPOSTPROCESS = scene.imageProcessingConfiguration.applyByPostProcess;
172
- //Attributes
173
- var attribs = [VertexBuffer.PositionKind];
174
- if (defines.NORMAL) {
175
- attribs.push(VertexBuffer.NormalKind);
176
- }
177
- if (defines.UV1) {
178
- attribs.push(VertexBuffer.UVKind);
179
- }
180
- if (defines.UV2) {
181
- attribs.push(VertexBuffer.UV2Kind);
182
- }
183
- if (defines.VERTEXCOLOR) {
184
- attribs.push(VertexBuffer.ColorKind);
185
- }
186
- MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
187
- MaterialHelper.PrepareAttributesForInstances(attribs, defines);
188
- // Legacy browser patch
189
- var shaderName = "fur";
190
- var join = defines.toString();
191
- var uniforms = [
192
- "world",
193
- "view",
194
- "viewProjection",
195
- "vEyePosition",
196
- "vLightsType",
197
- "vDiffuseColor",
198
- "vFogInfos",
199
- "vFogColor",
200
- "pointSize",
201
- "vDiffuseInfos",
202
- "mBones",
203
- "vClipPlane",
204
- "vClipPlane2",
205
- "vClipPlane3",
206
- "vClipPlane4",
207
- "vClipPlane5",
208
- "vClipPlane6",
209
- "diffuseMatrix",
210
- "furLength",
211
- "furAngle",
212
- "furColor",
213
- "furOffset",
214
- "furGravity",
215
- "furTime",
216
- "furSpacing",
217
- "furDensity",
218
- "furOcclusion",
219
- ];
220
- var samplers = ["diffuseSampler", "heightTexture", "furTexture"];
221
- var uniformBuffers = new Array();
222
- MaterialHelper.PrepareUniformsAndSamplersList({
223
- uniformsNames: uniforms,
224
- uniformBuffersNames: uniformBuffers,
225
- samplers: samplers,
226
- defines: defines,
227
- maxSimultaneousLights: this.maxSimultaneousLights,
228
- });
229
- subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
230
- attributes: attribs,
231
- uniformsNames: uniforms,
232
- uniformBuffersNames: uniformBuffers,
233
- samplers: samplers,
234
- defines: join,
235
- fallbacks: fallbacks,
236
- onCompiled: this.onCompiled,
237
- onError: this.onError,
238
- indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights },
239
- }, engine), defines, this._materialContext);
240
- }
241
- if (!subMesh.effect || !subMesh.effect.isReady()) {
242
- return false;
243
- }
244
- defines._renderId = scene.getRenderId();
245
- subMesh.effect._wasPreviouslyReady = true;
246
- return true;
247
- };
248
- FurMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
249
- var scene = this.getScene();
250
- var defines = subMesh.materialDefines;
251
- if (!defines) {
252
- return;
253
- }
254
- var effect = subMesh.effect;
255
- if (!effect) {
256
- return;
257
- }
258
- this._activeEffect = effect;
259
- // Matrices
260
- this.bindOnlyWorldMatrix(world);
261
- this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
262
- // Bones
263
- MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
264
- if (scene.getCachedMaterial() !== this) {
265
- // Textures
266
- if (this._diffuseTexture && MaterialFlags.DiffuseTextureEnabled) {
267
- this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
268
- this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
269
- this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
270
- }
271
- if (this._heightTexture) {
272
- this._activeEffect.setTexture("heightTexture", this._heightTexture);
273
- }
274
- // Clip plane
275
- MaterialHelper.BindClipPlane(this._activeEffect, scene);
276
- // Point size
277
- if (this.pointsCloud) {
278
- this._activeEffect.setFloat("pointSize", this.pointSize);
279
- }
280
- scene.bindEyePosition(effect);
281
- }
282
- this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
283
- if (scene.lightsEnabled && !this.disableLighting) {
284
- MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
285
- }
286
- // View
287
- if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
288
- this._activeEffect.setMatrix("view", scene.getViewMatrix());
289
- }
290
- // Fog
291
- MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
292
- this._activeEffect.setFloat("furLength", this.furLength);
293
- this._activeEffect.setFloat("furAngle", this.furAngle);
294
- this._activeEffect.setColor4("furColor", this.furColor, 1.0);
295
- if (this.highLevelFur) {
296
- this._activeEffect.setVector3("furGravity", this.furGravity);
297
- this._activeEffect.setFloat("furOffset", this.furOffset);
298
- this._activeEffect.setFloat("furSpacing", this.furSpacing);
299
- this._activeEffect.setFloat("furDensity", this.furDensity);
300
- this._activeEffect.setFloat("furOcclusion", this.furOcclusion);
301
- this._furTime += this.getScene().getEngine().getDeltaTime() / this.furSpeed;
302
- this._activeEffect.setFloat("furTime", this._furTime);
303
- this._activeEffect.setTexture("furTexture", this.furTexture);
304
- }
305
- this._afterBind(mesh, this._activeEffect);
306
- };
307
- FurMaterial.prototype.getAnimatables = function () {
308
- var results = [];
309
- if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
310
- results.push(this.diffuseTexture);
311
- }
312
- if (this.heightTexture && this.heightTexture.animations && this.heightTexture.animations.length > 0) {
313
- results.push(this.heightTexture);
314
- }
315
- return results;
316
- };
317
- FurMaterial.prototype.getActiveTextures = function () {
318
- var activeTextures = _super.prototype.getActiveTextures.call(this);
319
- if (this._diffuseTexture) {
320
- activeTextures.push(this._diffuseTexture);
321
- }
322
- if (this._heightTexture) {
323
- activeTextures.push(this._heightTexture);
324
- }
325
- return activeTextures;
326
- };
327
- FurMaterial.prototype.hasTexture = function (texture) {
328
- if (_super.prototype.hasTexture.call(this, texture)) {
329
- return true;
330
- }
331
- if (this.diffuseTexture === texture) {
332
- return true;
333
- }
334
- if (this._heightTexture === texture) {
335
- return true;
336
- }
337
- return false;
338
- };
339
- FurMaterial.prototype.dispose = function (forceDisposeEffect) {
340
- if (this.diffuseTexture) {
341
- this.diffuseTexture.dispose();
342
- }
343
- if (this._meshes) {
344
- for (var i = 1; i < this._meshes.length; i++) {
345
- var mat = this._meshes[i].material;
346
- if (mat) {
347
- mat.dispose(forceDisposeEffect);
348
- }
349
- this._meshes[i].dispose();
350
- }
351
- }
352
- _super.prototype.dispose.call(this, forceDisposeEffect);
353
- };
354
- FurMaterial.prototype.clone = function (name) {
355
- var _this = this;
356
- return SerializationHelper.Clone(function () { return new FurMaterial(name, _this.getScene()); }, this);
357
- };
358
- FurMaterial.prototype.serialize = function () {
359
- var serializationObject = _super.prototype.serialize.call(this);
360
- serializationObject.customType = "BABYLON.FurMaterial";
361
- if (this._meshes) {
362
- serializationObject.sourceMeshName = this._meshes[0].name;
363
- serializationObject.quality = this._meshes.length;
364
- }
365
- return serializationObject;
366
- };
367
- FurMaterial.prototype.getClassName = function () {
368
- return "FurMaterial";
369
- };
370
- // Statics
371
- FurMaterial.Parse = function (source, scene, rootUrl) {
372
- var material = SerializationHelper.Parse(function () { return new FurMaterial(source.name, scene); }, source, scene, rootUrl);
373
- if (source.sourceMeshName && material.highLevelFur) {
374
- scene.executeWhenReady(function () {
375
- var sourceMesh = scene.getMeshByName(source.sourceMeshName);
376
- if (sourceMesh) {
377
- var furTexture = FurMaterial.GenerateTexture("Fur Texture", scene);
378
- material.furTexture = furTexture;
379
- FurMaterial.FurifyMesh(sourceMesh, source.quality);
380
- }
381
- });
382
- }
383
- return material;
384
- };
385
- FurMaterial.GenerateTexture = function (name, scene) {
386
- // Generate fur textures
387
- var texture = new DynamicTexture("FurTexture " + name, 256, scene, true);
388
- var context = texture.getContext();
389
- for (var i = 0; i < 20000; ++i) {
390
- context.fillStyle = "rgba(255, " + Math.floor(Math.random() * 255) + ", " + Math.floor(Math.random() * 255) + ", 1)";
391
- context.fillRect(Math.random() * texture.getSize().width, Math.random() * texture.getSize().height, 2, 2);
392
- }
393
- texture.update(false);
394
- texture.wrapU = Texture.WRAP_ADDRESSMODE;
395
- texture.wrapV = Texture.WRAP_ADDRESSMODE;
396
- return texture;
397
- };
398
- // Creates and returns an array of meshes used as shells for the Fur Material
399
- // that can be disposed later in your code
400
- // The quality is in interval [0, 100]
401
- FurMaterial.FurifyMesh = function (sourceMesh, quality) {
402
- var meshes = [sourceMesh];
403
- var mat = sourceMesh.material;
404
- var i;
405
- if (!(mat instanceof FurMaterial)) {
406
- throw "The material of the source mesh must be a Fur Material";
407
- }
408
- for (i = 1; i < quality; i++) {
409
- var offsetFur = new FurMaterial(mat.name + i, sourceMesh.getScene());
410
- sourceMesh.getScene().materials.pop();
411
- Tags.EnableFor(offsetFur);
412
- Tags.AddTagsTo(offsetFur, "furShellMaterial");
413
- offsetFur.furLength = mat.furLength;
414
- offsetFur.furAngle = mat.furAngle;
415
- offsetFur.furGravity = mat.furGravity;
416
- offsetFur.furSpacing = mat.furSpacing;
417
- offsetFur.furSpeed = mat.furSpeed;
418
- offsetFur.furColor = mat.furColor;
419
- offsetFur.diffuseTexture = mat.diffuseTexture;
420
- offsetFur.furOffset = i / quality;
421
- offsetFur.furTexture = mat.furTexture;
422
- offsetFur.highLevelFur = mat.highLevelFur;
423
- offsetFur.furTime = mat.furTime;
424
- offsetFur.furDensity = mat.furDensity;
425
- var offsetMesh = sourceMesh.clone(sourceMesh.name + i);
426
- offsetMesh.material = offsetFur;
427
- offsetMesh.skeleton = sourceMesh.skeleton;
428
- offsetMesh.position = Vector3.Zero();
429
- meshes.push(offsetMesh);
430
- }
431
- for (i = 1; i < meshes.length; i++) {
432
- meshes[i].parent = sourceMesh;
433
- }
434
- sourceMesh.material._meshes = meshes;
435
- return meshes;
436
- };
437
- __decorate([
438
- serializeAsTexture("diffuseTexture")
439
- ], FurMaterial.prototype, "_diffuseTexture", void 0);
440
- __decorate([
441
- expandToProperty("_markAllSubMeshesAsTexturesDirty")
442
- ], FurMaterial.prototype, "diffuseTexture", void 0);
443
- __decorate([
444
- serializeAsTexture("heightTexture")
445
- ], FurMaterial.prototype, "_heightTexture", void 0);
446
- __decorate([
447
- expandToProperty("_markAllSubMeshesAsTexturesDirty")
448
- ], FurMaterial.prototype, "heightTexture", void 0);
449
- __decorate([
450
- serializeAsColor3()
451
- ], FurMaterial.prototype, "diffuseColor", void 0);
452
- __decorate([
453
- serialize()
454
- ], FurMaterial.prototype, "furLength", void 0);
455
- __decorate([
456
- serialize()
457
- ], FurMaterial.prototype, "furAngle", void 0);
458
- __decorate([
459
- serializeAsColor3()
460
- ], FurMaterial.prototype, "furColor", void 0);
461
- __decorate([
462
- serialize()
463
- ], FurMaterial.prototype, "furOffset", void 0);
464
- __decorate([
465
- serialize()
466
- ], FurMaterial.prototype, "furSpacing", void 0);
467
- __decorate([
468
- serializeAsVector3()
469
- ], FurMaterial.prototype, "furGravity", void 0);
470
- __decorate([
471
- serialize()
472
- ], FurMaterial.prototype, "furSpeed", void 0);
473
- __decorate([
474
- serialize()
475
- ], FurMaterial.prototype, "furDensity", void 0);
476
- __decorate([
477
- serialize()
478
- ], FurMaterial.prototype, "furOcclusion", void 0);
479
- __decorate([
480
- serialize("disableLighting")
481
- ], FurMaterial.prototype, "_disableLighting", void 0);
482
- __decorate([
483
- expandToProperty("_markAllSubMeshesAsLightsDirty")
484
- ], FurMaterial.prototype, "disableLighting", void 0);
485
- __decorate([
486
- serialize("maxSimultaneousLights")
487
- ], FurMaterial.prototype, "_maxSimultaneousLights", void 0);
488
- __decorate([
489
- expandToProperty("_markAllSubMeshesAsLightsDirty")
490
- ], FurMaterial.prototype, "maxSimultaneousLights", void 0);
491
- __decorate([
492
- serialize()
493
- ], FurMaterial.prototype, "highLevelFur", void 0);
494
- __decorate([
495
- serialize()
496
- ], FurMaterial.prototype, "furTime", null);
497
- return FurMaterial;
498
- }(PushMaterial));
499
- export { FurMaterial };
500
- RegisterClass("BABYLON.FurMaterial", FurMaterial);
1
+ import { __decorate, __extends } from "tslib";
2
+ import { serializeAsVector3, serializeAsTexture, serialize, expandToProperty, serializeAsColor3, SerializationHelper } from "@babylonjs/core/Misc/decorators.js";
3
+ import { Vector3 } from "@babylonjs/core/Maths/math.vector.js";
4
+ import { Color3 } from "@babylonjs/core/Maths/math.color.js";
5
+ import { Tags } from "@babylonjs/core/Misc/tags.js";
6
+ import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
7
+ import { DynamicTexture } from "@babylonjs/core/Materials/Textures/dynamicTexture.js";
8
+ import { MaterialDefines } from "@babylonjs/core/Materials/materialDefines.js";
9
+ import { MaterialHelper } from "@babylonjs/core/Materials/materialHelper.js";
10
+ import { PushMaterial } from "@babylonjs/core/Materials/pushMaterial.js";
11
+ import { MaterialFlags } from "@babylonjs/core/Materials/materialFlags.js";
12
+ import { VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
13
+ import { Scene } from "@babylonjs/core/scene.js";
14
+ import { RegisterClass } from "@babylonjs/core/Misc/typeStore.js";
15
+ import { EffectFallbacks } from "@babylonjs/core/Materials/effectFallbacks.js";
16
+ import "./fur.fragment";
17
+ import "./fur.vertex";
18
+ var FurMaterialDefines = /** @class */ (function (_super) {
19
+ __extends(FurMaterialDefines, _super);
20
+ function FurMaterialDefines() {
21
+ var _this = _super.call(this) || this;
22
+ _this.DIFFUSE = false;
23
+ _this.HEIGHTMAP = false;
24
+ _this.CLIPPLANE = false;
25
+ _this.CLIPPLANE2 = false;
26
+ _this.CLIPPLANE3 = false;
27
+ _this.CLIPPLANE4 = false;
28
+ _this.CLIPPLANE5 = false;
29
+ _this.CLIPPLANE6 = false;
30
+ _this.ALPHATEST = false;
31
+ _this.DEPTHPREPASS = false;
32
+ _this.POINTSIZE = false;
33
+ _this.FOG = false;
34
+ _this.NORMAL = false;
35
+ _this.UV1 = false;
36
+ _this.UV2 = false;
37
+ _this.VERTEXCOLOR = false;
38
+ _this.VERTEXALPHA = false;
39
+ _this.NUM_BONE_INFLUENCERS = 0;
40
+ _this.BonesPerMesh = 0;
41
+ _this.INSTANCES = false;
42
+ _this.INSTANCESCOLOR = false;
43
+ _this.HIGHLEVEL = false;
44
+ _this.IMAGEPROCESSINGPOSTPROCESS = false;
45
+ _this.SKIPFINALCOLORCLAMP = false;
46
+ _this.rebuild();
47
+ return _this;
48
+ }
49
+ return FurMaterialDefines;
50
+ }(MaterialDefines));
51
+ var FurMaterial = /** @class */ (function (_super) {
52
+ __extends(FurMaterial, _super);
53
+ function FurMaterial(name, scene) {
54
+ var _this = _super.call(this, name, scene) || this;
55
+ _this.diffuseColor = new Color3(1, 1, 1);
56
+ _this.furLength = 1;
57
+ _this.furAngle = 0;
58
+ _this.furColor = new Color3(0.44, 0.21, 0.02);
59
+ _this.furOffset = 0.0;
60
+ _this.furSpacing = 12;
61
+ _this.furGravity = new Vector3(0, 0, 0);
62
+ _this.furSpeed = 100;
63
+ _this.furDensity = 20;
64
+ _this.furOcclusion = 0.0;
65
+ _this._disableLighting = false;
66
+ _this._maxSimultaneousLights = 4;
67
+ _this.highLevelFur = true;
68
+ _this._furTime = 0;
69
+ return _this;
70
+ }
71
+ Object.defineProperty(FurMaterial.prototype, "furTime", {
72
+ get: function () {
73
+ return this._furTime;
74
+ },
75
+ set: function (furTime) {
76
+ this._furTime = furTime;
77
+ },
78
+ enumerable: false,
79
+ configurable: true
80
+ });
81
+ FurMaterial.prototype.needAlphaBlending = function () {
82
+ return this.alpha < 1.0;
83
+ };
84
+ FurMaterial.prototype.needAlphaTesting = function () {
85
+ return false;
86
+ };
87
+ FurMaterial.prototype.getAlphaTestTexture = function () {
88
+ return null;
89
+ };
90
+ FurMaterial.prototype.updateFur = function () {
91
+ for (var i = 1; i < this._meshes.length; i++) {
92
+ var offsetFur = this._meshes[i].material;
93
+ offsetFur.furLength = this.furLength;
94
+ offsetFur.furAngle = this.furAngle;
95
+ offsetFur.furGravity = this.furGravity;
96
+ offsetFur.furSpacing = this.furSpacing;
97
+ offsetFur.furSpeed = this.furSpeed;
98
+ offsetFur.furColor = this.furColor;
99
+ offsetFur.diffuseTexture = this.diffuseTexture;
100
+ offsetFur.furTexture = this.furTexture;
101
+ offsetFur.highLevelFur = this.highLevelFur;
102
+ offsetFur.furTime = this.furTime;
103
+ offsetFur.furDensity = this.furDensity;
104
+ }
105
+ };
106
+ // Methods
107
+ FurMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
108
+ if (this.isFrozen) {
109
+ if (subMesh.effect && subMesh.effect._wasPreviouslyReady) {
110
+ return true;
111
+ }
112
+ }
113
+ if (!subMesh.materialDefines) {
114
+ subMesh.materialDefines = new FurMaterialDefines();
115
+ }
116
+ var defines = subMesh.materialDefines;
117
+ var scene = this.getScene();
118
+ if (this._isReadyForSubMesh(subMesh)) {
119
+ return true;
120
+ }
121
+ var engine = scene.getEngine();
122
+ // Textures
123
+ if (defines._areTexturesDirty) {
124
+ if (scene.texturesEnabled) {
125
+ if (this.diffuseTexture && MaterialFlags.DiffuseTextureEnabled) {
126
+ if (!this.diffuseTexture.isReady()) {
127
+ return false;
128
+ }
129
+ else {
130
+ defines._needUVs = true;
131
+ defines.DIFFUSE = true;
132
+ }
133
+ }
134
+ if (this.heightTexture && engine.getCaps().maxVertexTextureImageUnits) {
135
+ if (!this.heightTexture.isReady()) {
136
+ return false;
137
+ }
138
+ else {
139
+ defines._needUVs = true;
140
+ defines.HEIGHTMAP = true;
141
+ }
142
+ }
143
+ }
144
+ }
145
+ // High level
146
+ if (this.highLevelFur !== defines.HIGHLEVEL) {
147
+ defines.HIGHLEVEL = true;
148
+ defines.markAsUnprocessed();
149
+ }
150
+ // Misc.
151
+ MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
152
+ // Lights
153
+ defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
154
+ // Values that need to be evaluated on every frame
155
+ MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
156
+ // Attribs
157
+ MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
158
+ // Get correct effect
159
+ if (defines.isDirty) {
160
+ defines.markAsProcessed();
161
+ scene.resetCachedMaterial();
162
+ // Fallbacks
163
+ var fallbacks = new EffectFallbacks();
164
+ if (defines.FOG) {
165
+ fallbacks.addFallback(1, "FOG");
166
+ }
167
+ MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
168
+ if (defines.NUM_BONE_INFLUENCERS > 0) {
169
+ fallbacks.addCPUSkinningFallback(0, mesh);
170
+ }
171
+ defines.IMAGEPROCESSINGPOSTPROCESS = scene.imageProcessingConfiguration.applyByPostProcess;
172
+ //Attributes
173
+ var attribs = [VertexBuffer.PositionKind];
174
+ if (defines.NORMAL) {
175
+ attribs.push(VertexBuffer.NormalKind);
176
+ }
177
+ if (defines.UV1) {
178
+ attribs.push(VertexBuffer.UVKind);
179
+ }
180
+ if (defines.UV2) {
181
+ attribs.push(VertexBuffer.UV2Kind);
182
+ }
183
+ if (defines.VERTEXCOLOR) {
184
+ attribs.push(VertexBuffer.ColorKind);
185
+ }
186
+ MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
187
+ MaterialHelper.PrepareAttributesForInstances(attribs, defines);
188
+ // Legacy browser patch
189
+ var shaderName = "fur";
190
+ var join = defines.toString();
191
+ var uniforms = [
192
+ "world",
193
+ "view",
194
+ "viewProjection",
195
+ "vEyePosition",
196
+ "vLightsType",
197
+ "vDiffuseColor",
198
+ "vFogInfos",
199
+ "vFogColor",
200
+ "pointSize",
201
+ "vDiffuseInfos",
202
+ "mBones",
203
+ "vClipPlane",
204
+ "vClipPlane2",
205
+ "vClipPlane3",
206
+ "vClipPlane4",
207
+ "vClipPlane5",
208
+ "vClipPlane6",
209
+ "diffuseMatrix",
210
+ "furLength",
211
+ "furAngle",
212
+ "furColor",
213
+ "furOffset",
214
+ "furGravity",
215
+ "furTime",
216
+ "furSpacing",
217
+ "furDensity",
218
+ "furOcclusion",
219
+ ];
220
+ var samplers = ["diffuseSampler", "heightTexture", "furTexture"];
221
+ var uniformBuffers = new Array();
222
+ MaterialHelper.PrepareUniformsAndSamplersList({
223
+ uniformsNames: uniforms,
224
+ uniformBuffersNames: uniformBuffers,
225
+ samplers: samplers,
226
+ defines: defines,
227
+ maxSimultaneousLights: this.maxSimultaneousLights,
228
+ });
229
+ subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
230
+ attributes: attribs,
231
+ uniformsNames: uniforms,
232
+ uniformBuffersNames: uniformBuffers,
233
+ samplers: samplers,
234
+ defines: join,
235
+ fallbacks: fallbacks,
236
+ onCompiled: this.onCompiled,
237
+ onError: this.onError,
238
+ indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights },
239
+ }, engine), defines, this._materialContext);
240
+ }
241
+ if (!subMesh.effect || !subMesh.effect.isReady()) {
242
+ return false;
243
+ }
244
+ defines._renderId = scene.getRenderId();
245
+ subMesh.effect._wasPreviouslyReady = true;
246
+ return true;
247
+ };
248
+ FurMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
249
+ var scene = this.getScene();
250
+ var defines = subMesh.materialDefines;
251
+ if (!defines) {
252
+ return;
253
+ }
254
+ var effect = subMesh.effect;
255
+ if (!effect) {
256
+ return;
257
+ }
258
+ this._activeEffect = effect;
259
+ // Matrices
260
+ this.bindOnlyWorldMatrix(world);
261
+ this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
262
+ // Bones
263
+ MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
264
+ if (scene.getCachedMaterial() !== this) {
265
+ // Textures
266
+ if (this._diffuseTexture && MaterialFlags.DiffuseTextureEnabled) {
267
+ this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
268
+ this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
269
+ this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
270
+ }
271
+ if (this._heightTexture) {
272
+ this._activeEffect.setTexture("heightTexture", this._heightTexture);
273
+ }
274
+ // Clip plane
275
+ MaterialHelper.BindClipPlane(this._activeEffect, scene);
276
+ // Point size
277
+ if (this.pointsCloud) {
278
+ this._activeEffect.setFloat("pointSize", this.pointSize);
279
+ }
280
+ scene.bindEyePosition(effect);
281
+ }
282
+ this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
283
+ if (scene.lightsEnabled && !this.disableLighting) {
284
+ MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
285
+ }
286
+ // View
287
+ if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
288
+ this._activeEffect.setMatrix("view", scene.getViewMatrix());
289
+ }
290
+ // Fog
291
+ MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
292
+ this._activeEffect.setFloat("furLength", this.furLength);
293
+ this._activeEffect.setFloat("furAngle", this.furAngle);
294
+ this._activeEffect.setColor4("furColor", this.furColor, 1.0);
295
+ if (this.highLevelFur) {
296
+ this._activeEffect.setVector3("furGravity", this.furGravity);
297
+ this._activeEffect.setFloat("furOffset", this.furOffset);
298
+ this._activeEffect.setFloat("furSpacing", this.furSpacing);
299
+ this._activeEffect.setFloat("furDensity", this.furDensity);
300
+ this._activeEffect.setFloat("furOcclusion", this.furOcclusion);
301
+ this._furTime += this.getScene().getEngine().getDeltaTime() / this.furSpeed;
302
+ this._activeEffect.setFloat("furTime", this._furTime);
303
+ this._activeEffect.setTexture("furTexture", this.furTexture);
304
+ }
305
+ this._afterBind(mesh, this._activeEffect);
306
+ };
307
+ FurMaterial.prototype.getAnimatables = function () {
308
+ var results = [];
309
+ if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
310
+ results.push(this.diffuseTexture);
311
+ }
312
+ if (this.heightTexture && this.heightTexture.animations && this.heightTexture.animations.length > 0) {
313
+ results.push(this.heightTexture);
314
+ }
315
+ return results;
316
+ };
317
+ FurMaterial.prototype.getActiveTextures = function () {
318
+ var activeTextures = _super.prototype.getActiveTextures.call(this);
319
+ if (this._diffuseTexture) {
320
+ activeTextures.push(this._diffuseTexture);
321
+ }
322
+ if (this._heightTexture) {
323
+ activeTextures.push(this._heightTexture);
324
+ }
325
+ return activeTextures;
326
+ };
327
+ FurMaterial.prototype.hasTexture = function (texture) {
328
+ if (_super.prototype.hasTexture.call(this, texture)) {
329
+ return true;
330
+ }
331
+ if (this.diffuseTexture === texture) {
332
+ return true;
333
+ }
334
+ if (this._heightTexture === texture) {
335
+ return true;
336
+ }
337
+ return false;
338
+ };
339
+ FurMaterial.prototype.dispose = function (forceDisposeEffect) {
340
+ if (this.diffuseTexture) {
341
+ this.diffuseTexture.dispose();
342
+ }
343
+ if (this._meshes) {
344
+ for (var i = 1; i < this._meshes.length; i++) {
345
+ var mat = this._meshes[i].material;
346
+ if (mat) {
347
+ mat.dispose(forceDisposeEffect);
348
+ }
349
+ this._meshes[i].dispose();
350
+ }
351
+ }
352
+ _super.prototype.dispose.call(this, forceDisposeEffect);
353
+ };
354
+ FurMaterial.prototype.clone = function (name) {
355
+ var _this = this;
356
+ return SerializationHelper.Clone(function () { return new FurMaterial(name, _this.getScene()); }, this);
357
+ };
358
+ FurMaterial.prototype.serialize = function () {
359
+ var serializationObject = _super.prototype.serialize.call(this);
360
+ serializationObject.customType = "BABYLON.FurMaterial";
361
+ if (this._meshes) {
362
+ serializationObject.sourceMeshName = this._meshes[0].name;
363
+ serializationObject.quality = this._meshes.length;
364
+ }
365
+ return serializationObject;
366
+ };
367
+ FurMaterial.prototype.getClassName = function () {
368
+ return "FurMaterial";
369
+ };
370
+ // Statics
371
+ FurMaterial.Parse = function (source, scene, rootUrl) {
372
+ var material = SerializationHelper.Parse(function () { return new FurMaterial(source.name, scene); }, source, scene, rootUrl);
373
+ if (source.sourceMeshName && material.highLevelFur) {
374
+ scene.executeWhenReady(function () {
375
+ var sourceMesh = scene.getMeshByName(source.sourceMeshName);
376
+ if (sourceMesh) {
377
+ var furTexture = FurMaterial.GenerateTexture("Fur Texture", scene);
378
+ material.furTexture = furTexture;
379
+ FurMaterial.FurifyMesh(sourceMesh, source.quality);
380
+ }
381
+ });
382
+ }
383
+ return material;
384
+ };
385
+ FurMaterial.GenerateTexture = function (name, scene) {
386
+ // Generate fur textures
387
+ var texture = new DynamicTexture("FurTexture " + name, 256, scene, true);
388
+ var context = texture.getContext();
389
+ for (var i = 0; i < 20000; ++i) {
390
+ context.fillStyle = "rgba(255, " + Math.floor(Math.random() * 255) + ", " + Math.floor(Math.random() * 255) + ", 1)";
391
+ context.fillRect(Math.random() * texture.getSize().width, Math.random() * texture.getSize().height, 2, 2);
392
+ }
393
+ texture.update(false);
394
+ texture.wrapU = Texture.WRAP_ADDRESSMODE;
395
+ texture.wrapV = Texture.WRAP_ADDRESSMODE;
396
+ return texture;
397
+ };
398
+ // Creates and returns an array of meshes used as shells for the Fur Material
399
+ // that can be disposed later in your code
400
+ // The quality is in interval [0, 100]
401
+ FurMaterial.FurifyMesh = function (sourceMesh, quality) {
402
+ var meshes = [sourceMesh];
403
+ var mat = sourceMesh.material;
404
+ var i;
405
+ if (!(mat instanceof FurMaterial)) {
406
+ throw "The material of the source mesh must be a Fur Material";
407
+ }
408
+ for (i = 1; i < quality; i++) {
409
+ var offsetFur = new FurMaterial(mat.name + i, sourceMesh.getScene());
410
+ sourceMesh.getScene().materials.pop();
411
+ Tags.EnableFor(offsetFur);
412
+ Tags.AddTagsTo(offsetFur, "furShellMaterial");
413
+ offsetFur.furLength = mat.furLength;
414
+ offsetFur.furAngle = mat.furAngle;
415
+ offsetFur.furGravity = mat.furGravity;
416
+ offsetFur.furSpacing = mat.furSpacing;
417
+ offsetFur.furSpeed = mat.furSpeed;
418
+ offsetFur.furColor = mat.furColor;
419
+ offsetFur.diffuseTexture = mat.diffuseTexture;
420
+ offsetFur.furOffset = i / quality;
421
+ offsetFur.furTexture = mat.furTexture;
422
+ offsetFur.highLevelFur = mat.highLevelFur;
423
+ offsetFur.furTime = mat.furTime;
424
+ offsetFur.furDensity = mat.furDensity;
425
+ var offsetMesh = sourceMesh.clone(sourceMesh.name + i);
426
+ offsetMesh.material = offsetFur;
427
+ offsetMesh.skeleton = sourceMesh.skeleton;
428
+ offsetMesh.position = Vector3.Zero();
429
+ meshes.push(offsetMesh);
430
+ }
431
+ for (i = 1; i < meshes.length; i++) {
432
+ meshes[i].parent = sourceMesh;
433
+ }
434
+ sourceMesh.material._meshes = meshes;
435
+ return meshes;
436
+ };
437
+ __decorate([
438
+ serializeAsTexture("diffuseTexture")
439
+ ], FurMaterial.prototype, "_diffuseTexture", void 0);
440
+ __decorate([
441
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
442
+ ], FurMaterial.prototype, "diffuseTexture", void 0);
443
+ __decorate([
444
+ serializeAsTexture("heightTexture")
445
+ ], FurMaterial.prototype, "_heightTexture", void 0);
446
+ __decorate([
447
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
448
+ ], FurMaterial.prototype, "heightTexture", void 0);
449
+ __decorate([
450
+ serializeAsColor3()
451
+ ], FurMaterial.prototype, "diffuseColor", void 0);
452
+ __decorate([
453
+ serialize()
454
+ ], FurMaterial.prototype, "furLength", void 0);
455
+ __decorate([
456
+ serialize()
457
+ ], FurMaterial.prototype, "furAngle", void 0);
458
+ __decorate([
459
+ serializeAsColor3()
460
+ ], FurMaterial.prototype, "furColor", void 0);
461
+ __decorate([
462
+ serialize()
463
+ ], FurMaterial.prototype, "furOffset", void 0);
464
+ __decorate([
465
+ serialize()
466
+ ], FurMaterial.prototype, "furSpacing", void 0);
467
+ __decorate([
468
+ serializeAsVector3()
469
+ ], FurMaterial.prototype, "furGravity", void 0);
470
+ __decorate([
471
+ serialize()
472
+ ], FurMaterial.prototype, "furSpeed", void 0);
473
+ __decorate([
474
+ serialize()
475
+ ], FurMaterial.prototype, "furDensity", void 0);
476
+ __decorate([
477
+ serialize()
478
+ ], FurMaterial.prototype, "furOcclusion", void 0);
479
+ __decorate([
480
+ serialize("disableLighting")
481
+ ], FurMaterial.prototype, "_disableLighting", void 0);
482
+ __decorate([
483
+ expandToProperty("_markAllSubMeshesAsLightsDirty")
484
+ ], FurMaterial.prototype, "disableLighting", void 0);
485
+ __decorate([
486
+ serialize("maxSimultaneousLights")
487
+ ], FurMaterial.prototype, "_maxSimultaneousLights", void 0);
488
+ __decorate([
489
+ expandToProperty("_markAllSubMeshesAsLightsDirty")
490
+ ], FurMaterial.prototype, "maxSimultaneousLights", void 0);
491
+ __decorate([
492
+ serialize()
493
+ ], FurMaterial.prototype, "highLevelFur", void 0);
494
+ __decorate([
495
+ serialize()
496
+ ], FurMaterial.prototype, "furTime", null);
497
+ return FurMaterial;
498
+ }(PushMaterial));
499
+ export { FurMaterial };
500
+ RegisterClass("BABYLON.FurMaterial", FurMaterial);
501
501
  //# sourceMappingURL=furMaterial.js.map