-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathmeshUtil.cpp
97 lines (84 loc) · 2.59 KB
/
meshUtil.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2024 The Khronos Group
// SPDX-License-Identifier: Apache-2.0
#include "meshUtil.h"
#include <pxr/imaging/hd/perfLog.h>
#include <pxr/imaging/hd/vtBufferSource.h>
#include <pxr/pxr.h>
#include <pxr/base/gf/vec2d.h>
#include <pxr/base/gf/vec2f.h>
#include <pxr/base/gf/vec2i.h>
#include <pxr/base/gf/vec3d.h>
#include <pxr/base/gf/vec3f.h>
#include <pxr/base/gf/vec3i.h>
#include <pxr/base/gf/vec4d.h>
#include <pxr/base/gf/vec4f.h>
#include <pxr/base/gf/vec4i.h>
PXR_NAMESPACE_OPEN_SCOPE
template <typename T>
void HdAnariMeshUtil::GatherPerFacePrimVar(VtIntArray const &primitiveParams,
void const *sourceUntyped,
VtValue *mappedPrimvar)
{
T const *source = static_cast<T const *>(sourceUntyped);
VtArray<T> results;
results.reserve(primitiveParams.size());
for (auto pp : primitiveParams) {
int faceIndex = HdMeshUtil::DecodeFaceIndexFromCoarseFaceParam(pp);
results.push_back(source[faceIndex]);
}
*mappedPrimvar = results;
}
bool HdAnariMeshUtil::GatherPerFacePrimvar(const SdfPath &id,
const TfToken &pvname,
VtValue value,
VtIntArray primitiveParameters,
VtValue *mappedPrimvar) const
{
HD_TRACE_FUNCTION();
if (mappedPrimvar == nullptr) {
TF_CODING_ERROR("No output buffer provided for triangulation");
return false;
}
HdVtBufferSource buffer(pvname, value);
switch (buffer.GetTupleType().type) {
case HdTypeFloat:
GatherPerFacePrimVar<float>(
primitiveParameters, buffer.GetData(), mappedPrimvar);
break;
case HdTypeFloatVec2:
GatherPerFacePrimVar<GfVec2f>(
primitiveParameters, buffer.GetData(), mappedPrimvar);
break;
case HdTypeFloatVec3:
GatherPerFacePrimVar<GfVec3f>(
primitiveParameters, buffer.GetData(), mappedPrimvar);
break;
case HdTypeFloatVec4:
GatherPerFacePrimVar<GfVec4f>(
primitiveParameters, buffer.GetData(), mappedPrimvar);
break;
case HdTypeDouble:
GatherPerFacePrimVar<double>(
primitiveParameters, buffer.GetData(), mappedPrimvar);
break;
case HdTypeDoubleVec2:
GatherPerFacePrimVar<GfVec2d>(
primitiveParameters, buffer.GetData(), mappedPrimvar);
break;
case HdTypeDoubleVec3:
GatherPerFacePrimVar<GfVec3d>(
primitiveParameters, buffer.GetData(), mappedPrimvar);
break;
case HdTypeDoubleVec4:
GatherPerFacePrimVar<GfVec4d>(
primitiveParameters, buffer.GetData(), mappedPrimvar);
break;
default:
TF_CODING_ERROR("Unsupported primvar type for triangle mapping [%s.%s]",
id.GetText(),
pvname.GetText());
return false;
}
return true;
}
PXR_NAMESPACE_CLOSE_SCOPE