HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SIM_Object.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  */
7 
8 #ifndef __SIM_Object_h__
9 #define __SIM_Object_h__
10 
11 #include "SIM_API.h"
12 #include "SIM_RootData.h"
13 #include "SIM_PhysicalParms.h"
14 #include "SIM_RelationshipArray.h"
15 #include "SIM_ColliderInfo.h"
16 
17 class UT_IStream;
18 class UT_TokenString;
19 class SIM_Collider;
20 class SIM_ColliderLabel;
21 class SIM_Geometry;
22 class SIM_Position;
24 class SIM_Solver;
25 class SIM_MetaObject;
26 class SIM_ObjectArray;
28 class SIM_SimulationState;
29 
30 /// This class is a simple container for all the data that is used to
31 /// represent an object in a simulation. Each piece of data has a name
32 /// and can be of any type that is subclassed from SIM_Data.
34 {
35 public:
36  /// Returns the unique identifier for the object. This identifier is
37  /// unique for the duration of a simulation and will not be reused even
38  /// if the object is deleted.
39  int getObjectId() const;
40  /// Sets the name ofthe object to a new value. This value does not need
41  /// to be unique. If the value is not a valid object name (e.g. it
42  /// contains spaces or other invalid characters), this function modifies
43  /// the name to make it valid.
44  void setName(const char *name);
45  /// Returns true if the object's baked flag is set. This flag indicates
46  /// that the object was loaded from a file or merged from another
47  /// simulation.
48  bool getIsBaked() const;
49  /// Returns true if the object allows cachine. Uncached objects
50  /// will not persist in the cache.
51  bool getAllowCaching() const;
52  void setAllowCaching(bool allowcaching);
53  /// Returns true if the object was created with the solve first frame
54  /// flag turned on.
55  bool getSolveFirstFrame() const;
56  /// Returns the affector information for this object. The returned
57  /// array contains a list of all objects that affect this object.
58  void getAffectors(SIM_ObjectArray &affobjs,
59  const char *relationshiptype);
60  /// Returns the affector information for this object. The returned
61  /// array contains a const list of all objects that affect this object.
62  void getConstAffectors(SIM_ConstObjectArray &affobjs,
63  const char *relationshiptype) const;
64  /// Returns true if the supplied object is an affector of this object.
65  /// Checking this way is faster than building a full affector list and
66  /// comparing against that.
67  bool getIsAffector(const SIM_Object *affector,
68  const char *relationshiptype) const;
69  /// Gets an array of objects we will collide with, what collider to
70  /// use, and how to apply impact data to those objects.
71  void getColliderInfo(
72  SIM_ColliderInfoArray &colliderinfo) const;
73  /// Fills a UT_TokenString with enough information to uniquely determine
74  /// what the SIM_ColliderInfoArray for this object will contain. This lets
75  /// use very quickly determine if two objects will have the same array
76  /// of collider infos.
77  void getColliderInfoTokenString(UT_TokenString &ts) const;
78 
79  /// This enumeration defines the possible solve states for an object.
80  typedef enum {
84  SIM_SOLVED
85  } SIM_SolveState;
86  /// Returns the current solved state of this object.
87  const SIM_SolveState &getSolveState() const;
88 
89  /// Returns our cached SIM_Solver pointer. This function is equivalent to
90  /// but much faster than using the SIM_DATA_GETCONST() macro.
91  const SIM_Solver *getSolver() const;
92  /// Returns our cached SIM_Position pointer. This function is equivalent to
93  /// but much faster than using the SIM_DATA_GETCONST() macro.
94  const SIM_Position *getPosition() const;
95  /// Returns our cached SIM_Geometry pointer. This function is equivalent to
96  /// but much faster than using the SIM_DATA_GETCONST() macro.
97  const SIM_Geometry *getGeometry() const;
98  /// Returns our cached SIM_PhysicalParms pointer. This function is
99  /// equivalent to but much faster than using the SIM_DATA_GETCONST() macro.
100  const SIM_PhysicalParms *getPhysicalParms() const;
101  /// Returns our cached SIM_ColliderLabel pointer. This function is
102  /// equivalent to but much faster than using the SIM_DATA_GETCONST() macro.
103  const SIM_ColliderLabel *getColliderLabel() const;
104  /// Gets the actual collider label string from our collider label subdata.
105  /// If we have no collider label subdata, our solver is queried to get
106  /// the default collider label for an object handled by that solver.
107  void getColliderLabel(UT_String &label) const;
108 
109  /// Get a const reference to our array of relationships. Note that even
110  /// though the returned array is const, it's members are non-const, and
111  /// so the SIM_Relationship data can be modified. Thus this must be a
112  /// non-const function on SIM_Object.
113  const SIM_RelationshipArray &getRelationships(bool ingroup);
114  /// Returns the number of relationships to which this object belongs.
115  int getNumRelationships(bool ingroup) const;
116  /// This function allows looping through the relationships for an object.
117  /// This is a const function, so it returns a const SIM_Relationship.
118  const SIM_Relationship *getRelationship(bool ingroup, int index) const;
119  /// Get the relationship for this object with a particular name. Because
120  /// This is a const function, so it returns a const SIM_Relationship.
121  const SIM_Relationship *getRelationship(bool ingroup,
122  const char *name) const;
123  /// Gets all the relationships of a particular type. The type of a
124  /// relationship is defined by the one subdata on the SIM_Relationship.
125  void filterConstRelationships(bool ingroup,
126  const SIM_DataFilter &filter,
127  SIM_ConstDataArray &rels) const;
128 
129  /// Returns whether or not this object is a substep object. This is
130  /// true for both temporary interpolated objects created with
131  /// SIM_Engine::getObjectAtTime() and substep objects explicitly
132  /// created with SIM_Engine::createSubStepObject().
133  bool getIsSubStepObject() const;
134  /// Returns false if the object is either a baked object (because it
135  /// was loaded from a file) or it is passive.
136  bool getIsStatic() const;
137  /// Returns true if the object is marked as intangible, ie, should
138  /// ignore all auto-relationships from merge nodes and only
139  /// deal with explicit merges.
140  bool getIsIntangible() const;
141 
142  /// Gets the meta-object pointer for this object. The meta-object is
143  /// a value that is used only by the SIM_Engine.
144  SIM_MetaObject *getMetaObject() const;
145 
146  /// Returns a pointer to a SIM_Collider that should be used to do
147  /// collision detection between this object and the supplied affector
148  /// object. This function should be called only if the SIM_ColliderInfo
149  /// for this affector object did not specify a SIM_Collider to use.
150  /// The return value from this function can be null, in which case no
151  /// collision detection should be done between the objects.
152  ///
153  /// The method for determining the SIM_Collider to use is as follows:
154  /// First, we look at the collider label for the affector, and look
155  /// for SIM_Collider subdata on the SIM_ColliderLabel of this object
156  /// with a name that matches the affector's collider label. If a
157  /// SIM_Collider is found with that subdata name, we return that
158  /// collider. Otherwise, we go to the solver attached to this object.
159  /// The SIM_Solver::getDefaultCollider() function is called, passing
160  /// in this object, the affector object's collider label. This function
161  /// returns the name of the SIM_Collider subclass we should use based
162  /// on the needs of the solver. We then create subdata on the solver
163  /// itself, and attach a SIM_Collider of the requested type. Then
164  /// we return a pointer to this new collider.
165  ///
166  /// For the special case of self-collision, the collider label of
167  /// the affector is replaced with SIM_COLLIDERLABEL_SELF, which allows
168  /// the solver and the collider label data to treat self-collision as
169  /// a special case. In some cases this means using a spcial SIM_Collider,
170  /// and in other cases it means returning null and skipping collision
171  /// detection altogether (e.g. the RBD Solver doesn't do self-collision
172  /// detection).
173  const SIM_Collider *getCollider(const SIM_Object &affector,
174  const char *defaultlabel=0) const;
175  /// Stores impacts information from the temporary locations to the
176  /// permanent locations. Copies impact information from the
177  /// SIM_NEWIMPACTS_DATANAME data into SIM_IMPACTS_DATANAME, and
178  /// from SIM_NEWFEEDBACK_DATANAME to SIM_FEEDBACK_DATANAME. Then
179  /// the NEW impact data is removed. This should be called after
180  /// a set of new impacts have been processed successfully.
181  void preserveImpacts(SIM_Engine &engine);
182  /// Eliminates any temporary impact data. Temporary impacts data is
183  /// stored in SIM_Impacts data named SIM_NEWIMPACTS_DATANAME and
184  /// SIM_NEWFEEDBACK_DATANAME. Unlike preserveImpacts(), which copies
185  /// the data into SIM_IMPACTS_DATANAME and SIM_FEEDBACK_DATANAME,
186  /// this function simply deletes the data. This funciton should be
187  /// called when rolling back a substep.
188  void rollbackImpacts(SIM_Engine &engine);
189 
190  /// Gets the velocity of a point in the space local to an object. The
191  /// returned velocity is also in local space. There are two methods
192  /// that can be used to calculate the velocity. The first method uses
193  /// the SDF representing the geometry at the previous time step
194  /// compared to the current time step. The second method uses the
195  /// velocity point attribute attached to the geometry. If no velocity
196  /// attribute is found, the geometry at this time step is compared to
197  /// the geometry at the previous time step to calculate the velocity
198  /// for each point.
199  UT_Vector3 getLocalVelocityAtPosition(
200  const UT_Vector3 &localspacepos,
201  bool usesdfhistory,
202  bool usegeohistory) const;
203 
204  /// Gets the velocity of a point on the object specified in world space.
205  /// The returned velocity is also in world space. The two boolean values
206  /// specify what method should be used to determine the local space
207  /// portion of the velocity. If both these values are false, no local
208  /// velocity component is calculated and it is assumed that the geometry
209  /// attached to the object is static.
210  UT_Vector3 getVelocityAtPosition(
211  const UT_Vector3 &worldspacepos,
212  bool usesdfhistory,
213  bool usegeohistory,
214  fpreal integrateovertime = 0.0) const;
215 
216  /// Returns a resolver for efficiently computing velocity values
217  /// The caller must delete the returned object.
218  SIM_PropertyResolver *getVelocityAtPositionResolver(
219  bool usesdfhistory,
220  bool usegeohistory,
221  fpreal integrateovertime = 0.0) const;
222 
223  /// Gets the value of some physical property for the supplied object
224  /// at a given position in world space. This function calls
225  /// SIM_Solver::getPropertyAtPosition().
226  fpreal getPropertyAtPosition(const UT_Vector3 &wpos,
227  const SIM_Property &property) const;
228  /// Gets the value of some physical property for the supplied object
229  /// at a given point on the object's geometry. This function calls
230  /// SIM_Solver::getPropertyAtPoint().
231  fpreal getPropertyAtPoint(GA_Index ptnum,
232  const SIM_Property &property) const;
233 
234  /// Returns a resolver for efficiently computing property values
235  /// The caller must delete the returned object.
236  SIM_PropertyResolver *getPropertyResolver(const SIM_Property &property) const;
237 
238  /// Gets the velocity of a point on the object specified by a point
239  /// number. The returned velocity is in world space. If a velocity
240  /// point attribute exists, that value is used as the local velocity.
241  UT_Vector3 getVelocityAtPoint(GA_Index ptnum,
242  const SIM_Geometry *geo = 0) const;
243  /// Gets the simulation space position of a point on our geometry.
244  UT_Vector3 getPositionOfPoint(GA_Index ptnum,
245  const SIM_Geometry *geo = 0) const;
246  /// Returns the point number closest to a world space position.
247  GA_Index getNearestPoint(const UT_Vector3 &wspos) const;
248 
249  /// Returns a resolver to lookup the closest point and extract
250  /// the given attribute. If attribute not found, 1.0 is returned.
251  SIM_PropertyResolver *getNearestPointAttribResolver(const char *attribname) const;
252 
253  /// Fetches the value of the supplied point attribute from our geometry.
254  /// Returns true if the attribute was found, otherwise it returns false.
255  /// The attribute must be a simple float attribute.
256  bool getPointAttribute(GA_Index ptnum,
257  const char *attrib,
258  fpreal &value) const;
259 
260  /// Fetches the SIM_Position data associated with the geometry data
261  /// at the supplied location.
262  /// This uses the SIM_NAME_POSITIONPATH relative path to find the
263  /// SIM_Position that the data refers to. Supported data are
264  /// SIM_Geometry and SIM_*Field.
265  const SIM_Position *getPositionForGeometry(const char *geo) const;
266 
267  /// Returns the object-specific solve info for this object.
268  SIM_ObjectSolveInfo *getSolveInfo() const;
269 
270 protected:
271  /// The constructor for a new simulation object.
272  explicit SIM_Object(const SIM_SimulationState *factory);
273  /// The object destructor.
274  ~SIM_Object() override;
275 
276  /// Clears all attached data.
277  void initializeSubclass() override;
278  /// Makes two objects equal, but not their names or object ids.
279  void makeEqualSubclass(const SIM_Data *source) override;
280  /// Saves an object to a stream.
281  void saveSubclass(std::ostream &os) const override;
282  /// Loads an object from a stream.
283  bool loadSubclass(UT_IStream &is) override;
284  /// Caches the solver, collider, and position data for quick access.
285  void setNamedSubDataSubclass(const char *dataname,
286  const SIM_Data *data) override;
287  /// Clears the solver, collider, and position cached pointers.
289  const char *dataname) override;
290  /// Creates a query object for getting SIM_Object-specific information.
291  SIM_Query *createQueryObjectSubclass() const override;
292  /// Overrides interpolateSubclass() to set our interpolated flag.
293  void interpolateSubclass(const SIM_Data *source1,
294  const SIM_Data *source2,
295  fpreal interp) override;
296  /// Get the amount of memory used by this object.
297  int64 getMemorySizeSubclass() const override;
298 
299  /// Override the SIM_RootData function for getting our identifier.
301  SIM_RootDataId &id) const override;
302  /// Override the SIM_RootData function for matching us to a string.
304  const char *pattern) const override;
305 
306 private:
307  void getAffectorsUnsafe(SIM_ObjectArray &affectors,
308  const char *relationshiptype) const;
309  void setMetaObject(SIM_MetaObject *metaobject);
310  void setSubStepCopyFromObject(SIM_Object *fromobject);
311  void setObjectId(int id);
312  void setIsBaked(bool baked);
313  void setSolveFirstFrame(bool solvefirstframe);
314  void setSolveState(const SIM_SolveState &solvestate);
315  void copyObjectIdentifiers(const SIM_Object &source);
316  UT_Vector3 getSDFVelocity(const UT_Vector3 &localpos) const;
317  UT_Vector3 getPointVelocity(const UT_Vector3 &localpos) const;
318 
319  /// Get a const reference to our array of relationships.
320  const SIM_RelationshipArray &getRelationshipArray(bool ingroup) const;
321  /// Get a non-const reference to our array of relationships.
322  SIM_RelationshipArray &getRelationshipArray(bool ingroup);
323 
324  const SIM_SimulationState *mySimulationState;
325 
326  SIM_MetaObject *myMetaObject;
327  SIM_Object *mySubStepCopyFromObject;
328  SIM_SolveState mySolveState;
329  SIM_RelationshipArray myGroupRelationships;
330  SIM_RelationshipArray myAffectorRelationships;
331 
332  const SIM_Solver *myCachedSolver;
333  const SIM_Geometry *myCachedGeometry;
334  const SIM_ColliderLabel *myCachedColliderLabel;
335  const SIM_PhysicalParms *myCachedPhysicalParms;
336  mutable SIM_ObjectSolveInfo *mySolveInfo;
337 
338  int myObjectId;
339  bool myIsBaked;
340  bool mySolveFirstFrame;
341  bool myAllowCaching;
342 
343  friend class SIM_SimulationState;
344  friend class SIM_Relationship;
345  friend class SIM_ObjectSolveInfo;
346 
349 };
350 
351 #endif
352 
virtual void makeEqualSubclass(const SIM_Data *source)
#define DECLARE_STANDARD_GETCASTTOTYPE()
Definition: SIM_DataUtils.h:50
#define DECLARE_CLASSNAME(DataClass, SuperClass)
Definition: SIM_DataUtils.h:20
virtual bool loadSubclass(UT_IStream &is)
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
virtual SIM_Query * createQueryObjectSubclass() const
This class contains physical attributes that apply to all objects.
virtual int64 getMemorySizeSubclass() const
virtual bool getMatchesStringSubclass(const char *pattern) const =0
Holds pointers to a number of SIM_Relationships.
Holds pointers to a number of SIM_Object objects.
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
virtual void saveSubclass(std::ostream &os) const
long long int64
Definition: SYS_Types.h:116
virtual void interpolateSubclass(const SIM_Data *source1, const SIM_Data *source2, fpreal interp)
GLuint const GLchar * name
Definition: glcorearb.h:786
GLushort pattern
Definition: glad.h:2583
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:640
Holds pointers to a number of const SIM_Object objects.
fpreal64 fpreal
Definition: SYS_Types.h:277
GLuint index
Definition: glcorearb.h:786
#define SIM_API
Definition: SIM_API.h:12
Definition: core.h:1131
virtual void removeNamedSubDataSubclass(const char *dataname)
virtual void setNamedSubDataSubclass(const char *dataname, const SIM_Data *data)
SIM_Property
Definition: format.h:895
virtual void getRootDataIdSubclass(SIM_RootDataId &id) const =0
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297
virtual void initializeSubclass()