Correct NiBoundingVolume loading

just_say_no_to_geode
Alexei Kotov 3 years ago
parent fad49a1bd8
commit e6f7a2f1ef

@ -1,6 +1,8 @@
#ifndef OPENMW_COMPONENTS_NIF_NODE_HPP #ifndef OPENMW_COMPONENTS_NIF_NODE_HPP
#define OPENMW_COMPONENTS_NIF_NODE_HPP #define OPENMW_COMPONENTS_NIF_NODE_HPP
#include <osg/Plane>
#include "controlled.hpp" #include "controlled.hpp"
#include "extra.hpp" #include "extra.hpp"
#include "data.hpp" #include "data.hpp"
@ -21,6 +23,7 @@ struct NiBoundingVolume
{ {
enum Type enum Type
{ {
BASE_BV = 0xFFFFFFFF,
SPHERE_BV = 0, SPHERE_BV = 0,
BOX_BV = 1, BOX_BV = 1,
CAPSULE_BV = 2, CAPSULE_BV = 2,
@ -38,7 +41,7 @@ struct NiBoundingVolume
struct NiBoxBV struct NiBoxBV
{ {
osg::Vec3f center; osg::Vec3f center;
Matrix3 axis; Matrix3 axes;
osg::Vec3f extents; osg::Vec3f extents;
}; };
@ -56,7 +59,8 @@ struct NiBoundingVolume
struct NiHalfSpaceBV struct NiHalfSpaceBV
{ {
osg::Vec3f center, normal; osg::Plane plane;
osg::Vec3f origin;
}; };
unsigned int type; unsigned int type;
@ -65,12 +69,14 @@ struct NiBoundingVolume
NiCapsuleBV capsule; NiCapsuleBV capsule;
NiLozengeBV lozenge; NiLozengeBV lozenge;
std::vector<NiBoundingVolume> children; std::vector<NiBoundingVolume> children;
NiHalfSpaceBV plane; NiHalfSpaceBV halfSpace;
void read(NIFStream* nif) void read(NIFStream* nif)
{ {
type = nif->getUInt(); type = nif->getUInt();
switch (type) switch (type)
{ {
case BASE_BV:
break;
case SPHERE_BV: case SPHERE_BV:
{ {
sphere.center = nif->getVector3(); sphere.center = nif->getVector3();
@ -80,7 +86,7 @@ struct NiBoundingVolume
case BOX_BV: case BOX_BV:
{ {
box.center = nif->getVector3(); box.center = nif->getVector3();
box.axis = nif->getMatrix3(); box.axes = nif->getMatrix3();
box.extents = nif->getVector3(); box.extents = nif->getVector3();
break; break;
} }
@ -95,8 +101,11 @@ struct NiBoundingVolume
case LOZENGE_BV: case LOZENGE_BV:
{ {
lozenge.radius = nif->getFloat(); lozenge.radius = nif->getFloat();
lozenge.extent0 = nif->getFloat(); if (nif->getVersion() >= NIFStream::generateVersion(4,2,1,0))
lozenge.extent1 = nif->getFloat(); {
lozenge.extent0 = nif->getFloat();
lozenge.extent1 = nif->getFloat();
}
lozenge.center = nif->getVector3(); lozenge.center = nif->getVector3();
lozenge.axis0 = nif->getVector3(); lozenge.axis0 = nif->getVector3();
lozenge.axis1 = nif->getVector3(); lozenge.axis1 = nif->getVector3();
@ -114,8 +123,9 @@ struct NiBoundingVolume
} }
case HALFSPACE_BV: case HALFSPACE_BV:
{ {
plane.center = nif->getVector3(); halfSpace.plane = osg::Plane(nif->getVector4());
plane.normal = nif->getVector3(); if (nif->getVersion() >= NIFStream::generateVersion(4,2,1,0))
halfSpace.origin = nif->getVector3();
break; break;
} }
default: default:

Loading…
Cancel
Save