super-three 0.163.0 → 0.165.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/README.md +3 -3
- package/build/three.cjs +1127 -452
- package/build/three.module.js +1127 -452
- package/build/three.module.min.js +2 -2
- package/examples/jsm/animation/CCDIKSolver.js +4 -2
- package/examples/jsm/controls/TransformControls.js +1 -1
- package/examples/jsm/environments/RoomEnvironment.js +1 -5
- package/examples/jsm/exporters/GLTFExporter.js +45 -1
- package/examples/jsm/exporters/USDZExporter.js +13 -5
- package/examples/jsm/helpers/ViewHelper.js +32 -67
- package/examples/jsm/libs/draco/README.md +2 -2
- package/examples/jsm/libs/tween.module.js +75 -64
- package/examples/jsm/lines/LineMaterial.js +1 -15
- package/examples/jsm/lines/LineSegments2.js +15 -0
- package/examples/jsm/lines/Wireframe.js +16 -1
- package/examples/jsm/loaders/DRACOLoader.js +1 -1
- package/examples/jsm/loaders/EXRLoader.js +283 -99
- package/examples/jsm/loaders/FBXLoader.js +24 -13
- package/examples/jsm/loaders/GLTFLoader.js +55 -0
- package/examples/jsm/loaders/KTX2Loader.js +3 -6
- package/examples/jsm/loaders/LDrawLoader.js +3 -2
- package/examples/jsm/loaders/MMDLoader.js +31 -12
- package/examples/jsm/loaders/VRMLLoader.js +1 -1
- package/examples/jsm/loaders/lwo/IFFParser.js +8 -5
- package/examples/jsm/materials/MeshGouraudMaterial.js +7 -1
- package/examples/jsm/math/Octree.js +26 -20
- package/examples/jsm/modifiers/CurveModifier.js +11 -9
- package/examples/jsm/nodes/Nodes.js +15 -13
- package/examples/jsm/nodes/accessors/AccessorsUtils.js +16 -1
- package/examples/jsm/nodes/accessors/BitangentNode.js +7 -83
- package/examples/jsm/nodes/accessors/BufferNode.js +6 -0
- package/examples/jsm/nodes/accessors/CameraNode.js +12 -119
- package/examples/jsm/nodes/accessors/ClippingNode.js +3 -2
- package/examples/jsm/nodes/accessors/MaterialNode.js +109 -3
- package/examples/jsm/nodes/accessors/ModelNode.js +3 -0
- package/examples/jsm/nodes/accessors/NormalNode.js +9 -101
- package/examples/jsm/nodes/accessors/PositionNode.js +6 -100
- package/examples/jsm/nodes/accessors/ReferenceNode.js +6 -0
- package/examples/jsm/nodes/accessors/ReflectVectorNode.js +2 -31
- package/examples/jsm/nodes/accessors/StorageBufferNode.js +9 -0
- package/examples/jsm/nodes/accessors/{TextureStoreNode.js → StorageTextureNode.js} +19 -6
- package/examples/jsm/nodes/accessors/TangentNode.js +11 -97
- package/examples/jsm/nodes/accessors/Texture3DNode.js +100 -0
- package/examples/jsm/nodes/accessors/TextureNode.js +21 -3
- package/examples/jsm/nodes/accessors/TextureSizeNode.js +1 -1
- package/examples/jsm/nodes/accessors/UVNode.js +2 -46
- package/examples/jsm/nodes/code/FunctionNode.js +0 -8
- package/examples/jsm/nodes/core/AttributeNode.js +15 -3
- package/examples/jsm/nodes/core/ContextNode.js +6 -0
- package/examples/jsm/nodes/core/Node.js +23 -2
- package/examples/jsm/nodes/core/NodeBuilder.js +25 -18
- package/examples/jsm/nodes/core/NodeKeywords.js +1 -1
- package/examples/jsm/nodes/core/OutputStructNode.js +3 -6
- package/examples/jsm/nodes/core/PropertyNode.js +11 -0
- package/examples/jsm/nodes/core/VaryingNode.js +40 -9
- package/examples/jsm/nodes/display/AfterImageNode.js +14 -2
- package/examples/jsm/nodes/display/BumpMapNode.js +7 -26
- package/examples/jsm/nodes/display/FrontFacingNode.js +13 -0
- package/examples/jsm/nodes/display/PassNode.js +3 -1
- package/examples/jsm/nodes/display/ViewportDepthNode.js +1 -1
- package/examples/jsm/nodes/display/ViewportNode.js +5 -3
- package/examples/jsm/nodes/display/ViewportTextureNode.js +4 -1
- package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +26 -7
- package/examples/jsm/nodes/functions/BSDF/D_GGX_Anisotropic.js +28 -0
- package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +1 -3
- package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +29 -0
- package/examples/jsm/nodes/functions/PhongLightingModel.js +1 -1
- package/examples/jsm/nodes/functions/PhysicalLightingModel.js +210 -12
- package/examples/jsm/nodes/functions/ShadowMaskModel.js +31 -0
- package/examples/jsm/nodes/functions/ToonLightingModel.js +49 -0
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +20 -5
- package/examples/jsm/nodes/lighting/DirectionalLightNode.js +2 -1
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +11 -2
- package/examples/jsm/nodes/lighting/IrradianceNode.js +24 -0
- package/examples/jsm/nodes/lighting/LightsNode.js +28 -1
- package/examples/jsm/nodes/lighting/PointLightNode.js +2 -1
- package/examples/jsm/nodes/lighting/SpotLightNode.js +2 -1
- package/examples/jsm/nodes/materials/Line2NodeMaterial.js +11 -7
- package/examples/jsm/nodes/materials/Materials.js +4 -0
- package/examples/jsm/nodes/materials/MeshMatcapNodeMaterial.js +52 -0
- package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +0 -2
- package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +2 -2
- package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +94 -6
- package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +11 -4
- package/examples/jsm/nodes/materials/MeshToonNodeMaterial.js +34 -0
- package/examples/jsm/nodes/materials/NodeMaterial.js +43 -45
- package/examples/jsm/nodes/materials/ShadowNodeMaterial.js +34 -0
- package/examples/jsm/nodes/materials/VolumeNodeMaterial.js +106 -0
- package/examples/jsm/nodes/math/HashNode.js +2 -2
- package/examples/jsm/nodes/pmrem/PMREMUtils.js +1 -1
- package/examples/jsm/nodes/shadernode/ShaderNode.js +57 -41
- package/examples/jsm/nodes/utils/ArrayElementNode.js +1 -1
- package/examples/jsm/nodes/utils/MatcapUVNode.js +1 -1
- package/examples/jsm/nodes/utils/TimerNode.js +1 -1
- package/examples/jsm/objects/Lensflare.js +2 -2
- package/examples/jsm/physics/JoltPhysics.js +281 -0
- package/examples/jsm/postprocessing/RenderPass.js +1 -1
- package/examples/jsm/postprocessing/RenderTransitionPass.js +193 -0
- package/examples/jsm/renderers/CSS2DRenderer.js +25 -5
- package/examples/jsm/renderers/CSS3DRenderer.js +24 -3
- package/examples/jsm/renderers/common/Attributes.js +2 -0
- package/examples/jsm/renderers/common/Background.js +3 -3
- package/examples/jsm/renderers/common/Bindings.js +17 -0
- package/examples/jsm/renderers/common/ChainMap.js +18 -48
- package/examples/jsm/renderers/common/ClippingContext.js +5 -5
- package/examples/jsm/renderers/common/Pipelines.js +2 -2
- package/examples/jsm/renderers/common/RenderBundle.js +18 -0
- package/examples/jsm/renderers/common/RenderBundles.js +38 -0
- package/examples/jsm/renderers/common/RenderList.js +10 -1
- package/examples/jsm/renderers/common/RenderObject.js +49 -1
- package/examples/jsm/renderers/common/Renderer.js +268 -25
- package/examples/jsm/renderers/common/Textures.js +1 -1
- package/examples/jsm/renderers/common/Uniform.js +1 -1
- package/examples/jsm/renderers/common/extras/PMREMGenerator.js +13 -17
- package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +18 -4
- package/examples/jsm/renderers/common/nodes/NodeSampler.js +6 -0
- package/examples/jsm/renderers/common/nodes/Nodes.js +31 -47
- package/examples/jsm/renderers/webgl/WebGLBackend.js +7 -21
- package/examples/jsm/renderers/webgl/WebGLBufferRenderer.js +5 -1
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +23 -5
- package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +114 -13
- package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +3 -21
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +80 -46
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +85 -12
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +4 -1
- package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +10 -1
- package/examples/jsm/renderers/webgpu/utils/WebGPUConstants.js +6 -0
- package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +62 -19
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +62 -3
- package/examples/jsm/transpiler/GLSLDecoder.js +1 -1
- package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
- package/examples/jsm/utils/BufferGeometryUtils.js +18 -16
- package/examples/jsm/utils/GPUStatsPanel.js +2 -0
- package/examples/jsm/utils/SceneUtils.js +60 -1
- package/examples/jsm/utils/SortUtils.js +8 -5
- package/examples/jsm/webxr/OculusHandModel.js +3 -2
- package/examples/jsm/webxr/XRHandModelFactory.js +4 -2
- package/package.json +3 -2
- package/src/animation/tracks/BooleanKeyframeTrack.js +10 -1
- package/src/animation/tracks/QuaternionKeyframeTrack.js +1 -2
- package/src/animation/tracks/StringKeyframeTrack.js +10 -1
- package/src/constants.js +1 -1
- package/src/core/Object3D.js +2 -0
- package/src/core/Raycaster.js +6 -2
- package/src/core/RenderTarget.js +8 -0
- package/src/extras/PMREMGenerator.js +12 -11
- package/src/loaders/FileLoader.js +5 -1
- package/src/loaders/LoaderUtils.js +3 -1
- package/src/loaders/MaterialLoader.js +1 -0
- package/src/loaders/ObjectLoader.js +1 -0
- package/src/materials/Material.js +2 -0
- package/src/materials/MeshPhysicalMaterial.js +20 -0
- package/src/objects/BatchedMesh.js +114 -1
- package/src/objects/Line.js +66 -43
- package/src/renderers/WebGLRenderer.js +371 -109
- package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +15 -0
- package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +9 -1
- package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +8 -22
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +1 -0
- package/src/renderers/shaders/ShaderChunk/morphcolor_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/morphinstance_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl.js +3 -14
- package/src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl.js +10 -31
- package/src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl.js +3 -23
- package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +17 -9
- package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +47 -13
- package/src/renderers/shaders/ShaderChunk.js +0 -2
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -0
- package/src/renderers/shaders/ShaderLib.js +1 -0
- package/src/renderers/webgl/WebGLBackground.js +24 -3
- package/src/renderers/webgl/WebGLBufferRenderer.js +36 -0
- package/src/renderers/webgl/WebGLCapabilities.js +33 -1
- package/src/renderers/webgl/WebGLExtensions.js +3 -1
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +36 -0
- package/src/renderers/webgl/WebGLLights.js +9 -12
- package/src/renderers/webgl/WebGLMaterials.js +7 -5
- package/src/renderers/webgl/WebGLMorphtargets.js +1 -2
- package/src/renderers/webgl/WebGLProgram.js +5 -36
- package/src/renderers/webgl/WebGLPrograms.js +19 -14
- package/src/renderers/webgl/WebGLRenderStates.js +8 -4
- package/src/renderers/webgl/WebGLShadowMap.js +25 -25
- package/src/renderers/webgl/WebGLTextures.js +206 -129
- package/src/renderers/webgl/WebGLUtils.js +3 -21
- package/src/renderers/webxr/WebXRDepthSensing.js +3 -3
- package/src/renderers/webxr/WebXRManager.js +8 -6
- package/src/textures/CompressedArrayTexture.js +14 -0
- package/src/textures/DataArrayTexture.js +14 -0
- package/src/textures/DepthTexture.js +1 -3
- package/src/utils.js +30 -1
- package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +0 -318
- package/examples/jsm/renderers/webgl-legacy/nodes/SlotNode.js +0 -26
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +0 -792
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js +0 -51
- package/src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl.js +0 -10
|
@@ -251,9 +251,15 @@ class ShaderCallNodeInternal extends Node {
|
|
|
251
251
|
|
|
252
252
|
getNodeType( builder ) {
|
|
253
253
|
|
|
254
|
-
const
|
|
254
|
+
const properties = builder.getNodeProperties( this );
|
|
255
|
+
|
|
256
|
+
if ( properties.outputNode === null ) {
|
|
257
|
+
|
|
258
|
+
properties.outputNode = this.setupOutput( builder );
|
|
255
259
|
|
|
256
|
-
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return properties.outputNode.getNodeType( builder );
|
|
257
263
|
|
|
258
264
|
}
|
|
259
265
|
|
|
@@ -302,6 +308,14 @@ class ShaderCallNodeInternal extends Node {
|
|
|
302
308
|
|
|
303
309
|
setup( builder ) {
|
|
304
310
|
|
|
311
|
+
const { outputNode } = builder.getNodeProperties( this );
|
|
312
|
+
|
|
313
|
+
return outputNode || this.setupOutput( builder );
|
|
314
|
+
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
setupOutput( builder ) {
|
|
318
|
+
|
|
305
319
|
builder.addStack();
|
|
306
320
|
|
|
307
321
|
builder.stack.outputNode = this.call( builder );
|
|
@@ -456,6 +470,8 @@ const ConvertType = function ( type, cacheMap = null ) {
|
|
|
456
470
|
|
|
457
471
|
// exports
|
|
458
472
|
|
|
473
|
+
export const defined = ( value ) => value && value.value;
|
|
474
|
+
|
|
459
475
|
// utils
|
|
460
476
|
|
|
461
477
|
export const getConstNodeType = ( value ) => ( value !== undefined && value !== null ) ? ( value.nodeType || value.convertTo || ( typeof value === 'string' ? value : null ) ) : null;
|
|
@@ -474,14 +490,6 @@ export const nodeArray = ( val, altType = null ) => new ShaderNodeArray( val, al
|
|
|
474
490
|
export const nodeProxy = ( ...params ) => new ShaderNodeProxy( ...params );
|
|
475
491
|
export const nodeImmutable = ( ...params ) => new ShaderNodeImmutable( ...params );
|
|
476
492
|
|
|
477
|
-
export const shader = ( jsFunc ) => { // @deprecated, r154
|
|
478
|
-
|
|
479
|
-
console.warn( 'TSL: shader() is deprecated. Use tslFn() instead.' );
|
|
480
|
-
|
|
481
|
-
return new ShaderNode( jsFunc );
|
|
482
|
-
|
|
483
|
-
};
|
|
484
|
-
|
|
485
493
|
export const tslFn = ( jsFunc ) => {
|
|
486
494
|
|
|
487
495
|
const shaderNode = new ShaderNode( jsFunc );
|
|
@@ -523,6 +531,16 @@ addNodeClass( 'ShaderNode', ShaderNode );
|
|
|
523
531
|
|
|
524
532
|
//
|
|
525
533
|
|
|
534
|
+
addNodeElement( 'toGlobal', ( node ) => {
|
|
535
|
+
|
|
536
|
+
node.global = true;
|
|
537
|
+
|
|
538
|
+
return node;
|
|
539
|
+
|
|
540
|
+
} );
|
|
541
|
+
|
|
542
|
+
//
|
|
543
|
+
|
|
526
544
|
export const setCurrentStack = ( stack ) => {
|
|
527
545
|
|
|
528
546
|
if ( currentStack === stack ) {
|
|
@@ -592,37 +610,35 @@ export const bmat4 = new ConvertType( 'bmat4' );
|
|
|
592
610
|
export const string = ( value = '' ) => nodeObject( new ConstNode( value, 'string' ) );
|
|
593
611
|
export const arrayBuffer = ( value ) => nodeObject( new ConstNode( value, 'ArrayBuffer' ) );
|
|
594
612
|
|
|
595
|
-
addNodeElement( '
|
|
596
|
-
addNodeElement( '
|
|
597
|
-
addNodeElement( '
|
|
598
|
-
addNodeElement( '
|
|
599
|
-
addNodeElement( '
|
|
600
|
-
addNodeElement( '
|
|
601
|
-
addNodeElement( '
|
|
602
|
-
addNodeElement( '
|
|
603
|
-
addNodeElement( '
|
|
604
|
-
addNodeElement( '
|
|
605
|
-
addNodeElement( '
|
|
606
|
-
addNodeElement( '
|
|
607
|
-
addNodeElement( '
|
|
608
|
-
addNodeElement( '
|
|
609
|
-
addNodeElement( '
|
|
610
|
-
addNodeElement( '
|
|
611
|
-
addNodeElement( '
|
|
612
|
-
addNodeElement( '
|
|
613
|
-
addNodeElement( '
|
|
614
|
-
addNodeElement( '
|
|
615
|
-
addNodeElement( '
|
|
616
|
-
addNodeElement( '
|
|
617
|
-
addNodeElement( '
|
|
618
|
-
addNodeElement( '
|
|
619
|
-
addNodeElement( '
|
|
620
|
-
addNodeElement( '
|
|
621
|
-
addNodeElement( '
|
|
622
|
-
addNodeElement( '
|
|
623
|
-
addNodeElement( '
|
|
624
|
-
addNodeElement( 'string', string );
|
|
625
|
-
addNodeElement( 'arrayBuffer', arrayBuffer );
|
|
613
|
+
addNodeElement( 'toColor', color );
|
|
614
|
+
addNodeElement( 'toFloat', float );
|
|
615
|
+
addNodeElement( 'toInt', int );
|
|
616
|
+
addNodeElement( 'toUint', uint );
|
|
617
|
+
addNodeElement( 'toBool', bool );
|
|
618
|
+
addNodeElement( 'toVec2', vec2 );
|
|
619
|
+
addNodeElement( 'toIvec2', ivec2 );
|
|
620
|
+
addNodeElement( 'toUvec2', uvec2 );
|
|
621
|
+
addNodeElement( 'toBvec2', bvec2 );
|
|
622
|
+
addNodeElement( 'toVec3', vec3 );
|
|
623
|
+
addNodeElement( 'toIvec3', ivec3 );
|
|
624
|
+
addNodeElement( 'toUvec3', uvec3 );
|
|
625
|
+
addNodeElement( 'toBvec3', bvec3 );
|
|
626
|
+
addNodeElement( 'toVec4', vec4 );
|
|
627
|
+
addNodeElement( 'toIvec4', ivec4 );
|
|
628
|
+
addNodeElement( 'toUvec4', uvec4 );
|
|
629
|
+
addNodeElement( 'toBvec4', bvec4 );
|
|
630
|
+
addNodeElement( 'toMat2', mat2 );
|
|
631
|
+
addNodeElement( 'toImat2', imat2 );
|
|
632
|
+
addNodeElement( 'toUmat2', umat2 );
|
|
633
|
+
addNodeElement( 'toBmat2', bmat2 );
|
|
634
|
+
addNodeElement( 'toMat3', mat3 );
|
|
635
|
+
addNodeElement( 'toImat3', imat3 );
|
|
636
|
+
addNodeElement( 'toUmat3', umat3 );
|
|
637
|
+
addNodeElement( 'toBmat3', bmat3 );
|
|
638
|
+
addNodeElement( 'toMat4', mat4 );
|
|
639
|
+
addNodeElement( 'toImat4', imat4 );
|
|
640
|
+
addNodeElement( 'toUmat4', umat4 );
|
|
641
|
+
addNodeElement( 'toBmat4', bmat4 );
|
|
626
642
|
|
|
627
643
|
// basic nodes
|
|
628
644
|
// HACK - we cannot export them from the corresponding files because of the cyclic dependency
|
|
@@ -17,7 +17,7 @@ class MatcapUVNode extends TempNode {
|
|
|
17
17
|
const x = vec3( positionViewDirection.z, 0, positionViewDirection.x.negate() ).normalize();
|
|
18
18
|
const y = positionViewDirection.cross( x );
|
|
19
19
|
|
|
20
|
-
return vec2( x.dot( transformedNormalView ), y.dot( transformedNormalView ) ).mul( 0.495 ).add( 0.5 );
|
|
20
|
+
return vec2( x.dot( transformedNormalView ), y.dot( transformedNormalView ) ).mul( 0.495 ).add( 0.5 ); // 0.495 to remove artifacts caused by undersized matcap disks
|
|
21
21
|
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -89,6 +89,6 @@ export default TimerNode;
|
|
|
89
89
|
export const timerLocal = ( timeScale, value = 0 ) => nodeObject( new TimerNode( TimerNode.LOCAL, timeScale, value ) );
|
|
90
90
|
export const timerGlobal = ( timeScale, value = 0 ) => nodeObject( new TimerNode( TimerNode.GLOBAL, timeScale, value ) );
|
|
91
91
|
export const timerDelta = ( timeScale, value = 0 ) => nodeObject( new TimerNode( TimerNode.DELTA, timeScale, value ) );
|
|
92
|
-
export const frameId = nodeImmutable( TimerNode, TimerNode.FRAME ).
|
|
92
|
+
export const frameId = nodeImmutable( TimerNode, TimerNode.FRAME ).toUint();
|
|
93
93
|
|
|
94
94
|
addNodeClass( 'TimerNode', TimerNode );
|
|
@@ -210,7 +210,7 @@ class Lensflare extends Mesh {
|
|
|
210
210
|
|
|
211
211
|
// save current RGB to temp texture
|
|
212
212
|
|
|
213
|
-
renderer.copyFramebufferToTexture(
|
|
213
|
+
renderer.copyFramebufferToTexture( tempMap, screenPositionPixels );
|
|
214
214
|
|
|
215
215
|
// render pink quad
|
|
216
216
|
|
|
@@ -222,7 +222,7 @@ class Lensflare extends Mesh {
|
|
|
222
222
|
|
|
223
223
|
// copy result to occlusionMap
|
|
224
224
|
|
|
225
|
-
renderer.copyFramebufferToTexture(
|
|
225
|
+
renderer.copyFramebufferToTexture( occlusionMap, screenPositionPixels );
|
|
226
226
|
|
|
227
227
|
// restore graphics
|
|
228
228
|
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { Clock, Vector3, Quaternion, Matrix4 } from 'three';
|
|
2
|
+
|
|
3
|
+
const JOLT_PATH = 'https://cdn.jsdelivr.net/npm/jolt-physics@0.23.0/dist/jolt-physics.wasm-compat.js';
|
|
4
|
+
|
|
5
|
+
const frameRate = 60;
|
|
6
|
+
|
|
7
|
+
let Jolt = null;
|
|
8
|
+
|
|
9
|
+
function getShape( geometry ) {
|
|
10
|
+
|
|
11
|
+
const parameters = geometry.parameters;
|
|
12
|
+
|
|
13
|
+
// TODO change type to is*
|
|
14
|
+
|
|
15
|
+
if ( geometry.type === 'BoxGeometry' ) {
|
|
16
|
+
|
|
17
|
+
const sx = parameters.width !== undefined ? parameters.width / 2 : 0.5;
|
|
18
|
+
const sy = parameters.height !== undefined ? parameters.height / 2 : 0.5;
|
|
19
|
+
const sz = parameters.depth !== undefined ? parameters.depth / 2 : 0.5;
|
|
20
|
+
|
|
21
|
+
return new Jolt.BoxShape( new Jolt.Vec3( sx, sy, sz ), 0.05 * Math.min( sx, sy, sz ), null );
|
|
22
|
+
|
|
23
|
+
} else if ( geometry.type === 'SphereGeometry' || geometry.type === 'IcosahedronGeometry' ) {
|
|
24
|
+
|
|
25
|
+
const radius = parameters.radius !== undefined ? parameters.radius : 1;
|
|
26
|
+
|
|
27
|
+
return new Jolt.SphereShape( radius, null );
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return null;
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Object layers
|
|
36
|
+
const LAYER_NON_MOVING = 0;
|
|
37
|
+
const LAYER_MOVING = 1;
|
|
38
|
+
const NUM_OBJECT_LAYERS = 2;
|
|
39
|
+
|
|
40
|
+
function setupCollisionFiltering( settings ) {
|
|
41
|
+
|
|
42
|
+
let objectFilter = new Jolt.ObjectLayerPairFilterTable( NUM_OBJECT_LAYERS );
|
|
43
|
+
objectFilter.EnableCollision( LAYER_NON_MOVING, LAYER_MOVING );
|
|
44
|
+
objectFilter.EnableCollision( LAYER_MOVING, LAYER_MOVING );
|
|
45
|
+
|
|
46
|
+
const BP_LAYER_NON_MOVING = new Jolt.BroadPhaseLayer( 0 );
|
|
47
|
+
const BP_LAYER_MOVING = new Jolt.BroadPhaseLayer( 1 );
|
|
48
|
+
const NUM_BROAD_PHASE_LAYERS = 2;
|
|
49
|
+
|
|
50
|
+
let bpInterface = new Jolt.BroadPhaseLayerInterfaceTable( NUM_OBJECT_LAYERS, NUM_BROAD_PHASE_LAYERS );
|
|
51
|
+
bpInterface.MapObjectToBroadPhaseLayer( LAYER_NON_MOVING, BP_LAYER_NON_MOVING );
|
|
52
|
+
bpInterface.MapObjectToBroadPhaseLayer( LAYER_MOVING, BP_LAYER_MOVING );
|
|
53
|
+
|
|
54
|
+
settings.mObjectLayerPairFilter = objectFilter;
|
|
55
|
+
settings.mBroadPhaseLayerInterface = bpInterface;
|
|
56
|
+
settings.mObjectVsBroadPhaseLayerFilter = new Jolt.ObjectVsBroadPhaseLayerFilterTable( settings.mBroadPhaseLayerInterface, NUM_BROAD_PHASE_LAYERS, settings.mObjectLayerPairFilter, NUM_OBJECT_LAYERS );
|
|
57
|
+
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
async function JoltPhysics() {
|
|
61
|
+
|
|
62
|
+
if ( Jolt === null ) {
|
|
63
|
+
|
|
64
|
+
const { default: initJolt } = await import( JOLT_PATH );
|
|
65
|
+
Jolt = await initJolt();
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const settings = new Jolt.JoltSettings();
|
|
70
|
+
setupCollisionFiltering( settings );
|
|
71
|
+
|
|
72
|
+
const jolt = new Jolt.JoltInterface( settings );
|
|
73
|
+
Jolt.destroy( settings );
|
|
74
|
+
|
|
75
|
+
const physicsSystem = jolt.GetPhysicsSystem();
|
|
76
|
+
const bodyInterface = physicsSystem.GetBodyInterface();
|
|
77
|
+
|
|
78
|
+
const meshes = [];
|
|
79
|
+
const meshMap = new WeakMap();
|
|
80
|
+
|
|
81
|
+
const _position = new Vector3();
|
|
82
|
+
const _quaternion = new Quaternion();
|
|
83
|
+
const _scale = new Vector3( 1, 1, 1 );
|
|
84
|
+
|
|
85
|
+
const _matrix = new Matrix4();
|
|
86
|
+
|
|
87
|
+
function addScene( scene ) {
|
|
88
|
+
|
|
89
|
+
scene.traverse( function ( child ) {
|
|
90
|
+
|
|
91
|
+
if ( child.isMesh ) {
|
|
92
|
+
|
|
93
|
+
const physics = child.userData.physics;
|
|
94
|
+
|
|
95
|
+
if ( physics ) {
|
|
96
|
+
|
|
97
|
+
addMesh( child, physics.mass, physics.restitution );
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
} );
|
|
104
|
+
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function addMesh( mesh, mass = 0, restitution = 0 ) {
|
|
108
|
+
|
|
109
|
+
const shape = getShape( mesh.geometry );
|
|
110
|
+
|
|
111
|
+
if ( shape === null ) return;
|
|
112
|
+
|
|
113
|
+
const body = mesh.isInstancedMesh
|
|
114
|
+
? createInstancedBody( mesh, mass, restitution, shape )
|
|
115
|
+
: createBody( mesh.position, mesh.quaternion, mass, restitution, shape );
|
|
116
|
+
|
|
117
|
+
if ( mass > 0 ) {
|
|
118
|
+
|
|
119
|
+
meshes.push( mesh );
|
|
120
|
+
meshMap.set( mesh, body );
|
|
121
|
+
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function createInstancedBody( mesh, mass, restitution, shape ) {
|
|
127
|
+
|
|
128
|
+
const array = mesh.instanceMatrix.array;
|
|
129
|
+
|
|
130
|
+
const bodies = [];
|
|
131
|
+
|
|
132
|
+
for ( let i = 0; i < mesh.count; i ++ ) {
|
|
133
|
+
|
|
134
|
+
const position = _position.fromArray( array, i * 16 + 12 );
|
|
135
|
+
const quaternion = _quaternion.setFromRotationMatrix( _matrix.fromArray( array, i * 16 ) ); // TODO Copilot did this
|
|
136
|
+
bodies.push( createBody( position, quaternion, mass, restitution, shape ) );
|
|
137
|
+
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return bodies;
|
|
141
|
+
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function createBody( position, rotation, mass, restitution, shape ) {
|
|
145
|
+
|
|
146
|
+
const pos = new Jolt.Vec3( position.x, position.y, position.z );
|
|
147
|
+
const rot = new Jolt.Quat( rotation.x, rotation.y, rotation.z, rotation.w );
|
|
148
|
+
|
|
149
|
+
const motion = mass > 0 ? Jolt.EMotionType_Dynamic : Jolt.EMotionType_Static;
|
|
150
|
+
const layer = mass > 0 ? LAYER_MOVING : LAYER_NON_MOVING;
|
|
151
|
+
|
|
152
|
+
const creationSettings = new Jolt.BodyCreationSettings( shape, pos, rot, motion, layer );
|
|
153
|
+
creationSettings.mRestitution = restitution;
|
|
154
|
+
|
|
155
|
+
const body = bodyInterface.CreateBody( creationSettings );
|
|
156
|
+
|
|
157
|
+
bodyInterface.AddBody( body.GetID(), Jolt.EActivation_Activate );
|
|
158
|
+
|
|
159
|
+
Jolt.destroy( creationSettings );
|
|
160
|
+
|
|
161
|
+
return body;
|
|
162
|
+
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function setMeshPosition( mesh, position, index = 0 ) {
|
|
166
|
+
|
|
167
|
+
if ( mesh.isInstancedMesh ) {
|
|
168
|
+
|
|
169
|
+
const bodies = meshMap.get( mesh );
|
|
170
|
+
|
|
171
|
+
const body = bodies[ index ];
|
|
172
|
+
|
|
173
|
+
bodyInterface.RemoveBody( body.GetID() );
|
|
174
|
+
bodyInterface.DestroyBody( body.GetID() );
|
|
175
|
+
|
|
176
|
+
const physics = mesh.userData.physics;
|
|
177
|
+
|
|
178
|
+
let shape = body.GetShape();
|
|
179
|
+
let body2 = createBody( position, { x: 0, y: 0, z: 0, w: 1 }, physics.mass, physics.restitution, shape );
|
|
180
|
+
|
|
181
|
+
bodies[ index ] = body2;
|
|
182
|
+
|
|
183
|
+
} else {
|
|
184
|
+
|
|
185
|
+
// TODO: Implement this
|
|
186
|
+
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function setMeshVelocity( mesh, velocity, index = 0 ) {
|
|
192
|
+
|
|
193
|
+
/*
|
|
194
|
+
let body = meshMap.get( mesh );
|
|
195
|
+
|
|
196
|
+
if ( mesh.isInstancedMesh ) {
|
|
197
|
+
|
|
198
|
+
body = body[ index ];
|
|
199
|
+
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
body.setLinvel( velocity );
|
|
203
|
+
*/
|
|
204
|
+
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
//
|
|
208
|
+
|
|
209
|
+
const clock = new Clock();
|
|
210
|
+
|
|
211
|
+
function step() {
|
|
212
|
+
|
|
213
|
+
let deltaTime = clock.getDelta();
|
|
214
|
+
|
|
215
|
+
// Don't go below 30 Hz to prevent spiral of death
|
|
216
|
+
deltaTime = Math.min( deltaTime, 1.0 / 30.0 );
|
|
217
|
+
|
|
218
|
+
// When running below 55 Hz, do 2 steps instead of 1
|
|
219
|
+
const numSteps = deltaTime > 1.0 / 55.0 ? 2 : 1;
|
|
220
|
+
|
|
221
|
+
// Step the physics world
|
|
222
|
+
jolt.Step( deltaTime, numSteps );
|
|
223
|
+
|
|
224
|
+
//
|
|
225
|
+
|
|
226
|
+
for ( let i = 0, l = meshes.length; i < l; i ++ ) {
|
|
227
|
+
|
|
228
|
+
const mesh = meshes[ i ];
|
|
229
|
+
|
|
230
|
+
if ( mesh.isInstancedMesh ) {
|
|
231
|
+
|
|
232
|
+
const array = mesh.instanceMatrix.array;
|
|
233
|
+
const bodies = meshMap.get( mesh );
|
|
234
|
+
|
|
235
|
+
for ( let j = 0; j < bodies.length; j ++ ) {
|
|
236
|
+
|
|
237
|
+
const body = bodies[ j ];
|
|
238
|
+
|
|
239
|
+
const position = body.GetPosition();
|
|
240
|
+
const quaternion = body.GetRotation();
|
|
241
|
+
|
|
242
|
+
_position.set( position.GetX(), position.GetY(), position.GetZ() );
|
|
243
|
+
_quaternion.set( quaternion.GetX(), quaternion.GetY(), quaternion.GetZ(), quaternion.GetW() );
|
|
244
|
+
|
|
245
|
+
_matrix.compose( _position, _quaternion, _scale ).toArray( array, j * 16 );
|
|
246
|
+
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
mesh.instanceMatrix.needsUpdate = true;
|
|
250
|
+
mesh.computeBoundingSphere();
|
|
251
|
+
|
|
252
|
+
} else {
|
|
253
|
+
|
|
254
|
+
const body = meshMap.get( mesh );
|
|
255
|
+
|
|
256
|
+
const position = body.GetPosition();
|
|
257
|
+
const rotation = body.GetRotation();
|
|
258
|
+
|
|
259
|
+
mesh.position.set( position.GetX(), position.GetY(), position.GetZ() );
|
|
260
|
+
mesh.quaternion.set( rotation.GetX(), rotation.GetY(), rotation.GetZ(), rotation.GetW() );
|
|
261
|
+
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// animate
|
|
269
|
+
|
|
270
|
+
setInterval( step, 1000 / frameRate );
|
|
271
|
+
|
|
272
|
+
return {
|
|
273
|
+
addScene: addScene,
|
|
274
|
+
addMesh: addMesh,
|
|
275
|
+
setMeshPosition: setMeshPosition,
|
|
276
|
+
setMeshVelocity: setMeshVelocity
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export { JoltPhysics };
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HalfFloatType,
|
|
3
|
+
ShaderMaterial,
|
|
4
|
+
WebGLRenderTarget
|
|
5
|
+
} from 'three';
|
|
6
|
+
import { FullScreenQuad, Pass } from './Pass.js';
|
|
7
|
+
|
|
8
|
+
class RenderTransitionPass extends Pass {
|
|
9
|
+
|
|
10
|
+
constructor( sceneA, cameraA, sceneB, cameraB ) {
|
|
11
|
+
|
|
12
|
+
super();
|
|
13
|
+
|
|
14
|
+
this.material = this.createMaterial();
|
|
15
|
+
this.fsQuad = new FullScreenQuad( this.material );
|
|
16
|
+
|
|
17
|
+
this.sceneA = sceneA;
|
|
18
|
+
this.cameraA = cameraA;
|
|
19
|
+
this.sceneB = sceneB;
|
|
20
|
+
this.cameraB = cameraB;
|
|
21
|
+
|
|
22
|
+
this.renderTargetA = new WebGLRenderTarget();
|
|
23
|
+
this.renderTargetA.texture.type = HalfFloatType;
|
|
24
|
+
this.renderTargetB = new WebGLRenderTarget();
|
|
25
|
+
this.renderTargetB.texture.type = HalfFloatType;
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
setTransition( value ) {
|
|
30
|
+
|
|
31
|
+
this.material.uniforms.mixRatio.value = value;
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
useTexture( value ) {
|
|
36
|
+
|
|
37
|
+
this.material.uniforms.useTexture.value = value ? 1 : 0;
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
setTexture( value ) {
|
|
42
|
+
|
|
43
|
+
this.material.uniforms.tMixTexture.value = value;
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
setTextureThreshold( value ) {
|
|
48
|
+
|
|
49
|
+
this.material.uniforms.threshold.value = value;
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
setSize( width, height ) {
|
|
54
|
+
|
|
55
|
+
this.renderTargetA.setSize( width, height );
|
|
56
|
+
this.renderTargetB.setSize( width, height );
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
render( renderer, writeBuffer ) {
|
|
61
|
+
|
|
62
|
+
const uniforms = this.fsQuad.material.uniforms;
|
|
63
|
+
const transition = uniforms.mixRatio.value;
|
|
64
|
+
|
|
65
|
+
// Prevent render both scenes when it's not necessary
|
|
66
|
+
|
|
67
|
+
if ( transition === 0 ) {
|
|
68
|
+
|
|
69
|
+
renderer.setRenderTarget( writeBuffer );
|
|
70
|
+
if ( this.clear ) renderer.clear();
|
|
71
|
+
renderer.render( this.sceneB, this.cameraB );
|
|
72
|
+
|
|
73
|
+
} else if ( transition === 1 ) {
|
|
74
|
+
|
|
75
|
+
renderer.setRenderTarget( writeBuffer );
|
|
76
|
+
if ( this.clear ) renderer.clear();
|
|
77
|
+
renderer.render( this.sceneA, this.cameraA );
|
|
78
|
+
|
|
79
|
+
} else {
|
|
80
|
+
|
|
81
|
+
// When 0 < transition < 1 render transition between two scenes
|
|
82
|
+
|
|
83
|
+
renderer.setRenderTarget( this.renderTargetA );
|
|
84
|
+
renderer.render( this.sceneA, this.cameraA );
|
|
85
|
+
renderer.setRenderTarget( this.renderTargetB );
|
|
86
|
+
renderer.render( this.sceneB, this.cameraB );
|
|
87
|
+
|
|
88
|
+
uniforms.tDiffuse1.value = this.renderTargetA.texture;
|
|
89
|
+
uniforms.tDiffuse2.value = this.renderTargetB.texture;
|
|
90
|
+
|
|
91
|
+
if ( this.renderToScreen ) {
|
|
92
|
+
|
|
93
|
+
renderer.setRenderTarget( null );
|
|
94
|
+
renderer.clear();
|
|
95
|
+
|
|
96
|
+
} else {
|
|
97
|
+
|
|
98
|
+
renderer.setRenderTarget( writeBuffer );
|
|
99
|
+
if ( this.clear ) renderer.clear();
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
this.fsQuad.render( renderer );
|
|
104
|
+
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
dispose() {
|
|
110
|
+
|
|
111
|
+
this.renderTargetA.dispose();
|
|
112
|
+
this.renderTargetB.dispose();
|
|
113
|
+
this.material.dispose();
|
|
114
|
+
this.fsQuad.dispose();
|
|
115
|
+
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
createMaterial() {
|
|
119
|
+
|
|
120
|
+
return new ShaderMaterial( {
|
|
121
|
+
uniforms: {
|
|
122
|
+
tDiffuse1: {
|
|
123
|
+
value: null
|
|
124
|
+
},
|
|
125
|
+
tDiffuse2: {
|
|
126
|
+
value: null
|
|
127
|
+
},
|
|
128
|
+
mixRatio: {
|
|
129
|
+
value: 0.0
|
|
130
|
+
},
|
|
131
|
+
threshold: {
|
|
132
|
+
value: 0.1
|
|
133
|
+
},
|
|
134
|
+
useTexture: {
|
|
135
|
+
value: 1
|
|
136
|
+
},
|
|
137
|
+
tMixTexture: {
|
|
138
|
+
value: null
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
vertexShader: /* glsl */`
|
|
142
|
+
varying vec2 vUv;
|
|
143
|
+
|
|
144
|
+
void main() {
|
|
145
|
+
|
|
146
|
+
vUv = vec2( uv.x, uv.y );
|
|
147
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
`,
|
|
151
|
+
fragmentShader: /* glsl */`
|
|
152
|
+
uniform float mixRatio;
|
|
153
|
+
|
|
154
|
+
uniform sampler2D tDiffuse1;
|
|
155
|
+
uniform sampler2D tDiffuse2;
|
|
156
|
+
uniform sampler2D tMixTexture;
|
|
157
|
+
|
|
158
|
+
uniform int useTexture;
|
|
159
|
+
uniform float threshold;
|
|
160
|
+
|
|
161
|
+
varying vec2 vUv;
|
|
162
|
+
|
|
163
|
+
void main() {
|
|
164
|
+
|
|
165
|
+
vec4 texel1 = texture2D( tDiffuse1, vUv );
|
|
166
|
+
vec4 texel2 = texture2D( tDiffuse2, vUv );
|
|
167
|
+
|
|
168
|
+
if (useTexture == 1) {
|
|
169
|
+
|
|
170
|
+
vec4 transitionTexel = texture2D( tMixTexture, vUv );
|
|
171
|
+
float r = mixRatio * ( 1.0 + threshold * 2.0 ) - threshold;
|
|
172
|
+
float mixf = clamp( ( transitionTexel.r - r ) * ( 1.0 / threshold ), 0.0, 1.0 );
|
|
173
|
+
|
|
174
|
+
gl_FragColor = mix( texel1, texel2, mixf );
|
|
175
|
+
|
|
176
|
+
} else {
|
|
177
|
+
|
|
178
|
+
gl_FragColor = mix( texel2, texel1, mixRatio );
|
|
179
|
+
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
#include <tonemapping_fragment>
|
|
183
|
+
#include <colorspace_fragment>
|
|
184
|
+
|
|
185
|
+
}
|
|
186
|
+
`
|
|
187
|
+
} );
|
|
188
|
+
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export { RenderTransitionPass };
|