@needle-tools/three 0.145.4 → 0.146.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/build/three.cjs +32586 -35951
- package/build/three.js +32600 -35965
- package/build/three.min.js +6 -7
- package/build/three.module.js +1547 -1154
- package/examples/js/animation/AnimationClipCreator.js +0 -8
- package/examples/js/animation/CCDIKSolver.js +49 -66
- package/examples/js/animation/MMDAnimationHelper.js +66 -137
- package/examples/js/animation/MMDPhysics.js +70 -134
- package/examples/js/cameras/CinematicCamera.js +33 -22
- package/examples/js/controls/ArcballControls.js +138 -405
- package/examples/js/controls/DragControls.js +8 -33
- package/examples/js/controls/FirstPersonControls.js +32 -54
- package/examples/js/controls/FlyControls.js +29 -55
- package/examples/js/controls/OrbitControls.js +85 -95
- package/examples/js/controls/PointerLockControls.js +5 -14
- package/examples/js/controls/TrackballControls.js +33 -86
- package/examples/js/controls/TransformControls.js +84 -169
- package/examples/js/csm/CSM.js +4 -39
- package/examples/js/csm/CSMFrustum.js +3 -9
- package/examples/js/csm/CSMHelper.js +24 -4
- package/examples/js/csm/CSMShader.js +2 -6
- package/examples/js/curves/CurveExtras.js +27 -27
- package/examples/js/curves/NURBSCurve.js +4 -16
- package/examples/js/curves/NURBSSurface.js +3 -9
- package/examples/js/curves/NURBSUtils.js +8 -45
- package/examples/js/effects/AnaglyphEffect.js +4 -18
- package/examples/js/effects/AsciiEffect.js +32 -31
- package/examples/js/effects/OutlineEffect.js +26 -30
- package/examples/js/effects/ParallaxBarrierEffect.js +0 -13
- package/examples/js/effects/PeppersGhostEffect.js +12 -39
- package/examples/js/effects/StereoEffect.js +0 -4
- package/examples/js/environments/RoomEnvironment.js +12 -10
- package/examples/js/exporters/ColladaExporter.js +48 -65
- package/examples/js/exporters/DRACOExporter.js +22 -22
- package/examples/js/exporters/EXRExporter.js +15 -18
- package/examples/js/exporters/GLTFExporter.js +143 -261
- package/examples/js/exporters/MMDExporter.js +5 -12
- package/examples/js/exporters/OBJExporter.js +42 -33
- package/examples/js/exporters/PLYExporter.js +38 -33
- package/examples/js/exporters/STLExporter.js +5 -7
- package/examples/js/exporters/USDZExporter.js +110 -25
- package/examples/js/geometries/BoxLineGeometry.js +0 -1
- package/examples/js/geometries/ConvexGeometry.js +11 -6
- package/examples/js/geometries/DecalGeometry.js +53 -20
- package/examples/js/geometries/LightningStrike.js +54 -67
- package/examples/js/geometries/ParametricGeometries.js +8 -7
- package/examples/js/geometries/ParametricGeometry.js +25 -12
- package/examples/js/geometries/RoundedBoxGeometry.js +21 -19
- package/examples/js/geometries/TeapotGeometry.js +54 -50
- package/examples/js/geometries/TextGeometry.js +6 -4
- package/examples/js/helpers/LightProbeHelper.js +1 -2
- package/examples/js/helpers/OctreeHelper.js +22 -20
- package/examples/js/helpers/PositionalAudioHelper.js +8 -6
- package/examples/js/helpers/RectAreaLightHelper.js +6 -7
- package/examples/js/helpers/VertexNormalsHelper.js +15 -13
- package/examples/js/helpers/VertexTangentsHelper.js +15 -9
- package/examples/js/helpers/ViewHelper.js +31 -16
- package/examples/js/interactive/HTMLMesh.js +22 -33
- package/examples/js/interactive/InteractiveGroup.js +6 -12
- package/examples/js/interactive/SelectionBox.js +3 -70
- package/examples/js/interactive/SelectionHelper.js +0 -8
- package/examples/js/lights/LightProbeGenerator.js +32 -39
- package/examples/js/lights/RectAreaLightUniformsLib.js +5 -1
- package/examples/js/lines/LineGeometry.js +3 -5
- package/examples/js/lines/LineMaterial.js +4 -11
- package/examples/js/lines/LineSegments2.js +38 -89
- package/examples/js/lines/LineSegmentsGeometry.js +7 -28
- package/examples/js/lines/Wireframe.js +2 -7
- package/examples/js/lines/WireframeGeometry2.js +3 -1
- package/examples/js/loaders/3DMLoader.js +58 -155
- package/examples/js/loaders/3MFLoader.js +72 -106
- package/examples/js/loaders/AMFLoader.js +0 -25
- package/examples/js/loaders/BVHLoader.js +44 -43
- package/examples/js/loaders/BasisTextureLoader.js +16 -46
- package/examples/js/loaders/ColladaLoader.js +201 -359
- package/examples/js/loaders/DDSLoader.js +24 -25
- package/examples/js/loaders/DRACOLoader.js +29 -66
- package/examples/js/loaders/EXRLoader.js +67 -164
- package/examples/js/loaders/FBXLoader.js +286 -441
- package/examples/js/loaders/FontLoader.js +6 -15
- package/examples/js/loaders/GCodeLoader.js +15 -16
- package/examples/js/loaders/GLTFLoader.js +354 -405
- package/examples/js/loaders/HDRCubeTextureLoader.js +0 -6
- package/examples/js/loaders/KMZLoader.js +3 -7
- package/examples/js/loaders/KTXLoader.js +12 -30
- package/examples/js/loaders/LDrawLoader.js +178 -289
- package/examples/js/loaders/LUT3dlLoader.js +7 -11
- package/examples/js/loaders/LUTCubeLoader.js +0 -8
- package/examples/js/loaders/LWOLoader.js +59 -124
- package/examples/js/loaders/LogLuvLoader.js +27 -77
- package/examples/js/loaders/LottieLoader.js +4 -4
- package/examples/js/loaders/MD2Loader.js +26 -27
- package/examples/js/loaders/MDDLoader.js +6 -10
- package/examples/js/loaders/MMDLoader.js +180 -189
- package/examples/js/loaders/MTLLoader.js +18 -47
- package/examples/js/loaders/MaterialXLoader.js +392 -0
- package/examples/js/loaders/NRRDLoader.js +44 -84
- package/examples/js/loaders/OBJLoader.js +50 -65
- package/examples/js/loaders/PCDLoader.js +34 -29
- package/examples/js/loaders/PDBLoader.js +17 -13
- package/examples/js/loaders/PLYLoader.js +9 -39
- package/examples/js/loaders/PRWMLoader.js +11 -22
- package/examples/js/loaders/PVRLoader.js +7 -16
- package/examples/js/loaders/RGBELoader.js +36 -61
- package/examples/js/loaders/RGBMLoader.js +26 -87
- package/examples/js/loaders/STLLoader.js +20 -27
- package/examples/js/loaders/SVGLoader.js +361 -233
- package/examples/js/loaders/TDSLoader.js +81 -118
- package/examples/js/loaders/TGALoader.js +39 -41
- package/examples/js/loaders/TIFFLoader.js +0 -1
- package/examples/js/loaders/TTFLoader.js +0 -8
- package/examples/js/loaders/TiltLoader.js +14 -15
- package/examples/js/loaders/VOXLoader.js +8 -16
- package/examples/js/loaders/VRMLLoader.js +243 -340
- package/examples/js/loaders/VTKLoader.js +101 -118
- package/examples/js/loaders/XYZLoader.js +2 -4
- package/examples/js/loaders/lwo/IFFParser.js +55 -136
- package/examples/js/loaders/lwo/LWO2Parser.js +32 -83
- package/examples/js/loaders/lwo/LWO3Parser.js +31 -73
- package/examples/js/materials/MeshGouraudMaterial.js +15 -13
- package/examples/js/math/Capsule.js +0 -17
- package/examples/js/math/ColorConverter.js +3 -3
- package/examples/js/math/ConvexHull.js +183 -139
- package/examples/js/math/ImprovedNoise.js +1 -1
- package/examples/js/math/Lut.js +8 -15
- package/examples/js/math/MeshSurfaceSampler.js +6 -28
- package/examples/js/math/OBB.js +90 -49
- package/examples/js/math/Octree.js +2 -57
- package/examples/js/math/SimplexNoise.js +74 -88
- package/examples/js/misc/ConvexObjectBreaker.js +37 -48
- package/examples/js/misc/GPUComputationRenderer.js +14 -18
- package/examples/js/misc/Gyroscope.js +5 -9
- package/examples/js/misc/MD2Character.js +14 -23
- package/examples/js/misc/MD2CharacterComplex.js +73 -54
- package/examples/js/misc/MorphAnimMesh.js +0 -6
- package/examples/js/misc/MorphBlendMesh.js +3 -30
- package/examples/js/misc/ProgressiveLightMap.js +47 -43
- package/examples/js/misc/RollerCoaster.js +17 -24
- package/examples/js/misc/TubePainter.js +18 -12
- package/examples/js/misc/Volume.js +16 -45
- package/examples/js/misc/VolumeSlice.js +14 -24
- package/examples/js/modifiers/CurveModifier.js +19 -21
- package/examples/js/modifiers/EdgeSplitModifier.js +0 -30
- package/examples/js/modifiers/SimplifyModifier.js +56 -59
- package/examples/js/modifiers/TessellateModifier.js +2 -9
- package/examples/js/objects/GroundProjectedEnv.js +2 -14
- package/examples/js/objects/Lensflare.js +47 -38
- package/examples/js/objects/LightningStorm.js +10 -13
- package/examples/js/objects/MarchingCubes.js +80 -59
- package/examples/js/objects/Reflector.js +22 -20
- package/examples/js/objects/ReflectorForSSRPass.js +19 -23
- package/examples/js/objects/Refractor.js +52 -30
- package/examples/js/objects/ShadowMesh.js +1 -2
- package/examples/js/objects/Sky.js +2 -7
- package/examples/js/objects/Water.js +23 -18
- package/examples/js/objects/Water2.js +20 -19
- package/examples/js/physics/AmmoPhysics.js +23 -20
- package/examples/js/physics/OimoPhysics.js +19 -17
- package/examples/js/postprocessing/AdaptiveToneMappingPass.js +13 -20
- package/examples/js/postprocessing/AfterimagePass.js +19 -12
- package/examples/js/postprocessing/BloomPass.js +38 -17
- package/examples/js/postprocessing/BokehPass.js +29 -12
- package/examples/js/postprocessing/ClearPass.js +1 -6
- package/examples/js/postprocessing/CubeTexturePass.js +12 -9
- package/examples/js/postprocessing/DotScreenPass.js +7 -5
- package/examples/js/postprocessing/EffectComposer.js +25 -32
- package/examples/js/postprocessing/FilmPass.js +7 -5
- package/examples/js/postprocessing/GlitchPass.js +10 -11
- package/examples/js/postprocessing/HalftonePass.js +9 -9
- package/examples/js/postprocessing/LUTPass.js +2 -15
- package/examples/js/postprocessing/MaskPass.js +20 -17
- package/examples/js/postprocessing/OutlinePass.js +45 -36
- package/examples/js/postprocessing/Pass.js +11 -14
- package/examples/js/postprocessing/RenderPass.js +3 -7
- package/examples/js/postprocessing/SAOPass.js +40 -32
- package/examples/js/postprocessing/SMAAPass.js +34 -17
- package/examples/js/postprocessing/SSAARenderPass.js +14 -14
- package/examples/js/postprocessing/SSAOPass.js +56 -42
- package/examples/js/postprocessing/SSRPass.js +78 -61
- package/examples/js/postprocessing/SavePass.js +14 -6
- package/examples/js/postprocessing/ShaderPass.js +9 -8
- package/examples/js/postprocessing/TAARenderPass.js +11 -9
- package/examples/js/postprocessing/TexturePass.js +7 -4
- package/examples/js/postprocessing/UnrealBloomPass.js +43 -25
- package/examples/js/renderers/CSS2DRenderer.js +2 -21
- package/examples/js/renderers/CSS3DRenderer.js +3 -24
- package/examples/js/renderers/Projector.js +29 -85
- package/examples/js/renderers/SVGRenderer.js +4 -50
- package/examples/js/shaders/ACESFilmicToneMappingShader.js +3 -6
- package/examples/js/shaders/AfterimageShader.js +3 -6
- package/examples/js/shaders/BasicShader.js +3 -6
- package/examples/js/shaders/BleachBypassShader.js +3 -6
- package/examples/js/shaders/BlendShader.js +3 -6
- package/examples/js/shaders/BokehShader.js +3 -6
- package/examples/js/shaders/BokehShader2.js +4 -13
- package/examples/js/shaders/BrightnessContrastShader.js +3 -6
- package/examples/js/shaders/ColorCorrectionShader.js +2 -6
- package/examples/js/shaders/ColorifyShader.js +2 -6
- package/examples/js/shaders/ConvolutionShader.js +5 -10
- package/examples/js/shaders/CopyShader.js +3 -6
- package/examples/js/shaders/DOFMipMapShader.js +3 -6
- package/examples/js/shaders/DepthLimitedBlurShader.js +2 -9
- package/examples/js/shaders/DigitalGlitch.js +3 -6
- package/examples/js/shaders/DotScreenShader.js +2 -6
- package/examples/js/shaders/FXAAShader.js +1 -3
- package/examples/js/shaders/FilmShader.js +3 -6
- package/examples/js/shaders/FocusShader.js +3 -6
- package/examples/js/shaders/FreiChenShader.js +2 -6
- package/examples/js/shaders/GammaCorrectionShader.js +3 -6
- package/examples/js/shaders/GodRaysShader.js +11 -24
- package/examples/js/shaders/HalftoneShader.js +3 -6
- package/examples/js/shaders/HorizontalBlurShader.js +3 -6
- package/examples/js/shaders/HorizontalTiltShiftShader.js +3 -6
- package/examples/js/shaders/HueSaturationShader.js +3 -6
- package/examples/js/shaders/KaleidoShader.js +3 -6
- package/examples/js/shaders/LuminosityHighPassShader.js +2 -6
- package/examples/js/shaders/LuminosityShader.js +3 -6
- package/examples/js/shaders/MMDToonShader.js +2 -6
- package/examples/js/shaders/MirrorShader.js +3 -6
- package/examples/js/shaders/NormalMapShader.js +2 -6
- package/examples/js/shaders/RGBShiftShader.js +3 -6
- package/examples/js/shaders/SAOShader.js +2 -6
- package/examples/js/shaders/SMAAShader.js +6 -18
- package/examples/js/shaders/SSAOShader.js +2 -6
- package/examples/js/shaders/SSRShader.js +6 -18
- package/examples/js/shaders/SepiaShader.js +3 -6
- package/examples/js/shaders/SobelOperatorShader.js +2 -6
- package/examples/js/shaders/TechnicolorShader.js +3 -6
- package/examples/js/shaders/ToneMapShader.js +3 -6
- package/examples/js/shaders/ToonShader.js +8 -24
- package/examples/js/shaders/TriangleBlurShader.js +2 -6
- package/examples/js/shaders/UnpackDepthRGBAShader.js +3 -6
- package/examples/js/shaders/VelocityShader.js +126 -0
- package/examples/js/shaders/VerticalBlurShader.js +3 -6
- package/examples/js/shaders/VerticalTiltShiftShader.js +3 -6
- package/examples/js/shaders/VignetteShader.js +3 -6
- package/examples/js/shaders/VolumeShader.js +2 -6
- package/examples/js/shaders/WaterRefractionShader.js +2 -6
- package/examples/js/textures/FlakesTexture.js +0 -1
- package/examples/js/utils/BufferGeometryUtils.js +234 -168
- package/examples/js/utils/CameraUtils.js +5 -20
- package/examples/js/utils/GPUStatsPanel.js +3 -12
- package/examples/js/utils/GeometryCompressionUtils.js +19 -44
- package/examples/js/utils/GeometryUtils.js +13 -18
- package/examples/js/utils/LDrawUtils.js +8 -11
- package/examples/js/utils/PackedPhongMaterial.js +6 -4
- package/examples/js/utils/SceneUtils.js +117 -6
- package/examples/js/utils/ShadowMapViewer.js +17 -14
- package/examples/js/utils/SkeletonUtils.js +13 -27
- package/examples/js/utils/UVsDebug.js +20 -12
- package/examples/js/utils/WorkerPool.js +1 -11
- package/examples/jsm/animation/CCDIKSolver.js +1 -1
- package/examples/jsm/capabilities/WebGPU.js +3 -1
- package/examples/jsm/controls/OrbitControls.js +44 -4
- package/examples/jsm/exporters/GLTFExporter.js +17 -131
- package/examples/jsm/exporters/USDZExporter.js +75 -19
- package/examples/jsm/interactive/HTMLMesh.js +2 -0
- package/examples/jsm/libs/lottie_canvas.module.js +14844 -0
- package/examples/jsm/loaders/3DMLoader.js +1 -2
- package/examples/jsm/loaders/ColladaLoader.js +28 -0
- package/examples/jsm/loaders/FBXLoader.js +16 -2
- package/examples/jsm/loaders/GLTFLoader.js +204 -377
- package/examples/jsm/loaders/KTX2Loader.js +68 -29
- package/examples/jsm/loaders/LDrawLoader.js +14 -13
- package/examples/jsm/loaders/LottieLoader.js +4 -2
- package/examples/jsm/loaders/MaterialXLoader.js +728 -0
- package/examples/jsm/loaders/PCDLoader.js +1 -1
- package/examples/jsm/loaders/PLYLoader.js +68 -16
- package/examples/jsm/loaders/SVGLoader.js +227 -14
- package/examples/jsm/loaders/USDZLoader.js +31 -16
- package/examples/jsm/nodes/Nodes.js +14 -2
- package/examples/jsm/nodes/accessors/Object3DNode.js +1 -1
- package/examples/jsm/nodes/accessors/PositionNode.js +6 -0
- package/examples/jsm/nodes/accessors/ReferenceNode.js +1 -1
- package/examples/jsm/nodes/accessors/SkinningNode.js +1 -1
- package/examples/jsm/nodes/core/Node.js +1 -1
- package/examples/jsm/nodes/core/NodeBuilder.js +36 -4
- package/examples/jsm/nodes/core/NodeFrame.js +2 -2
- package/examples/jsm/nodes/core/NodeVarying.js +7 -4
- package/examples/jsm/nodes/core/VaryingNode.js +6 -4
- package/examples/jsm/nodes/core/constants.js +13 -13
- package/examples/jsm/nodes/display/PosterizeNode.js +25 -0
- package/examples/jsm/nodes/display/ViewportNode.js +106 -0
- package/examples/jsm/nodes/gpgpu/ComputeNode.js +1 -1
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +1 -1
- package/examples/jsm/nodes/loaders/NodeMaterialLoader.js +3 -1
- package/examples/jsm/nodes/materials/Materials.js +9 -7
- package/examples/jsm/nodes/materials/NodeMaterial.js +9 -1
- package/examples/jsm/nodes/materialx/MaterialXNodes.js +6 -2
- package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +18 -0
- package/examples/jsm/nodes/math/MathNode.js +5 -0
- package/examples/jsm/nodes/math/OperatorNode.js +6 -1
- package/examples/jsm/nodes/shadernode/ShaderNode.js +26 -13
- package/examples/jsm/nodes/shadernode/ShaderNodeBaseElements.js +2 -0
- package/examples/jsm/nodes/shadernode/ShaderNodeElements.js +18 -0
- package/examples/jsm/nodes/utils/EquirectUVNode.js +27 -0
- package/examples/jsm/nodes/utils/JoinNode.js +8 -2
- package/examples/jsm/nodes/utils/MatcapUVNode.js +2 -4
- package/examples/jsm/nodes/utils/MaxMipLevelNode.js +1 -1
- package/examples/jsm/nodes/utils/SpriteSheetUVNode.js +8 -10
- package/examples/jsm/nodes/utils/TimerNode.js +1 -1
- package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +51 -0
- package/examples/jsm/postprocessing/AfterimagePass.js +17 -4
- package/examples/jsm/postprocessing/BloomPass.js +22 -3
- package/examples/jsm/postprocessing/BokehPass.js +18 -4
- package/examples/jsm/postprocessing/CubeTexturePass.js +12 -5
- package/examples/jsm/postprocessing/DotScreenPass.js +8 -0
- package/examples/jsm/postprocessing/EffectComposer.js +9 -0
- package/examples/jsm/postprocessing/FilmPass.js +8 -0
- package/examples/jsm/postprocessing/GlitchPass.js +13 -1
- package/examples/jsm/postprocessing/HalftonePass.js +8 -0
- package/examples/jsm/postprocessing/OutlinePass.js +10 -0
- package/examples/jsm/postprocessing/Pass.js +2 -0
- package/examples/jsm/postprocessing/RenderPixelatedPass.js +234 -0
- package/examples/jsm/postprocessing/SAOPass.js +20 -0
- package/examples/jsm/postprocessing/SMAAPass.js +16 -0
- package/examples/jsm/postprocessing/SSAARenderPass.js +4 -0
- package/examples/jsm/postprocessing/SavePass.js +17 -1
- package/examples/jsm/postprocessing/ShaderPass.js +8 -0
- package/examples/jsm/postprocessing/TAARenderPass.js +9 -0
- package/examples/jsm/postprocessing/TexturePass.js +8 -0
- package/examples/jsm/postprocessing/UnrealBloomPass.js +16 -0
- package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +39 -16
- package/examples/jsm/renderers/webgpu/WebGPUAnimation.js +58 -0
- package/examples/jsm/renderers/webgpu/WebGPUAttributes.js +63 -5
- package/examples/jsm/renderers/webgpu/WebGPUBackground.js +36 -7
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +47 -12
- package/examples/jsm/renderers/webgpu/nodes/WebGPUNodeBuilder.js +35 -5
- package/examples/jsm/shaders/MMDToonShader.js +0 -2
- package/examples/jsm/shaders/VelocityShader.js +128 -0
- package/examples/jsm/utils/BufferGeometryUtils.js +130 -6
- package/examples/jsm/utils/SceneUtils.js +129 -4
- package/examples/jsm/utils/TextureUtils.js +85 -0
- package/examples/jsm/webxr/OculusHandModel.js +1 -1
- package/examples/jsm/webxr/XRHandMeshModel.js +6 -3
- package/package.json +11 -12
- package/src/Three.js +1 -0
- package/src/audio/AudioContext.js +5 -5
- package/src/cameras/CubeCamera.js +14 -14
- package/src/constants.js +1 -1
- package/src/core/InstancedBufferGeometry.js +1 -7
- package/src/extras/Earcut.js +67 -67
- package/src/helpers/DirectionalLightHelper.js +5 -1
- package/src/helpers/HemisphereLightHelper.js +4 -1
- package/src/helpers/PointLightHelper.js +2 -1
- package/src/helpers/SpotLightHelper.js +4 -2
- package/src/lights/PointLight.js +2 -2
- package/src/lights/SpotLight.js +2 -2
- package/src/loaders/FileLoader.js +4 -1
- package/src/loaders/ObjectLoader.js +5 -1
- package/src/materials/Material.js +1 -1
- package/src/math/Color.js +5 -5
- package/src/math/Matrix3.js +53 -18
- package/src/math/Ray.js +2 -5
- package/src/math/Sphere.js +19 -26
- package/src/objects/InstancedMesh.js +7 -0
- package/src/objects/LOD.js +25 -6
- package/src/renderers/WebGL3DRenderTarget.js +1 -1
- package/src/renderers/WebGLArrayRenderTarget.js +1 -1
- package/src/renderers/WebGLCubeRenderTarget.js +1 -1
- package/src/renderers/WebGLMultipleRenderTargets.js +1 -1
- package/src/renderers/WebGLRenderTarget.js +1 -1
- package/src/renderers/WebGLRenderer.js +36 -62
- package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +0 -4
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +0 -1
- package/src/renderers/shaders/ShaderChunk/lights_lambert_pars_fragment.glsl.js +0 -2
- package/src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl.js +0 -2
- package/src/renderers/shaders/ShaderChunk/lights_toon_pars_fragment.glsl.js +0 -2
- package/src/renderers/shaders/ShaderChunk/packing.glsl.js +8 -0
- package/src/renderers/shaders/ShaderChunk.js +3 -0
- package/src/renderers/shaders/ShaderLib/background.glsl.js +7 -2
- package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +62 -0
- package/src/renderers/shaders/ShaderLib/cube.glsl.js +4 -6
- package/src/renderers/shaders/ShaderLib.js +20 -6
- package/src/renderers/shaders/UniformsLib.js +1 -1
- package/src/renderers/shaders/UniformsUtils.js +15 -0
- package/src/renderers/webgl/WebGLAttributes.js +2 -0
- package/src/renderers/webgl/WebGLBackground.js +15 -7
- package/src/renderers/webgl/WebGLLights.js +0 -4
- package/src/renderers/webgl/WebGLMaterials.js +2 -1
- package/src/renderers/webgl/WebGLShadowMap.js +3 -1
- package/src/renderers/webgl/WebGLState.js +31 -1
- package/src/renderers/webgl/WebGLTextures.js +71 -18
- package/src/renderers/webgl/WebGLUniforms.js +116 -20
- package/src/renderers/webgl/WebGLUtils.js +1 -1
- package/src/renderers/webxr/WebXRController.js +46 -13
- package/src/renderers/webxr/WebXRManager.js +85 -3
- package/src/scenes/Scene.js +8 -0
- package/src/textures/CompressedArrayTexture.js +18 -0
- package/examples/js/libs/lottie_canvas.js +0 -12751
- package/examples/js/shaders/PixelShader.js +0 -51
- package/examples/jsm/shaders/PixelShader.js +0 -44
|
@@ -4,17 +4,19 @@
|
|
|
4
4
|
|
|
5
5
|
constructor( manager ) {
|
|
6
6
|
|
|
7
|
-
super( manager );
|
|
7
|
+
super( manager );
|
|
8
|
+
|
|
9
|
+
// dependency check
|
|
8
10
|
|
|
9
11
|
if ( typeof chevrotain === 'undefined' ) {
|
|
10
12
|
|
|
11
13
|
// eslint-disable-line no-undef
|
|
14
|
+
|
|
12
15
|
throw Error( 'THREE.VRMLLoader: External library chevrotain.min.js required.' );
|
|
13
16
|
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
}
|
|
17
|
-
|
|
18
20
|
load( url, onLoad, onProgress, onError ) {
|
|
19
21
|
|
|
20
22
|
const scope = this;
|
|
@@ -48,31 +50,34 @@
|
|
|
48
50
|
}, onProgress, onError );
|
|
49
51
|
|
|
50
52
|
}
|
|
51
|
-
|
|
52
53
|
parse( data, path ) {
|
|
53
54
|
|
|
54
55
|
const nodeMap = {};
|
|
55
|
-
|
|
56
56
|
function generateVRMLTree( data ) {
|
|
57
57
|
|
|
58
58
|
// create lexer, parser and visitor
|
|
59
|
+
|
|
59
60
|
const tokenData = createTokens();
|
|
60
61
|
const lexer = new VRMLLexer( tokenData.tokens );
|
|
61
62
|
const parser = new VRMLParser( tokenData.tokenVocabulary );
|
|
62
|
-
const visitor = createVisitor( parser.getBaseCstVisitorConstructor() );
|
|
63
|
+
const visitor = createVisitor( parser.getBaseCstVisitorConstructor() );
|
|
64
|
+
|
|
65
|
+
// lexing
|
|
63
66
|
|
|
64
67
|
const lexingResult = lexer.lex( data );
|
|
65
|
-
parser.input = lexingResult.tokens;
|
|
68
|
+
parser.input = lexingResult.tokens;
|
|
66
69
|
|
|
67
|
-
|
|
70
|
+
// parsing
|
|
68
71
|
|
|
72
|
+
const cstOutput = parser.vrml();
|
|
69
73
|
if ( parser.errors.length > 0 ) {
|
|
70
74
|
|
|
71
75
|
console.error( parser.errors );
|
|
72
76
|
throw Error( 'THREE.VRMLLoader: Parsing errors detected.' );
|
|
73
77
|
|
|
74
|
-
}
|
|
78
|
+
}
|
|
75
79
|
|
|
80
|
+
// actions
|
|
76
81
|
|
|
77
82
|
const ast = visitor.visit( cstOutput );
|
|
78
83
|
return ast;
|
|
@@ -82,6 +87,7 @@
|
|
|
82
87
|
function createTokens() {
|
|
83
88
|
|
|
84
89
|
const createToken = chevrotain.createToken; // eslint-disable-line no-undef
|
|
90
|
+
|
|
85
91
|
// from http://gun.teipir.gr/VRML-amgem/spec/part1/concepts.html#SyntaxBasics
|
|
86
92
|
|
|
87
93
|
const RouteIdentifier = createToken( {
|
|
@@ -92,19 +98,32 @@
|
|
|
92
98
|
name: 'Identifier',
|
|
93
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]*/,
|
|
94
100
|
longer_alt: RouteIdentifier
|
|
95
|
-
} );
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
'
|
|
102
|
-
|
|
103
|
-
'
|
|
104
|
-
|
|
105
|
-
'
|
|
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
|
|
106
123
|
'Text' // Text must be placed at the end of the regex so there are no matches for TextureTransform and TextureCoordinate
|
|
107
|
-
];
|
|
124
|
+
];
|
|
125
|
+
|
|
126
|
+
//
|
|
108
127
|
|
|
109
128
|
const Version = createToken( {
|
|
110
129
|
name: 'Version',
|
|
@@ -135,7 +154,9 @@
|
|
|
135
154
|
name: 'TO',
|
|
136
155
|
pattern: /TO/,
|
|
137
156
|
longer_alt: Identifier
|
|
138
|
-
} );
|
|
157
|
+
} );
|
|
158
|
+
|
|
159
|
+
//
|
|
139
160
|
|
|
140
161
|
const StringLiteral = createToken( {
|
|
141
162
|
name: 'StringLiteral',
|
|
@@ -181,20 +202,22 @@
|
|
|
181
202
|
name: 'Comment',
|
|
182
203
|
pattern: /#.*/,
|
|
183
204
|
group: chevrotain.Lexer.SKIPPED // eslint-disable-line no-undef
|
|
205
|
+
} );
|
|
184
206
|
|
|
185
|
-
|
|
207
|
+
// commas, blanks, tabs, newlines and carriage returns are whitespace characters wherever they appear outside of string fields
|
|
186
208
|
|
|
187
209
|
const WhiteSpace = createToken( {
|
|
188
210
|
name: 'WhiteSpace',
|
|
189
211
|
pattern: /[ ,\s]/,
|
|
190
212
|
group: chevrotain.Lexer.SKIPPED // eslint-disable-line no-undef
|
|
191
|
-
|
|
192
213
|
} );
|
|
193
|
-
|
|
194
|
-
|
|
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
|
|
195
219
|
Version, Identifier, RouteIdentifier, StringLiteral, HexLiteral, NumberLiteral, LSquare, RSquare, LCurly, RCurly, Comment ];
|
|
196
220
|
const tokenVocabulary = {};
|
|
197
|
-
|
|
198
221
|
for ( let i = 0, l = tokens.length; i < l; i ++ ) {
|
|
199
222
|
|
|
200
223
|
const token = tokens[ i ];
|
|
@@ -212,6 +235,7 @@
|
|
|
212
235
|
function createVisitor( BaseVRMLVisitor ) {
|
|
213
236
|
|
|
214
237
|
// the visitor is created dynmaically based on the given base class
|
|
238
|
+
|
|
215
239
|
class VRMLToASTVisitor extends BaseVRMLVisitor {
|
|
216
240
|
|
|
217
241
|
constructor() {
|
|
@@ -220,7 +244,6 @@
|
|
|
220
244
|
this.validateVisitor();
|
|
221
245
|
|
|
222
246
|
}
|
|
223
|
-
|
|
224
247
|
vrml( ctx ) {
|
|
225
248
|
|
|
226
249
|
const data = {
|
|
@@ -228,7 +251,6 @@
|
|
|
228
251
|
nodes: [],
|
|
229
252
|
routes: []
|
|
230
253
|
};
|
|
231
|
-
|
|
232
254
|
for ( let i = 0, l = ctx.node.length; i < l; i ++ ) {
|
|
233
255
|
|
|
234
256
|
const node = ctx.node[ i ];
|
|
@@ -250,20 +272,17 @@
|
|
|
250
272
|
return data;
|
|
251
273
|
|
|
252
274
|
}
|
|
253
|
-
|
|
254
275
|
version( ctx ) {
|
|
255
276
|
|
|
256
277
|
return ctx.Version[ 0 ].image;
|
|
257
278
|
|
|
258
279
|
}
|
|
259
|
-
|
|
260
280
|
node( ctx ) {
|
|
261
281
|
|
|
262
282
|
const data = {
|
|
263
283
|
name: ctx.NodeName[ 0 ].image,
|
|
264
284
|
fields: []
|
|
265
285
|
};
|
|
266
|
-
|
|
267
286
|
if ( ctx.field ) {
|
|
268
287
|
|
|
269
288
|
for ( let i = 0, l = ctx.field.length; i < l; i ++ ) {
|
|
@@ -273,8 +292,9 @@
|
|
|
273
292
|
|
|
274
293
|
}
|
|
275
294
|
|
|
276
|
-
}
|
|
295
|
+
}
|
|
277
296
|
|
|
297
|
+
// DEF
|
|
278
298
|
|
|
279
299
|
if ( ctx.def ) {
|
|
280
300
|
|
|
@@ -285,7 +305,6 @@
|
|
|
285
305
|
return data;
|
|
286
306
|
|
|
287
307
|
}
|
|
288
|
-
|
|
289
308
|
field( ctx ) {
|
|
290
309
|
|
|
291
310
|
const data = {
|
|
@@ -293,14 +312,17 @@
|
|
|
293
312
|
type: null,
|
|
294
313
|
values: null
|
|
295
314
|
};
|
|
296
|
-
let result;
|
|
315
|
+
let result;
|
|
316
|
+
|
|
317
|
+
// SFValue
|
|
297
318
|
|
|
298
319
|
if ( ctx.singleFieldValue ) {
|
|
299
320
|
|
|
300
321
|
result = this.visit( ctx.singleFieldValue[ 0 ] );
|
|
301
322
|
|
|
302
|
-
}
|
|
323
|
+
}
|
|
303
324
|
|
|
325
|
+
// MFValue
|
|
304
326
|
|
|
305
327
|
if ( ctx.multiFieldValue ) {
|
|
306
328
|
|
|
@@ -313,13 +335,11 @@
|
|
|
313
335
|
return data;
|
|
314
336
|
|
|
315
337
|
}
|
|
316
|
-
|
|
317
338
|
def( ctx ) {
|
|
318
339
|
|
|
319
340
|
return ( ctx.Identifier || ctx.NodeName )[ 0 ].image;
|
|
320
341
|
|
|
321
342
|
}
|
|
322
|
-
|
|
323
343
|
use( ctx ) {
|
|
324
344
|
|
|
325
345
|
return {
|
|
@@ -327,19 +347,16 @@
|
|
|
327
347
|
};
|
|
328
348
|
|
|
329
349
|
}
|
|
330
|
-
|
|
331
350
|
singleFieldValue( ctx ) {
|
|
332
351
|
|
|
333
352
|
return processField( this, ctx );
|
|
334
353
|
|
|
335
354
|
}
|
|
336
|
-
|
|
337
355
|
multiFieldValue( ctx ) {
|
|
338
356
|
|
|
339
357
|
return processField( this, ctx );
|
|
340
358
|
|
|
341
359
|
}
|
|
342
|
-
|
|
343
360
|
route( ctx ) {
|
|
344
361
|
|
|
345
362
|
const data = {
|
|
@@ -351,18 +368,15 @@
|
|
|
351
368
|
}
|
|
352
369
|
|
|
353
370
|
}
|
|
354
|
-
|
|
355
371
|
function processField( scope, ctx ) {
|
|
356
372
|
|
|
357
373
|
const field = {
|
|
358
374
|
type: null,
|
|
359
375
|
values: []
|
|
360
376
|
};
|
|
361
|
-
|
|
362
377
|
if ( ctx.node ) {
|
|
363
378
|
|
|
364
379
|
field.type = 'node';
|
|
365
|
-
|
|
366
380
|
for ( let i = 0, l = ctx.node.length; i < l; i ++ ) {
|
|
367
381
|
|
|
368
382
|
const node = ctx.node[ i ];
|
|
@@ -375,7 +389,6 @@
|
|
|
375
389
|
if ( ctx.use ) {
|
|
376
390
|
|
|
377
391
|
field.type = 'use';
|
|
378
|
-
|
|
379
392
|
for ( let i = 0, l = ctx.use.length; i < l; i ++ ) {
|
|
380
393
|
|
|
381
394
|
const use = ctx.use[ i ];
|
|
@@ -388,7 +401,6 @@
|
|
|
388
401
|
if ( ctx.StringLiteral ) {
|
|
389
402
|
|
|
390
403
|
field.type = 'string';
|
|
391
|
-
|
|
392
404
|
for ( let i = 0, l = ctx.StringLiteral.length; i < l; i ++ ) {
|
|
393
405
|
|
|
394
406
|
const stringLiteral = ctx.StringLiteral[ i ];
|
|
@@ -401,7 +413,6 @@
|
|
|
401
413
|
if ( ctx.NumberLiteral ) {
|
|
402
414
|
|
|
403
415
|
field.type = 'number';
|
|
404
|
-
|
|
405
416
|
for ( let i = 0, l = ctx.NumberLiteral.length; i < l; i ++ ) {
|
|
406
417
|
|
|
407
418
|
const numberLiteral = ctx.NumberLiteral[ i ];
|
|
@@ -414,7 +425,6 @@
|
|
|
414
425
|
if ( ctx.HexLiteral ) {
|
|
415
426
|
|
|
416
427
|
field.type = 'hex';
|
|
417
|
-
|
|
418
428
|
for ( let i = 0, l = ctx.HexLiteral.length; i < l; i ++ ) {
|
|
419
429
|
|
|
420
430
|
const hexLiteral = ctx.HexLiteral[ i ];
|
|
@@ -427,7 +437,6 @@
|
|
|
427
437
|
if ( ctx.TrueLiteral ) {
|
|
428
438
|
|
|
429
439
|
field.type = 'boolean';
|
|
430
|
-
|
|
431
440
|
for ( let i = 0, l = ctx.TrueLiteral.length; i < l; i ++ ) {
|
|
432
441
|
|
|
433
442
|
const trueLiteral = ctx.TrueLiteral[ i ];
|
|
@@ -440,7 +449,6 @@
|
|
|
440
449
|
if ( ctx.FalseLiteral ) {
|
|
441
450
|
|
|
442
451
|
field.type = 'boolean';
|
|
443
|
-
|
|
444
452
|
for ( let i = 0, l = ctx.FalseLiteral.length; i < l; i ++ ) {
|
|
445
453
|
|
|
446
454
|
const falseLiteral = ctx.FalseLiteral[ i ];
|
|
@@ -472,16 +480,20 @@
|
|
|
472
480
|
function parseTree( tree ) {
|
|
473
481
|
|
|
474
482
|
// console.log( JSON.stringify( tree, null, 2 ) );
|
|
483
|
+
|
|
475
484
|
const nodes = tree.nodes;
|
|
476
|
-
const scene = new THREE.Scene();
|
|
485
|
+
const scene = new THREE.Scene();
|
|
486
|
+
|
|
487
|
+
// first iteration: build nodemap based on DEF statements
|
|
477
488
|
|
|
478
489
|
for ( let i = 0, l = nodes.length; i < l; i ++ ) {
|
|
479
490
|
|
|
480
491
|
const node = nodes[ i ];
|
|
481
492
|
buildNodeMap( node );
|
|
482
493
|
|
|
483
|
-
}
|
|
494
|
+
}
|
|
484
495
|
|
|
496
|
+
// second iteration: build nodes
|
|
485
497
|
|
|
486
498
|
for ( let i = 0, l = nodes.length; i < l; i ++ ) {
|
|
487
499
|
|
|
@@ -505,15 +517,12 @@
|
|
|
505
517
|
}
|
|
506
518
|
|
|
507
519
|
const fields = node.fields;
|
|
508
|
-
|
|
509
520
|
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
510
521
|
|
|
511
522
|
const field = fields[ i ];
|
|
512
|
-
|
|
513
523
|
if ( field.type === 'node' ) {
|
|
514
524
|
|
|
515
525
|
const fieldValues = field.values;
|
|
516
|
-
|
|
517
526
|
for ( let j = 0, jl = fieldValues.length; j < jl; j ++ ) {
|
|
518
527
|
|
|
519
528
|
buildNodeMap( fieldValues[ j ] );
|
|
@@ -529,6 +538,7 @@
|
|
|
529
538
|
function getNode( node ) {
|
|
530
539
|
|
|
531
540
|
// handle case where a node refers to a different one
|
|
541
|
+
|
|
532
542
|
if ( node.USE ) {
|
|
533
543
|
|
|
534
544
|
return resolveUSE( node.USE );
|
|
@@ -539,98 +549,79 @@
|
|
|
539
549
|
node.build = buildNode( node );
|
|
540
550
|
return node.build;
|
|
541
551
|
|
|
542
|
-
}
|
|
552
|
+
}
|
|
543
553
|
|
|
554
|
+
// node builder
|
|
544
555
|
|
|
545
556
|
function buildNode( node ) {
|
|
546
557
|
|
|
547
558
|
const nodeName = node.name;
|
|
548
559
|
let build;
|
|
549
|
-
|
|
550
560
|
switch ( nodeName ) {
|
|
551
561
|
|
|
562
|
+
case 'Anchor':
|
|
552
563
|
case 'Group':
|
|
553
564
|
case 'Transform':
|
|
554
565
|
case 'Collision':
|
|
555
566
|
build = buildGroupingNode( node );
|
|
556
567
|
break;
|
|
557
|
-
|
|
558
568
|
case 'Background':
|
|
559
569
|
build = buildBackgroundNode( node );
|
|
560
570
|
break;
|
|
561
|
-
|
|
562
571
|
case 'Shape':
|
|
563
572
|
build = buildShapeNode( node );
|
|
564
573
|
break;
|
|
565
|
-
|
|
566
574
|
case 'Appearance':
|
|
567
575
|
build = buildAppearanceNode( node );
|
|
568
576
|
break;
|
|
569
|
-
|
|
570
577
|
case 'Material':
|
|
571
578
|
build = buildMaterialNode( node );
|
|
572
579
|
break;
|
|
573
|
-
|
|
574
580
|
case 'ImageTexture':
|
|
575
581
|
build = buildImageTextureNode( node );
|
|
576
582
|
break;
|
|
577
|
-
|
|
578
583
|
case 'PixelTexture':
|
|
579
584
|
build = buildPixelTextureNode( node );
|
|
580
585
|
break;
|
|
581
|
-
|
|
582
586
|
case 'TextureTransform':
|
|
583
587
|
build = buildTextureTransformNode( node );
|
|
584
588
|
break;
|
|
585
|
-
|
|
586
589
|
case 'IndexedFaceSet':
|
|
587
590
|
build = buildIndexedFaceSetNode( node );
|
|
588
591
|
break;
|
|
589
|
-
|
|
590
592
|
case 'IndexedLineSet':
|
|
591
593
|
build = buildIndexedLineSetNode( node );
|
|
592
594
|
break;
|
|
593
|
-
|
|
594
595
|
case 'PointSet':
|
|
595
596
|
build = buildPointSetNode( node );
|
|
596
597
|
break;
|
|
597
|
-
|
|
598
598
|
case 'Box':
|
|
599
599
|
build = buildBoxNode( node );
|
|
600
600
|
break;
|
|
601
|
-
|
|
602
601
|
case 'Cone':
|
|
603
602
|
build = buildConeNode( node );
|
|
604
603
|
break;
|
|
605
|
-
|
|
606
604
|
case 'Cylinder':
|
|
607
605
|
build = buildCylinderNode( node );
|
|
608
606
|
break;
|
|
609
|
-
|
|
610
607
|
case 'Sphere':
|
|
611
608
|
build = buildSphereNode( node );
|
|
612
609
|
break;
|
|
613
|
-
|
|
614
610
|
case 'ElevationGrid':
|
|
615
611
|
build = buildElevationGridNode( node );
|
|
616
612
|
break;
|
|
617
|
-
|
|
618
613
|
case 'Extrusion':
|
|
619
614
|
build = buildExtrusionNode( node );
|
|
620
615
|
break;
|
|
621
|
-
|
|
622
616
|
case 'Color':
|
|
623
617
|
case 'Coordinate':
|
|
624
618
|
case 'Normal':
|
|
625
619
|
case 'TextureCoordinate':
|
|
626
620
|
build = buildGeometricNode( node );
|
|
627
621
|
break;
|
|
628
|
-
|
|
629
622
|
case 'WorldInfo':
|
|
630
623
|
build = buildWorldInfoNode( node );
|
|
631
624
|
break;
|
|
632
|
-
|
|
633
|
-
case 'Anchor':
|
|
634
625
|
case 'Billboard':
|
|
635
626
|
case 'Inline':
|
|
636
627
|
case 'LOD':
|
|
@@ -662,7 +653,6 @@
|
|
|
662
653
|
case 'Viewpoint':
|
|
663
654
|
// node not supported yet
|
|
664
655
|
break;
|
|
665
|
-
|
|
666
656
|
default:
|
|
667
657
|
console.warn( 'THREE.VRMLLoader: Unknown node:', nodeName );
|
|
668
658
|
break;
|
|
@@ -681,60 +671,59 @@
|
|
|
681
671
|
|
|
682
672
|
function buildGroupingNode( node ) {
|
|
683
673
|
|
|
684
|
-
const object = new THREE.Group();
|
|
674
|
+
const object = new THREE.Group();
|
|
685
675
|
|
|
686
|
-
|
|
676
|
+
//
|
|
687
677
|
|
|
678
|
+
const fields = node.fields;
|
|
688
679
|
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
689
680
|
|
|
690
681
|
const field = fields[ i ];
|
|
691
682
|
const fieldName = field.name;
|
|
692
683
|
const fieldValues = field.values;
|
|
693
|
-
|
|
694
684
|
switch ( fieldName ) {
|
|
695
685
|
|
|
696
686
|
case 'bboxCenter':
|
|
697
687
|
// field not supported
|
|
698
688
|
break;
|
|
699
|
-
|
|
700
689
|
case 'bboxSize':
|
|
701
690
|
// field not supported
|
|
702
691
|
break;
|
|
703
|
-
|
|
704
692
|
case 'center':
|
|
705
693
|
// field not supported
|
|
706
694
|
break;
|
|
707
|
-
|
|
708
695
|
case 'children':
|
|
709
696
|
parseFieldChildren( fieldValues, object );
|
|
710
697
|
break;
|
|
711
|
-
|
|
698
|
+
case 'description':
|
|
699
|
+
// field not supported
|
|
700
|
+
break;
|
|
712
701
|
case 'collide':
|
|
713
702
|
// field not supported
|
|
714
703
|
break;
|
|
715
|
-
|
|
704
|
+
case 'parameter':
|
|
705
|
+
// field not supported
|
|
706
|
+
break;
|
|
716
707
|
case 'rotation':
|
|
717
708
|
const axis = new THREE.Vector3( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
|
|
718
709
|
const angle = fieldValues[ 3 ];
|
|
719
710
|
object.quaternion.setFromAxisAngle( axis, angle );
|
|
720
711
|
break;
|
|
721
|
-
|
|
722
712
|
case 'scale':
|
|
723
713
|
object.scale.set( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
|
|
724
714
|
break;
|
|
725
|
-
|
|
726
715
|
case 'scaleOrientation':
|
|
727
716
|
// field not supported
|
|
728
717
|
break;
|
|
729
|
-
|
|
730
718
|
case 'translation':
|
|
731
719
|
object.position.set( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
|
|
732
720
|
break;
|
|
733
|
-
|
|
734
721
|
case 'proxy':
|
|
735
722
|
// field not supported
|
|
736
723
|
break;
|
|
737
|
-
|
|
724
|
+
case 'url':
|
|
725
|
+
// field not supported
|
|
726
|
+
break;
|
|
738
727
|
default:
|
|
739
728
|
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
740
729
|
break;
|
|
@@ -753,55 +742,43 @@
|
|
|
753
742
|
let groundAngle, groundColor;
|
|
754
743
|
let skyAngle, skyColor;
|
|
755
744
|
const fields = node.fields;
|
|
756
|
-
|
|
757
745
|
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
758
746
|
|
|
759
747
|
const field = fields[ i ];
|
|
760
748
|
const fieldName = field.name;
|
|
761
749
|
const fieldValues = field.values;
|
|
762
|
-
|
|
763
750
|
switch ( fieldName ) {
|
|
764
751
|
|
|
765
752
|
case 'groundAngle':
|
|
766
753
|
groundAngle = fieldValues;
|
|
767
754
|
break;
|
|
768
|
-
|
|
769
755
|
case 'groundColor':
|
|
770
756
|
groundColor = fieldValues;
|
|
771
757
|
break;
|
|
772
|
-
|
|
773
758
|
case 'backUrl':
|
|
774
759
|
// field not supported
|
|
775
760
|
break;
|
|
776
|
-
|
|
777
761
|
case 'bottomUrl':
|
|
778
762
|
// field not supported
|
|
779
763
|
break;
|
|
780
|
-
|
|
781
764
|
case 'frontUrl':
|
|
782
765
|
// field not supported
|
|
783
766
|
break;
|
|
784
|
-
|
|
785
767
|
case 'leftUrl':
|
|
786
768
|
// field not supported
|
|
787
769
|
break;
|
|
788
|
-
|
|
789
770
|
case 'rightUrl':
|
|
790
771
|
// field not supported
|
|
791
772
|
break;
|
|
792
|
-
|
|
793
773
|
case 'topUrl':
|
|
794
774
|
// field not supported
|
|
795
775
|
break;
|
|
796
|
-
|
|
797
776
|
case 'skyAngle':
|
|
798
777
|
skyAngle = fieldValues;
|
|
799
778
|
break;
|
|
800
|
-
|
|
801
779
|
case 'skyColor':
|
|
802
780
|
skyColor = fieldValues;
|
|
803
781
|
break;
|
|
804
|
-
|
|
805
782
|
default:
|
|
806
783
|
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
807
784
|
break;
|
|
@@ -810,7 +787,9 @@
|
|
|
810
787
|
|
|
811
788
|
}
|
|
812
789
|
|
|
813
|
-
const radius = 10000;
|
|
790
|
+
const radius = 10000;
|
|
791
|
+
|
|
792
|
+
// sky
|
|
814
793
|
|
|
815
794
|
if ( skyColor ) {
|
|
816
795
|
|
|
@@ -821,7 +800,6 @@
|
|
|
821
800
|
depthWrite: false,
|
|
822
801
|
depthTest: false
|
|
823
802
|
} );
|
|
824
|
-
|
|
825
803
|
if ( skyColor.length > 3 ) {
|
|
826
804
|
|
|
827
805
|
paintFaces( skyGeometry, radius, skyAngle, toColorArray( skyColor ), true );
|
|
@@ -836,8 +814,9 @@
|
|
|
836
814
|
const sky = new THREE.Mesh( skyGeometry, skyMaterial );
|
|
837
815
|
group.add( sky );
|
|
838
816
|
|
|
839
|
-
}
|
|
817
|
+
}
|
|
840
818
|
|
|
819
|
+
// ground
|
|
841
820
|
|
|
842
821
|
if ( groundColor ) {
|
|
843
822
|
|
|
@@ -857,8 +836,9 @@
|
|
|
857
836
|
|
|
858
837
|
}
|
|
859
838
|
|
|
860
|
-
}
|
|
839
|
+
}
|
|
861
840
|
|
|
841
|
+
// render background group first
|
|
862
842
|
|
|
863
843
|
group.renderOrder = - Infinity;
|
|
864
844
|
return group;
|
|
@@ -867,19 +847,19 @@
|
|
|
867
847
|
|
|
868
848
|
function buildShapeNode( node ) {
|
|
869
849
|
|
|
870
|
-
const fields = node.fields;
|
|
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)
|
|
871
853
|
|
|
872
854
|
let material = new THREE.MeshBasicMaterial( {
|
|
873
855
|
color: 0x000000
|
|
874
856
|
} );
|
|
875
857
|
let geometry;
|
|
876
|
-
|
|
877
858
|
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
878
859
|
|
|
879
860
|
const field = fields[ i ];
|
|
880
861
|
const fieldName = field.name;
|
|
881
862
|
const fieldValues = field.values;
|
|
882
|
-
|
|
883
863
|
switch ( fieldName ) {
|
|
884
864
|
|
|
885
865
|
case 'appearance':
|
|
@@ -890,7 +870,6 @@
|
|
|
890
870
|
}
|
|
891
871
|
|
|
892
872
|
break;
|
|
893
|
-
|
|
894
873
|
case 'geometry':
|
|
895
874
|
if ( fieldValues[ 0 ] !== null ) {
|
|
896
875
|
|
|
@@ -899,29 +878,27 @@
|
|
|
899
878
|
}
|
|
900
879
|
|
|
901
880
|
break;
|
|
902
|
-
|
|
903
881
|
default:
|
|
904
882
|
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
905
883
|
break;
|
|
906
884
|
|
|
907
885
|
}
|
|
908
886
|
|
|
909
|
-
}
|
|
887
|
+
}
|
|
910
888
|
|
|
889
|
+
// build 3D object
|
|
911
890
|
|
|
912
891
|
let object;
|
|
913
|
-
|
|
914
892
|
if ( geometry && geometry.attributes.position ) {
|
|
915
893
|
|
|
916
894
|
const type = geometry._type;
|
|
917
|
-
|
|
918
895
|
if ( type === 'points' ) {
|
|
919
896
|
|
|
920
897
|
// points
|
|
898
|
+
|
|
921
899
|
const pointsMaterial = new THREE.PointsMaterial( {
|
|
922
900
|
color: 0xffffff
|
|
923
901
|
} );
|
|
924
|
-
|
|
925
902
|
if ( geometry.attributes.color !== undefined ) {
|
|
926
903
|
|
|
927
904
|
pointsMaterial.vertexColors = true;
|
|
@@ -929,6 +906,7 @@
|
|
|
929
906
|
} else {
|
|
930
907
|
|
|
931
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
|
+
|
|
932
910
|
if ( material.isMeshPhongMaterial ) {
|
|
933
911
|
|
|
934
912
|
pointsMaterial.color.copy( material.emissive );
|
|
@@ -942,10 +920,10 @@
|
|
|
942
920
|
} else if ( type === 'line' ) {
|
|
943
921
|
|
|
944
922
|
// lines
|
|
923
|
+
|
|
945
924
|
const lineMaterial = new THREE.LineBasicMaterial( {
|
|
946
925
|
color: 0xffffff
|
|
947
926
|
} );
|
|
948
|
-
|
|
949
927
|
if ( geometry.attributes.color !== undefined ) {
|
|
950
928
|
|
|
951
929
|
lineMaterial.vertexColors = true;
|
|
@@ -953,6 +931,7 @@
|
|
|
953
931
|
} else {
|
|
954
932
|
|
|
955
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
|
+
|
|
956
935
|
if ( material.isMeshPhongMaterial ) {
|
|
957
936
|
|
|
958
937
|
lineMaterial.color.copy( material.emissive );
|
|
@@ -966,13 +945,16 @@
|
|
|
966
945
|
} else {
|
|
967
946
|
|
|
968
947
|
// consider meshes
|
|
948
|
+
|
|
969
949
|
// check "solid" hint (it's placed in the geometry but affects the material)
|
|
950
|
+
|
|
970
951
|
if ( geometry._solid !== undefined ) {
|
|
971
952
|
|
|
972
953
|
material.side = geometry._solid ? THREE.FrontSide : THREE.DoubleSide;
|
|
973
954
|
|
|
974
|
-
}
|
|
955
|
+
}
|
|
975
956
|
|
|
957
|
+
// check for vertex colors
|
|
976
958
|
|
|
977
959
|
if ( geometry.attributes.color !== undefined ) {
|
|
978
960
|
|
|
@@ -986,7 +968,9 @@
|
|
|
986
968
|
|
|
987
969
|
} else {
|
|
988
970
|
|
|
989
|
-
object = new THREE.Object3D();
|
|
971
|
+
object = new THREE.Object3D();
|
|
972
|
+
|
|
973
|
+
// if the geometry field is NULL or no vertices are defined the object is not drawn
|
|
990
974
|
|
|
991
975
|
object.visible = false;
|
|
992
976
|
|
|
@@ -1001,13 +985,11 @@
|
|
|
1001
985
|
let material = new THREE.MeshPhongMaterial();
|
|
1002
986
|
let transformData;
|
|
1003
987
|
const fields = node.fields;
|
|
1004
|
-
|
|
1005
988
|
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1006
989
|
|
|
1007
990
|
const field = fields[ i ];
|
|
1008
991
|
const fieldName = field.name;
|
|
1009
992
|
const fieldValues = field.values;
|
|
1010
|
-
|
|
1011
993
|
switch ( fieldName ) {
|
|
1012
994
|
|
|
1013
995
|
case 'material':
|
|
@@ -1024,6 +1006,7 @@
|
|
|
1024
1006
|
} else {
|
|
1025
1007
|
|
|
1026
1008
|
// if the material field is NULL or unspecified, lighting is off and the unlit object color is (0, 0, 0)
|
|
1009
|
+
|
|
1027
1010
|
material = new THREE.MeshBasicMaterial( {
|
|
1028
1011
|
color: 0x000000
|
|
1029
1012
|
} );
|
|
@@ -1031,23 +1014,22 @@
|
|
|
1031
1014
|
}
|
|
1032
1015
|
|
|
1033
1016
|
break;
|
|
1034
|
-
|
|
1035
1017
|
case 'texture':
|
|
1036
1018
|
const textureNode = fieldValues[ 0 ];
|
|
1037
|
-
|
|
1038
1019
|
if ( textureNode !== null ) {
|
|
1039
1020
|
|
|
1040
1021
|
if ( textureNode.name === 'ImageTexture' || textureNode.name === 'PixelTexture' ) {
|
|
1041
1022
|
|
|
1042
1023
|
material.map = getNode( textureNode );
|
|
1043
1024
|
|
|
1044
|
-
} else {
|
|
1025
|
+
} else {
|
|
1026
|
+
|
|
1027
|
+
// MovieTexture not supported yet
|
|
1045
1028
|
}
|
|
1046
1029
|
|
|
1047
1030
|
}
|
|
1048
1031
|
|
|
1049
1032
|
break;
|
|
1050
|
-
|
|
1051
1033
|
case 'textureTransform':
|
|
1052
1034
|
if ( fieldValues[ 0 ] !== null ) {
|
|
1053
1035
|
|
|
@@ -1056,48 +1038,43 @@
|
|
|
1056
1038
|
}
|
|
1057
1039
|
|
|
1058
1040
|
break;
|
|
1059
|
-
|
|
1060
1041
|
default:
|
|
1061
1042
|
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1062
1043
|
break;
|
|
1063
1044
|
|
|
1064
1045
|
}
|
|
1065
1046
|
|
|
1066
|
-
}
|
|
1047
|
+
}
|
|
1067
1048
|
|
|
1049
|
+
// only apply texture transform data if a texture was defined
|
|
1068
1050
|
|
|
1069
1051
|
if ( material.map ) {
|
|
1070
1052
|
|
|
1071
1053
|
// respect VRML lighting model
|
|
1054
|
+
|
|
1072
1055
|
if ( material.map.__type ) {
|
|
1073
1056
|
|
|
1074
1057
|
switch ( material.map.__type ) {
|
|
1075
1058
|
|
|
1076
1059
|
case TEXTURE_TYPE.INTENSITY_ALPHA:
|
|
1077
1060
|
material.opacity = 1; // ignore transparency
|
|
1078
|
-
|
|
1079
1061
|
break;
|
|
1080
|
-
|
|
1081
1062
|
case TEXTURE_TYPE.RGB:
|
|
1082
1063
|
material.color.set( 0xffffff ); // ignore material color
|
|
1083
|
-
|
|
1084
1064
|
break;
|
|
1085
|
-
|
|
1086
1065
|
case TEXTURE_TYPE.RGBA:
|
|
1087
1066
|
material.color.set( 0xffffff ); // ignore material color
|
|
1088
|
-
|
|
1089
1067
|
material.opacity = 1; // ignore transparency
|
|
1090
|
-
|
|
1091
1068
|
break;
|
|
1092
|
-
|
|
1093
1069
|
default:
|
|
1094
1070
|
|
|
1095
1071
|
}
|
|
1096
1072
|
|
|
1097
1073
|
delete material.map.__type;
|
|
1098
1074
|
|
|
1099
|
-
}
|
|
1075
|
+
}
|
|
1100
1076
|
|
|
1077
|
+
// apply texture transform
|
|
1101
1078
|
|
|
1102
1079
|
if ( transformData ) {
|
|
1103
1080
|
|
|
@@ -1118,39 +1095,31 @@
|
|
|
1118
1095
|
|
|
1119
1096
|
const materialData = {};
|
|
1120
1097
|
const fields = node.fields;
|
|
1121
|
-
|
|
1122
1098
|
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1123
1099
|
|
|
1124
1100
|
const field = fields[ i ];
|
|
1125
1101
|
const fieldName = field.name;
|
|
1126
1102
|
const fieldValues = field.values;
|
|
1127
|
-
|
|
1128
1103
|
switch ( fieldName ) {
|
|
1129
1104
|
|
|
1130
1105
|
case 'ambientIntensity':
|
|
1131
1106
|
// field not supported
|
|
1132
1107
|
break;
|
|
1133
|
-
|
|
1134
1108
|
case 'diffuseColor':
|
|
1135
1109
|
materialData.diffuseColor = new THREE.Color( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
|
|
1136
1110
|
break;
|
|
1137
|
-
|
|
1138
1111
|
case 'emissiveColor':
|
|
1139
1112
|
materialData.emissiveColor = new THREE.Color( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
|
|
1140
1113
|
break;
|
|
1141
|
-
|
|
1142
1114
|
case 'shininess':
|
|
1143
1115
|
materialData.shininess = fieldValues[ 0 ];
|
|
1144
1116
|
break;
|
|
1145
|
-
|
|
1146
1117
|
case 'specularColor':
|
|
1147
1118
|
materialData.emissiveColor = new THREE.Color( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
|
|
1148
1119
|
break;
|
|
1149
|
-
|
|
1150
1120
|
case 'transparency':
|
|
1151
1121
|
materialData.transparency = fieldValues[ 0 ];
|
|
1152
1122
|
break;
|
|
1153
|
-
|
|
1154
1123
|
default:
|
|
1155
1124
|
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1156
1125
|
break;
|
|
@@ -1166,7 +1135,6 @@
|
|
|
1166
1135
|
function parseHexColor( hex, textureType, color ) {
|
|
1167
1136
|
|
|
1168
1137
|
let value;
|
|
1169
|
-
|
|
1170
1138
|
switch ( textureType ) {
|
|
1171
1139
|
|
|
1172
1140
|
case TEXTURE_TYPE.INTENSITY:
|
|
@@ -1177,7 +1145,6 @@
|
|
|
1177
1145
|
color.b = value;
|
|
1178
1146
|
color.a = 1;
|
|
1179
1147
|
break;
|
|
1180
|
-
|
|
1181
1148
|
case TEXTURE_TYPE.INTENSITY_ALPHA:
|
|
1182
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.
|
|
1183
1150
|
value = parseInt( '0x' + hex.substring( 2, 4 ) );
|
|
@@ -1186,7 +1153,6 @@
|
|
|
1186
1153
|
color.b = value;
|
|
1187
1154
|
color.a = parseInt( '0x' + hex.substring( 4, 6 ) );
|
|
1188
1155
|
break;
|
|
1189
|
-
|
|
1190
1156
|
case TEXTURE_TYPE.RGB:
|
|
1191
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
|
|
1192
1158
|
color.r = parseInt( '0x' + hex.substring( 2, 4 ) );
|
|
@@ -1194,7 +1160,6 @@
|
|
|
1194
1160
|
color.b = parseInt( '0x' + hex.substring( 6, 8 ) );
|
|
1195
1161
|
color.a = 1;
|
|
1196
1162
|
break;
|
|
1197
|
-
|
|
1198
1163
|
case TEXTURE_TYPE.RGBA:
|
|
1199
1164
|
// RGBA texture: Four-component images specify the alpha opacity byte after red/green/blue
|
|
1200
1165
|
color.r = parseInt( '0x' + hex.substring( 2, 4 ) );
|
|
@@ -1202,7 +1167,6 @@
|
|
|
1202
1167
|
color.b = parseInt( '0x' + hex.substring( 6, 8 ) );
|
|
1203
1168
|
color.a = parseInt( '0x' + hex.substring( 8, 10 ) );
|
|
1204
1169
|
break;
|
|
1205
|
-
|
|
1206
1170
|
default:
|
|
1207
1171
|
|
|
1208
1172
|
}
|
|
@@ -1212,25 +1176,20 @@
|
|
|
1212
1176
|
function getTextureType( num_components ) {
|
|
1213
1177
|
|
|
1214
1178
|
let type;
|
|
1215
|
-
|
|
1216
1179
|
switch ( num_components ) {
|
|
1217
1180
|
|
|
1218
1181
|
case 1:
|
|
1219
1182
|
type = TEXTURE_TYPE.INTENSITY;
|
|
1220
1183
|
break;
|
|
1221
|
-
|
|
1222
1184
|
case 2:
|
|
1223
1185
|
type = TEXTURE_TYPE.INTENSITY_ALPHA;
|
|
1224
1186
|
break;
|
|
1225
|
-
|
|
1226
1187
|
case 3:
|
|
1227
1188
|
type = TEXTURE_TYPE.RGB;
|
|
1228
1189
|
break;
|
|
1229
|
-
|
|
1230
1190
|
case 4:
|
|
1231
1191
|
type = TEXTURE_TYPE.RGBA;
|
|
1232
1192
|
break;
|
|
1233
|
-
|
|
1234
1193
|
default:
|
|
1235
1194
|
|
|
1236
1195
|
}
|
|
@@ -1245,13 +1204,11 @@
|
|
|
1245
1204
|
let wrapS = THREE.RepeatWrapping;
|
|
1246
1205
|
let wrapT = THREE.RepeatWrapping;
|
|
1247
1206
|
const fields = node.fields;
|
|
1248
|
-
|
|
1249
1207
|
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1250
1208
|
|
|
1251
1209
|
const field = fields[ i ];
|
|
1252
1210
|
const fieldName = field.name;
|
|
1253
1211
|
const fieldValues = field.values;
|
|
1254
|
-
|
|
1255
1212
|
switch ( fieldName ) {
|
|
1256
1213
|
|
|
1257
1214
|
case 'image':
|
|
@@ -1266,7 +1223,6 @@
|
|
|
1266
1223
|
b: 0,
|
|
1267
1224
|
a: 0
|
|
1268
1225
|
};
|
|
1269
|
-
|
|
1270
1226
|
for ( let j = 3, k = 0, jl = fieldValues.length; j < jl; j ++, k ++ ) {
|
|
1271
1227
|
|
|
1272
1228
|
parseHexColor( fieldValues[ j ], textureType, color );
|
|
@@ -1281,17 +1237,13 @@
|
|
|
1281
1237
|
texture = new THREE.DataTexture( data, width, height );
|
|
1282
1238
|
texture.needsUpdate = true;
|
|
1283
1239
|
texture.__type = textureType; // needed for material modifications
|
|
1284
|
-
|
|
1285
1240
|
break;
|
|
1286
|
-
|
|
1287
1241
|
case 'repeatS':
|
|
1288
1242
|
if ( fieldValues[ 0 ] === false ) wrapS = THREE.ClampToEdgeWrapping;
|
|
1289
1243
|
break;
|
|
1290
|
-
|
|
1291
1244
|
case 'repeatT':
|
|
1292
1245
|
if ( fieldValues[ 0 ] === false ) wrapT = THREE.ClampToEdgeWrapping;
|
|
1293
1246
|
break;
|
|
1294
|
-
|
|
1295
1247
|
default:
|
|
1296
1248
|
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1297
1249
|
break;
|
|
@@ -1317,28 +1269,23 @@
|
|
|
1317
1269
|
let wrapS = THREE.RepeatWrapping;
|
|
1318
1270
|
let wrapT = THREE.RepeatWrapping;
|
|
1319
1271
|
const fields = node.fields;
|
|
1320
|
-
|
|
1321
1272
|
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1322
1273
|
|
|
1323
1274
|
const field = fields[ i ];
|
|
1324
1275
|
const fieldName = field.name;
|
|
1325
1276
|
const fieldValues = field.values;
|
|
1326
|
-
|
|
1327
1277
|
switch ( fieldName ) {
|
|
1328
1278
|
|
|
1329
1279
|
case 'url':
|
|
1330
1280
|
const url = fieldValues[ 0 ];
|
|
1331
1281
|
if ( url ) texture = textureLoader.load( url );
|
|
1332
1282
|
break;
|
|
1333
|
-
|
|
1334
1283
|
case 'repeatS':
|
|
1335
1284
|
if ( fieldValues[ 0 ] === false ) wrapS = THREE.ClampToEdgeWrapping;
|
|
1336
1285
|
break;
|
|
1337
|
-
|
|
1338
1286
|
case 'repeatT':
|
|
1339
1287
|
if ( fieldValues[ 0 ] === false ) wrapT = THREE.ClampToEdgeWrapping;
|
|
1340
1288
|
break;
|
|
1341
|
-
|
|
1342
1289
|
default:
|
|
1343
1290
|
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1344
1291
|
break;
|
|
@@ -1367,31 +1314,25 @@
|
|
|
1367
1314
|
translation: new THREE.Vector2()
|
|
1368
1315
|
};
|
|
1369
1316
|
const fields = node.fields;
|
|
1370
|
-
|
|
1371
1317
|
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1372
1318
|
|
|
1373
1319
|
const field = fields[ i ];
|
|
1374
1320
|
const fieldName = field.name;
|
|
1375
1321
|
const fieldValues = field.values;
|
|
1376
|
-
|
|
1377
1322
|
switch ( fieldName ) {
|
|
1378
1323
|
|
|
1379
1324
|
case 'center':
|
|
1380
1325
|
transformData.center.set( fieldValues[ 0 ], fieldValues[ 1 ] );
|
|
1381
1326
|
break;
|
|
1382
|
-
|
|
1383
1327
|
case 'rotation':
|
|
1384
1328
|
transformData.rotation = fieldValues[ 0 ];
|
|
1385
1329
|
break;
|
|
1386
|
-
|
|
1387
1330
|
case 'scale':
|
|
1388
1331
|
transformData.scale.set( fieldValues[ 0 ], fieldValues[ 1 ] );
|
|
1389
1332
|
break;
|
|
1390
|
-
|
|
1391
1333
|
case 'translation':
|
|
1392
1334
|
transformData.translation.set( fieldValues[ 0 ], fieldValues[ 1 ] );
|
|
1393
1335
|
break;
|
|
1394
|
-
|
|
1395
1336
|
default:
|
|
1396
1337
|
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1397
1338
|
break;
|
|
@@ -1414,23 +1355,19 @@
|
|
|
1414
1355
|
|
|
1415
1356
|
const worldInfo = {};
|
|
1416
1357
|
const fields = node.fields;
|
|
1417
|
-
|
|
1418
1358
|
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1419
1359
|
|
|
1420
1360
|
const field = fields[ i ];
|
|
1421
1361
|
const fieldName = field.name;
|
|
1422
1362
|
const fieldValues = field.values;
|
|
1423
|
-
|
|
1424
1363
|
switch ( fieldName ) {
|
|
1425
1364
|
|
|
1426
1365
|
case 'title':
|
|
1427
1366
|
worldInfo.title = fieldValues[ 0 ];
|
|
1428
1367
|
break;
|
|
1429
|
-
|
|
1430
1368
|
case 'info':
|
|
1431
1369
|
worldInfo.info = fieldValues;
|
|
1432
1370
|
break;
|
|
1433
|
-
|
|
1434
1371
|
default:
|
|
1435
1372
|
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1436
1373
|
break;
|
|
@@ -1453,18 +1390,15 @@
|
|
|
1453
1390
|
let colorPerVertex = true,
|
|
1454
1391
|
normalPerVertex = true;
|
|
1455
1392
|
const fields = node.fields;
|
|
1456
|
-
|
|
1457
1393
|
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1458
1394
|
|
|
1459
1395
|
const field = fields[ i ];
|
|
1460
1396
|
const fieldName = field.name;
|
|
1461
1397
|
const fieldValues = field.values;
|
|
1462
|
-
|
|
1463
1398
|
switch ( fieldName ) {
|
|
1464
1399
|
|
|
1465
1400
|
case 'color':
|
|
1466
1401
|
const colorNode = fieldValues[ 0 ];
|
|
1467
|
-
|
|
1468
1402
|
if ( colorNode !== null ) {
|
|
1469
1403
|
|
|
1470
1404
|
color = getNode( colorNode );
|
|
@@ -1472,10 +1406,8 @@
|
|
|
1472
1406
|
}
|
|
1473
1407
|
|
|
1474
1408
|
break;
|
|
1475
|
-
|
|
1476
1409
|
case 'coord':
|
|
1477
1410
|
const coordNode = fieldValues[ 0 ];
|
|
1478
|
-
|
|
1479
1411
|
if ( coordNode !== null ) {
|
|
1480
1412
|
|
|
1481
1413
|
coord = getNode( coordNode );
|
|
@@ -1483,10 +1415,8 @@
|
|
|
1483
1415
|
}
|
|
1484
1416
|
|
|
1485
1417
|
break;
|
|
1486
|
-
|
|
1487
1418
|
case 'normal':
|
|
1488
1419
|
const normalNode = fieldValues[ 0 ];
|
|
1489
|
-
|
|
1490
1420
|
if ( normalNode !== null ) {
|
|
1491
1421
|
|
|
1492
1422
|
normal = getNode( normalNode );
|
|
@@ -1494,10 +1424,8 @@
|
|
|
1494
1424
|
}
|
|
1495
1425
|
|
|
1496
1426
|
break;
|
|
1497
|
-
|
|
1498
1427
|
case 'texCoord':
|
|
1499
1428
|
const texCoordNode = fieldValues[ 0 ];
|
|
1500
|
-
|
|
1501
1429
|
if ( texCoordNode !== null ) {
|
|
1502
1430
|
|
|
1503
1431
|
texCoord = getNode( texCoordNode );
|
|
@@ -1505,47 +1433,36 @@
|
|
|
1505
1433
|
}
|
|
1506
1434
|
|
|
1507
1435
|
break;
|
|
1508
|
-
|
|
1509
1436
|
case 'ccw':
|
|
1510
1437
|
ccw = fieldValues[ 0 ];
|
|
1511
1438
|
break;
|
|
1512
|
-
|
|
1513
1439
|
case 'colorIndex':
|
|
1514
1440
|
colorIndex = fieldValues;
|
|
1515
1441
|
break;
|
|
1516
|
-
|
|
1517
1442
|
case 'colorPerVertex':
|
|
1518
1443
|
colorPerVertex = fieldValues[ 0 ];
|
|
1519
1444
|
break;
|
|
1520
|
-
|
|
1521
1445
|
case 'convex':
|
|
1522
1446
|
// field not supported
|
|
1523
1447
|
break;
|
|
1524
|
-
|
|
1525
1448
|
case 'coordIndex':
|
|
1526
1449
|
coordIndex = fieldValues;
|
|
1527
1450
|
break;
|
|
1528
|
-
|
|
1529
1451
|
case 'creaseAngle':
|
|
1530
1452
|
creaseAngle = fieldValues[ 0 ];
|
|
1531
1453
|
break;
|
|
1532
|
-
|
|
1533
1454
|
case 'normalIndex':
|
|
1534
1455
|
normalIndex = fieldValues;
|
|
1535
1456
|
break;
|
|
1536
|
-
|
|
1537
1457
|
case 'normalPerVertex':
|
|
1538
1458
|
normalPerVertex = fieldValues[ 0 ];
|
|
1539
1459
|
break;
|
|
1540
|
-
|
|
1541
1460
|
case 'solid':
|
|
1542
1461
|
solid = fieldValues[ 0 ];
|
|
1543
1462
|
break;
|
|
1544
|
-
|
|
1545
1463
|
case 'texCoordIndex':
|
|
1546
1464
|
texCoordIndex = fieldValues;
|
|
1547
1465
|
break;
|
|
1548
|
-
|
|
1549
1466
|
default:
|
|
1550
1467
|
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1551
1468
|
break;
|
|
@@ -1565,7 +1482,6 @@
|
|
|
1565
1482
|
let colorAttribute;
|
|
1566
1483
|
let normalAttribute;
|
|
1567
1484
|
let uvAttribute;
|
|
1568
|
-
|
|
1569
1485
|
if ( color ) {
|
|
1570
1486
|
|
|
1571
1487
|
if ( colorPerVertex === true ) {
|
|
@@ -1573,12 +1489,14 @@
|
|
|
1573
1489
|
if ( colorIndex && colorIndex.length > 0 ) {
|
|
1574
1490
|
|
|
1575
1491
|
// if the colorIndex field is not empty, then it is used to choose colors for each vertex of the IndexedFaceSet.
|
|
1492
|
+
|
|
1576
1493
|
const triangulatedColorIndex = triangulateFaceIndex( colorIndex, ccw );
|
|
1577
1494
|
colorAttribute = computeAttributeFromIndexedData( triangulatedCoordIndex, triangulatedColorIndex, color, 3 );
|
|
1578
1495
|
|
|
1579
1496
|
} else {
|
|
1580
1497
|
|
|
1581
1498
|
// if the colorIndex field is empty, then the coordIndex field is used to choose colors from the THREE.Color node
|
|
1499
|
+
|
|
1582
1500
|
colorAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new THREE.Float32BufferAttribute( color, 3 ) );
|
|
1583
1501
|
|
|
1584
1502
|
}
|
|
@@ -1588,6 +1506,7 @@
|
|
|
1588
1506
|
if ( colorIndex && colorIndex.length > 0 ) {
|
|
1589
1507
|
|
|
1590
1508
|
// if the colorIndex field is not empty, then they are used to choose one color for each face of the IndexedFaceSet
|
|
1509
|
+
|
|
1591
1510
|
const flattenFaceColors = flattenData( color, colorIndex );
|
|
1592
1511
|
const triangulatedFaceColors = triangulateFaceData( flattenFaceColors, coordIndex );
|
|
1593
1512
|
colorAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceColors );
|
|
@@ -1595,6 +1514,7 @@
|
|
|
1595
1514
|
} else {
|
|
1596
1515
|
|
|
1597
1516
|
// if the colorIndex field is empty, then the color are applied to each face of the IndexedFaceSet in order
|
|
1517
|
+
|
|
1598
1518
|
const triangulatedFaceColors = triangulateFaceData( color, coordIndex );
|
|
1599
1519
|
colorAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceColors );
|
|
1600
1520
|
|
|
@@ -1609,15 +1529,18 @@
|
|
|
1609
1529
|
if ( normalPerVertex === true ) {
|
|
1610
1530
|
|
|
1611
1531
|
// consider vertex normals
|
|
1532
|
+
|
|
1612
1533
|
if ( normalIndex && normalIndex.length > 0 ) {
|
|
1613
1534
|
|
|
1614
1535
|
// if the normalIndex field is not empty, then it is used to choose normals for each vertex of the IndexedFaceSet.
|
|
1536
|
+
|
|
1615
1537
|
const triangulatedNormalIndex = triangulateFaceIndex( normalIndex, ccw );
|
|
1616
1538
|
normalAttribute = computeAttributeFromIndexedData( triangulatedCoordIndex, triangulatedNormalIndex, normal, 3 );
|
|
1617
1539
|
|
|
1618
1540
|
} else {
|
|
1619
1541
|
|
|
1620
1542
|
// if the normalIndex field is empty, then the coordIndex field is used to choose normals from the Normal node
|
|
1543
|
+
|
|
1621
1544
|
normalAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new THREE.Float32BufferAttribute( normal, 3 ) );
|
|
1622
1545
|
|
|
1623
1546
|
}
|
|
@@ -1625,9 +1548,11 @@
|
|
|
1625
1548
|
} else {
|
|
1626
1549
|
|
|
1627
1550
|
// consider face normals
|
|
1551
|
+
|
|
1628
1552
|
if ( normalIndex && normalIndex.length > 0 ) {
|
|
1629
1553
|
|
|
1630
1554
|
// if the normalIndex field is not empty, then they are used to choose one normal for each face of the IndexedFaceSet
|
|
1555
|
+
|
|
1631
1556
|
const flattenFaceNormals = flattenData( normal, normalIndex );
|
|
1632
1557
|
const triangulatedFaceNormals = triangulateFaceData( flattenFaceNormals, coordIndex );
|
|
1633
1558
|
normalAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceNormals );
|
|
@@ -1635,6 +1560,7 @@
|
|
|
1635
1560
|
} else {
|
|
1636
1561
|
|
|
1637
1562
|
// if the normalIndex field is empty, then the normals are applied to each face of the IndexedFaceSet in order
|
|
1563
|
+
|
|
1638
1564
|
const triangulatedFaceNormals = triangulateFaceData( normal, coordIndex );
|
|
1639
1565
|
normalAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceNormals );
|
|
1640
1566
|
|
|
@@ -1645,6 +1571,7 @@
|
|
|
1645
1571
|
} else {
|
|
1646
1572
|
|
|
1647
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
|
+
|
|
1648
1575
|
normalAttribute = computeNormalAttribute( triangulatedCoordIndex, coord, creaseAngle );
|
|
1649
1576
|
|
|
1650
1577
|
}
|
|
@@ -1652,15 +1579,18 @@
|
|
|
1652
1579
|
if ( texCoord ) {
|
|
1653
1580
|
|
|
1654
1581
|
// texture coordinates are always defined on vertex level
|
|
1582
|
+
|
|
1655
1583
|
if ( texCoordIndex && texCoordIndex.length > 0 ) {
|
|
1656
1584
|
|
|
1657
1585
|
// if the texCoordIndex field is not empty, then it is used to choose texture coordinates for each vertex of the IndexedFaceSet.
|
|
1586
|
+
|
|
1658
1587
|
const triangulatedTexCoordIndex = triangulateFaceIndex( texCoordIndex, ccw );
|
|
1659
1588
|
uvAttribute = computeAttributeFromIndexedData( triangulatedCoordIndex, triangulatedTexCoordIndex, texCoord, 2 );
|
|
1660
1589
|
|
|
1661
1590
|
} else {
|
|
1662
1591
|
|
|
1663
1592
|
// if the texCoordIndex field is empty, then the coordIndex array is used to choose texture coordinates from the TextureCoordinate node
|
|
1593
|
+
|
|
1664
1594
|
uvAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new THREE.Float32BufferAttribute( texCoord, 2 ) );
|
|
1665
1595
|
|
|
1666
1596
|
}
|
|
@@ -1670,10 +1600,14 @@
|
|
|
1670
1600
|
const geometry = new THREE.BufferGeometry();
|
|
1671
1601
|
const positionAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new THREE.Float32BufferAttribute( coord, 3 ) );
|
|
1672
1602
|
geometry.setAttribute( 'position', positionAttribute );
|
|
1673
|
-
geometry.setAttribute( 'normal', normalAttribute );
|
|
1603
|
+
geometry.setAttribute( 'normal', normalAttribute );
|
|
1604
|
+
|
|
1605
|
+
// optional attributes
|
|
1674
1606
|
|
|
1675
1607
|
if ( colorAttribute ) geometry.setAttribute( 'color', colorAttribute );
|
|
1676
|
-
if ( uvAttribute ) geometry.setAttribute( 'uv', uvAttribute );
|
|
1608
|
+
if ( uvAttribute ) geometry.setAttribute( 'uv', uvAttribute );
|
|
1609
|
+
|
|
1610
|
+
// "solid" influences the material so let's store it for later use
|
|
1677
1611
|
|
|
1678
1612
|
geometry._solid = solid;
|
|
1679
1613
|
geometry._type = 'mesh';
|
|
@@ -1687,18 +1621,15 @@
|
|
|
1687
1621
|
let colorIndex, coordIndex;
|
|
1688
1622
|
let colorPerVertex = true;
|
|
1689
1623
|
const fields = node.fields;
|
|
1690
|
-
|
|
1691
1624
|
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1692
1625
|
|
|
1693
1626
|
const field = fields[ i ];
|
|
1694
1627
|
const fieldName = field.name;
|
|
1695
1628
|
const fieldValues = field.values;
|
|
1696
|
-
|
|
1697
1629
|
switch ( fieldName ) {
|
|
1698
1630
|
|
|
1699
1631
|
case 'color':
|
|
1700
1632
|
const colorNode = fieldValues[ 0 ];
|
|
1701
|
-
|
|
1702
1633
|
if ( colorNode !== null ) {
|
|
1703
1634
|
|
|
1704
1635
|
color = getNode( colorNode );
|
|
@@ -1706,10 +1637,8 @@
|
|
|
1706
1637
|
}
|
|
1707
1638
|
|
|
1708
1639
|
break;
|
|
1709
|
-
|
|
1710
1640
|
case 'coord':
|
|
1711
1641
|
const coordNode = fieldValues[ 0 ];
|
|
1712
|
-
|
|
1713
1642
|
if ( coordNode !== null ) {
|
|
1714
1643
|
|
|
1715
1644
|
coord = getNode( coordNode );
|
|
@@ -1717,27 +1646,24 @@
|
|
|
1717
1646
|
}
|
|
1718
1647
|
|
|
1719
1648
|
break;
|
|
1720
|
-
|
|
1721
1649
|
case 'colorIndex':
|
|
1722
1650
|
colorIndex = fieldValues;
|
|
1723
1651
|
break;
|
|
1724
|
-
|
|
1725
1652
|
case 'colorPerVertex':
|
|
1726
1653
|
colorPerVertex = fieldValues[ 0 ];
|
|
1727
1654
|
break;
|
|
1728
|
-
|
|
1729
1655
|
case 'coordIndex':
|
|
1730
1656
|
coordIndex = fieldValues;
|
|
1731
1657
|
break;
|
|
1732
|
-
|
|
1733
1658
|
default:
|
|
1734
1659
|
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1735
1660
|
break;
|
|
1736
1661
|
|
|
1737
1662
|
}
|
|
1738
1663
|
|
|
1739
|
-
}
|
|
1664
|
+
}
|
|
1740
1665
|
|
|
1666
|
+
// build lines
|
|
1741
1667
|
|
|
1742
1668
|
let colorAttribute;
|
|
1743
1669
|
const expandedLineIndex = expandLineIndex( coordIndex ); // create an index for three.js's linesegment primitive
|
|
@@ -1749,13 +1675,14 @@
|
|
|
1749
1675
|
if ( colorIndex.length > 0 ) {
|
|
1750
1676
|
|
|
1751
1677
|
// if the colorIndex field is not empty, then one color is used for each polyline of the IndexedLineSet.
|
|
1752
|
-
const expandedColorIndex = expandLineIndex( colorIndex ); // compute colors for each line segment (rendering primitve)
|
|
1753
1678
|
|
|
1679
|
+
const expandedColorIndex = expandLineIndex( colorIndex ); // compute colors for each line segment (rendering primitve)
|
|
1754
1680
|
colorAttribute = computeAttributeFromIndexedData( expandedLineIndex, expandedColorIndex, color, 3 ); // compute data on vertex level
|
|
1755
1681
|
|
|
1756
1682
|
} else {
|
|
1757
1683
|
|
|
1758
1684
|
// if the colorIndex field is empty, then the colors are applied to each polyline of the IndexedLineSet in order.
|
|
1685
|
+
|
|
1759
1686
|
colorAttribute = toNonIndexedAttribute( expandedLineIndex, new THREE.Float32BufferAttribute( color, 3 ) );
|
|
1760
1687
|
|
|
1761
1688
|
}
|
|
@@ -1765,25 +1692,25 @@
|
|
|
1765
1692
|
if ( colorIndex.length > 0 ) {
|
|
1766
1693
|
|
|
1767
1694
|
// if the colorIndex field is not empty, then colors are applied to each vertex of the IndexedLineSet
|
|
1768
|
-
const flattenLineColors = flattenData( color, colorIndex ); // compute colors for each VRML primitve
|
|
1769
1695
|
|
|
1696
|
+
const flattenLineColors = flattenData( color, colorIndex ); // compute colors for each VRML primitve
|
|
1770
1697
|
const expandedLineColors = expandLineData( flattenLineColors, coordIndex ); // compute colors for each line segment (rendering primitve)
|
|
1771
|
-
|
|
1772
1698
|
colorAttribute = computeAttributeFromLineData( expandedLineIndex, expandedLineColors ); // compute data on vertex level
|
|
1773
1699
|
|
|
1774
1700
|
} else {
|
|
1775
1701
|
|
|
1776
1702
|
// if the colorIndex field is empty, then the coordIndex field is used to choose colors from the THREE.Color node
|
|
1777
|
-
const expandedLineColors = expandLineData( color, coordIndex ); // compute colors for each line segment (rendering primitve)
|
|
1778
1703
|
|
|
1704
|
+
const expandedLineColors = expandLineData( color, coordIndex ); // compute colors for each line segment (rendering primitve)
|
|
1779
1705
|
colorAttribute = computeAttributeFromLineData( expandedLineIndex, expandedLineColors ); // compute data on vertex level
|
|
1780
1706
|
|
|
1781
1707
|
}
|
|
1782
1708
|
|
|
1783
1709
|
}
|
|
1784
1710
|
|
|
1785
|
-
}
|
|
1711
|
+
}
|
|
1786
1712
|
|
|
1713
|
+
//
|
|
1787
1714
|
|
|
1788
1715
|
const geometry = new THREE.BufferGeometry();
|
|
1789
1716
|
const positionAttribute = toNonIndexedAttribute( expandedLineIndex, new THREE.Float32BufferAttribute( coord, 3 ) );
|
|
@@ -1798,18 +1725,15 @@
|
|
|
1798
1725
|
|
|
1799
1726
|
let color, coord;
|
|
1800
1727
|
const fields = node.fields;
|
|
1801
|
-
|
|
1802
1728
|
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1803
1729
|
|
|
1804
1730
|
const field = fields[ i ];
|
|
1805
1731
|
const fieldName = field.name;
|
|
1806
1732
|
const fieldValues = field.values;
|
|
1807
|
-
|
|
1808
1733
|
switch ( fieldName ) {
|
|
1809
1734
|
|
|
1810
1735
|
case 'color':
|
|
1811
1736
|
const colorNode = fieldValues[ 0 ];
|
|
1812
|
-
|
|
1813
1737
|
if ( colorNode !== null ) {
|
|
1814
1738
|
|
|
1815
1739
|
color = getNode( colorNode );
|
|
@@ -1817,10 +1741,8 @@
|
|
|
1817
1741
|
}
|
|
1818
1742
|
|
|
1819
1743
|
break;
|
|
1820
|
-
|
|
1821
1744
|
case 'coord':
|
|
1822
1745
|
const coordNode = fieldValues[ 0 ];
|
|
1823
|
-
|
|
1824
1746
|
if ( coordNode !== null ) {
|
|
1825
1747
|
|
|
1826
1748
|
coord = getNode( coordNode );
|
|
@@ -1828,7 +1750,6 @@
|
|
|
1828
1750
|
}
|
|
1829
1751
|
|
|
1830
1752
|
break;
|
|
1831
|
-
|
|
1832
1753
|
default:
|
|
1833
1754
|
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1834
1755
|
break;
|
|
@@ -1849,13 +1770,11 @@
|
|
|
1849
1770
|
|
|
1850
1771
|
const size = new THREE.Vector3( 2, 2, 2 );
|
|
1851
1772
|
const fields = node.fields;
|
|
1852
|
-
|
|
1853
1773
|
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1854
1774
|
|
|
1855
1775
|
const field = fields[ i ];
|
|
1856
1776
|
const fieldName = field.name;
|
|
1857
1777
|
const fieldValues = field.values;
|
|
1858
|
-
|
|
1859
1778
|
switch ( fieldName ) {
|
|
1860
1779
|
|
|
1861
1780
|
case 'size':
|
|
@@ -1863,7 +1782,6 @@
|
|
|
1863
1782
|
size.y = fieldValues[ 1 ];
|
|
1864
1783
|
size.z = fieldValues[ 2 ];
|
|
1865
1784
|
break;
|
|
1866
|
-
|
|
1867
1785
|
default:
|
|
1868
1786
|
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1869
1787
|
break;
|
|
@@ -1883,31 +1801,25 @@
|
|
|
1883
1801
|
height = 2,
|
|
1884
1802
|
openEnded = false;
|
|
1885
1803
|
const fields = node.fields;
|
|
1886
|
-
|
|
1887
1804
|
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1888
1805
|
|
|
1889
1806
|
const field = fields[ i ];
|
|
1890
1807
|
const fieldName = field.name;
|
|
1891
1808
|
const fieldValues = field.values;
|
|
1892
|
-
|
|
1893
1809
|
switch ( fieldName ) {
|
|
1894
1810
|
|
|
1895
1811
|
case 'bottom':
|
|
1896
1812
|
openEnded = ! fieldValues[ 0 ];
|
|
1897
1813
|
break;
|
|
1898
|
-
|
|
1899
1814
|
case 'bottomRadius':
|
|
1900
1815
|
radius = fieldValues[ 0 ];
|
|
1901
1816
|
break;
|
|
1902
|
-
|
|
1903
1817
|
case 'height':
|
|
1904
1818
|
height = fieldValues[ 0 ];
|
|
1905
1819
|
break;
|
|
1906
|
-
|
|
1907
1820
|
case 'side':
|
|
1908
1821
|
// field not supported
|
|
1909
1822
|
break;
|
|
1910
|
-
|
|
1911
1823
|
default:
|
|
1912
1824
|
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1913
1825
|
break;
|
|
@@ -1926,35 +1838,28 @@
|
|
|
1926
1838
|
let radius = 1,
|
|
1927
1839
|
height = 2;
|
|
1928
1840
|
const fields = node.fields;
|
|
1929
|
-
|
|
1930
1841
|
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1931
1842
|
|
|
1932
1843
|
const field = fields[ i ];
|
|
1933
1844
|
const fieldName = field.name;
|
|
1934
1845
|
const fieldValues = field.values;
|
|
1935
|
-
|
|
1936
1846
|
switch ( fieldName ) {
|
|
1937
1847
|
|
|
1938
1848
|
case 'bottom':
|
|
1939
1849
|
// field not supported
|
|
1940
1850
|
break;
|
|
1941
|
-
|
|
1942
1851
|
case 'radius':
|
|
1943
1852
|
radius = fieldValues[ 0 ];
|
|
1944
1853
|
break;
|
|
1945
|
-
|
|
1946
1854
|
case 'height':
|
|
1947
1855
|
height = fieldValues[ 0 ];
|
|
1948
1856
|
break;
|
|
1949
|
-
|
|
1950
1857
|
case 'side':
|
|
1951
1858
|
// field not supported
|
|
1952
1859
|
break;
|
|
1953
|
-
|
|
1954
1860
|
case 'top':
|
|
1955
1861
|
// field not supported
|
|
1956
1862
|
break;
|
|
1957
|
-
|
|
1958
1863
|
default:
|
|
1959
1864
|
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1960
1865
|
break;
|
|
@@ -1972,19 +1877,16 @@
|
|
|
1972
1877
|
|
|
1973
1878
|
let radius = 1;
|
|
1974
1879
|
const fields = node.fields;
|
|
1975
|
-
|
|
1976
1880
|
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
1977
1881
|
|
|
1978
1882
|
const field = fields[ i ];
|
|
1979
1883
|
const fieldName = field.name;
|
|
1980
1884
|
const fieldValues = field.values;
|
|
1981
|
-
|
|
1982
1885
|
switch ( fieldName ) {
|
|
1983
1886
|
|
|
1984
1887
|
case 'radius':
|
|
1985
1888
|
radius = fieldValues[ 0 ];
|
|
1986
1889
|
break;
|
|
1987
|
-
|
|
1988
1890
|
default:
|
|
1989
1891
|
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
1990
1892
|
break;
|
|
@@ -2014,18 +1916,15 @@
|
|
|
2014
1916
|
let xSpacing = 1;
|
|
2015
1917
|
let zSpacing = 1;
|
|
2016
1918
|
const fields = node.fields;
|
|
2017
|
-
|
|
2018
1919
|
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
2019
1920
|
|
|
2020
1921
|
const field = fields[ i ];
|
|
2021
1922
|
const fieldName = field.name;
|
|
2022
1923
|
const fieldValues = field.values;
|
|
2023
|
-
|
|
2024
1924
|
switch ( fieldName ) {
|
|
2025
1925
|
|
|
2026
1926
|
case 'color':
|
|
2027
1927
|
const colorNode = fieldValues[ 0 ];
|
|
2028
|
-
|
|
2029
1928
|
if ( colorNode !== null ) {
|
|
2030
1929
|
|
|
2031
1930
|
color = getNode( colorNode );
|
|
@@ -2033,10 +1932,8 @@
|
|
|
2033
1932
|
}
|
|
2034
1933
|
|
|
2035
1934
|
break;
|
|
2036
|
-
|
|
2037
1935
|
case 'normal':
|
|
2038
1936
|
const normalNode = fieldValues[ 0 ];
|
|
2039
|
-
|
|
2040
1937
|
if ( normalNode !== null ) {
|
|
2041
1938
|
|
|
2042
1939
|
normal = getNode( normalNode );
|
|
@@ -2044,10 +1941,8 @@
|
|
|
2044
1941
|
}
|
|
2045
1942
|
|
|
2046
1943
|
break;
|
|
2047
|
-
|
|
2048
1944
|
case 'texCoord':
|
|
2049
1945
|
const texCoordNode = fieldValues[ 0 ];
|
|
2050
|
-
|
|
2051
1946
|
if ( texCoordNode !== null ) {
|
|
2052
1947
|
|
|
2053
1948
|
texCoord = getNode( texCoordNode );
|
|
@@ -2055,72 +1950,66 @@
|
|
|
2055
1950
|
}
|
|
2056
1951
|
|
|
2057
1952
|
break;
|
|
2058
|
-
|
|
2059
1953
|
case 'height':
|
|
2060
1954
|
height = fieldValues;
|
|
2061
1955
|
break;
|
|
2062
|
-
|
|
2063
1956
|
case 'ccw':
|
|
2064
1957
|
ccw = fieldValues[ 0 ];
|
|
2065
1958
|
break;
|
|
2066
|
-
|
|
2067
1959
|
case 'colorPerVertex':
|
|
2068
1960
|
colorPerVertex = fieldValues[ 0 ];
|
|
2069
1961
|
break;
|
|
2070
|
-
|
|
2071
1962
|
case 'creaseAngle':
|
|
2072
1963
|
creaseAngle = fieldValues[ 0 ];
|
|
2073
1964
|
break;
|
|
2074
|
-
|
|
2075
1965
|
case 'normalPerVertex':
|
|
2076
1966
|
normalPerVertex = fieldValues[ 0 ];
|
|
2077
1967
|
break;
|
|
2078
|
-
|
|
2079
1968
|
case 'solid':
|
|
2080
1969
|
solid = fieldValues[ 0 ];
|
|
2081
1970
|
break;
|
|
2082
|
-
|
|
2083
1971
|
case 'xDimension':
|
|
2084
1972
|
xDimension = fieldValues[ 0 ];
|
|
2085
1973
|
break;
|
|
2086
|
-
|
|
2087
1974
|
case 'xSpacing':
|
|
2088
1975
|
xSpacing = fieldValues[ 0 ];
|
|
2089
1976
|
break;
|
|
2090
|
-
|
|
2091
1977
|
case 'zDimension':
|
|
2092
1978
|
zDimension = fieldValues[ 0 ];
|
|
2093
1979
|
break;
|
|
2094
|
-
|
|
2095
1980
|
case 'zSpacing':
|
|
2096
1981
|
zSpacing = fieldValues[ 0 ];
|
|
2097
1982
|
break;
|
|
2098
|
-
|
|
2099
1983
|
default:
|
|
2100
1984
|
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
2101
1985
|
break;
|
|
2102
1986
|
|
|
2103
1987
|
}
|
|
2104
1988
|
|
|
2105
|
-
}
|
|
1989
|
+
}
|
|
2106
1990
|
|
|
1991
|
+
// vertex data
|
|
2107
1992
|
|
|
2108
1993
|
const vertices = [];
|
|
2109
1994
|
const normals = [];
|
|
2110
1995
|
const colors = [];
|
|
2111
1996
|
const uvs = [];
|
|
2112
|
-
|
|
2113
1997
|
for ( let i = 0; i < zDimension; i ++ ) {
|
|
2114
1998
|
|
|
2115
1999
|
for ( let j = 0; j < xDimension; j ++ ) {
|
|
2116
2000
|
|
|
2117
2001
|
// compute a row major index
|
|
2118
|
-
|
|
2002
|
+
|
|
2003
|
+
const index = i * xDimension + j;
|
|
2004
|
+
|
|
2005
|
+
// vertices
|
|
2119
2006
|
|
|
2120
2007
|
const x = xSpacing * i;
|
|
2121
2008
|
const y = height[ index ];
|
|
2122
2009
|
const z = zSpacing * j;
|
|
2123
|
-
vertices.push( x, y, z );
|
|
2010
|
+
vertices.push( x, y, z );
|
|
2011
|
+
|
|
2012
|
+
// colors
|
|
2124
2013
|
|
|
2125
2014
|
if ( color && colorPerVertex === true ) {
|
|
2126
2015
|
|
|
@@ -2129,8 +2018,9 @@
|
|
|
2129
2018
|
const b = color[ index * 3 + 2 ];
|
|
2130
2019
|
colors.push( r, g, b );
|
|
2131
2020
|
|
|
2132
|
-
}
|
|
2021
|
+
}
|
|
2133
2022
|
|
|
2023
|
+
// normals
|
|
2134
2024
|
|
|
2135
2025
|
if ( normal && normalPerVertex === true ) {
|
|
2136
2026
|
|
|
@@ -2139,8 +2029,9 @@
|
|
|
2139
2029
|
const zn = normal[ index * 3 + 2 ];
|
|
2140
2030
|
normals.push( xn, yn, zn );
|
|
2141
2031
|
|
|
2142
|
-
}
|
|
2032
|
+
}
|
|
2143
2033
|
|
|
2034
|
+
// uvs
|
|
2144
2035
|
|
|
2145
2036
|
if ( texCoord ) {
|
|
2146
2037
|
|
|
@@ -2156,20 +2047,23 @@
|
|
|
2156
2047
|
|
|
2157
2048
|
}
|
|
2158
2049
|
|
|
2159
|
-
}
|
|
2050
|
+
}
|
|
2160
2051
|
|
|
2052
|
+
// indices
|
|
2161
2053
|
|
|
2162
2054
|
const indices = [];
|
|
2163
|
-
|
|
2164
2055
|
for ( let i = 0; i < xDimension - 1; i ++ ) {
|
|
2165
2056
|
|
|
2166
2057
|
for ( let j = 0; j < zDimension - 1; j ++ ) {
|
|
2167
2058
|
|
|
2168
2059
|
// from https://tecfa.unige.ch/guides/vrml/vrml97/spec/part1/nodesRef.html#ElevationGrid
|
|
2060
|
+
|
|
2169
2061
|
const a = i + j * xDimension;
|
|
2170
2062
|
const b = i + ( j + 1 ) * xDimension;
|
|
2171
2063
|
const c = i + 1 + ( j + 1 ) * xDimension;
|
|
2172
|
-
const d = i + 1 + j * xDimension;
|
|
2064
|
+
const d = i + 1 + j * xDimension;
|
|
2065
|
+
|
|
2066
|
+
// faces
|
|
2173
2067
|
|
|
2174
2068
|
if ( ccw === true ) {
|
|
2175
2069
|
|
|
@@ -2185,13 +2079,16 @@
|
|
|
2185
2079
|
|
|
2186
2080
|
}
|
|
2187
2081
|
|
|
2188
|
-
}
|
|
2082
|
+
}
|
|
2189
2083
|
|
|
2084
|
+
//
|
|
2190
2085
|
|
|
2191
2086
|
const positionAttribute = toNonIndexedAttribute( indices, new THREE.Float32BufferAttribute( vertices, 3 ) );
|
|
2192
2087
|
const uvAttribute = toNonIndexedAttribute( indices, new THREE.Float32BufferAttribute( uvs, 2 ) );
|
|
2193
2088
|
let colorAttribute;
|
|
2194
|
-
let normalAttribute;
|
|
2089
|
+
let normalAttribute;
|
|
2090
|
+
|
|
2091
|
+
// color attribute
|
|
2195
2092
|
|
|
2196
2093
|
if ( color ) {
|
|
2197
2094
|
|
|
@@ -2204,7 +2101,9 @@
|
|
|
2204
2101
|
const index = i + j * ( xDimension - 1 );
|
|
2205
2102
|
const r = color[ index * 3 + 0 ];
|
|
2206
2103
|
const g = color[ index * 3 + 1 ];
|
|
2207
|
-
const b = color[ index * 3 + 2 ];
|
|
2104
|
+
const b = color[ index * 3 + 2 ];
|
|
2105
|
+
|
|
2106
|
+
// one color per quad
|
|
2208
2107
|
|
|
2209
2108
|
colors.push( r, g, b );
|
|
2210
2109
|
colors.push( r, g, b );
|
|
@@ -2225,8 +2124,9 @@
|
|
|
2225
2124
|
|
|
2226
2125
|
}
|
|
2227
2126
|
|
|
2228
|
-
}
|
|
2127
|
+
}
|
|
2229
2128
|
|
|
2129
|
+
// normal attribute
|
|
2230
2130
|
|
|
2231
2131
|
if ( normal ) {
|
|
2232
2132
|
|
|
@@ -2239,7 +2139,9 @@
|
|
|
2239
2139
|
const index = i + j * ( xDimension - 1 );
|
|
2240
2140
|
const xn = normal[ index * 3 + 0 ];
|
|
2241
2141
|
const yn = normal[ index * 3 + 1 ];
|
|
2242
|
-
const zn = normal[ index * 3 + 2 ];
|
|
2142
|
+
const zn = normal[ index * 3 + 2 ];
|
|
2143
|
+
|
|
2144
|
+
// one normal per quad
|
|
2243
2145
|
|
|
2244
2146
|
normals.push( xn, yn, zn );
|
|
2245
2147
|
normals.push( xn, yn, zn );
|
|
@@ -2264,14 +2166,17 @@
|
|
|
2264
2166
|
|
|
2265
2167
|
normalAttribute = computeNormalAttribute( indices, vertices, creaseAngle );
|
|
2266
2168
|
|
|
2267
|
-
}
|
|
2169
|
+
}
|
|
2268
2170
|
|
|
2171
|
+
// build geometry
|
|
2269
2172
|
|
|
2270
2173
|
const geometry = new THREE.BufferGeometry();
|
|
2271
2174
|
geometry.setAttribute( 'position', positionAttribute );
|
|
2272
2175
|
geometry.setAttribute( 'normal', normalAttribute );
|
|
2273
2176
|
geometry.setAttribute( 'uv', uvAttribute );
|
|
2274
|
-
if ( colorAttribute ) geometry.setAttribute( 'color', colorAttribute );
|
|
2177
|
+
if ( colorAttribute ) geometry.setAttribute( 'color', colorAttribute );
|
|
2178
|
+
|
|
2179
|
+
// "solid" influences the material so let's store it for later use
|
|
2275
2180
|
|
|
2276
2181
|
geometry._solid = solid;
|
|
2277
2182
|
geometry._type = 'mesh';
|
|
@@ -2291,56 +2196,43 @@
|
|
|
2291
2196
|
let endCap = true;
|
|
2292
2197
|
let solid = true;
|
|
2293
2198
|
const fields = node.fields;
|
|
2294
|
-
|
|
2295
2199
|
for ( let i = 0, l = fields.length; i < l; i ++ ) {
|
|
2296
2200
|
|
|
2297
2201
|
const field = fields[ i ];
|
|
2298
2202
|
const fieldName = field.name;
|
|
2299
2203
|
const fieldValues = field.values;
|
|
2300
|
-
|
|
2301
2204
|
switch ( fieldName ) {
|
|
2302
2205
|
|
|
2303
2206
|
case 'beginCap':
|
|
2304
2207
|
beginCap = fieldValues[ 0 ];
|
|
2305
2208
|
break;
|
|
2306
|
-
|
|
2307
2209
|
case 'ccw':
|
|
2308
2210
|
ccw = fieldValues[ 0 ];
|
|
2309
2211
|
break;
|
|
2310
|
-
|
|
2311
2212
|
case 'convex':
|
|
2312
2213
|
// field not supported
|
|
2313
2214
|
break;
|
|
2314
|
-
|
|
2315
2215
|
case 'creaseAngle':
|
|
2316
2216
|
creaseAngle = fieldValues[ 0 ];
|
|
2317
2217
|
break;
|
|
2318
|
-
|
|
2319
2218
|
case 'crossSection':
|
|
2320
2219
|
crossSection = fieldValues;
|
|
2321
2220
|
break;
|
|
2322
|
-
|
|
2323
2221
|
case 'endCap':
|
|
2324
2222
|
endCap = fieldValues[ 0 ];
|
|
2325
2223
|
break;
|
|
2326
|
-
|
|
2327
2224
|
case 'orientation':
|
|
2328
2225
|
orientation = fieldValues;
|
|
2329
2226
|
break;
|
|
2330
|
-
|
|
2331
2227
|
case 'scale':
|
|
2332
2228
|
scale = fieldValues;
|
|
2333
2229
|
break;
|
|
2334
|
-
|
|
2335
2230
|
case 'solid':
|
|
2336
2231
|
solid = fieldValues[ 0 ];
|
|
2337
2232
|
break;
|
|
2338
|
-
|
|
2339
2233
|
case 'spine':
|
|
2340
2234
|
spine = fieldValues; // only extrusion along the Y-axis are supported so far
|
|
2341
|
-
|
|
2342
2235
|
break;
|
|
2343
|
-
|
|
2344
2236
|
default:
|
|
2345
2237
|
console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
|
|
2346
2238
|
break;
|
|
@@ -2349,7 +2241,9 @@
|
|
|
2349
2241
|
|
|
2350
2242
|
}
|
|
2351
2243
|
|
|
2352
|
-
const crossSectionClosed = crossSection[ 0 ] === crossSection[ crossSection.length - 2 ] && crossSection[ 1 ] === crossSection[ crossSection.length - 1 ];
|
|
2244
|
+
const crossSectionClosed = crossSection[ 0 ] === crossSection[ crossSection.length - 2 ] && crossSection[ 1 ] === crossSection[ crossSection.length - 1 ];
|
|
2245
|
+
|
|
2246
|
+
// vertices
|
|
2353
2247
|
|
|
2354
2248
|
const vertices = [];
|
|
2355
2249
|
const spineVector = new THREE.Vector3();
|
|
@@ -2357,7 +2251,6 @@
|
|
|
2357
2251
|
const axis = new THREE.Vector3();
|
|
2358
2252
|
const vertex = new THREE.Vector3();
|
|
2359
2253
|
const quaternion = new THREE.Quaternion();
|
|
2360
|
-
|
|
2361
2254
|
for ( let i = 0, j = 0, o = 0, il = spine.length; i < il; i += 3, j += 2, o += 4 ) {
|
|
2362
2255
|
|
|
2363
2256
|
spineVector.fromArray( spine, i );
|
|
@@ -2368,30 +2261,35 @@
|
|
|
2368
2261
|
axis.y = orientation ? orientation[ o + 1 ] : 0;
|
|
2369
2262
|
axis.z = orientation ? orientation[ o + 2 ] : 1;
|
|
2370
2263
|
const angle = orientation ? orientation[ o + 3 ] : 0;
|
|
2371
|
-
|
|
2372
2264
|
for ( let k = 0, kl = crossSection.length; k < kl; k += 2 ) {
|
|
2373
2265
|
|
|
2374
2266
|
vertex.x = crossSection[ k + 0 ];
|
|
2375
2267
|
vertex.y = 0;
|
|
2376
|
-
vertex.z = crossSection[ k + 1 ];
|
|
2268
|
+
vertex.z = crossSection[ k + 1 ];
|
|
2377
2269
|
|
|
2378
|
-
|
|
2270
|
+
// scale
|
|
2271
|
+
|
|
2272
|
+
vertex.multiply( scaling );
|
|
2273
|
+
|
|
2274
|
+
// rotate
|
|
2379
2275
|
|
|
2380
2276
|
quaternion.setFromAxisAngle( axis, angle );
|
|
2381
|
-
vertex.applyQuaternion( quaternion );
|
|
2277
|
+
vertex.applyQuaternion( quaternion );
|
|
2278
|
+
|
|
2279
|
+
// translate
|
|
2382
2280
|
|
|
2383
2281
|
vertex.add( spineVector );
|
|
2384
2282
|
vertices.push( vertex.x, vertex.y, vertex.z );
|
|
2385
2283
|
|
|
2386
2284
|
}
|
|
2387
2285
|
|
|
2388
|
-
}
|
|
2286
|
+
}
|
|
2389
2287
|
|
|
2288
|
+
// indices
|
|
2390
2289
|
|
|
2391
2290
|
const indices = [];
|
|
2392
2291
|
const spineCount = spine.length / 3;
|
|
2393
2292
|
const crossSectionCount = crossSection.length / 2;
|
|
2394
|
-
|
|
2395
2293
|
for ( let i = 0; i < spineCount - 1; i ++ ) {
|
|
2396
2294
|
|
|
2397
2295
|
for ( let j = 0; j < crossSectionCount - 1; j ++ ) {
|
|
@@ -2400,7 +2298,6 @@
|
|
|
2400
2298
|
let b = j + 1 + i * crossSectionCount;
|
|
2401
2299
|
const c = j + ( i + 1 ) * crossSectionCount;
|
|
2402
2300
|
let d = j + 1 + ( i + 1 ) * crossSectionCount;
|
|
2403
|
-
|
|
2404
2301
|
if ( j === crossSectionCount - 2 && crossSectionClosed === true ) {
|
|
2405
2302
|
|
|
2406
2303
|
b = i * crossSectionCount;
|
|
@@ -2422,13 +2319,13 @@
|
|
|
2422
2319
|
|
|
2423
2320
|
}
|
|
2424
2321
|
|
|
2425
|
-
}
|
|
2322
|
+
}
|
|
2426
2323
|
|
|
2324
|
+
// triangulate cap
|
|
2427
2325
|
|
|
2428
2326
|
if ( beginCap === true || endCap === true ) {
|
|
2429
2327
|
|
|
2430
2328
|
const contour = [];
|
|
2431
|
-
|
|
2432
2329
|
for ( let i = 0, l = crossSection.length; i < l; i += 2 ) {
|
|
2433
2330
|
|
|
2434
2331
|
contour.push( new THREE.Vector2( crossSection[ i ], crossSection[ i + 1 ] ) );
|
|
@@ -2437,14 +2334,14 @@
|
|
|
2437
2334
|
|
|
2438
2335
|
const faces = THREE.ShapeUtils.triangulateShape( contour, [] );
|
|
2439
2336
|
const capIndices = [];
|
|
2440
|
-
|
|
2441
2337
|
for ( let i = 0, l = faces.length; i < l; i ++ ) {
|
|
2442
2338
|
|
|
2443
2339
|
const face = faces[ i ];
|
|
2444
2340
|
capIndices.push( face[ 0 ], face[ 1 ], face[ 2 ] );
|
|
2445
2341
|
|
|
2446
|
-
}
|
|
2342
|
+
}
|
|
2447
2343
|
|
|
2344
|
+
// begin cap
|
|
2448
2345
|
|
|
2449
2346
|
if ( beginCap === true ) {
|
|
2450
2347
|
|
|
@@ -2462,8 +2359,9 @@
|
|
|
2462
2359
|
|
|
2463
2360
|
}
|
|
2464
2361
|
|
|
2465
|
-
}
|
|
2362
|
+
}
|
|
2466
2363
|
|
|
2364
|
+
// end cap
|
|
2467
2365
|
|
|
2468
2366
|
if ( endCap === true ) {
|
|
2469
2367
|
|
|
@@ -2491,20 +2389,25 @@
|
|
|
2491
2389
|
const normalAttribute = computeNormalAttribute( indices, vertices, creaseAngle );
|
|
2492
2390
|
const geometry = new THREE.BufferGeometry();
|
|
2493
2391
|
geometry.setAttribute( 'position', positionAttribute );
|
|
2494
|
-
geometry.setAttribute( 'normal', normalAttribute );
|
|
2392
|
+
geometry.setAttribute( 'normal', normalAttribute );
|
|
2393
|
+
// no uvs yet
|
|
2394
|
+
|
|
2495
2395
|
// "solid" influences the material so let's store it for later use
|
|
2496
2396
|
|
|
2497
2397
|
geometry._solid = solid;
|
|
2498
2398
|
geometry._type = 'mesh';
|
|
2499
2399
|
return geometry;
|
|
2500
2400
|
|
|
2501
|
-
}
|
|
2401
|
+
}
|
|
2502
2402
|
|
|
2403
|
+
// helper functions
|
|
2503
2404
|
|
|
2504
2405
|
function resolveUSE( identifier ) {
|
|
2505
2406
|
|
|
2506
2407
|
const node = nodeMap[ identifier ];
|
|
2507
|
-
const build = getNode( node );
|
|
2408
|
+
const build = getNode( node );
|
|
2409
|
+
|
|
2410
|
+
// because the same 3D objects can have different transformations, it's necessary to clone them.
|
|
2508
2411
|
// materials can be influenced by the geometry (e.g. vertex normals). cloning is necessary to avoid
|
|
2509
2412
|
// any side effects
|
|
2510
2413
|
|
|
@@ -2525,17 +2428,20 @@
|
|
|
2525
2428
|
|
|
2526
2429
|
function triangulateFaceIndex( index, ccw ) {
|
|
2527
2430
|
|
|
2528
|
-
const indices = [];
|
|
2431
|
+
const indices = [];
|
|
2432
|
+
|
|
2433
|
+
// since face defintions can have more than three vertices, it's necessary to
|
|
2529
2434
|
// perform a simple triangulation
|
|
2530
2435
|
|
|
2531
2436
|
let start = 0;
|
|
2532
|
-
|
|
2533
2437
|
for ( let i = 0, l = index.length; i < l; i ++ ) {
|
|
2534
2438
|
|
|
2535
2439
|
const i1 = index[ start ];
|
|
2536
2440
|
const i2 = index[ i + ( ccw ? 1 : 2 ) ];
|
|
2537
2441
|
const i3 = index[ i + ( ccw ? 2 : 1 ) ];
|
|
2538
|
-
indices.push( i1, i2, i3 );
|
|
2442
|
+
indices.push( i1, i2, i3 );
|
|
2443
|
+
|
|
2444
|
+
// an index of -1 indicates that the current face has ended and the next one begins
|
|
2539
2445
|
|
|
2540
2446
|
if ( index[ i + 3 ] === - 1 || i + 3 >= l ) {
|
|
2541
2447
|
|
|
@@ -2554,14 +2460,15 @@
|
|
|
2554
2460
|
|
|
2555
2461
|
const triangulatedData = [];
|
|
2556
2462
|
let start = 0;
|
|
2557
|
-
|
|
2558
2463
|
for ( let i = 0, l = index.length; i < l; i ++ ) {
|
|
2559
2464
|
|
|
2560
2465
|
const stride = start * 3;
|
|
2561
2466
|
const x = data[ stride ];
|
|
2562
2467
|
const y = data[ stride + 1 ];
|
|
2563
2468
|
const z = data[ stride + 2 ];
|
|
2564
|
-
triangulatedData.push( x, y, z );
|
|
2469
|
+
triangulatedData.push( x, y, z );
|
|
2470
|
+
|
|
2471
|
+
// an index of -1 indicates that the current face has ended and the next one begins
|
|
2565
2472
|
|
|
2566
2473
|
if ( index[ i + 3 ] === - 1 || i + 3 >= l ) {
|
|
2567
2474
|
|
|
@@ -2579,7 +2486,6 @@
|
|
|
2579
2486
|
function flattenData( data, index ) {
|
|
2580
2487
|
|
|
2581
2488
|
const flattenData = [];
|
|
2582
|
-
|
|
2583
2489
|
for ( let i = 0, l = index.length; i < l; i ++ ) {
|
|
2584
2490
|
|
|
2585
2491
|
const i1 = index[ i ];
|
|
@@ -2598,12 +2504,13 @@
|
|
|
2598
2504
|
function expandLineIndex( index ) {
|
|
2599
2505
|
|
|
2600
2506
|
const indices = [];
|
|
2601
|
-
|
|
2602
2507
|
for ( let i = 0, l = index.length; i < l; i ++ ) {
|
|
2603
2508
|
|
|
2604
2509
|
const i1 = index[ i ];
|
|
2605
2510
|
const i2 = index[ i + 1 ];
|
|
2606
|
-
indices.push( i1, i2 );
|
|
2511
|
+
indices.push( i1, i2 );
|
|
2512
|
+
|
|
2513
|
+
// an index of -1 indicates that the current line has ended and the next one begins
|
|
2607
2514
|
|
|
2608
2515
|
if ( index[ i + 2 ] === - 1 || i + 2 >= l ) {
|
|
2609
2516
|
|
|
@@ -2621,14 +2528,15 @@
|
|
|
2621
2528
|
|
|
2622
2529
|
const triangulatedData = [];
|
|
2623
2530
|
let start = 0;
|
|
2624
|
-
|
|
2625
2531
|
for ( let i = 0, l = index.length; i < l; i ++ ) {
|
|
2626
2532
|
|
|
2627
2533
|
const stride = start * 3;
|
|
2628
2534
|
const x = data[ stride ];
|
|
2629
2535
|
const y = data[ stride + 1 ];
|
|
2630
2536
|
const z = data[ stride + 2 ];
|
|
2631
|
-
triangulatedData.push( x, y, z );
|
|
2537
|
+
triangulatedData.push( x, y, z );
|
|
2538
|
+
|
|
2539
|
+
// an index of -1 indicates that the current line has ended and the next one begins
|
|
2632
2540
|
|
|
2633
2541
|
if ( index[ i + 2 ] === - 1 || i + 2 >= l ) {
|
|
2634
2542
|
|
|
@@ -2649,17 +2557,17 @@
|
|
|
2649
2557
|
const uvA = new THREE.Vector2();
|
|
2650
2558
|
const uvB = new THREE.Vector2();
|
|
2651
2559
|
const uvC = new THREE.Vector2();
|
|
2652
|
-
|
|
2653
2560
|
function computeAttributeFromIndexedData( coordIndex, index, data, itemSize ) {
|
|
2654
2561
|
|
|
2655
|
-
const array = [];
|
|
2562
|
+
const array = [];
|
|
2563
|
+
|
|
2564
|
+
// we use the coordIndex.length as delimiter since normalIndex must contain at least as many indices
|
|
2656
2565
|
|
|
2657
2566
|
for ( let i = 0, l = coordIndex.length; i < l; i += 3 ) {
|
|
2658
2567
|
|
|
2659
2568
|
const a = index[ i ];
|
|
2660
2569
|
const b = index[ i + 1 ];
|
|
2661
2570
|
const c = index[ i + 2 ];
|
|
2662
|
-
|
|
2663
2571
|
if ( itemSize === 2 ) {
|
|
2664
2572
|
|
|
2665
2573
|
uvA.fromArray( data, a * itemSize );
|
|
@@ -2689,7 +2597,6 @@
|
|
|
2689
2597
|
function computeAttributeFromFaceData( index, faceData ) {
|
|
2690
2598
|
|
|
2691
2599
|
const array = [];
|
|
2692
|
-
|
|
2693
2600
|
for ( let i = 0, j = 0, l = index.length; i < l; i += 3, j ++ ) {
|
|
2694
2601
|
|
|
2695
2602
|
vA.fromArray( faceData, j * 3 );
|
|
@@ -2706,7 +2613,6 @@
|
|
|
2706
2613
|
function computeAttributeFromLineData( index, lineData ) {
|
|
2707
2614
|
|
|
2708
2615
|
const array = [];
|
|
2709
|
-
|
|
2710
2616
|
for ( let i = 0, j = 0, l = index.length; i < l; i += 2, j ++ ) {
|
|
2711
2617
|
|
|
2712
2618
|
vA.fromArray( lineData, j * 3 );
|
|
@@ -2726,11 +2632,9 @@
|
|
|
2726
2632
|
const array2 = new array.constructor( indices.length * itemSize );
|
|
2727
2633
|
let index = 0,
|
|
2728
2634
|
index2 = 0;
|
|
2729
|
-
|
|
2730
2635
|
for ( let i = 0, l = indices.length; i < l; i ++ ) {
|
|
2731
2636
|
|
|
2732
2637
|
index = indices[ i ] * itemSize;
|
|
2733
|
-
|
|
2734
2638
|
for ( let j = 0; j < itemSize; j ++ ) {
|
|
2735
2639
|
|
|
2736
2640
|
array2[ index2 ++ ] = array[ index ++ ];
|
|
@@ -2745,11 +2649,12 @@
|
|
|
2745
2649
|
|
|
2746
2650
|
const ab = new THREE.Vector3();
|
|
2747
2651
|
const cb = new THREE.Vector3();
|
|
2748
|
-
|
|
2749
2652
|
function computeNormalAttribute( index, coord, creaseAngle ) {
|
|
2750
2653
|
|
|
2751
2654
|
const faces = [];
|
|
2752
|
-
const vertexNormals = {};
|
|
2655
|
+
const vertexNormals = {};
|
|
2656
|
+
|
|
2657
|
+
// prepare face and raw vertex normals
|
|
2753
2658
|
|
|
2754
2659
|
for ( let i = 0, l = index.length; i < l; i += 3 ) {
|
|
2755
2660
|
|
|
@@ -2773,11 +2678,11 @@
|
|
|
2773
2678
|
vertexNormals[ c ].push( face.normal );
|
|
2774
2679
|
faces.push( face );
|
|
2775
2680
|
|
|
2776
|
-
}
|
|
2681
|
+
}
|
|
2777
2682
|
|
|
2683
|
+
// compute vertex normals and build final geometry
|
|
2778
2684
|
|
|
2779
2685
|
const normals = [];
|
|
2780
|
-
|
|
2781
2686
|
for ( let i = 0, l = faces.length; i < l; i ++ ) {
|
|
2782
2687
|
|
|
2783
2688
|
const face = faces[ i ];
|
|
@@ -2800,7 +2705,6 @@
|
|
|
2800
2705
|
function weightedNormal( normals, vector, creaseAngle ) {
|
|
2801
2706
|
|
|
2802
2707
|
const normal = new THREE.Vector3();
|
|
2803
|
-
|
|
2804
2708
|
if ( creaseAngle === 0 ) {
|
|
2805
2709
|
|
|
2806
2710
|
normal.copy( vector );
|
|
@@ -2826,7 +2730,6 @@
|
|
|
2826
2730
|
function toColorArray( colors ) {
|
|
2827
2731
|
|
|
2828
2732
|
const array = [];
|
|
2829
|
-
|
|
2830
2733
|
for ( let i = 0, l = colors.length; i < l; i += 3 ) {
|
|
2831
2734
|
|
|
2832
2735
|
array.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
|
|
@@ -2836,6 +2739,7 @@
|
|
|
2836
2739
|
return array;
|
|
2837
2740
|
|
|
2838
2741
|
}
|
|
2742
|
+
|
|
2839
2743
|
/**
|
|
2840
2744
|
* Vertically paints the faces interpolating between the
|
|
2841
2745
|
* specified colors at the specified angels. This is used for the Background
|
|
@@ -2858,14 +2762,12 @@
|
|
|
2858
2762
|
* @param {array} colors
|
|
2859
2763
|
* @param {boolean} topDown - Whether to work top down or bottom up.
|
|
2860
2764
|
*/
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
2765
|
function paintFaces( geometry, radius, angles, colors, topDown ) {
|
|
2864
2766
|
|
|
2865
2767
|
// compute threshold values
|
|
2768
|
+
|
|
2866
2769
|
const thresholds = [];
|
|
2867
2770
|
const startAngle = topDown === true ? 0 : Math.PI;
|
|
2868
|
-
|
|
2869
2771
|
for ( let i = 0, l = colors.length; i < l; i ++ ) {
|
|
2870
2772
|
|
|
2871
2773
|
let angle = i === 0 ? 0 : angles[ i - 1 ];
|
|
@@ -2874,32 +2776,31 @@
|
|
|
2874
2776
|
point.setFromSphericalCoords( radius, angle, 0 );
|
|
2875
2777
|
thresholds.push( point );
|
|
2876
2778
|
|
|
2877
|
-
}
|
|
2779
|
+
}
|
|
2878
2780
|
|
|
2781
|
+
// generate vertex colors
|
|
2879
2782
|
|
|
2880
2783
|
const indices = geometry.index;
|
|
2881
2784
|
const positionAttribute = geometry.attributes.position;
|
|
2882
2785
|
const colorAttribute = new THREE.BufferAttribute( new Float32Array( geometry.attributes.position.count * 3 ), 3 );
|
|
2883
2786
|
const position = new THREE.Vector3();
|
|
2884
2787
|
const color = new THREE.Color();
|
|
2885
|
-
|
|
2886
2788
|
for ( let i = 0; i < indices.count; i ++ ) {
|
|
2887
2789
|
|
|
2888
2790
|
const index = indices.getX( i );
|
|
2889
2791
|
position.fromBufferAttribute( positionAttribute, index );
|
|
2890
2792
|
let thresholdIndexA, thresholdIndexB;
|
|
2891
2793
|
let t = 1;
|
|
2892
|
-
|
|
2893
2794
|
for ( let j = 1; j < thresholds.length; j ++ ) {
|
|
2894
2795
|
|
|
2895
2796
|
thresholdIndexA = j - 1;
|
|
2896
2797
|
thresholdIndexB = j;
|
|
2897
2798
|
const thresholdA = thresholds[ thresholdIndexA ];
|
|
2898
2799
|
const thresholdB = thresholds[ thresholdIndexB ];
|
|
2899
|
-
|
|
2900
2800
|
if ( topDown === true ) {
|
|
2901
2801
|
|
|
2902
2802
|
// interpolation for sky color
|
|
2803
|
+
|
|
2903
2804
|
if ( position.y <= thresholdA.y && position.y > thresholdB.y ) {
|
|
2904
2805
|
|
|
2905
2806
|
t = Math.abs( thresholdA.y - position.y ) / Math.abs( thresholdA.y - thresholdB.y );
|
|
@@ -2910,6 +2811,7 @@
|
|
|
2910
2811
|
} else {
|
|
2911
2812
|
|
|
2912
2813
|
// interpolation for ground color
|
|
2814
|
+
|
|
2913
2815
|
if ( position.y >= thresholdA.y && position.y < thresholdB.y ) {
|
|
2914
2816
|
|
|
2915
2817
|
t = Math.abs( thresholdA.y - position.y ) / Math.abs( thresholdA.y - thresholdB.y );
|
|
@@ -2930,20 +2832,26 @@
|
|
|
2930
2832
|
|
|
2931
2833
|
geometry.setAttribute( 'color', colorAttribute );
|
|
2932
2834
|
|
|
2933
|
-
}
|
|
2835
|
+
}
|
|
2934
2836
|
|
|
2837
|
+
//
|
|
2935
2838
|
|
|
2936
2839
|
const textureLoader = new THREE.TextureLoader( this.manager );
|
|
2937
|
-
textureLoader.setPath( this.resourcePath || path ).setCrossOrigin( this.crossOrigin );
|
|
2840
|
+
textureLoader.setPath( this.resourcePath || path ).setCrossOrigin( this.crossOrigin );
|
|
2841
|
+
|
|
2842
|
+
// check version (only 2.0 is supported)
|
|
2938
2843
|
|
|
2939
2844
|
if ( data.indexOf( '#VRML V2.0' ) === - 1 ) {
|
|
2940
2845
|
|
|
2941
2846
|
throw Error( 'THREE.VRMLLexer: Version of VRML asset not supported.' );
|
|
2942
2847
|
|
|
2943
|
-
}
|
|
2848
|
+
}
|
|
2849
|
+
|
|
2850
|
+
// create JSON representing the tree structure of the VRML asset
|
|
2944
2851
|
|
|
2852
|
+
const tree = generateVRMLTree( data );
|
|
2945
2853
|
|
|
2946
|
-
|
|
2854
|
+
// parse the tree structure to a three.js scene
|
|
2947
2855
|
|
|
2948
2856
|
const scene = parseTree( tree );
|
|
2949
2857
|
return scene;
|
|
@@ -2951,7 +2859,6 @@
|
|
|
2951
2859
|
}
|
|
2952
2860
|
|
|
2953
2861
|
}
|
|
2954
|
-
|
|
2955
2862
|
class VRMLLexer {
|
|
2956
2863
|
|
|
2957
2864
|
constructor( tokens ) {
|
|
@@ -2963,7 +2870,6 @@
|
|
|
2963
2870
|
lex( inputText ) {
|
|
2964
2871
|
|
|
2965
2872
|
const lexingResult = this.lexer.tokenize( inputText );
|
|
2966
|
-
|
|
2967
2873
|
if ( lexingResult.errors.length > 0 ) {
|
|
2968
2874
|
|
|
2969
2875
|
console.error( lexingResult.errors );
|
|
@@ -2976,7 +2882,6 @@
|
|
|
2976
2882
|
}
|
|
2977
2883
|
|
|
2978
2884
|
}
|
|
2979
|
-
|
|
2980
2885
|
const CstParser = chevrotain.CstParser; // eslint-disable-line no-undef
|
|
2981
2886
|
|
|
2982
2887
|
class VRMLParser extends CstParser {
|
|
@@ -3211,7 +3116,6 @@
|
|
|
3211
3116
|
}
|
|
3212
3117
|
|
|
3213
3118
|
}
|
|
3214
|
-
|
|
3215
3119
|
class Face {
|
|
3216
3120
|
|
|
3217
3121
|
constructor( a, b, c ) {
|
|
@@ -3224,7 +3128,6 @@
|
|
|
3224
3128
|
}
|
|
3225
3129
|
|
|
3226
3130
|
}
|
|
3227
|
-
|
|
3228
3131
|
const TEXTURE_TYPE = {
|
|
3229
3132
|
INTENSITY: 1,
|
|
3230
3133
|
INTENSITY_ALPHA: 2,
|