@needle-tools/three 0.154.1 → 0.154.3

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.
@@ -4269,7 +4269,6 @@ class GLTFParser {
4269
4269
  const tracks = [];
4270
4270
 
4271
4271
  const targetName = node.name ? node.name : node.uuid;
4272
-
4273
4272
  const targetNames = [];
4274
4273
 
4275
4274
  if ( PATH_PROPERTIES[ target.path ] === PATH_PROPERTIES.weights ) {
@@ -4306,7 +4305,12 @@ class GLTFParser {
4306
4305
 
4307
4306
  case PATH_PROPERTIES.position:
4308
4307
  case PATH_PROPERTIES.scale:
4308
+
4309
+ TypedKeyframeTrack = VectorKeyframeTrack;
4310
+ break;
4311
+
4309
4312
  default:
4313
+
4310
4314
  switch ( outputAccessor.itemSize ) {
4311
4315
 
4312
4316
  case 1:
@@ -4314,6 +4318,7 @@ class GLTFParser {
4314
4318
  break;
4315
4319
  case 2:
4316
4320
  case 3:
4321
+ default:
4317
4322
  TypedKeyframeTrack = VectorKeyframeTrack;
4318
4323
  break;
4319
4324
 
@@ -4325,6 +4330,7 @@ class GLTFParser {
4325
4330
 
4326
4331
  const interpolation = sampler.interpolation !== undefined ? INTERPOLATION[ sampler.interpolation ] : InterpolateLinear;
4327
4332
 
4333
+
4328
4334
  const outputArray = this._getArrayFromAccessor( outputAccessor );
4329
4335
 
4330
4336
  for ( let j = 0, jl = targetNames.length; j < jl; j ++ ) {
@@ -4337,7 +4343,7 @@ class GLTFParser {
4337
4343
  );
4338
4344
 
4339
4345
  // Override interpolation with custom factory method.
4340
- if ( interpolation === 'CUBICSPLINE' ) {
4346
+ if ( sampler.interpolation === 'CUBICSPLINE' ) {
4341
4347
 
4342
4348
  this._createCubicSplineTrackInterpolant( track );
4343
4349
 
@@ -7,6 +7,7 @@ import {
7
7
  PropertyBinding,
8
8
  QuaternionKeyframeTrack,
9
9
  VectorKeyframeTrack,
10
+ SkinnedMesh
10
11
  } from 'three';
11
12
 
12
13
  // DUPLICATED from GLTFLoader.js
@@ -72,8 +73,8 @@ class GLTFAnimationPointerExtension {
72
73
  const uuid = nextIndex < 0 ? remainingPath : remainingPath.substring( 0, nextIndex );
73
74
  let res = null;
74
75
  node.traverse( x => {
75
-
76
- if ( res !== null || x.type !== 'Mesh' ) return;
76
+
77
+ if ( res !== null || (x.type !== 'Mesh' && x.type !== 'SkinnedMesh') ) return;
77
78
  if ( x[ 'material' ] && (x[ 'material' ].uuid === uuid || x[ 'material' ].name === uuid )) {
78
79
 
79
80
  res = x[ 'material' ];
@@ -465,89 +466,124 @@ class GLTFAnimationPointerExtension {
465
466
  animationPointerPropertyPath = animationPointerPropertyPath.replaceAll( '/', '.' );
466
467
  // replace node/material/camera/light ID by UUID
467
468
  const parts = animationPointerPropertyPath.split( '.' );
468
- parts[ 2 ] = (node.name !== undefined && node.name !== null) ? node.name : node.uuid;
469
- animationPointerPropertyPath = parts.join( '.' );
470
- if ( _animationPointerDebug )
471
- console.log( node, inputAccessor, outputAccessor, target, animationPointerPropertyPath );
472
-
473
- let TypedKeyframeTrack;
469
+ const hasName = node.name !== undefined && node.name !== null;
470
+ var nodeTargetName = hasName ? node.name : node.uuid;
471
+ parts[ 2 ] = nodeTargetName;
474
472
 
475
- switch ( outputAccessor.itemSize ) {
473
+ // specially handle the morphTargetInfluences property for multi-material meshes
474
+ // in which case the target object is a Group and the children are the actual targets
475
+ // see NE-3311
476
+ if ( parts[ 3 ] === "morphTargetInfluences" ) {
476
477
 
477
- case 1:
478
- TypedKeyframeTrack = NumberKeyframeTrack;
479
- break;
480
- case 2:
481
- case 3:
482
- TypedKeyframeTrack = VectorKeyframeTrack;
483
- break;
484
- case 4:
478
+ if( node.type === "Group" ) {
485
479
 
486
- if ( animationPointerPropertyPath.endsWith( '.quaternion' ) )
487
- TypedKeyframeTrack = QuaternionKeyframeTrack;
488
- else
489
- TypedKeyframeTrack = ColorKeyframeTrack;
480
+ if ( _animationPointerDebug )
481
+ console.log( "Detected multi-material skinnedMesh export", animationPointerPropertyPath, node );
482
+
483
+ // We assume the children are skinned meshes
484
+ for ( const ch of node.children ) {
485
+ if( ch instanceof SkinnedMesh && ch.morphTargetInfluences ) {
486
+ parts[ 3 ] = ch.name;
487
+ parts[ 4 ] = "morphTargetInfluences";
488
+ __createTrack( this.parser );
489
+ }
490
+ }
490
491
 
491
- break;
492
+ return tracks;
493
+ }
492
494
 
493
495
  }
494
496
 
495
- const interpolation = sampler.interpolation !== undefined ? INTERPOLATION[ sampler.interpolation ] : InterpolateLinear;
496
-
497
- let outputArray = this.parser._getArrayFromAccessor( outputAccessor );
497
+ // default
498
+ __createTrack(this.parser);
499
+
500
+ /** Create a new track using the current parts array */
501
+ function __createTrack( parser ) {
498
502
 
499
- // convert fov values from radians to degrees
500
- if ( animationPointerPropertyPath.endsWith( '.fov' ) ) {
501
-
502
- outputArray = outputArray.map( value => value / Math.PI * 180 );
503
+ animationPointerPropertyPath = parts.join( '.' );
503
504
 
504
- }
505
+ if ( _animationPointerDebug )
506
+ console.log( node, inputAccessor, outputAccessor, target, animationPointerPropertyPath );
505
507
 
506
- const track = new TypedKeyframeTrack(
507
- animationPointerPropertyPath,
508
- inputAccessor.array,
509
- outputArray,
510
- interpolation
511
- );
508
+ let TypedKeyframeTrack;
512
509
 
513
- // Override interpolation with custom factory method.
514
- if ( interpolation === 'CUBICSPLINE' ) {
510
+ switch ( outputAccessor.itemSize ) {
515
511
 
516
- this.parser._createCubicSplineTrackInterpolant( track );
512
+ case 1:
513
+ TypedKeyframeTrack = NumberKeyframeTrack;
514
+ break;
515
+ case 2:
516
+ case 3:
517
+ TypedKeyframeTrack = VectorKeyframeTrack;
518
+ break;
519
+ case 4:
517
520
 
518
- }
521
+ if ( animationPointerPropertyPath.endsWith( '.quaternion' ) )
522
+ TypedKeyframeTrack = QuaternionKeyframeTrack;
523
+ else
524
+ TypedKeyframeTrack = ColorKeyframeTrack;
519
525
 
520
- tracks.push( track );
526
+ break;
521
527
 
522
- // glTF has opacity animation as last component of baseColorFactor,
523
- // so we need to split that up here and create a separate opacity track if that is animated.
524
- if ( animationPointerPropertyPath && outputAccessor.itemSize === 4 &&
525
- animationPointerPropertyPath.startsWith( '.materials.' ) && animationPointerPropertyPath.endsWith( '.color' ) ) {
528
+ }
526
529
 
527
- const opacityArray = new Float32Array( outputArray.length / 4 );
530
+ const interpolation = sampler.interpolation !== undefined ? INTERPOLATION[ sampler.interpolation ] : InterpolateLinear;
528
531
 
529
- for ( let j = 0, jl = outputArray.length / 4; j < jl; j += 1 ) {
532
+ let outputArray = parser._getArrayFromAccessor( outputAccessor );
530
533
 
531
- opacityArray[ j ] = outputArray[ j * 4 + 3 ];
534
+ // convert fov values from radians to degrees
535
+ if ( animationPointerPropertyPath.endsWith( '.fov' ) ) {
536
+
537
+ outputArray = outputArray.map( value => value / Math.PI * 180 );
532
538
 
533
539
  }
534
540
 
535
- const opacityTrack = new TypedKeyframeTrack(
536
- animationPointerPropertyPath.replace( '.color', '.opacity' ),
541
+ const track = new TypedKeyframeTrack(
542
+ animationPointerPropertyPath,
537
543
  inputAccessor.array,
538
- opacityArray,
544
+ outputArray,
539
545
  interpolation
540
546
  );
541
547
 
542
548
  // Override interpolation with custom factory method.
543
549
  if ( interpolation === 'CUBICSPLINE' ) {
544
550
 
545
- this.parser._createCubicSplineTrackInterpolant( track );
551
+ parser._createCubicSplineTrackInterpolant( track );
546
552
 
547
553
  }
548
554
 
549
- tracks.push( opacityTrack );
555
+ tracks.push( track );
550
556
 
557
+ // glTF has opacity animation as last component of baseColorFactor,
558
+ // so we need to split that up here and create a separate opacity track if that is animated.
559
+ if ( animationPointerPropertyPath && outputAccessor.itemSize === 4 &&
560
+ animationPointerPropertyPath.startsWith( '.materials.' ) && animationPointerPropertyPath.endsWith( '.color' ) ) {
561
+
562
+ const opacityArray = new Float32Array( outputArray.length / 4 );
563
+
564
+ for ( let j = 0, jl = outputArray.length / 4; j < jl; j += 1 ) {
565
+
566
+ opacityArray[ j ] = outputArray[ j * 4 + 3 ];
567
+
568
+ }
569
+
570
+ const opacityTrack = new TypedKeyframeTrack(
571
+ animationPointerPropertyPath.replace( '.color', '.opacity' ),
572
+ inputAccessor.array,
573
+ opacityArray,
574
+ interpolation
575
+ );
576
+
577
+ // Override interpolation with custom factory method.
578
+ if ( interpolation === 'CUBICSPLINE' ) {
579
+
580
+ parser._createCubicSplineTrackInterpolant( track );
581
+
582
+ }
583
+
584
+ tracks.push( opacityTrack );
585
+
586
+ }
551
587
  }
552
588
 
553
589
  return tracks;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/three",
3
- "version": "0.154.1",
3
+ "version": "0.154.3",
4
4
  "description": "JavaScript 3D library",
5
5
  "type": "module",
6
6
  "main": "./build/three.js",