itowns 2.44.3-next.8 → 2.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. package/README.md +3 -129
  2. package/examples/3dtiles_loader.html +123 -48
  3. package/examples/config.json +3 -10
  4. package/examples/copc_simple_loader.html +15 -5
  5. package/examples/effects_stereo.html +2 -2
  6. package/examples/entwine_3d_loader.html +3 -1
  7. package/examples/entwine_simple_loader.html +1 -1
  8. package/examples/images/itowns_logo.svg +123 -0
  9. package/examples/js/plugins/COGParser.js +1 -1
  10. package/examples/jsm/OGC3DTilesHelper.js +6 -1
  11. package/examples/layers/JSONLayers/GeoidMNT.json +3 -1
  12. package/examples/misc_collada.html +2 -2
  13. package/examples/source_file_geojson_3d.html +0 -1
  14. package/examples/source_file_kml_raster_usgs.html +0 -1
  15. package/examples/source_stream_wfs_raster.html +0 -7
  16. package/examples/vector_tile_mapbox_raster.html +91 -0
  17. package/examples/view_3d_map_webxr.html +3 -1
  18. package/examples/view_multi_25d.html +2 -2
  19. package/package.json +21 -75
  20. package/CODING.md +0 -120
  21. package/CONTRIBUTING.md +0 -150
  22. package/CONTRIBUTORS.md +0 -55
  23. package/LICENSE.md +0 -44
  24. package/changelog.md +0 -1361
  25. package/dist/455.js +0 -2
  26. package/dist/455.js.map +0 -1
  27. package/dist/debug.js +0 -3
  28. package/dist/debug.js.LICENSE.txt +0 -13
  29. package/dist/debug.js.map +0 -1
  30. package/dist/itowns.js +0 -3
  31. package/dist/itowns.js.LICENSE.txt +0 -7
  32. package/dist/itowns.js.map +0 -1
  33. package/dist/itowns_lasparser.js +0 -2
  34. package/dist/itowns_lasparser.js.map +0 -1
  35. package/dist/itowns_lasworker.js +0 -2
  36. package/dist/itowns_lasworker.js.map +0 -1
  37. package/dist/itowns_potree2worker.js +0 -2
  38. package/dist/itowns_potree2worker.js.map +0 -1
  39. package/dist/itowns_widgets.js +0 -2
  40. package/dist/itowns_widgets.js.map +0 -1
  41. package/examples/.eslintrc.cjs +0 -35
  42. package/examples/3dtiles_25d.html +0 -120
  43. package/examples/3dtiles_basic.html +0 -94
  44. package/examples/3dtiles_batch_table.html +0 -86
  45. package/examples/3dtiles_ion.html +0 -126
  46. package/examples/3dtiles_pointcloud.html +0 -95
  47. package/examples/jsm/.eslintrc.cjs +0 -38
  48. package/lib/Controls/FirstPersonControls.js +0 -308
  49. package/lib/Controls/FlyControls.js +0 -175
  50. package/lib/Controls/GlobeControls.js +0 -1162
  51. package/lib/Controls/PlanarControls.js +0 -1025
  52. package/lib/Controls/StateControl.js +0 -429
  53. package/lib/Controls/StreetControls.js +0 -392
  54. package/lib/Converter/Feature2Mesh.js +0 -615
  55. package/lib/Converter/Feature2Texture.js +0 -170
  56. package/lib/Converter/convertToTile.js +0 -75
  57. package/lib/Converter/textureConverter.js +0 -44
  58. package/lib/Core/3DTiles/C3DTBatchTable.js +0 -131
  59. package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +0 -96
  60. package/lib/Core/3DTiles/C3DTBoundingVolume.js +0 -157
  61. package/lib/Core/3DTiles/C3DTExtensions.js +0 -97
  62. package/lib/Core/3DTiles/C3DTFeature.js +0 -110
  63. package/lib/Core/3DTiles/C3DTilesEnums.js +0 -20
  64. package/lib/Core/3DTiles/C3DTileset.js +0 -99
  65. package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +0 -100
  66. package/lib/Core/AnimationPlayer.js +0 -142
  67. package/lib/Core/CopcNode.js +0 -174
  68. package/lib/Core/Deprecated/Undeprecator.js +0 -75
  69. package/lib/Core/EntwinePointTileNode.js +0 -126
  70. package/lib/Core/Feature.js +0 -490
  71. package/lib/Core/Geographic/CoordStars.js +0 -80
  72. package/lib/Core/Geographic/Coordinates.js +0 -320
  73. package/lib/Core/Geographic/Crs.js +0 -175
  74. package/lib/Core/Geographic/Extent.js +0 -534
  75. package/lib/Core/Geographic/GeoidGrid.js +0 -109
  76. package/lib/Core/Label.js +0 -222
  77. package/lib/Core/MainLoop.js +0 -211
  78. package/lib/Core/Math/Ellipsoid.js +0 -144
  79. package/lib/Core/Picking.js +0 -255
  80. package/lib/Core/PointCloudNode.js +0 -42
  81. package/lib/Core/Potree2Node.js +0 -206
  82. package/lib/Core/Potree2PointAttributes.js +0 -139
  83. package/lib/Core/PotreeNode.js +0 -101
  84. package/lib/Core/Prefab/Globe/Atmosphere.js +0 -299
  85. package/lib/Core/Prefab/Globe/BuilderEllipsoidTile.js +0 -110
  86. package/lib/Core/Prefab/Globe/GlobeLayer.js +0 -145
  87. package/lib/Core/Prefab/Globe/SkyShader.js +0 -78
  88. package/lib/Core/Prefab/GlobeView.js +0 -161
  89. package/lib/Core/Prefab/Planar/PlanarLayer.js +0 -53
  90. package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +0 -72
  91. package/lib/Core/Prefab/PlanarView.js +0 -62
  92. package/lib/Core/Prefab/TileBuilder.js +0 -80
  93. package/lib/Core/Prefab/computeBufferTileGeometry.js +0 -183
  94. package/lib/Core/Scheduler/Cache.js +0 -256
  95. package/lib/Core/Scheduler/CancelledCommandException.js +0 -15
  96. package/lib/Core/Scheduler/Scheduler.js +0 -294
  97. package/lib/Core/Style.js +0 -1121
  98. package/lib/Core/System/Capabilities.js +0 -63
  99. package/lib/Core/Tile/Tile.js +0 -219
  100. package/lib/Core/Tile/TileGrid.js +0 -46
  101. package/lib/Core/TileGeometry.js +0 -40
  102. package/lib/Core/TileMesh.js +0 -109
  103. package/lib/Core/View.js +0 -1109
  104. package/lib/Layer/C3DTilesLayer.js +0 -455
  105. package/lib/Layer/ColorLayer.js +0 -128
  106. package/lib/Layer/CopcLayer.js +0 -58
  107. package/lib/Layer/ElevationLayer.js +0 -107
  108. package/lib/Layer/EntwinePointTileLayer.js +0 -64
  109. package/lib/Layer/FeatureGeometryLayer.js +0 -63
  110. package/lib/Layer/GeoidLayer.js +0 -80
  111. package/lib/Layer/GeometryLayer.js +0 -202
  112. package/lib/Layer/InfoLayer.js +0 -64
  113. package/lib/Layer/LabelLayer.js +0 -456
  114. package/lib/Layer/Layer.js +0 -304
  115. package/lib/Layer/LayerUpdateState.js +0 -89
  116. package/lib/Layer/LayerUpdateStrategy.js +0 -80
  117. package/lib/Layer/OGC3DTilesLayer.js +0 -387
  118. package/lib/Layer/OrientedImageLayer.js +0 -222
  119. package/lib/Layer/PointCloudLayer.js +0 -359
  120. package/lib/Layer/Potree2Layer.js +0 -164
  121. package/lib/Layer/PotreeLayer.js +0 -65
  122. package/lib/Layer/RasterLayer.js +0 -27
  123. package/lib/Layer/ReferencingLayerProperties.js +0 -62
  124. package/lib/Layer/TiledGeometryLayer.js +0 -403
  125. package/lib/Loader/LASLoader.js +0 -193
  126. package/lib/Loader/Potree2BrotliLoader.js +0 -261
  127. package/lib/Loader/Potree2Loader.js +0 -207
  128. package/lib/Main.js +0 -115
  129. package/lib/MainBundle.js +0 -4
  130. package/lib/Parser/B3dmParser.js +0 -174
  131. package/lib/Parser/CameraCalibrationParser.js +0 -94
  132. package/lib/Parser/GDFParser.js +0 -72
  133. package/lib/Parser/GTXParser.js +0 -75
  134. package/lib/Parser/GeoJsonParser.js +0 -212
  135. package/lib/Parser/GpxParser.js +0 -25
  136. package/lib/Parser/ISGParser.js +0 -71
  137. package/lib/Parser/KMLParser.js +0 -25
  138. package/lib/Parser/LASParser.js +0 -137
  139. package/lib/Parser/MapBoxUrlParser.js +0 -83
  140. package/lib/Parser/PntsParser.js +0 -131
  141. package/lib/Parser/Potree2BinParser.js +0 -92
  142. package/lib/Parser/PotreeBinParser.js +0 -106
  143. package/lib/Parser/PotreeCinParser.js +0 -29
  144. package/lib/Parser/ShapefileParser.js +0 -78
  145. package/lib/Parser/VectorTileParser.js +0 -202
  146. package/lib/Parser/XbilParser.js +0 -119
  147. package/lib/Parser/deprecated/LegacyGLTFLoader.js +0 -1386
  148. package/lib/Parser/iGLTFLoader.js +0 -168
  149. package/lib/Process/3dTilesProcessing.js +0 -304
  150. package/lib/Process/FeatureProcessing.js +0 -76
  151. package/lib/Process/LayeredMaterialNodeProcessing.js +0 -221
  152. package/lib/Process/ObjectRemovalHelper.js +0 -97
  153. package/lib/Process/handlerNodeError.js +0 -23
  154. package/lib/Provider/3dTilesProvider.js +0 -149
  155. package/lib/Provider/DataSourceProvider.js +0 -8
  156. package/lib/Provider/Fetcher.js +0 -229
  157. package/lib/Provider/PointCloudProvider.js +0 -45
  158. package/lib/Provider/TileProvider.js +0 -16
  159. package/lib/Provider/URLBuilder.js +0 -116
  160. package/lib/Renderer/Camera.js +0 -281
  161. package/lib/Renderer/Color.js +0 -56
  162. package/lib/Renderer/ColorLayersOrdering.js +0 -115
  163. package/lib/Renderer/CommonMaterial.js +0 -31
  164. package/lib/Renderer/Label2DRenderer.js +0 -190
  165. package/lib/Renderer/LayeredMaterial.js +0 -243
  166. package/lib/Renderer/OBB.js +0 -153
  167. package/lib/Renderer/OrientedImageCamera.js +0 -118
  168. package/lib/Renderer/OrientedImageMaterial.js +0 -167
  169. package/lib/Renderer/PointsMaterial.js +0 -485
  170. package/lib/Renderer/RasterTile.js +0 -209
  171. package/lib/Renderer/RenderMode.js +0 -31
  172. package/lib/Renderer/Shader/ShaderChunk.js +0 -160
  173. package/lib/Renderer/Shader/ShaderUtils.js +0 -47
  174. package/lib/Renderer/SphereHelper.js +0 -23
  175. package/lib/Renderer/WebXR.js +0 -51
  176. package/lib/Renderer/c3DEngine.js +0 -214
  177. package/lib/Source/C3DTilesGoogleSource.js +0 -74
  178. package/lib/Source/C3DTilesIonSource.js +0 -54
  179. package/lib/Source/C3DTilesSource.js +0 -30
  180. package/lib/Source/CopcSource.js +0 -115
  181. package/lib/Source/EntwinePointTileSource.js +0 -62
  182. package/lib/Source/FileSource.js +0 -189
  183. package/lib/Source/OGC3DTilesGoogleSource.js +0 -29
  184. package/lib/Source/OGC3DTilesIonSource.js +0 -34
  185. package/lib/Source/OGC3DTilesSource.js +0 -21
  186. package/lib/Source/OrientedImageSource.js +0 -59
  187. package/lib/Source/Potree2Source.js +0 -167
  188. package/lib/Source/PotreeSource.js +0 -82
  189. package/lib/Source/Source.js +0 -223
  190. package/lib/Source/TMSSource.js +0 -145
  191. package/lib/Source/VectorTilesSource.js +0 -178
  192. package/lib/Source/WFSSource.js +0 -168
  193. package/lib/Source/WMSSource.js +0 -133
  194. package/lib/Source/WMTSSource.js +0 -86
  195. package/lib/ThreeExtended/capabilities/WebGL.js +0 -69
  196. package/lib/ThreeExtended/libs/ktx-parse.module.js +0 -470
  197. package/lib/ThreeExtended/libs/zstddec.module.js +0 -29
  198. package/lib/ThreeExtended/loaders/DDSLoader.js +0 -200
  199. package/lib/ThreeExtended/loaders/DRACOLoader.js +0 -399
  200. package/lib/ThreeExtended/loaders/GLTFLoader.js +0 -2876
  201. package/lib/ThreeExtended/loaders/KTX2Loader.js +0 -625
  202. package/lib/ThreeExtended/utils/BufferGeometryUtils.js +0 -846
  203. package/lib/ThreeExtended/utils/WorkerPool.js +0 -70
  204. package/lib/Utils/CameraUtils.js +0 -555
  205. package/lib/Utils/DEMUtils.js +0 -350
  206. package/lib/Utils/FeaturesUtils.js +0 -156
  207. package/lib/Utils/Gradients.js +0 -16
  208. package/lib/Utils/OrientationUtils.js +0 -457
  209. package/lib/Utils/ThreeUtils.js +0 -115
  210. package/lib/Utils/gui/C3DTilesStyle.js +0 -215
  211. package/lib/Utils/gui/Main.js +0 -7
  212. package/lib/Utils/gui/Minimap.js +0 -154
  213. package/lib/Utils/gui/Navigation.js +0 -245
  214. package/lib/Utils/gui/Scale.js +0 -107
  215. package/lib/Utils/gui/Searchbar.js +0 -234
  216. package/lib/Utils/gui/Widget.js +0 -80
  217. package/lib/Utils/placeObjectOnGround.js +0 -137
  218. package/lib/Worker/LASLoaderWorker.js +0 -19
  219. package/lib/Worker/Potree2Worker.js +0 -21
@@ -1,846 +0,0 @@
1
- import { BufferAttribute, BufferGeometry, Float32BufferAttribute, InstancedBufferAttribute, InterleavedBuffer, InterleavedBufferAttribute, TriangleFanDrawMode, TriangleStripDrawMode, TrianglesDrawMode, Vector3 } from 'three';
2
- function computeMikkTSpaceTangents(geometry, MikkTSpace) {
3
- let negateSign = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
4
- if (!MikkTSpace || !MikkTSpace.isReady) {
5
- throw new Error('BufferGeometryUtils: Initialized MikkTSpace library required.');
6
- }
7
- if (!geometry.hasAttribute('position') || !geometry.hasAttribute('normal') || !geometry.hasAttribute('uv')) {
8
- throw new Error('BufferGeometryUtils: Tangents require "position", "normal", and "uv" attributes.');
9
- }
10
- function getAttributeArray(attribute) {
11
- if (attribute.normalized || attribute.isInterleavedBufferAttribute) {
12
- const dstArray = new Float32Array(attribute.count * attribute.itemSize);
13
- for (let i = 0, j = 0; i < attribute.count; i++) {
14
- dstArray[j++] = attribute.getX(i);
15
- dstArray[j++] = attribute.getY(i);
16
- if (attribute.itemSize > 2) {
17
- dstArray[j++] = attribute.getZ(i);
18
- }
19
- }
20
- return dstArray;
21
- }
22
- if (attribute.array instanceof Float32Array) {
23
- return attribute.array;
24
- }
25
- return new Float32Array(attribute.array);
26
- }
27
-
28
- // MikkTSpace algorithm requires non-indexed input.
29
-
30
- const _geometry = geometry.index ? geometry.toNonIndexed() : geometry;
31
-
32
- // Compute vertex tangents.
33
-
34
- const tangents = MikkTSpace.generateTangents(getAttributeArray(_geometry.attributes.position), getAttributeArray(_geometry.attributes.normal), getAttributeArray(_geometry.attributes.uv));
35
-
36
- // Texture coordinate convention of glTF differs from the apparent
37
- // default of the MikkTSpace library; .w component must be flipped.
38
-
39
- if (negateSign) {
40
- for (let i = 3; i < tangents.length; i += 4) {
41
- tangents[i] *= -1;
42
- }
43
- }
44
-
45
- //
46
-
47
- _geometry.setAttribute('tangent', new BufferAttribute(tangents, 4));
48
- if (geometry !== _geometry) {
49
- geometry.copy(_geometry);
50
- }
51
- return geometry;
52
- }
53
-
54
- /**
55
- * @param {Array<BufferGeometry>} geometries
56
- * @param {Boolean} useGroups
57
- * @return {BufferGeometry}
58
- */
59
- function mergeGeometries(geometries) {
60
- let useGroups = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
61
- const isIndexed = geometries[0].index !== null;
62
- const attributesUsed = new Set(Object.keys(geometries[0].attributes));
63
- const morphAttributesUsed = new Set(Object.keys(geometries[0].morphAttributes));
64
- const attributes = {};
65
- const morphAttributes = {};
66
- const morphTargetsRelative = geometries[0].morphTargetsRelative;
67
- const mergedGeometry = new BufferGeometry();
68
- let offset = 0;
69
- for (let i = 0; i < geometries.length; ++i) {
70
- const geometry = geometries[i];
71
- let attributesCount = 0;
72
-
73
- // ensure that all geometries are indexed, or none
74
-
75
- if (isIndexed !== (geometry.index !== null)) {
76
- console.error('THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.');
77
- return null;
78
- }
79
-
80
- // gather attributes, exit early if they're different
81
-
82
- for (const name in geometry.attributes) {
83
- if (!attributesUsed.has(name)) {
84
- console.error('THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. All geometries must have compatible attributes; make sure "' + name + '" attribute exists among all geometries, or in none of them.');
85
- return null;
86
- }
87
- if (attributes[name] === undefined) attributes[name] = [];
88
- attributes[name].push(geometry.attributes[name]);
89
- attributesCount++;
90
- }
91
-
92
- // ensure geometries have the same number of attributes
93
-
94
- if (attributesCount !== attributesUsed.size) {
95
- console.error('THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. Make sure all geometries have the same number of attributes.');
96
- return null;
97
- }
98
-
99
- // gather morph attributes, exit early if they're different
100
-
101
- if (morphTargetsRelative !== geometry.morphTargetsRelative) {
102
- console.error('THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. .morphTargetsRelative must be consistent throughout all geometries.');
103
- return null;
104
- }
105
- for (const name in geometry.morphAttributes) {
106
- if (!morphAttributesUsed.has(name)) {
107
- console.error('THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. .morphAttributes must be consistent throughout all geometries.');
108
- return null;
109
- }
110
- if (morphAttributes[name] === undefined) morphAttributes[name] = [];
111
- morphAttributes[name].push(geometry.morphAttributes[name]);
112
- }
113
- if (useGroups) {
114
- let count;
115
- if (isIndexed) {
116
- count = geometry.index.count;
117
- } else if (geometry.attributes.position !== undefined) {
118
- count = geometry.attributes.position.count;
119
- } else {
120
- console.error('THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. The geometry must have either an index or a position attribute');
121
- return null;
122
- }
123
- mergedGeometry.addGroup(offset, count, i);
124
- offset += count;
125
- }
126
- }
127
-
128
- // merge indices
129
-
130
- if (isIndexed) {
131
- let indexOffset = 0;
132
- const mergedIndex = [];
133
- for (let i = 0; i < geometries.length; ++i) {
134
- const index = geometries[i].index;
135
- for (let j = 0; j < index.count; ++j) {
136
- mergedIndex.push(index.getX(j) + indexOffset);
137
- }
138
- indexOffset += geometries[i].attributes.position.count;
139
- }
140
- mergedGeometry.setIndex(mergedIndex);
141
- }
142
-
143
- // merge attributes
144
-
145
- for (const name in attributes) {
146
- const mergedAttribute = mergeAttributes(attributes[name]);
147
- if (!mergedAttribute) {
148
- console.error('THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the ' + name + ' attribute.');
149
- return null;
150
- }
151
- mergedGeometry.setAttribute(name, mergedAttribute);
152
- }
153
-
154
- // merge morph attributes
155
-
156
- for (const name in morphAttributes) {
157
- const numMorphTargets = morphAttributes[name][0].length;
158
- if (numMorphTargets === 0) break;
159
- mergedGeometry.morphAttributes = mergedGeometry.morphAttributes || {};
160
- mergedGeometry.morphAttributes[name] = [];
161
- for (let i = 0; i < numMorphTargets; ++i) {
162
- const morphAttributesToMerge = [];
163
- for (let j = 0; j < morphAttributes[name].length; ++j) {
164
- morphAttributesToMerge.push(morphAttributes[name][j][i]);
165
- }
166
- const mergedMorphAttribute = mergeAttributes(morphAttributesToMerge);
167
- if (!mergedMorphAttribute) {
168
- console.error('THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the ' + name + ' morphAttribute.');
169
- return null;
170
- }
171
- mergedGeometry.morphAttributes[name].push(mergedMorphAttribute);
172
- }
173
- }
174
- return mergedGeometry;
175
- }
176
-
177
- /**
178
- * @param {Array<BufferAttribute>} attributes
179
- * @return {BufferAttribute}
180
- */
181
- function mergeAttributes(attributes) {
182
- let TypedArray;
183
- let itemSize;
184
- let normalized;
185
- let gpuType = -1;
186
- let arrayLength = 0;
187
- for (let i = 0; i < attributes.length; ++i) {
188
- const attribute = attributes[i];
189
- if (TypedArray === undefined) TypedArray = attribute.array.constructor;
190
- if (TypedArray !== attribute.array.constructor) {
191
- console.error('THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes.');
192
- return null;
193
- }
194
- if (itemSize === undefined) itemSize = attribute.itemSize;
195
- if (itemSize !== attribute.itemSize) {
196
- console.error('THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes.');
197
- return null;
198
- }
199
- if (normalized === undefined) normalized = attribute.normalized;
200
- if (normalized !== attribute.normalized) {
201
- console.error('THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes.');
202
- return null;
203
- }
204
- if (gpuType === -1) gpuType = attribute.gpuType;
205
- if (gpuType !== attribute.gpuType) {
206
- console.error('THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes.');
207
- return null;
208
- }
209
- arrayLength += attribute.count * itemSize;
210
- }
211
- const array = new TypedArray(arrayLength);
212
- const result = new BufferAttribute(array, itemSize, normalized);
213
- let offset = 0;
214
- for (let i = 0; i < attributes.length; ++i) {
215
- const attribute = attributes[i];
216
- if (attribute.isInterleavedBufferAttribute) {
217
- const tupleOffset = offset / itemSize;
218
- for (let j = 0, l = attribute.count; j < l; j++) {
219
- for (let c = 0; c < itemSize; c++) {
220
- const value = attribute.getComponent(j, c);
221
- result.setComponent(j + tupleOffset, c, value);
222
- }
223
- }
224
- } else {
225
- array.set(attribute.array, offset);
226
- }
227
- offset += attribute.count * itemSize;
228
- }
229
- if (gpuType !== undefined) {
230
- result.gpuType = gpuType;
231
- }
232
- return result;
233
- }
234
-
235
- /**
236
- * @param {BufferAttribute}
237
- * @return {BufferAttribute}
238
- */
239
- export function deepCloneAttribute(attribute) {
240
- if (attribute.isInstancedInterleavedBufferAttribute || attribute.isInterleavedBufferAttribute) {
241
- return deinterleaveAttribute(attribute);
242
- }
243
- if (attribute.isInstancedBufferAttribute) {
244
- return new InstancedBufferAttribute().copy(attribute);
245
- }
246
- return new BufferAttribute().copy(attribute);
247
- }
248
-
249
- /**
250
- * @param {Array<BufferAttribute>} attributes
251
- * @return {Array<InterleavedBufferAttribute>}
252
- */
253
- function interleaveAttributes(attributes) {
254
- // Interleaves the provided attributes into an InterleavedBuffer and returns
255
- // a set of InterleavedBufferAttributes for each attribute
256
- let TypedArray;
257
- let arrayLength = 0;
258
- let stride = 0;
259
-
260
- // calculate the length and type of the interleavedBuffer
261
- for (let i = 0, l = attributes.length; i < l; ++i) {
262
- const attribute = attributes[i];
263
- if (TypedArray === undefined) TypedArray = attribute.array.constructor;
264
- if (TypedArray !== attribute.array.constructor) {
265
- console.error('AttributeBuffers of different types cannot be interleaved');
266
- return null;
267
- }
268
- arrayLength += attribute.array.length;
269
- stride += attribute.itemSize;
270
- }
271
-
272
- // Create the set of buffer attributes
273
- const interleavedBuffer = new InterleavedBuffer(new TypedArray(arrayLength), stride);
274
- let offset = 0;
275
- const res = [];
276
- const getters = ['getX', 'getY', 'getZ', 'getW'];
277
- const setters = ['setX', 'setY', 'setZ', 'setW'];
278
- for (let j = 0, l = attributes.length; j < l; j++) {
279
- const attribute = attributes[j];
280
- const itemSize = attribute.itemSize;
281
- const count = attribute.count;
282
- const iba = new InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, attribute.normalized);
283
- res.push(iba);
284
- offset += itemSize;
285
-
286
- // Move the data for each attribute into the new interleavedBuffer
287
- // at the appropriate offset
288
- for (let c = 0; c < count; c++) {
289
- for (let k = 0; k < itemSize; k++) {
290
- iba[setters[k]](c, attribute[getters[k]](c));
291
- }
292
- }
293
- }
294
- return res;
295
- }
296
-
297
- // returns a new, non-interleaved version of the provided attribute
298
- export function deinterleaveAttribute(attribute) {
299
- const cons = attribute.data.array.constructor;
300
- const count = attribute.count;
301
- const itemSize = attribute.itemSize;
302
- const normalized = attribute.normalized;
303
- const array = new cons(count * itemSize);
304
- let newAttribute;
305
- if (attribute.isInstancedInterleavedBufferAttribute) {
306
- newAttribute = new InstancedBufferAttribute(array, itemSize, normalized, attribute.meshPerAttribute);
307
- } else {
308
- newAttribute = new BufferAttribute(array, itemSize, normalized);
309
- }
310
- for (let i = 0; i < count; i++) {
311
- newAttribute.setX(i, attribute.getX(i));
312
- if (itemSize >= 2) {
313
- newAttribute.setY(i, attribute.getY(i));
314
- }
315
- if (itemSize >= 3) {
316
- newAttribute.setZ(i, attribute.getZ(i));
317
- }
318
- if (itemSize >= 4) {
319
- newAttribute.setW(i, attribute.getW(i));
320
- }
321
- }
322
- return newAttribute;
323
- }
324
-
325
- // deinterleaves all attributes on the geometry
326
- export function deinterleaveGeometry(geometry) {
327
- const attributes = geometry.attributes;
328
- const morphTargets = geometry.morphTargets;
329
- const attrMap = new Map();
330
- for (const key in attributes) {
331
- const attr = attributes[key];
332
- if (attr.isInterleavedBufferAttribute) {
333
- if (!attrMap.has(attr)) {
334
- attrMap.set(attr, deinterleaveAttribute(attr));
335
- }
336
- attributes[key] = attrMap.get(attr);
337
- }
338
- }
339
- for (const key in morphTargets) {
340
- const attr = morphTargets[key];
341
- if (attr.isInterleavedBufferAttribute) {
342
- if (!attrMap.has(attr)) {
343
- attrMap.set(attr, deinterleaveAttribute(attr));
344
- }
345
- morphTargets[key] = attrMap.get(attr);
346
- }
347
- }
348
- }
349
-
350
- /**
351
- * @param {BufferGeometry} geometry
352
- * @return {number}
353
- */
354
- function estimateBytesUsed(geometry) {
355
- // Return the estimated memory used by this geometry in bytes
356
- // Calculate using itemSize, count, and BYTES_PER_ELEMENT to account
357
- // for InterleavedBufferAttributes.
358
- let mem = 0;
359
- for (const name in geometry.attributes) {
360
- const attr = geometry.getAttribute(name);
361
- mem += attr.count * attr.itemSize * attr.array.BYTES_PER_ELEMENT;
362
- }
363
- const indices = geometry.getIndex();
364
- mem += indices ? indices.count * indices.itemSize * indices.array.BYTES_PER_ELEMENT : 0;
365
- return mem;
366
- }
367
-
368
- /**
369
- * @param {BufferGeometry} geometry
370
- * @param {number} tolerance
371
- * @return {BufferGeometry}
372
- */
373
- function mergeVertices(geometry) {
374
- let tolerance = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1e-4;
375
- tolerance = Math.max(tolerance, Number.EPSILON);
376
-
377
- // Generate an index buffer if the geometry doesn't have one, or optimize it
378
- // if it's already available.
379
- const hashToIndex = {};
380
- const indices = geometry.getIndex();
381
- const positions = geometry.getAttribute('position');
382
- const vertexCount = indices ? indices.count : positions.count;
383
-
384
- // next value for triangle indices
385
- let nextIndex = 0;
386
-
387
- // attributes and new attribute arrays
388
- const attributeNames = Object.keys(geometry.attributes);
389
- const tmpAttributes = {};
390
- const tmpMorphAttributes = {};
391
- const newIndices = [];
392
- const getters = ['getX', 'getY', 'getZ', 'getW'];
393
- const setters = ['setX', 'setY', 'setZ', 'setW'];
394
-
395
- // Initialize the arrays, allocating space conservatively. Extra
396
- // space will be trimmed in the last step.
397
- for (let i = 0, l = attributeNames.length; i < l; i++) {
398
- const name = attributeNames[i];
399
- const attr = geometry.attributes[name];
400
- tmpAttributes[name] = new attr.constructor(new attr.array.constructor(attr.count * attr.itemSize), attr.itemSize, attr.normalized);
401
- const morphAttributes = geometry.morphAttributes[name];
402
- if (morphAttributes) {
403
- if (!tmpMorphAttributes[name]) tmpMorphAttributes[name] = [];
404
- morphAttributes.forEach((morphAttr, i) => {
405
- const array = new morphAttr.array.constructor(morphAttr.count * morphAttr.itemSize);
406
- tmpMorphAttributes[name][i] = new morphAttr.constructor(array, morphAttr.itemSize, morphAttr.normalized);
407
- });
408
- }
409
- }
410
-
411
- // convert the error tolerance to an amount of decimal places to truncate to
412
- const halfTolerance = tolerance * 0.5;
413
- const exponent = Math.log10(1 / tolerance);
414
- const hashMultiplier = Math.pow(10, exponent);
415
- for (let i = 0; i < vertexCount; i++) {
416
- const index = indices ? indices.getX(i) : i;
417
-
418
- // Generate a hash for the vertex attributes at the current index 'i'
419
- let hash = '';
420
- for (let j = 0, l = attributeNames.length; j < l; j++) {
421
- const name = attributeNames[j];
422
- const attribute = geometry.getAttribute(name);
423
- const itemSize = attribute.itemSize;
424
- for (let k = 0; k < itemSize; k++) {
425
- // double tilde truncates the decimal value
426
- hash += `${~~(attribute[getters[k]](index) * hashMultiplier + halfTolerance * hashMultiplier)},`;
427
- }
428
- }
429
-
430
- // Add another reference to the vertex if it's already
431
- // used by another index
432
- if (hash in hashToIndex) {
433
- newIndices.push(hashToIndex[hash]);
434
- } else {
435
- // copy data to the new index in the temporary attributes
436
- for (let j = 0, l = attributeNames.length; j < l; j++) {
437
- const name = attributeNames[j];
438
- const attribute = geometry.getAttribute(name);
439
- const morphAttributes = geometry.morphAttributes[name];
440
- const itemSize = attribute.itemSize;
441
- const newArray = tmpAttributes[name];
442
- const newMorphArrays = tmpMorphAttributes[name];
443
- for (let k = 0; k < itemSize; k++) {
444
- const getterFunc = getters[k];
445
- const setterFunc = setters[k];
446
- newArray[setterFunc](nextIndex, attribute[getterFunc](index));
447
- if (morphAttributes) {
448
- for (let m = 0, ml = morphAttributes.length; m < ml; m++) {
449
- newMorphArrays[m][setterFunc](nextIndex, morphAttributes[m][getterFunc](index));
450
- }
451
- }
452
- }
453
- }
454
- hashToIndex[hash] = nextIndex;
455
- newIndices.push(nextIndex);
456
- nextIndex++;
457
- }
458
- }
459
-
460
- // generate result BufferGeometry
461
- const result = geometry.clone();
462
- for (const name in geometry.attributes) {
463
- const tmpAttribute = tmpAttributes[name];
464
- result.setAttribute(name, new tmpAttribute.constructor(tmpAttribute.array.slice(0, nextIndex * tmpAttribute.itemSize), tmpAttribute.itemSize, tmpAttribute.normalized));
465
- if (!(name in tmpMorphAttributes)) continue;
466
- for (let j = 0; j < tmpMorphAttributes[name].length; j++) {
467
- const tmpMorphAttribute = tmpMorphAttributes[name][j];
468
- result.morphAttributes[name][j] = new tmpMorphAttribute.constructor(tmpMorphAttribute.array.slice(0, nextIndex * tmpMorphAttribute.itemSize), tmpMorphAttribute.itemSize, tmpMorphAttribute.normalized);
469
- }
470
- }
471
-
472
- // indices
473
-
474
- result.setIndex(newIndices);
475
- return result;
476
- }
477
-
478
- /**
479
- * @param {BufferGeometry} geometry
480
- * @param {number} drawMode
481
- * @return {BufferGeometry}
482
- */
483
- function toTrianglesDrawMode(geometry, drawMode) {
484
- if (drawMode === TrianglesDrawMode) {
485
- console.warn('THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles.');
486
- return geometry;
487
- }
488
- if (drawMode === TriangleFanDrawMode || drawMode === TriangleStripDrawMode) {
489
- let index = geometry.getIndex();
490
-
491
- // generate index if not present
492
-
493
- if (index === null) {
494
- const indices = [];
495
- const position = geometry.getAttribute('position');
496
- if (position !== undefined) {
497
- for (let i = 0; i < position.count; i++) {
498
- indices.push(i);
499
- }
500
- geometry.setIndex(indices);
501
- index = geometry.getIndex();
502
- } else {
503
- console.error('THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible.');
504
- return geometry;
505
- }
506
- }
507
-
508
- //
509
-
510
- const numberOfTriangles = index.count - 2;
511
- const newIndices = [];
512
- if (drawMode === TriangleFanDrawMode) {
513
- // gl.TRIANGLE_FAN
514
-
515
- for (let i = 1; i <= numberOfTriangles; i++) {
516
- newIndices.push(index.getX(0));
517
- newIndices.push(index.getX(i));
518
- newIndices.push(index.getX(i + 1));
519
- }
520
- } else {
521
- // gl.TRIANGLE_STRIP
522
-
523
- for (let i = 0; i < numberOfTriangles; i++) {
524
- if (i % 2 === 0) {
525
- newIndices.push(index.getX(i));
526
- newIndices.push(index.getX(i + 1));
527
- newIndices.push(index.getX(i + 2));
528
- } else {
529
- newIndices.push(index.getX(i + 2));
530
- newIndices.push(index.getX(i + 1));
531
- newIndices.push(index.getX(i));
532
- }
533
- }
534
- }
535
- if (newIndices.length / 3 !== numberOfTriangles) {
536
- console.error('THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.');
537
- }
538
-
539
- // build final geometry
540
-
541
- const newGeometry = geometry.clone();
542
- newGeometry.setIndex(newIndices);
543
- newGeometry.clearGroups();
544
- return newGeometry;
545
- } else {
546
- console.error('THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:', drawMode);
547
- return geometry;
548
- }
549
- }
550
-
551
- /**
552
- * Calculates the morphed attributes of a morphed/skinned BufferGeometry.
553
- * Helpful for Raytracing or Decals.
554
- * @param {Mesh | Line | Points} object An instance of Mesh, Line or Points.
555
- * @return {Object} An Object with original position/normal attributes and morphed ones.
556
- */
557
- function computeMorphedAttributes(object) {
558
- const _vA = new Vector3();
559
- const _vB = new Vector3();
560
- const _vC = new Vector3();
561
- const _tempA = new Vector3();
562
- const _tempB = new Vector3();
563
- const _tempC = new Vector3();
564
- const _morphA = new Vector3();
565
- const _morphB = new Vector3();
566
- const _morphC = new Vector3();
567
- function _calculateMorphedAttributeData(object, attribute, morphAttribute, morphTargetsRelative, a, b, c, modifiedAttributeArray) {
568
- _vA.fromBufferAttribute(attribute, a);
569
- _vB.fromBufferAttribute(attribute, b);
570
- _vC.fromBufferAttribute(attribute, c);
571
- const morphInfluences = object.morphTargetInfluences;
572
- if (morphAttribute && morphInfluences) {
573
- _morphA.set(0, 0, 0);
574
- _morphB.set(0, 0, 0);
575
- _morphC.set(0, 0, 0);
576
- for (let i = 0, il = morphAttribute.length; i < il; i++) {
577
- const influence = morphInfluences[i];
578
- const morph = morphAttribute[i];
579
- if (influence === 0) continue;
580
- _tempA.fromBufferAttribute(morph, a);
581
- _tempB.fromBufferAttribute(morph, b);
582
- _tempC.fromBufferAttribute(morph, c);
583
- if (morphTargetsRelative) {
584
- _morphA.addScaledVector(_tempA, influence);
585
- _morphB.addScaledVector(_tempB, influence);
586
- _morphC.addScaledVector(_tempC, influence);
587
- } else {
588
- _morphA.addScaledVector(_tempA.sub(_vA), influence);
589
- _morphB.addScaledVector(_tempB.sub(_vB), influence);
590
- _morphC.addScaledVector(_tempC.sub(_vC), influence);
591
- }
592
- }
593
- _vA.add(_morphA);
594
- _vB.add(_morphB);
595
- _vC.add(_morphC);
596
- }
597
- if (object.isSkinnedMesh) {
598
- object.applyBoneTransform(a, _vA);
599
- object.applyBoneTransform(b, _vB);
600
- object.applyBoneTransform(c, _vC);
601
- }
602
- modifiedAttributeArray[a * 3 + 0] = _vA.x;
603
- modifiedAttributeArray[a * 3 + 1] = _vA.y;
604
- modifiedAttributeArray[a * 3 + 2] = _vA.z;
605
- modifiedAttributeArray[b * 3 + 0] = _vB.x;
606
- modifiedAttributeArray[b * 3 + 1] = _vB.y;
607
- modifiedAttributeArray[b * 3 + 2] = _vB.z;
608
- modifiedAttributeArray[c * 3 + 0] = _vC.x;
609
- modifiedAttributeArray[c * 3 + 1] = _vC.y;
610
- modifiedAttributeArray[c * 3 + 2] = _vC.z;
611
- }
612
- const geometry = object.geometry;
613
- const material = object.material;
614
- let a, b, c;
615
- const index = geometry.index;
616
- const positionAttribute = geometry.attributes.position;
617
- const morphPosition = geometry.morphAttributes.position;
618
- const morphTargetsRelative = geometry.morphTargetsRelative;
619
- const normalAttribute = geometry.attributes.normal;
620
- const morphNormal = geometry.morphAttributes.position;
621
- const groups = geometry.groups;
622
- const drawRange = geometry.drawRange;
623
- let i, j, il, jl;
624
- let group;
625
- let start, end;
626
- const modifiedPosition = new Float32Array(positionAttribute.count * positionAttribute.itemSize);
627
- const modifiedNormal = new Float32Array(normalAttribute.count * normalAttribute.itemSize);
628
- if (index !== null) {
629
- // indexed buffer geometry
630
-
631
- if (Array.isArray(material)) {
632
- for (i = 0, il = groups.length; i < il; i++) {
633
- group = groups[i];
634
- start = Math.max(group.start, drawRange.start);
635
- end = Math.min(group.start + group.count, drawRange.start + drawRange.count);
636
- for (j = start, jl = end; j < jl; j += 3) {
637
- a = index.getX(j);
638
- b = index.getX(j + 1);
639
- c = index.getX(j + 2);
640
- _calculateMorphedAttributeData(object, positionAttribute, morphPosition, morphTargetsRelative, a, b, c, modifiedPosition);
641
- _calculateMorphedAttributeData(object, normalAttribute, morphNormal, morphTargetsRelative, a, b, c, modifiedNormal);
642
- }
643
- }
644
- } else {
645
- start = Math.max(0, drawRange.start);
646
- end = Math.min(index.count, drawRange.start + drawRange.count);
647
- for (i = start, il = end; i < il; i += 3) {
648
- a = index.getX(i);
649
- b = index.getX(i + 1);
650
- c = index.getX(i + 2);
651
- _calculateMorphedAttributeData(object, positionAttribute, morphPosition, morphTargetsRelative, a, b, c, modifiedPosition);
652
- _calculateMorphedAttributeData(object, normalAttribute, morphNormal, morphTargetsRelative, a, b, c, modifiedNormal);
653
- }
654
- }
655
- } else {
656
- // non-indexed buffer geometry
657
-
658
- if (Array.isArray(material)) {
659
- for (i = 0, il = groups.length; i < il; i++) {
660
- group = groups[i];
661
- start = Math.max(group.start, drawRange.start);
662
- end = Math.min(group.start + group.count, drawRange.start + drawRange.count);
663
- for (j = start, jl = end; j < jl; j += 3) {
664
- a = j;
665
- b = j + 1;
666
- c = j + 2;
667
- _calculateMorphedAttributeData(object, positionAttribute, morphPosition, morphTargetsRelative, a, b, c, modifiedPosition);
668
- _calculateMorphedAttributeData(object, normalAttribute, morphNormal, morphTargetsRelative, a, b, c, modifiedNormal);
669
- }
670
- }
671
- } else {
672
- start = Math.max(0, drawRange.start);
673
- end = Math.min(positionAttribute.count, drawRange.start + drawRange.count);
674
- for (i = start, il = end; i < il; i += 3) {
675
- a = i;
676
- b = i + 1;
677
- c = i + 2;
678
- _calculateMorphedAttributeData(object, positionAttribute, morphPosition, morphTargetsRelative, a, b, c, modifiedPosition);
679
- _calculateMorphedAttributeData(object, normalAttribute, morphNormal, morphTargetsRelative, a, b, c, modifiedNormal);
680
- }
681
- }
682
- }
683
- const morphedPositionAttribute = new Float32BufferAttribute(modifiedPosition, 3);
684
- const morphedNormalAttribute = new Float32BufferAttribute(modifiedNormal, 3);
685
- return {
686
- positionAttribute: positionAttribute,
687
- normalAttribute: normalAttribute,
688
- morphedPositionAttribute: morphedPositionAttribute,
689
- morphedNormalAttribute: morphedNormalAttribute
690
- };
691
- }
692
- function mergeGroups(geometry) {
693
- if (geometry.groups.length === 0) {
694
- console.warn('THREE.BufferGeometryUtils.mergeGroups(): No groups are defined. Nothing to merge.');
695
- return geometry;
696
- }
697
- let groups = geometry.groups;
698
-
699
- // sort groups by material index
700
-
701
- groups = groups.sort((a, b) => {
702
- if (a.materialIndex !== b.materialIndex) return a.materialIndex - b.materialIndex;
703
- return a.start - b.start;
704
- });
705
-
706
- // create index for non-indexed geometries
707
-
708
- if (geometry.getIndex() === null) {
709
- const positionAttribute = geometry.getAttribute('position');
710
- const indices = [];
711
- for (let i = 0; i < positionAttribute.count; i += 3) {
712
- indices.push(i, i + 1, i + 2);
713
- }
714
- geometry.setIndex(indices);
715
- }
716
-
717
- // sort index
718
-
719
- const index = geometry.getIndex();
720
- const newIndices = [];
721
- for (let i = 0; i < groups.length; i++) {
722
- const group = groups[i];
723
- const groupStart = group.start;
724
- const groupLength = groupStart + group.count;
725
- for (let j = groupStart; j < groupLength; j++) {
726
- newIndices.push(index.getX(j));
727
- }
728
- }
729
- geometry.dispose(); // Required to force buffer recreation
730
- geometry.setIndex(newIndices);
731
-
732
- // update groups indices
733
-
734
- let start = 0;
735
- for (let i = 0; i < groups.length; i++) {
736
- const group = groups[i];
737
- group.start = start;
738
- start += group.count;
739
- }
740
-
741
- // merge groups
742
-
743
- let currentGroup = groups[0];
744
- geometry.groups = [currentGroup];
745
- for (let i = 1; i < groups.length; i++) {
746
- const group = groups[i];
747
- if (currentGroup.materialIndex === group.materialIndex) {
748
- currentGroup.count += group.count;
749
- } else {
750
- currentGroup = group;
751
- geometry.groups.push(currentGroup);
752
- }
753
- }
754
- return geometry;
755
- }
756
-
757
- /**
758
- * Modifies the supplied geometry if it is non-indexed, otherwise creates a new,
759
- * non-indexed geometry. Returns the geometry with smooth normals everywhere except
760
- * faces that meet at an angle greater than the crease angle.
761
- *
762
- * @param {BufferGeometry} geometry
763
- * @param {number} [creaseAngle]
764
- * @return {BufferGeometry}
765
- */
766
- function toCreasedNormals(geometry) {
767
- let creaseAngle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Math.PI / 3;
768
- const creaseDot = Math.cos(creaseAngle);
769
- const hashMultiplier = (1 + 1e-10) * 1e2;
770
-
771
- // reusable vectors
772
- const verts = [new Vector3(), new Vector3(), new Vector3()];
773
- const tempVec1 = new Vector3();
774
- const tempVec2 = new Vector3();
775
- const tempNorm = new Vector3();
776
- const tempNorm2 = new Vector3();
777
-
778
- // hashes a vector
779
- function hashVertex(v) {
780
- const x = ~~(v.x * hashMultiplier);
781
- const y = ~~(v.y * hashMultiplier);
782
- const z = ~~(v.z * hashMultiplier);
783
- return `${x},${y},${z}`;
784
- }
785
-
786
- // BufferGeometry.toNonIndexed() warns if the geometry is non-indexed
787
- // and returns the original geometry
788
- const resultGeometry = geometry.index ? geometry.toNonIndexed() : geometry;
789
- const posAttr = resultGeometry.attributes.position;
790
- const vertexMap = {};
791
-
792
- // find all the normals shared by commonly located vertices
793
- for (let i = 0, l = posAttr.count / 3; i < l; i++) {
794
- const i3 = 3 * i;
795
- const a = verts[0].fromBufferAttribute(posAttr, i3 + 0);
796
- const b = verts[1].fromBufferAttribute(posAttr, i3 + 1);
797
- const c = verts[2].fromBufferAttribute(posAttr, i3 + 2);
798
- tempVec1.subVectors(c, b);
799
- tempVec2.subVectors(a, b);
800
-
801
- // add the normal to the map for all vertices
802
- const normal = new Vector3().crossVectors(tempVec1, tempVec2).normalize();
803
- for (let n = 0; n < 3; n++) {
804
- const vert = verts[n];
805
- const hash = hashVertex(vert);
806
- if (!(hash in vertexMap)) {
807
- vertexMap[hash] = [];
808
- }
809
- vertexMap[hash].push(normal);
810
- }
811
- }
812
-
813
- // average normals from all vertices that share a common location if they are within the
814
- // provided crease threshold
815
- const normalArray = new Float32Array(posAttr.count * 3);
816
- const normAttr = new BufferAttribute(normalArray, 3, false);
817
- for (let i = 0, l = posAttr.count / 3; i < l; i++) {
818
- // get the face normal for this vertex
819
- const i3 = 3 * i;
820
- const a = verts[0].fromBufferAttribute(posAttr, i3 + 0);
821
- const b = verts[1].fromBufferAttribute(posAttr, i3 + 1);
822
- const c = verts[2].fromBufferAttribute(posAttr, i3 + 2);
823
- tempVec1.subVectors(c, b);
824
- tempVec2.subVectors(a, b);
825
- tempNorm.crossVectors(tempVec1, tempVec2).normalize();
826
-
827
- // average all normals that meet the threshold and set the normal value
828
- for (let n = 0; n < 3; n++) {
829
- const vert = verts[n];
830
- const hash = hashVertex(vert);
831
- const otherNormals = vertexMap[hash];
832
- tempNorm2.set(0, 0, 0);
833
- for (let k = 0, lk = otherNormals.length; k < lk; k++) {
834
- const otherNorm = otherNormals[k];
835
- if (tempNorm.dot(otherNorm) > creaseDot) {
836
- tempNorm2.add(otherNorm);
837
- }
838
- }
839
- tempNorm2.normalize();
840
- normAttr.setXYZ(i3 + n, tempNorm2.x, tempNorm2.y, tempNorm2.z);
841
- }
842
- }
843
- resultGeometry.setAttribute('normal', normAttr);
844
- return resultGeometry;
845
- }
846
- export { computeMikkTSpaceTangents, mergeGeometries, mergeAttributes, interleaveAttributes, estimateBytesUsed, mergeVertices, toTrianglesDrawMode, computeMorphedAttributes, mergeGroups, toCreasedNormals };