1 /*
2     Copyright (c) 2008-2009 NetAllied Systems GmbH
3 
4 	This file is part of COLLADAStreamWriter.
5 
6     Licensed under the MIT Open Source License,
7     for details please see LICENSE file or the website
8     http://www.opensource.org/licenses/mit-license.php
9 */
10 
11 #ifndef __COLLADASTREAMWRITER_NODE_H__
12 #define __COLLADASTREAMWRITER_NODE_H__
13 
14 #include "COLLADASWPrerequisites.h"
15 #include "COLLADASWElementWriter.h"
16 #include "COLLADASWExtraTechnique.h"
17 #include "COLLADASWConstants.h"
18 #include "COLLADABUURI.h"
19 
20 namespace COLLADASW
21 {
22 
23     /** A class to write a @a \<node\> element to the stream.*/
24 
25     class Node : public ElementWriter, public BaseExtraTechnique
26     {
27 
28     public:
29 
30         /** The node types*/
31         enum Type
32         {
33             DEFAULT,
34             NODE,
35             JOINT // Joints are called bones in 3dsMax. A joint is a scene node that is used in skinning.
36         };
37 
38     private:
39 
40         /** Closer to close the node*/
41         TagCloser mNodeCloser;
42 
43         /** The type of the node*/
44         Type mType;
45 
46         /** The id of the node*/
47         String mNodeId;
48 
49         /** The name of the node*/
50         String mNodeName;
51 
52         /** The sid of the current node. Used for joints. */
53         String mNodeSid;
54 
55         /** The URL of an instance node. */
56         COLLADABU::URI mNodeURL;
57 
58         /** Flag, if it is an node instance. */
59         bool mIsInstanceNode;
60 
61     public:
62 
63         Node ( StreamWriter* streamWriter, const bool isInstanceNode=false )
ElementWriter(streamWriter)64                 : ElementWriter ( streamWriter ),
65                 mType ( DEFAULT ),
66                 mNodeId ( EMPTY_STRING ),
67                 mNodeName ( EMPTY_STRING ),
68                 mNodeURL ( EMPTY_STRING, EMPTY_STRING ),
69                 mIsInstanceNode ( isInstanceNode )
70         {}
71 
72 		/** Flag, if it is an node instance. */
getIsInstanceNode()73         bool getIsInstanceNode() const
74         {
75             return mIsInstanceNode;
76         }
77 
78         /** Flag, if it is an node instance. */
setIsInstanceNode(bool val)79         void setIsInstanceNode( bool val )
80         {
81             mIsInstanceNode = val;
82         }
83 
84 		/** Returns a reference to the id of the node*/
getNodeId()85         const String& getNodeId() const
86         {
87             return mNodeId;
88         }
89 
90         /** Sets the id of the node*/
setNodeId(const String & id)91         void setNodeId ( const String& id )
92         {
93             mNodeId = id;
94         }
95 
96         /** Returns a reference to the name of the node*/
getNodeName()97         const String& getNodeName() const
98         {
99             return mNodeName;
100         }
101 
102         /** Sets the name of the node*/
setNodeName(const String & nodeName)103         void setNodeName ( const String& nodeName )
104         {
105             mNodeName = nodeName;
106         }
107 
108         /** The sid of the current node. Used for joints. */
getNodeSid()109         const String getNodeSid() const
110         {
111             return mNodeSid;
112         }
113 
114         /** The sid of the current node. Used for joints. */
setNodeSid(const String & val)115         void setNodeSid( const String& val )
116         {
117             mNodeSid = val;
118         }
119 
120         /** The URL of an instance node. */
getNodeURL()121         const COLLADABU::URI& getNodeURL() const
122         {
123             return mNodeURL;
124         }
125 
126         /** The URL of an instance node. */
setNodeURL(const COLLADABU::URI & val)127         void setNodeURL( const COLLADABU::URI& val )
128         {
129             mNodeURL = val;
130         }
131 
132         /** Returns the type of the node*/
getType()133         Type getType() const
134         {
135             return mType;
136         }
137 
138         /** Sets the type of the node*/
setType(Type type)139         void setType ( Type type )
140         {
141             mType = type;
142         }
143 
144         /** Opens the node
145         It should be closed using close()*/
146 		void start(bool forceNonInstancedNode = false);
147 
148         /** Adds a translation with sid @a sid*/
149         void addTranslate ( const String& sid, double x, double y, double z ) const ;
150 
151         /** Adds a translation*/
152         void addTranslate ( double x, double y, double z ) const ;
153 
154         /** Adds a rotation with sid @a sid*/
155         void addRotate ( const String& sid, double x, double y, double z, double angle ) const ;
156 
157         /** Adds a rotation around the x-axis with sid @a sid */
addRotateX(const String & sid,double angle)158         void addRotateX ( const String& sid, double angle ) const
159         {
160             addRotate ( sid, 1, 0, 0, angle );
161         }
162 
163         /** Adds a rotation around the y-axis with sid @a sid */
addRotateY(const String & sid,double angle)164         void addRotateY ( const String& sid, double angle )  const
165         {
166             addRotate ( sid, 0, 1, 0, angle );
167         }
168 
169         /** Adds a rotation around the Z-axis with sid @a sid */
addRotateZ(const String & sid,double angle)170         void addRotateZ ( const String& sid, double angle ) const
171         {
172             addRotate ( sid, 0, 0, 1, angle );
173         }
174 
175 		/** Adds a rotation around the x-axis.*/
addRotateX(double angle)176 		void addRotateX ( double angle ) const
177 		{
178 			addRotate ( 1, 0, 0, angle );
179 		}
180 
181 		/** Adds a rotation around the y-axis.*/
addRotateY(double angle)182 		void addRotateY (  double angle )  const
183 		{
184 			addRotate ( 0, 1, 0, angle );
185 		}
186 
187 		/** Adds a rotation around the Z-axis.*/
addRotateZ(double angle)188 		void addRotateZ ( double angle ) const
189 		{
190 			addRotate ( 0, 0, 1, angle );
191 		}
192 
193 
194 
195 		/** Adds a rotation*/
196         void addRotate ( double x, double y, double z, double angle ) const ;
197 
198         /** Adds a matrix with sid @a sid*/
199         void addMatrix ( const String& sid, double matrix[4][4] ) const ;
200 
201         /** Adds a matrix*/
202         void addMatrix ( double matrix[4][4] ) const ;
203 
204         /** Adds a scale with sid @a sid*/
205         void addScale ( const String& sid, double x, double y, double z )  const;
206 
207         /** Adds a scale*/
208         void addScale ( double x, double y, double z ) const;
209 
210         /** Adds the skew of the current mesh element. */
211         void addSkew ( const String& sid, const float angle,
212                        const float rotateAxis[3], const float aroundAxis[3] ) const;
213 
214         /**
215          * The <lookat> element contains a float3x3, which is three
216          * mathematical vectors.
217          * Positioning and orienting a camera or object in the scene is often
218          * complicated when using a matrix. A lookat transform is an intuitive
219          * way to specify an eye position, interest point, and orientation.
220          * @param eyePosition[3] The position of the object.
221          * @param interestPosition[3] The position of the interest point.
222          * @param upPosition[3] The direction that points up.
223          * @param sid Subidentifier of this element, optional.
224          */
225         void addLookat (
226             const float eyePosition[3],
227             const float interestPosition[3],
228             const float upPosition[3],
229             const String &sid = "" );
230 
231         /** Closes the node
232         It must have been opened using open()*/
233         void end() ;
234 
235     };
236 
237 
238 } //namespace COLLADASW
239 
240 
241 #endif //__COLLADASTREAMWRITER_NODE_H__
242