@babylonjs/materials 5.0.0-rc.1 → 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,262 +1,277 @@
1
- import { __decorate, __extends } from "tslib";
2
- import { serializeAsTexture, serialize, expandToProperty, serializeAsColor3, SerializationHelper, serializeAsVector3 } from "@babylonjs/core/Misc/decorators.js";
3
- import { Vector4, Vector3 } from "@babylonjs/core/Maths/math.vector.js";
4
- import { Color3 } from "@babylonjs/core/Maths/math.color.js";
5
- import { MaterialDefines } from "@babylonjs/core/Materials/materialDefines.js";
6
- import { MaterialHelper } from "@babylonjs/core/Materials/materialHelper.js";
7
- import { PushMaterial } from "@babylonjs/core/Materials/pushMaterial.js";
8
- import { MaterialFlags } from "@babylonjs/core/Materials/materialFlags.js";
9
- import { VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
10
- import { RegisterClass } from '@babylonjs/core/Misc/typeStore.js';
11
- import "./grid.fragment.js";
12
- import "./grid.vertex.js";
13
- var GridMaterialDefines = /** @class */ (function (_super) {
14
- __extends(GridMaterialDefines, _super);
15
- function GridMaterialDefines() {
16
- var _this = _super.call(this) || this;
17
- _this.OPACITY = false;
18
- _this.TRANSPARENT = false;
19
- _this.FOG = false;
20
- _this.PREMULTIPLYALPHA = false;
21
- _this.MAX_LINE = false;
22
- _this.UV1 = false;
23
- _this.UV2 = false;
24
- _this.INSTANCES = false;
25
- _this.THIN_INSTANCES = false;
26
- _this.IMAGEPROCESSINGPOSTPROCESS = false;
27
- _this.SKIPFINALCOLORCLAMP = false;
28
- _this.rebuild();
29
- return _this;
30
- }
31
- return GridMaterialDefines;
32
- }(MaterialDefines));
33
- /**
34
- * The grid materials allows you to wrap any shape with a grid.
35
- * Colors are customizable.
36
- */
37
- var GridMaterial = /** @class */ (function (_super) {
38
- __extends(GridMaterial, _super);
39
- /**
40
- * constructor
41
- * @param name The name given to the material in order to identify it afterwards.
42
- * @param scene The scene the material is used in.
43
- */
44
- function GridMaterial(name, scene) {
45
- var _this = _super.call(this, name, scene) || this;
46
- /**
47
- * Main color of the grid (e.g. between lines)
48
- */
49
- _this.mainColor = Color3.Black();
50
- /**
51
- * Color of the grid lines.
52
- */
53
- _this.lineColor = Color3.Teal();
54
- /**
55
- * The scale of the grid compared to unit.
56
- */
57
- _this.gridRatio = 1.0;
58
- /**
59
- * Allows setting an offset for the grid lines.
60
- */
61
- _this.gridOffset = Vector3.Zero();
62
- /**
63
- * The frequency of thicker lines.
64
- */
65
- _this.majorUnitFrequency = 10;
66
- /**
67
- * The visibility of minor units in the grid.
68
- */
69
- _this.minorUnitVisibility = 0.33;
70
- /**
71
- * The grid opacity outside of the lines.
72
- */
73
- _this.opacity = 1.0;
74
- /**
75
- * Determine RBG output is premultiplied by alpha value.
76
- */
77
- _this.preMultiplyAlpha = false;
78
- /**
79
- * Determines if the max line value will be used instead of the sum wherever grid lines intersect.
80
- */
81
- _this.useMaxLine = false;
82
- _this._gridControl = new Vector4(_this.gridRatio, _this.majorUnitFrequency, _this.minorUnitVisibility, _this.opacity);
83
- return _this;
84
- }
85
- /**
86
- * Returns wehter or not the grid requires alpha blending.
87
- */
88
- GridMaterial.prototype.needAlphaBlending = function () {
89
- return this.opacity < 1.0 || this._opacityTexture && this._opacityTexture.isReady();
90
- };
91
- GridMaterial.prototype.needAlphaBlendingForMesh = function (mesh) {
92
- return mesh.visibility < 1.0 || this.needAlphaBlending();
93
- };
94
- GridMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
95
- if (this.isFrozen) {
96
- if (subMesh.effect && subMesh.effect._wasPreviouslyReady) {
97
- return true;
98
- }
99
- }
100
- if (!subMesh.materialDefines) {
101
- subMesh.materialDefines = new GridMaterialDefines();
102
- }
103
- var defines = subMesh.materialDefines;
104
- var scene = this.getScene();
105
- if (this._isReadyForSubMesh(subMesh)) {
106
- return true;
107
- }
108
- if (defines.TRANSPARENT !== (this.opacity < 1.0)) {
109
- defines.TRANSPARENT = !defines.TRANSPARENT;
110
- defines.markAsUnprocessed();
111
- }
112
- if (defines.PREMULTIPLYALPHA != this.preMultiplyAlpha) {
113
- defines.PREMULTIPLYALPHA = !defines.PREMULTIPLYALPHA;
114
- defines.markAsUnprocessed();
115
- }
116
- if (defines.MAX_LINE !== this.useMaxLine) {
117
- defines.MAX_LINE = !defines.MAX_LINE;
118
- defines.markAsUnprocessed();
119
- }
120
- // Textures
121
- if (defines._areTexturesDirty) {
122
- defines._needUVs = false;
123
- if (scene.texturesEnabled) {
124
- if (this._opacityTexture && MaterialFlags.OpacityTextureEnabled) {
125
- if (!this._opacityTexture.isReady()) {
126
- return false;
127
- }
128
- else {
129
- defines._needUVs = true;
130
- defines.OPACITY = true;
131
- }
132
- }
133
- }
134
- }
135
- MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, false, this.fogEnabled, false, defines);
136
- // Values that need to be evaluated on every frame
137
- MaterialHelper.PrepareDefinesForFrameBoundValues(scene, scene.getEngine(), defines, !!useInstances);
138
- // Get correct effect
139
- if (defines.isDirty) {
140
- defines.markAsProcessed();
141
- scene.resetCachedMaterial();
142
- // Attributes
143
- MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, false);
144
- var attribs = [VertexBuffer.PositionKind, VertexBuffer.NormalKind];
145
- if (defines.UV1) {
146
- attribs.push(VertexBuffer.UVKind);
147
- }
148
- if (defines.UV2) {
149
- attribs.push(VertexBuffer.UV2Kind);
150
- }
151
- defines.IMAGEPROCESSINGPOSTPROCESS = scene.imageProcessingConfiguration.applyByPostProcess;
152
- MaterialHelper.PrepareAttributesForInstances(attribs, defines);
153
- // Defines
154
- var join = defines.toString();
155
- subMesh.setEffect(scene.getEngine().createEffect("grid", attribs, ["projection", "mainColor", "lineColor", "gridControl", "gridOffset", "vFogInfos", "vFogColor", "world", "view",
156
- "opacityMatrix", "vOpacityInfos", "visibility"], ["opacitySampler"], join, undefined, this.onCompiled, this.onError), defines, this._materialContext);
157
- }
158
- if (!subMesh.effect || !subMesh.effect.isReady()) {
159
- return false;
160
- }
161
- defines._renderId = scene.getRenderId();
162
- subMesh.effect._wasPreviouslyReady = true;
163
- return true;
164
- };
165
- GridMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
166
- var scene = this.getScene();
167
- var defines = subMesh.materialDefines;
168
- if (!defines) {
169
- return;
170
- }
171
- var effect = subMesh.effect;
172
- if (!effect) {
173
- return;
174
- }
175
- this._activeEffect = effect;
176
- this._activeEffect.setFloat("visibility", mesh.visibility);
177
- // Matrices
178
- if (!defines.INSTANCES || defines.THIN_INSTANCE) {
179
- this.bindOnlyWorldMatrix(world);
180
- }
181
- this._activeEffect.setMatrix("view", scene.getViewMatrix());
182
- this._activeEffect.setMatrix("projection", scene.getProjectionMatrix());
183
- // Uniforms
184
- if (this._mustRebind(scene, effect)) {
185
- this._activeEffect.setColor3("mainColor", this.mainColor);
186
- this._activeEffect.setColor3("lineColor", this.lineColor);
187
- this._activeEffect.setVector3("gridOffset", this.gridOffset);
188
- this._gridControl.x = this.gridRatio;
189
- this._gridControl.y = Math.round(this.majorUnitFrequency);
190
- this._gridControl.z = this.minorUnitVisibility;
191
- this._gridControl.w = this.opacity;
192
- this._activeEffect.setVector4("gridControl", this._gridControl);
193
- if (this._opacityTexture && MaterialFlags.OpacityTextureEnabled) {
194
- this._activeEffect.setTexture("opacitySampler", this._opacityTexture);
195
- this._activeEffect.setFloat2("vOpacityInfos", this._opacityTexture.coordinatesIndex, this._opacityTexture.level);
196
- this._activeEffect.setMatrix("opacityMatrix", this._opacityTexture.getTextureMatrix());
197
- }
198
- }
199
- // Fog
200
- MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
201
- this._afterBind(mesh, this._activeEffect);
202
- };
203
- /**
204
- * Dispose the material and its associated resources.
205
- * @param forceDisposeEffect will also dispose the used effect when true
206
- */
207
- GridMaterial.prototype.dispose = function (forceDisposeEffect) {
208
- _super.prototype.dispose.call(this, forceDisposeEffect);
209
- };
210
- GridMaterial.prototype.clone = function (name) {
211
- var _this = this;
212
- return SerializationHelper.Clone(function () { return new GridMaterial(name, _this.getScene()); }, this);
213
- };
214
- GridMaterial.prototype.serialize = function () {
215
- var serializationObject = SerializationHelper.Serialize(this);
216
- serializationObject.customType = "BABYLON.GridMaterial";
217
- return serializationObject;
218
- };
219
- GridMaterial.prototype.getClassName = function () {
220
- return "GridMaterial";
221
- };
222
- GridMaterial.Parse = function (source, scene, rootUrl) {
223
- return SerializationHelper.Parse(function () { return new GridMaterial(source.name, scene); }, source, scene, rootUrl);
224
- };
225
- __decorate([
226
- serializeAsColor3()
227
- ], GridMaterial.prototype, "mainColor", void 0);
228
- __decorate([
229
- serializeAsColor3()
230
- ], GridMaterial.prototype, "lineColor", void 0);
231
- __decorate([
232
- serialize()
233
- ], GridMaterial.prototype, "gridRatio", void 0);
234
- __decorate([
235
- serializeAsVector3()
236
- ], GridMaterial.prototype, "gridOffset", void 0);
237
- __decorate([
238
- serialize()
239
- ], GridMaterial.prototype, "majorUnitFrequency", void 0);
240
- __decorate([
241
- serialize()
242
- ], GridMaterial.prototype, "minorUnitVisibility", void 0);
243
- __decorate([
244
- serialize()
245
- ], GridMaterial.prototype, "opacity", void 0);
246
- __decorate([
247
- serialize()
248
- ], GridMaterial.prototype, "preMultiplyAlpha", void 0);
249
- __decorate([
250
- serialize()
251
- ], GridMaterial.prototype, "useMaxLine", void 0);
252
- __decorate([
253
- serializeAsTexture("opacityTexture")
254
- ], GridMaterial.prototype, "_opacityTexture", void 0);
255
- __decorate([
256
- expandToProperty("_markAllSubMeshesAsTexturesDirty")
257
- ], GridMaterial.prototype, "opacityTexture", void 0);
258
- return GridMaterial;
259
- }(PushMaterial));
260
- export { GridMaterial };
261
- RegisterClass("BABYLON.GridMaterial", GridMaterial);
1
+ import { __decorate, __extends } from "tslib";
2
+ /* eslint-disable @typescript-eslint/naming-convention */
3
+ import { serializeAsTexture, serialize, expandToProperty, serializeAsColor3, SerializationHelper, serializeAsVector3 } from "@babylonjs/core/Misc/decorators.js";
4
+ import { Vector4, Vector3 } from "@babylonjs/core/Maths/math.vector.js";
5
+ import { Color3 } from "@babylonjs/core/Maths/math.color.js";
6
+ import { MaterialDefines } from "@babylonjs/core/Materials/materialDefines.js";
7
+ import { MaterialHelper } from "@babylonjs/core/Materials/materialHelper.js";
8
+ import { PushMaterial } from "@babylonjs/core/Materials/pushMaterial.js";
9
+ import { MaterialFlags } from "@babylonjs/core/Materials/materialFlags.js";
10
+ import { VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
11
+ import { RegisterClass } from "@babylonjs/core/Misc/typeStore.js";
12
+ import "./grid.fragment";
13
+ import "./grid.vertex";
14
+ var GridMaterialDefines = /** @class */ (function (_super) {
15
+ __extends(GridMaterialDefines, _super);
16
+ function GridMaterialDefines() {
17
+ var _this = _super.call(this) || this;
18
+ _this.OPACITY = false;
19
+ _this.TRANSPARENT = false;
20
+ _this.FOG = false;
21
+ _this.PREMULTIPLYALPHA = false;
22
+ _this.MAX_LINE = false;
23
+ _this.UV1 = false;
24
+ _this.UV2 = false;
25
+ _this.INSTANCES = false;
26
+ _this.THIN_INSTANCES = false;
27
+ _this.IMAGEPROCESSINGPOSTPROCESS = false;
28
+ _this.SKIPFINALCOLORCLAMP = false;
29
+ _this.rebuild();
30
+ return _this;
31
+ }
32
+ return GridMaterialDefines;
33
+ }(MaterialDefines));
34
+ /**
35
+ * The grid materials allows you to wrap any shape with a grid.
36
+ * Colors are customizable.
37
+ */
38
+ var GridMaterial = /** @class */ (function (_super) {
39
+ __extends(GridMaterial, _super);
40
+ /**
41
+ * constructor
42
+ * @param name The name given to the material in order to identify it afterwards.
43
+ * @param scene The scene the material is used in.
44
+ */
45
+ function GridMaterial(name, scene) {
46
+ var _this = _super.call(this, name, scene) || this;
47
+ /**
48
+ * Main color of the grid (e.g. between lines)
49
+ */
50
+ _this.mainColor = Color3.Black();
51
+ /**
52
+ * Color of the grid lines.
53
+ */
54
+ _this.lineColor = Color3.Teal();
55
+ /**
56
+ * The scale of the grid compared to unit.
57
+ */
58
+ _this.gridRatio = 1.0;
59
+ /**
60
+ * Allows setting an offset for the grid lines.
61
+ */
62
+ _this.gridOffset = Vector3.Zero();
63
+ /**
64
+ * The frequency of thicker lines.
65
+ */
66
+ _this.majorUnitFrequency = 10;
67
+ /**
68
+ * The visibility of minor units in the grid.
69
+ */
70
+ _this.minorUnitVisibility = 0.33;
71
+ /**
72
+ * The grid opacity outside of the lines.
73
+ */
74
+ _this.opacity = 1.0;
75
+ /**
76
+ * Determine RBG output is premultiplied by alpha value.
77
+ */
78
+ _this.preMultiplyAlpha = false;
79
+ /**
80
+ * Determines if the max line value will be used instead of the sum wherever grid lines intersect.
81
+ */
82
+ _this.useMaxLine = false;
83
+ _this._gridControl = new Vector4(_this.gridRatio, _this.majorUnitFrequency, _this.minorUnitVisibility, _this.opacity);
84
+ return _this;
85
+ }
86
+ /**
87
+ * Returns whether or not the grid requires alpha blending.
88
+ */
89
+ GridMaterial.prototype.needAlphaBlending = function () {
90
+ return this.opacity < 1.0 || (this._opacityTexture && this._opacityTexture.isReady());
91
+ };
92
+ GridMaterial.prototype.needAlphaBlendingForMesh = function (mesh) {
93
+ return mesh.visibility < 1.0 || this.needAlphaBlending();
94
+ };
95
+ GridMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
96
+ if (this.isFrozen) {
97
+ if (subMesh.effect && subMesh.effect._wasPreviouslyReady) {
98
+ return true;
99
+ }
100
+ }
101
+ if (!subMesh.materialDefines) {
102
+ subMesh.materialDefines = new GridMaterialDefines();
103
+ }
104
+ var defines = subMesh.materialDefines;
105
+ var scene = this.getScene();
106
+ if (this._isReadyForSubMesh(subMesh)) {
107
+ return true;
108
+ }
109
+ if (defines.TRANSPARENT !== this.opacity < 1.0) {
110
+ defines.TRANSPARENT = !defines.TRANSPARENT;
111
+ defines.markAsUnprocessed();
112
+ }
113
+ if (defines.PREMULTIPLYALPHA != this.preMultiplyAlpha) {
114
+ defines.PREMULTIPLYALPHA = !defines.PREMULTIPLYALPHA;
115
+ defines.markAsUnprocessed();
116
+ }
117
+ if (defines.MAX_LINE !== this.useMaxLine) {
118
+ defines.MAX_LINE = !defines.MAX_LINE;
119
+ defines.markAsUnprocessed();
120
+ }
121
+ // Textures
122
+ if (defines._areTexturesDirty) {
123
+ defines._needUVs = false;
124
+ if (scene.texturesEnabled) {
125
+ if (this._opacityTexture && MaterialFlags.OpacityTextureEnabled) {
126
+ if (!this._opacityTexture.isReady()) {
127
+ return false;
128
+ }
129
+ else {
130
+ defines._needUVs = true;
131
+ defines.OPACITY = true;
132
+ }
133
+ }
134
+ }
135
+ }
136
+ MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, false, this.fogEnabled, false, defines);
137
+ // Values that need to be evaluated on every frame
138
+ MaterialHelper.PrepareDefinesForFrameBoundValues(scene, scene.getEngine(), defines, !!useInstances);
139
+ // Get correct effect
140
+ if (defines.isDirty) {
141
+ defines.markAsProcessed();
142
+ scene.resetCachedMaterial();
143
+ // Attributes
144
+ MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, false);
145
+ var attribs = [VertexBuffer.PositionKind, VertexBuffer.NormalKind];
146
+ if (defines.UV1) {
147
+ attribs.push(VertexBuffer.UVKind);
148
+ }
149
+ if (defines.UV2) {
150
+ attribs.push(VertexBuffer.UV2Kind);
151
+ }
152
+ defines.IMAGEPROCESSINGPOSTPROCESS = scene.imageProcessingConfiguration.applyByPostProcess;
153
+ MaterialHelper.PrepareAttributesForInstances(attribs, defines);
154
+ // Defines
155
+ var join = defines.toString();
156
+ subMesh.setEffect(scene
157
+ .getEngine()
158
+ .createEffect("grid", attribs, [
159
+ "projection",
160
+ "mainColor",
161
+ "lineColor",
162
+ "gridControl",
163
+ "gridOffset",
164
+ "vFogInfos",
165
+ "vFogColor",
166
+ "world",
167
+ "view",
168
+ "opacityMatrix",
169
+ "vOpacityInfos",
170
+ "visibility",
171
+ ], ["opacitySampler"], join, undefined, this.onCompiled, this.onError), defines, this._materialContext);
172
+ }
173
+ if (!subMesh.effect || !subMesh.effect.isReady()) {
174
+ return false;
175
+ }
176
+ defines._renderId = scene.getRenderId();
177
+ subMesh.effect._wasPreviouslyReady = true;
178
+ return true;
179
+ };
180
+ GridMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
181
+ var scene = this.getScene();
182
+ var defines = subMesh.materialDefines;
183
+ if (!defines) {
184
+ return;
185
+ }
186
+ var effect = subMesh.effect;
187
+ if (!effect) {
188
+ return;
189
+ }
190
+ this._activeEffect = effect;
191
+ this._activeEffect.setFloat("visibility", mesh.visibility);
192
+ // Matrices
193
+ if (!defines.INSTANCES || defines.THIN_INSTANCE) {
194
+ this.bindOnlyWorldMatrix(world);
195
+ }
196
+ this._activeEffect.setMatrix("view", scene.getViewMatrix());
197
+ this._activeEffect.setMatrix("projection", scene.getProjectionMatrix());
198
+ // Uniforms
199
+ if (this._mustRebind(scene, effect)) {
200
+ this._activeEffect.setColor3("mainColor", this.mainColor);
201
+ this._activeEffect.setColor3("lineColor", this.lineColor);
202
+ this._activeEffect.setVector3("gridOffset", this.gridOffset);
203
+ this._gridControl.x = this.gridRatio;
204
+ this._gridControl.y = Math.round(this.majorUnitFrequency);
205
+ this._gridControl.z = this.minorUnitVisibility;
206
+ this._gridControl.w = this.opacity;
207
+ this._activeEffect.setVector4("gridControl", this._gridControl);
208
+ if (this._opacityTexture && MaterialFlags.OpacityTextureEnabled) {
209
+ this._activeEffect.setTexture("opacitySampler", this._opacityTexture);
210
+ this._activeEffect.setFloat2("vOpacityInfos", this._opacityTexture.coordinatesIndex, this._opacityTexture.level);
211
+ this._activeEffect.setMatrix("opacityMatrix", this._opacityTexture.getTextureMatrix());
212
+ }
213
+ }
214
+ // Fog
215
+ MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
216
+ this._afterBind(mesh, this._activeEffect);
217
+ };
218
+ /**
219
+ * Dispose the material and its associated resources.
220
+ * @param forceDisposeEffect will also dispose the used effect when true
221
+ */
222
+ GridMaterial.prototype.dispose = function (forceDisposeEffect) {
223
+ _super.prototype.dispose.call(this, forceDisposeEffect);
224
+ };
225
+ GridMaterial.prototype.clone = function (name) {
226
+ var _this = this;
227
+ return SerializationHelper.Clone(function () { return new GridMaterial(name, _this.getScene()); }, this);
228
+ };
229
+ GridMaterial.prototype.serialize = function () {
230
+ var serializationObject = SerializationHelper.Serialize(this);
231
+ serializationObject.customType = "BABYLON.GridMaterial";
232
+ return serializationObject;
233
+ };
234
+ GridMaterial.prototype.getClassName = function () {
235
+ return "GridMaterial";
236
+ };
237
+ GridMaterial.Parse = function (source, scene, rootUrl) {
238
+ return SerializationHelper.Parse(function () { return new GridMaterial(source.name, scene); }, source, scene, rootUrl);
239
+ };
240
+ __decorate([
241
+ serializeAsColor3()
242
+ ], GridMaterial.prototype, "mainColor", void 0);
243
+ __decorate([
244
+ serializeAsColor3()
245
+ ], GridMaterial.prototype, "lineColor", void 0);
246
+ __decorate([
247
+ serialize()
248
+ ], GridMaterial.prototype, "gridRatio", void 0);
249
+ __decorate([
250
+ serializeAsVector3()
251
+ ], GridMaterial.prototype, "gridOffset", void 0);
252
+ __decorate([
253
+ serialize()
254
+ ], GridMaterial.prototype, "majorUnitFrequency", void 0);
255
+ __decorate([
256
+ serialize()
257
+ ], GridMaterial.prototype, "minorUnitVisibility", void 0);
258
+ __decorate([
259
+ serialize()
260
+ ], GridMaterial.prototype, "opacity", void 0);
261
+ __decorate([
262
+ serialize()
263
+ ], GridMaterial.prototype, "preMultiplyAlpha", void 0);
264
+ __decorate([
265
+ serialize()
266
+ ], GridMaterial.prototype, "useMaxLine", void 0);
267
+ __decorate([
268
+ serializeAsTexture("opacityTexture")
269
+ ], GridMaterial.prototype, "_opacityTexture", void 0);
270
+ __decorate([
271
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
272
+ ], GridMaterial.prototype, "opacityTexture", void 0);
273
+ return GridMaterial;
274
+ }(PushMaterial));
275
+ export { GridMaterial };
276
+ RegisterClass("BABYLON.GridMaterial", GridMaterial);
262
277
  //# sourceMappingURL=gridMaterial.js.map