@gnsx/three 0.185.16 → 0.186.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/three.cjs +10 -82600
- package/build/three.core.js +1309 -807
- package/build/three.module.js +439 -338
- package/build/three.tsl.js +74 -44
- package/build/three.webgpu.js +6036 -2184
- package/build/three.webgpu.nodes.js +6020 -2184
- package/examples/jsm/Addons.js +6 -6
- package/examples/jsm/controls/ArcballControls.js +1 -1
- package/examples/jsm/controls/FirstPersonControls.js +44 -20
- package/examples/jsm/controls/OrbitControls.js +9 -0
- package/examples/jsm/controls/TrackballControls.js +109 -4
- package/examples/jsm/csm/CSMShadowNode.js +13 -0
- package/examples/jsm/exporters/GLTFExporter.js +23 -7
- package/examples/jsm/exporters/USDZExporter.js +2 -2
- package/examples/jsm/generators/CityGenerator.js +377 -45
- package/examples/jsm/generators/ForestGenerator.js +12 -12
- package/examples/jsm/generators/TerrainGenerator.js +49 -37
- package/examples/jsm/generators/TreeGenerator.js +70 -76
- package/examples/jsm/generators/city/BenchGenerator.js +127 -0
- package/examples/jsm/generators/city/CarGenerator.js +479 -0
- package/examples/jsm/generators/city/CityGeneratorUtils.js +31 -0
- package/examples/jsm/generators/city/HydrantGenerator.js +106 -0
- package/examples/jsm/generators/city/InstancedMeshGenerator.js +86 -0
- package/examples/jsm/generators/city/PersonGenerator.js +447 -0
- package/examples/jsm/generators/city/SidewalkGenerator.js +33 -38
- package/examples/jsm/generators/city/SkyscraperGenerator.js +448 -48
- package/examples/jsm/generators/city/StreetTreeGenerator.js +231 -0
- package/examples/jsm/generators/city/StreetlightGenerator.js +100 -0
- package/examples/jsm/generators/city/TrafficlightGenerator.js +106 -0
- package/examples/jsm/generators/city/TrashcanGenerator.js +100 -0
- package/examples/jsm/geometries/BoxLineGeometry.js +1 -1
- package/examples/jsm/geometries/ParametricGeometry.js +1 -1
- package/examples/jsm/geometries/RoundedBoxGeometry.js +1 -1
- package/examples/jsm/gpgpu/CountingSort.js +271 -0
- package/examples/jsm/helpers/LightProbeGridHelper.js +60 -239
- package/examples/jsm/helpers/LightProbeGridHelperWebGL.js +221 -0
- package/examples/jsm/inspector/Extension.js +94 -0
- package/examples/jsm/inspector/Inspector.js +145 -41
- package/examples/jsm/inspector/RendererInspector.js +100 -52
- package/examples/jsm/inspector/extensions/color-grading/ColorGrading.js +2609 -0
- package/examples/jsm/inspector/extensions/color-grading/ColorWheel.js +352 -0
- package/examples/jsm/inspector/extensions/color-grading/CurveEditor.js +599 -0
- package/examples/jsm/inspector/extensions/color-grading/LUT3DStyle.js +1201 -0
- package/examples/jsm/inspector/extensions/color-grading/LUTMath.js +788 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/BrightnessModule.js +72 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/ColorWheelModule.js +112 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/ContrastModule.js +82 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/CurvesModule.js +109 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/ExposureHueModule.js +110 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/ExposureModule.js +73 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/HueModule.js +78 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/ImportedCubeModule.js +89 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/Module.js +285 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/OutputModule.js +101 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/RendererModule.js +225 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/SatVibranceModule.js +102 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/SaturationModule.js +76 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/VibranceModule.js +76 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/WhiteBalanceModule.js +86 -0
- package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphEditor.js +26 -31
- package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphLoader.js +1 -0
- package/examples/jsm/inspector/tabs/Memory.js +0 -2
- package/examples/jsm/inspector/tabs/Settings.js +4 -0
- package/examples/jsm/inspector/tabs/Timeline.js +223 -171
- package/examples/jsm/inspector/tabs/Viewer.js +515 -21
- package/examples/jsm/inspector/ui/List.js +15 -9
- package/examples/jsm/inspector/ui/Profiler.js +170 -14
- package/examples/jsm/inspector/ui/Style.js +269 -23
- package/examples/jsm/inspector/ui/Tab.js +2 -0
- package/examples/jsm/inspector/ui/Values.js +14 -2
- package/examples/jsm/interactive/HTMLMesh.js +19 -3
- package/examples/jsm/lighting/LightProbeGrid.js +484 -889
- package/examples/jsm/lighting/LightProbeGridUtils.js +107 -0
- package/examples/jsm/lighting/LightProbeGridWebGL.js +841 -0
- package/examples/jsm/lighting/vxgi/VXGIConeTracer.js +194 -0
- package/examples/jsm/lighting/vxgi/VXGINode.js +660 -0
- package/examples/jsm/lighting/vxgi/VXGISceneCollector.js +478 -0
- package/examples/jsm/lighting/vxgi/VXGIVolume.js +1430 -0
- package/examples/jsm/lights/SunLight.js +95 -0
- package/examples/jsm/lights/SunLightNode.js +56 -0
- package/examples/jsm/lights/SunLightShadow.js +319 -0
- package/examples/jsm/lights/SunShadowNode.js +312 -0
- package/examples/jsm/loaders/3DMLoader.js +150 -49
- package/examples/jsm/loaders/3MFLoader.js +202 -1
- package/examples/jsm/loaders/FBXLoader.js +81 -5
- package/examples/jsm/loaders/GLTFGaussianSplatLoaderExtension.js +330 -0
- package/examples/jsm/loaders/GLTFLoader.js +79 -14
- package/examples/jsm/loaders/GaussianSplatPLYLoader.js +386 -0
- package/examples/jsm/loaders/KSPLATLoader.js +463 -0
- package/examples/jsm/loaders/MaterialXLoader.js +111 -1010
- package/examples/jsm/loaders/PCDLoader.js +1 -1
- package/examples/jsm/loaders/SPLATLoader.js +139 -0
- package/examples/jsm/loaders/SPZLoader.js +561 -0
- package/examples/jsm/loaders/materialx/MaterialXArchive.js +108 -0
- package/examples/jsm/loaders/materialx/MaterialXDocument.js +878 -0
- package/examples/jsm/loaders/materialx/MaterialXHextile.js +183 -0
- package/examples/jsm/loaders/materialx/MaterialXInterfaceValidation.js +376 -0
- package/examples/jsm/loaders/materialx/MaterialXLog.js +75 -0
- package/examples/jsm/loaders/materialx/MaterialXNodeInterfaceRegistry.js +4 -0
- package/examples/jsm/loaders/materialx/MaterialXNodeLibrary.js +1021 -0
- package/examples/jsm/loaders/materialx/MaterialXSurfaceMappings.js +661 -0
- package/examples/jsm/loaders/materialx/MaterialXUtils.js +57 -0
- package/examples/jsm/loaders/materialx/compile/MaterialXCompileRegistry.js +997 -0
- package/examples/jsm/loaders/materialx/parse/MaterialXParser.js +28 -0
- package/examples/jsm/loaders/usd/USDAParser.js +15 -2
- package/examples/jsm/loaders/usd/USDCParser.js +1 -4
- package/examples/jsm/loaders/usd/USDComposer.js +80 -42
- package/examples/jsm/materials/WoodNodeMaterial.js +6 -108
- package/examples/jsm/misc/RollerCoaster.js +2 -2
- package/examples/jsm/misc/SculptGL.LICENSE.txt +21 -0
- package/examples/jsm/misc/Sculptor.js +1679 -0
- package/examples/jsm/misc/SculptorMesh.js +1504 -0
- package/examples/jsm/misc/SculptorTools.js +1180 -0
- package/examples/jsm/misc/SculptorUtils.js +345 -0
- package/examples/jsm/misc/TubePainter.js +28 -16
- package/examples/jsm/misc/VolumeSlice.js +24 -24
- package/examples/jsm/modifiers/SimplifyModifier.js +63 -556
- package/examples/jsm/objects/GaussianSplat.js +1039 -0
- package/examples/jsm/objects/Sky.js +66 -45
- package/examples/jsm/objects/SkyMesh.js +70 -51
- package/examples/jsm/physics/JoltPhysics.js +1 -1
- package/examples/jsm/postprocessing/AfterimagePass.js +4 -2
- package/examples/jsm/postprocessing/BloomPass.js +2 -2
- package/examples/jsm/postprocessing/GTAOPass.js +1 -1
- package/examples/jsm/postprocessing/OutlinePass.js +5 -5
- package/examples/jsm/postprocessing/SAOPass.js +1 -1
- package/examples/jsm/postprocessing/SSAOPass.js +1 -1
- package/examples/jsm/postprocessing/SSRPass.js +4 -2
- package/examples/jsm/postprocessing/SavePass.js +1 -1
- package/examples/jsm/postprocessing/TAARenderPass.js +1 -1
- package/examples/jsm/postprocessing/UnrealBloomPass.js +30 -13
- package/examples/jsm/renderers/CSS2DRenderer.js +29 -5
- package/examples/jsm/shaders/DepthLimitedBlurShader.js +4 -1
- package/examples/jsm/shaders/ExposureShader.js +1 -1
- package/examples/jsm/shaders/FilmShader.js +2 -1
- package/examples/jsm/transpiler/AST.js +21 -2
- package/examples/jsm/transpiler/GLSLDecoder.js +498 -8
- package/examples/jsm/transpiler/TSLEncoder.js +82 -10
- package/examples/jsm/transpiler/WGSLEncoder.js +33 -4
- package/examples/jsm/tsl/WebGLNodesHandler.js +29 -39
- package/examples/jsm/tsl/display/AfterImageNode.js +2 -0
- package/examples/jsm/tsl/display/AnaglyphPassNode.js +3 -2
- package/examples/jsm/tsl/display/BilateralBlurNode.js +5 -2
- package/examples/jsm/tsl/display/BloomNode.js +55 -30
- package/examples/jsm/tsl/display/DenoiseNode.js +21 -1
- package/examples/jsm/tsl/display/DepthOfFieldNode.js +24 -6
- package/examples/jsm/tsl/display/DotScreenNode.js +11 -11
- package/examples/jsm/tsl/display/FSR1Node.js +8 -4
- package/examples/jsm/tsl/display/GTAONode.js +199 -86
- package/examples/jsm/tsl/display/GaussianBlurNode.js +65 -52
- package/examples/jsm/tsl/display/GodraysNode.js +5 -2
- package/examples/jsm/tsl/display/ImportanceSampledEnvironment.js +2 -2
- package/examples/jsm/tsl/display/LensflareNode.js +5 -2
- package/examples/jsm/tsl/display/OITPassNode.js +352 -0
- package/examples/jsm/tsl/display/OutlineNode.js +2 -0
- package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +3 -2
- package/examples/jsm/tsl/display/RGBShiftNode.js +9 -9
- package/examples/jsm/tsl/display/RecurrentDenoiseNode.js +7 -4
- package/examples/jsm/tsl/display/RetroPassNode.js +1 -1
- package/examples/jsm/tsl/display/SMAANode.js +22 -61
- package/examples/jsm/tsl/display/SSAAPassNode.js +2 -4
- package/examples/jsm/tsl/display/SSAONode.js +436 -0
- package/examples/jsm/tsl/display/SSGINode.js +5 -2
- package/examples/jsm/tsl/display/SSRNode.js +7 -2
- package/examples/jsm/tsl/display/SSSNode.js +5 -2
- package/examples/jsm/tsl/display/SharpenNode.js +5 -4
- package/examples/jsm/tsl/display/StereoCompositePassNode.js +1 -3
- package/examples/jsm/tsl/display/StereoPassNode.js +1 -3
- package/examples/jsm/tsl/display/TAAUNode.js +22 -125
- package/examples/jsm/tsl/display/TRAANode.js +16 -142
- package/examples/jsm/tsl/display/TemporalReprojectNode.js +21 -15
- package/examples/jsm/tsl/display/depthAwareBlur.js +63 -0
- package/examples/jsm/tsl/display/hashBlur.js +3 -2
- package/examples/jsm/tsl/lighting/ClusteredLightsNode.js +38 -27
- package/examples/jsm/tsl/lighting/LightProbeGridNode.js +136 -0
- package/examples/jsm/tsl/math/voronoiNoise.js +112 -0
- package/examples/jsm/tsl/shadows/TileShadowNode.js +4 -6
- package/examples/jsm/tsl/utils/Raymarching.js +5 -5
- package/examples/jsm/tsl/utils/SoftParticles.js +60 -0
- package/examples/jsm/tsl/utils/TAAUtils.js +195 -0
- package/examples/jsm/utils/BufferGeometryUtils.js +14 -14
- package/examples/jsm/utils/GaussianSplatUtils.js +229 -0
- package/examples/jsm/utils/WebGLTextureUtils.js +1 -1
- package/examples/jsm/utils/WebGPUTextureUtils.js +1 -1
- package/examples/jsm/webxr/WebGLXRFallback.js +2 -16
- package/examples/jsm/webxr/XRControllerModelFactory.js +16 -4
- package/package.json +9 -16
- package/src/Three.Core.js +2 -1
- package/src/Three.TSL.js +73 -43
- package/src/Three.WebGPU.Nodes.js +1 -0
- package/src/Three.WebGPU.js +1 -0
- package/src/animation/AnimationClip.js +15 -2
- package/src/animation/AnimationObjectGroup.js +18 -6
- package/src/animation/AnimationUtils.js +26 -0
- package/src/animation/KeyframeTrack.js +37 -0
- package/src/constants.js +23 -1
- package/src/core/BufferAttribute.js +3 -2
- package/src/core/BufferGeometry.js +1 -1
- package/src/core/InterleavedBuffer.js +5 -1
- package/src/core/Object3D.js +40 -12
- package/src/core/Raycaster.js +4 -0
- package/src/core/RenderTarget.js +99 -9
- package/src/core/RenderTarget3D.js +12 -8
- package/src/extras/Controls.js +0 -8
- package/src/extras/PMREMGenerator.js +99 -205
- package/src/geometries/TorusGeometry.js +1 -1
- package/src/helpers/ArrowHelper.js +2 -0
- package/src/helpers/AxesHelper.js +2 -0
- package/src/helpers/Box3Helper.js +2 -0
- package/src/helpers/BoxHelper.js +2 -0
- package/src/helpers/CameraHelper.js +2 -0
- package/src/helpers/DirectionalLightHelper.js +2 -0
- package/src/helpers/GridHelper.js +2 -0
- package/src/helpers/HemisphereLightHelper.js +2 -0
- package/src/helpers/PlaneHelper.js +2 -0
- package/src/helpers/PointLightHelper.js +2 -0
- package/src/helpers/PolarGridHelper.js +2 -0
- package/src/helpers/SkeletonHelper.js +2 -0
- package/src/helpers/SpotLightHelper.js +2 -0
- package/src/lights/Light.js +0 -10
- package/src/lights/LightShadow.js +43 -12
- package/src/lights/SpotLightShadow.js +18 -0
- package/src/loaders/BufferGeometryLoader.js +5 -0
- package/src/loaders/ImageBitmapLoader.js +3 -1
- package/src/loaders/ObjectLoader.js +8 -5
- package/src/materials/Material.js +80 -57
- package/src/materials/MeshPhysicalMaterial.js +32 -0
- package/src/materials/nodes/Line2NodeMaterial.js +17 -8
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +42 -5
- package/src/materials/nodes/NodeMaterial.js +19 -13
- package/src/materials/nodes/PointsNodeMaterial.js +2 -1
- package/src/materials/nodes/manager/NodeMaterialObserver.js +282 -55
- package/src/math/Frustum.js +9 -0
- package/src/math/FrustumArray.js +1 -1
- package/src/math/MathUtils.js +5 -3
- package/src/math/Matrix4.js +2 -9
- package/src/math/Plane.js +30 -1
- package/src/math/Quaternion.js +0 -10
- package/src/math/Ray.js +95 -45
- package/src/math/Triangle.js +0 -2
- package/src/math/Vector3.js +2 -2
- package/src/math/Vector4.js +0 -4
- package/src/math/interpolants/BezierInterpolant.js +36 -23
- package/src/nodes/Nodes.js +2 -0
- package/src/nodes/TSL.js +11 -3
- package/src/nodes/accessors/Batch.js +85 -13
- package/src/nodes/accessors/BufferAttributeNode.js +1 -1
- package/src/nodes/accessors/BuiltinNode.js +1 -1
- package/src/nodes/accessors/Instance.js +19 -18
- package/src/nodes/accessors/MaterialNode.js +9 -0
- package/src/nodes/accessors/ModelNode.js +85 -9
- package/src/nodes/accessors/ReferenceBaseNode.js +1 -70
- package/src/nodes/accessors/ReferenceElementNode.js +72 -0
- package/src/nodes/accessors/ReferenceNode.js +1 -70
- package/src/nodes/accessors/Skinning.js +124 -12
- package/src/nodes/accessors/StorageTextureNode.js +7 -3
- package/src/nodes/accessors/Texture3DNode.js +1 -1
- package/src/nodes/accessors/TextureNode.js +51 -21
- package/src/nodes/accessors/TextureSizeNode.js +4 -2
- package/src/nodes/accessors/UniformArrayNode.js +30 -5
- package/src/nodes/code/CodeNode.js +1 -1
- package/src/nodes/code/FunctionNode.js +12 -2
- package/src/nodes/core/ArrayNode.js +2 -2
- package/src/nodes/core/ContextNode.js +57 -4
- package/src/nodes/core/IndexNode.js +69 -4
- package/src/nodes/core/InspectorNode.js +2 -2
- package/src/nodes/core/MRTNode.js +44 -2
- package/src/nodes/core/Node.js +6 -3
- package/src/nodes/core/NodeBuilder.js +65 -50
- package/src/nodes/core/NodeFrame.js +11 -3
- package/src/nodes/core/NodeUtils.js +88 -0
- package/src/nodes/core/PropertyNode.js +8 -0
- package/src/nodes/core/StackNode.js +0 -1
- package/src/nodes/core/StructNode.js +4 -3
- package/src/nodes/core/UniformGroupNode.js +3 -2
- package/src/nodes/core/UniformNode.js +26 -12
- package/src/nodes/core/VarNode.js +0 -1
- package/src/nodes/display/BumpMapNode.js +2 -2
- package/src/nodes/display/ColorAdjustment.js +1 -1
- package/src/nodes/display/PassNode.js +76 -15
- package/src/nodes/display/ScreenNode.js +22 -65
- package/src/nodes/fog/Fog.js +4 -4
- package/src/nodes/functions/BSDF/BRDF_GGX.js +6 -6
- package/src/nodes/functions/BSDF/BRDF_Sheen.js +1 -1
- package/src/nodes/functions/BSDF/DFGLUT.js +2 -1
- package/src/nodes/functions/BSDF/LTC.js +1 -1
- package/src/nodes/functions/PhongLightingModel.js +1 -1
- package/src/nodes/functions/PhysicalLightingModel.js +83 -25
- package/src/nodes/functions/ToonLightingModel.js +2 -2
- package/src/nodes/functions/material/getParallaxCorrectNormal.js +3 -3
- package/src/nodes/gpgpu/AtomicFunctionNode.js +64 -13
- package/src/nodes/gpgpu/BarrierNode.js +13 -4
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +1 -1
- package/src/nodes/gpgpu/ComputeNode.js +20 -17
- package/src/nodes/gpgpu/SubgroupFunctionNode.js +165 -37
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +44 -6
- package/src/nodes/lighting/EnvironmentNode.js +40 -4
- package/src/nodes/lighting/LightsNode.js +20 -4
- package/src/nodes/lighting/ShadowBaseNode.js +158 -1
- package/src/nodes/lighting/ShadowFilterNode.js +2 -106
- package/src/nodes/lighting/ShadowNode.js +22 -91
- package/src/nodes/materialx/{lib/mx_hsv.js → MaterialXColor.js} +3 -6
- package/src/nodes/materialx/{lib/mx_transform_color.js → MaterialXColorTransform.js} +3 -6
- package/src/nodes/materialx/MaterialXCore.js +37 -0
- package/src/nodes/materialx/MaterialXNodes.js +64 -72
- package/src/nodes/materialx/{lib/mx_noise.js → MaterialXNoise.js} +426 -197
- package/src/nodes/math/BitcountNode.js +24 -4
- package/src/nodes/math/MathNode.js +4 -4
- package/src/nodes/math/MathUtils.js +15 -4
- package/src/nodes/math/OperatorNode.js +2 -2
- package/src/nodes/math/PackFloatNode.js +29 -1
- package/src/nodes/math/Packed4x8IntegerNode.js +433 -0
- package/src/nodes/math/UnpackFloatNode.js +30 -2
- package/src/nodes/parsers/GLSLNodeFunction.js +1 -1
- package/src/nodes/pmrem/PMREMNode.js +1 -1
- package/src/nodes/pmrem/PMREMUtils.js +31 -74
- package/src/nodes/shapes/Shapes.js +1 -1
- package/src/nodes/tsl/TSLCore.js +1 -31
- package/src/nodes/utils/EventNode.js +75 -0
- package/src/nodes/utils/LoopNode.js +54 -13
- package/src/nodes/utils/PostProcessingUtils.js +23 -2
- package/src/nodes/utils/RTTNode.js +97 -32
- package/src/nodes/utils/ReflectorNode.js +8 -4
- package/src/nodes/utils/RotateNode.js +85 -8
- package/src/nodes/utils/SpriteUtils.js +58 -23
- package/src/objects/BatchedMesh.js +6 -0
- package/src/objects/InstancedMesh.js +1 -1
- package/src/objects/LOD.js +1 -1
- package/src/objects/Line.js +12 -0
- package/src/objects/Mesh.js +12 -0
- package/src/objects/Points.js +12 -0
- package/src/objects/Sprite.js +12 -0
- package/src/renderers/WebGLRenderer.js +93 -27
- package/src/renderers/common/Animation.js +12 -2
- package/src/renderers/common/Backend.js +38 -10
- package/src/renderers/common/BindGroup.js +0 -1
- package/src/renderers/common/Bindings.js +50 -4
- package/src/renderers/common/BundleGroup.js +4 -0
- package/src/renderers/common/ClippingContext.js +11 -1
- package/src/renderers/common/Color4.js +9 -0
- package/src/renderers/common/Constants.js +0 -5
- package/src/renderers/common/DirectRenderPipeline.js +233 -0
- package/src/renderers/common/Geometries.js +24 -3
- package/src/renderers/common/Info.js +3 -3
- package/src/renderers/common/InspectorBase.js +37 -8
- package/src/renderers/common/Lighting.js +11 -4
- package/src/renderers/common/Pipelines.js +6 -4
- package/src/renderers/common/QuadMesh.js +16 -2
- package/src/renderers/common/RenderContext.js +8 -0
- package/src/renderers/common/RenderList.js +53 -19
- package/src/renderers/common/RenderLists.js +58 -11
- package/src/renderers/common/RenderObject.js +14 -0
- package/src/renderers/common/RenderObjects.js +14 -9
- package/src/renderers/common/RenderPipeline.js +52 -44
- package/src/renderers/common/Renderer.js +226 -55
- package/src/renderers/common/Storage3DTexture.js +16 -0
- package/src/renderers/common/Textures.js +3 -3
- package/src/renderers/common/XRManager.js +79 -72
- package/src/renderers/common/extras/PMREMGenerator.js +76 -144
- package/src/renderers/common/nodes/NodeManager.js +144 -6
- package/src/renderers/common/nodes/NodeStorageBuffer.js +3 -1
- package/src/renderers/common/nodes/NodeUniformBuffer.js +3 -1
- package/src/renderers/shaders/DFGLUTData.js +2 -1
- package/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js +4 -2
- package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +48 -0
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +53 -4
- package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +20 -2
- package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +20 -0
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +61 -57
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +82 -0
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl.js +9 -0
- package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +8 -1
- package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +15 -0
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -0
- package/src/renderers/shaders/ShaderLib.js +1 -0
- package/src/renderers/shaders/UniformsLib.js +16 -0
- package/src/renderers/webgl/WebGLAnimation.js +2 -2
- package/src/renderers/webgl/WebGLCapabilities.js +2 -2
- package/src/renderers/webgl/WebGLLights.js +74 -4
- package/src/renderers/webgl/WebGLMaterials.js +6 -0
- package/src/renderers/webgl/WebGLOutput.js +36 -24
- package/src/renderers/webgl/WebGLProgram.js +3 -0
- package/src/renderers/webgl/WebGLPrograms.js +8 -0
- package/src/renderers/webgl/WebGLRenderLists.js +6 -10
- package/src/renderers/webgl/WebGLShadowMap.js +47 -44
- package/src/renderers/webgl/WebGLTextures.js +7 -7
- package/src/renderers/webgl-fallback/WebGLBackend.js +153 -45
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +83 -29
- package/src/renderers/webgl-fallback/utils/WebGLState.js +163 -17
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +32 -5
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +11 -4
- package/src/renderers/webgpu/WebGPUBackend.js +513 -145
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +99 -20
- package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +2 -1
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +3 -12
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +24 -14
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +80 -14
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +62 -7
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +9 -3
- package/src/renderers/webgpu/utils/WebGPUUtils.js +16 -4
- package/src/renderers/webxr/WebXRManager.js +25 -2
- package/src/scenes/Scene.js +3 -3
- package/src/textures/CompressedArrayTexture.js +16 -0
- package/src/textures/Data3DTexture.js +16 -0
- package/src/textures/DataArrayTexture.js +16 -0
- package/src/textures/DepthTexture.js +3 -3
- package/src/textures/Texture.js +3 -3
- package/src/textures/{Source.js → TextureSource.js} +39 -8
- package/src/utils.js +6 -79
- package/build/three.core.min.js +0 -6
- package/build/three.module.min.js +0 -6
- package/build/three.tsl.min.js +0 -6
- package/build/three.webgpu.min.js +0 -6
- package/build/three.webgpu.nodes.min.js +0 -6
- package/examples/jsm/libs/ecsy.module.js +0 -1792
- package/examples/jsm/loaders/LottieLoader.js +0 -130
- package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +0 -52
|
@@ -0,0 +1,1180 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Portions adapted from SculptGL by Stéphane Ginier.
|
|
3
|
+
* Copyright (c) 2019 Stéphane GINIER
|
|
4
|
+
* Licensed under the MIT License; see ./SculptGL.LICENSE.txt.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
TRI_INDEX,
|
|
9
|
+
getMemory,
|
|
10
|
+
replaceElement,
|
|
11
|
+
removeElement,
|
|
12
|
+
tidy,
|
|
13
|
+
sqrDist,
|
|
14
|
+
triangleInsideSphere,
|
|
15
|
+
falloff
|
|
16
|
+
} from './SculptorUtils.js';
|
|
17
|
+
|
|
18
|
+
// Subdivision
|
|
19
|
+
|
|
20
|
+
const SubData = {
|
|
21
|
+
_mesh: null,
|
|
22
|
+
_verticesMap: new Map(),
|
|
23
|
+
_edgeKeyStride: 0,
|
|
24
|
+
_stringEdgeKeys: false,
|
|
25
|
+
_center: [ 0, 0, 0 ],
|
|
26
|
+
_radius2: 0,
|
|
27
|
+
_edgeMax2: 0
|
|
28
|
+
};
|
|
29
|
+
const _subV1 = [ 0, 0, 0 ];
|
|
30
|
+
const _subV2 = [ 0, 0, 0 ];
|
|
31
|
+
const _subV3 = [ 0, 0, 0 ];
|
|
32
|
+
const MAX_EDGE_KEY_STRIDE = Math.floor( Math.sqrt( Number.MAX_SAFE_INTEGER ) );
|
|
33
|
+
|
|
34
|
+
function subEdgeKey( iv1, iv2 ) {
|
|
35
|
+
|
|
36
|
+
const low = Math.min( iv1, iv2 );
|
|
37
|
+
const high = Math.max( iv1, iv2 );
|
|
38
|
+
return SubData._stringEdgeKeys ? low + '+' + high : low * SubData._edgeKeyStride + high;
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function subFillTriangle( iTri, iv1, iv2, iv3, ivMid ) {
|
|
43
|
+
|
|
44
|
+
const mesh = SubData._mesh;
|
|
45
|
+
const vrv = mesh.getVerticesRingVert();
|
|
46
|
+
const vrf = mesh.getVerticesRingFace();
|
|
47
|
+
const pil = mesh.getFacePosInLeaf();
|
|
48
|
+
const fleaf = mesh.getFaceLeaf();
|
|
49
|
+
const fAr = mesh.getFaces();
|
|
50
|
+
|
|
51
|
+
let j = iTri * 4;
|
|
52
|
+
fAr[ j ] = iv1; fAr[ j + 1 ] = ivMid; fAr[ j + 2 ] = iv3; fAr[ j + 3 ] = TRI_INDEX;
|
|
53
|
+
const leaf = fleaf[ iTri ];
|
|
54
|
+
const iTrisLeaf = leaf._iFaces;
|
|
55
|
+
|
|
56
|
+
vrv[ ivMid ].push( iv3 );
|
|
57
|
+
vrv[ iv3 ].push( ivMid );
|
|
58
|
+
|
|
59
|
+
const iNewTri = mesh.getNbTriangles();
|
|
60
|
+
vrf[ ivMid ].push( iTri, iNewTri );
|
|
61
|
+
|
|
62
|
+
j = iNewTri * 4;
|
|
63
|
+
fAr[ j ] = ivMid; fAr[ j + 1 ] = iv2; fAr[ j + 2 ] = iv3; fAr[ j + 3 ] = TRI_INDEX;
|
|
64
|
+
fleaf[ iNewTri ] = leaf;
|
|
65
|
+
pil[ iNewTri ] = iTrisLeaf.length;
|
|
66
|
+
vrf[ iv3 ].push( iNewTri );
|
|
67
|
+
replaceElement( vrf[ iv2 ], iTri, iNewTri );
|
|
68
|
+
iTrisLeaf.push( iNewTri );
|
|
69
|
+
mesh.addNbFace( 1 );
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function subFillTriangles( iTris ) {
|
|
74
|
+
|
|
75
|
+
const mesh = SubData._mesh;
|
|
76
|
+
const vrv = mesh.getVerticesRingVert();
|
|
77
|
+
const fAr = mesh.getFaces();
|
|
78
|
+
const nbTris = iTris.length;
|
|
79
|
+
const iTrisNext = new Uint32Array( getMemory( 4 * 2 * nbTris ), 0, 2 * nbTris );
|
|
80
|
+
let nbNext = 0;
|
|
81
|
+
const vMap = SubData._verticesMap;
|
|
82
|
+
|
|
83
|
+
for ( let i = 0; i < nbTris; ++ i ) {
|
|
84
|
+
|
|
85
|
+
const iTri = iTris[ i ];
|
|
86
|
+
const j = iTri * 4;
|
|
87
|
+
const iv1 = fAr[ j ], iv2 = fAr[ j + 1 ], iv3 = fAr[ j + 2 ];
|
|
88
|
+
const val1 = vMap.get( subEdgeKey( iv1, iv2 ) );
|
|
89
|
+
const val2 = vMap.get( subEdgeKey( iv2, iv3 ) );
|
|
90
|
+
const val3 = vMap.get( subEdgeKey( iv1, iv3 ) );
|
|
91
|
+
const num1 = vrv[ iv1 ].length, num2 = vrv[ iv2 ].length, num3 = vrv[ iv3 ].length;
|
|
92
|
+
let split = 0;
|
|
93
|
+
if ( val1 ) {
|
|
94
|
+
|
|
95
|
+
if ( val2 ) {
|
|
96
|
+
|
|
97
|
+
if ( val3 ) {
|
|
98
|
+
|
|
99
|
+
if ( num1 < num2 && num1 < num3 ) split = 2; else if ( num2 < num3 ) split = 3; else split = 1;
|
|
100
|
+
|
|
101
|
+
} else if ( num1 < num3 ) split = 2; else split = 1;
|
|
102
|
+
|
|
103
|
+
} else if ( val3 && num2 < num3 ) split = 3;
|
|
104
|
+
else split = 1;
|
|
105
|
+
|
|
106
|
+
} else if ( val2 ) {
|
|
107
|
+
|
|
108
|
+
if ( val3 && num2 < num1 ) split = 3; else split = 2;
|
|
109
|
+
|
|
110
|
+
} else if ( val3 ) split = 3;
|
|
111
|
+
|
|
112
|
+
if ( split === 1 ) subFillTriangle( iTri, iv1, iv2, iv3, val1 );
|
|
113
|
+
else if ( split === 2 ) subFillTriangle( iTri, iv2, iv3, iv1, val2 );
|
|
114
|
+
else if ( split === 3 ) subFillTriangle( iTri, iv3, iv1, iv2, val3 );
|
|
115
|
+
else continue;
|
|
116
|
+
iTrisNext[ nbNext ++ ] = iTri;
|
|
117
|
+
iTrisNext[ nbNext ++ ] = mesh.getNbTriangles() - 1;
|
|
118
|
+
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return iTrisNext.slice( 0, nbNext );
|
|
122
|
+
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function halfEdgeSplit( iTri, iv1, iv2, iv3 ) {
|
|
126
|
+
|
|
127
|
+
const mesh = SubData._mesh;
|
|
128
|
+
const vAr = mesh.getVertices();
|
|
129
|
+
const nAr = mesh.getNormals();
|
|
130
|
+
const fAr = mesh.getFaces();
|
|
131
|
+
const pil = mesh.getFacePosInLeaf();
|
|
132
|
+
const fleaf = mesh.getFaceLeaf();
|
|
133
|
+
const vrv = mesh.getVerticesRingVert();
|
|
134
|
+
const vrf = mesh.getVerticesRingFace();
|
|
135
|
+
|
|
136
|
+
const vMap = SubData._verticesMap;
|
|
137
|
+
const key = subEdgeKey( iv1, iv2 );
|
|
138
|
+
let isNewVertex = false;
|
|
139
|
+
let ivMid = vMap.get( key );
|
|
140
|
+
if ( ivMid === undefined ) {
|
|
141
|
+
|
|
142
|
+
ivMid = mesh.getNbVertices();
|
|
143
|
+
isNewVertex = true;
|
|
144
|
+
vMap.set( key, ivMid );
|
|
145
|
+
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
vrv[ iv3 ].push( ivMid );
|
|
149
|
+
let id = iTri * 4;
|
|
150
|
+
fAr[ id ] = iv1; fAr[ id + 1 ] = ivMid; fAr[ id + 2 ] = iv3; fAr[ id + 3 ] = TRI_INDEX;
|
|
151
|
+
|
|
152
|
+
const iNewTri = mesh.getNbTriangles();
|
|
153
|
+
id = iNewTri * 4;
|
|
154
|
+
fAr[ id ] = ivMid; fAr[ id + 1 ] = iv2; fAr[ id + 2 ] = iv3; fAr[ id + 3 ] = TRI_INDEX;
|
|
155
|
+
|
|
156
|
+
vrf[ iv3 ].push( iNewTri );
|
|
157
|
+
replaceElement( vrf[ iv2 ], iTri, iNewTri );
|
|
158
|
+
const leaf = fleaf[ iTri ];
|
|
159
|
+
const iTrisLeaf = leaf._iFaces;
|
|
160
|
+
fleaf[ iNewTri ] = leaf;
|
|
161
|
+
pil[ iNewTri ] = iTrisLeaf.length;
|
|
162
|
+
iTrisLeaf.push( iNewTri );
|
|
163
|
+
|
|
164
|
+
if ( ! isNewVertex ) {
|
|
165
|
+
|
|
166
|
+
vrv[ ivMid ].push( iv3 );
|
|
167
|
+
vrf[ ivMid ].push( iTri, iNewTri );
|
|
168
|
+
mesh.addNbFace( 1 );
|
|
169
|
+
return;
|
|
170
|
+
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const id1 = iv1 * 3, id2 = iv2 * 3;
|
|
174
|
+
const v1x = vAr[ id1 ], v1y = vAr[ id1 + 1 ], v1z = vAr[ id1 + 2 ];
|
|
175
|
+
const n1x = nAr[ id1 ], n1y = nAr[ id1 + 1 ], n1z = nAr[ id1 + 2 ];
|
|
176
|
+
const v2x = vAr[ id2 ], v2y = vAr[ id2 + 1 ], v2z = vAr[ id2 + 2 ];
|
|
177
|
+
const n2x = nAr[ id2 ], n2y = nAr[ id2 + 1 ], n2z = nAr[ id2 + 2 ];
|
|
178
|
+
|
|
179
|
+
const n1n2x = n1x + n2x, n1n2y = n1y + n2y, n1n2z = n1z + n2z;
|
|
180
|
+
id = ivMid * 3;
|
|
181
|
+
nAr[ id ] = n1n2x * 0.5; nAr[ id + 1 ] = n1n2y * 0.5; nAr[ id + 2 ] = n1n2z * 0.5;
|
|
182
|
+
|
|
183
|
+
let nn1x = n1x, nn1y = n1y, nn1z = n1z;
|
|
184
|
+
let len = nn1x * nn1x + nn1y * nn1y + nn1z * nn1z;
|
|
185
|
+
if ( len === 0 ) {
|
|
186
|
+
|
|
187
|
+
nn1x = 1;
|
|
188
|
+
|
|
189
|
+
} else {
|
|
190
|
+
|
|
191
|
+
len = 1 / Math.sqrt( len ); nn1x *= len; nn1y *= len; nn1z *= len;
|
|
192
|
+
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
let nn2x = n2x, nn2y = n2y, nn2z = n2z;
|
|
196
|
+
len = nn2x * nn2x + nn2y * nn2y + nn2z * nn2z;
|
|
197
|
+
if ( len === 0 ) {
|
|
198
|
+
|
|
199
|
+
nn2x = 1;
|
|
200
|
+
|
|
201
|
+
} else {
|
|
202
|
+
|
|
203
|
+
len = 1 / Math.sqrt( len ); nn2x *= len; nn2y *= len; nn2z *= len;
|
|
204
|
+
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const d = nn1x * nn2x + nn1y * nn2y + nn1z * nn2z;
|
|
208
|
+
let angle = 0;
|
|
209
|
+
if ( d <= - 1 ) angle = Math.PI;
|
|
210
|
+
else if ( d >= 1 ) angle = 0;
|
|
211
|
+
else angle = Math.acos( d );
|
|
212
|
+
|
|
213
|
+
const ex = v1x - v2x, ey = v1y - v2y, ez = v1z - v2z;
|
|
214
|
+
let offset = angle * 0.12 * Math.sqrt( ex * ex + ey * ey + ez * ez );
|
|
215
|
+
len = n1n2x * n1n2x + n1n2y * n1n2y + n1n2z * n1n2z;
|
|
216
|
+
if ( len > 0 ) offset /= Math.sqrt( len );
|
|
217
|
+
if ( ( ex * ( nn1x - nn2x ) + ey * ( nn1y - nn2y ) + ez * ( nn1z - nn2z ) ) < 0 ) offset = - offset;
|
|
218
|
+
vAr[ id ] = ( v1x + v2x ) * 0.5 + n1n2x * offset;
|
|
219
|
+
vAr[ id + 1 ] = ( v1y + v2y ) * 0.5 + n1n2y * offset;
|
|
220
|
+
vAr[ id + 2 ] = ( v1z + v2z ) * 0.5 + n1n2z * offset;
|
|
221
|
+
|
|
222
|
+
vrv[ ivMid ] = [ iv1, iv2, iv3 ];
|
|
223
|
+
vrf[ ivMid ] = [ iTri, iNewTri ];
|
|
224
|
+
replaceElement( vrv[ iv1 ], iv2, ivMid );
|
|
225
|
+
replaceElement( vrv[ iv2 ], iv1, ivMid );
|
|
226
|
+
mesh.addNbVertice( 1 );
|
|
227
|
+
mesh.addNbFace( 1 );
|
|
228
|
+
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function subFindSplit( iTri, checkInsideSphere ) {
|
|
232
|
+
|
|
233
|
+
const mesh = SubData._mesh;
|
|
234
|
+
const vAr = mesh.getVertices();
|
|
235
|
+
const fAr = mesh.getFaces();
|
|
236
|
+
const id = iTri * 4;
|
|
237
|
+
const ind1 = fAr[ id ] * 3, ind2 = fAr[ id + 1 ] * 3, ind3 = fAr[ id + 2 ] * 3;
|
|
238
|
+
_subV1[ 0 ] = vAr[ ind1 ]; _subV1[ 1 ] = vAr[ ind1 + 1 ]; _subV1[ 2 ] = vAr[ ind1 + 2 ];
|
|
239
|
+
_subV2[ 0 ] = vAr[ ind2 ]; _subV2[ 1 ] = vAr[ ind2 + 1 ]; _subV2[ 2 ] = vAr[ ind2 + 2 ];
|
|
240
|
+
_subV3[ 0 ] = vAr[ ind3 ]; _subV3[ 1 ] = vAr[ ind3 + 1 ]; _subV3[ 2 ] = vAr[ ind3 + 2 ];
|
|
241
|
+
|
|
242
|
+
if ( checkInsideSphere && ! triangleInsideSphere( SubData._center, SubData._radius2, _subV1, _subV2, _subV3 ) )
|
|
243
|
+
return 0;
|
|
244
|
+
|
|
245
|
+
const length1 = sqrDist( _subV1, _subV2 ), length2 = sqrDist( _subV2, _subV3 ), length3 = sqrDist( _subV1, _subV3 );
|
|
246
|
+
if ( length1 > length2 && length1 > length3 ) return length1 > SubData._edgeMax2 ? 1 : 0;
|
|
247
|
+
else if ( length2 > length3 ) return length2 > SubData._edgeMax2 ? 2 : 0;
|
|
248
|
+
else return length3 > SubData._edgeMax2 ? 3 : 0;
|
|
249
|
+
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function subdivide( iTris ) {
|
|
253
|
+
|
|
254
|
+
const mesh = SubData._mesh;
|
|
255
|
+
const nbVertsInit = mesh.getNbVertices();
|
|
256
|
+
const nbTrisInit = mesh.getNbTriangles();
|
|
257
|
+
SubData._verticesMap.clear();
|
|
258
|
+
|
|
259
|
+
let nbTris = iTris.length;
|
|
260
|
+
const buffer = getMemory( ( 4 + 1 ) * nbTris );
|
|
261
|
+
let iTrisSubd = new Uint32Array( buffer, 0, nbTris );
|
|
262
|
+
let splitArr = new Uint8Array( buffer, 4 * nbTris, nbTris );
|
|
263
|
+
let acc = 0;
|
|
264
|
+
for ( let i = 0; i < nbTris; ++ i ) {
|
|
265
|
+
|
|
266
|
+
const iTri = iTris[ i ];
|
|
267
|
+
const splitNum = subFindSplit( iTri, true );
|
|
268
|
+
if ( splitNum === 0 ) continue;
|
|
269
|
+
splitArr[ acc ] = splitNum;
|
|
270
|
+
iTrisSubd[ acc ++ ] = iTri;
|
|
271
|
+
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if ( acc === 0 ) {
|
|
275
|
+
|
|
276
|
+
mesh.reAllocateArrays( 0 );
|
|
277
|
+
return iTris;
|
|
278
|
+
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
iTrisSubd = iTrisSubd.slice( 0, acc );
|
|
282
|
+
splitArr = splitArr.slice( 0, acc );
|
|
283
|
+
|
|
284
|
+
if ( iTrisSubd.length > 5 ) {
|
|
285
|
+
|
|
286
|
+
iTrisSubd = mesh.expandsFaces( iTrisSubd, 3 );
|
|
287
|
+
const newSplit = new Uint8Array( iTrisSubd.length );
|
|
288
|
+
newSplit.set( splitArr );
|
|
289
|
+
splitArr = newSplit;
|
|
290
|
+
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// Reserve one new vertex per selected triangle for collision-free edge keys.
|
|
294
|
+
// Pack vertex pairs into safe integers; use strings when the range is too large.
|
|
295
|
+
SubData._edgeKeyStride = mesh.getNbVertices() + iTrisSubd.length + 1;
|
|
296
|
+
SubData._stringEdgeKeys = SubData._edgeKeyStride > MAX_EDGE_KEY_STRIDE;
|
|
297
|
+
|
|
298
|
+
const fAr = mesh.getFaces();
|
|
299
|
+
mesh.reAllocateArrays( splitArr.length );
|
|
300
|
+
for ( let i = 0, l = iTrisSubd.length; i < l; ++ i ) {
|
|
301
|
+
|
|
302
|
+
const iTri = iTrisSubd[ i ];
|
|
303
|
+
let splitNum = splitArr[ i ];
|
|
304
|
+
if ( splitNum === 0 ) splitNum = subFindSplit( iTri );
|
|
305
|
+
const ind = iTri * 4;
|
|
306
|
+
if ( splitNum === 1 ) halfEdgeSplit( iTri, fAr[ ind ], fAr[ ind + 1 ], fAr[ ind + 2 ] );
|
|
307
|
+
else if ( splitNum === 2 ) halfEdgeSplit( iTri, fAr[ ind + 1 ], fAr[ ind + 2 ], fAr[ ind ] );
|
|
308
|
+
else if ( splitNum === 3 ) halfEdgeSplit( iTri, fAr[ ind + 2 ], fAr[ ind ], fAr[ ind + 1 ] );
|
|
309
|
+
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
let nbNewTris = mesh.getNbTriangles() - nbTrisInit;
|
|
313
|
+
let newTriangles = new Uint32Array( nbNewTris );
|
|
314
|
+
for ( let i = 0; i < nbNewTris; ++ i ) newTriangles[ i ] = nbTrisInit + i;
|
|
315
|
+
newTriangles = mesh.expandsFaces( newTriangles, 1 );
|
|
316
|
+
|
|
317
|
+
let temp = iTris;
|
|
318
|
+
nbTris = iTris.length;
|
|
319
|
+
iTris = new Uint32Array( nbTris + newTriangles.length );
|
|
320
|
+
iTris.set( temp );
|
|
321
|
+
iTris.set( newTriangles, nbTris );
|
|
322
|
+
|
|
323
|
+
const ftf = mesh.getFacesTagFlags();
|
|
324
|
+
const tagFlag = mesh.nextTagFlag();
|
|
325
|
+
const iTrisMask = new Uint32Array( getMemory( iTris.length * 4 ), 0, iTris.length );
|
|
326
|
+
let nbTriMask = 0;
|
|
327
|
+
for ( let i = 0, l = iTris.length; i < l; ++ i ) {
|
|
328
|
+
|
|
329
|
+
const iTri = iTris[ i ];
|
|
330
|
+
if ( ftf[ iTri ] === tagFlag ) continue;
|
|
331
|
+
ftf[ iTri ] = tagFlag;
|
|
332
|
+
iTrisMask[ nbTriMask ++ ] = iTri;
|
|
333
|
+
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
let resultTris = iTrisMask.slice( 0, nbTriMask );
|
|
337
|
+
|
|
338
|
+
// Split neighboring faces to close subdivision cracks.
|
|
339
|
+
const nbTrianglesOld = mesh.getNbTriangles();
|
|
340
|
+
while ( newTriangles.length > 0 ) {
|
|
341
|
+
|
|
342
|
+
mesh.reAllocateArrays( newTriangles.length );
|
|
343
|
+
newTriangles = subFillTriangles( newTriangles );
|
|
344
|
+
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
nbNewTris = mesh.getNbTriangles() - nbTrianglesOld;
|
|
348
|
+
temp = resultTris;
|
|
349
|
+
resultTris = new Uint32Array( nbTriMask + nbNewTris );
|
|
350
|
+
resultTris.set( temp );
|
|
351
|
+
for ( let i = 0; i < nbNewTris; ++ i ) resultTris[ nbTriMask + i ] = nbTrianglesOld + i;
|
|
352
|
+
|
|
353
|
+
// Smooth neighboring vertices before updating sculpt flags.
|
|
354
|
+
const nbVNew = mesh.getNbVertices() - nbVertsInit;
|
|
355
|
+
let vNew = new Uint32Array( nbVNew );
|
|
356
|
+
for ( let i = 0; i < nbVNew; ++ i ) vNew[ i ] = nbVertsInit + i;
|
|
357
|
+
vNew = mesh.expandsVertices( vNew, 1 );
|
|
358
|
+
|
|
359
|
+
const expV = vNew.subarray( nbVNew );
|
|
360
|
+
smoothTangentVerts( mesh, expV, 1.0 );
|
|
361
|
+
|
|
362
|
+
const vAr = mesh.getVertices();
|
|
363
|
+
const vscf = mesh.getVerticesSculptFlags();
|
|
364
|
+
const cx = SubData._center[ 0 ], cy = SubData._center[ 1 ], cz = SubData._center[ 2 ];
|
|
365
|
+
const sculptMask = mesh.getSculptFlag();
|
|
366
|
+
for ( let i = 0, l = vNew.length; i < l; ++ i ) {
|
|
367
|
+
|
|
368
|
+
const ind = vNew[ i ];
|
|
369
|
+
const j = ind * 3;
|
|
370
|
+
const dx = vAr[ j ] - cx, dy = vAr[ j + 1 ] - cy, dz = vAr[ j + 2 ] - cz;
|
|
371
|
+
vscf[ ind ] = ( dx * dx + dy * dy + dz * dz ) < SubData._radius2 ? sculptMask : sculptMask - 1;
|
|
372
|
+
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
return resultTris;
|
|
376
|
+
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function subdivisionPass( mesh, iTris, center, radius2, detail2 ) {
|
|
380
|
+
|
|
381
|
+
SubData._mesh = mesh;
|
|
382
|
+
SubData._center[ 0 ] = center[ 0 ]; SubData._center[ 1 ] = center[ 1 ]; SubData._center[ 2 ] = center[ 2 ];
|
|
383
|
+
SubData._radius2 = radius2;
|
|
384
|
+
SubData._edgeMax2 = detail2;
|
|
385
|
+
|
|
386
|
+
try {
|
|
387
|
+
|
|
388
|
+
let nbTriangles = 0;
|
|
389
|
+
while ( nbTriangles !== mesh.getNbTriangles() ) {
|
|
390
|
+
|
|
391
|
+
nbTriangles = mesh.getNbTriangles();
|
|
392
|
+
iTris = subdivide( iTris );
|
|
393
|
+
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return iTris;
|
|
397
|
+
|
|
398
|
+
} finally {
|
|
399
|
+
|
|
400
|
+
SubData._mesh = null;
|
|
401
|
+
SubData._verticesMap.clear();
|
|
402
|
+
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// Decimation
|
|
408
|
+
|
|
409
|
+
const DecData = {
|
|
410
|
+
_mesh: null,
|
|
411
|
+
_iTrisToDelete: [],
|
|
412
|
+
_iVertsToDelete: [],
|
|
413
|
+
_iVertsDecimated: []
|
|
414
|
+
};
|
|
415
|
+
const sortByIndex = ( a, b ) => a - b;
|
|
416
|
+
|
|
417
|
+
function hasAtLeastThreeCommonElements( a, b ) {
|
|
418
|
+
|
|
419
|
+
let ai = 0;
|
|
420
|
+
let bi = 0;
|
|
421
|
+
let count = 0;
|
|
422
|
+
|
|
423
|
+
while ( ai < a.length && bi < b.length ) {
|
|
424
|
+
|
|
425
|
+
if ( a[ ai ] < b[ bi ] ) ai ++;
|
|
426
|
+
else if ( a[ ai ] > b[ bi ] ) bi ++;
|
|
427
|
+
else {
|
|
428
|
+
|
|
429
|
+
if ( ++ count === 3 ) return true;
|
|
430
|
+
ai ++;
|
|
431
|
+
bi ++;
|
|
432
|
+
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
return false;
|
|
438
|
+
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function decDeleteTriangle( iTri ) {
|
|
442
|
+
|
|
443
|
+
const mesh = DecData._mesh;
|
|
444
|
+
const vrf = mesh.getVerticesRingFace();
|
|
445
|
+
const ftf = mesh.getFacesTagFlags();
|
|
446
|
+
const fAr = mesh.getFaces();
|
|
447
|
+
const pil = mesh.getFacePosInLeaf();
|
|
448
|
+
const fleaf = mesh.getFaceLeaf();
|
|
449
|
+
|
|
450
|
+
const oldPos = pil[ iTri ];
|
|
451
|
+
const iTrisLeaf = fleaf[ iTri ]._iFaces;
|
|
452
|
+
const lastTri = iTrisLeaf[ iTrisLeaf.length - 1 ];
|
|
453
|
+
if ( iTri !== lastTri ) {
|
|
454
|
+
|
|
455
|
+
iTrisLeaf[ oldPos ] = lastTri; pil[ lastTri ] = oldPos;
|
|
456
|
+
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
iTrisLeaf.pop();
|
|
460
|
+
|
|
461
|
+
const lastPos = mesh.getNbTriangles() - 1;
|
|
462
|
+
if ( lastPos === iTri ) {
|
|
463
|
+
|
|
464
|
+
fleaf.length = lastPos;
|
|
465
|
+
mesh.addNbFace( - 1 ); return;
|
|
466
|
+
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
const id = lastPos * 4;
|
|
470
|
+
const iv1 = fAr[ id ], iv2 = fAr[ id + 1 ], iv3 = fAr[ id + 2 ];
|
|
471
|
+
replaceElement( vrf[ iv1 ], lastPos, iTri );
|
|
472
|
+
replaceElement( vrf[ iv2 ], lastPos, iTri );
|
|
473
|
+
replaceElement( vrf[ iv3 ], lastPos, iTri );
|
|
474
|
+
|
|
475
|
+
const leafLast = fleaf[ lastPos ];
|
|
476
|
+
const pilLast = pil[ lastPos ];
|
|
477
|
+
leafLast._iFaces[ pilLast ] = iTri;
|
|
478
|
+
fleaf[ iTri ] = leafLast;
|
|
479
|
+
pil[ iTri ] = pilLast;
|
|
480
|
+
ftf[ iTri ] = ftf[ lastPos ];
|
|
481
|
+
const j = iTri * 4;
|
|
482
|
+
fAr[ j ] = iv1; fAr[ j + 1 ] = iv2; fAr[ j + 2 ] = iv3; fAr[ j + 3 ] = TRI_INDEX;
|
|
483
|
+
fleaf.length = lastPos;
|
|
484
|
+
DecData._iVertsDecimated.push( iv1, iv2, iv3 );
|
|
485
|
+
mesh.addNbFace( - 1 );
|
|
486
|
+
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
function decDeleteVertex( iVert ) {
|
|
490
|
+
|
|
491
|
+
const mesh = DecData._mesh;
|
|
492
|
+
const vrv = mesh.getVerticesRingVert();
|
|
493
|
+
const vrf = mesh.getVerticesRingFace();
|
|
494
|
+
const vAr = mesh.getVertices();
|
|
495
|
+
const nAr = mesh.getNormals();
|
|
496
|
+
const fAr = mesh.getFaces();
|
|
497
|
+
const vtf = mesh.getVerticesTagFlags();
|
|
498
|
+
const vsctf = mesh.getVerticesSculptFlags();
|
|
499
|
+
|
|
500
|
+
const lastPos = mesh.getNbVertices() - 1;
|
|
501
|
+
if ( iVert === lastPos ) {
|
|
502
|
+
|
|
503
|
+
vrv.length = lastPos;
|
|
504
|
+
vrf.length = lastPos;
|
|
505
|
+
mesh.addNbVertice( - 1 ); return;
|
|
506
|
+
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
const iTris = vrf[ lastPos ];
|
|
510
|
+
const ring = vrv[ lastPos ];
|
|
511
|
+
for ( let i = 0, l = iTris.length; i < l; ++ i ) {
|
|
512
|
+
|
|
513
|
+
const id = iTris[ i ] * 4;
|
|
514
|
+
if ( fAr[ id ] === lastPos ) fAr[ id ] = iVert;
|
|
515
|
+
else if ( fAr[ id + 1 ] === lastPos ) fAr[ id + 1 ] = iVert;
|
|
516
|
+
else fAr[ id + 2 ] = iVert;
|
|
517
|
+
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
for ( let i = 0, l = ring.length; i < l; ++ i ) replaceElement( vrv[ ring[ i ] ], lastPos, iVert );
|
|
521
|
+
|
|
522
|
+
vrv[ iVert ] = vrv[ lastPos ].slice();
|
|
523
|
+
vrf[ iVert ] = vrf[ lastPos ].slice();
|
|
524
|
+
vtf[ iVert ] = vtf[ lastPos ];
|
|
525
|
+
vsctf[ iVert ] = vsctf[ lastPos ];
|
|
526
|
+
const idLast = lastPos * 3, id = iVert * 3;
|
|
527
|
+
vAr[ id ] = vAr[ idLast ]; vAr[ id + 1 ] = vAr[ idLast + 1 ]; vAr[ id + 2 ] = vAr[ idLast + 2 ];
|
|
528
|
+
nAr[ id ] = nAr[ idLast ]; nAr[ id + 1 ] = nAr[ idLast + 1 ]; nAr[ id + 2 ] = nAr[ idLast + 2 ];
|
|
529
|
+
vrv.length = lastPos;
|
|
530
|
+
vrf.length = lastPos;
|
|
531
|
+
mesh.addNbVertice( - 1 );
|
|
532
|
+
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function decEdgeCollapse( iTri1, iTri2, iv1, iv2, ivOpp1, ivOpp2, iTris ) {
|
|
536
|
+
|
|
537
|
+
const mesh = DecData._mesh;
|
|
538
|
+
const vAr = mesh.getVertices();
|
|
539
|
+
const nAr = mesh.getNormals();
|
|
540
|
+
const fAr = mesh.getFaces();
|
|
541
|
+
const vtf = mesh.getVerticesTagFlags();
|
|
542
|
+
const ftf = mesh.getFacesTagFlags();
|
|
543
|
+
const vrv = mesh.getVerticesRingVert();
|
|
544
|
+
const vrf = mesh.getVerticesRingFace();
|
|
545
|
+
|
|
546
|
+
const ring1 = vrv[ iv1 ], ring2 = vrv[ iv2 ];
|
|
547
|
+
const tris1 = vrf[ iv1 ], tris2 = vrf[ iv2 ];
|
|
548
|
+
|
|
549
|
+
if ( ring1.length !== tris1.length || ring2.length !== tris2.length ) return;
|
|
550
|
+
const ringOpp1 = vrv[ ivOpp1 ], ringOpp2 = vrv[ ivOpp2 ];
|
|
551
|
+
const trisOpp1 = vrf[ ivOpp1 ], trisOpp2 = vrf[ ivOpp2 ];
|
|
552
|
+
if ( ringOpp1.length !== trisOpp1.length || ringOpp2.length !== trisOpp2.length ) return;
|
|
553
|
+
|
|
554
|
+
// A tetrahedron cannot collapse without leaving coincident triangles.
|
|
555
|
+
// Check local valence to protect disconnected shells.
|
|
556
|
+
if ( ring1.length === 3 && ring2.length === 3 ) return;
|
|
557
|
+
|
|
558
|
+
ring1.sort( sortByIndex );
|
|
559
|
+
ring2.sort( sortByIndex );
|
|
560
|
+
|
|
561
|
+
if ( hasAtLeastThreeCommonElements( ring1, ring2 ) ) {
|
|
562
|
+
|
|
563
|
+
// Skip existing diagonals: a flip would leave four triangles sharing an edge.
|
|
564
|
+
if ( ringOpp1.includes( ivOpp2 ) ) return;
|
|
565
|
+
DecData._iVertsDecimated.push( iv1, iv2 );
|
|
566
|
+
|
|
567
|
+
removeElement( tris1, iTri2 );
|
|
568
|
+
removeElement( tris2, iTri1 );
|
|
569
|
+
trisOpp1.push( iTri2 );
|
|
570
|
+
trisOpp2.push( iTri1 );
|
|
571
|
+
let id = iTri1 * 4;
|
|
572
|
+
if ( fAr[ id ] === iv2 ) fAr[ id ] = ivOpp2;
|
|
573
|
+
else if ( fAr[ id + 1 ] === iv2 ) fAr[ id + 1 ] = ivOpp2;
|
|
574
|
+
else fAr[ id + 2 ] = ivOpp2;
|
|
575
|
+
id = iTri2 * 4;
|
|
576
|
+
if ( fAr[ id ] === iv1 ) fAr[ id ] = ivOpp1;
|
|
577
|
+
else if ( fAr[ id + 1 ] === iv1 ) fAr[ id + 1 ] = ivOpp1;
|
|
578
|
+
else fAr[ id + 2 ] = ivOpp1;
|
|
579
|
+
mesh._computeRingVertices( iv1 );
|
|
580
|
+
mesh._computeRingVertices( iv2 );
|
|
581
|
+
mesh._computeRingVertices( ivOpp1 );
|
|
582
|
+
mesh._computeRingVertices( ivOpp2 );
|
|
583
|
+
mesh.markTopologyChanged();
|
|
584
|
+
return;
|
|
585
|
+
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
DecData._iVertsDecimated.push( iv1, iv2 );
|
|
589
|
+
|
|
590
|
+
const id = iv1 * 3;
|
|
591
|
+
const id2 = iv2 * 3;
|
|
592
|
+
let nx = nAr[ id ] + nAr[ id2 ], ny = nAr[ id + 1 ] + nAr[ id2 + 1 ], nz = nAr[ id + 2 ] + nAr[ id2 + 2 ];
|
|
593
|
+
let len = nx * nx + ny * ny + nz * nz;
|
|
594
|
+
if ( len === 0 ) {
|
|
595
|
+
|
|
596
|
+
nx = 1;
|
|
597
|
+
|
|
598
|
+
} else {
|
|
599
|
+
|
|
600
|
+
len = 1 / Math.sqrt( len ); nx *= len; ny *= len; nz *= len;
|
|
601
|
+
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
nAr[ id ] = nx; nAr[ id + 1 ] = ny; nAr[ id + 2 ] = nz;
|
|
605
|
+
|
|
606
|
+
removeElement( tris1, iTri1 ); removeElement( tris1, iTri2 );
|
|
607
|
+
removeElement( tris2, iTri1 ); removeElement( tris2, iTri2 );
|
|
608
|
+
removeElement( trisOpp1, iTri1 ); removeElement( trisOpp2, iTri2 );
|
|
609
|
+
|
|
610
|
+
for ( let i = 0, l = tris2.length; i < l; ++ i ) {
|
|
611
|
+
|
|
612
|
+
const tri2 = tris2[ i ];
|
|
613
|
+
tris1.push( tri2 );
|
|
614
|
+
const idx = tri2 * 4;
|
|
615
|
+
if ( fAr[ idx ] === iv2 ) fAr[ idx ] = iv1;
|
|
616
|
+
else if ( fAr[ idx + 1 ] === iv2 ) fAr[ idx + 1 ] = iv1;
|
|
617
|
+
else fAr[ idx + 2 ] = iv1;
|
|
618
|
+
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
for ( let i = 0, l = ring2.length; i < l; ++ i ) ring1.push( ring2[ i ] );
|
|
622
|
+
|
|
623
|
+
mesh._computeRingVertices( iv1 );
|
|
624
|
+
|
|
625
|
+
// Project the neighbor average onto the tangent plane.
|
|
626
|
+
let meanX = 0, meanY = 0, meanZ = 0;
|
|
627
|
+
const nbRing1 = ring1.length;
|
|
628
|
+
for ( let i = 0; i < nbRing1; ++ i ) {
|
|
629
|
+
|
|
630
|
+
const ivRing = ring1[ i ];
|
|
631
|
+
mesh._computeRingVertices( ivRing );
|
|
632
|
+
const ivr3 = ivRing * 3;
|
|
633
|
+
meanX += vAr[ ivr3 ]; meanY += vAr[ ivr3 + 1 ]; meanZ += vAr[ ivr3 + 2 ];
|
|
634
|
+
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
meanX /= nbRing1; meanY /= nbRing1; meanZ /= nbRing1;
|
|
638
|
+
const dotN = nx * ( meanX - vAr[ id ] ) + ny * ( meanY - vAr[ id + 1 ] ) + nz * ( meanZ - vAr[ id + 2 ] );
|
|
639
|
+
vAr[ id ] = meanX - nx * dotN;
|
|
640
|
+
vAr[ id + 1 ] = meanY - ny * dotN;
|
|
641
|
+
vAr[ id + 2 ] = meanZ - nz * dotN;
|
|
642
|
+
|
|
643
|
+
vtf[ iv2 ] = ftf[ iTri1 ] = ftf[ iTri2 ] = - 1;
|
|
644
|
+
DecData._iVertsToDelete.push( iv2 );
|
|
645
|
+
DecData._iTrisToDelete.push( iTri1, iTri2 );
|
|
646
|
+
|
|
647
|
+
for ( let i = 0, l = tris1.length; i < l; ++ i ) iTris.push( tris1[ i ] );
|
|
648
|
+
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
function decDecimateTriangles( iTri1, iTri2, iTris ) {
|
|
652
|
+
|
|
653
|
+
if ( iTri2 === - 1 ) return;
|
|
654
|
+
const fAr = DecData._mesh.getFaces();
|
|
655
|
+
const id1 = iTri1 * 4, id2 = iTri2 * 4;
|
|
656
|
+
const iv11 = fAr[ id1 ], iv21 = fAr[ id1 + 1 ], iv31 = fAr[ id1 + 2 ];
|
|
657
|
+
const iv12 = fAr[ id2 ], iv22 = fAr[ id2 + 1 ], iv32 = fAr[ id2 + 2 ];
|
|
658
|
+
|
|
659
|
+
if ( iv11 === iv12 ) {
|
|
660
|
+
|
|
661
|
+
if ( iv21 === iv32 ) decEdgeCollapse( iTri1, iTri2, iv11, iv21, iv31, iv22, iTris );
|
|
662
|
+
else decEdgeCollapse( iTri1, iTri2, iv11, iv31, iv21, iv32, iTris );
|
|
663
|
+
|
|
664
|
+
} else if ( iv11 === iv22 ) {
|
|
665
|
+
|
|
666
|
+
if ( iv21 === iv12 ) decEdgeCollapse( iTri1, iTri2, iv11, iv21, iv31, iv32, iTris );
|
|
667
|
+
else decEdgeCollapse( iTri1, iTri2, iv11, iv31, iv21, iv12, iTris );
|
|
668
|
+
|
|
669
|
+
} else if ( iv11 === iv32 ) {
|
|
670
|
+
|
|
671
|
+
if ( iv21 === iv22 ) decEdgeCollapse( iTri1, iTri2, iv11, iv21, iv31, iv12, iTris );
|
|
672
|
+
else decEdgeCollapse( iTri1, iTri2, iv11, iv31, iv21, iv22, iTris );
|
|
673
|
+
|
|
674
|
+
} else if ( iv21 === iv12 ) decEdgeCollapse( iTri1, iTri2, iv31, iv21, iv11, iv22, iTris );
|
|
675
|
+
else if ( iv21 === iv22 ) decEdgeCollapse( iTri1, iTri2, iv31, iv21, iv11, iv32, iTris );
|
|
676
|
+
else decEdgeCollapse( iTri1, iTri2, iv31, iv21, iv11, iv12, iTris );
|
|
677
|
+
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
function decFindOppositeTriangle( iTri, iv1, iv2 ) {
|
|
681
|
+
|
|
682
|
+
const vrf = DecData._mesh.getVerticesRingFace();
|
|
683
|
+
const iTris1 = vrf[ iv1 ];
|
|
684
|
+
const iTris2 = vrf[ iv2 ];
|
|
685
|
+
let count = 0;
|
|
686
|
+
let opposite = - 1;
|
|
687
|
+
|
|
688
|
+
for ( let i = 0, l = iTris1.length; i < l; ++ i ) {
|
|
689
|
+
|
|
690
|
+
const candidate = iTris1[ i ];
|
|
691
|
+
|
|
692
|
+
for ( let j = 0, jl = iTris2.length; j < jl; ++ j ) {
|
|
693
|
+
|
|
694
|
+
if ( candidate !== iTris2[ j ] ) continue;
|
|
695
|
+
|
|
696
|
+
count ++;
|
|
697
|
+
if ( candidate !== iTri ) opposite = candidate;
|
|
698
|
+
break;
|
|
699
|
+
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
return count === 2 ? opposite : - 1;
|
|
705
|
+
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
function decimationPass( mesh, iTris, center, radius2, detail2 ) {
|
|
709
|
+
|
|
710
|
+
DecData._mesh = mesh;
|
|
711
|
+
DecData._iVertsDecimated.length = 0;
|
|
712
|
+
DecData._iTrisToDelete.length = 0;
|
|
713
|
+
DecData._iVertsToDelete.length = 0;
|
|
714
|
+
|
|
715
|
+
try {
|
|
716
|
+
|
|
717
|
+
return decimate( mesh, iTris, center, radius2, detail2 );
|
|
718
|
+
|
|
719
|
+
} finally {
|
|
720
|
+
|
|
721
|
+
DecData._mesh = null;
|
|
722
|
+
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
function decimate( mesh, iTris, center, radius2, detail2 ) {
|
|
728
|
+
|
|
729
|
+
const radius = Math.sqrt( radius2 );
|
|
730
|
+
const ftf = mesh.getFacesTagFlags();
|
|
731
|
+
const vAr = mesh.getVertices();
|
|
732
|
+
const fAr = mesh.getFaces();
|
|
733
|
+
const cenx = center[ 0 ], ceny = center[ 1 ], cenz = center[ 2 ];
|
|
734
|
+
|
|
735
|
+
const nbInit = iTris.length;
|
|
736
|
+
const dynArr = new Array( nbInit );
|
|
737
|
+
for ( let i = 0; i < nbInit; ++ i ) dynArr[ i ] = iTris[ i ];
|
|
738
|
+
|
|
739
|
+
for ( let i = 0; i < dynArr.length; ++ i ) {
|
|
740
|
+
|
|
741
|
+
const iTri = dynArr[ i ];
|
|
742
|
+
if ( ftf[ iTri ] < 0 ) continue;
|
|
743
|
+
const id = iTri * 4;
|
|
744
|
+
const iv1 = fAr[ id ], iv2 = fAr[ id + 1 ], iv3 = fAr[ id + 2 ];
|
|
745
|
+
const ind1 = iv1 * 3, ind2 = iv2 * 3, ind3 = iv3 * 3;
|
|
746
|
+
const v1x = vAr[ ind1 ], v1y = vAr[ ind1 + 1 ], v1z = vAr[ ind1 + 2 ];
|
|
747
|
+
const v2x = vAr[ ind2 ], v2y = vAr[ ind2 + 1 ], v2z = vAr[ ind2 + 2 ];
|
|
748
|
+
const v3x = vAr[ ind3 ], v3y = vAr[ ind3 + 1 ], v3z = vAr[ ind3 + 2 ];
|
|
749
|
+
|
|
750
|
+
let dx = ( v1x + v2x + v3x ) / 3.0 - cenx;
|
|
751
|
+
let dy = ( v1y + v2y + v3y ) / 3.0 - ceny;
|
|
752
|
+
let dz = ( v1z + v2z + v3z ) / 3.0 - cenz;
|
|
753
|
+
let fallOff = dx * dx + dy * dy + dz * dz;
|
|
754
|
+
|
|
755
|
+
if ( fallOff < radius2 ) fallOff = 1.0;
|
|
756
|
+
else if ( fallOff < radius2 * 2.0 ) {
|
|
757
|
+
|
|
758
|
+
fallOff = ( Math.sqrt( fallOff ) - radius ) / ( radius * Math.SQRT2 - radius );
|
|
759
|
+
const f2 = fallOff * fallOff;
|
|
760
|
+
fallOff = 3.0 * f2 * f2 - 4.0 * f2 * fallOff + 1.0;
|
|
761
|
+
|
|
762
|
+
} else continue;
|
|
763
|
+
|
|
764
|
+
dx = v2x - v1x; dy = v2y - v1y; dz = v2z - v1z;
|
|
765
|
+
const len1 = dx * dx + dy * dy + dz * dz;
|
|
766
|
+
dx = v2x - v3x; dy = v2y - v3y; dz = v2z - v3z;
|
|
767
|
+
const len2 = dx * dx + dy * dy + dz * dz;
|
|
768
|
+
dx = v1x - v3x; dy = v1y - v3y; dz = v1z - v3z;
|
|
769
|
+
const len3 = dx * dx + dy * dy + dz * dz;
|
|
770
|
+
|
|
771
|
+
if ( len1 < len2 && len1 < len3 ) {
|
|
772
|
+
|
|
773
|
+
if ( len1 < detail2 * fallOff )
|
|
774
|
+
decDecimateTriangles( iTri, decFindOppositeTriangle( iTri, iv1, iv2 ), dynArr );
|
|
775
|
+
|
|
776
|
+
} else if ( len2 < len3 ) {
|
|
777
|
+
|
|
778
|
+
if ( len2 < detail2 * fallOff )
|
|
779
|
+
decDecimateTriangles( iTri, decFindOppositeTriangle( iTri, iv2, iv3 ), dynArr );
|
|
780
|
+
|
|
781
|
+
} else {
|
|
782
|
+
|
|
783
|
+
if ( len3 < detail2 * fallOff )
|
|
784
|
+
decDecimateTriangles( iTri, decFindOppositeTriangle( iTri, iv1, iv3 ), dynArr );
|
|
785
|
+
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
// Delete highest indices first so swaps preserve pending deletion indices.
|
|
791
|
+
tidy( DecData._iTrisToDelete );
|
|
792
|
+
for ( let i = DecData._iTrisToDelete.length - 1; i >= 0; -- i ) decDeleteTriangle( DecData._iTrisToDelete[ i ] );
|
|
793
|
+
tidy( DecData._iVertsToDelete );
|
|
794
|
+
for ( let i = DecData._iVertsToDelete.length - 1; i >= 0; -- i ) decDeleteVertex( DecData._iVertsToDelete[ i ] );
|
|
795
|
+
|
|
796
|
+
const iVertsDecimated = DecData._iVertsDecimated;
|
|
797
|
+
const nbVertices = mesh.getNbVertices();
|
|
798
|
+
const vtfDec = mesh.getVerticesTagFlags();
|
|
799
|
+
let tagFlag = mesh.nextTagFlag();
|
|
800
|
+
const validVertices = new Uint32Array( getMemory( iVertsDecimated.length * 4 ), 0, iVertsDecimated.length );
|
|
801
|
+
let nbValid = 0;
|
|
802
|
+
for ( let i = 0, l = iVertsDecimated.length; i < l; ++ i ) {
|
|
803
|
+
|
|
804
|
+
const iVert = iVertsDecimated[ i ];
|
|
805
|
+
if ( iVert >= nbVertices || vtfDec[ iVert ] === tagFlag ) continue;
|
|
806
|
+
vtfDec[ iVert ] = tagFlag;
|
|
807
|
+
validVertices[ nbValid ++ ] = iVert;
|
|
808
|
+
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
const newTris = mesh.getFacesFromVertices( validVertices.slice( 0, nbValid ) );
|
|
812
|
+
const nbTris = dynArr.length;
|
|
813
|
+
const nbCombined = nbTris + newTris.length;
|
|
814
|
+
|
|
815
|
+
tagFlag = mesh.nextTagFlag();
|
|
816
|
+
const nbTriangles = mesh.getNbTriangles();
|
|
817
|
+
const validTris = new Uint32Array( getMemory( nbCombined * 4 ), 0, nbCombined );
|
|
818
|
+
let nbValidTris = 0;
|
|
819
|
+
for ( let i = 0; i < nbCombined; ++ i ) {
|
|
820
|
+
|
|
821
|
+
const t = i < nbTris ? dynArr[ i ] : newTris[ i - nbTris ];
|
|
822
|
+
if ( t >= nbTriangles || ftf[ t ] === tagFlag ) continue;
|
|
823
|
+
ftf[ t ] = tagFlag;
|
|
824
|
+
validTris[ nbValidTris ++ ] = t;
|
|
825
|
+
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
return validTris.slice( 0, nbValidTris );
|
|
829
|
+
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
// Tool helpers
|
|
833
|
+
|
|
834
|
+
function laplacianSmooth( mesh, iVerts, smoothVerts, vField ) {
|
|
835
|
+
|
|
836
|
+
const vrings = mesh.getVerticesRingVert();
|
|
837
|
+
const vertOnEdge = mesh.getVerticesOnEdge();
|
|
838
|
+
const vAr = vField || mesh.getVertices();
|
|
839
|
+
const nbVerts = iVerts.length;
|
|
840
|
+
|
|
841
|
+
for ( let i = 0; i < nbVerts; ++ i ) {
|
|
842
|
+
|
|
843
|
+
const i3 = i * 3;
|
|
844
|
+
const id = iVerts[ i ];
|
|
845
|
+
const ring = vrings[ id ];
|
|
846
|
+
const vcount = ring.length;
|
|
847
|
+
if ( vcount <= 2 ) {
|
|
848
|
+
|
|
849
|
+
const idv = id * 3;
|
|
850
|
+
smoothVerts[ i3 ] = vAr[ idv ]; smoothVerts[ i3 + 1 ] = vAr[ idv + 1 ]; smoothVerts[ i3 + 2 ] = vAr[ idv + 2 ];
|
|
851
|
+
continue;
|
|
852
|
+
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
let avx = 0, avy = 0, avz = 0;
|
|
856
|
+
if ( vertOnEdge[ id ] === 1 ) {
|
|
857
|
+
|
|
858
|
+
let nbVertEdge = 0;
|
|
859
|
+
for ( let j = 0, l = vcount; j < l; ++ j ) {
|
|
860
|
+
|
|
861
|
+
const idv = ring[ j ];
|
|
862
|
+
if ( vertOnEdge[ idv ] === 1 ) {
|
|
863
|
+
|
|
864
|
+
const idv3 = idv * 3;
|
|
865
|
+
avx += vAr[ idv3 ]; avy += vAr[ idv3 + 1 ]; avz += vAr[ idv3 + 2 ];
|
|
866
|
+
++ nbVertEdge;
|
|
867
|
+
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
if ( nbVertEdge >= 2 ) {
|
|
873
|
+
|
|
874
|
+
smoothVerts[ i3 ] = avx / nbVertEdge; smoothVerts[ i3 + 1 ] = avy / nbVertEdge; smoothVerts[ i3 + 2 ] = avz / nbVertEdge;
|
|
875
|
+
continue;
|
|
876
|
+
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
avx = avy = avz = 0;
|
|
880
|
+
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
for ( let j = 0; j < vcount; ++ j ) {
|
|
884
|
+
|
|
885
|
+
const idv = ring[ j ] * 3;
|
|
886
|
+
avx += vAr[ idv ]; avy += vAr[ idv + 1 ]; avz += vAr[ idv + 2 ];
|
|
887
|
+
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
smoothVerts[ i3 ] = avx / vcount; smoothVerts[ i3 + 1 ] = avy / vcount; smoothVerts[ i3 + 2 ] = avz / vcount;
|
|
891
|
+
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
function smoothTangentVerts( mesh, iVerts, strength ) {
|
|
897
|
+
|
|
898
|
+
const vAr = mesh.getVertices();
|
|
899
|
+
const nAr = mesh.getNormals();
|
|
900
|
+
const intensity = Math.min( strength, 1.0 );
|
|
901
|
+
const nbVerts = iVerts.length;
|
|
902
|
+
const smoothVerts = new Float32Array( getMemory( nbVerts * 4 * 3 ), 0, nbVerts * 3 );
|
|
903
|
+
laplacianSmooth( mesh, iVerts, smoothVerts );
|
|
904
|
+
for ( let i = 0; i < nbVerts; ++ i ) {
|
|
905
|
+
|
|
906
|
+
const ind = iVerts[ i ] * 3;
|
|
907
|
+
const vx = vAr[ ind ], vy = vAr[ ind + 1 ], vz = vAr[ ind + 2 ];
|
|
908
|
+
let nx = nAr[ ind ], ny = nAr[ ind + 1 ], nz = nAr[ ind + 2 ];
|
|
909
|
+
let len = nx * nx + ny * ny + nz * nz;
|
|
910
|
+
if ( len === 0 ) continue;
|
|
911
|
+
len = 1 / Math.sqrt( len );
|
|
912
|
+
nx *= len; ny *= len; nz *= len;
|
|
913
|
+
const i3 = i * 3;
|
|
914
|
+
const smx = smoothVerts[ i3 ], smy = smoothVerts[ i3 + 1 ], smz = smoothVerts[ i3 + 2 ];
|
|
915
|
+
const d = nx * ( smx - vx ) + ny * ( smy - vy ) + nz * ( smz - vz );
|
|
916
|
+
vAr[ ind ] = vx + ( smx - nx * d - vx ) * intensity;
|
|
917
|
+
vAr[ ind + 1 ] = vy + ( smy - ny * d - vy ) * intensity;
|
|
918
|
+
vAr[ ind + 2 ] = vz + ( smz - nz * d - vz ) * intensity;
|
|
919
|
+
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
function getFrontVertices( mesh, iVertsInRadius, eyeDir ) {
|
|
925
|
+
|
|
926
|
+
const nbVerts = iVertsInRadius.length;
|
|
927
|
+
const iVertsFront = new Uint32Array( getMemory( 4 * nbVerts ), 0, nbVerts );
|
|
928
|
+
let acc = 0;
|
|
929
|
+
const nAr = mesh.getNormals();
|
|
930
|
+
const ex = eyeDir[ 0 ], ey = eyeDir[ 1 ], ez = eyeDir[ 2 ];
|
|
931
|
+
for ( let i = 0; i < nbVerts; ++ i ) {
|
|
932
|
+
|
|
933
|
+
const id = iVertsInRadius[ i ];
|
|
934
|
+
const j = id * 3;
|
|
935
|
+
if ( nAr[ j ] * ex + nAr[ j + 1 ] * ey + nAr[ j + 2 ] * ez <= 0 ) iVertsFront[ acc ++ ] = id;
|
|
936
|
+
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
return iVertsFront.slice( 0, acc );
|
|
940
|
+
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
function areaNormal( mesh, iVerts ) {
|
|
944
|
+
|
|
945
|
+
const nAr = mesh.getNormals();
|
|
946
|
+
let anx = 0, any = 0, anz = 0;
|
|
947
|
+
for ( let i = 0, l = iVerts.length; i < l; ++ i ) {
|
|
948
|
+
|
|
949
|
+
const ind = iVerts[ i ] * 3;
|
|
950
|
+
anx += nAr[ ind ]; any += nAr[ ind + 1 ]; anz += nAr[ ind + 2 ];
|
|
951
|
+
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
const len = Math.sqrt( anx * anx + any * any + anz * anz );
|
|
955
|
+
if ( len === 0 ) return null;
|
|
956
|
+
const inv = 1.0 / len;
|
|
957
|
+
return [ anx * inv, any * inv, anz * inv ];
|
|
958
|
+
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
function areaCenter( mesh, iVerts ) {
|
|
962
|
+
|
|
963
|
+
const vAr = mesh.getVertices();
|
|
964
|
+
let ax = 0, ay = 0, az = 0;
|
|
965
|
+
const acc = iVerts.length;
|
|
966
|
+
for ( let i = 0, l = iVerts.length; i < l; ++ i ) {
|
|
967
|
+
|
|
968
|
+
const ind = iVerts[ i ] * 3;
|
|
969
|
+
ax += vAr[ ind ]; ay += vAr[ ind + 1 ]; az += vAr[ ind + 2 ];
|
|
970
|
+
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
return [ ax / acc, ay / acc, az / acc ];
|
|
974
|
+
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
// Tools
|
|
978
|
+
|
|
979
|
+
function toolBrush( mesh, iVerts, aNormal, center, radiusSq, strength, negative ) {
|
|
980
|
+
|
|
981
|
+
const vAr = mesh.getVertices();
|
|
982
|
+
const radius = Math.sqrt( radiusSq );
|
|
983
|
+
let deform = strength * radius * 0.1;
|
|
984
|
+
if ( negative ) deform = - deform;
|
|
985
|
+
const cx = center[ 0 ], cy = center[ 1 ], cz = center[ 2 ];
|
|
986
|
+
const anx = aNormal[ 0 ], any = aNormal[ 1 ], anz = aNormal[ 2 ];
|
|
987
|
+
for ( let i = 0, l = iVerts.length; i < l; ++ i ) {
|
|
988
|
+
|
|
989
|
+
const ind = iVerts[ i ] * 3;
|
|
990
|
+
const dx = vAr[ ind ] - cx, dy = vAr[ ind + 1 ] - cy, dz = vAr[ ind + 2 ] - cz;
|
|
991
|
+
const dist = Math.sqrt( dx * dx + dy * dy + dz * dz ) / radius;
|
|
992
|
+
if ( dist >= 1.0 ) continue;
|
|
993
|
+
const fallOff = falloff( dist ) * deform;
|
|
994
|
+
vAr[ ind ] += anx * fallOff;
|
|
995
|
+
vAr[ ind + 1 ] += any * fallOff;
|
|
996
|
+
vAr[ ind + 2 ] += anz * fallOff;
|
|
997
|
+
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
function toolFlatten( mesh, iVerts, aNormal, aCenter2, center, radiusSq, strength, negative ) {
|
|
1003
|
+
|
|
1004
|
+
const vAr = mesh.getVertices();
|
|
1005
|
+
const radius = Math.sqrt( radiusSq );
|
|
1006
|
+
const cx = center[ 0 ], cy = center[ 1 ], cz = center[ 2 ];
|
|
1007
|
+
const ax = aCenter2[ 0 ], ay = aCenter2[ 1 ], az = aCenter2[ 2 ];
|
|
1008
|
+
const anx = aNormal[ 0 ], any = aNormal[ 1 ], anz = aNormal[ 2 ];
|
|
1009
|
+
const comp = negative ? - 1 : 1;
|
|
1010
|
+
for ( let i = 0, l = iVerts.length; i < l; ++ i ) {
|
|
1011
|
+
|
|
1012
|
+
const ind = iVerts[ i ] * 3;
|
|
1013
|
+
const vx = vAr[ ind ], vy = vAr[ ind + 1 ], vz = vAr[ ind + 2 ];
|
|
1014
|
+
const distToPlane = ( vx - ax ) * anx + ( vy - ay ) * any + ( vz - az ) * anz;
|
|
1015
|
+
if ( distToPlane * comp > 0 ) continue;
|
|
1016
|
+
const dx = vx - cx, dy = vy - cy, dz = vz - cz;
|
|
1017
|
+
const dist = Math.sqrt( dx * dx + dy * dy + dz * dz ) / radius;
|
|
1018
|
+
if ( dist >= 1.0 ) continue;
|
|
1019
|
+
const fallOff = falloff( dist ) * distToPlane * strength;
|
|
1020
|
+
vAr[ ind ] -= anx * fallOff;
|
|
1021
|
+
vAr[ ind + 1 ] -= any * fallOff;
|
|
1022
|
+
vAr[ ind + 2 ] -= anz * fallOff;
|
|
1023
|
+
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
function toolInflate( mesh, iVerts, center, radiusSq, strength, negative ) {
|
|
1029
|
+
|
|
1030
|
+
const vAr = mesh.getVertices();
|
|
1031
|
+
const nAr = mesh.getNormals();
|
|
1032
|
+
const radius = Math.sqrt( radiusSq );
|
|
1033
|
+
let deform = strength * radius * 0.1;
|
|
1034
|
+
if ( negative ) deform = - deform;
|
|
1035
|
+
const cx = center[ 0 ], cy = center[ 1 ], cz = center[ 2 ];
|
|
1036
|
+
for ( let i = 0, l = iVerts.length; i < l; ++ i ) {
|
|
1037
|
+
|
|
1038
|
+
const ind = iVerts[ i ] * 3;
|
|
1039
|
+
const dx = vAr[ ind ] - cx, dy = vAr[ ind + 1 ] - cy, dz = vAr[ ind + 2 ] - cz;
|
|
1040
|
+
const dist = Math.sqrt( dx * dx + dy * dy + dz * dz ) / radius;
|
|
1041
|
+
if ( dist >= 1.0 ) continue;
|
|
1042
|
+
let fallOff = falloff( dist ) * deform;
|
|
1043
|
+
const nx = nAr[ ind ], ny = nAr[ ind + 1 ], nz = nAr[ ind + 2 ];
|
|
1044
|
+
const nLen = Math.sqrt( nx * nx + ny * ny + nz * nz );
|
|
1045
|
+
if ( nLen > 0 ) fallOff /= nLen;
|
|
1046
|
+
vAr[ ind ] += nx * fallOff;
|
|
1047
|
+
vAr[ ind + 1 ] += ny * fallOff;
|
|
1048
|
+
vAr[ ind + 2 ] += nz * fallOff;
|
|
1049
|
+
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
function toolSmooth( mesh, iVerts, strength ) {
|
|
1055
|
+
|
|
1056
|
+
const vAr = mesh.getVertices();
|
|
1057
|
+
const intensity = Math.min( strength, 1.0 );
|
|
1058
|
+
const intComp = 1.0 - intensity;
|
|
1059
|
+
const nbVerts = iVerts.length;
|
|
1060
|
+
const smoothVerts = new Float32Array( getMemory( nbVerts * 4 * 3 ), 0, nbVerts * 3 );
|
|
1061
|
+
laplacianSmooth( mesh, iVerts, smoothVerts );
|
|
1062
|
+
for ( let i = 0; i < nbVerts; ++ i ) {
|
|
1063
|
+
|
|
1064
|
+
const ind = iVerts[ i ] * 3;
|
|
1065
|
+
const vx = vAr[ ind ], vy = vAr[ ind + 1 ], vz = vAr[ ind + 2 ];
|
|
1066
|
+
const i3 = i * 3;
|
|
1067
|
+
vAr[ ind ] = vx * intComp + smoothVerts[ i3 ] * intensity;
|
|
1068
|
+
vAr[ ind + 1 ] = vy * intComp + smoothVerts[ i3 + 1 ] * intensity;
|
|
1069
|
+
vAr[ ind + 2 ] = vz * intComp + smoothVerts[ i3 + 2 ] * intensity;
|
|
1070
|
+
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
function toolPinch( mesh, iVerts, center, radiusSq, strength, negative ) {
|
|
1076
|
+
|
|
1077
|
+
const vAr = mesh.getVertices();
|
|
1078
|
+
const radius = Math.sqrt( radiusSq );
|
|
1079
|
+
const cx = center[ 0 ], cy = center[ 1 ], cz = center[ 2 ];
|
|
1080
|
+
let deform = strength * 0.05;
|
|
1081
|
+
if ( negative ) deform = - deform;
|
|
1082
|
+
for ( let i = 0, l = iVerts.length; i < l; ++ i ) {
|
|
1083
|
+
|
|
1084
|
+
const ind = iVerts[ i ] * 3;
|
|
1085
|
+
const vx = vAr[ ind ], vy = vAr[ ind + 1 ], vz = vAr[ ind + 2 ];
|
|
1086
|
+
const dx = cx - vx, dy = cy - vy, dz = cz - vz;
|
|
1087
|
+
const dist = Math.sqrt( dx * dx + dy * dy + dz * dz ) / radius;
|
|
1088
|
+
const fallOff = falloff( dist ) * deform;
|
|
1089
|
+
vAr[ ind ] = vx + dx * fallOff;
|
|
1090
|
+
vAr[ ind + 1 ] = vy + dy * fallOff;
|
|
1091
|
+
vAr[ ind + 2 ] = vz + dz * fallOff;
|
|
1092
|
+
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
function toolCrease( mesh, iVerts, aNormal, center, radiusSq, strength, negative ) {
|
|
1098
|
+
|
|
1099
|
+
const vAr = mesh.getVertices();
|
|
1100
|
+
const radius = Math.sqrt( radiusSq );
|
|
1101
|
+
const cx = center[ 0 ], cy = center[ 1 ], cz = center[ 2 ];
|
|
1102
|
+
const anx = aNormal[ 0 ], any = aNormal[ 1 ], anz = aNormal[ 2 ];
|
|
1103
|
+
const deform = strength * 0.07;
|
|
1104
|
+
let brushFactor = deform * radius;
|
|
1105
|
+
if ( negative ) brushFactor = - brushFactor;
|
|
1106
|
+
for ( let i = 0, l = iVerts.length; i < l; ++ i ) {
|
|
1107
|
+
|
|
1108
|
+
const ind = iVerts[ i ] * 3;
|
|
1109
|
+
const dx = cx - vAr[ ind ], dy = cy - vAr[ ind + 1 ], dz = cz - vAr[ ind + 2 ];
|
|
1110
|
+
const dist = Math.sqrt( dx * dx + dy * dy + dz * dz ) / radius;
|
|
1111
|
+
if ( dist >= 1.0 ) continue;
|
|
1112
|
+
const vx = vAr[ ind ], vy = vAr[ ind + 1 ], vz = vAr[ ind + 2 ];
|
|
1113
|
+
const fallOff = falloff( dist );
|
|
1114
|
+
const brushMod = Math.pow( fallOff, 5 ) * brushFactor;
|
|
1115
|
+
const pinchF = fallOff * deform;
|
|
1116
|
+
vAr[ ind ] = vx + dx * pinchF + anx * brushMod;
|
|
1117
|
+
vAr[ ind + 1 ] = vy + dy * pinchF + any * brushMod;
|
|
1118
|
+
vAr[ ind + 2 ] = vz + dz * pinchF + anz * brushMod;
|
|
1119
|
+
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
function toolDrag( mesh, iVerts, center, radiusSq, dragDir ) {
|
|
1125
|
+
|
|
1126
|
+
const vAr = mesh.getVertices();
|
|
1127
|
+
const radius = Math.sqrt( radiusSq );
|
|
1128
|
+
const cx = center[ 0 ], cy = center[ 1 ], cz = center[ 2 ];
|
|
1129
|
+
const dirx = dragDir[ 0 ], diry = dragDir[ 1 ], dirz = dragDir[ 2 ];
|
|
1130
|
+
for ( let i = 0, l = iVerts.length; i < l; ++ i ) {
|
|
1131
|
+
|
|
1132
|
+
const ind = iVerts[ i ] * 3;
|
|
1133
|
+
const vx = vAr[ ind ], vy = vAr[ ind + 1 ], vz = vAr[ ind + 2 ];
|
|
1134
|
+
const dx = vx - cx, dy = vy - cy, dz = vz - cz;
|
|
1135
|
+
const dist = Math.sqrt( dx * dx + dy * dy + dz * dz ) / radius;
|
|
1136
|
+
const fallOff = falloff( dist );
|
|
1137
|
+
vAr[ ind ] = vx + dirx * fallOff;
|
|
1138
|
+
vAr[ ind + 1 ] = vy + diry * fallOff;
|
|
1139
|
+
vAr[ ind + 2 ] = vz + dirz * fallOff;
|
|
1140
|
+
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
function toolScale( mesh, iVerts, center, radiusSq, deltaScale ) {
|
|
1146
|
+
|
|
1147
|
+
const vAr = mesh.getVertices();
|
|
1148
|
+
const radius = Math.sqrt( radiusSq );
|
|
1149
|
+
const cx = center[ 0 ], cy = center[ 1 ], cz = center[ 2 ];
|
|
1150
|
+
const scale = deltaScale * 0.01;
|
|
1151
|
+
for ( let i = 0, l = iVerts.length; i < l; ++ i ) {
|
|
1152
|
+
|
|
1153
|
+
const ind = iVerts[ i ] * 3;
|
|
1154
|
+
const vx = vAr[ ind ], vy = vAr[ ind + 1 ], vz = vAr[ ind + 2 ];
|
|
1155
|
+
const dx = vx - cx, dy = vy - cy, dz = vz - cz;
|
|
1156
|
+
const dist = Math.sqrt( dx * dx + dy * dy + dz * dz ) / radius;
|
|
1157
|
+
const fallOff = falloff( dist ) * scale;
|
|
1158
|
+
vAr[ ind ] = vx + dx * fallOff;
|
|
1159
|
+
vAr[ ind + 1 ] = vy + dy * fallOff;
|
|
1160
|
+
vAr[ ind + 2 ] = vz + dz * fallOff;
|
|
1161
|
+
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
export {
|
|
1167
|
+
subdivisionPass,
|
|
1168
|
+
decimationPass,
|
|
1169
|
+
getFrontVertices,
|
|
1170
|
+
areaNormal,
|
|
1171
|
+
areaCenter,
|
|
1172
|
+
toolBrush,
|
|
1173
|
+
toolFlatten,
|
|
1174
|
+
toolInflate,
|
|
1175
|
+
toolSmooth,
|
|
1176
|
+
toolPinch,
|
|
1177
|
+
toolCrease,
|
|
1178
|
+
toolDrag,
|
|
1179
|
+
toolScale
|
|
1180
|
+
};
|