4545#include " maya/MFnDagNode.h"
4646#include " maya/MTime.h"
4747#include " maya/MEvaluationNode.h"
48+ #include " maya/MItDependencyGraph.h"
49+
4850
4951using namespace IECore ;
5052using namespace IECoreScene ;
5153using namespace IECoreMaya ;
5254
55+ namespace
56+ {
57+ const MString g_mayaGlobalTimeNodeName ( " time1" );
58+ }
59+
5360MTypeId SceneShape::id = SceneShapeId;
5461MObject SceneShape::aSceneFilePlug;
5562MObject SceneShape::aSceneRootPlug;
@@ -256,7 +263,7 @@ ConstObjectPtr SceneShape::readSceneShapeLink( const MDagPath &p )
256263 SceneShape *sceneShape = findScene ( p, true , &dagPath );
257264 if ( !sceneShape )
258265 {
259- throw Exception (" readSceneShapeLink: Could not find SceneShape!" );
266+ throw Exception ( " readSceneShapeLink: Could not find SceneShape!" );
260267 }
261268
262269 const SceneInterface *scene = sceneShape->getSceneInterface ().get ();
@@ -270,26 +277,36 @@ ConstObjectPtr SceneShape::readSceneShapeLink( const MDagPath &p )
270277 MPlug timePlug = fnChildDag.findPlug ( aTime, false , &st );
271278 if ( !st )
272279 {
273- throw Exception ( " Could not find 'time' plug in SceneShape!" );
280+ throw Exception ( " Could not find 'time' plug in SceneShape!" );
274281 }
275282
276- // if time plug is connected to maya global time, then we assume there's no time remapping between the Maya scene and the loaded scene.
277- MPlugArray array;
278- timePlug.connectedTo ( array, true , false , &st );
279- if ( !st )
283+ MItDependencyGraph it = MItDependencyGraph ( timePlug, MFn::kInvalid , MItDependencyGraph::kUpstream , MItDependencyGraph::kDepthFirst , MItDependencyGraph::kPlugLevel );
284+ for ( ; !it.isDone () ; it.next () )
280285 {
281- throw Exception ( " Could not find 'time' plug connections in SceneShape!" );
282- }
286+ MPlug currPlug = it.thisPlug ( &st );
287+ CHECK_MSTATUS (st);
288+ MFnDependencyNode nodeFn ( currPlug.node (), &st );
289+ CHECK_MSTATUS (st);
283290
284- for ( unsigned int i = 0 ; i < array.length (); i++ )
285- {
286- if ( array[i].name () == " time1.outTime" )
291+ if ( nodeFn.name () == g_mayaGlobalTimeNodeName )
287292 {
288- // / connected to time, so no time remapping between maya scene and loaded scene.
293+ // / The plug is connected to maya global time, so no time remapping is happening
289294 return LinkedScene::linkAttributeData ( scene );
290295 }
296+
297+ unsigned int nodeId = nodeFn.typeId ().id ();
298+ bool isSceneShape = nodeId == SceneShapeId || nodeId == SceneShapeProxyId;
299+ if ( !isSceneShape )
300+ {
301+ // / The time plug is not connected to global maya time or a scene shape (expanded hierarchy),
302+ // / so we assume some kind of time manipulation (a maya add node to offset the value or similiar)
303+ MTime time;
304+ timePlug.getValue ( time );
305+ return LinkedScene::linkAttributeData ( scene, time.as ( MTime::kSeconds ) );
306+ }
291307 }
292- // / couldn't find connection to maya time, so this node is mapping the time some other way.
308+
309+ // / The time plug doesn't have any connection at all (time hold)
293310 MTime time;
294311 timePlug.getValue ( time );
295312 return LinkedScene::linkAttributeData ( scene, time.as ( MTime::kSeconds ) );
0 commit comments