super-three 0.168.0 → 0.169.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/three.cjs +384 -700
- package/build/three.module.js +384 -700
- package/build/three.module.min.js +1 -1
- package/build/three.webgpu.js +24644 -22406
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +79941 -0
- package/build/three.webgpu.nodes.min.js +6 -0
- package/examples/jsm/Addons.js +0 -6
- package/examples/jsm/controls/TrackballControls.js +32 -12
- package/examples/jsm/controls/TransformControls.js +97 -62
- package/examples/jsm/exporters/DRACOExporter.js +4 -2
- package/examples/jsm/exporters/EXRExporter.js +19 -11
- package/examples/jsm/exporters/KTX2Exporter.js +21 -13
- package/examples/jsm/exporters/OBJExporter.js +5 -1
- package/examples/jsm/exporters/PLYExporter.js +9 -7
- package/examples/jsm/geometries/DecalGeometry.js +4 -1
- package/examples/jsm/geometries/InstancedPointsGeometry.js +1 -1
- package/examples/jsm/helpers/LightProbeHelper.js +1 -1
- package/examples/jsm/helpers/LightProbeHelperGPU.js +65 -0
- package/examples/jsm/libs/basis/basis_transcoder.js +8 -10
- package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
- package/examples/jsm/libs/ktx-parse.module.js +1 -1
- package/examples/jsm/lights/LightProbeGenerator.js +24 -10
- package/examples/jsm/loaders/ColladaLoader.js +9 -6
- package/examples/jsm/loaders/DRACOLoader.js +3 -1
- package/examples/jsm/loaders/FBXLoader.js +30 -20
- package/examples/jsm/loaders/GLTFLoader.js +5 -10
- package/examples/jsm/loaders/KTX2Loader.js +10 -7
- package/examples/jsm/loaders/MTLLoader.js +4 -3
- package/examples/jsm/loaders/MaterialXLoader.js +29 -10
- package/examples/jsm/loaders/OBJLoader.js +5 -3
- package/examples/jsm/loaders/PCDLoader.js +5 -4
- package/examples/jsm/loaders/PDBLoader.js +3 -2
- package/examples/jsm/loaders/PLYLoader.js +8 -5
- package/examples/jsm/loaders/STLLoader.js +3 -2
- package/examples/jsm/loaders/VRMLLoader.js +10 -10
- package/examples/jsm/loaders/VTKLoader.js +4 -3
- package/examples/jsm/loaders/XYZLoader.js +3 -2
- package/examples/jsm/misc/Timer.js +1 -1
- package/examples/jsm/modifiers/CurveModifierGPU.js +233 -0
- package/examples/jsm/objects/LensflareMesh.js +322 -0
- package/examples/jsm/objects/SkyMesh.js +1 -2
- package/examples/jsm/objects/Water2Mesh.js +2 -3
- package/examples/jsm/objects/WaterMesh.js +1 -2
- package/examples/jsm/physics/JoltPhysics.js +1 -1
- package/examples/jsm/physics/RapierPhysics.js +1 -1
- package/examples/jsm/transpiler/GLSLDecoder.js +1 -1
- package/examples/jsm/transpiler/ShaderToyDecoder.js +2 -2
- package/examples/jsm/utils/GeometryCompressionUtils.js +37 -122
- 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/TextureUtils.js +1 -0
- package/examples/jsm/utils/TextureUtilsGPU.js +63 -0
- package/examples/jsm/webxr/XRControllerModelFactory.js +1 -1
- package/package.json +2 -2
- package/src/Three.WebGPU.Nodes.js +200 -0
- package/src/Three.WebGPU.js +2 -1
- package/src/audio/Audio.js +2 -2
- package/src/constants.js +1 -1
- package/src/core/BufferAttribute.js +0 -9
- package/src/core/Clock.js +1 -1
- package/src/core/InterleavedBuffer.js +0 -9
- package/src/extras/Controls.js +1 -1
- package/src/geometries/CylinderGeometry.js +11 -4
- package/src/loaders/MaterialLoader.js +7 -1
- package/src/loaders/nodes/NodeLoader.js +24 -4
- package/src/loaders/nodes/NodeMaterialLoader.js +21 -17
- package/src/loaders/nodes/NodeObjectLoader.js +19 -0
- package/src/materials/nodes/InstancedPointsNodeMaterial.js +19 -34
- package/src/materials/nodes/Line2NodeMaterial.js +26 -26
- package/src/materials/nodes/LineBasicNodeMaterial.js +7 -3
- package/src/materials/nodes/LineDashedNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshBasicNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshLambertNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshMatcapNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshNormalNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshPhongNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +6 -3
- package/src/materials/nodes/MeshSSSNodeMaterial.js +6 -3
- package/src/materials/nodes/MeshStandardNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshToonNodeMaterial.js +7 -3
- package/src/materials/nodes/NodeMaterial.js +20 -45
- package/src/materials/nodes/NodeMaterials.js +2 -0
- package/src/materials/nodes/PointsNodeMaterial.js +7 -3
- package/src/materials/nodes/ShadowNodeMaterial.js +7 -3
- package/src/materials/nodes/SpriteNodeMaterial.js +39 -6
- package/src/materials/nodes/VolumeNodeMaterial.js +13 -9
- package/src/materials/nodes/manager/NodeMaterialObserver.js +302 -0
- package/src/math/Triangle.js +24 -0
- package/src/nodes/Nodes.js +3 -3
- package/src/nodes/TSL.js +96 -93
- package/src/nodes/accessors/BatchNode.js +7 -3
- package/src/nodes/accessors/BufferAttributeNode.js +6 -3
- package/src/nodes/accessors/BufferNode.js +6 -3
- package/src/nodes/accessors/Camera.js +10 -16
- package/src/nodes/accessors/ClippingNode.js +7 -3
- package/src/nodes/accessors/CubeTextureNode.js +6 -3
- package/src/nodes/accessors/InstanceNode.js +11 -11
- package/src/nodes/accessors/InstancedPointsMaterialNode.js +6 -3
- package/src/nodes/accessors/Lights.js +51 -0
- package/src/nodes/accessors/MaterialNode.js +8 -4
- package/src/nodes/accessors/MaterialReferenceNode.js +6 -3
- package/src/nodes/accessors/ModelNode.js +42 -7
- package/src/nodes/accessors/ModelViewProjectionNode.js +9 -5
- package/src/nodes/accessors/MorphNode.js +7 -3
- package/src/nodes/accessors/Normal.js +32 -6
- package/src/nodes/accessors/Object3DNode.js +11 -27
- package/src/nodes/accessors/PointUVNode.js +7 -3
- package/src/nodes/accessors/ReferenceBaseNode.js +32 -4
- package/src/nodes/accessors/ReferenceNode.js +40 -3
- package/src/nodes/accessors/RendererReferenceNode.js +9 -3
- package/src/nodes/accessors/SceneNode.js +7 -3
- package/src/nodes/accessors/SkinningNode.js +7 -3
- package/src/nodes/accessors/StorageBufferNode.js +21 -3
- package/src/nodes/accessors/StorageTextureNode.js +7 -4
- package/src/nodes/accessors/Texture3DNode.js +7 -4
- package/src/nodes/accessors/TextureNode.js +19 -8
- package/src/nodes/accessors/TextureSizeNode.js +8 -5
- package/src/nodes/accessors/UniformArrayNode.js +12 -9
- package/src/nodes/accessors/UserDataNode.js +9 -6
- package/src/nodes/accessors/VelocityNode.js +74 -23
- package/src/nodes/accessors/VertexColorNode.js +6 -3
- package/src/nodes/code/CodeNode.js +7 -3
- package/src/nodes/code/ExpressionNode.js +8 -4
- package/src/nodes/code/FunctionCallNode.js +6 -3
- package/src/nodes/code/FunctionNode.js +6 -3
- package/src/nodes/code/ScriptableNode.js +11 -6
- package/src/nodes/code/ScriptableValueNode.js +7 -3
- package/src/nodes/core/AssignNode.js +9 -6
- package/src/nodes/core/AttributeNode.js +7 -3
- package/src/nodes/core/BypassNode.js +8 -4
- package/src/nodes/core/CacheNode.js +8 -4
- package/src/nodes/core/ConstNode.js +6 -3
- package/src/nodes/core/ContextNode.js +7 -3
- package/src/nodes/core/IndexNode.js +25 -3
- package/src/nodes/core/InputNode.js +7 -3
- package/src/nodes/core/MRTNode.js +6 -3
- package/src/nodes/core/Node.js +10 -51
- package/src/nodes/core/NodeBuilder.js +71 -5
- package/src/nodes/core/NodeUtils.js +48 -6
- package/src/nodes/core/OutputStructNode.js +8 -4
- package/src/nodes/core/ParameterNode.js +6 -3
- package/src/nodes/core/PropertyNode.js +7 -3
- package/src/nodes/core/StackNode.js +7 -3
- package/src/nodes/core/StructTypeNode.js +7 -3
- package/src/nodes/core/TempNode.js +8 -4
- package/src/nodes/core/UniformGroupNode.js +10 -6
- package/src/nodes/core/UniformNode.js +6 -3
- package/src/nodes/core/VarNode.js +8 -4
- package/src/nodes/core/VaryingNode.js +7 -3
- package/src/nodes/display/AfterImageNode.js +6 -0
- package/src/nodes/display/AnaglyphPassNode.js +6 -0
- package/src/nodes/display/AnamorphicNode.js +6 -0
- package/src/nodes/display/BloomNode.js +6 -0
- package/src/nodes/display/BumpMapNode.js +6 -0
- package/src/nodes/display/ColorSpaceFunctions.js +4 -4
- package/src/nodes/display/ColorSpaceNode.js +43 -14
- package/src/nodes/display/DenoiseNode.js +6 -3
- package/src/nodes/display/DepthOfFieldNode.js +6 -3
- package/src/nodes/display/DotScreenNode.js +8 -5
- package/src/nodes/display/FXAANode.js +6 -3
- package/src/nodes/display/FilmNode.js +6 -3
- package/src/nodes/display/FrontFacingNode.js +7 -3
- package/src/nodes/display/GTAONode.js +6 -3
- package/src/nodes/display/GaussianBlurNode.js +6 -3
- package/src/nodes/display/Lut3DNode.js +6 -3
- package/src/nodes/display/NormalMapNode.js +8 -6
- package/src/nodes/display/ParallaxBarrierPassNode.js +8 -5
- package/src/nodes/display/PassNode.js +18 -7
- package/src/nodes/display/PixelationPassNode.js +12 -5
- package/src/nodes/display/PosterizeNode.js +6 -3
- package/src/nodes/display/RGBShiftNode.js +6 -3
- package/src/nodes/display/RenderOutputNode.js +12 -8
- package/src/nodes/display/SSAAPassNode.js +6 -3
- package/src/nodes/display/ScreenNode.js +181 -0
- package/src/nodes/display/SobelOperatorNode.js +6 -3
- package/src/nodes/display/StereoCompositePassNode.js +6 -3
- package/src/nodes/display/StereoPassNode.js +6 -3
- package/src/nodes/display/ToneMappingFunctions.js +12 -12
- package/src/nodes/display/ToneMappingNode.js +8 -7
- package/src/nodes/display/ToonOutlinePassNode.js +111 -0
- package/src/nodes/display/TransitionNode.js +6 -3
- package/src/nodes/display/ViewportDepthNode.js +7 -3
- package/src/nodes/display/ViewportDepthTextureNode.js +8 -5
- package/src/nodes/display/ViewportSharedTextureNode.js +8 -5
- package/src/nodes/display/ViewportTextureNode.js +8 -5
- package/src/nodes/fog/FogExp2Node.js +6 -3
- package/src/nodes/fog/FogNode.js +7 -3
- package/src/nodes/fog/FogRangeNode.js +6 -3
- package/src/nodes/functions/PhysicalLightingModel.js +2 -2
- package/src/nodes/functions/material/getShIrradianceAt.js +28 -0
- package/src/nodes/geometry/RangeNode.js +7 -3
- package/src/nodes/gpgpu/AtomicFunctionNode.js +99 -0
- package/src/nodes/gpgpu/BarrierNode.js +40 -0
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +98 -0
- package/src/nodes/gpgpu/ComputeNode.js +8 -4
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +100 -0
- package/src/nodes/lighting/AONode.js +6 -3
- package/src/nodes/lighting/AmbientLightNode.js +6 -3
- package/src/nodes/lighting/AnalyticLightNode.js +198 -30
- package/src/nodes/lighting/BasicEnvironmentNode.js +6 -3
- package/src/nodes/lighting/BasicLightMapNode.js +6 -3
- package/src/nodes/lighting/DirectionalLightNode.js +7 -4
- package/src/nodes/lighting/EnvironmentNode.js +6 -3
- package/src/nodes/lighting/HemisphereLightNode.js +10 -6
- package/src/nodes/lighting/IESSpotLightNode.js +6 -3
- package/src/nodes/lighting/IrradianceNode.js +6 -3
- package/src/nodes/lighting/LightProbeNode.js +8 -31
- package/src/nodes/lighting/LightingContextNode.js +6 -3
- package/src/nodes/lighting/LightingNode.js +7 -3
- package/src/nodes/lighting/LightsNode.js +24 -5
- package/src/nodes/lighting/PointLightNode.js +11 -7
- package/src/nodes/lighting/RectAreaLightNode.js +11 -7
- package/src/nodes/lighting/SpotLightNode.js +13 -10
- package/src/nodes/math/ConditionalNode.js +23 -6
- package/src/nodes/math/MathNode.js +6 -3
- package/src/nodes/math/OperatorNode.js +6 -3
- package/src/nodes/pmrem/PMREMNode.js +6 -3
- package/src/nodes/utils/ArrayElementNode.js +8 -4
- package/src/nodes/utils/ConvertNode.js +7 -3
- package/src/nodes/utils/CubeMapNode.js +6 -3
- package/src/nodes/utils/EquirectUVNode.js +6 -3
- package/src/nodes/utils/FlipNode.js +7 -4
- package/src/nodes/utils/FunctionOverloadingNode.js +7 -3
- package/src/nodes/utils/JoinNode.js +6 -3
- package/src/nodes/utils/LoopNode.js +7 -3
- package/src/nodes/utils/MatcapUVNode.js +6 -3
- package/src/nodes/utils/MaxMipLevelNode.js +6 -3
- package/src/nodes/utils/OscNode.js +7 -3
- package/src/nodes/utils/RTTNode.js +6 -3
- package/src/nodes/utils/ReflectorNode.js +8 -5
- package/src/nodes/utils/RemapNode.js +7 -3
- package/src/nodes/utils/RotateNode.js +6 -3
- package/src/nodes/utils/SetNode.js +7 -4
- package/src/nodes/utils/SplitNode.js +7 -3
- package/src/nodes/utils/SpriteSheetUVNode.js +7 -3
- package/src/nodes/utils/StorageArrayElementNode.js +9 -8
- package/src/nodes/utils/TimerNode.js +6 -3
- package/src/nodes/utils/TriplanarTexturesNode.js +7 -3
- package/src/nodes/utils/ViewportUtils.js +2 -2
- package/src/objects/BatchedMesh.js +76 -10
- package/src/objects/LOD.js +21 -0
- package/src/objects/Line.js +1 -0
- package/src/objects/Mesh.js +7 -23
- package/src/objects/Points.js +2 -0
- package/src/renderers/WebGLRenderer.js +65 -50
- package/src/renderers/common/BundleGroup.js +26 -0
- package/src/renderers/common/ClippingContext.js +4 -3
- package/src/renderers/common/RenderContext.js +4 -5
- package/src/renderers/common/RenderObject.js +116 -5
- package/src/renderers/common/RenderObjects.js +8 -1
- package/src/renderers/common/Renderer.js +57 -49
- package/src/renderers/common/extras/PMREMGenerator.js +7 -9
- package/src/renderers/common/nodes/NodeBuilderState.js +3 -3
- package/src/renderers/common/nodes/Nodes.js +33 -14
- package/src/renderers/shaders/ShaderLib/sprite.glsl.js +2 -4
- package/src/renderers/webgl/WebGLAttributes.js +45 -14
- package/src/renderers/webgl/WebGLCapabilities.js +9 -0
- package/src/renderers/webgl/WebGLProgram.js +2 -0
- package/src/renderers/webgl/WebGLPrograms.js +21 -17
- package/src/renderers/webgl/WebGLState.js +21 -0
- package/src/renderers/webgl/WebGLTextures.js +22 -0
- package/src/renderers/webgl-fallback/WebGLBackend.js +50 -45
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +4 -4
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +6 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +1 -4
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +61 -16
- package/src/renderers/webgpu/WebGPUBackend.js +33 -25
- package/src/renderers/webgpu/WebGPURenderer.Nodes.js +42 -0
- package/src/renderers/webgpu/WebGPURenderer.js +5 -2
- package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +59 -0
- package/src/renderers/{common → webgpu}/nodes/StandardNodeLibrary.js +11 -11
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +91 -11
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +6 -16
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +1 -1
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +7 -5
- package/src/renderers/webgpu/utils/WebGPUUtils.js +1 -1
- package/src/utils.js +33 -1
- package/examples/jsm/geometries/SDFGeometryGenerator.js +0 -144
- package/examples/jsm/loaders/TiltLoader.js +0 -520
- package/examples/jsm/utils/GPUStatsPanel.js +0 -95
- package/examples/jsm/utils/PackedPhongMaterial.js +0 -178
- package/src/nodes/display/ViewportNode.js +0 -138
- package/src/nodes/lighting/LightNode.js +0 -57
- package/src/renderers/common/StandardRenderer.js +0 -18
- package/src/renderers/webvr/WebVRManager.js +0 -495
- package/src/renderers/webvr/WebVRUtils.js +0 -66
|
@@ -1,495 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author mrdoob / http://mrdoob.com/
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { EventDispatcher } from '../../core/EventDispatcher.js';
|
|
6
|
-
import { Group } from '../../objects/Group.js';
|
|
7
|
-
import { Matrix4 } from '../../math/Matrix4.js';
|
|
8
|
-
import { Vector2 } from '../../math/Vector2.js';
|
|
9
|
-
import { Vector3 } from '../../math/Vector3.js';
|
|
10
|
-
import { Vector4 } from '../../math/Vector4.js';
|
|
11
|
-
import { Quaternion } from '../../math/Quaternion.js';
|
|
12
|
-
import { ArrayCamera } from '../../cameras/ArrayCamera.js';
|
|
13
|
-
import { PerspectiveCamera } from '../../cameras/PerspectiveCamera.js';
|
|
14
|
-
import { WebGLAnimation } from '../webgl/WebGLAnimation.js';
|
|
15
|
-
import { setProjectionFromUnion } from './WebVRUtils.js';
|
|
16
|
-
|
|
17
|
-
function WebVRManager( renderer ) {
|
|
18
|
-
|
|
19
|
-
var renderWidth, renderHeight;
|
|
20
|
-
var scope = this;
|
|
21
|
-
|
|
22
|
-
var device = null;
|
|
23
|
-
var frameData = null;
|
|
24
|
-
|
|
25
|
-
var poseTarget = null;
|
|
26
|
-
|
|
27
|
-
var controllers = [];
|
|
28
|
-
var standingMatrix = new Matrix4();
|
|
29
|
-
var standingMatrixInverse = new Matrix4();
|
|
30
|
-
|
|
31
|
-
var framebufferScaleFactor = 1.0;
|
|
32
|
-
|
|
33
|
-
var referenceSpaceType = 'local-floor';
|
|
34
|
-
|
|
35
|
-
if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
|
|
36
|
-
|
|
37
|
-
frameData = new window.VRFrameData();
|
|
38
|
-
window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
var matrixWorldInverse = new Matrix4();
|
|
43
|
-
var tempQuaternion = new Quaternion();
|
|
44
|
-
var tempPosition = new Vector3();
|
|
45
|
-
|
|
46
|
-
var cameraL = new PerspectiveCamera();
|
|
47
|
-
cameraL.viewport = new Vector4();
|
|
48
|
-
cameraL.layers.enable( 1 );
|
|
49
|
-
|
|
50
|
-
var cameraR = new PerspectiveCamera();
|
|
51
|
-
cameraR.viewport = new Vector4();
|
|
52
|
-
cameraR.layers.enable( 2 );
|
|
53
|
-
|
|
54
|
-
var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
|
|
55
|
-
cameraVR.layers.enable( 1 );
|
|
56
|
-
cameraVR.layers.enable( 2 );
|
|
57
|
-
|
|
58
|
-
var currentSize = new Vector2(), currentPixelRatio;
|
|
59
|
-
|
|
60
|
-
function onVRDisplayPresentChange() {
|
|
61
|
-
|
|
62
|
-
var isPresenting = scope.isPresenting = device !== null && device.isPresenting === true;
|
|
63
|
-
|
|
64
|
-
if ( isPresenting ) {
|
|
65
|
-
|
|
66
|
-
var eyeParameters = device.getEyeParameters( 'left' );
|
|
67
|
-
renderWidth = 2 * eyeParameters.renderWidth * framebufferScaleFactor;
|
|
68
|
-
renderHeight = eyeParameters.renderHeight * framebufferScaleFactor;
|
|
69
|
-
|
|
70
|
-
currentPixelRatio = renderer.getPixelRatio();
|
|
71
|
-
renderer.getSize( currentSize );
|
|
72
|
-
|
|
73
|
-
renderer.setDrawingBufferSize( renderWidth, renderHeight, 1 );
|
|
74
|
-
|
|
75
|
-
cameraL.viewport.set( 0, 0, renderWidth / 2, renderHeight );
|
|
76
|
-
cameraR.viewport.set( renderWidth / 2, 0, renderWidth / 2, renderHeight );
|
|
77
|
-
|
|
78
|
-
animation.start();
|
|
79
|
-
|
|
80
|
-
scope.dispatchEvent( { type: 'sessionstart' } );
|
|
81
|
-
|
|
82
|
-
} else {
|
|
83
|
-
|
|
84
|
-
if ( scope.enabled ) {
|
|
85
|
-
|
|
86
|
-
renderer.setDrawingBufferSize( currentSize.width, currentSize.height, currentPixelRatio );
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
animation.stop();
|
|
91
|
-
|
|
92
|
-
scope.dispatchEvent( { type: 'sessionend' } );
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
//
|
|
99
|
-
|
|
100
|
-
var triggers = [];
|
|
101
|
-
var grips = [];
|
|
102
|
-
|
|
103
|
-
function findGamepad( id ) {
|
|
104
|
-
|
|
105
|
-
var gamepads = navigator.getGamepads && navigator.getGamepads();
|
|
106
|
-
|
|
107
|
-
for ( var i = 0, l = gamepads.length; i < l; i ++ ) {
|
|
108
|
-
|
|
109
|
-
var gamepad = gamepads[ i ];
|
|
110
|
-
|
|
111
|
-
if ( gamepad && ( gamepad.id === 'Daydream Controller' ||
|
|
112
|
-
gamepad.id === 'Gear VR Controller' || gamepad.id === 'Oculus Go Controller' ||
|
|
113
|
-
gamepad.id === 'OpenVR Gamepad' || gamepad.id.startsWith( 'Oculus Touch' ) ||
|
|
114
|
-
gamepad.id.startsWith( 'HTC Vive Focus' ) ||
|
|
115
|
-
gamepad.id.startsWith( 'Spatial Controller' ) ) ) {
|
|
116
|
-
|
|
117
|
-
var hand = gamepad.hand;
|
|
118
|
-
|
|
119
|
-
if ( id === 0 && ( hand === '' || hand === 'right' ) ) return gamepad;
|
|
120
|
-
if ( id === 1 && ( hand === 'left' ) ) return gamepad;
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function updateControllers() {
|
|
129
|
-
|
|
130
|
-
for ( var i = 0; i < controllers.length; i ++ ) {
|
|
131
|
-
|
|
132
|
-
var controller = controllers[ i ];
|
|
133
|
-
|
|
134
|
-
var gamepad = findGamepad( i );
|
|
135
|
-
|
|
136
|
-
if ( gamepad !== undefined && gamepad.pose !== undefined ) {
|
|
137
|
-
|
|
138
|
-
if ( gamepad.pose === null ) return;
|
|
139
|
-
|
|
140
|
-
// Pose
|
|
141
|
-
|
|
142
|
-
var pose = gamepad.pose;
|
|
143
|
-
|
|
144
|
-
if ( pose.hasPosition === false ) controller.position.set( 0.2, - 0.6, - 0.05 );
|
|
145
|
-
|
|
146
|
-
if ( pose.position !== null ) controller.position.fromArray( pose.position );
|
|
147
|
-
if ( pose.orientation !== null ) controller.quaternion.fromArray( pose.orientation );
|
|
148
|
-
controller.matrix.compose( controller.position, controller.quaternion, controller.scale );
|
|
149
|
-
controller.matrix.premultiply( standingMatrix );
|
|
150
|
-
controller.matrix.decompose( controller.position, controller.quaternion, controller.scale );
|
|
151
|
-
controller.matrixWorldNeedsUpdate = true;
|
|
152
|
-
controller.visible = true;
|
|
153
|
-
|
|
154
|
-
// Trigger
|
|
155
|
-
|
|
156
|
-
var buttonId = gamepad.id === 'Daydream Controller' ? 0 : 1;
|
|
157
|
-
|
|
158
|
-
if ( triggers[ i ] === undefined ) triggers[ i ] = false;
|
|
159
|
-
|
|
160
|
-
if ( triggers[ i ] !== gamepad.buttons[ buttonId ].pressed ) {
|
|
161
|
-
|
|
162
|
-
triggers[ i ] = gamepad.buttons[ buttonId ].pressed;
|
|
163
|
-
|
|
164
|
-
if ( triggers[ i ] === true ) {
|
|
165
|
-
|
|
166
|
-
controller.dispatchEvent( { type: 'selectstart' } );
|
|
167
|
-
|
|
168
|
-
} else {
|
|
169
|
-
|
|
170
|
-
controller.dispatchEvent( { type: 'selectend' } );
|
|
171
|
-
controller.dispatchEvent( { type: 'select' } );
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// Grip
|
|
178
|
-
buttonId = 2;
|
|
179
|
-
|
|
180
|
-
if ( grips[ i ] === undefined ) grips[ i ] = false;
|
|
181
|
-
|
|
182
|
-
// Skip if the grip button doesn't exist on this controller
|
|
183
|
-
if ( gamepad.buttons[ buttonId ] !== undefined ) {
|
|
184
|
-
|
|
185
|
-
if ( grips[ i ] !== gamepad.buttons[ buttonId ].pressed ) {
|
|
186
|
-
|
|
187
|
-
grips[ i ] = gamepad.buttons[ buttonId ].pressed;
|
|
188
|
-
|
|
189
|
-
if ( grips[ i ] === true ) {
|
|
190
|
-
|
|
191
|
-
controller.dispatchEvent( { type: 'squeezestart' } );
|
|
192
|
-
|
|
193
|
-
} else {
|
|
194
|
-
|
|
195
|
-
controller.dispatchEvent( { type: 'squeezeend' } );
|
|
196
|
-
controller.dispatchEvent( { type: 'squeeze' } );
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
} else {
|
|
205
|
-
|
|
206
|
-
controller.visible = false;
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function updateViewportFromBounds( viewport, bounds ) {
|
|
215
|
-
|
|
216
|
-
if ( bounds !== null && bounds.length === 4 ) {
|
|
217
|
-
|
|
218
|
-
viewport.set( bounds[ 0 ] * renderWidth, bounds[ 1 ] * renderHeight, bounds[ 2 ] * renderWidth, bounds[ 3 ] * renderHeight );
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
//
|
|
225
|
-
|
|
226
|
-
this.enabled = false;
|
|
227
|
-
|
|
228
|
-
this.getController = function ( id ) {
|
|
229
|
-
|
|
230
|
-
var controller = controllers[ id ];
|
|
231
|
-
|
|
232
|
-
if ( controller === undefined ) {
|
|
233
|
-
|
|
234
|
-
controller = new Group();
|
|
235
|
-
controller.matrixAutoUpdate = false;
|
|
236
|
-
controller.visible = false;
|
|
237
|
-
|
|
238
|
-
controllers[ id ] = controller;
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return controller;
|
|
243
|
-
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
this.getDevice = function () {
|
|
247
|
-
|
|
248
|
-
return device;
|
|
249
|
-
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
this.setDevice = function ( value ) {
|
|
253
|
-
|
|
254
|
-
if ( value !== undefined ) device = value;
|
|
255
|
-
|
|
256
|
-
animation.setContext( value );
|
|
257
|
-
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
this.setFramebufferScaleFactor = function ( value ) {
|
|
261
|
-
|
|
262
|
-
framebufferScaleFactor = value;
|
|
263
|
-
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
this.setReferenceSpaceType = function ( value ) {
|
|
267
|
-
|
|
268
|
-
referenceSpaceType = value;
|
|
269
|
-
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
this.setPoseTarget = function ( object ) {
|
|
273
|
-
|
|
274
|
-
if ( object !== undefined ) poseTarget = object;
|
|
275
|
-
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
//
|
|
279
|
-
|
|
280
|
-
this.cameraAutoUpdate = true;
|
|
281
|
-
|
|
282
|
-
this.updateCamera = function ( camera ) {
|
|
283
|
-
|
|
284
|
-
var userHeight = referenceSpaceType === 'local-floor' ? 1.6 : 0;
|
|
285
|
-
|
|
286
|
-
device.depthNear = camera.near;
|
|
287
|
-
device.depthFar = camera.far;
|
|
288
|
-
|
|
289
|
-
device.getFrameData( frameData );
|
|
290
|
-
|
|
291
|
-
//
|
|
292
|
-
|
|
293
|
-
if ( referenceSpaceType === 'local-floor' ) {
|
|
294
|
-
|
|
295
|
-
var stageParameters = device.stageParameters;
|
|
296
|
-
|
|
297
|
-
if ( stageParameters ) {
|
|
298
|
-
|
|
299
|
-
standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
|
|
300
|
-
|
|
301
|
-
} else {
|
|
302
|
-
|
|
303
|
-
standingMatrix.makeTranslation( 0, userHeight, 0 );
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
var pose = frameData.pose;
|
|
311
|
-
var poseObject = poseTarget !== null ? poseTarget : camera;
|
|
312
|
-
|
|
313
|
-
// We want to manipulate poseObject by its position and quaternion components since users may rely on them.
|
|
314
|
-
poseObject.matrix.copy( standingMatrix );
|
|
315
|
-
poseObject.matrix.decompose( poseObject.position, poseObject.quaternion, poseObject.scale );
|
|
316
|
-
|
|
317
|
-
if ( pose.orientation !== null ) {
|
|
318
|
-
|
|
319
|
-
tempQuaternion.fromArray( pose.orientation );
|
|
320
|
-
poseObject.quaternion.multiply( tempQuaternion );
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
if ( pose.position !== null ) {
|
|
325
|
-
|
|
326
|
-
tempQuaternion.setFromRotationMatrix( standingMatrix );
|
|
327
|
-
tempPosition.fromArray( pose.position );
|
|
328
|
-
tempPosition.applyQuaternion( tempQuaternion );
|
|
329
|
-
poseObject.position.add( tempPosition );
|
|
330
|
-
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
poseObject.updateMatrixWorld();
|
|
334
|
-
|
|
335
|
-
var children = poseObject.children;
|
|
336
|
-
for ( var i = 0, l = children.length; i < l; i ++ ) {
|
|
337
|
-
|
|
338
|
-
children[ i ].updateMatrixWorld( true );
|
|
339
|
-
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
//
|
|
343
|
-
|
|
344
|
-
cameraL.near = camera.near;
|
|
345
|
-
cameraR.near = camera.near;
|
|
346
|
-
|
|
347
|
-
cameraL.far = camera.far;
|
|
348
|
-
cameraR.far = camera.far;
|
|
349
|
-
|
|
350
|
-
cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
|
|
351
|
-
cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
|
|
352
|
-
|
|
353
|
-
// TODO (mrdoob) Double check this code
|
|
354
|
-
|
|
355
|
-
standingMatrixInverse.copy( standingMatrix ).invert();
|
|
356
|
-
|
|
357
|
-
if ( referenceSpaceType === 'local-floor' ) {
|
|
358
|
-
|
|
359
|
-
cameraL.matrixWorldInverse.multiply( standingMatrixInverse );
|
|
360
|
-
cameraR.matrixWorldInverse.multiply( standingMatrixInverse );
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
var parent = poseObject.parent;
|
|
365
|
-
|
|
366
|
-
if ( parent !== null ) {
|
|
367
|
-
|
|
368
|
-
matrixWorldInverse.copy( parent.matrixWorld ).invert();
|
|
369
|
-
|
|
370
|
-
cameraL.matrixWorldInverse.multiply( matrixWorldInverse );
|
|
371
|
-
cameraR.matrixWorldInverse.multiply( matrixWorldInverse );
|
|
372
|
-
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
// envMap and Mirror needs camera.matrixWorld
|
|
376
|
-
|
|
377
|
-
cameraL.matrixWorld.copy( cameraL.matrixWorldInverse ).invert();
|
|
378
|
-
cameraR.matrixWorld.copy( cameraR.matrixWorldInverse ).invert();
|
|
379
|
-
|
|
380
|
-
cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
|
|
381
|
-
cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
|
|
382
|
-
|
|
383
|
-
setProjectionFromUnion( cameraVR, cameraL, cameraR );
|
|
384
|
-
|
|
385
|
-
//
|
|
386
|
-
|
|
387
|
-
var layers = device.getLayers();
|
|
388
|
-
|
|
389
|
-
if ( layers.length ) {
|
|
390
|
-
|
|
391
|
-
var layer = layers[ 0 ];
|
|
392
|
-
|
|
393
|
-
updateViewportFromBounds( cameraL.viewport, layer.leftBounds );
|
|
394
|
-
updateViewportFromBounds( cameraR.viewport, layer.rightBounds );
|
|
395
|
-
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
updateControllers();
|
|
399
|
-
|
|
400
|
-
return cameraVR;
|
|
401
|
-
|
|
402
|
-
};
|
|
403
|
-
|
|
404
|
-
this.getCamera = function () {
|
|
405
|
-
|
|
406
|
-
return cameraVR;
|
|
407
|
-
|
|
408
|
-
};
|
|
409
|
-
|
|
410
|
-
// Dummy getFoveation/setFoveation to have the same API as WebXR
|
|
411
|
-
|
|
412
|
-
this.getFoveation = function () {
|
|
413
|
-
|
|
414
|
-
return 1;
|
|
415
|
-
|
|
416
|
-
};
|
|
417
|
-
|
|
418
|
-
this.setFoveation = function ( foveation ) {
|
|
419
|
-
|
|
420
|
-
if ( foveation !== 1 ) {
|
|
421
|
-
|
|
422
|
-
console.warn( 'THREE.WebVRManager: setFoveation() not used in WebVR.' );
|
|
423
|
-
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
};
|
|
427
|
-
|
|
428
|
-
// Dummy getEnvironmentBlendMode to have the same API as WebXR
|
|
429
|
-
|
|
430
|
-
this.getEnvironmentBlendMode = function () {
|
|
431
|
-
|
|
432
|
-
if ( scope.isPresenting ) {
|
|
433
|
-
|
|
434
|
-
return 'opaque';
|
|
435
|
-
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
};
|
|
439
|
-
|
|
440
|
-
//
|
|
441
|
-
|
|
442
|
-
this.getStandingMatrix = function () {
|
|
443
|
-
|
|
444
|
-
return standingMatrix;
|
|
445
|
-
|
|
446
|
-
};
|
|
447
|
-
|
|
448
|
-
this.isPresenting = false;
|
|
449
|
-
|
|
450
|
-
// Animation Loop
|
|
451
|
-
|
|
452
|
-
var animation = new WebGLAnimation();
|
|
453
|
-
|
|
454
|
-
this.setAnimationLoop = function ( callback ) {
|
|
455
|
-
|
|
456
|
-
animation.setAnimationLoop( callback );
|
|
457
|
-
|
|
458
|
-
if ( this.isPresenting ) animation.start();
|
|
459
|
-
|
|
460
|
-
};
|
|
461
|
-
|
|
462
|
-
this.submitFrame = function () {
|
|
463
|
-
|
|
464
|
-
if ( this.isPresenting ) device.submitFrame();
|
|
465
|
-
|
|
466
|
-
};
|
|
467
|
-
|
|
468
|
-
this.dispose = function () {
|
|
469
|
-
|
|
470
|
-
if ( typeof window !== 'undefined' ) {
|
|
471
|
-
|
|
472
|
-
window.removeEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange );
|
|
473
|
-
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
};
|
|
477
|
-
|
|
478
|
-
// DEPRECATED
|
|
479
|
-
|
|
480
|
-
this.setFrameOfReferenceType = function () {
|
|
481
|
-
|
|
482
|
-
console.warn( 'THREE.WebVRManager: setFrameOfReferenceType() has been deprecated.' );
|
|
483
|
-
|
|
484
|
-
};
|
|
485
|
-
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
Object.assign( WebVRManager.prototype, {
|
|
489
|
-
addEventListener: EventDispatcher.prototype.addEventListener,
|
|
490
|
-
hasEventListener: EventDispatcher.prototype.hasEventListener,
|
|
491
|
-
removeEventListener: EventDispatcher.prototype.removeEventListener,
|
|
492
|
-
dispatchEvent: EventDispatcher.prototype.dispatchEvent
|
|
493
|
-
} );
|
|
494
|
-
|
|
495
|
-
export { WebVRManager };
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author jsantell / https://www.jsantell.com/
|
|
3
|
-
* @author mrdoob / http://mrdoob.com/
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { Vector3 } from '../../math/Vector3.js';
|
|
7
|
-
|
|
8
|
-
var cameraLPos = new Vector3();
|
|
9
|
-
var cameraRPos = new Vector3();
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Assumes 2 cameras that are parallel and share an X-axis, and that
|
|
13
|
-
* the cameras' projection and world matrices have already been set.
|
|
14
|
-
* And that near and far planes are identical for both cameras.
|
|
15
|
-
* Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
|
|
16
|
-
*/
|
|
17
|
-
function setProjectionFromUnion( camera, cameraL, cameraR ) {
|
|
18
|
-
|
|
19
|
-
cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
|
|
20
|
-
cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
|
|
21
|
-
|
|
22
|
-
var ipd = cameraLPos.distanceTo( cameraRPos );
|
|
23
|
-
|
|
24
|
-
var projL = cameraL.projectionMatrix.elements;
|
|
25
|
-
var projR = cameraR.projectionMatrix.elements;
|
|
26
|
-
|
|
27
|
-
// VR systems will have identical far and near planes, and
|
|
28
|
-
// most likely identical top and bottom frustum extents.
|
|
29
|
-
// Use the left camera for these values.
|
|
30
|
-
var near = projL[ 14 ] / ( projL[ 10 ] - 1 );
|
|
31
|
-
var far = projL[ 14 ] / ( projL[ 10 ] + 1 );
|
|
32
|
-
var topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
|
|
33
|
-
var bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
|
|
34
|
-
|
|
35
|
-
var leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
|
|
36
|
-
var rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
|
|
37
|
-
var left = near * leftFov;
|
|
38
|
-
var right = near * rightFov;
|
|
39
|
-
|
|
40
|
-
// Calculate the new camera's position offset from the
|
|
41
|
-
// left camera. xOffset should be roughly half `ipd`.
|
|
42
|
-
var zOffset = ipd / ( - leftFov + rightFov );
|
|
43
|
-
var xOffset = zOffset * - leftFov;
|
|
44
|
-
|
|
45
|
-
// TODO: Better way to apply this offset?
|
|
46
|
-
cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
|
|
47
|
-
camera.translateX( xOffset );
|
|
48
|
-
camera.translateZ( zOffset );
|
|
49
|
-
camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale );
|
|
50
|
-
camera.matrixWorldInverse.copy( camera.matrixWorld ).invert();
|
|
51
|
-
|
|
52
|
-
// Find the union of the frustum values of the cameras and scale
|
|
53
|
-
// the values so that the near plane's position does not change in world space,
|
|
54
|
-
// although must now be relative to the new union camera.
|
|
55
|
-
var near2 = near + zOffset;
|
|
56
|
-
var far2 = far + zOffset;
|
|
57
|
-
var left2 = left - xOffset;
|
|
58
|
-
var right2 = right + ( ipd - xOffset );
|
|
59
|
-
var top2 = topFov * far / far2 * near2;
|
|
60
|
-
var bottom2 = bottomFov * far / far2 * near2;
|
|
61
|
-
|
|
62
|
-
camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export { setProjectionFromUnion };
|