@plastic-software/three 0.167.4 → 0.174.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/LICENSE +1 -1
- package/README.md +1 -1
- package/build/three.cjs +36217 -23964
- package/build/three.core.js +48830 -0
- package/build/three.core.min.js +6 -0
- package/build/three.module.js +10175 -46744
- package/build/three.module.min.js +2 -3
- package/build/three.tsl.js +550 -0
- package/build/three.tsl.min.js +6 -0
- package/build/three.webgpu.js +44348 -50671
- package/build/three.webgpu.min.js +2 -3
- package/build/three.webgpu.nodes.js +70301 -0
- package/build/three.webgpu.nodes.min.js +6 -0
- package/examples/jsm/Addons.js +3 -15
- package/examples/jsm/animation/AnimationClipCreator.js +1 -1
- package/examples/jsm/animation/CCDIKSolver.js +61 -11
- package/examples/jsm/capabilities/WebGL.js +27 -21
- package/examples/jsm/capabilities/WebGPU.js +1 -10
- package/examples/jsm/controls/ArcballControls.js +262 -231
- package/examples/jsm/controls/DragControls.js +1 -1
- package/examples/jsm/controls/FirstPersonControls.js +175 -163
- package/examples/jsm/controls/FlyControls.js +194 -188
- package/examples/jsm/controls/OrbitControls.js +801 -777
- package/examples/jsm/controls/PointerLockControls.js +26 -20
- package/examples/jsm/controls/TrackballControls.js +469 -448
- package/examples/jsm/controls/TransformControls.js +119 -68
- package/examples/jsm/csm/CSM.js +2 -2
- package/examples/jsm/csm/CSMFrustum.js +7 -4
- package/examples/jsm/csm/CSMHelper.js +2 -0
- package/examples/jsm/csm/CSMShadowNode.js +442 -0
- package/examples/jsm/curves/NURBSCurve.js +33 -2
- package/examples/jsm/curves/NURBSUtils.js +3 -0
- package/examples/jsm/effects/AnaglyphEffect.js +6 -13
- package/examples/jsm/effects/OutlineEffect.js +1 -1
- package/examples/jsm/effects/ParallaxBarrierEffect.js +17 -11
- package/examples/jsm/effects/StereoEffect.js +6 -1
- package/examples/jsm/exporters/DRACOExporter.js +4 -2
- package/examples/jsm/exporters/EXRExporter.js +19 -11
- package/examples/jsm/exporters/GLTFExporter.js +181 -109
- package/examples/jsm/exporters/KTX2Exporter.js +54 -23
- package/examples/jsm/exporters/OBJExporter.js +5 -1
- package/examples/jsm/exporters/PLYExporter.js +11 -9
- package/examples/jsm/exporters/USDZExporter.js +50 -11
- package/examples/jsm/geometries/DecalGeometry.js +73 -21
- package/examples/jsm/geometries/TextGeometry.js +1 -12
- package/examples/jsm/helpers/LightProbeHelper.js +43 -44
- package/examples/jsm/helpers/LightProbeHelperGPU.js +65 -0
- package/examples/jsm/helpers/TextureHelperGPU.js +185 -0
- package/examples/jsm/helpers/VertexNormalsHelper.js +2 -0
- package/examples/jsm/interactive/HTMLMesh.js +1 -0
- package/examples/jsm/interactive/InteractiveGroup.js +108 -51
- package/examples/jsm/interactive/SelectionHelper.js +3 -1
- package/examples/jsm/libs/basis/basis_transcoder.js +8 -10
- package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
- package/examples/jsm/libs/demuxer_mp4.js +109 -0
- package/examples/jsm/libs/ktx-parse.module.js +1 -1
- package/examples/jsm/lighting/TiledLighting.js +18 -0
- package/examples/jsm/lights/LightProbeGenerator.js +26 -12
- package/examples/jsm/lights/RectAreaLightTexturesLib.js +1 -1
- package/examples/jsm/lines/LineGeometry.js +25 -0
- package/examples/jsm/lines/LineMaterial.js +0 -1
- package/examples/jsm/lines/LineSegmentsGeometry.js +2 -0
- package/examples/jsm/lines/webgpu/Line2.js +2 -1
- package/examples/jsm/lines/webgpu/LineSegments2.js +16 -21
- package/examples/jsm/lines/webgpu/Wireframe.js +57 -0
- package/examples/jsm/loaders/3DMLoader.js +1 -0
- package/examples/jsm/loaders/3MFLoader.js +104 -2
- package/examples/jsm/loaders/BVHLoader.js +1 -1
- package/examples/jsm/loaders/ColladaLoader.js +15 -12
- package/examples/jsm/loaders/DDSLoader.js +42 -0
- package/examples/jsm/loaders/DRACOLoader.js +3 -1
- package/examples/jsm/loaders/FBXLoader.js +71 -22
- package/examples/jsm/loaders/GCodeLoader.js +4 -2
- package/examples/jsm/loaders/GLTFLoader.js +29 -14
- package/examples/jsm/loaders/KTX2Loader.js +160 -58
- package/examples/jsm/loaders/KTXLoader.js +4 -4
- package/examples/jsm/loaders/LDrawLoader.js +22 -136
- package/examples/jsm/loaders/LottieLoader.js +2 -1
- package/examples/jsm/loaders/MTLLoader.js +27 -7
- package/examples/jsm/loaders/MaterialXLoader.js +40 -14
- package/examples/jsm/loaders/NRRDLoader.js +1 -1
- package/examples/jsm/loaders/OBJLoader.js +5 -3
- package/examples/jsm/loaders/PCDLoader.js +14 -13
- package/examples/jsm/loaders/PDBLoader.js +3 -2
- package/examples/jsm/loaders/PLYLoader.js +15 -12
- package/examples/jsm/loaders/PVRLoader.js +1 -1
- package/examples/jsm/loaders/STLLoader.js +3 -2
- package/examples/jsm/loaders/SVGLoader.js +2 -2
- package/examples/jsm/loaders/TDSLoader.js +17 -18
- package/examples/jsm/loaders/VRMLLoader.js +17 -17
- package/examples/jsm/loaders/VTKLoader.js +4 -3
- package/examples/jsm/loaders/XYZLoader.js +3 -2
- package/examples/jsm/loaders/lwo/IFFParser.js +4 -4
- package/examples/jsm/materials/LDrawConditionalLineMaterial.js +143 -0
- package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +114 -0
- package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
- package/examples/jsm/math/ColorSpaces.js +76 -0
- package/examples/jsm/math/ConvexHull.js +1 -1
- package/examples/jsm/math/OBB.js +17 -0
- package/examples/jsm/misc/GPUComputationRenderer.js +6 -7
- package/examples/jsm/misc/ProgressiveLightMap.js +54 -41
- package/examples/jsm/misc/ProgressiveLightMapGPU.js +294 -0
- package/examples/jsm/misc/Timer.js +27 -12
- package/examples/jsm/misc/Volume.js +28 -18
- package/examples/jsm/misc/VolumeSlice.js +19 -16
- package/examples/jsm/modifiers/CurveModifier.js +10 -8
- package/examples/jsm/modifiers/CurveModifierGPU.js +235 -0
- package/examples/jsm/modifiers/SimplifyModifier.js +2 -2
- package/examples/jsm/objects/GroundedSkybox.js +4 -4
- package/examples/jsm/objects/LensflareMesh.js +324 -0
- package/examples/jsm/objects/Reflector.js +5 -2
- package/examples/jsm/objects/Sky.js +2 -2
- package/examples/jsm/objects/SkyMesh.js +14 -14
- package/examples/jsm/objects/Water2.js +1 -1
- package/examples/jsm/objects/Water2Mesh.js +11 -9
- package/examples/jsm/objects/WaterMesh.js +38 -33
- package/examples/jsm/physics/JoltPhysics.js +8 -8
- package/examples/jsm/physics/RapierPhysics.js +5 -5
- package/examples/jsm/postprocessing/AfterimagePass.js +14 -3
- package/examples/jsm/postprocessing/BloomPass.js +2 -2
- package/examples/jsm/postprocessing/EffectComposer.js +1 -2
- package/examples/jsm/postprocessing/OutlinePass.js +37 -51
- package/examples/jsm/postprocessing/OutputPass.js +2 -0
- package/examples/jsm/postprocessing/SAOPass.js +1 -2
- package/examples/jsm/postprocessing/SMAAPass.js +1 -3
- package/examples/jsm/postprocessing/SSAARenderPass.js +3 -1
- package/examples/jsm/postprocessing/SSAOPass.js +2 -4
- package/examples/jsm/postprocessing/SSRPass.js +8 -4
- package/examples/jsm/postprocessing/UnrealBloomPass.js +2 -2
- package/examples/jsm/renderers/CSS2DRenderer.js +6 -3
- package/examples/jsm/renderers/CSS3DRenderer.js +7 -4
- package/examples/jsm/renderers/SVGRenderer.js +6 -4
- package/examples/jsm/shaders/BokehShader2.js +1 -1
- package/examples/jsm/shaders/FXAAShader.js +225 -224
- package/examples/jsm/shaders/GodRaysShader.js +3 -3
- package/examples/jsm/shaders/OutputShader.js +6 -2
- package/examples/jsm/shaders/SobelOperatorShader.js +1 -1
- package/examples/jsm/transpiler/AST.js +12 -2
- package/examples/jsm/transpiler/GLSLDecoder.js +77 -31
- package/examples/jsm/transpiler/ShaderToyDecoder.js +3 -3
- package/examples/jsm/transpiler/TSLEncoder.js +96 -21
- package/examples/jsm/tsl/display/AfterImageNode.js +243 -0
- package/examples/jsm/tsl/display/AnaglyphPassNode.js +106 -0
- package/examples/jsm/tsl/display/AnamorphicNode.js +257 -0
- package/{src/nodes/display/BleachBypassNode.js → examples/jsm/tsl/display/BleachBypass.js} +11 -6
- package/{src/nodes → examples/jsm/tsl}/display/BloomNode.js +252 -67
- package/examples/jsm/tsl/display/DenoiseNode.js +332 -0
- package/{src/nodes → examples/jsm/tsl}/display/DepthOfFieldNode.js +92 -14
- package/examples/jsm/tsl/display/DotScreenNode.js +103 -0
- package/examples/jsm/tsl/display/FXAANode.js +364 -0
- package/examples/jsm/tsl/display/FilmNode.js +100 -0
- package/examples/jsm/tsl/display/GTAONode.js +521 -0
- package/examples/jsm/tsl/display/GaussianBlurNode.js +393 -0
- package/examples/jsm/tsl/display/LensflareNode.js +278 -0
- package/examples/jsm/tsl/display/Lut3DNode.js +108 -0
- package/examples/jsm/tsl/display/MotionBlur.js +33 -0
- package/examples/jsm/tsl/display/OutlineNode.js +750 -0
- package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +88 -0
- package/{src/nodes → examples/jsm/tsl}/display/PixelationPassNode.js +160 -28
- package/examples/jsm/tsl/display/RGBShiftNode.js +95 -0
- package/examples/jsm/tsl/display/SMAANode.js +767 -0
- package/examples/jsm/tsl/display/SSAAPassNode.js +357 -0
- package/examples/jsm/tsl/display/SSRNode.js +538 -0
- package/examples/jsm/tsl/display/Sepia.js +24 -0
- package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +66 -20
- package/examples/jsm/tsl/display/StereoCompositePassNode.js +184 -0
- package/examples/jsm/tsl/display/StereoPassNode.js +119 -0
- package/examples/jsm/tsl/display/TRAAPassNode.js +451 -0
- package/examples/jsm/tsl/display/TransitionNode.js +140 -0
- package/examples/jsm/tsl/display/hashBlur.js +34 -0
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +395 -0
- package/examples/jsm/tsl/math/Bayer.js +18 -0
- package/examples/jsm/tsl/utils/Raymarching.js +65 -0
- package/examples/jsm/utils/BufferGeometryUtils.js +2 -2
- package/examples/jsm/utils/CameraUtils.js +4 -1
- package/examples/jsm/utils/GeometryCompressionUtils.js +38 -123
- package/examples/jsm/utils/GeometryUtils.js +22 -19
- package/examples/jsm/utils/SceneOptimizer.js +410 -0
- package/examples/jsm/utils/SceneUtils.js +2 -2
- package/examples/jsm/utils/ShadowMapViewer.js +3 -8
- package/examples/jsm/utils/ShadowMapViewerGPU.js +201 -0
- package/examples/jsm/utils/SkeletonUtils.js +84 -66
- package/examples/jsm/utils/UVsDebug.js +1 -1
- package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +1 -0
- package/examples/jsm/utils/WebGPUTextureUtils.js +64 -0
- package/examples/jsm/webxr/OculusHandPointerModel.js +21 -21
- package/examples/jsm/webxr/Text2D.js +6 -6
- package/examples/jsm/webxr/XRControllerModelFactory.js +7 -2
- package/examples/jsm/webxr/XREstimatedLight.js +1 -1
- package/package.json +14 -9
- package/src/Three.Core.js +182 -0
- package/src/Three.Legacy.js +0 -21
- package/src/Three.TSL.js +543 -0
- package/src/Three.WebGPU.Nodes.js +23 -0
- package/src/Three.WebGPU.js +13 -184
- package/src/Three.js +1 -176
- package/src/animation/AnimationClip.js +2 -2
- package/src/animation/AnimationObjectGroup.js +2 -2
- package/src/animation/AnimationUtils.js +1 -1
- package/src/animation/PropertyBinding.js +2 -2
- package/src/audio/Audio.js +379 -2
- package/src/audio/AudioAnalyser.js +58 -1
- package/src/audio/AudioContext.js +15 -0
- package/src/audio/AudioListener.js +76 -0
- package/src/audio/PositionalAudio.js +107 -0
- package/src/cameras/ArrayCamera.js +29 -0
- package/src/cameras/Camera.js +47 -0
- package/src/cameras/CubeCamera.js +66 -0
- package/src/cameras/OrthographicCamera.js +109 -0
- package/src/cameras/PerspectiveCamera.js +173 -34
- package/src/cameras/StereoCamera.js +48 -2
- package/src/constants.js +6 -6
- package/src/core/BufferAttribute.js +4 -9
- package/src/core/BufferGeometry.js +48 -8
- package/src/core/Clock.js +1 -1
- package/src/core/EventDispatcher.js +52 -8
- package/src/core/InterleavedBuffer.js +4 -13
- package/src/core/Object3D.js +573 -3
- package/src/core/RenderTarget.js +22 -4
- package/src/core/RenderTarget3D.js +22 -0
- package/src/core/RenderTargetArray.js +22 -0
- package/src/extras/Controls.js +104 -0
- package/src/extras/DataUtils.js +48 -8
- package/src/extras/Earcut.js +18 -7
- package/src/extras/ImageUtils.js +18 -11
- package/src/extras/PMREMGenerator.js +40 -9
- package/src/extras/ShapeUtils.js +24 -2
- package/src/extras/TextureUtils.js +96 -10
- package/src/extras/core/Curve.js +153 -53
- package/src/extras/core/CurvePath.js +63 -22
- package/src/extras/core/Interpolations.js +29 -3
- package/src/extras/core/Path.js +134 -1
- package/src/extras/core/Shape.js +66 -3
- package/src/extras/core/ShapePath.js +76 -0
- package/src/extras/curves/ArcCurve.js +22 -0
- package/src/extras/curves/CatmullRomCurve3.js +89 -18
- package/src/extras/curves/CubicBezierCurve.js +67 -0
- package/src/extras/curves/CubicBezierCurve3.js +50 -0
- package/src/extras/curves/EllipseCurve.js +102 -0
- package/src/extras/curves/LineCurve.js +36 -0
- package/src/extras/curves/LineCurve3.js +36 -0
- package/src/extras/curves/QuadraticBezierCurve.js +59 -0
- package/src/extras/curves/QuadraticBezierCurve3.js +43 -0
- package/src/extras/curves/SplineCurve.js +48 -0
- package/src/geometries/BoxGeometry.js +38 -0
- package/src/geometries/CapsuleGeometry.js +34 -0
- package/src/geometries/CircleGeometry.js +40 -0
- package/src/geometries/ConeGeometry.js +38 -0
- package/src/geometries/CylinderGeometry.js +50 -4
- package/src/geometries/DodecahedronGeometry.js +32 -0
- package/src/geometries/EdgesGeometry.js +30 -2
- package/src/geometries/ExtrudeGeometry.js +52 -0
- package/src/geometries/IcosahedronGeometry.js +32 -0
- package/src/geometries/LatheGeometry.js +43 -3
- package/src/geometries/OctahedronGeometry.js +32 -0
- package/src/geometries/PlaneGeometry.js +34 -0
- package/src/geometries/PolyhedronGeometry.js +29 -0
- package/src/geometries/RingGeometry.js +36 -0
- package/src/geometries/ShapeGeometry.js +37 -0
- package/src/geometries/SphereGeometry.js +37 -0
- package/src/geometries/TetrahedronGeometry.js +32 -0
- package/src/geometries/TorusGeometry.js +35 -0
- package/src/geometries/TorusKnotGeometry.js +38 -0
- package/src/geometries/TubeGeometry.js +49 -0
- package/src/geometries/WireframeGeometry.js +32 -0
- package/src/helpers/ArrowHelper.js +60 -3
- package/src/helpers/AxesHelper.js +28 -0
- package/src/helpers/Box3Helper.js +28 -0
- package/src/helpers/BoxHelper.js +43 -7
- package/src/helpers/CameraHelper.js +61 -18
- package/src/helpers/DirectionalLightHelper.js +52 -0
- package/src/helpers/GridHelper.js +26 -0
- package/src/helpers/HemisphereLightHelper.js +39 -0
- package/src/helpers/PlaneHelper.js +33 -0
- package/src/helpers/PointLightHelper.js +43 -0
- package/src/helpers/PolarGridHelper.js +30 -0
- package/src/helpers/SkeletonHelper.js +39 -2
- package/src/helpers/SpotLightHelper.js +40 -0
- package/src/lights/AmbientLight.js +25 -0
- package/src/lights/DirectionalLight.js +57 -0
- package/src/lights/DirectionalLightShadow.js +15 -0
- package/src/lights/HemisphereLight.js +32 -0
- package/src/lights/Light.js +36 -0
- package/src/lights/LightProbe.js +43 -0
- package/src/lights/LightShadow.js +159 -0
- package/src/lights/PointLight.js +59 -0
- package/src/lights/PointLightShadow.js +21 -0
- package/src/lights/RectAreaLight.js +59 -0
- package/src/lights/SpotLight.js +102 -0
- package/src/lights/SpotLightShadow.js +24 -2
- package/src/lights/webgpu/IESSpotLight.js +21 -0
- package/src/loaders/Loader.js +132 -0
- package/src/loaders/MaterialLoader.js +7 -1
- package/src/loaders/nodes/NodeLoader.js +189 -0
- package/src/loaders/nodes/NodeMaterialLoader.js +108 -0
- package/src/loaders/nodes/NodeObjectLoader.js +151 -0
- package/src/materials/LineDashedMaterial.js +0 -1
- package/src/materials/Material.js +469 -7
- package/src/materials/MeshPhongMaterial.js +1 -1
- package/src/materials/MeshPhysicalMaterial.js +2 -2
- package/src/materials/MeshStandardMaterial.js +2 -2
- package/src/{nodes/materials → materials/nodes}/Line2NodeMaterial.js +192 -82
- package/src/materials/nodes/LineBasicNodeMaterial.js +46 -0
- package/src/materials/nodes/LineDashedNodeMaterial.js +132 -0
- package/src/materials/nodes/MeshBasicNodeMaterial.js +133 -0
- package/src/materials/nodes/MeshLambertNodeMaterial.js +82 -0
- package/src/materials/nodes/MeshMatcapNodeMaterial.js +77 -0
- package/src/materials/nodes/MeshNormalNodeMaterial.js +67 -0
- package/src/materials/nodes/MeshPhongNodeMaterial.js +141 -0
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +517 -0
- package/src/materials/nodes/MeshSSSNodeMaterial.js +175 -0
- package/src/materials/nodes/MeshStandardNodeMaterial.js +186 -0
- package/src/materials/nodes/MeshToonNodeMaterial.js +66 -0
- package/src/materials/nodes/NodeMaterial.js +1180 -0
- package/src/{nodes/materials/Materials.js → materials/nodes/NodeMaterials.js} +3 -2
- package/src/materials/nodes/PointsNodeMaterial.js +153 -0
- package/src/materials/nodes/ShadowNodeMaterial.js +67 -0
- package/src/materials/nodes/SpriteNodeMaterial.js +198 -0
- package/src/materials/nodes/VolumeNodeMaterial.js +72 -0
- package/src/materials/nodes/manager/NodeMaterialObserver.js +509 -0
- package/src/math/Box2.js +177 -0
- package/src/math/Box3.js +243 -0
- package/src/math/Color.js +343 -0
- package/src/math/ColorManagement.js +143 -102
- package/src/math/Cylindrical.js +65 -6
- package/src/math/Euler.js +137 -4
- package/src/math/Frustum.js +83 -0
- package/src/math/Interpolant.js +87 -8
- package/src/math/Line3.js +96 -2
- package/src/math/MathUtils.js +182 -19
- package/src/math/Matrix2.js +70 -0
- package/src/math/Matrix3.js +229 -4
- package/src/math/Matrix4.js +368 -3
- package/src/math/Plane.js +164 -2
- package/src/math/Quaternion.js +265 -9
- package/src/math/Ray.js +160 -0
- package/src/math/Sphere.js +147 -0
- package/src/math/Spherical.js +73 -11
- package/src/math/SphericalHarmonics3.js +112 -14
- package/src/math/Triangle.js +230 -2
- package/src/math/Vector2.js +396 -10
- package/src/math/Vector3.js +550 -13
- package/src/math/Vector4.js +415 -9
- package/src/math/interpolants/CubicInterpolant.js +10 -1
- package/src/math/interpolants/DiscreteInterpolant.js +10 -2
- package/src/math/interpolants/LinearInterpolant.js +13 -0
- package/src/math/interpolants/QuaternionLinearInterpolant.js +10 -1
- package/src/nodes/Nodes.js +84 -166
- package/src/nodes/TSL.js +167 -0
- package/src/nodes/accessors/AccessorsUtils.js +39 -10
- package/src/nodes/accessors/Arrays.js +68 -0
- package/src/nodes/accessors/BatchNode.js +93 -26
- package/src/nodes/accessors/Bitangent.js +54 -0
- package/src/nodes/accessors/BufferAttributeNode.js +189 -11
- package/src/nodes/accessors/BufferNode.js +70 -5
- package/src/nodes/accessors/BuiltinNode.js +63 -0
- package/src/nodes/accessors/Camera.js +129 -0
- package/src/nodes/accessors/ClippingNode.js +152 -43
- package/src/nodes/accessors/CubeTextureNode.js +76 -13
- package/src/nodes/accessors/InstanceNode.js +118 -35
- package/src/nodes/accessors/InstancedMeshNode.js +50 -0
- package/src/nodes/accessors/Lights.js +129 -0
- package/src/nodes/accessors/MaterialNode.js +394 -58
- package/src/nodes/accessors/MaterialProperties.js +57 -1
- package/src/nodes/accessors/MaterialReferenceNode.js +60 -18
- package/src/nodes/accessors/ModelNode.js +159 -12
- package/src/nodes/accessors/ModelViewProjectionNode.js +10 -36
- package/src/nodes/accessors/MorphNode.js +60 -13
- package/src/nodes/accessors/Normal.js +156 -0
- package/src/nodes/accessors/Object3DNode.js +154 -35
- package/src/nodes/accessors/PointUVNode.js +35 -6
- package/src/nodes/accessors/Position.js +64 -0
- package/src/nodes/accessors/ReferenceBaseNode.js +357 -0
- package/src/nodes/accessors/ReferenceNode.js +243 -6
- package/src/nodes/accessors/ReflectVector.js +36 -0
- package/src/nodes/accessors/RendererReferenceNode.js +57 -7
- package/src/nodes/accessors/SceneNode.js +98 -6
- package/src/nodes/accessors/SkinningNode.js +214 -21
- package/src/nodes/accessors/StorageBufferNode.js +288 -28
- package/src/nodes/accessors/StorageTextureNode.js +139 -12
- package/src/nodes/accessors/Tangent.js +62 -0
- package/src/nodes/accessors/Texture3DNode.js +98 -12
- package/src/nodes/accessors/{TextureBicubicNode.js → TextureBicubic.js} +14 -34
- package/src/nodes/accessors/TextureNode.js +347 -34
- package/src/nodes/accessors/TextureSizeNode.js +51 -9
- package/src/nodes/accessors/UV.js +11 -0
- package/src/nodes/accessors/UniformArrayNode.js +241 -32
- package/src/nodes/accessors/UserDataNode.js +55 -7
- package/src/nodes/accessors/VelocityNode.js +223 -0
- package/src/nodes/accessors/VertexColorNode.js +45 -6
- package/src/nodes/code/CodeNode.js +108 -8
- package/src/nodes/code/ExpressionNode.js +38 -7
- package/src/nodes/code/FunctionCallNode.js +62 -11
- package/src/nodes/code/FunctionNode.js +54 -24
- package/src/nodes/code/ScriptableNode.js +241 -17
- package/src/nodes/code/ScriptableValueNode.js +93 -8
- package/src/nodes/core/ArrayNode.js +142 -0
- package/src/nodes/core/AssignNode.js +60 -12
- package/src/nodes/core/AttributeNode.js +55 -22
- package/src/nodes/core/BypassNode.js +59 -11
- package/src/nodes/core/CacheNode.js +64 -10
- package/src/nodes/core/ConstNode.js +38 -3
- package/src/nodes/core/ContextNode.js +87 -12
- package/src/nodes/core/IndexNode.js +102 -10
- package/src/nodes/core/InputNode.js +55 -3
- package/src/nodes/core/LightingModel.js +65 -5
- package/src/nodes/core/MRTNode.js +81 -7
- package/src/nodes/core/Node.js +368 -50
- package/src/nodes/core/NodeAttribute.js +38 -0
- package/src/nodes/core/NodeBuilder.js +1317 -83
- package/src/nodes/core/NodeCache.js +41 -2
- package/src/nodes/core/NodeCode.js +31 -0
- package/src/nodes/core/NodeFrame.js +123 -2
- package/src/nodes/core/NodeFunction.js +46 -0
- package/src/nodes/core/NodeFunctionInput.js +44 -0
- package/src/nodes/core/NodeParser.js +11 -0
- package/src/nodes/core/NodeUniform.js +52 -0
- package/src/nodes/core/NodeUtils.js +226 -6
- package/src/nodes/core/NodeVar.js +47 -1
- package/src/nodes/core/NodeVarying.js +28 -0
- package/src/nodes/core/OutputStructNode.js +61 -17
- package/src/nodes/core/ParameterNode.js +34 -4
- package/src/nodes/core/PropertyNode.js +296 -32
- package/src/nodes/core/StackNode.js +108 -8
- package/src/nodes/core/StructNode.js +120 -0
- package/src/nodes/core/StructType.js +13 -0
- package/src/nodes/core/StructTypeNode.js +116 -9
- package/src/nodes/core/TempNode.js +37 -7
- package/src/nodes/core/UniformGroupNode.js +98 -17
- package/src/nodes/core/UniformNode.js +72 -4
- package/src/nodes/core/VarNode.js +170 -13
- package/src/nodes/core/VaryingNode.js +109 -8
- package/src/nodes/core/constants.js +40 -0
- package/src/nodes/display/BlendModes.js +193 -0
- package/src/nodes/display/BumpMapNode.js +47 -10
- package/src/nodes/display/ColorAdjustment.js +141 -0
- package/src/nodes/display/ColorSpaceFunctions.js +54 -0
- package/src/nodes/display/ColorSpaceNode.js +147 -68
- package/src/nodes/display/FrontFacingNode.js +39 -6
- package/src/nodes/display/NormalMapNode.js +55 -13
- package/src/nodes/display/PassNode.js +420 -19
- package/src/nodes/display/PosterizeNode.js +40 -7
- package/src/nodes/display/RenderOutputNode.js +81 -13
- package/src/nodes/display/ScreenNode.js +286 -0
- package/src/nodes/display/ToneMappingFunctions.js +242 -0
- package/src/nodes/display/ToneMappingNode.js +68 -175
- package/src/nodes/display/ToonOutlinePassNode.js +183 -0
- package/src/nodes/display/ViewportDepthNode.js +210 -36
- package/src/nodes/display/ViewportDepthTextureNode.js +32 -9
- package/src/nodes/display/ViewportSharedTextureNode.js +32 -9
- package/src/nodes/display/ViewportTextureNode.js +68 -11
- package/src/nodes/fog/Fog.js +113 -0
- package/src/nodes/functions/BSDF/BRDF_GGX.js +4 -4
- package/src/nodes/functions/BSDF/BRDF_Lambert.js +2 -2
- package/src/nodes/functions/BSDF/BRDF_Sheen.js +6 -6
- package/src/nodes/functions/BSDF/DFGApprox.js +2 -2
- package/src/nodes/functions/BSDF/D_GGX.js +2 -2
- package/src/nodes/functions/BSDF/D_GGX_Anisotropic.js +3 -3
- package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
- package/src/nodes/functions/BSDF/F_Schlick.js +2 -2
- package/src/nodes/functions/BSDF/LTC.js +50 -6
- package/src/nodes/functions/BSDF/Schlick_to_F0.js +2 -2
- package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +2 -2
- package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +2 -2
- package/src/nodes/functions/BasicLightingModel.js +27 -6
- package/src/nodes/functions/PhongLightingModel.js +38 -8
- package/src/nodes/functions/PhysicalLightingModel.js +215 -51
- package/src/nodes/functions/ShadowMaskModel.js +24 -1
- package/src/nodes/functions/ToonLightingModel.js +24 -5
- package/src/nodes/functions/VolumetricLightingModel.js +183 -0
- package/src/nodes/functions/material/getAlphaHashThreshold.js +68 -0
- package/src/nodes/functions/material/getGeometryRoughness.js +10 -4
- package/src/nodes/functions/material/getParallaxCorrectNormal.js +37 -0
- package/src/nodes/functions/material/getRoughness.js +2 -2
- package/src/nodes/functions/material/getShIrradianceAt.js +28 -0
- package/src/nodes/geometry/RangeNode.js +62 -7
- package/src/nodes/gpgpu/AtomicFunctionNode.js +280 -0
- package/src/nodes/gpgpu/BarrierNode.js +89 -0
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +227 -0
- package/src/nodes/gpgpu/ComputeNode.js +124 -9
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +208 -0
- package/src/nodes/lighting/AONode.js +24 -3
- package/src/nodes/lighting/AmbientLightNode.js +16 -8
- package/src/nodes/lighting/AnalyticLightNode.js +151 -231
- package/src/nodes/lighting/BasicEnvironmentNode.js +25 -3
- package/src/nodes/lighting/BasicLightMapNode.js +25 -5
- package/src/nodes/lighting/DirectionalLightNode.js +19 -20
- package/src/nodes/lighting/EnvironmentNode.js +34 -17
- package/src/nodes/lighting/HemisphereLightNode.js +42 -11
- package/src/nodes/lighting/IESSpotLightNode.js +18 -9
- package/src/nodes/lighting/IrradianceNode.js +23 -3
- package/src/nodes/lighting/LightProbeNode.js +29 -36
- package/src/nodes/lighting/LightUtils.js +12 -4
- package/src/nodes/lighting/LightingContextNode.js +70 -21
- package/src/nodes/lighting/LightingNode.js +22 -9
- package/src/nodes/lighting/LightsNode.js +309 -86
- package/src/nodes/lighting/PointLightNode.js +66 -32
- package/src/nodes/lighting/PointShadowNode.js +306 -0
- package/src/nodes/lighting/RectAreaLightNode.js +61 -25
- package/src/nodes/lighting/ShadowBaseNode.js +92 -0
- package/src/nodes/lighting/ShadowNode.js +812 -0
- package/src/nodes/lighting/SpotLightNode.js +73 -31
- package/src/nodes/materialx/MaterialXNodes.js +2 -2
- package/src/nodes/materialx/lib/mx_hsv.js +27 -22
- package/src/nodes/materialx/lib/mx_noise.js +70 -70
- package/src/nodes/materialx/lib/mx_transform_color.js +2 -2
- package/src/nodes/math/ConditionalNode.js +230 -0
- package/src/nodes/math/Hash.js +21 -0
- package/src/nodes/math/MathNode.js +812 -131
- package/src/nodes/math/MathUtils.js +47 -8
- package/src/nodes/math/OperatorNode.js +410 -66
- package/src/nodes/math/TriNoise3D.js +32 -32
- package/src/nodes/parsers/GLSLNodeFunction.js +16 -0
- package/src/nodes/parsers/GLSLNodeParser.js +11 -0
- package/src/nodes/pmrem/PMREMNode.js +188 -28
- package/src/nodes/pmrem/PMREMUtils.js +24 -24
- package/src/nodes/procedural/Checker.js +22 -0
- package/src/nodes/shapes/Shapes.js +32 -0
- package/src/nodes/tsl/TSLBase.js +31 -0
- package/src/nodes/{shadernode/ShaderNode.js → tsl/TSLCore.js} +114 -98
- package/src/nodes/utils/ArrayElementNode.js +45 -5
- package/src/nodes/utils/ConvertNode.js +39 -4
- package/src/nodes/utils/CubeMapNode.js +88 -8
- package/src/nodes/utils/Discard.js +24 -0
- package/src/nodes/utils/EquirectUVNode.js +39 -7
- package/src/nodes/utils/FlipNode.js +106 -0
- package/src/nodes/utils/FunctionOverloadingNode.js +61 -6
- package/src/nodes/utils/JoinNode.js +31 -3
- package/src/nodes/utils/LoopNode.js +95 -9
- package/src/nodes/utils/MatcapUVNode.js +27 -8
- package/src/nodes/utils/MaxMipLevelNode.js +57 -6
- package/src/nodes/utils/MemberNode.js +68 -0
- package/src/nodes/utils/Oscillators.js +41 -0
- package/src/nodes/utils/Packing.js +21 -0
- package/src/nodes/utils/PostProcessingUtils.js +95 -0
- package/src/nodes/utils/RTTNode.js +141 -9
- package/src/nodes/utils/ReflectorNode.js +295 -21
- package/src/nodes/utils/RemapNode.js +93 -10
- package/src/nodes/utils/RotateNode.js +48 -13
- package/src/nodes/utils/SetNode.js +50 -4
- package/src/nodes/utils/SplitNode.js +62 -6
- package/src/nodes/utils/SpriteSheetUVNode.js +56 -7
- package/src/nodes/utils/SpriteUtils.js +21 -5
- package/src/nodes/utils/StorageArrayElementNode.js +64 -12
- package/src/nodes/utils/Timer.js +73 -0
- package/src/nodes/utils/TriplanarTexturesNode.js +96 -10
- package/src/nodes/utils/UVUtils.js +27 -9
- package/src/nodes/utils/ViewportUtils.js +16 -4
- package/src/objects/BatchedMesh.js +808 -281
- package/src/objects/Bone.js +24 -0
- package/src/objects/ClippingGroup.js +68 -0
- package/src/objects/Group.js +24 -0
- package/src/objects/InstancedMesh.js +120 -2
- package/src/objects/LOD.js +120 -5
- package/src/objects/Line.js +89 -6
- package/src/objects/LineLoop.js +20 -0
- package/src/objects/LineSegments.js +18 -0
- package/src/objects/Mesh.js +82 -23
- package/src/objects/Points.js +62 -0
- package/src/objects/Skeleton.js +107 -2
- package/src/objects/SkinnedMesh.js +99 -5
- package/src/objects/Sprite.js +54 -0
- package/src/renderers/WebGLRenderer.js +274 -157
- package/src/renderers/common/Animation.js +109 -12
- package/src/renderers/common/Attributes.js +40 -0
- package/src/renderers/common/Backend.js +504 -44
- package/src/renderers/common/Background.js +67 -9
- package/src/renderers/common/BindGroup.js +45 -1
- package/src/renderers/common/Binding.js +35 -0
- package/src/renderers/common/Bindings.js +136 -19
- package/src/renderers/common/Buffer.js +49 -0
- package/src/renderers/common/BufferUtils.js +25 -0
- package/src/renderers/common/BundleGroup.js +83 -0
- package/src/renderers/common/ChainMap.js +45 -6
- package/src/renderers/common/ClippingContext.js +175 -80
- package/src/renderers/common/Color4.js +40 -0
- package/src/renderers/common/ComputePipeline.js +24 -0
- package/src/renderers/common/Constants.js +2 -1
- package/src/renderers/common/CubeRenderTarget.js +22 -3
- package/src/renderers/common/DataMap.js +37 -1
- package/src/renderers/common/Geometries.js +111 -14
- package/src/renderers/common/IndirectStorageBufferAttribute.js +38 -0
- package/src/renderers/common/Info.js +78 -35
- package/src/renderers/common/Lighting.js +73 -0
- package/src/renderers/common/Pipeline.js +22 -0
- package/src/renderers/common/Pipelines.js +148 -5
- package/src/renderers/common/PostProcessing.js +112 -11
- package/src/renderers/common/ProgrammableStage.js +60 -2
- package/src/renderers/common/QuadMesh.js +56 -5
- package/src/renderers/common/RenderBundle.js +14 -8
- package/src/renderers/common/RenderBundles.js +39 -10
- package/src/renderers/common/RenderContext.js +205 -7
- package/src/renderers/common/RenderContexts.js +59 -6
- package/src/renderers/common/RenderList.js +230 -21
- package/src/renderers/common/RenderLists.js +45 -6
- package/src/renderers/common/RenderObject.js +552 -41
- package/src/renderers/common/RenderObjects.js +118 -9
- package/src/renderers/common/RenderPipeline.js +24 -0
- package/src/renderers/common/Renderer.js +1537 -239
- package/src/renderers/common/RendererUtils.js +191 -0
- package/src/renderers/common/SampledTexture.js +132 -3
- package/src/renderers/common/Sampler.js +30 -0
- package/src/renderers/common/StorageBuffer.js +24 -0
- package/src/renderers/common/StorageBufferAttribute.js +31 -2
- package/src/renderers/common/StorageInstancedBufferAttribute.js +31 -2
- package/src/renderers/common/StorageTexture.js +38 -0
- package/src/renderers/common/Textures.js +142 -32
- package/src/renderers/common/TimestampQueryPool.js +98 -0
- package/src/renderers/common/Uniform.js +225 -3
- package/src/renderers/common/UniformBuffer.js +19 -0
- package/src/renderers/common/UniformsGroup.js +157 -6
- package/src/renderers/common/XRManager.js +1185 -0
- package/src/renderers/common/XRRenderTarget.js +74 -0
- package/src/renderers/common/extras/PMREMGenerator.js +211 -53
- package/src/renderers/common/nodes/NodeBuilderState.js +100 -6
- package/src/renderers/common/nodes/NodeLibrary.js +194 -0
- package/src/renderers/common/nodes/NodeSampledTexture.js +92 -4
- package/src/renderers/common/nodes/NodeSampler.js +28 -0
- package/src/renderers/common/nodes/NodeStorageBuffer.js +37 -3
- package/src/renderers/common/nodes/NodeUniform.js +285 -2
- package/src/renderers/common/nodes/NodeUniformBuffer.js +29 -0
- package/src/renderers/common/nodes/NodeUniformsGroup.js +31 -18
- package/src/renderers/common/nodes/Nodes.js +390 -70
- package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
- package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderLib/sprite.glsl.js +2 -4
- package/src/renderers/webgl/WebGLAttributes.js +45 -14
- package/src/renderers/webgl/WebGLBackground.js +24 -1
- package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLCapabilities.js +2 -0
- package/src/renderers/webgl/WebGLGeometries.js +0 -28
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLProgram.js +27 -29
- package/src/renderers/webgl/WebGLPrograms.js +24 -16
- package/src/renderers/webgl/WebGLState.js +68 -11
- package/src/renderers/webgl/WebGLTextures.js +49 -10
- package/src/renderers/webgl-fallback/WebGLBackend.js +1055 -238
- package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +5 -10
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +425 -48
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +64 -1
- package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
- package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +419 -14
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +281 -59
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +367 -0
- package/src/renderers/webgl-fallback/utils/WebGLUtils.js +43 -0
- package/src/renderers/webgpu/WebGPUBackend.js +816 -236
- package/src/renderers/webgpu/WebGPURenderer.Nodes.js +78 -0
- package/src/renderers/webgpu/WebGPURenderer.js +45 -6
- package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +63 -0
- package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +97 -0
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +954 -147
- package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +29 -4
- package/src/renderers/webgpu/nodes/WGSLNodeParser.js +11 -0
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +147 -31
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +213 -31
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +146 -28
- package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +161 -7
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +333 -50
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +287 -0
- package/src/renderers/webgpu/utils/WebGPUUtils.js +131 -3
- package/src/renderers/webxr/WebXRDepthSensing.js +1 -1
- package/src/renderers/webxr/WebXRManager.js +54 -32
- package/src/scenes/Fog.js +60 -0
- package/src/scenes/FogExp2.js +51 -0
- package/src/scenes/Scene.js +87 -0
- package/src/textures/Data3DTexture.js +2 -2
- package/src/textures/DepthTexture.js +2 -0
- package/src/textures/Source.js +2 -2
- package/src/textures/Texture.js +368 -5
- package/src/textures/VideoFrameTexture.js +35 -0
- package/src/utils.js +33 -1
- package/examples/jsm/animation/MMDAnimationHelper.js +0 -1207
- package/examples/jsm/animation/MMDPhysics.js +0 -1406
- package/examples/jsm/cameras/CinematicCamera.js +0 -208
- package/examples/jsm/controls/Controls.js +0 -32
- package/examples/jsm/exporters/MMDExporter.js +0 -217
- package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -174
- package/examples/jsm/geometries/SDFGeometryGenerator.js +0 -144
- package/examples/jsm/libs/mmdparser.module.js +0 -11530
- package/examples/jsm/loaders/LogLuvLoader.js +0 -606
- package/examples/jsm/loaders/MMDLoader.js +0 -2295
- package/examples/jsm/loaders/TiltLoader.js +0 -520
- package/examples/jsm/objects/InstancedPoints.js +0 -21
- package/examples/jsm/shaders/MMDToonShader.js +0 -134
- package/examples/jsm/utils/GPUStatsPanel.js +0 -95
- package/examples/jsm/utils/PackedPhongMaterial.js +0 -178
- package/src/nodes/accessors/BitangentNode.js +0 -13
- package/src/nodes/accessors/CameraNode.js +0 -19
- package/src/nodes/accessors/InstancedPointsMaterialNode.js +0 -21
- package/src/nodes/accessors/NormalNode.js +0 -14
- package/src/nodes/accessors/PositionNode.js +0 -10
- package/src/nodes/accessors/ReflectVectorNode.js +0 -10
- package/src/nodes/accessors/TangentNode.js +0 -23
- package/src/nodes/accessors/UVNode.js +0 -3
- package/src/nodes/core/NodeKeywords.js +0 -80
- package/src/nodes/core/UniformGroup.js +0 -13
- package/src/nodes/display/AfterImageNode.js +0 -152
- package/src/nodes/display/AnamorphicNode.js +0 -145
- package/src/nodes/display/BlendModeNode.js +0 -128
- package/src/nodes/display/ColorAdjustmentNode.js +0 -104
- package/src/nodes/display/DenoiseNode.js +0 -198
- package/src/nodes/display/DotScreenNode.js +0 -75
- package/src/nodes/display/FXAANode.js +0 -327
- package/src/nodes/display/FilmNode.js +0 -52
- package/src/nodes/display/GTAONode.js +0 -324
- package/src/nodes/display/GaussianBlurNode.js +0 -207
- package/src/nodes/display/Lut3DNode.js +0 -53
- package/src/nodes/display/RGBShiftNode.js +0 -49
- package/src/nodes/display/SepiaNode.js +0 -18
- package/src/nodes/display/TransitionNode.js +0 -76
- package/src/nodes/display/ViewportNode.js +0 -137
- package/src/nodes/fog/FogExp2Node.js +0 -34
- package/src/nodes/fog/FogNode.js +0 -48
- package/src/nodes/fog/FogRangeNode.js +0 -35
- package/src/nodes/lighting/LightNode.js +0 -57
- package/src/nodes/loaders/NodeLoader.js +0 -110
- package/src/nodes/loaders/NodeMaterialLoader.js +0 -60
- package/src/nodes/loaders/NodeObjectLoader.js +0 -71
- package/src/nodes/materials/InstancedPointsNodeMaterial.js +0 -162
- package/src/nodes/materials/LineBasicNodeMaterial.js +0 -28
- package/src/nodes/materials/LineDashedNodeMaterial.js +0 -55
- package/src/nodes/materials/MeshBasicNodeMaterial.js +0 -73
- package/src/nodes/materials/MeshLambertNodeMaterial.js +0 -43
- package/src/nodes/materials/MeshMatcapNodeMaterial.js +0 -53
- package/src/nodes/materials/MeshNormalNodeMaterial.js +0 -40
- package/src/nodes/materials/MeshPhongNodeMaterial.js +0 -74
- package/src/nodes/materials/MeshPhysicalNodeMaterial.js +0 -244
- package/src/nodes/materials/MeshSSSNodeMaterial.js +0 -84
- package/src/nodes/materials/MeshStandardNodeMaterial.js +0 -104
- package/src/nodes/materials/MeshToonNodeMaterial.js +0 -34
- package/src/nodes/materials/NodeMaterial.js +0 -680
- package/src/nodes/materials/PointsNodeMaterial.js +0 -39
- package/src/nodes/materials/ShadowNodeMaterial.js +0 -34
- package/src/nodes/materials/SpriteNodeMaterial.js +0 -90
- package/src/nodes/materials/VolumeNodeMaterial.js +0 -106
- package/src/nodes/math/CondNode.js +0 -139
- package/src/nodes/math/HashNode.js +0 -34
- package/src/nodes/procedural/CheckerNode.js +0 -42
- package/src/nodes/utils/DiscardNode.js +0 -28
- package/src/nodes/utils/OscNode.js +0 -81
- package/src/nodes/utils/PackingNode.js +0 -55
- package/src/nodes/utils/TimerNode.js +0 -94
|
@@ -14,29 +14,57 @@ import Color4 from './Color4.js';
|
|
|
14
14
|
import ClippingContext from './ClippingContext.js';
|
|
15
15
|
import QuadMesh from './QuadMesh.js';
|
|
16
16
|
import RenderBundles from './RenderBundles.js';
|
|
17
|
+
import NodeLibrary from './nodes/NodeLibrary.js';
|
|
18
|
+
import Lighting from './Lighting.js';
|
|
19
|
+
import XRManager from './XRManager.js';
|
|
17
20
|
|
|
18
|
-
import
|
|
21
|
+
import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
|
|
19
22
|
|
|
20
23
|
import { Scene } from '../../scenes/Scene.js';
|
|
21
24
|
import { Frustum } from '../../math/Frustum.js';
|
|
22
25
|
import { Matrix4 } from '../../math/Matrix4.js';
|
|
23
26
|
import { Vector2 } from '../../math/Vector2.js';
|
|
24
|
-
import { Vector3 } from '../../math/Vector3.js';
|
|
25
27
|
import { Vector4 } from '../../math/Vector4.js';
|
|
26
28
|
import { RenderTarget } from '../../core/RenderTarget.js';
|
|
27
|
-
import { DoubleSide, BackSide, FrontSide, SRGBColorSpace,
|
|
29
|
+
import { DoubleSide, BackSide, FrontSide, SRGBColorSpace, NoToneMapping, LinearFilter, LinearSRGBColorSpace, HalfFloatType, RGBAFormat, PCFShadowMap } from '../../constants.js';
|
|
28
30
|
|
|
29
31
|
const _scene = /*@__PURE__*/ new Scene();
|
|
30
32
|
const _drawingBufferSize = /*@__PURE__*/ new Vector2();
|
|
31
33
|
const _screen = /*@__PURE__*/ new Vector4();
|
|
32
34
|
const _frustum = /*@__PURE__*/ new Frustum();
|
|
33
35
|
const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
|
|
34
|
-
const
|
|
36
|
+
const _vector4 = /*@__PURE__*/ new Vector4();
|
|
35
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Base class for renderers.
|
|
40
|
+
*/
|
|
36
41
|
class Renderer {
|
|
37
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Constructs a new renderer.
|
|
45
|
+
*
|
|
46
|
+
* @param {Backend} backend - The backend the renderer is targeting (e.g. WebGPU or WebGL 2).
|
|
47
|
+
* @param {Object} parameters - The configuration parameter.
|
|
48
|
+
* @param {boolean} [parameters.logarithmicDepthBuffer=false] - Whether logarithmic depth buffer is enabled or not.
|
|
49
|
+
* @param {boolean} [parameters.alpha=true] - Whether the default framebuffer (which represents the final contents of the canvas) should be transparent or opaque.
|
|
50
|
+
* @param {boolean} [parameters.depth=true] - Whether the default framebuffer should have a depth buffer or not.
|
|
51
|
+
* @param {boolean} [parameters.stencil=false] - Whether the default framebuffer should have a stencil buffer or not.
|
|
52
|
+
* @param {boolean} [parameters.antialias=false] - Whether MSAA as the default anti-aliasing should be enabled or not.
|
|
53
|
+
* @param {number} [parameters.samples=0] - When `antialias` is `true`, `4` samples are used by default. This parameter can set to any other integer value than 0
|
|
54
|
+
* to overwrite the default.
|
|
55
|
+
* @param {?Function} [parameters.getFallback=null] - This callback function can be used to provide a fallback backend, if the primary backend can't be targeted.
|
|
56
|
+
* @param {number} [parameters.colorBufferType=HalfFloatType] - Defines the type of color buffers. The default `HalfFloatType` is recommend for best
|
|
57
|
+
* quality. To save memory and bandwidth, `UnsignedByteType` might be used. This will reduce rendering quality though.
|
|
58
|
+
*/
|
|
38
59
|
constructor( backend, parameters = {} ) {
|
|
39
60
|
|
|
61
|
+
/**
|
|
62
|
+
* This flag can be used for type testing.
|
|
63
|
+
*
|
|
64
|
+
* @type {boolean}
|
|
65
|
+
* @readonly
|
|
66
|
+
* @default true
|
|
67
|
+
*/
|
|
40
68
|
this.isRenderer = true;
|
|
41
69
|
|
|
42
70
|
//
|
|
@@ -44,107 +72,618 @@ class Renderer {
|
|
|
44
72
|
const {
|
|
45
73
|
logarithmicDepthBuffer = false,
|
|
46
74
|
alpha = true,
|
|
75
|
+
depth = true,
|
|
76
|
+
stencil = false,
|
|
47
77
|
antialias = false,
|
|
48
|
-
samples = 0
|
|
78
|
+
samples = 0,
|
|
79
|
+
getFallback = null,
|
|
80
|
+
colorBufferType = HalfFloatType
|
|
49
81
|
} = parameters;
|
|
50
82
|
|
|
51
|
-
|
|
83
|
+
/**
|
|
84
|
+
* A reference to the canvas element the renderer is drawing to.
|
|
85
|
+
* This value of this property will automatically be created by
|
|
86
|
+
* the renderer.
|
|
87
|
+
*
|
|
88
|
+
* @type {HTMLCanvasElement|OffscreenCanvas}
|
|
89
|
+
*/
|
|
52
90
|
this.domElement = backend.getDomElement();
|
|
53
91
|
|
|
92
|
+
/**
|
|
93
|
+
* A reference to the current backend.
|
|
94
|
+
*
|
|
95
|
+
* @type {Backend}
|
|
96
|
+
*/
|
|
54
97
|
this.backend = backend;
|
|
55
98
|
|
|
99
|
+
/**
|
|
100
|
+
* The number of MSAA samples.
|
|
101
|
+
*
|
|
102
|
+
* @type {number}
|
|
103
|
+
* @default 0
|
|
104
|
+
*/
|
|
56
105
|
this.samples = samples || ( antialias === true ) ? 4 : 0;
|
|
57
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Whether the renderer should automatically clear the current rendering target
|
|
109
|
+
* before execute a `render()` call. The target can be the canvas (default framebuffer)
|
|
110
|
+
* or the current bound render target (custom framebuffer).
|
|
111
|
+
*
|
|
112
|
+
* @type {boolean}
|
|
113
|
+
* @default true
|
|
114
|
+
*/
|
|
58
115
|
this.autoClear = true;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* When `autoClear` is set to `true`, this property defines whether the renderer
|
|
119
|
+
* should clear the color buffer.
|
|
120
|
+
*
|
|
121
|
+
* @type {boolean}
|
|
122
|
+
* @default true
|
|
123
|
+
*/
|
|
59
124
|
this.autoClearColor = true;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* When `autoClear` is set to `true`, this property defines whether the renderer
|
|
128
|
+
* should clear the depth buffer.
|
|
129
|
+
*
|
|
130
|
+
* @type {boolean}
|
|
131
|
+
* @default true
|
|
132
|
+
*/
|
|
60
133
|
this.autoClearDepth = true;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* When `autoClear` is set to `true`, this property defines whether the renderer
|
|
137
|
+
* should clear the stencil buffer.
|
|
138
|
+
*
|
|
139
|
+
* @type {boolean}
|
|
140
|
+
* @default true
|
|
141
|
+
*/
|
|
61
142
|
this.autoClearStencil = true;
|
|
62
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Whether the default framebuffer should be transparent or opaque.
|
|
146
|
+
*
|
|
147
|
+
* @type {boolean}
|
|
148
|
+
* @default true
|
|
149
|
+
*/
|
|
63
150
|
this.alpha = alpha;
|
|
64
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Whether logarithmic depth buffer is enabled or not.
|
|
154
|
+
*
|
|
155
|
+
* @type {boolean}
|
|
156
|
+
* @default false
|
|
157
|
+
*/
|
|
65
158
|
this.logarithmicDepthBuffer = logarithmicDepthBuffer;
|
|
66
159
|
|
|
160
|
+
/**
|
|
161
|
+
* Defines the output color space of the renderer.
|
|
162
|
+
*
|
|
163
|
+
* @type {string}
|
|
164
|
+
* @default SRGBColorSpace
|
|
165
|
+
*/
|
|
67
166
|
this.outputColorSpace = SRGBColorSpace;
|
|
68
167
|
|
|
168
|
+
/**
|
|
169
|
+
* Defines the tone mapping of the renderer.
|
|
170
|
+
*
|
|
171
|
+
* @type {number}
|
|
172
|
+
* @default NoToneMapping
|
|
173
|
+
*/
|
|
69
174
|
this.toneMapping = NoToneMapping;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Defines the tone mapping exposure.
|
|
178
|
+
*
|
|
179
|
+
* @type {number}
|
|
180
|
+
* @default 1
|
|
181
|
+
*/
|
|
70
182
|
this.toneMappingExposure = 1.0;
|
|
71
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Whether the renderer should sort its render lists or not.
|
|
186
|
+
*
|
|
187
|
+
* Note: Sorting is used to attempt to properly render objects that have some degree of transparency.
|
|
188
|
+
* By definition, sorting objects may not work in all cases. Depending on the needs of application,
|
|
189
|
+
* it may be necessary to turn off sorting and use other methods to deal with transparency rendering
|
|
190
|
+
* e.g. manually determining each object's rendering order.
|
|
191
|
+
*
|
|
192
|
+
* @type {boolean}
|
|
193
|
+
* @default true
|
|
194
|
+
*/
|
|
72
195
|
this.sortObjects = true;
|
|
73
196
|
|
|
74
|
-
|
|
75
|
-
|
|
197
|
+
/**
|
|
198
|
+
* Whether the default framebuffer should have a depth buffer or not.
|
|
199
|
+
*
|
|
200
|
+
* @type {boolean}
|
|
201
|
+
* @default true
|
|
202
|
+
*/
|
|
203
|
+
this.depth = depth;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Whether the default framebuffer should have a stencil buffer or not.
|
|
207
|
+
*
|
|
208
|
+
* @type {boolean}
|
|
209
|
+
* @default false
|
|
210
|
+
*/
|
|
211
|
+
this.stencil = stencil;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Holds a series of statistical information about the GPU memory
|
|
215
|
+
* and the rendering process. Useful for debugging and monitoring.
|
|
216
|
+
*
|
|
217
|
+
* @type {Info}
|
|
218
|
+
*/
|
|
219
|
+
this.info = new Info();
|
|
76
220
|
|
|
77
|
-
this.
|
|
221
|
+
this.nodes = {
|
|
222
|
+
modelViewMatrix: null,
|
|
223
|
+
modelNormalViewMatrix: null
|
|
224
|
+
};
|
|
78
225
|
|
|
79
|
-
|
|
226
|
+
/**
|
|
227
|
+
* The node library defines how certain library objects like materials, lights
|
|
228
|
+
* or tone mapping functions are mapped to node types. This is required since
|
|
229
|
+
* although instances of classes like `MeshBasicMaterial` or `PointLight` can
|
|
230
|
+
* be part of the scene graph, they are internally represented as nodes for
|
|
231
|
+
* further processing.
|
|
232
|
+
*
|
|
233
|
+
* @type {NodeLibrary}
|
|
234
|
+
*/
|
|
235
|
+
this.library = new NodeLibrary();
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* A map-like data structure for managing lights.
|
|
239
|
+
*
|
|
240
|
+
* @type {Lighting}
|
|
241
|
+
*/
|
|
242
|
+
this.lighting = new Lighting();
|
|
80
243
|
|
|
81
244
|
// internals
|
|
82
245
|
|
|
246
|
+
/**
|
|
247
|
+
* This callback function can be used to provide a fallback backend, if the primary backend can't be targeted.
|
|
248
|
+
*
|
|
249
|
+
* @private
|
|
250
|
+
* @type {Function}
|
|
251
|
+
*/
|
|
252
|
+
this._getFallback = getFallback;
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* The renderer's pixel ratio.
|
|
256
|
+
*
|
|
257
|
+
* @private
|
|
258
|
+
* @type {number}
|
|
259
|
+
* @default 1
|
|
260
|
+
*/
|
|
83
261
|
this._pixelRatio = 1;
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* The width of the renderer's default framebuffer in logical pixel unit.
|
|
265
|
+
*
|
|
266
|
+
* @private
|
|
267
|
+
* @type {number}
|
|
268
|
+
*/
|
|
84
269
|
this._width = this.domElement.width;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* The height of the renderer's default framebuffer in logical pixel unit.
|
|
273
|
+
*
|
|
274
|
+
* @private
|
|
275
|
+
* @type {number}
|
|
276
|
+
*/
|
|
85
277
|
this._height = this.domElement.height;
|
|
86
278
|
|
|
279
|
+
/**
|
|
280
|
+
* The viewport of the renderer in logical pixel unit.
|
|
281
|
+
*
|
|
282
|
+
* @private
|
|
283
|
+
* @type {Vector4}
|
|
284
|
+
*/
|
|
87
285
|
this._viewport = new Vector4( 0, 0, this._width, this._height );
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* The scissor rectangle of the renderer in logical pixel unit.
|
|
289
|
+
*
|
|
290
|
+
* @private
|
|
291
|
+
* @type {Vector4}
|
|
292
|
+
*/
|
|
88
293
|
this._scissor = new Vector4( 0, 0, this._width, this._height );
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Whether the scissor test should be enabled or not.
|
|
297
|
+
*
|
|
298
|
+
* @private
|
|
299
|
+
* @type {boolean}
|
|
300
|
+
*/
|
|
89
301
|
this._scissorTest = false;
|
|
90
302
|
|
|
303
|
+
/**
|
|
304
|
+
* A reference to a renderer module for managing shader attributes.
|
|
305
|
+
*
|
|
306
|
+
* @private
|
|
307
|
+
* @type {?Attributes}
|
|
308
|
+
* @default null
|
|
309
|
+
*/
|
|
91
310
|
this._attributes = null;
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* A reference to a renderer module for managing geometries.
|
|
314
|
+
*
|
|
315
|
+
* @private
|
|
316
|
+
* @type {?Geometries}
|
|
317
|
+
* @default null
|
|
318
|
+
*/
|
|
92
319
|
this._geometries = null;
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* A reference to a renderer module for managing node related logic.
|
|
323
|
+
*
|
|
324
|
+
* @private
|
|
325
|
+
* @type {?Nodes}
|
|
326
|
+
* @default null
|
|
327
|
+
*/
|
|
93
328
|
this._nodes = null;
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* A reference to a renderer module for managing the internal animation loop.
|
|
332
|
+
*
|
|
333
|
+
* @private
|
|
334
|
+
* @type {?Animation}
|
|
335
|
+
* @default null
|
|
336
|
+
*/
|
|
94
337
|
this._animation = null;
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* A reference to a renderer module for managing shader program bindings.
|
|
341
|
+
*
|
|
342
|
+
* @private
|
|
343
|
+
* @type {?Bindings}
|
|
344
|
+
* @default null
|
|
345
|
+
*/
|
|
95
346
|
this._bindings = null;
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* A reference to a renderer module for managing render objects.
|
|
350
|
+
*
|
|
351
|
+
* @private
|
|
352
|
+
* @type {?RenderObjects}
|
|
353
|
+
* @default null
|
|
354
|
+
*/
|
|
96
355
|
this._objects = null;
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* A reference to a renderer module for managing render and compute pipelines.
|
|
359
|
+
*
|
|
360
|
+
* @private
|
|
361
|
+
* @type {?Pipelines}
|
|
362
|
+
* @default null
|
|
363
|
+
*/
|
|
97
364
|
this._pipelines = null;
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* A reference to a renderer module for managing render bundles.
|
|
368
|
+
*
|
|
369
|
+
* @private
|
|
370
|
+
* @type {?RenderBundles}
|
|
371
|
+
* @default null
|
|
372
|
+
*/
|
|
98
373
|
this._bundles = null;
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* A reference to a renderer module for managing render lists.
|
|
377
|
+
*
|
|
378
|
+
* @private
|
|
379
|
+
* @type {?RenderLists}
|
|
380
|
+
* @default null
|
|
381
|
+
*/
|
|
99
382
|
this._renderLists = null;
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* A reference to a renderer module for managing render contexts.
|
|
386
|
+
*
|
|
387
|
+
* @private
|
|
388
|
+
* @type {?RenderContexts}
|
|
389
|
+
* @default null
|
|
390
|
+
*/
|
|
100
391
|
this._renderContexts = null;
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* A reference to a renderer module for managing textures.
|
|
395
|
+
*
|
|
396
|
+
* @private
|
|
397
|
+
* @type {?Textures}
|
|
398
|
+
* @default null
|
|
399
|
+
*/
|
|
101
400
|
this._textures = null;
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* A reference to a renderer module for backgrounds.
|
|
404
|
+
*
|
|
405
|
+
* @private
|
|
406
|
+
* @type {?Background}
|
|
407
|
+
* @default null
|
|
408
|
+
*/
|
|
102
409
|
this._background = null;
|
|
103
410
|
|
|
411
|
+
/**
|
|
412
|
+
* This fullscreen quad is used for internal render passes
|
|
413
|
+
* like the tone mapping and color space output pass.
|
|
414
|
+
*
|
|
415
|
+
* @private
|
|
416
|
+
* @type {QuadMesh}
|
|
417
|
+
*/
|
|
104
418
|
this._quad = new QuadMesh( new NodeMaterial() );
|
|
105
|
-
|
|
419
|
+
this._quad.material.name = 'Renderer_output';
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* A reference to the current render context.
|
|
423
|
+
*
|
|
424
|
+
* @private
|
|
425
|
+
* @type {?RenderContext}
|
|
426
|
+
* @default null
|
|
427
|
+
*/
|
|
106
428
|
this._currentRenderContext = null;
|
|
107
429
|
|
|
430
|
+
/**
|
|
431
|
+
* A custom sort function for the opaque render list.
|
|
432
|
+
*
|
|
433
|
+
* @private
|
|
434
|
+
* @type {?Function}
|
|
435
|
+
* @default null
|
|
436
|
+
*/
|
|
108
437
|
this._opaqueSort = null;
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* A custom sort function for the transparent render list.
|
|
441
|
+
*
|
|
442
|
+
* @private
|
|
443
|
+
* @type {?Function}
|
|
444
|
+
* @default null
|
|
445
|
+
*/
|
|
109
446
|
this._transparentSort = null;
|
|
110
447
|
|
|
448
|
+
/**
|
|
449
|
+
* The framebuffer target.
|
|
450
|
+
*
|
|
451
|
+
* @private
|
|
452
|
+
* @type {?RenderTarget}
|
|
453
|
+
* @default null
|
|
454
|
+
*/
|
|
111
455
|
this._frameBufferTarget = null;
|
|
112
456
|
|
|
113
457
|
const alphaClear = this.alpha === true ? 0 : 1;
|
|
114
458
|
|
|
459
|
+
/**
|
|
460
|
+
* The clear color value.
|
|
461
|
+
*
|
|
462
|
+
* @private
|
|
463
|
+
* @type {Color4}
|
|
464
|
+
*/
|
|
115
465
|
this._clearColor = new Color4( 0, 0, 0, alphaClear );
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* The clear depth value.
|
|
469
|
+
*
|
|
470
|
+
* @private
|
|
471
|
+
* @type {number}
|
|
472
|
+
* @default 1
|
|
473
|
+
*/
|
|
116
474
|
this._clearDepth = 1;
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* The clear stencil value.
|
|
478
|
+
*
|
|
479
|
+
* @private
|
|
480
|
+
* @type {number}
|
|
481
|
+
* @default 0
|
|
482
|
+
*/
|
|
117
483
|
this._clearStencil = 0;
|
|
118
484
|
|
|
485
|
+
/**
|
|
486
|
+
* The current render target.
|
|
487
|
+
*
|
|
488
|
+
* @private
|
|
489
|
+
* @type {?RenderTarget}
|
|
490
|
+
* @default null
|
|
491
|
+
*/
|
|
119
492
|
this._renderTarget = null;
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* The active cube face.
|
|
496
|
+
*
|
|
497
|
+
* @private
|
|
498
|
+
* @type {number}
|
|
499
|
+
* @default 0
|
|
500
|
+
*/
|
|
120
501
|
this._activeCubeFace = 0;
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* The active mipmap level.
|
|
505
|
+
*
|
|
506
|
+
* @private
|
|
507
|
+
* @type {number}
|
|
508
|
+
* @default 0
|
|
509
|
+
*/
|
|
121
510
|
this._activeMipmapLevel = 0;
|
|
122
511
|
|
|
512
|
+
/**
|
|
513
|
+
* The current output render target.
|
|
514
|
+
*
|
|
515
|
+
* @private
|
|
516
|
+
* @type {?RenderTarget}
|
|
517
|
+
* @default null
|
|
518
|
+
*/
|
|
519
|
+
this._outputRenderTarget = null;
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* The MRT setting.
|
|
523
|
+
*
|
|
524
|
+
* @private
|
|
525
|
+
* @type {?MRTNode}
|
|
526
|
+
* @default null
|
|
527
|
+
*/
|
|
123
528
|
this._mrt = null;
|
|
124
529
|
|
|
530
|
+
/**
|
|
531
|
+
* This function defines how a render object is going
|
|
532
|
+
* to be rendered.
|
|
533
|
+
*
|
|
534
|
+
* @private
|
|
535
|
+
* @type {?Function}
|
|
536
|
+
* @default null
|
|
537
|
+
*/
|
|
125
538
|
this._renderObjectFunction = null;
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Used to keep track of the current render object function.
|
|
542
|
+
*
|
|
543
|
+
* @private
|
|
544
|
+
* @type {?Function}
|
|
545
|
+
* @default null
|
|
546
|
+
*/
|
|
126
547
|
this._currentRenderObjectFunction = null;
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Used to keep track of the current render bundle.
|
|
551
|
+
*
|
|
552
|
+
* @private
|
|
553
|
+
* @type {?RenderBundle}
|
|
554
|
+
* @default null
|
|
555
|
+
*/
|
|
127
556
|
this._currentRenderBundle = null;
|
|
128
557
|
|
|
558
|
+
/**
|
|
559
|
+
* Next to `_renderObjectFunction()`, this function provides another hook
|
|
560
|
+
* for influencing the render process of a render object. It is meant for internal
|
|
561
|
+
* use and only relevant for `compileAsync()` right now. Instead of using
|
|
562
|
+
* the default logic of `_renderObjectDirect()` which actually draws the render object,
|
|
563
|
+
* a different function might be used which performs no draw but just the node
|
|
564
|
+
* and pipeline updates.
|
|
565
|
+
*
|
|
566
|
+
* @private
|
|
567
|
+
* @type {?Function}
|
|
568
|
+
* @default null
|
|
569
|
+
*/
|
|
129
570
|
this._handleObjectFunction = this._renderObjectDirect;
|
|
130
571
|
|
|
572
|
+
/**
|
|
573
|
+
* Indicates whether the device has been lost or not. In WebGL terms, the device
|
|
574
|
+
* lost is considered as a context lost. When this is set to `true`, rendering
|
|
575
|
+
* isn't possible anymore.
|
|
576
|
+
*
|
|
577
|
+
* @private
|
|
578
|
+
* @type {boolean}
|
|
579
|
+
* @default false
|
|
580
|
+
*/
|
|
581
|
+
this._isDeviceLost = false;
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* A callback function that defines what should happen when a device/context lost occurs.
|
|
585
|
+
*
|
|
586
|
+
* @type {Function}
|
|
587
|
+
*/
|
|
588
|
+
this.onDeviceLost = this._onDeviceLost;
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* Defines the type of color buffers. The default `HalfFloatType` is recommend for
|
|
592
|
+
* best quality. To save memory and bandwidth, `UnsignedByteType` might be used.
|
|
593
|
+
* This will reduce rendering quality though.
|
|
594
|
+
*
|
|
595
|
+
* @private
|
|
596
|
+
* @type {number}
|
|
597
|
+
* @default HalfFloatType
|
|
598
|
+
*/
|
|
599
|
+
this._colorBufferType = colorBufferType;
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Whether the renderer has been initialized or not.
|
|
603
|
+
*
|
|
604
|
+
* @private
|
|
605
|
+
* @type {boolean}
|
|
606
|
+
* @default false
|
|
607
|
+
*/
|
|
131
608
|
this._initialized = false;
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* A reference to the promise which initializes the renderer.
|
|
612
|
+
*
|
|
613
|
+
* @private
|
|
614
|
+
* @type {?Promise<this>}
|
|
615
|
+
* @default null
|
|
616
|
+
*/
|
|
132
617
|
this._initPromise = null;
|
|
133
618
|
|
|
619
|
+
/**
|
|
620
|
+
* An array of compilation promises which are used in `compileAsync()`.
|
|
621
|
+
*
|
|
622
|
+
* @private
|
|
623
|
+
* @type {?Array<Promise>}
|
|
624
|
+
* @default null
|
|
625
|
+
*/
|
|
134
626
|
this._compilationPromises = null;
|
|
135
627
|
|
|
628
|
+
/**
|
|
629
|
+
* Whether the renderer should render transparent render objects or not.
|
|
630
|
+
*
|
|
631
|
+
* @type {boolean}
|
|
632
|
+
* @default true
|
|
633
|
+
*/
|
|
136
634
|
this.transparent = true;
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Whether the renderer should render opaque render objects or not.
|
|
638
|
+
*
|
|
639
|
+
* @type {boolean}
|
|
640
|
+
* @default true
|
|
641
|
+
*/
|
|
137
642
|
this.opaque = true;
|
|
138
643
|
|
|
644
|
+
/**
|
|
645
|
+
* Shadow map configuration
|
|
646
|
+
* @typedef {Object} ShadowMapConfig
|
|
647
|
+
* @property {boolean} enabled - Whether to globally enable shadows or not.
|
|
648
|
+
* @property {number} type - The shadow map type.
|
|
649
|
+
*/
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* The renderer's shadow configuration.
|
|
653
|
+
*
|
|
654
|
+
* @type {ShadowMapConfig}
|
|
655
|
+
*/
|
|
139
656
|
this.shadowMap = {
|
|
140
657
|
enabled: false,
|
|
141
658
|
type: PCFShadowMap
|
|
142
659
|
};
|
|
143
660
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
661
|
+
/**
|
|
662
|
+
* XR configuration.
|
|
663
|
+
* @typedef {Object} XRConfig
|
|
664
|
+
* @property {boolean} enabled - Whether to globally enable XR or not.
|
|
665
|
+
*/
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* The renderer's XR manager.
|
|
669
|
+
*
|
|
670
|
+
* @type {XRManager}
|
|
671
|
+
*/
|
|
672
|
+
this.xr = new XRManager( this );
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* Debug configuration.
|
|
676
|
+
* @typedef {Object} DebugConfig
|
|
677
|
+
* @property {boolean} checkShaderErrors - Whether shader errors should be checked or not.
|
|
678
|
+
* @property {Function} onShaderError - A callback function that is executed when a shader error happens. Only supported with WebGL 2 right now.
|
|
679
|
+
* @property {Function} getShaderAsync - Allows the get the raw shader code for the given scene, camera and 3D object.
|
|
680
|
+
*/
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* The renderer's debug configuration.
|
|
684
|
+
*
|
|
685
|
+
* @type {DebugConfig}
|
|
686
|
+
*/
|
|
148
687
|
this.debug = {
|
|
149
688
|
checkShaderErrors: true,
|
|
150
689
|
onShaderError: null,
|
|
@@ -157,7 +696,7 @@ class Renderer {
|
|
|
157
696
|
|
|
158
697
|
const material = scene.overrideMaterial || object.material;
|
|
159
698
|
|
|
160
|
-
const renderObject = this._objects.get( object, material, scene, camera, renderList.lightsNode, renderContext );
|
|
699
|
+
const renderObject = this._objects.get( object, material, scene, camera, renderList.lightsNode, renderContext, renderContext.clippingContext );
|
|
161
700
|
|
|
162
701
|
const { fragmentShader, vertexShader } = renderObject.getNodeBuilderState();
|
|
163
702
|
|
|
@@ -168,6 +707,12 @@ class Renderer {
|
|
|
168
707
|
|
|
169
708
|
}
|
|
170
709
|
|
|
710
|
+
/**
|
|
711
|
+
* Initializes the renderer so it is ready for usage.
|
|
712
|
+
*
|
|
713
|
+
* @async
|
|
714
|
+
* @return {Promise<this>} A Promise that resolves when the renderer has been initialized.
|
|
715
|
+
*/
|
|
171
716
|
async init() {
|
|
172
717
|
|
|
173
718
|
if ( this._initialized ) {
|
|
@@ -184,7 +729,7 @@ class Renderer {
|
|
|
184
729
|
|
|
185
730
|
this._initPromise = new Promise( async ( resolve, reject ) => {
|
|
186
731
|
|
|
187
|
-
|
|
732
|
+
let backend = this.backend;
|
|
188
733
|
|
|
189
734
|
try {
|
|
190
735
|
|
|
@@ -192,8 +737,28 @@ class Renderer {
|
|
|
192
737
|
|
|
193
738
|
} catch ( error ) {
|
|
194
739
|
|
|
195
|
-
|
|
196
|
-
|
|
740
|
+
if ( this._getFallback !== null ) {
|
|
741
|
+
|
|
742
|
+
// try the fallback
|
|
743
|
+
|
|
744
|
+
try {
|
|
745
|
+
|
|
746
|
+
this.backend = backend = this._getFallback( error );
|
|
747
|
+
await backend.init( this );
|
|
748
|
+
|
|
749
|
+
} catch ( error ) {
|
|
750
|
+
|
|
751
|
+
reject( error );
|
|
752
|
+
return;
|
|
753
|
+
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
} else {
|
|
757
|
+
|
|
758
|
+
reject( error );
|
|
759
|
+
return;
|
|
760
|
+
|
|
761
|
+
}
|
|
197
762
|
|
|
198
763
|
}
|
|
199
764
|
|
|
@@ -206,15 +771,16 @@ class Renderer {
|
|
|
206
771
|
this._pipelines = new Pipelines( backend, this._nodes );
|
|
207
772
|
this._bindings = new Bindings( backend, this._nodes, this._textures, this._attributes, this._pipelines, this.info );
|
|
208
773
|
this._objects = new RenderObjects( this, this._nodes, this._geometries, this._pipelines, this._bindings, this.info );
|
|
209
|
-
this._renderLists = new RenderLists();
|
|
774
|
+
this._renderLists = new RenderLists( this.lighting );
|
|
210
775
|
this._bundles = new RenderBundles();
|
|
211
776
|
this._renderContexts = new RenderContexts();
|
|
212
777
|
|
|
213
778
|
//
|
|
214
779
|
|
|
780
|
+
this._animation.start();
|
|
215
781
|
this._initialized = true;
|
|
216
782
|
|
|
217
|
-
resolve();
|
|
783
|
+
resolve( this );
|
|
218
784
|
|
|
219
785
|
} );
|
|
220
786
|
|
|
@@ -222,14 +788,39 @@ class Renderer {
|
|
|
222
788
|
|
|
223
789
|
}
|
|
224
790
|
|
|
791
|
+
/**
|
|
792
|
+
* The coordinate system of the renderer. The value of this property
|
|
793
|
+
* depends on the selected backend. Either `THREE.WebGLCoordinateSystem` or
|
|
794
|
+
* `THREE.WebGPUCoordinateSystem`.
|
|
795
|
+
*
|
|
796
|
+
* @readonly
|
|
797
|
+
* @type {number}
|
|
798
|
+
*/
|
|
225
799
|
get coordinateSystem() {
|
|
226
800
|
|
|
227
801
|
return this.backend.coordinateSystem;
|
|
228
802
|
|
|
229
803
|
}
|
|
230
804
|
|
|
805
|
+
/**
|
|
806
|
+
* Compiles all materials in the given scene. This can be useful to avoid a
|
|
807
|
+
* phenomenon which is called "shader compilation stutter", which occurs when
|
|
808
|
+
* rendering an object with a new shader for the first time.
|
|
809
|
+
*
|
|
810
|
+
* If you want to add a 3D object to an existing scene, use the third optional
|
|
811
|
+
* parameter for applying the target scene. Note that the (target) scene's lighting
|
|
812
|
+
* and environment must be configured before calling this method.
|
|
813
|
+
*
|
|
814
|
+
* @async
|
|
815
|
+
* @param {Object3D} scene - The scene or 3D object to precompile.
|
|
816
|
+
* @param {Camera} camera - The camera that is used to render the scene.
|
|
817
|
+
* @param {Scene} targetScene - If the first argument is a 3D object, this parameter must represent the scene the 3D object is going to be added.
|
|
818
|
+
* @return {Promise<Array>} A Promise that resolves when the compile has been finished.
|
|
819
|
+
*/
|
|
231
820
|
async compileAsync( scene, camera, targetScene = null ) {
|
|
232
821
|
|
|
822
|
+
if ( this._isDeviceLost === true ) return;
|
|
823
|
+
|
|
233
824
|
if ( this._initialized === false ) await this.init();
|
|
234
825
|
|
|
235
826
|
// preserve render tree
|
|
@@ -272,7 +863,7 @@ class Renderer {
|
|
|
272
863
|
renderContext.stencil = this.stencil;
|
|
273
864
|
|
|
274
865
|
if ( ! renderContext.clippingContext ) renderContext.clippingContext = new ClippingContext();
|
|
275
|
-
renderContext.clippingContext.updateGlobal(
|
|
866
|
+
renderContext.clippingContext.updateGlobal( sceneRef, camera );
|
|
276
867
|
|
|
277
868
|
//
|
|
278
869
|
|
|
@@ -283,7 +874,7 @@ class Renderer {
|
|
|
283
874
|
const renderList = this._renderLists.get( scene, camera );
|
|
284
875
|
renderList.begin();
|
|
285
876
|
|
|
286
|
-
this._projectObject( scene, camera, 0, renderList );
|
|
877
|
+
this._projectObject( scene, camera, 0, renderList, renderContext.clippingContext );
|
|
287
878
|
|
|
288
879
|
// include lights from target scene
|
|
289
880
|
if ( targetScene !== scene ) {
|
|
@@ -322,20 +913,17 @@ class Renderer {
|
|
|
322
913
|
|
|
323
914
|
//
|
|
324
915
|
|
|
325
|
-
this._nodes.updateScene( sceneRef );
|
|
326
|
-
|
|
327
|
-
//
|
|
328
|
-
|
|
329
916
|
this._background.update( sceneRef, renderList, renderContext );
|
|
330
917
|
|
|
331
918
|
// process render lists
|
|
332
919
|
|
|
333
920
|
const opaqueObjects = renderList.opaque;
|
|
334
921
|
const transparentObjects = renderList.transparent;
|
|
922
|
+
const transparentDoublePassObjects = renderList.transparentDoublePass;
|
|
335
923
|
const lightsNode = renderList.lightsNode;
|
|
336
924
|
|
|
337
925
|
if ( this.opaque === true && opaqueObjects.length > 0 ) this._renderObjects( opaqueObjects, camera, sceneRef, lightsNode );
|
|
338
|
-
if ( this.transparent === true && transparentObjects.length > 0 ) this.
|
|
926
|
+
if ( this.transparent === true && transparentObjects.length > 0 ) this._renderTransparents( transparentObjects, transparentDoublePassObjects, camera, sceneRef, lightsNode );
|
|
339
927
|
|
|
340
928
|
// restore render tree
|
|
341
929
|
|
|
@@ -353,16 +941,41 @@ class Renderer {
|
|
|
353
941
|
|
|
354
942
|
}
|
|
355
943
|
|
|
944
|
+
/**
|
|
945
|
+
* Renders the scene in an async fashion.
|
|
946
|
+
*
|
|
947
|
+
* @async
|
|
948
|
+
* @param {Object3D} scene - The scene or 3D object to render.
|
|
949
|
+
* @param {Camera} camera - The camera.
|
|
950
|
+
* @return {Promise} A Promise that resolves when the render has been finished.
|
|
951
|
+
*/
|
|
356
952
|
async renderAsync( scene, camera ) {
|
|
357
953
|
|
|
358
954
|
if ( this._initialized === false ) await this.init();
|
|
359
955
|
|
|
360
|
-
|
|
956
|
+
this._renderScene( scene, camera );
|
|
957
|
+
|
|
958
|
+
}
|
|
361
959
|
|
|
362
|
-
|
|
960
|
+
/**
|
|
961
|
+
* Can be used to synchronize CPU operations with GPU tasks. So when this method is called,
|
|
962
|
+
* the CPU waits for the GPU to complete its operation (e.g. a compute task).
|
|
963
|
+
*
|
|
964
|
+
* @async
|
|
965
|
+
* @return {Promise} A Promise that resolves when synchronization has been finished.
|
|
966
|
+
*/
|
|
967
|
+
async waitForGPU() {
|
|
968
|
+
|
|
969
|
+
await this.backend.waitForGPU();
|
|
363
970
|
|
|
364
971
|
}
|
|
365
972
|
|
|
973
|
+
/**
|
|
974
|
+
* Sets the given MRT configuration.
|
|
975
|
+
*
|
|
976
|
+
* @param {MRTNode} mrt - The MRT node to set.
|
|
977
|
+
* @return {Renderer} A reference to this renderer.
|
|
978
|
+
*/
|
|
366
979
|
setMRT( mrt ) {
|
|
367
980
|
|
|
368
981
|
this._mrt = mrt;
|
|
@@ -371,45 +984,85 @@ class Renderer {
|
|
|
371
984
|
|
|
372
985
|
}
|
|
373
986
|
|
|
987
|
+
/**
|
|
988
|
+
* Returns the MRT configuration.
|
|
989
|
+
*
|
|
990
|
+
* @return {MRTNode} The MRT configuration.
|
|
991
|
+
*/
|
|
374
992
|
getMRT() {
|
|
375
993
|
|
|
376
994
|
return this._mrt;
|
|
377
995
|
|
|
378
996
|
}
|
|
379
997
|
|
|
998
|
+
/**
|
|
999
|
+
* Returns the color buffer type.
|
|
1000
|
+
*
|
|
1001
|
+
* @return {number} The color buffer type.
|
|
1002
|
+
*/
|
|
1003
|
+
getColorBufferType() {
|
|
1004
|
+
|
|
1005
|
+
return this._colorBufferType;
|
|
1006
|
+
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
/**
|
|
1010
|
+
* Default implementation of the device lost callback.
|
|
1011
|
+
*
|
|
1012
|
+
* @private
|
|
1013
|
+
* @param {Object} info - Information about the context lost.
|
|
1014
|
+
*/
|
|
1015
|
+
_onDeviceLost( info ) {
|
|
1016
|
+
|
|
1017
|
+
let errorMessage = `THREE.WebGPURenderer: ${info.api} Device Lost:\n\nMessage: ${info.message}`;
|
|
1018
|
+
|
|
1019
|
+
if ( info.reason ) {
|
|
1020
|
+
|
|
1021
|
+
errorMessage += `\nReason: ${info.reason}`;
|
|
1022
|
+
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
console.error( errorMessage );
|
|
1026
|
+
|
|
1027
|
+
this._isDeviceLost = true;
|
|
1028
|
+
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
/**
|
|
1032
|
+
* Renders the given render bundle.
|
|
1033
|
+
*
|
|
1034
|
+
* @private
|
|
1035
|
+
* @param {Object} bundle - Render bundle data.
|
|
1036
|
+
* @param {Scene} sceneRef - The scene the render bundle belongs to.
|
|
1037
|
+
* @param {LightsNode} lightsNode - The current lights node.
|
|
1038
|
+
*/
|
|
380
1039
|
_renderBundle( bundle, sceneRef, lightsNode ) {
|
|
381
1040
|
|
|
382
|
-
const {
|
|
1041
|
+
const { bundleGroup, camera, renderList } = bundle;
|
|
383
1042
|
|
|
384
1043
|
const renderContext = this._currentRenderContext;
|
|
385
|
-
const renderContextData = this.backend.get( renderContext );
|
|
386
1044
|
|
|
387
1045
|
//
|
|
388
1046
|
|
|
389
|
-
const renderBundle = this._bundles.get(
|
|
390
|
-
|
|
1047
|
+
const renderBundle = this._bundles.get( bundleGroup, camera );
|
|
391
1048
|
const renderBundleData = this.backend.get( renderBundle );
|
|
1049
|
+
|
|
392
1050
|
if ( renderBundleData.renderContexts === undefined ) renderBundleData.renderContexts = new Set();
|
|
393
1051
|
|
|
394
1052
|
//
|
|
395
1053
|
|
|
396
|
-
const
|
|
1054
|
+
const needsUpdate = bundleGroup.version !== renderBundleData.version;
|
|
1055
|
+
const renderBundleNeedsUpdate = renderBundleData.renderContexts.has( renderContext ) === false || needsUpdate;
|
|
397
1056
|
|
|
398
1057
|
renderBundleData.renderContexts.add( renderContext );
|
|
399
1058
|
|
|
400
1059
|
if ( renderBundleNeedsUpdate ) {
|
|
401
1060
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
const nodeFrame = this._nodes.nodeFrame;
|
|
1061
|
+
this.backend.beginBundle( renderContext );
|
|
405
1062
|
|
|
406
|
-
|
|
407
|
-
renderContextData.renderBundles = [];
|
|
408
|
-
renderContextData.scene = sceneRef;
|
|
409
|
-
renderContextData.camera = camera;
|
|
410
|
-
renderContextData.renderId = nodeFrame.renderId;
|
|
1063
|
+
if ( renderBundleData.renderObjects === undefined || needsUpdate ) {
|
|
411
1064
|
|
|
412
|
-
|
|
1065
|
+
renderBundleData.renderObjects = [];
|
|
413
1066
|
|
|
414
1067
|
}
|
|
415
1068
|
|
|
@@ -417,43 +1070,55 @@ class Renderer {
|
|
|
417
1070
|
|
|
418
1071
|
const opaqueObjects = renderList.opaque;
|
|
419
1072
|
|
|
420
|
-
if ( opaqueObjects.length > 0 ) this._renderObjects( opaqueObjects, camera, sceneRef, lightsNode );
|
|
1073
|
+
if ( this.opaque === true && opaqueObjects.length > 0 ) this._renderObjects( opaqueObjects, camera, sceneRef, lightsNode );
|
|
421
1074
|
|
|
422
1075
|
this._currentRenderBundle = null;
|
|
423
1076
|
|
|
424
1077
|
//
|
|
425
1078
|
|
|
426
|
-
|
|
1079
|
+
this.backend.finishBundle( renderContext, renderBundle );
|
|
427
1080
|
|
|
428
|
-
|
|
1081
|
+
renderBundleData.version = bundleGroup.version;
|
|
429
1082
|
|
|
430
|
-
|
|
431
|
-
const renderContextData = this.backend.get( renderContext );
|
|
1083
|
+
} else {
|
|
432
1084
|
|
|
433
|
-
|
|
1085
|
+
const { renderObjects } = renderBundleData;
|
|
434
1086
|
|
|
435
|
-
|
|
1087
|
+
for ( let i = 0, l = renderObjects.length; i < l; i ++ ) {
|
|
436
1088
|
|
|
437
|
-
|
|
1089
|
+
const renderObject = renderObjects[ i ];
|
|
438
1090
|
|
|
439
|
-
|
|
1091
|
+
if ( this._nodes.needsRefresh( renderObject ) ) {
|
|
440
1092
|
|
|
441
|
-
|
|
442
|
-
renderObject.object.normalMatrix.getNormalMatrix( renderObject.object.modelViewMatrix );
|
|
1093
|
+
this._nodes.updateBefore( renderObject );
|
|
443
1094
|
|
|
444
|
-
|
|
445
|
-
|
|
1095
|
+
this._nodes.updateForRender( renderObject );
|
|
1096
|
+
this._bindings.updateForRender( renderObject );
|
|
446
1097
|
|
|
447
|
-
|
|
1098
|
+
this._nodes.updateAfter( renderObject );
|
|
448
1099
|
|
|
449
|
-
|
|
1100
|
+
}
|
|
450
1101
|
|
|
451
1102
|
}
|
|
452
1103
|
|
|
453
1104
|
}
|
|
454
1105
|
|
|
1106
|
+
this.backend.addBundle( renderContext, renderBundle );
|
|
1107
|
+
|
|
455
1108
|
}
|
|
456
1109
|
|
|
1110
|
+
/**
|
|
1111
|
+
* Renders the scene or 3D object with the given camera. This method can only be called
|
|
1112
|
+
* if the renderer has been initialized.
|
|
1113
|
+
*
|
|
1114
|
+
* The target of the method is the default framebuffer (meaning the canvas)
|
|
1115
|
+
* or alternatively a render target when specified via `setRenderTarget()`.
|
|
1116
|
+
*
|
|
1117
|
+
* @param {Object3D} scene - The scene or 3D object to render.
|
|
1118
|
+
* @param {Camera} camera - The camera to render the scene with.
|
|
1119
|
+
* @return {?Promise} A Promise that resolve when the scene has been rendered.
|
|
1120
|
+
* Only returned when the renderer has not been initialized.
|
|
1121
|
+
*/
|
|
457
1122
|
render( scene, camera ) {
|
|
458
1123
|
|
|
459
1124
|
if ( this._initialized === false ) {
|
|
@@ -468,12 +1133,20 @@ class Renderer {
|
|
|
468
1133
|
|
|
469
1134
|
}
|
|
470
1135
|
|
|
1136
|
+
/**
|
|
1137
|
+
* Returns an internal render target which is used when computing the output tone mapping
|
|
1138
|
+
* and color space conversion. Unlike in `WebGLRenderer`, this is done in a separate render
|
|
1139
|
+
* pass and not inline to achieve more correct results.
|
|
1140
|
+
*
|
|
1141
|
+
* @private
|
|
1142
|
+
* @return {?RenderTarget} The render target. The method returns `null` if no output conversion should be applied.
|
|
1143
|
+
*/
|
|
471
1144
|
_getFrameBufferTarget() {
|
|
472
1145
|
|
|
473
|
-
const { currentColorSpace } = this;
|
|
1146
|
+
const { currentToneMapping, currentColorSpace } = this;
|
|
474
1147
|
|
|
475
|
-
const useToneMapping =
|
|
476
|
-
const useColorSpace =
|
|
1148
|
+
const useToneMapping = currentToneMapping !== NoToneMapping;
|
|
1149
|
+
const useColorSpace = currentColorSpace !== LinearSRGBColorSpace;
|
|
477
1150
|
|
|
478
1151
|
if ( useToneMapping === false && useColorSpace === false ) return null;
|
|
479
1152
|
|
|
@@ -487,7 +1160,7 @@ class Renderer {
|
|
|
487
1160
|
frameBufferTarget = new RenderTarget( width, height, {
|
|
488
1161
|
depthBuffer: depth,
|
|
489
1162
|
stencilBuffer: stencil,
|
|
490
|
-
type:
|
|
1163
|
+
type: this._colorBufferType,
|
|
491
1164
|
format: RGBAFormat,
|
|
492
1165
|
colorSpace: LinearSRGBColorSpace,
|
|
493
1166
|
generateMipmaps: false,
|
|
@@ -515,8 +1188,19 @@ class Renderer {
|
|
|
515
1188
|
|
|
516
1189
|
}
|
|
517
1190
|
|
|
1191
|
+
/**
|
|
1192
|
+
* Renders the scene or 3D object with the given camera.
|
|
1193
|
+
*
|
|
1194
|
+
* @private
|
|
1195
|
+
* @param {Object3D} scene - The scene or 3D object to render.
|
|
1196
|
+
* @param {Camera} camera - The camera to render the scene with.
|
|
1197
|
+
* @param {boolean} [useFrameBufferTarget=true] - Whether to use a framebuffer target or not.
|
|
1198
|
+
* @return {RenderContext} The current render context.
|
|
1199
|
+
*/
|
|
518
1200
|
_renderScene( scene, camera, useFrameBufferTarget = true ) {
|
|
519
1201
|
|
|
1202
|
+
if ( this._isDeviceLost === true ) return;
|
|
1203
|
+
|
|
520
1204
|
const frameBufferTarget = useFrameBufferTarget ? this._getFrameBufferTarget() : null;
|
|
521
1205
|
|
|
522
1206
|
// preserve render tree
|
|
@@ -531,7 +1215,7 @@ class Renderer {
|
|
|
531
1215
|
|
|
532
1216
|
const sceneRef = ( scene.isScene === true ) ? scene : _scene;
|
|
533
1217
|
|
|
534
|
-
const outputRenderTarget = this._renderTarget;
|
|
1218
|
+
const outputRenderTarget = this._renderTarget || this._outputRenderTarget;
|
|
535
1219
|
|
|
536
1220
|
const activeCubeFace = this._activeCubeFace;
|
|
537
1221
|
const activeMipmapLevel = this._activeMipmapLevel;
|
|
@@ -570,13 +1254,24 @@ class Renderer {
|
|
|
570
1254
|
//
|
|
571
1255
|
|
|
572
1256
|
const coordinateSystem = this.coordinateSystem;
|
|
1257
|
+
const xr = this.xr;
|
|
573
1258
|
|
|
574
|
-
if ( camera.coordinateSystem !== coordinateSystem ) {
|
|
1259
|
+
if ( camera.coordinateSystem !== coordinateSystem && xr.isPresenting === false ) {
|
|
575
1260
|
|
|
576
1261
|
camera.coordinateSystem = coordinateSystem;
|
|
577
|
-
|
|
578
1262
|
camera.updateProjectionMatrix();
|
|
579
1263
|
|
|
1264
|
+
if ( camera.isArrayCamera ) {
|
|
1265
|
+
|
|
1266
|
+
for ( const subCamera of camera.cameras ) {
|
|
1267
|
+
|
|
1268
|
+
subCamera.coordinateSystem = coordinateSystem;
|
|
1269
|
+
subCamera.updateProjectionMatrix();
|
|
1270
|
+
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
}
|
|
1274
|
+
|
|
580
1275
|
}
|
|
581
1276
|
|
|
582
1277
|
//
|
|
@@ -585,6 +1280,13 @@ class Renderer {
|
|
|
585
1280
|
|
|
586
1281
|
if ( camera.parent === null && camera.matrixWorldAutoUpdate === true ) camera.updateMatrixWorld();
|
|
587
1282
|
|
|
1283
|
+
if ( xr.enabled === true && xr.isPresenting === true ) {
|
|
1284
|
+
|
|
1285
|
+
if ( xr.cameraAutoUpdate === true ) xr.updateCamera( camera );
|
|
1286
|
+
camera = xr.getCamera(); // use XR camera for rendering
|
|
1287
|
+
|
|
1288
|
+
}
|
|
1289
|
+
|
|
588
1290
|
//
|
|
589
1291
|
|
|
590
1292
|
let viewport = this._viewport;
|
|
@@ -619,7 +1321,7 @@ class Renderer {
|
|
|
619
1321
|
renderContext.scissorValue.height >>= activeMipmapLevel;
|
|
620
1322
|
|
|
621
1323
|
if ( ! renderContext.clippingContext ) renderContext.clippingContext = new ClippingContext();
|
|
622
|
-
renderContext.clippingContext.updateGlobal(
|
|
1324
|
+
renderContext.clippingContext.updateGlobal( sceneRef, camera );
|
|
623
1325
|
|
|
624
1326
|
//
|
|
625
1327
|
|
|
@@ -633,7 +1335,7 @@ class Renderer {
|
|
|
633
1335
|
const renderList = this._renderLists.get( scene, camera );
|
|
634
1336
|
renderList.begin();
|
|
635
1337
|
|
|
636
|
-
this._projectObject( scene, camera, 0, renderList );
|
|
1338
|
+
this._projectObject( scene, camera, 0, renderList, renderContext.clippingContext );
|
|
637
1339
|
|
|
638
1340
|
renderList.finish();
|
|
639
1341
|
|
|
@@ -678,10 +1380,6 @@ class Renderer {
|
|
|
678
1380
|
|
|
679
1381
|
//
|
|
680
1382
|
|
|
681
|
-
this._nodes.updateScene( sceneRef );
|
|
682
|
-
|
|
683
|
-
//
|
|
684
|
-
|
|
685
1383
|
this._background.update( sceneRef, renderList, renderContext );
|
|
686
1384
|
|
|
687
1385
|
//
|
|
@@ -690,14 +1388,17 @@ class Renderer {
|
|
|
690
1388
|
|
|
691
1389
|
// process render lists
|
|
692
1390
|
|
|
693
|
-
const
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
1391
|
+
const {
|
|
1392
|
+
bundles,
|
|
1393
|
+
lightsNode,
|
|
1394
|
+
transparentDoublePass: transparentDoublePassObjects,
|
|
1395
|
+
transparent: transparentObjects,
|
|
1396
|
+
opaque: opaqueObjects
|
|
1397
|
+
} = renderList;
|
|
697
1398
|
|
|
698
1399
|
if ( bundles.length > 0 ) this._renderBundles( bundles, sceneRef, lightsNode );
|
|
699
1400
|
if ( this.opaque === true && opaqueObjects.length > 0 ) this._renderObjects( opaqueObjects, camera, sceneRef, lightsNode );
|
|
700
|
-
if ( this.transparent === true && transparentObjects.length > 0 ) this.
|
|
1401
|
+
if ( this.transparent === true && transparentObjects.length > 0 ) this._renderTransparents( transparentObjects, transparentDoublePassObjects, camera, sceneRef, lightsNode );
|
|
701
1402
|
|
|
702
1403
|
// finish render pass
|
|
703
1404
|
|
|
@@ -716,16 +1417,7 @@ class Renderer {
|
|
|
716
1417
|
|
|
717
1418
|
this.setRenderTarget( outputRenderTarget, activeCubeFace, activeMipmapLevel );
|
|
718
1419
|
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
if ( this._nodes.hasOutputChange( renderTarget.texture ) ) {
|
|
722
|
-
|
|
723
|
-
quad.material.fragmentNode = this._nodes.getOutputNode( renderTarget.texture );
|
|
724
|
-
quad.material.needsUpdate = true;
|
|
725
|
-
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
this._renderScene( quad, quad.camera, false );
|
|
1420
|
+
this._renderOutput( renderTarget );
|
|
729
1421
|
|
|
730
1422
|
}
|
|
731
1423
|
|
|
@@ -739,24 +1431,81 @@ class Renderer {
|
|
|
739
1431
|
|
|
740
1432
|
}
|
|
741
1433
|
|
|
1434
|
+
/**
|
|
1435
|
+
* The output pass performs tone mapping and color space conversion.
|
|
1436
|
+
*
|
|
1437
|
+
* @private
|
|
1438
|
+
* @param {RenderTarget} renderTarget - The current render target.
|
|
1439
|
+
*/
|
|
1440
|
+
_renderOutput( renderTarget ) {
|
|
1441
|
+
|
|
1442
|
+
const quad = this._quad;
|
|
1443
|
+
|
|
1444
|
+
if ( this._nodes.hasOutputChange( renderTarget.texture ) ) {
|
|
1445
|
+
|
|
1446
|
+
quad.material.fragmentNode = this._nodes.getOutputNode( renderTarget.texture );
|
|
1447
|
+
quad.material.needsUpdate = true;
|
|
1448
|
+
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
// a clear operation clears the intermediate renderTarget texture, but should not update the screen canvas.
|
|
1452
|
+
|
|
1453
|
+
const currentAutoClear = this.autoClear;
|
|
1454
|
+
const currentXR = this.xr.enabled;
|
|
1455
|
+
|
|
1456
|
+
this.autoClear = false;
|
|
1457
|
+
this.xr.enabled = false;
|
|
1458
|
+
|
|
1459
|
+
this._renderScene( quad, quad.camera, false );
|
|
1460
|
+
|
|
1461
|
+
this.autoClear = currentAutoClear;
|
|
1462
|
+
this.xr.enabled = currentXR;
|
|
1463
|
+
|
|
1464
|
+
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
/**
|
|
1468
|
+
* Returns the maximum available anisotropy for texture filtering.
|
|
1469
|
+
*
|
|
1470
|
+
* @return {number} The maximum available anisotropy.
|
|
1471
|
+
*/
|
|
742
1472
|
getMaxAnisotropy() {
|
|
743
1473
|
|
|
744
1474
|
return this.backend.getMaxAnisotropy();
|
|
745
1475
|
|
|
746
1476
|
}
|
|
747
1477
|
|
|
1478
|
+
/**
|
|
1479
|
+
* Returns the active cube face.
|
|
1480
|
+
*
|
|
1481
|
+
* @return {number} The active cube face.
|
|
1482
|
+
*/
|
|
748
1483
|
getActiveCubeFace() {
|
|
749
1484
|
|
|
750
1485
|
return this._activeCubeFace;
|
|
751
1486
|
|
|
752
1487
|
}
|
|
753
1488
|
|
|
1489
|
+
/**
|
|
1490
|
+
* Returns the active mipmap level.
|
|
1491
|
+
*
|
|
1492
|
+
* @return {number} The active mipmap level.
|
|
1493
|
+
*/
|
|
754
1494
|
getActiveMipmapLevel() {
|
|
755
1495
|
|
|
756
1496
|
return this._activeMipmapLevel;
|
|
757
1497
|
|
|
758
1498
|
}
|
|
759
1499
|
|
|
1500
|
+
/**
|
|
1501
|
+
* Applications are advised to always define the animation loop
|
|
1502
|
+
* with this method and not manually with `requestAnimationFrame()`
|
|
1503
|
+
* for best compatibility.
|
|
1504
|
+
*
|
|
1505
|
+
* @async
|
|
1506
|
+
* @param {Function} callback - The application's animation loop.
|
|
1507
|
+
* @return {Promise} A Promise that resolves when the set has been executed.
|
|
1508
|
+
*/
|
|
760
1509
|
async setAnimationLoop( callback ) {
|
|
761
1510
|
|
|
762
1511
|
if ( this._initialized === false ) await this.init();
|
|
@@ -765,44 +1514,94 @@ class Renderer {
|
|
|
765
1514
|
|
|
766
1515
|
}
|
|
767
1516
|
|
|
1517
|
+
/**
|
|
1518
|
+
* Can be used to transfer buffer data from a storage buffer attribute
|
|
1519
|
+
* from the GPU to the CPU in context of compute shaders.
|
|
1520
|
+
*
|
|
1521
|
+
* @async
|
|
1522
|
+
* @param {StorageBufferAttribute} attribute - The storage buffer attribute.
|
|
1523
|
+
* @return {Promise<ArrayBuffer>} A promise that resolves with the buffer data when the data are ready.
|
|
1524
|
+
*/
|
|
768
1525
|
async getArrayBufferAsync( attribute ) {
|
|
769
1526
|
|
|
770
1527
|
return await this.backend.getArrayBufferAsync( attribute );
|
|
771
1528
|
|
|
772
1529
|
}
|
|
773
1530
|
|
|
1531
|
+
/**
|
|
1532
|
+
* Returns the rendering context.
|
|
1533
|
+
*
|
|
1534
|
+
* @return {GPUCanvasContext|WebGL2RenderingContext} The rendering context.
|
|
1535
|
+
*/
|
|
774
1536
|
getContext() {
|
|
775
1537
|
|
|
776
1538
|
return this.backend.getContext();
|
|
777
1539
|
|
|
778
1540
|
}
|
|
779
1541
|
|
|
1542
|
+
/**
|
|
1543
|
+
* Returns the pixel ratio.
|
|
1544
|
+
*
|
|
1545
|
+
* @return {number} The pixel ratio.
|
|
1546
|
+
*/
|
|
780
1547
|
getPixelRatio() {
|
|
781
1548
|
|
|
782
1549
|
return this._pixelRatio;
|
|
783
1550
|
|
|
784
1551
|
}
|
|
785
1552
|
|
|
1553
|
+
/**
|
|
1554
|
+
* Returns the drawing buffer size in physical pixels. This method honors the pixel ratio.
|
|
1555
|
+
*
|
|
1556
|
+
* @param {Vector2} target - The method writes the result in this target object.
|
|
1557
|
+
* @return {Vector2} The drawing buffer size.
|
|
1558
|
+
*/
|
|
786
1559
|
getDrawingBufferSize( target ) {
|
|
787
1560
|
|
|
788
1561
|
return target.set( this._width * this._pixelRatio, this._height * this._pixelRatio ).floor();
|
|
789
1562
|
|
|
790
1563
|
}
|
|
791
1564
|
|
|
1565
|
+
/**
|
|
1566
|
+
* Returns the renderer's size in logical pixels. This method does not honor the pixel ratio.
|
|
1567
|
+
*
|
|
1568
|
+
* @param {Vector2} target - The method writes the result in this target object.
|
|
1569
|
+
* @return {Vector2} The drawing buffer size.
|
|
1570
|
+
*/
|
|
792
1571
|
getSize( target ) {
|
|
793
1572
|
|
|
794
1573
|
return target.set( this._width, this._height );
|
|
795
1574
|
|
|
796
1575
|
}
|
|
797
1576
|
|
|
1577
|
+
/**
|
|
1578
|
+
* Sets the given pixel ratio and resizes the canvas if necessary.
|
|
1579
|
+
*
|
|
1580
|
+
* @param {number} [value=1] - The pixel ratio.
|
|
1581
|
+
*/
|
|
798
1582
|
setPixelRatio( value = 1 ) {
|
|
799
1583
|
|
|
1584
|
+
if ( this._pixelRatio === value ) return;
|
|
1585
|
+
|
|
800
1586
|
this._pixelRatio = value;
|
|
801
1587
|
|
|
802
1588
|
this.setSize( this._width, this._height, false );
|
|
803
1589
|
|
|
804
1590
|
}
|
|
805
1591
|
|
|
1592
|
+
/**
|
|
1593
|
+
* This method allows to define the drawing buffer size by specifying
|
|
1594
|
+
* width, height and pixel ratio all at once. The size of the drawing
|
|
1595
|
+
* buffer is computed with this formula:
|
|
1596
|
+
* ````
|
|
1597
|
+
* size.x = width * pixelRatio;
|
|
1598
|
+
* size.y = height * pixelRatio;
|
|
1599
|
+
*```
|
|
1600
|
+
*
|
|
1601
|
+
* @param {number} width - The width in logical pixels.
|
|
1602
|
+
* @param {number} height - The height in logical pixels.
|
|
1603
|
+
* @param {number} pixelRatio - The pixel ratio.
|
|
1604
|
+
*/
|
|
806
1605
|
setDrawingBufferSize( width, height, pixelRatio ) {
|
|
807
1606
|
|
|
808
1607
|
this._width = width;
|
|
@@ -819,6 +1618,13 @@ class Renderer {
|
|
|
819
1618
|
|
|
820
1619
|
}
|
|
821
1620
|
|
|
1621
|
+
/**
|
|
1622
|
+
* Sets the size of the renderer.
|
|
1623
|
+
*
|
|
1624
|
+
* @param {number} width - The width in logical pixels.
|
|
1625
|
+
* @param {number} height - The height in logical pixels.
|
|
1626
|
+
* @param {boolean} [updateStyle=true] - Whether to update the `style` attribute of the canvas or not.
|
|
1627
|
+
*/
|
|
822
1628
|
setSize( width, height, updateStyle = true ) {
|
|
823
1629
|
|
|
824
1630
|
this._width = width;
|
|
@@ -840,18 +1646,36 @@ class Renderer {
|
|
|
840
1646
|
|
|
841
1647
|
}
|
|
842
1648
|
|
|
1649
|
+
/**
|
|
1650
|
+
* Defines a manual sort function for the opaque render list.
|
|
1651
|
+
* Pass `null` to use the default sort.
|
|
1652
|
+
*
|
|
1653
|
+
* @param {Function} method - The sort function.
|
|
1654
|
+
*/
|
|
843
1655
|
setOpaqueSort( method ) {
|
|
844
1656
|
|
|
845
1657
|
this._opaqueSort = method;
|
|
846
1658
|
|
|
847
1659
|
}
|
|
848
1660
|
|
|
1661
|
+
/**
|
|
1662
|
+
* Defines a manual sort function for the transparent render list.
|
|
1663
|
+
* Pass `null` to use the default sort.
|
|
1664
|
+
*
|
|
1665
|
+
* @param {Function} method - The sort function.
|
|
1666
|
+
*/
|
|
849
1667
|
setTransparentSort( method ) {
|
|
850
1668
|
|
|
851
1669
|
this._transparentSort = method;
|
|
852
1670
|
|
|
853
1671
|
}
|
|
854
1672
|
|
|
1673
|
+
/**
|
|
1674
|
+
* Returns the scissor rectangle.
|
|
1675
|
+
*
|
|
1676
|
+
* @param {Vector4} target - The method writes the result in this target object.
|
|
1677
|
+
* @return {Vector4} The scissor rectangle.
|
|
1678
|
+
*/
|
|
855
1679
|
getScissor( target ) {
|
|
856
1680
|
|
|
857
1681
|
const scissor = this._scissor;
|
|
@@ -865,6 +1689,15 @@ class Renderer {
|
|
|
865
1689
|
|
|
866
1690
|
}
|
|
867
1691
|
|
|
1692
|
+
/**
|
|
1693
|
+
* Defines the scissor rectangle.
|
|
1694
|
+
*
|
|
1695
|
+
* @param {number | Vector4} x - The horizontal coordinate for the lower left corner of the box in logical pixel unit.
|
|
1696
|
+
* Instead of passing four arguments, the method also works with a single four-dimensional vector.
|
|
1697
|
+
* @param {number} y - The vertical coordinate for the lower left corner of the box in logical pixel unit.
|
|
1698
|
+
* @param {number} width - The width of the scissor box in logical pixel unit.
|
|
1699
|
+
* @param {number} height - The height of the scissor box in logical pixel unit.
|
|
1700
|
+
*/
|
|
868
1701
|
setScissor( x, y, width, height ) {
|
|
869
1702
|
|
|
870
1703
|
const scissor = this._scissor;
|
|
@@ -881,12 +1714,22 @@ class Renderer {
|
|
|
881
1714
|
|
|
882
1715
|
}
|
|
883
1716
|
|
|
1717
|
+
/**
|
|
1718
|
+
* Returns the scissor test value.
|
|
1719
|
+
*
|
|
1720
|
+
* @return {boolean} Whether the scissor test should be enabled or not.
|
|
1721
|
+
*/
|
|
884
1722
|
getScissorTest() {
|
|
885
1723
|
|
|
886
1724
|
return this._scissorTest;
|
|
887
1725
|
|
|
888
1726
|
}
|
|
889
1727
|
|
|
1728
|
+
/**
|
|
1729
|
+
* Defines the scissor test.
|
|
1730
|
+
*
|
|
1731
|
+
* @param {boolean} boolean - Whether the scissor test should be enabled or not.
|
|
1732
|
+
*/
|
|
890
1733
|
setScissorTest( boolean ) {
|
|
891
1734
|
|
|
892
1735
|
this._scissorTest = boolean;
|
|
@@ -895,12 +1738,28 @@ class Renderer {
|
|
|
895
1738
|
|
|
896
1739
|
}
|
|
897
1740
|
|
|
1741
|
+
/**
|
|
1742
|
+
* Returns the viewport definition.
|
|
1743
|
+
*
|
|
1744
|
+
* @param {Vector4} target - The method writes the result in this target object.
|
|
1745
|
+
* @return {Vector4} The viewport definition.
|
|
1746
|
+
*/
|
|
898
1747
|
getViewport( target ) {
|
|
899
1748
|
|
|
900
1749
|
return target.copy( this._viewport );
|
|
901
1750
|
|
|
902
1751
|
}
|
|
903
1752
|
|
|
1753
|
+
/**
|
|
1754
|
+
* Defines the viewport.
|
|
1755
|
+
*
|
|
1756
|
+
* @param {number | Vector4} x - The horizontal coordinate for the lower left corner of the viewport origin in logical pixel unit.
|
|
1757
|
+
* @param {number} y - The vertical coordinate for the lower left corner of the viewport origin in logical pixel unit.
|
|
1758
|
+
* @param {number} width - The width of the viewport in logical pixel unit.
|
|
1759
|
+
* @param {number} height - The height of the viewport in logical pixel unit.
|
|
1760
|
+
* @param {number} minDepth - The minimum depth value of the viewport. WebGPU only.
|
|
1761
|
+
* @param {number} maxDepth - The maximum depth value of the viewport. WebGPU only.
|
|
1762
|
+
*/
|
|
904
1763
|
setViewport( x, y, width, height, minDepth = 0, maxDepth = 1 ) {
|
|
905
1764
|
|
|
906
1765
|
const viewport = this._viewport;
|
|
@@ -920,12 +1779,24 @@ class Renderer {
|
|
|
920
1779
|
|
|
921
1780
|
}
|
|
922
1781
|
|
|
1782
|
+
/**
|
|
1783
|
+
* Returns the clear color.
|
|
1784
|
+
*
|
|
1785
|
+
* @param {Color} target - The method writes the result in this target object.
|
|
1786
|
+
* @return {Color} The clear color.
|
|
1787
|
+
*/
|
|
923
1788
|
getClearColor( target ) {
|
|
924
1789
|
|
|
925
1790
|
return target.copy( this._clearColor );
|
|
926
1791
|
|
|
927
1792
|
}
|
|
928
1793
|
|
|
1794
|
+
/**
|
|
1795
|
+
* Defines the clear color and optionally the clear alpha.
|
|
1796
|
+
*
|
|
1797
|
+
* @param {Color} color - The clear color.
|
|
1798
|
+
* @param {number} [alpha=1] - The clear alpha.
|
|
1799
|
+
*/
|
|
929
1800
|
setClearColor( color, alpha = 1 ) {
|
|
930
1801
|
|
|
931
1802
|
this._clearColor.set( color );
|
|
@@ -933,42 +1804,80 @@ class Renderer {
|
|
|
933
1804
|
|
|
934
1805
|
}
|
|
935
1806
|
|
|
1807
|
+
/**
|
|
1808
|
+
* Returns the clear alpha.
|
|
1809
|
+
*
|
|
1810
|
+
* @return {number} The clear alpha.
|
|
1811
|
+
*/
|
|
936
1812
|
getClearAlpha() {
|
|
937
1813
|
|
|
938
1814
|
return this._clearColor.a;
|
|
939
1815
|
|
|
940
1816
|
}
|
|
941
1817
|
|
|
1818
|
+
/**
|
|
1819
|
+
* Defines the clear alpha.
|
|
1820
|
+
*
|
|
1821
|
+
* @param {number} alpha - The clear alpha.
|
|
1822
|
+
*/
|
|
942
1823
|
setClearAlpha( alpha ) {
|
|
943
1824
|
|
|
944
1825
|
this._clearColor.a = alpha;
|
|
945
1826
|
|
|
946
1827
|
}
|
|
947
1828
|
|
|
1829
|
+
/**
|
|
1830
|
+
* Returns the clear depth.
|
|
1831
|
+
*
|
|
1832
|
+
* @return {number} The clear depth.
|
|
1833
|
+
*/
|
|
948
1834
|
getClearDepth() {
|
|
949
1835
|
|
|
950
1836
|
return this._clearDepth;
|
|
951
1837
|
|
|
952
1838
|
}
|
|
953
1839
|
|
|
1840
|
+
/**
|
|
1841
|
+
* Defines the clear depth.
|
|
1842
|
+
*
|
|
1843
|
+
* @param {number} depth - The clear depth.
|
|
1844
|
+
*/
|
|
954
1845
|
setClearDepth( depth ) {
|
|
955
1846
|
|
|
956
1847
|
this._clearDepth = depth;
|
|
957
1848
|
|
|
958
1849
|
}
|
|
959
1850
|
|
|
1851
|
+
/**
|
|
1852
|
+
* Returns the clear stencil.
|
|
1853
|
+
*
|
|
1854
|
+
* @return {number} The clear stencil.
|
|
1855
|
+
*/
|
|
960
1856
|
getClearStencil() {
|
|
961
1857
|
|
|
962
1858
|
return this._clearStencil;
|
|
963
1859
|
|
|
964
1860
|
}
|
|
965
1861
|
|
|
1862
|
+
/**
|
|
1863
|
+
* Defines the clear stencil.
|
|
1864
|
+
*
|
|
1865
|
+
* @param {number} stencil - The clear stencil.
|
|
1866
|
+
*/
|
|
966
1867
|
setClearStencil( stencil ) {
|
|
967
1868
|
|
|
968
1869
|
this._clearStencil = stencil;
|
|
969
1870
|
|
|
970
1871
|
}
|
|
971
1872
|
|
|
1873
|
+
/**
|
|
1874
|
+
* This method performs an occlusion query for the given 3D object.
|
|
1875
|
+
* It returns `true` if the given 3D object is fully occluded by other
|
|
1876
|
+
* 3D objects in the scene.
|
|
1877
|
+
*
|
|
1878
|
+
* @param {Object3D} object - The 3D object to test.
|
|
1879
|
+
* @return {boolean} Whether the 3D object is fully occluded or not.
|
|
1880
|
+
*/
|
|
972
1881
|
isOccluded( object ) {
|
|
973
1882
|
|
|
974
1883
|
const renderContext = this._currentRenderContext;
|
|
@@ -977,6 +1886,15 @@ class Renderer {
|
|
|
977
1886
|
|
|
978
1887
|
}
|
|
979
1888
|
|
|
1889
|
+
/**
|
|
1890
|
+
* Performs a manual clear operation. This method ignores `autoClear` properties.
|
|
1891
|
+
*
|
|
1892
|
+
* @param {boolean} [color=true] - Whether the color buffer should be cleared or not.
|
|
1893
|
+
* @param {boolean} [depth=true] - Whether the depth buffer should be cleared or not.
|
|
1894
|
+
* @param {boolean} [stencil=true] - Whether the stencil buffer should be cleared or not.
|
|
1895
|
+
* @return {Promise} A Promise that resolves when the clear operation has been executed.
|
|
1896
|
+
* Only returned when the renderer has not been initialized.
|
|
1897
|
+
*/
|
|
980
1898
|
clear( color = true, depth = true, stencil = true ) {
|
|
981
1899
|
|
|
982
1900
|
if ( this._initialized === false ) {
|
|
@@ -989,56 +1907,82 @@ class Renderer {
|
|
|
989
1907
|
|
|
990
1908
|
const renderTarget = this._renderTarget || this._getFrameBufferTarget();
|
|
991
1909
|
|
|
992
|
-
let
|
|
1910
|
+
let renderContext = null;
|
|
993
1911
|
|
|
994
1912
|
if ( renderTarget !== null ) {
|
|
995
1913
|
|
|
996
1914
|
this._textures.updateRenderTarget( renderTarget );
|
|
997
1915
|
|
|
998
|
-
renderTargetData = this._textures.get( renderTarget );
|
|
1916
|
+
const renderTargetData = this._textures.get( renderTarget );
|
|
1917
|
+
|
|
1918
|
+
renderContext = this._renderContexts.getForClear( renderTarget );
|
|
1919
|
+
renderContext.textures = renderTargetData.textures;
|
|
1920
|
+
renderContext.depthTexture = renderTargetData.depthTexture;
|
|
1921
|
+
renderContext.width = renderTargetData.width;
|
|
1922
|
+
renderContext.height = renderTargetData.height;
|
|
1923
|
+
renderContext.renderTarget = renderTarget;
|
|
1924
|
+
renderContext.depth = renderTarget.depthBuffer;
|
|
1925
|
+
renderContext.stencil = renderTarget.stencilBuffer;
|
|
1926
|
+
// #30329
|
|
1927
|
+
renderContext.clearColorValue = this.backend.getClearColor();
|
|
999
1928
|
|
|
1000
1929
|
}
|
|
1001
1930
|
|
|
1002
|
-
this.backend.clear( color, depth, stencil,
|
|
1931
|
+
this.backend.clear( color, depth, stencil, renderContext );
|
|
1003
1932
|
|
|
1004
1933
|
if ( renderTarget !== null && this._renderTarget === null ) {
|
|
1005
1934
|
|
|
1006
|
-
|
|
1007
|
-
// the clear operation clears the intermediate renderTarget texture, but does not update the screen canvas.
|
|
1008
|
-
|
|
1009
|
-
const quad = this._quad;
|
|
1010
|
-
|
|
1011
|
-
if ( this._nodes.hasOutputChange( renderTarget.texture ) ) {
|
|
1012
|
-
|
|
1013
|
-
quad.material.fragmentNode = this._nodes.getOutputNode( renderTarget.texture );
|
|
1014
|
-
quad.material.needsUpdate = true;
|
|
1015
|
-
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
this._renderScene( quad, quad.camera, false );
|
|
1935
|
+
this._renderOutput( renderTarget );
|
|
1019
1936
|
|
|
1020
1937
|
}
|
|
1021
1938
|
|
|
1022
1939
|
}
|
|
1023
1940
|
|
|
1941
|
+
/**
|
|
1942
|
+
* Performs a manual clear operation of the color buffer. This method ignores `autoClear` properties.
|
|
1943
|
+
*
|
|
1944
|
+
* @return {Promise} A Promise that resolves when the clear operation has been executed.
|
|
1945
|
+
* Only returned when the renderer has not been initialized.
|
|
1946
|
+
*/
|
|
1024
1947
|
clearColor() {
|
|
1025
1948
|
|
|
1026
1949
|
return this.clear( true, false, false );
|
|
1027
1950
|
|
|
1028
1951
|
}
|
|
1029
1952
|
|
|
1953
|
+
/**
|
|
1954
|
+
* Performs a manual clear operation of the depth buffer. This method ignores `autoClear` properties.
|
|
1955
|
+
*
|
|
1956
|
+
* @return {Promise} A Promise that resolves when the clear operation has been executed.
|
|
1957
|
+
* Only returned when the renderer has not been initialized.
|
|
1958
|
+
*/
|
|
1030
1959
|
clearDepth() {
|
|
1031
1960
|
|
|
1032
1961
|
return this.clear( false, true, false );
|
|
1033
1962
|
|
|
1034
1963
|
}
|
|
1035
1964
|
|
|
1965
|
+
/**
|
|
1966
|
+
* Performs a manual clear operation of the stencil buffer. This method ignores `autoClear` properties.
|
|
1967
|
+
*
|
|
1968
|
+
* @return {Promise} A Promise that resolves when the clear operation has been executed.
|
|
1969
|
+
* Only returned when the renderer has not been initialized.
|
|
1970
|
+
*/
|
|
1036
1971
|
clearStencil() {
|
|
1037
1972
|
|
|
1038
1973
|
return this.clear( false, false, true );
|
|
1039
1974
|
|
|
1040
1975
|
}
|
|
1041
1976
|
|
|
1977
|
+
/**
|
|
1978
|
+
* Async version of {@link Renderer#clear}.
|
|
1979
|
+
*
|
|
1980
|
+
* @async
|
|
1981
|
+
* @param {boolean} [color=true] - Whether the color buffer should be cleared or not.
|
|
1982
|
+
* @param {boolean} [depth=true] - Whether the depth buffer should be cleared or not.
|
|
1983
|
+
* @param {boolean} [stencil=true] - Whether the stencil buffer should be cleared or not.
|
|
1984
|
+
* @return {Promise} A Promise that resolves when the clear operation has been executed.
|
|
1985
|
+
*/
|
|
1042
1986
|
async clearAsync( color = true, depth = true, stencil = true ) {
|
|
1043
1987
|
|
|
1044
1988
|
if ( this._initialized === false ) await this.init();
|
|
@@ -1047,43 +1991,85 @@ class Renderer {
|
|
|
1047
1991
|
|
|
1048
1992
|
}
|
|
1049
1993
|
|
|
1050
|
-
|
|
1994
|
+
/**
|
|
1995
|
+
* Async version of {@link Renderer#clearColor}.
|
|
1996
|
+
*
|
|
1997
|
+
* @async
|
|
1998
|
+
* @return {Promise} A Promise that resolves when the clear operation has been executed.
|
|
1999
|
+
*/
|
|
2000
|
+
async clearColorAsync() {
|
|
1051
2001
|
|
|
1052
|
-
|
|
2002
|
+
this.clearAsync( true, false, false );
|
|
1053
2003
|
|
|
1054
2004
|
}
|
|
1055
2005
|
|
|
1056
|
-
|
|
2006
|
+
/**
|
|
2007
|
+
* Async version of {@link Renderer#clearDepth}.
|
|
2008
|
+
*
|
|
2009
|
+
* @async
|
|
2010
|
+
* @return {Promise} A Promise that resolves when the clear operation has been executed.
|
|
2011
|
+
*/
|
|
2012
|
+
async clearDepthAsync() {
|
|
1057
2013
|
|
|
1058
|
-
|
|
2014
|
+
this.clearAsync( false, true, false );
|
|
1059
2015
|
|
|
1060
2016
|
}
|
|
1061
2017
|
|
|
1062
|
-
|
|
2018
|
+
/**
|
|
2019
|
+
* Async version of {@link Renderer#clearStencil}.
|
|
2020
|
+
*
|
|
2021
|
+
* @async
|
|
2022
|
+
* @return {Promise} A Promise that resolves when the clear operation has been executed.
|
|
2023
|
+
*/
|
|
2024
|
+
async clearStencilAsync() {
|
|
1063
2025
|
|
|
1064
|
-
|
|
2026
|
+
this.clearAsync( false, false, true );
|
|
1065
2027
|
|
|
1066
2028
|
}
|
|
1067
2029
|
|
|
1068
|
-
|
|
2030
|
+
/**
|
|
2031
|
+
* The current output tone mapping of the renderer. When a render target is set,
|
|
2032
|
+
* the output tone mapping is always `NoToneMapping`.
|
|
2033
|
+
*
|
|
2034
|
+
* @type {number}
|
|
2035
|
+
*/
|
|
2036
|
+
get currentToneMapping() {
|
|
1069
2037
|
|
|
1070
|
-
|
|
2038
|
+
return this.isOutputTarget ? this.toneMapping : NoToneMapping;
|
|
1071
2039
|
|
|
1072
|
-
|
|
2040
|
+
}
|
|
1073
2041
|
|
|
1074
|
-
|
|
2042
|
+
/**
|
|
2043
|
+
* The current output color space of the renderer. When a render target is set,
|
|
2044
|
+
* the output color space is always `LinearSRGBColorSpace`.
|
|
2045
|
+
*
|
|
2046
|
+
* @type {string}
|
|
2047
|
+
*/
|
|
2048
|
+
get currentColorSpace() {
|
|
1075
2049
|
|
|
1076
|
-
|
|
2050
|
+
return this.isOutputTarget ? this.outputColorSpace : LinearSRGBColorSpace;
|
|
1077
2051
|
|
|
1078
|
-
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
/**
|
|
2055
|
+
* Returns `true` if the rendering settings are set to screen output.
|
|
2056
|
+
*
|
|
2057
|
+
* @returns {boolean} True if the current render target is the same of output render target or `null`, otherwise false.
|
|
2058
|
+
*/
|
|
2059
|
+
get isOutputTarget() {
|
|
1079
2060
|
|
|
1080
|
-
return this.
|
|
2061
|
+
return this._renderTarget === this._outputRenderTarget || this._renderTarget === null;
|
|
1081
2062
|
|
|
1082
2063
|
}
|
|
1083
2064
|
|
|
2065
|
+
/**
|
|
2066
|
+
* Frees all internal resources of the renderer. Call this method if the renderer
|
|
2067
|
+
* is no longer in use by your app.
|
|
2068
|
+
*/
|
|
1084
2069
|
dispose() {
|
|
1085
2070
|
|
|
1086
2071
|
this.info.dispose();
|
|
2072
|
+
this.backend.dispose();
|
|
1087
2073
|
|
|
1088
2074
|
this._animation.dispose();
|
|
1089
2075
|
this._objects.dispose();
|
|
@@ -1094,11 +2080,28 @@ class Renderer {
|
|
|
1094
2080
|
this._renderContexts.dispose();
|
|
1095
2081
|
this._textures.dispose();
|
|
1096
2082
|
|
|
2083
|
+
if ( this._frameBufferTarget !== null ) this._frameBufferTarget.dispose();
|
|
2084
|
+
|
|
2085
|
+
Object.values( this.backend.timestampQueryPool ).forEach( queryPool => {
|
|
2086
|
+
|
|
2087
|
+
if ( queryPool !== null ) queryPool.dispose();
|
|
2088
|
+
|
|
2089
|
+
} );
|
|
2090
|
+
|
|
1097
2091
|
this.setRenderTarget( null );
|
|
1098
2092
|
this.setAnimationLoop( null );
|
|
1099
2093
|
|
|
1100
2094
|
}
|
|
1101
2095
|
|
|
2096
|
+
/**
|
|
2097
|
+
* Sets the given render target. Calling this method means the renderer does not
|
|
2098
|
+
* target the default framebuffer (meaning the canvas) anymore but a custom framebuffer.
|
|
2099
|
+
* Use `null` as the first argument to reset the state.
|
|
2100
|
+
*
|
|
2101
|
+
* @param {?RenderTarget} renderTarget - The render target to set.
|
|
2102
|
+
* @param {number} [activeCubeFace=0] - The active cube face.
|
|
2103
|
+
* @param {number} [activeMipmapLevel=0] - The active mipmap level.
|
|
2104
|
+
*/
|
|
1102
2105
|
setRenderTarget( renderTarget, activeCubeFace = 0, activeMipmapLevel = 0 ) {
|
|
1103
2106
|
|
|
1104
2107
|
this._renderTarget = renderTarget;
|
|
@@ -1107,27 +2110,102 @@ class Renderer {
|
|
|
1107
2110
|
|
|
1108
2111
|
}
|
|
1109
2112
|
|
|
2113
|
+
/**
|
|
2114
|
+
* Returns the current render target.
|
|
2115
|
+
*
|
|
2116
|
+
* @return {?RenderTarget} The render target. Returns `null` if no render target is set.
|
|
2117
|
+
*/
|
|
1110
2118
|
getRenderTarget() {
|
|
1111
2119
|
|
|
1112
2120
|
return this._renderTarget;
|
|
1113
2121
|
|
|
1114
2122
|
}
|
|
1115
2123
|
|
|
2124
|
+
/**
|
|
2125
|
+
* Sets the output render target for the renderer.
|
|
2126
|
+
*
|
|
2127
|
+
* @param {Object} renderTarget - The render target to set as the output target.
|
|
2128
|
+
*/
|
|
2129
|
+
setOutputRenderTarget( renderTarget ) {
|
|
2130
|
+
|
|
2131
|
+
this._outputRenderTarget = renderTarget;
|
|
2132
|
+
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2135
|
+
/**
|
|
2136
|
+
* Returns the current output target.
|
|
2137
|
+
*
|
|
2138
|
+
* @return {?RenderTarget} The current output render target. Returns `null` if no output target is set.
|
|
2139
|
+
*/
|
|
2140
|
+
getOutputRenderTarget() {
|
|
2141
|
+
|
|
2142
|
+
return this._outputRenderTarget;
|
|
2143
|
+
|
|
2144
|
+
}
|
|
2145
|
+
|
|
2146
|
+
/**
|
|
2147
|
+
* Callback for {@link Renderer#setRenderObjectFunction}.
|
|
2148
|
+
*
|
|
2149
|
+
* @callback renderObjectFunction
|
|
2150
|
+
* @param {Object3D} object - The 3D object.
|
|
2151
|
+
* @param {Scene} scene - The scene the 3D object belongs to.
|
|
2152
|
+
* @param {Camera} camera - The camera the object should be rendered with.
|
|
2153
|
+
* @param {BufferGeometry} geometry - The object's geometry.
|
|
2154
|
+
* @param {Material} material - The object's material.
|
|
2155
|
+
* @param {?Object} group - Only relevant for objects using multiple materials. This represents a group entry from the respective `BufferGeometry`.
|
|
2156
|
+
* @param {LightsNode} lightsNode - The current lights node.
|
|
2157
|
+
* @param {ClippingContext} clippingContext - The clipping context.
|
|
2158
|
+
* @param {?string} [passId=null] - An optional ID for identifying the pass.
|
|
2159
|
+
*/
|
|
2160
|
+
|
|
2161
|
+
/**
|
|
2162
|
+
* Sets the given render object function. Calling this method overwrites the default implementation
|
|
2163
|
+
* which is {@link Renderer#renderObject}. Defining a custom function can be useful
|
|
2164
|
+
* if you want to modify the way objects are rendered. For example you can define things like "every
|
|
2165
|
+
* object that has material of a certain type should perform a pre-pass with a special overwrite material".
|
|
2166
|
+
* The custom function must always call `renderObject()` in its implementation.
|
|
2167
|
+
*
|
|
2168
|
+
* Use `null` as the first argument to reset the state.
|
|
2169
|
+
*
|
|
2170
|
+
* @param {?renderObjectFunction} renderObjectFunction - The render object function.
|
|
2171
|
+
*/
|
|
1116
2172
|
setRenderObjectFunction( renderObjectFunction ) {
|
|
1117
2173
|
|
|
1118
2174
|
this._renderObjectFunction = renderObjectFunction;
|
|
1119
2175
|
|
|
1120
2176
|
}
|
|
1121
2177
|
|
|
2178
|
+
/**
|
|
2179
|
+
* Returns the current render object function.
|
|
2180
|
+
*
|
|
2181
|
+
* @return {?Function} The current render object function. Returns `null` if no function is set.
|
|
2182
|
+
*/
|
|
1122
2183
|
getRenderObjectFunction() {
|
|
1123
2184
|
|
|
1124
2185
|
return this._renderObjectFunction;
|
|
1125
2186
|
|
|
1126
2187
|
}
|
|
1127
2188
|
|
|
1128
|
-
|
|
2189
|
+
/**
|
|
2190
|
+
* Execute a single or an array of compute nodes. This method can only be called
|
|
2191
|
+
* if the renderer has been initialized.
|
|
2192
|
+
*
|
|
2193
|
+
* @param {Node|Array<Node>} computeNodes - The compute node(s).
|
|
2194
|
+
* @return {?Promise} A Promise that resolve when the compute has finished. Only returned when the renderer has not been initialized.
|
|
2195
|
+
*/
|
|
2196
|
+
compute( computeNodes ) {
|
|
1129
2197
|
|
|
1130
|
-
if ( this.
|
|
2198
|
+
if ( this._isDeviceLost === true ) return;
|
|
2199
|
+
|
|
2200
|
+
if ( this._initialized === false ) {
|
|
2201
|
+
|
|
2202
|
+
console.warn( 'THREE.Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead.' );
|
|
2203
|
+
|
|
2204
|
+
return this.computeAsync( computeNodes );
|
|
2205
|
+
|
|
2206
|
+
}
|
|
2207
|
+
|
|
2208
|
+
//
|
|
1131
2209
|
|
|
1132
2210
|
const nodeFrame = this._nodes.nodeFrame;
|
|
1133
2211
|
|
|
@@ -1178,7 +2256,13 @@ class Renderer {
|
|
|
1178
2256
|
|
|
1179
2257
|
//
|
|
1180
2258
|
|
|
1181
|
-
|
|
2259
|
+
const onInitFn = computeNode.onInitFunction;
|
|
2260
|
+
|
|
2261
|
+
if ( onInitFn !== null ) {
|
|
2262
|
+
|
|
2263
|
+
onInitFn.call( computeNode, { renderer: this } );
|
|
2264
|
+
|
|
2265
|
+
}
|
|
1182
2266
|
|
|
1183
2267
|
}
|
|
1184
2268
|
|
|
@@ -1194,14 +2278,34 @@ class Renderer {
|
|
|
1194
2278
|
|
|
1195
2279
|
backend.finishCompute( computeNodes );
|
|
1196
2280
|
|
|
1197
|
-
await this.backend.resolveTimestampAsync( computeNodes, 'compute' );
|
|
1198
|
-
|
|
1199
2281
|
//
|
|
1200
2282
|
|
|
1201
2283
|
nodeFrame.renderId = previousRenderId;
|
|
1202
2284
|
|
|
1203
2285
|
}
|
|
1204
2286
|
|
|
2287
|
+
/**
|
|
2288
|
+
* Execute a single or an array of compute nodes.
|
|
2289
|
+
*
|
|
2290
|
+
* @async
|
|
2291
|
+
* @param {Node|Array<Node>} computeNodes - The compute node(s).
|
|
2292
|
+
* @return {Promise} A Promise that resolve when the compute has finished.
|
|
2293
|
+
*/
|
|
2294
|
+
async computeAsync( computeNodes ) {
|
|
2295
|
+
|
|
2296
|
+
if ( this._initialized === false ) await this.init();
|
|
2297
|
+
|
|
2298
|
+
this.compute( computeNodes );
|
|
2299
|
+
|
|
2300
|
+
}
|
|
2301
|
+
|
|
2302
|
+
/**
|
|
2303
|
+
* Checks if the given feature is supported by the selected backend.
|
|
2304
|
+
*
|
|
2305
|
+
* @async
|
|
2306
|
+
* @param {string} name - The feature's name.
|
|
2307
|
+
* @return {Promise<boolean>} A Promise that resolves with a bool that indicates whether the feature is supported or not.
|
|
2308
|
+
*/
|
|
1205
2309
|
async hasFeatureAsync( name ) {
|
|
1206
2310
|
|
|
1207
2311
|
if ( this._initialized === false ) await this.init();
|
|
@@ -1210,6 +2314,21 @@ class Renderer {
|
|
|
1210
2314
|
|
|
1211
2315
|
}
|
|
1212
2316
|
|
|
2317
|
+
async resolveTimestampsAsync( type = 'render' ) {
|
|
2318
|
+
|
|
2319
|
+
if ( this._initialized === false ) await this.init();
|
|
2320
|
+
|
|
2321
|
+
return this.backend.resolveTimestampsAsync( type );
|
|
2322
|
+
|
|
2323
|
+
}
|
|
2324
|
+
|
|
2325
|
+
/**
|
|
2326
|
+
* Checks if the given feature is supported by the selected backend. If the
|
|
2327
|
+
* renderer has not been initialized, this method always returns `false`.
|
|
2328
|
+
*
|
|
2329
|
+
* @param {string} name - The feature's name.
|
|
2330
|
+
* @return {boolean} Whether the feature is supported or not.
|
|
2331
|
+
*/
|
|
1213
2332
|
hasFeature( name ) {
|
|
1214
2333
|
|
|
1215
2334
|
if ( this._initialized === false ) {
|
|
@@ -1224,16 +2343,125 @@ class Renderer {
|
|
|
1224
2343
|
|
|
1225
2344
|
}
|
|
1226
2345
|
|
|
1227
|
-
|
|
2346
|
+
/**
|
|
2347
|
+
* Returns `true` when the renderer has been initialized.
|
|
2348
|
+
*
|
|
2349
|
+
* @return {boolean} Whether the renderer has been initialized or not.
|
|
2350
|
+
*/
|
|
2351
|
+
hasInitialized() {
|
|
1228
2352
|
|
|
1229
|
-
|
|
2353
|
+
return this._initialized;
|
|
1230
2354
|
|
|
1231
|
-
|
|
2355
|
+
}
|
|
2356
|
+
|
|
2357
|
+
/**
|
|
2358
|
+
* Initializes the given textures. Useful for preloading a texture rather than waiting until first render
|
|
2359
|
+
* (which can cause noticeable lags due to decode and GPU upload overhead).
|
|
2360
|
+
*
|
|
2361
|
+
* @async
|
|
2362
|
+
* @param {Texture} texture - The texture.
|
|
2363
|
+
* @return {Promise} A Promise that resolves when the texture has been initialized.
|
|
2364
|
+
*/
|
|
2365
|
+
async initTextureAsync( texture ) {
|
|
2366
|
+
|
|
2367
|
+
if ( this._initialized === false ) await this.init();
|
|
1232
2368
|
|
|
1233
|
-
this.
|
|
2369
|
+
this._textures.updateTexture( texture );
|
|
1234
2370
|
|
|
1235
2371
|
}
|
|
1236
2372
|
|
|
2373
|
+
/**
|
|
2374
|
+
* Initializes the given textures. Useful for preloading a texture rather than waiting until first render
|
|
2375
|
+
* (which can cause noticeable lags due to decode and GPU upload overhead).
|
|
2376
|
+
*
|
|
2377
|
+
* This method can only be used if the renderer has been initialized.
|
|
2378
|
+
*
|
|
2379
|
+
* @param {Texture} texture - The texture.
|
|
2380
|
+
*/
|
|
2381
|
+
initTexture( texture ) {
|
|
2382
|
+
|
|
2383
|
+
if ( this._initialized === false ) {
|
|
2384
|
+
|
|
2385
|
+
console.warn( 'THREE.Renderer: .initTexture() called before the backend is initialized. Try using .initTextureAsync() instead.' );
|
|
2386
|
+
|
|
2387
|
+
}
|
|
2388
|
+
|
|
2389
|
+
this._textures.updateTexture( texture );
|
|
2390
|
+
|
|
2391
|
+
}
|
|
2392
|
+
|
|
2393
|
+
/**
|
|
2394
|
+
* Copies the current bound framebuffer into the given texture.
|
|
2395
|
+
*
|
|
2396
|
+
* @param {FramebufferTexture} framebufferTexture - The texture.
|
|
2397
|
+
* @param {Vector2|Vector4} rectangle - A two or four dimensional vector that defines the rectangular portion of the framebuffer that should be copied.
|
|
2398
|
+
*/
|
|
2399
|
+
copyFramebufferToTexture( framebufferTexture, rectangle = null ) {
|
|
2400
|
+
|
|
2401
|
+
if ( rectangle !== null ) {
|
|
2402
|
+
|
|
2403
|
+
if ( rectangle.isVector2 ) {
|
|
2404
|
+
|
|
2405
|
+
rectangle = _vector4.set( rectangle.x, rectangle.y, framebufferTexture.image.width, framebufferTexture.image.height ).floor();
|
|
2406
|
+
|
|
2407
|
+
} else if ( rectangle.isVector4 ) {
|
|
2408
|
+
|
|
2409
|
+
rectangle = _vector4.copy( rectangle ).floor();
|
|
2410
|
+
|
|
2411
|
+
} else {
|
|
2412
|
+
|
|
2413
|
+
console.error( 'THREE.Renderer.copyFramebufferToTexture: Invalid rectangle.' );
|
|
2414
|
+
|
|
2415
|
+
return;
|
|
2416
|
+
|
|
2417
|
+
}
|
|
2418
|
+
|
|
2419
|
+
} else {
|
|
2420
|
+
|
|
2421
|
+
rectangle = _vector4.set( 0, 0, framebufferTexture.image.width, framebufferTexture.image.height );
|
|
2422
|
+
|
|
2423
|
+
}
|
|
2424
|
+
|
|
2425
|
+
//
|
|
2426
|
+
|
|
2427
|
+
let renderContext = this._currentRenderContext;
|
|
2428
|
+
let renderTarget;
|
|
2429
|
+
|
|
2430
|
+
if ( renderContext !== null ) {
|
|
2431
|
+
|
|
2432
|
+
renderTarget = renderContext.renderTarget;
|
|
2433
|
+
|
|
2434
|
+
} else {
|
|
2435
|
+
|
|
2436
|
+
renderTarget = this._renderTarget || this._getFrameBufferTarget();
|
|
2437
|
+
|
|
2438
|
+
if ( renderTarget !== null ) {
|
|
2439
|
+
|
|
2440
|
+
this._textures.updateRenderTarget( renderTarget );
|
|
2441
|
+
|
|
2442
|
+
renderContext = this._textures.get( renderTarget );
|
|
2443
|
+
|
|
2444
|
+
}
|
|
2445
|
+
|
|
2446
|
+
}
|
|
2447
|
+
|
|
2448
|
+
//
|
|
2449
|
+
|
|
2450
|
+
this._textures.updateTexture( framebufferTexture, { renderTarget } );
|
|
2451
|
+
|
|
2452
|
+
this.backend.copyFramebufferToTexture( framebufferTexture, renderContext, rectangle );
|
|
2453
|
+
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2456
|
+
/**
|
|
2457
|
+
* Copies data of source texture into a destination texture.
|
|
2458
|
+
*
|
|
2459
|
+
* @param {Texture} srcTexture - The source texture.
|
|
2460
|
+
* @param {Texture} dstTexture - The destination texture.
|
|
2461
|
+
* @param {Box2|Box3} [srcRegion=null] - A bounding box which describes the source region. Can be two or three-dimensional.
|
|
2462
|
+
* @param {Vector2|Vector3} [dstPosition=null] - A vector that represents the origin of the destination region. Can be two or three-dimensional.
|
|
2463
|
+
* @param {number} level - The mipmap level to copy.
|
|
2464
|
+
*/
|
|
1237
2465
|
copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) {
|
|
1238
2466
|
|
|
1239
2467
|
this._textures.updateTexture( srcTexture );
|
|
@@ -1243,14 +2471,36 @@ class Renderer {
|
|
|
1243
2471
|
|
|
1244
2472
|
}
|
|
1245
2473
|
|
|
2474
|
+
/**
|
|
2475
|
+
* Reads pixel data from the given render target.
|
|
2476
|
+
*
|
|
2477
|
+
* @async
|
|
2478
|
+
* @param {RenderTarget} renderTarget - The render target to read from.
|
|
2479
|
+
* @param {number} x - The `x` coordinate of the copy region's origin.
|
|
2480
|
+
* @param {number} y - The `y` coordinate of the copy region's origin.
|
|
2481
|
+
* @param {number} width - The width of the copy region.
|
|
2482
|
+
* @param {number} height - The height of the copy region.
|
|
2483
|
+
* @param {number} [textureIndex=0] - The texture index of a MRT render target.
|
|
2484
|
+
* @param {number} [faceIndex=0] - The active cube face index.
|
|
2485
|
+
* @return {Promise<TypedArray>} A Promise that resolves when the read has been finished. The resolve provides the read data as a typed array.
|
|
2486
|
+
*/
|
|
2487
|
+
async readRenderTargetPixelsAsync( renderTarget, x, y, width, height, textureIndex = 0, faceIndex = 0 ) {
|
|
1246
2488
|
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
return this.backend.copyTextureToBuffer( renderTarget.textures[ index ], x, y, width, height );
|
|
2489
|
+
return this.backend.copyTextureToBuffer( renderTarget.textures[ textureIndex ], x, y, width, height, faceIndex );
|
|
1250
2490
|
|
|
1251
2491
|
}
|
|
1252
2492
|
|
|
1253
|
-
|
|
2493
|
+
/**
|
|
2494
|
+
* Analyzes the given 3D object's hierarchy and builds render lists from the
|
|
2495
|
+
* processed hierarchy.
|
|
2496
|
+
*
|
|
2497
|
+
* @param {Object3D} object - The 3D object to process (usually a scene).
|
|
2498
|
+
* @param {Camera} camera - The camera the object is rendered with.
|
|
2499
|
+
* @param {number} groupOrder - The group order is derived from the `renderOrder` of groups and is used to group 3D objects within groups.
|
|
2500
|
+
* @param {RenderList} renderList - The current render list.
|
|
2501
|
+
* @param {ClippingContext} clippingContext - The current clipping context.
|
|
2502
|
+
*/
|
|
2503
|
+
_projectObject( object, camera, groupOrder, renderList, clippingContext ) {
|
|
1254
2504
|
|
|
1255
2505
|
if ( object.visible === false ) return;
|
|
1256
2506
|
|
|
@@ -1262,6 +2512,8 @@ class Renderer {
|
|
|
1262
2512
|
|
|
1263
2513
|
groupOrder = object.renderOrder;
|
|
1264
2514
|
|
|
2515
|
+
if ( object.isClippingGroup && object.enabled ) clippingContext = clippingContext.getGroupContext( object );
|
|
2516
|
+
|
|
1265
2517
|
} else if ( object.isLOD ) {
|
|
1266
2518
|
|
|
1267
2519
|
if ( object.autoUpdate === true ) object.update( camera );
|
|
@@ -1276,16 +2528,15 @@ class Renderer {
|
|
|
1276
2528
|
|
|
1277
2529
|
if ( this.sortObjects === true ) {
|
|
1278
2530
|
|
|
1279
|
-
|
|
2531
|
+
_vector4.setFromMatrixPosition( object.matrixWorld ).applyMatrix4( _projScreenMatrix );
|
|
1280
2532
|
|
|
1281
2533
|
}
|
|
1282
2534
|
|
|
1283
|
-
const geometry = object
|
|
1284
|
-
const material = object.material;
|
|
2535
|
+
const { geometry, material } = object;
|
|
1285
2536
|
|
|
1286
2537
|
if ( material.visible ) {
|
|
1287
2538
|
|
|
1288
|
-
renderList.push( object, geometry, material, groupOrder,
|
|
2539
|
+
renderList.push( object, geometry, material, groupOrder, _vector4.z, null, clippingContext );
|
|
1289
2540
|
|
|
1290
2541
|
}
|
|
1291
2542
|
|
|
@@ -1299,14 +2550,13 @@ class Renderer {
|
|
|
1299
2550
|
|
|
1300
2551
|
if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
|
|
1301
2552
|
|
|
1302
|
-
const geometry = object
|
|
1303
|
-
const material = object.material;
|
|
2553
|
+
const { geometry, material } = object;
|
|
1304
2554
|
|
|
1305
2555
|
if ( this.sortObjects === true ) {
|
|
1306
2556
|
|
|
1307
2557
|
if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
|
|
1308
2558
|
|
|
1309
|
-
|
|
2559
|
+
_vector4
|
|
1310
2560
|
.copy( geometry.boundingSphere.center )
|
|
1311
2561
|
.applyMatrix4( object.matrixWorld )
|
|
1312
2562
|
.applyMatrix4( _projScreenMatrix );
|
|
@@ -1324,7 +2574,7 @@ class Renderer {
|
|
|
1324
2574
|
|
|
1325
2575
|
if ( groupMaterial && groupMaterial.visible ) {
|
|
1326
2576
|
|
|
1327
|
-
renderList.push( object, geometry, groupMaterial, groupOrder,
|
|
2577
|
+
renderList.push( object, geometry, groupMaterial, groupOrder, _vector4.z, group, clippingContext );
|
|
1328
2578
|
|
|
1329
2579
|
}
|
|
1330
2580
|
|
|
@@ -1332,7 +2582,7 @@ class Renderer {
|
|
|
1332
2582
|
|
|
1333
2583
|
} else if ( material.visible ) {
|
|
1334
2584
|
|
|
1335
|
-
renderList.push( object, geometry, material, groupOrder,
|
|
2585
|
+
renderList.push( object, geometry, material, groupOrder, _vector4.z, null, clippingContext );
|
|
1336
2586
|
|
|
1337
2587
|
}
|
|
1338
2588
|
|
|
@@ -1342,7 +2592,7 @@ class Renderer {
|
|
|
1342
2592
|
|
|
1343
2593
|
}
|
|
1344
2594
|
|
|
1345
|
-
if ( object.
|
|
2595
|
+
if ( object.isBundleGroup === true && this.backend.beginBundle !== undefined ) {
|
|
1346
2596
|
|
|
1347
2597
|
const baseRenderList = renderList;
|
|
1348
2598
|
|
|
@@ -1352,7 +2602,7 @@ class Renderer {
|
|
|
1352
2602
|
renderList.begin();
|
|
1353
2603
|
|
|
1354
2604
|
baseRenderList.pushBundle( {
|
|
1355
|
-
object,
|
|
2605
|
+
bundleGroup: object,
|
|
1356
2606
|
camera,
|
|
1357
2607
|
renderList,
|
|
1358
2608
|
} );
|
|
@@ -1365,12 +2615,20 @@ class Renderer {
|
|
|
1365
2615
|
|
|
1366
2616
|
for ( let i = 0, l = children.length; i < l; i ++ ) {
|
|
1367
2617
|
|
|
1368
|
-
this._projectObject( children[ i ], camera, groupOrder, renderList );
|
|
2618
|
+
this._projectObject( children[ i ], camera, groupOrder, renderList, clippingContext );
|
|
1369
2619
|
|
|
1370
2620
|
}
|
|
1371
2621
|
|
|
1372
2622
|
}
|
|
1373
2623
|
|
|
2624
|
+
/**
|
|
2625
|
+
* Renders the given render bundles.
|
|
2626
|
+
*
|
|
2627
|
+
* @private
|
|
2628
|
+
* @param {Array<Object>} bundles - Array with render bundle data.
|
|
2629
|
+
* @param {Scene} sceneRef - The scene the render bundles belong to.
|
|
2630
|
+
* @param {LightsNode} lightsNode - The current lights node.
|
|
2631
|
+
*/
|
|
1374
2632
|
_renderBundles( bundles, sceneRef, lightsNode ) {
|
|
1375
2633
|
|
|
1376
2634
|
for ( const bundle of bundles ) {
|
|
@@ -1381,60 +2639,96 @@ class Renderer {
|
|
|
1381
2639
|
|
|
1382
2640
|
}
|
|
1383
2641
|
|
|
1384
|
-
|
|
2642
|
+
/**
|
|
2643
|
+
* Renders the transparent objects from the given render lists.
|
|
2644
|
+
*
|
|
2645
|
+
* @private
|
|
2646
|
+
* @param {Array<Object>} renderList - The transparent render list.
|
|
2647
|
+
* @param {Array<Object>} doublePassList - The list of transparent objects which require a double pass (e.g. because of transmission).
|
|
2648
|
+
* @param {Camera} camera - The camera the render list should be rendered with.
|
|
2649
|
+
* @param {Scene} scene - The scene the render list belongs to.
|
|
2650
|
+
* @param {LightsNode} lightsNode - The current lights node.
|
|
2651
|
+
*/
|
|
2652
|
+
_renderTransparents( renderList, doublePassList, camera, scene, lightsNode ) {
|
|
1385
2653
|
|
|
1386
|
-
|
|
2654
|
+
if ( doublePassList.length > 0 ) {
|
|
1387
2655
|
|
|
1388
|
-
|
|
2656
|
+
// render back side
|
|
1389
2657
|
|
|
1390
|
-
const
|
|
2658
|
+
for ( const { material } of doublePassList ) {
|
|
1391
2659
|
|
|
1392
|
-
|
|
1393
|
-
// the material from the renderItem object and pass it with its group data to renderObject().
|
|
2660
|
+
material.side = BackSide;
|
|
1394
2661
|
|
|
1395
|
-
|
|
2662
|
+
}
|
|
1396
2663
|
|
|
1397
|
-
|
|
2664
|
+
this._renderObjects( doublePassList, camera, scene, lightsNode, 'backSide' );
|
|
1398
2665
|
|
|
1399
|
-
|
|
2666
|
+
// render front side
|
|
1400
2667
|
|
|
1401
|
-
|
|
2668
|
+
for ( const { material } of doublePassList ) {
|
|
1402
2669
|
|
|
1403
|
-
|
|
2670
|
+
material.side = FrontSide;
|
|
1404
2671
|
|
|
1405
|
-
|
|
2672
|
+
}
|
|
1406
2673
|
|
|
1407
|
-
|
|
1408
|
-
const minDepth = ( vp.minDepth === undefined ) ? 0 : vp.minDepth;
|
|
1409
|
-
const maxDepth = ( vp.maxDepth === undefined ) ? 1 : vp.maxDepth;
|
|
2674
|
+
this._renderObjects( renderList, camera, scene, lightsNode );
|
|
1410
2675
|
|
|
1411
|
-
|
|
1412
|
-
viewportValue.copy( vp ).multiplyScalar( this._pixelRatio ).floor();
|
|
1413
|
-
viewportValue.minDepth = minDepth;
|
|
1414
|
-
viewportValue.maxDepth = maxDepth;
|
|
2676
|
+
// restore
|
|
1415
2677
|
|
|
1416
|
-
|
|
2678
|
+
for ( const { material } of doublePassList ) {
|
|
1417
2679
|
|
|
1418
|
-
|
|
2680
|
+
material.side = DoubleSide;
|
|
1419
2681
|
|
|
1420
|
-
|
|
2682
|
+
}
|
|
1421
2683
|
|
|
1422
|
-
|
|
2684
|
+
} else {
|
|
1423
2685
|
|
|
1424
|
-
|
|
2686
|
+
this._renderObjects( renderList, camera, scene, lightsNode );
|
|
1425
2687
|
|
|
1426
|
-
|
|
2688
|
+
}
|
|
1427
2689
|
|
|
1428
|
-
|
|
2690
|
+
}
|
|
2691
|
+
|
|
2692
|
+
/**
|
|
2693
|
+
* Renders the objects from the given render list.
|
|
2694
|
+
*
|
|
2695
|
+
* @private
|
|
2696
|
+
* @param {Array<Object>} renderList - The render list.
|
|
2697
|
+
* @param {Camera} camera - The camera the render list should be rendered with.
|
|
2698
|
+
* @param {Scene} scene - The scene the render list belongs to.
|
|
2699
|
+
* @param {LightsNode} lightsNode - The current lights node.
|
|
2700
|
+
* @param {?string} [passId=null] - An optional ID for identifying the pass.
|
|
2701
|
+
*/
|
|
2702
|
+
_renderObjects( renderList, camera, scene, lightsNode, passId = null ) {
|
|
2703
|
+
|
|
2704
|
+
for ( let i = 0, il = renderList.length; i < il; i ++ ) {
|
|
2705
|
+
|
|
2706
|
+
const { object, geometry, material, group, clippingContext } = renderList[ i ];
|
|
2707
|
+
|
|
2708
|
+
this._currentRenderObjectFunction( object, scene, camera, geometry, material, group, lightsNode, clippingContext, passId );
|
|
1429
2709
|
|
|
1430
2710
|
}
|
|
1431
2711
|
|
|
1432
2712
|
}
|
|
1433
2713
|
|
|
1434
|
-
|
|
2714
|
+
/**
|
|
2715
|
+
* This method represents the default render object function that manages the render lifecycle
|
|
2716
|
+
* of the object.
|
|
2717
|
+
*
|
|
2718
|
+
* @param {Object3D} object - The 3D object.
|
|
2719
|
+
* @param {Scene} scene - The scene the 3D object belongs to.
|
|
2720
|
+
* @param {Camera} camera - The camera the object should be rendered with.
|
|
2721
|
+
* @param {BufferGeometry} geometry - The object's geometry.
|
|
2722
|
+
* @param {Material} material - The object's material.
|
|
2723
|
+
* @param {?Object} group - Only relevant for objects using multiple materials. This represents a group entry from the respective `BufferGeometry`.
|
|
2724
|
+
* @param {LightsNode} lightsNode - The current lights node.
|
|
2725
|
+
* @param {ClippingContext} clippingContext - The clipping context.
|
|
2726
|
+
* @param {?string} [passId=null] - An optional ID for identifying the pass.
|
|
2727
|
+
*/
|
|
2728
|
+
renderObject( object, scene, camera, geometry, material, group, lightsNode, clippingContext = null, passId = null ) {
|
|
1435
2729
|
|
|
1436
2730
|
let overridePositionNode;
|
|
1437
|
-
let
|
|
2731
|
+
let overrideColorNode;
|
|
1438
2732
|
let overrideDepthNode;
|
|
1439
2733
|
|
|
1440
2734
|
//
|
|
@@ -1454,7 +2748,11 @@ class Renderer {
|
|
|
1454
2748
|
|
|
1455
2749
|
}
|
|
1456
2750
|
|
|
1457
|
-
|
|
2751
|
+
overrideMaterial.alphaTest = material.alphaTest;
|
|
2752
|
+
overrideMaterial.alphaMap = material.alphaMap;
|
|
2753
|
+
overrideMaterial.transparent = material.transparent || material.transmission > 0;
|
|
2754
|
+
|
|
2755
|
+
if ( overrideMaterial.isShadowPassMaterial ) {
|
|
1458
2756
|
|
|
1459
2757
|
overrideMaterial.side = material.shadowSide === null ? material.side : material.shadowSide;
|
|
1460
2758
|
|
|
@@ -1465,37 +2763,10 @@ class Renderer {
|
|
|
1465
2763
|
|
|
1466
2764
|
}
|
|
1467
2765
|
|
|
2766
|
+
if ( material.castShadowNode && material.castShadowNode.isNode ) {
|
|
1468
2767
|
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
overrideFragmentNode = overrideMaterial.fragmentNode;
|
|
1472
|
-
overrideMaterial.fragmentNode = material.shadowNode;
|
|
1473
|
-
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
if ( this.localClippingEnabled ) {
|
|
1477
|
-
|
|
1478
|
-
if ( material.clipShadows ) {
|
|
1479
|
-
|
|
1480
|
-
if ( overrideMaterial.clippingPlanes !== material.clippingPlanes ) {
|
|
1481
|
-
|
|
1482
|
-
overrideMaterial.clippingPlanes = material.clippingPlanes;
|
|
1483
|
-
overrideMaterial.needsUpdate = true;
|
|
1484
|
-
|
|
1485
|
-
}
|
|
1486
|
-
|
|
1487
|
-
if ( overrideMaterial.clipIntersection !== material.clipIntersection ) {
|
|
1488
|
-
|
|
1489
|
-
overrideMaterial.clipIntersection = material.clipIntersection;
|
|
1490
|
-
|
|
1491
|
-
}
|
|
1492
|
-
|
|
1493
|
-
} else if ( Array.isArray( overrideMaterial.clippingPlanes ) ) {
|
|
1494
|
-
|
|
1495
|
-
overrideMaterial.clippingPlanes = null;
|
|
1496
|
-
overrideMaterial.needsUpdate = true;
|
|
1497
|
-
|
|
1498
|
-
}
|
|
2768
|
+
overrideColorNode = overrideMaterial.colorNode;
|
|
2769
|
+
overrideMaterial.colorNode = material.castShadowNode;
|
|
1499
2770
|
|
|
1500
2771
|
}
|
|
1501
2772
|
|
|
@@ -1510,16 +2781,16 @@ class Renderer {
|
|
|
1510
2781
|
if ( material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false ) {
|
|
1511
2782
|
|
|
1512
2783
|
material.side = BackSide;
|
|
1513
|
-
this._handleObjectFunction( object, material, scene, camera, lightsNode, group, 'backSide' ); // create backSide pass id
|
|
2784
|
+
this._handleObjectFunction( object, material, scene, camera, lightsNode, group, clippingContext, 'backSide' ); // create backSide pass id
|
|
1514
2785
|
|
|
1515
2786
|
material.side = FrontSide;
|
|
1516
|
-
this._handleObjectFunction( object, material, scene, camera, lightsNode, group ); // use default pass id
|
|
2787
|
+
this._handleObjectFunction( object, material, scene, camera, lightsNode, group, clippingContext, passId ); // use default pass id
|
|
1517
2788
|
|
|
1518
2789
|
material.side = DoubleSide;
|
|
1519
2790
|
|
|
1520
2791
|
} else {
|
|
1521
2792
|
|
|
1522
|
-
this._handleObjectFunction( object, material, scene, camera, lightsNode, group );
|
|
2793
|
+
this._handleObjectFunction( object, material, scene, camera, lightsNode, group, clippingContext, passId );
|
|
1523
2794
|
|
|
1524
2795
|
}
|
|
1525
2796
|
|
|
@@ -1537,9 +2808,9 @@ class Renderer {
|
|
|
1537
2808
|
|
|
1538
2809
|
}
|
|
1539
2810
|
|
|
1540
|
-
if (
|
|
2811
|
+
if ( overrideColorNode !== undefined ) {
|
|
1541
2812
|
|
|
1542
|
-
scene.overrideMaterial.
|
|
2813
|
+
scene.overrideMaterial.colorNode = overrideColorNode;
|
|
1543
2814
|
|
|
1544
2815
|
}
|
|
1545
2816
|
|
|
@@ -1549,64 +2820,88 @@ class Renderer {
|
|
|
1549
2820
|
|
|
1550
2821
|
}
|
|
1551
2822
|
|
|
1552
|
-
|
|
2823
|
+
/**
|
|
2824
|
+
* This method represents the default `_handleObjectFunction` implementation which creates
|
|
2825
|
+
* a render object from the given data and performs the draw command with the selected backend.
|
|
2826
|
+
*
|
|
2827
|
+
* @private
|
|
2828
|
+
* @param {Object3D} object - The 3D object.
|
|
2829
|
+
* @param {Material} material - The object's material.
|
|
2830
|
+
* @param {Scene} scene - The scene the 3D object belongs to.
|
|
2831
|
+
* @param {Camera} camera - The camera the object should be rendered with.
|
|
2832
|
+
* @param {LightsNode} lightsNode - The current lights node.
|
|
2833
|
+
* @param {?{start: number, count: number}} group - Only relevant for objects using multiple materials. This represents a group entry from the respective `BufferGeometry`.
|
|
2834
|
+
* @param {ClippingContext} clippingContext - The clipping context.
|
|
2835
|
+
* @param {?string} [passId=null] - An optional ID for identifying the pass.
|
|
2836
|
+
*/
|
|
2837
|
+
_renderObjectDirect( object, material, scene, camera, lightsNode, group, clippingContext, passId ) {
|
|
1553
2838
|
|
|
1554
|
-
const renderObject = this._objects.get( object, material, scene, camera, lightsNode, this._currentRenderContext, passId );
|
|
1555
|
-
renderObject.drawRange =
|
|
2839
|
+
const renderObject = this._objects.get( object, material, scene, camera, lightsNode, this._currentRenderContext, clippingContext, passId );
|
|
2840
|
+
renderObject.drawRange = object.geometry.drawRange;
|
|
2841
|
+
renderObject.group = group;
|
|
1556
2842
|
|
|
1557
2843
|
//
|
|
1558
2844
|
|
|
1559
|
-
this._nodes.
|
|
2845
|
+
const needsRefresh = this._nodes.needsRefresh( renderObject );
|
|
1560
2846
|
|
|
1561
|
-
|
|
2847
|
+
if ( needsRefresh ) {
|
|
1562
2848
|
|
|
1563
|
-
|
|
1564
|
-
object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
|
|
2849
|
+
this._nodes.updateBefore( renderObject );
|
|
1565
2850
|
|
|
1566
|
-
|
|
2851
|
+
this._geometries.updateForRender( renderObject );
|
|
2852
|
+
|
|
2853
|
+
this._nodes.updateForRender( renderObject );
|
|
2854
|
+
this._bindings.updateForRender( renderObject );
|
|
2855
|
+
|
|
2856
|
+
}
|
|
1567
2857
|
|
|
1568
|
-
this._nodes.updateForRender( renderObject );
|
|
1569
|
-
this._geometries.updateForRender( renderObject );
|
|
1570
|
-
this._bindings.updateForRender( renderObject );
|
|
1571
2858
|
this._pipelines.updateForRender( renderObject );
|
|
1572
2859
|
|
|
1573
2860
|
//
|
|
1574
2861
|
|
|
1575
|
-
if ( this._currentRenderBundle !== null
|
|
2862
|
+
if ( this._currentRenderBundle !== null ) {
|
|
1576
2863
|
|
|
1577
|
-
const
|
|
2864
|
+
const renderBundleData = this.backend.get( this._currentRenderBundle );
|
|
1578
2865
|
|
|
1579
|
-
|
|
1580
|
-
|
|
2866
|
+
renderBundleData.renderObjects.push( renderObject );
|
|
2867
|
+
|
|
2868
|
+
renderObject.bundle = this._currentRenderBundle.bundleGroup;
|
|
1581
2869
|
|
|
1582
2870
|
}
|
|
1583
2871
|
|
|
1584
2872
|
this.backend.draw( renderObject, this.info );
|
|
1585
2873
|
|
|
1586
|
-
if ( this.
|
|
1587
|
-
|
|
1588
|
-
const renderContextData = this.backend.get( this._currentRenderContext );
|
|
1589
|
-
|
|
1590
|
-
renderContextData.renderObjects.push( renderObject );
|
|
1591
|
-
|
|
1592
|
-
}
|
|
1593
|
-
|
|
1594
|
-
this._nodes.updateAfter( renderObject );
|
|
2874
|
+
if ( needsRefresh ) this._nodes.updateAfter( renderObject );
|
|
1595
2875
|
|
|
1596
2876
|
}
|
|
1597
2877
|
|
|
1598
|
-
|
|
2878
|
+
/**
|
|
2879
|
+
* A different implementation for `_handleObjectFunction` which only makes sure the object is ready for rendering.
|
|
2880
|
+
* Used in `compileAsync()`.
|
|
2881
|
+
*
|
|
2882
|
+
* @private
|
|
2883
|
+
* @param {Object3D} object - The 3D object.
|
|
2884
|
+
* @param {Material} material - The object's material.
|
|
2885
|
+
* @param {Scene} scene - The scene the 3D object belongs to.
|
|
2886
|
+
* @param {Camera} camera - The camera the object should be rendered with.
|
|
2887
|
+
* @param {LightsNode} lightsNode - The current lights node.
|
|
2888
|
+
* @param {?{start: number, count: number}} group - Only relevant for objects using multiple materials. This represents a group entry from the respective `BufferGeometry`.
|
|
2889
|
+
* @param {ClippingContext} clippingContext - The clipping context.
|
|
2890
|
+
* @param {?string} [passId=null] - An optional ID for identifying the pass.
|
|
2891
|
+
*/
|
|
2892
|
+
_createObjectPipeline( object, material, scene, camera, lightsNode, group, clippingContext, passId ) {
|
|
1599
2893
|
|
|
1600
|
-
const renderObject = this._objects.get( object, material, scene, camera, lightsNode, this._currentRenderContext, passId );
|
|
2894
|
+
const renderObject = this._objects.get( object, material, scene, camera, lightsNode, this._currentRenderContext, clippingContext, passId );
|
|
2895
|
+
renderObject.drawRange = object.geometry.drawRange;
|
|
2896
|
+
renderObject.group = group;
|
|
1601
2897
|
|
|
1602
2898
|
//
|
|
1603
2899
|
|
|
1604
2900
|
this._nodes.updateBefore( renderObject );
|
|
1605
2901
|
|
|
1606
|
-
|
|
2902
|
+
this._geometries.updateForRender( renderObject );
|
|
1607
2903
|
|
|
1608
2904
|
this._nodes.updateForRender( renderObject );
|
|
1609
|
-
this._geometries.updateForRender( renderObject );
|
|
1610
2905
|
this._bindings.updateForRender( renderObject );
|
|
1611
2906
|
|
|
1612
2907
|
this._pipelines.getForRender( renderObject, this._compilationPromises );
|
|
@@ -1615,12 +2910,15 @@ class Renderer {
|
|
|
1615
2910
|
|
|
1616
2911
|
}
|
|
1617
2912
|
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
2913
|
+
/**
|
|
2914
|
+
* Alias for `compileAsync()`.
|
|
2915
|
+
*
|
|
2916
|
+
* @method
|
|
2917
|
+
* @param {Object3D} scene - The scene or 3D object to precompile.
|
|
2918
|
+
* @param {Camera} camera - The camera that is used to render the scene.
|
|
2919
|
+
* @param {Scene} targetScene - If the first argument is a 3D object, this parameter must represent the scene the 3D object is going to be added.
|
|
2920
|
+
* @return {Promise} A Promise that resolves when the compile has been finished.
|
|
2921
|
+
*/
|
|
1624
2922
|
get compile() {
|
|
1625
2923
|
|
|
1626
2924
|
return this.compileAsync;
|