itowns 2.45.1-next.0 → 2.45.1-next.1
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.
- package/dist/455.js +2 -0
- package/dist/455.js.map +1 -0
- package/dist/debug.js +3 -0
- package/dist/debug.js.LICENSE.txt +13 -0
- package/dist/debug.js.map +1 -0
- package/dist/itowns.js +3 -0
- package/dist/itowns.js.LICENSE.txt +5 -0
- package/dist/itowns.js.map +1 -0
- package/dist/itowns_lasparser.js +2 -0
- package/dist/itowns_lasparser.js.map +1 -0
- package/dist/itowns_lasworker.js +2 -0
- package/dist/itowns_lasworker.js.map +1 -0
- package/dist/itowns_potree2worker.js +2 -0
- package/dist/itowns_potree2worker.js.map +1 -0
- package/dist/itowns_widgets.js +2 -0
- package/dist/itowns_widgets.js.map +1 -0
- package/lib/Controls/FirstPersonControls.js +308 -0
- package/lib/Controls/FlyControls.js +175 -0
- package/lib/Controls/GlobeControls.js +1178 -0
- package/lib/Controls/PlanarControls.js +1025 -0
- package/lib/Controls/StateControl.js +432 -0
- package/lib/Controls/StreetControls.js +392 -0
- package/lib/Converter/Feature2Mesh.js +612 -0
- package/lib/Converter/Feature2Texture.js +174 -0
- package/lib/Converter/convertToTile.js +70 -0
- package/lib/Converter/textureConverter.js +43 -0
- package/lib/Core/3DTiles/C3DTBatchTable.js +131 -0
- package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +96 -0
- package/lib/Core/3DTiles/C3DTBoundingVolume.js +156 -0
- package/lib/Core/3DTiles/C3DTExtensions.js +97 -0
- package/lib/Core/3DTiles/C3DTFeature.js +110 -0
- package/lib/Core/3DTiles/C3DTilesEnums.js +20 -0
- package/lib/Core/3DTiles/C3DTileset.js +99 -0
- package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +100 -0
- package/lib/Core/AnimationPlayer.js +142 -0
- package/lib/Core/CopcNode.js +174 -0
- package/lib/Core/Deprecated/Undeprecator.js +74 -0
- package/lib/Core/EntwinePointTileNode.js +126 -0
- package/lib/Core/Feature.js +488 -0
- package/lib/Core/Geographic/GeoidGrid.js +108 -0
- package/lib/Core/Label.js +222 -0
- package/lib/Core/MainLoop.js +209 -0
- package/lib/Core/Picking.js +255 -0
- package/lib/Core/PointCloudNode.js +42 -0
- package/lib/Core/Potree2Node.js +206 -0
- package/lib/Core/Potree2PointAttributes.js +139 -0
- package/lib/Core/PotreeNode.js +101 -0
- package/lib/Core/Prefab/Globe/Atmosphere.js +293 -0
- package/lib/Core/Prefab/Globe/GlobeLayer.js +152 -0
- package/lib/Core/Prefab/Globe/GlobeTileBuilder.js +110 -0
- package/lib/Core/Prefab/Globe/SkyShader.js +78 -0
- package/lib/Core/Prefab/GlobeView.js +155 -0
- package/lib/Core/Prefab/Planar/PlanarLayer.js +59 -0
- package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +71 -0
- package/lib/Core/Prefab/PlanarView.js +62 -0
- package/lib/Core/Prefab/TileBuilder.js +82 -0
- package/lib/Core/Prefab/computeBufferTileGeometry.js +248 -0
- package/lib/Core/Scheduler/Cache.js +17 -0
- package/lib/Core/Scheduler/CancelledCommandException.js +15 -0
- package/lib/Core/Scheduler/Scheduler.js +294 -0
- package/lib/Core/Style.js +660 -0
- package/lib/Core/StyleOptions.js +486 -0
- package/lib/Core/System/Capabilities.js +63 -0
- package/lib/Core/Tile/Tile.js +205 -0
- package/lib/Core/Tile/TileGrid.js +49 -0
- package/lib/Core/TileGeometry.js +124 -0
- package/lib/Core/TileMesh.js +108 -0
- package/lib/Core/View.js +1115 -0
- package/lib/Layer/C3DTilesLayer.js +459 -0
- package/lib/Layer/ColorLayer.js +154 -0
- package/lib/Layer/CopcLayer.js +63 -0
- package/lib/Layer/ElevationLayer.js +139 -0
- package/lib/Layer/EntwinePointTileLayer.js +71 -0
- package/lib/Layer/FeatureGeometryLayer.js +77 -0
- package/lib/Layer/GeoidLayer.js +80 -0
- package/lib/Layer/GeometryLayer.js +233 -0
- package/lib/Layer/InfoLayer.js +64 -0
- package/lib/Layer/LabelLayer.js +469 -0
- package/lib/Layer/Layer.js +335 -0
- package/lib/Layer/LayerUpdateState.js +89 -0
- package/lib/Layer/LayerUpdateStrategy.js +80 -0
- package/lib/Layer/OGC3DTilesLayer.js +543 -0
- package/lib/Layer/OrientedImageLayer.js +227 -0
- package/lib/Layer/PointCloudLayer.js +405 -0
- package/lib/Layer/Potree2Layer.js +171 -0
- package/lib/Layer/PotreeLayer.js +72 -0
- package/lib/Layer/RasterLayer.js +37 -0
- package/lib/Layer/ReferencingLayerProperties.js +62 -0
- package/lib/Layer/TiledGeometryLayer.js +459 -0
- package/lib/Loader/LASLoader.js +193 -0
- package/lib/Loader/Potree2BrotliLoader.js +261 -0
- package/lib/Loader/Potree2Loader.js +207 -0
- package/lib/Main.js +113 -0
- package/lib/MainBundle.js +4 -0
- package/lib/Parser/B3dmParser.js +174 -0
- package/lib/Parser/CameraCalibrationParser.js +94 -0
- package/lib/Parser/GDFParser.js +72 -0
- package/lib/Parser/GTXParser.js +75 -0
- package/lib/Parser/GeoJsonParser.js +212 -0
- package/lib/Parser/GpxParser.js +25 -0
- package/lib/Parser/ISGParser.js +71 -0
- package/lib/Parser/KMLParser.js +25 -0
- package/lib/Parser/LASParser.js +137 -0
- package/lib/Parser/MapBoxUrlParser.js +83 -0
- package/lib/Parser/PntsParser.js +131 -0
- package/lib/Parser/Potree2BinParser.js +92 -0
- package/lib/Parser/PotreeBinParser.js +106 -0
- package/lib/Parser/PotreeCinParser.js +29 -0
- package/lib/Parser/ShapefileParser.js +78 -0
- package/lib/Parser/VectorTileParser.js +215 -0
- package/lib/Parser/XbilParser.js +120 -0
- package/lib/Parser/deprecated/LegacyGLTFLoader.js +1386 -0
- package/lib/Parser/iGLTFLoader.js +168 -0
- package/lib/Process/3dTilesProcessing.js +304 -0
- package/lib/Process/FeatureProcessing.js +76 -0
- package/lib/Process/LayeredMaterialNodeProcessing.js +229 -0
- package/lib/Process/ObjectRemovalHelper.js +97 -0
- package/lib/Process/handlerNodeError.js +23 -0
- package/lib/Provider/3dTilesProvider.js +149 -0
- package/lib/Provider/DataSourceProvider.js +24 -0
- package/lib/Provider/Fetcher.js +233 -0
- package/lib/Provider/PointCloudProvider.js +45 -0
- package/lib/Provider/TileProvider.js +16 -0
- package/lib/Provider/URLBuilder.js +116 -0
- package/lib/Renderer/Camera.js +281 -0
- package/lib/Renderer/Color.js +56 -0
- package/lib/Renderer/ColorLayersOrdering.js +115 -0
- package/lib/Renderer/CommonMaterial.js +31 -0
- package/lib/Renderer/Label2DRenderer.js +192 -0
- package/lib/Renderer/LayeredMaterial.js +243 -0
- package/lib/Renderer/OBB.js +150 -0
- package/lib/Renderer/OrientedImageCamera.js +118 -0
- package/lib/Renderer/OrientedImageMaterial.js +167 -0
- package/lib/Renderer/PointsMaterial.js +485 -0
- package/lib/Renderer/RasterTile.js +243 -0
- package/lib/Renderer/RenderMode.js +31 -0
- package/lib/Renderer/Shader/ShaderChunk.js +160 -0
- package/lib/Renderer/Shader/ShaderUtils.js +47 -0
- package/lib/Renderer/SphereHelper.js +17 -0
- package/lib/Renderer/WebXR.js +51 -0
- package/lib/Renderer/c3DEngine.js +214 -0
- package/lib/Source/C3DTilesGoogleSource.js +74 -0
- package/lib/Source/C3DTilesIonSource.js +54 -0
- package/lib/Source/C3DTilesSource.js +30 -0
- package/lib/Source/CopcSource.js +126 -0
- package/lib/Source/EntwinePointTileSource.js +72 -0
- package/lib/Source/FileSource.js +188 -0
- package/lib/Source/OGC3DTilesGoogleSource.js +29 -0
- package/lib/Source/OGC3DTilesIonSource.js +34 -0
- package/lib/Source/OGC3DTilesSource.js +21 -0
- package/lib/Source/OrientedImageSource.js +59 -0
- package/lib/Source/Potree2Source.js +167 -0
- package/lib/Source/PotreeSource.js +82 -0
- package/lib/Source/Source.js +202 -0
- package/lib/Source/TMSSource.js +144 -0
- package/lib/Source/VectorTilesSource.js +182 -0
- package/lib/Source/WFSSource.js +170 -0
- package/lib/Source/WMSSource.js +167 -0
- package/lib/Source/WMTSSource.js +92 -0
- package/lib/ThreeExtended/capabilities/WebGL.js +69 -0
- package/lib/ThreeExtended/libs/ktx-parse.module.js +506 -0
- package/lib/ThreeExtended/libs/zstddec.module.js +29 -0
- package/lib/ThreeExtended/loaders/DDSLoader.js +200 -0
- package/lib/ThreeExtended/loaders/DRACOLoader.js +400 -0
- package/lib/ThreeExtended/loaders/GLTFLoader.js +2879 -0
- package/lib/ThreeExtended/loaders/KTX2Loader.js +709 -0
- package/lib/ThreeExtended/math/ColorSpaces.js +59 -0
- package/lib/ThreeExtended/utils/BufferGeometryUtils.js +846 -0
- package/lib/ThreeExtended/utils/WorkerPool.js +70 -0
- package/lib/Utils/CameraUtils.js +554 -0
- package/lib/Utils/DEMUtils.js +350 -0
- package/lib/Utils/FeaturesUtils.js +156 -0
- package/lib/Utils/Gradients.js +16 -0
- package/lib/Utils/ThreeUtils.js +115 -0
- package/lib/Utils/gui/C3DTilesStyle.js +218 -0
- package/lib/Utils/gui/Main.js +7 -0
- package/lib/Utils/gui/Minimap.js +152 -0
- package/lib/Utils/gui/Navigation.js +245 -0
- package/lib/Utils/gui/Scale.js +104 -0
- package/lib/Utils/gui/Searchbar.js +234 -0
- package/lib/Utils/gui/Widget.js +80 -0
- package/lib/Utils/placeObjectOnGround.js +136 -0
- package/lib/Worker/LASLoaderWorker.js +19 -0
- package/lib/Worker/Potree2Worker.js +21 -0
- package/package.json +2 -2
|
@@ -0,0 +1,846 @@
|
|
|
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 };
|