@babylonjs/materials 5.0.0-beta.9 → 5.0.0-rc.10

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