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