@shapediver/viewer.rendering-engine.rendering-engine-threejs 3.16.8 → 3.16.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 (185) hide show
  1. package/dist/RenderingEngine.d.ts +294 -294
  2. package/dist/RenderingEngine.js +987 -977
  3. package/dist/RenderingEngine.js.map +1 -1
  4. package/dist/index.d.ts +16 -16
  5. package/dist/index.js +57 -57
  6. package/dist/injectors/TextureUnifierInjector.d.ts +13 -13
  7. package/dist/injectors/TextureUnifierInjector.js +181 -171
  8. package/dist/injectors/TextureUnifierInjector.js.map +1 -1
  9. package/dist/interfaces/ILoader.d.ts +3 -3
  10. package/dist/interfaces/ILoader.js +2 -2
  11. package/dist/interfaces/IRenderingEngine.d.ts +45 -45
  12. package/dist/interfaces/IRenderingEngine.js +2 -2
  13. package/dist/loaders/EnvironmentMapLoader.d.ts +119 -119
  14. package/dist/loaders/EnvironmentMapLoader.js +512 -502
  15. package/dist/loaders/EnvironmentMapLoader.js.map +1 -1
  16. package/dist/loaders/GeometryLoader.d.ts +39 -39
  17. package/dist/loaders/GeometryLoader.d.ts.map +1 -1
  18. package/dist/loaders/GeometryLoader.js +603 -593
  19. package/dist/loaders/GeometryLoader.js.map +1 -1
  20. package/dist/loaders/HTMLElementAnchorLoader.d.ts +15 -15
  21. package/dist/loaders/HTMLElementAnchorLoader.js +98 -98
  22. package/dist/loaders/HTMLElementAnchorLoader.js.map +1 -1
  23. package/dist/loaders/LightLoader.d.ts +19 -19
  24. package/dist/loaders/LightLoader.js +197 -187
  25. package/dist/loaders/LightLoader.js.map +1 -1
  26. package/dist/loaders/MaterialLoader.d.ts +115 -115
  27. package/dist/loaders/MaterialLoader.d.ts.map +1 -1
  28. package/dist/loaders/MaterialLoader.js +1612 -1602
  29. package/dist/loaders/MaterialLoader.js.map +1 -1
  30. package/dist/managers/ARManager.d.ts +17 -17
  31. package/dist/managers/ARManager.js +128 -128
  32. package/dist/managers/ARManager.js.map +1 -1
  33. package/dist/managers/CameraManager.d.ts +19 -19
  34. package/dist/managers/CameraManager.js +244 -234
  35. package/dist/managers/CameraManager.js.map +1 -1
  36. package/dist/managers/EnvironmentGeometryManager.d.ts +32 -32
  37. package/dist/managers/EnvironmentGeometryManager.js +114 -114
  38. package/dist/managers/EnvironmentGeometryManager.js.map +1 -1
  39. package/dist/managers/FlagManager.d.ts +19 -19
  40. package/dist/managers/FlagManager.js +143 -143
  41. package/dist/managers/FlagManager.js.map +1 -1
  42. package/dist/managers/PostProcessingManager.d.ts +1019 -1019
  43. package/dist/managers/PostProcessingManager.js +1306 -1296
  44. package/dist/managers/PostProcessingManager.js.map +1 -1
  45. package/dist/managers/RenderingManager.d.ts +84 -84
  46. package/dist/managers/RenderingManager.d.ts.map +1 -1
  47. package/dist/managers/RenderingManager.js +679 -669
  48. package/dist/managers/RenderingManager.js.map +1 -1
  49. package/dist/managers/SceneTracingManager.d.ts +28 -28
  50. package/dist/managers/SceneTracingManager.js +160 -150
  51. package/dist/managers/SceneTracingManager.js.map +1 -1
  52. package/dist/managers/SceneTreeManager.d.ts +81 -81
  53. package/dist/managers/SceneTreeManager.d.ts.map +1 -1
  54. package/dist/managers/SceneTreeManager.js +500 -490
  55. package/dist/managers/SceneTreeManager.js.map +1 -1
  56. package/dist/managers/SettingsManager.d.ts +28 -28
  57. package/dist/managers/SettingsManager.js +284 -284
  58. package/dist/managers/SettingsManager.js.map +1 -1
  59. package/dist/managers/environmentGeometry/ContactShadow.d.ts +42 -42
  60. package/dist/managers/environmentGeometry/ContactShadow.js +295 -285
  61. package/dist/managers/environmentGeometry/ContactShadow.js.map +1 -1
  62. package/dist/managers/environmentGeometry/Grid.d.ts +20 -20
  63. package/dist/managers/environmentGeometry/Grid.js +110 -100
  64. package/dist/managers/environmentGeometry/Grid.js.map +1 -1
  65. package/dist/managers/environmentGeometry/GroundPlane.d.ts +21 -21
  66. package/dist/managers/environmentGeometry/GroundPlane.js +105 -95
  67. package/dist/managers/environmentGeometry/GroundPlane.js.map +1 -1
  68. package/dist/managers/environmentGeometry/GroundPlaneShadow.d.ts +21 -21
  69. package/dist/managers/environmentGeometry/GroundPlaneShadow.js +96 -86
  70. package/dist/managers/environmentGeometry/GroundPlaneShadow.js.map +1 -1
  71. package/dist/managers/environmentGeometry/IEnvironmentGeometry.d.ts +8 -8
  72. package/dist/managers/environmentGeometry/IEnvironmentGeometry.js +2 -2
  73. package/dist/managers/postprocessing/GodRaysManager.d.ts +12 -12
  74. package/dist/managers/postprocessing/GodRaysManager.js +73 -63
  75. package/dist/managers/postprocessing/GodRaysManager.js.map +1 -1
  76. package/dist/managers/postprocessing/OutlineManager.d.ts +15 -15
  77. package/dist/managers/postprocessing/OutlineManager.js +86 -76
  78. package/dist/managers/postprocessing/OutlineManager.js.map +1 -1
  79. package/dist/managers/postprocessing/SSAARenderPass.d.ts +53 -53
  80. package/dist/managers/postprocessing/SSAARenderPass.js +281 -281
  81. package/dist/managers/postprocessing/SSAARenderPass.js.map +1 -1
  82. package/dist/managers/postprocessing/SelectiveBloomManager.d.ts +14 -14
  83. package/dist/managers/postprocessing/SelectiveBloomManager.js +76 -66
  84. package/dist/managers/postprocessing/SelectiveBloomManager.js.map +1 -1
  85. package/dist/managers/postprocessing/ao/ao/AOEffect.d.ts +46 -46
  86. package/dist/managers/postprocessing/ao/ao/AOEffect.js +142 -142
  87. package/dist/managers/postprocessing/ao/ao/AOEffect.js.map +1 -1
  88. package/dist/managers/postprocessing/ao/ao/AOPass.d.ts +12 -12
  89. package/dist/managers/postprocessing/ao/ao/AOPass.js +108 -108
  90. package/dist/managers/postprocessing/ao/ao/AOPass.js.map +1 -1
  91. package/dist/managers/postprocessing/ao/ao/shader/ao_compose.d.ts +1 -1
  92. package/dist/managers/postprocessing/ao/ao/shader/ao_compose.js +4 -4
  93. package/dist/managers/postprocessing/ao/ao/shader/ao_utils.d.ts +1 -1
  94. package/dist/managers/postprocessing/ao/ao/shader/ao_utils.js +4 -4
  95. package/dist/managers/postprocessing/ao/hbao/HBAOEffect.d.ts +14 -14
  96. package/dist/managers/postprocessing/ao/hbao/HBAOEffect.js +24 -24
  97. package/dist/managers/postprocessing/ao/hbao/shader/hbao.d.ts +1 -1
  98. package/dist/managers/postprocessing/ao/hbao/shader/hbao.js +4 -4
  99. package/dist/managers/postprocessing/ao/poissionDenoise/PoissionDenoisePass.d.ts +33 -33
  100. package/dist/managers/postprocessing/ao/poissionDenoise/PoissionDenoisePass.js +211 -211
  101. package/dist/managers/postprocessing/ao/poissionDenoise/PoissionDenoisePass.js.map +1 -1
  102. package/dist/managers/postprocessing/ao/poissionDenoise/shader/poissionDenoise.d.ts +1 -1
  103. package/dist/managers/postprocessing/ao/poissionDenoise/shader/poissionDenoise.js +4 -4
  104. package/dist/managers/postprocessing/ao/ssao/SSAOEffect.d.ts +14 -14
  105. package/dist/managers/postprocessing/ao/ssao/SSAOEffect.js +82 -82
  106. package/dist/managers/postprocessing/ao/ssao/SSAOEffect.js.map +1 -1
  107. package/dist/managers/postprocessing/ao/ssao/shader/ssao.d.ts +1 -1
  108. package/dist/managers/postprocessing/ao/ssao/shader/ssao.js +4 -4
  109. package/dist/managers/postprocessing/ao/utils/shader/basic.d.ts +1 -1
  110. package/dist/managers/postprocessing/ao/utils/shader/basic.js +4 -4
  111. package/dist/managers/postprocessing/ao/utils/shader/sampleBlueNoise.d.ts +1 -1
  112. package/dist/managers/postprocessing/ao/utils/shader/sampleBlueNoise.js +4 -4
  113. package/dist/managers/postprocessing/effects/tone-mapping/ToneMappingEffect.d.ts +165 -165
  114. package/dist/managers/postprocessing/effects/tone-mapping/ToneMappingEffect.js +299 -299
  115. package/dist/managers/postprocessing/effects/tone-mapping/ToneMappingEffect.js.map +1 -1
  116. package/dist/managers/postprocessing/effects/tone-mapping/tone-mapping.d.ts +1 -1
  117. package/dist/managers/postprocessing/effects/tone-mapping/tone-mapping.js +4 -4
  118. package/dist/managers/postprocessing/utils/CopyMaterial.d.ts +37 -37
  119. package/dist/managers/postprocessing/utils/CopyMaterial.js +69 -69
  120. package/dist/managers/postprocessing/utils/CopyShader.d.ts +13 -13
  121. package/dist/managers/postprocessing/utils/CopyShader.js +12 -12
  122. package/dist/managers/postprocessing/utils/FullScreenQuad.d.ts +9 -9
  123. package/dist/managers/postprocessing/utils/FullScreenQuad.js +28 -28
  124. package/dist/managers/postprocessing/utils/NormalPass.d.ts +87 -87
  125. package/dist/managers/postprocessing/utils/NormalPass.js +156 -156
  126. package/dist/managers/postprocessing/utils/NormalPass.js.map +1 -1
  127. package/dist/managers/postprocessing/utils/RenderPass.d.ts +114 -114
  128. package/dist/managers/postprocessing/utils/RenderPass.js +259 -259
  129. package/dist/managers/postprocessing/utils/RenderPass.js.map +1 -1
  130. package/dist/managers/sceneTree/SDTFUtils.d.ts +6 -6
  131. package/dist/managers/sceneTree/SDTFUtils.d.ts.map +1 -1
  132. package/dist/managers/sceneTree/SDTFUtils.js +50 -50
  133. package/dist/managers/sceneTree/SDTFUtils.js.map +1 -1
  134. package/dist/managers/sceneTree/SceenTreeManagerUtils.d.ts +7 -7
  135. package/dist/managers/sceneTree/SceenTreeManagerUtils.d.ts.map +1 -1
  136. package/dist/managers/sceneTree/SceenTreeManagerUtils.js +175 -165
  137. package/dist/managers/sceneTree/SceenTreeManagerUtils.js.map +1 -1
  138. package/dist/managers/sceneTree/ThreeJsDataUtils.d.ts +6 -6
  139. package/dist/managers/sceneTree/ThreeJsDataUtils.d.ts.map +1 -1
  140. package/dist/managers/sceneTree/ThreeJsDataUtils.js +80 -70
  141. package/dist/managers/sceneTree/ThreeJsDataUtils.js.map +1 -1
  142. package/dist/materials/GemMaterial.d.ts +37 -37
  143. package/dist/materials/GemMaterial.js +262 -252
  144. package/dist/materials/GemMaterial.js.map +1 -1
  145. package/dist/materials/MeshUnlitMaterialParameters.d.ts +3 -3
  146. package/dist/materials/MeshUnlitMaterialParameters.js +2 -2
  147. package/dist/materials/MultiPointsMaterial.d.ts +93 -93
  148. package/dist/materials/MultiPointsMaterial.js +577 -567
  149. package/dist/materials/MultiPointsMaterial.js.map +1 -1
  150. package/dist/materials/SpecularGlossinessMaterial.d.ts +13 -13
  151. package/dist/materials/SpecularGlossinessMaterial.js +171 -161
  152. package/dist/materials/SpecularGlossinessMaterial.js.map +1 -1
  153. package/dist/objects/SDColor.d.ts +16 -16
  154. package/dist/objects/SDColor.js +52 -52
  155. package/dist/objects/SDColor.js.map +1 -1
  156. package/dist/objects/SDObject.d.ts +27 -27
  157. package/dist/objects/SDObject.js +112 -102
  158. package/dist/objects/SDObject.js.map +1 -1
  159. package/dist/shaders/PCSS.d.ts +2 -2
  160. package/dist/shaders/PCSS.js +5 -5
  161. package/dist/shaders/gem.d.ts +2 -2
  162. package/dist/shaders/gem.js +5 -5
  163. package/dist/shaders/multi_points.d.ts +2 -2
  164. package/dist/shaders/multi_points.js +5 -5
  165. package/dist/styling/viewport-css.d.ts +1 -1
  166. package/dist/styling/viewport-css.js +4 -4
  167. package/dist/three/CSS2DRenderer.d.ts +31 -31
  168. package/dist/three/CSS2DRenderer.d.ts.map +1 -1
  169. package/dist/three/CSS2DRenderer.js +152 -152
  170. package/dist/three/CSS2DRenderer.js.map +1 -1
  171. package/dist/three/geometries/TextGeometry.d.ts +21 -21
  172. package/dist/three/geometries/TextGeometry.js +45 -45
  173. package/dist/three/geometries/TextGeometry.js.map +1 -1
  174. package/dist/three/loaders/RGBELoader.d.ts +23 -23
  175. package/dist/three/loaders/RGBELoader.js +311 -311
  176. package/dist/three/loaders/RGBELoader.js.map +1 -1
  177. package/dist/types/IThreejsData.d.ts +6 -6
  178. package/dist/types/IThreejsData.js +2 -2
  179. package/dist/types/ThreejsData.d.ts +10 -10
  180. package/dist/types/ThreejsData.js +41 -41
  181. package/package.json +18 -18
  182. package/dist/managers/InstanceGroupManager.d.ts +0 -58
  183. package/dist/managers/InstanceGroupManager.d.ts.map +0 -1
  184. package/dist/managers/InstanceGroupManager.js +0 -372
  185. package/dist/managers/InstanceGroupManager.js.map +0 -1
@@ -1,1577 +1,1587 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.adaptShaders = exports.MaterialLoader = void 0;
27
- const viewer_shared_node_tree_1 = require("@shapediver/viewer.shared.node-tree");
28
- const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
29
- const viewer_shared_types_1 = require("@shapediver/viewer.shared.types");
30
- const gl_matrix_1 = require("gl-matrix");
31
- const THREE = __importStar(require("three"));
32
- const GemMaterial_1 = require("../materials/GemMaterial");
33
- const MultiPointsMaterial_1 = require("../materials/MultiPointsMaterial");
34
- const SpecularGlossinessMaterial_1 = require("../materials/SpecularGlossinessMaterial");
35
- const SDColor_1 = require("../objects/SDColor");
36
- const PCSS_1 = require("../shaders/PCSS");
37
- const EnvironmentMapLoader_1 = require("./EnvironmentMapLoader");
38
- // #endregion Type aliases (6)
39
- // #region Classes (1)
40
- class MaterialLoader {
41
- // #endregion Properties (16)
42
- // #region Constructors (1)
43
- constructor(_renderingEngine) {
44
- this._renderingEngine = _renderingEngine;
45
- // #region Properties (16)
46
- this._converter = viewer_shared_services_1.Converter.instance;
47
- this._sceneTree = viewer_shared_node_tree_1.Tree.instance;
48
- this._blending = 0.0;
49
- this._defaultLineMaterialData = new viewer_shared_node_tree_1.MaterialBasicLineData({ color: "#199b9b" });
50
- this._defaultMaterialData = new viewer_shared_node_tree_1.MaterialStandardData({
51
- color: "#199b9b",
52
- side: viewer_shared_types_1.MATERIAL_SIDE.DOUBLE,
53
- metalness: 0.0,
54
- });
55
- this._defaultPointMaterialData = new viewer_shared_node_tree_1.MaterialPointData({ color: "#199b9b" });
56
- this._envMap = null;
57
- this._envMapIntensity = 1;
58
- this._envMapType = EnvironmentMapLoader_1.ENVIRONMENT_MAP_TYPE.NULL;
59
- this._environmentMapRotationEuler = new THREE.Euler();
60
- this._height = 1020;
61
- this._lightSizeUV = 0.025;
62
- this._materialOverrideType = undefined;
63
- this._materialCache = {};
64
- this._shaderProgramCache = new Map();
65
- this._compiledShaderSignatures = new Set();
66
- this._maxMapCount = 0;
67
- this._pointSize = 1.0;
68
- this._textureEncoding = THREE.SRGBColorSpace;
69
- this._threeJsTextureCache = {};
70
- }
71
- // #endregion Constructors (1)
72
- // #region Public Getters And Setters (12)
73
- get defaultLineMaterialData() {
74
- return this._defaultLineMaterialData;
75
- }
76
- set defaultLineMaterialData(value) {
77
- this._defaultLineMaterialData = value;
78
- this.assignDefaultLineMaterial();
79
- }
80
- get defaultMaterialData() {
81
- return this._defaultMaterialData;
82
- }
83
- set defaultMaterialData(value) {
84
- this._defaultMaterialData = value;
85
- this.assignDefaultMaterial();
86
- }
87
- get defaultPointMaterialData() {
88
- return this._defaultPointMaterialData;
89
- }
90
- set defaultPointMaterialData(value) {
91
- this._defaultPointMaterialData = value;
92
- this.assignDefaultPointMaterial();
93
- }
94
- get materialOverrideType() {
95
- return this._materialOverrideType;
96
- }
97
- set materialOverrideType(value) {
98
- if (this._materialOverrideType === value)
99
- return;
100
- this._materialOverrideType = value;
101
- for (const key in this._materialCache) {
102
- this._materialCache[key].material.dispose();
103
- delete this._materialCache[key];
104
- }
105
- this._sceneTree.root.updateVersion();
106
- }
107
- get maxMapCount() {
108
- return this._maxMapCount;
109
- }
110
- set maxMapCount(value) {
111
- this._maxMapCount = value;
112
- }
113
- get textureEncoding() {
114
- return this._textureEncoding;
115
- }
116
- set textureEncoding(value) {
117
- this._textureEncoding = value;
118
- this.assignTextureEncoding();
119
- }
120
- get threeJsTextureCache() {
121
- return this._threeJsTextureCache;
122
- }
123
- set threeJsTextureCache(value) {
124
- this._threeJsTextureCache = value;
125
- }
126
- // #endregion Public Getters And Setters (12)
127
- // #region Public Methods (18)
128
- assignColorCorrection(value) {
129
- const convertColor = (c, toggle) => {
130
- if (!c)
131
- return;
132
- if (c instanceof SDColor_1.SDColor) {
133
- c.colorCorrection(toggle);
134
- return c;
135
- }
136
- else {
137
- const sdColor = this._renderingEngine.colorCache.find((color) => color.equals(c));
138
- if (sdColor) {
139
- sdColor.colorCorrection(toggle);
140
- return sdColor;
141
- }
142
- else {
143
- // we check in this case if the converted color has been stored already
144
- const clone = c.clone();
145
- toggle === true
146
- ? clone.convertSRGBToLinear()
147
- : clone.convertLinearToSRGB();
148
- const sdColorClone = this._renderingEngine.colorCache.find((color) => color.equals(clone));
149
- if (sdColorClone) {
150
- sdColorClone.colorCorrection(toggle);
151
- return sdColorClone;
152
- }
153
- else {
154
- // some colors may not have been set by us, but have been set automatically
155
- // in this case we expect the color to be linear either way and therefore omit a color correction
156
- return c;
157
- }
158
- }
159
- }
160
- };
161
- for (const cacheKey in this._materialCache) {
162
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
163
- const material = this._materialCache[cacheKey].material;
164
- if (material.color)
165
- material.color = convertColor(material.color, value);
166
- if (material.specular)
167
- material.specular = convertColor(material.specular, value);
168
- if (material.emissive)
169
- material.emissive = convertColor(material.emissive, value);
170
- if (material.colorTransferBegin)
171
- material.colorTransferBegin = convertColor(material.colorTransferBegin, value);
172
- if (material.colorTransferEnd)
173
- material.colorTransferEnd = convertColor(material.colorTransferEnd, value);
174
- if (material.attenuationColor)
175
- material.attenuationColor = convertColor(material.attenuationColor, value);
176
- if (material.sheencolor)
177
- material.sheencolor = convertColor(material.sheencolor, value);
178
- if (material.specularColor)
179
- material.specularColor = convertColor(material.specularColor, value);
180
- material.needsUpdate = true;
181
- }
182
- }
183
- assignDefaultLineMaterial() {
184
- for (const cacheKey in this._materialCache) {
185
- if (this._materialCache[cacheKey].material instanceof
186
- THREE.LineBasicMaterial &&
187
- this._materialCache[cacheKey].materialData === null) {
188
- const material = this._materialCache[cacheKey].material;
189
- const { properties, mapCount } = this.getMaterialProperties(this._defaultLineMaterialData, GEOMETRY_MATERIAL_TYPE.LINE, undefined);
190
- this.maxMapCount = Math.max(this.maxMapCount, mapCount);
191
- material.copy(new THREE.LineBasicMaterial(properties));
192
- material.needsUpdate = true;
193
- }
194
- }
195
- }
196
- assignDefaultMaterial() {
197
- for (const cacheKey in this._materialCache) {
198
- if (this._materialCache[cacheKey].materialData === null) {
199
- const material = this._materialCache[cacheKey].material;
200
- const { properties, mapCount } = this.getMaterialProperties(this._defaultMaterialData, GEOMETRY_MATERIAL_TYPE.MESH, this._materialCache[cacheKey].materialSettings);
201
- this.maxMapCount = Math.max(this.maxMapCount, mapCount);
202
- if (material instanceof THREE.MeshBasicMaterial) {
203
- material.copy(new THREE.MeshBasicMaterial(properties));
204
- }
205
- else if (material instanceof THREE.MeshPhongMaterial) {
206
- material.copy(new THREE.MeshPhongMaterial(properties));
207
- }
208
- else if (material instanceof THREE.MeshLambertMaterial) {
209
- material.copy(new THREE.MeshLambertMaterial(properties));
210
- }
211
- else if (material instanceof SpecularGlossinessMaterial_1.SpecularGlossinessMaterial) {
212
- material.copy(new SpecularGlossinessMaterial_1.SpecularGlossinessMaterial(properties));
213
- }
214
- else {
215
- material.copy(new THREE.MeshPhysicalMaterial(properties));
216
- }
217
- material.needsUpdate = true;
218
- }
219
- }
220
- }
221
- assignDefaultPointMaterial() {
222
- for (const cacheKey in this._materialCache) {
223
- if (this._materialCache[cacheKey].material instanceof
224
- THREE.PointsMaterial &&
225
- this._materialCache[cacheKey].materialData === null) {
226
- const material = (this._materialCache[cacheKey].material);
227
- const { properties, mapCount } = this.getMaterialProperties(this._defaultPointMaterialData, GEOMETRY_MATERIAL_TYPE.POINT, undefined);
228
- this.maxMapCount = Math.max(this.maxMapCount, mapCount);
229
- material.copy(new THREE.PointsMaterial(properties));
230
- material.needsUpdate = true;
231
- }
232
- }
233
- }
234
- assignEnvironmentMap(e, type) {
235
- this._envMap = e;
236
- this._envMapType = type;
237
- for (const cacheKey in this._materialCache) {
238
- if (this._materialCache[cacheKey].material instanceof
239
- THREE.MeshPhysicalMaterial ||
240
- this._materialCache[cacheKey].material instanceof
241
- THREE.MeshStandardMaterial ||
242
- this._materialCache[cacheKey].material instanceof
243
- THREE.MeshBasicMaterial ||
244
- this._materialCache[cacheKey].material instanceof
245
- THREE.MeshLambertMaterial ||
246
- this._materialCache[cacheKey].material instanceof
247
- THREE.MeshPhongMaterial) {
248
- const material = this._materialCache[cacheKey].material;
249
- if (this._materialCache[cacheKey].materialData &&
250
- (this._materialCache[cacheKey].materialData instanceof
251
- viewer_shared_node_tree_1.MaterialStandardData ||
252
- this._materialCache[cacheKey].materialData instanceof
253
- viewer_shared_node_tree_1.MaterialGemData ||
254
- this._materialCache[cacheKey].materialData instanceof
255
- viewer_shared_node_tree_1.MaterialSpecularGlossinessData ||
256
- this._materialCache[cacheKey].materialData instanceof
257
- viewer_shared_node_tree_1.MaterialUnlitData ||
258
- this._materialCache[cacheKey].materialData instanceof
259
- viewer_shared_node_tree_1.MaterialLambertData ||
260
- this._materialCache[cacheKey].materialData instanceof
261
- viewer_shared_node_tree_1.MaterialPhongData) &&
262
- (this._materialCache[cacheKey].materialData).envMap !== undefined)
263
- continue;
264
- if ((this._materialCache[cacheKey].materialData instanceof
265
- viewer_shared_node_tree_1.MaterialUnlitData ||
266
- this._materialCache[cacheKey].materialData instanceof
267
- viewer_shared_node_tree_1.MaterialLambertData ||
268
- this._materialCache[cacheKey].materialData instanceof
269
- viewer_shared_node_tree_1.MaterialPhongData) &&
270
- this._renderingEngine.environmentMapForUnlitMaterials ===
271
- false)
272
- return;
273
- material.envMap = e;
274
- material.needsUpdate = true;
275
- for (const d in material.defines) {
276
- if (d.startsWith("ENVMAP_TYPE_"))
277
- delete material.defines[d];
278
- }
279
- if (material.defines)
280
- material.defines["ENVMAP_TYPE_" + this._envMapType.toUpperCase()] = "";
281
- this.assignEnvironmentMapRotation(this._renderingEngine.environmentMapRotation);
282
- }
283
- }
284
- }
285
- assignEnvironmentMapForUnlitMaterials(toggle) {
286
- for (const cacheKey in this._materialCache) {
287
- if (this._materialCache[cacheKey].material instanceof
288
- THREE.MeshBasicMaterial ||
289
- this._materialCache[cacheKey].material instanceof
290
- THREE.MeshLambertMaterial ||
291
- this._materialCache[cacheKey].material instanceof
292
- THREE.MeshPhongMaterial) {
293
- const material = this._materialCache[cacheKey]
294
- .material;
295
- if (this._materialCache[cacheKey].materialData &&
296
- (this._materialCache[cacheKey].materialData instanceof
297
- viewer_shared_node_tree_1.MaterialUnlitData ||
298
- this._materialCache[cacheKey].materialData instanceof
299
- viewer_shared_node_tree_1.MaterialLambertData ||
300
- this._materialCache[cacheKey].materialData instanceof
301
- viewer_shared_node_tree_1.MaterialPhongData) &&
302
- this._materialCache[cacheKey].materialData.envMap !== undefined)
303
- continue;
304
- if (toggle) {
305
- material.envMap = this._envMap;
306
- material.needsUpdate = true;
307
- for (const d in material.defines) {
308
- if (d.startsWith("ENVMAP_TYPE_"))
309
- delete material.defines[d];
310
- }
311
- if (material.defines)
312
- material.defines["ENVMAP_TYPE_" + this._envMapType.toUpperCase()] = "";
313
- }
314
- else {
315
- material.envMap = null;
316
- material.needsUpdate = true;
317
- }
318
- }
319
- }
320
- }
321
- assignEnvironmentMapIntensity(value) {
322
- this._envMapIntensity = value;
323
- for (const cacheKey in this._materialCache) {
324
- if (this._materialCache[cacheKey].material instanceof
325
- THREE.MeshPhysicalMaterial ||
326
- this._materialCache[cacheKey].material instanceof
327
- THREE.MeshStandardMaterial) {
328
- const material = this._materialCache[cacheKey]
329
- .material;
330
- if (this._materialCache[cacheKey].materialData &&
331
- (this._materialCache[cacheKey].materialData instanceof
332
- viewer_shared_node_tree_1.MaterialStandardData ||
333
- this._materialCache[cacheKey].materialData instanceof
334
- viewer_shared_node_tree_1.MaterialGemData ||
335
- this._materialCache[cacheKey].materialData instanceof
336
- viewer_shared_node_tree_1.MaterialSpecularGlossinessData ||
337
- this._materialCache[cacheKey].materialData instanceof
338
- viewer_shared_node_tree_1.MaterialUnlitData) &&
339
- (this._materialCache[cacheKey].materialData).envMap !== undefined)
340
- continue;
341
- material.envMapIntensity = value;
342
- material.needsUpdate = true;
343
- }
344
- }
345
- }
346
- assignEnvironmentMapRotation(value) {
347
- // we switch the y and z axis to match the three.js coordinate system
348
- const rotationMatrix = new THREE.Matrix4()
349
- .fromArray(gl_matrix_1.mat4.fromQuat(gl_matrix_1.mat4.create(), gl_matrix_1.quat.fromValues(value[0], value[2], -value[1], value[3])))
350
- .transpose();
351
- this._environmentMapRotationEuler =
352
- new THREE.Euler().setFromRotationMatrix(rotationMatrix);
353
- this._renderingEngine.scene.backgroundRotation =
354
- this._environmentMapRotationEuler;
355
- for (const cacheKey in this._materialCache) {
356
- if (this._materialCache[cacheKey].material instanceof
357
- THREE.MeshPhysicalMaterial ||
358
- this._materialCache[cacheKey].material instanceof
359
- THREE.MeshStandardMaterial) {
360
- const material = this._materialCache[cacheKey]
361
- .material;
362
- if (this._materialCache[cacheKey].materialData &&
363
- (this._materialCache[cacheKey].materialData instanceof
364
- viewer_shared_node_tree_1.MaterialStandardData ||
365
- this._materialCache[cacheKey].materialData instanceof
366
- viewer_shared_node_tree_1.MaterialGemData ||
367
- this._materialCache[cacheKey].materialData instanceof
368
- viewer_shared_node_tree_1.MaterialSpecularGlossinessData ||
369
- this._materialCache[cacheKey].materialData instanceof
370
- viewer_shared_node_tree_1.MaterialUnlitData) &&
371
- this._materialCache[cacheKey].materialData.envMap !== undefined)
372
- continue;
373
- material.envMapRotation = this._environmentMapRotationEuler;
374
- material.needsUpdate = true;
375
- }
376
- }
377
- }
378
- assignPointSize(p) {
379
- const height = this._renderingEngine.renderer
380
- ? this._renderingEngine.renderer.getSize(new THREE.Vector2()).y
381
- : 1080;
382
- if (height === this._height &&
383
- p * (this._height / 1080) === this._pointSize)
384
- return;
385
- this._height = height;
386
- this._pointSize = p * (this._height / 1080);
387
- for (const cacheKey in this._materialCache) {
388
- if (this._materialCache[cacheKey].material instanceof
389
- MultiPointsMaterial_1.MultiPointsMaterial) {
390
- const material = (this._materialCache[cacheKey].material);
391
- if (this._materialCache[cacheKey].material.userData
392
- .customPointSize_0Enabled &&
393
- this._materialCache[cacheKey].material.userData
394
- .customPointSize_0Enabled === true) {
395
- material.size_0 =
396
- this._pointSize *
397
- this._materialCache[cacheKey].material.userData
398
- .customPointSize_0;
399
- material.needsUpdate = true;
400
- }
401
- else {
402
- material.size_0 = this._pointSize;
403
- material.needsUpdate = true;
404
- }
405
- if (this._materialCache[cacheKey].material.userData
406
- .customPointSize_1Enabled &&
407
- this._materialCache[cacheKey].material.userData
408
- .customPointSize_1Enabled === true) {
409
- material.size_1 =
410
- this._pointSize *
411
- this._materialCache[cacheKey].material.userData
412
- .customPointSize_1;
413
- material.needsUpdate = true;
414
- }
415
- else {
416
- material.size_1 = this._pointSize;
417
- material.needsUpdate = true;
418
- }
419
- if (this._materialCache[cacheKey].material.userData
420
- .customPointSize_2Enabled &&
421
- this._materialCache[cacheKey].material.userData
422
- .customPointSize_2Enabled === true) {
423
- material.size_2 =
424
- this._pointSize *
425
- this._materialCache[cacheKey].material.userData
426
- .customPointSize_2;
427
- material.needsUpdate = true;
428
- }
429
- else {
430
- material.size_2 = this._pointSize;
431
- material.needsUpdate = true;
432
- }
433
- if (this._materialCache[cacheKey].material.userData
434
- .customPointSize_3Enabled &&
435
- this._materialCache[cacheKey].material.userData
436
- .customPointSize_3Enabled === true) {
437
- material.size_3 =
438
- this._pointSize *
439
- this._materialCache[cacheKey].material.userData
440
- .customPointSize_3;
441
- material.needsUpdate = true;
442
- }
443
- else {
444
- material.size_3 = this._pointSize;
445
- material.needsUpdate = true;
446
- }
447
- if (this._materialCache[cacheKey].material.userData
448
- .customPointSize_4Enabled &&
449
- this._materialCache[cacheKey].material.userData
450
- .customPointSize_4Enabled === true) {
451
- material.size_4 =
452
- this._pointSize *
453
- this._materialCache[cacheKey].material.userData
454
- .customPointSize_4;
455
- material.needsUpdate = true;
456
- }
457
- else {
458
- material.size_4 = this._pointSize;
459
- material.needsUpdate = true;
460
- }
461
- if (this._materialCache[cacheKey].material.userData
462
- .customPointSize_5Enabled &&
463
- this._materialCache[cacheKey].material.userData
464
- .customPointSize_5Enabled === true) {
465
- material.size_5 =
466
- this._pointSize *
467
- this._materialCache[cacheKey].material.userData
468
- .customPointSize_5;
469
- material.needsUpdate = true;
470
- }
471
- else {
472
- material.size_5 = this._pointSize;
473
- material.needsUpdate = true;
474
- }
475
- if (this._materialCache[cacheKey].material.userData
476
- .customPointSize_6Enabled &&
477
- this._materialCache[cacheKey].material.userData
478
- .customPointSize_6Enabled === true) {
479
- material.size_6 =
480
- this._pointSize *
481
- this._materialCache[cacheKey].material.userData
482
- .customPointSize_6;
483
- material.needsUpdate = true;
484
- }
485
- else {
486
- material.size_6 = this._pointSize;
487
- material.needsUpdate = true;
488
- }
489
- if (this._materialCache[cacheKey].material.userData
490
- .customPointSize_7Enabled &&
491
- this._materialCache[cacheKey].material.userData
492
- .customPointSize_7Enabled === true) {
493
- material.size_7 =
494
- this._pointSize *
495
- this._materialCache[cacheKey].material.userData
496
- .customPointSize_7;
497
- material.needsUpdate = true;
498
- }
499
- else {
500
- material.size_7 = this._pointSize;
501
- material.needsUpdate = true;
502
- }
503
- }
504
- else if (this._materialCache[cacheKey].material instanceof
505
- THREE.PointsMaterial) {
506
- const material = (this._materialCache[cacheKey].material);
507
- if (this._materialCache[cacheKey].material.userData
508
- .customPointSizeEnabled &&
509
- this._materialCache[cacheKey].material.userData
510
- .customPointSizeEnabled === true) {
511
- material.size =
512
- this._pointSize *
513
- this._materialCache[cacheKey].material.userData
514
- .customPointSize;
515
- material.needsUpdate = true;
516
- }
517
- else {
518
- material.size = this._pointSize;
519
- material.needsUpdate = true;
520
- }
521
- }
522
- }
523
- }
524
- cacheSize() {
525
- return Object.entries(this._materialCache).length;
526
- }
527
- createMaterial(type, incomingData, materialData, materialSettings) {
528
- const { properties, mapCount } = this.getMaterialProperties(materialData, type, materialSettings);
529
- this.maxMapCount = Math.max(this.maxMapCount, mapCount);
530
- let material;
531
- if (type === GEOMETRY_MATERIAL_TYPE.POINT) {
532
- if (materialData instanceof viewer_shared_node_tree_1.MaterialMultiPointData) {
533
- material = new MultiPointsMaterial_1.MultiPointsMaterial(properties);
534
- }
535
- else {
536
- material = new THREE.PointsMaterial(properties);
537
- }
538
- }
539
- else if (type === GEOMETRY_MATERIAL_TYPE.LINE) {
540
- material = new THREE.LineBasicMaterial(properties);
541
- }
542
- else {
543
- if (materialData instanceof viewer_shared_node_tree_1.MaterialUnlitData) {
544
- material = new THREE.MeshBasicMaterial(properties);
545
- }
546
- else {
547
- if (materialData instanceof viewer_shared_node_tree_1.MaterialShadowData) {
548
- material = new THREE.ShadowMaterial({
549
- opacity: properties.opacity,
550
- color: properties.color,
551
- transparent: true,
552
- depthWrite: false,
553
- });
554
- }
555
- else {
556
- if (this._materialOverrideType !== undefined) {
557
- if (this._materialOverrideType === viewer_shared_types_1.MATERIAL_TYPE.UNLIT) {
558
- material = new THREE.MeshBasicMaterial(properties);
559
- }
560
- else if (this._materialOverrideType ===
561
- viewer_shared_types_1.MATERIAL_TYPE.SPECULAR_GLOSSINESS) {
562
- material = new SpecularGlossinessMaterial_1.SpecularGlossinessMaterial(properties);
563
- }
564
- else if (this._materialOverrideType === viewer_shared_types_1.MATERIAL_TYPE.LAMBERT) {
565
- material = new THREE.MeshLambertMaterial(properties);
566
- }
567
- else if (this._materialOverrideType === viewer_shared_types_1.MATERIAL_TYPE.PHONG) {
568
- material = new THREE.MeshPhongMaterial(properties);
569
- }
570
- else {
571
- material = new THREE.MeshPhysicalMaterial(properties);
572
- }
573
- }
574
- else if (materialData instanceof viewer_shared_node_tree_1.MaterialSpecularGlossinessData) {
575
- material = new SpecularGlossinessMaterial_1.SpecularGlossinessMaterial(properties);
576
- }
577
- else if (materialData instanceof viewer_shared_node_tree_1.MaterialGemData) {
578
- material = new GemMaterial_1.GemMaterial(properties);
579
- }
580
- else if (materialData instanceof viewer_shared_node_tree_1.MaterialLambertData) {
581
- material = new THREE.MeshLambertMaterial(properties);
582
- }
583
- else if (materialData instanceof viewer_shared_node_tree_1.MaterialPhongData) {
584
- material = new THREE.MeshPhongMaterial(properties);
585
- }
586
- else {
587
- material = new THREE.MeshPhysicalMaterial(properties);
588
- }
589
- }
590
- const before = material.onBeforeCompile;
591
- material.onBeforeCompile = (shader, renderer) => {
592
- before(shader, renderer);
593
- // Only add uniforms once per shader program to improve performance
594
- if (!shader.uniforms.lightSizeUV) {
595
- shader.uniforms.lightSizeUV = {
596
- value: this._lightSizeUV,
597
- };
598
- shader.uniforms.blending = { value: this._blending };
599
- }
600
- material.userData.shader = shader;
601
- };
602
- if (material instanceof SpecularGlossinessMaterial_1.SpecularGlossinessMaterial ||
603
- material instanceof THREE.MeshPhysicalMaterial) {
604
- material.defines["ENVMAP_TYPE_" + this._envMapType.toUpperCase()] = "";
605
- if (materialSettings && materialSettings.useVertexTangents)
606
- material.normalScale.y *= -1;
607
- if (materialSettings &&
608
- materialSettings.useVertexTangents &&
609
- material instanceof THREE.MeshPhysicalMaterial)
610
- material.clearcoatNormalScale.y *= -1;
611
- if (materialSettings && materialSettings.useFlatShading)
612
- material.flatShading = true;
613
- }
614
- }
615
- }
616
- if (materialSettings && materialSettings.useVertexColors)
617
- material.vertexColors = true;
618
- if (materialData instanceof viewer_shared_node_tree_1.MaterialStandardData ||
619
- materialData instanceof viewer_shared_node_tree_1.MaterialGemData ||
620
- materialData instanceof viewer_shared_node_tree_1.MaterialSpecularGlossinessData ||
621
- materialData instanceof viewer_shared_node_tree_1.MaterialUnlitData ||
622
- materialData instanceof viewer_shared_node_tree_1.MaterialLambertData ||
623
- materialData instanceof viewer_shared_node_tree_1.MaterialPhongData) {
624
- if (materialData.envMap !== undefined) {
625
- const envMapInput = materialData
626
- .envMap;
627
- if (envMapInput !== undefined) {
628
- const envMapResult = this._renderingEngine.environmentMapLoader.loadEnvMap(envMapInput);
629
- envMapResult.map.then((envMap) => {
630
- if ((material instanceof THREE.MeshBasicMaterial ||
631
- material instanceof THREE.MeshLambertMaterial ||
632
- material instanceof THREE.MeshPhongMaterial) &&
633
- this._renderingEngine
634
- .environmentMapForUnlitMaterials === false)
635
- return;
636
- material.envMap = envMap;
637
- const envMapType = material
638
- .envMap instanceof THREE.CubeTexture
639
- ? EnvironmentMapLoader_1.ENVIRONMENT_MAP_TYPE.LDR
640
- : EnvironmentMapLoader_1.ENVIRONMENT_MAP_TYPE.HDR;
641
- for (const d in material.defines) {
642
- if (d.startsWith("ENVMAP_TYPE_"))
643
- delete material.defines[d];
644
- }
645
- if (material.defines)
646
- material.defines["ENVMAP_TYPE_" + envMapType.toUpperCase()] = "";
647
- material.needsUpdate = true;
648
- });
649
- }
650
- }
651
- }
652
- if (materialData)
653
- materialData.convertedObject[this._renderingEngine.id] = material;
654
- material.needsUpdate = true;
655
- if (material.userData) {
656
- material.userData.SDid = incomingData.id;
657
- material.userData.SDversion = incomingData.version;
658
- }
659
- else {
660
- material.userData = {
661
- SDid: incomingData.id,
662
- SDversion: incomingData.version,
663
- };
664
- }
665
- return material;
666
- }
667
- emptyMaterialCache() {
668
- this._materialCache = {};
669
- this._shaderProgramCache.clear();
670
- this._compiledShaderSignatures.clear();
671
- }
672
- getMaterialProperties(materialData, type, materialSettings) {
673
- const generalProperties = {};
674
- let mapCount = 0;
675
- // if no MaterialStandardData is provided, we return our default
676
- if (!materialData) {
677
- if (type === GEOMETRY_MATERIAL_TYPE.POINT) {
678
- return this.getMaterialProperties(this._defaultPointMaterialData, type, materialSettings);
679
- }
680
- else if (type === GEOMETRY_MATERIAL_TYPE.LINE) {
681
- return this.getMaterialProperties(this._defaultLineMaterialData, type, materialSettings);
682
- }
683
- else {
684
- if (materialSettings !== undefined &&
685
- materialSettings.useVertexColors) {
686
- const currentDefaultMaterialColor = this._defaultMaterialData.color;
687
- this._defaultMaterialData.color = "#d3d3d3";
688
- const properties = this.getMaterialProperties(this._defaultMaterialData, type, materialSettings);
689
- this._defaultMaterialData.color =
690
- currentDefaultMaterialColor;
691
- return properties;
692
- }
693
- else {
694
- return this.getMaterialProperties(this._defaultMaterialData, type, materialSettings);
695
- }
696
- }
697
- }
698
- /**
699
- * We know evaluate properties that can be applied to all materials
700
- */
701
- generalProperties.alphaTest = materialData.alphaCutoff;
702
- if (materialData.opacity !== undefined) {
703
- generalProperties.opacity = materialData.opacity;
704
- generalProperties.transparent = generalProperties.opacity < 1;
705
- }
706
- if (materialData.alphaMode === viewer_shared_types_1.MATERIAL_ALPHA.BLEND) {
707
- generalProperties.transparent = true;
708
- generalProperties.depthWrite = false;
709
- }
710
- else if (!generalProperties.transparent) {
711
- generalProperties.transparent = false;
712
- }
713
- if (materialData.depthTest !== undefined) {
714
- generalProperties.depthTest = materialData.depthTest;
715
- }
716
- if (materialData.depthWrite !== undefined) {
717
- generalProperties.depthWrite = materialData.depthWrite;
718
- }
719
- if (materialData.transparent !== undefined) {
720
- generalProperties.transparent = materialData.transparent;
721
- }
722
- if (materialData.color !== undefined)
723
- generalProperties.color = this._renderingEngine.createThreeJsColor(materialData.color);
724
- if (materialData.color === undefined &&
725
- materialData.map !== undefined &&
726
- materialData.map.color !== undefined)
727
- generalProperties.color = this._renderingEngine.createThreeJsColor(materialData.map.color);
728
- if (materialData.color === undefined &&
729
- materialData.map !== undefined &&
730
- materialData.map.color === undefined &&
731
- !(materialSettings !== undefined &&
732
- materialSettings.useVertexColors))
733
- generalProperties.color = this._renderingEngine.createThreeJsColor(this._renderingEngine.defaultMaterialColor);
734
- if (materialSettings !== undefined &&
735
- materialSettings.useVertexColors &&
736
- (materialData.color ===
737
- this._converter.toHexColor(this._renderingEngine.defaultMaterialColor) ||
738
- materialData.color + "ff" ===
739
- this._converter.toHexColor(this._renderingEngine.defaultMaterialColor) ||
740
- materialData.color ===
741
- this._renderingEngine.defaultMaterialColor ||
742
- materialData.color ===
743
- this._renderingEngine.defaultMaterialColor + "ff" ||
744
- materialData.color === undefined))
745
- generalProperties.color =
746
- this._renderingEngine.createThreeJsColor("#d3d3d3");
747
- if (materialData.side !== undefined)
748
- generalProperties.side =
749
- materialData.side === viewer_shared_types_1.MATERIAL_SIDE.BACK
750
- ? THREE.BackSide
751
- : materialData.side === viewer_shared_types_1.MATERIAL_SIDE.FRONT
752
- ? THREE.FrontSide
753
- : THREE.DoubleSide;
754
- /**
755
- *
756
- * First exit, lines ans points
757
- *
758
- */
759
- if (type === GEOMETRY_MATERIAL_TYPE.POINT) {
760
- if (materialData instanceof viewer_shared_node_tree_1.MaterialPointData) {
761
- const pointMaterialProperties = generalProperties;
762
- pointMaterialProperties.size =
763
- materialData.size !== undefined
764
- ? materialData.size
765
- : this._pointSize;
766
- pointMaterialProperties.userData = {
767
- customPointSizeEnabled: materialData.size !== undefined,
768
- customPointSize: materialData.size,
769
- };
770
- pointMaterialProperties.sizeAttenuation =
771
- materialData.sizeAttenuation !== undefined
772
- ? materialData.sizeAttenuation
773
- : true;
774
- if (materialData.map !== undefined) {
775
- pointMaterialProperties.map = this.createTexture(materialData.map);
776
- mapCount++;
777
- }
778
- if (materialData.alphaMap !== undefined) {
779
- pointMaterialProperties.alphaMap = this.createTexture(materialData.alphaMap);
780
- pointMaterialProperties.transparent = true;
781
- pointMaterialProperties.depthWrite = false;
782
- mapCount++;
783
- }
784
- }
785
- else if (materialData instanceof viewer_shared_node_tree_1.MaterialMultiPointData) {
786
- const multiPointMaterialProperties = generalProperties;
787
- if (materialData.materialIndexDataMap) {
788
- multiPointMaterialProperties.materialIndexDataTexture =
789
- this.createTexture(materialData.materialIndexDataMap);
790
- }
791
- else {
792
- multiPointMaterialProperties.materialIndexDataTexture =
793
- new THREE.DataTexture(new Uint8Array(multiPointMaterialProperties.materialIndexDataTextureSize ||
794
- 1024), multiPointMaterialProperties.materialIndexDataTextureSize ||
795
- 1024, 1, THREE.RedIntegerFormat, THREE.UnsignedIntType);
796
- multiPointMaterialProperties.materialIndexDataTexture.internalFormat =
797
- "R32UI";
798
- }
799
- multiPointMaterialProperties.size_0 =
800
- materialData.size_0 !== undefined
801
- ? this._pointSize * materialData.size_0
802
- : this._pointSize;
803
- multiPointMaterialProperties.size_1 =
804
- materialData.size_1 !== undefined
805
- ? this._pointSize * materialData.size_1
806
- : this._pointSize;
807
- multiPointMaterialProperties.size_2 =
808
- materialData.size_2 !== undefined
809
- ? this._pointSize * materialData.size_2
810
- : this._pointSize;
811
- multiPointMaterialProperties.size_3 =
812
- materialData.size_3 !== undefined
813
- ? this._pointSize * materialData.size_3
814
- : this._pointSize;
815
- multiPointMaterialProperties.size_4 =
816
- materialData.size_4 !== undefined
817
- ? this._pointSize * materialData.size_4
818
- : this._pointSize;
819
- multiPointMaterialProperties.size_5 =
820
- materialData.size_5 !== undefined
821
- ? this._pointSize * materialData.size_5
822
- : this._pointSize;
823
- multiPointMaterialProperties.size_6 =
824
- materialData.size_6 !== undefined
825
- ? this._pointSize * materialData.size_6
826
- : this._pointSize;
827
- multiPointMaterialProperties.size_7 =
828
- materialData.size_7 !== undefined
829
- ? this._pointSize * materialData.size_7
830
- : this._pointSize;
831
- multiPointMaterialProperties.userData = {
832
- customPointSize_0Enabled: materialData.size_0 !== undefined,
833
- customPointSize_1Enabled: materialData.size_1 !== undefined,
834
- customPointSize_2Enabled: materialData.size_2 !== undefined,
835
- customPointSize_3Enabled: materialData.size_3 !== undefined,
836
- customPointSize_4Enabled: materialData.size_4 !== undefined,
837
- customPointSize_5Enabled: materialData.size_5 !== undefined,
838
- customPointSize_6Enabled: materialData.size_6 !== undefined,
839
- customPointSize_7Enabled: materialData.size_7 !== undefined,
840
- customPointSize_0: materialData.size_0,
841
- customPointSize_1: materialData.size_1,
842
- customPointSize_2: materialData.size_2,
843
- customPointSize_3: materialData.size_3,
844
- customPointSize_4: materialData.size_4,
845
- customPointSize_5: materialData.size_5,
846
- customPointSize_6: materialData.size_6,
847
- customPointSize_7: materialData.size_7,
848
- };
849
- multiPointMaterialProperties.sizeAttenuation_0 =
850
- materialData.sizeAttenuation_0 !== undefined
851
- ? materialData.sizeAttenuation_0
852
- : false;
853
- multiPointMaterialProperties.sizeAttenuation_1 =
854
- materialData.sizeAttenuation_1 !== undefined
855
- ? materialData.sizeAttenuation_1
856
- : false;
857
- multiPointMaterialProperties.sizeAttenuation_2 =
858
- materialData.sizeAttenuation_2 !== undefined
859
- ? materialData.sizeAttenuation_2
860
- : false;
861
- multiPointMaterialProperties.sizeAttenuation_3 =
862
- materialData.sizeAttenuation_3 !== undefined
863
- ? materialData.sizeAttenuation_3
864
- : false;
865
- multiPointMaterialProperties.sizeAttenuation_4 =
866
- materialData.sizeAttenuation_4 !== undefined
867
- ? materialData.sizeAttenuation_4
868
- : false;
869
- multiPointMaterialProperties.sizeAttenuation_5 =
870
- materialData.sizeAttenuation_5 !== undefined
871
- ? materialData.sizeAttenuation_5
872
- : false;
873
- multiPointMaterialProperties.sizeAttenuation_6 =
874
- materialData.sizeAttenuation_6 !== undefined
875
- ? materialData.sizeAttenuation_6
876
- : false;
877
- multiPointMaterialProperties.sizeAttenuation_7 =
878
- materialData.sizeAttenuation_7 !== undefined
879
- ? materialData.sizeAttenuation_7
880
- : false;
881
- if (materialData.map_0 !== undefined) {
882
- multiPointMaterialProperties.map_0 = this.createTexture(materialData.map_0);
883
- multiPointMaterialProperties.map =
884
- multiPointMaterialProperties.map_0;
885
- mapCount++;
886
- }
887
- if (materialData.map_1 !== undefined) {
888
- multiPointMaterialProperties.map_1 = this.createTexture(materialData.map_1);
889
- multiPointMaterialProperties.map =
890
- multiPointMaterialProperties.map_0;
891
- mapCount++;
892
- }
893
- if (materialData.map_2 !== undefined) {
894
- multiPointMaterialProperties.map_2 = this.createTexture(materialData.map_2);
895
- multiPointMaterialProperties.map =
896
- multiPointMaterialProperties.map_0;
897
- mapCount++;
898
- }
899
- if (materialData.map_3 !== undefined) {
900
- multiPointMaterialProperties.map_3 = this.createTexture(materialData.map_3);
901
- multiPointMaterialProperties.map =
902
- multiPointMaterialProperties.map_0;
903
- mapCount++;
904
- }
905
- if (materialData.map_4 !== undefined) {
906
- multiPointMaterialProperties.map_4 = this.createTexture(materialData.map_4);
907
- multiPointMaterialProperties.map =
908
- multiPointMaterialProperties.map_0;
909
- mapCount++;
910
- }
911
- if (materialData.map_5 !== undefined) {
912
- multiPointMaterialProperties.map_5 = this.createTexture(materialData.map_5);
913
- multiPointMaterialProperties.map =
914
- multiPointMaterialProperties.map_0;
915
- mapCount++;
916
- }
917
- if (materialData.map_6 !== undefined) {
918
- multiPointMaterialProperties.map_6 = this.createTexture(materialData.map_6);
919
- multiPointMaterialProperties.map =
920
- multiPointMaterialProperties.map_0;
921
- mapCount++;
922
- }
923
- if (materialData.map_7 !== undefined) {
924
- multiPointMaterialProperties.map_7 = this.createTexture(materialData.map_7);
925
- multiPointMaterialProperties.map =
926
- multiPointMaterialProperties.map_0;
927
- mapCount++;
928
- }
929
- if (materialData.alphaMap_0 !== undefined) {
930
- multiPointMaterialProperties.alphaMap_0 =
931
- this.createTexture(materialData.alphaMap_0);
932
- multiPointMaterialProperties.alphaMap =
933
- multiPointMaterialProperties.alphaMap_0;
934
- multiPointMaterialProperties.transparent = true;
935
- multiPointMaterialProperties.depthWrite = false;
936
- mapCount++;
937
- }
938
- if (materialData.alphaMap_1 !== undefined) {
939
- multiPointMaterialProperties.alphaMap_1 =
940
- this.createTexture(materialData.alphaMap_1);
941
- multiPointMaterialProperties.alphaMap =
942
- multiPointMaterialProperties.alphaMap_0;
943
- multiPointMaterialProperties.transparent = true;
944
- multiPointMaterialProperties.depthWrite = false;
945
- mapCount++;
946
- }
947
- if (materialData.alphaMap_2 !== undefined) {
948
- multiPointMaterialProperties.alphaMap_2 =
949
- this.createTexture(materialData.alphaMap_2);
950
- multiPointMaterialProperties.alphaMap =
951
- multiPointMaterialProperties.alphaMap_0;
952
- multiPointMaterialProperties.transparent = true;
953
- multiPointMaterialProperties.depthWrite = false;
954
- mapCount++;
955
- }
956
- if (materialData.alphaMap_3 !== undefined) {
957
- multiPointMaterialProperties.alphaMap_3 =
958
- this.createTexture(materialData.alphaMap_3);
959
- multiPointMaterialProperties.alphaMap =
960
- multiPointMaterialProperties.alphaMap_0;
961
- multiPointMaterialProperties.transparent = true;
962
- multiPointMaterialProperties.depthWrite = false;
963
- mapCount++;
964
- }
965
- if (materialData.alphaMap_4 !== undefined) {
966
- multiPointMaterialProperties.alphaMap_4 =
967
- this.createTexture(materialData.alphaMap_4);
968
- multiPointMaterialProperties.alphaMap =
969
- multiPointMaterialProperties.alphaMap_0;
970
- multiPointMaterialProperties.transparent = true;
971
- multiPointMaterialProperties.depthWrite = false;
972
- mapCount++;
973
- }
974
- if (materialData.alphaMap_5 !== undefined) {
975
- multiPointMaterialProperties.alphaMap_5 =
976
- this.createTexture(materialData.alphaMap_5);
977
- multiPointMaterialProperties.alphaMap =
978
- multiPointMaterialProperties.alphaMap_0;
979
- multiPointMaterialProperties.transparent = true;
980
- multiPointMaterialProperties.depthWrite = false;
981
- mapCount++;
982
- }
983
- if (materialData.alphaMap_6 !== undefined) {
984
- multiPointMaterialProperties.alphaMap_6 =
985
- this.createTexture(materialData.alphaMap_6);
986
- multiPointMaterialProperties.alphaMap =
987
- multiPointMaterialProperties.alphaMap_0;
988
- multiPointMaterialProperties.transparent = true;
989
- multiPointMaterialProperties.depthWrite = false;
990
- mapCount++;
991
- }
992
- if (materialData.alphaMap_7 !== undefined) {
993
- multiPointMaterialProperties.alphaMap_7 =
994
- this.createTexture(materialData.alphaMap_7);
995
- multiPointMaterialProperties.alphaMap =
996
- multiPointMaterialProperties.alphaMap_0;
997
- multiPointMaterialProperties.transparent = true;
998
- multiPointMaterialProperties.depthWrite = false;
999
- mapCount++;
1000
- }
1001
- if (materialData.color_0 !== undefined) {
1002
- multiPointMaterialProperties.color_0 =
1003
- this._renderingEngine.createThreeJsColor(materialData.color_0);
1004
- }
1005
- if (materialData.color_1 !== undefined) {
1006
- multiPointMaterialProperties.color_1 =
1007
- this._renderingEngine.createThreeJsColor(materialData.color_1);
1008
- }
1009
- if (materialData.color_2 !== undefined) {
1010
- multiPointMaterialProperties.color_2 =
1011
- this._renderingEngine.createThreeJsColor(materialData.color_2);
1012
- }
1013
- if (materialData.color_3 !== undefined) {
1014
- multiPointMaterialProperties.color_3 =
1015
- this._renderingEngine.createThreeJsColor(materialData.color_3);
1016
- }
1017
- if (materialData.color_4 !== undefined) {
1018
- multiPointMaterialProperties.color_4 =
1019
- this._renderingEngine.createThreeJsColor(materialData.color_4);
1020
- }
1021
- if (materialData.color_5 !== undefined) {
1022
- multiPointMaterialProperties.color_5 =
1023
- this._renderingEngine.createThreeJsColor(materialData.color_5);
1024
- }
1025
- if (materialData.color_6 !== undefined) {
1026
- multiPointMaterialProperties.color_6 =
1027
- this._renderingEngine.createThreeJsColor(materialData.color_6);
1028
- }
1029
- if (materialData.color_7 !== undefined) {
1030
- multiPointMaterialProperties.color_7 =
1031
- this._renderingEngine.createThreeJsColor(materialData.color_7);
1032
- }
1033
- }
1034
- else {
1035
- const pointMaterialProperties = generalProperties;
1036
- pointMaterialProperties.size = this._pointSize;
1037
- }
1038
- return { properties: generalProperties, mapCount };
1039
- }
1040
- else if (type === GEOMETRY_MATERIAL_TYPE.LINE) {
1041
- return { properties: generalProperties, mapCount };
1042
- }
1043
- /**
1044
- *
1045
- * Second exit, the shadow material
1046
- *
1047
- */
1048
- if (materialData instanceof viewer_shared_node_tree_1.MaterialShadowData)
1049
- return { properties: generalProperties, mapCount };
1050
- /**
1051
- * We know evaluate properties that can be applied to basic mesh materials (and the ones extending from them)
1052
- */
1053
- const basicProperties = generalProperties;
1054
- if (materialData.alphaMap !== undefined) {
1055
- basicProperties.alphaMap = this.createTexture(materialData.alphaMap);
1056
- basicProperties.transparent = true;
1057
- basicProperties.depthWrite = false;
1058
- mapCount++;
1059
- }
1060
- if (materialData.aoMap !== undefined) {
1061
- basicProperties.aoMap = this.createTexture(materialData.aoMap);
1062
- mapCount++;
1063
- }
1064
- if (materialData.aoMapIntensity !== undefined) {
1065
- basicProperties.aoMapIntensity = materialData.aoMapIntensity;
1066
- }
1067
- if (materialData.map !== undefined) {
1068
- basicProperties.map = this.createTexture(materialData.map);
1069
- basicProperties.map.colorSpace = this._textureEncoding;
1070
- mapCount++;
1071
- }
1072
- /**
1073
- *
1074
- * Third exit, the unlit material
1075
- *
1076
- */
1077
- if (materialData instanceof viewer_shared_node_tree_1.MaterialUnlitData ||
1078
- this._materialOverrideType === viewer_shared_types_1.MATERIAL_TYPE.UNLIT ||
1079
- this._materialOverrideType === viewer_shared_types_1.MATERIAL_TYPE.LAMBERT ||
1080
- this._materialOverrideType === viewer_shared_types_1.MATERIAL_TYPE.PHONG)
1081
- return { properties: basicProperties, mapCount };
1082
- if (materialData instanceof viewer_shared_node_tree_1.MaterialPhongData &&
1083
- this._materialOverrideType === undefined) {
1084
- const phongProperties = basicProperties;
1085
- phongProperties.shininess = materialData.shininess;
1086
- if (materialData.specular !== undefined)
1087
- phongProperties.specular =
1088
- this._renderingEngine.createThreeJsColor(materialData.specular);
1089
- if (materialData.specularMap !== undefined) {
1090
- phongProperties.specularMap = this.createTexture(materialData.specularMap);
1091
- mapCount++;
1092
- }
1093
- phongProperties.displacementBias = materialData.displacementBias;
1094
- if (materialData.displacementMap !== undefined) {
1095
- phongProperties.displacementMap = this.createTexture(materialData.displacementMap);
1096
- mapCount++;
1097
- }
1098
- phongProperties.displacementScale = materialData.displacementScale;
1099
- phongProperties.reflectivity = materialData.reflectivity;
1100
- return { properties: phongProperties, mapCount };
1101
- }
1102
- if (materialData instanceof viewer_shared_node_tree_1.MaterialLambertData &&
1103
- this._materialOverrideType === undefined) {
1104
- const lambertProperties = basicProperties;
1105
- if (materialData.specularMap !== undefined) {
1106
- lambertProperties.specularMap = this.createTexture(materialData.specularMap);
1107
- mapCount++;
1108
- }
1109
- lambertProperties.displacementBias = materialData.displacementBias;
1110
- if (materialData.displacementMap !== undefined) {
1111
- lambertProperties.displacementMap = this.createTexture(materialData.displacementMap);
1112
- mapCount++;
1113
- }
1114
- lambertProperties.displacementScale =
1115
- materialData.displacementScale;
1116
- lambertProperties.reflectivity = materialData.reflectivity;
1117
- return { properties: lambertProperties, mapCount };
1118
- }
1119
- /**
1120
- * We know evaluate properties that can be applied to MeshPhysicalMaterials, SpecularGlossinessMaterials and GemMaterialParameters
1121
- */
1122
- const standardProperties = basicProperties;
1123
- if (materialData.shading !== undefined)
1124
- standardProperties.flatShading = materialData.shading !== "smooth";
1125
- if (materialData.bumpMap !== undefined) {
1126
- standardProperties.bumpMap = this.createTexture(materialData.bumpMap);
1127
- mapCount++;
1128
- }
1129
- standardProperties.bumpScale = materialData.bumpScale;
1130
- if (materialData.emissiveness !== undefined)
1131
- standardProperties.emissive =
1132
- this._renderingEngine.createThreeJsColor(materialData.emissiveness);
1133
- if (materialData.emissiveMap !== undefined) {
1134
- standardProperties.emissiveMap = this.createTexture(materialData.emissiveMap);
1135
- standardProperties.emissiveMap.colorSpace = this._textureEncoding;
1136
- mapCount++;
1137
- }
1138
- standardProperties.envMap = this._envMap;
1139
- standardProperties.envMapIntensity = this._envMapIntensity;
1140
- standardProperties.envMapRotation = this._environmentMapRotationEuler;
1141
- if (materialData.normalMap !== undefined) {
1142
- standardProperties.normalMap = this.createTexture(materialData.normalMap);
1143
- mapCount++;
1144
- }
1145
- if (materialData.normalScale !== undefined)
1146
- standardProperties.normalScale = new THREE.Vector2(materialData.normalScale, -materialData.normalScale);
1147
- /**
1148
- *
1149
- * Fourth exit, the specular-glossiness material
1150
- *
1151
- */
1152
- if (this._materialOverrideType === viewer_shared_types_1.MATERIAL_TYPE.SPECULAR_GLOSSINESS &&
1153
- !(materialData instanceof viewer_shared_node_tree_1.MaterialSpecularGlossinessData))
1154
- return { properties: standardProperties, mapCount };
1155
- if (materialData instanceof viewer_shared_node_tree_1.MaterialSpecularGlossinessData) {
1156
- const specularGlossinessProperties = standardProperties;
1157
- specularGlossinessProperties.specular =
1158
- this._renderingEngine.createThreeJsColor(materialData.specular);
1159
- specularGlossinessProperties.glossiness = materialData.glossiness;
1160
- if (materialData.specularGlossinessMap !== undefined) {
1161
- specularGlossinessProperties.specularMap2 = this.createTexture(materialData.specularGlossinessMap);
1162
- specularGlossinessProperties.specularMap2.colorSpace =
1163
- THREE.SRGBColorSpace;
1164
- specularGlossinessProperties.glossinessMap =
1165
- specularGlossinessProperties.specularMap2;
1166
- mapCount++;
1167
- }
1168
- else {
1169
- if (materialData.specularMap !== undefined) {
1170
- specularGlossinessProperties.specularMap2 =
1171
- this.createTexture(materialData.specularMap);
1172
- specularGlossinessProperties.specularMap2.colorSpace =
1173
- THREE.SRGBColorSpace;
1174
- mapCount++;
1175
- }
1176
- if (materialData.glossinessMap !== undefined) {
1177
- specularGlossinessProperties.glossinessMap =
1178
- this.createTexture(materialData.glossinessMap);
1179
- mapCount++;
1180
- }
1181
- }
1182
- return { properties: specularGlossinessProperties, mapCount };
1183
- }
1184
- /**
1185
- *
1186
- * Fourth exit, the gem material
1187
- *
1188
- */
1189
- if (materialData instanceof viewer_shared_node_tree_1.MaterialGemData &&
1190
- this._materialOverrideType === undefined) {
1191
- const gemProperties = standardProperties;
1192
- gemProperties.refractionIndex = materialData.refractionIndex;
1193
- if (materialData.impurityMap !== undefined) {
1194
- gemProperties.impurityMap = this.createTexture(materialData.impurityMap);
1195
- mapCount++;
1196
- }
1197
- gemProperties.impurityScale = materialData.impurityScale;
1198
- if (materialData.colorTransferBegin !== undefined) {
1199
- gemProperties.colorTransferBegin =
1200
- this._renderingEngine.createThreeJsColor(materialData.colorTransferBegin);
1201
- }
1202
- if (materialData.colorTransferEnd !== undefined) {
1203
- gemProperties.colorTransferEnd =
1204
- this._renderingEngine.createThreeJsColor(materialData.colorTransferEnd);
1205
- }
1206
- gemProperties.center = new THREE.Vector3(materialData.center[0], materialData.center[1], materialData.center[2]);
1207
- gemProperties.tracingDepth = materialData.tracingDepth;
1208
- gemProperties.radius = materialData.radius;
1209
- gemProperties.sphericalNormalMap = materialData.sphericalNormalMap;
1210
- gemProperties.gamma = materialData.gamma;
1211
- gemProperties.contrast = materialData.contrast;
1212
- gemProperties.brightness = materialData.brightness;
1213
- gemProperties.dispersion = materialData.dispersion;
1214
- gemProperties.tracingOpacity = materialData.tracingOpacity;
1215
- gemProperties.roughness = 0;
1216
- gemProperties.metalness = 1;
1217
- gemProperties.transparent = true;
1218
- gemProperties.opacity = 1.0;
1219
- gemProperties.side = THREE.FrontSide;
1220
- return { properties: gemProperties, mapCount };
1221
- }
1222
- /**
1223
- *
1224
- * the final exit, the MeshPhysicalMaterial
1225
- *
1226
- */
1227
- if (!(materialData instanceof viewer_shared_node_tree_1.MaterialStandardData))
1228
- return { properties: standardProperties, mapCount };
1229
- const meshPhysicalProperties = standardProperties;
1230
- meshPhysicalProperties.clearcoat = materialData.clearcoat;
1231
- if (materialData.clearcoatMap !== undefined) {
1232
- meshPhysicalProperties.clearcoatMap = this.createTexture(materialData.clearcoatMap);
1233
- mapCount++;
1234
- }
1235
- if (materialData.clearcoatNormalMap !== undefined) {
1236
- meshPhysicalProperties.clearcoatNormalMap = this.createTexture(materialData.clearcoatNormalMap);
1237
- mapCount++;
1238
- }
1239
- meshPhysicalProperties.clearcoatRoughness =
1240
- materialData.clearcoatRoughness;
1241
- if (materialData.clearcoatRoughnessMap !== undefined) {
1242
- meshPhysicalProperties.clearcoatRoughnessMap = this.createTexture(materialData.clearcoatRoughnessMap);
1243
- mapCount++;
1244
- }
1245
- if (materialData.displacementMap !== undefined) {
1246
- meshPhysicalProperties.displacementMap = this.createTexture(materialData.displacementMap);
1247
- mapCount++;
1248
- }
1249
- meshPhysicalProperties.displacementScale =
1250
- materialData.displacementScale;
1251
- meshPhysicalProperties.displacementBias = materialData.displacementBias;
1252
- meshPhysicalProperties.ior = materialData.ior;
1253
- meshPhysicalProperties.transmission = materialData.transmission;
1254
- if (materialData.transmissionMap !== undefined) {
1255
- meshPhysicalProperties.transmissionMap = this.createTexture(materialData.transmissionMap);
1256
- mapCount++;
1257
- }
1258
- meshPhysicalProperties.thickness =
1259
- materialData.thickness;
1260
- if (materialData.thicknessMap !== undefined) {
1261
- meshPhysicalProperties.thicknessMap =
1262
- this.createTexture(materialData.thicknessMap);
1263
- mapCount++;
1264
- }
1265
- meshPhysicalProperties.attenuationDistance =
1266
- materialData.attenuationDistance;
1267
- meshPhysicalProperties.attenuationColor =
1268
- this._renderingEngine.createThreeJsColor(materialData.attenuationColor);
1269
- meshPhysicalProperties.sheen = materialData.sheen;
1270
- meshPhysicalProperties.sheenColor =
1271
- this._renderingEngine.createThreeJsColor(materialData.sheenColor);
1272
- meshPhysicalProperties.sheenRoughness = materialData.sheenRoughness;
1273
- if (materialData.sheenColorMap !== undefined) {
1274
- meshPhysicalProperties.sheenColorMap =
1275
- this.createTexture(materialData.sheenColorMap);
1276
- mapCount++;
1277
- }
1278
- if (materialData.sheenRoughnessMap !== undefined) {
1279
- (meshPhysicalProperties).sheenRoughnessMap = this.createTexture(materialData.sheenRoughnessMap);
1280
- mapCount++;
1281
- }
1282
- meshPhysicalProperties.specularIntensity =
1283
- materialData.specularIntensity;
1284
- if (materialData.specularIntensityMap !== undefined) {
1285
- meshPhysicalProperties.specularIntensityMap = this.createTexture(materialData.specularIntensityMap);
1286
- mapCount++;
1287
- }
1288
- meshPhysicalProperties.specularColor =
1289
- this._renderingEngine.createThreeJsColor(materialData.specularColor);
1290
- if (materialData.specularColorMap !== undefined) {
1291
- meshPhysicalProperties.specularColorMap = this.createTexture(materialData.specularColorMap);
1292
- mapCount++;
1293
- }
1294
- meshPhysicalProperties.metalness = materialData.metalness;
1295
- meshPhysicalProperties.roughness = materialData.roughness;
1296
- if (materialData.metalnessRoughnessMap !== undefined) {
1297
- meshPhysicalProperties.metalnessMap = this.createTexture(materialData.metalnessRoughnessMap);
1298
- meshPhysicalProperties.roughnessMap =
1299
- meshPhysicalProperties.metalnessMap;
1300
- mapCount++;
1301
- }
1302
- else {
1303
- if (materialData.metalnessMap !== undefined) {
1304
- meshPhysicalProperties.metalnessMap = this.createTexture(materialData.metalnessMap);
1305
- mapCount++;
1306
- }
1307
- if (materialData.roughnessMap !== undefined) {
1308
- meshPhysicalProperties.roughnessMap = this.createTexture(materialData.roughnessMap);
1309
- mapCount++;
1310
- }
1311
- }
1312
- return { properties: meshPhysicalProperties, mapCount };
1313
- }
1314
- init() { }
1315
- /**
1316
- * Get a shader signature based on properties that affect shader compilation.
1317
- * Materials with the same signature can share compiled shader programs.
1318
- */
1319
- getShaderSignature(type, materialData, materialSettings) {
1320
- // Use a simple string concatenation for better performance than JSON.stringify
1321
- return `${type}_${(materialData === null || materialData === void 0 ? void 0 : materialData.constructor.name) || "default"}_${this._materialOverrideType || "none"}_${(materialSettings === null || materialSettings === void 0 ? void 0 : materialSettings.useVertexColors) ? "vc" : ""}_${(materialSettings === null || materialSettings === void 0 ? void 0 : materialSettings.useFlatShading) ? "fs" : ""}_${(materialSettings === null || materialSettings === void 0 ? void 0 : materialSettings.useMorphTargets) ? "mt" : ""}_${this._envMapType}`;
1322
- }
1323
- /**
1324
- * Precompile shaders for a batch of materials to avoid runtime compilation costs.
1325
- * This should be called during initialization or loading phases.
1326
- */
1327
- precompileShaders(materials, scene, camera) {
1328
- if (!this._renderingEngine.renderer)
1329
- return;
1330
- const compiler = this._renderingEngine.renderer;
1331
- const dummyGeometry = new THREE.PlaneGeometry(1, 1);
1332
- for (const material of materials) {
1333
- // Skip if already compiled
1334
- const signature = material.userData.shaderSignature;
1335
- if (signature && this._compiledShaderSignatures.has(signature)) {
1336
- continue;
1337
- }
1338
- const dummyMesh = new THREE.Mesh(dummyGeometry, material);
1339
- scene.add(dummyMesh);
1340
- compiler.compile(scene, camera);
1341
- scene.remove(dummyMesh);
1342
- if (signature) {
1343
- this._compiledShaderSignatures.add(signature);
1344
- }
1345
- }
1346
- dummyGeometry.dispose();
1347
- }
1348
- /**
1349
- * Create a material object with the provided material data.
1350
- *
1351
- * @param material the material data
1352
- * @returns the material object
1353
- */
1354
- load(incomingData, materialSettings) {
1355
- let materialData = null;
1356
- if (!(incomingData instanceof viewer_shared_node_tree_1.GeometryData))
1357
- materialData = incomingData;
1358
- // evaluate which type of material properties we are constructing
1359
- let type;
1360
- if (materialSettings && materialSettings.mode === 0) {
1361
- type = GEOMETRY_MATERIAL_TYPE.POINT;
1362
- }
1363
- else if (materialSettings &&
1364
- (materialSettings.mode === 1 ||
1365
- materialSettings.mode === 2 ||
1366
- materialSettings.mode === 3)) {
1367
- type = GEOMETRY_MATERIAL_TYPE.LINE;
1368
- }
1369
- else {
1370
- type = GEOMETRY_MATERIAL_TYPE.MESH;
1371
- }
1372
- const cacheKey = this.createDataKeyFromMaterial(incomingData, type, materialSettings);
1373
- // Check material cache first
1374
- if (this._materialCache[cacheKey]) {
1375
- return this._materialCache[cacheKey].material;
1376
- }
1377
- // Create new material
1378
- const material = this.createMaterial(type, incomingData, materialData, materialSettings);
1379
- // Track shader signature for potential future optimizations
1380
- const shaderSignature = this.getShaderSignature(type, materialData, materialSettings);
1381
- material.userData.cacheKey = cacheKey;
1382
- material.userData.shaderSignature = shaderSignature;
1383
- // Store in shader program cache for precompilation tracking
1384
- if (!this._shaderProgramCache.has(shaderSignature)) {
1385
- this._shaderProgramCache.set(shaderSignature, material);
1386
- }
1387
- this._materialCache[cacheKey] = {
1388
- material,
1389
- materialData,
1390
- materialSettings,
1391
- };
1392
- return material;
1393
- }
1394
- removeFromMaterialCache(cacheKey) {
1395
- if (!this._materialCache[cacheKey])
1396
- return;
1397
- this._materialCache[cacheKey].material.dispose();
1398
- delete this._materialCache[cacheKey];
1399
- }
1400
- updateMaterials() {
1401
- for (const cacheKey in this._materialCache)
1402
- this._materialCache[cacheKey].material.needsUpdate = true;
1403
- }
1404
- updateSoftShadow(lightSizeUV, blending) {
1405
- this._lightSizeUV = lightSizeUV;
1406
- this._blending = blending;
1407
- for (const cacheKey in this._materialCache) {
1408
- if (this._materialCache[cacheKey].material.userData.shader) {
1409
- this._materialCache[cacheKey].material.userData.shader.uniforms.lightSizeUV.value =
1410
- lightSizeUV;
1411
- this._materialCache[cacheKey].material.userData.shader.uniforms.blending.value = blending;
1412
- }
1413
- }
1414
- }
1415
- // #endregion Public Methods (18)
1416
- // #region Private Methods (4)
1417
- assignTextureEncoding() {
1418
- for (const cacheKey in this._materialCache) {
1419
- if (this._materialCache[cacheKey].material instanceof
1420
- THREE.MeshPhysicalMaterial ||
1421
- this._materialCache[cacheKey].material instanceof
1422
- THREE.MeshStandardMaterial) {
1423
- const material = this._materialCache[cacheKey].material;
1424
- if (material.emissiveMap) {
1425
- material.emissiveMap.colorSpace = this._textureEncoding;
1426
- material.emissiveMap.needsUpdate = true;
1427
- }
1428
- if (material.map) {
1429
- material.map.colorSpace = this._textureEncoding;
1430
- material.map.needsUpdate = true;
1431
- }
1432
- material.needsUpdate = true;
1433
- }
1434
- }
1435
- }
1436
- createDataKeyFromMap(map) {
1437
- let id = "";
1438
- if (map.asData === true) {
1439
- id = map.id;
1440
- }
1441
- else if (map.image instanceof HTMLImageElement) {
1442
- id = map.image.src;
1443
- }
1444
- else if (map.image instanceof ImageBitmap) {
1445
- id = map.image.id;
1446
- }
1447
- else {
1448
- id = String(map.data);
1449
- }
1450
- return (0, viewer_shared_services_1.btoaCustom)(`${id}_${map.center}_${map.color}_${map.flipY}_${map.magFilter}_${map.minFilter}_${map.offset}_${map.repeat}_${map.rotation}_${map.texCoord}_${map.wrapS}_${map.wrapT}`);
1451
- }
1452
- createDataKeyFromMaterial(data, type, materialSettings) {
1453
- return (0, viewer_shared_services_1.btoaCustom)(data.id +
1454
- "_" +
1455
- data.version +
1456
- "_" +
1457
- type +
1458
- "_" +
1459
- JSON.stringify(materialSettings));
1460
- }
1461
- createTexture(map) {
1462
- if (map.image instanceof ArrayBuffer)
1463
- return new THREE.Texture();
1464
- const key = this.createDataKeyFromMap(map);
1465
- // texture in this structure are only stored until the next scene tree update call
1466
- // therefore no cache management is needed, as these textures need to be created either way
1467
- // the cache is cleared in updateSceneTree
1468
- if (this._threeJsTextureCache[key]) {
1469
- this._threeJsTextureCache[key].usage++;
1470
- return this._threeJsTextureCache[key].texture;
1471
- }
1472
- let texture;
1473
- if (map.asData === true) {
1474
- texture = new THREE.DataTexture(new Uint32Array(map.data), map.data.length, 1, THREE.RedIntegerFormat, THREE.UnsignedIntType);
1475
- texture.internalFormat = "R32UI";
1476
- }
1477
- else {
1478
- texture = new THREE.Texture(map.image);
1479
- texture.format = THREE.RGBAFormat;
1480
- texture.minFilter = (() => {
1481
- switch (map.minFilter) {
1482
- case viewer_shared_types_1.TEXTURE_FILTERING.NEAREST:
1483
- return THREE.NearestFilter;
1484
- case viewer_shared_types_1.TEXTURE_FILTERING.NEAREST_MIPMAP_NEAREST:
1485
- return THREE.NearestMipMapNearestFilter;
1486
- case viewer_shared_types_1.TEXTURE_FILTERING.LINEAR_MIPMAP_NEAREST:
1487
- return THREE.LinearMipMapNearestFilter;
1488
- case viewer_shared_types_1.TEXTURE_FILTERING.NEAREST_MIPMAP_LINEAR:
1489
- return THREE.NearestMipMapLinearFilter;
1490
- case viewer_shared_types_1.TEXTURE_FILTERING.LINEAR:
1491
- return THREE.LinearFilter;
1492
- case viewer_shared_types_1.TEXTURE_FILTERING.LINEAR_MIPMAP_LINEAR:
1493
- default:
1494
- return THREE.LinearMipMapLinearFilter;
1495
- }
1496
- })();
1497
- texture.magFilter = (() => {
1498
- switch (map.magFilter) {
1499
- case viewer_shared_types_1.TEXTURE_FILTERING.NEAREST:
1500
- return THREE.NearestFilter;
1501
- case viewer_shared_types_1.TEXTURE_FILTERING.LINEAR:
1502
- default:
1503
- return THREE.LinearFilter;
1504
- }
1505
- })();
1506
- texture.wrapS = (() => {
1507
- switch (map.wrapS) {
1508
- case viewer_shared_types_1.TEXTURE_WRAPPING.CLAMP_TO_EDGE:
1509
- return THREE.ClampToEdgeWrapping;
1510
- case viewer_shared_types_1.TEXTURE_WRAPPING.MIRRORED_REPEAT:
1511
- return THREE.MirroredRepeatWrapping;
1512
- case viewer_shared_types_1.TEXTURE_WRAPPING.REPEAT:
1513
- default:
1514
- return THREE.RepeatWrapping;
1515
- }
1516
- })();
1517
- texture.wrapT = (() => {
1518
- switch (map.wrapT) {
1519
- case viewer_shared_types_1.TEXTURE_WRAPPING.CLAMP_TO_EDGE:
1520
- return THREE.ClampToEdgeWrapping;
1521
- case viewer_shared_types_1.TEXTURE_WRAPPING.MIRRORED_REPEAT:
1522
- return THREE.MirroredRepeatWrapping;
1523
- case viewer_shared_types_1.TEXTURE_WRAPPING.REPEAT:
1524
- default:
1525
- return THREE.RepeatWrapping;
1526
- }
1527
- })();
1528
- texture.center = new THREE.Vector2(map.center[0], map.center[1]);
1529
- texture.offset = new THREE.Vector2(map.offset[0], map.offset[1]);
1530
- texture.repeat = new THREE.Vector2(map.repeat[0], map.repeat[1]);
1531
- texture.rotation = map.rotation;
1532
- if (map.texCoord !== undefined)
1533
- texture.channel = map.texCoord;
1534
- texture.flipY = map.flipY;
1535
- }
1536
- texture.needsUpdate = true;
1537
- texture.userData.cacheKey = key;
1538
- this._threeJsTextureCache[key] = {
1539
- texture,
1540
- usage: 1,
1541
- initialized: false,
1542
- };
1543
- return this._threeJsTextureCache[key].texture;
1544
- }
1545
- }
1546
- exports.MaterialLoader = MaterialLoader;
1547
- // #endregion Classes (1)
1548
- // #region Enums (1)
1549
- /* eslint-disable @typescript-eslint/no-empty-function */
1550
- var GEOMETRY_MATERIAL_TYPE;
1551
- (function (GEOMETRY_MATERIAL_TYPE) {
1552
- GEOMETRY_MATERIAL_TYPE["POINT"] = "point";
1553
- GEOMETRY_MATERIAL_TYPE["LINE"] = "line";
1554
- GEOMETRY_MATERIAL_TYPE["MESH"] = "mesh";
1555
- })(GEOMETRY_MATERIAL_TYPE || (GEOMETRY_MATERIAL_TYPE = {}));
1556
- // #endregion Enums (1)
1557
- // #region Variables (1)
1558
- const adaptShaders = () => {
1559
- let shader = THREE.ShaderChunk.shadowmap_pars_fragment;
1560
- if (!shader.includes("PCSS implementation")) {
1561
- shader = shader.replace("#ifdef USE_SHADOWMAP", "#ifdef USE_SHADOWMAP" + PCSS_1.main);
1562
- shader = shader.replace(shader.substr(shader.indexOf("#if defined( SHADOWMAP_TYPE_PCF )"), shader.indexOf("#elif defined( SHADOWMAP_TYPE_PCF_SOFT )") -
1563
- shader.indexOf("#if defined( SHADOWMAP_TYPE_PCF )")), "#if defined( SHADOWMAP_TYPE_PCF )\n" + PCSS_1.entry);
1564
- }
1565
- THREE.ShaderChunk.shadowmap_pars_fragment = shader;
1566
- // here we replace in the background cube fragment shader the y component of the reflection vector with the negative y component and inverse the rotation in the case of a LDR environment map
1567
- // console.log(THREE.ShaderChunk.backgroundCube_frag.includes('vec4 texColor = textureCube( envMap, backgroundRotation * vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) );'))
1568
- THREE.ShaderChunk.backgroundCube_frag =
1569
- THREE.ShaderChunk.backgroundCube_frag.replace("vec4 texColor = textureCube( envMap, backgroundRotation * vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) );", "vec4 texColor = textureCube( envMap, inverse(backgroundRotation) * vec3( flipEnvMap * vWorldDirection.x, -vWorldDirection.y, vWorldDirection.z ) );");
1570
- THREE.ShaderLib.backgroundCube.fragmentShader =
1571
- THREE.ShaderChunk.backgroundCube_frag;
1572
- // here we replace in the envmap_physical_pars_fragment the z component of the reflection vector with the negative z component in the case of a LDR environment map
1573
- // console.log(THREE.ShaderChunk.envmap_physical_pars_fragment, THREE.ShaderChunk.envmap_physical_pars_fragment.includes('vec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 );'));
1574
- THREE.ShaderChunk.envmap_physical_pars_fragment =
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.adaptShaders = exports.MaterialLoader = void 0;
37
+ const viewer_shared_node_tree_1 = require("@shapediver/viewer.shared.node-tree");
38
+ const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
39
+ const viewer_shared_types_1 = require("@shapediver/viewer.shared.types");
40
+ const gl_matrix_1 = require("gl-matrix");
41
+ const THREE = __importStar(require("three"));
42
+ const GemMaterial_1 = require("../materials/GemMaterial");
43
+ const MultiPointsMaterial_1 = require("../materials/MultiPointsMaterial");
44
+ const SpecularGlossinessMaterial_1 = require("../materials/SpecularGlossinessMaterial");
45
+ const SDColor_1 = require("../objects/SDColor");
46
+ const PCSS_1 = require("../shaders/PCSS");
47
+ const EnvironmentMapLoader_1 = require("./EnvironmentMapLoader");
48
+ // #endregion Type aliases (6)
49
+ // #region Classes (1)
50
+ class MaterialLoader {
51
+ // #endregion Properties (16)
52
+ // #region Constructors (1)
53
+ constructor(_renderingEngine) {
54
+ this._renderingEngine = _renderingEngine;
55
+ // #region Properties (16)
56
+ this._converter = viewer_shared_services_1.Converter.instance;
57
+ this._sceneTree = viewer_shared_node_tree_1.Tree.instance;
58
+ this._blending = 0.0;
59
+ this._defaultLineMaterialData = new viewer_shared_node_tree_1.MaterialBasicLineData({ color: "#199b9b" });
60
+ this._defaultMaterialData = new viewer_shared_node_tree_1.MaterialStandardData({
61
+ color: "#199b9b",
62
+ side: viewer_shared_types_1.MATERIAL_SIDE.DOUBLE,
63
+ metalness: 0.0,
64
+ });
65
+ this._defaultPointMaterialData = new viewer_shared_node_tree_1.MaterialPointData({ color: "#199b9b" });
66
+ this._envMap = null;
67
+ this._envMapIntensity = 1;
68
+ this._envMapType = EnvironmentMapLoader_1.ENVIRONMENT_MAP_TYPE.NULL;
69
+ this._environmentMapRotationEuler = new THREE.Euler();
70
+ this._height = 1020;
71
+ this._lightSizeUV = 0.025;
72
+ this._materialOverrideType = undefined;
73
+ this._materialCache = {};
74
+ this._shaderProgramCache = new Map();
75
+ this._compiledShaderSignatures = new Set();
76
+ this._maxMapCount = 0;
77
+ this._pointSize = 1.0;
78
+ this._textureEncoding = THREE.SRGBColorSpace;
79
+ this._threeJsTextureCache = {};
80
+ }
81
+ // #endregion Constructors (1)
82
+ // #region Public Getters And Setters (12)
83
+ get defaultLineMaterialData() {
84
+ return this._defaultLineMaterialData;
85
+ }
86
+ set defaultLineMaterialData(value) {
87
+ this._defaultLineMaterialData = value;
88
+ this.assignDefaultLineMaterial();
89
+ }
90
+ get defaultMaterialData() {
91
+ return this._defaultMaterialData;
92
+ }
93
+ set defaultMaterialData(value) {
94
+ this._defaultMaterialData = value;
95
+ this.assignDefaultMaterial();
96
+ }
97
+ get defaultPointMaterialData() {
98
+ return this._defaultPointMaterialData;
99
+ }
100
+ set defaultPointMaterialData(value) {
101
+ this._defaultPointMaterialData = value;
102
+ this.assignDefaultPointMaterial();
103
+ }
104
+ get materialOverrideType() {
105
+ return this._materialOverrideType;
106
+ }
107
+ set materialOverrideType(value) {
108
+ if (this._materialOverrideType === value)
109
+ return;
110
+ this._materialOverrideType = value;
111
+ for (const key in this._materialCache) {
112
+ this._materialCache[key].material.dispose();
113
+ delete this._materialCache[key];
114
+ }
115
+ this._sceneTree.root.updateVersion();
116
+ }
117
+ get maxMapCount() {
118
+ return this._maxMapCount;
119
+ }
120
+ set maxMapCount(value) {
121
+ this._maxMapCount = value;
122
+ }
123
+ get textureEncoding() {
124
+ return this._textureEncoding;
125
+ }
126
+ set textureEncoding(value) {
127
+ this._textureEncoding = value;
128
+ this.assignTextureEncoding();
129
+ }
130
+ get threeJsTextureCache() {
131
+ return this._threeJsTextureCache;
132
+ }
133
+ set threeJsTextureCache(value) {
134
+ this._threeJsTextureCache = value;
135
+ }
136
+ // #endregion Public Getters And Setters (12)
137
+ // #region Public Methods (18)
138
+ assignColorCorrection(value) {
139
+ const convertColor = (c, toggle) => {
140
+ if (!c)
141
+ return;
142
+ if (c instanceof SDColor_1.SDColor) {
143
+ c.colorCorrection(toggle);
144
+ return c;
145
+ }
146
+ else {
147
+ const sdColor = this._renderingEngine.colorCache.find((color) => color.equals(c));
148
+ if (sdColor) {
149
+ sdColor.colorCorrection(toggle);
150
+ return sdColor;
151
+ }
152
+ else {
153
+ // we check in this case if the converted color has been stored already
154
+ const clone = c.clone();
155
+ toggle === true
156
+ ? clone.convertSRGBToLinear()
157
+ : clone.convertLinearToSRGB();
158
+ const sdColorClone = this._renderingEngine.colorCache.find((color) => color.equals(clone));
159
+ if (sdColorClone) {
160
+ sdColorClone.colorCorrection(toggle);
161
+ return sdColorClone;
162
+ }
163
+ else {
164
+ // some colors may not have been set by us, but have been set automatically
165
+ // in this case we expect the color to be linear either way and therefore omit a color correction
166
+ return c;
167
+ }
168
+ }
169
+ }
170
+ };
171
+ for (const cacheKey in this._materialCache) {
172
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
173
+ const material = this._materialCache[cacheKey].material;
174
+ if (material.color)
175
+ material.color = convertColor(material.color, value);
176
+ if (material.specular)
177
+ material.specular = convertColor(material.specular, value);
178
+ if (material.emissive)
179
+ material.emissive = convertColor(material.emissive, value);
180
+ if (material.colorTransferBegin)
181
+ material.colorTransferBegin = convertColor(material.colorTransferBegin, value);
182
+ if (material.colorTransferEnd)
183
+ material.colorTransferEnd = convertColor(material.colorTransferEnd, value);
184
+ if (material.attenuationColor)
185
+ material.attenuationColor = convertColor(material.attenuationColor, value);
186
+ if (material.sheencolor)
187
+ material.sheencolor = convertColor(material.sheencolor, value);
188
+ if (material.specularColor)
189
+ material.specularColor = convertColor(material.specularColor, value);
190
+ material.needsUpdate = true;
191
+ }
192
+ }
193
+ assignDefaultLineMaterial() {
194
+ for (const cacheKey in this._materialCache) {
195
+ if (this._materialCache[cacheKey].material instanceof
196
+ THREE.LineBasicMaterial &&
197
+ this._materialCache[cacheKey].materialData === null) {
198
+ const material = this._materialCache[cacheKey].material;
199
+ const { properties, mapCount } = this.getMaterialProperties(this._defaultLineMaterialData, GEOMETRY_MATERIAL_TYPE.LINE, undefined);
200
+ this.maxMapCount = Math.max(this.maxMapCount, mapCount);
201
+ material.copy(new THREE.LineBasicMaterial(properties));
202
+ material.needsUpdate = true;
203
+ }
204
+ }
205
+ }
206
+ assignDefaultMaterial() {
207
+ for (const cacheKey in this._materialCache) {
208
+ if (this._materialCache[cacheKey].materialData === null) {
209
+ const material = this._materialCache[cacheKey].material;
210
+ const { properties, mapCount } = this.getMaterialProperties(this._defaultMaterialData, GEOMETRY_MATERIAL_TYPE.MESH, this._materialCache[cacheKey].materialSettings);
211
+ this.maxMapCount = Math.max(this.maxMapCount, mapCount);
212
+ if (material instanceof THREE.MeshBasicMaterial) {
213
+ material.copy(new THREE.MeshBasicMaterial(properties));
214
+ }
215
+ else if (material instanceof THREE.MeshPhongMaterial) {
216
+ material.copy(new THREE.MeshPhongMaterial(properties));
217
+ }
218
+ else if (material instanceof THREE.MeshLambertMaterial) {
219
+ material.copy(new THREE.MeshLambertMaterial(properties));
220
+ }
221
+ else if (material instanceof SpecularGlossinessMaterial_1.SpecularGlossinessMaterial) {
222
+ material.copy(new SpecularGlossinessMaterial_1.SpecularGlossinessMaterial(properties));
223
+ }
224
+ else {
225
+ material.copy(new THREE.MeshPhysicalMaterial(properties));
226
+ }
227
+ material.needsUpdate = true;
228
+ }
229
+ }
230
+ }
231
+ assignDefaultPointMaterial() {
232
+ for (const cacheKey in this._materialCache) {
233
+ if (this._materialCache[cacheKey].material instanceof
234
+ THREE.PointsMaterial &&
235
+ this._materialCache[cacheKey].materialData === null) {
236
+ const material = (this._materialCache[cacheKey].material);
237
+ const { properties, mapCount } = this.getMaterialProperties(this._defaultPointMaterialData, GEOMETRY_MATERIAL_TYPE.POINT, undefined);
238
+ this.maxMapCount = Math.max(this.maxMapCount, mapCount);
239
+ material.copy(new THREE.PointsMaterial(properties));
240
+ material.needsUpdate = true;
241
+ }
242
+ }
243
+ }
244
+ assignEnvironmentMap(e, type) {
245
+ this._envMap = e;
246
+ this._envMapType = type;
247
+ for (const cacheKey in this._materialCache) {
248
+ if (this._materialCache[cacheKey].material instanceof
249
+ THREE.MeshPhysicalMaterial ||
250
+ this._materialCache[cacheKey].material instanceof
251
+ THREE.MeshStandardMaterial ||
252
+ this._materialCache[cacheKey].material instanceof
253
+ THREE.MeshBasicMaterial ||
254
+ this._materialCache[cacheKey].material instanceof
255
+ THREE.MeshLambertMaterial ||
256
+ this._materialCache[cacheKey].material instanceof
257
+ THREE.MeshPhongMaterial) {
258
+ const material = this._materialCache[cacheKey].material;
259
+ if (this._materialCache[cacheKey].materialData &&
260
+ (this._materialCache[cacheKey].materialData instanceof
261
+ viewer_shared_node_tree_1.MaterialStandardData ||
262
+ this._materialCache[cacheKey].materialData instanceof
263
+ viewer_shared_node_tree_1.MaterialGemData ||
264
+ this._materialCache[cacheKey].materialData instanceof
265
+ viewer_shared_node_tree_1.MaterialSpecularGlossinessData ||
266
+ this._materialCache[cacheKey].materialData instanceof
267
+ viewer_shared_node_tree_1.MaterialUnlitData ||
268
+ this._materialCache[cacheKey].materialData instanceof
269
+ viewer_shared_node_tree_1.MaterialLambertData ||
270
+ this._materialCache[cacheKey].materialData instanceof
271
+ viewer_shared_node_tree_1.MaterialPhongData) &&
272
+ (this._materialCache[cacheKey].materialData).envMap !== undefined)
273
+ continue;
274
+ if ((this._materialCache[cacheKey].materialData instanceof
275
+ viewer_shared_node_tree_1.MaterialUnlitData ||
276
+ this._materialCache[cacheKey].materialData instanceof
277
+ viewer_shared_node_tree_1.MaterialLambertData ||
278
+ this._materialCache[cacheKey].materialData instanceof
279
+ viewer_shared_node_tree_1.MaterialPhongData) &&
280
+ this._renderingEngine.environmentMapForUnlitMaterials ===
281
+ false)
282
+ return;
283
+ material.envMap = e;
284
+ material.needsUpdate = true;
285
+ for (const d in material.defines) {
286
+ if (d.startsWith("ENVMAP_TYPE_"))
287
+ delete material.defines[d];
288
+ }
289
+ if (material.defines)
290
+ material.defines["ENVMAP_TYPE_" + this._envMapType.toUpperCase()] = "";
291
+ this.assignEnvironmentMapRotation(this._renderingEngine.environmentMapRotation);
292
+ }
293
+ }
294
+ }
295
+ assignEnvironmentMapForUnlitMaterials(toggle) {
296
+ for (const cacheKey in this._materialCache) {
297
+ if (this._materialCache[cacheKey].material instanceof
298
+ THREE.MeshBasicMaterial ||
299
+ this._materialCache[cacheKey].material instanceof
300
+ THREE.MeshLambertMaterial ||
301
+ this._materialCache[cacheKey].material instanceof
302
+ THREE.MeshPhongMaterial) {
303
+ const material = this._materialCache[cacheKey]
304
+ .material;
305
+ if (this._materialCache[cacheKey].materialData &&
306
+ (this._materialCache[cacheKey].materialData instanceof
307
+ viewer_shared_node_tree_1.MaterialUnlitData ||
308
+ this._materialCache[cacheKey].materialData instanceof
309
+ viewer_shared_node_tree_1.MaterialLambertData ||
310
+ this._materialCache[cacheKey].materialData instanceof
311
+ viewer_shared_node_tree_1.MaterialPhongData) &&
312
+ this._materialCache[cacheKey].materialData.envMap !== undefined)
313
+ continue;
314
+ if (toggle) {
315
+ material.envMap = this._envMap;
316
+ material.needsUpdate = true;
317
+ for (const d in material.defines) {
318
+ if (d.startsWith("ENVMAP_TYPE_"))
319
+ delete material.defines[d];
320
+ }
321
+ if (material.defines)
322
+ material.defines["ENVMAP_TYPE_" + this._envMapType.toUpperCase()] = "";
323
+ }
324
+ else {
325
+ material.envMap = null;
326
+ material.needsUpdate = true;
327
+ }
328
+ }
329
+ }
330
+ }
331
+ assignEnvironmentMapIntensity(value) {
332
+ this._envMapIntensity = value;
333
+ for (const cacheKey in this._materialCache) {
334
+ if (this._materialCache[cacheKey].material instanceof
335
+ THREE.MeshPhysicalMaterial ||
336
+ this._materialCache[cacheKey].material instanceof
337
+ THREE.MeshStandardMaterial) {
338
+ const material = this._materialCache[cacheKey]
339
+ .material;
340
+ if (this._materialCache[cacheKey].materialData &&
341
+ (this._materialCache[cacheKey].materialData instanceof
342
+ viewer_shared_node_tree_1.MaterialStandardData ||
343
+ this._materialCache[cacheKey].materialData instanceof
344
+ viewer_shared_node_tree_1.MaterialGemData ||
345
+ this._materialCache[cacheKey].materialData instanceof
346
+ viewer_shared_node_tree_1.MaterialSpecularGlossinessData ||
347
+ this._materialCache[cacheKey].materialData instanceof
348
+ viewer_shared_node_tree_1.MaterialUnlitData) &&
349
+ (this._materialCache[cacheKey].materialData).envMap !== undefined)
350
+ continue;
351
+ material.envMapIntensity = value;
352
+ material.needsUpdate = true;
353
+ }
354
+ }
355
+ }
356
+ assignEnvironmentMapRotation(value) {
357
+ // we switch the y and z axis to match the three.js coordinate system
358
+ const rotationMatrix = new THREE.Matrix4()
359
+ .fromArray(gl_matrix_1.mat4.fromQuat(gl_matrix_1.mat4.create(), gl_matrix_1.quat.fromValues(value[0], value[2], -value[1], value[3])))
360
+ .transpose();
361
+ this._environmentMapRotationEuler =
362
+ new THREE.Euler().setFromRotationMatrix(rotationMatrix);
363
+ this._renderingEngine.scene.backgroundRotation =
364
+ this._environmentMapRotationEuler;
365
+ for (const cacheKey in this._materialCache) {
366
+ if (this._materialCache[cacheKey].material instanceof
367
+ THREE.MeshPhysicalMaterial ||
368
+ this._materialCache[cacheKey].material instanceof
369
+ THREE.MeshStandardMaterial) {
370
+ const material = this._materialCache[cacheKey]
371
+ .material;
372
+ if (this._materialCache[cacheKey].materialData &&
373
+ (this._materialCache[cacheKey].materialData instanceof
374
+ viewer_shared_node_tree_1.MaterialStandardData ||
375
+ this._materialCache[cacheKey].materialData instanceof
376
+ viewer_shared_node_tree_1.MaterialGemData ||
377
+ this._materialCache[cacheKey].materialData instanceof
378
+ viewer_shared_node_tree_1.MaterialSpecularGlossinessData ||
379
+ this._materialCache[cacheKey].materialData instanceof
380
+ viewer_shared_node_tree_1.MaterialUnlitData) &&
381
+ this._materialCache[cacheKey].materialData.envMap !== undefined)
382
+ continue;
383
+ material.envMapRotation = this._environmentMapRotationEuler;
384
+ material.needsUpdate = true;
385
+ }
386
+ }
387
+ }
388
+ assignPointSize(p) {
389
+ const height = this._renderingEngine.renderer
390
+ ? this._renderingEngine.renderer.getSize(new THREE.Vector2()).y
391
+ : 1080;
392
+ if (height === this._height &&
393
+ p * (this._height / 1080) === this._pointSize)
394
+ return;
395
+ this._height = height;
396
+ this._pointSize = p * (this._height / 1080);
397
+ for (const cacheKey in this._materialCache) {
398
+ if (this._materialCache[cacheKey].material instanceof
399
+ MultiPointsMaterial_1.MultiPointsMaterial) {
400
+ const material = (this._materialCache[cacheKey].material);
401
+ if (this._materialCache[cacheKey].material.userData
402
+ .customPointSize_0Enabled &&
403
+ this._materialCache[cacheKey].material.userData
404
+ .customPointSize_0Enabled === true) {
405
+ material.size_0 =
406
+ this._pointSize *
407
+ this._materialCache[cacheKey].material.userData
408
+ .customPointSize_0;
409
+ material.needsUpdate = true;
410
+ }
411
+ else {
412
+ material.size_0 = this._pointSize;
413
+ material.needsUpdate = true;
414
+ }
415
+ if (this._materialCache[cacheKey].material.userData
416
+ .customPointSize_1Enabled &&
417
+ this._materialCache[cacheKey].material.userData
418
+ .customPointSize_1Enabled === true) {
419
+ material.size_1 =
420
+ this._pointSize *
421
+ this._materialCache[cacheKey].material.userData
422
+ .customPointSize_1;
423
+ material.needsUpdate = true;
424
+ }
425
+ else {
426
+ material.size_1 = this._pointSize;
427
+ material.needsUpdate = true;
428
+ }
429
+ if (this._materialCache[cacheKey].material.userData
430
+ .customPointSize_2Enabled &&
431
+ this._materialCache[cacheKey].material.userData
432
+ .customPointSize_2Enabled === true) {
433
+ material.size_2 =
434
+ this._pointSize *
435
+ this._materialCache[cacheKey].material.userData
436
+ .customPointSize_2;
437
+ material.needsUpdate = true;
438
+ }
439
+ else {
440
+ material.size_2 = this._pointSize;
441
+ material.needsUpdate = true;
442
+ }
443
+ if (this._materialCache[cacheKey].material.userData
444
+ .customPointSize_3Enabled &&
445
+ this._materialCache[cacheKey].material.userData
446
+ .customPointSize_3Enabled === true) {
447
+ material.size_3 =
448
+ this._pointSize *
449
+ this._materialCache[cacheKey].material.userData
450
+ .customPointSize_3;
451
+ material.needsUpdate = true;
452
+ }
453
+ else {
454
+ material.size_3 = this._pointSize;
455
+ material.needsUpdate = true;
456
+ }
457
+ if (this._materialCache[cacheKey].material.userData
458
+ .customPointSize_4Enabled &&
459
+ this._materialCache[cacheKey].material.userData
460
+ .customPointSize_4Enabled === true) {
461
+ material.size_4 =
462
+ this._pointSize *
463
+ this._materialCache[cacheKey].material.userData
464
+ .customPointSize_4;
465
+ material.needsUpdate = true;
466
+ }
467
+ else {
468
+ material.size_4 = this._pointSize;
469
+ material.needsUpdate = true;
470
+ }
471
+ if (this._materialCache[cacheKey].material.userData
472
+ .customPointSize_5Enabled &&
473
+ this._materialCache[cacheKey].material.userData
474
+ .customPointSize_5Enabled === true) {
475
+ material.size_5 =
476
+ this._pointSize *
477
+ this._materialCache[cacheKey].material.userData
478
+ .customPointSize_5;
479
+ material.needsUpdate = true;
480
+ }
481
+ else {
482
+ material.size_5 = this._pointSize;
483
+ material.needsUpdate = true;
484
+ }
485
+ if (this._materialCache[cacheKey].material.userData
486
+ .customPointSize_6Enabled &&
487
+ this._materialCache[cacheKey].material.userData
488
+ .customPointSize_6Enabled === true) {
489
+ material.size_6 =
490
+ this._pointSize *
491
+ this._materialCache[cacheKey].material.userData
492
+ .customPointSize_6;
493
+ material.needsUpdate = true;
494
+ }
495
+ else {
496
+ material.size_6 = this._pointSize;
497
+ material.needsUpdate = true;
498
+ }
499
+ if (this._materialCache[cacheKey].material.userData
500
+ .customPointSize_7Enabled &&
501
+ this._materialCache[cacheKey].material.userData
502
+ .customPointSize_7Enabled === true) {
503
+ material.size_7 =
504
+ this._pointSize *
505
+ this._materialCache[cacheKey].material.userData
506
+ .customPointSize_7;
507
+ material.needsUpdate = true;
508
+ }
509
+ else {
510
+ material.size_7 = this._pointSize;
511
+ material.needsUpdate = true;
512
+ }
513
+ }
514
+ else if (this._materialCache[cacheKey].material instanceof
515
+ THREE.PointsMaterial) {
516
+ const material = (this._materialCache[cacheKey].material);
517
+ if (this._materialCache[cacheKey].material.userData
518
+ .customPointSizeEnabled &&
519
+ this._materialCache[cacheKey].material.userData
520
+ .customPointSizeEnabled === true) {
521
+ material.size =
522
+ this._pointSize *
523
+ this._materialCache[cacheKey].material.userData
524
+ .customPointSize;
525
+ material.needsUpdate = true;
526
+ }
527
+ else {
528
+ material.size = this._pointSize;
529
+ material.needsUpdate = true;
530
+ }
531
+ }
532
+ }
533
+ }
534
+ cacheSize() {
535
+ return Object.entries(this._materialCache).length;
536
+ }
537
+ createMaterial(type, incomingData, materialData, materialSettings) {
538
+ const { properties, mapCount } = this.getMaterialProperties(materialData, type, materialSettings);
539
+ this.maxMapCount = Math.max(this.maxMapCount, mapCount);
540
+ let material;
541
+ if (type === GEOMETRY_MATERIAL_TYPE.POINT) {
542
+ if (materialData instanceof viewer_shared_node_tree_1.MaterialMultiPointData) {
543
+ material = new MultiPointsMaterial_1.MultiPointsMaterial(properties);
544
+ }
545
+ else {
546
+ material = new THREE.PointsMaterial(properties);
547
+ }
548
+ }
549
+ else if (type === GEOMETRY_MATERIAL_TYPE.LINE) {
550
+ material = new THREE.LineBasicMaterial(properties);
551
+ }
552
+ else {
553
+ if (materialData instanceof viewer_shared_node_tree_1.MaterialUnlitData) {
554
+ material = new THREE.MeshBasicMaterial(properties);
555
+ }
556
+ else {
557
+ if (materialData instanceof viewer_shared_node_tree_1.MaterialShadowData) {
558
+ material = new THREE.ShadowMaterial({
559
+ opacity: properties.opacity,
560
+ color: properties.color,
561
+ transparent: true,
562
+ depthWrite: false,
563
+ });
564
+ }
565
+ else {
566
+ if (this._materialOverrideType !== undefined) {
567
+ if (this._materialOverrideType === viewer_shared_types_1.MATERIAL_TYPE.UNLIT) {
568
+ material = new THREE.MeshBasicMaterial(properties);
569
+ }
570
+ else if (this._materialOverrideType ===
571
+ viewer_shared_types_1.MATERIAL_TYPE.SPECULAR_GLOSSINESS) {
572
+ material = new SpecularGlossinessMaterial_1.SpecularGlossinessMaterial(properties);
573
+ }
574
+ else if (this._materialOverrideType === viewer_shared_types_1.MATERIAL_TYPE.LAMBERT) {
575
+ material = new THREE.MeshLambertMaterial(properties);
576
+ }
577
+ else if (this._materialOverrideType === viewer_shared_types_1.MATERIAL_TYPE.PHONG) {
578
+ material = new THREE.MeshPhongMaterial(properties);
579
+ }
580
+ else {
581
+ material = new THREE.MeshPhysicalMaterial(properties);
582
+ }
583
+ }
584
+ else if (materialData instanceof viewer_shared_node_tree_1.MaterialSpecularGlossinessData) {
585
+ material = new SpecularGlossinessMaterial_1.SpecularGlossinessMaterial(properties);
586
+ }
587
+ else if (materialData instanceof viewer_shared_node_tree_1.MaterialGemData) {
588
+ material = new GemMaterial_1.GemMaterial(properties);
589
+ }
590
+ else if (materialData instanceof viewer_shared_node_tree_1.MaterialLambertData) {
591
+ material = new THREE.MeshLambertMaterial(properties);
592
+ }
593
+ else if (materialData instanceof viewer_shared_node_tree_1.MaterialPhongData) {
594
+ material = new THREE.MeshPhongMaterial(properties);
595
+ }
596
+ else {
597
+ material = new THREE.MeshPhysicalMaterial(properties);
598
+ }
599
+ }
600
+ const before = material.onBeforeCompile;
601
+ material.onBeforeCompile = (shader, renderer) => {
602
+ before(shader, renderer);
603
+ // Only add uniforms once per shader program to improve performance
604
+ if (!shader.uniforms.lightSizeUV) {
605
+ shader.uniforms.lightSizeUV = {
606
+ value: this._lightSizeUV,
607
+ };
608
+ shader.uniforms.blending = { value: this._blending };
609
+ }
610
+ material.userData.shader = shader;
611
+ };
612
+ if (material instanceof SpecularGlossinessMaterial_1.SpecularGlossinessMaterial ||
613
+ material instanceof THREE.MeshPhysicalMaterial) {
614
+ material.defines["ENVMAP_TYPE_" + this._envMapType.toUpperCase()] = "";
615
+ if (materialSettings && materialSettings.useVertexTangents)
616
+ material.normalScale.y *= -1;
617
+ if (materialSettings &&
618
+ materialSettings.useVertexTangents &&
619
+ material instanceof THREE.MeshPhysicalMaterial)
620
+ material.clearcoatNormalScale.y *= -1;
621
+ if (materialSettings && materialSettings.useFlatShading)
622
+ material.flatShading = true;
623
+ }
624
+ }
625
+ }
626
+ if (materialSettings && materialSettings.useVertexColors)
627
+ material.vertexColors = true;
628
+ if (materialData instanceof viewer_shared_node_tree_1.MaterialStandardData ||
629
+ materialData instanceof viewer_shared_node_tree_1.MaterialGemData ||
630
+ materialData instanceof viewer_shared_node_tree_1.MaterialSpecularGlossinessData ||
631
+ materialData instanceof viewer_shared_node_tree_1.MaterialUnlitData ||
632
+ materialData instanceof viewer_shared_node_tree_1.MaterialLambertData ||
633
+ materialData instanceof viewer_shared_node_tree_1.MaterialPhongData) {
634
+ if (materialData.envMap !== undefined) {
635
+ const envMapInput = materialData
636
+ .envMap;
637
+ if (envMapInput !== undefined) {
638
+ const envMapResult = this._renderingEngine.environmentMapLoader.loadEnvMap(envMapInput);
639
+ envMapResult.map.then((envMap) => {
640
+ if ((material instanceof THREE.MeshBasicMaterial ||
641
+ material instanceof THREE.MeshLambertMaterial ||
642
+ material instanceof THREE.MeshPhongMaterial) &&
643
+ this._renderingEngine
644
+ .environmentMapForUnlitMaterials === false)
645
+ return;
646
+ material.envMap = envMap;
647
+ const envMapType = material
648
+ .envMap instanceof THREE.CubeTexture
649
+ ? EnvironmentMapLoader_1.ENVIRONMENT_MAP_TYPE.LDR
650
+ : EnvironmentMapLoader_1.ENVIRONMENT_MAP_TYPE.HDR;
651
+ for (const d in material.defines) {
652
+ if (d.startsWith("ENVMAP_TYPE_"))
653
+ delete material.defines[d];
654
+ }
655
+ if (material.defines)
656
+ material.defines["ENVMAP_TYPE_" + envMapType.toUpperCase()] = "";
657
+ material.needsUpdate = true;
658
+ });
659
+ }
660
+ }
661
+ }
662
+ if (materialData)
663
+ materialData.convertedObject[this._renderingEngine.id] = material;
664
+ material.needsUpdate = true;
665
+ if (material.userData) {
666
+ material.userData.SDid = incomingData.id;
667
+ material.userData.SDversion = incomingData.version;
668
+ }
669
+ else {
670
+ material.userData = {
671
+ SDid: incomingData.id,
672
+ SDversion: incomingData.version,
673
+ };
674
+ }
675
+ return material;
676
+ }
677
+ emptyMaterialCache() {
678
+ this._materialCache = {};
679
+ this._shaderProgramCache.clear();
680
+ this._compiledShaderSignatures.clear();
681
+ }
682
+ getMaterialProperties(materialData, type, materialSettings) {
683
+ const generalProperties = {};
684
+ let mapCount = 0;
685
+ // if no MaterialStandardData is provided, we return our default
686
+ if (!materialData) {
687
+ if (type === GEOMETRY_MATERIAL_TYPE.POINT) {
688
+ return this.getMaterialProperties(this._defaultPointMaterialData, type, materialSettings);
689
+ }
690
+ else if (type === GEOMETRY_MATERIAL_TYPE.LINE) {
691
+ return this.getMaterialProperties(this._defaultLineMaterialData, type, materialSettings);
692
+ }
693
+ else {
694
+ if (materialSettings !== undefined &&
695
+ materialSettings.useVertexColors) {
696
+ const currentDefaultMaterialColor = this._defaultMaterialData.color;
697
+ this._defaultMaterialData.color = "#d3d3d3";
698
+ const properties = this.getMaterialProperties(this._defaultMaterialData, type, materialSettings);
699
+ this._defaultMaterialData.color =
700
+ currentDefaultMaterialColor;
701
+ return properties;
702
+ }
703
+ else {
704
+ return this.getMaterialProperties(this._defaultMaterialData, type, materialSettings);
705
+ }
706
+ }
707
+ }
708
+ /**
709
+ * We know evaluate properties that can be applied to all materials
710
+ */
711
+ generalProperties.alphaTest = materialData.alphaCutoff;
712
+ if (materialData.opacity !== undefined) {
713
+ generalProperties.opacity = materialData.opacity;
714
+ generalProperties.transparent = generalProperties.opacity < 1;
715
+ }
716
+ if (materialData.alphaMode === viewer_shared_types_1.MATERIAL_ALPHA.BLEND) {
717
+ generalProperties.transparent = true;
718
+ generalProperties.depthWrite = false;
719
+ }
720
+ else if (!generalProperties.transparent) {
721
+ generalProperties.transparent = false;
722
+ }
723
+ if (materialData.depthTest !== undefined) {
724
+ generalProperties.depthTest = materialData.depthTest;
725
+ }
726
+ if (materialData.depthWrite !== undefined) {
727
+ generalProperties.depthWrite = materialData.depthWrite;
728
+ }
729
+ if (materialData.transparent !== undefined) {
730
+ generalProperties.transparent = materialData.transparent;
731
+ }
732
+ if (materialData.color !== undefined)
733
+ generalProperties.color = this._renderingEngine.createThreeJsColor(materialData.color);
734
+ if (materialData.color === undefined &&
735
+ materialData.map !== undefined &&
736
+ materialData.map.color !== undefined)
737
+ generalProperties.color = this._renderingEngine.createThreeJsColor(materialData.map.color);
738
+ if (materialData.color === undefined &&
739
+ materialData.map !== undefined &&
740
+ materialData.map.color === undefined &&
741
+ !(materialSettings !== undefined &&
742
+ materialSettings.useVertexColors))
743
+ generalProperties.color = this._renderingEngine.createThreeJsColor(this._renderingEngine.defaultMaterialColor);
744
+ if (materialSettings !== undefined &&
745
+ materialSettings.useVertexColors &&
746
+ (materialData.color ===
747
+ this._converter.toHexColor(this._renderingEngine.defaultMaterialColor) ||
748
+ materialData.color + "ff" ===
749
+ this._converter.toHexColor(this._renderingEngine.defaultMaterialColor) ||
750
+ materialData.color ===
751
+ this._renderingEngine.defaultMaterialColor ||
752
+ materialData.color ===
753
+ this._renderingEngine.defaultMaterialColor + "ff" ||
754
+ materialData.color === undefined))
755
+ generalProperties.color =
756
+ this._renderingEngine.createThreeJsColor("#d3d3d3");
757
+ if (materialData.side !== undefined)
758
+ generalProperties.side =
759
+ materialData.side === viewer_shared_types_1.MATERIAL_SIDE.BACK
760
+ ? THREE.BackSide
761
+ : materialData.side === viewer_shared_types_1.MATERIAL_SIDE.FRONT
762
+ ? THREE.FrontSide
763
+ : THREE.DoubleSide;
764
+ /**
765
+ *
766
+ * First exit, lines ans points
767
+ *
768
+ */
769
+ if (type === GEOMETRY_MATERIAL_TYPE.POINT) {
770
+ if (materialData instanceof viewer_shared_node_tree_1.MaterialPointData) {
771
+ const pointMaterialProperties = generalProperties;
772
+ pointMaterialProperties.size =
773
+ materialData.size !== undefined
774
+ ? materialData.size
775
+ : this._pointSize;
776
+ pointMaterialProperties.userData = {
777
+ customPointSizeEnabled: materialData.size !== undefined,
778
+ customPointSize: materialData.size,
779
+ };
780
+ pointMaterialProperties.sizeAttenuation =
781
+ materialData.sizeAttenuation !== undefined
782
+ ? materialData.sizeAttenuation
783
+ : true;
784
+ if (materialData.map !== undefined) {
785
+ pointMaterialProperties.map = this.createTexture(materialData.map);
786
+ mapCount++;
787
+ }
788
+ if (materialData.alphaMap !== undefined) {
789
+ pointMaterialProperties.alphaMap = this.createTexture(materialData.alphaMap);
790
+ pointMaterialProperties.transparent = true;
791
+ pointMaterialProperties.depthWrite = false;
792
+ mapCount++;
793
+ }
794
+ }
795
+ else if (materialData instanceof viewer_shared_node_tree_1.MaterialMultiPointData) {
796
+ const multiPointMaterialProperties = generalProperties;
797
+ if (materialData.materialIndexDataMap) {
798
+ multiPointMaterialProperties.materialIndexDataTexture =
799
+ this.createTexture(materialData.materialIndexDataMap);
800
+ }
801
+ else {
802
+ multiPointMaterialProperties.materialIndexDataTexture =
803
+ new THREE.DataTexture(new Uint8Array(multiPointMaterialProperties.materialIndexDataTextureSize ||
804
+ 1024), multiPointMaterialProperties.materialIndexDataTextureSize ||
805
+ 1024, 1, THREE.RedIntegerFormat, THREE.UnsignedIntType);
806
+ multiPointMaterialProperties.materialIndexDataTexture.internalFormat =
807
+ "R32UI";
808
+ }
809
+ multiPointMaterialProperties.size_0 =
810
+ materialData.size_0 !== undefined
811
+ ? this._pointSize * materialData.size_0
812
+ : this._pointSize;
813
+ multiPointMaterialProperties.size_1 =
814
+ materialData.size_1 !== undefined
815
+ ? this._pointSize * materialData.size_1
816
+ : this._pointSize;
817
+ multiPointMaterialProperties.size_2 =
818
+ materialData.size_2 !== undefined
819
+ ? this._pointSize * materialData.size_2
820
+ : this._pointSize;
821
+ multiPointMaterialProperties.size_3 =
822
+ materialData.size_3 !== undefined
823
+ ? this._pointSize * materialData.size_3
824
+ : this._pointSize;
825
+ multiPointMaterialProperties.size_4 =
826
+ materialData.size_4 !== undefined
827
+ ? this._pointSize * materialData.size_4
828
+ : this._pointSize;
829
+ multiPointMaterialProperties.size_5 =
830
+ materialData.size_5 !== undefined
831
+ ? this._pointSize * materialData.size_5
832
+ : this._pointSize;
833
+ multiPointMaterialProperties.size_6 =
834
+ materialData.size_6 !== undefined
835
+ ? this._pointSize * materialData.size_6
836
+ : this._pointSize;
837
+ multiPointMaterialProperties.size_7 =
838
+ materialData.size_7 !== undefined
839
+ ? this._pointSize * materialData.size_7
840
+ : this._pointSize;
841
+ multiPointMaterialProperties.userData = {
842
+ customPointSize_0Enabled: materialData.size_0 !== undefined,
843
+ customPointSize_1Enabled: materialData.size_1 !== undefined,
844
+ customPointSize_2Enabled: materialData.size_2 !== undefined,
845
+ customPointSize_3Enabled: materialData.size_3 !== undefined,
846
+ customPointSize_4Enabled: materialData.size_4 !== undefined,
847
+ customPointSize_5Enabled: materialData.size_5 !== undefined,
848
+ customPointSize_6Enabled: materialData.size_6 !== undefined,
849
+ customPointSize_7Enabled: materialData.size_7 !== undefined,
850
+ customPointSize_0: materialData.size_0,
851
+ customPointSize_1: materialData.size_1,
852
+ customPointSize_2: materialData.size_2,
853
+ customPointSize_3: materialData.size_3,
854
+ customPointSize_4: materialData.size_4,
855
+ customPointSize_5: materialData.size_5,
856
+ customPointSize_6: materialData.size_6,
857
+ customPointSize_7: materialData.size_7,
858
+ };
859
+ multiPointMaterialProperties.sizeAttenuation_0 =
860
+ materialData.sizeAttenuation_0 !== undefined
861
+ ? materialData.sizeAttenuation_0
862
+ : false;
863
+ multiPointMaterialProperties.sizeAttenuation_1 =
864
+ materialData.sizeAttenuation_1 !== undefined
865
+ ? materialData.sizeAttenuation_1
866
+ : false;
867
+ multiPointMaterialProperties.sizeAttenuation_2 =
868
+ materialData.sizeAttenuation_2 !== undefined
869
+ ? materialData.sizeAttenuation_2
870
+ : false;
871
+ multiPointMaterialProperties.sizeAttenuation_3 =
872
+ materialData.sizeAttenuation_3 !== undefined
873
+ ? materialData.sizeAttenuation_3
874
+ : false;
875
+ multiPointMaterialProperties.sizeAttenuation_4 =
876
+ materialData.sizeAttenuation_4 !== undefined
877
+ ? materialData.sizeAttenuation_4
878
+ : false;
879
+ multiPointMaterialProperties.sizeAttenuation_5 =
880
+ materialData.sizeAttenuation_5 !== undefined
881
+ ? materialData.sizeAttenuation_5
882
+ : false;
883
+ multiPointMaterialProperties.sizeAttenuation_6 =
884
+ materialData.sizeAttenuation_6 !== undefined
885
+ ? materialData.sizeAttenuation_6
886
+ : false;
887
+ multiPointMaterialProperties.sizeAttenuation_7 =
888
+ materialData.sizeAttenuation_7 !== undefined
889
+ ? materialData.sizeAttenuation_7
890
+ : false;
891
+ if (materialData.map_0 !== undefined) {
892
+ multiPointMaterialProperties.map_0 = this.createTexture(materialData.map_0);
893
+ multiPointMaterialProperties.map =
894
+ multiPointMaterialProperties.map_0;
895
+ mapCount++;
896
+ }
897
+ if (materialData.map_1 !== undefined) {
898
+ multiPointMaterialProperties.map_1 = this.createTexture(materialData.map_1);
899
+ multiPointMaterialProperties.map =
900
+ multiPointMaterialProperties.map_0;
901
+ mapCount++;
902
+ }
903
+ if (materialData.map_2 !== undefined) {
904
+ multiPointMaterialProperties.map_2 = this.createTexture(materialData.map_2);
905
+ multiPointMaterialProperties.map =
906
+ multiPointMaterialProperties.map_0;
907
+ mapCount++;
908
+ }
909
+ if (materialData.map_3 !== undefined) {
910
+ multiPointMaterialProperties.map_3 = this.createTexture(materialData.map_3);
911
+ multiPointMaterialProperties.map =
912
+ multiPointMaterialProperties.map_0;
913
+ mapCount++;
914
+ }
915
+ if (materialData.map_4 !== undefined) {
916
+ multiPointMaterialProperties.map_4 = this.createTexture(materialData.map_4);
917
+ multiPointMaterialProperties.map =
918
+ multiPointMaterialProperties.map_0;
919
+ mapCount++;
920
+ }
921
+ if (materialData.map_5 !== undefined) {
922
+ multiPointMaterialProperties.map_5 = this.createTexture(materialData.map_5);
923
+ multiPointMaterialProperties.map =
924
+ multiPointMaterialProperties.map_0;
925
+ mapCount++;
926
+ }
927
+ if (materialData.map_6 !== undefined) {
928
+ multiPointMaterialProperties.map_6 = this.createTexture(materialData.map_6);
929
+ multiPointMaterialProperties.map =
930
+ multiPointMaterialProperties.map_0;
931
+ mapCount++;
932
+ }
933
+ if (materialData.map_7 !== undefined) {
934
+ multiPointMaterialProperties.map_7 = this.createTexture(materialData.map_7);
935
+ multiPointMaterialProperties.map =
936
+ multiPointMaterialProperties.map_0;
937
+ mapCount++;
938
+ }
939
+ if (materialData.alphaMap_0 !== undefined) {
940
+ multiPointMaterialProperties.alphaMap_0 =
941
+ this.createTexture(materialData.alphaMap_0);
942
+ multiPointMaterialProperties.alphaMap =
943
+ multiPointMaterialProperties.alphaMap_0;
944
+ multiPointMaterialProperties.transparent = true;
945
+ multiPointMaterialProperties.depthWrite = false;
946
+ mapCount++;
947
+ }
948
+ if (materialData.alphaMap_1 !== undefined) {
949
+ multiPointMaterialProperties.alphaMap_1 =
950
+ this.createTexture(materialData.alphaMap_1);
951
+ multiPointMaterialProperties.alphaMap =
952
+ multiPointMaterialProperties.alphaMap_0;
953
+ multiPointMaterialProperties.transparent = true;
954
+ multiPointMaterialProperties.depthWrite = false;
955
+ mapCount++;
956
+ }
957
+ if (materialData.alphaMap_2 !== undefined) {
958
+ multiPointMaterialProperties.alphaMap_2 =
959
+ this.createTexture(materialData.alphaMap_2);
960
+ multiPointMaterialProperties.alphaMap =
961
+ multiPointMaterialProperties.alphaMap_0;
962
+ multiPointMaterialProperties.transparent = true;
963
+ multiPointMaterialProperties.depthWrite = false;
964
+ mapCount++;
965
+ }
966
+ if (materialData.alphaMap_3 !== undefined) {
967
+ multiPointMaterialProperties.alphaMap_3 =
968
+ this.createTexture(materialData.alphaMap_3);
969
+ multiPointMaterialProperties.alphaMap =
970
+ multiPointMaterialProperties.alphaMap_0;
971
+ multiPointMaterialProperties.transparent = true;
972
+ multiPointMaterialProperties.depthWrite = false;
973
+ mapCount++;
974
+ }
975
+ if (materialData.alphaMap_4 !== undefined) {
976
+ multiPointMaterialProperties.alphaMap_4 =
977
+ this.createTexture(materialData.alphaMap_4);
978
+ multiPointMaterialProperties.alphaMap =
979
+ multiPointMaterialProperties.alphaMap_0;
980
+ multiPointMaterialProperties.transparent = true;
981
+ multiPointMaterialProperties.depthWrite = false;
982
+ mapCount++;
983
+ }
984
+ if (materialData.alphaMap_5 !== undefined) {
985
+ multiPointMaterialProperties.alphaMap_5 =
986
+ this.createTexture(materialData.alphaMap_5);
987
+ multiPointMaterialProperties.alphaMap =
988
+ multiPointMaterialProperties.alphaMap_0;
989
+ multiPointMaterialProperties.transparent = true;
990
+ multiPointMaterialProperties.depthWrite = false;
991
+ mapCount++;
992
+ }
993
+ if (materialData.alphaMap_6 !== undefined) {
994
+ multiPointMaterialProperties.alphaMap_6 =
995
+ this.createTexture(materialData.alphaMap_6);
996
+ multiPointMaterialProperties.alphaMap =
997
+ multiPointMaterialProperties.alphaMap_0;
998
+ multiPointMaterialProperties.transparent = true;
999
+ multiPointMaterialProperties.depthWrite = false;
1000
+ mapCount++;
1001
+ }
1002
+ if (materialData.alphaMap_7 !== undefined) {
1003
+ multiPointMaterialProperties.alphaMap_7 =
1004
+ this.createTexture(materialData.alphaMap_7);
1005
+ multiPointMaterialProperties.alphaMap =
1006
+ multiPointMaterialProperties.alphaMap_0;
1007
+ multiPointMaterialProperties.transparent = true;
1008
+ multiPointMaterialProperties.depthWrite = false;
1009
+ mapCount++;
1010
+ }
1011
+ if (materialData.color_0 !== undefined) {
1012
+ multiPointMaterialProperties.color_0 =
1013
+ this._renderingEngine.createThreeJsColor(materialData.color_0);
1014
+ }
1015
+ if (materialData.color_1 !== undefined) {
1016
+ multiPointMaterialProperties.color_1 =
1017
+ this._renderingEngine.createThreeJsColor(materialData.color_1);
1018
+ }
1019
+ if (materialData.color_2 !== undefined) {
1020
+ multiPointMaterialProperties.color_2 =
1021
+ this._renderingEngine.createThreeJsColor(materialData.color_2);
1022
+ }
1023
+ if (materialData.color_3 !== undefined) {
1024
+ multiPointMaterialProperties.color_3 =
1025
+ this._renderingEngine.createThreeJsColor(materialData.color_3);
1026
+ }
1027
+ if (materialData.color_4 !== undefined) {
1028
+ multiPointMaterialProperties.color_4 =
1029
+ this._renderingEngine.createThreeJsColor(materialData.color_4);
1030
+ }
1031
+ if (materialData.color_5 !== undefined) {
1032
+ multiPointMaterialProperties.color_5 =
1033
+ this._renderingEngine.createThreeJsColor(materialData.color_5);
1034
+ }
1035
+ if (materialData.color_6 !== undefined) {
1036
+ multiPointMaterialProperties.color_6 =
1037
+ this._renderingEngine.createThreeJsColor(materialData.color_6);
1038
+ }
1039
+ if (materialData.color_7 !== undefined) {
1040
+ multiPointMaterialProperties.color_7 =
1041
+ this._renderingEngine.createThreeJsColor(materialData.color_7);
1042
+ }
1043
+ }
1044
+ else {
1045
+ const pointMaterialProperties = generalProperties;
1046
+ pointMaterialProperties.size = this._pointSize;
1047
+ }
1048
+ return { properties: generalProperties, mapCount };
1049
+ }
1050
+ else if (type === GEOMETRY_MATERIAL_TYPE.LINE) {
1051
+ return { properties: generalProperties, mapCount };
1052
+ }
1053
+ /**
1054
+ *
1055
+ * Second exit, the shadow material
1056
+ *
1057
+ */
1058
+ if (materialData instanceof viewer_shared_node_tree_1.MaterialShadowData)
1059
+ return { properties: generalProperties, mapCount };
1060
+ /**
1061
+ * We know evaluate properties that can be applied to basic mesh materials (and the ones extending from them)
1062
+ */
1063
+ const basicProperties = generalProperties;
1064
+ if (materialData.alphaMap !== undefined) {
1065
+ basicProperties.alphaMap = this.createTexture(materialData.alphaMap);
1066
+ basicProperties.transparent = true;
1067
+ basicProperties.depthWrite = false;
1068
+ mapCount++;
1069
+ }
1070
+ if (materialData.aoMap !== undefined) {
1071
+ basicProperties.aoMap = this.createTexture(materialData.aoMap);
1072
+ mapCount++;
1073
+ }
1074
+ if (materialData.aoMapIntensity !== undefined) {
1075
+ basicProperties.aoMapIntensity = materialData.aoMapIntensity;
1076
+ }
1077
+ if (materialData.map !== undefined) {
1078
+ basicProperties.map = this.createTexture(materialData.map);
1079
+ basicProperties.map.colorSpace = this._textureEncoding;
1080
+ mapCount++;
1081
+ }
1082
+ /**
1083
+ *
1084
+ * Third exit, the unlit material
1085
+ *
1086
+ */
1087
+ if (materialData instanceof viewer_shared_node_tree_1.MaterialUnlitData ||
1088
+ this._materialOverrideType === viewer_shared_types_1.MATERIAL_TYPE.UNLIT ||
1089
+ this._materialOverrideType === viewer_shared_types_1.MATERIAL_TYPE.LAMBERT ||
1090
+ this._materialOverrideType === viewer_shared_types_1.MATERIAL_TYPE.PHONG)
1091
+ return { properties: basicProperties, mapCount };
1092
+ if (materialData instanceof viewer_shared_node_tree_1.MaterialPhongData &&
1093
+ this._materialOverrideType === undefined) {
1094
+ const phongProperties = basicProperties;
1095
+ phongProperties.shininess = materialData.shininess;
1096
+ if (materialData.specular !== undefined)
1097
+ phongProperties.specular =
1098
+ this._renderingEngine.createThreeJsColor(materialData.specular);
1099
+ if (materialData.specularMap !== undefined) {
1100
+ phongProperties.specularMap = this.createTexture(materialData.specularMap);
1101
+ mapCount++;
1102
+ }
1103
+ phongProperties.displacementBias = materialData.displacementBias;
1104
+ if (materialData.displacementMap !== undefined) {
1105
+ phongProperties.displacementMap = this.createTexture(materialData.displacementMap);
1106
+ mapCount++;
1107
+ }
1108
+ phongProperties.displacementScale = materialData.displacementScale;
1109
+ phongProperties.reflectivity = materialData.reflectivity;
1110
+ return { properties: phongProperties, mapCount };
1111
+ }
1112
+ if (materialData instanceof viewer_shared_node_tree_1.MaterialLambertData &&
1113
+ this._materialOverrideType === undefined) {
1114
+ const lambertProperties = basicProperties;
1115
+ if (materialData.specularMap !== undefined) {
1116
+ lambertProperties.specularMap = this.createTexture(materialData.specularMap);
1117
+ mapCount++;
1118
+ }
1119
+ lambertProperties.displacementBias = materialData.displacementBias;
1120
+ if (materialData.displacementMap !== undefined) {
1121
+ lambertProperties.displacementMap = this.createTexture(materialData.displacementMap);
1122
+ mapCount++;
1123
+ }
1124
+ lambertProperties.displacementScale =
1125
+ materialData.displacementScale;
1126
+ lambertProperties.reflectivity = materialData.reflectivity;
1127
+ return { properties: lambertProperties, mapCount };
1128
+ }
1129
+ /**
1130
+ * We know evaluate properties that can be applied to MeshPhysicalMaterials, SpecularGlossinessMaterials and GemMaterialParameters
1131
+ */
1132
+ const standardProperties = basicProperties;
1133
+ if (materialData.shading !== undefined)
1134
+ standardProperties.flatShading = materialData.shading !== "smooth";
1135
+ if (materialData.bumpMap !== undefined) {
1136
+ standardProperties.bumpMap = this.createTexture(materialData.bumpMap);
1137
+ mapCount++;
1138
+ }
1139
+ standardProperties.bumpScale = materialData.bumpScale;
1140
+ if (materialData.emissiveness !== undefined)
1141
+ standardProperties.emissive =
1142
+ this._renderingEngine.createThreeJsColor(materialData.emissiveness);
1143
+ if (materialData.emissiveMap !== undefined) {
1144
+ standardProperties.emissiveMap = this.createTexture(materialData.emissiveMap);
1145
+ standardProperties.emissiveMap.colorSpace = this._textureEncoding;
1146
+ mapCount++;
1147
+ }
1148
+ standardProperties.envMap = this._envMap;
1149
+ standardProperties.envMapIntensity = this._envMapIntensity;
1150
+ standardProperties.envMapRotation = this._environmentMapRotationEuler;
1151
+ if (materialData.normalMap !== undefined) {
1152
+ standardProperties.normalMap = this.createTexture(materialData.normalMap);
1153
+ mapCount++;
1154
+ }
1155
+ if (materialData.normalScale !== undefined)
1156
+ standardProperties.normalScale = new THREE.Vector2(materialData.normalScale, -materialData.normalScale);
1157
+ /**
1158
+ *
1159
+ * Fourth exit, the specular-glossiness material
1160
+ *
1161
+ */
1162
+ if (this._materialOverrideType === viewer_shared_types_1.MATERIAL_TYPE.SPECULAR_GLOSSINESS &&
1163
+ !(materialData instanceof viewer_shared_node_tree_1.MaterialSpecularGlossinessData))
1164
+ return { properties: standardProperties, mapCount };
1165
+ if (materialData instanceof viewer_shared_node_tree_1.MaterialSpecularGlossinessData) {
1166
+ const specularGlossinessProperties = standardProperties;
1167
+ specularGlossinessProperties.specular =
1168
+ this._renderingEngine.createThreeJsColor(materialData.specular);
1169
+ specularGlossinessProperties.glossiness = materialData.glossiness;
1170
+ if (materialData.specularGlossinessMap !== undefined) {
1171
+ specularGlossinessProperties.specularMap2 = this.createTexture(materialData.specularGlossinessMap);
1172
+ specularGlossinessProperties.specularMap2.colorSpace =
1173
+ THREE.SRGBColorSpace;
1174
+ specularGlossinessProperties.glossinessMap =
1175
+ specularGlossinessProperties.specularMap2;
1176
+ mapCount++;
1177
+ }
1178
+ else {
1179
+ if (materialData.specularMap !== undefined) {
1180
+ specularGlossinessProperties.specularMap2 =
1181
+ this.createTexture(materialData.specularMap);
1182
+ specularGlossinessProperties.specularMap2.colorSpace =
1183
+ THREE.SRGBColorSpace;
1184
+ mapCount++;
1185
+ }
1186
+ if (materialData.glossinessMap !== undefined) {
1187
+ specularGlossinessProperties.glossinessMap =
1188
+ this.createTexture(materialData.glossinessMap);
1189
+ mapCount++;
1190
+ }
1191
+ }
1192
+ return { properties: specularGlossinessProperties, mapCount };
1193
+ }
1194
+ /**
1195
+ *
1196
+ * Fourth exit, the gem material
1197
+ *
1198
+ */
1199
+ if (materialData instanceof viewer_shared_node_tree_1.MaterialGemData &&
1200
+ this._materialOverrideType === undefined) {
1201
+ const gemProperties = standardProperties;
1202
+ gemProperties.refractionIndex = materialData.refractionIndex;
1203
+ if (materialData.impurityMap !== undefined) {
1204
+ gemProperties.impurityMap = this.createTexture(materialData.impurityMap);
1205
+ mapCount++;
1206
+ }
1207
+ gemProperties.impurityScale = materialData.impurityScale;
1208
+ if (materialData.colorTransferBegin !== undefined) {
1209
+ gemProperties.colorTransferBegin =
1210
+ this._renderingEngine.createThreeJsColor(materialData.colorTransferBegin);
1211
+ }
1212
+ if (materialData.colorTransferEnd !== undefined) {
1213
+ gemProperties.colorTransferEnd =
1214
+ this._renderingEngine.createThreeJsColor(materialData.colorTransferEnd);
1215
+ }
1216
+ gemProperties.center = new THREE.Vector3(materialData.center[0], materialData.center[1], materialData.center[2]);
1217
+ gemProperties.tracingDepth = materialData.tracingDepth;
1218
+ gemProperties.radius = materialData.radius;
1219
+ gemProperties.sphericalNormalMap = materialData.sphericalNormalMap;
1220
+ gemProperties.gamma = materialData.gamma;
1221
+ gemProperties.contrast = materialData.contrast;
1222
+ gemProperties.brightness = materialData.brightness;
1223
+ gemProperties.dispersion = materialData.dispersion;
1224
+ gemProperties.tracingOpacity = materialData.tracingOpacity;
1225
+ gemProperties.roughness = 0;
1226
+ gemProperties.metalness = 1;
1227
+ gemProperties.transparent = true;
1228
+ gemProperties.opacity = 1.0;
1229
+ gemProperties.side = THREE.FrontSide;
1230
+ return { properties: gemProperties, mapCount };
1231
+ }
1232
+ /**
1233
+ *
1234
+ * the final exit, the MeshPhysicalMaterial
1235
+ *
1236
+ */
1237
+ if (!(materialData instanceof viewer_shared_node_tree_1.MaterialStandardData))
1238
+ return { properties: standardProperties, mapCount };
1239
+ const meshPhysicalProperties = standardProperties;
1240
+ meshPhysicalProperties.clearcoat = materialData.clearcoat;
1241
+ if (materialData.clearcoatMap !== undefined) {
1242
+ meshPhysicalProperties.clearcoatMap = this.createTexture(materialData.clearcoatMap);
1243
+ mapCount++;
1244
+ }
1245
+ if (materialData.clearcoatNormalMap !== undefined) {
1246
+ meshPhysicalProperties.clearcoatNormalMap = this.createTexture(materialData.clearcoatNormalMap);
1247
+ mapCount++;
1248
+ }
1249
+ meshPhysicalProperties.clearcoatRoughness =
1250
+ materialData.clearcoatRoughness;
1251
+ if (materialData.clearcoatRoughnessMap !== undefined) {
1252
+ meshPhysicalProperties.clearcoatRoughnessMap = this.createTexture(materialData.clearcoatRoughnessMap);
1253
+ mapCount++;
1254
+ }
1255
+ if (materialData.displacementMap !== undefined) {
1256
+ meshPhysicalProperties.displacementMap = this.createTexture(materialData.displacementMap);
1257
+ mapCount++;
1258
+ }
1259
+ meshPhysicalProperties.displacementScale =
1260
+ materialData.displacementScale;
1261
+ meshPhysicalProperties.displacementBias = materialData.displacementBias;
1262
+ meshPhysicalProperties.ior = materialData.ior;
1263
+ meshPhysicalProperties.transmission = materialData.transmission;
1264
+ if (materialData.transmissionMap !== undefined) {
1265
+ meshPhysicalProperties.transmissionMap = this.createTexture(materialData.transmissionMap);
1266
+ mapCount++;
1267
+ }
1268
+ meshPhysicalProperties.thickness =
1269
+ materialData.thickness;
1270
+ if (materialData.thicknessMap !== undefined) {
1271
+ meshPhysicalProperties.thicknessMap =
1272
+ this.createTexture(materialData.thicknessMap);
1273
+ mapCount++;
1274
+ }
1275
+ meshPhysicalProperties.attenuationDistance =
1276
+ materialData.attenuationDistance;
1277
+ meshPhysicalProperties.attenuationColor =
1278
+ this._renderingEngine.createThreeJsColor(materialData.attenuationColor);
1279
+ meshPhysicalProperties.sheen = materialData.sheen;
1280
+ meshPhysicalProperties.sheenColor =
1281
+ this._renderingEngine.createThreeJsColor(materialData.sheenColor);
1282
+ meshPhysicalProperties.sheenRoughness = materialData.sheenRoughness;
1283
+ if (materialData.sheenColorMap !== undefined) {
1284
+ meshPhysicalProperties.sheenColorMap =
1285
+ this.createTexture(materialData.sheenColorMap);
1286
+ mapCount++;
1287
+ }
1288
+ if (materialData.sheenRoughnessMap !== undefined) {
1289
+ (meshPhysicalProperties).sheenRoughnessMap = this.createTexture(materialData.sheenRoughnessMap);
1290
+ mapCount++;
1291
+ }
1292
+ meshPhysicalProperties.specularIntensity =
1293
+ materialData.specularIntensity;
1294
+ if (materialData.specularIntensityMap !== undefined) {
1295
+ meshPhysicalProperties.specularIntensityMap = this.createTexture(materialData.specularIntensityMap);
1296
+ mapCount++;
1297
+ }
1298
+ meshPhysicalProperties.specularColor =
1299
+ this._renderingEngine.createThreeJsColor(materialData.specularColor);
1300
+ if (materialData.specularColorMap !== undefined) {
1301
+ meshPhysicalProperties.specularColorMap = this.createTexture(materialData.specularColorMap);
1302
+ mapCount++;
1303
+ }
1304
+ meshPhysicalProperties.metalness = materialData.metalness;
1305
+ meshPhysicalProperties.roughness = materialData.roughness;
1306
+ if (materialData.metalnessRoughnessMap !== undefined) {
1307
+ meshPhysicalProperties.metalnessMap = this.createTexture(materialData.metalnessRoughnessMap);
1308
+ meshPhysicalProperties.roughnessMap =
1309
+ meshPhysicalProperties.metalnessMap;
1310
+ mapCount++;
1311
+ }
1312
+ else {
1313
+ if (materialData.metalnessMap !== undefined) {
1314
+ meshPhysicalProperties.metalnessMap = this.createTexture(materialData.metalnessMap);
1315
+ mapCount++;
1316
+ }
1317
+ if (materialData.roughnessMap !== undefined) {
1318
+ meshPhysicalProperties.roughnessMap = this.createTexture(materialData.roughnessMap);
1319
+ mapCount++;
1320
+ }
1321
+ }
1322
+ return { properties: meshPhysicalProperties, mapCount };
1323
+ }
1324
+ init() { }
1325
+ /**
1326
+ * Get a shader signature based on properties that affect shader compilation.
1327
+ * Materials with the same signature can share compiled shader programs.
1328
+ */
1329
+ getShaderSignature(type, materialData, materialSettings) {
1330
+ // Use a simple string concatenation for better performance than JSON.stringify
1331
+ return `${type}_${(materialData === null || materialData === void 0 ? void 0 : materialData.constructor.name) || "default"}_${this._materialOverrideType || "none"}_${(materialSettings === null || materialSettings === void 0 ? void 0 : materialSettings.useVertexColors) ? "vc" : ""}_${(materialSettings === null || materialSettings === void 0 ? void 0 : materialSettings.useFlatShading) ? "fs" : ""}_${(materialSettings === null || materialSettings === void 0 ? void 0 : materialSettings.useMorphTargets) ? "mt" : ""}_${this._envMapType}`;
1332
+ }
1333
+ /**
1334
+ * Precompile shaders for a batch of materials to avoid runtime compilation costs.
1335
+ * This should be called during initialization or loading phases.
1336
+ */
1337
+ precompileShaders(materials, scene, camera) {
1338
+ if (!this._renderingEngine.renderer)
1339
+ return;
1340
+ const compiler = this._renderingEngine.renderer;
1341
+ const dummyGeometry = new THREE.PlaneGeometry(1, 1);
1342
+ for (const material of materials) {
1343
+ // Skip if already compiled
1344
+ const signature = material.userData.shaderSignature;
1345
+ if (signature && this._compiledShaderSignatures.has(signature)) {
1346
+ continue;
1347
+ }
1348
+ const dummyMesh = new THREE.Mesh(dummyGeometry, material);
1349
+ scene.add(dummyMesh);
1350
+ compiler.compile(scene, camera);
1351
+ scene.remove(dummyMesh);
1352
+ if (signature) {
1353
+ this._compiledShaderSignatures.add(signature);
1354
+ }
1355
+ }
1356
+ dummyGeometry.dispose();
1357
+ }
1358
+ /**
1359
+ * Create a material object with the provided material data.
1360
+ *
1361
+ * @param material the material data
1362
+ * @returns the material object
1363
+ */
1364
+ load(incomingData, materialSettings) {
1365
+ let materialData = null;
1366
+ if (!(incomingData instanceof viewer_shared_node_tree_1.GeometryData))
1367
+ materialData = incomingData;
1368
+ // evaluate which type of material properties we are constructing
1369
+ let type;
1370
+ if (materialSettings && materialSettings.mode === 0) {
1371
+ type = GEOMETRY_MATERIAL_TYPE.POINT;
1372
+ }
1373
+ else if (materialSettings &&
1374
+ (materialSettings.mode === 1 ||
1375
+ materialSettings.mode === 2 ||
1376
+ materialSettings.mode === 3)) {
1377
+ type = GEOMETRY_MATERIAL_TYPE.LINE;
1378
+ }
1379
+ else {
1380
+ type = GEOMETRY_MATERIAL_TYPE.MESH;
1381
+ }
1382
+ const cacheKey = this.createDataKeyFromMaterial(incomingData, type, materialSettings);
1383
+ // Check material cache first
1384
+ if (this._materialCache[cacheKey]) {
1385
+ return this._materialCache[cacheKey].material;
1386
+ }
1387
+ // Create new material
1388
+ const material = this.createMaterial(type, incomingData, materialData, materialSettings);
1389
+ // Track shader signature for potential future optimizations
1390
+ const shaderSignature = this.getShaderSignature(type, materialData, materialSettings);
1391
+ material.userData.cacheKey = cacheKey;
1392
+ material.userData.shaderSignature = shaderSignature;
1393
+ // Store in shader program cache for precompilation tracking
1394
+ if (!this._shaderProgramCache.has(shaderSignature)) {
1395
+ this._shaderProgramCache.set(shaderSignature, material);
1396
+ }
1397
+ this._materialCache[cacheKey] = {
1398
+ material,
1399
+ materialData,
1400
+ materialSettings,
1401
+ };
1402
+ return material;
1403
+ }
1404
+ removeFromMaterialCache(cacheKey) {
1405
+ if (!this._materialCache[cacheKey])
1406
+ return;
1407
+ this._materialCache[cacheKey].material.dispose();
1408
+ delete this._materialCache[cacheKey];
1409
+ }
1410
+ updateMaterials() {
1411
+ for (const cacheKey in this._materialCache)
1412
+ this._materialCache[cacheKey].material.needsUpdate = true;
1413
+ }
1414
+ updateSoftShadow(lightSizeUV, blending) {
1415
+ this._lightSizeUV = lightSizeUV;
1416
+ this._blending = blending;
1417
+ for (const cacheKey in this._materialCache) {
1418
+ if (this._materialCache[cacheKey].material.userData.shader) {
1419
+ this._materialCache[cacheKey].material.userData.shader.uniforms.lightSizeUV.value =
1420
+ lightSizeUV;
1421
+ this._materialCache[cacheKey].material.userData.shader.uniforms.blending.value = blending;
1422
+ }
1423
+ }
1424
+ }
1425
+ // #endregion Public Methods (18)
1426
+ // #region Private Methods (4)
1427
+ assignTextureEncoding() {
1428
+ for (const cacheKey in this._materialCache) {
1429
+ if (this._materialCache[cacheKey].material instanceof
1430
+ THREE.MeshPhysicalMaterial ||
1431
+ this._materialCache[cacheKey].material instanceof
1432
+ THREE.MeshStandardMaterial) {
1433
+ const material = this._materialCache[cacheKey].material;
1434
+ if (material.emissiveMap) {
1435
+ material.emissiveMap.colorSpace = this._textureEncoding;
1436
+ material.emissiveMap.needsUpdate = true;
1437
+ }
1438
+ if (material.map) {
1439
+ material.map.colorSpace = this._textureEncoding;
1440
+ material.map.needsUpdate = true;
1441
+ }
1442
+ material.needsUpdate = true;
1443
+ }
1444
+ }
1445
+ }
1446
+ createDataKeyFromMap(map) {
1447
+ let id = "";
1448
+ if (map.asData === true) {
1449
+ id = map.id;
1450
+ }
1451
+ else if (map.image instanceof HTMLImageElement) {
1452
+ id = map.image.src;
1453
+ }
1454
+ else if (map.image instanceof ImageBitmap) {
1455
+ id = map.image.id;
1456
+ }
1457
+ else {
1458
+ id = String(map.data);
1459
+ }
1460
+ return (0, viewer_shared_services_1.btoaCustom)(`${id}_${map.center}_${map.color}_${map.flipY}_${map.magFilter}_${map.minFilter}_${map.offset}_${map.repeat}_${map.rotation}_${map.texCoord}_${map.wrapS}_${map.wrapT}`);
1461
+ }
1462
+ createDataKeyFromMaterial(data, type, materialSettings) {
1463
+ return (0, viewer_shared_services_1.btoaCustom)(data.id +
1464
+ "_" +
1465
+ data.version +
1466
+ "_" +
1467
+ type +
1468
+ "_" +
1469
+ JSON.stringify(materialSettings));
1470
+ }
1471
+ createTexture(map) {
1472
+ if (map.image instanceof ArrayBuffer)
1473
+ return new THREE.Texture();
1474
+ const key = this.createDataKeyFromMap(map);
1475
+ // texture in this structure are only stored until the next scene tree update call
1476
+ // therefore no cache management is needed, as these textures need to be created either way
1477
+ // the cache is cleared in updateSceneTree
1478
+ if (this._threeJsTextureCache[key]) {
1479
+ this._threeJsTextureCache[key].usage++;
1480
+ return this._threeJsTextureCache[key].texture;
1481
+ }
1482
+ let texture;
1483
+ if (map.asData === true) {
1484
+ texture = new THREE.DataTexture(new Uint32Array(map.data), map.data.length, 1, THREE.RedIntegerFormat, THREE.UnsignedIntType);
1485
+ texture.internalFormat = "R32UI";
1486
+ }
1487
+ else {
1488
+ texture = new THREE.Texture(map.image);
1489
+ texture.format = THREE.RGBAFormat;
1490
+ texture.minFilter = (() => {
1491
+ switch (map.minFilter) {
1492
+ case viewer_shared_types_1.TEXTURE_FILTERING.NEAREST:
1493
+ return THREE.NearestFilter;
1494
+ case viewer_shared_types_1.TEXTURE_FILTERING.NEAREST_MIPMAP_NEAREST:
1495
+ return THREE.NearestMipMapNearestFilter;
1496
+ case viewer_shared_types_1.TEXTURE_FILTERING.LINEAR_MIPMAP_NEAREST:
1497
+ return THREE.LinearMipMapNearestFilter;
1498
+ case viewer_shared_types_1.TEXTURE_FILTERING.NEAREST_MIPMAP_LINEAR:
1499
+ return THREE.NearestMipMapLinearFilter;
1500
+ case viewer_shared_types_1.TEXTURE_FILTERING.LINEAR:
1501
+ return THREE.LinearFilter;
1502
+ case viewer_shared_types_1.TEXTURE_FILTERING.LINEAR_MIPMAP_LINEAR:
1503
+ default:
1504
+ return THREE.LinearMipMapLinearFilter;
1505
+ }
1506
+ })();
1507
+ texture.magFilter = (() => {
1508
+ switch (map.magFilter) {
1509
+ case viewer_shared_types_1.TEXTURE_FILTERING.NEAREST:
1510
+ return THREE.NearestFilter;
1511
+ case viewer_shared_types_1.TEXTURE_FILTERING.LINEAR:
1512
+ default:
1513
+ return THREE.LinearFilter;
1514
+ }
1515
+ })();
1516
+ texture.wrapS = (() => {
1517
+ switch (map.wrapS) {
1518
+ case viewer_shared_types_1.TEXTURE_WRAPPING.CLAMP_TO_EDGE:
1519
+ return THREE.ClampToEdgeWrapping;
1520
+ case viewer_shared_types_1.TEXTURE_WRAPPING.MIRRORED_REPEAT:
1521
+ return THREE.MirroredRepeatWrapping;
1522
+ case viewer_shared_types_1.TEXTURE_WRAPPING.REPEAT:
1523
+ default:
1524
+ return THREE.RepeatWrapping;
1525
+ }
1526
+ })();
1527
+ texture.wrapT = (() => {
1528
+ switch (map.wrapT) {
1529
+ case viewer_shared_types_1.TEXTURE_WRAPPING.CLAMP_TO_EDGE:
1530
+ return THREE.ClampToEdgeWrapping;
1531
+ case viewer_shared_types_1.TEXTURE_WRAPPING.MIRRORED_REPEAT:
1532
+ return THREE.MirroredRepeatWrapping;
1533
+ case viewer_shared_types_1.TEXTURE_WRAPPING.REPEAT:
1534
+ default:
1535
+ return THREE.RepeatWrapping;
1536
+ }
1537
+ })();
1538
+ texture.center = new THREE.Vector2(map.center[0], map.center[1]);
1539
+ texture.offset = new THREE.Vector2(map.offset[0], map.offset[1]);
1540
+ texture.repeat = new THREE.Vector2(map.repeat[0], map.repeat[1]);
1541
+ texture.rotation = map.rotation;
1542
+ if (map.texCoord !== undefined)
1543
+ texture.channel = map.texCoord;
1544
+ texture.flipY = map.flipY;
1545
+ }
1546
+ texture.needsUpdate = true;
1547
+ texture.userData.cacheKey = key;
1548
+ this._threeJsTextureCache[key] = {
1549
+ texture,
1550
+ usage: 1,
1551
+ initialized: false,
1552
+ };
1553
+ return this._threeJsTextureCache[key].texture;
1554
+ }
1555
+ }
1556
+ exports.MaterialLoader = MaterialLoader;
1557
+ // #endregion Classes (1)
1558
+ // #region Enums (1)
1559
+ /* eslint-disable @typescript-eslint/no-empty-function */
1560
+ var GEOMETRY_MATERIAL_TYPE;
1561
+ (function (GEOMETRY_MATERIAL_TYPE) {
1562
+ GEOMETRY_MATERIAL_TYPE["POINT"] = "point";
1563
+ GEOMETRY_MATERIAL_TYPE["LINE"] = "line";
1564
+ GEOMETRY_MATERIAL_TYPE["MESH"] = "mesh";
1565
+ })(GEOMETRY_MATERIAL_TYPE || (GEOMETRY_MATERIAL_TYPE = {}));
1566
+ // #endregion Enums (1)
1567
+ // #region Variables (1)
1568
+ const adaptShaders = () => {
1569
+ let shader = THREE.ShaderChunk.shadowmap_pars_fragment;
1570
+ if (!shader.includes("PCSS implementation")) {
1571
+ shader = shader.replace("#ifdef USE_SHADOWMAP", "#ifdef USE_SHADOWMAP" + PCSS_1.main);
1572
+ shader = shader.replace(shader.substr(shader.indexOf("#if defined( SHADOWMAP_TYPE_PCF )"), shader.indexOf("#elif defined( SHADOWMAP_TYPE_PCF_SOFT )") -
1573
+ shader.indexOf("#if defined( SHADOWMAP_TYPE_PCF )")), "#if defined( SHADOWMAP_TYPE_PCF )\n" + PCSS_1.entry);
1574
+ }
1575
+ THREE.ShaderChunk.shadowmap_pars_fragment = shader;
1576
+ // here we replace in the background cube fragment shader the y component of the reflection vector with the negative y component and inverse the rotation in the case of a LDR environment map
1577
+ // console.log(THREE.ShaderChunk.backgroundCube_frag.includes('vec4 texColor = textureCube( envMap, backgroundRotation * vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) );'))
1578
+ THREE.ShaderChunk.backgroundCube_frag =
1579
+ THREE.ShaderChunk.backgroundCube_frag.replace("vec4 texColor = textureCube( envMap, backgroundRotation * vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) );", "vec4 texColor = textureCube( envMap, inverse(backgroundRotation) * vec3( flipEnvMap * vWorldDirection.x, -vWorldDirection.y, vWorldDirection.z ) );");
1580
+ THREE.ShaderLib.backgroundCube.fragmentShader =
1581
+ THREE.ShaderChunk.backgroundCube_frag;
1582
+ // here we replace in the envmap_physical_pars_fragment the z component of the reflection vector with the negative z component in the case of a LDR environment map
1583
+ // console.log(THREE.ShaderChunk.envmap_physical_pars_fragment, THREE.ShaderChunk.envmap_physical_pars_fragment.includes('vec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 );'));
1584
+ THREE.ShaderChunk.envmap_physical_pars_fragment =
1575
1585
  THREE.ShaderChunk.envmap_physical_pars_fragment.replace("vec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 );", `
1576
1586
  #ifdef ENVMAP_TYPE_LDR
1577
1587
  vec3 rotatedReflectVec = vec3(envMapRotation * worldNormal).xzy;
@@ -1580,10 +1590,10 @@ const adaptShaders = () => {
1580
1590
  vec3 rotatedReflectVec = vec3(envMapRotation * worldNormal);
1581
1591
  vec4 envMapColor = textureCubeUV( envMap, vec3(-rotatedReflectVec.x, rotatedReflectVec.y, rotatedReflectVec.z), 1.0 );
1582
1592
  #endif
1583
- `);
1584
- // here we replace in the envmap_fragment the z component of the reflection vector with the negative z component in the case of a LDR environment map
1585
- // console.log(THREE.ShaderChunk.envmap_physical_pars_fragment, THREE.ShaderChunk.envmap_physical_pars_fragment.includes('vec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );'));
1586
- THREE.ShaderChunk.envmap_physical_pars_fragment =
1593
+ `);
1594
+ // here we replace in the envmap_fragment the z component of the reflection vector with the negative z component in the case of a LDR environment map
1595
+ // console.log(THREE.ShaderChunk.envmap_physical_pars_fragment, THREE.ShaderChunk.envmap_physical_pars_fragment.includes('vec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );'));
1596
+ THREE.ShaderChunk.envmap_physical_pars_fragment =
1587
1597
  THREE.ShaderChunk.envmap_physical_pars_fragment.replace("vec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );", `
1588
1598
  #ifdef ENVMAP_TYPE_LDR
1589
1599
  vec3 rotatedReflectVec = vec3(envMapRotation * reflectVec).xzy;
@@ -1592,42 +1602,42 @@ const adaptShaders = () => {
1592
1602
  vec3 rotatedReflectVec = vec3(envMapRotation * reflectVec);
1593
1603
  vec4 envMapColor = textureCubeUV( envMap, vec3(rotatedReflectVec.x, rotatedReflectVec.y, rotatedReflectVec.z), roughness );
1594
1604
  #endif
1595
- `);
1596
- // here we replace in the envmap_fragment the z component of the reflection vector with the negative z component in the case of a LDR environment map
1597
- // console.log(THREE.ShaderChunk.envmap_fragment, THREE.ShaderChunk.envmap_fragment.includes('vec4 envColor = textureCube( envMap, envMapRotation * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );'));
1598
- THREE.ShaderChunk.envmap_fragment =
1605
+ `);
1606
+ // here we replace in the envmap_fragment the z component of the reflection vector with the negative z component in the case of a LDR environment map
1607
+ // console.log(THREE.ShaderChunk.envmap_fragment, THREE.ShaderChunk.envmap_fragment.includes('vec4 envColor = textureCube( envMap, envMapRotation * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );'));
1608
+ THREE.ShaderChunk.envmap_fragment =
1599
1609
  THREE.ShaderChunk.envmap_fragment.replace("vec4 envColor = textureCube( envMap, envMapRotation * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );", `
1600
1610
  #ifdef ENVMAP_TYPE_LDR
1601
1611
  vec4 envColor = textureCube( envMap, envMapRotation * vec3(flipEnvMap * reflectVec.x, reflectVec.y, -reflectVec.z ) );
1602
1612
  #else
1603
1613
  vec4 envColor = textureCube( envMap, envMapRotation * vec3(flipEnvMap * reflectVec.x, reflectVec.zy ) );
1604
1614
  #endif
1605
- `);
1606
- // here we replace the z and y component of the sampleDir in the cube_uv_reflection_fragment
1607
- // console.log(THREE.ShaderChunk.cube_uv_reflection_fragment.includes('vec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );'))
1608
- THREE.ShaderChunk.cube_uv_reflection_fragment =
1615
+ `);
1616
+ // here we replace the z and y component of the sampleDir in the cube_uv_reflection_fragment
1617
+ // console.log(THREE.ShaderChunk.cube_uv_reflection_fragment.includes('vec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );'))
1618
+ THREE.ShaderChunk.cube_uv_reflection_fragment =
1609
1619
  THREE.ShaderChunk.cube_uv_reflection_fragment.replace("vec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );", `
1610
1620
  #ifdef ENVMAP_TYPE_LDR
1611
1621
  vec3 color0 = bilinearCubeUV( envMap, sampleDir.xzy, mipInt );
1612
1622
  #else
1613
1623
  vec3 color0 = bilinearCubeUV( envMap, vec3(sampleDir.y, sampleDir.z, sampleDir.x), mipInt );
1614
1624
  #endif
1615
- `);
1616
- // here we replace the z and y component of the sampleDir in the cube_uv_reflection_fragment
1617
- // console.log(THREE.ShaderChunk.cube_uv_reflection_fragment)
1618
- THREE.ShaderChunk.cube_uv_reflection_fragment =
1625
+ `);
1626
+ // here we replace the z and y component of the sampleDir in the cube_uv_reflection_fragment
1627
+ // console.log(THREE.ShaderChunk.cube_uv_reflection_fragment)
1628
+ THREE.ShaderChunk.cube_uv_reflection_fragment =
1619
1629
  THREE.ShaderChunk.cube_uv_reflection_fragment.replace("vec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );", `
1620
1630
  #ifdef ENVMAP_TYPE_LDR
1621
1631
  vec3 color1 = bilinearCubeUV( envMap, sampleDir.xzy, mipInt + 1.0 );
1622
1632
  #else
1623
1633
  vec3 color1 = bilinearCubeUV( envMap, vec3(sampleDir.y, sampleDir.z, sampleDir.x), mipInt + 1.0 );
1624
1634
  #endif
1625
- `);
1626
- // here we create a new case in the lights_fragment_maps for the case of ENVMAP_TYPE_NONE
1627
- if (!THREE.ShaderChunk.lights_fragment_maps.includes("vec3 reflectVec")) {
1628
- const index = THREE.ShaderChunk.lights_fragment_maps.lastIndexOf("#endif");
1629
- THREE.ShaderChunk.lights_fragment_maps =
1630
- THREE.ShaderChunk.lights_fragment_maps.substring(0, index) +
1635
+ `);
1636
+ // here we create a new case in the lights_fragment_maps for the case of ENVMAP_TYPE_NONE
1637
+ if (!THREE.ShaderChunk.lights_fragment_maps.includes("vec3 reflectVec")) {
1638
+ const index = THREE.ShaderChunk.lights_fragment_maps.lastIndexOf("#endif");
1639
+ THREE.ShaderChunk.lights_fragment_maps =
1640
+ THREE.ShaderChunk.lights_fragment_maps.substring(0, index) +
1631
1641
  `#else
1632
1642
  #ifdef ENVMAP_TYPE_NONE
1633
1643
  vec3 reflectVec = reflect( -geometryViewDir, geometryNormal );
@@ -1636,10 +1646,10 @@ const adaptShaders = () => {
1636
1646
  radiance += (vec3((adjustedEnvReflectVector.z + 1.0) / 2.0) + 0.5) / 1.5;
1637
1647
  #endif
1638
1648
  #endif
1639
- ` +
1640
- THREE.ShaderChunk.lights_fragment_maps.substring(index + "#endif".length);
1641
- }
1642
- };
1643
- exports.adaptShaders = adaptShaders;
1644
- // #endregion Variables (1)
1649
+ ` +
1650
+ THREE.ShaderChunk.lights_fragment_maps.substring(index + "#endif".length);
1651
+ }
1652
+ };
1653
+ exports.adaptShaders = adaptShaders;
1654
+ // #endregion Variables (1)
1645
1655
  //# sourceMappingURL=MaterialLoader.js.map