-
Notifications
You must be signed in to change notification settings - Fork 8
/
UsdGeometry.h
180 lines (138 loc) · 5.38 KB
/
UsdGeometry.h
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// Copyright 2020 The Khronos Group
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "UsdBridgedBaseObject.h"
#include <memory>
#include <limits>
class UsdDataArray;
struct UsdBridgeMeshData;
static constexpr int MAX_ATTRIBS = 16;
enum class UsdGeometryComponents
{
POSITION = 0,
NORMAL,
COLOR,
INDEX,
SCALE,
ORIENTATION,
ID,
ATTRIBUTE0,
ATTRIBUTE1,
ATTRIBUTE2,
ATTRIBUTE3
};
struct UsdGeometryData
{
UsdSharedString* name = nullptr;
UsdSharedString* usdName = nullptr;
double timeStep = 0.0;
int timeVarying = 0xFFFFFFFF; // TimeVarying bits
const UsdDataArray* vertexPositions = nullptr;
const UsdDataArray* vertexNormals = nullptr;
const UsdDataArray* vertexColors = nullptr;
const UsdDataArray* vertexAttributes[MAX_ATTRIBS] = { nullptr };
const UsdDataArray* primitiveNormals = nullptr;
const UsdDataArray* primitiveColors = nullptr;
const UsdDataArray* primitiveAttributes[MAX_ATTRIBS] = { nullptr };
const UsdDataArray* primitiveIds = nullptr;
const UsdSharedString* attributeNames[MAX_ATTRIBS] = { nullptr };
const UsdDataArray* indices = nullptr;
// Spheres
const UsdDataArray* vertexRadii = nullptr;
float radiusConstant = 1.0f;
bool UseUsdGeomPoints =
#ifdef USE_USD_GEOM_POINTS
true;
#else
false;
#endif
// Cylinders
const UsdDataArray* primitiveRadii = nullptr;
// Curves
// Glyphs
const UsdDataArray* vertexScales = nullptr;
const UsdDataArray* primitiveScales = nullptr;
const UsdDataArray* vertexOrientations = nullptr;
const UsdDataArray* primitiveOrientations = nullptr;
UsdFloat3 scaleConstant = {1.0f, 1.0f, 1.0f};
UsdQuaternion orientationConstant;
UsdSharedString* shapeType = nullptr;
UsdGeometry* shapeGeometry = nullptr;
UsdFloatMat4 shapeTransform;
double shapeGeometryRefTimeStep = std::numeric_limits<float>::quiet_NaN();
};
struct UsdGeometryTempArrays;
class UsdGeometry : public UsdBridgedBaseObject<UsdGeometry, UsdGeometryData, UsdGeometryHandle, UsdGeometryComponents>
{
public:
enum GeomType
{
GEOM_UNKNOWN = 0,
GEOM_TRIANGLE,
GEOM_QUAD,
GEOM_SPHERE,
GEOM_CYLINDER,
GEOM_CONE,
GEOM_CURVE,
GEOM_GLYPH
};
typedef std::vector<UsdBridgeAttribute> AttributeArray;
typedef std::vector<std::vector<char>> AttributeDataArraysType;
UsdGeometry(const char* name, const char* type, UsdDevice* device);
~UsdGeometry();
void remove(UsdDevice* device) override;
void filterSetParam(const char *name,
ANARIDataType type,
const void *mem,
UsdDevice* device) override;
void commit(UsdDevice* device) override;
bool isInstanced() const
{
return geomType == GEOM_SPHERE
|| geomType == GEOM_CONE
|| geomType == GEOM_CYLINDER
|| geomType == GEOM_GLYPH;
}
bool getHasNewAttribName() const { return hasNewAttribName; }
static constexpr ComponentPair componentParamNames[] = {
ComponentPair(UsdGeometryComponents::POSITION, "position"),
ComponentPair(UsdGeometryComponents::NORMAL, "normal"),
ComponentPair(UsdGeometryComponents::COLOR, "color"),
ComponentPair(UsdGeometryComponents::INDEX, "index"),
ComponentPair(UsdGeometryComponents::SCALE, "scale"),
ComponentPair(UsdGeometryComponents::SCALE, "radius"),
ComponentPair(UsdGeometryComponents::ORIENTATION, "orientation"),
ComponentPair(UsdGeometryComponents::ID, "id"),
ComponentPair(UsdGeometryComponents::ATTRIBUTE0, "attribute0"),
ComponentPair(UsdGeometryComponents::ATTRIBUTE1, "attribute1"),
ComponentPair(UsdGeometryComponents::ATTRIBUTE2, "attribute2"),
ComponentPair(UsdGeometryComponents::ATTRIBUTE3, "attribute3")};
protected:
bool deferCommit(UsdDevice* device) override;
bool doCommitData(UsdDevice* device) override;
void doCommitRefs(UsdDevice* device) override;
void initializeGeomData(UsdBridgeMeshData& geomData);
void initializeGeomData(UsdBridgeInstancerData& geomData);
void initializeGeomData(UsdBridgeCurveData& geomData);
void initializeGeomRefData(UsdBridgeInstancerRefData& geomRefData);
bool checkArrayConstraints(const UsdDataArray* vertexArray, const UsdDataArray* primArray,
const char* paramName, UsdDevice* device, const char* debugName, int attribIndex = -1);
bool checkGeomParams(UsdDevice* device);
void updateGeomData(UsdDevice* device, UsdBridge* usdBridge, UsdBridgeMeshData& meshData, bool isNew);
void updateGeomData(UsdDevice* device, UsdBridge* usdBridge, UsdBridgeInstancerData& instancerData, bool isNew);
void updateGeomData(UsdDevice* device, UsdBridge* usdBridge, UsdBridgeCurveData& curveData, bool isNew);
template<typename UsdGeomType>
bool commitTemplate(UsdDevice* device);
void commitPrototypes(UsdBridge* usdBridge);
template<typename GeomDataType>
void setAttributeTimeVarying(typename GeomDataType::DataMemberId& timeVarying);
void syncAttributeArrays();
template<typename GeomDataType>
void copyAttributeArraysToData(GeomDataType& geomData);
void assignTempDataToAttributes(bool perPrimInterpolation);
GeomType geomType = GEOM_UNKNOWN;
bool protoShapeChanged = false; // Do not automatically commit shapes (the object may have been recreated onto an already existing USD prim)
bool hasNewAttribName = false;
std::unique_ptr<UsdGeometryTempArrays> tempArrays;
AttributeArray attributeArray;
};