Skip to content

Commit

Permalink
WIP on normals translation in hydra meshes Autodesk#1959
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienblor committed Jul 8, 2024
1 parent bd01e0e commit a3a86ec
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 24 deletions.
26 changes: 26 additions & 0 deletions libs/common/shape_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,32 @@ AtArray* GenerateVertexIdxs(unsigned int numIdxs, const VtIntArray* vertexCounts
return array;
}

AtArray* GenerateVertexIdxs(const VtIntArray& indices, AtArray* vidxs)
{
if (vidxs == nullptr || AiArrayGetNumElements(vidxs) == 0) {
return AiArrayAllocate(0, 1, AI_TYPE_UINT);
}
if (indices.empty())
return AiArrayCopy(vidxs);

const auto numIdxs = static_cast<uint32_t>(AiArrayGetNumElements(vidxs));
auto* array = AiArrayAllocate(numIdxs, 1, AI_TYPE_UINT);
auto* out = static_cast<uint32_t*>(AiArrayMap(array));
auto* in = static_cast<uint32_t*>(AiArrayMap(vidxs));

for (unsigned int i = 0; i < numIdxs; ++i) {
if (in[i] >= indices.size()) {
out[i] = {};
continue;
}
out[i] = indices[in[i]];
}

AiArrayUnmap(array);
AiArrayUnmap(vidxs);
return array;
}

template <typename T>
inline bool _FlattenIndexedValue(const VtValue& in, const VtIntArray& idx, VtValue& out)
{
Expand Down
7 changes: 7 additions & 0 deletions libs/common/shape_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ AtArray* GenerateVertexIdxs(
/// @return An AtArray converted from @p indices containing face-varying indices.
AtArray* GenerateVertexIdxs(const VtIntArray& indices, const VtIntArray* vertexCounts = nullptr);

/// Generate the idxs array for indexed primvars with vertex interpolation.
///
/// @param indices Vertex indices from Hydra for this primvar.
/// @param vidxs Vertex indices array from Arnold (vidxs)
/// @return An AtArray converted from @p indices containing face-varying indices.
AtArray* GenerateVertexIdxs(const VtIntArray& indices, AtArray* vidxs);

/// Type to store arnold param names and values.
using ArnoldUsdParamValueList = std::vector<std::pair<AtString, VtValue>>;

Expand Down
6 changes: 4 additions & 2 deletions libs/render_delegate/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ struct _ConvertValueToArnoldParameter<UsdType, ArnoldType, HdArnoldSampledPrimva

template <typename UsdType, unsigned ArnoldType, typename StorageType>
inline void _ConvertVertexPrimvarToBuiltin(
AtNode* node, const StorageType& data, const AtString& arnoldName, const AtString& arnoldIndexName)
AtNode* node, const StorageType& data, const VtIntArray &indices, const AtString& arnoldName, const AtString& arnoldIndexName)
{
// We are receiving per vertex data, the way to support this is in arnold to use the values and copy the vertex ids
// to the new ids for the given value.
_ConvertValueToArnoldParameter<UsdType, ArnoldType, StorageType>::convert(
node, data, arnoldName, arnoldIndexName,
[&](unsigned int) -> AtArray* { return AiArrayCopy(AiNodeGetArray(node, str::vidxs)); }, nullptr);
[&](unsigned int) -> AtArray* { return GenerateVertexIdxs(indices, AiNodeGetArray(node, str::vidxs)); }, nullptr);
}

template <typename UsdType, unsigned ArnoldType, typename StorageType>
Expand Down Expand Up @@ -472,6 +472,8 @@ void HdArnoldMesh::Sync(
if (desc.value.IsEmpty()) {
sceneDelegate->SamplePrimvar(id, primvar.first, &sample);
} else {
sample.values.clear();
sample.times.clear();
sample.values.push_back(desc.value);
sample.times.push_back(0.f);
}
Expand Down
36 changes: 15 additions & 21 deletions libs/render_delegate/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,30 +667,24 @@ void HdArnoldGetPrimvars(
// The number of motion keys has to be matched between points and normals, so if there are multiple
// position keys, so we are forcing the user to use the SamplePrimvars function.
if (multiplePositionKeys && primvarDesc.name == HdTokens->normals) {
HdArnoldInsertPrimvar(primvars, primvarDesc.name, primvarDesc.role, primvarDesc.interpolation,
#ifdef USD_HAS_SAMPLE_INDEXED_PRIMVAR
HdArnoldInsertPrimvar(primvars, primvarDesc.name, primvarDesc.role, primvarDesc.interpolation, {}, {});
#else
HdArnoldInsertPrimvar(primvars, primvarDesc.name, primvarDesc.role, primvarDesc.interpolation, {});
#endif
{}
#endif
, {});

} else {
#ifdef USD_HAS_SAMPLE_INDEXED_PRIMVAR
if (primvarDesc.interpolation == HdInterpolationFaceVarying) {
VtIntArray valueIndices;
const auto value = delegate->GetIndexedPrimvar(id, primvarDesc.name, &valueIndices);
HdArnoldInsertPrimvar(
primvars, primvarDesc.name, primvarDesc.role, primvarDesc.interpolation, value, valueIndices);
} else {
#endif
HdArnoldInsertPrimvar(
primvars, primvarDesc.name, primvarDesc.role, primvarDesc.interpolation,
delegate->Get(id, primvarDesc.name)
#ifdef USD_HAS_SAMPLE_INDEXED_PRIMVAR
,
{}
#endif
);
#ifdef USD_HAS_SAMPLE_INDEXED_PRIMVAR
}
VtIntArray valueIndices;
const auto value = delegate->GetIndexedPrimvar(id, primvarDesc.name, &valueIndices);
HdArnoldInsertPrimvar(
primvars, primvarDesc.name, primvarDesc.role, primvarDesc.interpolation, value, valueIndices);

#else
HdArnoldInsertPrimvar(
primvars, primvarDesc.name, primvarDesc.role, primvarDesc.interpolation,
delegate->Get(id, primvarDesc.name));

#endif
}
}
Expand Down
2 changes: 1 addition & 1 deletion testsuite/groups
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ darwin:
#######################
# Tests that can be run in hydra mode

hydra: test_0000 test_0001 test_0002 test_0003 test_0004 test_0005 test_0006 test_0007 test_0008 test_0009 test_0010 test_0011 test_0012 test_0014 test_0016 test_0017 test_0018 test_0019 test_0020 test_0021 test_0022 test_0023 test_0024 test_0025 test_0026 test_0027 test_0028 test_0029 test_0030 test_0031 test_0032 test_0033 test_0034 test_0037 test_0038 test_0041 test_0046 test_0048 test_0049 test_0050 test_0051 test_0052 test_0055 test_0056 test_0057 test_0058 test_0059 test_0060 test_0062 test_0064 test_0066 test_0067 test_0068 test_0071 test_0072 test_0073 test_0074 test_0077 test_0080 test_0081 test_0082 test_0083 test_0084 test_0086 test_0087 test_0088 test_0091 test_0093 test_0094 test_0097 test_0099 test_0104 test_0105 test_0107 test_0108 test_0110 test_0112 test_0113 test_0114 test_0115 test_0117 test_0120 test_0121 test_0122 test_0123 test_0125 test_0126 test_0127 test_0128 test_0129 test_0130 test_0132 test_0133 test_0135 test_0139 test_0140 test_0141 test_0142 test_0143 test_0144 test_0145 test_0148 test_0149 test_0150 test_0151 test_0158 test_0159 test_0160 test_0161 test_0162 test_0163 test_0164 test_0165 test_0166 test_0168 test_0169 test_0170 test_0171 test_0172 test_0173 test_0174 test_0175 test_0177 test_0178 test_0180 test_0183 test_0184 test_0186 test_0187 test_0188 test_0189 test_0191 test_0194 test_0195 test_0196 test_0197 test_0198 test_0200 test_0201 test_0202 test_0204 test_0205 test_0206 test_0207 test_0215 test_0216 test_0217 test_0219 test_0220 test_0221 test_0222 test_0223 test_0225 test_0227 test_0228 test_0229 test_0230 test_0231 test_0232 test_0233 test_0234 test_0238 test_0239 test_0240 test_0242 test_0243 test_0244 test_0245 test_0299 test_0316 test_0317 test_0739 test_1181 test_1204 test_1209 test_1223 test_1225 test_1238 test_1245 test_1262 test_1294 test_1309 test_1311 test_1313 test_1329 test_1333 test_1334 test_1346 test_1354 test_1416 test_1420 test_1426 test_1427.1 test_1427.2 test_1427.3 test_1430 test_1433 test_1435 test_1438 test_1442 test_1457 test_1486 test_1499 test_1524 test_1525 test_1530 test_1535 test_1538 test_1546 test_1547.1 test_1547.2 test_1550 test_1567 test_1588 test_1590 test_1593 test_1607 test_1613 test_1625 test_1632 test_1635 test_1654 test_1657 test_1678 test_1705 test_1718 test_1726 test_1730 test_1735 test_1769 test_1772 test_1776 test_1814 test_1868 test_1873 test_1878 test_1881 test_1894 test_1906 test_1923 test_1939 test_1940 test_14028
hydra: test_0000 test_0001 test_0002 test_0003 test_0004 test_0005 test_0006 test_0007 test_0008 test_0009 test_0010 test_0011 test_0012 test_0014 test_0016 test_0017 test_0018 test_0019 test_0020 test_0021 test_0022 test_0023 test_0024 test_0025 test_0026 test_0027 test_0028 test_0029 test_0030 test_0031 test_0032 test_0033 test_0034 test_0037 test_0038 test_0041 test_0046 test_0048 test_0049 test_0050 test_0051 test_0052 test_0055 test_0056 test_0057 test_0058 test_0059 test_0060 test_0062 test_0064 test_0066 test_0067 test_0068 test_0071 test_0072 test_0073 test_0074 test_0077 test_0080 test_0081 test_0082 test_0083 test_0084 test_0086 test_0087 test_0088 test_0091 test_0093 test_0094 test_0097 test_0099 test_0104 test_0105 test_0107 test_0108 test_0110 test_0112 test_0113 test_0114 test_0115 test_0117 test_0120 test_0121 test_0122 test_0123 test_0125 test_0126 test_0127 test_0128 test_0129 test_0130 test_0132 test_0133 test_0135 test_0139 test_0140 test_0141 test_0142 test_0143 test_0144 test_0145 test_0148 test_0149 test_0150 test_0151 test_0158 test_0159 test_0160 test_0161 test_0162 test_0163 test_0164 test_0165 test_0166 test_0168 test_0169 test_0170 test_0171 test_0172 test_0173 test_0174 test_0175 test_0177 test_0178 test_0180 test_0183 test_0184 test_0186 test_0187 test_0188 test_0189 test_0191 test_0194 test_0195 test_0196 test_0197 test_0198 test_0200 test_0201 test_0202 test_0204 test_0205 test_0206 test_0207 test_0215 test_0216 test_0217 test_0219 test_0220 test_0221 test_0222 test_0223 test_0225 test_0227 test_0228 test_0229 test_0230 test_0231 test_0232 test_0233 test_0234 test_0238 test_0239 test_0240 test_0242 test_0243 test_0244 test_0245 test_0299 test_0316 test_0317 test_0739 test_1181 test_1204 test_1209 test_1223 test_1225 test_1238 test_1245 test_1262 test_1294 test_1309 test_1311 test_1313 test_1329 test_1333 test_1334 test_1346 test_1354 test_1416 test_1420 test_1426 test_1427.1 test_1427.2 test_1427.3 test_1430 test_1433 test_1435 test_1438 test_1442 test_1457 test_1483 test_1486 test_1499 test_1524 test_1525 test_1530 test_1535 test_1538 test_1546 test_1547.1 test_1547.2 test_1550 test_1567 test_1588 test_1590 test_1593 test_1607 test_1613 test_1625 test_1632 test_1635 test_1654 test_1657 test_1678 test_1705 test_1718 test_1726 test_1730 test_1735 test_1769 test_1772 test_1776 test_1814 test_1868 test_1873 test_1878 test_1881 test_1894 test_1906 test_1923 test_1939 test_1940 test_14028

# Tests in this group will never be executed (you can use it to temporarily disable some tests and/or groups)
ignore:
Expand Down

0 comments on commit a3a86ec

Please sign in to comment.