Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
3DSceneNode.h
Go to the documentation of this file.
1//! @file 3DSceneNode.h
2//! @brief C3DSceneNode class definition
3//!
4//////////////////////////////////////////////////////////////////////
5
6#if !defined(AFX_3DSCENENODE_H__5C85DAE7_BE95_4F8B_B661_B0CF9BE55255__INCLUDED_)
7#define AFX_3DSCENENODE_H__5C85DAE7_BE95_4F8B_B661_B0CF9BE55255__INCLUDED_
8
9#ifdef _MSC_VER
10#pragma once
11#endif // _MSC_VER
12
13#include "Tree.h"
14#include "3DGeomObject.h"
15#include "3DAnimatable.h"
16
17BEGIN_MOOTOOLS_NAMESPACE
18
19#define NODE_REFERENCE_NODE MAKE_CUSTOM_ID('R', 'F', 'N', 'O') // A binary C3DSceneNode * pointer
20#define NODE_LAYER_ID MAKE_CUSTOM_ID('L', 'Y', 'E', 'R') // Unsigned int
21#define NODE_LAYER_BBOX MAKE_CUSTOM_ID('L', 'Y', 'B', 'X') // 6 floats
22#define NODE_JASON_TXT MAKE_CUSTOM_ID('J', 'S', 'O', 'N') // String: Jason extra data
23
24#define NODE_GUID_CLASS MAKE_CUSTOM_ID('N', 'O', 'D', 'E')
25
26//! @enum SCENE_NODE_FLAGS
27//! Flags defining node properties
28typedef enum SCENE_NODE_FLAGS XEnumType(unsigned int)
29{
30 SCENE_NODE_NONE = 0x00,
31 SCENE_NODE_HIDDEN = 0x01, // Node show / hide flag
32 SCENE_NODE_IS_SELECTED = 0x02, // Node selection flag
33 SCENE_NODE_USER_DEFINED = 0x04, // Node has been created by user. The flag can be used to tag nodes that have been created by user or caller after reading a file
34
35 // Caller temporary flags. These flags can be used for specific purposes but it cannot be considered as a safe way to keep an information
36 // As different process might use the same flag for different purposes.
37 SCENE_NODE_USER_PROPERTIES1 = 0x100000,
38 SCENE_NODE_USER_PROPERTIES2 = 0x200000,
39 SCENE_NODE_USER_PROPERTIES3 = 0x400000,
40 SCENE_NODE_USER_PROPERTIES4 = 0x800000,
42
43//! @enum SCENE_NODE_UPDATE_PROPERTIES
44//! Flags used by C3DSceneNode::Invalidate. Depending on the SCENE_NODE_INV, the method set SCENE_NODE_UPDATE flags that will be processed during C3DSceneNode::Update call
45typedef enum SCENE_NODE_UPDATE_PROPERTIES XEnumType(unsigned int)
46{
47 SCENE_NODE_UPDATE_NONE = 0x0000000,
48
49 SCENE_NODE_INV_FLAGS = 0xFFFF,
50 SCENE_NODE_INV_ALL = SCENE_NODE_INV_FLAGS,
51 SCENE_NODE_INV_DISPLAY = 0x0001, // Node should be redrawn (ie, the matrix, an attribute changed, or name changed). If the attached object change, it must be invalidated too
52 SCENE_NODE_INV_DATA = 0x000, // Node custom data changed
53
54 SCENE_NODE_UPDATE_ALL = 0xFFFF0000,
56
57//! @class C3DSceneNode
58//! @brief A node matches one element that is part of the C3DScene graph. It references a C3DBaseObject and has some properties such matrix name, transformation, user custom data...
59//! @details Several nodes might reference the same object, which is called instantiation process.
60//! Nodes are organized hierarchically in the scene.\n
61//! Cf. @ref NODES to get more details on node usage.
62//! @note C3DSceneNode is not instantiable.
63class DLL_3DFUNCTION C3DSceneNode : protected CTreeNode, public C3DKeyframable
64{
65 friend C3DScene;
66
67 DECLARE_SERIAL_XOBJECT(C3DSceneNode)
68
69public:
70 C3DSceneNode(C3DBaseObject *nodeObject = NULL); // Create a node with an optional object attached to the node
71 virtual ~C3DSceneNode(); // Use Delete instead
72
73 static C3DSceneNode *Create(); // Allocates and creates an empty node. Same as xNew(C3DSceneNode).
74 virtual bool Delete(); // Delete a node when it has not been attached to a scene
75
76 virtual void PostSerialize(CXArchive& ar, bool lastCall); // Called at the end of the scene serialization process, both when loading and saving
77 virtual void Serialize(CXArchive& ar);
78
79 SceneNodeID32 GetNodeID32() const; // Return a 32 bits version of the GUID.
80 SceneNodeID GetNodeID() const; // Return the node GUID depending on the scene. If no scene defined, CGuidMgr::UNDEFINED_GUID is returned.
81 BaseObjectID GetObjectID() const; // Retrieve object ID
82 SceneNodeID SetNodeID(SceneNodeID nodeid); // Replace the node ID by a new one. If nodeid GUID already exists, then the provided value might be modified.
83
84 OBJECT_KINDOF GetObjectKindOf() const
85 {
86 if (object)
87 return object->GetKindOf();
88
89 return OBJECT_UNKNOWN;
90 }
91
92 void SetScene(C3DScene *scene); // Define the scene to which the node belong to. Set the attached object scene to. A node cannot belong to several scene, but it could be not rely to any scene
93 void SetObject(C3DBaseObject *pObj, bool deletePrevious = true);
94 C3DScene* GetScene() { return scene; }
95 C3DBaseObject *GetBaseObject(int time = 0) const;
96 C3DGeomObject *GetGeomObject(int time = 0) const;
97 bool IsGeomObject() const;
98 C3DBaseObject *GetFinalObject(int time = 0, bool computeIfNeeded = true) const;
99 CCustomData& GetCustomData() { return customData; }
100 const CCustomData& GetCustomData() const { return customData; }
101
102 void SetFlag(SCENE_NODE_FLAGS flag, bool set);
103 void SetFlags(unsigned int flags, bool set);
104 bool IsFlagSet(unsigned int flag) const;
105 bool IsOneFlagSet(unsigned int flags) const;
106 bool CheckFlags(unsigned int checkflags, bool allSetOrNoneSet) const;
107
108 void Update(unsigned int updateMode);
109 void Invalidate(unsigned int sceneNodeInvFlags, bool set = true); // A combination of invalidation flags in SCENE_NODE_UPDATE_PROPERTIES.
110 void InvalidateNodeAndObject(unsigned int sceneNodeInvFlags, unsigned int objectInvalidationFlags); // Invalidate both node and associated object (SCENE_NODE_UPDATE_PROPERTIES and OBJECT_UPDATE_PROPERTIES combinations)
111 bool IsInvalidate(SCENE_NODE_UPDATE_PROPERTIES flag) const;
112
113 // Animation
114 using C3DKeyframable::GetTimeRange;
115
116 // Matrix methods
117 // GetNodeLocalTM is useful for exporting (retrieve a matrix without pivot)
118 // GetObjectLocalTM / GetNodeTM is useful for displaying an object. It handles all the transformation information readed from a file (matrix, scale, rotate, pivot...)
119 void GetNodeLocalTM(int time, C4x4Matrix& matrix) const; // A node local matrix (without pivot consideration), useful for exporting to parser which does not handle pivot
120 void SetObjectLocalTM(int time, const C4x4Matrix& localMatrix, bool allowTrsDecomposition = true); // Set the object matrix. If allowTrsDecomposition, and the matrix can be decompose in translation / rotation / scale then KEYFRAME_TRANS, KEYFRAME_ROT, KEYFRAME_SCALE are updated and previous KEYFRAME_MATRIX transform is removed. If allowTrsDecomposition = false, then KEYFRAME_MATRIX is updated and KEYFRAME_TRANS, KEYFRAME_ROT, KEYFRAME_SCALE are removed. If time = C3DKeyframable::INVALID_TIME, then matrix is ignored and all transformation are removed
121 void GetObjectLocalTM(int time, C4x4Matrix& matrix) const; // The object local transformation matrix
122 void GetNodeTM(int time, C4x4Matrix& matrix, bool includeRootOrientation = true, bool excludePivot = false) const; // The node transformation matrix (taking the pivot into account)
123 void CenterPivotOnCG(const C3DVector& bboxOffset = C3DVector(0.5, 0.5, 0.5), const C3DVector& additionalOffset = C3DVector(0.0, 0.0, 0.0)); // Center the object at the world origin and modify the transformation matrix accordingly in order to keep the object at the same position. This result at making the pivot being centered on the CG
124 bool SwapPoints(unsigned int swapMode); // Swap node object points
125 bool SwapTransformations(unsigned int swapMode); // Swap node transformation
126 bool ConvertToGlobalCoordinates(int time); // Convert to matrix using the local node matrix (as node keeps its parent). Return true if node changed (beware internal object might changed, must call C3DSceneNode::GetBaseObject after operation), false if matrix is identity or node unchanged by the method. Use C3DScene::ConvertToGlobalCoordinates for removing transformation to a node branch
127 bool ConvertToGlobalCoordinates(const C4x4Matrix& matrix); // Convert to global coordinates using an alternative matrix. This remove the object instanciation, as it turns the coord to global only for the specified node
128
129 // Instanciation
130 bool DeleteObjectInstanciation(); // Remove instanciation for the node and replace it by a real copy. Return false if no instanciation exists for the node, true if the instance has been replaced by a copy
131 bool IsObjectIntanciated(bool checkChilds = false) const; // Return true if the node's object is instanciated. If checkChilds = true, returns true if the whole child branch is made of instance (any childs of the node contains an object instance (excluding the node itself))
132
133 // Geometry information
134 bool GetBoundingBox(int time, C3DBBox& bbox, unsigned int bboxflags, unsigned int extraNodeOrPtFaceFlags = 0, unsigned int extraKindOfObject = OBJECT_UNKNOWN); // Note: BBOX_NODE_TRANSFORM set in bboxflags then all points are transformed with matrix node. Otherwise the node transform is only applied to bounding box. If no node transform is required, BBOX_DONT_APPLY_NODE_TRANSFORM must be used.
135 bool GetBoundingBox(int time, C3DPoint& point1, C3DPoint& point2, unsigned int bboxflags, unsigned int extraNodeOrPtFaceFlags = 0, unsigned int extraKindOfObject = OBJECT_UNKNOWN); // Note: BBOX_NODE_TRANSFORM set in bboxflags then all points are transformed with matrix node. Otherwise the node transform is only applied to bounding box. If no node transform is required, BBOX_DONT_APPLY_NODE_TRANSFORM must be used.
136 bool GetCG(int time, C3DPoint& CG);
137
138 // name
139 void SetName(const CXString& name);
140 CXString GetName() const;
141
142 void Inherit(const C3DSceneNode *from, int flags = OBJECT_COPY_DEFAULT); // Inherit the node properties (flag, customdata, keyframe). if OBJECT_COPY_KEEP_ID is defined, the node inherit from nodeID. Caller is responsible to attach the node to a scene using C3DScene::AddNode or to call SetScene. The node attached object is not modified by inherit
143 C3DSceneNode *Copy(int copyFlags = OBJECT_COPY_DEFAULT, C3DObjectCreator *objectCreator = NULL) const;
144 C3DSceneNode *CopyBranch(C3DSceneNode *parent = NULL, int copyFlags = OBJECT_COPY_DEFAULT, C3DObjectCreator *objectCreator = NULL) const; // Copy a branch
145
146 // Specific purposes
147 CTreeNode *GetTreeNode() { return this; } // CTreeNode base class has protected access, so use this with precaution
148
149#ifdef _DEBUG
150 virtual bool Dump(unsigned int flags) const;
151#endif
152
153protected:
154 C3DScene *scene;
155 C3DBaseObject *object;
156 CCustomData customData;
157
158 SceneNodeID nodeGUID;
159
160 int nodeFlags;
161 int updateFlags;
162
163 CXString name;
164
165 mutable struct CacheData
166 {
167 typedef enum ValidData XEnumType(unsigned int)
168 {
169 VALID_NONE,
170 VALID_NODE_TM,
171 VALID_LOCAL_TM,
172 } ValidData;
173
174 unsigned int validData;
175 int time;
176 C4x4Matrix nodeTm, localTm;
177
178 bool IsValid(unsigned int time, ValidData flag);
179 } cacheData;
180
181 void InitNode();
182 void SetInvalidateFlag(unsigned int flag, bool set);
183 virtual void OnParentingChanged() const; // Notify that a change occurs in parenting
184 virtual void OnKeyframesChanged(longuint classID) const; // Notify that something changed in the keyframes. classID == KEYFRAME_NULLID, if all kind of keyframe changed
185
186 bool InternalGetBoundingBox(int time, C3DPoint& point1, C3DPoint& point2, unsigned int bboxflags, unsigned int elmtflags, bool set) const;
187 bool InternalGetCG(int time, C3DPoint& CG) const;
188
189 // Inherited from CTree, low level access
190 virtual CXString GetDisplayName() const;
191
192private:
193 virtual C3DSceneNode& operator=(const C3DSceneNode& refnode) { return *this; }; // Use copy instead, or inherit to get node flags and matrices
194};
195
196END_MOOTOOLS_NAMESPACE
197
198#endif // !defined(AFX_3DSCENENODE_H__5C85DAE7_BE95_4F8B_B661_B0CF9BE55255__INCLUDED_)
C3DKeyframable class for handling keyframes.
OBJECT_KINDOF
Definition 3DBaseObject.h:28
SCENE_NODE_FLAGS
Definition 3DSceneNode.h:29
SCENE_NODE_UPDATE_PROPERTIES
Definition 3DSceneNode.h:46
This is the base class for any kind of object.
Definition 3DBaseObject.h:106
This is the base class for any object containing geometry (curve, polygonal object,...
Definition 3DGeomObject.h:49
This is the base class for any object that can be animated using C3DKeyframe.
Definition 3DAnimatable.h:51
This class can be provided in C3DScene::Copy operations and allows to modify the created kind of clas...
Definition 3DScene.h:47
The class allows to get access to the scene graph, node hierarchy, material.
Definition 3DScene.h:306
A node matches one element that is part of the C3DScene graph. It references a C3DBaseObject and has ...
Definition 3DSceneNode.h:64
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
CCustomData is a handly class for storing any kind of data.
Definition CustomData.h:106
Definition Tree.h:54
Definition XArchive.h:17