1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 15:29:55 +00:00
openmw/components/nif/node.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

397 lines
9.2 KiB
C++
Raw Normal View History

#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>
#include "base.hpp"
2010-01-06 11:28:37 +00:00
namespace Nif
{
struct NiNode;
2012-07-03 05:49:44 +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,
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
};
struct NiSphereBV
2022-09-22 18:26:05 +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
};
struct NiBoxBV
2022-09-22 18:26:05 +00:00
{
osg::Vec3f center;
2022-06-17 11:35:33 +00:00
Matrix3 axes;
osg::Vec3f extents;
2022-09-22 18:26:05 +00:00
};
struct NiCapsuleBV
2022-09-22 18:26:05 +00:00
{
osg::Vec3f center, axis;
float extent{ 0.f }, radius{ 0.f };
2022-09-22 18:26:05 +00:00
};
struct NiLozengeBV
2022-09-22 18:26:05 +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
};
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
};
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);
};
/** 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
*/
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
};
// Node flags. Interpretation depends somewhat on the type of node.
unsigned int flags;
2022-09-22 18:26:05 +00:00
2012-07-10 04:35:36 +00:00
Transformation trafo;
osg::Vec3f velocity; // Unused? Might be a run-time game state
PropertyList props;
2022-09-22 18:26:05 +00:00
// Bounding box info
bool hasBounds{ false };
NiBoundingVolume bounds;
2022-09-22 18:26:05 +00:00
// Collision object info
NiCollisionObjectPtr collision;
2022-09-22 18:26:05 +00:00
void read(NIFStream* nif) override;
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.
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
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; }
};
struct NiNode : Node
{
NodeList children;
NodeList effects;
2022-09-22 18:26:05 +00:00
enum BSAnimFlags
2022-09-22 18:26:05 +00:00
{
AnimFlag_AutoPlay = 0x0020
2022-09-22 18:26:05 +00:00
};
enum BSParticleFlags
2022-09-22 18:26:05 +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;
void post(Reader& nif) override;
};
struct NiGeometry : Node
{
/* Possible flags:
0x40 - mesh has no vertex normals ?
2022-09-22 18:26:05 +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
*/
struct MaterialData
2022-09-22 18:26:05 +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
};
NiGeometryDataPtr data;
2020-05-14 07:52:27 +00:00
NiSkinInstancePtr skin;
MaterialData material;
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;
void post(Reader& nif) override;
};
struct NiTriShape : NiGeometry
{
};
struct BSLODTriShape : NiTriShape
{
2022-06-17 11:35:33 +00:00
unsigned int lod0, lod1, lod2;
void read(NIFStream* nif) override;
};
struct NiTriStrips : NiGeometry
2022-09-22 18:26:05 +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
};
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 };
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
// Viewport
2021-01-09 10:21:57 +00:00
float vleft, vright, vtop, vbottom;
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
};
Camera cam;
void read(NIFStream* nif) override;
};
// A node used as the base to switch between child nodes, such as for LOD levels.
struct NiSwitchNode : public NiNode
{
unsigned int switchFlags{ 0 };
2020-05-14 07:52:27 +00:00
unsigned int initialIndex{ 0 };
2022-07-21 11:51:34 +00:00
void read(NIFStream* nif) override;
};
2010-01-07 18:11:03 +00:00
struct NiLODNode : public NiSwitchNode
{
osg::Vec3f lodCenter;
2010-01-07 18:11:03 +00:00
struct LODRange
2022-09-22 18:26:05 +00:00
{
2015-11-12 18:40:31 +00:00
float minRange;
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;
};
2010-01-07 18:11:03 +00:00
2015-11-12 18:40:31 +00:00
struct NiFltAnimationNode : public NiSwitchNode
{
float mDuration;
enum Flags
2022-09-22 18:26:05 +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
{
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
{
};
struct NiAlphaAccumulator : NiClusterAccumulator
{
};
struct NiSortAdjustNode : NiNode
2022-09-22 18:26:05 +00:00
{
enum SortingMode
2022-09-22 18:26:05 +00:00
{
SortingMode_Inherit,
SortingMode_Off,
SortingMode_Subsort
2022-09-22 18:26:05 +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;
void post(Reader& nif) override;
};
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