@needle-tools/three 0.154.2 → 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.
@@ -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
@@ -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 );
469
+ const hasName = node.name !== undefined && node.name !== null;
470
+ var nodeTargetName = hasName ? node.name : node.uuid;
471
+ parts[ 2 ] = nodeTargetName;
472
472
 
473
- let TypedKeyframeTrack;
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" ) {
474
477
 
475
- switch ( outputAccessor.itemSize ) {
478
+ if( node.type === "Group" ) {
476
479
 
477
- case 1:
478
- TypedKeyframeTrack = NumberKeyframeTrack;
479
- break;
480
- case 2:
481
- case 3:
482
- TypedKeyframeTrack = VectorKeyframeTrack;
483
- break;
484
- case 4:
485
-
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.2",
3
+ "version": "0.154.3",
4
4
  "description": "JavaScript 3D library",
5
5
  "type": "module",
6
6
  "main": "./build/three.js",