HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OBJ_LightLink.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: OBJ_LightLink.h (OBJ Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __OBJ_LightLink__
12 #define __OBJ_LightLink__
13 
14 #include "OBJ_API.h"
15 
16 #include <UT/UT_Set.h>
17 #include <UT/UT_Map.h>
18 #include <UT/UT_TagManager.h>
19 #include <GA/GA_Types.h>
20 #include <SOP/SOP_Node.h>
22 
23 class UT_JSONWriter;
24 class UT_JSONParser;
25 class OP_Network;
26 class OBJ_Node;
27 
28 /// Helper class to assist with managing tags and expressions on objects.
29 ///
30 /// The class contains a simple representation for objects that have tag
31 /// expressions (i.e. objects which have a light selection expression). This
32 /// class allows you to make edits to the tag expressions using a list object
33 /// centric view. That is, the object that stores the list of tags can
34 /// add/remove tags from the expression objects.
36 {
37 public:
44 
45  /// Open a chooser of all objects, selecting the objects with the given
46  /// tag. On completion, the user selected objects will be lit by the tag.
47  void runLightSelection(const char *title,
48  const char *tag,
49  bool include_packed=true,
50  OP_Network *parent = NULL);
51 
52  /// The @c node_path refers to the geometry object (or SOP). When
53  /// referring to a packed SOP, the @c packed_path refers to the path
54  /// attribute. As a note, when referring to a SOP, the SOP must support
55  /// the SOP_ObjectAppearance interface.
56  bool runObjectCentric(const char *title,
57  OBJ_Node *node, const char *packed_path=NULL) const;
58 
59  class ObjectData
60  {
61  public:
63  : myInitial()
64  , myValue()
65  , myOpId(-1)
66  {
67  }
69  : myInitial(src.myInitial)
70  , myValue(src.myValue)
71  , myOpId(src.myOpId)
72  {
73  }
74  void initialize(const CompiledTagExpression &expr, int opid)
75  {
76  myOpId = opid;
77  myInitial = expr;
78  myValue = expr;
79  }
80  /// Indicate whether the object is changed from its original value
81  bool changed() const;
82 
83  /// Remove the given tag from the object, returning true if the
84  /// object changed.
85  bool removeTag(const char *tag);
86 
87  /// Add the given tag to the object, returning true if the object
88  /// changed.
89  bool addTag(const char *tag);
90 
91  /// Get the expression as a string
92  void exprSource(UT_WorkBuffer &expr) const;
93 
94  /// @{
95  /// Accessors
96  const CompiledTagExpression &expr() const { return myValue; }
97  int opid() const { return myOpId; }
98  /// @}
99 
100  private:
101  CompiledTagExpression myInitial;
102  CompiledTagExpression myValue;
103  int myOpId;
104  };
105  /// There's one SOPData per SOP. This is used for editing all paths in the
106  /// SOP.
107  class SOPData
108  {
109  public:
110  /// The appearance pointer is used to edit light values.
111  /// The path start is the offset of the SOP's path
112  SOPData(const std::string &soppath,
113  const SOP_ObjectAppearancePtr &app)
114  : myPath(soppath)
115  , myAppearance(app)
116  {
117  }
119  : myPath(src.myPath)
120  , myAppearance(src.myAppearance)
121  {
122  }
123  void initialize(const std::string &soppath,
124  const SOP_ObjectAppearancePtr &app)
125  {
126  myPath = soppath;
127  myAppearance = app;
128  }
131  const char *tag)
132  {
133  return myAppearance->getLightSelection(tags, myPath,
134  selection, tag);
135  }
137  const ObjectSet &sel,
138  const char *tag)
139  {
140  return myAppearance->editLightSelection(tags, myPath, sel, tag);
141  }
142  const SOP_ObjectAppearancePtr &appearance() const { return myAppearance; }
143  const std::string &path() const { return myPath; }
144  private:
145  SOP_ObjectAppearancePtr myAppearance;
146  std::string myPath;
147  };
150 
151  OBJ_LightLink();
152  ~OBJ_LightLink();
153 
154  /// Helper function to populate the light linker database with objects from
155  /// the given network.
156  void populateFromNetwork(OP_Network *net, fpreal t);
157 
158  /// Add geometry which can be lit or might not be lit
159  bool addObject(const ObjectId &path,
160  const SourceTagExpression &expr,
161  int opid=-1);
162  bool addSOP(const std::string &soppath,
163  const SOP_ObjectAppearancePtr &app);
164 
165  /// Get objects which match a given tag.
166  /// Non-const since tag manager is modified.
167  void getMatching(ObjectSet &objects, const char *tag);
168 
169  /// The given set of @c objects will be set to match the @c tag. All other
170  /// objects will be adjusted to no longer match the given @c tag. The list
171  /// of @c changed objects is returned.
172  void setMatching(const ObjectSet &objects,
173  const char *tag, fpreal t);
174 
175  /// Set all objects to be matching the given tag.
176  void setAllMatching(const char *tag, fpreal t);
177 
178  /// Get a list of all objects modified by set operations
179  void getChanged(ObjectSet &objects);
180 
181  /// Get the expression source for the given object
182  bool getSourceExpression(const ObjectId &path,
183  UT_WorkBuffer &expr) const;
184 
185  /// Export lighting information to a file
186  /// Save options:
187  /// - "save_material" [True] @n
188  /// Save materials for objects/SOPs
189  /// - "save_visibility" [True] @n
190  /// Save visibility for objects/SOPs
191  /// - "save_linking" [True] @n
192  /// Save linking information for objects/SOPs
193  /// - "root" ["/obj"] @n
194  /// Root of network to save
195  ///
196  bool exportLighting(UT_JSONWriter &os,
197  const UT_Options &save_options,
198  UT_StringArray &errors) const;
199  /// Import lighting information from a file
200  bool importLighting(UT_JSONParser &is,
201  const UT_Options &load_options,
202  UT_StringArray &errors) const;
203 
204 private:
205  ObjectMap myObjects;
206  SOPList mySOPs;
207  UT_TagManager myTags;
208 };
209 
210 #endif
211 
GT_API const UT_StringHolder selection
Definition: UT_Set.h:58
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
Wrapper around hboost::intrusive_ptr.
GLdouble t
Definition: glad.h:2397
A map of string to various well defined value types.
Definition: UT_Options.h:84
fpreal64 fpreal
Definition: SYS_Types.h:277
#define OBJ_API
Definition: OBJ_API.h:10
GLenum src
Definition: glcorearb.h:1793