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  isBone = false;
59  }
60 
61  void post(NIFFile *nif)
62  {
63  Named::post(nif);
64  props.post(nif);
65  }
66 
67  // Parent node, or NULL for the root node. As far as I'm aware, only
68  // NiNodes (or types derived from NiNodes) can be parents.
70 
71  bool isBone;
72 
73  void setBone()
74  {
75  isBone = true;
76  }
77 };
78 
79 struct NiNode : Node
80 {
83 
84  enum Flags {
85  Flag_Hidden = 0x0001,
88  };
89  enum BSAnimFlags {
91  };
95  };
98  };
99 
100  void read(NIFStream *nif)
101  {
102  Node::read(nif);
103  children.read(nif);
104  effects.read(nif);
105 
106  // Discard transformations for the root node, otherwise some meshes
107  // occasionally get wrong orientation. Only for NiNode-s for now, but
108  // can be expanded if needed.
109  if (0 == recIndex && !Misc::StringUtils::ciEqual(name, "bip01"))
110  {
111  static_cast<Nif::Node*>(this)->trafo = Nif::Transformation::getIdentity();
112  }
113  }
114 
115  void post(NIFFile *nif)
116  {
117  Node::post(nif);
118  children.post(nif);
119  effects.post(nif);
120 
121  for(size_t i = 0;i < children.length();i++)
122  {
123  // Why would a unique list of children contain empty refs?
124  if(!children[i].empty())
125  children[i]->parent = this;
126  }
127  }
128 };
129 
130 struct NiTriShape : Node
131 {
132  /* Possible flags:
133  0x40 - mesh has no vertex normals ?
134 
135  Only flags included in 0x47 (ie. 0x01, 0x02, 0x04 and 0x40) have
136  been observed so far.
137  */
138 
141 
142  void read(NIFStream *nif)
143  {
144  Node::read(nif);
145  data.read(nif);
146  skin.read(nif);
147  }
148 
149  void post(NIFFile *nif)
150  {
151  Node::post(nif);
152  data.post(nif);
153  skin.post(nif);
154  if (!skin.empty())
155  nif->setUseSkinning(true);
156  }
157 };
158 
159 struct NiCamera : Node
160 {
161  struct Camera
162  {
163  // Camera frustrum
165 
166  // Viewport
168 
169  // Level of detail modifier
170  float LOD;
171 
172  void read(NIFStream *nif)
173  {
174  left = nif->getFloat();
175  right = nif->getFloat();
176  top = nif->getFloat();
177  bottom = nif->getFloat();
178  nearDist = nif->getFloat();
179  farDist = nif->getFloat();
180 
181  vleft = nif->getFloat();
182  vright = nif->getFloat();
183  vtop = nif->getFloat();
184  vbottom = nif->getFloat();
185 
186  LOD = nif->getFloat();
187  }
188  };
190 
191  void read(NIFStream *nif)
192  {
193  Node::read(nif);
194 
195  cam.read(nif);
196 
197  nif->getInt(); // -1
198  nif->getInt(); // 0
199  }
200 };
201 
203 {
205 
206  void read(NIFStream *nif)
207  {
208  Node::read(nif);
209  data.read(nif);
210  nif->getInt(); // -1
211  }
212 
213  void post(NIFFile *nif)
214  {
215  Node::post(nif);
216  data.post(nif);
217  }
218 };
219 
221 {
223 
224  void read(NIFStream *nif)
225  {
226  Node::read(nif);
227  data.read(nif);
228  nif->getInt(); // -1
229  }
230 
231  void post(NIFFile *nif)
232  {
233  Node::post(nif);
234  data.post(nif);
235  }
236 };
237 
238 // A node used as the base to switch between child nodes, such as for LOD levels.
239 struct NiSwitchNode : public NiNode
240 {
241  void read(NIFStream *nif)
242  {
243  NiNode::read(nif);
244  nif->getInt(); // unknown
245  }
246 };
247 
248 struct NiLODNode : public NiSwitchNode
249 {
250  osg::Vec3f lodCenter;
251 
252  struct LODRange
253  {
254  float minRange;
255  float maxRange;
256  };
257  std::vector<LODRange> lodLevels;
258 
259  void read(NIFStream *nif)
260  {
261  NiSwitchNode::read(nif);
262  lodCenter = nif->getVector3();
263  unsigned int numLodLevels = nif->getUInt();
264  for (unsigned int i=0; i<numLodLevels; ++i)
265  {
266  LODRange r;
267  r.minRange = nif->getFloat();
268  r.maxRange = nif->getFloat();
269  lodLevels.push_back(r);
270  }
271  }
272 };
273 
274 } // Namespace
275 #endif
float vbottom
Definition: node.hpp:167
Definition: node.hpp:85
Definition: niffile.hpp:40
osg::Vec3f lodCenter
Definition: node.hpp:250
static bool ciEqual(const std::string &x, const std::string &y)
Definition: stringops.hpp:129
void read(NIFStream *nif)
Parses the record from file.
Definition: node.hpp:259
NiNode * parent
Definition: node.hpp:69
float vright
Definition: node.hpp:167
Matrix3 boundRot
Definition: node.hpp:35
int getInt()
Definition: nifstream.hpp:111
Definition: node.hpp:97
float LOD
Definition: node.hpp:170
Definition: node.hpp:86
float nearDist
Definition: node.hpp:164
void read(NIFStream *nif)
Parses the record from file.
Definition: base.hpp:64
float maxRange
Definition: node.hpp:255
Definition: node.hpp:93
void setUseSkinning(bool skinning) override
Definition: niffile.cpp:216
void read(NIFStream *nif)
Parses the record from file.
Definition: node.hpp:241
float top
Definition: node.hpp:164
Matrix3 getMatrix3()
Definition: nifstream.hpp:147
NiRotatingParticlesDataPtr data
Definition: node.hpp:222
void read(NIFStream *nif)
Parses the record from file.
Definition: node.hpp:38
size_t length() const
Definition: recordptr.hpp:118
std::string name
Definition: base.hpp:62
BSParticleFlags
Definition: node.hpp:92
void post(NIFFile *nif)
Does post-processing, after the entire tree is loaded.
Definition: node.hpp:61
unsigned short getUShort()
Definition: nifstream.hpp:106
PropertyList props
Definition: node.hpp:30
Camera cam
Definition: node.hpp:189
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:19
float right
Definition: node.hpp:164
void post(NIFFile *nif)
Resolve index to pointer.
Definition: recordptr.hpp:40
void read(NIFStream *nif)
Parses the record from file.
Definition: node.hpp:100
Flags
Definition: node.hpp:84
Definition: node.hpp:202
void read(NIFStream *nif)
Definition: node.hpp:172
osg::Vec3f velocity
Definition: node.hpp:29
Definition: node.hpp:159
void read(NIFStream *nif)
Read the index from the nif.
Definition: recordptr.hpp:29
Definition: node.hpp:130
void post(NIFFile *nif)
Does post-processing, after the entire tree is loaded.
Definition: node.hpp:231
Definition: node.hpp:239
Definition: niftypes.hpp:56
void post(NIFFile *nif)
Does post-processing, after the entire tree is loaded.
Definition: node.hpp:115
void read(NIFStream *nif)
Parses the record from file.
Definition: node.hpp:142
Definition: node.hpp:220
Definition: node.hpp:23
NodeList children
Definition: node.hpp:81
Definition: node.hpp:252
NodeList effects
Definition: node.hpp:82
Definition: node.hpp:248
BSAnimFlags
Definition: node.hpp:89
Definition: node.hpp:161
void post(NIFFile *nif)
Definition: recordptr.hpp:107
osg::Vec3f getVector3()
Definition: nifstream.hpp:133
float vleft
Definition: node.hpp:167
void read(NIFStream *nif)
Parses the record from file.
Definition: node.hpp:224
bool isBone
Definition: node.hpp:71
float farDist
Definition: node.hpp:164
float getFloat()
Definition: nifstream.hpp:121
static const Transformation & getIdentity()
Definition: niftypes.hpp:80
NiSkinInstancePtr skin
Definition: node.hpp:140
void post(NIFFile *nif)
Does post-processing, after the entire tree is loaded.
Definition: node.hpp:213
Definition: niftypes.hpp:35
Definition: node.hpp:79
NiTriShapeDataPtr data
Definition: node.hpp:139
NiAutoNormalParticlesDataPtr data
Definition: node.hpp:204
Definition: nifstream.hpp:83
unsigned int getUInt()
Definition: nifstream.hpp:116
void read(NIFStream *nif)
Parses the record from file.
Definition: node.hpp:191
void read(NIFStream *nif)
Definition: recordptr.hpp:98
void setBone()
Definition: node.hpp:73
bool hasBounds
Definition: node.hpp:33
ControllerFlags
Definition: node.hpp:96
float minRange
Definition: node.hpp:254
void read(NIFStream *nif)
Parses the record from file.
Definition: node.hpp:206
Definition: node.hpp:90
bool empty() const
Pointers are allowed to be empty.
Definition: recordptr.hpp:77
size_t recIndex
Definition: record.hpp:106
std::vector< LODRange > lodLevels
Definition: node.hpp:257
Definition: node.hpp:87
float vtop
Definition: node.hpp:167
float bottom
Definition: node.hpp:164
int flags
Definition: node.hpp:27
float left
Definition: node.hpp:164
void post(NIFFile *nif)
Does post-processing, after the entire tree is loaded.
Definition: node.hpp:149