super-three 0.163.0 → 0.165.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.
- package/README.md +3 -3
- package/build/three.cjs +1127 -452
- package/build/three.module.js +1127 -452
- package/build/three.module.min.js +2 -2
- package/examples/jsm/animation/CCDIKSolver.js +4 -2
- package/examples/jsm/controls/TransformControls.js +1 -1
- package/examples/jsm/environments/RoomEnvironment.js +1 -5
- package/examples/jsm/exporters/GLTFExporter.js +45 -1
- package/examples/jsm/exporters/USDZExporter.js +13 -5
- package/examples/jsm/helpers/ViewHelper.js +32 -67
- package/examples/jsm/libs/draco/README.md +2 -2
- package/examples/jsm/libs/tween.module.js +75 -64
- package/examples/jsm/lines/LineMaterial.js +1 -15
- package/examples/jsm/lines/LineSegments2.js +15 -0
- package/examples/jsm/lines/Wireframe.js +16 -1
- package/examples/jsm/loaders/DRACOLoader.js +1 -1
- package/examples/jsm/loaders/EXRLoader.js +283 -99
- package/examples/jsm/loaders/FBXLoader.js +24 -13
- package/examples/jsm/loaders/GLTFLoader.js +55 -0
- package/examples/jsm/loaders/KTX2Loader.js +3 -6
- package/examples/jsm/loaders/LDrawLoader.js +3 -2
- package/examples/jsm/loaders/MMDLoader.js +31 -12
- package/examples/jsm/loaders/VRMLLoader.js +1 -1
- package/examples/jsm/loaders/lwo/IFFParser.js +8 -5
- package/examples/jsm/materials/MeshGouraudMaterial.js +7 -1
- package/examples/jsm/math/Octree.js +26 -20
- package/examples/jsm/modifiers/CurveModifier.js +11 -9
- package/examples/jsm/nodes/Nodes.js +15 -13
- package/examples/jsm/nodes/accessors/AccessorsUtils.js +16 -1
- package/examples/jsm/nodes/accessors/BitangentNode.js +7 -83
- package/examples/jsm/nodes/accessors/BufferNode.js +6 -0
- package/examples/jsm/nodes/accessors/CameraNode.js +12 -119
- package/examples/jsm/nodes/accessors/ClippingNode.js +3 -2
- package/examples/jsm/nodes/accessors/MaterialNode.js +109 -3
- package/examples/jsm/nodes/accessors/ModelNode.js +3 -0
- package/examples/jsm/nodes/accessors/NormalNode.js +9 -101
- package/examples/jsm/nodes/accessors/PositionNode.js +6 -100
- package/examples/jsm/nodes/accessors/ReferenceNode.js +6 -0
- package/examples/jsm/nodes/accessors/ReflectVectorNode.js +2 -31
- package/examples/jsm/nodes/accessors/StorageBufferNode.js +9 -0
- package/examples/jsm/nodes/accessors/{TextureStoreNode.js → StorageTextureNode.js} +19 -6
- package/examples/jsm/nodes/accessors/TangentNode.js +11 -97
- package/examples/jsm/nodes/accessors/Texture3DNode.js +100 -0
- package/examples/jsm/nodes/accessors/TextureNode.js +21 -3
- package/examples/jsm/nodes/accessors/TextureSizeNode.js +1 -1
- package/examples/jsm/nodes/accessors/UVNode.js +2 -46
- package/examples/jsm/nodes/code/FunctionNode.js +0 -8
- package/examples/jsm/nodes/core/AttributeNode.js +15 -3
- package/examples/jsm/nodes/core/ContextNode.js +6 -0
- package/examples/jsm/nodes/core/Node.js +23 -2
- package/examples/jsm/nodes/core/NodeBuilder.js +25 -18
- package/examples/jsm/nodes/core/NodeKeywords.js +1 -1
- package/examples/jsm/nodes/core/OutputStructNode.js +3 -6
- package/examples/jsm/nodes/core/PropertyNode.js +11 -0
- package/examples/jsm/nodes/core/VaryingNode.js +40 -9
- package/examples/jsm/nodes/display/AfterImageNode.js +14 -2
- package/examples/jsm/nodes/display/BumpMapNode.js +7 -26
- package/examples/jsm/nodes/display/FrontFacingNode.js +13 -0
- package/examples/jsm/nodes/display/PassNode.js +3 -1
- package/examples/jsm/nodes/display/ViewportDepthNode.js +1 -1
- package/examples/jsm/nodes/display/ViewportNode.js +5 -3
- package/examples/jsm/nodes/display/ViewportTextureNode.js +4 -1
- package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +26 -7
- package/examples/jsm/nodes/functions/BSDF/D_GGX_Anisotropic.js +28 -0
- package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +1 -3
- package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +29 -0
- package/examples/jsm/nodes/functions/PhongLightingModel.js +1 -1
- package/examples/jsm/nodes/functions/PhysicalLightingModel.js +210 -12
- package/examples/jsm/nodes/functions/ShadowMaskModel.js +31 -0
- package/examples/jsm/nodes/functions/ToonLightingModel.js +49 -0
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +20 -5
- package/examples/jsm/nodes/lighting/DirectionalLightNode.js +2 -1
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +11 -2
- package/examples/jsm/nodes/lighting/IrradianceNode.js +24 -0
- package/examples/jsm/nodes/lighting/LightsNode.js +28 -1
- package/examples/jsm/nodes/lighting/PointLightNode.js +2 -1
- package/examples/jsm/nodes/lighting/SpotLightNode.js +2 -1
- package/examples/jsm/nodes/materials/Line2NodeMaterial.js +11 -7
- package/examples/jsm/nodes/materials/Materials.js +4 -0
- package/examples/jsm/nodes/materials/MeshMatcapNodeMaterial.js +52 -0
- package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +0 -2
- package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +2 -2
- package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +94 -6
- package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +11 -4
- package/examples/jsm/nodes/materials/MeshToonNodeMaterial.js +34 -0
- package/examples/jsm/nodes/materials/NodeMaterial.js +43 -45
- package/examples/jsm/nodes/materials/ShadowNodeMaterial.js +34 -0
- package/examples/jsm/nodes/materials/VolumeNodeMaterial.js +106 -0
- package/examples/jsm/nodes/math/HashNode.js +2 -2
- package/examples/jsm/nodes/pmrem/PMREMUtils.js +1 -1
- package/examples/jsm/nodes/shadernode/ShaderNode.js +57 -41
- package/examples/jsm/nodes/utils/ArrayElementNode.js +1 -1
- package/examples/jsm/nodes/utils/MatcapUVNode.js +1 -1
- package/examples/jsm/nodes/utils/TimerNode.js +1 -1
- package/examples/jsm/objects/Lensflare.js +2 -2
- package/examples/jsm/physics/JoltPhysics.js +281 -0
- package/examples/jsm/postprocessing/RenderPass.js +1 -1
- package/examples/jsm/postprocessing/RenderTransitionPass.js +193 -0
- package/examples/jsm/renderers/CSS2DRenderer.js +25 -5
- package/examples/jsm/renderers/CSS3DRenderer.js +24 -3
- package/examples/jsm/renderers/common/Attributes.js +2 -0
- package/examples/jsm/renderers/common/Background.js +3 -3
- package/examples/jsm/renderers/common/Bindings.js +17 -0
- package/examples/jsm/renderers/common/ChainMap.js +18 -48
- package/examples/jsm/renderers/common/ClippingContext.js +5 -5
- package/examples/jsm/renderers/common/Pipelines.js +2 -2
- package/examples/jsm/renderers/common/RenderBundle.js +18 -0
- package/examples/jsm/renderers/common/RenderBundles.js +38 -0
- package/examples/jsm/renderers/common/RenderList.js +10 -1
- package/examples/jsm/renderers/common/RenderObject.js +49 -1
- package/examples/jsm/renderers/common/Renderer.js +268 -25
- package/examples/jsm/renderers/common/Textures.js +1 -1
- package/examples/jsm/renderers/common/Uniform.js +1 -1
- package/examples/jsm/renderers/common/extras/PMREMGenerator.js +13 -17
- package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +18 -4
- package/examples/jsm/renderers/common/nodes/NodeSampler.js +6 -0
- package/examples/jsm/renderers/common/nodes/Nodes.js +31 -47
- package/examples/jsm/renderers/webgl/WebGLBackend.js +7 -21
- package/examples/jsm/renderers/webgl/WebGLBufferRenderer.js +5 -1
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +23 -5
- package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +114 -13
- package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +3 -21
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +80 -46
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +85 -12
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +4 -1
- package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +10 -1
- package/examples/jsm/renderers/webgpu/utils/WebGPUConstants.js +6 -0
- package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +62 -19
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +62 -3
- package/examples/jsm/transpiler/GLSLDecoder.js +1 -1
- package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
- package/examples/jsm/utils/BufferGeometryUtils.js +18 -16
- package/examples/jsm/utils/GPUStatsPanel.js +2 -0
- package/examples/jsm/utils/SceneUtils.js +60 -1
- package/examples/jsm/utils/SortUtils.js +8 -5
- package/examples/jsm/webxr/OculusHandModel.js +3 -2
- package/examples/jsm/webxr/XRHandModelFactory.js +4 -2
- package/package.json +3 -2
- package/src/animation/tracks/BooleanKeyframeTrack.js +10 -1
- package/src/animation/tracks/QuaternionKeyframeTrack.js +1 -2
- package/src/animation/tracks/StringKeyframeTrack.js +10 -1
- package/src/constants.js +1 -1
- package/src/core/Object3D.js +2 -0
- package/src/core/Raycaster.js +6 -2
- package/src/core/RenderTarget.js +8 -0
- package/src/extras/PMREMGenerator.js +12 -11
- package/src/loaders/FileLoader.js +5 -1
- package/src/loaders/LoaderUtils.js +3 -1
- package/src/loaders/MaterialLoader.js +1 -0
- package/src/loaders/ObjectLoader.js +1 -0
- package/src/materials/Material.js +2 -0
- package/src/materials/MeshPhysicalMaterial.js +20 -0
- package/src/objects/BatchedMesh.js +114 -1
- package/src/objects/Line.js +66 -43
- package/src/renderers/WebGLRenderer.js +371 -109
- package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +15 -0
- package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +9 -1
- package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +8 -22
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +1 -0
- package/src/renderers/shaders/ShaderChunk/morphcolor_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/morphinstance_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl.js +3 -14
- package/src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl.js +10 -31
- package/src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl.js +3 -23
- package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +17 -9
- package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +47 -13
- package/src/renderers/shaders/ShaderChunk.js +0 -2
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -0
- package/src/renderers/shaders/ShaderLib.js +1 -0
- package/src/renderers/webgl/WebGLBackground.js +24 -3
- package/src/renderers/webgl/WebGLBufferRenderer.js +36 -0
- package/src/renderers/webgl/WebGLCapabilities.js +33 -1
- package/src/renderers/webgl/WebGLExtensions.js +3 -1
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +36 -0
- package/src/renderers/webgl/WebGLLights.js +9 -12
- package/src/renderers/webgl/WebGLMaterials.js +7 -5
- package/src/renderers/webgl/WebGLMorphtargets.js +1 -2
- package/src/renderers/webgl/WebGLProgram.js +5 -36
- package/src/renderers/webgl/WebGLPrograms.js +19 -14
- package/src/renderers/webgl/WebGLRenderStates.js +8 -4
- package/src/renderers/webgl/WebGLShadowMap.js +25 -25
- package/src/renderers/webgl/WebGLTextures.js +206 -129
- package/src/renderers/webgl/WebGLUtils.js +3 -21
- package/src/renderers/webxr/WebXRDepthSensing.js +3 -3
- package/src/renderers/webxr/WebXRManager.js +8 -6
- package/src/textures/CompressedArrayTexture.js +14 -0
- package/src/textures/DataArrayTexture.js +14 -0
- package/src/textures/DepthTexture.js +1 -3
- package/src/utils.js +30 -1
- package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +0 -318
- package/examples/jsm/renderers/webgl-legacy/nodes/SlotNode.js +0 -26
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +0 -792
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js +0 -51
- package/src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl.js +0 -10
|
@@ -5,10 +5,12 @@ import { FloatType } from '../constants.js';
|
|
|
5
5
|
import { Matrix4 } from '../math/Matrix4.js';
|
|
6
6
|
import { Mesh } from './Mesh.js';
|
|
7
7
|
import { RGBAFormat } from '../constants.js';
|
|
8
|
+
import { ColorManagement } from '../math/ColorManagement.js';
|
|
8
9
|
import { Box3 } from '../math/Box3.js';
|
|
9
10
|
import { Sphere } from '../math/Sphere.js';
|
|
10
11
|
import { Frustum } from '../math/Frustum.js';
|
|
11
12
|
import { Vector3 } from '../math/Vector3.js';
|
|
13
|
+
import { Color } from '../math/Color.js';
|
|
12
14
|
|
|
13
15
|
function sortOpaque( a, b ) {
|
|
14
16
|
|
|
@@ -71,11 +73,14 @@ const ID_ATTR_NAME = 'batchId';
|
|
|
71
73
|
const _matrix = /*@__PURE__*/ new Matrix4();
|
|
72
74
|
const _invMatrixWorld = /*@__PURE__*/ new Matrix4();
|
|
73
75
|
const _identityMatrix = /*@__PURE__*/ new Matrix4();
|
|
76
|
+
const _whiteColor = /*@__PURE__*/ new Color( 1, 1, 1 );
|
|
74
77
|
const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
|
|
75
78
|
const _frustum = /*@__PURE__*/ new Frustum();
|
|
76
79
|
const _box = /*@__PURE__*/ new Box3();
|
|
77
80
|
const _sphere = /*@__PURE__*/ new Sphere();
|
|
78
81
|
const _vector = /*@__PURE__*/ new Vector3();
|
|
82
|
+
const _forward = /*@__PURE__*/ new Vector3();
|
|
83
|
+
const _temp = /*@__PURE__*/ new Vector3();
|
|
79
84
|
const _renderList = /*@__PURE__*/ new MultiDrawRenderList();
|
|
80
85
|
const _mesh = /*@__PURE__*/ new Mesh();
|
|
81
86
|
const _batchIntersects = [];
|
|
@@ -152,6 +157,7 @@ class BatchedMesh extends Mesh {
|
|
|
152
157
|
this._multiDrawCounts = new Int32Array( maxGeometryCount );
|
|
153
158
|
this._multiDrawStarts = new Int32Array( maxGeometryCount );
|
|
154
159
|
this._multiDrawCount = 0;
|
|
160
|
+
this._multiDrawInstances = null;
|
|
155
161
|
this._visibilityChanged = true;
|
|
156
162
|
|
|
157
163
|
// Local matrix per geometry by using data texture
|
|
@@ -159,6 +165,9 @@ class BatchedMesh extends Mesh {
|
|
|
159
165
|
|
|
160
166
|
this._initMatricesTexture();
|
|
161
167
|
|
|
168
|
+
// Local color per geometry by using data texture
|
|
169
|
+
this._colorsTexture = null;
|
|
170
|
+
|
|
162
171
|
}
|
|
163
172
|
|
|
164
173
|
_initMatricesTexture() {
|
|
@@ -181,6 +190,20 @@ class BatchedMesh extends Mesh {
|
|
|
181
190
|
|
|
182
191
|
}
|
|
183
192
|
|
|
193
|
+
_initColorsTexture() {
|
|
194
|
+
|
|
195
|
+
let size = Math.sqrt( this._maxGeometryCount );
|
|
196
|
+
size = Math.ceil( size );
|
|
197
|
+
|
|
198
|
+
// 4 floats per RGBA pixel initialized to white
|
|
199
|
+
const colorsArray = new Float32Array( size * size * 4 ).fill( 1 );
|
|
200
|
+
const colorsTexture = new DataTexture( colorsArray, size, size, RGBAFormat, FloatType );
|
|
201
|
+
colorsTexture.colorSpace = ColorManagement.workingColorSpace;
|
|
202
|
+
|
|
203
|
+
this._colorsTexture = colorsTexture;
|
|
204
|
+
|
|
205
|
+
}
|
|
206
|
+
|
|
184
207
|
_initializeGeometry( reference ) {
|
|
185
208
|
|
|
186
209
|
const geometry = this.geometry;
|
|
@@ -414,6 +437,7 @@ class BatchedMesh extends Mesh {
|
|
|
414
437
|
const active = this._active;
|
|
415
438
|
const matricesTexture = this._matricesTexture;
|
|
416
439
|
const matricesArray = this._matricesTexture.image.data;
|
|
440
|
+
const colorsTexture = this._colorsTexture;
|
|
417
441
|
|
|
418
442
|
// push new visibility states
|
|
419
443
|
visibility.push( true );
|
|
@@ -427,6 +451,14 @@ class BatchedMesh extends Mesh {
|
|
|
427
451
|
_identityMatrix.toArray( matricesArray, geometryId * 16 );
|
|
428
452
|
matricesTexture.needsUpdate = true;
|
|
429
453
|
|
|
454
|
+
// initialize the color to white
|
|
455
|
+
if ( colorsTexture !== null ) {
|
|
456
|
+
|
|
457
|
+
_whiteColor.toArray( colorsTexture.image.data, geometryId * 4 );
|
|
458
|
+
colorsTexture.needsUpdate = true;
|
|
459
|
+
|
|
460
|
+
}
|
|
461
|
+
|
|
430
462
|
// add the reserved range and draw range objects
|
|
431
463
|
reservedRanges.push( reservedRange );
|
|
432
464
|
drawRanges.push( {
|
|
@@ -593,6 +625,28 @@ class BatchedMesh extends Mesh {
|
|
|
593
625
|
|
|
594
626
|
}
|
|
595
627
|
|
|
628
|
+
getInstanceCountAt( id ) {
|
|
629
|
+
|
|
630
|
+
if ( this._multiDrawInstances === null ) return null;
|
|
631
|
+
|
|
632
|
+
return this._multiDrawInstances[ id ];
|
|
633
|
+
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
setInstanceCountAt( id, instanceCount ) {
|
|
637
|
+
|
|
638
|
+
if ( this._multiDrawInstances === null ) {
|
|
639
|
+
|
|
640
|
+
this._multiDrawInstances = new Int32Array( this._maxGeometryCount ).fill( 1 );
|
|
641
|
+
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
this._multiDrawInstances[ id ] = instanceCount;
|
|
645
|
+
|
|
646
|
+
return id;
|
|
647
|
+
|
|
648
|
+
}
|
|
649
|
+
|
|
596
650
|
// get bounding box and compute it if it doesn't exist
|
|
597
651
|
getBoundingBoxAt( id, target ) {
|
|
598
652
|
|
|
@@ -723,6 +777,49 @@ class BatchedMesh extends Mesh {
|
|
|
723
777
|
|
|
724
778
|
}
|
|
725
779
|
|
|
780
|
+
setColorAt( geometryId, color ) {
|
|
781
|
+
|
|
782
|
+
if ( this._colorsTexture === null ) {
|
|
783
|
+
|
|
784
|
+
this._initColorsTexture();
|
|
785
|
+
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
// @TODO: Map geometryId to index of the arrays because
|
|
789
|
+
// optimize() can make geometryId mismatch the index
|
|
790
|
+
|
|
791
|
+
const active = this._active;
|
|
792
|
+
const colorsTexture = this._colorsTexture;
|
|
793
|
+
const colorsArray = this._colorsTexture.image.data;
|
|
794
|
+
const geometryCount = this._geometryCount;
|
|
795
|
+
if ( geometryId >= geometryCount || active[ geometryId ] === false ) {
|
|
796
|
+
|
|
797
|
+
return this;
|
|
798
|
+
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
color.toArray( colorsArray, geometryId * 4 );
|
|
802
|
+
colorsTexture.needsUpdate = true;
|
|
803
|
+
|
|
804
|
+
return this;
|
|
805
|
+
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
getColorAt( geometryId, color ) {
|
|
809
|
+
|
|
810
|
+
const active = this._active;
|
|
811
|
+
const colorsArray = this._colorsTexture.image.data;
|
|
812
|
+
const geometryCount = this._geometryCount;
|
|
813
|
+
if ( geometryId >= geometryCount || active[ geometryId ] === false ) {
|
|
814
|
+
|
|
815
|
+
return null;
|
|
816
|
+
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
return color.fromArray( colorsArray, geometryId * 4 );
|
|
820
|
+
|
|
821
|
+
}
|
|
822
|
+
|
|
726
823
|
setVisibleAt( geometryId, value ) {
|
|
727
824
|
|
|
728
825
|
const visibility = this._visibility;
|
|
@@ -863,6 +960,13 @@ class BatchedMesh extends Mesh {
|
|
|
863
960
|
this._matricesTexture = source._matricesTexture.clone();
|
|
864
961
|
this._matricesTexture.image.data = this._matricesTexture.image.slice();
|
|
865
962
|
|
|
963
|
+
if ( this._colorsTexture !== null ) {
|
|
964
|
+
|
|
965
|
+
this._colorsTexture = source._colorsTexture.clone();
|
|
966
|
+
this._colorsTexture.image.data = this._colorsTexture.image.slice();
|
|
967
|
+
|
|
968
|
+
}
|
|
969
|
+
|
|
866
970
|
return this;
|
|
867
971
|
|
|
868
972
|
}
|
|
@@ -874,6 +978,14 @@ class BatchedMesh extends Mesh {
|
|
|
874
978
|
|
|
875
979
|
this._matricesTexture.dispose();
|
|
876
980
|
this._matricesTexture = null;
|
|
981
|
+
|
|
982
|
+
if ( this._colorsTexture !== null ) {
|
|
983
|
+
|
|
984
|
+
this._colorsTexture.dispose();
|
|
985
|
+
this._colorsTexture = null;
|
|
986
|
+
|
|
987
|
+
}
|
|
988
|
+
|
|
877
989
|
return this;
|
|
878
990
|
|
|
879
991
|
}
|
|
@@ -919,6 +1031,7 @@ class BatchedMesh extends Mesh {
|
|
|
919
1031
|
// get the camera position in the local frame
|
|
920
1032
|
_invMatrixWorld.copy( this.matrixWorld ).invert();
|
|
921
1033
|
_vector.setFromMatrixPosition( camera.matrixWorld ).applyMatrix4( _invMatrixWorld );
|
|
1034
|
+
_forward.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld ).transformDirection( _invMatrixWorld );
|
|
922
1035
|
|
|
923
1036
|
for ( let i = 0, l = visibility.length; i < l; i ++ ) {
|
|
924
1037
|
|
|
@@ -939,7 +1052,7 @@ class BatchedMesh extends Mesh {
|
|
|
939
1052
|
if ( ! culled ) {
|
|
940
1053
|
|
|
941
1054
|
// get the distance from camera used for sorting
|
|
942
|
-
const z =
|
|
1055
|
+
const z = _temp.subVectors( _sphere.center, _vector ).dot( _forward );
|
|
943
1056
|
_renderList.push( drawRanges[ i ], z );
|
|
944
1057
|
|
|
945
1058
|
}
|
package/src/objects/Line.js
CHANGED
|
@@ -7,12 +7,16 @@ import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
|
|
|
7
7
|
import { BufferGeometry } from '../core/BufferGeometry.js';
|
|
8
8
|
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
|
9
9
|
|
|
10
|
-
const
|
|
11
|
-
const
|
|
10
|
+
const _vStart = /*@__PURE__*/ new Vector3();
|
|
11
|
+
const _vEnd = /*@__PURE__*/ new Vector3();
|
|
12
|
+
|
|
12
13
|
const _inverseMatrix = /*@__PURE__*/ new Matrix4();
|
|
13
14
|
const _ray = /*@__PURE__*/ new Ray();
|
|
14
15
|
const _sphere = /*@__PURE__*/ new Sphere();
|
|
15
16
|
|
|
17
|
+
const _intersectPointOnRay = /*@__PURE__*/ new Vector3();
|
|
18
|
+
const _intersectPointOnSegment = /*@__PURE__*/ new Vector3();
|
|
19
|
+
|
|
16
20
|
class Line extends Object3D {
|
|
17
21
|
|
|
18
22
|
constructor( geometry = new BufferGeometry(), material = new LineBasicMaterial() ) {
|
|
@@ -54,11 +58,11 @@ class Line extends Object3D {
|
|
|
54
58
|
|
|
55
59
|
for ( let i = 1, l = positionAttribute.count; i < l; i ++ ) {
|
|
56
60
|
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
_vStart.fromBufferAttribute( positionAttribute, i - 1 );
|
|
62
|
+
_vEnd.fromBufferAttribute( positionAttribute, i );
|
|
59
63
|
|
|
60
64
|
lineDistances[ i ] = lineDistances[ i - 1 ];
|
|
61
|
-
lineDistances[ i ] +=
|
|
65
|
+
lineDistances[ i ] += _vStart.distanceTo( _vEnd );
|
|
62
66
|
|
|
63
67
|
}
|
|
64
68
|
|
|
@@ -99,10 +103,6 @@ class Line extends Object3D {
|
|
|
99
103
|
const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
|
|
100
104
|
const localThresholdSq = localThreshold * localThreshold;
|
|
101
105
|
|
|
102
|
-
const vStart = new Vector3();
|
|
103
|
-
const vEnd = new Vector3();
|
|
104
|
-
const interSegment = new Vector3();
|
|
105
|
-
const interRay = new Vector3();
|
|
106
106
|
const step = this.isLineSegments ? 2 : 1;
|
|
107
107
|
|
|
108
108
|
const index = geometry.index;
|
|
@@ -119,31 +119,28 @@ class Line extends Object3D {
|
|
|
119
119
|
const a = index.getX( i );
|
|
120
120
|
const b = index.getX( i + 1 );
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
const intersect = checkIntersection( this, raycaster, _ray, localThresholdSq, a, b );
|
|
123
|
+
|
|
124
|
+
if ( intersect ) {
|
|
124
125
|
|
|
125
|
-
|
|
126
|
+
intersects.push( intersect );
|
|
126
127
|
|
|
127
|
-
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
}
|
|
128
131
|
|
|
129
|
-
|
|
132
|
+
if ( this.isLineLoop ) {
|
|
130
133
|
|
|
131
|
-
const
|
|
134
|
+
const a = index.getX( end - 1 );
|
|
135
|
+
const b = index.getX( start );
|
|
132
136
|
|
|
133
|
-
|
|
137
|
+
const intersect = checkIntersection( this, raycaster, _ray, localThresholdSq, a, b );
|
|
134
138
|
|
|
135
|
-
|
|
139
|
+
if ( intersect ) {
|
|
136
140
|
|
|
137
|
-
|
|
138
|
-
// What do we want? intersection point on the ray or on the segment??
|
|
139
|
-
// point: raycaster.ray.at( distance ),
|
|
140
|
-
point: interSegment.clone().applyMatrix4( this.matrixWorld ),
|
|
141
|
-
index: i,
|
|
142
|
-
face: null,
|
|
143
|
-
faceIndex: null,
|
|
144
|
-
object: this
|
|
141
|
+
intersects.push( intersect );
|
|
145
142
|
|
|
146
|
-
}
|
|
143
|
+
}
|
|
147
144
|
|
|
148
145
|
}
|
|
149
146
|
|
|
@@ -154,31 +151,25 @@ class Line extends Object3D {
|
|
|
154
151
|
|
|
155
152
|
for ( let i = start, l = end - 1; i < l; i += step ) {
|
|
156
153
|
|
|
157
|
-
|
|
158
|
-
|
|
154
|
+
const intersect = checkIntersection( this, raycaster, _ray, localThresholdSq, i, i + 1 );
|
|
155
|
+
|
|
156
|
+
if ( intersect ) {
|
|
159
157
|
|
|
160
|
-
|
|
158
|
+
intersects.push( intersect );
|
|
161
159
|
|
|
162
|
-
|
|
160
|
+
}
|
|
163
161
|
|
|
164
|
-
|
|
162
|
+
}
|
|
165
163
|
|
|
166
|
-
|
|
164
|
+
if ( this.isLineLoop ) {
|
|
167
165
|
|
|
168
|
-
|
|
166
|
+
const intersect = checkIntersection( this, raycaster, _ray, localThresholdSq, end - 1, start );
|
|
169
167
|
|
|
170
|
-
|
|
168
|
+
if ( intersect ) {
|
|
171
169
|
|
|
172
|
-
|
|
173
|
-
// What do we want? intersection point on the ray or on the segment??
|
|
174
|
-
// point: raycaster.ray.at( distance ),
|
|
175
|
-
point: interSegment.clone().applyMatrix4( this.matrixWorld ),
|
|
176
|
-
index: i,
|
|
177
|
-
face: null,
|
|
178
|
-
faceIndex: null,
|
|
179
|
-
object: this
|
|
170
|
+
intersects.push( intersect );
|
|
180
171
|
|
|
181
|
-
}
|
|
172
|
+
}
|
|
182
173
|
|
|
183
174
|
}
|
|
184
175
|
|
|
@@ -219,4 +210,36 @@ class Line extends Object3D {
|
|
|
219
210
|
|
|
220
211
|
}
|
|
221
212
|
|
|
213
|
+
function checkIntersection( object, raycaster, ray, thresholdSq, a, b ) {
|
|
214
|
+
|
|
215
|
+
const positionAttribute = object.geometry.attributes.position;
|
|
216
|
+
|
|
217
|
+
_vStart.fromBufferAttribute( positionAttribute, a );
|
|
218
|
+
_vEnd.fromBufferAttribute( positionAttribute, b );
|
|
219
|
+
|
|
220
|
+
const distSq = ray.distanceSqToSegment( _vStart, _vEnd, _intersectPointOnRay, _intersectPointOnSegment );
|
|
221
|
+
|
|
222
|
+
if ( distSq > thresholdSq ) return;
|
|
223
|
+
|
|
224
|
+
_intersectPointOnRay.applyMatrix4( object.matrixWorld ); // Move back to world space for distance calculation
|
|
225
|
+
|
|
226
|
+
const distance = raycaster.ray.origin.distanceTo( _intersectPointOnRay );
|
|
227
|
+
|
|
228
|
+
if ( distance < raycaster.near || distance > raycaster.far ) return;
|
|
229
|
+
|
|
230
|
+
return {
|
|
231
|
+
|
|
232
|
+
distance: distance,
|
|
233
|
+
// What do we want? intersection point on the ray or on the segment??
|
|
234
|
+
// point: raycaster.ray.at( distance ),
|
|
235
|
+
point: _intersectPointOnSegment.clone().applyMatrix4( object.matrixWorld ),
|
|
236
|
+
index: a,
|
|
237
|
+
face: null,
|
|
238
|
+
faceIndex: null,
|
|
239
|
+
object: object
|
|
240
|
+
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
}
|
|
244
|
+
|
|
222
245
|
export { Line };
|