Skip to content

Commit

Permalink
Matching to Houdini build 18.5.80.
Browse files Browse the repository at this point in the history
  • Loading branch information
SideFX authored and Prisms User committed Jan 4, 2020
1 parent 3f5de72 commit bc1ae87
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 31 deletions.
24 changes: 16 additions & 8 deletions src/houdini/custom/USD/GEO_FileData.C
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
#include <HUSD/HUSD_Constants.h>
#include <HUSD/XUSD_TicketRegistry.h>
#include <HUSD/XUSD_Utils.h>
#include <gusd/context.h>
#include <gusd/primWrapper.h>
#include <gusd/GT_Utils.h>
#include <OP/OP_Director.h>
#include <GT/GT_RefineParms.h>
#include <GU/GU_Detail.h>
Expand Down Expand Up @@ -71,11 +68,13 @@ GEO_FileData::New(const SdfFileFormat::FileFormatArguments &args)
data->mySampleFrame = SYSatof(timeit->second.c_str());
data->mySampleFrame = CHgetSampleFromTime(data->mySampleFrame);
data->mySampleFrameSet = true;
data->mySaveSampleFrame = false;
}
else
{
data->mySampleFrame = CHgetSampleFromTime(0.0);
data->mySampleFrameSet = false;
data->mySaveSampleFrame = false;
}

return data;
Expand Down Expand Up @@ -202,6 +201,18 @@ GEO_FileData::Open(const std::string& filePath)
UT_String path_attr_str;
UT_WorkArgs path_attr_args;

// Only grab the sample frame from the gdp if we weren't passed
// a value in the args used to open the file.
if (!mySampleFrameSet)
{
if (getCookOption(&myCookArgs, "sampleframe", gdp, cook_option))
{
mySampleFrame = SYSatof(cook_option.c_str());
mySampleFrameSet = true;
mySaveSampleFrame = true;
}
}

if (getCookOption(&myCookArgs, "pathattr", gdp, cook_option))
path_attr_str = cook_option;
else
Expand Down Expand Up @@ -390,10 +401,6 @@ GEO_FileData::Open(const std::string& filePath)
refiner.refineDetail(gdh, refine_parms);

const GEO_FileRefiner::GEO_FileGprimArray &prims = refiner.finish();
GusdGT_AttrFilter attr_filter;
GusdContext context(UsdTimeCode(mySampleFrame),
GusdContext::PER_FRAME,
attr_filter);
SdfPath default_prim_path;

// No point in outputting our path attributes.
Expand All @@ -413,7 +420,8 @@ GEO_FileData::Open(const std::string& filePath)
while (default_prim_path != SdfPath::AbsoluteRootPath() &&
!default_prim_path.IsRootPrimPath())
default_prim_path = default_prim_path.GetParentPath();
GEOinitRootPrim(*myPseudoRoot, default_prim_path.GetNameToken());
GEOinitRootPrim(*myPseudoRoot, default_prim_path.GetNameToken(),
mySaveSampleFrame, mySampleFrame);

GEO_HandleOtherPrims parents_primhandling = options.myOtherPrimHandling;
GEO_KindSchema parents_kind = options.myKindSchema;
Expand Down
1 change: 1 addition & 0 deletions src/houdini/custom/USD/GEO_FileData.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class GEO_FileData : public SdfAbstractData
SdfFileFormat::FileFormatArguments myCookArgs;
fpreal mySampleFrame;
bool mySampleFrameSet;
bool mySaveSampleFrame;

friend class GEO_FilePrim;
};
Expand Down
12 changes: 11 additions & 1 deletion src/houdini/custom/USD/GEO_FilePrimUtils.C
Original file line number Diff line number Diff line change
Expand Up @@ -1827,12 +1827,22 @@ GEOsetKind(GEO_FilePrim &fileprim,

void
GEOinitRootPrim(GEO_FilePrim &fileprim,
const TfToken &default_prim_name)
const TfToken &default_prim_name,
bool save_sample_frame,
fpreal sample_frame)
{
if (!default_prim_name.IsEmpty())
fileprim.addMetadata(SdfFieldKeys->DefaultPrim,
VtValue(default_prim_name));

if (save_sample_frame)
{
fileprim.addMetadata(SdfFieldKeys->StartTimeCode,
VtValue(sample_frame));
fileprim.addMetadata(SdfFieldKeys->EndTimeCode,
VtValue(sample_frame));
}

fileprim.setInitialized();
}

Expand Down
4 changes: 3 additions & 1 deletion src/houdini/custom/USD/GEO_FilePrimUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ GEOsetKind(GEO_FilePrim &prim,

void
GEOinitRootPrim(GEO_FilePrim &fileprim,
const TfToken &default_prim_name);
const TfToken &default_prim_name,
bool save_sample_frame,
fpreal sample_frame);

void
GEOinitXformPrim(GEO_FilePrim &fileprim,
Expand Down
94 changes: 85 additions & 9 deletions src/houdini/lib/H_USD/HUSD/HUSD_Skeleton.C
Original file line number Diff line number Diff line change
Expand Up @@ -529,15 +529,31 @@ HUSDimportAgentRig(const HUSD_AutoReadLock &readlock,
return rig;
}

/// Import the geometry for a blendshape input, which consists of point
/// positions and an id attribute (for sparse blendshapes).
static bool
husdGetOffsets(const UsdSkelBlendShape &blendshape, VtVec3fArray &offsets)
{
return blendshape.GetOffsetsAttr().Get(&offsets);
}

static bool
husdGetOffsets(const UsdSkelInbetweenShape &inbetween, VtVec3fArray &offsets)
{
return inbetween.GetOffsets(&offsets);
}

/// Import the geometry for a blendshape input or in-between shape, which
/// consists of point positions and an id attribute (for sparse blendshapes).
/// In-between shapes use the point indices from the primary shape, if
/// authored.
template <typename BlendshapeT>
static bool
husdImportBlendShape(GU_Detail &detail,
const BlendshapeT &blendshape_or_inbetween,
const UsdSkelBlendShape &blendshape,
const GU_Detail &base_shape)
{
VtVec3fArray offsets;
if (!blendshape.GetOffsetsAttr().Get(&offsets))
if (!husdGetOffsets(blendshape_or_inbetween, offsets))
{
HUSD_ErrorScope::addError(
HUSD_ERR_STRING, "'offsets' attribute was not authored.");
Expand Down Expand Up @@ -646,21 +662,27 @@ husdImportBlendShapes(GU_Detail &base_shape,
UT_StringArray channel_names;
channel_names.setCapacity(blendshape_query.GetNumBlendShapes());

static constexpr UT_StringLit theInbetweensPrefix("inbetweens:");
UT_WorkBuffer inbetween_name;
UT_StringArray inbetween_names;
UT_Array<fpreal> inbetween_weights;

for (exint i = 0, n = blendshape_query.GetNumBlendShapes(); i < n; ++i)
{
UsdSkelBlendShape blendshape = blendshape_query.GetBlendShape(i);

channel_names.append(channel_names_attr[i].GetString());

SdfPath path = blendshape.GetPrim().GetPath();
UT_StringHolder name = path.MakeRelativePath(root_path).GetString();
SdfPath path =
blendshape.GetPrim().GetPath().MakeRelativePath(root_path);
UT_StringHolder name = path.GetString();
shape_names.append(name);

GU_DetailHandle gdh;
gdh.allocateAndSet(new GU_Detail());

GU_DetailHandleAutoWriteLock detail(gdh);
if (!husdImportBlendShape(*detail, blendshape, base_shape))
if (!husdImportBlendShape(*detail, blendshape, blendshape, base_shape))
{
UT_WorkBuffer msg;
msg.format("Failed to import blendshape '{}'",
Expand All @@ -672,7 +694,56 @@ husdImportBlendShapes(GU_Detail &base_shape,
all_shape_details.append(gdh);
all_shape_names.append(name);

// TODO - import in-between shapes.
// Import in-between shapes.
inbetween_names.clear();
inbetween_weights.clear();
for (const UsdSkelInbetweenShape &inbetween :
blendshape.GetInbetweens())
{
inbetween_name = inbetween.GetAttr().GetName().GetString();

// Strip the "inbetweens:" prefix.
if (!inbetween_name.strncmp(
theInbetweensPrefix.c_str(), theInbetweensPrefix.length()))
{
inbetween_name.eraseHead(theInbetweensPrefix.length());
}

float weight = 0;
if (!inbetween.GetWeight(&weight))
{
HUSD_ErrorScope::addError(
HUSD_ERR_STRING,
"Weight is not authored for in-between shape");
return false;
}

GU_DetailHandle inbetween_gdh =
gdh.duplicateGeometry(GA_DATA_ID_BUMP);
inbetween_gdh.allocateAndSet(new GU_Detail());
GU_DetailHandleAutoWriteLock inbetween_detail(inbetween_gdh);

if (!husdImportBlendShape(
*inbetween_detail, inbetween, blendshape, base_shape))
{
UT_WorkBuffer msg;
msg.format("Failed to import in-between '{}' for '{}'",
inbetween.GetAttr().GetName().GetString(),
blendshape.GetPath().GetString());
HUSD_ErrorScope::addError(HUSD_ERR_STRING, msg.buffer());
return false;
}

all_shape_names.append(
path.AppendChild(TfToken(inbetween_name.buffer())).GetString());
all_shape_details.append(inbetween_gdh);

inbetween_names.append(all_shape_names.last());
inbetween_weights.append(weight);
}

GU_AgentBlendShapeUtils::addInBetweenShapes(
*detail, inbetween_names, inbetween_weights);
}

// Record the blendshape inputs as detail attributes on the base shape.
Expand Down Expand Up @@ -921,8 +992,13 @@ HUSDimportAgentClip(GU_AgentClip &clip,
UT_Vector3F r, s, t;
for (exint sample_i = 0; sample_i < num_samples; ++sample_i)
{
UsdTimeCode timecode(start_time + sample_i);
if (!animquery.ComputeJointLocalTransforms(&local_matrices, timecode))
const UsdTimeCode timecode(start_time + sample_i);

// If there aren't any joints (i.e. the rig only has the locomotion
// transform), don't call ComputeJointLocalTransforms() which will
// fail.
if (rig.transformCount() > 1 &&
!animquery.ComputeJointLocalTransforms(&local_matrices, timecode))
{
HUSD_ErrorScope::addError(
HUSD_ERR_STRING, "Failed to compute local transforms.");
Expand Down
18 changes: 6 additions & 12 deletions src/houdini/lib/H_USD/gusd/agentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,9 @@ GusdCreateAgentRig(const UT_StringHolder &name,
}

VtTokenArray joints;
if (!skel.GetJointsAttr().Get(&joints)) {
GUSD_WARN().Msg("%s -- 'joints' attr is invalid",
skel.GetPrim().GetPath().GetText());
return nullptr;
}
// Note - it's acceptable for there to be no joints authored if e.g. there
// are only blendshapes.
skel.GetJointsAttr().Get(&joints);

VtTokenArray jointNames;
if (!Gusd_GetJointNames(skel, joints, jointNames)) {
Expand Down Expand Up @@ -865,19 +863,15 @@ GusdForEachSkinnedPrim(const UsdSkelBinding &binding,
const UsdSkelSkeleton &skel = binding.GetSkeleton();

VtTokenArray joints;
if (!skel.GetJointsAttr().Get(&joints))
{
GUSD_WARN().Msg("%s -- 'joints' attr is invalid",
skel.GetPrim().GetPath().GetText());
return false;
}
skel.GetJointsAttr().Get(&joints);

VtTokenArray jointNames;
if (!Gusd_GetJointNames(skel, joints, jointNames))
return false;

VtMatrix4dArray invBindTransforms;
if (!skel.GetBindTransformsAttr().Get(&invBindTransforms))
if (!joints.empty() &&
!skel.GetBindTransformsAttr().Get(&invBindTransforms))
{
GUSD_WARN().Msg("%s -- no authored bindTransforms",
skel.GetPrim().GetPath().GetText());
Expand Down

0 comments on commit bc1ae87

Please sign in to comment.