super-three 0.170.0 → 0.170.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/build/three.cjs +24410 -24422
- package/build/three.core.js +37002 -0
- package/build/three.core.min.js +6 -0
- package/build/three.module.js +10573 -47578
- package/build/three.module.min.js +1 -1
- package/build/three.tsl.js +533 -0
- package/build/three.tsl.min.js +6 -0
- package/build/three.webgpu.js +2907 -37975
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +2914 -37959
- package/build/three.webgpu.nodes.min.js +1 -1
- package/examples/jsm/capabilities/WebGPU.js +1 -10
- package/examples/jsm/controls/ArcballControls.js +25 -21
- package/examples/jsm/controls/OrbitControls.js +41 -9
- package/examples/jsm/controls/PointerLockControls.js +2 -5
- package/examples/jsm/csm/CSMShadowNode.js +7 -5
- package/examples/jsm/geometries/DecalGeometry.js +5 -1
- package/examples/jsm/lighting/TiledLighting.js +1 -1
- package/examples/jsm/lines/LineGeometry.js +25 -0
- package/examples/jsm/lines/LineMaterial.js +1 -7
- package/examples/jsm/lines/webgpu/Line2.js +2 -1
- package/examples/jsm/lines/webgpu/LineSegments2.js +2 -1
- package/examples/jsm/lines/webgpu/Wireframe.js +2 -1
- package/examples/jsm/loaders/KTX2Loader.js +3 -0
- package/examples/jsm/loaders/MMDLoader.js +2 -6
- package/examples/jsm/loaders/MaterialXLoader.js +2 -2
- package/examples/jsm/materials/MeshGouraudMaterial.js +2 -6
- package/examples/jsm/misc/ProgressiveLightMapGPU.js +2 -2
- package/examples/jsm/objects/InstancedPoints.js +2 -4
- package/examples/jsm/objects/LensflareMesh.js +4 -2
- package/examples/jsm/objects/SkyMesh.js +5 -3
- package/examples/jsm/objects/Water2Mesh.js +7 -3
- package/examples/jsm/objects/WaterMesh.js +5 -3
- package/examples/jsm/transpiler/AST.js +2 -2
- package/examples/jsm/transpiler/GLSLDecoder.js +57 -25
- package/examples/jsm/transpiler/TSLEncoder.js +11 -6
- package/examples/jsm/tsl/display/AfterImageNode.js +3 -3
- package/examples/jsm/tsl/display/AnaglyphPassNode.js +2 -2
- package/examples/jsm/tsl/display/AnamorphicNode.js +2 -2
- package/examples/jsm/tsl/display/BloomNode.js +3 -3
- package/examples/jsm/tsl/display/DenoiseNode.js +48 -12
- package/examples/jsm/tsl/display/DepthOfFieldNode.js +3 -2
- package/examples/jsm/tsl/display/DotScreenNode.js +2 -2
- package/examples/jsm/tsl/display/FXAANode.js +3 -3
- package/examples/jsm/tsl/display/FilmNode.js +3 -2
- package/examples/jsm/tsl/display/GTAONode.js +62 -27
- package/examples/jsm/tsl/display/GaussianBlurNode.js +6 -8
- package/examples/jsm/tsl/display/LensflareNode.js +3 -3
- package/examples/jsm/tsl/display/Lut3DNode.js +3 -2
- package/examples/jsm/tsl/display/OutlineNode.js +2 -2
- package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +2 -1
- package/examples/jsm/tsl/display/PixelationPassNode.js +4 -4
- package/examples/jsm/tsl/display/RGBShiftNode.js +2 -1
- package/examples/jsm/tsl/display/SMAANode.js +3 -3
- package/examples/jsm/tsl/display/SSAAPassNode.js +2 -2
- package/examples/jsm/tsl/display/SSRNode.js +31 -8
- package/examples/jsm/tsl/display/SobelOperatorNode.js +3 -3
- package/examples/jsm/tsl/display/StereoCompositePassNode.js +4 -4
- package/examples/jsm/tsl/display/StereoPassNode.js +2 -2
- package/examples/jsm/tsl/display/TRAAPassNode.js +2 -2
- package/examples/jsm/tsl/display/TransitionNode.js +3 -2
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +6 -9
- package/examples/jsm/utils/SceneOptimizer.js +410 -0
- package/examples/jsm/utils/UVsDebug.js +1 -1
- package/package.json +3 -3
- package/src/Three.Core.js +178 -0
- package/src/Three.TSL.js +526 -0
- package/src/Three.WebGPU.Nodes.js +5 -186
- package/src/Three.WebGPU.js +4 -186
- package/src/Three.js +1 -177
- package/src/animation/AnimationClip.js +2 -2
- package/src/animation/AnimationObjectGroup.js +2 -2
- package/src/audio/Audio.js +38 -0
- package/src/cameras/PerspectiveCamera.js +6 -6
- package/src/cameras/StereoCamera.js +2 -2
- package/src/constants.js +1 -1
- package/src/core/BufferGeometry.js +5 -3
- package/src/core/InterleavedBuffer.js +4 -4
- package/src/core/Object3D.js +2 -2
- package/src/extras/core/Curve.js +3 -3
- package/src/extras/core/Shape.js +2 -2
- package/src/geometries/EdgesGeometry.js +2 -2
- package/src/geometries/LatheGeometry.js +2 -2
- package/src/lights/SpotLightShadow.js +2 -2
- package/src/materials/LineBasicMaterial.js +2 -6
- package/src/materials/LineDashedMaterial.js +1 -6
- package/src/materials/Material.js +3 -16
- package/src/materials/MeshBasicMaterial.js +2 -6
- package/src/materials/MeshDepthMaterial.js +2 -6
- package/src/materials/MeshDistanceMaterial.js +2 -6
- package/src/materials/MeshLambertMaterial.js +2 -6
- package/src/materials/MeshMatcapMaterial.js +2 -6
- package/src/materials/MeshNormalMaterial.js +2 -6
- package/src/materials/MeshPhongMaterial.js +3 -7
- package/src/materials/MeshPhysicalMaterial.js +4 -8
- package/src/materials/MeshStandardMaterial.js +2 -6
- package/src/materials/MeshToonMaterial.js +2 -6
- package/src/materials/PointsMaterial.js +2 -6
- package/src/materials/RawShaderMaterial.js +2 -6
- package/src/materials/ShaderMaterial.js +2 -6
- package/src/materials/ShadowMaterial.js +2 -6
- package/src/materials/SpriteMaterial.js +2 -6
- package/src/materials/nodes/Line2NodeMaterial.js +32 -13
- package/src/materials/nodes/LineDashedNodeMaterial.js +4 -2
- package/src/materials/nodes/NodeMaterial.js +64 -16
- package/src/materials/nodes/manager/NodeMaterialObserver.js +13 -10
- package/src/math/ColorManagement.js +130 -122
- package/src/math/Line3.js +2 -2
- package/src/math/Quaternion.js +2 -2
- package/src/math/Spherical.js +3 -3
- package/src/math/Vector2.js +7 -7
- package/src/math/Vector3.js +9 -9
- package/src/math/Vector4.js +11 -9
- package/src/nodes/Nodes.js +1 -0
- package/src/nodes/TSL.js +3 -1
- package/src/nodes/accessors/Arrays.js +27 -0
- package/src/nodes/accessors/BuiltinNode.js +26 -0
- package/src/nodes/accessors/ClippingNode.js +76 -42
- package/src/nodes/accessors/InstanceNode.js +17 -20
- package/src/nodes/accessors/InstancedMeshNode.js +26 -0
- package/src/nodes/accessors/Lights.js +32 -0
- package/src/nodes/accessors/StorageBufferNode.js +29 -9
- package/src/nodes/accessors/StorageTextureNode.js +10 -4
- package/src/nodes/accessors/TextureNode.js +1 -1
- package/src/nodes/core/NodeBuilder.js +2 -9
- package/src/nodes/core/NodeUtils.js +28 -0
- package/src/nodes/core/constants.js +6 -0
- package/src/nodes/display/BlendModes.js +99 -0
- package/src/nodes/display/ToonOutlinePassNode.js +3 -3
- package/src/nodes/display/ViewportDepthNode.js +21 -6
- package/src/nodes/functions/material/getAlphaHashThreshold.js +13 -7
- package/src/nodes/functions/material/getParallaxCorrectNormal.js +1 -1
- package/src/nodes/lighting/AnalyticLightNode.js +12 -4
- package/src/nodes/lighting/PointLightNode.js +10 -1
- package/src/nodes/lighting/PointShadowNode.js +254 -0
- package/src/nodes/lighting/ShadowNode.js +176 -67
- package/src/nodes/lighting/SpotLightNode.js +14 -2
- package/src/nodes/utils/RTTNode.js +9 -1
- package/src/nodes/utils/StorageArrayElementNode.js +2 -2
- package/src/objects/BatchedMesh.js +54 -95
- package/src/objects/ClippingGroup.js +19 -0
- package/src/objects/Skeleton.js +2 -2
- package/src/renderers/WebGLRenderer.js +94 -23
- package/src/renderers/common/Animation.js +23 -11
- package/src/renderers/common/Background.js +1 -1
- package/src/renderers/common/Bindings.js +20 -4
- package/src/renderers/common/ClippingContext.js +77 -85
- package/src/renderers/common/RenderList.js +9 -6
- package/src/renderers/common/RenderObject.js +27 -27
- package/src/renderers/common/RenderObjects.js +12 -6
- package/src/renderers/common/Renderer.js +63 -57
- package/src/renderers/common/Textures.js +11 -3
- package/src/renderers/common/UniformsGroup.js +16 -4
- package/src/renderers/common/extras/PMREMGenerator.js +89 -13
- package/src/renderers/common/nodes/NodeLibrary.js +2 -2
- package/src/renderers/common/nodes/NodeStorageBuffer.js +2 -3
- package/src/renderers/common/nodes/NodeUniform.js +42 -0
- package/src/renderers/webgl/WebGLBackground.js +20 -1
- package/src/renderers/webgl/WebGLGeometries.js +0 -28
- package/src/renderers/webgl-fallback/WebGLBackend.js +13 -6
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +43 -12
- package/src/renderers/webgl-fallback/utils/WebGLState.js +26 -1
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +4 -1
- package/src/renderers/webgpu/WebGPUBackend.js +47 -31
- package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +13 -26
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +184 -74
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +15 -2
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +72 -7
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +5 -1
- package/src/textures/Source.js +2 -2
- package/src/textures/Texture.js +2 -2
- package/src/nodes/display/BlendMode.js +0 -54
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
|
|
3
|
+
class SceneOptimizer {
|
|
4
|
+
|
|
5
|
+
constructor( scene, options = {} ) {
|
|
6
|
+
|
|
7
|
+
this.scene = scene;
|
|
8
|
+
this.debug = options.debug || false;
|
|
9
|
+
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
bufferToHash( buffer ) {
|
|
13
|
+
|
|
14
|
+
let hash = 0;
|
|
15
|
+
if ( buffer.byteLength !== 0 ) {
|
|
16
|
+
|
|
17
|
+
let uintArray;
|
|
18
|
+
if ( buffer.buffer ) {
|
|
19
|
+
|
|
20
|
+
uintArray = new Uint8Array(
|
|
21
|
+
buffer.buffer,
|
|
22
|
+
buffer.byteOffset,
|
|
23
|
+
buffer.byteLength
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
} else {
|
|
27
|
+
|
|
28
|
+
uintArray = new Uint8Array( buffer );
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
for ( let i = 0; i < buffer.byteLength; i ++ ) {
|
|
33
|
+
|
|
34
|
+
const byte = uintArray[ i ];
|
|
35
|
+
hash = ( hash << 5 ) - hash + byte;
|
|
36
|
+
hash |= 0;
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return hash;
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
getMaterialPropertiesHash( material ) {
|
|
47
|
+
|
|
48
|
+
const mapProps = [
|
|
49
|
+
'map',
|
|
50
|
+
'alphaMap',
|
|
51
|
+
'aoMap',
|
|
52
|
+
'bumpMap',
|
|
53
|
+
'displacementMap',
|
|
54
|
+
'emissiveMap',
|
|
55
|
+
'envMap',
|
|
56
|
+
'lightMap',
|
|
57
|
+
'metalnessMap',
|
|
58
|
+
'normalMap',
|
|
59
|
+
'roughnessMap',
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
const mapHash = mapProps
|
|
63
|
+
.map( ( prop ) => {
|
|
64
|
+
|
|
65
|
+
const map = material[ prop ];
|
|
66
|
+
if ( ! map ) return 0;
|
|
67
|
+
return `${map.uuid}_${map.offset.x}_${map.offset.y}_${map.repeat.x}_${map.repeat.y}_${map.rotation}`;
|
|
68
|
+
|
|
69
|
+
} )
|
|
70
|
+
.join( '|' );
|
|
71
|
+
|
|
72
|
+
const physicalProps = [
|
|
73
|
+
'transparent',
|
|
74
|
+
'opacity',
|
|
75
|
+
'alphaTest',
|
|
76
|
+
'alphaToCoverage',
|
|
77
|
+
'side',
|
|
78
|
+
'vertexColors',
|
|
79
|
+
'visible',
|
|
80
|
+
'blending',
|
|
81
|
+
'wireframe',
|
|
82
|
+
'flatShading',
|
|
83
|
+
'premultipliedAlpha',
|
|
84
|
+
'dithering',
|
|
85
|
+
'toneMapped',
|
|
86
|
+
'depthTest',
|
|
87
|
+
'depthWrite',
|
|
88
|
+
'metalness',
|
|
89
|
+
'roughness',
|
|
90
|
+
'clearcoat',
|
|
91
|
+
'clearcoatRoughness',
|
|
92
|
+
'sheen',
|
|
93
|
+
'sheenRoughness',
|
|
94
|
+
'transmission',
|
|
95
|
+
'thickness',
|
|
96
|
+
'attenuationDistance',
|
|
97
|
+
'ior',
|
|
98
|
+
'iridescence',
|
|
99
|
+
'iridescenceIOR',
|
|
100
|
+
'iridescenceThicknessRange',
|
|
101
|
+
'reflectivity',
|
|
102
|
+
]
|
|
103
|
+
.map( ( prop ) => {
|
|
104
|
+
|
|
105
|
+
if ( typeof material[ prop ] === 'undefined' ) return 0;
|
|
106
|
+
if ( material[ prop ] === null ) return 0;
|
|
107
|
+
return material[ prop ].toString();
|
|
108
|
+
|
|
109
|
+
} )
|
|
110
|
+
.join( '|' );
|
|
111
|
+
|
|
112
|
+
const emissiveHash = material.emissive ? material.emissive.getHexString() : 0;
|
|
113
|
+
const attenuationHash = material.attenuationColor
|
|
114
|
+
? material.attenuationColor.getHexString()
|
|
115
|
+
: 0;
|
|
116
|
+
const sheenColorHash = material.sheenColor
|
|
117
|
+
? material.sheenColor.getHexString()
|
|
118
|
+
: 0;
|
|
119
|
+
|
|
120
|
+
return [
|
|
121
|
+
material.type,
|
|
122
|
+
physicalProps,
|
|
123
|
+
mapHash,
|
|
124
|
+
emissiveHash,
|
|
125
|
+
attenuationHash,
|
|
126
|
+
sheenColorHash,
|
|
127
|
+
].join( '_' );
|
|
128
|
+
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
getAttributesSignature( geometry ) {
|
|
132
|
+
|
|
133
|
+
return Object.keys( geometry.attributes )
|
|
134
|
+
.sort()
|
|
135
|
+
.map( ( name ) => {
|
|
136
|
+
|
|
137
|
+
const attribute = geometry.attributes[ name ];
|
|
138
|
+
return `${name}_${attribute.itemSize}_${attribute.normalized}`;
|
|
139
|
+
|
|
140
|
+
} )
|
|
141
|
+
.join( '|' );
|
|
142
|
+
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
getGeometryHash( geometry ) {
|
|
146
|
+
|
|
147
|
+
const indexHash = geometry.index
|
|
148
|
+
? this.bufferToHash( geometry.index.array )
|
|
149
|
+
: 'noIndex';
|
|
150
|
+
const positionHash = this.bufferToHash( geometry.attributes.position.array );
|
|
151
|
+
const attributesSignature = this.getAttributesSignature( geometry );
|
|
152
|
+
return `${indexHash}_${positionHash}_${attributesSignature}`;
|
|
153
|
+
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
getBatchKey( materialProps, attributesSignature ) {
|
|
157
|
+
|
|
158
|
+
return `${materialProps}_${attributesSignature}`;
|
|
159
|
+
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
analyzeModel() {
|
|
163
|
+
|
|
164
|
+
const batchGroups = new Map();
|
|
165
|
+
const singleGroups = new Map();
|
|
166
|
+
const uniqueGeometries = new Set();
|
|
167
|
+
|
|
168
|
+
this.scene.updateMatrixWorld( true );
|
|
169
|
+
this.scene.traverse( ( node ) => {
|
|
170
|
+
|
|
171
|
+
if ( ! node.isMesh ) return;
|
|
172
|
+
|
|
173
|
+
const materialProps = this.getMaterialPropertiesHash( node.material );
|
|
174
|
+
const attributesSignature = this.getAttributesSignature( node.geometry );
|
|
175
|
+
const batchKey = this.getBatchKey( materialProps, attributesSignature );
|
|
176
|
+
const geometryHash = this.getGeometryHash( node.geometry );
|
|
177
|
+
uniqueGeometries.add( geometryHash );
|
|
178
|
+
|
|
179
|
+
if ( ! batchGroups.has( batchKey ) ) {
|
|
180
|
+
|
|
181
|
+
batchGroups.set( batchKey, {
|
|
182
|
+
meshes: [],
|
|
183
|
+
geometryStats: new Map(),
|
|
184
|
+
totalInstances: 0,
|
|
185
|
+
materialProps: node.material.clone(),
|
|
186
|
+
} );
|
|
187
|
+
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const group = batchGroups.get( batchKey );
|
|
191
|
+
group.meshes.push( node );
|
|
192
|
+
group.totalInstances ++;
|
|
193
|
+
|
|
194
|
+
if ( ! group.geometryStats.has( geometryHash ) ) {
|
|
195
|
+
|
|
196
|
+
group.geometryStats.set( geometryHash, {
|
|
197
|
+
count: 0,
|
|
198
|
+
vertices: node.geometry.attributes.position.count,
|
|
199
|
+
indices: node.geometry.index ? node.geometry.index.count : 0,
|
|
200
|
+
geometry: node.geometry,
|
|
201
|
+
} );
|
|
202
|
+
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
group.geometryStats.get( geometryHash ).count ++;
|
|
206
|
+
|
|
207
|
+
} );
|
|
208
|
+
|
|
209
|
+
// Move single instance groups to singleGroups
|
|
210
|
+
for ( const [ batchKey, group ] of batchGroups ) {
|
|
211
|
+
|
|
212
|
+
if ( group.totalInstances === 1 ) {
|
|
213
|
+
|
|
214
|
+
singleGroups.set( batchKey, group );
|
|
215
|
+
batchGroups.delete( batchKey );
|
|
216
|
+
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return { batchGroups, singleGroups, uniqueGeometries: uniqueGeometries.size };
|
|
222
|
+
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
createBatchedMeshes( batchGroups ) {
|
|
226
|
+
|
|
227
|
+
const meshesToRemove = new Set();
|
|
228
|
+
|
|
229
|
+
for ( const [ , group ] of batchGroups ) {
|
|
230
|
+
|
|
231
|
+
const maxGeometries = group.totalInstances;
|
|
232
|
+
const maxVertices = Array.from( group.geometryStats.values() ).reduce(
|
|
233
|
+
( sum, stats ) => sum + stats.vertices,
|
|
234
|
+
0
|
|
235
|
+
);
|
|
236
|
+
const maxIndices = Array.from( group.geometryStats.values() ).reduce(
|
|
237
|
+
( sum, stats ) => sum + stats.indices,
|
|
238
|
+
0
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
const batchedMaterial = new group.materialProps.constructor( group.materialProps );
|
|
242
|
+
|
|
243
|
+
if ( batchedMaterial.color !== undefined ) {
|
|
244
|
+
|
|
245
|
+
// Reset color to white, color will be set per instance
|
|
246
|
+
batchedMaterial.color.set( 1, 1, 1 );
|
|
247
|
+
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const batchedMesh = new THREE.BatchedMesh(
|
|
251
|
+
maxGeometries,
|
|
252
|
+
maxVertices,
|
|
253
|
+
maxIndices,
|
|
254
|
+
batchedMaterial
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
const referenceMesh = group.meshes[ 0 ];
|
|
258
|
+
batchedMesh.name = `${referenceMesh.name}_batch`;
|
|
259
|
+
|
|
260
|
+
const geometryIds = new Map();
|
|
261
|
+
const inverseParentMatrix = new THREE.Matrix4();
|
|
262
|
+
|
|
263
|
+
if ( referenceMesh.parent ) {
|
|
264
|
+
|
|
265
|
+
referenceMesh.parent.updateWorldMatrix( true, false );
|
|
266
|
+
inverseParentMatrix.copy( referenceMesh.parent.matrixWorld ).invert();
|
|
267
|
+
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
for ( const mesh of group.meshes ) {
|
|
271
|
+
|
|
272
|
+
const geometryHash = this.getGeometryHash( mesh.geometry );
|
|
273
|
+
|
|
274
|
+
if ( ! geometryIds.has( geometryHash ) ) {
|
|
275
|
+
|
|
276
|
+
geometryIds.set( geometryHash, batchedMesh.addGeometry( mesh.geometry ) );
|
|
277
|
+
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const geometryId = geometryIds.get( geometryHash );
|
|
281
|
+
const instanceId = batchedMesh.addInstance( geometryId );
|
|
282
|
+
|
|
283
|
+
const localMatrix = new THREE.Matrix4();
|
|
284
|
+
mesh.updateWorldMatrix( true, false );
|
|
285
|
+
localMatrix.copy( mesh.matrixWorld );
|
|
286
|
+
if ( referenceMesh.parent ) {
|
|
287
|
+
|
|
288
|
+
localMatrix.premultiply( inverseParentMatrix );
|
|
289
|
+
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
batchedMesh.setMatrixAt( instanceId, localMatrix );
|
|
293
|
+
batchedMesh.setColorAt( instanceId, mesh.material.color );
|
|
294
|
+
|
|
295
|
+
meshesToRemove.add( mesh );
|
|
296
|
+
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if ( referenceMesh.parent ) {
|
|
300
|
+
|
|
301
|
+
referenceMesh.parent.add( batchedMesh );
|
|
302
|
+
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return meshesToRemove;
|
|
308
|
+
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
removeEmptyNodes( object ) {
|
|
312
|
+
|
|
313
|
+
const children = [ ...object.children ];
|
|
314
|
+
|
|
315
|
+
for ( const child of children ) {
|
|
316
|
+
|
|
317
|
+
this.removeEmptyNodes( child );
|
|
318
|
+
|
|
319
|
+
if ( ( child instanceof THREE.Group || child.constructor === THREE.Object3D )
|
|
320
|
+
&& child.children.length === 0 ) {
|
|
321
|
+
|
|
322
|
+
object.remove( child );
|
|
323
|
+
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
disposeMeshes( meshesToRemove ) {
|
|
331
|
+
|
|
332
|
+
meshesToRemove.forEach( ( mesh ) => {
|
|
333
|
+
|
|
334
|
+
if ( mesh.parent ) {
|
|
335
|
+
|
|
336
|
+
mesh.parent.remove( mesh );
|
|
337
|
+
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if ( mesh.geometry ) mesh.geometry.dispose();
|
|
341
|
+
if ( mesh.material ) {
|
|
342
|
+
|
|
343
|
+
if ( Array.isArray( mesh.material ) ) {
|
|
344
|
+
|
|
345
|
+
mesh.material.forEach( ( m ) => m.dispose() );
|
|
346
|
+
|
|
347
|
+
} else {
|
|
348
|
+
|
|
349
|
+
mesh.material.dispose();
|
|
350
|
+
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
} );
|
|
356
|
+
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
logDebugInfo( stats ) {
|
|
360
|
+
|
|
361
|
+
console.group( 'Scene Optimization Results' );
|
|
362
|
+
console.log( `Original meshes: ${stats.originalMeshes}` );
|
|
363
|
+
console.log( `Batched into: ${stats.batchedMeshes} BatchedMesh` );
|
|
364
|
+
console.log( `Single meshes: ${stats.singleMeshes} Mesh` );
|
|
365
|
+
console.log( `Total draw calls: ${stats.drawCalls}` );
|
|
366
|
+
console.log( `Reduction Ratio: ${stats.reductionRatio}% fewer draw calls` );
|
|
367
|
+
console.groupEnd();
|
|
368
|
+
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
toBatchedMesh() {
|
|
372
|
+
|
|
373
|
+
const { batchGroups, singleGroups, uniqueGeometries } = this.analyzeModel();
|
|
374
|
+
const meshesToRemove = this.createBatchedMeshes( batchGroups );
|
|
375
|
+
|
|
376
|
+
this.disposeMeshes( meshesToRemove );
|
|
377
|
+
this.removeEmptyNodes( this.scene );
|
|
378
|
+
|
|
379
|
+
if ( this.debug ) {
|
|
380
|
+
|
|
381
|
+
const totalOriginalMeshes = meshesToRemove.size + singleGroups.size;
|
|
382
|
+
const totalFinalMeshes = batchGroups.size + singleGroups.size;
|
|
383
|
+
|
|
384
|
+
const stats = {
|
|
385
|
+
originalMeshes: totalOriginalMeshes,
|
|
386
|
+
batchedMeshes: batchGroups.size,
|
|
387
|
+
singleMeshes: singleGroups.size,
|
|
388
|
+
drawCalls: totalFinalMeshes,
|
|
389
|
+
uniqueGeometries: uniqueGeometries,
|
|
390
|
+
reductionRatio: ( ( 1 - totalFinalMeshes / totalOriginalMeshes ) * 100 ).toFixed( 1 ),
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
this.logDebugInfo( stats );
|
|
394
|
+
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
return this.scene;
|
|
398
|
+
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// Placeholder for future implementation
|
|
402
|
+
toInstancingMesh() {
|
|
403
|
+
|
|
404
|
+
throw new Error( 'InstancedMesh optimization not implemented yet' );
|
|
405
|
+
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export { SceneOptimizer };
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
* tool for "unwrapping" and debugging three.js geometries UV mapping
|
|
7
7
|
*
|
|
8
8
|
* Sample usage:
|
|
9
|
-
* document.body.appendChild( UVsDebug( new THREE.SphereGeometry( 10, 10, 10, 10 ) );
|
|
9
|
+
* document.body.appendChild( UVsDebug( new THREE.SphereGeometry( 10, 10, 10, 10 ) ) );
|
|
10
10
|
*
|
|
11
11
|
*/
|
|
12
12
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "super-three",
|
|
3
|
-
"version": "0.170.
|
|
3
|
+
"version": "0.170.1",
|
|
4
4
|
"description": "JavaScript 3D library",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./build/three.cjs",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"./addons/*": "./examples/jsm/*",
|
|
17
17
|
"./src/*": "./src/*",
|
|
18
18
|
"./webgpu": "./build/three.webgpu.js",
|
|
19
|
-
"./tsl": "./build/three.
|
|
19
|
+
"./tsl": "./build/three.tsl.js"
|
|
20
20
|
},
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"eslint-plugin-html": "^8.0.0",
|
|
102
102
|
"eslint-plugin-import": "^2.27.5",
|
|
103
103
|
"failonlyreporter": "^1.0.0",
|
|
104
|
-
"jimp": "^
|
|
104
|
+
"jimp": "^1.6.0",
|
|
105
105
|
"magic-string": "^0.30.0",
|
|
106
106
|
"pixelmatch": "^6.0.0",
|
|
107
107
|
"puppeteer": "^22.0.0",
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { REVISION } from './constants.js';
|
|
2
|
+
|
|
3
|
+
export { WebGLArrayRenderTarget } from './renderers/WebGLArrayRenderTarget.js';
|
|
4
|
+
export { WebGL3DRenderTarget } from './renderers/WebGL3DRenderTarget.js';
|
|
5
|
+
export { WebGLCubeRenderTarget } from './renderers/WebGLCubeRenderTarget.js';
|
|
6
|
+
export { WebGLRenderTarget } from './renderers/WebGLRenderTarget.js';
|
|
7
|
+
export { FogExp2 } from './scenes/FogExp2.js';
|
|
8
|
+
export { Fog } from './scenes/Fog.js';
|
|
9
|
+
export { Scene } from './scenes/Scene.js';
|
|
10
|
+
export { Sprite } from './objects/Sprite.js';
|
|
11
|
+
export { LOD } from './objects/LOD.js';
|
|
12
|
+
export { SkinnedMesh } from './objects/SkinnedMesh.js';
|
|
13
|
+
export { Skeleton } from './objects/Skeleton.js';
|
|
14
|
+
export { Bone } from './objects/Bone.js';
|
|
15
|
+
export { Mesh } from './objects/Mesh.js';
|
|
16
|
+
export { InstancedMesh } from './objects/InstancedMesh.js';
|
|
17
|
+
export { BatchedMesh } from './objects/BatchedMesh.js';
|
|
18
|
+
export { LineSegments } from './objects/LineSegments.js';
|
|
19
|
+
export { LineLoop } from './objects/LineLoop.js';
|
|
20
|
+
export { Line } from './objects/Line.js';
|
|
21
|
+
export { Points } from './objects/Points.js';
|
|
22
|
+
export { Group } from './objects/Group.js';
|
|
23
|
+
export { VideoTexture } from './textures/VideoTexture.js';
|
|
24
|
+
export { FramebufferTexture } from './textures/FramebufferTexture.js';
|
|
25
|
+
export { Source } from './textures/Source.js';
|
|
26
|
+
export { DataTexture } from './textures/DataTexture.js';
|
|
27
|
+
export { DataArrayTexture } from './textures/DataArrayTexture.js';
|
|
28
|
+
export { Data3DTexture } from './textures/Data3DTexture.js';
|
|
29
|
+
export { CompressedTexture } from './textures/CompressedTexture.js';
|
|
30
|
+
export { CompressedArrayTexture } from './textures/CompressedArrayTexture.js';
|
|
31
|
+
export { CompressedCubeTexture } from './textures/CompressedCubeTexture.js';
|
|
32
|
+
export { CubeTexture } from './textures/CubeTexture.js';
|
|
33
|
+
export { CanvasTexture } from './textures/CanvasTexture.js';
|
|
34
|
+
export { DepthTexture } from './textures/DepthTexture.js';
|
|
35
|
+
export { Texture } from './textures/Texture.js';
|
|
36
|
+
export * from './geometries/Geometries.js';
|
|
37
|
+
export * from './materials/Materials.js';
|
|
38
|
+
export { AnimationLoader } from './loaders/AnimationLoader.js';
|
|
39
|
+
export { CompressedTextureLoader } from './loaders/CompressedTextureLoader.js';
|
|
40
|
+
export { CubeTextureLoader } from './loaders/CubeTextureLoader.js';
|
|
41
|
+
export { DataTextureLoader } from './loaders/DataTextureLoader.js';
|
|
42
|
+
export { TextureLoader } from './loaders/TextureLoader.js';
|
|
43
|
+
export { ObjectLoader } from './loaders/ObjectLoader.js';
|
|
44
|
+
export { MaterialLoader } from './loaders/MaterialLoader.js';
|
|
45
|
+
export { BufferGeometryLoader } from './loaders/BufferGeometryLoader.js';
|
|
46
|
+
export { DefaultLoadingManager, LoadingManager } from './loaders/LoadingManager.js';
|
|
47
|
+
export { ImageLoader } from './loaders/ImageLoader.js';
|
|
48
|
+
export { ImageBitmapLoader } from './loaders/ImageBitmapLoader.js';
|
|
49
|
+
export { FileLoader } from './loaders/FileLoader.js';
|
|
50
|
+
export { Loader } from './loaders/Loader.js';
|
|
51
|
+
export { LoaderUtils } from './loaders/LoaderUtils.js';
|
|
52
|
+
export { Cache } from './loaders/Cache.js';
|
|
53
|
+
export { AudioLoader } from './loaders/AudioLoader.js';
|
|
54
|
+
export { SpotLight } from './lights/SpotLight.js';
|
|
55
|
+
export { PointLight } from './lights/PointLight.js';
|
|
56
|
+
export { RectAreaLight } from './lights/RectAreaLight.js';
|
|
57
|
+
export { HemisphereLight } from './lights/HemisphereLight.js';
|
|
58
|
+
export { DirectionalLight } from './lights/DirectionalLight.js';
|
|
59
|
+
export { AmbientLight } from './lights/AmbientLight.js';
|
|
60
|
+
export { Light } from './lights/Light.js';
|
|
61
|
+
export { LightProbe } from './lights/LightProbe.js';
|
|
62
|
+
export { StereoCamera } from './cameras/StereoCamera.js';
|
|
63
|
+
export { PerspectiveCamera } from './cameras/PerspectiveCamera.js';
|
|
64
|
+
export { OrthographicCamera } from './cameras/OrthographicCamera.js';
|
|
65
|
+
export { CubeCamera } from './cameras/CubeCamera.js';
|
|
66
|
+
export { ArrayCamera } from './cameras/ArrayCamera.js';
|
|
67
|
+
export { Camera } from './cameras/Camera.js';
|
|
68
|
+
export { AudioListener } from './audio/AudioListener.js';
|
|
69
|
+
export { PositionalAudio } from './audio/PositionalAudio.js';
|
|
70
|
+
export { AudioContext } from './audio/AudioContext.js';
|
|
71
|
+
export { AudioAnalyser } from './audio/AudioAnalyser.js';
|
|
72
|
+
export { Audio } from './audio/Audio.js';
|
|
73
|
+
export { VectorKeyframeTrack } from './animation/tracks/VectorKeyframeTrack.js';
|
|
74
|
+
export { StringKeyframeTrack } from './animation/tracks/StringKeyframeTrack.js';
|
|
75
|
+
export { QuaternionKeyframeTrack } from './animation/tracks/QuaternionKeyframeTrack.js';
|
|
76
|
+
export { NumberKeyframeTrack } from './animation/tracks/NumberKeyframeTrack.js';
|
|
77
|
+
export { ColorKeyframeTrack } from './animation/tracks/ColorKeyframeTrack.js';
|
|
78
|
+
export { BooleanKeyframeTrack } from './animation/tracks/BooleanKeyframeTrack.js';
|
|
79
|
+
export { PropertyMixer } from './animation/PropertyMixer.js';
|
|
80
|
+
export { PropertyBinding } from './animation/PropertyBinding.js';
|
|
81
|
+
export { KeyframeTrack } from './animation/KeyframeTrack.js';
|
|
82
|
+
export { AnimationUtils } from './animation/AnimationUtils.js';
|
|
83
|
+
export { AnimationObjectGroup } from './animation/AnimationObjectGroup.js';
|
|
84
|
+
export { AnimationMixer } from './animation/AnimationMixer.js';
|
|
85
|
+
export { AnimationClip } from './animation/AnimationClip.js';
|
|
86
|
+
export { AnimationAction } from './animation/AnimationAction.js';
|
|
87
|
+
export { RenderTarget } from './core/RenderTarget.js';
|
|
88
|
+
export { Uniform } from './core/Uniform.js';
|
|
89
|
+
export { UniformsGroup } from './core/UniformsGroup.js';
|
|
90
|
+
export { InstancedBufferGeometry } from './core/InstancedBufferGeometry.js';
|
|
91
|
+
export { BufferGeometry } from './core/BufferGeometry.js';
|
|
92
|
+
export { InterleavedBufferAttribute } from './core/InterleavedBufferAttribute.js';
|
|
93
|
+
export { InstancedInterleavedBuffer } from './core/InstancedInterleavedBuffer.js';
|
|
94
|
+
export { InterleavedBuffer } from './core/InterleavedBuffer.js';
|
|
95
|
+
export { InstancedBufferAttribute } from './core/InstancedBufferAttribute.js';
|
|
96
|
+
export { GLBufferAttribute } from './core/GLBufferAttribute.js';
|
|
97
|
+
export * from './core/BufferAttribute.js';
|
|
98
|
+
export { Object3D } from './core/Object3D.js';
|
|
99
|
+
export { Raycaster } from './core/Raycaster.js';
|
|
100
|
+
export { Layers } from './core/Layers.js';
|
|
101
|
+
export { EventDispatcher } from './core/EventDispatcher.js';
|
|
102
|
+
export { Clock } from './core/Clock.js';
|
|
103
|
+
export { QuaternionLinearInterpolant } from './math/interpolants/QuaternionLinearInterpolant.js';
|
|
104
|
+
export { LinearInterpolant } from './math/interpolants/LinearInterpolant.js';
|
|
105
|
+
export { DiscreteInterpolant } from './math/interpolants/DiscreteInterpolant.js';
|
|
106
|
+
export { CubicInterpolant } from './math/interpolants/CubicInterpolant.js';
|
|
107
|
+
export { Interpolant } from './math/Interpolant.js';
|
|
108
|
+
export { Triangle } from './math/Triangle.js';
|
|
109
|
+
export { MathUtils } from './math/MathUtils.js';
|
|
110
|
+
export { Spherical } from './math/Spherical.js';
|
|
111
|
+
export { Cylindrical } from './math/Cylindrical.js';
|
|
112
|
+
export { Plane } from './math/Plane.js';
|
|
113
|
+
export { Frustum } from './math/Frustum.js';
|
|
114
|
+
export { Sphere } from './math/Sphere.js';
|
|
115
|
+
export { Ray } from './math/Ray.js';
|
|
116
|
+
export { Matrix4 } from './math/Matrix4.js';
|
|
117
|
+
export { Matrix3 } from './math/Matrix3.js';
|
|
118
|
+
export { Matrix2 } from './math/Matrix2.js';
|
|
119
|
+
export { Box3 } from './math/Box3.js';
|
|
120
|
+
export { Box2 } from './math/Box2.js';
|
|
121
|
+
export { Line3 } from './math/Line3.js';
|
|
122
|
+
export { Euler } from './math/Euler.js';
|
|
123
|
+
export { Vector4 } from './math/Vector4.js';
|
|
124
|
+
export { Vector3 } from './math/Vector3.js';
|
|
125
|
+
export { Vector2 } from './math/Vector2.js';
|
|
126
|
+
export { Quaternion } from './math/Quaternion.js';
|
|
127
|
+
export { Color } from './math/Color.js';
|
|
128
|
+
export { ColorManagement } from './math/ColorManagement.js';
|
|
129
|
+
export { SphericalHarmonics3 } from './math/SphericalHarmonics3.js';
|
|
130
|
+
export { SpotLightHelper } from './helpers/SpotLightHelper.js';
|
|
131
|
+
export { SkeletonHelper } from './helpers/SkeletonHelper.js';
|
|
132
|
+
export { PointLightHelper } from './helpers/PointLightHelper.js';
|
|
133
|
+
export { HemisphereLightHelper } from './helpers/HemisphereLightHelper.js';
|
|
134
|
+
export { GridHelper } from './helpers/GridHelper.js';
|
|
135
|
+
export { PolarGridHelper } from './helpers/PolarGridHelper.js';
|
|
136
|
+
export { DirectionalLightHelper } from './helpers/DirectionalLightHelper.js';
|
|
137
|
+
export { CameraHelper } from './helpers/CameraHelper.js';
|
|
138
|
+
export { BoxHelper } from './helpers/BoxHelper.js';
|
|
139
|
+
export { Box3Helper } from './helpers/Box3Helper.js';
|
|
140
|
+
export { PlaneHelper } from './helpers/PlaneHelper.js';
|
|
141
|
+
export { ArrowHelper } from './helpers/ArrowHelper.js';
|
|
142
|
+
export { AxesHelper } from './helpers/AxesHelper.js';
|
|
143
|
+
export * from './extras/curves/Curves.js';
|
|
144
|
+
export { Shape } from './extras/core/Shape.js';
|
|
145
|
+
export { Path } from './extras/core/Path.js';
|
|
146
|
+
export { ShapePath } from './extras/core/ShapePath.js';
|
|
147
|
+
export { CurvePath } from './extras/core/CurvePath.js';
|
|
148
|
+
export { Curve } from './extras/core/Curve.js';
|
|
149
|
+
export { Controls } from './extras/Controls.js';
|
|
150
|
+
export { DataUtils } from './extras/DataUtils.js';
|
|
151
|
+
export { ImageUtils } from './extras/ImageUtils.js';
|
|
152
|
+
export { ShapeUtils } from './extras/ShapeUtils.js';
|
|
153
|
+
export { TextureUtils } from './extras/TextureUtils.js';
|
|
154
|
+
export { createCanvasElement } from './utils.js';
|
|
155
|
+
export * from './constants.js';
|
|
156
|
+
export * from './Three.Legacy.js';
|
|
157
|
+
|
|
158
|
+
if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
|
|
159
|
+
|
|
160
|
+
__THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'register', { detail: {
|
|
161
|
+
revision: REVISION,
|
|
162
|
+
} } ) );
|
|
163
|
+
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if ( typeof window !== 'undefined' ) {
|
|
167
|
+
|
|
168
|
+
if ( window.__THREE__ ) {
|
|
169
|
+
|
|
170
|
+
console.warn( 'WARNING: Multiple instances of Three.js being imported.' );
|
|
171
|
+
|
|
172
|
+
} else {
|
|
173
|
+
|
|
174
|
+
window.__THREE__ = REVISION;
|
|
175
|
+
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
}
|