super-three 0.169.0 → 0.170.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.
Files changed (195) hide show
  1. package/build/three.cjs +989 -1131
  2. package/build/three.module.js +990 -1128
  3. package/build/three.module.min.js +1 -1
  4. package/build/three.webgpu.js +8398 -9842
  5. package/build/three.webgpu.min.js +1 -1
  6. package/build/three.webgpu.nodes.js +8398 -9842
  7. package/build/three.webgpu.nodes.min.js +1 -1
  8. package/examples/jsm/Addons.js +3 -3
  9. package/examples/jsm/animation/MMDAnimationHelper.js +2 -0
  10. package/examples/jsm/animation/MMDPhysics.js +2 -0
  11. package/examples/jsm/controls/TransformControls.js +22 -6
  12. package/examples/jsm/csm/CSM.js +2 -2
  13. package/examples/jsm/csm/CSMFrustum.js +7 -4
  14. package/examples/jsm/csm/CSMHelper.js +2 -0
  15. package/examples/jsm/csm/CSMShadowNode.js +435 -0
  16. package/examples/jsm/curves/NURBSCurve.js +34 -3
  17. package/examples/jsm/exporters/GLTFExporter.js +138 -71
  18. package/examples/jsm/exporters/KTX2Exporter.js +35 -12
  19. package/examples/jsm/exporters/MMDExporter.js +6 -0
  20. package/examples/jsm/exporters/USDZExporter.js +21 -3
  21. package/examples/jsm/geometries/DecalGeometry.js +65 -20
  22. package/examples/jsm/geometries/InstancedPointsGeometry.js +2 -0
  23. package/examples/jsm/helpers/TextureHelperGPU.js +175 -0
  24. package/examples/jsm/interactive/HTMLMesh.js +1 -0
  25. package/examples/jsm/lighting/TiledLighting.js +18 -0
  26. package/examples/jsm/lights/RectAreaLightTexturesLib.js +1 -1
  27. package/examples/jsm/lines/LineMaterial.js +7 -2
  28. package/examples/jsm/lines/LineSegmentsGeometry.js +2 -0
  29. package/examples/jsm/lines/webgpu/LineSegments2.js +0 -15
  30. package/examples/jsm/lines/webgpu/Wireframe.js +56 -0
  31. package/examples/jsm/loaders/3DMLoader.js +1 -0
  32. package/examples/jsm/loaders/3MFLoader.js +91 -0
  33. package/examples/jsm/loaders/FBXLoader.js +12 -2
  34. package/examples/jsm/loaders/GLTFLoader.js +2 -0
  35. package/examples/jsm/loaders/KTX2Loader.js +140 -49
  36. package/examples/jsm/loaders/LDrawLoader.js +22 -136
  37. package/examples/jsm/loaders/LottieLoader.js +1 -0
  38. package/examples/jsm/loaders/MMDLoader.js +9 -2
  39. package/examples/jsm/materials/LDrawConditionalLineMaterial.js +143 -0
  40. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +114 -0
  41. package/examples/jsm/materials/MeshGouraudMaterial.js +6 -2
  42. package/examples/jsm/math/ColorSpaces.js +76 -0
  43. package/examples/jsm/misc/ProgressiveLightMap.js +52 -40
  44. package/examples/jsm/misc/ProgressiveLightMapGPU.js +293 -0
  45. package/examples/jsm/misc/VolumeSlice.js +1 -0
  46. package/examples/jsm/objects/WaterMesh.js +8 -8
  47. package/examples/jsm/postprocessing/AfterimagePass.js +14 -3
  48. package/examples/jsm/postprocessing/SSRPass.js +6 -0
  49. package/examples/jsm/renderers/CSS2DRenderer.js +6 -3
  50. package/examples/jsm/renderers/CSS3DRenderer.js +7 -4
  51. package/examples/jsm/shaders/FXAAShader.js +225 -224
  52. package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
  53. package/{src/nodes → examples/jsm/tsl}/display/AfterImageNode.js +17 -20
  54. package/{src/nodes → examples/jsm/tsl}/display/AnaglyphPassNode.js +2 -6
  55. package/{src/nodes → examples/jsm/tsl}/display/AnamorphicNode.js +12 -18
  56. package/{src/nodes → examples/jsm/tsl}/display/BleachBypass.js +1 -3
  57. package/{src/nodes → examples/jsm/tsl}/display/BloomNode.js +11 -40
  58. package/{src/nodes → examples/jsm/tsl}/display/DenoiseNode.js +18 -41
  59. package/{src/nodes → examples/jsm/tsl}/display/DepthOfFieldNode.js +2 -8
  60. package/{src/nodes → examples/jsm/tsl}/display/DotScreenNode.js +2 -9
  61. package/examples/jsm/tsl/display/FXAANode.js +316 -0
  62. package/{src/nodes → examples/jsm/tsl}/display/FilmNode.js +2 -6
  63. package/{src/nodes → examples/jsm/tsl}/display/GTAONode.js +30 -70
  64. package/{src/nodes → examples/jsm/tsl}/display/GaussianBlurNode.js +74 -36
  65. package/examples/jsm/tsl/display/LensflareNode.js +161 -0
  66. package/{src/nodes → examples/jsm/tsl}/display/Lut3DNode.js +1 -4
  67. package/{src/nodes → examples/jsm/tsl}/display/MotionBlur.js +2 -3
  68. package/examples/jsm/tsl/display/OutlineNode.js +434 -0
  69. package/{src/nodes → examples/jsm/tsl}/display/ParallaxBarrierPassNode.js +1 -5
  70. package/{src/nodes → examples/jsm/tsl}/display/PixelationPassNode.js +3 -15
  71. package/{src/nodes → examples/jsm/tsl}/display/RGBShiftNode.js +1 -6
  72. package/examples/jsm/tsl/display/SMAANode.js +620 -0
  73. package/{src/nodes → examples/jsm/tsl}/display/SSAAPassNode.js +10 -25
  74. package/examples/jsm/tsl/display/SSRNode.js +343 -0
  75. package/{src/nodes → examples/jsm/tsl}/display/Sepia.js +1 -2
  76. package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +3 -11
  77. package/{src/nodes → examples/jsm/tsl}/display/StereoCompositePassNode.js +9 -11
  78. package/{src/nodes → examples/jsm/tsl}/display/StereoPassNode.js +10 -11
  79. package/examples/jsm/tsl/display/TRAAPassNode.js +355 -0
  80. package/{src/nodes → examples/jsm/tsl}/display/TransitionNode.js +1 -6
  81. package/examples/jsm/tsl/display/hashBlur.js +24 -0
  82. package/examples/jsm/tsl/lighting/TiledLightsNode.js +392 -0
  83. package/examples/jsm/utils/{TextureUtilsGPU.js → WebGPUTextureUtils.js} +2 -1
  84. package/examples/jsm/webxr/OculusHandPointerModel.js +21 -21
  85. package/examples/jsm/webxr/Text2D.js +6 -6
  86. package/package.json +2 -2
  87. package/src/Three.WebGPU.Nodes.js +4 -0
  88. package/src/Three.WebGPU.js +4 -0
  89. package/src/constants.js +1 -6
  90. package/src/core/BufferGeometry.js +44 -6
  91. package/src/geometries/CylinderGeometry.js +2 -2
  92. package/src/materials/LineBasicMaterial.js +6 -2
  93. package/src/materials/LineDashedMaterial.js +6 -2
  94. package/src/materials/Material.js +14 -1
  95. package/src/materials/MeshBasicMaterial.js +6 -2
  96. package/src/materials/MeshDepthMaterial.js +6 -2
  97. package/src/materials/MeshDistanceMaterial.js +6 -2
  98. package/src/materials/MeshLambertMaterial.js +6 -2
  99. package/src/materials/MeshMatcapMaterial.js +6 -2
  100. package/src/materials/MeshNormalMaterial.js +6 -2
  101. package/src/materials/MeshPhongMaterial.js +6 -2
  102. package/src/materials/MeshPhysicalMaterial.js +6 -2
  103. package/src/materials/MeshStandardMaterial.js +6 -2
  104. package/src/materials/MeshToonMaterial.js +6 -2
  105. package/src/materials/PointsMaterial.js +6 -2
  106. package/src/materials/RawShaderMaterial.js +6 -2
  107. package/src/materials/ShaderMaterial.js +6 -2
  108. package/src/materials/ShadowMaterial.js +6 -2
  109. package/src/materials/SpriteMaterial.js +6 -2
  110. package/src/materials/nodes/NodeMaterial.js +31 -9
  111. package/src/materials/nodes/SpriteNodeMaterial.js +11 -2
  112. package/src/materials/nodes/manager/NodeMaterialObserver.js +111 -2
  113. package/src/math/ColorManagement.js +118 -85
  114. package/src/math/Vector4.js +11 -0
  115. package/src/nodes/Nodes.js +1 -21
  116. package/src/nodes/TSL.js +6 -24
  117. package/src/nodes/accessors/Camera.js +0 -1
  118. package/src/nodes/accessors/SceneNode.js +35 -1
  119. package/src/nodes/accessors/StorageBufferNode.js +32 -10
  120. package/src/nodes/accessors/VelocityNode.js +13 -3
  121. package/src/nodes/code/FunctionCallNode.js +16 -5
  122. package/src/nodes/code/ScriptableNode.js +4 -4
  123. package/src/nodes/core/Node.js +1 -0
  124. package/src/nodes/core/NodeBuilder.js +29 -5
  125. package/src/nodes/core/VarNode.js +15 -3
  126. package/src/nodes/display/ColorAdjustment.js +53 -4
  127. package/src/nodes/display/ColorSpaceFunctions.js +5 -5
  128. package/src/nodes/display/ColorSpaceNode.js +27 -39
  129. package/src/nodes/display/PassNode.js +6 -4
  130. package/src/nodes/display/ToneMappingNode.js +1 -1
  131. package/src/nodes/display/ViewportDepthNode.js +33 -1
  132. package/src/nodes/functions/PhysicalLightingModel.js +21 -15
  133. package/src/nodes/functions/material/getAlphaHashThreshold.js +64 -0
  134. package/src/nodes/functions/material/getGeometryRoughness.js +8 -2
  135. package/src/nodes/functions/material/getParallaxCorrectNormal.js +22 -0
  136. package/src/nodes/gpgpu/ComputeNode.js +9 -1
  137. package/src/nodes/lighting/AnalyticLightNode.js +12 -416
  138. package/src/nodes/lighting/LightsNode.js +24 -12
  139. package/src/nodes/lighting/PointLightNode.js +36 -26
  140. package/src/nodes/lighting/RectAreaLightNode.js +3 -0
  141. package/src/nodes/lighting/ShadowNode.js +484 -0
  142. package/src/nodes/utils/LoopNode.js +2 -2
  143. package/src/nodes/utils/Oscillators.js +6 -0
  144. package/src/nodes/utils/PostProcessingUtils.js +89 -0
  145. package/src/nodes/utils/ReflectorNode.js +101 -15
  146. package/src/nodes/utils/Timer.js +29 -0
  147. package/src/objects/BatchedMesh.js +458 -241
  148. package/src/renderers/WebGLRenderer.js +121 -126
  149. package/src/renderers/common/Attributes.js +4 -0
  150. package/src/renderers/common/Backend.js +2 -0
  151. package/src/renderers/common/Background.js +14 -4
  152. package/src/renderers/common/Bindings.js +3 -2
  153. package/src/renderers/common/Constants.js +2 -1
  154. package/src/renderers/common/Geometries.js +20 -0
  155. package/src/renderers/common/IndirectStorageBufferAttribute.js +15 -0
  156. package/src/renderers/common/Lighting.js +45 -0
  157. package/src/renderers/common/PostProcessingUtils.js +86 -0
  158. package/src/renderers/common/RenderList.js +39 -11
  159. package/src/renderers/common/RenderLists.js +4 -2
  160. package/src/renderers/common/RenderObject.js +18 -1
  161. package/src/renderers/common/Renderer.js +165 -26
  162. package/src/renderers/common/Textures.js +30 -14
  163. package/src/renderers/common/nodes/NodeLibrary.js +1 -14
  164. package/src/renderers/common/nodes/Nodes.js +2 -2
  165. package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
  166. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
  167. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
  168. package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
  169. package/src/renderers/webgl/WebGLCapabilities.js +0 -7
  170. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
  171. package/src/renderers/webgl/WebGLProgram.js +24 -28
  172. package/src/renderers/webgl/WebGLPrograms.js +5 -2
  173. package/src/renderers/webgl/WebGLState.js +37 -1
  174. package/src/renderers/webgl/WebGLTextures.js +29 -12
  175. package/src/renderers/webgl-fallback/WebGLBackend.js +98 -31
  176. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +2 -7
  177. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +33 -8
  178. package/src/renderers/webgpu/WebGPUBackend.js +105 -25
  179. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +1 -1
  180. package/src/renderers/webgpu/WebGPURenderer.js +1 -1
  181. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +0 -8
  182. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +0 -8
  183. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +10 -20
  184. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +12 -4
  185. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +29 -9
  186. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +24 -6
  187. package/src/renderers/webgpu/utils/WebGPUUtils.js +0 -1
  188. package/src/renderers/webxr/WebXRManager.js +4 -4
  189. package/examples/jsm/cameras/CinematicCamera.js +0 -208
  190. package/src/nodes/display/FXAANode.js +0 -332
  191. package/src/nodes/utils/OscNode.js +0 -85
  192. package/src/nodes/utils/TimerNode.js +0 -97
  193. package/src/renderers/webvr/WebVRManager.js +0 -495
  194. package/src/renderers/webvr/WebVRUtils.js +0 -66
  195. /package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +0 -0
@@ -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 };