From dbd7440abbf1407373484de4152869b1eb08db87 Mon Sep 17 00:00:00 2001 From: pixar-oss Date: Fri, 7 Feb 2020 11:01:17 -0800 Subject: [PATCH] Now creates a UsdShadeInput for every connected input on vop shader nodes. (Previously, only input connections with corresponding parms had a UsdShadeInput created). (Internal change: 2040562) --- third_party/houdini/gusd/shaderWrapper.cpp | 61 ++++++++++++++++++++-- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/third_party/houdini/gusd/shaderWrapper.cpp b/third_party/houdini/gusd/shaderWrapper.cpp index cbc2e5016c..ea780a9ef9 100644 --- a/third_party/houdini/gusd/shaderWrapper.cpp +++ b/third_party/houdini/gusd/shaderWrapper.cpp @@ -225,6 +225,41 @@ void _buildRampParmInputs(const PRM_Parm* parm, UsdShadeShader& shaderObject) } } +SdfValueTypeName +_vopTypeToSdfType(const VOP_Type& vopType) { + switch(vopType) { + case VOP_TYPE_INTEGER: return SdfValueTypeNames->Int; + case VOP_TYPE_FLOAT: return SdfValueTypeNames->Float; + case VOP_TYPE_STRING: return SdfValueTypeNames->String; + case VOP_TYPE_POINT: return SdfValueTypeNames->Point3f; + case VOP_TYPE_NORMAL: return SdfValueTypeNames->Normal3f; + case VOP_TYPE_COLOR: return SdfValueTypeNames->Color3f; + case VOP_TYPE_VECTOR: return SdfValueTypeNames->Vector3f; + case VOP_TYPE_VECTOR2: return SdfValueTypeNames->Float2; + case VOP_TYPE_VECTOR4: return SdfValueTypeNames->Float4; + case VOP_TYPE_MATRIX2: return SdfValueTypeNames->Matrix2d; + case VOP_TYPE_MATRIX3: return SdfValueTypeNames->Matrix3d; + case VOP_TYPE_MATRIX4: return SdfValueTypeNames->Matrix4d; + case VOP_TYPE_STRUCT: return SdfValueTypeNames->Token; + + case VOP_TYPE_INTEGER_ARRAY: return SdfValueTypeNames->IntArray; + case VOP_TYPE_FLOAT_ARRAY: return SdfValueTypeNames->FloatArray; + case VOP_TYPE_STRING_ARRAY: return SdfValueTypeNames->StringArray; + case VOP_TYPE_POINT_ARRAY: return SdfValueTypeNames->Point3fArray; + case VOP_TYPE_NORMAL_ARRAY: return SdfValueTypeNames->Normal3fArray; + case VOP_TYPE_COLOR_ARRAY: return SdfValueTypeNames->Color3fArray; + case VOP_TYPE_VECTOR_ARRAY: return SdfValueTypeNames->Vector3fArray; + case VOP_TYPE_VECTOR2_ARRAY: return SdfValueTypeNames->Float2Array; + case VOP_TYPE_VECTOR4_ARRAY: return SdfValueTypeNames->Float4Array; + case VOP_TYPE_MATRIX2_ARRAY: return SdfValueTypeNames->Matrix2dArray; + case VOP_TYPE_MATRIX3_ARRAY: return SdfValueTypeNames->Matrix3dArray; + case VOP_TYPE_MATRIX4_ARRAY: return SdfValueTypeNames->Matrix4dArray; + // VOP_TYPE_STRUCT_ARRAY doesn't exist + + default: return SdfValueTypeName(); + } +} + UsdShadeShader _vopGraphToUsdTraversal(const VOP_Node* vopNode, UsdStagePtr& stage, @@ -459,11 +494,29 @@ _vopGraphToUsdTraversal(const VOP_Node* vopNode, vopNode->getInputName(inputName, inIdx); inputVop->getOutputName(outputName,outIdx); - UsdShadeInput shadeInput - = shaderObject.GetInput(TfToken(inputName.toStdString())); - UsdShadeConnectableAPI::ConnectToSource(shadeInput, - inputPrim, TfToken(outputName.toStdString())); + TfToken inputToken(inputName.toStdString()); + UsdShadeInput shadeInput = shaderObject.GetInput(inputToken); + + // + // It's possible that no UsdShadeInput has been created for this + // connection yet. Only input connections with corresponding parms + // have been visited so far. This must be an input with no parm. + // + if (!shadeInput) { + VOP_Type vopType = vopNode->getInputType(inIdx); + auto sdfType = _vopTypeToSdfType(vopType); + if (sdfType) { + shadeInput = shaderObject.CreateInput(inputToken, sdfType); + } + } + if (shadeInput) { + UsdShadeConnectableAPI::ConnectToSource(shadeInput, + inputPrim, TfToken(outputName.toStdString())); + } else { + TF_CODING_ERROR("Error creating or retrieving input '%s' on " + "shader '%s'.", inputToken.GetText(), nodeName.c_str()); + } } }