RenderMan  26.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RixSceneGraph.h
Go to the documentation of this file.
1 /*
2 # ------------------------------------------------------------------------------
3 #
4 # Copyright (c) 2021 Pixar. All rights reserved.
5 #
6 # The information in this file (the "Software") is provided for the exclusive
7 # use of the software licensees of Pixar ("Licensees"). Licensees have the
8 # right to incorporate the Software into other products for use by other
9 # authorized software licensees of Pixar, without fee. Except as expressly
10 # permitted herein, the Software may not be disclosed to third parties, copied
11 # or duplicated in any form, in whole or in part, without the prior written
12 # permission of Pixar.
13 #
14 # The copyright notices in the Software and this entire statement, including the
15 # above license grant, this restriction and the following disclaimer, must be
16 # included in all copies of the Software, in whole or in part, and all permitted
17 # derivative works of the Software, unless such copies or derivative works are
18 # solely in the form of machine-executable object code generated by a source
19 # language processor.
20 #
21 # PIXAR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL PIXAR BE
23 # LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
24 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
25 # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
26 # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. IN NO CASE WILL
27 # PIXAR'S TOTAL LIABILITY FOR ALL DAMAGES ARISING OUT OF OR IN CONNECTION WITH
28 # THE USE OR PERFORMANCE OF THIS SOFTWARE EXCEED $50.
29 #
30 # Pixar
31 # 1200 Park Ave
32 # Emeryville CA 94608
33 #
34 # ------------------------------------------------------------------------------
35 */
36 
37 /*
38  * Version 3
39  *
40  * This is a preview release and is not supported. This API will change substantially
41  * in the next release of RenderMan. Names, namespaces, methods, parameters, types,
42  * enums, and the structure of the interface are expected to change.
43  *
44  */
45 
46 #ifndef RixSceneGraph_h
47 #define RixSceneGraph_h
48 
49 #include "RiTypesHelper.h" // RtUString, RtPoint3, RtMatrix4x4, etc.
50 #include "RixInterfaces.h" // RixInterface
51 
52 namespace stats
53 {
54 class Session;
55 }
56 
57 #define k_RixSGManagerVersion 3
58 #define RMAN_SCENEGRAPH_NAMESPACE scenegraph
59 #define RMAN_SCENEGRAPH_NAMESPACE_OPEN_SCOPE \
60  namespace RMAN_SCENEGRAPH_NAMESPACE \
61  {
62 #define RMAN_SCENEGRAPH_NAMESPACE_CLOSE_SCOPE }
63 
64 RMAN_NAMESPACE_OPEN_SCOPE
66 
67 class Camera;
68 class Curves;
69 class Geometry;
70 class Group;
71 class AnalyticLight;
72 class Material;
73 class Mesh;
74 class NuPatch;
75 class Points;
76 class Procedural;
77 class Quadric;
78 class Scene;
79 class Volume;
80 class Blobby;
81 struct DisplayChannel;
82 struct Shader;
83 
85 typedef uint64_t (*UpdateIdCallback)(void* ctx, Group const* node, RtUString const& path);
86 
89 enum class Error
90 {
91  k_Success,
94 };
95 
98 enum class DagType
99 {
100  k_Group,
101  k_Camera,
104  k_Geometry,
105  k_Quadric,
106  k_Mesh,
107  k_NuPatch,
108  k_Curves,
109  k_Points,
110  k_Blobby,
111  k_Volume,
112  k_Procedural,
113 };
114 
117 enum class ShaderType
118 {
119  k_Invalid,
120  k_Pattern,
121  k_Bxdf,
122  k_Integrator,
123  k_Light,
124  k_LightFilter,
125  k_Projection,
129  k_Display,
130 };
131 
137 {
139  DisplayChannel();
140 
142  DisplayChannel(RtDataType t, RtUString h);
143 
145  DisplayChannel(DisplayChannel const&) = default;
146 
148  DisplayChannel& operator=(DisplayChannel const&) = default;
149 
151  RtDataType type;
152 
154  RtUString handle;
155 
157  RtParamList params;
158 };
159 
163 struct Shader
164 {
166  Shader();
167 
169  Shader(ShaderType t, RtUString n, RtUString h);
170 
172  Shader(Shader const&) = default;
173 
175  Shader& operator=(Shader const&) = default;
176 
179 
181  RtUString name;
182 
184  RtUString handle;
185 
187  RtParamList params;
188 };
189 
194 class Material
195 {
196 public:
204  virtual RtUString GetIdentifier() const = 0;
205 
214  virtual Error SetIdentifier(RtUString identifier) = 0;
215 
225  virtual Error SetBxdf(unsigned num, Shader const* nodes) = 0;
226 
237  virtual Error SetLight(unsigned num, Shader const* nodes) = 0;
238 
249  virtual Error SetLightFilter(unsigned num, Shader const* nodes) = 0;
250 
260  virtual Error SetDisplace(unsigned num, Shader const* nodes) = 0;
261 
262  inline Material() = default;
263  virtual ~Material() = default;
264 };
265 
271 class Group
272 {
273 public:
280  virtual DagType GetDagType() const = 0;
281 
289  virtual RtUString GetIdentifier() const = 0;
290 
299  virtual Error SetIdentifier(RtUString identifier) = 0;
300 
316  virtual Error SetTransform(unsigned numsamples, RtMatrix4x4 const* xforms,
317  float const* times) = 0;
318 
330  virtual Error SetTransformNumSamples(unsigned numsamples) = 0;
331 
344  virtual Error SetTransformSample(unsigned sample, RtMatrix4x4 const& xform, float time) = 0;
345 
355  Error SetTransform(RtMatrix4x4 const& xform);
356 
364  Error SetIdentity();
365 
374  virtual unsigned GetTransformNumSamples() const = 0;
375 
387  virtual Error GetTransformSample(unsigned sample, RtMatrix4x4& xform, float& time) const = 0;
388 
397  virtual Error SetHidden(int state) = 0;
398 
406  virtual int GetHidden() const = 0;
407 
421  virtual Error AddCoordinateSystem(Group* coordsys) = 0;
422 
436  virtual Error RemoveCoordinateSystem(Group* coordsys) = 0;
437 
450  virtual Error RemoveAllCoordinateSystems() = 0;
451 
464  virtual unsigned GetNumCoordinateSystems() const = 0;
465 
479  virtual Group* GetCoordinateSystem(unsigned idx) const = 0;
480 
499  virtual Error AddChild(Group* child) = 0;
500 
519  virtual Error RemoveChild(Group* child) = 0;
520 
538  virtual Error RemoveAllChildren() = 0;
539 
557  virtual unsigned GetNumChildren() const = 0;
558 
577  virtual Group* GetChild(unsigned idx) const = 0;
578 
596  virtual unsigned GetNumParents() const = 0;
597 
616  virtual Group* GetParent(unsigned idx) const = 0;
617 
627  virtual Group* FindDagNode(char const* path) const = 0;
628 
637  virtual Material* GetMaterial() const = 0;
638 
648  virtual Error SetMaterial(Material* material) = 0;
649 
663  virtual Error OverrideMaterial(Material* material, unsigned depth, Group** path) = 0;
664 
675  virtual RtParamList const& GetAttributes() const = 0;
676 
688  virtual Error SetAttributes(RtParamList const& attributes) = 0;
689 
698  virtual Error SetNested(bool state) = 0;
699 
707  virtual bool GetNested() const = 0;
708 
718  virtual Error SetInheritTransform(bool value) = 0;
719 
727  virtual bool GetInheritTransform() const = 0;
728 
730  Group(Group const&) = delete;
731  Group const& operator=(Group const&) = delete;
733 
734  inline Group() = default;
735  virtual ~Group() = default;
736 };
737 
740 class Camera : public virtual Group
741 {
742 public:
751  virtual Error SetRenderable(int renderable) = 0;
752 
761  virtual Error SetProjection(unsigned num, Shader const* nodes) = 0;
762 
772  virtual Error SetDisplay(unsigned num, Shader const* nodes) = 0;
773 
782  virtual Error SetOrientTransform(RtMatrix4x4 const& localxform) = 0;
783 
791  virtual RtParamList const& GetProperties() const = 0;
792 
801  virtual Error SetProperties(RtParamList const& prop) = 0;
802 
803 protected:
804  inline Camera() = default;
805  ~Camera() override = default;
806 };
807 
810 class ClippingPlane : public virtual Group
811 {
812 public:
820  virtual Error SetActive(bool active) = 0;
821 
830  virtual Error SetOrientTransform(RtMatrix4x4 const& localxform) = 0;
831 
832 protected:
833  inline ClippingPlane() = default;
834  ~ClippingPlane() override = default;
835 };
836 
839 class AnalyticLight : public virtual Group
840 {
841 public:
852  virtual Error SetLight(unsigned num, Shader const* nodes) = 0;
853 
863  virtual Error SetLightFilter(unsigned num, Shader const* nodes) = 0;
864 
873  virtual Error SetOrientTransform(RtMatrix4x4 const& localxform) = 0;
874 
881  virtual RtParamList const& GetProperties() const = 0;
882 
890  virtual Error SetProperties(RtParamList const& prop) = 0;
891 
892 protected:
893  inline AnalyticLight() = default;
894  ~AnalyticLight() override = default;
895 };
896 
898 class Geometry : public virtual Group
899 {
900 public:
902  virtual RtUString GetGeometry() const = 0;
903 
918  virtual Error SetGeometry(RtUString type) = 0;
919 
932  virtual RtPrimVarList const& GetPrimVars() const = 0;
933 
947  virtual Error SetPrimVars(RtPrimVarList const& primvars) = 0;
948 
949 protected:
950  inline Geometry() = default;
951  ~Geometry() override = default;
952 };
953 
956 class Quadric : public virtual Geometry
957 {
958 public:
976  virtual Error SetGeometry(RtUString type) = 0;
977 
978 protected:
979  inline Quadric() = default;
980  ~Quadric() override = default;
981 };
982 
985 class Mesh : public virtual Geometry
986 {
987 public:
1007  virtual Error Define(int32_t npolys, int32_t npoints, int32_t nverts) = 0;
1008 
1015  virtual Error SetScheme(RtUString scheme) = 0;
1016 
1017 protected:
1018  inline Mesh() = default;
1019  ~Mesh() override = default;
1020 };
1021 
1024 class Points : public virtual Geometry
1025 {
1026 public:
1041  virtual Error Define(int32_t npoints) = 0;
1042 
1043 protected:
1044  inline Points() = default;
1045  ~Points() override = default;
1046 };
1047 
1049 class Volume : public virtual Geometry
1050 {
1051 public:
1070  virtual Error Define(int32_t nx, int32_t ny, int32_t nz) = 0;
1071 
1072 protected:
1073  inline Volume() = default;
1074  ~Volume() override = default;
1075 };
1076 
1079 class Blobby : public virtual Geometry
1080 {
1081 public:
1100  virtual Error Define(int32_t nleaf) = 0;
1101 
1102 protected:
1103  inline Blobby() = default;
1104  ~Blobby() override = default;
1105 };
1106 
1109 class Curves : public virtual Geometry
1110 {
1111 public:
1163  virtual Error Define(RtUString type, RtUString wrap, RtUString basis, int32_t ncurves,
1164  int32_t npoints) = 0;
1165 
1166 protected:
1167  inline Curves() = default;
1168  ~Curves() override = default;
1169 };
1170 
1172 class NuPatch : public virtual Geometry
1173 {
1174 public:
1212  virtual Error Define(int32_t nu, int32_t uorder, int32_t nv, int32_t vorder) = 0;
1213 
1214 protected:
1215  inline NuPatch() = default;
1216  ~NuPatch() override = default;
1217 };
1218 
1221 class Procedural : public virtual Geometry
1222 {
1223 public:
1238  virtual Error Define(RtUString subdivfunction, RtUString boundfunction) = 0;
1239 
1240 protected:
1241  inline Procedural() = default;
1242  ~Procedural() override = default;
1243 };
1244 
1247 class Scene
1248 {
1249 public:
1256  virtual Material* CreateMaterial(RtUString identifier) = 0;
1257 
1264  virtual Error DeleteMaterial(Material* material) = 0;
1265 
1272  virtual Group* CreateGroup(RtUString identifier) = 0;
1273 
1280  virtual Camera* CreateCamera(RtUString identifier) = 0;
1281 
1288  virtual ClippingPlane* CreateClippingPlane(RtUString identifier) = 0;
1289 
1296  virtual AnalyticLight* CreateAnalyticLight(RtUString identifier) = 0;
1297 
1304  virtual Geometry* CreateGeometry(RtUString identifier) = 0;
1305 
1312  virtual Quadric* CreateQuadric(RtUString identifier) = 0;
1313 
1320  virtual Mesh* CreateMesh(RtUString identifier) = 0;
1321 
1328  virtual Points* CreatePoints(RtUString identifier) = 0;
1329 
1336  virtual Volume* CreateVolume(RtUString identifier) = 0;
1337 
1344  virtual Blobby* CreateBlobby(RtUString identifier) = 0;
1345 
1352  virtual Curves* CreateCurves(RtUString identifier) = 0;
1353 
1360  virtual NuPatch* CreateNuPatch(RtUString identifier) = 0;
1361 
1368  virtual Procedural* CreateProcedural(RtUString identifier) = 0;
1369 
1378  virtual Error DeleteDagNode(Group* node) = 0;
1379 
1388  virtual Group* FindDagNode(char const* path) const = 0;
1389 
1401 
1406  virtual Error Render(char const* cmd) = 0;
1411 
1418  virtual Error Stop() = 0;
1419 
1426  struct ScopedEdit
1427  {
1428  ScopedEdit(Scene* scene);
1429  ~ScopedEdit();
1430  Scene* const sg;
1431  };
1432 
1439  virtual void EditBegin() = 0;
1440 
1447  virtual void EditEnd() = 0;
1448 
1457  virtual Error Clear() = 0;
1458 
1468  virtual Group* Root() const = 0;
1469 
1479  virtual Error SetIntegrator(unsigned num, Shader const* nodes) = 0;
1480 
1491  virtual Error SetSampleFilter(unsigned num, Shader const* nodes) = 0;
1492 
1502  virtual Error SetDisplayFilter(unsigned num, Shader const* nodes) = 0;
1503 
1512  virtual Error SetDisplayChannel(unsigned num, DisplayChannel const* nodes) = 0;
1513 
1522  virtual RtParamList const& GetOptions() const = 0;
1523 
1533  virtual Error SetOptions(RtParamList const& options) = 0;
1534 
1543  virtual Error SetUpdateIdCallback(UpdateIdCallback callback, void* ctx) = 0;
1544 
1546  //
1551  virtual Error InvalidateTexture(RtUString const name) = 0;
1552 
1553 protected:
1554  Scene() = default;
1555  virtual ~Scene() = default;
1556 };
1557 
1558 /* inlined */
1559 
1560 inline DisplayChannel::DisplayChannel() : type(RtDataType::k_float), handle(US_NULL)
1561 {}
1562 
1563 inline DisplayChannel::DisplayChannel(RtDataType t, RtUString h) : type(t), handle(h)
1564 {}
1565 
1566 inline Shader::Shader() : type(ShaderType::k_Invalid), name(US_NULL), handle(US_NULL)
1567 {}
1568 
1569 inline Shader::Shader(ShaderType t, RtUString n, RtUString h) : type(t), name(n), handle(h)
1570 {}
1571 
1572 inline Error Group::SetTransform(RtMatrix4x4 const& xform)
1573 {
1574  return SetTransform(1, &xform, nullptr);
1575 }
1576 
1578 {
1579  return SetTransformNumSamples(0);
1580 }
1581 
1582 inline Scene::ScopedEdit::ScopedEdit(Scene* scene) : sg(scene)
1583 {
1584  sg->EditBegin();
1585 }
1586 
1588 {
1589  sg->EditEnd();
1590 }
1591 
1593 
1594 RMAN_NAMESPACE_CLOSE_SCOPE
1595 
1596 // Backward compatability
1597 typedef RMAN_NAMESPACE::RMAN_SCENEGRAPH_NAMESPACE::AnalyticLight RixSGAnalyticLight;
1598 typedef RMAN_NAMESPACE::RMAN_SCENEGRAPH_NAMESPACE::Blobby RixSGBlobby;
1599 typedef RMAN_NAMESPACE::RMAN_SCENEGRAPH_NAMESPACE::Camera RixSGCamera;
1600 typedef RMAN_NAMESPACE::RMAN_SCENEGRAPH_NAMESPACE::ClippingPlane RixSGClippingPlane;
1601 typedef RMAN_NAMESPACE::RMAN_SCENEGRAPH_NAMESPACE::Curves RixSGCurves;
1603 typedef RMAN_NAMESPACE::RMAN_SCENEGRAPH_NAMESPACE::DisplayChannel RixSGDisplayChannel;
1605 typedef RMAN_NAMESPACE::RMAN_SCENEGRAPH_NAMESPACE::Geometry RixSGGeometry;
1606 typedef RMAN_NAMESPACE::RMAN_SCENEGRAPH_NAMESPACE::Group RixSGGroup;
1607 typedef RMAN_NAMESPACE::RMAN_SCENEGRAPH_NAMESPACE::Material RixSGMaterial;
1608 typedef RMAN_NAMESPACE::RMAN_SCENEGRAPH_NAMESPACE::Mesh RixSGMesh;
1609 typedef RMAN_NAMESPACE::RMAN_SCENEGRAPH_NAMESPACE::NuPatch RixSGNuPatch;
1610 typedef RMAN_NAMESPACE::RMAN_SCENEGRAPH_NAMESPACE::Points RixSGPoints;
1611 typedef RMAN_NAMESPACE::RMAN_SCENEGRAPH_NAMESPACE::Procedural RixSGProcedural;
1612 typedef RMAN_NAMESPACE::RMAN_SCENEGRAPH_NAMESPACE::Quadric RixSGQuadric;
1613 typedef RMAN_NAMESPACE::RMAN_SCENEGRAPH_NAMESPACE::Scene RixSGScene;
1614 typedef RMAN_NAMESPACE::RMAN_SCENEGRAPH_NAMESPACE::Shader RixSGShader;
1617 typedef RMAN_NAMESPACE::RMAN_SCENEGRAPH_NAMESPACE::Volume RixSGVolume;
1618 
1621 {
1622 public:
1629  virtual RixSGScene* CreateScene(RtParamList const& config, RtParamList const& renderConfig, stats::Session& statsSession) = 0;
1630 
1635  virtual RixSGError DeleteScene(RixSGScene* scene) = 0;
1636 
1637 protected:
1639  {}
1640  ~RixSGManager() override = default;
1641 };
1642 
1643 #endif // RixSceneGraph_h