From 6da88cc5e2cb4edf10b8d02fb84b54831e838682 Mon Sep 17 00:00:00 2001 From: Aleka McAdams Date: Wed, 25 Oct 2017 14:25:04 -0700 Subject: [PATCH] Initialise all layers on file load. --- lib/AL_USDMaya/AL/usdmaya/Global.cpp | 69 +++++++++++++++-------- lib/AL_USDMaya/AL/usdmaya/nodes/Layer.cpp | 15 +++-- 2 files changed, 54 insertions(+), 30 deletions(-) diff --git a/lib/AL_USDMaya/AL/usdmaya/Global.cpp b/lib/AL_USDMaya/AL/usdmaya/Global.cpp index 80cd4b13..dae5d33a 100644 --- a/lib/AL_USDMaya/AL/usdmaya/Global.cpp +++ b/lib/AL_USDMaya/AL/usdmaya/Global.cpp @@ -61,7 +61,36 @@ static void preFileOpen(void*) { TF_DEBUG(ALUSDMAYA_EVENTS).Msg("preFileOpen\n"); } +//---------------------------------------------------------------------------------------------------------------------- +static void initialiseChildAndSublayers(nodes::Layer& layer, nodes::ProxyShape* proxy) +{ + // initialise self + MPlug plug = layer.nameOnLoadPlug(); + MString path = plug.asString(); + if(path.length() && path.substring(0, 3) != "anon") + { + 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*) { @@ -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 + 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); + } } } } @@ -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. } //---------------------------------------------------------------------------------------------------------------------- @@ -180,4 +202,3 @@ void Global::onPluginUnload() } // usdmaya } // al //---------------------------------------------------------------------------------------------------------------------- - diff --git a/lib/AL_USDMaya/AL/usdmaya/nodes/Layer.cpp b/lib/AL_USDMaya/AL/usdmaya/nodes/Layer.cpp index b5170464..552f1b2f 100644 --- a/lib/AL_USDMaya/AL/usdmaya/nodes/Layer.cpp +++ b/lib/AL_USDMaya/AL/usdmaya/nodes/Layer.cpp @@ -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()); + } } }