File: node.hpp

package info (click to toggle)
openmw 0.49.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,992 kB
  • sloc: cpp: 372,479; xml: 2,149; sh: 1,403; python: 797; makefile: 26
file content (530 lines) | stat: -rw-r--r-- 12,910 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
#ifndef OPENMW_COMPONENTS_NIF_NODE_HPP
#define OPENMW_COMPONENTS_NIF_NODE_HPP

#include <array>
#include <unordered_map>

#include <osg/Plane>

#include "base.hpp"

class btCollisionShape;

namespace Nif
{

    struct NiNode;

    struct BoundingVolume
    {
        enum Type : uint32_t
        {
            BASE_BV = 0xFFFFFFFF,
            SPHERE_BV = 0,
            BOX_BV = 1,
            CAPSULE_BV = 2,
            LOZENGE_BV = 3,
            UNION_BV = 4,
            HALFSPACE_BV = 5
        };

        struct NiBoxBV
        {
            osg::Vec3f mCenter;
            Matrix3 mAxes;
            osg::Vec3f mExtents;
        };

        struct NiCapsuleBV
        {
            osg::Vec3f mCenter, mAxis;
            float mExtent{ 0.f }, mRadius{ 0.f };
        };

        struct NiLozengeBV
        {
            float mRadius{ 0.f }, mExtent0{ 0.f }, mExtent1{ 0.f };
            osg::Vec3f mCenter, mAxis0, mAxis1;
        };

        struct NiHalfSpaceBV
        {
            osg::Plane mPlane;
            osg::Vec3f mOrigin;
        };

        uint32_t mType{ BASE_BV };
        osg::BoundingSpheref mSphere;
        NiBoxBV mBox;
        NiCapsuleBV mCapsule;
        NiLozengeBV mLozenge;
        std::vector<BoundingVolume> mChildren;
        NiHalfSpaceBV mHalfSpace;

        void read(NIFStream* nif);
    };

    struct NiSequenceStreamHelper : NiObjectNET
    {
    };

    // NiAVObject is an object that is a part of the main NIF tree. It has
    // a parent node (unless it's the root) and transformation relative to its parent.
    struct NiAVObject : NiObjectNET
    {
        enum Flags
        {
            Flag_Hidden = 0x0001,
            Flag_MeshCollision = 0x0002,
            Flag_BBoxCollision = 0x0004,
            Flag_ActiveCollision = 0x0020
        };

        // Node flags. Interpretation depends on the record type.
        uint32_t mFlags;
        NiTransform mTransform;
        osg::Vec3f mVelocity;
        NiPropertyList mProperties;
        BoundingVolume mBounds;
        NiCollisionObjectPtr mCollision;
        // Parent nodes for the node. Only types derived from NiNode can be parents.
        std::vector<NiNode*> mParents;
        bool mIsBone{ false };

        void read(NIFStream* nif) override;
        void post(Reader& nif) override;

        void setBone();
        bool isHidden() const { return mFlags & Flag_Hidden; }
        bool hasMeshCollision() const { return mFlags & Flag_MeshCollision; }
        bool hasBBoxCollision() const { return mFlags & Flag_BBoxCollision; }
        bool collisionActive() const { return mFlags & Flag_ActiveCollision; }
    };

    struct NiNode : NiAVObject
    {
        enum BSAnimFlags
        {
            AnimFlag_AutoPlay = 0x0020
        };

        enum BSParticleFlags
        {
            ParticleFlag_AutoPlay = 0x0020,
            ParticleFlag_LocalSpace = 0x0080
        };

        NiAVObjectList mChildren;
        NiAVObjectList mEffects;

        void read(NIFStream* nif) override;
        void post(Reader& nif) override;
    };

    struct NiGeometry : NiAVObject
    {
        /* Possible flags:
            0x40 - mesh has no vertex normals ?

            Only flags included in 0x47 (ie. 0x01, 0x02, 0x04 and 0x40) have
            been observed so far.
        */

        struct MaterialData
        {
            std::vector<std::string> mNames;
            std::vector<int> mExtra;
            int32_t mActive{ -1 };
            bool mNeedsUpdate{ false };

            void read(NIFStream* nif);
        };

        NiGeometryDataPtr mData;
        NiSkinInstancePtr mSkin;
        MaterialData mMaterial;
        BSShaderPropertyPtr mShaderProperty;
        NiAlphaPropertyPtr mAlphaProperty;

        void read(NIFStream* nif) override;
        void post(Reader& nif) override;

        virtual std::unique_ptr<btCollisionShape> getCollisionShape() const
        {
            throw std::runtime_error("NiGeometry::getCollisionShape() called on base class");
        }
    };

    // Abstract triangle-based geometry
    struct NiTriBasedGeom : NiGeometry
    {
    };

    struct NiTriShape : NiTriBasedGeom
    {
        std::unique_ptr<btCollisionShape> getCollisionShape() const override;
    };

    struct BSSegmentedTriShape : NiTriShape
    {
        struct SegmentData
        {
            uint8_t mFlags;
            uint32_t mStartIndex;
            uint32_t mNumTriangles;

            void read(NIFStream* nif);
        };

        std::vector<SegmentData> mSegments;

        void read(NIFStream* nif);
    };

    struct NiTriStrips : NiTriBasedGeom
    {
        std::unique_ptr<btCollisionShape> getCollisionShape() const override;
    };

    struct NiLines : NiTriBasedGeom
    {
        std::unique_ptr<btCollisionShape> getCollisionShape() const override;
    };

    struct NiParticles : NiGeometry
    {
        std::unique_ptr<btCollisionShape> getCollisionShape() const override;
    };

    struct BSLODTriShape : NiTriShape
    {
        std::array<uint32_t, 3> mLOD;
        void read(NIFStream* nif) override;
    };

    struct NiCamera : NiAVObject
    {
        uint16_t mCameraFlags{ 0 };
        // Camera frustum
        float mLeft, mRight, mTop, mBottom, mNearDist, mFarDist;
        bool mOrthographic{ false };
        // Viewport
        float mVLeft, mVRight, mVTop, mVBottom;
        float mLODAdjust;
        NiAVObjectPtr mScene;

        void read(NIFStream* nif) override;
        void post(Reader& nif) override;
    };

    // A node used as the base to switch between child nodes, such as for LOD levels.
    struct NiSwitchNode : NiNode
    {
        uint16_t mSwitchFlags;
        uint32_t mInitialIndex;

        void read(NIFStream* nif) override;
    };

    struct NiLODNode : NiSwitchNode
    {
        struct LODRange
        {
            float mMinRange;
            float mMaxRange;
        };

        osg::Vec3f mLODCenter;
        std::vector<LODRange> mLODLevels;

        void read(NIFStream* nif) override;
    };

    struct NiFltAnimationNode : NiSwitchNode
    {
        enum Flags
        {
            Flag_Swing = 0x40
        };

        float mDuration;

        void read(NIFStream* nif) override;

        bool swing() const { return mFlags & Flag_Swing; }
    };

    // Abstract
    struct NiAccumulator : Record
    {
        void read(NIFStream* nif) override {}
    };

    // Node children sorters
    struct NiClusterAccumulator : NiAccumulator
    {
    };

    struct NiAlphaAccumulator : NiClusterAccumulator
    {
    };

    struct NiSortAdjustNode : NiNode
    {
        enum class SortingMode : uint32_t
        {
            Inherit,
            Off,
            Subsort,
        };

        SortingMode mMode;
        NiAccumulatorPtr mSubSorter;

        void read(NIFStream* nif) override;
        void post(Reader& nif) override;
    };

    struct NiBillboardNode : NiNode
    {
        int mMode;

        void read(NIFStream* nif) override;
    };

    struct NiDefaultAVObjectPalette : Record
    {
        NiAVObjectPtr mScene;
        std::unordered_map<std::string, NiAVObjectPtr> mObjects;

        void read(NIFStream* nif) override;
        void post(Reader& nif) override;
    };

    struct BSTreeNode : NiNode
    {
        NiAVObjectList mBones1, mBones2;

        void read(NIFStream* nif) override;
        void post(Reader& nif) override;
    };

    struct BSMultiBoundNode : NiNode
    {
        enum class BSCPCullingType : uint32_t
        {
            Normal,
            AllPass,
            AllFail,
            IgnoreMultiBounds,
            ForceMultiBoundsNoUpdate,
        };

        BSMultiBoundPtr mMultiBound;
        BSCPCullingType mCullingType;

        void read(NIFStream* nif) override;
        void post(Reader& nif) override;
    };

    struct BSVertexDesc
    {
        uint8_t mVertexDataSize;
        uint8_t mDynamicVertexSize;
        uint8_t mUV1Offset;
        uint8_t mUV2Offset;
        uint8_t mNormalOffset;
        uint8_t mTangentOffset;
        uint8_t mColorOffset;
        uint8_t mSkinningDataOffset;
        uint8_t mLandscapeDataOffset;
        uint8_t mEyeDataOffset;
        uint16_t mFlags;

        enum VertexAttribute
        {
            Vertex = 0x0001,
            UVs = 0x0002,
            UVs_2 = 0x0004,
            Normals = 0x0008,
            Tangents = 0x0010,
            Vertex_Colors = 0x0020,
            Skinned = 0x0040,
            Land_Data = 0x0080,
            Eye_Data = 0x0100,
            Instance = 0x0200,
            Full_Precision = 0x0400,
        };

        void read(NIFStream* nif);
    };

    struct BSVertexData
    {
        osg::Vec4f mVertex; // Bitangent X is stored in the fourth component
        std::array<Misc::float16_t, 4> mHalfVertex; // Ditto
        std::array<Misc::float16_t, 2> mUV;
        std::array<char, 4> mNormal; // Bitangent Y is stored in the fourth component
        std::array<char, 4> mTangent; // Bitangent Z is stored in the fourth component
        std::array<char, 4> mVertColor;
        std::array<Misc::float16_t, 4> mBoneWeights;
        std::array<char, 4> mBoneIndices;
        float mEyeData;

        void read(NIFStream* nif, uint16_t flags);
    };

    struct BSTriShape : NiAVObject
    {
        osg::BoundingSpheref mBoundingSphere;
        std::array<float, 6> mBoundMinMax;
        RecordPtrT<Record> mSkin;
        BSShaderPropertyPtr mShaderProperty;
        NiAlphaPropertyPtr mAlphaProperty;
        BSVertexDesc mVertDesc;
        uint32_t mDataSize;
        std::vector<BSVertexData> mVertData;
        std::vector<unsigned short> mTriangles;
        uint32_t mParticleDataSize;
        std::vector<Misc::float16_t> mParticleVerts;
        std::vector<Misc::float16_t> mParticleNormals;
        std::vector<unsigned short> mParticleTriangles;

        void read(NIFStream* nif) override;
        void post(Reader& nif) override;
    };

    struct BSDynamicTriShape : BSTriShape
    {
        uint32_t mDynamicDataSize;
        std::vector<osg::Vec4f> mDynamicData;

        void read(NIFStream* nif) override;
    };

    struct BSMeshLODTriShape : BSTriShape
    {
        std::array<uint32_t, 3> mLOD;

        void read(NIFStream* nif) override;
    };

    struct BSSubIndexTriShape : BSTriShape
    {
        struct SubSegment
        {
            uint32_t mStartIndex;
            uint32_t mNumPrimitives;
            uint32_t mArrayIndex;

            void read(NIFStream* nif);
        };

        struct Segment
        {
            uint32_t mStartIndex;
            uint32_t mNumPrimitives;
            uint32_t mParentArrayIndex;
            std::vector<SubSegment> mSubSegments;

            void read(NIFStream* nif);
        };

        struct SubSegmentDataRecord
        {
            uint32_t mUserSlotID;
            uint32_t mMaterial;
            std::vector<float> mExtraData;

            void read(NIFStream* nif);
        };

        struct SubSegmentData
        {
            std::vector<uint32_t> mArrayIndices;
            std::vector<SubSegmentDataRecord> mDataRecords;
            std::string mSSFFile;

            void read(NIFStream* nif);
        };

        struct Segmentation
        {
            uint32_t mNumPrimitives;
            uint32_t mNumTotalSegments;
            std::vector<Segment> mSegments;
            SubSegmentData mSubSegmentData;

            void read(NIFStream* nif);
        };

        std::vector<BSSegmentedTriShape::SegmentData> mSegments; // SSE
        Segmentation mSegmentation; // FO4

        void read(NIFStream* nif) override;
    };

    struct BSValueNode : NiNode
    {
        enum Flags
        {
            Flag_BillboardWorldZ = 0x1,
            Flag_UsePlayerAdjust = 0x2,
        };

        uint32_t mValue;
        uint8_t mValueFlags;

        void read(NIFStream* nif) override;
    };

    struct BSOrderedNode : NiNode
    {
        osg::Vec4f mAlphaSortBound;
        bool mStaticBound;

        void read(NIFStream* nif) override;
    };

    struct BSRangeNode : NiNode
    {
        uint8_t mMin, mMax;
        uint8_t mCurrent;

        void read(NIFStream* nif) override;
    };

    struct BSResourceID
    {
        uint32_t mFileHash;
        std::array<char, 4> mExtension;
        uint32_t mDirectoryHash;

        void read(NIFStream* nif);
    };

    struct BSDistantObjectInstance
    {
        BSResourceID mResourceID;
        std::vector<osg::Matrixf> mTransforms;

        void read(NIFStream* nif);
    };

    struct BSShaderTextureArray
    {
        std::vector<std::vector<std::string>> mTextureArrays;

        void read(NIFStream* nif);
    };

    struct BSDistantObjectInstancedNode : BSMultiBoundNode
    {
        std::vector<BSDistantObjectInstance> mInstances;
        std::array<BSShaderTextureArray, 3> mShaderTextureArrays;

        void read(NIFStream* nif) override;
    };

}
#endif