@needle-tools/three 0.146.10 → 0.153.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/LICENSE +1 -1
- package/build/three.cjs +40124 -20919
- package/build/three.js +40120 -20914
- package/build/three.min.js +8 -6
- package/build/three.module.js +7298 -6003
- package/build/three.module.min.js +7 -0
- package/examples/jsm/animation/AnimationClipCreator.js +5 -3
- package/examples/jsm/cameras/CinematicCamera.js +1 -2
- package/examples/jsm/capabilities/WebGPU.js +17 -5
- package/examples/jsm/controls/ArcballControls.js +1828 -1821
- package/examples/jsm/controls/MapControls.js +28 -0
- package/examples/jsm/controls/OrbitControls.js +26 -53
- package/examples/jsm/controls/PointerLockControls.js +70 -65
- package/examples/jsm/controls/TrackballControls.js +18 -4
- package/examples/jsm/controls/TransformControls.js +0 -1
- package/examples/jsm/csm/CSM.js +11 -5
- package/examples/jsm/csm/CSMShader.js +7 -6
- package/examples/jsm/effects/AnaglyphEffect.js +6 -20
- package/examples/jsm/effects/AsciiEffect.js +3 -6
- package/examples/jsm/effects/OutlineEffect.js +1 -15
- package/examples/jsm/effects/ParallaxBarrierEffect.js +3 -0
- package/examples/jsm/exporters/DRACOExporter.js +53 -11
- package/examples/jsm/exporters/EXRExporter.js +3 -9
- package/examples/jsm/exporters/GLTFExporter.js +561 -154
- package/examples/jsm/exporters/KTX2Exporter.js +34 -23
- package/examples/jsm/exporters/MMDExporter.js +1 -1
- package/examples/jsm/exporters/PLYExporter.js +8 -1
- package/examples/jsm/exporters/STLExporter.js +8 -4
- package/examples/jsm/exporters/USDZExporter.js +305 -792
- package/examples/jsm/geometries/ConvexGeometry.js +0 -6
- package/examples/jsm/geometries/ParametricGeometry.js +10 -0
- package/examples/jsm/helpers/OctreeHelper.js +1 -0
- package/examples/jsm/helpers/ViewHelper.js +71 -57
- package/examples/jsm/interactive/HTMLMesh.js +16 -3
- package/examples/jsm/interactive/InteractiveGroup.js +1 -1
- package/examples/{js → jsm}/libs/basis/README.md +4 -4
- package/examples/jsm/libs/draco/draco_decoder.js +34 -0
- package/examples/jsm/libs/draco/draco_decoder.wasm +0 -0
- package/examples/jsm/libs/draco/draco_wasm_wrapper.js +117 -0
- package/examples/jsm/libs/draco/gltf/draco_decoder.js +33 -0
- package/examples/jsm/libs/draco/gltf/draco_decoder.wasm +0 -0
- package/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js +116 -0
- package/examples/jsm/libs/lil-gui.module.min.js +2 -2
- package/examples/jsm/libs/tween.module.js +803 -0
- package/examples/jsm/lights/IESSpotLight.js +25 -0
- package/examples/jsm/lights/LightProbeGenerator.js +11 -9
- package/examples/jsm/lines/LineSegments2.js +16 -10
- package/examples/jsm/loaders/3DMLoader.js +8 -5
- package/examples/jsm/loaders/3MFLoader.js +12 -11
- package/examples/jsm/loaders/AMFLoader.js +2 -3
- package/examples/jsm/loaders/BVHLoader.js +2 -2
- package/examples/jsm/loaders/ColladaLoader.js +15 -16
- package/examples/jsm/loaders/DRACOLoader.js +69 -18
- package/examples/jsm/loaders/EXRLoader.js +23 -24
- package/examples/jsm/loaders/FBXLoader.js +34 -50
- package/examples/jsm/loaders/GCodeLoader.js +1 -2
- package/examples/jsm/loaders/GLTFLoader.js +417 -895
- package/examples/jsm/loaders/GLTFLoaderAnimationPointer.js +684 -0
- package/examples/jsm/loaders/HDRCubeTextureLoader.js +4 -4
- package/examples/jsm/loaders/IESLoader.js +337 -0
- package/examples/jsm/loaders/KMZLoader.js +4 -4
- package/examples/jsm/loaders/KTX2Loader.js +145 -69
- package/examples/jsm/loaders/LDrawLoader.js +20 -18
- package/examples/jsm/loaders/LWOLoader.js +12 -29
- package/examples/jsm/loaders/LottieLoader.js +3 -1
- package/examples/jsm/loaders/MMDLoader.js +49 -18
- package/examples/jsm/loaders/MTLLoader.js +2 -2
- package/examples/jsm/loaders/MaterialXLoader.js +9 -3
- package/examples/jsm/loaders/NRRDLoader.js +33 -5
- package/examples/jsm/loaders/OBJLoader.js +1 -1
- package/examples/jsm/loaders/PCDLoader.js +26 -12
- package/examples/jsm/loaders/PDBLoader.js +7 -2
- package/examples/jsm/loaders/PLYLoader.js +254 -109
- package/examples/jsm/loaders/RGBELoader.js +3 -3
- package/examples/jsm/loaders/STLLoader.js +9 -5
- package/examples/jsm/loaders/SVGLoader.js +36 -27
- package/examples/jsm/loaders/TTFLoader.js +1 -8
- package/examples/jsm/loaders/TiltLoader.js +13 -7
- package/examples/jsm/loaders/USDZLoader.js +6 -6
- package/examples/jsm/loaders/VOXLoader.js +8 -2
- package/examples/jsm/loaders/VRMLLoader.js +44 -16
- package/examples/jsm/loaders/VTKLoader.js +19 -10
- package/examples/jsm/loaders/XYZLoader.js +9 -3
- package/examples/jsm/loaders/lwo/IFFParser.js +19 -19
- package/examples/jsm/materials/MeshGouraudMaterial.js +0 -3
- package/examples/jsm/math/ConvexHull.js +3 -3
- package/examples/jsm/math/Lut.js +5 -4
- package/examples/jsm/math/MeshSurfaceSampler.js +7 -9
- package/examples/jsm/math/Octree.js +1 -1
- package/examples/jsm/misc/ConvexObjectBreaker.js +2 -8
- package/examples/jsm/misc/GPUComputationRenderer.js +6 -5
- package/examples/jsm/misc/MD2Character.js +2 -2
- package/examples/jsm/misc/MD2CharacterComplex.js +2 -2
- package/examples/jsm/misc/ProgressiveLightMap.js +12 -10
- package/examples/jsm/misc/RollerCoaster.js +7 -1
- package/examples/jsm/misc/Volume.js +20 -5
- package/examples/jsm/misc/VolumeSlice.js +3 -1
- package/examples/jsm/modifiers/CurveModifier.js +1 -0
- package/examples/jsm/modifiers/TessellateModifier.js +19 -19
- package/examples/jsm/nodes/Nodes.js +144 -335
- package/examples/jsm/nodes/accessors/BitangentNode.js +43 -16
- package/examples/jsm/nodes/accessors/BufferAttributeNode.js +86 -0
- package/examples/jsm/nodes/accessors/BufferNode.js +6 -0
- package/examples/jsm/nodes/accessors/CameraNode.js +12 -2
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +27 -33
- package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +58 -0
- package/examples/jsm/nodes/accessors/InstanceNode.js +41 -26
- package/examples/jsm/nodes/accessors/MaterialNode.js +155 -38
- package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +16 -0
- package/examples/jsm/nodes/accessors/ModelNode.js +11 -0
- package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +13 -14
- package/examples/jsm/nodes/accessors/NormalNode.js +35 -19
- package/examples/jsm/nodes/accessors/Object3DNode.js +32 -12
- package/examples/jsm/nodes/accessors/PointUVNode.js +6 -1
- package/examples/jsm/nodes/accessors/PositionNode.js +38 -23
- package/examples/jsm/nodes/accessors/ReferenceNode.js +21 -14
- package/examples/jsm/nodes/accessors/ReflectVectorNode.js +11 -7
- package/examples/jsm/nodes/accessors/SkinningNode.js +43 -40
- package/examples/jsm/nodes/accessors/StorageBufferNode.js +6 -0
- package/examples/jsm/nodes/accessors/TangentNode.js +28 -20
- package/examples/jsm/nodes/accessors/TextureNode.js +80 -12
- package/examples/jsm/nodes/accessors/UVNode.js +6 -0
- package/examples/jsm/nodes/accessors/UserDataNode.js +6 -0
- package/examples/jsm/nodes/code/CodeNode.js +75 -0
- package/examples/jsm/nodes/code/ExpressionNode.js +37 -0
- package/examples/jsm/nodes/{core → code}/FunctionCallNode.js +15 -1
- package/examples/jsm/nodes/{core → code}/FunctionNode.js +8 -7
- package/examples/jsm/nodes/code/ScriptableNode.js +488 -0
- package/examples/jsm/nodes/code/ScriptableValueNode.js +167 -0
- package/examples/jsm/nodes/core/ArrayUniformNode.js +3 -0
- package/examples/jsm/nodes/core/AttributeNode.js +17 -9
- package/examples/jsm/nodes/core/BypassNode.js +9 -2
- package/examples/jsm/nodes/core/CacheNode.js +46 -0
- package/examples/jsm/nodes/core/ConstNode.js +3 -0
- package/examples/jsm/nodes/core/ContextNode.js +8 -1
- package/examples/jsm/nodes/core/InputNode.js +26 -5
- package/examples/jsm/nodes/core/InstanceIndexNode.js +26 -2
- package/examples/jsm/nodes/core/LightingModel.js +16 -0
- package/examples/jsm/nodes/core/Node.js +129 -35
- package/examples/jsm/nodes/core/NodeAttribute.js +2 -1
- package/examples/jsm/nodes/core/NodeBuilder.js +271 -121
- package/examples/jsm/nodes/core/NodeCache.js +26 -0
- package/examples/jsm/nodes/core/NodeFrame.js +56 -5
- package/examples/jsm/nodes/core/NodeUtils.js +115 -28
- package/examples/jsm/nodes/core/PropertyNode.js +19 -2
- package/examples/jsm/nodes/core/StackNode.js +99 -0
- package/examples/jsm/nodes/core/TempNode.js +11 -3
- package/examples/jsm/nodes/core/UniformNode.js +16 -1
- package/examples/jsm/nodes/core/VarNode.js +21 -29
- package/examples/jsm/nodes/core/VaryingNode.js +15 -2
- package/examples/jsm/nodes/core/constants.js +6 -0
- package/examples/jsm/nodes/display/BlendModeNode.js +25 -11
- package/examples/jsm/nodes/display/ColorAdjustmentNode.js +30 -14
- package/examples/jsm/nodes/display/ColorSpaceNode.js +39 -27
- package/examples/jsm/nodes/display/FrontFacingNode.js +7 -1
- package/examples/jsm/nodes/display/NormalMapNode.js +31 -18
- package/examples/jsm/nodes/display/PosterizeNode.js +10 -3
- package/examples/jsm/nodes/display/ToneMappingNode.js +101 -11
- package/examples/jsm/nodes/display/ViewportNode.js +27 -18
- package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +30 -0
- package/examples/jsm/nodes/display/ViewportTextureNode.js +67 -0
- package/examples/jsm/nodes/fog/FogExp2Node.js +35 -0
- package/examples/jsm/nodes/fog/FogNode.js +12 -6
- package/examples/jsm/nodes/fog/FogRangeNode.js +12 -5
- package/examples/jsm/nodes/functions/BSDF/BRDF_BlinnPhong.js +30 -0
- package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +10 -13
- package/examples/jsm/nodes/functions/BSDF/BRDF_Lambert.js +2 -2
- package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +8 -6
- package/examples/jsm/nodes/functions/BSDF/D_GGX.js +4 -4
- package/examples/jsm/nodes/functions/BSDF/F_Schlick.js +3 -3
- package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +7 -5
- package/examples/jsm/nodes/functions/PhongLightingModel.js +28 -0
- package/examples/jsm/nodes/functions/PhysicalLightingModel.js +35 -36
- package/examples/jsm/nodes/functions/material/getGeometryRoughness.js +4 -3
- package/examples/jsm/nodes/functions/material/getRoughness.js +4 -4
- package/examples/jsm/nodes/geometry/RangeNode.js +50 -55
- package/examples/jsm/nodes/gpgpu/ComputeNode.js +9 -2
- package/examples/jsm/nodes/lighting/AONode.js +5 -3
- package/examples/jsm/nodes/lighting/AmbientLightNode.js +27 -0
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +114 -5
- package/examples/jsm/nodes/lighting/DirectionalLightNode.js +43 -0
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +121 -35
- package/examples/jsm/nodes/lighting/HemisphereLightNode.js +15 -10
- package/examples/jsm/nodes/lighting/IESSpotLightNode.js +39 -0
- package/examples/jsm/nodes/lighting/LightNode.js +57 -0
- package/examples/jsm/nodes/lighting/LightUtils.js +17 -0
- package/examples/jsm/nodes/lighting/LightingContextNode.js +30 -8
- package/examples/jsm/nodes/lighting/LightingNode.js +3 -1
- package/examples/jsm/nodes/lighting/LightsNode.js +18 -10
- package/examples/jsm/nodes/lighting/PointLightNode.js +71 -0
- package/examples/jsm/nodes/lighting/SpotLightNode.js +92 -0
- package/examples/jsm/nodes/loaders/NodeLoader.js +5 -4
- package/examples/jsm/nodes/loaders/NodeMaterialLoader.js +4 -20
- package/examples/jsm/nodes/materials/LineBasicNodeMaterial.js +6 -9
- package/examples/jsm/nodes/materials/Materials.js +11 -55
- package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +5 -11
- package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +48 -0
- package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +74 -0
- package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +6 -6
- package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +21 -96
- package/examples/jsm/nodes/materials/NodeMaterial.js +284 -62
- package/examples/jsm/nodes/materials/PointsNodeMaterial.js +7 -1
- package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +29 -25
- package/examples/jsm/nodes/materialx/MaterialXNodes.js +31 -22
- package/examples/jsm/nodes/materialx/lib/mx_hsv.js +1 -1
- package/examples/jsm/nodes/materialx/lib/mx_noise.js +2 -1
- package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +2 -1
- package/examples/jsm/nodes/math/CondNode.js +43 -17
- package/examples/jsm/nodes/math/MathNode.js +178 -73
- package/examples/jsm/nodes/math/OperatorNode.js +52 -2
- package/examples/jsm/nodes/procedural/CheckerNode.js +14 -6
- package/examples/jsm/nodes/shadernode/ShaderNode.js +186 -63
- package/examples/jsm/nodes/utils/ArrayElementNode.js +4 -2
- package/examples/jsm/nodes/utils/ConvertNode.js +19 -1
- package/examples/jsm/nodes/utils/DiscardNode.js +26 -0
- package/examples/jsm/nodes/utils/EquirectUVNode.js +10 -4
- package/examples/jsm/nodes/utils/JoinNode.js +4 -1
- package/examples/jsm/nodes/utils/LoopNode.js +186 -0
- package/examples/jsm/nodes/utils/MatcapUVNode.js +11 -4
- package/examples/jsm/nodes/utils/MaxMipLevelNode.js +18 -5
- package/examples/jsm/nodes/utils/OscNode.js +21 -14
- package/examples/jsm/nodes/utils/PackingNode.js +55 -0
- package/examples/jsm/nodes/utils/RemapNode.js +13 -5
- package/examples/jsm/nodes/utils/RotateUVNode.js +18 -7
- package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +37 -0
- package/examples/jsm/nodes/utils/SplitNode.js +7 -5
- package/examples/jsm/nodes/utils/SpriteSheetUVNode.js +15 -30
- package/examples/jsm/nodes/utils/TimerNode.js +16 -6
- package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +21 -10
- package/examples/jsm/objects/GroundProjectedSkybox.js +172 -0
- package/examples/jsm/objects/Lensflare.js +3 -4
- package/examples/jsm/objects/MarchingCubes.js +5 -1
- package/examples/jsm/objects/Reflector.js +7 -4
- package/examples/jsm/objects/Refractor.js +4 -4
- package/examples/jsm/objects/ShadowMesh.js +3 -3
- package/examples/jsm/objects/Water.js +2 -1
- package/examples/jsm/physics/AmmoPhysics.js +27 -28
- package/examples/jsm/physics/RapierPhysics.js +199 -0
- package/examples/jsm/postprocessing/AfterimagePass.js +3 -2
- package/examples/jsm/postprocessing/BloomPass.js +7 -4
- package/examples/jsm/postprocessing/BokehPass.js +3 -8
- package/examples/jsm/postprocessing/DotScreenPass.js +1 -2
- package/examples/jsm/postprocessing/EffectComposer.js +5 -95
- package/examples/jsm/postprocessing/FilmPass.js +1 -2
- package/examples/jsm/postprocessing/GlitchPass.js +0 -2
- package/examples/jsm/postprocessing/HalftonePass.js +0 -6
- package/examples/jsm/postprocessing/OutlinePass.js +7 -7
- package/examples/jsm/postprocessing/OutputPass.js +72 -0
- package/examples/jsm/postprocessing/Pass.js +2 -0
- package/examples/jsm/postprocessing/RenderPixelatedPass.js +4 -3
- package/examples/jsm/postprocessing/SAOPass.js +4 -26
- package/examples/jsm/postprocessing/SMAAPass.js +5 -8
- package/examples/jsm/postprocessing/SSAARenderPass.js +15 -6
- package/examples/jsm/postprocessing/SSAOPass.js +4 -14
- package/examples/jsm/postprocessing/SSRPass.js +3 -7
- package/examples/jsm/postprocessing/SavePass.js +2 -3
- package/examples/jsm/postprocessing/ShaderPass.js +1 -0
- package/examples/jsm/postprocessing/TAARenderPass.js +3 -2
- package/examples/jsm/postprocessing/TexturePass.js +0 -2
- package/examples/jsm/postprocessing/UnrealBloomPass.js +4 -11
- package/examples/jsm/renderers/CSS2DRenderer.js +6 -1
- package/examples/jsm/renderers/CSS3DRenderer.js +27 -5
- package/examples/jsm/renderers/{webgpu/WebGPUAnimation.js → common/Animation.js} +4 -4
- package/examples/jsm/renderers/common/Attributes.js +75 -0
- package/examples/jsm/renderers/common/Backend.js +160 -0
- package/examples/jsm/renderers/common/Background.js +133 -0
- package/examples/jsm/renderers/common/Binding.js +11 -0
- package/examples/jsm/renderers/common/Bindings.js +169 -0
- package/examples/jsm/renderers/common/Buffer.js +38 -0
- package/examples/jsm/renderers/{webgpu/WebGPUBufferUtils.js → common/BufferUtils.js} +2 -2
- package/examples/jsm/renderers/common/ChainMap.js +89 -0
- package/examples/jsm/renderers/common/ComputePipeline.js +17 -0
- package/examples/jsm/renderers/common/Constants.js +14 -0
- package/examples/jsm/renderers/common/CubeRenderTarget.js +65 -0
- package/examples/jsm/renderers/common/DataMap.js +54 -0
- package/examples/jsm/renderers/common/Geometries.js +215 -0
- package/examples/jsm/renderers/{webgpu/WebGPUInfo.js → common/Info.js} +2 -3
- package/examples/jsm/renderers/common/Pipeline.js +13 -0
- package/examples/jsm/renderers/common/Pipelines.js +309 -0
- package/examples/jsm/renderers/common/ProgrammableStage.js +18 -0
- package/examples/jsm/renderers/common/RenderContext.js +37 -0
- package/examples/jsm/renderers/common/RenderContexts.js +38 -0
- package/examples/jsm/renderers/{webgpu/WebGPURenderLists.js → common/RenderList.js} +26 -47
- package/examples/jsm/renderers/common/RenderLists.js +38 -0
- package/examples/jsm/renderers/common/RenderObject.js +95 -0
- package/examples/jsm/renderers/common/RenderObjects.js +92 -0
- package/examples/jsm/renderers/common/RenderPipeline.js +16 -0
- package/examples/jsm/renderers/common/RenderTarget.js +15 -0
- package/examples/jsm/renderers/common/Renderer.js +822 -0
- package/examples/jsm/renderers/common/SampledTexture.js +80 -0
- package/examples/jsm/renderers/common/Sampler.js +18 -0
- package/examples/jsm/renderers/common/StorageBuffer.js +17 -0
- package/examples/jsm/renderers/common/Textures.js +206 -0
- package/examples/jsm/renderers/{webgpu/WebGPUUniform.js → common/Uniform.js} +13 -9
- package/examples/jsm/renderers/common/UniformBuffer.js +15 -0
- package/examples/jsm/renderers/{webgpu/WebGPUUniformsGroup.js → common/UniformsGroup.js} +13 -13
- package/examples/jsm/renderers/common/nodes/NodeRender.js +302 -0
- package/examples/jsm/renderers/{webgpu/nodes/WebGPUNodeSampledTexture.js → common/nodes/NodeSampledTexture.js} +4 -4
- package/examples/jsm/renderers/{webgpu/nodes/WebGPUNodeSampler.js → common/nodes/NodeSampler.js} +3 -3
- package/examples/jsm/renderers/{webgpu/nodes/WebGPUNodeUniform.js → common/nodes/NodeUniform.js} +1 -1
- package/examples/jsm/renderers/common/nodes/Nodes.js +319 -0
- package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +35 -31
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +765 -0
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +15 -987
- package/examples/jsm/renderers/webgpu/nodes/{WebGPUNodeBuilder.js → WGSLNodeBuilder.js} +117 -90
- package/examples/jsm/{nodes/parsers → renderers/webgpu/nodes}/WGSLNodeFunction.js +2 -2
- package/examples/jsm/{nodes/parsers → renderers/webgpu/nodes}/WGSLNodeParser.js +1 -1
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +251 -0
- package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +145 -0
- package/examples/jsm/renderers/webgpu/{constants.js → utils/WebGPUConstants.js} +73 -12
- package/examples/jsm/renderers/webgpu/{WebGPURenderPipeline.js → utils/WebGPUPipelineUtils.js} +135 -285
- package/examples/jsm/renderers/webgpu/{WebGPUTextureUtils.js → utils/WebGPUTextureMipmapUtils.js} +5 -25
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +855 -0
- package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +88 -0
- package/examples/jsm/shaders/BleachBypassShader.js +2 -0
- package/examples/jsm/shaders/BokehShader2.js +3 -0
- package/examples/jsm/shaders/ColorifyShader.js +2 -0
- package/examples/jsm/shaders/ConvolutionShader.js +2 -0
- package/examples/jsm/shaders/CopyShader.js +2 -0
- package/examples/jsm/shaders/DotScreenShader.js +2 -0
- package/examples/jsm/shaders/ExposureShader.js +44 -0
- package/examples/jsm/shaders/FilmShader.js +2 -0
- package/examples/jsm/shaders/GammaCorrectionShader.js +2 -0
- package/examples/jsm/shaders/HorizontalBlurShader.js +2 -0
- package/examples/jsm/shaders/MMDToonShader.js +15 -4
- package/examples/jsm/shaders/OutputShader.js +61 -0
- package/examples/jsm/shaders/RGBShiftShader.js +4 -2
- package/examples/jsm/shaders/SepiaShader.js +2 -0
- package/examples/jsm/shaders/ToonShader.js +13 -5
- package/examples/jsm/shaders/VelocityShader.js +1 -1
- package/examples/jsm/shaders/VerticalBlurShader.js +2 -0
- package/examples/jsm/shaders/VignetteShader.js +2 -0
- package/examples/jsm/shaders/WaterRefractionShader.js +5 -2
- package/examples/jsm/utils/BufferGeometryUtils.js +54 -36
- package/examples/jsm/utils/LDrawUtils.js +4 -4
- package/examples/jsm/utils/PackedPhongMaterial.js +5 -78
- package/examples/jsm/utils/SceneUtils.js +8 -4
- package/examples/jsm/utils/SkeletonUtils.js +27 -210
- package/examples/jsm/utils/TextureUtils.js +41 -40
- package/examples/jsm/webxr/VRButton.js +1 -2
- package/examples/jsm/webxr/XRButton.js +198 -0
- package/examples/jsm/webxr/XRHandPrimitiveModel.js +1 -0
- package/examples/jsm/webxr/XRPlanes.js +100 -0
- package/package.json +34 -87
- package/src/Three.Legacy.js +19 -110
- package/src/Three.js +4 -3
- package/src/animation/AnimationUtils.js +13 -1
- package/src/audio/Audio.js +7 -2
- package/src/audio/PositionalAudio.js +8 -0
- package/src/cameras/Camera.js +5 -0
- package/src/cameras/CubeCamera.js +76 -13
- package/src/cameras/OrthographicCamera.js +1 -1
- package/src/cameras/PerspectiveCamera.js +1 -1
- package/src/constants.js +22 -2
- package/src/core/BufferAttribute.js +150 -9
- package/src/core/BufferGeometry.js +4 -10
- package/src/core/GLBufferAttribute.js +2 -0
- package/src/core/InterleavedBufferAttribute.js +5 -5
- package/src/core/Object3D.js +37 -8
- package/src/extras/DataUtils.js +7 -1
- package/src/extras/ImageUtils.js +2 -2
- package/src/extras/PMREMGenerator.js +5 -5
- package/src/extras/core/Curve.js +1 -1
- package/src/extras/curves/LineCurve.js +6 -4
- package/src/extras/curves/LineCurve3.js +13 -0
- package/src/geometries/BoxGeometry.js +10 -0
- package/src/geometries/CircleGeometry.js +11 -1
- package/src/geometries/ConeGeometry.js +1 -1
- package/src/geometries/CylinderGeometry.js +11 -1
- package/src/geometries/EdgesGeometry.js +10 -0
- package/src/geometries/ExtrudeGeometry.js +11 -1
- package/src/geometries/LatheGeometry.js +10 -0
- package/src/geometries/PlaneGeometry.js +10 -0
- package/src/geometries/PolyhedronGeometry.js +11 -1
- package/src/geometries/RingGeometry.js +11 -1
- package/src/geometries/ShapeGeometry.js +11 -1
- package/src/geometries/SphereGeometry.js +12 -2
- package/src/geometries/TorusGeometry.js +11 -1
- package/src/geometries/TorusKnotGeometry.js +10 -0
- package/src/geometries/TubeGeometry.js +10 -0
- package/src/geometries/WireframeGeometry.js +10 -0
- package/src/helpers/Box3Helper.js +1 -2
- package/src/lights/DirectionalLight.js +1 -1
- package/src/lights/HemisphereLight.js +1 -1
- package/src/lights/SpotLight.js +1 -1
- package/src/loaders/AudioLoader.js +14 -8
- package/src/loaders/CubeTextureLoader.js +2 -0
- package/src/loaders/DataTextureLoader.js +5 -1
- package/src/loaders/MaterialLoader.js +8 -0
- package/src/loaders/ObjectLoader.js +10 -2
- package/src/materials/LineBasicMaterial.js +4 -0
- package/src/materials/Material.js +16 -4
- package/src/materials/MeshDistanceMaterial.js +0 -9
- package/src/materials/MeshPhysicalMaterial.js +32 -6
- package/src/materials/ShaderMaterial.js +6 -1
- package/src/math/Box2.js +3 -2
- package/src/math/Box3.js +49 -64
- package/src/math/Color.js +88 -66
- package/src/math/ColorManagement.js +75 -16
- package/src/math/Euler.js +2 -11
- package/src/math/Frustum.js +29 -5
- package/src/math/MathUtils.js +43 -1
- package/src/math/Matrix3.js +26 -6
- package/src/math/Matrix4.js +74 -19
- package/src/math/Plane.js +2 -2
- package/src/math/Quaternion.js +6 -0
- package/src/math/Ray.js +7 -7
- package/src/math/Triangle.js +37 -7
- package/src/math/Vector2.js +16 -0
- package/src/math/Vector3.js +10 -0
- package/src/math/interpolants/CubicInterpolant.js +1 -2
- package/src/objects/InstancedMesh.js +82 -1
- package/src/objects/Mesh.js +108 -76
- package/src/objects/Skeleton.js +1 -1
- package/src/objects/SkinnedMesh.js +123 -8
- package/src/objects/Sprite.js +1 -1
- package/src/renderers/WebGLCubeRenderTarget.js +12 -3
- package/src/renderers/WebGLMultipleRenderTargets.js +4 -2
- package/src/renderers/WebGLRenderTarget.js +14 -2
- package/src/renderers/WebGLRenderer.js +1433 -1236
- package/src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/aomap_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/bsdfs.glsl.js +0 -271
- package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +5 -5
- package/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_maps.glsl.js +2 -10
- package/src/renderers/shaders/ShaderChunk/clearcoat_pars_fragment.glsl.js +5 -5
- package/src/renderers/shaders/ShaderChunk/common.glsl.js +32 -0
- package/src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +26 -3
- package/src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +3 -3
- package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +10 -2
- package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +11 -11
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +39 -13
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +306 -10
- package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -10
- package/src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl.js +9 -1
- package/src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl.js +10 -2
- package/src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +32 -10
- package/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js +5 -13
- package/src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/output_fragment.glsl.js +1 -2
- package/src/renderers/shaders/ShaderChunk/packing.glsl.js +11 -5
- package/src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +4 -11
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +39 -34
- package/src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +5 -5
- package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +101 -16
- package/src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl.js +113 -1
- package/src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl.js +134 -6
- package/src/renderers/shaders/ShaderChunk/uv_vertex.glsl.js +116 -1
- package/src/renderers/shaders/ShaderChunk.js +0 -6
- package/src/renderers/shaders/ShaderLib/background.glsl.js +0 -8
- package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +5 -0
- package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +1 -4
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +0 -3
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +3 -3
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +0 -3
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +16 -12
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +0 -3
- package/src/renderers/shaders/ShaderLib/points.glsl.js +13 -0
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +5 -0
- package/src/renderers/shaders/ShaderLib.js +18 -4
- package/src/renderers/shaders/UniformsLib.js +27 -15
- package/src/renderers/shaders/UniformsUtils.js +12 -3
- package/src/renderers/webgl/WebGLBackground.js +23 -12
- package/src/renderers/webgl/WebGLBindingStates.js +13 -5
- package/src/renderers/webgl/WebGLCapabilities.js +1 -2
- package/src/renderers/webgl/WebGLClipping.js +7 -3
- package/src/renderers/webgl/WebGLGeometries.js +12 -0
- package/src/renderers/webgl/WebGLInfo.js +0 -1
- package/src/renderers/webgl/WebGLLights.js +2 -2
- package/src/renderers/webgl/WebGLMaterials.js +123 -234
- package/src/renderers/webgl/WebGLMorphtargets.js +1 -1
- package/src/renderers/webgl/WebGLProgram.js +130 -48
- package/src/renderers/webgl/WebGLPrograms.js +210 -130
- package/src/renderers/webgl/WebGLRenderStates.js +2 -2
- package/src/renderers/webgl/WebGLShadowMap.js +40 -27
- package/src/renderers/webgl/WebGLState.js +23 -9
- package/src/renderers/webgl/WebGLTextures.js +39 -19
- package/src/renderers/webgl/WebGLUniformsGroups.js +74 -33
- package/src/renderers/webgl/WebGLUtils.js +41 -29
- package/src/renderers/webxr/WebXRController.js +3 -0
- package/src/renderers/webxr/WebXRManager.js +89 -141
- package/src/scenes/Scene.js +4 -6
- package/src/textures/CompressedTexture.js +2 -2
- package/src/textures/CubeTexture.js +2 -2
- package/src/textures/DataTexture.js +2 -2
- package/src/textures/DepthTexture.js +22 -0
- package/src/textures/FramebufferTexture.js +1 -3
- package/src/textures/Source.js +4 -0
- package/src/textures/Texture.js +43 -13
- package/src/utils.js +13 -1
- package/examples/fonts/open-sans/open-sans-v15-cyrillic-ext_greek_greek-ext_cyrillic_latin_latin-ext_vietnamese-regular.woff +0 -0
- package/examples/fonts/open-sans/open-sans-v15-cyrillic-ext_greek_greek-ext_cyrillic_latin_latin-ext_vietnamese-regular.woff2 +0 -0
- package/examples/fonts/open-sans/open-sans.css +0 -9
- package/examples/fonts/tabler-icons/fonts/tabler-icons.eot +0 -0
- package/examples/fonts/tabler-icons/fonts/tabler-icons.svg +0 -3966
- package/examples/fonts/tabler-icons/fonts/tabler-icons.ttf +0 -0
- package/examples/fonts/tabler-icons/fonts/tabler-icons.woff +0 -0
- package/examples/fonts/tabler-icons/fonts/tabler-icons.woff2 +0 -0
- package/examples/fonts/tabler-icons/tabler-icons.min.css +0 -4
- package/examples/js/animation/AnimationClipCreator.js +0 -89
- package/examples/js/animation/CCDIKSolver.js +0 -416
- package/examples/js/animation/MMDAnimationHelper.js +0 -1046
- package/examples/js/animation/MMDPhysics.js +0 -1174
- package/examples/js/cameras/CinematicCamera.js +0 -168
- package/examples/js/controls/ArcballControls.js +0 -2770
- package/examples/js/controls/DragControls.js +0 -205
- package/examples/js/controls/FirstPersonControls.js +0 -312
- package/examples/js/controls/FlyControls.js +0 -321
- package/examples/js/controls/OrbitControls.js +0 -1065
- package/examples/js/controls/PointerLockControls.js +0 -144
- package/examples/js/controls/TrackballControls.js +0 -729
- package/examples/js/controls/TransformControls.js +0 -1301
- package/examples/js/csm/CSM.js +0 -347
- package/examples/js/csm/CSMFrustum.js +0 -127
- package/examples/js/csm/CSMHelper.js +0 -165
- package/examples/js/csm/CSMShader.js +0 -253
- package/examples/js/curves/CurveExtras.js +0 -348
- package/examples/js/curves/NURBSCurve.js +0 -63
- package/examples/js/curves/NURBSSurface.js +0 -48
- package/examples/js/curves/NURBSUtils.js +0 -439
- package/examples/js/effects/AnaglyphEffect.js +0 -86
- package/examples/js/effects/AsciiEffect.js +0 -260
- package/examples/js/effects/OutlineEffect.js +0 -450
- package/examples/js/effects/ParallaxBarrierEffect.js +0 -62
- package/examples/js/effects/PeppersGhostEffect.js +0 -139
- package/examples/js/effects/StereoEffect.js +0 -46
- package/examples/js/environments/DebugEnvironment.js +0 -53
- package/examples/js/environments/RoomEnvironment.js +0 -124
- package/examples/js/exporters/ColladaExporter.js +0 -487
- package/examples/js/exporters/DRACOExporter.js +0 -212
- package/examples/js/exporters/EXRExporter.js +0 -455
- package/examples/js/exporters/GLTFExporter.js +0 -2425
- package/examples/js/exporters/MMDExporter.js +0 -187
- package/examples/js/exporters/OBJExporter.js +0 -260
- package/examples/js/exporters/PLYExporter.js +0 -427
- package/examples/js/exporters/STLExporter.js +0 -188
- package/examples/js/exporters/USDZExporter.js +0 -608
- package/examples/js/geometries/BoxLineGeometry.js +0 -59
- package/examples/js/geometries/ConvexGeometry.js +0 -53
- package/examples/js/geometries/DecalGeometry.js +0 -324
- package/examples/js/geometries/LightningStrike.js +0 -861
- package/examples/js/geometries/ParametricGeometries.js +0 -216
- package/examples/js/geometries/ParametricGeometry.js +0 -121
- package/examples/js/geometries/RoundedBoxGeometry.js +0 -142
- package/examples/js/geometries/TeapotGeometry.js +0 -335
- package/examples/js/geometries/TextGeometry.js +0 -53
- package/examples/js/helpers/LightProbeHelper.js +0 -48
- package/examples/js/helpers/OctreeHelper.js +0 -76
- package/examples/js/helpers/PositionalAudioHelper.js +0 -91
- package/examples/js/helpers/RectAreaLightHelper.js +0 -73
- package/examples/js/helpers/VertexNormalsHelper.js +0 -74
- package/examples/js/helpers/VertexTangentsHelper.js +0 -68
- package/examples/js/helpers/ViewHelper.js +0 -281
- package/examples/js/interactive/HTMLMesh.js +0 -497
- package/examples/js/interactive/InteractiveGroup.js +0 -95
- package/examples/js/interactive/SelectionBox.js +0 -195
- package/examples/js/interactive/SelectionHelper.js +0 -83
- package/examples/js/libs/chevrotain.min.js +0 -3
- package/examples/js/libs/draco/draco_decoder.js +0 -52
- package/examples/js/libs/draco/draco_decoder.wasm +0 -0
- package/examples/js/libs/draco/draco_wasm_wrapper.js +0 -104
- package/examples/js/libs/draco/gltf/draco_decoder.js +0 -48
- package/examples/js/libs/draco/gltf/draco_decoder.wasm +0 -0
- package/examples/js/libs/draco/gltf/draco_wasm_wrapper.js +0 -104
- package/examples/js/libs/fflate.min.js +0 -7
- package/examples/js/libs/ktx-parse.umd.js +0 -1
- package/examples/js/libs/meshopt_decoder.js +0 -188
- package/examples/js/libs/opentype.min.js +0 -1
- package/examples/js/libs/stats.min.js +0 -5
- package/examples/js/lights/LightProbeGenerator.js +0 -221
- package/examples/js/lights/RectAreaLightUniformsLib.js +0 -60
- package/examples/js/lines/Line2.js +0 -19
- package/examples/js/lines/LineGeometry.js +0 -69
- package/examples/js/lines/LineMaterial.js +0 -635
- package/examples/js/lines/LineSegments2.js +0 -311
- package/examples/js/lines/LineSegmentsGeometry.js +0 -198
- package/examples/js/lines/Wireframe.js +0 -47
- package/examples/js/lines/WireframeGeometry2.js +0 -20
- package/examples/js/loaders/3DMLoader.js +0 -1273
- package/examples/js/loaders/3MFLoader.js +0 -1306
- package/examples/js/loaders/AMFLoader.js +0 -504
- package/examples/js/loaders/BVHLoader.js +0 -395
- package/examples/js/loaders/BasisTextureLoader.js +0 -706
- package/examples/js/loaders/ColladaLoader.js +0 -3663
- package/examples/js/loaders/DDSLoader.js +0 -244
- package/examples/js/loaders/DRACOLoader.js +0 -511
- package/examples/js/loaders/EXRLoader.js +0 -2039
- package/examples/js/loaders/FBXLoader.js +0 -3680
- package/examples/js/loaders/FontLoader.js +0 -160
- package/examples/js/loaders/GCodeLoader.js +0 -255
- package/examples/js/loaders/GLTFLoader.js +0 -4108
- package/examples/js/loaders/HDRCubeTextureLoader.js +0 -87
- package/examples/js/loaders/KMZLoader.js +0 -121
- package/examples/js/loaders/KTXLoader.js +0 -159
- package/examples/js/loaders/LDrawLoader.js +0 -2263
- package/examples/js/loaders/LUT3dlLoader.js +0 -135
- package/examples/js/loaders/LUTCubeLoader.js +0 -132
- package/examples/js/loaders/LWOLoader.js +0 -901
- package/examples/js/loaders/LogLuvLoader.js +0 -715
- package/examples/js/loaders/LottieLoader.js +0 -62
- package/examples/js/loaders/MD2Loader.js +0 -248
- package/examples/js/loaders/MDDLoader.js +0 -91
- package/examples/js/loaders/MMDLoader.js +0 -1915
- package/examples/js/loaders/MTLLoader.js +0 -472
- package/examples/js/loaders/MaterialXLoader.js +0 -392
- package/examples/js/loaders/NRRDLoader.js +0 -609
- package/examples/js/loaders/OBJLoader.js +0 -789
- package/examples/js/loaders/PCDLoader.js +0 -413
- package/examples/js/loaders/PDBLoader.js +0 -317
- package/examples/js/loaders/PLYLoader.js +0 -532
- package/examples/js/loaders/PRWMLoader.js +0 -249
- package/examples/js/loaders/PVRLoader.js +0 -218
- package/examples/js/loaders/RGBELoader.js +0 -442
- package/examples/js/loaders/RGBMLoader.js +0 -1354
- package/examples/js/loaders/STLLoader.js +0 -364
- package/examples/js/loaders/SVGLoader.js +0 -2783
- package/examples/js/loaders/TDSLoader.js +0 -992
- package/examples/js/loaders/TGALoader.js +0 -484
- package/examples/js/loaders/TIFFLoader.js +0 -30
- package/examples/js/loaders/TTFLoader.js +0 -203
- package/examples/js/loaders/TiltLoader.js +0 -459
- package/examples/js/loaders/VOXLoader.js +0 -240
- package/examples/js/loaders/VRMLLoader.js +0 -3140
- package/examples/js/loaders/VTKLoader.js +0 -1078
- package/examples/js/loaders/XYZLoader.js +0 -89
- package/examples/js/loaders/lwo/IFFParser.js +0 -1067
- package/examples/js/loaders/lwo/LWO2Parser.js +0 -397
- package/examples/js/loaders/lwo/LWO3Parser.js +0 -360
- package/examples/js/materials/MeshGouraudMaterial.js +0 -387
- package/examples/js/math/Capsule.js +0 -103
- package/examples/js/math/ColorConverter.js +0 -33
- package/examples/js/math/ConvexHull.js +0 -1154
- package/examples/js/math/ImprovedNoise.js +0 -66
- package/examples/js/math/Lut.js +0 -164
- package/examples/js/math/MeshSurfaceSampler.js +0 -171
- package/examples/js/math/OBB.js +0 -382
- package/examples/js/math/Octree.js +0 -410
- package/examples/js/math/SimplexNoise.js +0 -445
- package/examples/js/misc/ConvexObjectBreaker.js +0 -474
- package/examples/js/misc/GPUComputationRenderer.js +0 -393
- package/examples/js/misc/Gyroscope.js +0 -56
- package/examples/js/misc/MD2Character.js +0 -235
- package/examples/js/misc/MD2CharacterComplex.js +0 -513
- package/examples/js/misc/MorphAnimMesh.js +0 -63
- package/examples/js/misc/MorphBlendMesh.js +0 -265
- package/examples/js/misc/ProgressiveLightMap.js +0 -335
- package/examples/js/misc/RollerCoaster.js +0 -430
- package/examples/js/misc/TubePainter.js +0 -167
- package/examples/js/misc/Volume.js +0 -437
- package/examples/js/misc/VolumeSlice.js +0 -214
- package/examples/js/modifiers/CurveModifier.js +0 -309
- package/examples/js/modifiers/EdgeSplitModifier.js +0 -228
- package/examples/js/modifiers/SimplifyModifier.js +0 -465
- package/examples/js/modifiers/TessellateModifier.js +0 -276
- package/examples/js/objects/GroundProjectedEnv.js +0 -181
- package/examples/js/objects/Lensflare.js +0 -356
- package/examples/js/objects/LightningStorm.js +0 -206
- package/examples/js/objects/MarchingCubes.js +0 -759
- package/examples/js/objects/Reflector.js +0 -216
- package/examples/js/objects/ReflectorForSSRPass.js +0 -315
- package/examples/js/objects/Refractor.js +0 -283
- package/examples/js/objects/ShadowMesh.js +0 -59
- package/examples/js/objects/Sky.js +0 -218
- package/examples/js/objects/Water.js +0 -292
- package/examples/js/objects/Water2.js +0 -307
- package/examples/js/physics/AmmoPhysics.js +0 -259
- package/examples/js/physics/OimoPhysics.js +0 -217
- package/examples/js/postprocessing/AdaptiveToneMappingPass.js +0 -335
- package/examples/js/postprocessing/AfterimagePass.js +0 -77
- package/examples/js/postprocessing/BloomPass.js +0 -135
- package/examples/js/postprocessing/BokehPass.js +0 -120
- package/examples/js/postprocessing/ClearPass.js +0 -39
- package/examples/js/postprocessing/CubeTexturePass.js +0 -60
- package/examples/js/postprocessing/DotScreenPass.js +0 -51
- package/examples/js/postprocessing/EffectComposer.js +0 -272
- package/examples/js/postprocessing/FilmPass.js +0 -52
- package/examples/js/postprocessing/GlitchPass.js +0 -104
- package/examples/js/postprocessing/HalftonePass.js +0 -75
- package/examples/js/postprocessing/LUTPass.js +0 -171
- package/examples/js/postprocessing/MaskPass.js +0 -95
- package/examples/js/postprocessing/OutlinePass.js +0 -598
- package/examples/js/postprocessing/Pass.js +0 -72
- package/examples/js/postprocessing/RenderPass.js +0 -70
- package/examples/js/postprocessing/SAOPass.js +0 -374
- package/examples/js/postprocessing/SMAAPass.js +0 -170
- package/examples/js/postprocessing/SSAARenderPass.js +0 -156
- package/examples/js/postprocessing/SSAOPass.js +0 -365
- package/examples/js/postprocessing/SSRPass.js +0 -567
- package/examples/js/postprocessing/SavePass.js +0 -59
- package/examples/js/postprocessing/ShaderPass.js +0 -64
- package/examples/js/postprocessing/TAARenderPass.js +0 -130
- package/examples/js/postprocessing/TexturePass.js +0 -49
- package/examples/js/postprocessing/UnrealBloomPass.js +0 -375
- package/examples/js/renderers/CSS2DRenderer.js +0 -178
- package/examples/js/renderers/CSS3DRenderer.js +0 -237
- package/examples/js/renderers/Projector.js +0 -818
- package/examples/js/renderers/SVGRenderer.js +0 -491
- package/examples/js/shaders/ACESFilmicToneMappingShader.js +0 -89
- package/examples/js/shaders/AfterimageShader.js +0 -60
- package/examples/js/shaders/BasicShader.js +0 -27
- package/examples/js/shaders/BleachBypassShader.js +0 -62
- package/examples/js/shaders/BlendShader.js +0 -54
- package/examples/js/shaders/BokehShader.js +0 -156
- package/examples/js/shaders/BokehShader2.js +0 -419
- package/examples/js/shaders/BrightnessContrastShader.js +0 -58
- package/examples/js/shaders/ColorCorrectionShader.js +0 -52
- package/examples/js/shaders/ColorifyShader.js +0 -47
- package/examples/js/shaders/ConvolutionShader.js +0 -92
- package/examples/js/shaders/CopyShader.js +0 -45
- package/examples/js/shaders/DOFMipMapShader.js +0 -60
- package/examples/js/shaders/DepthLimitedBlurShader.js +0 -173
- package/examples/js/shaders/DigitalGlitch.js +0 -127
- package/examples/js/shaders/DotScreenShader.js +0 -72
- package/examples/js/shaders/FXAAShader.js +0 -284
- package/examples/js/shaders/FilmShader.js +0 -110
- package/examples/js/shaders/FocusShader.js +0 -95
- package/examples/js/shaders/FreiChenShader.js +0 -93
- package/examples/js/shaders/GammaCorrectionShader.js +0 -41
- package/examples/js/shaders/GodRaysShader.js +0 -284
- package/examples/js/shaders/HalftoneShader.js +0 -336
- package/examples/js/shaders/HorizontalBlurShader.js +0 -59
- package/examples/js/shaders/HorizontalTiltShiftShader.js +0 -65
- package/examples/js/shaders/HueSaturationShader.js +0 -69
- package/examples/js/shaders/KaleidoShader.js +0 -60
- package/examples/js/shaders/LuminosityHighPassShader.js +0 -67
- package/examples/js/shaders/LuminosityShader.js +0 -46
- package/examples/js/shaders/MMDToonShader.js +0 -96
- package/examples/js/shaders/MirrorShader.js +0 -56
- package/examples/js/shaders/NormalMapShader.js +0 -55
- package/examples/js/shaders/RGBShiftShader.js +0 -56
- package/examples/js/shaders/SAOShader.js +0 -209
- package/examples/js/shaders/SMAAShader.js +0 -454
- package/examples/js/shaders/SSAOShader.js +0 -295
- package/examples/js/shaders/SSRShader.js +0 -381
- package/examples/js/shaders/SepiaShader.js +0 -52
- package/examples/js/shaders/SobelOperatorShader.js +0 -88
- package/examples/js/shaders/SubsurfaceScatteringShader.js +0 -49
- package/examples/js/shaders/TechnicolorShader.js +0 -43
- package/examples/js/shaders/ToneMapShader.js +0 -84
- package/examples/js/shaders/ToonShader.js +0 -335
- package/examples/js/shaders/TriangleBlurShader.js +0 -70
- package/examples/js/shaders/UnpackDepthRGBAShader.js +0 -47
- package/examples/js/shaders/VelocityShader.js +0 -126
- package/examples/js/shaders/VerticalBlurShader.js +0 -59
- package/examples/js/shaders/VerticalTiltShiftShader.js +0 -65
- package/examples/js/shaders/VignetteShader.js +0 -53
- package/examples/js/shaders/VolumeShader.js +0 -296
- package/examples/js/shaders/WaterRefractionShader.js +0 -84
- package/examples/js/textures/FlakesTexture.js +0 -40
- package/examples/js/utils/BufferGeometryUtils.js +0 -1160
- package/examples/js/utils/CameraUtils.js +0 -71
- package/examples/js/utils/GPUStatsPanel.js +0 -125
- package/examples/js/utils/GeometryCompressionUtils.js +0 -549
- package/examples/js/utils/GeometryUtils.js +0 -168
- package/examples/js/utils/LDrawUtils.js +0 -179
- package/examples/js/utils/PackedPhongMaterial.js +0 -109
- package/examples/js/utils/SceneUtils.js +0 -214
- package/examples/js/utils/ShadowMapViewer.js +0 -183
- package/examples/js/utils/SkeletonUtils.js +0 -493
- package/examples/js/utils/UVsDebug.js +0 -143
- package/examples/js/utils/WorkerPool.js +0 -105
- package/examples/jsm/exporters/ColladaExporter.js +0 -713
- package/examples/jsm/geometries/LightningStrike.js +0 -1017
- package/examples/jsm/libs/OimoPhysics/OimoPhysics.js +0 -37071
- package/examples/jsm/libs/OimoPhysics/index.js +0 -43
- package/examples/jsm/libs/flow.module.js +0 -4552
- package/examples/jsm/libs/tween.module.min.js +0 -3
- package/examples/jsm/loaders/BasisTextureLoader.js +0 -790
- package/examples/jsm/loaders/IFCLoader.js +0 -2431
- package/examples/jsm/loaders/PRWMLoader.js +0 -299
- package/examples/jsm/loaders/ifc/web-ifc-api.js +0 -47504
- package/examples/jsm/loaders/ifc/web-ifc.wasm +0 -0
- package/examples/jsm/node-editor/NodeEditor.js +0 -857
- package/examples/jsm/node-editor/accessors/MatcapUVEditor.js +0 -14
- package/examples/jsm/node-editor/accessors/NormalEditor.js +0 -30
- package/examples/jsm/node-editor/accessors/PositionEditor.js +0 -30
- package/examples/jsm/node-editor/accessors/UVEditor.js +0 -25
- package/examples/jsm/node-editor/core/BaseNode.js +0 -96
- package/examples/jsm/node-editor/core/DataFile.js +0 -59
- package/examples/jsm/node-editor/core/FileEditor.js +0 -20
- package/examples/jsm/node-editor/core/FileURLEditor.js +0 -29
- package/examples/jsm/node-editor/display/BlendEditor.js +0 -44
- package/examples/jsm/node-editor/display/NormalMapEditor.js +0 -49
- package/examples/jsm/node-editor/examples/animate-uv.json +0 -1
- package/examples/jsm/node-editor/examples/fake-top-light.json +0 -1
- package/examples/jsm/node-editor/examples/matcap.json +0 -1
- package/examples/jsm/node-editor/examples/oscillator-color.json +0 -1
- package/examples/jsm/node-editor/examples/rim.json +0 -1
- package/examples/jsm/node-editor/inputs/ColorEditor.js +0 -96
- package/examples/jsm/node-editor/inputs/FloatEditor.js +0 -23
- package/examples/jsm/node-editor/inputs/SliderEditor.js +0 -67
- package/examples/jsm/node-editor/inputs/TextureEditor.js +0 -155
- package/examples/jsm/node-editor/inputs/Vector2Editor.js +0 -28
- package/examples/jsm/node-editor/inputs/Vector3Editor.js +0 -30
- package/examples/jsm/node-editor/inputs/Vector4Editor.js +0 -37
- package/examples/jsm/node-editor/materials/BasicMaterialEditor.js +0 -84
- package/examples/jsm/node-editor/materials/PointsMaterialEditor.js +0 -102
- package/examples/jsm/node-editor/materials/StandardMaterialEditor.js +0 -118
- package/examples/jsm/node-editor/math/AngleEditor.js +0 -40
- package/examples/jsm/node-editor/math/DotEditor.js +0 -35
- package/examples/jsm/node-editor/math/InvertEditor.js +0 -39
- package/examples/jsm/node-editor/math/LimiterEditor.js +0 -62
- package/examples/jsm/node-editor/math/NormalizeEditor.js +0 -28
- package/examples/jsm/node-editor/math/OperatorEditor.js +0 -63
- package/examples/jsm/node-editor/math/PowerEditor.js +0 -44
- package/examples/jsm/node-editor/math/TrigonometryEditor.js +0 -45
- package/examples/jsm/node-editor/procedural/CheckerEditor.js +0 -27
- package/examples/jsm/node-editor/scene/MeshEditor.js +0 -102
- package/examples/jsm/node-editor/scene/Object3DEditor.js +0 -160
- package/examples/jsm/node-editor/scene/PointsEditor.js +0 -99
- package/examples/jsm/node-editor/utils/JoinEditor.js +0 -58
- package/examples/jsm/node-editor/utils/OscillatorEditor.js +0 -43
- package/examples/jsm/node-editor/utils/PreviewEditor.js +0 -170
- package/examples/jsm/node-editor/utils/SplitEditor.js +0 -39
- package/examples/jsm/node-editor/utils/TimerEditor.js +0 -58
- package/examples/jsm/nodes/core/CodeNode.js +0 -50
- package/examples/jsm/nodes/core/ExpressionNode.js +0 -32
- package/examples/jsm/nodes/functions/light/getDistanceAttenuation.js +0 -22
- package/examples/jsm/nodes/lighting/PunctualLightNode.js +0 -68
- package/examples/jsm/nodes/shadernode/ShaderNodeBaseElements.js +0 -301
- package/examples/jsm/nodes/shadernode/ShaderNodeElements.js +0 -149
- package/examples/jsm/objects/GroundProjectedEnv.js +0 -186
- package/examples/jsm/objects/LightningStorm.js +0 -245
- package/examples/jsm/physics/OimoPhysics.js +0 -231
- package/examples/jsm/postprocessing/AdaptiveToneMappingPass.js +0 -369
- package/examples/jsm/renderers/webgpu/WebGPUAttributes.js +0 -187
- package/examples/jsm/renderers/webgpu/WebGPUBackground.js +0 -173
- package/examples/jsm/renderers/webgpu/WebGPUBinding.js +0 -22
- package/examples/jsm/renderers/webgpu/WebGPUBindings.js +0 -255
- package/examples/jsm/renderers/webgpu/WebGPUBuffer.js +0 -43
- package/examples/jsm/renderers/webgpu/WebGPUComputePipelines.js +0 -78
- package/examples/jsm/renderers/webgpu/WebGPUGeometries.js +0 -82
- package/examples/jsm/renderers/webgpu/WebGPUObjects.js +0 -36
- package/examples/jsm/renderers/webgpu/WebGPUProgrammableStage.js +0 -22
- package/examples/jsm/renderers/webgpu/WebGPUProperties.js +0 -38
- package/examples/jsm/renderers/webgpu/WebGPURenderPipelines.js +0 -296
- package/examples/jsm/renderers/webgpu/WebGPURenderStates.js +0 -66
- package/examples/jsm/renderers/webgpu/WebGPUSampledTexture.js +0 -73
- package/examples/jsm/renderers/webgpu/WebGPUSampler.js +0 -29
- package/examples/jsm/renderers/webgpu/WebGPUStorageBuffer.js +0 -20
- package/examples/jsm/renderers/webgpu/WebGPUTextureRenderer.js +0 -40
- package/examples/jsm/renderers/webgpu/WebGPUTextures.js +0 -794
- package/examples/jsm/renderers/webgpu/WebGPUUniformBuffer.js +0 -18
- package/examples/jsm/renderers/webgpu/WebGPUUtils.js +0 -81
- package/examples/jsm/renderers/webgpu/nodes/WebGPUNodes.js +0 -83
- package/examples/jsm/shaders/ToneMapShader.js +0 -73
- package/src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl.js +0 -7
- package/src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl.js +0 -10
- package/src/renderers/shaders/ShaderChunk/uv2_vertex.glsl.js +0 -7
- /package/examples/{js → jsm}/libs/ammo.wasm.js +0 -0
- /package/examples/{js → jsm}/libs/ammo.wasm.wasm +0 -0
- /package/examples/{js → jsm}/libs/basis/basis_transcoder.js +0 -0
- /package/examples/{js → jsm}/libs/basis/basis_transcoder.wasm +0 -0
- /package/examples/{js → jsm}/libs/draco/README.md +0 -0
- /package/examples/{js → jsm}/libs/draco/draco_encoder.js +0 -0
- /package/examples/{js → jsm}/libs/draco/gltf/draco_encoder.js +0 -0
|
@@ -1,3140 +0,0 @@
|
|
|
1
|
-
( function () {
|
|
2
|
-
|
|
3
|
-
class VRMLLoader extends THREE.Loader {
|
|
4
|
-
|
|
5
|
-
constructor( manager ) {
|
|
6
|
-
|
|
7
|
-
super( manager );
|
|
8
|
-
|
|
9
|
-
// dependency check
|
|
10
|
-
|
|
11
|
-
if ( typeof chevrotain === 'undefined' ) {
|
|
12
|
-
|
|
13
|
-
// eslint-disable-line no-undef
|
|
14
|
-
|
|
15
|
-
throw Error( 'THREE.VRMLLoader: External library chevrotain.min.js required.' );
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
load( url, onLoad, onProgress, onError ) {
|
|
21
|
-
|
|
22
|
-
const scope = this;
|
|
23
|
-
const path = scope.path === '' ? THREE.LoaderUtils.extractUrlBase( url ) : scope.path;
|
|
24
|
-
const loader = new THREE.FileLoader( scope.manager );
|
|
25
|
-
loader.setPath( scope.path );
|
|
26
|
-
loader.setRequestHeader( scope.requestHeader );
|
|
27
|
-
loader.setWithCredentials( scope.withCredentials );
|
|
28
|
-
loader.load( url, function ( text ) {
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
|
|
32
|
-
onLoad( scope.parse( text, path ) );
|
|
33
|
-
|
|
34
|
-
} catch ( e ) {
|
|
35
|
-
|
|
36
|
-
if ( onError ) {
|
|
37
|
-
|
|
38
|
-
onError( e );
|
|
39
|
-
|
|
40
|
-
} else {
|
|
41
|
-
|
|
42
|
-
console.error( e );
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
scope.manager.itemError( url );
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
}, onProgress, onError );
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
parse( data, path ) {
|
|
54
|
-
|
|
55
|
-
const nodeMap = {};
|
|
56
|
-
function generateVRMLTree( data ) {
|
|
57
|
-
|
|
58
|
-
// create lexer, parser and visitor
|
|
59
|
-
|
|
60
|
-
const tokenData = createTokens();
|
|
61
|
-
const lexer = new VRMLLexer( tokenData.tokens );
|
|
62
|
-
const parser = new VRMLParser( tokenData.tokenVocabulary );
|
|
63
|
-
const visitor = createVisitor( parser.getBaseCstVisitorConstructor() );
|
|
64
|
-
|
|
65
|
-
// lexing
|
|
66
|
-
|
|
67
|
-
const lexingResult = lexer.lex( data );
|
|
68
|
-
parser.input = lexingResult.tokens;
|
|
69
|
-
|
|
70
|
-
// parsing
|
|
71
|
-
|
|
72
|
-
const cstOutput = parser.vrml();
|
|
73
|
-
if ( parser.errors.length > 0 ) {
|
|
74
|
-
|
|
75
|
-
console.error( parser.errors );
|
|
76
|
-
throw Error( 'THREE.VRMLLoader: Parsing errors detected.' );
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// actions
|
|
81
|
-
|
|
82
|
-
const ast = visitor.visit( cstOutput );
|
|
83
|
-
return ast;
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function createTokens() {
|
|
88
|
-
|
|
89
|
-
const createToken = chevrotain.createToken; // eslint-disable-line no-undef
|
|
90
|
-
|
|
91
|
-
// from http://gun.teipir.gr/VRML-amgem/spec/part1/concepts.html#SyntaxBasics
|
|
92
|
-
|
|
93
|
-
const RouteIdentifier = createToken( {
|
|
94
|
-
name: 'RouteIdentifier',
|
|
95
|
-
pattern: /[^\x30-\x39\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d][^\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d]*[\.][^\x30-\x39\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d][^\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d]*/
|
|
96
|
-
} );
|
|
97
|
-
const Identifier = createToken( {
|
|
98
|
-
name: 'Identifier',
|
|
99
|
-
pattern: /[^\x30-\x39\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d][^\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d]*/,
|
|
100
|
-
longer_alt: RouteIdentifier
|
|
101
|
-
} );
|
|
102
|
-
|
|
103
|
-
// from http://gun.teipir.gr/VRML-amgem/spec/part1/nodesRef.html
|
|
104
|
-
|
|
105
|
-
const nodeTypes = [ 'Anchor', 'Billboard', 'Collision', 'Group', 'Transform',
|
|
106
|
-
// grouping nodes
|
|
107
|
-
'Inline', 'LOD', 'Switch',
|
|
108
|
-
// special groups
|
|
109
|
-
'AudioClip', 'DirectionalLight', 'PointLight', 'Script', 'Shape', 'Sound', 'SpotLight', 'WorldInfo',
|
|
110
|
-
// common nodes
|
|
111
|
-
'CylinderSensor', 'PlaneSensor', 'ProximitySensor', 'SphereSensor', 'TimeSensor', 'TouchSensor', 'VisibilitySensor',
|
|
112
|
-
// sensors
|
|
113
|
-
'Box', 'Cone', 'Cylinder', 'ElevationGrid', 'Extrusion', 'IndexedFaceSet', 'IndexedLineSet', 'PointSet', 'Sphere',
|
|
114
|
-
// geometries
|
|
115
|
-
'Color', 'Coordinate', 'Normal', 'TextureCoordinate',
|
|
116
|
-
// geometric properties
|
|
117
|
-
'Appearance', 'FontStyle', 'ImageTexture', 'Material', 'MovieTexture', 'PixelTexture', 'TextureTransform',
|
|
118
|
-
// appearance
|
|
119
|
-
'ColorInterpolator', 'CoordinateInterpolator', 'NormalInterpolator', 'OrientationInterpolator', 'PositionInterpolator', 'ScalarInterpolator',
|
|
120
|
-
// interpolators
|
|
121
|
-
'Background', 'Fog', 'NavigationInfo', 'Viewpoint',
|
|
122
|
-
// bindable nodes
|
|
123
|
-
'Text' // Text must be placed at the end of the regex so there are no matches for TextureTransform and TextureCoordinate
|
|
124
|
-
];
|
|
125
|
-
|
|
126
|
-
//
|
|
127
|
-
|
|
128
|
-
const Version = createToken( {
|
|
129
|
-
name: 'Version',
|
|
130
|
-
pattern: /#VRML.*/,
|
|
131
|
-
longer_alt: Identifier
|
|
132
|
-
} );
|
|
133
|
-
const NodeName = createToken( {
|
|
134
|
-
name: 'NodeName',
|
|
135
|
-
pattern: new RegExp( nodeTypes.join( '|' ) ),
|
|
136
|
-
longer_alt: Identifier
|
|
137
|
-
} );
|
|
138
|
-
const DEF = createToken( {
|
|
139
|
-
name: 'DEF',
|
|
140
|
-
pattern: /DEF/,
|
|
141
|
-
longer_alt: Identifier
|
|
142
|
-
} );
|
|
143
|
-
const USE = createToken( {
|
|
144
|
-
name: 'USE',
|
|
145
|
-
pattern: /USE/,
|
|
146
|
-
longer_alt: Identifier
|
|
147
|
-
} );
|
|
148
|
-
const ROUTE = createToken( {
|
|
149
|
-
name: 'ROUTE',
|
|
150
|
-
pattern: /ROUTE/,
|
|
151
|
-
longer_alt: Identifier
|
|
152
|
-
} );
|
|
153
|
-
const TO = createToken( {
|
|
154
|
-
name: 'TO',
|
|
155
|
-
pattern: /TO/,
|
|
156
|
-
longer_alt: Identifier
|
|
157
|
-
} );
|
|
158
|
-
|
|
159
|
-
//
|
|
160
|
-
|
|
161
|
-
const StringLiteral = createToken( {
|
|
162
|
-
name: 'StringLiteral',
|
|
163
|
-
pattern: /"(?:[^\\"\n\r]|\\[bfnrtv"\\/]|\\u[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])*"/
|
|
164
|
-
} );
|
|
165
|
-
const HexLiteral = createToken( {
|
|
166
|
-
name: 'HexLiteral',
|
|
167
|
-
pattern: /0[xX][0-9a-fA-F]+/
|
|
168
|
-
} );
|
|
169
|
-
const NumberLiteral = createToken( {
|
|
170
|
-
name: 'NumberLiteral',
|
|
171
|
-
pattern: /[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/
|
|
172
|
-
} );
|
|
173
|
-
const TrueLiteral = createToken( {
|
|
174
|
-
name: 'TrueLiteral',
|
|
175
|
-
pattern: /TRUE/
|
|
176
|
-
} );
|
|
177
|
-
const FalseLiteral = createToken( {
|
|
178
|
-
name: 'FalseLiteral',
|
|
179
|
-
pattern: /FALSE/
|
|
180
|
-
} );
|
|
181
|
-
const NullLiteral = createToken( {
|
|
182
|
-
name: 'NullLiteral',
|
|
183
|
-
pattern: /NULL/
|
|
184
|
-
} );
|
|
185
|
-
const LSquare = createToken( {
|
|
186
|
-
name: 'LSquare',
|
|
187
|
-
pattern: /\[/
|
|
188
|
-
} );
|
|
189
|
-
const RSquare = createToken( {
|
|
190
|
-
name: 'RSquare',
|
|
191
|
-
pattern: /]/
|
|
192
|
-
} );
|
|
193
|
-
const LCurly = createToken( {
|
|
194
|
-
name: 'LCurly',
|
|
195
|
-
pattern: /{/
|
|
196
|
-
} );
|
|
197
|
-
const RCurly = createToken( {
|
|
198
|
-
name: 'RCurly',
|
|
199
|
-
pattern: /}/
|
|
200
|
-
} );
|
|
201
|
-
const Comment = createToken( {
|
|
202
|
-
name: 'Comment',
|
|
203
|
-
pattern: /#.*/,
|
|
204
|
-
group: chevrotain.Lexer.SKIPPED // eslint-disable-line no-undef
|
|
205
|
-
} );
|
|
206
|
-
|
|
207
|
-
// commas, blanks, tabs, newlines and carriage returns are whitespace characters wherever they appear outside of string fields
|
|
208
|
-
|
|
209
|
-
const WhiteSpace = createToken( {
|
|
210
|
-
name: 'WhiteSpace',
|
|
211
|
-
pattern: /[ ,\s]/,
|
|
212
|
-
group: chevrotain.Lexer.SKIPPED // eslint-disable-line no-undef
|
|
213
|
-
} );
|
|
214
|
-
|
|
215
|
-
const tokens = [ WhiteSpace,
|
|
216
|
-
// keywords appear before the Identifier
|
|
217
|
-
NodeName, DEF, USE, ROUTE, TO, TrueLiteral, FalseLiteral, NullLiteral,
|
|
218
|
-
// the Identifier must appear after the keywords because all keywords are valid identifiers
|
|
219
|
-
Version, Identifier, RouteIdentifier, StringLiteral, HexLiteral, NumberLiteral, LSquare, RSquare, LCurly, RCurly, Comment ];
|
|
220
|
-
const tokenVocabulary = {};
|
|
221
|
-
for ( let i = 0, l = tokens.length; i < l; i ++ ) {
|
|
222
|
-
|
|
223
|
-
const token = tokens[ i ];
|
|
224
|
-
tokenVocabulary[ token.name ] = token;
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return {
|
|
229
|
-
tokens: tokens,
|
|
230
|
-
tokenVocabulary: tokenVocabulary
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function createVisitor( BaseVRMLVisitor ) {
|
|
236
|
-
|
|
237
|
-
// the visitor is created dynmaically based on the given base class
|
|
238
|
-
|
|
239
|
-
class VRMLToASTVisitor extends BaseVRMLVisitor {
|
|
240
|
-
|
|
241
|
-
constructor() {
|
|
242
|
-
|
|
243
|
-
super();
|
|
244
|
-
this.validateVisitor();
|
|
245
|
-
|
|
246
|
-
}
|
|
247
|
-
vrml( ctx ) {
|
|
248
|
-
|
|
249
|
-
const data = {
|
|
250
|
-
version: this.visit( ctx.version ),
|
|
251
|
-
nodes: [],
|
|
252
|
-
routes: []
|
|
253
|
-
};
|
|
254
|
-
for ( let i = 0, l = ctx.node.length; i < l; i ++ ) {
|
|
255
|
-
|
|
256
|
-
const node = ctx.node[ i ];
|
|
257
|
-
data.nodes.push( this.visit( node ) );
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
if ( ctx.route ) {
|
|
262
|
-
|
|
263
|
-
for ( let i = 0, l = ctx.route.length; i < l; i ++ ) {
|
|
264
|
-
|
|
265
|
-
const route = ctx.route[ i ];
|
|
266
|
-
data.routes.push( this.visit( route ) );
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
return data;
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
version( ctx ) {
|
|
276
|
-
|
|
277
|
-
return ctx.Version[ 0 ].image;
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
node( ctx ) {
|
|
281
|
-
|
|
282
|
-
const data = {
|
|
283
|
-
name: ctx.NodeName[ 0 ].image,
|
|
284
|
-
fields: []
|
|
285
|
-
};
|
|
286
|
-
if ( ctx.field ) {
|
|
287
|
-
|
|
288
|
-
for ( let i = 0, l = ctx.field.length; i < l; i ++ ) {
|
|
289
|
-
|
|
290
|
-
const field = ctx.field[ i ];
|
|
291
|
-
data.fields.push( this.visit( field ) );
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
// DEF
|
|
298
|
-
|
|
299
|
-
if ( ctx.def ) {
|
|
300
|
-
|
|
301
|
-
data.DEF = this.visit( ctx.def[ 0 ] );
|
|
302
|
-
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
return data;
|
|
306
|
-
|
|
307
|
-
}
|
|
308
|
-
field( ctx ) {
|
|
309
|
-
|
|
310
|
-
const data = {
|
|
311
|
-
name: ctx.Identifier[ 0 ].image,
|
|
312
|
-
type: null,
|
|
313
|
-
values: null
|
|
314
|
-
};
|
|
315
|
-
let result;
|
|
316
|
-
|
|
317
|
-
// SFValue
|
|
318
|
-
|
|
319
|
-
if ( ctx.singleFieldValue ) {
|
|
320
|
-
|
|
321
|
-
result = this.visit( ctx.singleFieldValue[ 0 ] );
|
|
322
|
-
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// MFValue
|
|
326
|
-
|
|
327
|
-
if ( ctx.multiFieldValue ) {
|
|
328
|
-
|
|
329
|
-
result = this.visit( ctx.multiFieldValue[ 0 ] );
|
|
330
|
-
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
data.type = result.type;
|
|
334
|
-
data.values = result.values;
|
|
335
|
-
return data;
|
|
336
|
-
|
|
337
|
-
}
|
|
338
|
-
def( ctx ) {
|
|
339
|
-
|
|
340
|
-
return ( ctx.Identifier || ctx.NodeName )[ 0 ].image;
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
use( ctx ) {
|
|
344
|
-
|
|
345
|
-
return {
|
|
346
|
-
USE: ( ctx.Identifier || ctx.NodeName )[ 0 ].image
|
|
347
|
-
};
|
|
348
|
-
|
|
349
|
-
}
|
|
350
|
-
singleFieldValue( ctx ) {
|
|
351
|
-
|
|
352
|
-
return processField( this, ctx );
|
|
353
|
-
|
|
354
|
-
}
|
|
355
|
-
multiFieldValue( ctx ) {
|
|
356
|
-
|
|
357
|
-
return processField( this, ctx );
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
route( ctx ) {
|
|
361
|
-
|
|
362
|
-
const data = {
|
|
363
|
-
FROM: ctx.RouteIdentifier[ 0 ].image,
|
|
364
|
-
TO: ctx.RouteIdentifier[ 1 ].image
|
|
365
|
-
};
|
|
366
|
-
return data;
|
|
367
|
-
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
}
|
|
371
|
-
function processField( scope, ctx ) {
|
|
372
|
-
|
|
373
|
-
const field = {
|
|
374
|
-
type: null,
|
|
375
|
-
values: []
|
|
376
|
-
};
|
|
377
|
-
if ( ctx.node ) {
|
|
378
|
-
|
|
379
|
-
field.type = 'node';
|
|
380
|
-
for ( let i = 0, l = ctx.node.length; i < l; i ++ ) {
|
|
381
|
-
|
|
382
|
-
const node = ctx.node[ i ];
|
|
383
|
-
field.values.push( scope.visit( node ) );
|
|
384
|
-
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
if ( ctx.use ) {
|
|
390
|
-
|
|
391
|
-
field.type = 'use';
|
|
392
|
-
for ( let i = 0, l = ctx.use.length; i < l; i ++ ) {
|
|
393
|
-
|
|
394
|
-
const use = ctx.use[ i ];
|
|
395
|
-
field.values.push( scope.visit( use ) );
|
|
396
|
-
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
if ( ctx.StringLiteral ) {
|
|
402
|
-
|
|
403
|
-
field.type = 'string';
|
|
404
|
-
for ( let i = 0, l = ctx.StringLiteral.length; i < l; i ++ ) {
|
|
405
|
-
|
|
406
|
-
const stringLiteral = ctx.StringLiteral[ i ];
|
|
407
|
-
field.values.push( stringLiteral.image.replace( /'|"/g, '' ) );
|
|
408
|
-
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
if ( ctx.NumberLiteral ) {
|
|
414
|
-
|
|
415
|
-
field.type = 'number';
|
|
416
|
-
for ( let i = 0, l = ctx.NumberLiteral.length; i < l; i ++ ) {
|
|
417
|
-
|
|
418
|
-
const numberLiteral = ctx.NumberLiteral[ i ];
|
|
419
|
-
field.values.push( parseFloat( numberLiteral.image ) );
|
|
420
|
-
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
if ( ctx.HexLiteral ) {
|
|
426
|
-
|
|
427
|
-
field.type = 'hex';
|
|
428
|
-
for ( let i = 0, l = ctx.HexLiteral.length; i < l; i ++ ) {
|
|
429
|
-
|
|
430
|
-
const hexLiteral = ctx.HexLiteral[ i ];
|
|
431
|
-
field.values.push( hexLiteral.image );
|
|
432
|
-
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
if ( ctx.TrueLiteral ) {
|
|
438
|
-
|
|
439
|
-
field.type = 'boolean';
|
|
440
|
-
for ( let i = 0, l = ctx.TrueLiteral.length; i < l; i ++ ) {
|
|
441
|
-
|
|
442
|
-
const trueLiteral = ctx.TrueLiteral[ i ];
|
|
443
|
-
if ( trueLiteral.image === 'TRUE' ) field.values.push( true );
|
|
444
|
-
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
if ( ctx.FalseLiteral ) {
|
|
450
|
-
|
|
451
|
-
field.type = 'boolean';
|
|
452
|
-
for ( let i = 0, l = ctx.FalseLiteral.length; i < l; i ++ ) {
|
|
453
|
-
|
|
454
|
-
const falseLiteral = ctx.FalseLiteral[ i ];
|
|
455
|
-
if ( falseLiteral.image === 'FALSE' ) field.values.push( false );
|
|
456
|
-
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
if ( ctx.NullLiteral ) {
|
|
462
|
-
|
|
463
|
-
field.type = 'null';
|
|
464
|
-
ctx.NullLiteral.forEach( function () {
|
|
465
|
-
|
|
466
|
-
field.values.push( null );
|
|
467
|
-
|
|
468
|
-
} );
|
|
469
|
-
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
return field;
|
|
473
|
-
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
return new VRMLToASTVisitor();
|
|
477
|
-
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
function parseTree( tree ) {
|
|
481
|
-
|
|
482
|
-
// console.log( JSON.stringify( tree, null, 2 ) );
|
|
483
|
-
|
|
484
|
-
const nodes = tree.nodes;
|
|
485
|
-
const scene = new THREE.Scene();
|
|
486
|
-
|
|
487
|
-
// first iteration: build nodemap based on DEF statements
|
|
488
|
-
|
|
489
|
-
for ( let i = 0, l = nodes.length; i < l; i ++ ) {
|
|
490
|
-
|
|
491
|
-
const node = nodes[ i ];
|
|
492
|
-
buildNodeMap( node );
|
|
493
|
-
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
// second iteration: build nodes
|
|
497
|
-
|
|
498
|
-
for ( let i = 0, l = nodes.length; i < l; i ++ ) {
|
|
499
|
-
|
|
500
|
-
const node = nodes[ i ];
|
|
501
|
-
const object = getNode( node );
|
|
502
|
-
if ( object instanceof THREE.Object3D ) scene.add( object );
|
|
503
|
-
if ( node.name === 'WorldInfo' ) scene.userData.worldInfo = object;
|
|
504
|
-
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
return scene;
|
|
508
|
-
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
function buildNodeMap( node ) {
|
|
512
|
-
|
|
513
|
-
if ( node.DEF ) {
|
|
514
|
-
|
|
515
|
-
nodeMap[ node.DEF ] = node;
|
|
516
|
-
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
const fields = node.fields;
|
|
520
|
-
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
521
|
-
|
|
522
|
-
const field = fields[ i ];
|
|
523
|
-
if ( field.type === 'node' ) {
|
|
524
|
-
|
|
525
|
-
const fieldValues = field.values;
|
|
526
|
-
for ( let j = 0, jl = fieldValues.length; j < jl; j ++ ) {
|
|
527
|
-
|
|
528
|
-
buildNodeMap( fieldValues[ j ] );
|
|
529
|
-
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
function getNode( node ) {
|
|
539
|
-
|
|
540
|
-
// handle case where a node refers to a different one
|
|
541
|
-
|
|
542
|
-
if ( node.USE ) {
|
|
543
|
-
|
|
544
|
-
return resolveUSE( node.USE );
|
|
545
|
-
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
if ( node.build !== undefined ) return node.build;
|
|
549
|
-
node.build = buildNode( node );
|
|
550
|
-
return node.build;
|
|
551
|
-
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
// node builder
|
|
555
|
-
|
|
556
|
-
function buildNode( node ) {
|
|
557
|
-
|
|
558
|
-
const nodeName = node.name;
|
|
559
|
-
let build;
|
|
560
|
-
switch ( nodeName ) {
|
|
561
|
-
|
|
562
|
-
case 'Anchor':
|
|
563
|
-
case 'Group':
|
|
564
|
-
case 'Transform':
|
|
565
|
-
case 'Collision':
|
|
566
|
-
build = buildGroupingNode( node );
|
|
567
|
-
break;
|
|
568
|
-
case 'Background':
|
|
569
|
-
build = buildBackgroundNode( node );
|
|
570
|
-
break;
|
|
571
|
-
case 'Shape':
|
|
572
|
-
build = buildShapeNode( node );
|
|
573
|
-
break;
|
|
574
|
-
case 'Appearance':
|
|
575
|
-
build = buildAppearanceNode( node );
|
|
576
|
-
break;
|
|
577
|
-
case 'Material':
|
|
578
|
-
build = buildMaterialNode( node );
|
|
579
|
-
break;
|
|
580
|
-
case 'ImageTexture':
|
|
581
|
-
build = buildImageTextureNode( node );
|
|
582
|
-
break;
|
|
583
|
-
case 'PixelTexture':
|
|
584
|
-
build = buildPixelTextureNode( node );
|
|
585
|
-
break;
|
|
586
|
-
case 'TextureTransform':
|
|
587
|
-
build = buildTextureTransformNode( node );
|
|
588
|
-
break;
|
|
589
|
-
case 'IndexedFaceSet':
|
|
590
|
-
build = buildIndexedFaceSetNode( node );
|
|
591
|
-
break;
|
|
592
|
-
case 'IndexedLineSet':
|
|
593
|
-
build = buildIndexedLineSetNode( node );
|
|
594
|
-
break;
|
|
595
|
-
case 'PointSet':
|
|
596
|
-
build = buildPointSetNode( node );
|
|
597
|
-
break;
|
|
598
|
-
case 'Box':
|
|
599
|
-
build = buildBoxNode( node );
|
|
600
|
-
break;
|
|
601
|
-
case 'Cone':
|
|
602
|
-
build = buildConeNode( node );
|
|
603
|
-
break;
|
|
604
|
-
case 'Cylinder':
|
|
605
|
-
build = buildCylinderNode( node );
|
|
606
|
-
break;
|
|
607
|
-
case 'Sphere':
|
|
608
|
-
build = buildSphereNode( node );
|
|
609
|
-
break;
|
|
610
|
-
case 'ElevationGrid':
|
|
611
|
-
build = buildElevationGridNode( node );
|
|
612
|
-
break;
|
|
613
|
-
case 'Extrusion':
|
|
614
|
-
build = buildExtrusionNode( node );
|
|
615
|
-
break;
|
|
616
|
-
case 'Color':
|
|
617
|
-
case 'Coordinate':
|
|
618
|
-
case 'Normal':
|
|
619
|
-
case 'TextureCoordinate':
|
|
620
|
-
build = buildGeometricNode( node );
|
|
621
|
-
break;
|
|
622
|
-
case 'WorldInfo':
|
|
623
|
-
build = buildWorldInfoNode( node );
|
|
624
|
-
break;
|
|
625
|
-
case 'Billboard':
|
|
626
|
-
case 'Inline':
|
|
627
|
-
case 'LOD':
|
|
628
|
-
case 'Switch':
|
|
629
|
-
case 'AudioClip':
|
|
630
|
-
case 'DirectionalLight':
|
|
631
|
-
case 'PointLight':
|
|
632
|
-
case 'Script':
|
|
633
|
-
case 'Sound':
|
|
634
|
-
case 'SpotLight':
|
|
635
|
-
case 'CylinderSensor':
|
|
636
|
-
case 'PlaneSensor':
|
|
637
|
-
case 'ProximitySensor':
|
|
638
|
-
case 'SphereSensor':
|
|
639
|
-
case 'TimeSensor':
|
|
640
|
-
case 'TouchSensor':
|
|
641
|
-
case 'VisibilitySensor':
|
|
642
|
-
case 'Text':
|
|
643
|
-
case 'FontStyle':
|
|
644
|
-
case 'MovieTexture':
|
|
645
|
-
case 'ColorInterpolator':
|
|
646
|
-
case 'CoordinateInterpolator':
|
|
647
|
-
case 'NormalInterpolator':
|
|
648
|
-
case 'OrientationInterpolator':
|
|
649
|
-
case 'PositionInterpolator':
|
|
650
|
-
case 'ScalarInterpolator':
|
|
651
|
-
case 'Fog':
|
|
652
|
-
case 'NavigationInfo':
|
|
653
|
-
case 'Viewpoint':
|
|
654
|
-
// node not supported yet
|
|
655
|
-
break;
|
|
656
|
-
default:
|
|
657
|
-
console.warn( 'THREE.VRMLLoader: Unknown node:', nodeName );
|
|
658
|
-
break;
|
|
659
|
-
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
if ( build !== undefined && node.DEF !== undefined && build.hasOwnProperty( 'name' ) === true ) {
|
|
663
|
-
|
|
664
|
-
build.name = node.DEF;
|
|
665
|
-
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
return build;
|
|
669
|
-
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
function buildGroupingNode( node ) {
|
|
673
|
-
|
|
674
|
-
const object = new THREE.Group();
|
|
675
|
-
|
|
676
|
-
//
|
|
677
|
-
|
|
678
|
-
const fields = node.fields;
|
|
679
|
-
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
680
|
-
|
|
681
|
-
const field = fields[ i ];
|
|
682
|
-
const fieldName = field.name;
|
|
683
|
-
const fieldValues = field.values;
|
|
684
|
-
switch ( fieldName ) {
|
|
685
|
-
|
|
686
|
-
case 'bboxCenter':
|
|
687
|
-
// field not supported
|
|
688
|
-
break;
|
|
689
|
-
case 'bboxSize':
|
|
690
|
-
// field not supported
|
|
691
|
-
break;
|
|
692
|
-
case 'center':
|
|
693
|
-
// field not supported
|
|
694
|
-
break;
|
|
695
|
-
case 'children':
|
|
696
|
-
parseFieldChildren( fieldValues, object );
|
|
697
|
-
break;
|
|
698
|
-
case 'description':
|
|
699
|
-
// field not supported
|
|
700
|
-
break;
|
|
701
|
-
case 'collide':
|
|
702
|
-
// field not supported
|
|
703
|
-
break;
|
|
704
|
-
case 'parameter':
|
|
705
|
-
// field not supported
|
|
706
|
-
break;
|
|
707
|
-
case 'rotation':
|
|
708
|
-
const axis = new THREE.Vector3( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
|
|
709
|
-
const angle = fieldValues[ 3 ];
|
|
710
|
-
object.quaternion.setFromAxisAngle( axis, angle );
|
|
711
|
-
break;
|
|
712
|
-
case 'scale':
|
|
713
|
-
object.scale.set( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
|
|
714
|
-
break;
|
|
715
|
-
case 'scaleOrientation':
|
|
716
|
-
// field not supported
|
|
717
|
-
break;
|
|
718
|
-
case 'translation':
|
|
719
|
-
object.position.set( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
|
|
720
|
-
break;
|
|
721
|
-
case 'proxy':
|
|
722
|
-
// field not supported
|
|
723
|
-
break;
|
|
724
|
-
case 'url':
|
|
725
|
-
// field not supported
|
|
726
|
-
break;
|
|
727
|
-
default:
|
|
728
|
-
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
729
|
-
break;
|
|
730
|
-
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
return object;
|
|
736
|
-
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
function buildBackgroundNode( node ) {
|
|
740
|
-
|
|
741
|
-
const group = new THREE.Group();
|
|
742
|
-
let groundAngle, groundColor;
|
|
743
|
-
let skyAngle, skyColor;
|
|
744
|
-
const fields = node.fields;
|
|
745
|
-
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
746
|
-
|
|
747
|
-
const field = fields[ i ];
|
|
748
|
-
const fieldName = field.name;
|
|
749
|
-
const fieldValues = field.values;
|
|
750
|
-
switch ( fieldName ) {
|
|
751
|
-
|
|
752
|
-
case 'groundAngle':
|
|
753
|
-
groundAngle = fieldValues;
|
|
754
|
-
break;
|
|
755
|
-
case 'groundColor':
|
|
756
|
-
groundColor = fieldValues;
|
|
757
|
-
break;
|
|
758
|
-
case 'backUrl':
|
|
759
|
-
// field not supported
|
|
760
|
-
break;
|
|
761
|
-
case 'bottomUrl':
|
|
762
|
-
// field not supported
|
|
763
|
-
break;
|
|
764
|
-
case 'frontUrl':
|
|
765
|
-
// field not supported
|
|
766
|
-
break;
|
|
767
|
-
case 'leftUrl':
|
|
768
|
-
// field not supported
|
|
769
|
-
break;
|
|
770
|
-
case 'rightUrl':
|
|
771
|
-
// field not supported
|
|
772
|
-
break;
|
|
773
|
-
case 'topUrl':
|
|
774
|
-
// field not supported
|
|
775
|
-
break;
|
|
776
|
-
case 'skyAngle':
|
|
777
|
-
skyAngle = fieldValues;
|
|
778
|
-
break;
|
|
779
|
-
case 'skyColor':
|
|
780
|
-
skyColor = fieldValues;
|
|
781
|
-
break;
|
|
782
|
-
default:
|
|
783
|
-
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
784
|
-
break;
|
|
785
|
-
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
const radius = 10000;
|
|
791
|
-
|
|
792
|
-
// sky
|
|
793
|
-
|
|
794
|
-
if ( skyColor ) {
|
|
795
|
-
|
|
796
|
-
const skyGeometry = new THREE.SphereGeometry( radius, 32, 16 );
|
|
797
|
-
const skyMaterial = new THREE.MeshBasicMaterial( {
|
|
798
|
-
fog: false,
|
|
799
|
-
side: THREE.BackSide,
|
|
800
|
-
depthWrite: false,
|
|
801
|
-
depthTest: false
|
|
802
|
-
} );
|
|
803
|
-
if ( skyColor.length > 3 ) {
|
|
804
|
-
|
|
805
|
-
paintFaces( skyGeometry, radius, skyAngle, toColorArray( skyColor ), true );
|
|
806
|
-
skyMaterial.vertexColors = true;
|
|
807
|
-
|
|
808
|
-
} else {
|
|
809
|
-
|
|
810
|
-
skyMaterial.color.setRGB( skyColor[ 0 ], skyColor[ 1 ], skyColor[ 2 ] );
|
|
811
|
-
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
const sky = new THREE.Mesh( skyGeometry, skyMaterial );
|
|
815
|
-
group.add( sky );
|
|
816
|
-
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
// ground
|
|
820
|
-
|
|
821
|
-
if ( groundColor ) {
|
|
822
|
-
|
|
823
|
-
if ( groundColor.length > 0 ) {
|
|
824
|
-
|
|
825
|
-
const groundGeometry = new THREE.SphereGeometry( radius, 32, 16, 0, 2 * Math.PI, 0.5 * Math.PI, 1.5 * Math.PI );
|
|
826
|
-
const groundMaterial = new THREE.MeshBasicMaterial( {
|
|
827
|
-
fog: false,
|
|
828
|
-
side: THREE.BackSide,
|
|
829
|
-
vertexColors: true,
|
|
830
|
-
depthWrite: false,
|
|
831
|
-
depthTest: false
|
|
832
|
-
} );
|
|
833
|
-
paintFaces( groundGeometry, radius, groundAngle, toColorArray( groundColor ), false );
|
|
834
|
-
const ground = new THREE.Mesh( groundGeometry, groundMaterial );
|
|
835
|
-
group.add( ground );
|
|
836
|
-
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
// render background group first
|
|
842
|
-
|
|
843
|
-
group.renderOrder = - Infinity;
|
|
844
|
-
return group;
|
|
845
|
-
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
function buildShapeNode( node ) {
|
|
849
|
-
|
|
850
|
-
const fields = node.fields;
|
|
851
|
-
|
|
852
|
-
// if the appearance field is NULL or unspecified, lighting is off and the unlit object color is (0, 0, 0)
|
|
853
|
-
|
|
854
|
-
let material = new THREE.MeshBasicMaterial( {
|
|
855
|
-
color: 0x000000
|
|
856
|
-
} );
|
|
857
|
-
let geometry;
|
|
858
|
-
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
859
|
-
|
|
860
|
-
const field = fields[ i ];
|
|
861
|
-
const fieldName = field.name;
|
|
862
|
-
const fieldValues = field.values;
|
|
863
|
-
switch ( fieldName ) {
|
|
864
|
-
|
|
865
|
-
case 'appearance':
|
|
866
|
-
if ( fieldValues[ 0 ] !== null ) {
|
|
867
|
-
|
|
868
|
-
material = getNode( fieldValues[ 0 ] );
|
|
869
|
-
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
break;
|
|
873
|
-
case 'geometry':
|
|
874
|
-
if ( fieldValues[ 0 ] !== null ) {
|
|
875
|
-
|
|
876
|
-
geometry = getNode( fieldValues[ 0 ] );
|
|
877
|
-
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
break;
|
|
881
|
-
default:
|
|
882
|
-
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
883
|
-
break;
|
|
884
|
-
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
// build 3D object
|
|
890
|
-
|
|
891
|
-
let object;
|
|
892
|
-
if ( geometry && geometry.attributes.position ) {
|
|
893
|
-
|
|
894
|
-
const type = geometry._type;
|
|
895
|
-
if ( type === 'points' ) {
|
|
896
|
-
|
|
897
|
-
// points
|
|
898
|
-
|
|
899
|
-
const pointsMaterial = new THREE.PointsMaterial( {
|
|
900
|
-
color: 0xffffff
|
|
901
|
-
} );
|
|
902
|
-
if ( geometry.attributes.color !== undefined ) {
|
|
903
|
-
|
|
904
|
-
pointsMaterial.vertexColors = true;
|
|
905
|
-
|
|
906
|
-
} else {
|
|
907
|
-
|
|
908
|
-
// if the color field is NULL and there is a material defined for the appearance affecting this PointSet, then use the emissiveColor of the material to draw the points
|
|
909
|
-
|
|
910
|
-
if ( material.isMeshPhongMaterial ) {
|
|
911
|
-
|
|
912
|
-
pointsMaterial.color.copy( material.emissive );
|
|
913
|
-
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
object = new THREE.Points( geometry, pointsMaterial );
|
|
919
|
-
|
|
920
|
-
} else if ( type === 'line' ) {
|
|
921
|
-
|
|
922
|
-
// lines
|
|
923
|
-
|
|
924
|
-
const lineMaterial = new THREE.LineBasicMaterial( {
|
|
925
|
-
color: 0xffffff
|
|
926
|
-
} );
|
|
927
|
-
if ( geometry.attributes.color !== undefined ) {
|
|
928
|
-
|
|
929
|
-
lineMaterial.vertexColors = true;
|
|
930
|
-
|
|
931
|
-
} else {
|
|
932
|
-
|
|
933
|
-
// if the color field is NULL and there is a material defined for the appearance affecting this IndexedLineSet, then use the emissiveColor of the material to draw the lines
|
|
934
|
-
|
|
935
|
-
if ( material.isMeshPhongMaterial ) {
|
|
936
|
-
|
|
937
|
-
lineMaterial.color.copy( material.emissive );
|
|
938
|
-
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
}
|
|
942
|
-
|
|
943
|
-
object = new THREE.LineSegments( geometry, lineMaterial );
|
|
944
|
-
|
|
945
|
-
} else {
|
|
946
|
-
|
|
947
|
-
// consider meshes
|
|
948
|
-
|
|
949
|
-
// check "solid" hint (it's placed in the geometry but affects the material)
|
|
950
|
-
|
|
951
|
-
if ( geometry._solid !== undefined ) {
|
|
952
|
-
|
|
953
|
-
material.side = geometry._solid ? THREE.FrontSide : THREE.DoubleSide;
|
|
954
|
-
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
// check for vertex colors
|
|
958
|
-
|
|
959
|
-
if ( geometry.attributes.color !== undefined ) {
|
|
960
|
-
|
|
961
|
-
material.vertexColors = true;
|
|
962
|
-
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
object = new THREE.Mesh( geometry, material );
|
|
966
|
-
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
} else {
|
|
970
|
-
|
|
971
|
-
object = new THREE.Object3D();
|
|
972
|
-
|
|
973
|
-
// if the geometry field is NULL or no vertices are defined the object is not drawn
|
|
974
|
-
|
|
975
|
-
object.visible = false;
|
|
976
|
-
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
return object;
|
|
980
|
-
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
function buildAppearanceNode( node ) {
|
|
984
|
-
|
|
985
|
-
let material = new THREE.MeshPhongMaterial();
|
|
986
|
-
let transformData;
|
|
987
|
-
const fields = node.fields;
|
|
988
|
-
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
989
|
-
|
|
990
|
-
const field = fields[ i ];
|
|
991
|
-
const fieldName = field.name;
|
|
992
|
-
const fieldValues = field.values;
|
|
993
|
-
switch ( fieldName ) {
|
|
994
|
-
|
|
995
|
-
case 'material':
|
|
996
|
-
if ( fieldValues[ 0 ] !== null ) {
|
|
997
|
-
|
|
998
|
-
const materialData = getNode( fieldValues[ 0 ] );
|
|
999
|
-
if ( materialData.diffuseColor ) material.color.copy( materialData.diffuseColor );
|
|
1000
|
-
if ( materialData.emissiveColor ) material.emissive.copy( materialData.emissiveColor );
|
|
1001
|
-
if ( materialData.shininess ) material.shininess = materialData.shininess;
|
|
1002
|
-
if ( materialData.specularColor ) material.specular.copy( materialData.specularColor );
|
|
1003
|
-
if ( materialData.transparency ) material.opacity = 1 - materialData.transparency;
|
|
1004
|
-
if ( materialData.transparency > 0 ) material.transparent = true;
|
|
1005
|
-
|
|
1006
|
-
} else {
|
|
1007
|
-
|
|
1008
|
-
// if the material field is NULL or unspecified, lighting is off and the unlit object color is (0, 0, 0)
|
|
1009
|
-
|
|
1010
|
-
material = new THREE.MeshBasicMaterial( {
|
|
1011
|
-
color: 0x000000
|
|
1012
|
-
} );
|
|
1013
|
-
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
break;
|
|
1017
|
-
case 'texture':
|
|
1018
|
-
const textureNode = fieldValues[ 0 ];
|
|
1019
|
-
if ( textureNode !== null ) {
|
|
1020
|
-
|
|
1021
|
-
if ( textureNode.name === 'ImageTexture' || textureNode.name === 'PixelTexture' ) {
|
|
1022
|
-
|
|
1023
|
-
material.map = getNode( textureNode );
|
|
1024
|
-
|
|
1025
|
-
} else {
|
|
1026
|
-
|
|
1027
|
-
// MovieTexture not supported yet
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
|
-
break;
|
|
1033
|
-
case 'textureTransform':
|
|
1034
|
-
if ( fieldValues[ 0 ] !== null ) {
|
|
1035
|
-
|
|
1036
|
-
transformData = getNode( fieldValues[ 0 ] );
|
|
1037
|
-
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
break;
|
|
1041
|
-
default:
|
|
1042
|
-
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1043
|
-
break;
|
|
1044
|
-
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
}
|
|
1048
|
-
|
|
1049
|
-
// only apply texture transform data if a texture was defined
|
|
1050
|
-
|
|
1051
|
-
if ( material.map ) {
|
|
1052
|
-
|
|
1053
|
-
// respect VRML lighting model
|
|
1054
|
-
|
|
1055
|
-
if ( material.map.__type ) {
|
|
1056
|
-
|
|
1057
|
-
switch ( material.map.__type ) {
|
|
1058
|
-
|
|
1059
|
-
case TEXTURE_TYPE.INTENSITY_ALPHA:
|
|
1060
|
-
material.opacity = 1; // ignore transparency
|
|
1061
|
-
break;
|
|
1062
|
-
case TEXTURE_TYPE.RGB:
|
|
1063
|
-
material.color.set( 0xffffff ); // ignore material color
|
|
1064
|
-
break;
|
|
1065
|
-
case TEXTURE_TYPE.RGBA:
|
|
1066
|
-
material.color.set( 0xffffff ); // ignore material color
|
|
1067
|
-
material.opacity = 1; // ignore transparency
|
|
1068
|
-
break;
|
|
1069
|
-
default:
|
|
1070
|
-
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1073
|
-
delete material.map.__type;
|
|
1074
|
-
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
// apply texture transform
|
|
1078
|
-
|
|
1079
|
-
if ( transformData ) {
|
|
1080
|
-
|
|
1081
|
-
material.map.center.copy( transformData.center );
|
|
1082
|
-
material.map.rotation = transformData.rotation;
|
|
1083
|
-
material.map.repeat.copy( transformData.scale );
|
|
1084
|
-
material.map.offset.copy( transformData.translation );
|
|
1085
|
-
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
}
|
|
1089
|
-
|
|
1090
|
-
return material;
|
|
1091
|
-
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
|
-
function buildMaterialNode( node ) {
|
|
1095
|
-
|
|
1096
|
-
const materialData = {};
|
|
1097
|
-
const fields = node.fields;
|
|
1098
|
-
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1099
|
-
|
|
1100
|
-
const field = fields[ i ];
|
|
1101
|
-
const fieldName = field.name;
|
|
1102
|
-
const fieldValues = field.values;
|
|
1103
|
-
switch ( fieldName ) {
|
|
1104
|
-
|
|
1105
|
-
case 'ambientIntensity':
|
|
1106
|
-
// field not supported
|
|
1107
|
-
break;
|
|
1108
|
-
case 'diffuseColor':
|
|
1109
|
-
materialData.diffuseColor = new THREE.Color( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
|
|
1110
|
-
break;
|
|
1111
|
-
case 'emissiveColor':
|
|
1112
|
-
materialData.emissiveColor = new THREE.Color( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
|
|
1113
|
-
break;
|
|
1114
|
-
case 'shininess':
|
|
1115
|
-
materialData.shininess = fieldValues[ 0 ];
|
|
1116
|
-
break;
|
|
1117
|
-
case 'specularColor':
|
|
1118
|
-
materialData.emissiveColor = new THREE.Color( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
|
|
1119
|
-
break;
|
|
1120
|
-
case 'transparency':
|
|
1121
|
-
materialData.transparency = fieldValues[ 0 ];
|
|
1122
|
-
break;
|
|
1123
|
-
default:
|
|
1124
|
-
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1125
|
-
break;
|
|
1126
|
-
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
}
|
|
1130
|
-
|
|
1131
|
-
return materialData;
|
|
1132
|
-
|
|
1133
|
-
}
|
|
1134
|
-
|
|
1135
|
-
function parseHexColor( hex, textureType, color ) {
|
|
1136
|
-
|
|
1137
|
-
let value;
|
|
1138
|
-
switch ( textureType ) {
|
|
1139
|
-
|
|
1140
|
-
case TEXTURE_TYPE.INTENSITY:
|
|
1141
|
-
// Intensity texture: A one-component image specifies one-byte hexadecimal or integer values representing the intensity of the image
|
|
1142
|
-
value = parseInt( hex );
|
|
1143
|
-
color.r = value;
|
|
1144
|
-
color.g = value;
|
|
1145
|
-
color.b = value;
|
|
1146
|
-
color.a = 1;
|
|
1147
|
-
break;
|
|
1148
|
-
case TEXTURE_TYPE.INTENSITY_ALPHA:
|
|
1149
|
-
// Intensity+Alpha texture: A two-component image specifies the intensity in the first (high) byte and the alpha opacity in the second (low) byte.
|
|
1150
|
-
value = parseInt( '0x' + hex.substring( 2, 4 ) );
|
|
1151
|
-
color.r = value;
|
|
1152
|
-
color.g = value;
|
|
1153
|
-
color.b = value;
|
|
1154
|
-
color.a = parseInt( '0x' + hex.substring( 4, 6 ) );
|
|
1155
|
-
break;
|
|
1156
|
-
case TEXTURE_TYPE.RGB:
|
|
1157
|
-
// RGB texture: Pixels in a three-component image specify the red component in the first (high) byte, followed by the green and blue components
|
|
1158
|
-
color.r = parseInt( '0x' + hex.substring( 2, 4 ) );
|
|
1159
|
-
color.g = parseInt( '0x' + hex.substring( 4, 6 ) );
|
|
1160
|
-
color.b = parseInt( '0x' + hex.substring( 6, 8 ) );
|
|
1161
|
-
color.a = 1;
|
|
1162
|
-
break;
|
|
1163
|
-
case TEXTURE_TYPE.RGBA:
|
|
1164
|
-
// RGBA texture: Four-component images specify the alpha opacity byte after red/green/blue
|
|
1165
|
-
color.r = parseInt( '0x' + hex.substring( 2, 4 ) );
|
|
1166
|
-
color.g = parseInt( '0x' + hex.substring( 4, 6 ) );
|
|
1167
|
-
color.b = parseInt( '0x' + hex.substring( 6, 8 ) );
|
|
1168
|
-
color.a = parseInt( '0x' + hex.substring( 8, 10 ) );
|
|
1169
|
-
break;
|
|
1170
|
-
default:
|
|
1171
|
-
|
|
1172
|
-
}
|
|
1173
|
-
|
|
1174
|
-
}
|
|
1175
|
-
|
|
1176
|
-
function getTextureType( num_components ) {
|
|
1177
|
-
|
|
1178
|
-
let type;
|
|
1179
|
-
switch ( num_components ) {
|
|
1180
|
-
|
|
1181
|
-
case 1:
|
|
1182
|
-
type = TEXTURE_TYPE.INTENSITY;
|
|
1183
|
-
break;
|
|
1184
|
-
case 2:
|
|
1185
|
-
type = TEXTURE_TYPE.INTENSITY_ALPHA;
|
|
1186
|
-
break;
|
|
1187
|
-
case 3:
|
|
1188
|
-
type = TEXTURE_TYPE.RGB;
|
|
1189
|
-
break;
|
|
1190
|
-
case 4:
|
|
1191
|
-
type = TEXTURE_TYPE.RGBA;
|
|
1192
|
-
break;
|
|
1193
|
-
default:
|
|
1194
|
-
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
|
-
return type;
|
|
1198
|
-
|
|
1199
|
-
}
|
|
1200
|
-
|
|
1201
|
-
function buildPixelTextureNode( node ) {
|
|
1202
|
-
|
|
1203
|
-
let texture;
|
|
1204
|
-
let wrapS = THREE.RepeatWrapping;
|
|
1205
|
-
let wrapT = THREE.RepeatWrapping;
|
|
1206
|
-
const fields = node.fields;
|
|
1207
|
-
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1208
|
-
|
|
1209
|
-
const field = fields[ i ];
|
|
1210
|
-
const fieldName = field.name;
|
|
1211
|
-
const fieldValues = field.values;
|
|
1212
|
-
switch ( fieldName ) {
|
|
1213
|
-
|
|
1214
|
-
case 'image':
|
|
1215
|
-
const width = fieldValues[ 0 ];
|
|
1216
|
-
const height = fieldValues[ 1 ];
|
|
1217
|
-
const num_components = fieldValues[ 2 ];
|
|
1218
|
-
const textureType = getTextureType( num_components );
|
|
1219
|
-
const data = new Uint8Array( 4 * width * height );
|
|
1220
|
-
const color = {
|
|
1221
|
-
r: 0,
|
|
1222
|
-
g: 0,
|
|
1223
|
-
b: 0,
|
|
1224
|
-
a: 0
|
|
1225
|
-
};
|
|
1226
|
-
for ( let j = 3, k = 0, jl = fieldValues.length; j < jl; j ++, k ++ ) {
|
|
1227
|
-
|
|
1228
|
-
parseHexColor( fieldValues[ j ], textureType, color );
|
|
1229
|
-
const stride = k * 4;
|
|
1230
|
-
data[ stride + 0 ] = color.r;
|
|
1231
|
-
data[ stride + 1 ] = color.g;
|
|
1232
|
-
data[ stride + 2 ] = color.b;
|
|
1233
|
-
data[ stride + 3 ] = color.a;
|
|
1234
|
-
|
|
1235
|
-
}
|
|
1236
|
-
|
|
1237
|
-
texture = new THREE.DataTexture( data, width, height );
|
|
1238
|
-
texture.needsUpdate = true;
|
|
1239
|
-
texture.__type = textureType; // needed for material modifications
|
|
1240
|
-
break;
|
|
1241
|
-
case 'repeatS':
|
|
1242
|
-
if ( fieldValues[ 0 ] === false ) wrapS = THREE.ClampToEdgeWrapping;
|
|
1243
|
-
break;
|
|
1244
|
-
case 'repeatT':
|
|
1245
|
-
if ( fieldValues[ 0 ] === false ) wrapT = THREE.ClampToEdgeWrapping;
|
|
1246
|
-
break;
|
|
1247
|
-
default:
|
|
1248
|
-
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1249
|
-
break;
|
|
1250
|
-
|
|
1251
|
-
}
|
|
1252
|
-
|
|
1253
|
-
}
|
|
1254
|
-
|
|
1255
|
-
if ( texture ) {
|
|
1256
|
-
|
|
1257
|
-
texture.wrapS = wrapS;
|
|
1258
|
-
texture.wrapT = wrapT;
|
|
1259
|
-
|
|
1260
|
-
}
|
|
1261
|
-
|
|
1262
|
-
return texture;
|
|
1263
|
-
|
|
1264
|
-
}
|
|
1265
|
-
|
|
1266
|
-
function buildImageTextureNode( node ) {
|
|
1267
|
-
|
|
1268
|
-
let texture;
|
|
1269
|
-
let wrapS = THREE.RepeatWrapping;
|
|
1270
|
-
let wrapT = THREE.RepeatWrapping;
|
|
1271
|
-
const fields = node.fields;
|
|
1272
|
-
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1273
|
-
|
|
1274
|
-
const field = fields[ i ];
|
|
1275
|
-
const fieldName = field.name;
|
|
1276
|
-
const fieldValues = field.values;
|
|
1277
|
-
switch ( fieldName ) {
|
|
1278
|
-
|
|
1279
|
-
case 'url':
|
|
1280
|
-
const url = fieldValues[ 0 ];
|
|
1281
|
-
if ( url ) texture = textureLoader.load( url );
|
|
1282
|
-
break;
|
|
1283
|
-
case 'repeatS':
|
|
1284
|
-
if ( fieldValues[ 0 ] === false ) wrapS = THREE.ClampToEdgeWrapping;
|
|
1285
|
-
break;
|
|
1286
|
-
case 'repeatT':
|
|
1287
|
-
if ( fieldValues[ 0 ] === false ) wrapT = THREE.ClampToEdgeWrapping;
|
|
1288
|
-
break;
|
|
1289
|
-
default:
|
|
1290
|
-
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1291
|
-
break;
|
|
1292
|
-
|
|
1293
|
-
}
|
|
1294
|
-
|
|
1295
|
-
}
|
|
1296
|
-
|
|
1297
|
-
if ( texture ) {
|
|
1298
|
-
|
|
1299
|
-
texture.wrapS = wrapS;
|
|
1300
|
-
texture.wrapT = wrapT;
|
|
1301
|
-
|
|
1302
|
-
}
|
|
1303
|
-
|
|
1304
|
-
return texture;
|
|
1305
|
-
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1308
|
-
function buildTextureTransformNode( node ) {
|
|
1309
|
-
|
|
1310
|
-
const transformData = {
|
|
1311
|
-
center: new THREE.Vector2(),
|
|
1312
|
-
rotation: new THREE.Vector2(),
|
|
1313
|
-
scale: new THREE.Vector2(),
|
|
1314
|
-
translation: new THREE.Vector2()
|
|
1315
|
-
};
|
|
1316
|
-
const fields = node.fields;
|
|
1317
|
-
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1318
|
-
|
|
1319
|
-
const field = fields[ i ];
|
|
1320
|
-
const fieldName = field.name;
|
|
1321
|
-
const fieldValues = field.values;
|
|
1322
|
-
switch ( fieldName ) {
|
|
1323
|
-
|
|
1324
|
-
case 'center':
|
|
1325
|
-
transformData.center.set( fieldValues[ 0 ], fieldValues[ 1 ] );
|
|
1326
|
-
break;
|
|
1327
|
-
case 'rotation':
|
|
1328
|
-
transformData.rotation = fieldValues[ 0 ];
|
|
1329
|
-
break;
|
|
1330
|
-
case 'scale':
|
|
1331
|
-
transformData.scale.set( fieldValues[ 0 ], fieldValues[ 1 ] );
|
|
1332
|
-
break;
|
|
1333
|
-
case 'translation':
|
|
1334
|
-
transformData.translation.set( fieldValues[ 0 ], fieldValues[ 1 ] );
|
|
1335
|
-
break;
|
|
1336
|
-
default:
|
|
1337
|
-
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1338
|
-
break;
|
|
1339
|
-
|
|
1340
|
-
}
|
|
1341
|
-
|
|
1342
|
-
}
|
|
1343
|
-
|
|
1344
|
-
return transformData;
|
|
1345
|
-
|
|
1346
|
-
}
|
|
1347
|
-
|
|
1348
|
-
function buildGeometricNode( node ) {
|
|
1349
|
-
|
|
1350
|
-
return node.fields[ 0 ].values;
|
|
1351
|
-
|
|
1352
|
-
}
|
|
1353
|
-
|
|
1354
|
-
function buildWorldInfoNode( node ) {
|
|
1355
|
-
|
|
1356
|
-
const worldInfo = {};
|
|
1357
|
-
const fields = node.fields;
|
|
1358
|
-
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1359
|
-
|
|
1360
|
-
const field = fields[ i ];
|
|
1361
|
-
const fieldName = field.name;
|
|
1362
|
-
const fieldValues = field.values;
|
|
1363
|
-
switch ( fieldName ) {
|
|
1364
|
-
|
|
1365
|
-
case 'title':
|
|
1366
|
-
worldInfo.title = fieldValues[ 0 ];
|
|
1367
|
-
break;
|
|
1368
|
-
case 'info':
|
|
1369
|
-
worldInfo.info = fieldValues;
|
|
1370
|
-
break;
|
|
1371
|
-
default:
|
|
1372
|
-
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1373
|
-
break;
|
|
1374
|
-
|
|
1375
|
-
}
|
|
1376
|
-
|
|
1377
|
-
}
|
|
1378
|
-
|
|
1379
|
-
return worldInfo;
|
|
1380
|
-
|
|
1381
|
-
}
|
|
1382
|
-
|
|
1383
|
-
function buildIndexedFaceSetNode( node ) {
|
|
1384
|
-
|
|
1385
|
-
let color, coord, normal, texCoord;
|
|
1386
|
-
let ccw = true,
|
|
1387
|
-
solid = true,
|
|
1388
|
-
creaseAngle = 0;
|
|
1389
|
-
let colorIndex, coordIndex, normalIndex, texCoordIndex;
|
|
1390
|
-
let colorPerVertex = true,
|
|
1391
|
-
normalPerVertex = true;
|
|
1392
|
-
const fields = node.fields;
|
|
1393
|
-
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1394
|
-
|
|
1395
|
-
const field = fields[ i ];
|
|
1396
|
-
const fieldName = field.name;
|
|
1397
|
-
const fieldValues = field.values;
|
|
1398
|
-
switch ( fieldName ) {
|
|
1399
|
-
|
|
1400
|
-
case 'color':
|
|
1401
|
-
const colorNode = fieldValues[ 0 ];
|
|
1402
|
-
if ( colorNode !== null ) {
|
|
1403
|
-
|
|
1404
|
-
color = getNode( colorNode );
|
|
1405
|
-
|
|
1406
|
-
}
|
|
1407
|
-
|
|
1408
|
-
break;
|
|
1409
|
-
case 'coord':
|
|
1410
|
-
const coordNode = fieldValues[ 0 ];
|
|
1411
|
-
if ( coordNode !== null ) {
|
|
1412
|
-
|
|
1413
|
-
coord = getNode( coordNode );
|
|
1414
|
-
|
|
1415
|
-
}
|
|
1416
|
-
|
|
1417
|
-
break;
|
|
1418
|
-
case 'normal':
|
|
1419
|
-
const normalNode = fieldValues[ 0 ];
|
|
1420
|
-
if ( normalNode !== null ) {
|
|
1421
|
-
|
|
1422
|
-
normal = getNode( normalNode );
|
|
1423
|
-
|
|
1424
|
-
}
|
|
1425
|
-
|
|
1426
|
-
break;
|
|
1427
|
-
case 'texCoord':
|
|
1428
|
-
const texCoordNode = fieldValues[ 0 ];
|
|
1429
|
-
if ( texCoordNode !== null ) {
|
|
1430
|
-
|
|
1431
|
-
texCoord = getNode( texCoordNode );
|
|
1432
|
-
|
|
1433
|
-
}
|
|
1434
|
-
|
|
1435
|
-
break;
|
|
1436
|
-
case 'ccw':
|
|
1437
|
-
ccw = fieldValues[ 0 ];
|
|
1438
|
-
break;
|
|
1439
|
-
case 'colorIndex':
|
|
1440
|
-
colorIndex = fieldValues;
|
|
1441
|
-
break;
|
|
1442
|
-
case 'colorPerVertex':
|
|
1443
|
-
colorPerVertex = fieldValues[ 0 ];
|
|
1444
|
-
break;
|
|
1445
|
-
case 'convex':
|
|
1446
|
-
// field not supported
|
|
1447
|
-
break;
|
|
1448
|
-
case 'coordIndex':
|
|
1449
|
-
coordIndex = fieldValues;
|
|
1450
|
-
break;
|
|
1451
|
-
case 'creaseAngle':
|
|
1452
|
-
creaseAngle = fieldValues[ 0 ];
|
|
1453
|
-
break;
|
|
1454
|
-
case 'normalIndex':
|
|
1455
|
-
normalIndex = fieldValues;
|
|
1456
|
-
break;
|
|
1457
|
-
case 'normalPerVertex':
|
|
1458
|
-
normalPerVertex = fieldValues[ 0 ];
|
|
1459
|
-
break;
|
|
1460
|
-
case 'solid':
|
|
1461
|
-
solid = fieldValues[ 0 ];
|
|
1462
|
-
break;
|
|
1463
|
-
case 'texCoordIndex':
|
|
1464
|
-
texCoordIndex = fieldValues;
|
|
1465
|
-
break;
|
|
1466
|
-
default:
|
|
1467
|
-
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1468
|
-
break;
|
|
1469
|
-
|
|
1470
|
-
}
|
|
1471
|
-
|
|
1472
|
-
}
|
|
1473
|
-
|
|
1474
|
-
if ( coordIndex === undefined ) {
|
|
1475
|
-
|
|
1476
|
-
console.warn( 'THREE.VRMLLoader: Missing coordIndex.' );
|
|
1477
|
-
return new THREE.BufferGeometry(); // handle VRML files with incomplete geometry definition
|
|
1478
|
-
|
|
1479
|
-
}
|
|
1480
|
-
|
|
1481
|
-
const triangulatedCoordIndex = triangulateFaceIndex( coordIndex, ccw );
|
|
1482
|
-
let colorAttribute;
|
|
1483
|
-
let normalAttribute;
|
|
1484
|
-
let uvAttribute;
|
|
1485
|
-
if ( color ) {
|
|
1486
|
-
|
|
1487
|
-
if ( colorPerVertex === true ) {
|
|
1488
|
-
|
|
1489
|
-
if ( colorIndex && colorIndex.length > 0 ) {
|
|
1490
|
-
|
|
1491
|
-
// if the colorIndex field is not empty, then it is used to choose colors for each vertex of the IndexedFaceSet.
|
|
1492
|
-
|
|
1493
|
-
const triangulatedColorIndex = triangulateFaceIndex( colorIndex, ccw );
|
|
1494
|
-
colorAttribute = computeAttributeFromIndexedData( triangulatedCoordIndex, triangulatedColorIndex, color, 3 );
|
|
1495
|
-
|
|
1496
|
-
} else {
|
|
1497
|
-
|
|
1498
|
-
// if the colorIndex field is empty, then the coordIndex field is used to choose colors from the THREE.Color node
|
|
1499
|
-
|
|
1500
|
-
colorAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new THREE.Float32BufferAttribute( color, 3 ) );
|
|
1501
|
-
|
|
1502
|
-
}
|
|
1503
|
-
|
|
1504
|
-
} else {
|
|
1505
|
-
|
|
1506
|
-
if ( colorIndex && colorIndex.length > 0 ) {
|
|
1507
|
-
|
|
1508
|
-
// if the colorIndex field is not empty, then they are used to choose one color for each face of the IndexedFaceSet
|
|
1509
|
-
|
|
1510
|
-
const flattenFaceColors = flattenData( color, colorIndex );
|
|
1511
|
-
const triangulatedFaceColors = triangulateFaceData( flattenFaceColors, coordIndex );
|
|
1512
|
-
colorAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceColors );
|
|
1513
|
-
|
|
1514
|
-
} else {
|
|
1515
|
-
|
|
1516
|
-
// if the colorIndex field is empty, then the color are applied to each face of the IndexedFaceSet in order
|
|
1517
|
-
|
|
1518
|
-
const triangulatedFaceColors = triangulateFaceData( color, coordIndex );
|
|
1519
|
-
colorAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceColors );
|
|
1520
|
-
|
|
1521
|
-
}
|
|
1522
|
-
|
|
1523
|
-
}
|
|
1524
|
-
|
|
1525
|
-
}
|
|
1526
|
-
|
|
1527
|
-
if ( normal ) {
|
|
1528
|
-
|
|
1529
|
-
if ( normalPerVertex === true ) {
|
|
1530
|
-
|
|
1531
|
-
// consider vertex normals
|
|
1532
|
-
|
|
1533
|
-
if ( normalIndex && normalIndex.length > 0 ) {
|
|
1534
|
-
|
|
1535
|
-
// if the normalIndex field is not empty, then it is used to choose normals for each vertex of the IndexedFaceSet.
|
|
1536
|
-
|
|
1537
|
-
const triangulatedNormalIndex = triangulateFaceIndex( normalIndex, ccw );
|
|
1538
|
-
normalAttribute = computeAttributeFromIndexedData( triangulatedCoordIndex, triangulatedNormalIndex, normal, 3 );
|
|
1539
|
-
|
|
1540
|
-
} else {
|
|
1541
|
-
|
|
1542
|
-
// if the normalIndex field is empty, then the coordIndex field is used to choose normals from the Normal node
|
|
1543
|
-
|
|
1544
|
-
normalAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new THREE.Float32BufferAttribute( normal, 3 ) );
|
|
1545
|
-
|
|
1546
|
-
}
|
|
1547
|
-
|
|
1548
|
-
} else {
|
|
1549
|
-
|
|
1550
|
-
// consider face normals
|
|
1551
|
-
|
|
1552
|
-
if ( normalIndex && normalIndex.length > 0 ) {
|
|
1553
|
-
|
|
1554
|
-
// if the normalIndex field is not empty, then they are used to choose one normal for each face of the IndexedFaceSet
|
|
1555
|
-
|
|
1556
|
-
const flattenFaceNormals = flattenData( normal, normalIndex );
|
|
1557
|
-
const triangulatedFaceNormals = triangulateFaceData( flattenFaceNormals, coordIndex );
|
|
1558
|
-
normalAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceNormals );
|
|
1559
|
-
|
|
1560
|
-
} else {
|
|
1561
|
-
|
|
1562
|
-
// if the normalIndex field is empty, then the normals are applied to each face of the IndexedFaceSet in order
|
|
1563
|
-
|
|
1564
|
-
const triangulatedFaceNormals = triangulateFaceData( normal, coordIndex );
|
|
1565
|
-
normalAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceNormals );
|
|
1566
|
-
|
|
1567
|
-
}
|
|
1568
|
-
|
|
1569
|
-
}
|
|
1570
|
-
|
|
1571
|
-
} else {
|
|
1572
|
-
|
|
1573
|
-
// if the normal field is NULL, then the loader should automatically generate normals, using creaseAngle to determine if and how normals are smoothed across shared vertices
|
|
1574
|
-
|
|
1575
|
-
normalAttribute = computeNormalAttribute( triangulatedCoordIndex, coord, creaseAngle );
|
|
1576
|
-
|
|
1577
|
-
}
|
|
1578
|
-
|
|
1579
|
-
if ( texCoord ) {
|
|
1580
|
-
|
|
1581
|
-
// texture coordinates are always defined on vertex level
|
|
1582
|
-
|
|
1583
|
-
if ( texCoordIndex && texCoordIndex.length > 0 ) {
|
|
1584
|
-
|
|
1585
|
-
// if the texCoordIndex field is not empty, then it is used to choose texture coordinates for each vertex of the IndexedFaceSet.
|
|
1586
|
-
|
|
1587
|
-
const triangulatedTexCoordIndex = triangulateFaceIndex( texCoordIndex, ccw );
|
|
1588
|
-
uvAttribute = computeAttributeFromIndexedData( triangulatedCoordIndex, triangulatedTexCoordIndex, texCoord, 2 );
|
|
1589
|
-
|
|
1590
|
-
} else {
|
|
1591
|
-
|
|
1592
|
-
// if the texCoordIndex field is empty, then the coordIndex array is used to choose texture coordinates from the TextureCoordinate node
|
|
1593
|
-
|
|
1594
|
-
uvAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new THREE.Float32BufferAttribute( texCoord, 2 ) );
|
|
1595
|
-
|
|
1596
|
-
}
|
|
1597
|
-
|
|
1598
|
-
}
|
|
1599
|
-
|
|
1600
|
-
const geometry = new THREE.BufferGeometry();
|
|
1601
|
-
const positionAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new THREE.Float32BufferAttribute( coord, 3 ) );
|
|
1602
|
-
geometry.setAttribute( 'position', positionAttribute );
|
|
1603
|
-
geometry.setAttribute( 'normal', normalAttribute );
|
|
1604
|
-
|
|
1605
|
-
// optional attributes
|
|
1606
|
-
|
|
1607
|
-
if ( colorAttribute ) geometry.setAttribute( 'color', colorAttribute );
|
|
1608
|
-
if ( uvAttribute ) geometry.setAttribute( 'uv', uvAttribute );
|
|
1609
|
-
|
|
1610
|
-
// "solid" influences the material so let's store it for later use
|
|
1611
|
-
|
|
1612
|
-
geometry._solid = solid;
|
|
1613
|
-
geometry._type = 'mesh';
|
|
1614
|
-
return geometry;
|
|
1615
|
-
|
|
1616
|
-
}
|
|
1617
|
-
|
|
1618
|
-
function buildIndexedLineSetNode( node ) {
|
|
1619
|
-
|
|
1620
|
-
let color, coord;
|
|
1621
|
-
let colorIndex, coordIndex;
|
|
1622
|
-
let colorPerVertex = true;
|
|
1623
|
-
const fields = node.fields;
|
|
1624
|
-
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1625
|
-
|
|
1626
|
-
const field = fields[ i ];
|
|
1627
|
-
const fieldName = field.name;
|
|
1628
|
-
const fieldValues = field.values;
|
|
1629
|
-
switch ( fieldName ) {
|
|
1630
|
-
|
|
1631
|
-
case 'color':
|
|
1632
|
-
const colorNode = fieldValues[ 0 ];
|
|
1633
|
-
if ( colorNode !== null ) {
|
|
1634
|
-
|
|
1635
|
-
color = getNode( colorNode );
|
|
1636
|
-
|
|
1637
|
-
}
|
|
1638
|
-
|
|
1639
|
-
break;
|
|
1640
|
-
case 'coord':
|
|
1641
|
-
const coordNode = fieldValues[ 0 ];
|
|
1642
|
-
if ( coordNode !== null ) {
|
|
1643
|
-
|
|
1644
|
-
coord = getNode( coordNode );
|
|
1645
|
-
|
|
1646
|
-
}
|
|
1647
|
-
|
|
1648
|
-
break;
|
|
1649
|
-
case 'colorIndex':
|
|
1650
|
-
colorIndex = fieldValues;
|
|
1651
|
-
break;
|
|
1652
|
-
case 'colorPerVertex':
|
|
1653
|
-
colorPerVertex = fieldValues[ 0 ];
|
|
1654
|
-
break;
|
|
1655
|
-
case 'coordIndex':
|
|
1656
|
-
coordIndex = fieldValues;
|
|
1657
|
-
break;
|
|
1658
|
-
default:
|
|
1659
|
-
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1660
|
-
break;
|
|
1661
|
-
|
|
1662
|
-
}
|
|
1663
|
-
|
|
1664
|
-
}
|
|
1665
|
-
|
|
1666
|
-
// build lines
|
|
1667
|
-
|
|
1668
|
-
let colorAttribute;
|
|
1669
|
-
const expandedLineIndex = expandLineIndex( coordIndex ); // create an index for three.js's linesegment primitive
|
|
1670
|
-
|
|
1671
|
-
if ( color ) {
|
|
1672
|
-
|
|
1673
|
-
if ( colorPerVertex === true ) {
|
|
1674
|
-
|
|
1675
|
-
if ( colorIndex.length > 0 ) {
|
|
1676
|
-
|
|
1677
|
-
// if the colorIndex field is not empty, then one color is used for each polyline of the IndexedLineSet.
|
|
1678
|
-
|
|
1679
|
-
const expandedColorIndex = expandLineIndex( colorIndex ); // compute colors for each line segment (rendering primitve)
|
|
1680
|
-
colorAttribute = computeAttributeFromIndexedData( expandedLineIndex, expandedColorIndex, color, 3 ); // compute data on vertex level
|
|
1681
|
-
|
|
1682
|
-
} else {
|
|
1683
|
-
|
|
1684
|
-
// if the colorIndex field is empty, then the colors are applied to each polyline of the IndexedLineSet in order.
|
|
1685
|
-
|
|
1686
|
-
colorAttribute = toNonIndexedAttribute( expandedLineIndex, new THREE.Float32BufferAttribute( color, 3 ) );
|
|
1687
|
-
|
|
1688
|
-
}
|
|
1689
|
-
|
|
1690
|
-
} else {
|
|
1691
|
-
|
|
1692
|
-
if ( colorIndex.length > 0 ) {
|
|
1693
|
-
|
|
1694
|
-
// if the colorIndex field is not empty, then colors are applied to each vertex of the IndexedLineSet
|
|
1695
|
-
|
|
1696
|
-
const flattenLineColors = flattenData( color, colorIndex ); // compute colors for each VRML primitve
|
|
1697
|
-
const expandedLineColors = expandLineData( flattenLineColors, coordIndex ); // compute colors for each line segment (rendering primitve)
|
|
1698
|
-
colorAttribute = computeAttributeFromLineData( expandedLineIndex, expandedLineColors ); // compute data on vertex level
|
|
1699
|
-
|
|
1700
|
-
} else {
|
|
1701
|
-
|
|
1702
|
-
// if the colorIndex field is empty, then the coordIndex field is used to choose colors from the THREE.Color node
|
|
1703
|
-
|
|
1704
|
-
const expandedLineColors = expandLineData( color, coordIndex ); // compute colors for each line segment (rendering primitve)
|
|
1705
|
-
colorAttribute = computeAttributeFromLineData( expandedLineIndex, expandedLineColors ); // compute data on vertex level
|
|
1706
|
-
|
|
1707
|
-
}
|
|
1708
|
-
|
|
1709
|
-
}
|
|
1710
|
-
|
|
1711
|
-
}
|
|
1712
|
-
|
|
1713
|
-
//
|
|
1714
|
-
|
|
1715
|
-
const geometry = new THREE.BufferGeometry();
|
|
1716
|
-
const positionAttribute = toNonIndexedAttribute( expandedLineIndex, new THREE.Float32BufferAttribute( coord, 3 ) );
|
|
1717
|
-
geometry.setAttribute( 'position', positionAttribute );
|
|
1718
|
-
if ( colorAttribute ) geometry.setAttribute( 'color', colorAttribute );
|
|
1719
|
-
geometry._type = 'line';
|
|
1720
|
-
return geometry;
|
|
1721
|
-
|
|
1722
|
-
}
|
|
1723
|
-
|
|
1724
|
-
function buildPointSetNode( node ) {
|
|
1725
|
-
|
|
1726
|
-
let color, coord;
|
|
1727
|
-
const fields = node.fields;
|
|
1728
|
-
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1729
|
-
|
|
1730
|
-
const field = fields[ i ];
|
|
1731
|
-
const fieldName = field.name;
|
|
1732
|
-
const fieldValues = field.values;
|
|
1733
|
-
switch ( fieldName ) {
|
|
1734
|
-
|
|
1735
|
-
case 'color':
|
|
1736
|
-
const colorNode = fieldValues[ 0 ];
|
|
1737
|
-
if ( colorNode !== null ) {
|
|
1738
|
-
|
|
1739
|
-
color = getNode( colorNode );
|
|
1740
|
-
|
|
1741
|
-
}
|
|
1742
|
-
|
|
1743
|
-
break;
|
|
1744
|
-
case 'coord':
|
|
1745
|
-
const coordNode = fieldValues[ 0 ];
|
|
1746
|
-
if ( coordNode !== null ) {
|
|
1747
|
-
|
|
1748
|
-
coord = getNode( coordNode );
|
|
1749
|
-
|
|
1750
|
-
}
|
|
1751
|
-
|
|
1752
|
-
break;
|
|
1753
|
-
default:
|
|
1754
|
-
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1755
|
-
break;
|
|
1756
|
-
|
|
1757
|
-
}
|
|
1758
|
-
|
|
1759
|
-
}
|
|
1760
|
-
|
|
1761
|
-
const geometry = new THREE.BufferGeometry();
|
|
1762
|
-
geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( coord, 3 ) );
|
|
1763
|
-
if ( color ) geometry.setAttribute( 'color', new THREE.Float32BufferAttribute( color, 3 ) );
|
|
1764
|
-
geometry._type = 'points';
|
|
1765
|
-
return geometry;
|
|
1766
|
-
|
|
1767
|
-
}
|
|
1768
|
-
|
|
1769
|
-
function buildBoxNode( node ) {
|
|
1770
|
-
|
|
1771
|
-
const size = new THREE.Vector3( 2, 2, 2 );
|
|
1772
|
-
const fields = node.fields;
|
|
1773
|
-
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1774
|
-
|
|
1775
|
-
const field = fields[ i ];
|
|
1776
|
-
const fieldName = field.name;
|
|
1777
|
-
const fieldValues = field.values;
|
|
1778
|
-
switch ( fieldName ) {
|
|
1779
|
-
|
|
1780
|
-
case 'size':
|
|
1781
|
-
size.x = fieldValues[ 0 ];
|
|
1782
|
-
size.y = fieldValues[ 1 ];
|
|
1783
|
-
size.z = fieldValues[ 2 ];
|
|
1784
|
-
break;
|
|
1785
|
-
default:
|
|
1786
|
-
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1787
|
-
break;
|
|
1788
|
-
|
|
1789
|
-
}
|
|
1790
|
-
|
|
1791
|
-
}
|
|
1792
|
-
|
|
1793
|
-
const geometry = new THREE.BoxGeometry( size.x, size.y, size.z );
|
|
1794
|
-
return geometry;
|
|
1795
|
-
|
|
1796
|
-
}
|
|
1797
|
-
|
|
1798
|
-
function buildConeNode( node ) {
|
|
1799
|
-
|
|
1800
|
-
let radius = 1,
|
|
1801
|
-
height = 2,
|
|
1802
|
-
openEnded = false;
|
|
1803
|
-
const fields = node.fields;
|
|
1804
|
-
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1805
|
-
|
|
1806
|
-
const field = fields[ i ];
|
|
1807
|
-
const fieldName = field.name;
|
|
1808
|
-
const fieldValues = field.values;
|
|
1809
|
-
switch ( fieldName ) {
|
|
1810
|
-
|
|
1811
|
-
case 'bottom':
|
|
1812
|
-
openEnded = ! fieldValues[ 0 ];
|
|
1813
|
-
break;
|
|
1814
|
-
case 'bottomRadius':
|
|
1815
|
-
radius = fieldValues[ 0 ];
|
|
1816
|
-
break;
|
|
1817
|
-
case 'height':
|
|
1818
|
-
height = fieldValues[ 0 ];
|
|
1819
|
-
break;
|
|
1820
|
-
case 'side':
|
|
1821
|
-
// field not supported
|
|
1822
|
-
break;
|
|
1823
|
-
default:
|
|
1824
|
-
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1825
|
-
break;
|
|
1826
|
-
|
|
1827
|
-
}
|
|
1828
|
-
|
|
1829
|
-
}
|
|
1830
|
-
|
|
1831
|
-
const geometry = new THREE.ConeGeometry( radius, height, 16, 1, openEnded );
|
|
1832
|
-
return geometry;
|
|
1833
|
-
|
|
1834
|
-
}
|
|
1835
|
-
|
|
1836
|
-
function buildCylinderNode( node ) {
|
|
1837
|
-
|
|
1838
|
-
let radius = 1,
|
|
1839
|
-
height = 2;
|
|
1840
|
-
const fields = node.fields;
|
|
1841
|
-
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1842
|
-
|
|
1843
|
-
const field = fields[ i ];
|
|
1844
|
-
const fieldName = field.name;
|
|
1845
|
-
const fieldValues = field.values;
|
|
1846
|
-
switch ( fieldName ) {
|
|
1847
|
-
|
|
1848
|
-
case 'bottom':
|
|
1849
|
-
// field not supported
|
|
1850
|
-
break;
|
|
1851
|
-
case 'radius':
|
|
1852
|
-
radius = fieldValues[ 0 ];
|
|
1853
|
-
break;
|
|
1854
|
-
case 'height':
|
|
1855
|
-
height = fieldValues[ 0 ];
|
|
1856
|
-
break;
|
|
1857
|
-
case 'side':
|
|
1858
|
-
// field not supported
|
|
1859
|
-
break;
|
|
1860
|
-
case 'top':
|
|
1861
|
-
// field not supported
|
|
1862
|
-
break;
|
|
1863
|
-
default:
|
|
1864
|
-
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1865
|
-
break;
|
|
1866
|
-
|
|
1867
|
-
}
|
|
1868
|
-
|
|
1869
|
-
}
|
|
1870
|
-
|
|
1871
|
-
const geometry = new THREE.CylinderGeometry( radius, radius, height, 16, 1 );
|
|
1872
|
-
return geometry;
|
|
1873
|
-
|
|
1874
|
-
}
|
|
1875
|
-
|
|
1876
|
-
function buildSphereNode( node ) {
|
|
1877
|
-
|
|
1878
|
-
let radius = 1;
|
|
1879
|
-
const fields = node.fields;
|
|
1880
|
-
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1881
|
-
|
|
1882
|
-
const field = fields[ i ];
|
|
1883
|
-
const fieldName = field.name;
|
|
1884
|
-
const fieldValues = field.values;
|
|
1885
|
-
switch ( fieldName ) {
|
|
1886
|
-
|
|
1887
|
-
case 'radius':
|
|
1888
|
-
radius = fieldValues[ 0 ];
|
|
1889
|
-
break;
|
|
1890
|
-
default:
|
|
1891
|
-
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1892
|
-
break;
|
|
1893
|
-
|
|
1894
|
-
}
|
|
1895
|
-
|
|
1896
|
-
}
|
|
1897
|
-
|
|
1898
|
-
const geometry = new THREE.SphereGeometry( radius, 16, 16 );
|
|
1899
|
-
return geometry;
|
|
1900
|
-
|
|
1901
|
-
}
|
|
1902
|
-
|
|
1903
|
-
function buildElevationGridNode( node ) {
|
|
1904
|
-
|
|
1905
|
-
let color;
|
|
1906
|
-
let normal;
|
|
1907
|
-
let texCoord;
|
|
1908
|
-
let height;
|
|
1909
|
-
let colorPerVertex = true;
|
|
1910
|
-
let normalPerVertex = true;
|
|
1911
|
-
let solid = true;
|
|
1912
|
-
let ccw = true;
|
|
1913
|
-
let creaseAngle = 0;
|
|
1914
|
-
let xDimension = 2;
|
|
1915
|
-
let zDimension = 2;
|
|
1916
|
-
let xSpacing = 1;
|
|
1917
|
-
let zSpacing = 1;
|
|
1918
|
-
const fields = node.fields;
|
|
1919
|
-
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1920
|
-
|
|
1921
|
-
const field = fields[ i ];
|
|
1922
|
-
const fieldName = field.name;
|
|
1923
|
-
const fieldValues = field.values;
|
|
1924
|
-
switch ( fieldName ) {
|
|
1925
|
-
|
|
1926
|
-
case 'color':
|
|
1927
|
-
const colorNode = fieldValues[ 0 ];
|
|
1928
|
-
if ( colorNode !== null ) {
|
|
1929
|
-
|
|
1930
|
-
color = getNode( colorNode );
|
|
1931
|
-
|
|
1932
|
-
}
|
|
1933
|
-
|
|
1934
|
-
break;
|
|
1935
|
-
case 'normal':
|
|
1936
|
-
const normalNode = fieldValues[ 0 ];
|
|
1937
|
-
if ( normalNode !== null ) {
|
|
1938
|
-
|
|
1939
|
-
normal = getNode( normalNode );
|
|
1940
|
-
|
|
1941
|
-
}
|
|
1942
|
-
|
|
1943
|
-
break;
|
|
1944
|
-
case 'texCoord':
|
|
1945
|
-
const texCoordNode = fieldValues[ 0 ];
|
|
1946
|
-
if ( texCoordNode !== null ) {
|
|
1947
|
-
|
|
1948
|
-
texCoord = getNode( texCoordNode );
|
|
1949
|
-
|
|
1950
|
-
}
|
|
1951
|
-
|
|
1952
|
-
break;
|
|
1953
|
-
case 'height':
|
|
1954
|
-
height = fieldValues;
|
|
1955
|
-
break;
|
|
1956
|
-
case 'ccw':
|
|
1957
|
-
ccw = fieldValues[ 0 ];
|
|
1958
|
-
break;
|
|
1959
|
-
case 'colorPerVertex':
|
|
1960
|
-
colorPerVertex = fieldValues[ 0 ];
|
|
1961
|
-
break;
|
|
1962
|
-
case 'creaseAngle':
|
|
1963
|
-
creaseAngle = fieldValues[ 0 ];
|
|
1964
|
-
break;
|
|
1965
|
-
case 'normalPerVertex':
|
|
1966
|
-
normalPerVertex = fieldValues[ 0 ];
|
|
1967
|
-
break;
|
|
1968
|
-
case 'solid':
|
|
1969
|
-
solid = fieldValues[ 0 ];
|
|
1970
|
-
break;
|
|
1971
|
-
case 'xDimension':
|
|
1972
|
-
xDimension = fieldValues[ 0 ];
|
|
1973
|
-
break;
|
|
1974
|
-
case 'xSpacing':
|
|
1975
|
-
xSpacing = fieldValues[ 0 ];
|
|
1976
|
-
break;
|
|
1977
|
-
case 'zDimension':
|
|
1978
|
-
zDimension = fieldValues[ 0 ];
|
|
1979
|
-
break;
|
|
1980
|
-
case 'zSpacing':
|
|
1981
|
-
zSpacing = fieldValues[ 0 ];
|
|
1982
|
-
break;
|
|
1983
|
-
default:
|
|
1984
|
-
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1985
|
-
break;
|
|
1986
|
-
|
|
1987
|
-
}
|
|
1988
|
-
|
|
1989
|
-
}
|
|
1990
|
-
|
|
1991
|
-
// vertex data
|
|
1992
|
-
|
|
1993
|
-
const vertices = [];
|
|
1994
|
-
const normals = [];
|
|
1995
|
-
const colors = [];
|
|
1996
|
-
const uvs = [];
|
|
1997
|
-
for ( let i = 0; i < zDimension; i ++ ) {
|
|
1998
|
-
|
|
1999
|
-
for ( let j = 0; j < xDimension; j ++ ) {
|
|
2000
|
-
|
|
2001
|
-
// compute a row major index
|
|
2002
|
-
|
|
2003
|
-
const index = i * xDimension + j;
|
|
2004
|
-
|
|
2005
|
-
// vertices
|
|
2006
|
-
|
|
2007
|
-
const x = xSpacing * i;
|
|
2008
|
-
const y = height[ index ];
|
|
2009
|
-
const z = zSpacing * j;
|
|
2010
|
-
vertices.push( x, y, z );
|
|
2011
|
-
|
|
2012
|
-
// colors
|
|
2013
|
-
|
|
2014
|
-
if ( color && colorPerVertex === true ) {
|
|
2015
|
-
|
|
2016
|
-
const r = color[ index * 3 + 0 ];
|
|
2017
|
-
const g = color[ index * 3 + 1 ];
|
|
2018
|
-
const b = color[ index * 3 + 2 ];
|
|
2019
|
-
colors.push( r, g, b );
|
|
2020
|
-
|
|
2021
|
-
}
|
|
2022
|
-
|
|
2023
|
-
// normals
|
|
2024
|
-
|
|
2025
|
-
if ( normal && normalPerVertex === true ) {
|
|
2026
|
-
|
|
2027
|
-
const xn = normal[ index * 3 + 0 ];
|
|
2028
|
-
const yn = normal[ index * 3 + 1 ];
|
|
2029
|
-
const zn = normal[ index * 3 + 2 ];
|
|
2030
|
-
normals.push( xn, yn, zn );
|
|
2031
|
-
|
|
2032
|
-
}
|
|
2033
|
-
|
|
2034
|
-
// uvs
|
|
2035
|
-
|
|
2036
|
-
if ( texCoord ) {
|
|
2037
|
-
|
|
2038
|
-
const s = texCoord[ index * 2 + 0 ];
|
|
2039
|
-
const t = texCoord[ index * 2 + 1 ];
|
|
2040
|
-
uvs.push( s, t );
|
|
2041
|
-
|
|
2042
|
-
} else {
|
|
2043
|
-
|
|
2044
|
-
uvs.push( i / ( xDimension - 1 ), j / ( zDimension - 1 ) );
|
|
2045
|
-
|
|
2046
|
-
}
|
|
2047
|
-
|
|
2048
|
-
}
|
|
2049
|
-
|
|
2050
|
-
}
|
|
2051
|
-
|
|
2052
|
-
// indices
|
|
2053
|
-
|
|
2054
|
-
const indices = [];
|
|
2055
|
-
for ( let i = 0; i < xDimension - 1; i ++ ) {
|
|
2056
|
-
|
|
2057
|
-
for ( let j = 0; j < zDimension - 1; j ++ ) {
|
|
2058
|
-
|
|
2059
|
-
// from https://tecfa.unige.ch/guides/vrml/vrml97/spec/part1/nodesRef.html#ElevationGrid
|
|
2060
|
-
|
|
2061
|
-
const a = i + j * xDimension;
|
|
2062
|
-
const b = i + ( j + 1 ) * xDimension;
|
|
2063
|
-
const c = i + 1 + ( j + 1 ) * xDimension;
|
|
2064
|
-
const d = i + 1 + j * xDimension;
|
|
2065
|
-
|
|
2066
|
-
// faces
|
|
2067
|
-
|
|
2068
|
-
if ( ccw === true ) {
|
|
2069
|
-
|
|
2070
|
-
indices.push( a, c, b );
|
|
2071
|
-
indices.push( c, a, d );
|
|
2072
|
-
|
|
2073
|
-
} else {
|
|
2074
|
-
|
|
2075
|
-
indices.push( a, b, c );
|
|
2076
|
-
indices.push( c, d, a );
|
|
2077
|
-
|
|
2078
|
-
}
|
|
2079
|
-
|
|
2080
|
-
}
|
|
2081
|
-
|
|
2082
|
-
}
|
|
2083
|
-
|
|
2084
|
-
//
|
|
2085
|
-
|
|
2086
|
-
const positionAttribute = toNonIndexedAttribute( indices, new THREE.Float32BufferAttribute( vertices, 3 ) );
|
|
2087
|
-
const uvAttribute = toNonIndexedAttribute( indices, new THREE.Float32BufferAttribute( uvs, 2 ) );
|
|
2088
|
-
let colorAttribute;
|
|
2089
|
-
let normalAttribute;
|
|
2090
|
-
|
|
2091
|
-
// color attribute
|
|
2092
|
-
|
|
2093
|
-
if ( color ) {
|
|
2094
|
-
|
|
2095
|
-
if ( colorPerVertex === false ) {
|
|
2096
|
-
|
|
2097
|
-
for ( let i = 0; i < xDimension - 1; i ++ ) {
|
|
2098
|
-
|
|
2099
|
-
for ( let j = 0; j < zDimension - 1; j ++ ) {
|
|
2100
|
-
|
|
2101
|
-
const index = i + j * ( xDimension - 1 );
|
|
2102
|
-
const r = color[ index * 3 + 0 ];
|
|
2103
|
-
const g = color[ index * 3 + 1 ];
|
|
2104
|
-
const b = color[ index * 3 + 2 ];
|
|
2105
|
-
|
|
2106
|
-
// one color per quad
|
|
2107
|
-
|
|
2108
|
-
colors.push( r, g, b );
|
|
2109
|
-
colors.push( r, g, b );
|
|
2110
|
-
colors.push( r, g, b );
|
|
2111
|
-
colors.push( r, g, b );
|
|
2112
|
-
colors.push( r, g, b );
|
|
2113
|
-
colors.push( r, g, b );
|
|
2114
|
-
|
|
2115
|
-
}
|
|
2116
|
-
|
|
2117
|
-
}
|
|
2118
|
-
|
|
2119
|
-
colorAttribute = new THREE.Float32BufferAttribute( colors, 3 );
|
|
2120
|
-
|
|
2121
|
-
} else {
|
|
2122
|
-
|
|
2123
|
-
colorAttribute = toNonIndexedAttribute( indices, new THREE.Float32BufferAttribute( colors, 3 ) );
|
|
2124
|
-
|
|
2125
|
-
}
|
|
2126
|
-
|
|
2127
|
-
}
|
|
2128
|
-
|
|
2129
|
-
// normal attribute
|
|
2130
|
-
|
|
2131
|
-
if ( normal ) {
|
|
2132
|
-
|
|
2133
|
-
if ( normalPerVertex === false ) {
|
|
2134
|
-
|
|
2135
|
-
for ( let i = 0; i < xDimension - 1; i ++ ) {
|
|
2136
|
-
|
|
2137
|
-
for ( let j = 0; j < zDimension - 1; j ++ ) {
|
|
2138
|
-
|
|
2139
|
-
const index = i + j * ( xDimension - 1 );
|
|
2140
|
-
const xn = normal[ index * 3 + 0 ];
|
|
2141
|
-
const yn = normal[ index * 3 + 1 ];
|
|
2142
|
-
const zn = normal[ index * 3 + 2 ];
|
|
2143
|
-
|
|
2144
|
-
// one normal per quad
|
|
2145
|
-
|
|
2146
|
-
normals.push( xn, yn, zn );
|
|
2147
|
-
normals.push( xn, yn, zn );
|
|
2148
|
-
normals.push( xn, yn, zn );
|
|
2149
|
-
normals.push( xn, yn, zn );
|
|
2150
|
-
normals.push( xn, yn, zn );
|
|
2151
|
-
normals.push( xn, yn, zn );
|
|
2152
|
-
|
|
2153
|
-
}
|
|
2154
|
-
|
|
2155
|
-
}
|
|
2156
|
-
|
|
2157
|
-
normalAttribute = new THREE.Float32BufferAttribute( normals, 3 );
|
|
2158
|
-
|
|
2159
|
-
} else {
|
|
2160
|
-
|
|
2161
|
-
normalAttribute = toNonIndexedAttribute( indices, new THREE.Float32BufferAttribute( normals, 3 ) );
|
|
2162
|
-
|
|
2163
|
-
}
|
|
2164
|
-
|
|
2165
|
-
} else {
|
|
2166
|
-
|
|
2167
|
-
normalAttribute = computeNormalAttribute( indices, vertices, creaseAngle );
|
|
2168
|
-
|
|
2169
|
-
}
|
|
2170
|
-
|
|
2171
|
-
// build geometry
|
|
2172
|
-
|
|
2173
|
-
const geometry = new THREE.BufferGeometry();
|
|
2174
|
-
geometry.setAttribute( 'position', positionAttribute );
|
|
2175
|
-
geometry.setAttribute( 'normal', normalAttribute );
|
|
2176
|
-
geometry.setAttribute( 'uv', uvAttribute );
|
|
2177
|
-
if ( colorAttribute ) geometry.setAttribute( 'color', colorAttribute );
|
|
2178
|
-
|
|
2179
|
-
// "solid" influences the material so let's store it for later use
|
|
2180
|
-
|
|
2181
|
-
geometry._solid = solid;
|
|
2182
|
-
geometry._type = 'mesh';
|
|
2183
|
-
return geometry;
|
|
2184
|
-
|
|
2185
|
-
}
|
|
2186
|
-
|
|
2187
|
-
function buildExtrusionNode( node ) {
|
|
2188
|
-
|
|
2189
|
-
let crossSection = [ 1, 1, 1, - 1, - 1, - 1, - 1, 1, 1, 1 ];
|
|
2190
|
-
let spine = [ 0, 0, 0, 0, 1, 0 ];
|
|
2191
|
-
let scale;
|
|
2192
|
-
let orientation;
|
|
2193
|
-
let beginCap = true;
|
|
2194
|
-
let ccw = true;
|
|
2195
|
-
let creaseAngle = 0;
|
|
2196
|
-
let endCap = true;
|
|
2197
|
-
let solid = true;
|
|
2198
|
-
const fields = node.fields;
|
|
2199
|
-
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
2200
|
-
|
|
2201
|
-
const field = fields[ i ];
|
|
2202
|
-
const fieldName = field.name;
|
|
2203
|
-
const fieldValues = field.values;
|
|
2204
|
-
switch ( fieldName ) {
|
|
2205
|
-
|
|
2206
|
-
case 'beginCap':
|
|
2207
|
-
beginCap = fieldValues[ 0 ];
|
|
2208
|
-
break;
|
|
2209
|
-
case 'ccw':
|
|
2210
|
-
ccw = fieldValues[ 0 ];
|
|
2211
|
-
break;
|
|
2212
|
-
case 'convex':
|
|
2213
|
-
// field not supported
|
|
2214
|
-
break;
|
|
2215
|
-
case 'creaseAngle':
|
|
2216
|
-
creaseAngle = fieldValues[ 0 ];
|
|
2217
|
-
break;
|
|
2218
|
-
case 'crossSection':
|
|
2219
|
-
crossSection = fieldValues;
|
|
2220
|
-
break;
|
|
2221
|
-
case 'endCap':
|
|
2222
|
-
endCap = fieldValues[ 0 ];
|
|
2223
|
-
break;
|
|
2224
|
-
case 'orientation':
|
|
2225
|
-
orientation = fieldValues;
|
|
2226
|
-
break;
|
|
2227
|
-
case 'scale':
|
|
2228
|
-
scale = fieldValues;
|
|
2229
|
-
break;
|
|
2230
|
-
case 'solid':
|
|
2231
|
-
solid = fieldValues[ 0 ];
|
|
2232
|
-
break;
|
|
2233
|
-
case 'spine':
|
|
2234
|
-
spine = fieldValues; // only extrusion along the Y-axis are supported so far
|
|
2235
|
-
break;
|
|
2236
|
-
default:
|
|
2237
|
-
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
2238
|
-
break;
|
|
2239
|
-
|
|
2240
|
-
}
|
|
2241
|
-
|
|
2242
|
-
}
|
|
2243
|
-
|
|
2244
|
-
const crossSectionClosed = crossSection[ 0 ] === crossSection[ crossSection.length - 2 ] && crossSection[ 1 ] === crossSection[ crossSection.length - 1 ];
|
|
2245
|
-
|
|
2246
|
-
// vertices
|
|
2247
|
-
|
|
2248
|
-
const vertices = [];
|
|
2249
|
-
const spineVector = new THREE.Vector3();
|
|
2250
|
-
const scaling = new THREE.Vector3();
|
|
2251
|
-
const axis = new THREE.Vector3();
|
|
2252
|
-
const vertex = new THREE.Vector3();
|
|
2253
|
-
const quaternion = new THREE.Quaternion();
|
|
2254
|
-
for ( let i = 0, j = 0, o = 0, il = spine.length; i < il; i += 3, j += 2, o += 4 ) {
|
|
2255
|
-
|
|
2256
|
-
spineVector.fromArray( spine, i );
|
|
2257
|
-
scaling.x = scale ? scale[ j + 0 ] : 1;
|
|
2258
|
-
scaling.y = 1;
|
|
2259
|
-
scaling.z = scale ? scale[ j + 1 ] : 1;
|
|
2260
|
-
axis.x = orientation ? orientation[ o + 0 ] : 0;
|
|
2261
|
-
axis.y = orientation ? orientation[ o + 1 ] : 0;
|
|
2262
|
-
axis.z = orientation ? orientation[ o + 2 ] : 1;
|
|
2263
|
-
const angle = orientation ? orientation[ o + 3 ] : 0;
|
|
2264
|
-
for ( let k = 0, kl = crossSection.length; k < kl; k += 2 ) {
|
|
2265
|
-
|
|
2266
|
-
vertex.x = crossSection[ k + 0 ];
|
|
2267
|
-
vertex.y = 0;
|
|
2268
|
-
vertex.z = crossSection[ k + 1 ];
|
|
2269
|
-
|
|
2270
|
-
// scale
|
|
2271
|
-
|
|
2272
|
-
vertex.multiply( scaling );
|
|
2273
|
-
|
|
2274
|
-
// rotate
|
|
2275
|
-
|
|
2276
|
-
quaternion.setFromAxisAngle( axis, angle );
|
|
2277
|
-
vertex.applyQuaternion( quaternion );
|
|
2278
|
-
|
|
2279
|
-
// translate
|
|
2280
|
-
|
|
2281
|
-
vertex.add( spineVector );
|
|
2282
|
-
vertices.push( vertex.x, vertex.y, vertex.z );
|
|
2283
|
-
|
|
2284
|
-
}
|
|
2285
|
-
|
|
2286
|
-
}
|
|
2287
|
-
|
|
2288
|
-
// indices
|
|
2289
|
-
|
|
2290
|
-
const indices = [];
|
|
2291
|
-
const spineCount = spine.length / 3;
|
|
2292
|
-
const crossSectionCount = crossSection.length / 2;
|
|
2293
|
-
for ( let i = 0; i < spineCount - 1; i ++ ) {
|
|
2294
|
-
|
|
2295
|
-
for ( let j = 0; j < crossSectionCount - 1; j ++ ) {
|
|
2296
|
-
|
|
2297
|
-
const a = j + i * crossSectionCount;
|
|
2298
|
-
let b = j + 1 + i * crossSectionCount;
|
|
2299
|
-
const c = j + ( i + 1 ) * crossSectionCount;
|
|
2300
|
-
let d = j + 1 + ( i + 1 ) * crossSectionCount;
|
|
2301
|
-
if ( j === crossSectionCount - 2 && crossSectionClosed === true ) {
|
|
2302
|
-
|
|
2303
|
-
b = i * crossSectionCount;
|
|
2304
|
-
d = ( i + 1 ) * crossSectionCount;
|
|
2305
|
-
|
|
2306
|
-
}
|
|
2307
|
-
|
|
2308
|
-
if ( ccw === true ) {
|
|
2309
|
-
|
|
2310
|
-
indices.push( a, b, c );
|
|
2311
|
-
indices.push( c, b, d );
|
|
2312
|
-
|
|
2313
|
-
} else {
|
|
2314
|
-
|
|
2315
|
-
indices.push( a, c, b );
|
|
2316
|
-
indices.push( c, d, b );
|
|
2317
|
-
|
|
2318
|
-
}
|
|
2319
|
-
|
|
2320
|
-
}
|
|
2321
|
-
|
|
2322
|
-
}
|
|
2323
|
-
|
|
2324
|
-
// triangulate cap
|
|
2325
|
-
|
|
2326
|
-
if ( beginCap === true || endCap === true ) {
|
|
2327
|
-
|
|
2328
|
-
const contour = [];
|
|
2329
|
-
for ( let i = 0, l = crossSection.length; i < l; i += 2 ) {
|
|
2330
|
-
|
|
2331
|
-
contour.push( new THREE.Vector2( crossSection[ i ], crossSection[ i + 1 ] ) );
|
|
2332
|
-
|
|
2333
|
-
}
|
|
2334
|
-
|
|
2335
|
-
const faces = THREE.ShapeUtils.triangulateShape( contour, [] );
|
|
2336
|
-
const capIndices = [];
|
|
2337
|
-
for ( let i = 0, l = faces.length; i < l; i ++ ) {
|
|
2338
|
-
|
|
2339
|
-
const face = faces[ i ];
|
|
2340
|
-
capIndices.push( face[ 0 ], face[ 1 ], face[ 2 ] );
|
|
2341
|
-
|
|
2342
|
-
}
|
|
2343
|
-
|
|
2344
|
-
// begin cap
|
|
2345
|
-
|
|
2346
|
-
if ( beginCap === true ) {
|
|
2347
|
-
|
|
2348
|
-
for ( let i = 0, l = capIndices.length; i < l; i += 3 ) {
|
|
2349
|
-
|
|
2350
|
-
if ( ccw === true ) {
|
|
2351
|
-
|
|
2352
|
-
indices.push( capIndices[ i + 0 ], capIndices[ i + 1 ], capIndices[ i + 2 ] );
|
|
2353
|
-
|
|
2354
|
-
} else {
|
|
2355
|
-
|
|
2356
|
-
indices.push( capIndices[ i + 0 ], capIndices[ i + 2 ], capIndices[ i + 1 ] );
|
|
2357
|
-
|
|
2358
|
-
}
|
|
2359
|
-
|
|
2360
|
-
}
|
|
2361
|
-
|
|
2362
|
-
}
|
|
2363
|
-
|
|
2364
|
-
// end cap
|
|
2365
|
-
|
|
2366
|
-
if ( endCap === true ) {
|
|
2367
|
-
|
|
2368
|
-
const indexOffset = crossSectionCount * ( spineCount - 1 ); // references to the first vertex of the last cross section
|
|
2369
|
-
|
|
2370
|
-
for ( let i = 0, l = capIndices.length; i < l; i += 3 ) {
|
|
2371
|
-
|
|
2372
|
-
if ( ccw === true ) {
|
|
2373
|
-
|
|
2374
|
-
indices.push( indexOffset + capIndices[ i + 0 ], indexOffset + capIndices[ i + 2 ], indexOffset + capIndices[ i + 1 ] );
|
|
2375
|
-
|
|
2376
|
-
} else {
|
|
2377
|
-
|
|
2378
|
-
indices.push( indexOffset + capIndices[ i + 0 ], indexOffset + capIndices[ i + 1 ], indexOffset + capIndices[ i + 2 ] );
|
|
2379
|
-
|
|
2380
|
-
}
|
|
2381
|
-
|
|
2382
|
-
}
|
|
2383
|
-
|
|
2384
|
-
}
|
|
2385
|
-
|
|
2386
|
-
}
|
|
2387
|
-
|
|
2388
|
-
const positionAttribute = toNonIndexedAttribute( indices, new THREE.Float32BufferAttribute( vertices, 3 ) );
|
|
2389
|
-
const normalAttribute = computeNormalAttribute( indices, vertices, creaseAngle );
|
|
2390
|
-
const geometry = new THREE.BufferGeometry();
|
|
2391
|
-
geometry.setAttribute( 'position', positionAttribute );
|
|
2392
|
-
geometry.setAttribute( 'normal', normalAttribute );
|
|
2393
|
-
// no uvs yet
|
|
2394
|
-
|
|
2395
|
-
// "solid" influences the material so let's store it for later use
|
|
2396
|
-
|
|
2397
|
-
geometry._solid = solid;
|
|
2398
|
-
geometry._type = 'mesh';
|
|
2399
|
-
return geometry;
|
|
2400
|
-
|
|
2401
|
-
}
|
|
2402
|
-
|
|
2403
|
-
// helper functions
|
|
2404
|
-
|
|
2405
|
-
function resolveUSE( identifier ) {
|
|
2406
|
-
|
|
2407
|
-
const node = nodeMap[ identifier ];
|
|
2408
|
-
const build = getNode( node );
|
|
2409
|
-
|
|
2410
|
-
// because the same 3D objects can have different transformations, it's necessary to clone them.
|
|
2411
|
-
// materials can be influenced by the geometry (e.g. vertex normals). cloning is necessary to avoid
|
|
2412
|
-
// any side effects
|
|
2413
|
-
|
|
2414
|
-
return build.isObject3D || build.isMaterial ? build.clone() : build;
|
|
2415
|
-
|
|
2416
|
-
}
|
|
2417
|
-
|
|
2418
|
-
function parseFieldChildren( children, owner ) {
|
|
2419
|
-
|
|
2420
|
-
for ( let i = 0, l = children.length; i < l; i ++ ) {
|
|
2421
|
-
|
|
2422
|
-
const object = getNode( children[ i ] );
|
|
2423
|
-
if ( object instanceof THREE.Object3D ) owner.add( object );
|
|
2424
|
-
|
|
2425
|
-
}
|
|
2426
|
-
|
|
2427
|
-
}
|
|
2428
|
-
|
|
2429
|
-
function triangulateFaceIndex( index, ccw ) {
|
|
2430
|
-
|
|
2431
|
-
const indices = [];
|
|
2432
|
-
|
|
2433
|
-
// since face defintions can have more than three vertices, it's necessary to
|
|
2434
|
-
// perform a simple triangulation
|
|
2435
|
-
|
|
2436
|
-
let start = 0;
|
|
2437
|
-
for ( let i = 0, l = index.length; i < l; i ++ ) {
|
|
2438
|
-
|
|
2439
|
-
const i1 = index[ start ];
|
|
2440
|
-
const i2 = index[ i + ( ccw ? 1 : 2 ) ];
|
|
2441
|
-
const i3 = index[ i + ( ccw ? 2 : 1 ) ];
|
|
2442
|
-
indices.push( i1, i2, i3 );
|
|
2443
|
-
|
|
2444
|
-
// an index of -1 indicates that the current face has ended and the next one begins
|
|
2445
|
-
|
|
2446
|
-
if ( index[ i + 3 ] === - 1 || i + 3 >= l ) {
|
|
2447
|
-
|
|
2448
|
-
i += 3;
|
|
2449
|
-
start = i + 1;
|
|
2450
|
-
|
|
2451
|
-
}
|
|
2452
|
-
|
|
2453
|
-
}
|
|
2454
|
-
|
|
2455
|
-
return indices;
|
|
2456
|
-
|
|
2457
|
-
}
|
|
2458
|
-
|
|
2459
|
-
function triangulateFaceData( data, index ) {
|
|
2460
|
-
|
|
2461
|
-
const triangulatedData = [];
|
|
2462
|
-
let start = 0;
|
|
2463
|
-
for ( let i = 0, l = index.length; i < l; i ++ ) {
|
|
2464
|
-
|
|
2465
|
-
const stride = start * 3;
|
|
2466
|
-
const x = data[ stride ];
|
|
2467
|
-
const y = data[ stride + 1 ];
|
|
2468
|
-
const z = data[ stride + 2 ];
|
|
2469
|
-
triangulatedData.push( x, y, z );
|
|
2470
|
-
|
|
2471
|
-
// an index of -1 indicates that the current face has ended and the next one begins
|
|
2472
|
-
|
|
2473
|
-
if ( index[ i + 3 ] === - 1 || i + 3 >= l ) {
|
|
2474
|
-
|
|
2475
|
-
i += 3;
|
|
2476
|
-
start ++;
|
|
2477
|
-
|
|
2478
|
-
}
|
|
2479
|
-
|
|
2480
|
-
}
|
|
2481
|
-
|
|
2482
|
-
return triangulatedData;
|
|
2483
|
-
|
|
2484
|
-
}
|
|
2485
|
-
|
|
2486
|
-
function flattenData( data, index ) {
|
|
2487
|
-
|
|
2488
|
-
const flattenData = [];
|
|
2489
|
-
for ( let i = 0, l = index.length; i < l; i ++ ) {
|
|
2490
|
-
|
|
2491
|
-
const i1 = index[ i ];
|
|
2492
|
-
const stride = i1 * 3;
|
|
2493
|
-
const x = data[ stride ];
|
|
2494
|
-
const y = data[ stride + 1 ];
|
|
2495
|
-
const z = data[ stride + 2 ];
|
|
2496
|
-
flattenData.push( x, y, z );
|
|
2497
|
-
|
|
2498
|
-
}
|
|
2499
|
-
|
|
2500
|
-
return flattenData;
|
|
2501
|
-
|
|
2502
|
-
}
|
|
2503
|
-
|
|
2504
|
-
function expandLineIndex( index ) {
|
|
2505
|
-
|
|
2506
|
-
const indices = [];
|
|
2507
|
-
for ( let i = 0, l = index.length; i < l; i ++ ) {
|
|
2508
|
-
|
|
2509
|
-
const i1 = index[ i ];
|
|
2510
|
-
const i2 = index[ i + 1 ];
|
|
2511
|
-
indices.push( i1, i2 );
|
|
2512
|
-
|
|
2513
|
-
// an index of -1 indicates that the current line has ended and the next one begins
|
|
2514
|
-
|
|
2515
|
-
if ( index[ i + 2 ] === - 1 || i + 2 >= l ) {
|
|
2516
|
-
|
|
2517
|
-
i += 2;
|
|
2518
|
-
|
|
2519
|
-
}
|
|
2520
|
-
|
|
2521
|
-
}
|
|
2522
|
-
|
|
2523
|
-
return indices;
|
|
2524
|
-
|
|
2525
|
-
}
|
|
2526
|
-
|
|
2527
|
-
function expandLineData( data, index ) {
|
|
2528
|
-
|
|
2529
|
-
const triangulatedData = [];
|
|
2530
|
-
let start = 0;
|
|
2531
|
-
for ( let i = 0, l = index.length; i < l; i ++ ) {
|
|
2532
|
-
|
|
2533
|
-
const stride = start * 3;
|
|
2534
|
-
const x = data[ stride ];
|
|
2535
|
-
const y = data[ stride + 1 ];
|
|
2536
|
-
const z = data[ stride + 2 ];
|
|
2537
|
-
triangulatedData.push( x, y, z );
|
|
2538
|
-
|
|
2539
|
-
// an index of -1 indicates that the current line has ended and the next one begins
|
|
2540
|
-
|
|
2541
|
-
if ( index[ i + 2 ] === - 1 || i + 2 >= l ) {
|
|
2542
|
-
|
|
2543
|
-
i += 2;
|
|
2544
|
-
start ++;
|
|
2545
|
-
|
|
2546
|
-
}
|
|
2547
|
-
|
|
2548
|
-
}
|
|
2549
|
-
|
|
2550
|
-
return triangulatedData;
|
|
2551
|
-
|
|
2552
|
-
}
|
|
2553
|
-
|
|
2554
|
-
const vA = new THREE.Vector3();
|
|
2555
|
-
const vB = new THREE.Vector3();
|
|
2556
|
-
const vC = new THREE.Vector3();
|
|
2557
|
-
const uvA = new THREE.Vector2();
|
|
2558
|
-
const uvB = new THREE.Vector2();
|
|
2559
|
-
const uvC = new THREE.Vector2();
|
|
2560
|
-
function computeAttributeFromIndexedData( coordIndex, index, data, itemSize ) {
|
|
2561
|
-
|
|
2562
|
-
const array = [];
|
|
2563
|
-
|
|
2564
|
-
// we use the coordIndex.length as delimiter since normalIndex must contain at least as many indices
|
|
2565
|
-
|
|
2566
|
-
for ( let i = 0, l = coordIndex.length; i < l; i += 3 ) {
|
|
2567
|
-
|
|
2568
|
-
const a = index[ i ];
|
|
2569
|
-
const b = index[ i + 1 ];
|
|
2570
|
-
const c = index[ i + 2 ];
|
|
2571
|
-
if ( itemSize === 2 ) {
|
|
2572
|
-
|
|
2573
|
-
uvA.fromArray( data, a * itemSize );
|
|
2574
|
-
uvB.fromArray( data, b * itemSize );
|
|
2575
|
-
uvC.fromArray( data, c * itemSize );
|
|
2576
|
-
array.push( uvA.x, uvA.y );
|
|
2577
|
-
array.push( uvB.x, uvB.y );
|
|
2578
|
-
array.push( uvC.x, uvC.y );
|
|
2579
|
-
|
|
2580
|
-
} else {
|
|
2581
|
-
|
|
2582
|
-
vA.fromArray( data, a * itemSize );
|
|
2583
|
-
vB.fromArray( data, b * itemSize );
|
|
2584
|
-
vC.fromArray( data, c * itemSize );
|
|
2585
|
-
array.push( vA.x, vA.y, vA.z );
|
|
2586
|
-
array.push( vB.x, vB.y, vB.z );
|
|
2587
|
-
array.push( vC.x, vC.y, vC.z );
|
|
2588
|
-
|
|
2589
|
-
}
|
|
2590
|
-
|
|
2591
|
-
}
|
|
2592
|
-
|
|
2593
|
-
return new THREE.Float32BufferAttribute( array, itemSize );
|
|
2594
|
-
|
|
2595
|
-
}
|
|
2596
|
-
|
|
2597
|
-
function computeAttributeFromFaceData( index, faceData ) {
|
|
2598
|
-
|
|
2599
|
-
const array = [];
|
|
2600
|
-
for ( let i = 0, j = 0, l = index.length; i < l; i += 3, j ++ ) {
|
|
2601
|
-
|
|
2602
|
-
vA.fromArray( faceData, j * 3 );
|
|
2603
|
-
array.push( vA.x, vA.y, vA.z );
|
|
2604
|
-
array.push( vA.x, vA.y, vA.z );
|
|
2605
|
-
array.push( vA.x, vA.y, vA.z );
|
|
2606
|
-
|
|
2607
|
-
}
|
|
2608
|
-
|
|
2609
|
-
return new THREE.Float32BufferAttribute( array, 3 );
|
|
2610
|
-
|
|
2611
|
-
}
|
|
2612
|
-
|
|
2613
|
-
function computeAttributeFromLineData( index, lineData ) {
|
|
2614
|
-
|
|
2615
|
-
const array = [];
|
|
2616
|
-
for ( let i = 0, j = 0, l = index.length; i < l; i += 2, j ++ ) {
|
|
2617
|
-
|
|
2618
|
-
vA.fromArray( lineData, j * 3 );
|
|
2619
|
-
array.push( vA.x, vA.y, vA.z );
|
|
2620
|
-
array.push( vA.x, vA.y, vA.z );
|
|
2621
|
-
|
|
2622
|
-
}
|
|
2623
|
-
|
|
2624
|
-
return new THREE.Float32BufferAttribute( array, 3 );
|
|
2625
|
-
|
|
2626
|
-
}
|
|
2627
|
-
|
|
2628
|
-
function toNonIndexedAttribute( indices, attribute ) {
|
|
2629
|
-
|
|
2630
|
-
const array = attribute.array;
|
|
2631
|
-
const itemSize = attribute.itemSize;
|
|
2632
|
-
const array2 = new array.constructor( indices.length * itemSize );
|
|
2633
|
-
let index = 0,
|
|
2634
|
-
index2 = 0;
|
|
2635
|
-
for ( let i = 0, l = indices.length; i < l; i ++ ) {
|
|
2636
|
-
|
|
2637
|
-
index = indices[ i ] * itemSize;
|
|
2638
|
-
for ( let j = 0; j < itemSize; j ++ ) {
|
|
2639
|
-
|
|
2640
|
-
array2[ index2 ++ ] = array[ index ++ ];
|
|
2641
|
-
|
|
2642
|
-
}
|
|
2643
|
-
|
|
2644
|
-
}
|
|
2645
|
-
|
|
2646
|
-
return new THREE.Float32BufferAttribute( array2, itemSize );
|
|
2647
|
-
|
|
2648
|
-
}
|
|
2649
|
-
|
|
2650
|
-
const ab = new THREE.Vector3();
|
|
2651
|
-
const cb = new THREE.Vector3();
|
|
2652
|
-
function computeNormalAttribute( index, coord, creaseAngle ) {
|
|
2653
|
-
|
|
2654
|
-
const faces = [];
|
|
2655
|
-
const vertexNormals = {};
|
|
2656
|
-
|
|
2657
|
-
// prepare face and raw vertex normals
|
|
2658
|
-
|
|
2659
|
-
for ( let i = 0, l = index.length; i < l; i += 3 ) {
|
|
2660
|
-
|
|
2661
|
-
const a = index[ i ];
|
|
2662
|
-
const b = index[ i + 1 ];
|
|
2663
|
-
const c = index[ i + 2 ];
|
|
2664
|
-
const face = new Face( a, b, c );
|
|
2665
|
-
vA.fromArray( coord, a * 3 );
|
|
2666
|
-
vB.fromArray( coord, b * 3 );
|
|
2667
|
-
vC.fromArray( coord, c * 3 );
|
|
2668
|
-
cb.subVectors( vC, vB );
|
|
2669
|
-
ab.subVectors( vA, vB );
|
|
2670
|
-
cb.cross( ab );
|
|
2671
|
-
cb.normalize();
|
|
2672
|
-
face.normal.copy( cb );
|
|
2673
|
-
if ( vertexNormals[ a ] === undefined ) vertexNormals[ a ] = [];
|
|
2674
|
-
if ( vertexNormals[ b ] === undefined ) vertexNormals[ b ] = [];
|
|
2675
|
-
if ( vertexNormals[ c ] === undefined ) vertexNormals[ c ] = [];
|
|
2676
|
-
vertexNormals[ a ].push( face.normal );
|
|
2677
|
-
vertexNormals[ b ].push( face.normal );
|
|
2678
|
-
vertexNormals[ c ].push( face.normal );
|
|
2679
|
-
faces.push( face );
|
|
2680
|
-
|
|
2681
|
-
}
|
|
2682
|
-
|
|
2683
|
-
// compute vertex normals and build final geometry
|
|
2684
|
-
|
|
2685
|
-
const normals = [];
|
|
2686
|
-
for ( let i = 0, l = faces.length; i < l; i ++ ) {
|
|
2687
|
-
|
|
2688
|
-
const face = faces[ i ];
|
|
2689
|
-
const nA = weightedNormal( vertexNormals[ face.a ], face.normal, creaseAngle );
|
|
2690
|
-
const nB = weightedNormal( vertexNormals[ face.b ], face.normal, creaseAngle );
|
|
2691
|
-
const nC = weightedNormal( vertexNormals[ face.c ], face.normal, creaseAngle );
|
|
2692
|
-
vA.fromArray( coord, face.a * 3 );
|
|
2693
|
-
vB.fromArray( coord, face.b * 3 );
|
|
2694
|
-
vC.fromArray( coord, face.c * 3 );
|
|
2695
|
-
normals.push( nA.x, nA.y, nA.z );
|
|
2696
|
-
normals.push( nB.x, nB.y, nB.z );
|
|
2697
|
-
normals.push( nC.x, nC.y, nC.z );
|
|
2698
|
-
|
|
2699
|
-
}
|
|
2700
|
-
|
|
2701
|
-
return new THREE.Float32BufferAttribute( normals, 3 );
|
|
2702
|
-
|
|
2703
|
-
}
|
|
2704
|
-
|
|
2705
|
-
function weightedNormal( normals, vector, creaseAngle ) {
|
|
2706
|
-
|
|
2707
|
-
const normal = new THREE.Vector3();
|
|
2708
|
-
if ( creaseAngle === 0 ) {
|
|
2709
|
-
|
|
2710
|
-
normal.copy( vector );
|
|
2711
|
-
|
|
2712
|
-
} else {
|
|
2713
|
-
|
|
2714
|
-
for ( let i = 0, l = normals.length; i < l; i ++ ) {
|
|
2715
|
-
|
|
2716
|
-
if ( normals[ i ].angleTo( vector ) < creaseAngle ) {
|
|
2717
|
-
|
|
2718
|
-
normal.add( normals[ i ] );
|
|
2719
|
-
|
|
2720
|
-
}
|
|
2721
|
-
|
|
2722
|
-
}
|
|
2723
|
-
|
|
2724
|
-
}
|
|
2725
|
-
|
|
2726
|
-
return normal.normalize();
|
|
2727
|
-
|
|
2728
|
-
}
|
|
2729
|
-
|
|
2730
|
-
function toColorArray( colors ) {
|
|
2731
|
-
|
|
2732
|
-
const array = [];
|
|
2733
|
-
for ( let i = 0, l = colors.length; i < l; i += 3 ) {
|
|
2734
|
-
|
|
2735
|
-
array.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
|
|
2736
|
-
|
|
2737
|
-
}
|
|
2738
|
-
|
|
2739
|
-
return array;
|
|
2740
|
-
|
|
2741
|
-
}
|
|
2742
|
-
|
|
2743
|
-
/**
|
|
2744
|
-
* Vertically paints the faces interpolating between the
|
|
2745
|
-
* specified colors at the specified angels. This is used for the Background
|
|
2746
|
-
* node, but could be applied to other nodes with multiple faces as well.
|
|
2747
|
-
*
|
|
2748
|
-
* When used with the Background node, default is directionIsDown is true if
|
|
2749
|
-
* interpolating the skyColor down from the Zenith. When interpolationg up from
|
|
2750
|
-
* the Nadir i.e. interpolating the groundColor, the directionIsDown is false.
|
|
2751
|
-
*
|
|
2752
|
-
* The first angle is never specified, it is the Zenith (0 rad). Angles are specified
|
|
2753
|
-
* in radians. The geometry is thought a sphere, but could be anything. The color interpolation
|
|
2754
|
-
* is linear along the Y axis in any case.
|
|
2755
|
-
*
|
|
2756
|
-
* You must specify one more color than you have angles at the beginning of the colors array.
|
|
2757
|
-
* This is the color of the Zenith (the top of the shape).
|
|
2758
|
-
*
|
|
2759
|
-
* @param {BufferGeometry} geometry
|
|
2760
|
-
* @param {number} radius
|
|
2761
|
-
* @param {array} angles
|
|
2762
|
-
* @param {array} colors
|
|
2763
|
-
* @param {boolean} topDown - Whether to work top down or bottom up.
|
|
2764
|
-
*/
|
|
2765
|
-
function paintFaces( geometry, radius, angles, colors, topDown ) {
|
|
2766
|
-
|
|
2767
|
-
// compute threshold values
|
|
2768
|
-
|
|
2769
|
-
const thresholds = [];
|
|
2770
|
-
const startAngle = topDown === true ? 0 : Math.PI;
|
|
2771
|
-
for ( let i = 0, l = colors.length; i < l; i ++ ) {
|
|
2772
|
-
|
|
2773
|
-
let angle = i === 0 ? 0 : angles[ i - 1 ];
|
|
2774
|
-
angle = topDown === true ? angle : startAngle - angle;
|
|
2775
|
-
const point = new THREE.Vector3();
|
|
2776
|
-
point.setFromSphericalCoords( radius, angle, 0 );
|
|
2777
|
-
thresholds.push( point );
|
|
2778
|
-
|
|
2779
|
-
}
|
|
2780
|
-
|
|
2781
|
-
// generate vertex colors
|
|
2782
|
-
|
|
2783
|
-
const indices = geometry.index;
|
|
2784
|
-
const positionAttribute = geometry.attributes.position;
|
|
2785
|
-
const colorAttribute = new THREE.BufferAttribute( new Float32Array( geometry.attributes.position.count * 3 ), 3 );
|
|
2786
|
-
const position = new THREE.Vector3();
|
|
2787
|
-
const color = new THREE.Color();
|
|
2788
|
-
for ( let i = 0; i < indices.count; i ++ ) {
|
|
2789
|
-
|
|
2790
|
-
const index = indices.getX( i );
|
|
2791
|
-
position.fromBufferAttribute( positionAttribute, index );
|
|
2792
|
-
let thresholdIndexA, thresholdIndexB;
|
|
2793
|
-
let t = 1;
|
|
2794
|
-
for ( let j = 1; j < thresholds.length; j ++ ) {
|
|
2795
|
-
|
|
2796
|
-
thresholdIndexA = j - 1;
|
|
2797
|
-
thresholdIndexB = j;
|
|
2798
|
-
const thresholdA = thresholds[ thresholdIndexA ];
|
|
2799
|
-
const thresholdB = thresholds[ thresholdIndexB ];
|
|
2800
|
-
if ( topDown === true ) {
|
|
2801
|
-
|
|
2802
|
-
// interpolation for sky color
|
|
2803
|
-
|
|
2804
|
-
if ( position.y <= thresholdA.y && position.y > thresholdB.y ) {
|
|
2805
|
-
|
|
2806
|
-
t = Math.abs( thresholdA.y - position.y ) / Math.abs( thresholdA.y - thresholdB.y );
|
|
2807
|
-
break;
|
|
2808
|
-
|
|
2809
|
-
}
|
|
2810
|
-
|
|
2811
|
-
} else {
|
|
2812
|
-
|
|
2813
|
-
// interpolation for ground color
|
|
2814
|
-
|
|
2815
|
-
if ( position.y >= thresholdA.y && position.y < thresholdB.y ) {
|
|
2816
|
-
|
|
2817
|
-
t = Math.abs( thresholdA.y - position.y ) / Math.abs( thresholdA.y - thresholdB.y );
|
|
2818
|
-
break;
|
|
2819
|
-
|
|
2820
|
-
}
|
|
2821
|
-
|
|
2822
|
-
}
|
|
2823
|
-
|
|
2824
|
-
}
|
|
2825
|
-
|
|
2826
|
-
const colorA = colors[ thresholdIndexA ];
|
|
2827
|
-
const colorB = colors[ thresholdIndexB ];
|
|
2828
|
-
color.copy( colorA ).lerp( colorB, t );
|
|
2829
|
-
colorAttribute.setXYZ( index, color.r, color.g, color.b );
|
|
2830
|
-
|
|
2831
|
-
}
|
|
2832
|
-
|
|
2833
|
-
geometry.setAttribute( 'color', colorAttribute );
|
|
2834
|
-
|
|
2835
|
-
}
|
|
2836
|
-
|
|
2837
|
-
//
|
|
2838
|
-
|
|
2839
|
-
const textureLoader = new THREE.TextureLoader( this.manager );
|
|
2840
|
-
textureLoader.setPath( this.resourcePath || path ).setCrossOrigin( this.crossOrigin );
|
|
2841
|
-
|
|
2842
|
-
// check version (only 2.0 is supported)
|
|
2843
|
-
|
|
2844
|
-
if ( data.indexOf( '#VRML V2.0' ) === - 1 ) {
|
|
2845
|
-
|
|
2846
|
-
throw Error( 'THREE.VRMLLexer: Version of VRML asset not supported.' );
|
|
2847
|
-
|
|
2848
|
-
}
|
|
2849
|
-
|
|
2850
|
-
// create JSON representing the tree structure of the VRML asset
|
|
2851
|
-
|
|
2852
|
-
const tree = generateVRMLTree( data );
|
|
2853
|
-
|
|
2854
|
-
// parse the tree structure to a three.js scene
|
|
2855
|
-
|
|
2856
|
-
const scene = parseTree( tree );
|
|
2857
|
-
return scene;
|
|
2858
|
-
|
|
2859
|
-
}
|
|
2860
|
-
|
|
2861
|
-
}
|
|
2862
|
-
class VRMLLexer {
|
|
2863
|
-
|
|
2864
|
-
constructor( tokens ) {
|
|
2865
|
-
|
|
2866
|
-
this.lexer = new chevrotain.Lexer( tokens ); // eslint-disable-line no-undef
|
|
2867
|
-
|
|
2868
|
-
}
|
|
2869
|
-
|
|
2870
|
-
lex( inputText ) {
|
|
2871
|
-
|
|
2872
|
-
const lexingResult = this.lexer.tokenize( inputText );
|
|
2873
|
-
if ( lexingResult.errors.length > 0 ) {
|
|
2874
|
-
|
|
2875
|
-
console.error( lexingResult.errors );
|
|
2876
|
-
throw Error( 'THREE.VRMLLexer: Lexing errors detected.' );
|
|
2877
|
-
|
|
2878
|
-
}
|
|
2879
|
-
|
|
2880
|
-
return lexingResult;
|
|
2881
|
-
|
|
2882
|
-
}
|
|
2883
|
-
|
|
2884
|
-
}
|
|
2885
|
-
const CstParser = chevrotain.CstParser; // eslint-disable-line no-undef
|
|
2886
|
-
|
|
2887
|
-
class VRMLParser extends CstParser {
|
|
2888
|
-
|
|
2889
|
-
constructor( tokenVocabulary ) {
|
|
2890
|
-
|
|
2891
|
-
super( tokenVocabulary );
|
|
2892
|
-
const $ = this;
|
|
2893
|
-
const Version = tokenVocabulary[ 'Version' ];
|
|
2894
|
-
const LCurly = tokenVocabulary[ 'LCurly' ];
|
|
2895
|
-
const RCurly = tokenVocabulary[ 'RCurly' ];
|
|
2896
|
-
const LSquare = tokenVocabulary[ 'LSquare' ];
|
|
2897
|
-
const RSquare = tokenVocabulary[ 'RSquare' ];
|
|
2898
|
-
const Identifier = tokenVocabulary[ 'Identifier' ];
|
|
2899
|
-
const RouteIdentifier = tokenVocabulary[ 'RouteIdentifier' ];
|
|
2900
|
-
const StringLiteral = tokenVocabulary[ 'StringLiteral' ];
|
|
2901
|
-
const HexLiteral = tokenVocabulary[ 'HexLiteral' ];
|
|
2902
|
-
const NumberLiteral = tokenVocabulary[ 'NumberLiteral' ];
|
|
2903
|
-
const TrueLiteral = tokenVocabulary[ 'TrueLiteral' ];
|
|
2904
|
-
const FalseLiteral = tokenVocabulary[ 'FalseLiteral' ];
|
|
2905
|
-
const NullLiteral = tokenVocabulary[ 'NullLiteral' ];
|
|
2906
|
-
const DEF = tokenVocabulary[ 'DEF' ];
|
|
2907
|
-
const USE = tokenVocabulary[ 'USE' ];
|
|
2908
|
-
const ROUTE = tokenVocabulary[ 'ROUTE' ];
|
|
2909
|
-
const TO = tokenVocabulary[ 'TO' ];
|
|
2910
|
-
const NodeName = tokenVocabulary[ 'NodeName' ];
|
|
2911
|
-
$.RULE( 'vrml', function () {
|
|
2912
|
-
|
|
2913
|
-
$.SUBRULE( $.version );
|
|
2914
|
-
$.AT_LEAST_ONE( function () {
|
|
2915
|
-
|
|
2916
|
-
$.SUBRULE( $.node );
|
|
2917
|
-
|
|
2918
|
-
} );
|
|
2919
|
-
$.MANY( function () {
|
|
2920
|
-
|
|
2921
|
-
$.SUBRULE( $.route );
|
|
2922
|
-
|
|
2923
|
-
} );
|
|
2924
|
-
|
|
2925
|
-
} );
|
|
2926
|
-
$.RULE( 'version', function () {
|
|
2927
|
-
|
|
2928
|
-
$.CONSUME( Version );
|
|
2929
|
-
|
|
2930
|
-
} );
|
|
2931
|
-
$.RULE( 'node', function () {
|
|
2932
|
-
|
|
2933
|
-
$.OPTION( function () {
|
|
2934
|
-
|
|
2935
|
-
$.SUBRULE( $.def );
|
|
2936
|
-
|
|
2937
|
-
} );
|
|
2938
|
-
$.CONSUME( NodeName );
|
|
2939
|
-
$.CONSUME( LCurly );
|
|
2940
|
-
$.MANY( function () {
|
|
2941
|
-
|
|
2942
|
-
$.SUBRULE( $.field );
|
|
2943
|
-
|
|
2944
|
-
} );
|
|
2945
|
-
$.CONSUME( RCurly );
|
|
2946
|
-
|
|
2947
|
-
} );
|
|
2948
|
-
$.RULE( 'field', function () {
|
|
2949
|
-
|
|
2950
|
-
$.CONSUME( Identifier );
|
|
2951
|
-
$.OR2( [ {
|
|
2952
|
-
ALT: function () {
|
|
2953
|
-
|
|
2954
|
-
$.SUBRULE( $.singleFieldValue );
|
|
2955
|
-
|
|
2956
|
-
}
|
|
2957
|
-
}, {
|
|
2958
|
-
ALT: function () {
|
|
2959
|
-
|
|
2960
|
-
$.SUBRULE( $.multiFieldValue );
|
|
2961
|
-
|
|
2962
|
-
}
|
|
2963
|
-
} ] );
|
|
2964
|
-
|
|
2965
|
-
} );
|
|
2966
|
-
$.RULE( 'def', function () {
|
|
2967
|
-
|
|
2968
|
-
$.CONSUME( DEF );
|
|
2969
|
-
$.OR( [ {
|
|
2970
|
-
ALT: function () {
|
|
2971
|
-
|
|
2972
|
-
$.CONSUME( Identifier );
|
|
2973
|
-
|
|
2974
|
-
}
|
|
2975
|
-
}, {
|
|
2976
|
-
ALT: function () {
|
|
2977
|
-
|
|
2978
|
-
$.CONSUME( NodeName );
|
|
2979
|
-
|
|
2980
|
-
}
|
|
2981
|
-
} ] );
|
|
2982
|
-
|
|
2983
|
-
} );
|
|
2984
|
-
$.RULE( 'use', function () {
|
|
2985
|
-
|
|
2986
|
-
$.CONSUME( USE );
|
|
2987
|
-
$.OR( [ {
|
|
2988
|
-
ALT: function () {
|
|
2989
|
-
|
|
2990
|
-
$.CONSUME( Identifier );
|
|
2991
|
-
|
|
2992
|
-
}
|
|
2993
|
-
}, {
|
|
2994
|
-
ALT: function () {
|
|
2995
|
-
|
|
2996
|
-
$.CONSUME( NodeName );
|
|
2997
|
-
|
|
2998
|
-
}
|
|
2999
|
-
} ] );
|
|
3000
|
-
|
|
3001
|
-
} );
|
|
3002
|
-
$.RULE( 'singleFieldValue', function () {
|
|
3003
|
-
|
|
3004
|
-
$.AT_LEAST_ONE( function () {
|
|
3005
|
-
|
|
3006
|
-
$.OR( [ {
|
|
3007
|
-
ALT: function () {
|
|
3008
|
-
|
|
3009
|
-
$.SUBRULE( $.node );
|
|
3010
|
-
|
|
3011
|
-
}
|
|
3012
|
-
}, {
|
|
3013
|
-
ALT: function () {
|
|
3014
|
-
|
|
3015
|
-
$.SUBRULE( $.use );
|
|
3016
|
-
|
|
3017
|
-
}
|
|
3018
|
-
}, {
|
|
3019
|
-
ALT: function () {
|
|
3020
|
-
|
|
3021
|
-
$.CONSUME( StringLiteral );
|
|
3022
|
-
|
|
3023
|
-
}
|
|
3024
|
-
}, {
|
|
3025
|
-
ALT: function () {
|
|
3026
|
-
|
|
3027
|
-
$.CONSUME( HexLiteral );
|
|
3028
|
-
|
|
3029
|
-
}
|
|
3030
|
-
}, {
|
|
3031
|
-
ALT: function () {
|
|
3032
|
-
|
|
3033
|
-
$.CONSUME( NumberLiteral );
|
|
3034
|
-
|
|
3035
|
-
}
|
|
3036
|
-
}, {
|
|
3037
|
-
ALT: function () {
|
|
3038
|
-
|
|
3039
|
-
$.CONSUME( TrueLiteral );
|
|
3040
|
-
|
|
3041
|
-
}
|
|
3042
|
-
}, {
|
|
3043
|
-
ALT: function () {
|
|
3044
|
-
|
|
3045
|
-
$.CONSUME( FalseLiteral );
|
|
3046
|
-
|
|
3047
|
-
}
|
|
3048
|
-
}, {
|
|
3049
|
-
ALT: function () {
|
|
3050
|
-
|
|
3051
|
-
$.CONSUME( NullLiteral );
|
|
3052
|
-
|
|
3053
|
-
}
|
|
3054
|
-
} ] );
|
|
3055
|
-
|
|
3056
|
-
} );
|
|
3057
|
-
|
|
3058
|
-
} );
|
|
3059
|
-
$.RULE( 'multiFieldValue', function () {
|
|
3060
|
-
|
|
3061
|
-
$.CONSUME( LSquare );
|
|
3062
|
-
$.MANY( function () {
|
|
3063
|
-
|
|
3064
|
-
$.OR( [ {
|
|
3065
|
-
ALT: function () {
|
|
3066
|
-
|
|
3067
|
-
$.SUBRULE( $.node );
|
|
3068
|
-
|
|
3069
|
-
}
|
|
3070
|
-
}, {
|
|
3071
|
-
ALT: function () {
|
|
3072
|
-
|
|
3073
|
-
$.SUBRULE( $.use );
|
|
3074
|
-
|
|
3075
|
-
}
|
|
3076
|
-
}, {
|
|
3077
|
-
ALT: function () {
|
|
3078
|
-
|
|
3079
|
-
$.CONSUME( StringLiteral );
|
|
3080
|
-
|
|
3081
|
-
}
|
|
3082
|
-
}, {
|
|
3083
|
-
ALT: function () {
|
|
3084
|
-
|
|
3085
|
-
$.CONSUME( HexLiteral );
|
|
3086
|
-
|
|
3087
|
-
}
|
|
3088
|
-
}, {
|
|
3089
|
-
ALT: function () {
|
|
3090
|
-
|
|
3091
|
-
$.CONSUME( NumberLiteral );
|
|
3092
|
-
|
|
3093
|
-
}
|
|
3094
|
-
}, {
|
|
3095
|
-
ALT: function () {
|
|
3096
|
-
|
|
3097
|
-
$.CONSUME( NullLiteral );
|
|
3098
|
-
|
|
3099
|
-
}
|
|
3100
|
-
} ] );
|
|
3101
|
-
|
|
3102
|
-
} );
|
|
3103
|
-
$.CONSUME( RSquare );
|
|
3104
|
-
|
|
3105
|
-
} );
|
|
3106
|
-
$.RULE( 'route', function () {
|
|
3107
|
-
|
|
3108
|
-
$.CONSUME( ROUTE );
|
|
3109
|
-
$.CONSUME( RouteIdentifier );
|
|
3110
|
-
$.CONSUME( TO );
|
|
3111
|
-
$.CONSUME2( RouteIdentifier );
|
|
3112
|
-
|
|
3113
|
-
} );
|
|
3114
|
-
this.performSelfAnalysis();
|
|
3115
|
-
|
|
3116
|
-
}
|
|
3117
|
-
|
|
3118
|
-
}
|
|
3119
|
-
class Face {
|
|
3120
|
-
|
|
3121
|
-
constructor( a, b, c ) {
|
|
3122
|
-
|
|
3123
|
-
this.a = a;
|
|
3124
|
-
this.b = b;
|
|
3125
|
-
this.c = c;
|
|
3126
|
-
this.normal = new THREE.Vector3();
|
|
3127
|
-
|
|
3128
|
-
}
|
|
3129
|
-
|
|
3130
|
-
}
|
|
3131
|
-
const TEXTURE_TYPE = {
|
|
3132
|
-
INTENSITY: 1,
|
|
3133
|
-
INTENSITY_ALPHA: 2,
|
|
3134
|
-
RGB: 3,
|
|
3135
|
-
RGBA: 4
|
|
3136
|
-
};
|
|
3137
|
-
|
|
3138
|
-
THREE.VRMLLoader = VRMLLoader;
|
|
3139
|
-
|
|
3140
|
-
} )();
|