super-three 0.157.1 → 0.160.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 +6 -4
- package/build/three.cjs +3100 -1537
- package/build/three.js +3100 -1537
- package/build/three.min.js +1 -1
- package/build/three.module.js +3093 -1538
- package/build/three.module.min.js +1 -1
- package/examples/jsm/Addons.js +291 -0
- package/examples/jsm/controls/FlyControls.js +26 -0
- package/examples/jsm/controls/OrbitControls.js +62 -41
- package/examples/jsm/controls/TransformControls.js +27 -11
- package/examples/jsm/csm/CSMShader.js +53 -48
- package/examples/jsm/exporters/GLTFExporter.js +151 -3
- package/examples/jsm/exporters/USDZExporter.js +27 -19
- package/examples/jsm/geometries/InstancedPointsGeometry.js +174 -0
- package/examples/jsm/geometries/SDFGeometryGenerator.js +144 -0
- package/examples/jsm/helpers/TextureHelper.js +237 -0
- package/examples/jsm/interactive/HTMLMesh.js +9 -2
- package/examples/jsm/libs/lottie_canvas.module.js +6 -1
- package/examples/jsm/libs/opentype.module.js +13 -75
- package/examples/jsm/libs/surfaceNet.js +201 -0
- package/examples/jsm/lines/LineMaterial.js +16 -33
- package/examples/jsm/loaders/ColladaLoader.js +0 -6
- package/examples/jsm/loaders/DRACOLoader.js +4 -3
- package/examples/jsm/loaders/FBXLoader.js +294 -124
- package/examples/jsm/loaders/GLTFLoader.js +83 -6
- package/examples/jsm/loaders/LUTImageLoader.js +162 -0
- package/examples/jsm/loaders/MaterialXLoader.js +73 -54
- package/examples/jsm/loaders/NRRDLoader.js +0 -13
- package/examples/jsm/loaders/SVGLoader.js +4 -4
- package/examples/jsm/loaders/USDZLoader.js +3 -17
- package/examples/jsm/loaders/lwo/IFFParser.js +89 -93
- package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
- package/examples/jsm/math/Capsule.js +0 -55
- package/examples/jsm/math/Octree.js +85 -7
- package/examples/jsm/misc/Timer.js +119 -0
- package/examples/jsm/misc/TubePainter.js +3 -6
- package/examples/jsm/modifiers/CurveModifier.js +20 -2
- package/examples/jsm/modifiers/SimplifyModifier.js +103 -11
- package/examples/jsm/modifiers/TessellateModifier.js +3 -3
- package/examples/jsm/nodes/Nodes.js +16 -12
- package/examples/jsm/nodes/accessors/CameraNode.js +18 -2
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +5 -73
- package/examples/jsm/nodes/accessors/InstanceNode.js +3 -3
- package/examples/jsm/nodes/accessors/InstancedPointsMaterialNode.js +21 -0
- package/examples/jsm/nodes/accessors/MaterialNode.js +68 -31
- package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +11 -2
- package/examples/jsm/nodes/accessors/ModelNode.js +1 -2
- package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +12 -3
- package/examples/jsm/nodes/accessors/MorphNode.js +191 -16
- package/examples/jsm/nodes/accessors/NormalNode.js +1 -1
- package/examples/jsm/nodes/accessors/PositionNode.js +1 -1
- package/examples/jsm/nodes/accessors/ReferenceNode.js +25 -1
- package/examples/jsm/nodes/accessors/SkinningNode.js +13 -3
- package/examples/jsm/nodes/accessors/TextureNode.js +123 -37
- package/examples/jsm/nodes/code/CodeNode.js +3 -3
- package/examples/jsm/nodes/code/FunctionNode.js +1 -1
- package/examples/jsm/nodes/core/AssignNode.js +72 -0
- package/examples/jsm/nodes/core/AttributeNode.js +7 -1
- package/examples/jsm/nodes/core/CacheNode.js +4 -1
- package/examples/jsm/nodes/core/ConstNode.js +1 -1
- package/examples/jsm/nodes/core/LightingModel.js +3 -1
- package/examples/jsm/nodes/core/Node.js +13 -15
- package/examples/jsm/nodes/core/NodeBuilder.js +209 -42
- package/examples/jsm/nodes/core/NodeFrame.js +10 -8
- package/examples/jsm/nodes/core/NodeUniform.js +12 -0
- package/examples/jsm/nodes/core/NodeUtils.js +7 -9
- package/examples/jsm/nodes/core/OutputStructNode.js +4 -4
- package/examples/jsm/nodes/core/ParameterNode.js +33 -0
- package/examples/jsm/nodes/core/PropertyNode.js +15 -6
- package/examples/jsm/nodes/core/StackNode.js +7 -17
- package/examples/jsm/nodes/core/StructTypeNode.js +4 -4
- package/examples/jsm/nodes/core/TempNode.js +1 -1
- package/examples/jsm/nodes/core/UniformGroup.js +13 -0
- package/examples/jsm/nodes/core/UniformGroupNode.js +36 -0
- package/examples/jsm/nodes/core/UniformNode.js +17 -0
- package/examples/jsm/nodes/core/VarNode.js +7 -34
- package/examples/jsm/nodes/core/VaryingNode.js +3 -7
- package/examples/jsm/nodes/display/BumpMapNode.js +35 -13
- package/examples/jsm/nodes/display/ColorAdjustmentNode.js +6 -10
- package/examples/jsm/nodes/display/GaussianBlurNode.js +170 -0
- package/examples/jsm/nodes/display/NormalMapNode.js +3 -1
- package/examples/jsm/nodes/display/PassNode.js +182 -0
- package/examples/jsm/nodes/display/ViewportDepthNode.js +31 -3
- package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +2 -2
- package/examples/jsm/nodes/display/ViewportNode.js +17 -10
- package/examples/jsm/nodes/functions/BSDF/BRDF_Sheen.js +20 -6
- package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +8 -7
- package/examples/jsm/nodes/functions/BSDF/D_GGX.js +8 -3
- package/examples/jsm/nodes/functions/BSDF/Schlick_to_F0.js +8 -0
- package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +8 -0
- package/examples/jsm/nodes/functions/PhysicalLightingModel.js +93 -43
- package/examples/jsm/nodes/gpgpu/ComputeNode.js +2 -2
- package/examples/jsm/nodes/lighting/AmbientLightNode.js +1 -1
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +55 -6
- package/examples/jsm/nodes/lighting/DirectionalLightNode.js +1 -1
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +8 -18
- package/examples/jsm/nodes/lighting/LightingContextNode.js +21 -57
- package/examples/jsm/nodes/lighting/LightsNode.js +80 -20
- package/examples/jsm/nodes/lighting/PointLightNode.js +1 -1
- package/examples/jsm/nodes/lighting/SpotLightNode.js +1 -1
- package/examples/jsm/nodes/materials/InstancedPointsNodeMaterial.js +162 -0
- package/examples/jsm/nodes/materials/Line2NodeMaterial.js +76 -77
- package/examples/jsm/nodes/materials/LineDashedNodeMaterial.js +5 -5
- package/examples/jsm/nodes/materials/Materials.js +1 -0
- package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +1 -0
- package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +3 -3
- package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +3 -3
- package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +47 -20
- package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +6 -6
- package/examples/jsm/nodes/materials/NodeMaterial.js +82 -60
- package/examples/jsm/nodes/materials/PointsNodeMaterial.js +0 -10
- package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +0 -7
- package/examples/jsm/nodes/materialx/MaterialXNodes.js +10 -10
- package/examples/jsm/nodes/materialx/lib/mx_hsv.js +128 -54
- package/examples/jsm/nodes/materialx/lib/mx_noise.js +1430 -618
- package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +24 -14
- package/examples/jsm/nodes/math/MathNode.js +2 -0
- package/examples/jsm/nodes/math/OperatorNode.js +24 -27
- package/examples/jsm/nodes/shadernode/ShaderNode.js +158 -10
- package/examples/jsm/nodes/utils/ArrayElementNode.js +2 -0
- package/examples/jsm/nodes/utils/DiscardNode.js +3 -2
- package/examples/jsm/nodes/utils/FunctionOverloadingNode.js +95 -0
- package/examples/jsm/nodes/utils/JoinNode.js +11 -1
- package/examples/jsm/nodes/utils/LoopNode.js +36 -24
- package/examples/jsm/nodes/utils/RemapNode.js +2 -2
- package/examples/jsm/nodes/utils/SplitNode.js +10 -2
- package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +3 -3
- package/examples/jsm/objects/InstancedPoints.js +21 -0
- package/examples/jsm/objects/Lensflare.js +20 -0
- package/examples/jsm/objects/QuadMesh.js +60 -0
- package/examples/jsm/objects/ReflectorForSSRPass.js +3 -0
- package/examples/jsm/objects/Refractor.js +3 -0
- package/examples/jsm/objects/Sky.js +5 -3
- package/examples/jsm/objects/Water.js +5 -2
- package/examples/jsm/objects/Water2.js +3 -0
- package/examples/jsm/physics/AmmoPhysics.js +21 -0
- package/examples/jsm/physics/RapierPhysics.js +21 -0
- package/examples/jsm/postprocessing/BokehPass.js +3 -2
- package/examples/jsm/postprocessing/GTAOPass.js +572 -0
- package/examples/jsm/postprocessing/LUTPass.js +2 -1
- package/examples/jsm/postprocessing/OutputPass.js +3 -0
- package/examples/jsm/postprocessing/Pass.js +14 -3
- package/examples/jsm/postprocessing/SAOPass.js +0 -1
- package/examples/jsm/postprocessing/SMAAPass.js +0 -2
- package/examples/jsm/postprocessing/TAARenderPass.js +1 -2
- package/examples/jsm/renderers/CSS3DRenderer.js +3 -9
- package/examples/jsm/renderers/SVGRenderer.js +9 -6
- package/examples/jsm/renderers/common/Animation.js +10 -21
- package/examples/jsm/renderers/common/Backend.js +19 -3
- package/examples/jsm/renderers/common/Background.js +20 -22
- package/examples/jsm/renderers/common/Bindings.js +31 -22
- package/examples/jsm/renderers/common/ChainMap.js +3 -3
- package/examples/jsm/renderers/common/Color4.js +37 -0
- package/examples/jsm/renderers/common/Geometries.js +4 -4
- package/examples/jsm/renderers/common/Info.js +12 -2
- package/examples/jsm/renderers/common/Pipelines.js +3 -51
- package/examples/jsm/renderers/common/PostProcessing.js +25 -0
- package/examples/jsm/renderers/common/RenderContext.js +1 -1
- package/examples/jsm/renderers/common/RenderContexts.js +1 -1
- package/examples/jsm/renderers/common/RenderObject.js +21 -2
- package/examples/jsm/renderers/common/RenderObjects.js +5 -3
- package/examples/jsm/renderers/common/Renderer.js +137 -37
- package/examples/jsm/renderers/common/StorageTexture.js +1 -0
- package/examples/jsm/renderers/common/Textures.js +8 -37
- package/examples/jsm/renderers/common/nodes/NodeBuilderState.js +10 -2
- package/examples/jsm/renderers/common/nodes/NodeUniformsGroup.js +44 -0
- package/examples/jsm/renderers/common/nodes/Nodes.js +121 -19
- package/examples/jsm/renderers/webgl/WebGLBackend.js +366 -67
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +183 -38
- package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +92 -5
- package/examples/jsm/renderers/webgl/utils/WebGLCapabilities.js +36 -0
- package/examples/jsm/renderers/webgl/utils/WebGLExtensions.js +11 -1
- package/examples/jsm/renderers/webgl/utils/WebGLState.js +14 -2
- package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +71 -2
- package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +42 -0
- package/examples/jsm/renderers/webgl-legacy/nodes/SlotNode.js +1 -1
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +33 -3
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js +4 -14
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +188 -137
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +1 -1
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +241 -90
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +15 -10
- package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +11 -3
- package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +2 -3
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +88 -6
- package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +2 -0
- package/examples/jsm/shaders/AfterimageShader.js +2 -0
- package/examples/jsm/shaders/BasicShader.js +2 -0
- package/examples/jsm/shaders/BlendShader.js +2 -0
- package/examples/jsm/shaders/BokehShader.js +2 -0
- package/examples/jsm/shaders/BokehShader2.js +4 -0
- package/examples/jsm/shaders/BrightnessContrastShader.js +2 -0
- package/examples/jsm/shaders/ColorCorrectionShader.js +2 -0
- package/examples/jsm/shaders/DOFMipMapShader.js +2 -0
- package/examples/jsm/shaders/DepthLimitedBlurShader.js +5 -0
- package/examples/jsm/shaders/FXAAShader.js +135 -133
- package/examples/jsm/shaders/FilmShader.js +1 -1
- package/examples/jsm/shaders/FocusShader.js +2 -0
- package/examples/jsm/shaders/FreiChenShader.js +2 -0
- package/examples/jsm/shaders/GTAOShader.js +424 -0
- package/examples/jsm/shaders/GodRaysShader.js +8 -0
- package/examples/jsm/shaders/HalftoneShader.js +2 -0
- package/examples/jsm/shaders/HorizontalTiltShiftShader.js +2 -0
- package/examples/jsm/shaders/HueSaturationShader.js +2 -0
- package/examples/jsm/shaders/KaleidoShader.js +2 -0
- package/examples/jsm/shaders/LuminosityHighPassShader.js +2 -0
- package/examples/jsm/shaders/LuminosityShader.js +2 -0
- package/examples/jsm/shaders/MMDToonShader.js +2 -0
- package/examples/jsm/shaders/MirrorShader.js +2 -0
- package/examples/jsm/shaders/NormalMapShader.js +2 -0
- package/examples/jsm/shaders/OutputShader.js +8 -5
- package/examples/jsm/shaders/PoissonDenoiseShader.js +226 -0
- package/examples/jsm/shaders/SAOShader.js +7 -3
- package/examples/jsm/shaders/SMAAShader.js +6 -0
- package/examples/jsm/shaders/SSAOShader.js +8 -3
- package/examples/jsm/shaders/SSRShader.js +6 -0
- package/examples/jsm/shaders/SobelOperatorShader.js +2 -0
- package/examples/jsm/shaders/SubsurfaceScatteringShader.js +2 -0
- package/examples/jsm/shaders/TechnicolorShader.js +2 -0
- package/examples/jsm/shaders/TriangleBlurShader.js +2 -0
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +2 -0
- package/examples/jsm/shaders/VelocityShader.js +2 -0
- package/examples/jsm/shaders/VerticalTiltShiftShader.js +2 -0
- package/examples/jsm/shaders/WaterRefractionShader.js +2 -0
- package/examples/jsm/transpiler/AST.js +270 -0
- package/examples/jsm/transpiler/GLSLDecoder.js +941 -0
- package/examples/jsm/transpiler/ShaderToyDecoder.js +49 -0
- package/examples/jsm/transpiler/TSLEncoder.js +715 -0
- package/examples/jsm/transpiler/Transpiler.js +18 -0
- package/examples/jsm/utils/SortUtils.js +158 -0
- package/examples/jsm/utils/TextureUtils.js +33 -21
- package/examples/jsm/webxr/ARButton.js +14 -0
- package/examples/jsm/webxr/VRButton.js +24 -9
- package/examples/jsm/webxr/XRButton.js +27 -11
- package/examples/jsm/webxr/XREstimatedLight.js +1 -1
- package/package.json +8 -6
- package/src/Three.js +1 -0
- package/src/constants.js +8 -1
- package/src/core/BufferAttribute.js +21 -2
- package/src/core/InterleavedBuffer.js +21 -1
- package/src/core/Object3D.js +60 -12
- package/src/core/UniformsGroup.js +7 -1
- package/src/extras/PMREMGenerator.js +7 -1
- package/src/extras/curves/LineCurve3.js +4 -0
- package/src/loaders/AudioLoader.js +1 -1
- package/src/loaders/BufferGeometryLoader.js +0 -7
- package/src/loaders/ImageBitmapLoader.js +25 -1
- package/src/loaders/MaterialLoader.js +10 -2
- package/src/loaders/ObjectLoader.js +49 -0
- package/src/materials/Material.js +27 -13
- package/src/materials/ShaderMaterial.js +2 -1
- package/src/math/Box3.js +35 -18
- package/src/math/ColorManagement.js +0 -16
- package/src/math/Quaternion.js +5 -4
- package/src/math/Sphere.js +2 -0
- package/src/math/Triangle.js +17 -5
- package/src/math/Vector3.js +11 -12
- package/src/objects/BatchedMesh.js +1020 -0
- package/src/objects/Skeleton.js +1 -3
- package/src/objects/SkinnedMesh.js +6 -7
- package/src/renderers/WebGL3DRenderTarget.js +2 -2
- package/src/renderers/WebGLArrayRenderTarget.js +2 -2
- package/src/renderers/WebGLRenderer.js +165 -43
- package/src/renderers/shaders/ShaderChunk/aomap_fragment.glsl.js +8 -0
- package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +19 -0
- package/src/renderers/shaders/ShaderChunk/batching_vertex.glsl.js +5 -0
- package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +3 -2
- package/src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl.js +0 -5
- package/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js +31 -4
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +9 -4
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +8 -6
- package/src/renderers/shaders/ShaderChunk/project_vertex.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl.js +9 -17
- package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +84 -0
- package/src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk.js +4 -0
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/distanceRGBA.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +3 -0
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -2
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +3 -0
- package/src/renderers/webgl/WebGLAttributes.js +39 -5
- package/src/renderers/webgl/WebGLBufferRenderer.js +31 -0
- package/src/renderers/webgl/WebGLCubeMaps.js +1 -1
- package/src/renderers/webgl/WebGLExtensions.js +1 -0
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +31 -0
- package/src/renderers/webgl/WebGLLights.js +11 -2
- package/src/renderers/webgl/WebGLProgram.js +100 -51
- package/src/renderers/webgl/WebGLPrograms.js +8 -0
- package/src/renderers/webgl/WebGLShadowMap.js +35 -0
- package/src/renderers/webgl/WebGLState.js +25 -4
- package/src/renderers/webgl/WebGLTextures.js +7 -11
- package/src/renderers/webgl/WebGLUniforms.js +11 -1
- package/src/renderers/webgl/WebGLUniformsGroups.js +72 -93
- package/src/renderers/webxr/WebXRManager.js +16 -0
- package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +0 -76
- package/examples/jsm/nodes/accessors/LineMaterialNode.js +0 -29
|
@@ -6,7 +6,7 @@ vec3 geometryPosition = - vViewPosition;
|
|
|
6
6
|
vec3 geometryNormal = normal;
|
|
7
7
|
vec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );
|
|
8
8
|
|
|
9
|
-
vec3 geometryClearcoatNormal;
|
|
9
|
+
vec3 geometryClearcoatNormal = vec3( 0.0 );
|
|
10
10
|
|
|
11
11
|
#ifdef USE_CLEARCOAT
|
|
12
12
|
|
|
@@ -62,7 +62,7 @@ IncidentLight directLight;
|
|
|
62
62
|
vec4 spotColor;
|
|
63
63
|
vec3 spotLightCoord;
|
|
64
64
|
bool inSpotLightMap;
|
|
65
|
-
|
|
65
|
+
|
|
66
66
|
#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0
|
|
67
67
|
SpotLightShadow spotLightShadow;
|
|
68
68
|
#endif
|
|
@@ -112,57 +112,57 @@ IncidentLight directLight;
|
|
|
112
112
|
#endif
|
|
113
113
|
|
|
114
114
|
#if defined( USE_SHADOWMAP ) && defined( CSM_FADE )
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
115
|
+
vec2 cascade;
|
|
116
|
+
float cascadeCenter;
|
|
117
|
+
float closestEdge;
|
|
118
|
+
float margin;
|
|
119
|
+
float csmx;
|
|
120
|
+
float csmy;
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
#pragma unroll_loop_start
|
|
123
|
+
for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
directionalLight = directionalLights[ i ];
|
|
126
|
+
getDirectionalLightInfo( directionalLight, directLight );
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
float dist = min( linearDepth - csmx, csmy - linearDepth );
|
|
140
|
-
float ratio = clamp( dist / margin, 0.0, 1.0 );
|
|
141
|
-
|
|
142
|
-
vec3 prevColor = directLight.color;
|
|
143
|
-
directionalLightShadow = directionalLightShadows[ i ];
|
|
144
|
-
directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
|
|
128
|
+
#if ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
|
|
129
|
+
// NOTE: Depth gets larger away from the camera.
|
|
130
|
+
// cascade.x is closer, cascade.y is further
|
|
131
|
+
cascade = CSM_cascades[ i ];
|
|
132
|
+
cascadeCenter = ( cascade.x + cascade.y ) / 2.0;
|
|
133
|
+
closestEdge = linearDepth < cascadeCenter ? cascade.x : cascade.y;
|
|
134
|
+
margin = 0.25 * pow( closestEdge, 2.0 );
|
|
135
|
+
csmx = cascade.x - margin / 2.0;
|
|
136
|
+
csmy = cascade.y + margin / 2.0;
|
|
137
|
+
if( linearDepth >= csmx && ( linearDepth < csmy || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 ) ) {
|
|
145
138
|
|
|
146
|
-
|
|
147
|
-
|
|
139
|
+
float dist = min( linearDepth - csmx, csmy - linearDepth );
|
|
140
|
+
float ratio = clamp( dist / margin, 0.0, 1.0 );
|
|
148
141
|
|
|
149
|
-
|
|
150
|
-
|
|
142
|
+
vec3 prevColor = directLight.color;
|
|
143
|
+
directionalLightShadow = directionalLightShadows[ i ];
|
|
144
|
+
directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
|
|
151
145
|
|
|
152
|
-
|
|
153
|
-
|
|
146
|
+
bool shouldFadeLastCascade = UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 && linearDepth > cascadeCenter;
|
|
147
|
+
directLight.color = mix( prevColor, directLight.color, shouldFadeLastCascade ? ratio : 1.0 );
|
|
154
148
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
reflectedLight.indirectDiffuse = mix( prevLight.indirectDiffuse, reflectedLight.indirectDiffuse, blendRatio );
|
|
158
|
-
reflectedLight.indirectSpecular = mix( prevLight.indirectSpecular, reflectedLight.indirectSpecular, blendRatio );
|
|
149
|
+
ReflectedLight prevLight = reflectedLight;
|
|
150
|
+
RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
|
|
159
151
|
|
|
160
|
-
|
|
161
|
-
|
|
152
|
+
bool shouldBlend = UNROLLED_LOOP_INDEX != CSM_CASCADES - 1 || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 && linearDepth < cascadeCenter;
|
|
153
|
+
float blendRatio = shouldBlend ? ratio : 1.0;
|
|
162
154
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
155
|
+
reflectedLight.directDiffuse = mix( prevLight.directDiffuse, reflectedLight.directDiffuse, blendRatio );
|
|
156
|
+
reflectedLight.directSpecular = mix( prevLight.directSpecular, reflectedLight.directSpecular, blendRatio );
|
|
157
|
+
reflectedLight.indirectDiffuse = mix( prevLight.indirectDiffuse, reflectedLight.indirectDiffuse, blendRatio );
|
|
158
|
+
reflectedLight.indirectSpecular = mix( prevLight.indirectSpecular, reflectedLight.indirectSpecular, blendRatio );
|
|
159
|
+
|
|
160
|
+
}
|
|
161
|
+
#endif
|
|
162
|
+
|
|
163
|
+
}
|
|
164
|
+
#pragma unroll_loop_end
|
|
165
|
+
#elif defined (USE_SHADOWMAP)
|
|
166
166
|
|
|
167
167
|
#pragma unroll_loop_start
|
|
168
168
|
for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
|
|
@@ -170,18 +170,23 @@ IncidentLight directLight;
|
|
|
170
170
|
directionalLight = directionalLights[ i ];
|
|
171
171
|
getDirectionalLightInfo( directionalLight, directLight );
|
|
172
172
|
|
|
173
|
-
#if
|
|
173
|
+
#if ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
|
|
174
174
|
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
directionalLightShadow = directionalLightShadows[ i ];
|
|
176
|
+
if(linearDepth >= CSM_cascades[UNROLLED_LOOP_INDEX].x && linearDepth < CSM_cascades[UNROLLED_LOOP_INDEX].y) directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
|
|
177
177
|
|
|
178
|
-
|
|
178
|
+
if(linearDepth >= CSM_cascades[UNROLLED_LOOP_INDEX].x && (linearDepth < CSM_cascades[UNROLLED_LOOP_INDEX].y || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1)) RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
|
|
179
179
|
|
|
180
180
|
#endif
|
|
181
181
|
|
|
182
182
|
}
|
|
183
183
|
#pragma unroll_loop_end
|
|
184
184
|
|
|
185
|
+
#elif ( NUM_DIR_LIGHT_SHADOWS > 0 )
|
|
186
|
+
// note: no loop here - all CSM lights are in fact one light only
|
|
187
|
+
getDirectionalLightInfo( directionalLights[0], directLight );
|
|
188
|
+
RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
|
|
189
|
+
|
|
185
190
|
#endif
|
|
186
191
|
|
|
187
192
|
#if ( NUM_DIR_LIGHTS > NUM_DIR_LIGHT_SHADOWS)
|
|
@@ -22,7 +22,8 @@ import {
|
|
|
22
22
|
Source,
|
|
23
23
|
SRGBColorSpace,
|
|
24
24
|
CompressedTexture,
|
|
25
|
-
Vector3
|
|
25
|
+
Vector3,
|
|
26
|
+
Quaternion,
|
|
26
27
|
} from 'three';
|
|
27
28
|
import { decompress } from './../utils/TextureUtils.js';
|
|
28
29
|
|
|
@@ -134,6 +135,18 @@ class GLTFExporter {
|
|
|
134
135
|
|
|
135
136
|
} );
|
|
136
137
|
|
|
138
|
+
this.register( function ( writer ) {
|
|
139
|
+
|
|
140
|
+
return new GLTFMaterialsBumpExtension( writer );
|
|
141
|
+
|
|
142
|
+
} );
|
|
143
|
+
|
|
144
|
+
this.register( function ( writer ) {
|
|
145
|
+
|
|
146
|
+
return new GLTFMeshGpuInstancing( writer );
|
|
147
|
+
|
|
148
|
+
} );
|
|
149
|
+
|
|
137
150
|
}
|
|
138
151
|
|
|
139
152
|
register( callback ) {
|
|
@@ -1165,7 +1178,7 @@ class GLTFWriter {
|
|
|
1165
1178
|
}
|
|
1166
1179
|
|
|
1167
1180
|
if ( start === undefined ) start = 0;
|
|
1168
|
-
if ( count === undefined ) count = attribute.count;
|
|
1181
|
+
if ( count === undefined || count === Infinity ) count = attribute.count;
|
|
1169
1182
|
|
|
1170
1183
|
// Skip creating an accessor if the attribute doesn't have data to export
|
|
1171
1184
|
if ( count === 0 ) return null;
|
|
@@ -1639,6 +1652,8 @@ class GLTFWriter {
|
|
|
1639
1652
|
const nameConversion = {
|
|
1640
1653
|
uv: 'TEXCOORD_0',
|
|
1641
1654
|
uv1: 'TEXCOORD_1',
|
|
1655
|
+
uv2: 'TEXCOORD_2',
|
|
1656
|
+
uv3: 'TEXCOORD_3',
|
|
1642
1657
|
color: 'COLOR_0',
|
|
1643
1658
|
skinWeight: 'WEIGHTS_0',
|
|
1644
1659
|
skinIndex: 'JOINTS_0'
|
|
@@ -1820,6 +1835,24 @@ class GLTFWriter {
|
|
|
1820
1835
|
|
|
1821
1836
|
if ( isMultiMaterial && geometry.groups.length === 0 ) return null;
|
|
1822
1837
|
|
|
1838
|
+
let didForceIndices = false;
|
|
1839
|
+
|
|
1840
|
+
if ( isMultiMaterial && geometry.index === null ) {
|
|
1841
|
+
|
|
1842
|
+
const indices = [];
|
|
1843
|
+
|
|
1844
|
+
for ( let i = 0, il = geometry.attributes.position.count; i < il; i ++ ) {
|
|
1845
|
+
|
|
1846
|
+
indices[ i ] = i;
|
|
1847
|
+
|
|
1848
|
+
}
|
|
1849
|
+
|
|
1850
|
+
geometry.setIndex( indices );
|
|
1851
|
+
|
|
1852
|
+
didForceIndices = true;
|
|
1853
|
+
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1823
1856
|
const materials = isMultiMaterial ? mesh.material : [ mesh.material ];
|
|
1824
1857
|
const groups = isMultiMaterial ? geometry.groups : [ { materialIndex: 0, start: undefined, count: undefined } ];
|
|
1825
1858
|
|
|
@@ -1867,6 +1900,12 @@ class GLTFWriter {
|
|
|
1867
1900
|
|
|
1868
1901
|
}
|
|
1869
1902
|
|
|
1903
|
+
if ( didForceIndices === true ) {
|
|
1904
|
+
|
|
1905
|
+
geometry.setIndex( null );
|
|
1906
|
+
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1870
1909
|
meshDef.primitives = primitives;
|
|
1871
1910
|
|
|
1872
1911
|
if ( ! json.meshes ) json.meshes = [];
|
|
@@ -2787,7 +2826,7 @@ class GLTFMaterialsSpecularExtension {
|
|
|
2787
2826
|
|
|
2788
2827
|
if ( ! material.isMeshPhysicalMaterial || ( material.specularIntensity === 1.0 &&
|
|
2789
2828
|
material.specularColor.equals( DEFAULT_SPECULAR_COLOR ) &&
|
|
2790
|
-
! material.specularIntensityMap && ! material.
|
|
2829
|
+
! material.specularIntensityMap && ! material.specularColorMap ) ) return;
|
|
2791
2830
|
|
|
2792
2831
|
const writer = this.writer;
|
|
2793
2832
|
const extensionsUsed = writer.extensionsUsed;
|
|
@@ -2962,6 +3001,115 @@ class GLTFMaterialsEmissiveStrengthExtension {
|
|
|
2962
3001
|
|
|
2963
3002
|
}
|
|
2964
3003
|
|
|
3004
|
+
|
|
3005
|
+
/**
|
|
3006
|
+
* Materials bump Extension
|
|
3007
|
+
*
|
|
3008
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/EXT_materials_bump
|
|
3009
|
+
*/
|
|
3010
|
+
class GLTFMaterialsBumpExtension {
|
|
3011
|
+
|
|
3012
|
+
constructor( writer ) {
|
|
3013
|
+
|
|
3014
|
+
this.writer = writer;
|
|
3015
|
+
this.name = 'EXT_materials_bump';
|
|
3016
|
+
|
|
3017
|
+
}
|
|
3018
|
+
|
|
3019
|
+
writeMaterial( material, materialDef ) {
|
|
3020
|
+
|
|
3021
|
+
if ( ! material.isMeshStandardMaterial || (
|
|
3022
|
+
material.bumpScale === 1 &&
|
|
3023
|
+
! material.bumpMap ) ) return;
|
|
3024
|
+
|
|
3025
|
+
const writer = this.writer;
|
|
3026
|
+
const extensionsUsed = writer.extensionsUsed;
|
|
3027
|
+
|
|
3028
|
+
const extensionDef = {};
|
|
3029
|
+
|
|
3030
|
+
if ( material.bumpMap ) {
|
|
3031
|
+
|
|
3032
|
+
const bumpMapDef = {
|
|
3033
|
+
index: writer.processTexture( material.bumpMap ),
|
|
3034
|
+
texCoord: material.bumpMap.channel
|
|
3035
|
+
};
|
|
3036
|
+
writer.applyTextureTransform( bumpMapDef, material.bumpMap );
|
|
3037
|
+
extensionDef.bumpTexture = bumpMapDef;
|
|
3038
|
+
|
|
3039
|
+
}
|
|
3040
|
+
|
|
3041
|
+
extensionDef.bumpFactor = material.bumpScale;
|
|
3042
|
+
|
|
3043
|
+
materialDef.extensions = materialDef.extensions || {};
|
|
3044
|
+
materialDef.extensions[ this.name ] = extensionDef;
|
|
3045
|
+
|
|
3046
|
+
extensionsUsed[ this.name ] = true;
|
|
3047
|
+
|
|
3048
|
+
}
|
|
3049
|
+
|
|
3050
|
+
}
|
|
3051
|
+
|
|
3052
|
+
/**
|
|
3053
|
+
* GPU Instancing Extension
|
|
3054
|
+
*
|
|
3055
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_mesh_gpu_instancing
|
|
3056
|
+
*/
|
|
3057
|
+
class GLTFMeshGpuInstancing {
|
|
3058
|
+
|
|
3059
|
+
constructor( writer ) {
|
|
3060
|
+
|
|
3061
|
+
this.writer = writer;
|
|
3062
|
+
this.name = 'EXT_mesh_gpu_instancing';
|
|
3063
|
+
|
|
3064
|
+
}
|
|
3065
|
+
|
|
3066
|
+
writeNode( object, nodeDef ) {
|
|
3067
|
+
|
|
3068
|
+
if ( ! object.isInstancedMesh ) return;
|
|
3069
|
+
|
|
3070
|
+
const writer = this.writer;
|
|
3071
|
+
|
|
3072
|
+
const mesh = object;
|
|
3073
|
+
|
|
3074
|
+
const translationAttr = new Float32Array( mesh.count * 3 );
|
|
3075
|
+
const rotationAttr = new Float32Array( mesh.count * 4 );
|
|
3076
|
+
const scaleAttr = new Float32Array( mesh.count * 3 );
|
|
3077
|
+
|
|
3078
|
+
const matrix = new Matrix4();
|
|
3079
|
+
const position = new Vector3();
|
|
3080
|
+
const quaternion = new Quaternion();
|
|
3081
|
+
const scale = new Vector3();
|
|
3082
|
+
|
|
3083
|
+
for ( let i = 0; i < mesh.count; i ++ ) {
|
|
3084
|
+
|
|
3085
|
+
mesh.getMatrixAt( i, matrix );
|
|
3086
|
+
matrix.decompose( position, quaternion, scale );
|
|
3087
|
+
|
|
3088
|
+
position.toArray( translationAttr, i * 3 );
|
|
3089
|
+
quaternion.toArray( rotationAttr, i * 4 );
|
|
3090
|
+
scale.toArray( scaleAttr, i * 3 );
|
|
3091
|
+
|
|
3092
|
+
}
|
|
3093
|
+
|
|
3094
|
+
const attributes = {
|
|
3095
|
+
TRANSLATION: writer.processAccessor( new BufferAttribute( translationAttr, 3 ) ),
|
|
3096
|
+
ROTATION: writer.processAccessor( new BufferAttribute( rotationAttr, 4 ) ),
|
|
3097
|
+
SCALE: writer.processAccessor( new BufferAttribute( scaleAttr, 3 ) ),
|
|
3098
|
+
};
|
|
3099
|
+
|
|
3100
|
+
if ( mesh.instanceColor )
|
|
3101
|
+
attributes._COLOR_0 = writer.processAccessor( mesh.instanceColor );
|
|
3102
|
+
|
|
3103
|
+
nodeDef.extensions = nodeDef.extensions || {};
|
|
3104
|
+
nodeDef.extensions[ this.name ] = { attributes };
|
|
3105
|
+
|
|
3106
|
+
writer.extensionsUsed[ this.name ] = true;
|
|
3107
|
+
writer.extensionsRequired[ this.name ] = true;
|
|
3108
|
+
|
|
3109
|
+
}
|
|
3110
|
+
|
|
3111
|
+
}
|
|
3112
|
+
|
|
2965
3113
|
/**
|
|
2966
3114
|
* Static utility functions
|
|
2967
3115
|
*/
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
NoColorSpace,
|
|
3
|
+
DoubleSide,
|
|
4
|
+
} from 'three';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
strToU8,
|
|
8
|
+
zipSync,
|
|
9
|
+
} from '../libs/fflate.module.js';
|
|
10
|
+
|
|
11
|
+
import { decompress } from './../utils/TextureUtils.js';
|
|
3
12
|
|
|
4
13
|
class USDZExporter {
|
|
5
14
|
|
|
@@ -71,12 +80,18 @@ class USDZExporter {
|
|
|
71
80
|
|
|
72
81
|
output += buildMaterials( materials, textures, options.quickLookCompatible );
|
|
73
82
|
|
|
74
|
-
files[ modelFileName ] =
|
|
83
|
+
files[ modelFileName ] = strToU8( output );
|
|
75
84
|
output = null;
|
|
76
85
|
|
|
77
86
|
for ( const id in textures ) {
|
|
78
87
|
|
|
79
|
-
|
|
88
|
+
let texture = textures[ id ];
|
|
89
|
+
|
|
90
|
+
if ( texture.isCompressedTexture === true ) {
|
|
91
|
+
|
|
92
|
+
texture = decompress( texture );
|
|
93
|
+
|
|
94
|
+
}
|
|
80
95
|
|
|
81
96
|
const canvas = imageToCanvas( texture.image, texture.flipY );
|
|
82
97
|
const blob = await new Promise( resolve => canvas.toBlob( resolve, 'image/png', 1 ) );
|
|
@@ -112,7 +127,7 @@ class USDZExporter {
|
|
|
112
127
|
|
|
113
128
|
}
|
|
114
129
|
|
|
115
|
-
return
|
|
130
|
+
return zipSync( files, { level: 0 } );
|
|
116
131
|
|
|
117
132
|
}
|
|
118
133
|
|
|
@@ -212,7 +227,7 @@ function buildUSDFileAsString( dataToInsert ) {
|
|
|
212
227
|
|
|
213
228
|
let output = buildHeader();
|
|
214
229
|
output += dataToInsert;
|
|
215
|
-
return
|
|
230
|
+
return strToU8( output );
|
|
216
231
|
|
|
217
232
|
}
|
|
218
233
|
|
|
@@ -287,7 +302,7 @@ function buildMesh( geometry ) {
|
|
|
287
302
|
interpolation = "vertex"
|
|
288
303
|
)
|
|
289
304
|
point3f[] points = [${ buildVector3Array( attributes.position, count )}]
|
|
290
|
-
${ buildPrimvars( attributes
|
|
305
|
+
${ buildPrimvars( attributes ) }
|
|
291
306
|
uniform token subdivisionScheme = "none"
|
|
292
307
|
}
|
|
293
308
|
`;
|
|
@@ -356,14 +371,7 @@ function buildVector3Array( attribute, count ) {
|
|
|
356
371
|
|
|
357
372
|
}
|
|
358
373
|
|
|
359
|
-
function buildVector2Array( attribute
|
|
360
|
-
|
|
361
|
-
if ( attribute === undefined ) {
|
|
362
|
-
|
|
363
|
-
console.warn( 'USDZExporter: UVs missing.' );
|
|
364
|
-
return Array( count ).fill( '(0, 0)' ).join( ', ' );
|
|
365
|
-
|
|
366
|
-
}
|
|
374
|
+
function buildVector2Array( attribute ) {
|
|
367
375
|
|
|
368
376
|
const array = [];
|
|
369
377
|
|
|
@@ -380,7 +388,7 @@ function buildVector2Array( attribute, count ) {
|
|
|
380
388
|
|
|
381
389
|
}
|
|
382
390
|
|
|
383
|
-
function buildPrimvars( attributes
|
|
391
|
+
function buildPrimvars( attributes ) {
|
|
384
392
|
|
|
385
393
|
let string = '';
|
|
386
394
|
|
|
@@ -392,7 +400,7 @@ function buildPrimvars( attributes, count ) {
|
|
|
392
400
|
if ( attribute !== undefined ) {
|
|
393
401
|
|
|
394
402
|
string += `
|
|
395
|
-
texCoord2f[] primvars:st${ id } = [${ buildVector2Array( attribute
|
|
403
|
+
texCoord2f[] primvars:st${ id } = [${ buildVector2Array( attribute )}] (
|
|
396
404
|
interpolation = "vertex"
|
|
397
405
|
)`;
|
|
398
406
|
|
|
@@ -506,7 +514,7 @@ function buildMaterial( material, textures, quickLookCompatible = false ) {
|
|
|
506
514
|
asset inputs:file = @textures/Texture_${ id }.png@
|
|
507
515
|
float2 inputs:st.connect = </Materials/Material_${ material.id }/Transform2d_${ mapType }.outputs:result>
|
|
508
516
|
${ color !== undefined ? 'float4 inputs:scale = ' + buildColor4( color ) : '' }
|
|
509
|
-
token inputs:sourceColorSpace = "${ texture.colorSpace ===
|
|
517
|
+
token inputs:sourceColorSpace = "${ texture.colorSpace === NoColorSpace ? 'raw' : 'sRGB' }"
|
|
510
518
|
token inputs:wrapS = "${ WRAPPINGS[ texture.wrapS ] }"
|
|
511
519
|
token inputs:wrapT = "${ WRAPPINGS[ texture.wrapT ] }"
|
|
512
520
|
float outputs:r
|
|
@@ -519,7 +527,7 @@ function buildMaterial( material, textures, quickLookCompatible = false ) {
|
|
|
519
527
|
}
|
|
520
528
|
|
|
521
529
|
|
|
522
|
-
if ( material.side ===
|
|
530
|
+
if ( material.side === DoubleSide ) {
|
|
523
531
|
|
|
524
532
|
console.warn( 'THREE.USDZExporter: USDZ does not support double sided materials', material );
|
|
525
533
|
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Box3,
|
|
3
|
+
Float32BufferAttribute,
|
|
4
|
+
InstancedBufferGeometry,
|
|
5
|
+
InstancedBufferAttribute,
|
|
6
|
+
Sphere,
|
|
7
|
+
Vector3
|
|
8
|
+
} from 'three';
|
|
9
|
+
|
|
10
|
+
const _vector = new Vector3();
|
|
11
|
+
|
|
12
|
+
class InstancedPointsGeometry extends InstancedBufferGeometry {
|
|
13
|
+
|
|
14
|
+
constructor() {
|
|
15
|
+
|
|
16
|
+
super();
|
|
17
|
+
|
|
18
|
+
this.isInstancedPointsGeometry = true;
|
|
19
|
+
|
|
20
|
+
this.type = 'InstancedPointsGeometry';
|
|
21
|
+
|
|
22
|
+
const positions = [ - 1, 1, 0, 1, 1, 0, - 1, - 1, 0, 1, - 1, 0 ];
|
|
23
|
+
const uvs = [ - 1, 1, 1, 1, - 1, - 1, 1, - 1 ];
|
|
24
|
+
const index = [ 0, 2, 1, 2, 3, 1 ];
|
|
25
|
+
|
|
26
|
+
this.setIndex( index );
|
|
27
|
+
this.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
|
|
28
|
+
this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
applyMatrix4( matrix ) {
|
|
33
|
+
|
|
34
|
+
const pos = this.attributes.instancePosition;
|
|
35
|
+
|
|
36
|
+
if ( pos !== undefined ) {
|
|
37
|
+
|
|
38
|
+
pos.applyMatrix4( matrix );
|
|
39
|
+
|
|
40
|
+
pos.needsUpdate = true;
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if ( this.boundingBox !== null ) {
|
|
45
|
+
|
|
46
|
+
this.computeBoundingBox();
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if ( this.boundingSphere !== null ) {
|
|
51
|
+
|
|
52
|
+
this.computeBoundingSphere();
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return this;
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
setPositions( array ) {
|
|
61
|
+
|
|
62
|
+
let points;
|
|
63
|
+
|
|
64
|
+
if ( array instanceof Float32Array ) {
|
|
65
|
+
|
|
66
|
+
points = array;
|
|
67
|
+
|
|
68
|
+
} else if ( Array.isArray( array ) ) {
|
|
69
|
+
|
|
70
|
+
points = new Float32Array( array );
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this.setAttribute( 'instancePosition', new InstancedBufferAttribute( points, 3 ) ); // xyz
|
|
75
|
+
|
|
76
|
+
//
|
|
77
|
+
|
|
78
|
+
this.computeBoundingBox();
|
|
79
|
+
this.computeBoundingSphere();
|
|
80
|
+
|
|
81
|
+
return this;
|
|
82
|
+
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
setColors( array ) {
|
|
86
|
+
|
|
87
|
+
let colors;
|
|
88
|
+
|
|
89
|
+
if ( array instanceof Float32Array ) {
|
|
90
|
+
|
|
91
|
+
colors = array;
|
|
92
|
+
|
|
93
|
+
} else if ( Array.isArray( array ) ) {
|
|
94
|
+
|
|
95
|
+
colors = new Float32Array( array );
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
this.setAttribute( 'instanceColor', new InstancedBufferAttribute( colors, 3 ) ); // rgb
|
|
100
|
+
|
|
101
|
+
return this;
|
|
102
|
+
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
computeBoundingBox() {
|
|
106
|
+
|
|
107
|
+
if ( this.boundingBox === null ) {
|
|
108
|
+
|
|
109
|
+
this.boundingBox = new Box3();
|
|
110
|
+
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const pos = this.attributes.instancePosition;
|
|
114
|
+
|
|
115
|
+
if ( pos !== undefined ) {
|
|
116
|
+
|
|
117
|
+
this.boundingBox.setFromBufferAttribute( pos );
|
|
118
|
+
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
computeBoundingSphere() {
|
|
124
|
+
|
|
125
|
+
if ( this.boundingSphere === null ) {
|
|
126
|
+
|
|
127
|
+
this.boundingSphere = new Sphere();
|
|
128
|
+
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if ( this.boundingBox === null ) {
|
|
132
|
+
|
|
133
|
+
this.computeBoundingBox();
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const pos = this.attributes.instancePosition;
|
|
138
|
+
|
|
139
|
+
if ( pos !== undefined ) {
|
|
140
|
+
|
|
141
|
+
const center = this.boundingSphere.center;
|
|
142
|
+
|
|
143
|
+
this.boundingBox.getCenter( center );
|
|
144
|
+
|
|
145
|
+
let maxRadiusSq = 0;
|
|
146
|
+
|
|
147
|
+
for ( let i = 0, il = pos.count; i < il; i ++ ) {
|
|
148
|
+
|
|
149
|
+
_vector.fromBufferAttribute( pos, i );
|
|
150
|
+
maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector ) );
|
|
151
|
+
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
|
|
155
|
+
|
|
156
|
+
if ( isNaN( this.boundingSphere.radius ) ) {
|
|
157
|
+
|
|
158
|
+
console.error( 'THREE.InstancedPointsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.', this );
|
|
159
|
+
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
toJSON() {
|
|
167
|
+
|
|
168
|
+
// todo
|
|
169
|
+
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export default InstancedPointsGeometry;
|