@needle-tools/three 0.146.4 → 0.146.6

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.
@@ -12986,9 +12986,9 @@ var logdepthbuf_pars_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_
12986
12986
 
12987
12987
  var logdepthbuf_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvFragDepth = 1.0 + gl_Position.w;\n\t\tvIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n\t#else\n\t\tif ( isPerspectiveMatrix( projectionMatrix ) ) {\n\t\t\tgl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;\n\t\t\tgl_Position.z *= gl_Position.w;\n\t\t}\n\t#endif\n#endif";
12988
12988
 
12989
- var map_fragment = "#ifdef USE_MAP\n\tvec4 sampledDiffuseColor = texture2D( map, vUv );\n\t#ifdef DECODE_VIDEO_TEXTURE\n\t\tsampledDiffuseColor = vec4( mix( pow( sampledDiffuseColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), sampledDiffuseColor.rgb * 0.0773993808, vec3( lessThanEqual( sampledDiffuseColor.rgb, vec3( 0.04045 ) ) ) ), sampledDiffuseColor.w );\n\t#endif\n\tdiffuseColor *= sampledDiffuseColor;\n#endif";
12989
+ var map_fragment = "#ifdef USE_MAP\n#ifdef USE_MIPMAP_BIAS\n vec4 sampledDiffuseColor = texture2D( map, vUv, mipmapBias );\n#else\n\t\tvec4 sampledDiffuseColor = texture2D( map, vUv, -0.5 );\n#endif\n\t#ifdef DECODE_VIDEO_TEXTURE\n\t\tsampledDiffuseColor = vec4( mix( pow( sampledDiffuseColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), sampledDiffuseColor.rgb * 0.0773993808, vec3( lessThanEqual( sampledDiffuseColor.rgb, vec3( 0.04045 ) ) ) ), sampledDiffuseColor.w );\n\t#endif\n\tdiffuseColor *= sampledDiffuseColor;\n#endif";
12990
12990
 
12991
- var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
12991
+ var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n \n#ifdef USE_MIPMAP_BIAS\n uniform float mipmapBias;\n#endif\n#endif";
12992
12992
 
12993
12993
  var map_particle_fragment = "#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n#endif\n#ifdef USE_MAP\n\tdiffuseColor *= texture2D( map, uv );\n#endif\n#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, uv ).g;\n#endif";
12994
12994
 
@@ -25571,6 +25571,7 @@ class WebXRManager extends EventDispatcher {
25571
25571
  const bottom2 = bottomFov * far / far2 * near2;
25572
25572
 
25573
25573
  camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
25574
+ camera.projectionMatrixInverse.copy( camera.projectionMatrix ).invert();
25574
25575
 
25575
25576
  }
25576
25577
 
@@ -25622,12 +25623,42 @@ class WebXRManager extends EventDispatcher {
25622
25623
 
25623
25624
  }
25624
25625
 
25625
- cameraVR.matrixWorld.decompose( cameraVR.position, cameraVR.quaternion, cameraVR.scale );
25626
+ // update projection matrix for proper view frustum culling
25627
+
25628
+ if ( cameras.length === 2 ) {
25629
+
25630
+ setProjectionFromUnion( cameraVR, cameraL, cameraR );
25631
+
25632
+ } else {
25633
+
25634
+ // assume single camera setup (AR)
25635
+
25636
+ cameraVR.projectionMatrix.copy( cameraL.projectionMatrix );
25637
+
25638
+ }
25626
25639
 
25627
25640
  // update user camera and its children
25628
25641
 
25629
- camera.matrix.copy( cameraVR.matrix );
25642
+ updateUserCamera( camera, cameraVR, parent );
25643
+
25644
+ };
25645
+
25646
+ function updateUserCamera( camera, cameraVR, parent ) {
25647
+
25648
+ if ( parent === null ) {
25649
+
25650
+ camera.matrix.copy( cameraVR.matrixWorld );
25651
+
25652
+ } else {
25653
+
25654
+ camera.matrix.copy( parent.matrixWorld );
25655
+ camera.matrix.invert();
25656
+ camera.matrix.multiply( cameraVR.matrixWorld );
25657
+
25658
+ }
25659
+
25630
25660
  camera.matrix.decompose( camera.position, camera.quaternion, camera.scale );
25661
+ camera.updateMatrixWorld( true );
25631
25662
 
25632
25663
  const children = camera.children;
25633
25664
 
@@ -25637,21 +25668,17 @@ class WebXRManager extends EventDispatcher {
25637
25668
 
25638
25669
  }
25639
25670
 
25640
- // update projection matrix for proper view frustum culling
25641
-
25642
- if ( cameras.length === 2 ) {
25671
+ camera.projectionMatrix.copy( cameraVR.projectionMatrix );
25672
+ camera.projectionMatrixInverse.copy( cameraVR.projectionMatrixInverse );
25643
25673
 
25644
- setProjectionFromUnion( cameraVR, cameraL, cameraR );
25674
+ if ( camera.isPerspectiveCamera ) {
25645
25675
 
25646
- } else {
25647
-
25648
- // assume single camera setup (AR)
25649
-
25650
- cameraVR.projectionMatrix.copy( cameraL.projectionMatrix );
25676
+ camera.fov = RAD2DEG * 2 * Math.atan( 1 / camera.projectionMatrix.elements[ 5 ] );
25677
+ camera.zoom = 1;
25651
25678
 
25652
25679
  }
25653
25680
 
25654
- };
25681
+ }
25655
25682
 
25656
25683
  this.getCamera = function () {
25657
25684
 
@@ -25774,12 +25801,15 @@ class WebXRManager extends EventDispatcher {
25774
25801
  }
25775
25802
 
25776
25803
  camera.matrix.fromArray( view.transform.matrix );
25804
+ camera.matrix.decompose( camera.position, camera.quaternion, camera.scale );
25777
25805
  camera.projectionMatrix.fromArray( view.projectionMatrix );
25806
+ camera.projectionMatrixInverse.copy( camera.projectionMatrix ).invert();
25778
25807
  camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
25779
25808
 
25780
25809
  if ( i === 0 ) {
25781
25810
 
25782
25811
  cameraVR.matrix.copy( camera.matrix );
25812
+ cameraVR.matrix.decompose( cameraVR.position, cameraVR.quaternion, cameraVR.scale );
25783
25813
 
25784
25814
  }
25785
25815
 
@@ -5,7 +5,8 @@ import {
5
5
  Spherical,
6
6
  TOUCH,
7
7
  Vector2,
8
- Vector3
8
+ Vector3,
9
+ MathUtils
9
10
  } from 'three';
10
11
 
11
12
  // This set of controls performs orbiting, dollying (zooming), and panning.
@@ -222,7 +223,9 @@ class OrbitControls extends EventDispatcher {
222
223
  spherical.makeSafe();
223
224
 
224
225
 
225
- spherical.radius *= scale;
226
+ currentScale = MathUtils.lerp(currentScale, scale, scope.dampingFactor);
227
+
228
+ spherical.radius *= currentScale;
226
229
 
227
230
  // restrict radius to be between desired limits
228
231
  spherical.radius = Math.max( scope.minDistance, Math.min( scope.maxDistance, spherical.radius ) );
@@ -338,6 +341,7 @@ class OrbitControls extends EventDispatcher {
338
341
  const sphericalDelta = new Spherical();
339
342
 
340
343
  let scale = 1;
344
+ let currentScale = 1;
341
345
  const panOffset = new Vector3();
342
346
  let zoomChanged = false;
343
347
 
@@ -375,8 +375,6 @@ class USDZExporter {
375
375
 
376
376
  context.output += buildMaterials( materials, textures );
377
377
 
378
- invokeAll( context, 'onAfterHierarchy' );
379
-
380
378
  const header = context.document.buildHeader();
381
379
  const final = header + '\n' + context.output;
382
380
 
@@ -393,7 +391,6 @@ class USDZExporter {
393
391
  for ( const id in textures ) {
394
392
 
395
393
  let texture = textures[ id ];
396
- const color = id.split( '_' )[ 1 ];
397
394
  const isRGBA = texture.format === 1023;
398
395
  if ( texture.isCompressedTexture ) {
399
396
 
@@ -401,10 +398,20 @@ class USDZExporter {
401
398
 
402
399
  }
403
400
 
401
+ // TODO add readback options for textures that don't have texture.image
404
402
  const canvas = await imageToCanvas( texture.image );
405
- const blob = await new Promise( resolve => canvas.toBlob( resolve, isRGBA ? 'image/png' : 'image/jpeg', 1 ) );
406
403
 
407
- files[ `textures/Texture_${id}.${isRGBA ? 'png' : 'jpg'}` ] = new Uint8Array( await blob.arrayBuffer() );
404
+ if ( canvas ) {
405
+
406
+ const blob = await new Promise( resolve => canvas.toBlob( resolve, isRGBA ? 'image/png' : 'image/jpeg', 1 ) );
407
+ files[ `textures/Texture_${id}.${isRGBA ? 'png' : 'jpg'}` ] = new Uint8Array( await blob.arrayBuffer() );
408
+
409
+ }
410
+ else {
411
+
412
+ console.warn( 'Can`t export texture: ', texture );
413
+
414
+ }
408
415
 
409
416
  }
410
417
 
@@ -542,6 +549,8 @@ function parseDocument( context ) {
542
549
 
543
550
  }
544
551
 
552
+ invokeAll( context, 'onAfterHierarchy', writer );
553
+
545
554
  writer.closeBlock();
546
555
  writer.closeBlock();
547
556
  writer.closeBlock();
@@ -590,14 +599,14 @@ function addResources( object, context ) {
590
599
 
591
600
  }
592
601
 
593
- function invokeAll( context, name ) {
602
+ function invokeAll( context, name, writer = null ) {
594
603
 
595
604
  if ( context.extensions ) {
596
605
 
597
606
  for ( const ext of context.extensions ) {
598
607
 
599
608
  if ( typeof ext[ name ] === 'function' )
600
- ext[ name ]( context );
609
+ ext[ name ]( context, writer );
601
610
 
602
611
  }
603
612
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/three",
3
- "version": "0.146.4",
3
+ "version": "0.146.6",
4
4
  "description": "JavaScript 3D library",
5
5
  "type": "module",
6
6
  "main": "./build/three.js",
@@ -1,7 +1,11 @@
1
1
  export default /* glsl */`
2
2
  #ifdef USE_MAP
3
3
 
4
- vec4 sampledDiffuseColor = texture2D( map, vUv );
4
+ #ifdef USE_MIPMAP_BIAS
5
+ vec4 sampledDiffuseColor = texture2D( map, vUv, mipmapBias );
6
+ #else
7
+ vec4 sampledDiffuseColor = texture2D( map, vUv, -0.5 );
8
+ #endif
5
9
 
6
10
  #ifdef DECODE_VIDEO_TEXTURE
7
11
 
@@ -2,6 +2,10 @@ export default /* glsl */`
2
2
  #ifdef USE_MAP
3
3
 
4
4
  uniform sampler2D map;
5
+
6
+ #ifdef USE_MIPMAP_BIAS
7
+ uniform float mipmapBias;
8
+ #endif
5
9
 
6
10
  #endif
7
11
  `;
@@ -3,6 +3,7 @@ import { EventDispatcher } from '../../core/EventDispatcher.js';
3
3
  import { PerspectiveCamera } from '../../cameras/PerspectiveCamera.js';
4
4
  import { Vector3 } from '../../math/Vector3.js';
5
5
  import { Vector4 } from '../../math/Vector4.js';
6
+ import { RAD2DEG } from '../../math/MathUtils.js';
6
7
  import { WebGLAnimation } from '../webgl/WebGLAnimation.js';
7
8
  import { WebGLRenderTarget } from '../WebGLRenderTarget.js';
8
9
  import { WebXRController } from './WebXRController.js';
@@ -492,6 +493,7 @@ class WebXRManager extends EventDispatcher {
492
493
  const bottom2 = bottomFov * far / far2 * near2;
493
494
 
494
495
  camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
496
+ camera.projectionMatrixInverse.copy( camera.projectionMatrix ).invert();
495
497
 
496
498
  }
497
499
 
@@ -543,12 +545,42 @@ class WebXRManager extends EventDispatcher {
543
545
 
544
546
  }
545
547
 
546
- cameraVR.matrixWorld.decompose( cameraVR.position, cameraVR.quaternion, cameraVR.scale );
548
+ // update projection matrix for proper view frustum culling
549
+
550
+ if ( cameras.length === 2 ) {
551
+
552
+ setProjectionFromUnion( cameraVR, cameraL, cameraR );
553
+
554
+ } else {
555
+
556
+ // assume single camera setup (AR)
557
+
558
+ cameraVR.projectionMatrix.copy( cameraL.projectionMatrix );
559
+
560
+ }
547
561
 
548
562
  // update user camera and its children
549
563
 
550
- camera.matrix.copy( cameraVR.matrix );
564
+ updateUserCamera( camera, cameraVR, parent );
565
+
566
+ };
567
+
568
+ function updateUserCamera( camera, cameraVR, parent ) {
569
+
570
+ if ( parent === null ) {
571
+
572
+ camera.matrix.copy( cameraVR.matrixWorld );
573
+
574
+ } else {
575
+
576
+ camera.matrix.copy( parent.matrixWorld );
577
+ camera.matrix.invert();
578
+ camera.matrix.multiply( cameraVR.matrixWorld );
579
+
580
+ }
581
+
551
582
  camera.matrix.decompose( camera.position, camera.quaternion, camera.scale );
583
+ camera.updateMatrixWorld( true );
552
584
 
553
585
  const children = camera.children;
554
586
 
@@ -558,21 +590,17 @@ class WebXRManager extends EventDispatcher {
558
590
 
559
591
  }
560
592
 
561
- // update projection matrix for proper view frustum culling
562
-
563
- if ( cameras.length === 2 ) {
593
+ camera.projectionMatrix.copy( cameraVR.projectionMatrix );
594
+ camera.projectionMatrixInverse.copy( cameraVR.projectionMatrixInverse );
564
595
 
565
- setProjectionFromUnion( cameraVR, cameraL, cameraR );
596
+ if ( camera.isPerspectiveCamera ) {
566
597
 
567
- } else {
568
-
569
- // assume single camera setup (AR)
570
-
571
- cameraVR.projectionMatrix.copy( cameraL.projectionMatrix );
598
+ camera.fov = RAD2DEG * 2 * Math.atan( 1 / camera.projectionMatrix.elements[ 5 ] );
599
+ camera.zoom = 1;
572
600
 
573
601
  }
574
602
 
575
- };
603
+ }
576
604
 
577
605
  this.getCamera = function () {
578
606
 
@@ -695,12 +723,15 @@ class WebXRManager extends EventDispatcher {
695
723
  }
696
724
 
697
725
  camera.matrix.fromArray( view.transform.matrix );
726
+ camera.matrix.decompose( camera.position, camera.quaternion, camera.scale );
698
727
  camera.projectionMatrix.fromArray( view.projectionMatrix );
728
+ camera.projectionMatrixInverse.copy( camera.projectionMatrix ).invert();
699
729
  camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
700
730
 
701
731
  if ( i === 0 ) {
702
732
 
703
733
  cameraVR.matrix.copy( camera.matrix );
734
+ cameraVR.matrix.decompose( cameraVR.position, cameraVR.quaternion, cameraVR.scale );
704
735
 
705
736
  }
706
737