OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
node.hpp
Go to the documentation of this file.
1 #ifndef OPENMW_COMPONENTS_NIF_NODE_HPP
2 #define OPENMW_COMPONENTS_NIF_NODE_HPP
3 
4 #include "controlled.hpp"
5 #include "extra.hpp"
6 #include "data.hpp"
7 #include "property.hpp"
8 #include "niftypes.hpp"
9 #include "controller.hpp"
10 #include "base.hpp"
11 
13 
14 namespace Nif
15 {
16 
17 struct NiNode;
18 
23 class Node : public Named
24 {
25 public:
26  // Node flags. Interpretation depends somewhat on the type of node.
27  int flags;
29  osg::Vec3f velocity; // Unused? Might be a run-time game state
31 
32  // Bounding box info
33  bool hasBounds;
34  osg::Vec3f boundPos;
36  osg::Vec3f boundXYZ; // Box size
37 
38  void read(NIFStream *nif)
39  {
40  Named::read(nif);
41 
42  flags = nif->getUShort();
43  trafo = nif->getTrafo();
44  velocity = nif->getVector3();
45  props.read(nif);
46 
47  hasBounds = !!nif->getInt();
48  if(hasBounds)
49  {
50  nif->getInt(); // always 1
51  boundPos = nif->getVector3();
52  boundRot = nif->getMatrix3();
53  boundXYZ = nif->getVector3();
54  }
55 
56  parent = NULL;
57 
58  boneTrafo = NULL;
59  boneIndex = -1;
60  }
61 
62  void post(NIFFile *nif)
63  {
64  Named::post(nif);
65  props.post(nif);
66  }
67 
68  // Parent node, or NULL for the root node. As far as I'm aware, only
69  // NiNodes (or types derived from NiNodes) can be parents.
71 
72  // Bone transformation. If set, node is a part of a skeleton.
74 
75  // Bone weight info, from NiSkinData
77 
78  // Bone index. If -1, this node is either not a bone, or if
79  // boneTrafo is set it is the root bone in the skeleton.
80  short boneIndex;
81 
82  void makeRootBone(const Transformation *tr)
83  {
84  boneTrafo = tr;
85  boneIndex = -1;
86  }
87 
88  void makeBone(short ind, const NiSkinData::BoneInfo &bi)
89  {
90  boneInfo = &bi;
91  boneTrafo = &bi.trafo;
92  boneIndex = ind;
93  }
94 };
95 
96 struct NiNode : Node
97 {
100 
101  enum Flags {
102  Flag_Hidden = 0x0001,
105  };
106  enum BSAnimFlags {
108  };
112  };
115  };
116 
117  void read(NIFStream *nif)
118  {
119  Node::read(nif);
120  children.read(nif);
121  effects.read(nif);
122 
123  // Discard transformations for the root node, otherwise some meshes
124  // occasionally get wrong orientation. Only for NiNode-s for now, but
125  // can be expanded if needed.
126  if (0 == recIndex && !Misc::StringUtils::ciEqual(name, "bip01"))
127  {
128  static_cast<Nif::Node*>(this)->trafo = Nif::Transformation::getIdentity();
129  }
130  }
131 
132  void post(NIFFile *nif)
133  {
134  Node::post(nif);
135  children.post(nif);
136  effects.post(nif);
137 
138  for(size_t i = 0;i < children.length();i++)
139  {
140  // Why would a unique list of children contain empty refs?
141  if(!children[i].empty())
142  children[i]->parent = this;
143  }
144  }
145 };
146 
147 struct NiTriShape : Node
148 {
149  /* Possible flags:
150  0x40 - mesh has no vertex normals ?
151 
152  Only flags included in 0x47 (ie. 0x01, 0x02, 0x04 and 0x40) have
153  been observed so far.
154  */
155 
158 
159  void read(NIFStream *nif)
160  {
161  Node::read(nif);
162  data.read(nif);
163  skin.read(nif);
164  }
165 
166  void post(NIFFile *nif)
167  {
168  Node::post(nif);
169  data.post(nif);
170  skin.post(nif);
171  if (!skin.empty())
172  nif->setUseSkinning(true);
173  }
174 };
175 
176 struct NiCamera : Node
177 {
178  struct Camera
179  {
180  // Camera frustrum
182 
183  // Viewport
185 
186  // Level of detail modifier
187  float LOD;
188 
189  void read(NIFStream *nif)
190  {
191  left = nif->getFloat();
192  right = nif->getFloat();
193  top = nif->getFloat();
194  bottom = nif->getFloat();
195  nearDist = nif->getFloat();
196  farDist = nif->getFloat();
197 
198  vleft = nif->getFloat();
199  vright = nif->getFloat();
200  vtop = nif->getFloat();
201  vbottom = nif->getFloat();
202 
203  LOD = nif->getFloat();
204  }
205  };
207 
208  void read(NIFStream *nif)
209  {
210  Node::read(nif);
211 
212  cam.read(nif);
213 
214  nif->getInt(); // -1
215  nif->getInt(); // 0
216  }
217 };
218 
220 {
222 
223  void read(NIFStream *nif)
224  {
225  Node::read(nif);
226  data.read(nif);
227  nif->getInt(); // -1
228  }
229 
230  void post(NIFFile *nif)
231  {
232  Node::post(nif);
233  data.post(nif);
234  }
235 };
236 
238 {
240 
241  void read(NIFStream *nif)
242  {
243  Node::read(nif);
244  data.read(nif);
245  nif->getInt(); // -1
246  }
247 
248  void post(NIFFile *nif)
249  {
250  Node::post(nif);
251  data.post(nif);
252  }
253 };
254 
255 // A node used as the base to switch between child nodes, such as for LOD levels.
256 struct NiSwitchNode : public NiNode
257 {
258  void read(NIFStream *nif)
259  {
260  NiNode::read(nif);
261  nif->getInt(); // unknown
262  }
263 };
264 
265 struct NiLODNode : public NiSwitchNode
266 {
267  osg::Vec3f lodCenter;
268 
269  struct LODRange
270  {
271  float minRange;
272  float maxRange;
273  };
274  std::vector<LODRange> lodLevels;
275 
276  void read(NIFStream *nif)
277  {
278  NiSwitchNode::read(nif);
279  lodCenter = nif->getVector3();
280  unsigned int numLodLevels = nif->getUInt();
281  for (unsigned int i=0; i<numLodLevels; ++i)
282  {
283  LODRange r;
284  r.minRange = nif->getFloat();
285  r.maxRange = nif->getFloat();
286  lodLevels.push_back(r);
287  }
288  }
289 };
290 
291 } // Namespace
292 #endif
float vbottom
Definition: node.hpp:184
Definition: node.hpp:102
Definition: niffile.hpp:17
osg::Vec3f lodCenter
Definition: node.hpp:267
static bool ciEqual(const std::string &x, const std::string &y)
Definition: stringops.hpp:62
void read(NIFStream *nif)
Parses the record from file.
Definition: node.hpp:276
NiNode * parent
Definition: node.hpp:70
const NiSkinData::BoneInfo * boneInfo
Definition: node.hpp:76
float vright
Definition: node.hpp:184
Matrix3 boundRot
Definition: node.hpp:35
int getInt()
Definition: nifstream.hpp:47
Definition: node.hpp:114
float LOD
Definition: node.hpp:187
Definition: node.hpp:103
short boneIndex
Definition: node.hpp:80
float nearDist
Definition: node.hpp:181
void read(NIFStream *nif)
Parses the record from file.
Definition: base.hpp:64
float maxRange
Definition: node.hpp:272
Definition: node.hpp:110
void setUseSkinning(bool skinning)
Definition: niffile.cpp:215
void read(NIFStream *nif)
Parses the record from file.
Definition: node.hpp:258
float top
Definition: node.hpp:181
Matrix3 getMatrix3()
Definition: nifstream.cpp:58
NiRotatingParticlesDataPtr data
Definition: node.hpp:239
void read(NIFStream *nif)
Parses the record from file.
Definition: node.hpp:38
size_t length() const
Definition: recordptr.hpp:110
Definition: node.hpp:111
std::string name
Definition: base.hpp:62
BSParticleFlags
Definition: node.hpp:109
void post(NIFFile *nif)
Does post-processing, after the entire tree is loaded.
Definition: node.hpp:62
unsigned short getUShort()
Definition: nifstream.hpp:46
const Transformation * boneTrafo
Definition: node.hpp:73
PropertyList props
Definition: node.hpp:30
Camera cam
Definition: node.hpp:206
void post(NIFFile *nif)
Does post-processing, after the entire tree is loaded.
Definition: base.hpp:51
osg::Vec3f boundXYZ
Definition: node.hpp:36
Has name, extra-data and controller.
Definition: base.hpp:59
osg::Vec3f boundPos
Definition: node.hpp:34
Transformation trafo
Definition: node.hpp:28
Transformation getTrafo()
Definition: nifstream.cpp:77
float right
Definition: node.hpp:181
void post(NIFFile *nif)
Resolve index to pointer.
Definition: recordptr.hpp:38
void read(NIFStream *nif)
Parses the record from file.
Definition: node.hpp:117
Flags
Definition: node.hpp:101
Definition: node.hpp:219
void read(NIFStream *nif)
Definition: node.hpp:189
osg::Vec3f velocity
Definition: node.hpp:29
Definition: node.hpp:176
void read(NIFStream *nif)
Read the index from the nif.
Definition: recordptr.hpp:27
Definition: node.hpp:147
void post(NIFFile *nif)
Does post-processing, after the entire tree is loaded.
Definition: node.hpp:248
Definition: node.hpp:256
Definition: niftypes.hpp:56
void post(NIFFile *nif)
Does post-processing, after the entire tree is loaded.
Definition: node.hpp:132
void read(NIFStream *nif)
Parses the record from file.
Definition: node.hpp:159
Definition: node.hpp:237
Definition: node.hpp:23
NodeList children
Definition: node.hpp:98
Definition: node.hpp:269
NodeList effects
Definition: node.hpp:99
Definition: node.hpp:265
BSAnimFlags
Definition: node.hpp:106
Definition: node.hpp:178
void post(NIFFile *nif)
Definition: recordptr.hpp:99
osg::Vec3f getVector3()
Definition: nifstream.cpp:44
Transformation trafo
Definition: data.hpp:177
float vleft
Definition: node.hpp:184
void read(NIFStream *nif)
Parses the record from file.
Definition: node.hpp:241
float farDist
Definition: node.hpp:181
float getFloat()
Definition: nifstream.hpp:49
static const Transformation & getIdentity()
Definition: niftypes.hpp:80
NiSkinInstancePtr skin
Definition: node.hpp:157
void post(NIFFile *nif)
Does post-processing, after the entire tree is loaded.
Definition: node.hpp:230
Definition: niftypes.hpp:35
Definition: node.hpp:96
Definition: data.hpp:175
NiTriShapeDataPtr data
Definition: node.hpp:156
void makeRootBone(const Transformation *tr)
Definition: node.hpp:82
NiAutoNormalParticlesDataPtr data
Definition: node.hpp:221
Definition: nifstream.hpp:26
unsigned int getUInt()
Definition: nifstream.hpp:48
void read(NIFStream *nif)
Parses the record from file.
Definition: node.hpp:208
void read(NIFStream *nif)
Definition: recordptr.hpp:90
bool hasBounds
Definition: node.hpp:33
ControllerFlags
Definition: node.hpp:113
float minRange
Definition: node.hpp:271
void read(NIFStream *nif)
Parses the record from file.
Definition: node.hpp:223
Definition: node.hpp:107
bool empty() const
Pointers are allowed to be empty.
Definition: recordptr.hpp:75
size_t recIndex
Definition: record.hpp:105
std::vector< LODRange > lodLevels
Definition: node.hpp:274
void makeBone(short ind, const NiSkinData::BoneInfo &bi)
Definition: node.hpp:88
Definition: node.hpp:104
float vtop
Definition: node.hpp:184
float bottom
Definition: node.hpp:181
int flags
Definition: node.hpp:27
float left
Definition: node.hpp:181
void post(NIFFile *nif)
Does post-processing, after the entire tree is loaded.
Definition: node.hpp:166