/
Geometry.h
316 lines (255 loc) · 8.67 KB
/
Geometry.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
// Copyright 2023-2024 DreamWorks Animation LLC
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "Camera.h"
#include "Node.h"
#include "SceneClass.h"
#include "SceneObject.h"
#include "Types.h"
#include <scene_rdl2/common/except/exceptions.h>
#include <scene_rdl2/common/math/Xform.h>
#include <string>
namespace moonray { namespace geom { class Procedural; } }
namespace scene_rdl2 {
namespace rdl2 {
// This enum is used in multiple attributes.cc files and we require those files to have a minimum of
// depedencies on moonray itself. So this basically provides a convenient place to put a shared definition.
enum class MotionBlurType {
STATIC = 0,
VELOCITY = 1,
FRAME_DELTA = 2,
ACCELERATION = 3,
HERMITE = 4,
STATIC_DUPLICATE = 5,
BEST = -1
};
// Note about STATIC_DUPLICATE: This is not a motion blur type per se but is a way to create a vertex
// buffer with two identical motion steps. The vertices are then replaced with modified values such
// as in the moonshine WrapDeformGeometry procedural.
enum class PrimitiveAttributeFrame {
FIRST_MOTION_STEP = 0,
SECOND_MOTION_STEP = 1,
BOTH_MOTION_STEPS = 2,
};
class Geometry : public Node
{
public:
typedef Node Parent;
enum SideType { TWO_SIDED = 0, SINGLE_SIDED, MESH_DEFAULT_SIDED };
Geometry(const SceneClass& sceneClass, const std::string& name);
virtual ~Geometry();
static SceneObjectInterface declare(SceneClass& sceneClass);
/// Invokes createProcedural() and captures the returned procedural.
finline void loadProcedural();
/// destroy the loaded procedural
finline void unloadProcedural();
/// Returns the loaded procedural or null.
finline const moonray::geom::Procedural* getProcedural() const;
finline moonray::geom::Procedural* getProcedural();
/// Set the render to object transform cache, This should
/// be set by the renderer during geometry update or creation.
finline void setRender2Object(const math::Xform3f &render2Object);
/// Return the render2Object transform cache set by the renderer
finline math::Xform3f getRender2Object() const;
/// Convenience function for checking if the Geometry is static.
finline bool isStatic() const;
/// Returns the sidedness of the mesh.
finline SideType getSideType() const;
/// Check if normals of the mesh are reversed.
finline bool getReverseNormals() const;
// See if user has set a RayEpsilon (default 0.0f)
// If so, renderer should use this value. Otherwise, use renderer's estimate
finline float getRayEpsilon() const;
// See if user has set a ShadowRayEpsilon (default 0.0f)
// If so, renderer should use this value.
finline float getShadowRayEpsilon() const;
finline void setContainsCamera();
// Get the shadow receiver label string, used to look for matches with a correspoinding shadow caster label
finline const std::string& getShadowReceiverLabel() const;
// Get the shadow exclusion mappping string
finline const std::string& getShadowExclusionMappings() const;
/// Returns the mesh visibility Mask.
int getVisibilityMask() const;
/// Returns the dicing camera
finline const Camera* getDicingCamera() const;
/// Returns whether use_local_motion_blur is enabled
finline bool getUseLocalMotionBlur() const;
/// Returns whether use_local_motion_camera_blur is enabled
finline bool getUseLocalCameraMotionBlur() const;
// TODO this is a temporary band-aid to avoid attribute modification
// that doesn't require geometry to regenerate causing long regenerate wait
// during interactive workflow. One solution would be to have a more
// generic way to classify attributes for corresponding renderer behavior
// after attributes update.
// Or we should move such attributes out of the geometry object.
//
/// Returns whether the attributes graph this geometry depends on contains
/// update that requires geometry to regenerate/tessellate/construct accelerator
bool requiresGeometryUpdate(UpdateHelper& sceneObjects, int depth);
// Attributes common to all Geometries.
static AttributeKey<String> sLabel;
static AttributeKey<SceneObjectVector> sReferenceGeometries;
static AttributeKey<Bool> sStaticKey;
static AttributeKey<Int> sSideTypeKey;
static AttributeKey<Bool> sReverseNormals;
static AttributeKey<Bool> sVisibleCamera;
static AttributeKey<Bool> sVisibleShadow;
static AttributeKey<Bool> sVisibleDiffuseReflection;
static AttributeKey<Bool> sVisibleDiffuseTransmission;
static AttributeKey<Bool> sVisibleGlossyReflection;
static AttributeKey<Bool> sVisibleGlossyTransmission;
static AttributeKey<Bool> sVisibleMirrorReflection;
static AttributeKey<Bool> sVisibleMirrorTransmission;
static AttributeKey<Bool> sVisiblePhase;
static AttributeKey<Float> sRayEpsilon;
static AttributeKey<Float> sShadowRayEpsilon;
static AttributeKey<String> sShadowReceiverLabel;
static AttributeKey<String> sShadowExclusionMappings;
static AttributeKey<Bool> sContainsCamera;
static AttributeKey<SceneObject*> sDicingCamera;
static AttributeKey<Bool> sUseLocalMotionBlur;
static AttributeKey<Bool> sUseLocalCameraMotionBlur;
/// Returns whether the internal procedural geometric data has been deformed.
/// WARNING: assumes that procedural exists, verify that getProcedural
/// is non-null before calling.
virtual bool deformed() const { return false; }
/// Reset the deformed status.
/// WARNING: assumes that procedural exists, verify that getProcedural
/// is non-null before calling.
virtual void resetDeformed() {};
protected:
// Must be implemented by derived classes.
virtual moonray::geom::Procedural* createProcedural() const = 0;
virtual void destroyProcedural() const = 0;
protected:
moonray::geom::Procedural* mProcedural;
math::Xform3f mRender2Object;
template <typename Container>
bool geometryUpdatePrepSequenceContainer(const Attribute* attribute,
UpdateHelper& sceneObjects,
int depth)
{
bool updateRequired = false;
const AttributeKey<Container> key(*attribute);
const Container& objectVector = get(key);
for (SceneObject * const object : objectVector) {
if (object) {
if (object->isA<Geometry>() && !object->asA<Geometry>()->
requiresGeometryUpdate(sceneObjects, depth + 1)) {
continue;
}
updateRequired |= object->updatePrep(sceneObjects, depth);
}
}
mAttributeTreeChanged |= updateRequired;
return updateRequired;
}
private:
bool mContainsCamera;
};
void
Geometry::loadProcedural()
{
mProcedural = createProcedural();
}
void
Geometry::unloadProcedural()
{
destroyProcedural();
mProcedural = nullptr;
}
const moonray::geom::Procedural*
Geometry::getProcedural() const
{
return mProcedural;
}
moonray::geom::Procedural*
Geometry::getProcedural()
{
return mProcedural;
}
void
Geometry::setRender2Object(const math::Xform3f &render2Object)
{
mRender2Object = render2Object;
}
math::Xform3f
Geometry::getRender2Object() const
{
return mRender2Object;
}
bool
Geometry::isStatic() const
{
return get(sStaticKey);
}
Geometry::SideType
Geometry::getSideType() const
{
return static_cast<SideType>(get(sSideTypeKey));
}
bool
Geometry::getReverseNormals() const
{
return get(sReverseNormals);
}
float
Geometry::getRayEpsilon() const
{
return get(sRayEpsilon);
}
float
Geometry::getShadowRayEpsilon() const
{
return get(sShadowRayEpsilon);
}
void
Geometry::setContainsCamera()
{
bool& containsCamera = getMutable(sContainsCamera);
containsCamera = true;
}
const Camera*
Geometry::getDicingCamera() const
{
SceneObject* so = get(sDicingCamera);
if (so) {
Camera* dicingCamera = so->asA<Camera>();
return dicingCamera;
}
return nullptr;
}
bool
Geometry::getUseLocalMotionBlur() const
{
return get(sUseLocalMotionBlur);
}
bool
Geometry::getUseLocalCameraMotionBlur() const
{
return get(sUseLocalCameraMotionBlur);
}
const std::string&
Geometry::getShadowReceiverLabel() const
{
return get(sShadowReceiverLabel);
}
const std::string&
Geometry::getShadowExclusionMappings() const
{
return get(sShadowExclusionMappings);
}
template <>
inline const Geometry*
SceneObject::asA() const
{
return isA<Geometry>() ? static_cast<const Geometry*>(this) : nullptr;
}
template <>
inline Geometry*
SceneObject::asA()
{
return isA<Geometry>() ? static_cast<Geometry*>(this) : nullptr;
}
} // namespace rdl2
} // namespace scene_rdl2