[964] | 1 | /*
|
---|
| 2 | Copyright (C) 2005-2006 Feeling Software Inc.
|
---|
| 3 | MIT License: http://www.opensource.org/licenses/mit-license.php
|
---|
| 4 | */
|
---|
| 5 | /*
|
---|
| 6 | Based on the FS Import classes:
|
---|
| 7 | Copyright (C) 2005-2006 Feeling Software Inc
|
---|
| 8 | Copyright (C) 2005-2006 Autodesk Media Entertainment
|
---|
| 9 | MIT License: http://www.opensource.org/licenses/mit-license.php
|
---|
| 10 | */
|
---|
| 11 |
|
---|
| 12 | /**
|
---|
| 13 | @file FCDSceneNode.h
|
---|
| 14 | This file contains the FCDSceneNode class.
|
---|
| 15 | */
|
---|
| 16 |
|
---|
| 17 | #ifndef _FCD_SCENE_NODE_
|
---|
| 18 | #define _FCD_SCENE_NODE_
|
---|
| 19 |
|
---|
| 20 | #include "FCDocument/FCDEntity.h"
|
---|
| 21 | #include "FCDocument/FCDTransform.h" /** @todo Remove this include by moving the FCDTransform::Type enum to FUDaeEnum.h. */
|
---|
| 22 | #include "FCDocument/FCDEntityInstance.h" /** @todo Remove this include by moving the FCDEntityInstance::Type enum to FUDaeEnum.h. */
|
---|
| 23 |
|
---|
| 24 | class FCDocument;
|
---|
| 25 | class FCDEntityInstance;
|
---|
| 26 | class FCDSceneNode;
|
---|
| 27 | class FCDTransform;
|
---|
| 28 | class FCDExtra;
|
---|
| 29 | class FCDTRotation;
|
---|
| 30 | class FCDTTranslation;
|
---|
| 31 | class FCDTScale;
|
---|
| 32 | class FCDTSkew;
|
---|
| 33 | class FCDTLookAt;
|
---|
| 34 | class FCDTMatrix;
|
---|
| 35 |
|
---|
| 36 | typedef vector<FCDSceneNode*> FCDSceneNodeList; /**< A dynamically-sized array of scene nodes. */
|
---|
| 37 | typedef vector<FCDEntityInstance*> FCDEntityInstanceList; /**< A dynamically-sized array of entitiy instances. */
|
---|
| 38 | typedef vector<FCDTransform*> FCDTransformList; /**< A dynamically-sized array of transforms. */
|
---|
| 39 |
|
---|
| 40 | /**
|
---|
| 41 | A COLLADA visual scene node.
|
---|
| 42 | This class is also used to represent COLLADA visual scene entities.
|
---|
| 43 |
|
---|
| 44 | A visual scene node contains child scene nodes to make a tree.
|
---|
| 45 | A visual scene node may appear multiple times within the scene graph,
|
---|
| 46 | but checks are made to verify that there are no cycles within the graph.
|
---|
| 47 |
|
---|
| 48 | A visual scene node also contained an ordered list of transformations
|
---|
| 49 | and a list of entity instances.
|
---|
| 50 |
|
---|
| 51 | @ingroup FCDocument
|
---|
| 52 | */
|
---|
| 53 | class FCOLLADA_EXPORT FCDSceneNode : public FCDEntity
|
---|
| 54 | {
|
---|
| 55 | private:
|
---|
| 56 | DeclareObjectType;
|
---|
| 57 | FCDSceneNodeList parents;
|
---|
| 58 | FCDSceneNodeList children;
|
---|
| 59 | FCDTransformList transforms;
|
---|
| 60 | FCDEntityInstanceList instances;
|
---|
| 61 |
|
---|
| 62 | // Visibility parameter. Should be a boolean, but is animated
|
---|
| 63 | float visibility; // Maya-specific
|
---|
| 64 |
|
---|
| 65 | // The number of entities that target this node
|
---|
| 66 | uint32 targetCount;
|
---|
| 67 |
|
---|
| 68 | // Whether this node is a joint.
|
---|
| 69 | bool isJoint;
|
---|
| 70 |
|
---|
| 71 | public:
|
---|
| 72 | /** Constructor: do not use directly.
|
---|
| 73 | Instead, use the FCDSceneNode::AddChild function for child
|
---|
| 74 | visual scene nodes or the FCDLibrary::AddEntity function
|
---|
| 75 | for visual scenes.
|
---|
| 76 | @param document The COLLADA document that owns the scene node. */
|
---|
| 77 | FCDSceneNode(FCDocument* document);
|
---|
| 78 |
|
---|
| 79 | /** Destructor: do not use directly.
|
---|
| 80 | Instead, use the FCDSceneNode::ReleaseChild function for visual
|
---|
| 81 | scene nodes or the FCDLibrary::ReleaseEntity function for visual scenes. */
|
---|
| 82 | virtual ~FCDSceneNode();
|
---|
| 83 |
|
---|
| 84 | /** Retrieves the type of the entity class.
|
---|
| 85 | @return The type of entity class: SCENE_NODE. */
|
---|
| 86 | inline virtual Type GetType() const { return SCENE_NODE; }
|
---|
| 87 |
|
---|
| 88 | /** Retrieves the number of parent nodes for this visual scene node.
|
---|
| 89 | @return The number of parents. */
|
---|
| 90 | inline size_t GetParentCount() const { return parents.size(); };
|
---|
| 91 |
|
---|
| 92 | /** Retrieves a specific parent of the visual scene node.
|
---|
| 93 | @param index The index of the parent.
|
---|
| 94 | @return The parent visual scene node. This pointer will be NULL if
|
---|
| 95 | the scene node has no parents or if the index is out-of-bounds. */
|
---|
| 96 | inline FCDSceneNode* GetParent(size_t index = 0) { FUAssert(index == 0 || index < parents.size(), return NULL); return (!parents.empty()) ? parents.at(index) : NULL; }
|
---|
| 97 | inline const FCDSceneNode* GetParent(size_t index = 0) const { FUAssert(index == 0 || index < parents.size(), return NULL); return (!parents.empty()) ? parents.at(index) : NULL; } /**< See above. */
|
---|
| 98 |
|
---|
| 99 | /** Retrieves the number of child nodes for this visual scene node.
|
---|
| 100 | @return The number of children. */
|
---|
| 101 | inline size_t GetChildrenCount() const { return children.size(); };
|
---|
| 102 |
|
---|
| 103 | /** Retrieves a specific child of the visual scene node.
|
---|
| 104 | @param index The index of the child.
|
---|
| 105 | @return The child scene node. This pointer will be NULL if the
|
---|
| 106 | index is out-of-bounds. */
|
---|
| 107 | inline FCDSceneNode* GetChild(size_t index) { FUAssert(index < children.size(), return NULL); return children.at(index); }
|
---|
| 108 | inline const FCDSceneNode* GetChild(size_t index) const { FUAssert(index < children.size(), return NULL); return children.at(index); } /**< See above. */
|
---|
| 109 |
|
---|
| 110 | /** Retrieves the list of children of the visual scene node.
|
---|
| 111 | @return The list of child scene nodes. */
|
---|
| 112 | inline FCDSceneNodeList& GetChildren() { return children; }
|
---|
| 113 | inline const FCDSceneNodeList& GetChildren() const { return children; } /**< See above. */
|
---|
| 114 |
|
---|
| 115 | /** Creates a new child scene node.
|
---|
| 116 | @return The new child scene node. */
|
---|
| 117 | FCDSceneNode* AddChildNode();
|
---|
| 118 |
|
---|
| 119 | /** Attaches a existing scene node to this visual scene node.
|
---|
| 120 | This function will fail if attaching the given scene node
|
---|
| 121 | to this visual scene node creates a cycle within the scene graph.
|
---|
| 122 | @param sceneNode The scene node to attach.
|
---|
| 123 | @return Whether the given scene node was attached to this scene node. */
|
---|
| 124 | bool AddChildNode(FCDSceneNode* sceneNode);
|
---|
| 125 |
|
---|
| 126 | /** Retrieves the number of entity instances at this node of the scene graph.
|
---|
| 127 | @return The number of entity instances. */
|
---|
| 128 | inline size_t GetInstanceCount() const { return instances.size(); };
|
---|
| 129 |
|
---|
| 130 | /** Retrieves a specific entity instance.
|
---|
| 131 | @param index The index of the instance.
|
---|
| 132 | @return The entity instance at the given index. This pointer will be
|
---|
| 133 | NULL if the index is out-of-bounds. */
|
---|
| 134 | inline FCDEntityInstance* GetInstance(size_t index) { FUAssert(index < instances.size(), return NULL); return instances.at(index); }
|
---|
| 135 | inline const FCDEntityInstance* GetInstance(size_t index) const { FUAssert(index < instances.size(), return NULL); return instances.at(index); } /**< See above. */
|
---|
| 136 |
|
---|
| 137 | /** Retrieves the list of entity instances at this node of the scene graph.
|
---|
| 138 | @return The list of entity instances. */
|
---|
| 139 | inline FCDEntityInstanceList& GetInstances() { return instances; }
|
---|
| 140 | inline const FCDEntityInstanceList& GetInstances() const { return instances; } /**< See above. */
|
---|
| 141 |
|
---|
| 142 | /** Creates a new entity instance.
|
---|
| 143 | Only geometric entities, controllers, light and cameras
|
---|
| 144 | can be instantiated in the scene graph.
|
---|
| 145 | To instantiate visual scene nodes, use the AddChildNode function.
|
---|
| 146 | @param entity The entity to instantiate. Set this pointer to NULL
|
---|
| 147 | to instantiate an external entity.
|
---|
| 148 | @return The entity instance structure. This pointer will be NULL
|
---|
| 149 | if the entity cannot be instantiated here. */
|
---|
| 150 | FCDEntityInstance* AddInstance(FCDEntity* entity);
|
---|
| 151 |
|
---|
| 152 | /** Releases an entity instance.
|
---|
| 153 | @param instance The entity instance to release. */
|
---|
| 154 | void ReleaseInstance(FCDEntityInstance* instance);
|
---|
| 155 |
|
---|
| 156 | /** Retrieves the number of transforms for this node of the scene graph.
|
---|
| 157 | @return The number of transforms. */
|
---|
| 158 | inline size_t GetTransformCount() const { return transforms.size(); };
|
---|
| 159 |
|
---|
| 160 | /** Retrieves a specific transform.
|
---|
| 161 | @param index The index of the transform.
|
---|
| 162 | @return The transform at the given index. This pointer will be NULL
|
---|
| 163 | if the index is out-of-bounds. */
|
---|
| 164 | inline FCDTransform* GetTransform(size_t index) { FUAssert(index < transforms.size(), return NULL); return transforms.at(index); }
|
---|
| 165 | inline const FCDTransform* GetTransform(size_t index) const { FUAssert(index < transforms.size(), return NULL); return transforms.at(index); } /**< See above. */
|
---|
| 166 |
|
---|
| 167 | /** Retrieves the list of transforms for this node of the scene graph.
|
---|
| 168 | @return The list of transforms. */
|
---|
| 169 | inline FCDTransformList& GetTransforms() { return transforms; }
|
---|
| 170 | inline const FCDTransformList& GetTransforms() const { return transforms; } /**< See above. */
|
---|
| 171 |
|
---|
| 172 | /** Creates a new transform for this visual scene node.
|
---|
| 173 | The transforms are processed in order and COLLADA is column-major.
|
---|
| 174 | For row-major matrix stacks, such as DirectX, this implies that the
|
---|
| 175 | transformations will be processed in reverse order.
|
---|
| 176 | By default, a transform is added at the end of the list.
|
---|
| 177 | @param type The type of transform to create.
|
---|
| 178 | @param index The index at which to insert the transform. Set this value to -1
|
---|
| 179 | to indicate that you want this transform at the end of the stack.
|
---|
| 180 | @return The created transform. */
|
---|
| 181 | FCDTransform* AddTransform(FCDTransform::Type type, size_t index = (size_t)-1);
|
---|
| 182 |
|
---|
| 183 | /** Releases a transform affecting this visual scene node.
|
---|
| 184 | @param transform The transform to release. */
|
---|
| 185 | void ReleaseTransform(FCDTransform* transform);
|
---|
| 186 |
|
---|
| 187 |
|
---|
| 188 | /** Retrieves the visual scene node with the given id.
|
---|
| 189 | This function looks through the whole tree of visual scene nodes
|
---|
| 190 | for the wanted COLLADA id.
|
---|
| 191 | @param daeId The COLLADA id to look for.
|
---|
| 192 | @return The visual scene node which has the given COLLADA id. This pointer
|
---|
| 193 | will be NULL if no visual scene node can be found with the given COLLADA id. */
|
---|
| 194 | virtual FCDEntity* FindDaeId(const string& daeId);
|
---|
| 195 |
|
---|
| 196 | /** Retrieves whether the visual scene node is visible.
|
---|
| 197 | A hidden visual scene node will not be rendered but will
|
---|
| 198 | still affect the world. This parameter is a floating-point value
|
---|
| 199 | because it is animated. It should be intepreted as a Boolean value.
|
---|
| 200 | @return Whether the scene node is visible. */
|
---|
| 201 | inline float& GetVisibility() { return visibility; }
|
---|
| 202 | inline const float& GetVisibility() const { return visibility; } /**< See above. */
|
---|
| 203 |
|
---|
| 204 | /** Sets the visibility of the visual scene node.
|
---|
| 205 | A hidden visual scene node will not be rendered but will
|
---|
| 206 | still affect the world.
|
---|
| 207 | @param isVisible Whether the visual scene node is visible. */
|
---|
| 208 | inline void SetVisibility(bool isVisible) { visibility = isVisible; }
|
---|
| 209 |
|
---|
| 210 | /** Retrieves whether this visual scene node is the target of an entity.
|
---|
| 211 | @return Whether this is an entity target. */
|
---|
| 212 | inline bool IsTarget() const { return targetCount > 0; }
|
---|
| 213 |
|
---|
| 214 | /** Retrieves whether this visual scene node is a joint.
|
---|
| 215 | Joints are called bones in 3dsMax. A joint is a scene node that is used in skinning.
|
---|
| 216 | @return Whether this node is a joint. */
|
---|
| 217 | bool IsJoint() const { return isJoint; }
|
---|
| 218 |
|
---|
| 219 | /** Sets whether a visual scene node is a joint.
|
---|
| 220 | Joints are called bones in 3dsMax. A joint is a scene node that is used in skinning.
|
---|
| 221 | @param _isJoint Whether this node is a joint. */
|
---|
| 222 | void SetJointFlag(bool _isJoint) { isJoint = _isJoint; }
|
---|
| 223 |
|
---|
| 224 | /** Retrieves the local transform for this visual scene node.
|
---|
| 225 | This function does not handle or apply animations.
|
---|
| 226 | @return The local transform. */
|
---|
| 227 | FMMatrix44 ToMatrix() const;
|
---|
| 228 |
|
---|
| 229 | /** Generates a list of local transform samples for this visual scene node.
|
---|
| 230 | This function will <b>permanently</b> modify the transforms of this visual scene node.
|
---|
| 231 | @param keys A list of key inputs that will be filled in with the sample times.
|
---|
| 232 | @param values A list of matrices that will be filled in with the sampled local transforms. */
|
---|
| 233 | void GenerateSampledMatrixAnimation(FloatList& keys, FMMatrix44List& values);
|
---|
| 234 |
|
---|
| 235 | /** [INTERNAL] Increments the number of entities target this node.
|
---|
| 236 | To set targets, use the FCDTargetedEntity::SetTarget function. */
|
---|
| 237 | inline void IncrementTargetCount() { ++targetCount; }
|
---|
| 238 |
|
---|
| 239 | /** [INTERNAL] Decrements the number of entities target this node.
|
---|
| 240 | To set targets, use the FCDTargetedEntity::SetTarget function. */
|
---|
| 241 | inline void DecrementTargetCount() { if (targetCount > 0) --targetCount; }
|
---|
| 242 |
|
---|
| 243 | /** [INTERNAL] Reads in the visual scene node from a given COLLADA XML tree node.
|
---|
| 244 | @param sceneNode The COLLADA XML tree node.
|
---|
| 245 | @return The status of the import. If the status is not successful,
|
---|
| 246 | it may be dangerous to extract information from the node.*/
|
---|
| 247 | virtual FUStatus LoadFromXML(xmlNode* sceneNode);
|
---|
| 248 |
|
---|
| 249 | /** [INTERNAL] Writes out the visual scene node to the given COLLADA XML tree node.
|
---|
| 250 | @param parentNode The COLLADA XML parent node in which to insert the node.
|
---|
| 251 | @return The created XML tree node. */
|
---|
| 252 | virtual xmlNode* WriteToXML(xmlNode* parentNode) const;
|
---|
| 253 |
|
---|
| 254 | private:
|
---|
| 255 | FUStatus LoadFromExtra();
|
---|
| 256 | void BindMaterial(xmlNode* node);
|
---|
| 257 | void WriteToNodeXML(xmlNode* node, bool isVisualScene) const;
|
---|
| 258 | };
|
---|
| 259 |
|
---|
| 260 | #endif // _FCD_SCENE_NODE_
|
---|