parseAnimationLayers method
Map
parseAnimationLayers(
- dynamic curveNodesMap
)
Implementation
Map parseAnimationLayers( curveNodesMap ) {
var rawLayers = fbxTree.Objects["AnimationLayer"];
Map layersMap = {};
for ( var nodeID in rawLayers.keys ) {
var layerCurveNodes = [];
var connection = connections[ int.parse( nodeID.toString() ) ];
if ( connection != null ) {
// all the animationCurveNodes used in the layer
var children = connection["children"];
children.asMap().forEach( ( i, child ) {
if ( curveNodesMap.containsKey( child["ID"] ) ) {
var curveNode = curveNodesMap[ child["ID"] ];
// check that the curves are defined for at least one axis, otherwise ignore the curveNode
if ( curveNode["curves"]["x"] != null || curveNode["curves"]["y"] != null || curveNode["curves"]["z"] != null ) {
var modelID = connections[ child["ID"] ]["parents"].where( ( parent ) {
return parent["relationship"] != null;
} ).toList()[ 0 ]["ID"];
if ( modelID != null ) {
var rawModel = fbxTree.Objects["Model"][ modelID ];
if ( rawModel == null ) {
print( 'THREE.FBXLoader: Encountered a unused curve. ${child}' );
return;
}
var node = {
"modelName": rawModel["attrName"] != null ? PropertyBinding.sanitizeNodeName( rawModel["attrName"] ) : '',
"ID": rawModel["id"],
"initialPosition": [ 0, 0, 0 ],
"initialRotation": [ 0, 0, 0 ],
"initialScale": [ 1, 1, 1 ],
};
sceneGraph.traverse( ( child ) {
if ( child.id == rawModel["id"] ) {
node["transform"] = child.matrix;
if ( child.userData["transformData"] != null ) node["eulerOrder"] = child.userData["transformData"]["eulerOrder"];
}
} );
if ( node["transform"] == null ) node["transform"] = new Matrix4();
// if the animated model is pre rotated, we'll have to apply the pre rotations to every
// animation value as well
if ( rawModel.keys.contains('PreRotation') ) node["preRotation"] = rawModel["PreRotation"]["value"];
if ( rawModel.keys.contains('PostRotation') ) node["postRotation"] = rawModel["PostRotation"]["value"];
layerCurveNodes.add( node );
}
if ( layerCurveNodes[ i ] != null ) layerCurveNodes[ i ][ curveNode["attr"] ] = curveNode;
} else if ( curveNode.curves.morph != null ) {
if ( layerCurveNodes[ i ] == null ) {
var deformerID = connections[ child["ID"] ].parents.filter( ( parent ) {
return parent.relationship != null;
} )[ 0 ].ID;
var morpherID = connections[deformerID].parents[ 0 ].ID;
var geoID = connections[ morpherID ].parents[ 0 ].ID;
// assuming geometry is not used in more than one model
var modelID = connections[ geoID ].parents[ 0 ].ID;
var rawModel = fbxTree.Objects["Model"][ modelID ];
var node = {
"modelName": rawModel.attrName ? PropertyBinding.sanitizeNodeName( rawModel.attrName ) : '',
"morphName": fbxTree.Objects["Deformer"][ deformerID ].attrName,
};
layerCurveNodes[ i ] = node;
}
layerCurveNodes[ i ][ curveNode.attr ] = curveNode;
}
}
} );
layersMap[ int.parse( nodeID.toString() ) ] = layerCurveNodes;
}
}
return layersMap;
}