Skip to content

Commit

Permalink
Matching to Houdini build 18.5.31.
Browse files Browse the repository at this point in the history
  • Loading branch information
SideFX authored and Prisms User committed Nov 16, 2019
1 parent 593d797 commit d1663b7
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/houdini/custom/USDOP/CMakeSources.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set( sources
plugin.C
HUSD_FieldWrapper.C
HUSD_LopStageFactory.C
OBJ_LOP.C
OBJ_LOPCamera.C
Expand Down
171 changes: 171 additions & 0 deletions src/houdini/custom/USDOP/HUSD_FieldWrapper.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/*
* PROPRIETARY INFORMATION. This software is proprietary to
* Side Effects Software Inc., and is not to be reproduced,
* transmitted, or disclosed in any way without written permission.
*/

#include "HUSD_FieldWrapper.h"

#include <GT/GT_PrimVDB.h>
#include <GT/GT_PrimVolume.h>
#include <GT/GT_Refine.h>
#include <HUSD/HUSD_HydraField.h>
#include <HUSD/XUSD_Tokens.h>

PXR_NAMESPACE_OPEN_SCOPE

TF_DEFINE_PRIVATE_TOKENS(_tokens,
((vdbFieldPrimType, "OpenVDBAsset"))
((houdiniFieldPrimType, "HoudiniFieldAsset"))
);

void
HUSD_FieldWrapper::registerForRead()
{
static std::once_flag registered;

std::call_once(registered, []() {
// Register for both VDB and Houdini volumes.
GusdPrimWrapper::registerPrimDefinitionFuncForRead(
_tokens->vdbFieldPrimType, &HUSD_FieldWrapper::defineForRead);
GusdPrimWrapper::registerPrimDefinitionFuncForRead(
_tokens->houdiniFieldPrimType, &HUSD_FieldWrapper::defineForRead);
});
}

HUSD_FieldWrapper::HUSD_FieldWrapper(const UsdVolFieldAsset &usd_field,
UsdTimeCode time, GusdPurposeSet purposes)
: GusdPrimWrapper(time, purposes), myUsdField(usd_field)
{
}

HUSD_FieldWrapper::~HUSD_FieldWrapper() {}

const char *
HUSD_FieldWrapper::className() const
{
return "HUSD_FieldWrapper";
}

void
HUSD_FieldWrapper::enlargeBounds(UT_BoundingBox boxes[], int nsegments) const
{
UT_ASSERT_MSG(false, "HUSD_FieldWrapper::enlargeBounds not implemented");
}

int
HUSD_FieldWrapper::getMotionSegments() const
{
return 1;
}

int64
HUSD_FieldWrapper::getMemoryUsage() const
{
return sizeof(*this);
}

GT_PrimitiveHandle
HUSD_FieldWrapper::doSoftCopy() const
{
return GT_PrimitiveHandle(new HUSD_FieldWrapper(*this));
}

bool
HUSD_FieldWrapper::isValid() const
{
return static_cast<bool>(myUsdField);
}

bool
HUSD_FieldWrapper::refine(GT_Refine &refiner,
const GT_RefineParms *parms) const
{
if (!isValid())
{
TF_WARN("Invalid prim");
return false;
}

UsdAttribute file_path_attr = myUsdField.GetFilePathAttr();
SdfAssetPath file_path;
if (file_path_attr)
TF_VERIFY(file_path_attr.Get(&file_path, m_time));

UsdAttribute field_name_attr =
myUsdField.GetPrim().GetAttribute(UsdVolTokens->fieldName);
TfToken field_name;
if (field_name_attr)
TF_VERIFY(field_name_attr.Get(&field_name, m_time));

UsdAttribute field_index_attr =
myUsdField.GetPrim().GetAttribute(UsdVolTokens->fieldIndex);
int field_index = -1;
if (field_index_attr)
TF_VERIFY(field_index_attr.Get(&field_index, m_time));

bool is_vdb = false;
bool is_houdini_vol = false;
TfToken field_type;

// Determine the field type, and the correct type to pass to
// HUSD_HydraField::getVolumePrimitive (which expects Hydra prim types).
const TfToken &src_field_type = myUsdField.GetPrim().GetTypeName();
if (src_field_type == _tokens->vdbFieldPrimType)
{
is_vdb = true;
field_type = HusdHdPrimTypeTokens()->openvdbAsset;
}
else if (src_field_type == _tokens->houdiniFieldPrimType)
{
is_houdini_vol = true;
field_type = HusdHdPrimTypeTokens()->bprimHoudiniFieldAsset;
}
else
{
UT_ASSERT_MSG(false, "Unknown volume primitive type");
return false;
}

// Attempt to load the volume from disk or a SOP network.
GT_PrimitiveHandle volume = HUSD_HydraField::getVolumePrimitive(
file_path.GetAssetPath(), field_name.GetString(), field_index,
field_type.GetString());
if (!volume)
{
UT_ASSERT_MSG(false, "Could not load volume");
return false;
}

// Since we may have loaded the volume from SOPs, replace the attribute
// list with the field's primvars so that extra attributes won't
// unexpectedly appear.
GT_AttributeListHandle attribs =
new GT_AttributeList(new GT_AttributeMap());
loadPrimvars(m_time, parms, 1, 0, 0, myUsdField.GetPath().GetString(),
nullptr, nullptr, &attribs, nullptr);

if (is_vdb)
{
auto vol = UTverify_cast<GT_PrimVDB*>(volume.get());
vol->setUniformAttributes(attribs);
}
else if (is_houdini_vol)
{
auto vol = UTverify_cast<GT_PrimVolume *>(volume.get());
vol->setUniformAttributes(attribs);
}

refiner.addPrimitive(volume);
return true;
}

GT_PrimitiveHandle
HUSD_FieldWrapper::defineForRead(const UsdGeomImageable &source_prim,
UsdTimeCode time, GusdPurposeSet purposes)
{
return new HUSD_FieldWrapper(UsdVolFieldAsset(source_prim.GetPrim()), time,
purposes);
}

PXR_NAMESPACE_CLOSE_SCOPE
61 changes: 61 additions & 0 deletions src/houdini/custom/USDOP/HUSD_FieldWrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* PROPRIETARY INFORMATION. This software is proprietary to
* Side Effects Software Inc., and is not to be reproduced,
* transmitted, or disclosed in any way without written permission.
*/

#ifndef __HUSD_FieldWrapper__
#define __HUSD_FieldWrapper__

#include <gusd/primWrapper.h>
#include <pxr/usd/usdVol/fieldAsset.h>

PXR_NAMESPACE_OPEN_SCOPE

/// GusdPrimWrapper implementation for converting USD fields back to
/// GT_PrimVolume or GT_PrimVDB primitives.
class HUSD_FieldWrapper : public GusdPrimWrapper
{
public:
HUSD_FieldWrapper(const UsdVolFieldAsset &usd_field, UsdTimeCode t,
GusdPurposeSet purposes);
virtual ~HUSD_FieldWrapper();

static void registerForRead();

virtual const UsdGeomImageable getUsdPrim() const override
{
return myUsdField;
}

virtual const char *className() const override;

virtual void
enlargeBounds(UT_BoundingBox boxes[], int nsegments) const override;

virtual int getMotionSegments() const override;

virtual int64 getMemoryUsage() const override;

virtual GT_PrimitiveHandle doSoftCopy() const override;

virtual bool isValid() const override;

virtual bool refine(GT_Refine &refiner,
const GT_RefineParms *parms = nullptr) const override;

public:
static GT_PrimitiveHandle
defineForRead(const UsdGeomImageable &source_prim, UsdTimeCode time,
GusdPurposeSet purposes);

private:
bool initUsdPrim(const UsdStagePtr &stage, const SdfPath &path,
bool as_override);

UsdVolFieldAsset myUsdField;
};

PXR_NAMESPACE_CLOSE_SCOPE

#endif
5 changes: 5 additions & 0 deletions src/houdini/custom/USDOP/plugin.C
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "pxr/base/arch/export.h"
#include <gusd/gusd.h>
#include "HUSD_FieldWrapper.h"
#include "OBJ_LOP.h"
#include "OBJ_LOPCamera.h"
#include "SOP_LOP.h"
Expand All @@ -45,6 +46,7 @@ newSopOperator(OP_OperatorTable* operators)
if (SOLARIS_ENABLED)
{
PXR_NS::GusdInit();
PXR_NS::HUSD_FieldWrapper::registerForRead();
PXR_NS::SOP_LOP::Register(operators);
PXR_NS::SOP_UnpackUSD::Register(operators);
}
Expand All @@ -57,6 +59,7 @@ newObjectOperator(OP_OperatorTable* operators)
if (SOLARIS_ENABLED)
{
PXR_NS::GusdInit();
PXR_NS::HUSD_FieldWrapper::registerForRead();
PXR_NS::OBJ_LOP::Register(operators);
PXR_NS::OBJ_LOPCamera::Register(operators);
}
Expand All @@ -69,6 +72,7 @@ newGeometryPrim(GA_PrimitiveFactory *f)
if (SOLARIS_ENABLED)
{
PXR_NS::GusdInit();
PXR_NS::HUSD_FieldWrapper::registerForRead();
PXR_NS::GusdNewGeometryPrim(f);
}
}
Expand All @@ -80,6 +84,7 @@ newGeometryIO(void *)
if (SOLARIS_ENABLED)
{
PXR_NS::GusdInit();
PXR_NS::HUSD_FieldWrapper::registerForRead();
PXR_NS::GusdNewGeometryIO();
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/houdini/lib/H_USD/HUSD/HUSD_EditReferences.C
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,21 @@ HUSD_EditReferences::removeReference(const UT_StringRef &primpath,
if (prim)
{
SdfFileFormat::FileFormatArguments args;
SdfPath bestrefprimpath;

for (auto &&it : refargs)
args[it.first.toStdString()] = it.second.toStdString();

bestrefprimpath = HUSDgetBestRefPrimPath(
reffilepath, args, refprimpath, stage);

if (myRefType == HUSD_Constants::getReferenceTypeFile())
{
auto refs = prim.GetReferences();
SdfReference sdfreference(
SdfLayer::CreateIdentifier(
reffilepath.toStdString(), args),
HUSDgetSdfPath(refprimpath),
bestrefprimpath,
HUSDgetSdfLayerOffset(offset));

success = refs.RemoveReference(sdfreference);
Expand All @@ -227,7 +231,7 @@ HUSD_EditReferences::removeReference(const UT_StringRef &primpath,
auto refs = prim.GetReferences();
SdfReference sdfreference(
std::string(),
HUSDgetSdfPath(refprimpath),
bestrefprimpath,
HUSDgetSdfLayerOffset(offset));

success = refs.RemoveReference(sdfreference);
Expand All @@ -238,7 +242,7 @@ HUSD_EditReferences::removeReference(const UT_StringRef &primpath,
SdfPayload sdfpayload(
SdfLayer::CreateIdentifier(
reffilepath.toStdString(), args),
HUSDgetSdfPath(refprimpath),
bestrefprimpath,
HUSDgetSdfLayerOffset(offset));

success = payloads.RemovePayload(sdfpayload);
Expand Down

0 comments on commit d1663b7

Please sign in to comment.