HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BRAY_Interface.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_Interface.h (BRAY Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __BRAY_Interface__
12 #define __BRAY_Interface__
13 
14 #include "BRAY_API.h"
15 #include <UT/UT_Array.h>
16 #include <UT/UT_StringHolder.h>
17 #include <UT/UT_StringArray.h>
18 #include <UT/UT_NonCopyable.h>
19 #include <UT/UT_Options.h>
20 #include <UT/UT_SharedPtr.h>
21 #include <UT/UT_IntrusivePtr.h>
22 #include <UT/UT_UniquePtr.h>
23 #include <UT/UT_Rect.h>
24 #include <UT/UT_Set.h>
25 #include <UT/UT_Map.h>
26 #include <UT/UT_VectorTypes.h>
27 #include <GT/GT_Handles.h>
28 #include <GT/GT_DataArray.h>
29 #include <PXL/PXL_Common.h>
30 #include "BRAY_Types.h"
31 #include "BRAY_Stats.h"
32 
33 // Classes referenced by the interface
34 class BRAY_Procedural;
36 class BRAY_AOVBuffer;
37 class BRAY_Camera;
38 class BRAY_Object;
39 class BRAY_Renderer;
40 class BRAY_Light;
41 class BRAY_Scene;
42 class BRAY_ShaderGraph;
43 class BRAY_ShaderInstance;
44 class BRAY_VexMaterial;
45 class VPRM_Space;
46 class VPRM_OptionSet;
47 class UT_JSONWriter;
48 
51 
52 namespace BRAY
53 {
54 
55 class CameraPtr;
56 class CoordSysPtr;
57 class LightPtr;
58 class MaterialPtr;
59 class ObjectPtr;
60 class RendererPtr;
61 class ScenePtr;
62 class ShaderGraphPtr;
63 
65 {
66 public:
67  SpacePtr();
68  SpacePtr(const VPRM_SpacePtr &s);
69  SpacePtr(const SpacePtr &s);
70  SpacePtr(const UT_Matrix4D &xforms);
71  SpacePtr(const UT_Matrix4D *xforms, size_t num_motion_segments);
72  ~SpacePtr();
73  SpacePtr &operator=(const SpacePtr &s);
74 
75  /// @{
76  /// Private access
77  bool isValid() const { return mySpace.get() != nullptr; }
78  VPRM_SpacePtr &space() { return mySpace; }
79  const VPRM_SpacePtr &space() const { return mySpace; }
80  /// @}
81  /// Bool operator to test validity of pointer
82  SYS_SAFE_BOOL operator bool() const { return isValid(); }
83 
84  /// Multiply by the given space (i.e. this * sp)
85  SpacePtr mulSpace(const SpacePtr &sp) const;
86 
87  /// Return the number of motion segments
88  int motionSegments() const;
89  UT_Matrix4D getTransform(int segment) const;
90  void getTransform(UT_Matrix4D &x, BRAYtime shutter) const;
91  void dump() const;
92  void dump(UT_JSONWriter &w) const;
93 private:
94  VPRM_SpacePtr mySpace;
95 };
96 
97 /// The OptionSet acts as a pointer to an underlying set of options for various
98 /// different object types.
100 {
101 public:
102  OptionSet();
103  /// The copy c-tor will copy the underlying pointer, but refer to the same
104  /// underlying object.
105  OptionSet(const OptionSet &src);
106  explicit OptionSet(const VPRM_OptionSetPtr &o);
107  ~OptionSet();
108 
109  /// The assignment operator will change the pointer to the underlying
110  /// object. Both OptionSets will point to the same underlying object.
111  OptionSet &operator=(const OptionSet &o);
112 
113  /// This will create a new OptionSet, inheriting state information from the
114  /// this option set. Note that changing values in the this set @b may
115  /// result in unexpected changes in the new option set.
116  OptionSet duplicate() const;
117 
118  /// Returns true if property can be erased to revert back to default value.
119  /// If the options aren't inherited (i.e. offline render), it cannot be
120  /// erased.
121  bool canErase(int token) const;
122 
123  /// Erase properties
124  void erase(const UT_Set<int> &tokens);
125 
126  /// @{
127  /// Private access
128  bool isValid() const { return myOptions.get() != nullptr; }
129  VPRM_OptionSetPtr &options() { return myOptions; }
130  const VPRM_OptionSetPtr &options() const { return myOptions; }
131  /// @}
132  /// Bool operator to test validity of pointer
133  SYS_SAFE_BOOL operator bool() const { return isValid(); }
134 
135  /// Return the number of pre-defined properties in the option set
136  exint numProperties() const;
137 
138  /// Return the name associated with a given option (i.e. dicingquality)
139  const UT_StringHolder &name(int token) const;
140 
141  /// Return the fully qualified name (i.e. karma::object::dicingquality)
142  UT_StringHolder fullName(int token) const;
143 
144  /// Return the token associated with a given name (or -1 if invalid)
145  int find(const UT_StringRef &name) const;
146 
147  /// Import a property value. Method is specialized for T in:
148  /// - bool
149  /// - int32/int64
150  /// - fpreal32/fpreal64
151  /// - UT_StringHolder
152  template <typename T>
153  const T *import(int token, T *val, size_t n) const;
154 
155  /// Interface to set an property. This template class is specialized for:
156  /// - bool
157  /// - int32
158  /// - int64
159  /// - fpreal32
160  /// - fpreal64
161  /// - UT_StringHolder
162  template <typename T>
163  bool set(int token, const T *value, exint tuple_size);
164 
165  /// Simple interface to set a scalar property
166  template <typename T>
167  SYS_FORCE_INLINE bool set(int token, const T &value)
168  {
169  return set(token, &value, 1);
170  }
171 
172  /// Test whether a value is the same as the current property
173  template <typename T>
174  bool isEqual(int token, const T *value, exint tuple_size) const;
175 
176  /// Simple interface for equality of a scalar value.
177  template <typename T>
178  SYS_FORCE_INLINE bool isEqual(int token, const T &value) const
179  {
180  return isEqual(token, &value, 1);
181  }
182 
183  /// Test whether an option has variadic arguments
184  bool isVariadic(int token) const;
185 
186  /// Return the size of an option. This can be used for variadics
187  exint size(int token) const;
188 
189  /// Return the storage of an option. This will only be one of:
190  /// - GT_STORE_INVALID
191  /// - GT_STORE_UINT8 (for bool storage)
192  /// - GT_STORE_INT64
193  /// - GT_STORE_REAL64
194  /// - GT_STORE_STRING
195  GT_Storage storage(int token) const;
196 
197  /// @{
198  /// Direct access to internal option data. There are no checks on these
199  /// methods
200  const bool *bval(int token) const;
201  const int64 *ival(int token) const;
202  const fpreal64 *fval(int token) const;
203  const UT_StringHolder *sval(int token) const;
204  /// @}
205 
206  /// @private Debug the options (only available in debug builds)
207  void dump(UT_JSONWriter &w) const;
208 
209 private:
210  VPRM_OptionSetPtr myOptions;
211 };
212 
213 /// When defining materials for face sets, the material specification is
214 /// given by a pair of the @c MaterialPtr and an array of integers. The
215 /// integers specify the list of faces to material and must appear in
216 /// sorted order (smallest to largest).
217 /// Interface to the scene manager
219 {
220 public:
221  ScenePtr() = default;
222  ~ScenePtr();
223 
224  /// Allocate a new scene
225  static ScenePtr allocScene();
226 
227  /// Force an exit when there's a failed license check failure. The normal
228  /// behaviour is to render a black image.
229  static void setExitOnFailedLicense(bool state=true);
230 
231  /// Check to see whether a rendering engine is supported
232  static bool isEngineSupported(const UT_StringRef &name);
233 
234  /// convenience methods to determine which renderer is active (tests
235  /// the value of the BRAY_OPT_ENGINE option)
236  bool isKarmaCPU() const;
237  bool isKarmaXPU() const;
238 
239  /// Start edits/loading of the scene
240  void startEdits(BRAY::RendererPtr &renderer);
241 
242  /// Test validity
243  bool isValid() const { return myScene.get() != nullptr; }
244 
245  /// Test whether the scene is thread-safe
246  bool threadSafe() const;
247 
248  /// Test whether the renderer supports nested instancing
249  bool nestedInstancing() const;
250 
251  /// Update an object in the scene
252  void updateObject(const ObjectPtr &ptr, BRAY_EventType event);
253 
254  /// Update light object in the scene
255  void updateLight(const LightPtr &ptr, BRAY_EventType event);
256 
257  /// Update camera object in the scene
258  void updateCamera(const CameraPtr &ptr, BRAY_EventType event);
259 
260  /// Update material object in the scene
261  void updateMaterial(const MaterialPtr &ptr, BRAY_EventType event);
262 
263  /// Update coord sys object
264  void updateCoordSys(const CoordSysPtr &ptr, BRAY_EventType event);
265 
266  /// @{
267  /// Set the unit scale for the scene - this is in meters/unit. For
268  /// example, centimeters would be 0.01.
269  void setSceneUnits(fpreal64 units);
270  fpreal64 sceneUnits() const;
271  /// @}
272 
273  /// Forcibly save checkpoint as soon as possible (if checkpointing is enabled)
274  void saveCheckpointASAP();
275 
276  /// Set camera ray visibility. The mask should be a combination of
277  /// - BRAY_RAY_CAMERA
278  /// - BRAY_PROXY_CAMERA
279  /// - BRAY_GUIDE_CAMERA
280  /// For example, (BRAY_RAY_CAMERA|BRAY_GUIDE_CAMERA) will cause guide and
281  /// renderable object to be visible to camera rays, but not proxy objects
282  void setCameraRayMask(BRAY_RayVisibility mask);
283 
284  /// Set shadow ray visibility. The mask should be a combination of
285  /// - BRAY_RAY_SHADOW
286  /// - BRAY_PROXY_SHADOW
287  /// - BRAY_GUIDE_SHADOW
288  /// For example, (BRAY_RAY_SHADOW|BRAY_PROXY_SHADOW) will cause proxy and
289  /// renderable object to cast shadows, but not GUIDE objects.
290  void setShadowRayMask(BRAY_RayVisibility mask);
291 
292  /// Force redicing of displacement and subd surfaces on the next render.
293  /// This will only take effect on the next call to beginRender().
294  void forceRedice();
295 
296  /// @{
297  /// Private access to the underling scene
298  SYS_SAFE_BOOL operator bool() const { return isValid(); }
299  const BRAY_Scene *scenePtr() const { return myScene.get(); }
300  BRAY_Scene *scenePtr() { return myScene.get(); }
301  /// @}
302 
303  /// After changing any options, must commit prior to rendering
304  void commitOptions();
305 
306  /// @{
307  /// Grab a copy of the current scene options
308  OptionSet sceneOptions();
309  const OptionSet constSceneOptions() const;
310  /// @}
311 
312  /// @{
313  /// Grab a copy of the current object properties.
314  OptionSet objectProperties();
315  const OptionSet constObjectProperties() const;
316  /// @}
317 
318  /// @{
319  /// Grab a copy of the current light properties
320  OptionSet lightProperties();
321  const OptionSet constLightProperties() const;
322 
323  /// @{
324  /// Grab a copy of the current camera properties
325  OptionSet cameraProperties();
326  const OptionSet constCameraProperties() const;
327  /// @}
328 
329  /// Grab a copy of the current image plane properties
330  OptionSet planeProperties();
331  const OptionSet constPlaneProperties() const;
332  /// @}
333 
334  /// Grab a the default properties for a given type. Changing their values
335  /// will cause all future objects created to inherit the new values.
336  OptionSet defaultProperties(BRAY_PropertyType type) const;
337 
338  /// @{
339  /// Convenience methods to look up scene and scene options.
340  /// Get an scene option value.
341  template <typename T>
343  T *val, size_t n) const
344  {
345  return constSceneOptions().import(token, val, n);
346  }
347 
348  /// Interface to set an option. This template class is specialized for:
349  template <typename T>
351  const T *value,
352  exint tuple_size)
353  {
354  return sceneOptions().set(token, value, tuple_size);
355  }
356 
357  /// Simple interface to set a scalar option
358  template <typename T>
359  SYS_FORCE_INLINE bool
361  {
362  return setOption(token, &value, 1);
363  }
364 
365  /// Return the size of an option. This can be used for variadics
366  /// (e.g. shading quality will be 1)
368  {
369  return constSceneOptions().size(token);
370  }
371 
372  /// Return the storage class of an option.
375  {
376  return constSceneOptions().storage(token);
377  }
378 
379  /// Return whether an option has variadic arguments
380  SYS_FORCE_INLINE bool
382  {
383  return constSceneOptions().isVariadic(token);
384  }
386  { return *constSceneOptions().bval(t); }
388  { return *constSceneOptions().ival(t); }
390  { return *constSceneOptions().fval(t); }
392  { return *constSceneOptions().sval(t); }
393  /// @}
394 
395  /// @{
396  /// Convenience methods to look up object properties.
397  /// Get an object property value.
398  template <typename T>
400  T *val, size_t n) const
401  {
402  return constObjectProperties().import(token, val, n);
403  }
404 
405  /// Interface to set an property. This template class is specialized for:
406  template <typename T>
408  const T *value,
409  exint tuple_size)
410  {
411  return objectProperties().set(token, value, tuple_size);
412  }
413 
414  /// Locking the object property prevents any overriding of the property
415  /// after the fact, essentially turning the property into a read-only
416  /// property. This method is intended to lock default properties. The
417  /// current value of the property is used as the value.
418  ///
419  /// The return value is the previous lock state of the property.
420  bool lockProperty(BRAY_ObjectProperty token, bool state);
421 
422  /// Lock properties based on a string pattern of parameter names. This
423  /// method returns the number of properties modified.
424  exint lockProperties(const char *pattern, bool state);
425 
426  /// Lock or unlock all object properties.
428  { return lockProperties("*", state); }
429 
430  /// Simple interface to set a scalar property
431  template <typename T>
432  SYS_FORCE_INLINE bool
434  {
435  return setProperty(token, &value, 1);
436  }
437 
438  /// Return the size of an option. This can be used for variadics
439  /// (e.g. shading quality will be 1)
441  {
442  return constObjectProperties().size(token);
443  }
444 
445  /// Return the storage class of an option.
448  {
449  return constObjectProperties().storage(token);
450  }
451 
452  /// Return whether an property has variadic arguments
453  SYS_FORCE_INLINE bool
455  {
456  return constObjectProperties().isVariadic(token);
457  }
459  { return *constObjectProperties().bval(t); }
461  { return *constObjectProperties().ival(t); }
463  { return *constObjectProperties().fval(t); }
465  { return *constObjectProperties().sval(t); }
466  /// @}
467 
468  /// Create a light
469  LightPtr createLight(const UT_StringHolder &name);
470 
471  /// Create a camera
472  CameraPtr createCamera(const UT_StringHolder &name);
473 
474  /// Create a coordinate system
475  CoordSysPtr createCoordSys(const UT_StringHolder &name);
476 
477  /// Create a material
478  MaterialPtr createMaterial(const UT_StringHolder &name);
479 
480  /// Create an object given a GT_Primitive handle.
481  /// At the current time, the only classes supported are:
482  /// - GT_PrimPolygonMesh
483  /// - GT_PrimSubdivisionMesh
484  /// - GT_PrimCurveMesh
485  /// - GT_PrimPointMesh
486  /// The method will return a nullptr if it can't create a primitive
487  ObjectPtr createGeometry(const GT_PrimitiveHandle &prim);
488 
489  /// For polygonal meshes, use this to create geometry to handle holes
490  ObjectPtr createGeometry(const GT_PrimitiveHandle &prim,
491  const GT_DataArrayHandle &holes);
492 
493  /// Create a volume given its detail attribute and the names and
494  /// GT_PrimitiveHandles of the corresponding fields in the volume
495  ObjectPtr createVolume(const UT_StringHolder &name);
496 
497  /// Create an instance of an object
499  const UT_StringHolder &name);
500 
501  /// Create a nested scene graph
502  ObjectPtr createScene();
503 
504  /// Create a procedural object.
505  /// Ownership of the procedural is passed to the object.
506  ObjectPtr createProcedural(UT_UniquePtr<BRAY_Procedural> proc);
507 
508  /// Find a material.
509  MaterialPtr findMaterial(const UT_StringRef &name) const;
510 
511  /// Destroy/Delete a material (returns false if material wasn't found)
512  bool destroyMaterial(const UT_StringRef &name);
513 
514  /// Add traceset name to global list (categories on objects that do not
515  /// belong to this list will be ignored)
516  /// Returns true if added, false if already exists.
517  bool addTraceset(const UT_StringHolder &name);
518 
519  /// Check to see if a traceset exists.
520  bool isTraceset(const UT_StringHolder &name);
521 
522  /// Create a shader nodegraph
523  ShaderGraphPtr createShaderGraph(const UT_StringHolder &name);
524 
525  /// Load an HDA to define shader code. Not all applications support this
526  /// feature.
527  bool loadHDA(const char *path);
528 
529 private:
530  UT_SharedPtr<BRAY_Scene> myScene;
531 };
532 
533 /// Input connector for materials. This defines the name of the geometry
534 /// attribute (@c myInputName) to bind to the VEX shader parameter (@c myParmName)
536 {
537  enum class Storage
538  {
539  FLOAT,
540  INTEGER,
541  STRING
542  };
544  const UT_StringHolder &shader_parm,
545  Storage store,
546  int tsize,
547  bool is_array)
548  : myGeometry(primvar)
549  , myParmName(shader_parm)
550  , myStorage(store)
551  , myTupleSize(tsize)
552  , myIsArray(is_array)
553  {
554  }
555 
556  UT_StringHolder myGeometry; // Input name (primvar name)
557  UT_StringHolder myParmName; // Parameter Name (VEX parameter name)
558  Storage myStorage; // Base storage type
559  int myTupleSize; // Element tuple size
560  bool myIsArray; // Whether parameter is an array
561 };
562 
564 
565 /// Interface to scene materials
567 {
568 public:
569  MaterialPtr(BRAY_VexMaterial *mat = nullptr)
570  : myMat(mat)
571  {
572  }
574 
575  bool isValid() const { return myMat != nullptr; }
576 
577  /// @{
578  /// Access to the underling material
579  SYS_SAFE_BOOL operator bool() const { return isValid(); }
580  const BRAY_VexMaterial *materialPtr() const { return myMat; }
581  /// @}
582 
583  /// Update the surface shader and arguments
584  void updateSurface(const ScenePtr &scene,
585  const UT_StringArray &arguments);
586  /// Update the displacement shader and arguments
587  /// Returns true if arguments changed.
588  bool updateDisplace(ScenePtr &scene,
589  const UT_StringArray &arguments);
590 
591  /// Update surface shader VEX code. The @c preload flag is used when other
592  /// shaders in the network might depend on the code being updated.
593  void updateSurfaceCode(const ScenePtr &scene,
594  const UT_StringHolder &name,
595  const UT_StringRef &code,
596  bool preload=false);
597  /// Update displacement shader VEX code The @c preload flag is used when
598  /// other shaders in the network might depend on the code being updated.
599  /// Returns true if the name or the code changed.
600  bool updateDisplaceCode(const ScenePtr &scene,
601  const UT_StringHolder &name,
602  const UT_StringRef &code,
603  bool preload=false);
604 
605  /// Update the surface shader graph
606  void updateSurfaceGraph(const ScenePtr &scene,
607  const UT_StringHolder &name,
608  const ShaderGraphPtr &graphptr);
609  /// Update the displacement shader graph
610  /// Returns true if the name or the code changed.
611  bool updateDisplaceGraph(ScenePtr &scene,
612  const UT_StringHolder &name,
613  const ShaderGraphPtr &graphptr);
614 
615  /// Set the material input list
616  void setInputs(const ScenePtr &scene,
617  const MaterialInputList &inputs,
618  bool for_surface);
619 
620  /// Set the mapping for transform space aliases. This allows shaders to
621  /// reference a simple space name rather than the fully qualified path to
622  /// the space (e.g. "paintSpace" instead of "/World/Obj/PaintObj/Xform")
623  void setCoordSysAliases(const ScenePtr &scene,
625 
626 private:
627  BRAY_VexMaterial *myMat;
628 };
629 
631 {
633  const MaterialPtr &material = MaterialPtr())
634  : myFaceList(facelist)
635  , myMaterial(material)
636  {
637  }
640 };
641 
643 {
644 public:
645  ObjectPtr() = default;
646  ~ObjectPtr();
647 
648  /// Test validity
649  bool isValid() const { return myObject != nullptr; }
650 
651  /// Query if object is a leaf node (ie not scenegraph or instance)
652  bool isLeaf() const;
653 
654  /// @{
655  /// Access to the underlying object
656  SYS_SAFE_BOOL operator bool() const { return isValid(); }
657  const BRAY_Object *objectPtr() const { return myObject.get(); }
658  BRAY_Object *objectPtr() { return myObject.get(); }
659  /// @}
660 
661  /// Bind a material to the object. The method will fail if the underlying
662  /// object cannot set the material.
663  bool setMaterial(ScenePtr &scene,
664  const MaterialPtr &mat,
665  const OptionSet &opts,
666  exint nfacesets=0,
667  const FacesetMaterial *faceset_mat=nullptr);
668 
669  /// Set the prototype for an instance object
670  void setInstancePrototype(const ObjectPtr &proto);
671 
672  /// Set the transform on the instance
673  void setInstanceTransforms(ScenePtr &scene,
674  const UT_Array<SpacePtr> &xforms);
675 
676  /// Set attributes on instances
677  void setInstanceAttributes(const ScenePtr &scene,
678  const GT_AttributeListHandle &alist);
679 
680  /// Set property overrides for instances. The array must have an entry for
681  /// every instance. It's possible to have default options. Each
682  /// attribute's name should match an object property name. Warnings will
683  /// be output if an attribute doesn't match.
684  void setInstanceProperties(const ScenePtr &scene,
685  const GT_AttributeListHandle &alist);
686 
687  /// Set instance IDs. If not set (or given an empty array), it is assumed
688  /// that the ids are contiguous 0...N-1 where N is the number of xforms.
689  void setInstanceIds(UT_Array<exint> ids);
690 
691  /// Add an object to a scene
692  void addInstanceToScene(ObjectPtr &obj);
693 
694  /// Check to make sure that number of xforms, attribute list, ids all match
695  bool validateInstance() const;
696 
697  /// @{
698  /// This will return the object's base properties, or the scene defaults if
699  /// the object isn't defined yet.
700  OptionSet objectProperties(ScenePtr &scene);
701  const OptionSet objectProperties(const ScenePtr &scene) const;
702  /// @}
703 
704  /// Get the underlying GT_PrimitiveHandle (if possible). This method may
705  /// return a nullptr.
706  GT_PrimitiveHandle geometry() const;
707 
708  /// Pointer to the contained procedural. This may return a nullptr.
709  BRAY_Procedural *procedural();
710 
711  /// Update the geometry for the object. The method will fail if you're
712  /// trying to change the underlying primitive type.
713  bool setGeometry(const ScenePtr &scene,
714  const GT_PrimitiveHandle &prim);
715 
716  /// Set the list of "holes" for a polygon mesh (subdivision meshes have the
717  /// list of holes specified in the subdivision tags).
718  bool setGeometry(const ScenePtr &scene,
719  const GT_PrimitiveHandle &prim,
720  const GT_DataArrayHandle &holes);
721 
722  /// Update volume fields. This method will fail if the underlying
723  /// primitive isn't a volume (see createVolume())
725  bool setVolume(const ScenePtr &scene,
726  const GT_AttributeListHandle &clist,
727  const FieldList& fields);
728 
729  /// Return the detail attributes for a volume primitive
730  const GT_AttributeListHandle &volumeDetailAttributes() const;
731 
732  /// TODO: Deprecate this
733  void takeOwnership(BRAY_Object *obj);
734 
735 protected:
737  friend class ScenePtr;
738 };
739 
741 {
742 public:
744  : myLight(lp)
745  {
746  }
747  ~LightPtr();
748 
749  /// Test validity
750  bool isValid() const { return myLight != nullptr; }
751 
752  /// @{
753  /// Access to the underlying object
754  SYS_SAFE_BOOL operator bool() const { return isValid(); }
755  const BRAY_Light *lightPtr() const { return myLight.get(); }
756  BRAY_Light *lightPtr() { return myLight.get(); }
757  /// @}
758 
759  /// Return the type of light
760  BRAY_LightType type() const;
761 
762  /// Set the transform on the instance
763  void setTransform(const SpacePtr &xforms);
764 
765  /// Set the shader for the light
766  void setShader(const ScenePtr &scene, const UT_StringArray &args);
767 
768  /// Get the current object properties for modification.
769  OptionSet objectProperties();
770 
771  /// Get the current light properties for modification.
772  OptionSet lightProperties();
773 
774  /// After changing any options, must lock prior to rendering
775  void commitOptions(ScenePtr &scene);
776 
777  /// Update the light shader graph
778  void updateShaderGraph(const ScenePtr &scene,
779  const ShaderGraphPtr &graphptr,
780  const UT_Array<ShaderGraphPtr> &light_filters);
781 
782  /// If a light filter has been modified, this method should be called to
783  /// notify the light. The set should contain the names of the dirty light
784  /// filter shader graphs.
785  void updateFilters(const ScenePtr &scene,
786  const UT_Array<ShaderGraphPtr> &filters);
787 
788  /// Notify the light that a filter has been deleted
789  void eraseFilter(const ScenePtr &scene,
790  const UT_StringRef &shader_graph_name);
791 
792 protected:
794 };
795 
797 {
798 public:
800  : myCamera(cp)
801  {
802  }
803  ~CameraPtr();
804 
805  /// Test validity
806  bool isValid() const { return myCamera != nullptr; }
807 
808  /// @{
809  /// Access to the underlying object
810  SYS_SAFE_BOOL operator bool() const { return isValid(); }
811  const BRAY_Camera *cameraPtr() const { return myCamera.get(); }
812  BRAY_Camera *cameraPtr() { return myCamera.get(); }
813  /// @}
814 
815  /// Set the transform on the camera
816  void setTransform(ScenePtr &ptr, const SpacePtr &xforms);
817 
818  /// Set the lens shader for the camera
819  void setShader(const ScenePtr &scene, const UT_StringArray &args);
820 
821  /// Get the current object properties for modification.
822  OptionSet objectProperties();
823 
824  /// Set number of motion samples for animated camera properties (1 upon
825  /// construction). The last motion sample is assumed to have time offset of
826  /// 1.0. (eg. if there are 3 samples, the time offsets are: 0, 0.5, 1.0)
827  void resizeCameraProperties(int nseg);
828 
829  /// Get the current camera properties for modification.
830  UT_Array<OptionSet> cameraProperties();
831 
832  /// After changing any options, must lock prior to rendering
833  void commitOptions(ScenePtr &scene);
834 
835 protected:
837 
838 };
839 
841 {
842 public:
844  : mySpace(sp)
845  {
846  }
847  ~CoordSysPtr();
848 
849  /// Test validity
850  bool isValid() const { return mySpace != nullptr; }
851 
852 
853  /// @{
854  /// Access to underlying object
855  SYS_SAFE_BOOL operator bool() const { return isValid(); }
856  const BRAY_Camera *spacePtr() const { return mySpace.get(); }
857  BRAY_Camera *spacePtr() { return mySpace.get(); }
858  /// @}
859 
860  const UT_StringHolder &name() const;
861 
862  /// Set transform
863  void setTransform(ScenePtr &scn, const SpacePtr &xforms);
864 
865  /// The current object properties for modification (primarily for motion
866  /// blur settings)
867  OptionSet objectProperties();
868 
869  /// When a transform space has camera properties (for projection spaces),
870  /// it's possible the projection can be motion blurred. This allows you to
871  /// specify the motion segments for properties.
872  void resizeCameraProperties(int nseg);
873 
874  /// Get the current camera properties for modification
875  UT_Array<OptionSet> cameraProperties();
876 
877  /// After changing options, make sure to commit
878  void commit(ScenePtr &scene);
879 
880 private:
882 };
883 
885 {
886 public:
887  AOVBufferPtr() = default;
888 
890  : myAOVBuffer(aov)
891  {}
892 
894 
895  bool operator==(const AOVBufferPtr &aov) const
896  { return aov.myAOVBuffer == myAOVBuffer; }
897  bool operator!=(const AOVBufferPtr &aov) const
898  { return !(*this == aov); }
899 
900  const UT_StringHolder &getName() const;
901  const UT_StringHolder &getVariable() const;
902 
903  int getXres() const;
904  int getYres() const;
905  PXL_DataFormat getFormat() const;
906  PXL_Packing getPacking() const;
907  float getDefaultValue() const;
908 
909  void *map();
910  void unmap();
911  bool isMapped() const;
912 
913  // For extra channels
914  int getNumExtra() const;
915  const UT_StringHolder &nameExtra(int idx) const;
916  PXL_DataFormat getFormatExtra(int idx) const;
917  PXL_Packing getPackingExtra(int idx) const;
918  void *mapExtra(int idx);
919  void unmapExtra(int idx);
920 
921  // metadata to write to header of output file
922  const UT_Options &getMetadata() const;
923 
924  bool isConverged() const;
925  void setConverged();
926  void clearConverged();
927 
928  // Valid only after raster is allocated (ie render started)
929  bool isValid() const;
930 
931  SYS_SAFE_BOOL operator bool() const { return isValid(); }
932 
933 private:
934  UT_SharedPtr<BRAY_AOVBuffer> myAOVBuffer;
935 };
936 
937 /// A render product represents an output file
939 {
940 public:
941  // Test whether the type is understook by karma
942  // For example "karma:checkpoint"
943  static bool isKnownType(const UT_StringRef &type);
944 
945  // Clear all existing output files
946  static void clearFiles(BRAY::ScenePtr &scene);
947 
948  struct BRAY_API AOV
949  {
951  : myName(name)
952  {
953  }
954  /// Method is specialized for T in:
955  /// - bool
956  /// - int32/int64
957  /// - fpreal32/fpreal64
958  /// - UT_StringHolder
959  template <typename T>
960  bool setOption(const UT_StringHolder &name,
961  const T *value,
962  exint size);
963  template <typename T>
964  bool setOption(const UT_StringHolder &name, const T &value)
965  { return setOption(name, &value, 1); }
966 
967  /// Copy over options from those passed in
968  bool setOptions(const UT_Options &options);
969 
970  const UT_StringHolder &name() const { return myName; }
971  const UT_Options &options() const { return myOptions; }
972 
973  /// Dump method for debugging
974  void dump(UT_JSONWriter &w) const;
975  private:
976  UT_StringHolder myName;
977  UT_Options myOptions;
978  };
980  const UT_StringHolder &filename,
981  const UT_StringHolder &type)
982  : myScene(scene)
983  , myFilename(filename)
984  , myType(type)
985  {
986  }
987 
989  {
990  if (myFilename)
991  commit();
992  }
993 
994  /// @{
995  /// Method is specialized for T in:
996  /// - bool
997  /// - int32/int64
998  /// - fpreal32/fpreal64
999  /// - UT_StringHolder
1000  template <typename T>
1001  bool setOption(const UT_StringHolder &name,
1002  const T *value,
1003  exint size);
1004  template <typename T>
1005  bool setOption(const UT_StringHolder &name, const T &value)
1006  { return setOption(name, &value, 1); }
1007  /// @}
1008 
1009  /// Copy over options from those passed in
1010  bool setOptions(const UT_Options &options);
1011 
1012  /// Add an AOV to this output file
1014  {
1015  myAOVs.emplace_back(name);
1016  return myAOVs.last();
1017  }
1018 
1019  /// Commit and add this output file to the render
1020  bool commit()
1021  {
1022  bool result = doCommit();
1023  cancel(); // Once committed, no more changes
1024  return result;
1025  }
1026  /// Cancel this output file for some reason
1027  void cancel() { myFilename.clear(); }
1028 
1029  /// Access member data
1030  const UT_StringHolder &filename() const { return myFilename; }
1031  const UT_StringHolder &type() const { return myType; }
1032  const UT_Array<AOV> &aovs() const { return myAOVs; }
1033  const UT_Options &options() const { return myOptions; }
1034 
1035  /// @{
1036  /// Dump information (used by karma:debug)
1037  void dump() const;
1038  void dump(UT_JSONWriter &w) const;
1039  /// @}
1040 
1041 private:
1042  bool doCommit();
1043  BRAY::ScenePtr &myScene;
1044  UT_StringHolder myFilename;
1045  UT_StringHolder myType;
1046  UT_Array<AOV> myAOVs;
1047  UT_Options myOptions;
1048 };
1049 
1050 
1051 /// Interface to the renderer
1053 {
1054 public:
1055  /// Class used to define image planes
1056  struct ImagePlane
1057  {
1060  int mySize;
1063  };
1064 
1065  RendererPtr() = default;
1067 
1068  /// Allocate renderer
1069  static RendererPtr allocRenderer(BRAY::ScenePtr &sceneptr);
1070 
1071  SYS_SAFE_BOOL operator bool() const { return myRenderer.get(); }
1072 
1073  /// @{
1074  /// Define image planes for rendering
1075  void clearOutputPlanes();
1076  AOVBufferPtr addOutputPlane(const ImagePlane &plane);
1077  int getAOVCount() const;
1078  /// @}
1079 
1080  /// Access the stats for this render
1081  const BRAY::Stats &stats() const;
1082 
1083  /// Call before rendering begins. This lets the renderer prepare data
1084  /// structures before render() is called. For example, this will ensure
1085  /// all AOV buffers are allocated and active. The method returns false if
1086  /// there were errors setting up the render.
1087  bool prepareRender();
1088 
1089  /// Start rendering a scene
1090  void render(bool (*stopreq)(void *) = nullptr, void *data = nullptr);
1091 
1092  /// Test to see whether the current renderer is active
1093  bool isRendering() const;
1094 
1095  /// Test to see if there was an error rendering
1096  bool isError() const;
1097 
1098  /// Test to see if the renderer is paused
1099  bool isPaused() const;
1100 
1101  /// Tells the renderer to prepare to be stopped
1102  void prepareForStop();
1103 
1104  /// Pause rendering -- Returns true if the renderer is paused
1105  bool pauseRender();
1106 
1107  /// Restart rendering -- Returns true if @c isRendering();
1108  bool resumeRender();
1109 
1110  /// Set a point in the image to give priority to rendering
1111  void setPriority(int x, int y);
1112 
1113  /// Set a region in the image which should have priority
1114  void setPriority(const UT_DimRect &region);
1115 
1116  /// Clear the priority focus
1117  void clearPriority();
1118 
1119  /// Enables image filters by the given option.
1120  /// The is_render_settings_prim indicates whether the filter
1121  /// belongs to render settings prim or the display options.
1122  bool enableImageFilters(
1123  const UT_StringHolder &filters_opt,
1124  bool is_render_settings_prim);
1125 
1126  /// Set whether to use render settings prim or display options.
1127  void setUseRenderSettingsPrim(bool use_render_settings_prim);
1128 
1129  /// @private method
1130  BRAY_Renderer *renderer() { return myRenderer.get(); }
1131 
1132 private:
1133  UT_SharedPtr<BRAY_Renderer> myRenderer;
1134 };
1135 
1137 {
1138 public:
1140  : myGraph(graph)
1141  {}
1143 
1144  /// Make new node based on type and add to list of nodes in the current
1145  /// graph. Returns NULL if unknown type.
1146  /// Note that the root node (ie with surface/displace output) must be the
1147  /// first node added to the graph.
1148  BRAY_ShaderInstance *createNode(const UT_StringHolder &type,
1149  const UT_StringHolder &name);
1150 
1151  /// Returns OptionSet that contains input parameters for given shader node.
1152  /// Can be used to read and write values.
1153  OptionSet nodeParams(BRAY_ShaderInstance *node);
1154 
1155  /// Make connection between two nodes
1156  bool wireNodes(const UT_StringHolder &srcnode,
1157  const UT_StringHolder &srcoutput,
1158  const UT_StringHolder &dstnode,
1159  const UT_StringHolder &dstinput);
1160 
1161  // Definition of a shader node
1162  class NodeDecl
1163  : UT_NonCopyable
1164  {
1165  public:
1168  : myName(n)
1169  {
1170  }
1171 
1172  struct Parameter
1173  {
1174  UT_StringHolder myName; // Name of parameter
1175 
1176  bool isBool() const { return myType == 0; }
1177  bool isInt() const { return myType == 1; }
1178  bool isReal() const { return myType == 2; }
1179  bool isFloat() const { return myType == 2; }
1180  bool isString() const { return myType == 3; }
1181  bool isVariadic() const { return myVariadic; }
1182 
1183  exint size() const
1184  {
1185  return myB.size() + myI.size() + myF.size() + myS.size();
1186  }
1187 
1188  UT_Array<bool> myB; // Bool defaults
1189  UT_Array<int64> myI; // Integer defaults
1190  UT_Array<fpreal64> myF; // Real defaults
1191  UT_Array<UT_StringHolder> myS; // String defaults
1192  bool myVariadic; // Array valued (variadic)
1196 
1197  void dump(UT_JSONWriter &w) const;
1198  };
1199 
1200  const UT_StringHolder name() const
1201  { return myName; }
1203  { return myInputs; }
1205  { return myOutputs; }
1207  { return myMetadata; }
1208 
1210  { myName = n; }
1211  void addInput(const Parameter &parm)
1212  { myInputs.append(parm); }
1213  void addOutput(const Parameter &parm)
1214  { myOutputs.append(parm); }
1216  { myMetadata = metadata; }
1217 
1218  void dump() const;
1219  void dump(UT_JSONWriter &w) const;
1220 
1221  private:
1222  UT_StringHolder myName;
1223  UT_StringMap<UT_StringHolder> myMetadata;
1224  UT_Array<Parameter> myInputs;
1225  UT_Array<Parameter> myOutputs;
1226  };
1227 
1228  // Extract the definition of all supported nodes
1229  static const UT_Array<const NodeDecl *> &allNodes();
1230  // Find a node given the name
1231  static const NodeDecl *findNode(const UT_StringRef &name);
1232 
1233  /// Access the object properties on the shader graph. It's possible the
1234  /// shader graph has no options, so please check `isValid()`
1235  const OptionSet getObjectProperties() const;
1236  /// Create object properties for read/write
1237  OptionSet createObjectProperties(const BRAY::ScenePtr &scene);
1238  /// Clear any existing object properties
1239  void clearObjectProperties();
1240 private:
1241  friend class MaterialPtr;
1242  friend class LightPtr;
1244 };
1245 
1246 }; // End of namespace
1247 
1248 #endif
void cancel()
Cancel this output file for some reason.
BRAY_EventType
Types of events that can be sent as updates to the renderer.
Definition: BRAY_Types.h:39
AOV & appendAOV(const UT_StringHolder &name)
Add an AOV to this output file.
GT_Storage
Definition: GT_Types.h:19
UT_StringHolder optionS(BRAY_SceneOption t) const
int64 propertyI(BRAY_SceneOption t) const
GT_API const UT_StringHolder filename
const BRAY_Camera * spacePtr() const
Interface to scene materials.
const VPRM_SpacePtr & space() const
bool operator==(const AOVBufferPtr &aov) const
SYS_FORCE_INLINE const T * propertyImport(BRAY_ObjectProperty token, T *val, size_t n) const
const BRAY_Scene * scenePtr() const
bool commit()
Commit and add this output file to the render.
const BRAY_Camera * cameraPtr() const
void setName(const UT_StringHolder &n)
void addOutput(const Parameter &parm)
bool isValid() const
Test validity.
float BRAYtime
Consistent representation of time type within BRAY.
Definition: BRAY_Types.h:668
getFileOption("OpenEXR:storage") storage
Definition: HDK_Image.dox:276
VPRM_SpacePtr & space()
BRAY_Light * lightPtr()
bool operator!=(const AOVBufferPtr &aov) const
SYS_FORCE_INLINE bool setProperty(BRAY_ObjectProperty token, const T &value)
Simple interface to set a scalar property.
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
AOV(const UT_StringHolder &name)
UT_SharedPtr< BRAY_Light > myLight
FacesetMaterial(const GT_DataArrayHandle &facelist=GT_DataArrayHandle(), const MaterialPtr &material=MaterialPtr())
int64 exint
Definition: SYS_Types.h:125
GLdouble s
Definition: glad.h:3009
const UT_Options & options() const
const UT_StringMap< UT_StringHolder > & metadata() const
CoordSysPtr(const UT_SharedPtr< BRAY_Camera > &sp=UT_SharedPtr< BRAY_Camera >())
const UT_Array< AOV > & aovs() const
const UT_StringHolder & name() const
SYS_FORCE_INLINE const T * optionImport(BRAY_SceneOption token, T *val, size_t n) const
const UT_StringHolder & filename() const
Access member data.
bool setOption(const UT_StringHolder &name, const T &value)
GLint y
Definition: glcorearb.h:103
UT_StringHolder myGeometry
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
int64 optionI(BRAY_SceneOption t) const
**But if you need a result
Definition: thread.h:613
SYS_FORCE_INLINE bool set(int token, const T &value)
Simple interface to set a scalar property.
const BRAY_Object * objectPtr() const
SYS_FORCE_INLINE exint propertySize(BRAY_ObjectProperty token) const
const UT_Array< Parameter > & inputs() const
const BRAY_Light * lightPtr() const
OutputFile(BRAY::ScenePtr &scene, const UT_StringHolder &filename, const UT_StringHolder &type)
bool isValid() const
Test validity.
CameraPtr(const UT_SharedPtr< BRAY_Camera > &cp=UT_SharedPtr< BRAY_Camera >())
IFDmantra you can see code vm_image_mplay_direction endcode When SOHO starts a render
Definition: HDK_Image.dox:266
const BRAY_VexMaterial * materialPtr() const
GLintptr GLsizeiptr GLboolean commit
Definition: glcorearb.h:3363
SYS_FORCE_INLINE bool isEqual(int token, const T &value) const
Simple interface for equality of a scalar value.
UT_StringHolder propertyS(BRAY_SceneOption t) const
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
bool isValid() const
Test validity.
struct _cl_event * event
Definition: glcorearb.h:2961
UT_StringHolder myParmName
double fpreal64
Definition: SYS_Types.h:201
unsigned char uint8
Definition: SYS_Types.h:36
bool propertyB(BRAY_SceneOption t) const
VPRM_OptionSetPtr & options()
const UT_StringHolder name() const
GLdouble n
Definition: glcorearb.h:2008
BRAY_ObjectProperty
Definition: BRAY_Types.h:191
SYS_FORCE_INLINE GT_Storage propertyStorage(BRAY_ObjectProperty token) const
Return the storage class of an option.
UT_SharedPtr< BRAY_Camera > myCamera
BRAY_RayVisibility
Ray visibility flags.
Definition: BRAY_Types.h:713
UT_SharedPtr< BRAY_Object > myObject
#define SYS_SAFE_BOOL
Definition: SYS_Compiler.h:55
BRAY_Camera * cameraPtr()
bool isValid() const
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
BRAY_Camera * spacePtr()
UT_IntrusivePtr< GT_DataArray > GT_DataArrayHandle
Definition: GT_DataArray.h:32
SYS_FORCE_INLINE exint optionSize(BRAY_SceneOption token) const
PXL_API const char * getName(const ColorSpace *space)
Return the name of the color space.
void setMetadata(const UT_StringMap< UT_StringHolder > &metadata)
int setVolume(int speaker, float vol) override
ShaderGraphPtr(UT_SharedPtr< BRAY_ShaderGraph > graph)
bool isValid() const
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
GLint GLuint mask
Definition: glcorearb.h:124
NodeDecl(const UT_StringHolder &n)
SYS_FORCE_INLINE bool optionIsVariadic(BRAY_SceneOption token) const
Return whether an option has variadic arguments.
PXL_Packing
Definition: PXL_Common.h:32
SYS_FORCE_INLINE bool setOption(BRAY_SceneOption token, const T *value, exint tuple_size)
Interface to set an option. This template class is specialized for:
long long int64
Definition: SYS_Types.h:116
SYS_FORCE_INLINE exint lockAllObjectProperties(bool state)
Lock or unlock all object properties.
const UT_Array< Parameter > & outputs() const
bool isValid() const
Test validity.
Class used to define image planes.
GLuint const GLchar * name
Definition: glcorearb.h:786
MaterialInput(const UT_StringHolder &primvar, const UT_StringHolder &shader_parm, Storage store, int tsize, bool is_array)
PXL_DataFormat
Definition: PXL_Common.h:20
GLushort pattern
Definition: glad.h:2583
GLint GLenum GLint x
Definition: glcorearb.h:409
const UT_Options & options() const
GT_DataArrayHandle myFaceList
GLdouble t
Definition: glad.h:2397
GLfloat units
Definition: glcorearb.h:408
BRAY_LightType
Definition: BRAY_Types.h:537
SYS_FORCE_INLINE bool setOption(BRAY_SceneOption token, const T &value)
Simple interface to set a scalar option.
GLsizeiptr size
Definition: glcorearb.h:664
A map of string to various well defined value types.
Definition: UT_Options.h:84
A render product represents an output file.
BRAY_SceneOption
Definition: BRAY_Types.h:66
bool isValid() const
fpreal64 optionF(BRAY_SceneOption t) const
MaterialPtr(BRAY_VexMaterial *mat=nullptr)
VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE Result createInstance(const VULKAN_HPP_NAMESPACE::InstanceCreateInfo *pCreateInfo, const VULKAN_HPP_NAMESPACE::AllocationCallbacks *pAllocator, VULKAN_HPP_NAMESPACE::Instance *pInstance, Dispatch const &d) VULKAN_HPP_NOEXCEPT
SYS_FORCE_INLINE bool setProperty(BRAY_ObjectProperty token, const T *value, exint tuple_size)
Interface to set an property. This template class is specialized for:
AOVBufferPtr(const UT_SharedPtr< BRAY_AOVBuffer > &aov)
auto ptr(T p) -> const void *
Definition: format.h:2448
GLuint GLfloat * val
Definition: glcorearb.h:1608
SYS_FORCE_INLINE bool propertyIsVariadic(BRAY_ObjectProperty token) const
Return whether an property has variadic arguments.
#define BRAY_API
Definition: BRAY_API.h:12
bool isValid() const
Test validity.
**If you just want to fire and args
Definition: thread.h:609
BRAY_PropertyType
Definition: BRAY_Types.h:372
void addInput(const Parameter &parm)
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
Definition: core.h:1131
bool setOption(const UT_StringHolder &name, const T &value)
MX_GENSHADER_API const TypeDesc * INTEGER
std::shared_ptr< class ShaderMaterial > MaterialPtr
bool optionB(BRAY_SceneOption t) const
Interface to the renderer.
type
Definition: core.h:1059
const UT_StringHolder & type() const
fpreal64 propertyF(BRAY_SceneOption t) const
GLuint * ids
Definition: glcorearb.h:652
Definition: format.h:895
const VPRM_OptionSetPtr & options() const
BRAY_Object * objectPtr()
BRAY_Scene * scenePtr()
LightPtr(const UT_SharedPtr< BRAY_Light > &lp=UT_SharedPtr< BRAY_Light >())
SYS_FORCE_INLINE GT_Storage optionStorage(BRAY_SceneOption token) const
Return the storage class of an option.
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
Definition: core.h:2089
GLenum src
Definition: glcorearb.h:1793