Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
3DBaseObject.h
Go to the documentation of this file.
1//! @file 3DBaseObject.h
2//! @brief C3DBaseObject class which is the common base class for all object types
3//
4//////////////////////////////////////////////////////////////////////
5
6#if !defined(AFX_3DBASEOBJECT_H__31D6A935_B14E_11D2_A1E5_000000000000__INCLUDED_)
7#define AFX_3DBASEOBJECT_H__31D6A935_B14E_11D2_A1E5_000000000000__INCLUDED_
8
9#ifdef _MSC_VER
10#pragma once
11#endif // _MSC_VER
12
13#include "DependentChannels.h"
14#include "4x4Matrix.h"
15#include "3DPoint.h"
16
17BEGIN_MOOTOOLS_NAMESPACE
18
19// Object custom id
20#define OBJECT_REFERENCE_OBJECT MAKE_CUSTOM_ID('R', 'F', 'O', 'B')
21
22#define OBJECT_GUID_CLASS MAKE_CUSTOM_ID('O', 'B', 'J', 'C')
23
24//! @enum OBJECT_KINDOF
25//! The kind of object. An object has only one kind.\n
26//! It is possible to test if an object belong to a given kind using OR operator. Ie. if (kindOf & (OBJECT_MESH|OBJECT_CURVE))
27typedef enum OBJECT_KINDOF XEnumType(unsigned int)
28{
29 OBJECT_UNKNOWN = 0,
30
31 // Object kindof return by C3DBaseObject::GetKindOf
32 // This allows to cast a C3DBaseObject to another type of object
33 OBJECT_MESH = 0x01, //!< C3DObject
34 OBJECT_CURVE = 0x02, //!< C3DCurve
35 OBJECT_PATCH = 0x04, //!< C3DPatch
36 OBJECT_GROUP = 0x08, //!< C3DGroup
37 OBJECT_DUMMY = 0x10, //!< C3DDummy
38 OBJECT_CAMERA = 0x20, //!< C3DCamera
39 OBJECT_LIGHT = 0x40, //!< C3DLight
40
41 // Private object type
42 OBJECT_PRIVATE_TYPE = 0xFF000000,
43 OBJECT_POI_CAMERA = 0x01000000, // C3DPoiCamera = C3DCamera
44
45 //!< These flags can be used in C3DScene::GetFirstNode/GetNextNode or to perform a bitwise operation on C3DBaseObject::GetKindOf
48 OBJECT_ALL_KINDOF = (unsigned int)-1, //!< This also include private type for copy and other specific operations
50
51typedef enum _OBJECT_PROPERTIES XEnumType(unsigned int)
52{
53 OBJECT_NONE = 0x00,
54 OBJECT_IS_INVALID = 0x10,
55 OBJECT_RENDER_WIREFRAME = 0x20, // Object is rendered in wireframe only
56
57 OBJECT_USER_PROPERTIES1 = 0x01000000, // Specific user properties for specific purposes
58 OBJECT_USER_PROPERTIES2 = 0x02000000,
59 OBJECT_USER_PROPERTIES3 = 0x04000000,
60 OBJECT_USER_PROPERTIES4 = 0x08000000,
61} OBJECT_PROPERTIES;
62
63//! @enum OBJECT_UPDATE_PROPERTIES
64//! Flags used by C3DBaseObject::Invalidate / C3DBaseObject::Update. Depending on the SCENE_NODE_INV flags in a C3DBaseObject::Invalidate call, the method set required OBJECT_UPDATE flags that will be processed when calling C3DBaseObject::Update.\n
65//! For example OBJECT_INV_TOPO will flag OBJECT_UPDATE_GEOM. For a C3DPatch object, this will make the subdivided object to be invalidate and recomputed on the Update call.
66typedef enum OBJECT_UPDATE_PROPERTIES XEnumType(unsigned int)
67{
68 OBJECT_INV_FLAGS = 0xFFFF,
69 OBJECT_INV_ALL = OBJECT_INV_FLAGS,
70 OBJECT_INV_GEOM = 0x0001, //!< Points position or number changed
71 OBJECT_INV_TOPO = 0x0002, //!< Faces indexes size, indexes changes
72 OBJECT_INV_FACE_FLAG = 0x0004, //!< Face properties changed (ie HIDDEN flag of face changed)
73 OBJECT_INV_MATERIALS = 0x0008, //!< Face materials changes
74 OBJECT_INV_CHANNELS = 0x0010, //!< Channel changed, autogenerated channels need to be recomputed...
75 OBJECT_INV_MATERIAL_ATTR = 0x0020, //!< A material related to object changed
76 OBJECT_INV_DATA = 0x0040, //!< Custom data associated to object changed
77
78 OBJECT_INV_DISPLAY = 0x0800, //!< The object drawing should be updated
79
80 // This implies some recomputation in the object (Done through C3DBaseObject::Update)
81 OBJECT_UPDATE_NONE = 0x00000000,
82 OBJECT_UPDATE_ALL = 0x0FFF0000,
83 OBJECT_UPDATE_FIRST_VALUE = 0x00010000, //!< For intenal offset
84 OBJECT_UPDATE_BBOX = 0x00010000, //!< Bounding box will be recomputed next time we ask for the BBox
85 OBJECT_UPDATE_GEOM = 0x00020000, //!< Geometry need to be recomputed or updated. This should be done in the C3DBaseObject::Update
86 OBJECT_UPDATE_CHANNELS = 0x00040000, //!< Update autogenerated channels (normals or projected UV for example)
88
89//! @enum OBJECT_COPY_FLAGS
90//! Flags used to control the way objects are copied
91typedef enum OBJECT_COPY_FLAGS XEnumType(unsigned int)
92{
93 OBJECT_COPY_DEFAULT = 0x00,
94 OBJECT_COPY_CREATE_INSTANCE = 0x10, //!< Create an instance copy of the object that should be affected to a node.
95 OBJECT_PREVENT_OBJECT_COPY = 0x100, //!< Used internally. Prevent a node to copy its object (creating an empty node)
96 OBJECT_COPY_ALL_CHANNELS = 0x200, //!< If not defined, only CHANNEL_COPY_USEFUL_ONLY are copied (channels than are not auto generated
97 //OBJECT_COPY_KEEP_ID = 0x200, // Used internally. Keep the node and object id when copying to a different scene. The returned object/node are not assigned to any scene when set. Otherwise the returned object/node are assigned to the object/node reference scene, unless SetScene is call afterward.
99
100//! @class C3DBaseObject
101//! @brief This is the base class for any kind of object.
102//! @details The kind of C3DBaseObject can be retrieved using GetKindOf, which returns OBJECT_KINDOF. This is a way to cast the C3DBaseObject pointer into to one of its subclasses.
103//! Objects can be instantiated, which means referenced several time through the scene. This is why the destructor is protected and you must use Delete instead.\n
104//! Cf. @ref OBJECTS to get more details on objects and particularly C3DGeomObject.
105class DLL_3DFUNCTION C3DBaseObject : public CXObject, public CInstanciatedObject
106{
107 DECLARE_SERIAL_XOBJECT(C3DBaseObject);
108
109 friend CGeomInfo;
110
111public:
113 virtual bool DeleteFromNode(); // Internal: call from C3DSceneNode to decrease instance count if object has been instanciated. Return true if no instance of the object exists (most of the time this means that the object has been deleted, unless its ref with AddRef somewhere else)
114 static C3DBaseObject *Create(OBJECT_KINDOF kindOf); //!< Allocates and creates a new empty object of the given type #OBJECT_KINDOF. Uses xNew internally.
115
116 virtual void PostSerialize(CXArchive& ar, bool lastCall); // Called at the end of the scene serialization process
117 virtual void Serialize( CXArchive& ar );
118
119 //! @name Object instanciation
120 //!
121 //! objectGUID allows to get a single ID for a given object. This ID changed each time the object is copied, make any object having a single particular ID, except when object is instanciated.
122 //! All the objects instanciation share the same objectGUID.
123 //! Important: Instance of an object must be attached to a node, using C3DSceneNode::SetObject. Use AddRef otherwise.
124 //! Note: When object are copied between different scene, object instance are kept but a copy of the source is made and it has a different objectGUID
125 //!
126 //! Instanciation does not support material or UV bindings
127 //! Use C3DScene::CreateObjectInstance allow to create a new instance of the given object, or use Copy(OBJECT_COPY_CREATE_INSTANCE), then C3DSceneNode::SetObject
128 //!
129 //! @{
130 BaseObjectID GetObjectID() const; //!< Return the node GUID depending on the scene. If no scene defined, CGuidMgr::UNDEFINED_GUID is returned.
131 int GetInstanceCount() const; //!< Return the instance count. If the count then this is a single object that is referenced only one time in the scene
132 bool IsInstanciated() const; //!< return true if several instance of the object exists. The C3DSceneNode that reference these instances can be retrieved using C3DScene::GetInstancesByID
133
134 //! @}
135
136 virtual void SetScene(C3DScene *scene); //!< Associate the object to a scene. a GUID for that object in the scene is assigned.
137 C3DScene *GetScene() const; //!< Get the associated object scene
138
139 //! @name Checksum
140 //!
141 //! @brief These methods can be used to know if an object changed between two states.
142 //! If the checksum changed then the object too.
143 //! @{
144 unsigned int GetCustomDataChecksum(unsigned int ignoreCustomID, ...) const; //!< For object which are not geometric object, the checksum could be made on CustomData, and you can ignore some ID might be ignored if they content runtime value that does not reflect a change of the content. The list must be terminated by 0
145 virtual unsigned int GetChecksum(unsigned int checksumFlags = CHECKSUM_ALL) const; //!< When not overriden, the checksum is only made on the kind of object. When overidden, only the geometric data is taken into account. CustomData content is ignored, but if it is important a call to GetChecksum(unsigned int, ...) could be done.
146
147 //! @}
148
149 //! @name Object invalidation
150 //!
151 //! @{
152 virtual bool NeedUpdate() const;
153 virtual bool Update(C3DScene *scene, unsigned int updateMode); //!< Information that have been invalidated are recomputed when calling this method.IsInstanciated
154 virtual void Invalidate(unsigned int objectInvalidationFlags, bool set = true); //!< Notify that some information changed (combination of OBJECT_UPDATE_PROPERTIES invalidation flags) and invalidate related information, which will be updated in the Update call. The invalidated information is not destroyed until the next Update call.
155 virtual bool InvalidateChannels(unsigned int channelType); //!< Notify that channels that have cache should be recomputed (ie, UVW channel or normal channel for example). This give better control than Invalidate(OBJECT_INV_CHANNELS) which invalidate any channel information. We can specify with this method what need to be invalidated depending on the performed operation. Return true, if a cache has been invalidated
156
157 unsigned int GetInvalidateFlags() const; //!< Return the flags that have been invalidated
158 bool IsInvalidate(OBJECT_UPDATE_PROPERTIES flag) const; //!< Allow to know if an invalidate flag has been set. Invalidate flag is reset when Update is called.
159 longint GetUpdateStamp(OBJECT_UPDATE_PROPERTIES flags) const; //!< Allow to know if the given flag changed between two call
160
161 //! @}
162
163 //! @name Final object
164 //!
165 //! @brief Some kind of object might computes a final object, that depends of different internal parameters.
166 //! This is the case for C3DPatch for example where the final object depend on the subdivision level.
167 //! Most of the time the object and the final object are the same
168 //!
169 //! @{
170 //! @brief Returns true if this object is the object to be display (GetFinalObject == this) or false if the object to display should be computed from using this internal information (C3DPatch for example)
171 virtual bool IsFinalObject() const
172 {
173 return true;
174 }
175
176 //! @brief Returns the object itself or any kind of object. For example for a patch it can returns a C3DObject or a C3DPatch if the patch is not subdivided
177 virtual C3DBaseObject *GetFinalObject(bool detach = false, bool computeIfNeeded = true)
178 {
179 return this;
180 };
181
182 //! @}
183
184 //! @name Object operations
185 //!
186 //! @{
187 virtual bool MatrixTransform(const C4x4Matrix& matrix); //!< Transform the 3D information with the given matrix. The object should not be instanciated or all instance are modified
188 C3DBaseObject *Copy(int copyflags = OBJECT_COPY_DEFAULT, C3DObjectCreator *objectCreator = NULL) const;
189
190 //! @}
191
192 //! @name Kind of object, flags and custom data
193 //!
194 //! @{
195 void SetFlag(OBJECT_PROPERTIES flag, bool set);
196 void SetFlags(unsigned int flags, bool set);
197 bool IsFlagSet(OBJECT_PROPERTIES flag) const;
198 bool IsOneFlagSet(unsigned int flags) const;
199 bool CheckFlags(unsigned int checkflags, bool allSetOrNoneSet) const;
200
201 virtual void InheritFlags(const C3DBaseObject& srcObject, int copyflags = OBJECT_COPY_DEFAULT); //!< This methods only inherits srcObject flags and custom data and optionaly objectGUID / instanceID if srcObject is to be replaced by the object. It does not modify the data structure.
202
203 CCustomData& GetCustomData();
204 const CCustomData& GetCustomData() const;
205
206 //! @anchor cast
207 //! @brief Operators (cast operators, return NULL if object is this or if the type is incorrect
208 //! It does not perform any geometric or topologic conversions
209 operator C3DGeomObject*() const;
210 operator C3DGroup*() const; //!< Cf. @ref cast "C3DGeomObject*()"
211 operator C3DObject*() const; //!< Cf. @ref cast "C3DGeomObject*()"
212 operator C3DCurve*() const; //!< Cf. @ref cast "C3DGeomObject*()"
213 operator C3DPatch*() const; //!< Cf. @ref cast "C3DGeomObject*()"
214 operator C3DDummy*() const; //!< Cf. @ref cast "C3DGeomObject*()"
215 operator C3DLight*() const; //!< Cf. @ref cast "C3DGeomObject*()"
216 operator C3DCamera*() const; //!< Cf. @ref cast "C3DGeomObject*()"
217
218 bool IsGeomObject() const; //!< return true if the object is an OBJECT_GEOM. Cf. #OBJECT_KINDOF
219 OBJECT_KINDOF GetKindOf() const; //!< return #OBJECT_KINDOF, which defines the kind of object.
220 CXString GetTypeString() const; //!< return a string containing the kind of the object ("curve", "camera"...)
221
222 //! @}
223
224#ifdef _DEBUG
225 virtual void Dump(unsigned int flags);
226 virtual unsigned int MemoryStats() const;
227#endif
228
229protected :
230 virtual ~C3DBaseObject(); // Use Delete instead
231
232 void SetUpdateFlags(unsigned int flag, bool set);
233
234 virtual bool InternalCopy(C3DBaseObject *&dstObject, int flags = OBJECT_COPY_DEFAULT, C3DObjectCreator *objectCreator = NULL) const;
235
236 OBJECT_KINDOF kindOf;
237 unsigned int flags;
238 unsigned int updateFlags;
239 longint stamps[32];
240 CCustomData customData;
241 BaseObjectID objectGUID;
242 int instanceCount;
243
244 C3DScene *scene;
245
246private:
247 C3DBaseObject& operator=(const C3DBaseObject& refbaseObject) { return *this; }; // Use Copy instead
248};
249
250END_MOOTOOLS_NAMESPACE
251
252#endif // !defined(AFX_3DBASEOBJECT_H__31D6A935_B14E_11D2_A1E5_000000000000__INCLUDED_)
OBJECT_KINDOF
Definition 3DBaseObject.h:28
@ OBJECT_DUMMY
C3DDummy.
Definition 3DBaseObject.h:37
@ OBJECT_PATCH
C3DPatch.
Definition 3DBaseObject.h:35
@ OBJECT_GEOM_WITH_FACES
These flags can be used in C3DScene::GetFirstNode/GetNextNode or to perform a bitwise operation on C3...
Definition 3DBaseObject.h:46
@ OBJECT_CAMERA
C3DCamera.
Definition 3DBaseObject.h:38
@ OBJECT_ALL_KINDOF
This also include private type for copy and other specific operations.
Definition 3DBaseObject.h:48
@ OBJECT_MESH
C3DObject.
Definition 3DBaseObject.h:33
@ OBJECT_GROUP
C3DGroup.
Definition 3DBaseObject.h:36
@ OBJECT_CURVE
C3DCurve.
Definition 3DBaseObject.h:34
@ OBJECT_LIGHT
C3DLight.
Definition 3DBaseObject.h:39
OBJECT_UPDATE_PROPERTIES
Definition 3DBaseObject.h:67
@ OBJECT_INV_DATA
Custom data associated to object changed.
Definition 3DBaseObject.h:76
@ OBJECT_INV_DISPLAY
The object drawing should be updated.
Definition 3DBaseObject.h:78
@ OBJECT_INV_MATERIALS
Face materials changes.
Definition 3DBaseObject.h:73
@ OBJECT_INV_MATERIAL_ATTR
A material related to object changed.
Definition 3DBaseObject.h:75
@ OBJECT_INV_FACE_FLAG
Face properties changed (ie HIDDEN flag of face changed)
Definition 3DBaseObject.h:72
@ OBJECT_INV_CHANNELS
Channel changed, autogenerated channels need to be recomputed...
Definition 3DBaseObject.h:74
@ OBJECT_INV_TOPO
Faces indexes size, indexes changes.
Definition 3DBaseObject.h:71
@ OBJECT_UPDATE_BBOX
Bounding box will be recomputed next time we ask for the BBox.
Definition 3DBaseObject.h:84
@ OBJECT_INV_GEOM
Points position or number changed.
Definition 3DBaseObject.h:70
@ OBJECT_UPDATE_GEOM
Geometry need to be recomputed or updated. This should be done in the C3DBaseObject::Update.
Definition 3DBaseObject.h:85
@ OBJECT_UPDATE_CHANNELS
Update autogenerated channels (normals or projected UV for example)
Definition 3DBaseObject.h:86
@ OBJECT_UPDATE_FIRST_VALUE
For intenal offset.
Definition 3DBaseObject.h:83
OBJECT_COPY_FLAGS
Definition 3DBaseObject.h:92
@ OBJECT_COPY_ALL_CHANNELS
If not defined, only CHANNEL_COPY_USEFUL_ONLY are copied (channels than are not auto generated.
Definition 3DBaseObject.h:96
@ OBJECT_COPY_CREATE_INSTANCE
Create an instance copy of the object that should be affected to a node.
Definition 3DBaseObject.h:94
@ OBJECT_PREVENT_OBJECT_COPY
Used internally. Prevent a node to copy its object (creating an empty node)
Definition 3DBaseObject.h:95
C3DTPoint template class definition for handling x, y, z 3D point coordinate.
@ CHECKSUM_ALL
All is used for computing checksum.
Definition 3DType.h:433
CDependentChannels class definition which handles a CChannel array.
This is the base class for any kind of object.
Definition 3DBaseObject.h:106
virtual bool InvalidateChannels(unsigned int channelType)
Notify that channels that have cache should be recomputed (ie, UVW channel or normal channel for exam...
longint GetUpdateStamp(OBJECT_UPDATE_PROPERTIES flags) const
Allow to know if the given flag changed between two call.
virtual void InheritFlags(const C3DBaseObject &srcObject, int copyflags=OBJECT_COPY_DEFAULT)
This methods only inherits srcObject flags and custom data and optionaly objectGUID / instanceID if s...
virtual bool Update(C3DScene *scene, unsigned int updateMode)
Information that have been invalidated are recomputed when calling this method.IsInstanciated.
virtual bool MatrixTransform(const C4x4Matrix &matrix)
Transform the 3D information with the given matrix. The object should not be instanciated or all inst...
bool IsGeomObject() const
return true if the object is an OBJECT_GEOM. Cf. OBJECT_KINDOF
virtual unsigned int GetChecksum(unsigned int checksumFlags=CHECKSUM_ALL) const
When not overriden, the checksum is only made on the kind of object. When overidden,...
OBJECT_KINDOF GetKindOf() const
return OBJECT_KINDOF, which defines the kind of object.
BaseObjectID GetObjectID() const
Return the node GUID depending on the scene. If no scene defined, CGuidMgr::UNDEFINED_GUID is returne...
virtual void Invalidate(unsigned int objectInvalidationFlags, bool set=true)
Notify that some information changed (combination of OBJECT_UPDATE_PROPERTIES invalidation flags) and...
CXString GetTypeString() const
return a string containing the kind of the object ("curve", "camera"...)
static C3DBaseObject * Create(OBJECT_KINDOF kindOf)
Allocates and creates a new empty object of the given type OBJECT_KINDOF. Uses xNew internally.
bool IsInvalidate(OBJECT_UPDATE_PROPERTIES flag) const
Allow to know if an invalidate flag has been set. Invalidate flag is reset when Update is called.
int GetInstanceCount() const
Return the instance count. If the count then this is a single object that is referenced only one time...
bool IsInstanciated() const
return true if several instance of the object exists. The C3DSceneNode that reference these instances...
virtual void SetScene(C3DScene *scene)
Associate the object to a scene. a GUID for that object in the scene is assigned.
C3DScene * GetScene() const
Get the associated object scene.
virtual C3DBaseObject * GetFinalObject(bool detach=false, bool computeIfNeeded=true)
Returns the object itself or any kind of object. For example for a patch it can returns a C3DObject o...
Definition 3DBaseObject.h:177
unsigned int GetCustomDataChecksum(unsigned int ignoreCustomID,...) const
For object which are not geometric object, the checksum could be made on CustomData,...
unsigned int GetInvalidateFlags() const
Return the flags that have been invalidated.
C3DCamera handles camera object.
Definition 3DCamera.h:61
A 3D curve is a list of C3DPoint. It has specific flags and material.
Definition 3DCurve.h:20
A dummy is a void object that does not contains geometry.
Definition 3DDummy.h:21
This is the base class for any object containing geometry (curve, polygonal object,...
Definition 3DGeomObject.h:49
C3DGroup class is an object without geometry. C3DGroup allows to organize the scene hierarchically.
Definition 3DGroup.h:22
This class implements a light object in the scene (OBJECT_LIGHT)
Definition 3DLight.h:50
This class can be provided in C3DScene::Copy operations and allows to modify the created kind of clas...
Definition 3DScene.h:47
C3DObject handles polygonal mesh.
Definition 3DObject.h:24
C3DPatch handles handles patch object smoothed using a subdivision algorithm.
Definition 3DPatch.h:34
The class allows to get access to the scene graph, node hierarchy, material.
Definition 3DScene.h:306
CCustomData is a handly class for storing any kind of data.
Definition CustomData.h:106
CGeomInfo is an helper class oftenly required by different methods.
Definition GeomInfo.h:71
Definition InstanciatedObject.h:16
Definition XArchive.h:17