Skip to content

Commit 0d80834

Browse files
authored
Merge pull request #15017 from looeee/fbxloader_use_array_filter
FBXLoader: use Array.filter instead of forEach
2 parents 63560a1 + 14ecfab commit 0d80834

File tree

1 file changed

+34
-36
lines changed

1 file changed

+34
-36
lines changed

examples/js/loaders/FBXLoader.js

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -777,13 +777,11 @@ THREE.FBXLoader = ( function () {
777777

778778
if ( morphTargetNode.attrType !== 'BlendShapeChannel' ) return;
779779

780-
var targetRelationships = connections.get( parseInt( child.ID ) );
780+
rawMorphTarget.geoID = connections.get( parseInt( child.ID ) ).children.filter( function ( child ) {
781781

782-
targetRelationships.children.forEach( function ( child ) {
782+
return child.relationship === undefined;
783783

784-
if ( child.relationship === undefined ) rawMorphTarget.geoID = child.ID;
785-
786-
} );
784+
} )[ 0 ].ID;
787785

788786
rawMorphTargets.push( rawMorphTarget );
789787

@@ -2488,62 +2486,62 @@ THREE.FBXLoader = ( function () {
24882486

24892487
if ( layerCurveNodes[ i ] === undefined ) {
24902488

2491-
var modelID;
2489+
var modelID = connections.get( child.ID ).parents.filter( function ( parent ) {
24922490

2493-
connections.get( child.ID ).parents.forEach( function ( parent ) {
2491+
return parent.relationship !== undefined;
24942492

2495-
if ( parent.relationship !== undefined ) modelID = parent.ID;
2493+
} )[ 0 ].ID;
24962494

2497-
} );
2495+
if ( modelID !== undefined ) {
24982496

2499-
var rawModel = fbxTree.Objects.Model[ modelID.toString() ];
2497+
var rawModel = fbxTree.Objects.Model[ modelID.toString() ];
25002498

2501-
var node = {
2499+
var node = {
25022500

2503-
modelName: THREE.PropertyBinding.sanitizeNodeName( rawModel.attrName ),
2504-
ID: rawModel.id,
2505-
initialPosition: [ 0, 0, 0 ],
2506-
initialRotation: [ 0, 0, 0 ],
2507-
initialScale: [ 1, 1, 1 ],
2501+
modelName: THREE.PropertyBinding.sanitizeNodeName( rawModel.attrName ),
2502+
ID: rawModel.id,
2503+
initialPosition: [ 0, 0, 0 ],
2504+
initialRotation: [ 0, 0, 0 ],
2505+
initialScale: [ 1, 1, 1 ],
25082506

2509-
};
2507+
};
25102508

2511-
sceneGraph.traverse( function ( child ) {
2509+
sceneGraph.traverse( function ( child ) {
25122510

2513-
if ( child.ID = rawModel.id ) {
2511+
if ( child.ID = rawModel.id ) {
25142512

2515-
node.transform = child.matrix;
2513+
node.transform = child.matrix;
25162514

2517-
if ( child.userData.transformData ) node.eulerOrder = child.userData.transformData.eulerOrder;
2515+
if ( child.userData.transformData ) node.eulerOrder = child.userData.transformData.eulerOrder;
25182516

2519-
}
2517+
}
25202518

2521-
} );
2519+
} );
25222520

2523-
if ( ! node.transform ) node.transform = new THREE.Matrix4();
2521+
if ( ! node.transform ) node.transform = new THREE.Matrix4();
25242522

2525-
// if the animated model is pre rotated, we'll have to apply the pre rotations to every
2526-
// animation value as well
2527-
if ( 'PreRotation' in rawModel ) node.preRotation = rawModel.PreRotation.value;
2528-
if ( 'PostRotation' in rawModel ) node.postRotation = rawModel.PostRotation.value;
2523+
// if the animated model is pre rotated, we'll have to apply the pre rotations to every
2524+
// animation value as well
2525+
if ( 'PreRotation' in rawModel ) node.preRotation = rawModel.PreRotation.value;
2526+
if ( 'PostRotation' in rawModel ) node.postRotation = rawModel.PostRotation.value;
25292527

2530-
layerCurveNodes[ i ] = node;
2528+
layerCurveNodes[ i ] = node;
2529+
2530+
}
25312531

25322532
}
25332533

2534-
layerCurveNodes[ i ][ curveNode.attr ] = curveNode;
2534+
if ( layerCurveNodes[ i ] ) layerCurveNodes[ i ][ curveNode.attr ] = curveNode;
25352535

25362536
} else if ( curveNode.curves.morph !== undefined ) {
25372537

25382538
if ( layerCurveNodes[ i ] === undefined ) {
25392539

2540-
var deformerID;
2540+
var deformerID = connections.get( child.ID ).parents.filter( function ( parent ) {
25412541

2542-
connections.get( child.ID ).parents.forEach( function ( parent ) {
2542+
return parent.relationship !== undefined;
25432543

2544-
if ( parent.relationship !== undefined ) deformerID = parent.ID;
2545-
2546-
} );
2544+
} )[ 0 ].ID;
25472545

25482546
var morpherID = connections.get( deformerID ).parents[ 0 ].ID;
25492547
var geoID = connections.get( morpherID ).parents[ 0 ].ID;
@@ -4003,7 +4001,7 @@ THREE.FBXLoader = ( function () {
40034001
lParentGRSM = lParentTM.getInverse( lParentTM ).multiply( lParentGX );
40044002
lParentGSM = lParentGRM.getInverse( lParentGRM ).multiply( lParentGRSM );
40054003
lLSM = lScalingM;
4006-
4004+
40074005
var lGlobalRS;
40084006
if ( inheritType === 0 ) {
40094007

0 commit comments

Comments
 (0)