Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialise all layers on file load. #28

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 45 additions & 24 deletions lib/AL_USDMaya/AL/usdmaya/Global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,36 @@ static void preFileOpen(void*)
{
TF_DEBUG(ALUSDMAYA_EVENTS).Msg("preFileOpen\n");
}
//----------------------------------------------------------------------------------------------------------------------
static void initialiseChildAndSublayers(nodes::Layer& layer, nodes::ProxyShape* proxy)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move initialiseChildAndSublayers function to be in Layer.h/cpp

{
// initialise self
MPlug plug = layer.nameOnLoadPlug();
MString path = plug.asString();
if(path.length() && path.substring(0, 3) != "anon")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed we had this substring check before. Maybe we can do it better this time, try use SdfLayer::IsAnonymousLayerIdentifier to determine if it's anonymous

{
SdfLayerHandle layerHdl = SdfLayer::FindOrOpen(path.asChar());
LAYER_HANDLE_CHECK(layerHdl);
layer.setLayerAndClearAttribute(layerHdl);
layer.init(proxy, layerHdl);
}
else
{
layer.init(proxy, TfNullPtr);
}

// recursively call to initialise children/sublayers
auto subLayers = layer.getSubLayers();
for(auto subLayer : subLayers)
{
if(subLayer) initialiseChildAndSublayers(*subLayer, proxy);
}
auto childLayers = layer.getChildLayers();
for(auto childLayer : childLayers)
{
if(childLayer) initialiseChildAndSublayers(*childLayer, proxy);
}
}
//----------------------------------------------------------------------------------------------------------------------
static void postFileOpen(void*)
{
Expand All @@ -86,29 +115,19 @@ static void postFileOpen(void*)
if(layer)
{
layer->setLayerAndClearAttribute(stage->GetSessionLayer());
}
}
}
}
{
MItDependencyNodes iter(MFn::kPluginDependNode);
for(; !iter.isDone(); iter.next())
{
fn.setObject(iter.item());
if(fn.typeId() == nodes::Layer::kTypeId)
{
// now go and fix up each of the layer nodes in the scene
nodes::Layer* layerPtr = (nodes::Layer*)fn.userNode();
MPlug plug = layerPtr->nameOnLoadPlug();
MString path = plug.asString();
if(path.length() && path.substring(0, 3) != "anon")
{
SdfLayerHandle layer = SdfLayer::FindOrOpen(path.asChar());
LAYER_HANDLE_CHECK(layer);
layerPtr->setLayerAndClearAttribute(layer);
}
else
{
layer->init(proxy, stage->GetSessionLayer());

// initialise and fixup each child and sublayer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stick these sublayer and childlayer loops into a member function into Layer.h/cpp and call if from here

auto subLayers = layer->getSubLayers();
for(auto subLayer : subLayers)
{
if(subLayer) initialiseChildAndSublayers(*subLayer, proxy);
}
auto childLayers = layer->getChildLayers();
for(auto childLayer : childLayers)
{
if(childLayer) initialiseChildAndSublayers(*childLayer, proxy);
}
}
}
}
Expand All @@ -126,6 +145,9 @@ static void postFileOpen(void*)
}
}
}
// All layers should have been fixed up above. Do not fixup any
// orphaned layers as they will not have access to the proxy node/stage
// which makes them invalid.
}

//----------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -180,4 +202,3 @@ void Global::onPluginUnload()
} // usdmaya
} // al
//----------------------------------------------------------------------------------------------------------------------

15 changes: 9 additions & 6 deletions lib/AL_USDMaya/AL/usdmaya/nodes/Layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,14 +807,17 @@ void Layer::setLayerAndClearAttribute(SdfLayerHandle handle)
void Layer::populateSerialisationAttributes()
{
TF_DEBUG(ALUSDMAYA_LAYERS).Msg("Layer::populateSerialisationAttributes: %s %b", m_handle->GetDisplayName().c_str(), hasBeenTheEditTarget());
if(hasBeenTheEditTarget() && m_handle)
if(m_handle)
{
// always set nameOnLoad as this is necessary to initialise on file load
nameOnLoadPlug().setValue(realPathPlug().asString());

std::string temp;
m_handle->ExportToString(&temp);
serializedPlug().setValue(convert(temp));
TF_DEBUG(ALUSDMAYA_LAYERS).Msg("Layer::populateSerialisationAttributes -> contents\n%s\n", temp.c_str());
if(hasBeenEditTarget())
{
std::string temp;
m_handle->ExportToString(&temp);
serializedPlug().setValue(convert(temp));
TF_DEBUG(ALUSDMAYA_LAYERS).Msg("Layer::populateSerialisationAttributes -> contents\n%s\n", temp.c_str());
}
}
}

Expand Down