HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BRAY_ProceduralScene.h
Go to the documentation of this file.
1 /*
2 * PROPRIETARY INFORMATION. This software is proprietary to
3 * Side Effects Software Inc., and is not to be reproduced,
4 * transmitted, or disclosed in any way without written permission.
5 *
6 * NAME: BRAY_ProceduralScene.h (BRAY Library, C++)
7 *
8 * COMMENTS: BRAY procedural for building scenes with BRAY_Interface.
9 *
10 * This procedural can be inherited from and used as an easy
11 * way to generate render time geometry. All that needs to
12 * be implemented is the updateScene() and the
13 * doSetParameter() methods, as well as a BRAY_ProceduralFactory.
14 */
15 
16 #ifndef __BRAY_ProceduralScene__
17 #define __BRAY_ProceduralScene__
18 
19 #include <BRAY/BRAY_Procedural.h>
20 #include <BRAY/BRAY_Interface.h>
21 #include <UT/UT_SmallArray.h>
22 
23 class BRAY_Accelerator;
24 class BRAY_Instance;
25 
27 {
28 public:
29  /// Derive the SceneHit so we can pass around the hit instance
31  {
32  public:
33  ~SceneHit() override = default;
34 
35  const BRAY_Instance *inst;
36  };
37 
38  /// Wrapper around BRAY::ScenePtr
40  {
41  public:
42  Scene();
43 
44  /// Reset the scene
45  void reset();
46 
47  /// Bind the built scene to our pointers and check for validity
48  bool bindScene();
49 
50  /// Create an attribute list with all attributes
51  void
52  createAttribList(UT_Array<BRAY_AttribList::Attrib> &alist);
53 
54  /// Get the bounding box of the scene
55  void bounds(UT_BoundingBox &bounds, BRAYtime time) const;
56 
57  /// Templated function to evaluate attributes
58  /// Specialized for: int32/64, fpreal32/64, UT_StringHolder,
59  /// UT_ValArray<int32/64>, UT_ValArray<fpreal32/64> UT_StringArray
60  template <typename T>
61  const T *attribEval(
62  int attrib,
63  BRAYtime time,
64  const BRAY_Procedural::Hit &hit,
65  T *buf,
66  int size) const;
67 
68  /// Intersect the scene
69  template <typename T>
72  const BRAY_ProceduralScene &proc) const;
73 
74  /// Get the underlying ScenePtr
75  BRAY::ScenePtr &scene() { return myScene; }
76  const BRAY::ScenePtr &scene() const { return myScene; }
77 
78  struct AttrInfo
79  {
82  };
83 
84  private:
85  BRAY::ScenePtr myScene;
86  BRAY_Accelerator *myAccelerator;
87  BRAY_Scene *myRawScene;
88  // This array of maps let's us go from the global attriblist idx
89  // to the instance's attriblist idx
90  UT_Array<UT_StringMap<AttrInfo>> myAttribInstanceMap;
91  };
92 
94  virtual ~BRAY_ProceduralScene() override {};
95 
96  HitPtr newHit() const final override { return HitPtr(new SceneHit()); }
97 
98  /// Get the underlying ScenePtr
99  BRAY::ScenePtr &scene() { return myScene.scene(); }
100  const BRAY::ScenePtr &scene() const { return myScene.scene(); }
101 
102  /// Reset the underlying ScenePtr, note you'll need to get the
103  /// new ScenePtr using @c scene()
104  void reset() { myScene.reset(); }
105 
106  /// Allow the deriving class to override these, but by default build
107  /// the scene and set myValid based on it's return result
108  void doBeginUpdate() override { /* no action */ };
109  void doEndUpdate() override;
110 
111  /// Check to see whether the procedural is valid
112  bool checkIsValid() const override { return myValid; };
113 
114  /// Build or update the underlying scene, return true on success.
115  /// Use @c scene() to get the underlying ScenePtr, and use
116  virtual bool updateScene() = 0;
117 
118  /// Get the attribute list
119  const BRAY_AttribList *attribList() const override
120  { return myAttribs; }
121 
122  /// Fills the given bounding box
123  void bounds(UT_BoundingBox &bounds, BRAYtime time) const override
124  { myScene.bounds(bounds, time); }
125 
126  /// @{
127  /// Perform ray-intersection
128  HitPtr intersect(const Ray32 &ray) const final override
129  { return myScene.intersect(ray, *this); }
130  HitPtr intersect(const Ray64 &ray) const final override
131  { return myScene.intersect(ray, *this); }
132  /// @}
133 
134  // These are pure virtuals for the derived class to deal with
137  // NOTE: Not sure if this one should have a default in this class
139 
140  /// @{
141  /// Evaluate an attribute on this primitive. The methods should return a
142  /// pointer to the attribute data. If there isn't a direct raw pointer to
143  /// the data, the buffer passed in can be used to store the data and that
144  /// pointer can be returned.
145  const int32 *attribVal(int attrib, BRAYtime time,
146  const Hit &hit_info, int32 *buf,
147  int size) const final override;
148  const int64 *attribVal(int attrib, BRAYtime time,
149  const Hit &hit_info, int64 *buf,
150  int size) const final override;
151  const fpreal32 *attribVal(int attrib, BRAYtime time,
152  const Hit &hit_info, fpreal32 *buf,
153  int size) const final override;
154  const fpreal64 *attribVal(int attrib, BRAYtime time,
155  const Hit &hit_info, fpreal64 *buf,
156  int size) const final override;
157  const UT_StringHolder *attribVal(int attrib, BRAYtime time,
158  const Hit &hit_info, UT_StringHolder *buf,
159  int size) const final override;
160  /// @}
161 
162  /// @{
163  /// Evaluation of array attributes (each attribute can have an arbitrary
164  /// number of entries. By default, the array attribute evaluators set the
165  /// arrays to a size of 0 and return the storage array.
166  const UT_ValArray<int32> *attribVal(int attrib,
167  BRAYtime time,
168  const Hit &hit_info,
170  int size) const final override;
171  const UT_ValArray<int64> *attribVal(int attrib,
172  BRAYtime time,
173  const Hit &hit_info,
175  int size) const final override;
176  const UT_ValArray<fpreal32> *attribVal(int attrib,
177  BRAYtime time,
178  const Hit &hit_info,
180  int size) const final override;
181  const UT_ValArray<fpreal64> *attribVal(int attrib,
182  BRAYtime time,
183  const Hit &hit_info,
185  int size) const final override;
186  const UT_StringArray *attribVal(int attrib,
187  BRAYtime time,
188  const Hit &hit_info,
190  int size) const final override;
191  /// @}
192 
193 private:
194  Scene myScene;
195  const BRAY_AttribList *myAttribs;
196  bool myValid;
197 };
198 
199 #endif
void bounds(UT_BoundingBox &bounds, BRAYtime time) const override
Fills the given bounding box.
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2540
BRAY_AttribList::AttributeOwner myOwner
int int32
Definition: SYS_Types.h:39
Derive the SceneHit so we can pass around the hit instance.
float BRAYtime
Consistent representation of time type within BRAY.
Definition: BRAY_Types.h:670
GT_API const UT_StringHolder time
const BRAY_ProceduralFactory * factory() const
Return the factory definition.
float fpreal32
Definition: SYS_Types.h:200
void doBeginUpdate() override
HitPtr intersect(const Ray32 &ray) const finaloverride
double fpreal64
Definition: SYS_Types.h:201
virtual void update(BRAY_EventType event)=0
This method can be used to be notified of changes to the object.
GLboolean reset
Definition: glad.h:5138
long long int64
Definition: SYS_Types.h:116
HitPtr intersect(const Ray64 &ray) const finaloverride
HitPtr newHit() const finaloverride
bool checkIsValid() const override
Check to see whether the procedural is valid.
const BRAY::ScenePtr & scene() const
GLsizeiptr size
Definition: glcorearb.h:664
Each BRAY_Object can define a list of attributes that it can evaluate.
virtual ~BRAY_ProceduralScene() override
IMATH_CONSTEXPR14 bool intersect(const Line3< T > &line, const Vec3< T > &v0, const Vec3< T > &v1, const Vec3< T > &v2, Vec3< T > &pt, Vec3< T > &barycentric, bool &front) IMATH_NOEXCEPT
Definition: ImathLineAlgo.h:80
#define BRAY_API
Definition: BRAY_API.h:12
const BRAY_AttribList * attribList() const override
Get the attribute list.
#define const
Definition: zconf.h:214
BRAY::ScenePtr & scene()
Get the underlying ScenePtr.
Wrapper around BRAY::ScenePtr.
const BRAY::ScenePtr & scene() const
BRAY::ScenePtr & scene()
Get the underlying ScenePtr.
virtual void doSetParameter(const UT_StringRef &key, const int32 *values, int n=1)=0