three-stdlib 2.24.2 → 2.25.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/controls/OrbitControls.d.ts +2 -0
- package/index.cjs +116401 -611
- package/index.js +116037 -263
- package/package.json +17 -4
- package/_polyfill/CapsuleGeometry.cjs +0 -22
- package/_polyfill/CapsuleGeometry.js +0 -22
- package/_polyfill/CompressedArrayTexture.cjs +0 -12
- package/_polyfill/CompressedArrayTexture.js +0 -12
- package/_polyfill/Data3DTexture.cjs +0 -17
- package/_polyfill/Data3DTexture.js +0 -17
- package/animation/AnimationClipCreator.cjs +0 -56
- package/animation/AnimationClipCreator.js +0 -56
- package/animation/CCDIKSolver.cjs +0 -269
- package/animation/CCDIKSolver.js +0 -269
- package/animation/MMDAnimationHelper.cjs +0 -688
- package/animation/MMDAnimationHelper.js +0 -688
- package/animation/MMDPhysics.cjs +0 -830
- package/animation/MMDPhysics.js +0 -830
- package/cameras/CinematicCamera.cjs +0 -131
- package/cameras/CinematicCamera.js +0 -131
- package/controls/ArcballControls.cjs +0 -2033
- package/controls/ArcballControls.js +0 -2033
- package/controls/DeviceOrientationControls.cjs +0 -85
- package/controls/DeviceOrientationControls.js +0 -85
- package/controls/DragControls.cjs +0 -182
- package/controls/DragControls.js +0 -182
- package/controls/FirstPersonControls.cjs +0 -229
- package/controls/FirstPersonControls.js +0 -229
- package/controls/FlyControls.cjs +0 -248
- package/controls/FlyControls.js +0 -248
- package/controls/OrbitControls.cjs +0 -787
- package/controls/OrbitControls.js +0 -787
- package/controls/PointerLockControls.cjs +0 -103
- package/controls/PointerLockControls.js +0 -103
- package/controls/TrackballControls.cjs +0 -502
- package/controls/TrackballControls.js +0 -502
- package/controls/TransformControls.cjs +0 -1089
- package/controls/TransformControls.js +0 -1089
- package/controls/experimental/CameraControls.cjs +0 -736
- package/controls/experimental/CameraControls.js +0 -736
- package/csm/CSM.cjs +0 -244
- package/csm/CSM.js +0 -244
- package/csm/CSMFrustum.cjs +0 -75
- package/csm/CSMFrustum.js +0 -75
- package/csm/CSMHelper.cjs +0 -114
- package/csm/CSMHelper.js +0 -114
- package/csm/CSMShader.cjs +0 -261
- package/csm/CSMShader.js +0 -261
- package/curves/CurveExtras.cjs +0 -214
- package/curves/CurveExtras.js +0 -214
- package/curves/NURBSCurve.cjs +0 -35
- package/curves/NURBSCurve.js +0 -35
- package/curves/NURBSSurface.cjs +0 -28
- package/curves/NURBSSurface.js +0 -28
- package/curves/NURBSUtils.cjs +0 -226
- package/curves/NURBSUtils.js +0 -226
- package/deprecated/Geometry.cjs +0 -971
- package/deprecated/Geometry.js +0 -971
- package/effects/AnaglyphEffect.cjs +0 -102
- package/effects/AnaglyphEffect.js +0 -102
- package/effects/AsciiEffect.cjs +0 -155
- package/effects/AsciiEffect.js +0 -155
- package/effects/OutlineEffect.cjs +0 -275
- package/effects/OutlineEffect.js +0 -275
- package/effects/ParallaxBarrierEffect.cjs +0 -65
- package/effects/ParallaxBarrierEffect.js +0 -65
- package/effects/PeppersGhostEffect.cjs +0 -88
- package/effects/PeppersGhostEffect.js +0 -88
- package/effects/StereoEffect.cjs +0 -35
- package/effects/StereoEffect.js +0 -35
- package/environments/RoomEnvironment.cjs +0 -95
- package/environments/RoomEnvironment.js +0 -78
- package/exporters/ColladaExporter.cjs +0 -331
- package/exporters/ColladaExporter.js +0 -331
- package/exporters/DRACOExporter.cjs +0 -141
- package/exporters/DRACOExporter.js +0 -141
- package/exporters/GLTFExporter.cjs +0 -1909
- package/exporters/GLTFExporter.js +0 -1909
- package/exporters/MMDExporter.cjs +0 -131
- package/exporters/MMDExporter.js +0 -131
- package/exporters/OBJExporter.cjs +0 -181
- package/exporters/OBJExporter.js +0 -181
- package/exporters/PLYExporter.cjs +0 -280
- package/exporters/PLYExporter.js +0 -280
- package/exporters/STLExporter.cjs +0 -146
- package/exporters/STLExporter.js +0 -146
- package/exporters/USDZExporter.cjs +0 -340
- package/exporters/USDZExporter.js +0 -340
- package/geometries/BoxLineGeometry.cjs +0 -45
- package/geometries/BoxLineGeometry.js +0 -45
- package/geometries/ConvexGeometry.cjs +0 -26
- package/geometries/ConvexGeometry.js +0 -26
- package/geometries/DecalGeometry.cjs +0 -184
- package/geometries/DecalGeometry.js +0 -184
- package/geometries/LightningStrike.cjs +0 -553
- package/geometries/LightningStrike.js +0 -553
- package/geometries/ParametricGeometries.cjs +0 -130
- package/geometries/ParametricGeometries.js +0 -130
- package/geometries/ParametricGeometry.cjs +0 -63
- package/geometries/ParametricGeometry.js +0 -63
- package/geometries/RoundedBoxGeometry.cjs +0 -91
- package/geometries/RoundedBoxGeometry.js +0 -91
- package/geometries/TeapotGeometry.cjs +0 -1563
- package/geometries/TeapotGeometry.js +0 -1563
- package/geometries/TextGeometry.cjs +0 -27
- package/geometries/TextGeometry.js +0 -27
- package/helpers/LightProbeHelper.cjs +0 -73
- package/helpers/LightProbeHelper.js +0 -73
- package/helpers/PositionalAudioHelper.cjs +0 -68
- package/helpers/PositionalAudioHelper.js +0 -68
- package/helpers/RectAreaLightHelper.cjs +0 -44
- package/helpers/RectAreaLightHelper.js +0 -44
- package/helpers/VertexNormalsHelper.cjs +0 -47
- package/helpers/VertexNormalsHelper.js +0 -47
- package/helpers/VertexTangentsHelper.cjs +0 -43
- package/helpers/VertexTangentsHelper.js +0 -43
- package/interactive/HTMLMesh.cjs +0 -325
- package/interactive/HTMLMesh.js +0 -325
- package/interactive/InteractiveGroup.cjs +0 -68
- package/interactive/InteractiveGroup.js +0 -68
- package/interactive/SelectionBox.cjs +0 -134
- package/interactive/SelectionBox.js +0 -134
- package/interactive/SelectionHelper.cjs +0 -51
- package/interactive/SelectionHelper.js +0 -51
- package/libs/MeshoptDecoder.cjs +0 -221
- package/libs/MeshoptDecoder.js +0 -221
- package/libs/MotionControllers.cjs +0 -325
- package/libs/MotionControllers.js +0 -325
- package/lights/LightProbeGenerator.cjs +0 -145
- package/lights/LightProbeGenerator.js +0 -145
- package/lights/RectAreaLightUniformsLib.cjs +0 -32846
- package/lights/RectAreaLightUniformsLib.js +0 -32846
- package/lines/Line2.cjs +0 -13
- package/lines/Line2.js +0 -13
- package/lines/LineGeometry.cjs +0 -44
- package/lines/LineGeometry.js +0 -44
- package/lines/LineMaterial.cjs +0 -547
- package/lines/LineMaterial.js +0 -547
- package/lines/LineSegments2.cjs +0 -203
- package/lines/LineSegments2.js +0 -203
- package/lines/LineSegmentsGeometry.cjs +0 -124
- package/lines/LineSegmentsGeometry.js +0 -124
- package/lines/Wireframe.cjs +0 -32
- package/lines/Wireframe.js +0 -32
- package/lines/WireframeGeometry2.cjs +0 -13
- package/lines/WireframeGeometry2.js +0 -13
- package/loaders/3DMLoader.cjs +0 -803
- package/loaders/3DMLoader.js +0 -803
- package/loaders/3MFLoader.cjs +0 -854
- package/loaders/3MFLoader.js +0 -854
- package/loaders/AMFLoader.cjs +0 -284
- package/loaders/AMFLoader.js +0 -284
- package/loaders/AssimpLoader.cjs +0 -1434
- package/loaders/AssimpLoader.js +0 -1434
- package/loaders/BVHLoader.cjs +0 -207
- package/loaders/BVHLoader.js +0 -207
- package/loaders/BasisTextureLoader.cjs +0 -489
- package/loaders/BasisTextureLoader.js +0 -489
- package/loaders/ColladaLoader.cjs +0 -2405
- package/loaders/ColladaLoader.js +0 -2405
- package/loaders/DDSLoader.cjs +0 -148
- package/loaders/DDSLoader.js +0 -148
- package/loaders/DRACOLoader.cjs +0 -341
- package/loaders/DRACOLoader.js +0 -341
- package/loaders/EXRLoader.cjs +0 -1356
- package/loaders/EXRLoader.js +0 -1356
- package/loaders/FBXLoader.cjs +0 -2457
- package/loaders/FBXLoader.js +0 -2457
- package/loaders/FontLoader.cjs +0 -123
- package/loaders/FontLoader.js +0 -123
- package/loaders/GCodeLoader.cjs +0 -141
- package/loaders/GCodeLoader.js +0 -141
- package/loaders/GLTFLoader.cjs +0 -2504
- package/loaders/GLTFLoader.js +0 -2504
- package/loaders/HDRCubeTextureLoader.cjs +0 -75
- package/loaders/HDRCubeTextureLoader.js +0 -75
- package/loaders/KMZLoader.cjs +0 -75
- package/loaders/KMZLoader.js +0 -75
- package/loaders/KTX2Loader.cjs +0 -480
- package/loaders/KTX2Loader.js +0 -480
- package/loaders/KTXLoader.cjs +0 -93
- package/loaders/KTXLoader.js +0 -93
- package/loaders/LDrawLoader.cjs +0 -1424
- package/loaders/LDrawLoader.js +0 -1424
- package/loaders/LUT3dlLoader.cjs +0 -103
- package/loaders/LUT3dlLoader.js +0 -103
- package/loaders/LUTCubeLoader.cjs +0 -107
- package/loaders/LUTCubeLoader.js +0 -107
- package/loaders/LWOLoader.cjs +0 -645
- package/loaders/LWOLoader.js +0 -645
- package/loaders/LottieLoader.cjs +0 -47
- package/loaders/LottieLoader.js +0 -47
- package/loaders/MD2Loader.cjs +0 -359
- package/loaders/MD2Loader.js +0 -359
- package/loaders/MDDLoader.cjs +0 -58
- package/loaders/MDDLoader.js +0 -58
- package/loaders/MMDLoader.cjs +0 -1121
- package/loaders/MMDLoader.js +0 -1121
- package/loaders/MTLLoader.cjs +0 -304
- package/loaders/MTLLoader.js +0 -304
- package/loaders/NRRDLoader.cjs +0 -401
- package/loaders/NRRDLoader.js +0 -401
- package/loaders/OBJLoader.cjs +0 -487
- package/loaders/OBJLoader.js +0 -487
- package/loaders/PCDLoader.cjs +0 -248
- package/loaders/PCDLoader.js +0 -248
- package/loaders/PDBLoader.cjs +0 -247
- package/loaders/PDBLoader.js +0 -247
- package/loaders/PLYLoader.cjs +0 -317
- package/loaders/PLYLoader.js +0 -317
- package/loaders/PRWMLoader.cjs +0 -160
- package/loaders/PRWMLoader.js +0 -160
- package/loaders/PVRLoader.cjs +0 -131
- package/loaders/PVRLoader.js +0 -131
- package/loaders/RGBELoader.cjs +0 -252
- package/loaders/RGBELoader.js +0 -252
- package/loaders/RGBMLoader.cjs +0 -1004
- package/loaders/RGBMLoader.js +0 -1004
- package/loaders/STLLoader.cjs +0 -190
- package/loaders/STLLoader.js +0 -190
- package/loaders/SVGLoader.cjs +0 -1712
- package/loaders/SVGLoader.js +0 -1712
- package/loaders/TDSLoader.cjs +0 -650
- package/loaders/TDSLoader.js +0 -650
- package/loaders/TGALoader.cjs +0 -285
- package/loaders/TGALoader.js +0 -285
- package/loaders/TTFLoader.cjs +0 -131
- package/loaders/TTFLoader.js +0 -131
- package/loaders/TiltLoader.cjs +0 -375
- package/loaders/TiltLoader.js +0 -375
- package/loaders/VOXLoader.cjs +0 -432
- package/loaders/VOXLoader.js +0 -432
- package/loaders/VRMLLoader.cjs +0 -2105
- package/loaders/VRMLLoader.js +0 -2105
- package/loaders/VRMLoader.cjs +0 -38
- package/loaders/VRMLoader.js +0 -38
- package/loaders/VTKLoader.cjs +0 -648
- package/loaders/VTKLoader.js +0 -648
- package/loaders/XLoader.cjs +0 -1258
- package/loaders/XLoader.js +0 -1258
- package/loaders/XYZLoader.cjs +0 -60
- package/loaders/XYZLoader.js +0 -60
- package/loaders/lwo/IFFParser.cjs +0 -743
- package/loaders/lwo/IFFParser.js +0 -743
- package/loaders/lwo/LWO2Parser.cjs +0 -312
- package/loaders/lwo/LWO2Parser.js +0 -312
- package/loaders/lwo/LWO3Parser.cjs +0 -282
- package/loaders/lwo/LWO3Parser.js +0 -282
- package/math/Capsule.cjs +0 -98
- package/math/Capsule.js +0 -98
- package/math/ColorConverter.cjs +0 -42
- package/math/ColorConverter.js +0 -42
- package/math/ConvexHull.cjs +0 -596
- package/math/ConvexHull.js +0 -596
- package/math/ImprovedNoise.cjs +0 -304
- package/math/ImprovedNoise.js +0 -304
- package/math/Lut.cjs +0 -137
- package/math/Lut.js +0 -137
- package/math/MeshSurfaceSampler.cjs +0 -103
- package/math/MeshSurfaceSampler.js +0 -103
- package/math/OBB.cjs +0 -242
- package/math/OBB.js +0 -242
- package/math/Octree.cjs +0 -273
- package/math/Octree.js +0 -273
- package/math/SimplexNoise.cjs +0 -440
- package/math/SimplexNoise.js +0 -440
- package/misc/ConvexObjectBreaker.cjs +0 -292
- package/misc/ConvexObjectBreaker.js +0 -292
- package/misc/GPUComputationRenderer.cjs +0 -205
- package/misc/GPUComputationRenderer.js +0 -205
- package/misc/Gyroscope.cjs +0 -33
- package/misc/Gyroscope.js +0 -33
- package/misc/MD2Character.cjs +0 -167
- package/misc/MD2Character.js +0 -167
- package/misc/MD2CharacterComplex.cjs +0 -332
- package/misc/MD2CharacterComplex.js +0 -332
- package/misc/MorphAnimMesh.cjs +0 -40
- package/misc/MorphAnimMesh.js +0 -40
- package/misc/MorphBlendMesh.cjs +0 -179
- package/misc/MorphBlendMesh.js +0 -179
- package/misc/ProgressiveLightmap.cjs +0 -186
- package/misc/ProgressiveLightmap.js +0 -186
- package/misc/RollerCoaster.cjs +0 -353
- package/misc/RollerCoaster.js +0 -353
- package/misc/Timer.cjs +0 -101
- package/misc/Timer.js +0 -101
- package/misc/TubePainter.cjs +0 -123
- package/misc/TubePainter.js +0 -123
- package/misc/Volume.cjs +0 -305
- package/misc/Volume.js +0 -305
- package/misc/VolumeSlice.cjs +0 -114
- package/misc/VolumeSlice.js +0 -114
- package/misc/WebGL.cjs +0 -74
- package/misc/WebGL.js +0 -74
- package/modifiers/CurveModifier.cjs +0 -232
- package/modifiers/CurveModifier.js +0 -232
- package/modifiers/EdgeSplitModifier.cjs +0 -167
- package/modifiers/EdgeSplitModifier.js +0 -168
- package/modifiers/SimplifyModifier.cjs +0 -301
- package/modifiers/SimplifyModifier.js +0 -301
- package/modifiers/TessellateModifier.cjs +0 -214
- package/modifiers/TessellateModifier.js +0 -214
- package/objects/GroundProjectedEnv.cjs +0 -134
- package/objects/GroundProjectedEnv.js +0 -134
- package/objects/Lensflare.cjs +0 -291
- package/objects/Lensflare.js +0 -291
- package/objects/LightningStorm.cjs +0 -110
- package/objects/LightningStorm.js +0 -110
- package/objects/MarchingCubes.cjs +0 -4809
- package/objects/MarchingCubes.js +0 -4809
- package/objects/Reflector.cjs +0 -202
- package/objects/Reflector.js +0 -202
- package/objects/ReflectorForSSRPass.cjs +0 -260
- package/objects/ReflectorForSSRPass.js +0 -260
- package/objects/ReflectorRTT.cjs +0 -10
- package/objects/ReflectorRTT.js +0 -10
- package/objects/Refractor.cjs +0 -215
- package/objects/Refractor.js +0 -215
- package/objects/ShadowMesh.cjs +0 -45
- package/objects/ShadowMesh.js +0 -45
- package/objects/Sky.cjs +0 -200
- package/objects/Sky.js +0 -200
- package/objects/Water.cjs +0 -242
- package/objects/Water.js +0 -242
- package/objects/Water2.cjs +0 -256
- package/objects/Water2.js +0 -256
- package/physics/AmmoPhysics.cjs +0 -166
- package/physics/AmmoPhysics.js +0 -166
- package/postprocessing/AdaptiveToneMappingPass.cjs +0 -218
- package/postprocessing/AdaptiveToneMappingPass.js +0 -218
- package/postprocessing/AfterimagePass.cjs +0 -68
- package/postprocessing/AfterimagePass.js +0 -68
- package/postprocessing/BloomPass.cjs +0 -109
- package/postprocessing/BloomPass.js +0 -109
- package/postprocessing/BokehPass.cjs +0 -90
- package/postprocessing/BokehPass.js +0 -90
- package/postprocessing/ClearPass.cjs +0 -36
- package/postprocessing/ClearPass.js +0 -36
- package/postprocessing/CubeTexturePass.cjs +0 -53
- package/postprocessing/CubeTexturePass.js +0 -53
- package/postprocessing/DotScreenPass.cjs +0 -49
- package/postprocessing/DotScreenPass.js +0 -49
- package/postprocessing/EffectComposer.cjs +0 -157
- package/postprocessing/EffectComposer.js +0 -157
- package/postprocessing/FilmPass.cjs +0 -51
- package/postprocessing/FilmPass.js +0 -51
- package/postprocessing/GlitchPass.cjs +0 -84
- package/postprocessing/GlitchPass.js +0 -84
- package/postprocessing/HalftonePass.cjs +0 -53
- package/postprocessing/HalftonePass.js +0 -53
- package/postprocessing/LUTPass.cjs +0 -142
- package/postprocessing/LUTPass.js +0 -142
- package/postprocessing/MaskPass.cjs +0 -69
- package/postprocessing/MaskPass.js +0 -69
- package/postprocessing/OutlinePass.cjs +0 -479
- package/postprocessing/OutlinePass.js +0 -479
- package/postprocessing/Pass.cjs +0 -48
- package/postprocessing/Pass.js +0 -48
- package/postprocessing/RenderPass.cjs +0 -59
- package/postprocessing/RenderPass.js +0 -59
- package/postprocessing/RenderPixelatedPass.cjs +0 -199
- package/postprocessing/RenderPixelatedPass.js +0 -199
- package/postprocessing/SAOPass.cjs +0 -288
- package/postprocessing/SAOPass.js +0 -288
- package/postprocessing/SMAAPass.cjs +0 -112
- package/postprocessing/SMAAPass.js +0 -112
- package/postprocessing/SSAARenderPass.cjs +0 -189
- package/postprocessing/SSAARenderPass.js +0 -189
- package/postprocessing/SSAOPass.cjs +0 -272
- package/postprocessing/SSAOPass.js +0 -272
- package/postprocessing/SSRPass.cjs +0 -411
- package/postprocessing/SSRPass.js +0 -411
- package/postprocessing/SavePass.cjs +0 -38
- package/postprocessing/SavePass.js +0 -38
- package/postprocessing/ShaderPass.cjs +0 -49
- package/postprocessing/ShaderPass.js +0 -49
- package/postprocessing/TAARenderPass.cjs +0 -174
- package/postprocessing/TAARenderPass.js +0 -174
- package/postprocessing/TexturePass.cjs +0 -42
- package/postprocessing/TexturePass.js +0 -42
- package/postprocessing/UnrealBloomPass.cjs +0 -277
- package/postprocessing/UnrealBloomPass.js +0 -277
- package/postprocessing/WaterPass.cjs +0 -72
- package/postprocessing/WaterPass.js +0 -72
- package/renderers/CSS2DRenderer.cjs +0 -122
- package/renderers/CSS2DRenderer.js +0 -122
- package/renderers/CSS3DRenderer.cjs +0 -167
- package/renderers/CSS3DRenderer.js +0 -167
- package/renderers/Projector.cjs +0 -499
- package/renderers/Projector.js +0 -499
- package/renderers/SVGRenderer.cjs +0 -311
- package/renderers/SVGRenderer.js +0 -311
- package/shaders/ACESFilmicToneMappingShader.cjs +0 -55
- package/shaders/ACESFilmicToneMappingShader.js +0 -55
- package/shaders/AfterimageShader.cjs +0 -32
- package/shaders/AfterimageShader.js +0 -32
- package/shaders/BasicShader.cjs +0 -12
- package/shaders/BasicShader.js +0 -12
- package/shaders/BleachBypassShader.cjs +0 -35
- package/shaders/BleachBypassShader.js +0 -35
- package/shaders/BlendShader.cjs +0 -30
- package/shaders/BlendShader.js +0 -30
- package/shaders/BokehShader.cjs +0 -109
- package/shaders/BokehShader.js +0 -109
- package/shaders/BokehShader2.cjs +0 -269
- package/shaders/BokehShader2.js +0 -269
- package/shaders/BrightnessContrastShader.cjs +0 -32
- package/shaders/BrightnessContrastShader.js +0 -32
- package/shaders/ColorCorrectionShader.cjs +0 -30
- package/shaders/ColorCorrectionShader.js +0 -30
- package/shaders/ColorifyShader.cjs +0 -28
- package/shaders/ColorifyShader.js +0 -28
- package/shaders/ConvolutionShader.cjs +0 -55
- package/shaders/ConvolutionShader.js +0 -55
- package/shaders/CopyShader.cjs +0 -25
- package/shaders/CopyShader.js +0 -25
- package/shaders/DOFMipMapShader.cjs +0 -32
- package/shaders/DOFMipMapShader.js +0 -32
- package/shaders/DepthLimitedBlurShader.cjs +0 -114
- package/shaders/DepthLimitedBlurShader.js +0 -114
- package/shaders/DigitalGlitch.cjs +0 -85
- package/shaders/DigitalGlitch.js +0 -85
- package/shaders/DotScreenShader.cjs +0 -39
- package/shaders/DotScreenShader.js +0 -39
- package/shaders/FXAAShader.cjs +0 -1098
- package/shaders/FXAAShader.js +0 -1098
- package/shaders/FilmShader.cjs +0 -53
- package/shaders/FilmShader.js +0 -53
- package/shaders/FocusShader.cjs +0 -55
- package/shaders/FocusShader.js +0 -55
- package/shaders/FreiChenShader.cjs +0 -64
- package/shaders/FreiChenShader.js +0 -64
- package/shaders/FresnelShader.cjs +0 -47
- package/shaders/FresnelShader.js +0 -47
- package/shaders/GammaCorrectionShader.cjs +0 -23
- package/shaders/GammaCorrectionShader.js +0 -23
- package/shaders/GodRaysShader.cjs +0 -183
- package/shaders/GodRaysShader.js +0 -183
- package/shaders/HalftoneShader.cjs +0 -228
- package/shaders/HalftoneShader.js +0 -228
- package/shaders/HorizontalBlurShader.cjs +0 -49
- package/shaders/HorizontalBlurShader.js +0 -49
- package/shaders/HorizontalTiltShiftShader.cjs +0 -37
- package/shaders/HorizontalTiltShiftShader.js +0 -37
- package/shaders/HueSaturationShader.cjs +0 -43
- package/shaders/HueSaturationShader.js +0 -43
- package/shaders/KaleidoShader.cjs +0 -34
- package/shaders/KaleidoShader.js +0 -34
- package/shaders/LuminosityHighPassShader.cjs +0 -37
- package/shaders/LuminosityHighPassShader.js +0 -37
- package/shaders/LuminosityShader.cjs +0 -25
- package/shaders/LuminosityShader.js +0 -25
- package/shaders/MirrorShader.cjs +0 -35
- package/shaders/MirrorShader.js +0 -35
- package/shaders/NormalMapShader.cjs +0 -31
- package/shaders/NormalMapShader.js +0 -31
- package/shaders/ParallaxShader.cjs +0 -133
- package/shaders/ParallaxShader.js +0 -133
- package/shaders/PixelShader.cjs +0 -28
- package/shaders/PixelShader.js +0 -28
- package/shaders/RGBShiftShader.cjs +0 -30
- package/shaders/RGBShiftShader.js +0 -30
- package/shaders/SAOShader.cjs +0 -144
- package/shaders/SAOShader.js +0 -144
- package/shaders/SMAAShader.cjs +0 -358
- package/shaders/SMAAShader.js +0 -358
- package/shaders/SSAOShader.cjs +0 -182
- package/shaders/SSAOShader.js +0 -182
- package/shaders/SSRShader.cjs +0 -342
- package/shaders/SSRShader.js +0 -342
- package/shaders/SepiaShader.cjs +0 -29
- package/shaders/SepiaShader.js +0 -29
- package/shaders/SobelOperatorShader.cjs +0 -54
- package/shaders/SobelOperatorShader.js +0 -54
- package/shaders/SubsurfaceScatteringShader.cjs +0 -98
- package/shaders/SubsurfaceScatteringShader.js +0 -98
- package/shaders/TechnicolorShader.cjs +0 -24
- package/shaders/TechnicolorShader.js +0 -24
- package/shaders/ToneMapShader.cjs +0 -51
- package/shaders/ToneMapShader.js +0 -51
- package/shaders/ToonShader.cjs +0 -188
- package/shaders/ToonShader.js +0 -188
- package/shaders/TriangleBlurShader.cjs +0 -37
- package/shaders/TriangleBlurShader.js +0 -37
- package/shaders/UnpackDepthRGBAShader.cjs +0 -26
- package/shaders/UnpackDepthRGBAShader.js +0 -26
- package/shaders/VerticalBlurShader.cjs +0 -50
- package/shaders/VerticalBlurShader.js +0 -50
- package/shaders/VerticalTiltShiftShader.cjs +0 -37
- package/shaders/VerticalTiltShiftShader.js +0 -37
- package/shaders/VignetteShader.cjs +0 -38
- package/shaders/VignetteShader.js +0 -38
- package/shaders/VolumeShader.cjs +0 -225
- package/shaders/VolumeShader.js +0 -225
- package/shaders/WaterRefractionShader.cjs +0 -59
- package/shaders/WaterRefractionShader.js +0 -59
- package/shaders/types.cjs +0 -1
- package/shaders/types.js +0 -1
- package/textures/FlakesTexture.cjs +0 -30
- package/textures/FlakesTexture.js +0 -30
- package/types/helpers.cjs +0 -4
- package/types/helpers.js +0 -4
- package/utils/BufferGeometryUtils.cjs +0 -636
- package/utils/BufferGeometryUtils.js +0 -636
- package/utils/GeometryCompressionUtils.cjs +0 -573
- package/utils/GeometryCompressionUtils.js +0 -573
- package/utils/GeometryUtils.cjs +0 -109
- package/utils/GeometryUtils.js +0 -109
- package/utils/RoughnessMipmapper.cjs +0 -223
- package/utils/RoughnessMipmapper.js +0 -223
- package/utils/SceneUtils.cjs +0 -36
- package/utils/SceneUtils.js +0 -36
- package/utils/ShadowMapViewer.cjs +0 -111
- package/utils/ShadowMapViewer.js +0 -111
- package/utils/SkeletonUtils.cjs +0 -211
- package/utils/SkeletonUtils.js +0 -211
- package/utils/UVsDebug.cjs +0 -80
- package/utils/UVsDebug.js +0 -80
- package/utils/WorkerPool.cjs +0 -62
- package/utils/WorkerPool.js +0 -62
- package/webxr/ARButton.cjs +0 -119
- package/webxr/ARButton.js +0 -119
- package/webxr/OculusHandModel.cjs +0 -82
- package/webxr/OculusHandModel.js +0 -82
- package/webxr/OculusHandPointerModel.cjs +0 -241
- package/webxr/OculusHandPointerModel.js +0 -224
- package/webxr/Text2D.cjs +0 -48
- package/webxr/Text2D.js +0 -31
- package/webxr/VRButton.cjs +0 -111
- package/webxr/VRButton.js +0 -111
- package/webxr/XRControllerModelFactory.cjs +0 -174
- package/webxr/XRControllerModelFactory.js +0 -174
- package/webxr/XREstimatedLight.cjs +0 -126
- package/webxr/XREstimatedLight.js +0 -126
- package/webxr/XRHandMeshModel.cjs +0 -82
- package/webxr/XRHandMeshModel.js +0 -82
- package/webxr/XRHandModelFactory.cjs +0 -61
- package/webxr/XRHandModelFactory.js +0 -61
- package/webxr/XRHandPrimitiveModel.cjs +0 -68
- package/webxr/XRHandPrimitiveModel.js +0 -68
package/loaders/LDrawLoader.cjs
DELETED
|
@@ -1,1424 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const THREE = require("three");
|
|
4
|
-
const FINISH_TYPE_DEFAULT = 0;
|
|
5
|
-
const FINISH_TYPE_CHROME = 1;
|
|
6
|
-
const FINISH_TYPE_PEARLESCENT = 2;
|
|
7
|
-
const FINISH_TYPE_RUBBER = 3;
|
|
8
|
-
const FINISH_TYPE_MATTE_METALLIC = 4;
|
|
9
|
-
const FINISH_TYPE_METAL = 5;
|
|
10
|
-
const FILE_LOCATION_AS_IS = 0;
|
|
11
|
-
const FILE_LOCATION_TRY_PARTS = 1;
|
|
12
|
-
const FILE_LOCATION_TRY_P = 2;
|
|
13
|
-
const FILE_LOCATION_TRY_MODELS = 3;
|
|
14
|
-
const FILE_LOCATION_TRY_RELATIVE = 4;
|
|
15
|
-
const FILE_LOCATION_TRY_ABSOLUTE = 5;
|
|
16
|
-
const FILE_LOCATION_NOT_FOUND = 6;
|
|
17
|
-
const MAIN_COLOUR_CODE = "16";
|
|
18
|
-
const MAIN_EDGE_COLOUR_CODE = "24";
|
|
19
|
-
const _tempVec0 = /* @__PURE__ */ new THREE.Vector3();
|
|
20
|
-
const _tempVec1 = /* @__PURE__ */ new THREE.Vector3();
|
|
21
|
-
class LDrawConditionalLineMaterial extends THREE.ShaderMaterial {
|
|
22
|
-
constructor(parameters) {
|
|
23
|
-
super({
|
|
24
|
-
uniforms: THREE.UniformsUtils.merge([
|
|
25
|
-
THREE.UniformsLib.fog,
|
|
26
|
-
{
|
|
27
|
-
diffuse: {
|
|
28
|
-
value: new THREE.Color()
|
|
29
|
-
},
|
|
30
|
-
opacity: {
|
|
31
|
-
value: 1
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
]),
|
|
35
|
-
vertexShader: (
|
|
36
|
-
/* glsl */
|
|
37
|
-
`
|
|
38
|
-
attribute vec3 control0;
|
|
39
|
-
attribute vec3 control1;
|
|
40
|
-
attribute vec3 direction;
|
|
41
|
-
varying float discardFlag;
|
|
42
|
-
|
|
43
|
-
#include <common>
|
|
44
|
-
#include <color_pars_vertex>
|
|
45
|
-
#include <fog_pars_vertex>
|
|
46
|
-
#include <logdepthbuf_pars_vertex>
|
|
47
|
-
#include <clipping_planes_pars_vertex>
|
|
48
|
-
|
|
49
|
-
void main() {
|
|
50
|
-
#include <color_vertex>
|
|
51
|
-
|
|
52
|
-
vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);
|
|
53
|
-
gl_Position = projectionMatrix * mvPosition;
|
|
54
|
-
|
|
55
|
-
// Transform the line segment ends and control points into camera clip space
|
|
56
|
-
vec4 c0 = projectionMatrix * modelViewMatrix * vec4(control0, 1.0);
|
|
57
|
-
vec4 c1 = projectionMatrix * modelViewMatrix * vec4(control1, 1.0);
|
|
58
|
-
vec4 p0 = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
59
|
-
vec4 p1 = projectionMatrix * modelViewMatrix * vec4(position + direction, 1.0);
|
|
60
|
-
|
|
61
|
-
c0.xy /= c0.w;
|
|
62
|
-
c1.xy /= c1.w;
|
|
63
|
-
p0.xy /= p0.w;
|
|
64
|
-
p1.xy /= p1.w;
|
|
65
|
-
|
|
66
|
-
// Get the direction of the segment and an orthogonal vector
|
|
67
|
-
vec2 dir = p1.xy - p0.xy;
|
|
68
|
-
vec2 norm = vec2(-dir.y, dir.x);
|
|
69
|
-
|
|
70
|
-
// Get control point directions from the line
|
|
71
|
-
vec2 c0dir = c0.xy - p1.xy;
|
|
72
|
-
vec2 c1dir = c1.xy - p1.xy;
|
|
73
|
-
|
|
74
|
-
// If the vectors to the controls points are pointed in different directions away
|
|
75
|
-
// from the line segment then the line should not be drawn.
|
|
76
|
-
float d0 = dot(normalize(norm), normalize(c0dir));
|
|
77
|
-
float d1 = dot(normalize(norm), normalize(c1dir));
|
|
78
|
-
discardFlag = float(sign(d0) != sign(d1));
|
|
79
|
-
|
|
80
|
-
#include <logdepthbuf_vertex>
|
|
81
|
-
#include <clipping_planes_vertex>
|
|
82
|
-
#include <fog_vertex>
|
|
83
|
-
}
|
|
84
|
-
`
|
|
85
|
-
),
|
|
86
|
-
fragmentShader: (
|
|
87
|
-
/* glsl */
|
|
88
|
-
`
|
|
89
|
-
uniform vec3 diffuse;
|
|
90
|
-
uniform float opacity;
|
|
91
|
-
varying float discardFlag;
|
|
92
|
-
|
|
93
|
-
#include <common>
|
|
94
|
-
#include <color_pars_fragment>
|
|
95
|
-
#include <fog_pars_fragment>
|
|
96
|
-
#include <logdepthbuf_pars_fragment>
|
|
97
|
-
#include <clipping_planes_pars_fragment>
|
|
98
|
-
|
|
99
|
-
void main() {
|
|
100
|
-
if (discardFlag > 0.5) discard;
|
|
101
|
-
|
|
102
|
-
#include <clipping_planes_fragment>
|
|
103
|
-
vec3 outgoingLight = vec3(0.0);
|
|
104
|
-
vec4 diffuseColor = vec4(diffuse, opacity);
|
|
105
|
-
#include <logdepthbuf_fragment>
|
|
106
|
-
#include <color_fragment>
|
|
107
|
-
outgoingLight = diffuseColor.rgb; // simple shader
|
|
108
|
-
gl_FragColor = vec4(outgoingLight, diffuseColor.a);
|
|
109
|
-
#include <tonemapping_fragment>
|
|
110
|
-
#include <${parseInt(THREE.REVISION.replace(/\D+/g, "")) >= 154 ? "colorspace_fragment" : "encodings_fragment"}>
|
|
111
|
-
#include <fog_fragment>
|
|
112
|
-
#include <premultiplied_alpha_fragment>
|
|
113
|
-
}
|
|
114
|
-
`
|
|
115
|
-
)
|
|
116
|
-
});
|
|
117
|
-
Object.defineProperties(this, {
|
|
118
|
-
opacity: {
|
|
119
|
-
get: function() {
|
|
120
|
-
return this.uniforms.opacity.value;
|
|
121
|
-
},
|
|
122
|
-
set: function(value) {
|
|
123
|
-
this.uniforms.opacity.value = value;
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
color: {
|
|
127
|
-
get: function() {
|
|
128
|
-
return this.uniforms.diffuse.value;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
this.setValues(parameters);
|
|
133
|
-
this.isLDrawConditionalLineMaterial = true;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
class ConditionalLineSegments extends THREE.LineSegments {
|
|
137
|
-
constructor(geometry, material) {
|
|
138
|
-
super(geometry, material);
|
|
139
|
-
this.isConditionalLine = true;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
function generateFaceNormals(faces) {
|
|
143
|
-
for (let i = 0, l = faces.length; i < l; i++) {
|
|
144
|
-
const face = faces[i];
|
|
145
|
-
const vertices = face.vertices;
|
|
146
|
-
const v0 = vertices[0];
|
|
147
|
-
const v1 = vertices[1];
|
|
148
|
-
const v2 = vertices[2];
|
|
149
|
-
_tempVec0.subVectors(v1, v0);
|
|
150
|
-
_tempVec1.subVectors(v2, v1);
|
|
151
|
-
face.faceNormal = new THREE.Vector3().crossVectors(_tempVec0, _tempVec1).normalize();
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
const _ray = /* @__PURE__ */ new THREE.Ray();
|
|
155
|
-
function smoothNormals(faces, lineSegments, checkSubSegments = false) {
|
|
156
|
-
const hashMultiplier = (1 + 1e-10) * 100;
|
|
157
|
-
function hashVertex(v) {
|
|
158
|
-
const x = ~~(v.x * hashMultiplier);
|
|
159
|
-
const y = ~~(v.y * hashMultiplier);
|
|
160
|
-
const z = ~~(v.z * hashMultiplier);
|
|
161
|
-
return `${x},${y},${z}`;
|
|
162
|
-
}
|
|
163
|
-
function hashEdge(v0, v1) {
|
|
164
|
-
return `${hashVertex(v0)}_${hashVertex(v1)}`;
|
|
165
|
-
}
|
|
166
|
-
function toNormalizedRay(v0, v1, targetRay) {
|
|
167
|
-
targetRay.direction.subVectors(v1, v0).normalize();
|
|
168
|
-
const scalar = v0.dot(targetRay.direction);
|
|
169
|
-
targetRay.origin.copy(v0).addScaledVector(targetRay.direction, -scalar);
|
|
170
|
-
return targetRay;
|
|
171
|
-
}
|
|
172
|
-
function hashRay(ray) {
|
|
173
|
-
return hashEdge(ray.origin, ray.direction);
|
|
174
|
-
}
|
|
175
|
-
const hardEdges = /* @__PURE__ */ new Set();
|
|
176
|
-
const hardEdgeRays = /* @__PURE__ */ new Map();
|
|
177
|
-
const halfEdgeList = {};
|
|
178
|
-
const normals = [];
|
|
179
|
-
for (let i = 0, l = lineSegments.length; i < l; i++) {
|
|
180
|
-
const ls = lineSegments[i];
|
|
181
|
-
const vertices = ls.vertices;
|
|
182
|
-
const v0 = vertices[0];
|
|
183
|
-
const v1 = vertices[1];
|
|
184
|
-
hardEdges.add(hashEdge(v0, v1));
|
|
185
|
-
hardEdges.add(hashEdge(v1, v0));
|
|
186
|
-
if (checkSubSegments) {
|
|
187
|
-
const ray = toNormalizedRay(v0, v1, new THREE.Ray());
|
|
188
|
-
const rh1 = hashRay(ray);
|
|
189
|
-
if (!hardEdgeRays.has(rh1)) {
|
|
190
|
-
toNormalizedRay(v1, v0, ray);
|
|
191
|
-
const rh2 = hashRay(ray);
|
|
192
|
-
const info2 = {
|
|
193
|
-
ray,
|
|
194
|
-
distances: []
|
|
195
|
-
};
|
|
196
|
-
hardEdgeRays.set(rh1, info2);
|
|
197
|
-
hardEdgeRays.set(rh2, info2);
|
|
198
|
-
}
|
|
199
|
-
const info = hardEdgeRays.get(rh1);
|
|
200
|
-
let d0 = info.ray.direction.dot(v0);
|
|
201
|
-
let d1 = info.ray.direction.dot(v1);
|
|
202
|
-
if (d0 > d1) {
|
|
203
|
-
;
|
|
204
|
-
[d0, d1] = [d1, d0];
|
|
205
|
-
}
|
|
206
|
-
info.distances.push(d0, d1);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
for (let i = 0, l = faces.length; i < l; i++) {
|
|
210
|
-
const tri = faces[i];
|
|
211
|
-
const vertices = tri.vertices;
|
|
212
|
-
const vertCount = vertices.length;
|
|
213
|
-
for (let i2 = 0; i2 < vertCount; i2++) {
|
|
214
|
-
const index = i2;
|
|
215
|
-
const next = (i2 + 1) % vertCount;
|
|
216
|
-
const v0 = vertices[index];
|
|
217
|
-
const v1 = vertices[next];
|
|
218
|
-
const hash = hashEdge(v0, v1);
|
|
219
|
-
if (hardEdges.has(hash)) {
|
|
220
|
-
continue;
|
|
221
|
-
}
|
|
222
|
-
if (checkSubSegments) {
|
|
223
|
-
toNormalizedRay(v0, v1, _ray);
|
|
224
|
-
const rayHash = hashRay(_ray);
|
|
225
|
-
if (hardEdgeRays.has(rayHash)) {
|
|
226
|
-
const info2 = hardEdgeRays.get(rayHash);
|
|
227
|
-
const { ray, distances } = info2;
|
|
228
|
-
let d0 = ray.direction.dot(v0);
|
|
229
|
-
let d1 = ray.direction.dot(v1);
|
|
230
|
-
if (d0 > d1) {
|
|
231
|
-
;
|
|
232
|
-
[d0, d1] = [d1, d0];
|
|
233
|
-
}
|
|
234
|
-
let found = false;
|
|
235
|
-
for (let i3 = 0, l2 = distances.length; i3 < l2; i3 += 2) {
|
|
236
|
-
if (d0 >= distances[i3] && d1 <= distances[i3 + 1]) {
|
|
237
|
-
found = true;
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
if (found) {
|
|
242
|
-
continue;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
const info = {
|
|
247
|
-
index,
|
|
248
|
-
tri
|
|
249
|
-
};
|
|
250
|
-
halfEdgeList[hash] = info;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
while (true) {
|
|
254
|
-
let halfEdge = null;
|
|
255
|
-
for (const key in halfEdgeList) {
|
|
256
|
-
halfEdge = halfEdgeList[key];
|
|
257
|
-
break;
|
|
258
|
-
}
|
|
259
|
-
if (halfEdge === null) {
|
|
260
|
-
break;
|
|
261
|
-
}
|
|
262
|
-
const queue = [halfEdge];
|
|
263
|
-
while (queue.length > 0) {
|
|
264
|
-
const tri = queue.pop().tri;
|
|
265
|
-
const vertices = tri.vertices;
|
|
266
|
-
const vertNormals = tri.normals;
|
|
267
|
-
const faceNormal = tri.faceNormal;
|
|
268
|
-
const vertCount = vertices.length;
|
|
269
|
-
for (let i2 = 0; i2 < vertCount; i2++) {
|
|
270
|
-
const index = i2;
|
|
271
|
-
const next = (i2 + 1) % vertCount;
|
|
272
|
-
const v0 = vertices[index];
|
|
273
|
-
const v1 = vertices[next];
|
|
274
|
-
const hash = hashEdge(v0, v1);
|
|
275
|
-
delete halfEdgeList[hash];
|
|
276
|
-
const reverseHash = hashEdge(v1, v0);
|
|
277
|
-
const otherInfo = halfEdgeList[reverseHash];
|
|
278
|
-
if (otherInfo) {
|
|
279
|
-
const otherTri = otherInfo.tri;
|
|
280
|
-
const otherIndex = otherInfo.index;
|
|
281
|
-
const otherNormals = otherTri.normals;
|
|
282
|
-
const otherVertCount = otherNormals.length;
|
|
283
|
-
const otherFaceNormal = otherTri.faceNormal;
|
|
284
|
-
if (Math.abs(otherTri.faceNormal.dot(tri.faceNormal)) < 0.25) {
|
|
285
|
-
continue;
|
|
286
|
-
}
|
|
287
|
-
if (reverseHash in halfEdgeList) {
|
|
288
|
-
queue.push(otherInfo);
|
|
289
|
-
delete halfEdgeList[reverseHash];
|
|
290
|
-
}
|
|
291
|
-
const otherNext = (otherIndex + 1) % otherVertCount;
|
|
292
|
-
if (vertNormals[index] && otherNormals[otherNext] && vertNormals[index] !== otherNormals[otherNext]) {
|
|
293
|
-
otherNormals[otherNext].norm.add(vertNormals[index].norm);
|
|
294
|
-
vertNormals[index].norm = otherNormals[otherNext].norm;
|
|
295
|
-
}
|
|
296
|
-
let sharedNormal1 = vertNormals[index] || otherNormals[otherNext];
|
|
297
|
-
if (sharedNormal1 === null) {
|
|
298
|
-
sharedNormal1 = { norm: new THREE.Vector3() };
|
|
299
|
-
normals.push(sharedNormal1.norm);
|
|
300
|
-
}
|
|
301
|
-
if (vertNormals[index] === null) {
|
|
302
|
-
vertNormals[index] = sharedNormal1;
|
|
303
|
-
sharedNormal1.norm.add(faceNormal);
|
|
304
|
-
}
|
|
305
|
-
if (otherNormals[otherNext] === null) {
|
|
306
|
-
otherNormals[otherNext] = sharedNormal1;
|
|
307
|
-
sharedNormal1.norm.add(otherFaceNormal);
|
|
308
|
-
}
|
|
309
|
-
if (vertNormals[next] && otherNormals[otherIndex] && vertNormals[next] !== otherNormals[otherIndex]) {
|
|
310
|
-
otherNormals[otherIndex].norm.add(vertNormals[next].norm);
|
|
311
|
-
vertNormals[next].norm = otherNormals[otherIndex].norm;
|
|
312
|
-
}
|
|
313
|
-
let sharedNormal2 = vertNormals[next] || otherNormals[otherIndex];
|
|
314
|
-
if (sharedNormal2 === null) {
|
|
315
|
-
sharedNormal2 = { norm: new THREE.Vector3() };
|
|
316
|
-
normals.push(sharedNormal2.norm);
|
|
317
|
-
}
|
|
318
|
-
if (vertNormals[next] === null) {
|
|
319
|
-
vertNormals[next] = sharedNormal2;
|
|
320
|
-
sharedNormal2.norm.add(faceNormal);
|
|
321
|
-
}
|
|
322
|
-
if (otherNormals[otherIndex] === null) {
|
|
323
|
-
otherNormals[otherIndex] = sharedNormal2;
|
|
324
|
-
sharedNormal2.norm.add(otherFaceNormal);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
for (let i = 0, l = normals.length; i < l; i++) {
|
|
331
|
-
normals[i].normalize();
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
function isPartType(type) {
|
|
335
|
-
return type === "Part" || type === "Unofficial_Part";
|
|
336
|
-
}
|
|
337
|
-
function isPrimitiveType(type) {
|
|
338
|
-
return /primitive/i.test(type) || type === "Subpart";
|
|
339
|
-
}
|
|
340
|
-
class LineParser {
|
|
341
|
-
constructor(line, lineNumber) {
|
|
342
|
-
this.line = line;
|
|
343
|
-
this.lineLength = line.length;
|
|
344
|
-
this.currentCharIndex = 0;
|
|
345
|
-
this.currentChar = " ";
|
|
346
|
-
this.lineNumber = lineNumber;
|
|
347
|
-
}
|
|
348
|
-
seekNonSpace() {
|
|
349
|
-
while (this.currentCharIndex < this.lineLength) {
|
|
350
|
-
this.currentChar = this.line.charAt(this.currentCharIndex);
|
|
351
|
-
if (this.currentChar !== " " && this.currentChar !== " ") {
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
this.currentCharIndex++;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
getToken() {
|
|
358
|
-
const pos0 = this.currentCharIndex++;
|
|
359
|
-
while (this.currentCharIndex < this.lineLength) {
|
|
360
|
-
this.currentChar = this.line.charAt(this.currentCharIndex);
|
|
361
|
-
if (this.currentChar === " " || this.currentChar === " ") {
|
|
362
|
-
break;
|
|
363
|
-
}
|
|
364
|
-
this.currentCharIndex++;
|
|
365
|
-
}
|
|
366
|
-
const pos1 = this.currentCharIndex;
|
|
367
|
-
this.seekNonSpace();
|
|
368
|
-
return this.line.substring(pos0, pos1);
|
|
369
|
-
}
|
|
370
|
-
getVector() {
|
|
371
|
-
return new THREE.Vector3(parseFloat(this.getToken()), parseFloat(this.getToken()), parseFloat(this.getToken()));
|
|
372
|
-
}
|
|
373
|
-
getRemainingString() {
|
|
374
|
-
return this.line.substring(this.currentCharIndex, this.lineLength);
|
|
375
|
-
}
|
|
376
|
-
isAtTheEnd() {
|
|
377
|
-
return this.currentCharIndex >= this.lineLength;
|
|
378
|
-
}
|
|
379
|
-
setToEnd() {
|
|
380
|
-
this.currentCharIndex = this.lineLength;
|
|
381
|
-
}
|
|
382
|
-
getLineNumberString() {
|
|
383
|
-
return this.lineNumber >= 0 ? " at line " + this.lineNumber : "";
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
class LDrawParsedCache {
|
|
387
|
-
constructor(loader) {
|
|
388
|
-
this.loader = loader;
|
|
389
|
-
this._cache = {};
|
|
390
|
-
}
|
|
391
|
-
cloneResult(original) {
|
|
392
|
-
const result = {};
|
|
393
|
-
result.faces = original.faces.map((face) => {
|
|
394
|
-
return {
|
|
395
|
-
colorCode: face.colorCode,
|
|
396
|
-
material: face.material,
|
|
397
|
-
vertices: face.vertices.map((v) => v.clone()),
|
|
398
|
-
normals: face.normals.map(() => null),
|
|
399
|
-
faceNormal: null
|
|
400
|
-
};
|
|
401
|
-
});
|
|
402
|
-
result.conditionalSegments = original.conditionalSegments.map((face) => {
|
|
403
|
-
return {
|
|
404
|
-
colorCode: face.colorCode,
|
|
405
|
-
material: face.material,
|
|
406
|
-
vertices: face.vertices.map((v) => v.clone()),
|
|
407
|
-
controlPoints: face.controlPoints.map((v) => v.clone())
|
|
408
|
-
};
|
|
409
|
-
});
|
|
410
|
-
result.lineSegments = original.lineSegments.map((face) => {
|
|
411
|
-
return {
|
|
412
|
-
colorCode: face.colorCode,
|
|
413
|
-
material: face.material,
|
|
414
|
-
vertices: face.vertices.map((v) => v.clone())
|
|
415
|
-
};
|
|
416
|
-
});
|
|
417
|
-
result.type = original.type;
|
|
418
|
-
result.category = original.category;
|
|
419
|
-
result.keywords = original.keywords;
|
|
420
|
-
result.subobjects = original.subobjects;
|
|
421
|
-
result.totalFaces = original.totalFaces;
|
|
422
|
-
result.startingConstructionStep = original.startingConstructionStep;
|
|
423
|
-
result.materials = original.materials;
|
|
424
|
-
result.group = null;
|
|
425
|
-
return result;
|
|
426
|
-
}
|
|
427
|
-
async fetchData(fileName) {
|
|
428
|
-
let triedLowerCase = false;
|
|
429
|
-
let locationState = FILE_LOCATION_AS_IS;
|
|
430
|
-
while (locationState !== FILE_LOCATION_NOT_FOUND) {
|
|
431
|
-
let subobjectURL = fileName;
|
|
432
|
-
switch (locationState) {
|
|
433
|
-
case FILE_LOCATION_AS_IS:
|
|
434
|
-
locationState = locationState + 1;
|
|
435
|
-
break;
|
|
436
|
-
case FILE_LOCATION_TRY_PARTS:
|
|
437
|
-
subobjectURL = "parts/" + subobjectURL;
|
|
438
|
-
locationState = locationState + 1;
|
|
439
|
-
break;
|
|
440
|
-
case FILE_LOCATION_TRY_P:
|
|
441
|
-
subobjectURL = "p/" + subobjectURL;
|
|
442
|
-
locationState = locationState + 1;
|
|
443
|
-
break;
|
|
444
|
-
case FILE_LOCATION_TRY_MODELS:
|
|
445
|
-
subobjectURL = "models/" + subobjectURL;
|
|
446
|
-
locationState = locationState + 1;
|
|
447
|
-
break;
|
|
448
|
-
case FILE_LOCATION_TRY_RELATIVE:
|
|
449
|
-
subobjectURL = fileName.substring(0, fileName.lastIndexOf("/") + 1) + subobjectURL;
|
|
450
|
-
locationState = locationState + 1;
|
|
451
|
-
break;
|
|
452
|
-
case FILE_LOCATION_TRY_ABSOLUTE:
|
|
453
|
-
if (triedLowerCase) {
|
|
454
|
-
locationState = FILE_LOCATION_NOT_FOUND;
|
|
455
|
-
} else {
|
|
456
|
-
fileName = fileName.toLowerCase();
|
|
457
|
-
subobjectURL = fileName;
|
|
458
|
-
triedLowerCase = true;
|
|
459
|
-
locationState = FILE_LOCATION_AS_IS;
|
|
460
|
-
}
|
|
461
|
-
break;
|
|
462
|
-
}
|
|
463
|
-
const loader = this.loader;
|
|
464
|
-
const fileLoader = new THREE.FileLoader(loader.manager);
|
|
465
|
-
fileLoader.setPath(loader.partsLibraryPath);
|
|
466
|
-
fileLoader.setRequestHeader(loader.requestHeader);
|
|
467
|
-
fileLoader.setWithCredentials(loader.withCredentials);
|
|
468
|
-
try {
|
|
469
|
-
const text = await fileLoader.loadAsync(subobjectURL);
|
|
470
|
-
return text;
|
|
471
|
-
} catch (e) {
|
|
472
|
-
continue;
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
throw new Error('LDrawLoader: Subobject "' + fileName + '" could not be loaded.');
|
|
476
|
-
}
|
|
477
|
-
parse(text, fileName = null) {
|
|
478
|
-
const loader = this.loader;
|
|
479
|
-
const faces = [];
|
|
480
|
-
const lineSegments = [];
|
|
481
|
-
const conditionalSegments = [];
|
|
482
|
-
const subobjects = [];
|
|
483
|
-
const materials = {};
|
|
484
|
-
const getLocalMaterial = (colorCode) => {
|
|
485
|
-
return materials[colorCode] || null;
|
|
486
|
-
};
|
|
487
|
-
let type = "Model";
|
|
488
|
-
let category = null;
|
|
489
|
-
let keywords = null;
|
|
490
|
-
let totalFaces = 0;
|
|
491
|
-
if (text.indexOf("\r\n") !== -1) {
|
|
492
|
-
text = text.replace(/\r\n/g, "\n");
|
|
493
|
-
}
|
|
494
|
-
const lines = text.split("\n");
|
|
495
|
-
const numLines = lines.length;
|
|
496
|
-
let parsingEmbeddedFiles = false;
|
|
497
|
-
let currentEmbeddedFileName = null;
|
|
498
|
-
let currentEmbeddedText = null;
|
|
499
|
-
let bfcCertified = false;
|
|
500
|
-
let bfcCCW = true;
|
|
501
|
-
let bfcInverted = false;
|
|
502
|
-
let bfcCull = true;
|
|
503
|
-
let startingConstructionStep = false;
|
|
504
|
-
for (let lineIndex = 0; lineIndex < numLines; lineIndex++) {
|
|
505
|
-
const line = lines[lineIndex];
|
|
506
|
-
if (line.length === 0)
|
|
507
|
-
continue;
|
|
508
|
-
if (parsingEmbeddedFiles) {
|
|
509
|
-
if (line.startsWith("0 FILE ")) {
|
|
510
|
-
this.setData(currentEmbeddedFileName, currentEmbeddedText);
|
|
511
|
-
currentEmbeddedFileName = line.substring(7);
|
|
512
|
-
currentEmbeddedText = "";
|
|
513
|
-
} else {
|
|
514
|
-
currentEmbeddedText += line + "\n";
|
|
515
|
-
}
|
|
516
|
-
continue;
|
|
517
|
-
}
|
|
518
|
-
const lp = new LineParser(line, lineIndex + 1);
|
|
519
|
-
lp.seekNonSpace();
|
|
520
|
-
if (lp.isAtTheEnd()) {
|
|
521
|
-
continue;
|
|
522
|
-
}
|
|
523
|
-
const lineType = lp.getToken();
|
|
524
|
-
let material;
|
|
525
|
-
let colorCode;
|
|
526
|
-
let segment;
|
|
527
|
-
let ccw;
|
|
528
|
-
let doubleSided;
|
|
529
|
-
let v0, v1, v2, v3, c0, c1;
|
|
530
|
-
switch (lineType) {
|
|
531
|
-
case "0":
|
|
532
|
-
const meta = lp.getToken();
|
|
533
|
-
if (meta) {
|
|
534
|
-
switch (meta) {
|
|
535
|
-
case "!LDRAW_ORG":
|
|
536
|
-
type = lp.getToken();
|
|
537
|
-
break;
|
|
538
|
-
case "!COLOUR":
|
|
539
|
-
material = loader.parseColorMetaDirective(lp);
|
|
540
|
-
if (material) {
|
|
541
|
-
materials[material.userData.code] = material;
|
|
542
|
-
} else {
|
|
543
|
-
console.warn("LDrawLoader: Error parsing material" + lp.getLineNumberString());
|
|
544
|
-
}
|
|
545
|
-
break;
|
|
546
|
-
case "!CATEGORY":
|
|
547
|
-
category = lp.getToken();
|
|
548
|
-
break;
|
|
549
|
-
case "!KEYWORDS":
|
|
550
|
-
const newKeywords = lp.getRemainingString().split(",");
|
|
551
|
-
if (newKeywords.length > 0) {
|
|
552
|
-
if (!keywords) {
|
|
553
|
-
keywords = [];
|
|
554
|
-
}
|
|
555
|
-
newKeywords.forEach(function(keyword) {
|
|
556
|
-
keywords.push(keyword.trim());
|
|
557
|
-
});
|
|
558
|
-
}
|
|
559
|
-
break;
|
|
560
|
-
case "FILE":
|
|
561
|
-
if (lineIndex > 0) {
|
|
562
|
-
parsingEmbeddedFiles = true;
|
|
563
|
-
currentEmbeddedFileName = lp.getRemainingString();
|
|
564
|
-
currentEmbeddedText = "";
|
|
565
|
-
bfcCertified = false;
|
|
566
|
-
bfcCCW = true;
|
|
567
|
-
}
|
|
568
|
-
break;
|
|
569
|
-
case "BFC":
|
|
570
|
-
while (!lp.isAtTheEnd()) {
|
|
571
|
-
const token = lp.getToken();
|
|
572
|
-
switch (token) {
|
|
573
|
-
case "CERTIFY":
|
|
574
|
-
case "NOCERTIFY":
|
|
575
|
-
bfcCertified = token === "CERTIFY";
|
|
576
|
-
bfcCCW = true;
|
|
577
|
-
break;
|
|
578
|
-
case "CW":
|
|
579
|
-
case "CCW":
|
|
580
|
-
bfcCCW = token === "CCW";
|
|
581
|
-
break;
|
|
582
|
-
case "INVERTNEXT":
|
|
583
|
-
bfcInverted = true;
|
|
584
|
-
break;
|
|
585
|
-
case "CLIP":
|
|
586
|
-
case "NOCLIP":
|
|
587
|
-
bfcCull = token === "CLIP";
|
|
588
|
-
break;
|
|
589
|
-
default:
|
|
590
|
-
console.warn('THREE.LDrawLoader: BFC directive "' + token + '" is unknown.');
|
|
591
|
-
break;
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
break;
|
|
595
|
-
case "STEP":
|
|
596
|
-
startingConstructionStep = true;
|
|
597
|
-
break;
|
|
598
|
-
default:
|
|
599
|
-
break;
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
break;
|
|
603
|
-
case "1":
|
|
604
|
-
colorCode = lp.getToken();
|
|
605
|
-
material = getLocalMaterial(colorCode);
|
|
606
|
-
const posX = parseFloat(lp.getToken());
|
|
607
|
-
const posY = parseFloat(lp.getToken());
|
|
608
|
-
const posZ = parseFloat(lp.getToken());
|
|
609
|
-
const m0 = parseFloat(lp.getToken());
|
|
610
|
-
const m1 = parseFloat(lp.getToken());
|
|
611
|
-
const m2 = parseFloat(lp.getToken());
|
|
612
|
-
const m3 = parseFloat(lp.getToken());
|
|
613
|
-
const m4 = parseFloat(lp.getToken());
|
|
614
|
-
const m5 = parseFloat(lp.getToken());
|
|
615
|
-
const m6 = parseFloat(lp.getToken());
|
|
616
|
-
const m7 = parseFloat(lp.getToken());
|
|
617
|
-
const m8 = parseFloat(lp.getToken());
|
|
618
|
-
const matrix = new THREE.Matrix4().set(m0, m1, m2, posX, m3, m4, m5, posY, m6, m7, m8, posZ, 0, 0, 0, 1);
|
|
619
|
-
let fileName2 = lp.getRemainingString().trim().replace(/\\/g, "/");
|
|
620
|
-
if (loader.fileMap[fileName2]) {
|
|
621
|
-
fileName2 = loader.fileMap[fileName2];
|
|
622
|
-
} else {
|
|
623
|
-
if (fileName2.startsWith("s/")) {
|
|
624
|
-
fileName2 = "parts/" + fileName2;
|
|
625
|
-
} else if (fileName2.startsWith("48/")) {
|
|
626
|
-
fileName2 = "p/" + fileName2;
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
subobjects.push({
|
|
630
|
-
material,
|
|
631
|
-
colorCode,
|
|
632
|
-
matrix,
|
|
633
|
-
fileName: fileName2,
|
|
634
|
-
inverted: bfcInverted,
|
|
635
|
-
startingConstructionStep
|
|
636
|
-
});
|
|
637
|
-
bfcInverted = false;
|
|
638
|
-
break;
|
|
639
|
-
case "2":
|
|
640
|
-
colorCode = lp.getToken();
|
|
641
|
-
material = getLocalMaterial(colorCode);
|
|
642
|
-
v0 = lp.getVector();
|
|
643
|
-
v1 = lp.getVector();
|
|
644
|
-
segment = {
|
|
645
|
-
material,
|
|
646
|
-
colorCode,
|
|
647
|
-
vertices: [v0, v1]
|
|
648
|
-
};
|
|
649
|
-
lineSegments.push(segment);
|
|
650
|
-
break;
|
|
651
|
-
case "5":
|
|
652
|
-
colorCode = lp.getToken();
|
|
653
|
-
material = getLocalMaterial(colorCode);
|
|
654
|
-
v0 = lp.getVector();
|
|
655
|
-
v1 = lp.getVector();
|
|
656
|
-
c0 = lp.getVector();
|
|
657
|
-
c1 = lp.getVector();
|
|
658
|
-
segment = {
|
|
659
|
-
material,
|
|
660
|
-
colorCode,
|
|
661
|
-
vertices: [v0, v1],
|
|
662
|
-
controlPoints: [c0, c1]
|
|
663
|
-
};
|
|
664
|
-
conditionalSegments.push(segment);
|
|
665
|
-
break;
|
|
666
|
-
case "3":
|
|
667
|
-
colorCode = lp.getToken();
|
|
668
|
-
material = getLocalMaterial(colorCode);
|
|
669
|
-
ccw = bfcCCW;
|
|
670
|
-
doubleSided = !bfcCertified || !bfcCull;
|
|
671
|
-
if (ccw === true) {
|
|
672
|
-
v0 = lp.getVector();
|
|
673
|
-
v1 = lp.getVector();
|
|
674
|
-
v2 = lp.getVector();
|
|
675
|
-
} else {
|
|
676
|
-
v2 = lp.getVector();
|
|
677
|
-
v1 = lp.getVector();
|
|
678
|
-
v0 = lp.getVector();
|
|
679
|
-
}
|
|
680
|
-
faces.push({
|
|
681
|
-
material,
|
|
682
|
-
colorCode,
|
|
683
|
-
faceNormal: null,
|
|
684
|
-
vertices: [v0, v1, v2],
|
|
685
|
-
normals: [null, null, null]
|
|
686
|
-
});
|
|
687
|
-
totalFaces++;
|
|
688
|
-
if (doubleSided === true) {
|
|
689
|
-
faces.push({
|
|
690
|
-
material,
|
|
691
|
-
colorCode,
|
|
692
|
-
faceNormal: null,
|
|
693
|
-
vertices: [v2, v1, v0],
|
|
694
|
-
normals: [null, null, null]
|
|
695
|
-
});
|
|
696
|
-
totalFaces++;
|
|
697
|
-
}
|
|
698
|
-
break;
|
|
699
|
-
case "4":
|
|
700
|
-
colorCode = lp.getToken();
|
|
701
|
-
material = getLocalMaterial(colorCode);
|
|
702
|
-
ccw = bfcCCW;
|
|
703
|
-
doubleSided = !bfcCertified || !bfcCull;
|
|
704
|
-
if (ccw === true) {
|
|
705
|
-
v0 = lp.getVector();
|
|
706
|
-
v1 = lp.getVector();
|
|
707
|
-
v2 = lp.getVector();
|
|
708
|
-
v3 = lp.getVector();
|
|
709
|
-
} else {
|
|
710
|
-
v3 = lp.getVector();
|
|
711
|
-
v2 = lp.getVector();
|
|
712
|
-
v1 = lp.getVector();
|
|
713
|
-
v0 = lp.getVector();
|
|
714
|
-
}
|
|
715
|
-
faces.push({
|
|
716
|
-
material,
|
|
717
|
-
colorCode,
|
|
718
|
-
faceNormal: null,
|
|
719
|
-
vertices: [v0, v1, v2, v3],
|
|
720
|
-
normals: [null, null, null, null]
|
|
721
|
-
});
|
|
722
|
-
totalFaces += 2;
|
|
723
|
-
if (doubleSided === true) {
|
|
724
|
-
faces.push({
|
|
725
|
-
material,
|
|
726
|
-
colorCode,
|
|
727
|
-
faceNormal: null,
|
|
728
|
-
vertices: [v3, v2, v1, v0],
|
|
729
|
-
normals: [null, null, null, null]
|
|
730
|
-
});
|
|
731
|
-
totalFaces += 2;
|
|
732
|
-
}
|
|
733
|
-
break;
|
|
734
|
-
default:
|
|
735
|
-
throw new Error('LDrawLoader: Unknown line type "' + lineType + '"' + lp.getLineNumberString() + ".");
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
if (parsingEmbeddedFiles) {
|
|
739
|
-
this.setData(currentEmbeddedFileName, currentEmbeddedText);
|
|
740
|
-
}
|
|
741
|
-
return {
|
|
742
|
-
faces,
|
|
743
|
-
conditionalSegments,
|
|
744
|
-
lineSegments,
|
|
745
|
-
type,
|
|
746
|
-
category,
|
|
747
|
-
keywords,
|
|
748
|
-
subobjects,
|
|
749
|
-
totalFaces,
|
|
750
|
-
startingConstructionStep,
|
|
751
|
-
materials,
|
|
752
|
-
fileName,
|
|
753
|
-
group: null
|
|
754
|
-
};
|
|
755
|
-
}
|
|
756
|
-
// returns an (optionally cloned) instance of the data
|
|
757
|
-
getData(fileName, clone = true) {
|
|
758
|
-
const key = fileName.toLowerCase();
|
|
759
|
-
const result = this._cache[key];
|
|
760
|
-
if (result === null || result instanceof Promise) {
|
|
761
|
-
return null;
|
|
762
|
-
}
|
|
763
|
-
if (clone) {
|
|
764
|
-
return this.cloneResult(result);
|
|
765
|
-
} else {
|
|
766
|
-
return result;
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
// kicks off a fetch and parse of the requested data if it hasn't already been loaded. Returns when
|
|
770
|
-
// the data is ready to use and can be retrieved synchronously with "getData".
|
|
771
|
-
async ensureDataLoaded(fileName) {
|
|
772
|
-
const key = fileName.toLowerCase();
|
|
773
|
-
if (!(key in this._cache)) {
|
|
774
|
-
this._cache[key] = this.fetchData(fileName).then((text) => {
|
|
775
|
-
const info = this.parse(text, fileName);
|
|
776
|
-
this._cache[key] = info;
|
|
777
|
-
return info;
|
|
778
|
-
});
|
|
779
|
-
}
|
|
780
|
-
await this._cache[key];
|
|
781
|
-
}
|
|
782
|
-
// sets the data in the cache from parsed data
|
|
783
|
-
setData(fileName, text) {
|
|
784
|
-
const key = fileName.toLowerCase();
|
|
785
|
-
this._cache[key] = this.parse(text, fileName);
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
function getMaterialFromCode(colorCode, parentColorCode, materialHierarchy, forEdge) {
|
|
789
|
-
const isPassthrough = !forEdge && colorCode === MAIN_COLOUR_CODE || forEdge && colorCode === MAIN_EDGE_COLOUR_CODE;
|
|
790
|
-
if (isPassthrough) {
|
|
791
|
-
colorCode = parentColorCode;
|
|
792
|
-
}
|
|
793
|
-
return materialHierarchy[colorCode] || null;
|
|
794
|
-
}
|
|
795
|
-
class LDrawPartsGeometryCache {
|
|
796
|
-
constructor(loader) {
|
|
797
|
-
this.loader = loader;
|
|
798
|
-
this.parseCache = new LDrawParsedCache(loader);
|
|
799
|
-
this._cache = {};
|
|
800
|
-
}
|
|
801
|
-
// Convert the given file information into a mesh by processing subobjects.
|
|
802
|
-
async processIntoMesh(info) {
|
|
803
|
-
const loader = this.loader;
|
|
804
|
-
const parseCache = this.parseCache;
|
|
805
|
-
const faceMaterials = /* @__PURE__ */ new Set();
|
|
806
|
-
const processInfoSubobjects = async (info2, subobject = null) => {
|
|
807
|
-
const subobjects = info2.subobjects;
|
|
808
|
-
const promises = [];
|
|
809
|
-
for (let i = 0, l = subobjects.length; i < l; i++) {
|
|
810
|
-
const subobject2 = subobjects[i];
|
|
811
|
-
const promise = parseCache.ensureDataLoaded(subobject2.fileName).then(() => {
|
|
812
|
-
const subobjectInfo = parseCache.getData(subobject2.fileName, false);
|
|
813
|
-
if (!isPrimitiveType(subobjectInfo.type)) {
|
|
814
|
-
return this.loadModel(subobject2.fileName).catch((error) => {
|
|
815
|
-
console.warn(error);
|
|
816
|
-
return null;
|
|
817
|
-
});
|
|
818
|
-
}
|
|
819
|
-
return processInfoSubobjects(parseCache.getData(subobject2.fileName), subobject2);
|
|
820
|
-
});
|
|
821
|
-
promises.push(promise);
|
|
822
|
-
}
|
|
823
|
-
const group2 = new THREE.Group();
|
|
824
|
-
group2.userData.category = info2.category;
|
|
825
|
-
group2.userData.keywords = info2.keywords;
|
|
826
|
-
info2.group = group2;
|
|
827
|
-
const subobjectInfos = await Promise.all(promises);
|
|
828
|
-
for (let i = 0, l = subobjectInfos.length; i < l; i++) {
|
|
829
|
-
const subobject2 = info2.subobjects[i];
|
|
830
|
-
const subobjectInfo = subobjectInfos[i];
|
|
831
|
-
if (subobjectInfo === null) {
|
|
832
|
-
continue;
|
|
833
|
-
}
|
|
834
|
-
if (subobjectInfo.isGroup) {
|
|
835
|
-
const subobjectGroup = subobjectInfo;
|
|
836
|
-
subobject2.matrix.decompose(subobjectGroup.position, subobjectGroup.quaternion, subobjectGroup.scale);
|
|
837
|
-
subobjectGroup.userData.startingConstructionStep = subobject2.startingConstructionStep;
|
|
838
|
-
subobjectGroup.name = subobject2.fileName;
|
|
839
|
-
loader.applyMaterialsToMesh(subobjectGroup, subobject2.colorCode, info2.materials);
|
|
840
|
-
group2.add(subobjectGroup);
|
|
841
|
-
continue;
|
|
842
|
-
}
|
|
843
|
-
if (subobjectInfo.group.children.length) {
|
|
844
|
-
group2.add(subobjectInfo.group);
|
|
845
|
-
}
|
|
846
|
-
const parentLineSegments = info2.lineSegments;
|
|
847
|
-
const parentConditionalSegments = info2.conditionalSegments;
|
|
848
|
-
const parentFaces = info2.faces;
|
|
849
|
-
const lineSegments = subobjectInfo.lineSegments;
|
|
850
|
-
const conditionalSegments = subobjectInfo.conditionalSegments;
|
|
851
|
-
const faces = subobjectInfo.faces;
|
|
852
|
-
const matrix = subobject2.matrix;
|
|
853
|
-
const inverted = subobject2.inverted;
|
|
854
|
-
const matrixScaleInverted = matrix.determinant() < 0;
|
|
855
|
-
const colorCode = subobject2.colorCode;
|
|
856
|
-
const lineColorCode = colorCode === MAIN_COLOUR_CODE ? MAIN_EDGE_COLOUR_CODE : colorCode;
|
|
857
|
-
for (let i2 = 0, l2 = lineSegments.length; i2 < l2; i2++) {
|
|
858
|
-
const ls = lineSegments[i2];
|
|
859
|
-
const vertices = ls.vertices;
|
|
860
|
-
vertices[0].applyMatrix4(matrix);
|
|
861
|
-
vertices[1].applyMatrix4(matrix);
|
|
862
|
-
ls.colorCode = ls.colorCode === MAIN_EDGE_COLOUR_CODE ? lineColorCode : ls.colorCode;
|
|
863
|
-
ls.material = ls.material || getMaterialFromCode(ls.colorCode, ls.colorCode, info2.materials, true);
|
|
864
|
-
parentLineSegments.push(ls);
|
|
865
|
-
}
|
|
866
|
-
for (let i2 = 0, l2 = conditionalSegments.length; i2 < l2; i2++) {
|
|
867
|
-
const os = conditionalSegments[i2];
|
|
868
|
-
const vertices = os.vertices;
|
|
869
|
-
const controlPoints = os.controlPoints;
|
|
870
|
-
vertices[0].applyMatrix4(matrix);
|
|
871
|
-
vertices[1].applyMatrix4(matrix);
|
|
872
|
-
controlPoints[0].applyMatrix4(matrix);
|
|
873
|
-
controlPoints[1].applyMatrix4(matrix);
|
|
874
|
-
os.colorCode = os.colorCode === MAIN_EDGE_COLOUR_CODE ? lineColorCode : os.colorCode;
|
|
875
|
-
os.material = os.material || getMaterialFromCode(os.colorCode, os.colorCode, info2.materials, true);
|
|
876
|
-
parentConditionalSegments.push(os);
|
|
877
|
-
}
|
|
878
|
-
for (let i2 = 0, l2 = faces.length; i2 < l2; i2++) {
|
|
879
|
-
const tri = faces[i2];
|
|
880
|
-
const vertices = tri.vertices;
|
|
881
|
-
for (let i3 = 0, l3 = vertices.length; i3 < l3; i3++) {
|
|
882
|
-
vertices[i3].applyMatrix4(matrix);
|
|
883
|
-
}
|
|
884
|
-
tri.colorCode = tri.colorCode === MAIN_COLOUR_CODE ? colorCode : tri.colorCode;
|
|
885
|
-
tri.material = tri.material || getMaterialFromCode(tri.colorCode, colorCode, info2.materials, false);
|
|
886
|
-
faceMaterials.add(tri.colorCode);
|
|
887
|
-
if (matrixScaleInverted !== inverted) {
|
|
888
|
-
vertices.reverse();
|
|
889
|
-
}
|
|
890
|
-
parentFaces.push(tri);
|
|
891
|
-
}
|
|
892
|
-
info2.totalFaces += subobjectInfo.totalFaces;
|
|
893
|
-
}
|
|
894
|
-
if (subobject) {
|
|
895
|
-
loader.applyMaterialsToMesh(group2, subobject.colorCode, info2.materials);
|
|
896
|
-
}
|
|
897
|
-
return info2;
|
|
898
|
-
};
|
|
899
|
-
for (let i = 0, l = info.faces; i < l; i++) {
|
|
900
|
-
faceMaterials.add(info.faces[i].colorCode);
|
|
901
|
-
}
|
|
902
|
-
await processInfoSubobjects(info);
|
|
903
|
-
if (loader.smoothNormals) {
|
|
904
|
-
const checkSubSegments = faceMaterials.size > 1;
|
|
905
|
-
generateFaceNormals(info.faces);
|
|
906
|
-
smoothNormals(info.faces, info.lineSegments, checkSubSegments);
|
|
907
|
-
}
|
|
908
|
-
const group = info.group;
|
|
909
|
-
if (info.faces.length > 0) {
|
|
910
|
-
group.add(createObject(info.faces, 3, false, info.totalFaces));
|
|
911
|
-
}
|
|
912
|
-
if (info.lineSegments.length > 0) {
|
|
913
|
-
group.add(createObject(info.lineSegments, 2));
|
|
914
|
-
}
|
|
915
|
-
if (info.conditionalSegments.length > 0) {
|
|
916
|
-
group.add(createObject(info.conditionalSegments, 2, true));
|
|
917
|
-
}
|
|
918
|
-
return group;
|
|
919
|
-
}
|
|
920
|
-
hasCachedModel(fileName) {
|
|
921
|
-
return fileName !== null && fileName.toLowerCase() in this._cache;
|
|
922
|
-
}
|
|
923
|
-
async getCachedModel(fileName) {
|
|
924
|
-
if (fileName !== null && this.hasCachedModel(fileName)) {
|
|
925
|
-
const key = fileName.toLowerCase();
|
|
926
|
-
const group = await this._cache[key];
|
|
927
|
-
return group.clone();
|
|
928
|
-
} else {
|
|
929
|
-
return null;
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
// Loads and parses the model with the given file name. Returns a cached copy if available.
|
|
933
|
-
async loadModel(fileName) {
|
|
934
|
-
const parseCache = this.parseCache;
|
|
935
|
-
const key = fileName.toLowerCase();
|
|
936
|
-
if (this.hasCachedModel(fileName)) {
|
|
937
|
-
return this.getCachedModel(fileName);
|
|
938
|
-
} else {
|
|
939
|
-
await parseCache.ensureDataLoaded(fileName);
|
|
940
|
-
const info = parseCache.getData(fileName);
|
|
941
|
-
const promise = this.processIntoMesh(info);
|
|
942
|
-
if (this.hasCachedModel(fileName)) {
|
|
943
|
-
return this.getCachedModel(fileName);
|
|
944
|
-
}
|
|
945
|
-
if (isPartType(info.type)) {
|
|
946
|
-
this._cache[key] = promise;
|
|
947
|
-
}
|
|
948
|
-
const group = await promise;
|
|
949
|
-
return group.clone();
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
// parses the given model text into a renderable object. Returns cached copy if available.
|
|
953
|
-
async parseModel(text) {
|
|
954
|
-
const parseCache = this.parseCache;
|
|
955
|
-
const info = parseCache.parse(text);
|
|
956
|
-
if (isPartType(info.type) && this.hasCachedModel(info.fileName)) {
|
|
957
|
-
return this.getCachedModel(info.fileName);
|
|
958
|
-
}
|
|
959
|
-
return this.processIntoMesh(info);
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
function sortByMaterial(a, b) {
|
|
963
|
-
if (a.colorCode === b.colorCode) {
|
|
964
|
-
return 0;
|
|
965
|
-
}
|
|
966
|
-
if (a.colorCode < b.colorCode) {
|
|
967
|
-
return -1;
|
|
968
|
-
}
|
|
969
|
-
return 1;
|
|
970
|
-
}
|
|
971
|
-
function createObject(elements, elementSize, isConditionalSegments = false, totalElements = null) {
|
|
972
|
-
elements.sort(sortByMaterial);
|
|
973
|
-
if (totalElements === null) {
|
|
974
|
-
totalElements = elements.length;
|
|
975
|
-
}
|
|
976
|
-
const positions = new Float32Array(elementSize * totalElements * 3);
|
|
977
|
-
const normals = elementSize === 3 ? new Float32Array(elementSize * totalElements * 3) : null;
|
|
978
|
-
const materials = [];
|
|
979
|
-
const quadArray = new Array(6);
|
|
980
|
-
const bufferGeometry = new THREE.BufferGeometry();
|
|
981
|
-
let prevMaterial = null;
|
|
982
|
-
let index0 = 0;
|
|
983
|
-
let numGroupVerts = 0;
|
|
984
|
-
let offset = 0;
|
|
985
|
-
for (let iElem = 0, nElem = elements.length; iElem < nElem; iElem++) {
|
|
986
|
-
const elem = elements[iElem];
|
|
987
|
-
let vertices = elem.vertices;
|
|
988
|
-
if (vertices.length === 4) {
|
|
989
|
-
quadArray[0] = vertices[0];
|
|
990
|
-
quadArray[1] = vertices[1];
|
|
991
|
-
quadArray[2] = vertices[2];
|
|
992
|
-
quadArray[3] = vertices[0];
|
|
993
|
-
quadArray[4] = vertices[2];
|
|
994
|
-
quadArray[5] = vertices[3];
|
|
995
|
-
vertices = quadArray;
|
|
996
|
-
}
|
|
997
|
-
for (let j = 0, l = vertices.length; j < l; j++) {
|
|
998
|
-
const v = vertices[j];
|
|
999
|
-
const index = offset + j * 3;
|
|
1000
|
-
positions[index + 0] = v.x;
|
|
1001
|
-
positions[index + 1] = v.y;
|
|
1002
|
-
positions[index + 2] = v.z;
|
|
1003
|
-
}
|
|
1004
|
-
if (elementSize === 3) {
|
|
1005
|
-
if (!elem.faceNormal) {
|
|
1006
|
-
const v0 = vertices[0];
|
|
1007
|
-
const v1 = vertices[1];
|
|
1008
|
-
const v2 = vertices[2];
|
|
1009
|
-
_tempVec0.subVectors(v1, v0);
|
|
1010
|
-
_tempVec1.subVectors(v2, v1);
|
|
1011
|
-
elem.faceNormal = new THREE.Vector3().crossVectors(_tempVec0, _tempVec1).normalize();
|
|
1012
|
-
}
|
|
1013
|
-
let elemNormals = elem.normals;
|
|
1014
|
-
if (elemNormals.length === 4) {
|
|
1015
|
-
quadArray[0] = elemNormals[0];
|
|
1016
|
-
quadArray[1] = elemNormals[1];
|
|
1017
|
-
quadArray[2] = elemNormals[2];
|
|
1018
|
-
quadArray[3] = elemNormals[0];
|
|
1019
|
-
quadArray[4] = elemNormals[2];
|
|
1020
|
-
quadArray[5] = elemNormals[3];
|
|
1021
|
-
elemNormals = quadArray;
|
|
1022
|
-
}
|
|
1023
|
-
for (let j = 0, l = elemNormals.length; j < l; j++) {
|
|
1024
|
-
let n = elem.faceNormal;
|
|
1025
|
-
if (elemNormals[j]) {
|
|
1026
|
-
n = elemNormals[j].norm;
|
|
1027
|
-
}
|
|
1028
|
-
const index = offset + j * 3;
|
|
1029
|
-
normals[index + 0] = n.x;
|
|
1030
|
-
normals[index + 1] = n.y;
|
|
1031
|
-
normals[index + 2] = n.z;
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
if (prevMaterial !== elem.colorCode) {
|
|
1035
|
-
if (prevMaterial !== null) {
|
|
1036
|
-
bufferGeometry.addGroup(index0, numGroupVerts, materials.length - 1);
|
|
1037
|
-
}
|
|
1038
|
-
const material = elem.material;
|
|
1039
|
-
if (material !== null) {
|
|
1040
|
-
if (elementSize === 3) {
|
|
1041
|
-
materials.push(material);
|
|
1042
|
-
} else if (elementSize === 2) {
|
|
1043
|
-
if (material !== null) {
|
|
1044
|
-
if (isConditionalSegments) {
|
|
1045
|
-
materials.push(material.userData.edgeMaterial.userData.conditionalEdgeMaterial);
|
|
1046
|
-
} else {
|
|
1047
|
-
materials.push(material.userData.edgeMaterial);
|
|
1048
|
-
}
|
|
1049
|
-
} else {
|
|
1050
|
-
materials.push(null);
|
|
1051
|
-
}
|
|
1052
|
-
}
|
|
1053
|
-
} else {
|
|
1054
|
-
materials.push(elem.colorCode);
|
|
1055
|
-
}
|
|
1056
|
-
prevMaterial = elem.colorCode;
|
|
1057
|
-
index0 = offset / 3;
|
|
1058
|
-
numGroupVerts = vertices.length;
|
|
1059
|
-
} else {
|
|
1060
|
-
numGroupVerts += vertices.length;
|
|
1061
|
-
}
|
|
1062
|
-
offset += 3 * vertices.length;
|
|
1063
|
-
}
|
|
1064
|
-
if (numGroupVerts > 0) {
|
|
1065
|
-
bufferGeometry.addGroup(index0, Infinity, materials.length - 1);
|
|
1066
|
-
}
|
|
1067
|
-
bufferGeometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
|
|
1068
|
-
if (normals !== null) {
|
|
1069
|
-
bufferGeometry.setAttribute("normal", new THREE.BufferAttribute(normals, 3));
|
|
1070
|
-
}
|
|
1071
|
-
let object3d = null;
|
|
1072
|
-
if (elementSize === 2) {
|
|
1073
|
-
if (isConditionalSegments) {
|
|
1074
|
-
object3d = new ConditionalLineSegments(bufferGeometry, materials.length === 1 ? materials[0] : materials);
|
|
1075
|
-
} else {
|
|
1076
|
-
object3d = new THREE.LineSegments(bufferGeometry, materials.length === 1 ? materials[0] : materials);
|
|
1077
|
-
}
|
|
1078
|
-
} else if (elementSize === 3) {
|
|
1079
|
-
object3d = new THREE.Mesh(bufferGeometry, materials.length === 1 ? materials[0] : materials);
|
|
1080
|
-
}
|
|
1081
|
-
if (isConditionalSegments) {
|
|
1082
|
-
object3d.isConditionalLine = true;
|
|
1083
|
-
const controlArray0 = new Float32Array(elements.length * 3 * 2);
|
|
1084
|
-
const controlArray1 = new Float32Array(elements.length * 3 * 2);
|
|
1085
|
-
const directionArray = new Float32Array(elements.length * 3 * 2);
|
|
1086
|
-
for (let i = 0, l = elements.length; i < l; i++) {
|
|
1087
|
-
const os = elements[i];
|
|
1088
|
-
const vertices = os.vertices;
|
|
1089
|
-
const controlPoints = os.controlPoints;
|
|
1090
|
-
const c0 = controlPoints[0];
|
|
1091
|
-
const c1 = controlPoints[1];
|
|
1092
|
-
const v0 = vertices[0];
|
|
1093
|
-
const v1 = vertices[1];
|
|
1094
|
-
const index = i * 3 * 2;
|
|
1095
|
-
controlArray0[index + 0] = c0.x;
|
|
1096
|
-
controlArray0[index + 1] = c0.y;
|
|
1097
|
-
controlArray0[index + 2] = c0.z;
|
|
1098
|
-
controlArray0[index + 3] = c0.x;
|
|
1099
|
-
controlArray0[index + 4] = c0.y;
|
|
1100
|
-
controlArray0[index + 5] = c0.z;
|
|
1101
|
-
controlArray1[index + 0] = c1.x;
|
|
1102
|
-
controlArray1[index + 1] = c1.y;
|
|
1103
|
-
controlArray1[index + 2] = c1.z;
|
|
1104
|
-
controlArray1[index + 3] = c1.x;
|
|
1105
|
-
controlArray1[index + 4] = c1.y;
|
|
1106
|
-
controlArray1[index + 5] = c1.z;
|
|
1107
|
-
directionArray[index + 0] = v1.x - v0.x;
|
|
1108
|
-
directionArray[index + 1] = v1.y - v0.y;
|
|
1109
|
-
directionArray[index + 2] = v1.z - v0.z;
|
|
1110
|
-
directionArray[index + 3] = v1.x - v0.x;
|
|
1111
|
-
directionArray[index + 4] = v1.y - v0.y;
|
|
1112
|
-
directionArray[index + 5] = v1.z - v0.z;
|
|
1113
|
-
}
|
|
1114
|
-
bufferGeometry.setAttribute("control0", new THREE.BufferAttribute(controlArray0, 3, false));
|
|
1115
|
-
bufferGeometry.setAttribute("control1", new THREE.BufferAttribute(controlArray1, 3, false));
|
|
1116
|
-
bufferGeometry.setAttribute("direction", new THREE.BufferAttribute(directionArray, 3, false));
|
|
1117
|
-
}
|
|
1118
|
-
return object3d;
|
|
1119
|
-
}
|
|
1120
|
-
class LDrawLoader extends THREE.Loader {
|
|
1121
|
-
constructor(manager) {
|
|
1122
|
-
super(manager);
|
|
1123
|
-
this.materials = [];
|
|
1124
|
-
this.materialLibrary = {};
|
|
1125
|
-
this.partsCache = new LDrawPartsGeometryCache(this);
|
|
1126
|
-
this.fileMap = {};
|
|
1127
|
-
this.setMaterials([]);
|
|
1128
|
-
this.smoothNormals = true;
|
|
1129
|
-
this.partsLibraryPath = "";
|
|
1130
|
-
}
|
|
1131
|
-
setPartsLibraryPath(path) {
|
|
1132
|
-
this.partsLibraryPath = path;
|
|
1133
|
-
return this;
|
|
1134
|
-
}
|
|
1135
|
-
async preloadMaterials(url) {
|
|
1136
|
-
const fileLoader = new THREE.FileLoader(this.manager);
|
|
1137
|
-
fileLoader.setPath(this.path);
|
|
1138
|
-
fileLoader.setRequestHeader(this.requestHeader);
|
|
1139
|
-
fileLoader.setWithCredentials(this.withCredentials);
|
|
1140
|
-
const text = await fileLoader.loadAsync(url);
|
|
1141
|
-
const colorLineRegex = /^0 !COLOUR/;
|
|
1142
|
-
const lines = text.split(/[\n\r]/g);
|
|
1143
|
-
const materials = [];
|
|
1144
|
-
for (let i = 0, l = lines.length; i < l; i++) {
|
|
1145
|
-
const line = lines[i];
|
|
1146
|
-
if (colorLineRegex.test(line)) {
|
|
1147
|
-
const directive = line.replace(colorLineRegex, "");
|
|
1148
|
-
const material = this.parseColorMetaDirective(new LineParser(directive));
|
|
1149
|
-
materials.push(material);
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
this.setMaterials(materials);
|
|
1153
|
-
}
|
|
1154
|
-
load(url, onLoad, onProgress, onError) {
|
|
1155
|
-
const fileLoader = new THREE.FileLoader(this.manager);
|
|
1156
|
-
fileLoader.setPath(this.path);
|
|
1157
|
-
fileLoader.setRequestHeader(this.requestHeader);
|
|
1158
|
-
fileLoader.setWithCredentials(this.withCredentials);
|
|
1159
|
-
fileLoader.load(
|
|
1160
|
-
url,
|
|
1161
|
-
(text) => {
|
|
1162
|
-
this.partsCache.parseModel(text, this.materialLibrary).then((group) => {
|
|
1163
|
-
this.applyMaterialsToMesh(group, MAIN_COLOUR_CODE, this.materialLibrary, true);
|
|
1164
|
-
this.computeConstructionSteps(group);
|
|
1165
|
-
onLoad(group);
|
|
1166
|
-
}).catch(onError);
|
|
1167
|
-
},
|
|
1168
|
-
onProgress,
|
|
1169
|
-
onError
|
|
1170
|
-
);
|
|
1171
|
-
}
|
|
1172
|
-
parse(text, onLoad) {
|
|
1173
|
-
this.partsCache.parseModel(text, this.materialLibrary).then((group) => {
|
|
1174
|
-
this.computeConstructionSteps(group);
|
|
1175
|
-
onLoad(group);
|
|
1176
|
-
});
|
|
1177
|
-
}
|
|
1178
|
-
setMaterials(materials) {
|
|
1179
|
-
this.materialLibrary = {};
|
|
1180
|
-
this.materials = [];
|
|
1181
|
-
for (let i = 0, l = materials.length; i < l; i++) {
|
|
1182
|
-
this.addMaterial(materials[i]);
|
|
1183
|
-
}
|
|
1184
|
-
this.addMaterial(this.parseColorMetaDirective(new LineParser("Main_Colour CODE 16 VALUE #FF8080 EDGE #333333")));
|
|
1185
|
-
this.addMaterial(this.parseColorMetaDirective(new LineParser("Edge_Colour CODE 24 VALUE #A0A0A0 EDGE #333333")));
|
|
1186
|
-
return this;
|
|
1187
|
-
}
|
|
1188
|
-
setFileMap(fileMap) {
|
|
1189
|
-
this.fileMap = fileMap;
|
|
1190
|
-
return this;
|
|
1191
|
-
}
|
|
1192
|
-
addMaterial(material) {
|
|
1193
|
-
const matLib = this.materialLibrary;
|
|
1194
|
-
if (!matLib[material.userData.code]) {
|
|
1195
|
-
this.materials.push(material);
|
|
1196
|
-
matLib[material.userData.code] = material;
|
|
1197
|
-
}
|
|
1198
|
-
return this;
|
|
1199
|
-
}
|
|
1200
|
-
getMaterial(colorCode) {
|
|
1201
|
-
if (colorCode.startsWith("0x2")) {
|
|
1202
|
-
const color = colorCode.substring(3);
|
|
1203
|
-
return this.parseColorMetaDirective(
|
|
1204
|
-
new LineParser("Direct_Color_" + color + " CODE -1 VALUE #" + color + " EDGE #" + color)
|
|
1205
|
-
);
|
|
1206
|
-
}
|
|
1207
|
-
return this.materialLibrary[colorCode] || null;
|
|
1208
|
-
}
|
|
1209
|
-
// Applies the appropriate materials to a prebuilt hierarchy of geometry. Assumes that color codes are present
|
|
1210
|
-
// in the material array if they need to be filled in.
|
|
1211
|
-
applyMaterialsToMesh(group, parentColorCode, materialHierarchy, finalMaterialPass = false) {
|
|
1212
|
-
const loader = this;
|
|
1213
|
-
const parentIsPassthrough = parentColorCode === MAIN_COLOUR_CODE;
|
|
1214
|
-
group.traverse((c) => {
|
|
1215
|
-
if (c.isMesh || c.isLineSegments) {
|
|
1216
|
-
if (Array.isArray(c.material)) {
|
|
1217
|
-
for (let i = 0, l = c.material.length; i < l; i++) {
|
|
1218
|
-
if (!c.material[i].isMaterial) {
|
|
1219
|
-
c.material[i] = getMaterial(c, c.material[i]);
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1222
|
-
} else if (!c.material.isMaterial) {
|
|
1223
|
-
c.material = getMaterial(c, c.material);
|
|
1224
|
-
}
|
|
1225
|
-
}
|
|
1226
|
-
});
|
|
1227
|
-
function getMaterial(c, colorCode) {
|
|
1228
|
-
if (parentIsPassthrough && !(colorCode in materialHierarchy) && !finalMaterialPass) {
|
|
1229
|
-
return colorCode;
|
|
1230
|
-
}
|
|
1231
|
-
const forEdge = c.isLineSegments || c.isConditionalLine;
|
|
1232
|
-
const isPassthrough = !forEdge && colorCode === MAIN_COLOUR_CODE || forEdge && colorCode === MAIN_EDGE_COLOUR_CODE;
|
|
1233
|
-
if (isPassthrough) {
|
|
1234
|
-
colorCode = parentColorCode;
|
|
1235
|
-
}
|
|
1236
|
-
let material = null;
|
|
1237
|
-
if (colorCode in materialHierarchy) {
|
|
1238
|
-
material = materialHierarchy[colorCode];
|
|
1239
|
-
} else if (finalMaterialPass) {
|
|
1240
|
-
material = loader.getMaterial(colorCode);
|
|
1241
|
-
if (material === null) {
|
|
1242
|
-
throw new Error(`LDrawLoader: Material properties for code ${colorCode} not available.`);
|
|
1243
|
-
}
|
|
1244
|
-
} else {
|
|
1245
|
-
return colorCode;
|
|
1246
|
-
}
|
|
1247
|
-
if (c.isLineSegments) {
|
|
1248
|
-
material = material.userData.edgeMaterial;
|
|
1249
|
-
if (c.isConditionalLine) {
|
|
1250
|
-
material = material.userData.conditionalEdgeMaterial;
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
return material;
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
|
-
getMainMaterial() {
|
|
1257
|
-
return this.getMaterial(MAIN_COLOUR_CODE);
|
|
1258
|
-
}
|
|
1259
|
-
getMainEdgeMaterial() {
|
|
1260
|
-
return this.getMaterial(MAIN_EDGE_COLOUR_CODE);
|
|
1261
|
-
}
|
|
1262
|
-
parseColorMetaDirective(lineParser) {
|
|
1263
|
-
let code = null;
|
|
1264
|
-
let color = 16711935;
|
|
1265
|
-
let edgeColor = 16711935;
|
|
1266
|
-
let alpha = 1;
|
|
1267
|
-
let isTransparent = false;
|
|
1268
|
-
let luminance = 0;
|
|
1269
|
-
let finishType = FINISH_TYPE_DEFAULT;
|
|
1270
|
-
let edgeMaterial = null;
|
|
1271
|
-
const name = lineParser.getToken();
|
|
1272
|
-
if (!name) {
|
|
1273
|
-
throw new Error(
|
|
1274
|
-
'LDrawLoader: Material name was expected after "!COLOUR tag' + lineParser.getLineNumberString() + "."
|
|
1275
|
-
);
|
|
1276
|
-
}
|
|
1277
|
-
let token = null;
|
|
1278
|
-
while (true) {
|
|
1279
|
-
token = lineParser.getToken();
|
|
1280
|
-
if (!token) {
|
|
1281
|
-
break;
|
|
1282
|
-
}
|
|
1283
|
-
switch (token.toUpperCase()) {
|
|
1284
|
-
case "CODE":
|
|
1285
|
-
code = lineParser.getToken();
|
|
1286
|
-
break;
|
|
1287
|
-
case "VALUE":
|
|
1288
|
-
color = lineParser.getToken();
|
|
1289
|
-
if (color.startsWith("0x")) {
|
|
1290
|
-
color = "#" + color.substring(2);
|
|
1291
|
-
} else if (!color.startsWith("#")) {
|
|
1292
|
-
throw new Error(
|
|
1293
|
-
"LDrawLoader: Invalid color while parsing material" + lineParser.getLineNumberString() + "."
|
|
1294
|
-
);
|
|
1295
|
-
}
|
|
1296
|
-
break;
|
|
1297
|
-
case "EDGE":
|
|
1298
|
-
edgeColor = lineParser.getToken();
|
|
1299
|
-
if (edgeColor.startsWith("0x")) {
|
|
1300
|
-
edgeColor = "#" + edgeColor.substring(2);
|
|
1301
|
-
} else if (!edgeColor.startsWith("#")) {
|
|
1302
|
-
edgeMaterial = this.getMaterial(edgeColor);
|
|
1303
|
-
if (!edgeMaterial) {
|
|
1304
|
-
throw new Error(
|
|
1305
|
-
"LDrawLoader: Invalid edge color while parsing material" + lineParser.getLineNumberString() + "."
|
|
1306
|
-
);
|
|
1307
|
-
}
|
|
1308
|
-
edgeMaterial = edgeMaterial.userData.edgeMaterial;
|
|
1309
|
-
}
|
|
1310
|
-
break;
|
|
1311
|
-
case "ALPHA":
|
|
1312
|
-
alpha = parseInt(lineParser.getToken());
|
|
1313
|
-
if (isNaN(alpha)) {
|
|
1314
|
-
throw new Error(
|
|
1315
|
-
"LDrawLoader: Invalid alpha value in material definition" + lineParser.getLineNumberString() + "."
|
|
1316
|
-
);
|
|
1317
|
-
}
|
|
1318
|
-
alpha = Math.max(0, Math.min(1, alpha / 255));
|
|
1319
|
-
if (alpha < 1) {
|
|
1320
|
-
isTransparent = true;
|
|
1321
|
-
}
|
|
1322
|
-
break;
|
|
1323
|
-
case "LUMINANCE":
|
|
1324
|
-
luminance = parseInt(lineParser.getToken());
|
|
1325
|
-
if (isNaN(luminance)) {
|
|
1326
|
-
throw new Error(
|
|
1327
|
-
"LDrawLoader: Invalid luminance value in material definition" + LineParser.getLineNumberString() + "."
|
|
1328
|
-
);
|
|
1329
|
-
}
|
|
1330
|
-
luminance = Math.max(0, Math.min(1, luminance / 255));
|
|
1331
|
-
break;
|
|
1332
|
-
case "CHROME":
|
|
1333
|
-
finishType = FINISH_TYPE_CHROME;
|
|
1334
|
-
break;
|
|
1335
|
-
case "PEARLESCENT":
|
|
1336
|
-
finishType = FINISH_TYPE_PEARLESCENT;
|
|
1337
|
-
break;
|
|
1338
|
-
case "RUBBER":
|
|
1339
|
-
finishType = FINISH_TYPE_RUBBER;
|
|
1340
|
-
break;
|
|
1341
|
-
case "MATTE_METALLIC":
|
|
1342
|
-
finishType = FINISH_TYPE_MATTE_METALLIC;
|
|
1343
|
-
break;
|
|
1344
|
-
case "METAL":
|
|
1345
|
-
finishType = FINISH_TYPE_METAL;
|
|
1346
|
-
break;
|
|
1347
|
-
case "MATERIAL":
|
|
1348
|
-
lineParser.setToEnd();
|
|
1349
|
-
break;
|
|
1350
|
-
default:
|
|
1351
|
-
throw new Error(
|
|
1352
|
-
'LDrawLoader: Unknown token "' + token + '" while parsing material' + lineParser.getLineNumberString() + "."
|
|
1353
|
-
);
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
let material = null;
|
|
1357
|
-
switch (finishType) {
|
|
1358
|
-
case FINISH_TYPE_DEFAULT:
|
|
1359
|
-
material = new THREE.MeshStandardMaterial({ color, roughness: 0.3, metalness: 0 });
|
|
1360
|
-
break;
|
|
1361
|
-
case FINISH_TYPE_PEARLESCENT:
|
|
1362
|
-
material = new THREE.MeshStandardMaterial({ color, roughness: 0.3, metalness: 0.25 });
|
|
1363
|
-
break;
|
|
1364
|
-
case FINISH_TYPE_CHROME:
|
|
1365
|
-
material = new THREE.MeshStandardMaterial({ color, roughness: 0, metalness: 1 });
|
|
1366
|
-
break;
|
|
1367
|
-
case FINISH_TYPE_RUBBER:
|
|
1368
|
-
material = new THREE.MeshStandardMaterial({ color, roughness: 0.9, metalness: 0 });
|
|
1369
|
-
break;
|
|
1370
|
-
case FINISH_TYPE_MATTE_METALLIC:
|
|
1371
|
-
material = new THREE.MeshStandardMaterial({ color, roughness: 0.8, metalness: 0.4 });
|
|
1372
|
-
break;
|
|
1373
|
-
case FINISH_TYPE_METAL:
|
|
1374
|
-
material = new THREE.MeshStandardMaterial({ color, roughness: 0.2, metalness: 0.85 });
|
|
1375
|
-
break;
|
|
1376
|
-
default:
|
|
1377
|
-
break;
|
|
1378
|
-
}
|
|
1379
|
-
material.transparent = isTransparent;
|
|
1380
|
-
material.premultipliedAlpha = true;
|
|
1381
|
-
material.opacity = alpha;
|
|
1382
|
-
material.depthWrite = !isTransparent;
|
|
1383
|
-
material.polygonOffset = true;
|
|
1384
|
-
material.polygonOffsetFactor = 1;
|
|
1385
|
-
if (luminance !== 0) {
|
|
1386
|
-
material.emissive.set(material.color).multiplyScalar(luminance);
|
|
1387
|
-
}
|
|
1388
|
-
if (!edgeMaterial) {
|
|
1389
|
-
edgeMaterial = new THREE.LineBasicMaterial({
|
|
1390
|
-
color: edgeColor,
|
|
1391
|
-
transparent: isTransparent,
|
|
1392
|
-
opacity: alpha,
|
|
1393
|
-
depthWrite: !isTransparent
|
|
1394
|
-
});
|
|
1395
|
-
edgeMaterial.userData.code = code;
|
|
1396
|
-
edgeMaterial.name = name + " - Edge";
|
|
1397
|
-
edgeMaterial.userData.conditionalEdgeMaterial = new LDrawConditionalLineMaterial({
|
|
1398
|
-
fog: true,
|
|
1399
|
-
transparent: isTransparent,
|
|
1400
|
-
depthWrite: !isTransparent,
|
|
1401
|
-
color: edgeColor,
|
|
1402
|
-
opacity: alpha
|
|
1403
|
-
});
|
|
1404
|
-
}
|
|
1405
|
-
material.userData.code = code;
|
|
1406
|
-
material.name = name;
|
|
1407
|
-
material.userData.edgeMaterial = edgeMaterial;
|
|
1408
|
-
this.addMaterial(material);
|
|
1409
|
-
return material;
|
|
1410
|
-
}
|
|
1411
|
-
computeConstructionSteps(model) {
|
|
1412
|
-
let stepNumber = 0;
|
|
1413
|
-
model.traverse((c) => {
|
|
1414
|
-
if (c.isGroup) {
|
|
1415
|
-
if (c.userData.startingConstructionStep) {
|
|
1416
|
-
stepNumber++;
|
|
1417
|
-
}
|
|
1418
|
-
c.userData.constructionStep = stepNumber;
|
|
1419
|
-
}
|
|
1420
|
-
});
|
|
1421
|
-
model.userData.numConstructionSteps = stepNumber + 1;
|
|
1422
|
-
}
|
|
1423
|
-
}
|
|
1424
|
-
exports.LDrawLoader = LDrawLoader;
|