2013-02-24 21:51:56 +00:00
|
|
|
#ifndef OPENMW_COMPONENTS_NIF_NODE_HPP
|
|
|
|
#define OPENMW_COMPONENTS_NIF_NODE_HPP
|
2010-01-06 11:28:37 +00:00
|
|
|
|
2023-07-09 10:14:27 +00:00
|
|
|
#include <array>
|
2023-02-08 11:34:10 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
|
2022-06-17 11:35:33 +00:00
|
|
|
#include <osg/Plane>
|
|
|
|
|
2014-10-19 06:26:44 +00:00
|
|
|
#include "base.hpp"
|
2016-01-02 00:12:44 +00:00
|
|
|
|
2010-01-06 11:28:37 +00:00
|
|
|
namespace Nif
|
|
|
|
{
|
|
|
|
|
2015-03-06 08:36:42 +00:00
|
|
|
struct NiNode;
|
2012-07-03 05:49:44 +00:00
|
|
|
|
2020-11-14 00:42:15 +00:00
|
|
|
struct NiBoundingVolume
|
|
|
|
{
|
|
|
|
enum Type
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2022-06-17 11:35:33 +00:00
|
|
|
BASE_BV = 0xFFFFFFFF,
|
2020-11-14 00:42:15 +00:00
|
|
|
SPHERE_BV = 0,
|
|
|
|
BOX_BV = 1,
|
|
|
|
CAPSULE_BV = 2,
|
|
|
|
LOZENGE_BV = 3,
|
|
|
|
UNION_BV = 4,
|
|
|
|
HALFSPACE_BV = 5
|
2022-09-22 18:26:05 +00:00
|
|
|
};
|
|
|
|
|
2020-11-14 00:42:15 +00:00
|
|
|
struct NiSphereBV
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2020-11-14 00:42:15 +00:00
|
|
|
osg::Vec3f center;
|
|
|
|
float radius{ 0.f };
|
2023-07-09 10:14:27 +00:00
|
|
|
void read(NIFStream* nif);
|
2022-09-22 18:26:05 +00:00
|
|
|
};
|
|
|
|
|
2020-11-14 00:42:15 +00:00
|
|
|
struct NiBoxBV
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2020-11-14 00:42:15 +00:00
|
|
|
osg::Vec3f center;
|
2022-06-17 11:35:33 +00:00
|
|
|
Matrix3 axes;
|
2020-11-14 00:42:15 +00:00
|
|
|
osg::Vec3f extents;
|
2022-09-22 18:26:05 +00:00
|
|
|
};
|
|
|
|
|
2020-11-14 00:42:15 +00:00
|
|
|
struct NiCapsuleBV
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2020-11-14 00:42:15 +00:00
|
|
|
osg::Vec3f center, axis;
|
|
|
|
float extent{ 0.f }, radius{ 0.f };
|
2022-09-22 18:26:05 +00:00
|
|
|
};
|
|
|
|
|
2020-11-14 00:42:15 +00:00
|
|
|
struct NiLozengeBV
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2020-11-14 00:42:15 +00:00
|
|
|
float radius{ 0.f }, extent0{ 0.f }, extent1{ 0.f };
|
|
|
|
osg::Vec3f center, axis0, axis1;
|
2022-09-22 18:26:05 +00:00
|
|
|
};
|
|
|
|
|
2020-11-14 00:42:15 +00:00
|
|
|
struct NiHalfSpaceBV
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2022-06-17 11:35:33 +00:00
|
|
|
osg::Plane plane;
|
|
|
|
osg::Vec3f origin;
|
2022-09-22 18:26:05 +00:00
|
|
|
};
|
|
|
|
|
2020-11-14 00:42:15 +00:00
|
|
|
unsigned int type;
|
|
|
|
NiSphereBV sphere;
|
|
|
|
NiBoxBV box;
|
|
|
|
NiCapsuleBV capsule;
|
|
|
|
NiLozengeBV lozenge;
|
|
|
|
std::vector<NiBoundingVolume> children;
|
2022-06-17 11:35:33 +00:00
|
|
|
NiHalfSpaceBV halfSpace;
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2022-07-21 11:51:34 +00:00
|
|
|
void read(NIFStream* nif);
|
2020-11-14 00:42:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** A Node is an object that's part of the main NIF tree. It has
|
2010-01-06 11:28:37 +00:00
|
|
|
parent node (unless it's the root), and transformation (location
|
|
|
|
and rotation) relative to it's parent.
|
2022-09-22 18:26:05 +00:00
|
|
|
*/
|
2020-11-14 00:42:15 +00:00
|
|
|
struct Node : public Named
|
|
|
|
{
|
2022-06-21 21:43:16 +00:00
|
|
|
enum Flags
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2022-06-21 21:43:16 +00:00
|
|
|
Flag_Hidden = 0x0001,
|
|
|
|
Flag_MeshCollision = 0x0002,
|
|
|
|
Flag_BBoxCollision = 0x0004,
|
|
|
|
Flag_ActiveCollision = 0x0020
|
2022-09-22 18:26:05 +00:00
|
|
|
};
|
|
|
|
|
2020-11-14 00:42:15 +00:00
|
|
|
// Node flags. Interpretation depends somewhat on the type of node.
|
2019-12-29 12:53:44 +00:00
|
|
|
unsigned int flags;
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2012-07-10 04:35:36 +00:00
|
|
|
Transformation trafo;
|
2020-11-14 00:42:15 +00:00
|
|
|
osg::Vec3f velocity; // Unused? Might be a run-time game state
|
2012-07-03 04:41:21 +00:00
|
|
|
PropertyList props;
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2020-11-14 00:42:15 +00:00
|
|
|
// Bounding box info
|
|
|
|
bool hasBounds{ false };
|
|
|
|
NiBoundingVolume bounds;
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2021-11-10 16:31:28 +00:00
|
|
|
// Collision object info
|
|
|
|
NiCollisionObjectPtr collision;
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2020-11-14 00:42:15 +00:00
|
|
|
void read(NIFStream* nif) override;
|
2022-09-17 17:24:42 +00:00
|
|
|
void post(Reader& nif) override;
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2018-10-09 06:21:12 +00:00
|
|
|
// Parent node, or nullptr for the root node. As far as I'm aware, only
|
2012-07-03 05:49:44 +00:00
|
|
|
// NiNodes (or types derived from NiNodes) can be parents.
|
2022-01-21 23:15:56 +00:00
|
|
|
std::vector<NiNode*> parents;
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2021-01-09 10:21:57 +00:00
|
|
|
bool isBone{ false };
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2022-07-21 11:51:34 +00:00
|
|
|
void setBone();
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2020-11-14 00:42:15 +00:00
|
|
|
bool isHidden() const { return flags & Flag_Hidden; }
|
2022-06-21 21:43:16 +00:00
|
|
|
bool hasMeshCollision() const { return flags & Flag_MeshCollision; }
|
|
|
|
bool hasBBoxCollision() const { return flags & Flag_BBoxCollision; }
|
|
|
|
bool collisionActive() const { return flags & Flag_ActiveCollision; }
|
2020-11-14 00:42:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct NiNode : Node
|
|
|
|
{
|
|
|
|
NodeList children;
|
|
|
|
NodeList effects;
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2013-04-16 08:20:32 +00:00
|
|
|
enum BSAnimFlags
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2013-04-16 08:20:32 +00:00
|
|
|
AnimFlag_AutoPlay = 0x0020
|
2022-09-22 18:26:05 +00:00
|
|
|
};
|
2020-11-14 00:42:15 +00:00
|
|
|
enum BSParticleFlags
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2013-11-25 12:50:33 +00:00
|
|
|
ParticleFlag_AutoPlay = 0x0020,
|
|
|
|
ParticleFlag_LocalSpace = 0x0080
|
2022-09-22 18:26:05 +00:00
|
|
|
};
|
|
|
|
|
2022-07-21 11:51:34 +00:00
|
|
|
void read(NIFStream* nif) override;
|
2022-09-17 17:24:42 +00:00
|
|
|
void post(Reader& nif) override;
|
2020-11-14 00:42:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct NiGeometry : Node
|
|
|
|
{
|
|
|
|
/* Possible flags:
|
|
|
|
0x40 - mesh has no vertex normals ?
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2020-11-14 00:42:15 +00:00
|
|
|
Only flags included in 0x47 (ie. 0x01, 0x02, 0x04 and 0x40) have
|
|
|
|
been observed so far.
|
2022-09-22 18:26:05 +00:00
|
|
|
*/
|
|
|
|
|
2020-10-03 22:27:49 +00:00
|
|
|
struct MaterialData
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2020-11-14 00:42:15 +00:00
|
|
|
std::vector<std::string> names;
|
|
|
|
std::vector<int> extra;
|
|
|
|
unsigned int active{ 0 };
|
|
|
|
bool needsUpdate{ false };
|
|
|
|
void read(NIFStream* nif);
|
2022-09-22 18:26:05 +00:00
|
|
|
};
|
|
|
|
|
2020-12-13 00:16:05 +00:00
|
|
|
NiGeometryDataPtr data;
|
2020-05-14 07:52:27 +00:00
|
|
|
NiSkinInstancePtr skin;
|
2020-12-13 00:16:05 +00:00
|
|
|
MaterialData material;
|
2020-12-13 01:04:14 +00:00
|
|
|
BSShaderPropertyPtr shaderprop;
|
|
|
|
NiAlphaPropertyPtr alphaprop;
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2022-07-21 11:51:34 +00:00
|
|
|
void read(NIFStream* nif) override;
|
2022-09-17 17:24:42 +00:00
|
|
|
void post(Reader& nif) override;
|
2020-11-14 00:42:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct NiTriShape : NiGeometry
|
|
|
|
{
|
|
|
|
};
|
|
|
|
struct BSLODTriShape : NiTriShape
|
|
|
|
{
|
2022-06-17 11:35:33 +00:00
|
|
|
unsigned int lod0, lod1, lod2;
|
|
|
|
void read(NIFStream* nif) override;
|
2020-11-14 00:42:15 +00:00
|
|
|
};
|
|
|
|
struct NiTriStrips : NiGeometry
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2020-11-14 00:42:15 +00:00
|
|
|
};
|
2020-12-15 22:06:05 +00:00
|
|
|
struct NiLines : NiGeometry
|
2010-01-06 11:28:37 +00:00
|
|
|
{
|
2022-09-22 18:26:05 +00:00
|
|
|
};
|
2022-06-21 21:43:16 +00:00
|
|
|
struct NiParticles : NiGeometry
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2022-06-21 21:43:16 +00:00
|
|
|
};
|
|
|
|
|
2012-07-03 04:41:21 +00:00
|
|
|
struct NiCamera : Node
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2015-02-17 16:08:55 +00:00
|
|
|
struct Camera
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2015-02-17 16:08:55 +00:00
|
|
|
unsigned short cameraFlags{ 0 };
|
2012-07-03 04:41:21 +00:00
|
|
|
|
2018-10-09 06:21:12 +00:00
|
|
|
// Camera frustrum
|
|
|
|
float left, right, top, bottom, nearDist, farDist;
|
2012-07-03 05:49:44 +00:00
|
|
|
|
2012-07-03 04:41:21 +00:00
|
|
|
// Viewport
|
2021-01-09 10:21:57 +00:00
|
|
|
float vleft, vright, vtop, vbottom;
|
2012-07-03 04:41:21 +00:00
|
|
|
|
2022-07-21 11:51:34 +00:00
|
|
|
// Level of detail modifier
|
|
|
|
float LOD;
|
2022-06-21 21:43:16 +00:00
|
|
|
|
|
|
|
// Orthographic projection usage flag
|
|
|
|
bool orthographic{ false };
|
2010-01-06 14:00:08 +00:00
|
|
|
|
|
|
|
void read(NIFStream* nif);
|
2022-09-22 18:26:05 +00:00
|
|
|
};
|
2012-07-03 04:41:21 +00:00
|
|
|
Camera cam;
|
|
|
|
|
2013-04-16 08:20:32 +00:00
|
|
|
void read(NIFStream* nif) override;
|
|
|
|
};
|
2020-12-13 00:16:05 +00:00
|
|
|
|
2020-10-03 22:27:49 +00:00
|
|
|
// A node used as the base to switch between child nodes, such as for LOD levels.
|
|
|
|
struct NiSwitchNode : public NiNode
|
|
|
|
{
|
2020-12-13 00:16:05 +00:00
|
|
|
unsigned int switchFlags{ 0 };
|
2020-05-14 07:52:27 +00:00
|
|
|
unsigned int initialIndex{ 0 };
|
2019-08-08 10:11:24 +00:00
|
|
|
|
2022-07-21 11:51:34 +00:00
|
|
|
void read(NIFStream* nif) override;
|
2019-08-08 10:11:24 +00:00
|
|
|
};
|
|
|
|
|
2010-01-07 18:11:03 +00:00
|
|
|
struct NiLODNode : public NiSwitchNode
|
2012-07-03 04:41:21 +00:00
|
|
|
{
|
|
|
|
osg::Vec3f lodCenter;
|
2010-01-07 18:11:03 +00:00
|
|
|
|
2012-07-03 04:41:21 +00:00
|
|
|
struct LODRange
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2015-11-12 18:40:31 +00:00
|
|
|
float minRange;
|
2012-07-03 04:41:21 +00:00
|
|
|
float maxRange;
|
2022-09-22 18:26:05 +00:00
|
|
|
};
|
2015-11-12 18:40:31 +00:00
|
|
|
std::vector<LODRange> lodLevels;
|
2012-07-10 07:27:13 +00:00
|
|
|
|
2022-07-21 11:51:34 +00:00
|
|
|
void read(NIFStream* nif) override;
|
2012-07-03 04:41:21 +00:00
|
|
|
};
|
2010-01-07 18:11:03 +00:00
|
|
|
|
2015-11-12 18:40:31 +00:00
|
|
|
struct NiFltAnimationNode : public NiSwitchNode
|
|
|
|
{
|
2020-10-03 22:27:49 +00:00
|
|
|
float mDuration;
|
|
|
|
enum Flags
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2020-10-03 22:27:49 +00:00
|
|
|
Flag_Swing = 0x40
|
2021-01-09 10:21:57 +00:00
|
|
|
};
|
2019-06-08 22:58:02 +00:00
|
|
|
|
2022-07-21 11:51:34 +00:00
|
|
|
void read(NIFStream* nif) override;
|
2015-11-12 18:40:31 +00:00
|
|
|
|
|
|
|
bool swing() const { return flags & Flag_Swing; }
|
|
|
|
};
|
|
|
|
|
|
|
|
// Abstract
|
|
|
|
struct NiAccumulator : Record
|
|
|
|
{
|
2021-11-13 20:36:33 +00:00
|
|
|
void read(NIFStream* nif) override {}
|
2015-11-12 18:40:31 +00:00
|
|
|
};
|
|
|
|
|
2022-03-29 19:47:37 +00:00
|
|
|
// Node children sorters
|
|
|
|
struct NiClusterAccumulator : NiAccumulator
|
2022-03-30 07:27:00 +00:00
|
|
|
{
|
|
|
|
};
|
2021-11-13 20:36:33 +00:00
|
|
|
struct NiAlphaAccumulator : NiClusterAccumulator
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NiSortAdjustNode : NiNode
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2021-11-13 20:36:33 +00:00
|
|
|
enum SortingMode
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2021-11-13 20:36:33 +00:00
|
|
|
SortingMode_Inherit,
|
|
|
|
SortingMode_Off,
|
|
|
|
SortingMode_Subsort
|
2022-09-22 18:26:05 +00:00
|
|
|
};
|
|
|
|
|
2021-11-13 20:36:33 +00:00
|
|
|
int mMode;
|
|
|
|
NiAccumulatorPtr mSubSorter;
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2022-07-21 11:51:34 +00:00
|
|
|
void read(NIFStream* nif) override;
|
2022-09-17 17:24:42 +00:00
|
|
|
void post(Reader& nif) override;
|
2021-11-13 20:36:33 +00:00
|
|
|
};
|
|
|
|
|
2022-08-31 19:12:13 +00:00
|
|
|
struct NiBillboardNode : NiNode
|
|
|
|
{
|
|
|
|
int mMode{ 0 };
|
|
|
|
|
|
|
|
void read(NIFStream* nif) override;
|
|
|
|
};
|
|
|
|
|
2023-02-08 11:34:10 +00:00
|
|
|
struct NiDefaultAVObjectPalette : Record
|
|
|
|
{
|
|
|
|
NodePtr mScene;
|
|
|
|
std::unordered_map<std::string, NodePtr> mObjects;
|
|
|
|
|
|
|
|
void read(NIFStream* nif) override;
|
|
|
|
void post(Reader& nif) override;
|
|
|
|
};
|
|
|
|
|
2023-05-21 15:15:27 +00:00
|
|
|
struct BSTreeNode : NiNode
|
|
|
|
{
|
|
|
|
NodeList mBones1, mBones2;
|
|
|
|
void read(NIFStream* nif) override;
|
|
|
|
void post(Reader& nif) override;
|
|
|
|
};
|
|
|
|
|
2023-05-22 19:28:05 +00:00
|
|
|
struct BSMultiBoundNode : NiNode
|
|
|
|
{
|
|
|
|
BSMultiBoundPtr mMultiBound;
|
|
|
|
unsigned int mType{ 0 };
|
|
|
|
|
|
|
|
void read(NIFStream* nif) override;
|
|
|
|
void post(Reader& nif) override;
|
|
|
|
};
|
|
|
|
|
2023-07-09 10:14:27 +00:00
|
|
|
struct BSVertexDesc
|
|
|
|
{
|
|
|
|
unsigned char mVertexDataSize;
|
|
|
|
unsigned char mDynamicVertexSize;
|
|
|
|
unsigned char mUV1Offset;
|
|
|
|
unsigned char mUV2Offset;
|
|
|
|
unsigned char mNormalOffset;
|
|
|
|
unsigned char mTangentOffset;
|
|
|
|
unsigned char mColorOffset;
|
|
|
|
unsigned char mSkinningDataOffset;
|
|
|
|
unsigned char mLandscapeDataOffset;
|
|
|
|
unsigned char mEyeDataOffset;
|
|
|
|
unsigned short 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::Vec3f mVertex;
|
|
|
|
float mBitangentX;
|
|
|
|
unsigned int mUnusedW;
|
|
|
|
std::array<Misc::float16_t, 2> mUV;
|
|
|
|
|
|
|
|
std::array<char, 3> mNormal;
|
|
|
|
char mBitangentY;
|
|
|
|
std::array<char, 3> mTangent;
|
|
|
|
char mBitangentZ;
|
|
|
|
std::array<char, 4> mVertColors;
|
|
|
|
std::array<Misc::float16_t, 4> mBoneWeights;
|
|
|
|
std::array<char, 4> mBoneIndices;
|
|
|
|
float mEyeData;
|
|
|
|
|
|
|
|
void read(NIFStream* nif, uint16_t flags);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BSTriShape : Node
|
|
|
|
{
|
|
|
|
NiBoundingVolume::NiSphereBV mBoundingSphere;
|
|
|
|
std::vector<float> mBoundMinMax;
|
|
|
|
|
|
|
|
NiSkinInstancePtr mSkin;
|
|
|
|
BSShaderPropertyPtr mShaderProperty;
|
|
|
|
NiAlphaPropertyPtr mAlphaProperty;
|
|
|
|
|
|
|
|
BSVertexDesc mVertDesc;
|
|
|
|
|
|
|
|
unsigned int mDataSize;
|
|
|
|
unsigned int mParticleDataSize;
|
|
|
|
|
|
|
|
std::vector<BSVertexData> mVertData;
|
|
|
|
std::vector<unsigned short> mTriangles;
|
|
|
|
std::vector<unsigned short> mParticleTriangles;
|
|
|
|
std::vector<osg::Vec3f> mParticleVerts;
|
|
|
|
std::vector<osg::Vec3f> mParticleNormals;
|
|
|
|
|
|
|
|
void read(NIFStream* nif) override;
|
|
|
|
void post(Reader& nif) override;
|
|
|
|
};
|
|
|
|
|
2023-07-10 22:27:05 +00:00
|
|
|
struct BSValueNode : NiNode
|
|
|
|
{
|
|
|
|
unsigned int mValue;
|
|
|
|
char mValueFlags;
|
|
|
|
|
|
|
|
void read(NIFStream* nif) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BSOrderedNode : NiNode
|
|
|
|
{
|
|
|
|
osg::Vec4f mAlphaSortBound;
|
|
|
|
char mStaticBound;
|
|
|
|
|
|
|
|
void read(NIFStream* nif) override;
|
|
|
|
};
|
2010-01-06 11:28:37 +00:00
|
|
|
} // Namespace
|
|
|
|
#endif
|