From c512979b30f546a24792064e892907fba8756b3c Mon Sep 17 00:00:00 2001 From: SideFX Date: Fri, 22 Nov 2019 01:00:21 -0500 Subject: [PATCH] Matching to Houdini build 18.5.37. --- .../custom/USD/GEO_FilePrimAgentUtils.C | 10 ++--- .../custom/USD/GEO_FilePrimAgentUtils.h | 2 +- src/houdini/custom/USD/GEO_FilePrimUtils.C | 41 +++++++++++++------ src/houdini/lib/H_USD/HUSD/XUSD_Data.C | 20 +++++++-- 4 files changed, 51 insertions(+), 22 deletions(-) diff --git a/src/houdini/custom/USD/GEO_FilePrimAgentUtils.C b/src/houdini/custom/USD/GEO_FilePrimAgentUtils.C index a6f901bb..93f4e736 100644 --- a/src/houdini/custom/USD/GEO_FilePrimAgentUtils.C +++ b/src/houdini/custom/USD/GEO_FilePrimAgentUtils.C @@ -18,11 +18,11 @@ PXR_NAMESPACE_OPEN_SCOPE TF_DEFINE_PUBLIC_TOKENS(GEO_AgentPrimTokens, GEO_AGENT_PRIM_TOKENS); void -GEObuildJointList(const GU_AgentRig &rig, VtTokenArray &joint_list, +GEObuildJointList(const GU_AgentRig &rig, VtTokenArray &joint_paths, UT_Array &joint_order) { joint_order.setSizeNoInit(rig.transformCount()); - joint_list.reserve(rig.transformCount()); + joint_paths.reserve(rig.transformCount()); UT_WorkBuffer buf; exint ordered_idx = 0; @@ -35,18 +35,18 @@ GEObuildJointList(const GU_AgentRig &rig, VtTokenArray &joint_list, const exint parent_idx = rig.parentIndex(xform_idx); if (parent_idx >= 0) { - buf.append(joint_list[joint_order[parent_idx]].GetString()); + buf.append(joint_paths[joint_order[parent_idx]].GetString()); buf.append('/'); } buf.append(rig.transformName(xform_idx)); - joint_list.push_back(TfToken(buf.toStdString())); + joint_paths.push_back(TfToken(buf.toStdString())); joint_order[xform_idx] = ordered_idx; } #ifdef UT_DEBUG // Validate the hierarchy. - UsdSkelTopology topo(joint_list); + UsdSkelTopology topo(joint_paths); std::string errors; if (!topo.Validate(&errors)) UT_ASSERT_MSG(false, errors.c_str()); diff --git a/src/houdini/custom/USD/GEO_FilePrimAgentUtils.h b/src/houdini/custom/USD/GEO_FilePrimAgentUtils.h index 71d5a349..10846442 100644 --- a/src/houdini/custom/USD/GEO_FilePrimAgentUtils.h +++ b/src/houdini/custom/USD/GEO_FilePrimAgentUtils.h @@ -33,7 +33,7 @@ TF_DECLARE_PUBLIC_TOKENS(GEO_AgentPrimTokens, GEO_AGENT_PRIM_TOKENS); /// Build a list of the joint names in the format required by UsdSkel (i.e. /// full paths such as "A/B/C"), and ordered so that parents appear before /// children. -void GEObuildJointList(const GU_AgentRig &rig, VtTokenArray &joint_list, +void GEObuildJointList(const GU_AgentRig &rig, VtTokenArray &joint_paths, UT_Array &joint_order); /// Convert a list of joint transforms from GU_Agent::Matrix4Type to diff --git a/src/houdini/custom/USD/GEO_FilePrimUtils.C b/src/houdini/custom/USD/GEO_FilePrimUtils.C index b6eb8b66..1c97faf3 100644 --- a/src/houdini/custom/USD/GEO_FilePrimUtils.C +++ b/src/houdini/custom/USD/GEO_FilePrimUtils.C @@ -1862,7 +1862,7 @@ static void initSkeletonPrim(const GEO_FilePrim &defn_root, GEO_FilePrimMap &fileprimmap, const GEO_ImportOptions &options, const GU_AgentRig &rig, const GEO_AgentSkeleton &skeleton, - const VtTokenArray &joint_list, + const VtTokenArray &joint_paths, const UT_Array &joint_order) { SdfPath skel_path = defn_root.getPath().AppendChild(skeleton.myName); @@ -1876,7 +1876,24 @@ initSkeletonPrim(const GEO_FilePrim &defn_root, GEO_FilePrimMap &fileprimmap, // Record the joint list. GEO_FileProp *prop = skel_prim.addProperty( UsdSkelTokens->joints, SdfValueTypeNames->TokenArray, - new GEO_FilePropConstantSource(joint_list)); + new GEO_FilePropConstantSource(joint_paths)); + prop->setValueIsDefault(true); + prop->setValueIsUniform(true); + + // Also record the original unique joint names from GU_AgentRig. + // These can be used instead of the full paths when importing into another + // format (e.g. back to SOPs). + VtTokenArray joint_names; + joint_names.resize(joint_paths.size()); + for (exint i = 0, n = rig.transformCount(); i < n; ++i) + { + joint_names[joint_order[i]] = + TfToken(rig.transformName(i).toStdString()); + } + + prop = skel_prim.addProperty( + UsdSkelTokens->jointNames, SdfValueTypeNames->TokenArray, + new GEO_FilePropConstantSource(joint_names)); prop->setValueIsDefault(true); prop->setValueIsUniform(true); @@ -1895,7 +1912,7 @@ initSkeletonPrim(const GEO_FilePrim &defn_root, GEO_FilePrimMap &fileprimmap, // provide animation for all of the joints, but this ensures that the // source skeleton (which doesn't have an animation source) looks // reasonable if it's viewed. - UsdSkelTopology topology(joint_list); + UsdSkelTopology topology(joint_paths); VtMatrix4dArray rest_xforms; UsdSkelComputeJointLocalTransforms(topology, bind_xforms, &rest_xforms); @@ -1913,12 +1930,12 @@ initSkelAnimationPrim(GEO_FilePrim &anim_prim, const GU_Agent &agent, { // Add the joint list property. UT_Array joint_order; - VtTokenArray joint_list; - GEObuildJointList(rig, joint_list, joint_order); + VtTokenArray joint_paths; + GEObuildJointList(rig, joint_paths, joint_order); GEO_FileProp *prop = anim_prim.addProperty( UsdSkelTokens->joints, SdfValueTypeNames->TokenArray, - new GEO_FilePropConstantSource(joint_list)); + new GEO_FilePropConstantSource(joint_paths)); prop->setValueIsDefault(true); prop->setValueIsUniform(true); @@ -2217,7 +2234,7 @@ initAgentShapePrim(GEO_FilePrimMap &fileprimmap, const GU_AgentShapeLib::Shape &shape, const SdfPath &shapelib_path, const GU_AgentRig &rig, const UT_Array &joint_order, - const VtTokenArray &joint_list, + const VtTokenArray &joint_paths, const UT_Map &usd_shape_names) { UT_ASSERT(usd_shape_names.contains(shape.uniqueId())); @@ -2261,7 +2278,7 @@ initAgentShapePrim(GEO_FilePrimMap &fileprimmap, if (xform_idx >= 0) { const exint usd_joint_idx = joint_order[xform_idx]; - referenced_joints.push_back(joint_list[usd_joint_idx]); + referenced_joints.push_back(joint_paths[usd_joint_idx]); } else referenced_joints.push_back(TfToken()); @@ -3015,8 +3032,8 @@ GEOinitGTPrim(GEO_FilePrim &fileprim, // through the joint names and must be ordered so that parents appear // before children (unlike GU_AgentRig). UT_Array joint_order; - VtTokenArray joint_list; - GEObuildJointList(rig, joint_list, joint_order); + VtTokenArray joint_paths; + GEObuildJointList(rig, joint_paths, joint_order); UT_Map usd_shape_names; GEObuildUsdShapeNames(*defn.shapeLibrary(), usd_shape_names); @@ -3030,7 +3047,7 @@ GEOinitGTPrim(GEO_FilePrim &fileprim, for (const GEO_AgentSkeleton &skeleton : skeletons) { initSkeletonPrim(fileprim, fileprimmap, options, rig, skeleton, - joint_list, joint_order); + joint_paths, joint_order); } // During refinement the shape library geometry was also refined @@ -3056,7 +3073,7 @@ GEOinitGTPrim(GEO_FilePrim &fileprim, { initAgentShapePrim(fileprimmap, shapelib, *shapelib.findShape(shape_name), - shapelib_path, rig, joint_order, joint_list, + shapelib_path, rig, joint_order, joint_paths, usd_shape_names); } } diff --git a/src/houdini/lib/H_USD/HUSD/XUSD_Data.C b/src/houdini/lib/H_USD/HUSD/XUSD_Data.C index f37e5ed9..f6c1bb55 100644 --- a/src/houdini/lib/H_USD/HUSD/XUSD_Data.C +++ b/src/houdini/lib/H_USD/HUSD/XUSD_Data.C @@ -1401,11 +1401,17 @@ XUSD_Data::createFlattenedLayer( // stop processing at payloads/references anyway. SdfLayerRefPtr flattened = HUSDflattenLayers(getOrCreateStageForFlattening( response, UsdStage::LoadNone)); + std::string savepath; // Clear the save control. Mostly we want to ensure this layer is never // marked as a Placeholder. But we don't really want to preserve any of - // the other possible values either. - HUSDsetSaveControl(flattened, UT_StringHolder::theEmptyString); + // the other possible values either. Make an exception if the flattened + // layer has a save path set. Then we can assume the layer was intended + // to be saved explicitly. + if (HUSDgetSavePath(flattened, savepath)) + HUSDsetSaveControl(flattened, HUSD_Constants::getSaveControlExplicit()); + else + HUSDsetSaveControl(flattened, UT_StringHolder::theEmptyString); return flattened; } @@ -1418,11 +1424,17 @@ XUSD_Data::createFlattenedStage( // with the payload. SdfLayerRefPtr flattened = getOrCreateStageForFlattening( response, UsdStage::LoadAll)->Flatten(); + std::string savepath; // Clear the save control. Mostly we want to ensure this layer is never // marked as a Placeholder. But we don't really want to preserve any of - // the other possible values either. - HUSDsetSaveControl(flattened, UT_StringHolder::theEmptyString); + // the other possible values either. Make an exception if the flattened + // layer has a save path set. Then we can assume the layer was intended + // to be saved explicitly. + if (HUSDgetSavePath(flattened, savepath)) + HUSDsetSaveControl(flattened, HUSD_Constants::getSaveControlExplicit()); + else + HUSDsetSaveControl(flattened, UT_StringHolder::theEmptyString); return flattened; }