1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-30 09:15:38 +00:00

Read bhkRagdollConstraint

This commit is contained in:
Alexei Kotov 2023-07-15 06:09:34 +03:00
parent 723f5c58e1
commit 83be42893d
4 changed files with 161 additions and 0 deletions

View file

@ -179,6 +179,7 @@ namespace Nif
{ "bhkListShape", &construct<bhkListShape, RC_bhkListShape> },
{ "bhkRigidBody", &construct<bhkRigidBody, RC_bhkRigidBody> },
{ "bhkRigidBodyT", &construct<bhkRigidBody, RC_bhkRigidBodyT> },
{ "bhkRagdollConstraint", &construct<bhkRagdollConstraint, RC_bhkRagdollConstraint> },
{ "BSLightingShaderProperty", &construct<BSLightingShaderProperty, RC_BSLightingShaderProperty> },
{ "BSEffectShaderProperty", &construct<BSEffectShaderProperty, RC_BSEffectShaderProperty> },
{ "NiSortAdjustNode", &construct<NiSortAdjustNode, RC_NiSortAdjustNode> },

View file

@ -202,6 +202,88 @@ namespace Nif
postRecordList(nif, mEntities);
}
void bhkPositionConstraintMotor::read(NIFStream* nif)
{
nif->read(mMinForce);
nif->read(mMaxForce);
nif->read(mTau);
nif->read(mDamping);
nif->read(mProportionalRecoveryVelocity);
nif->read(mConstantRecoveryVelocity);
mEnabled = nif->getBoolean();
}
void bhkVelocityConstraintMotor::read(NIFStream* nif)
{
nif->read(mMinForce);
nif->read(mMaxForce);
nif->read(mTau);
nif->read(mTargetVelocity);
mUseVelocityTarget = nif->getBoolean();
mEnabled = nif->getBoolean();
}
void bhkSpringDamperConstraintMotor::read(NIFStream* nif)
{
nif->read(mMinForce);
nif->read(mMaxForce);
nif->read(mSpringConstant);
nif->read(mSpringDamping);
mEnabled = nif->getBoolean();
}
void bhkConstraintMotorCInfo::read(NIFStream* nif)
{
mType = static_cast<hkMotorType>(nif->get<uint32_t>());
switch (mType)
{
case hkMotorType::Motor_Position:
mPositionMotor.read(nif);
break;
case hkMotorType::Motor_Velocity:
mVelocityMotor.read(nif);
break;
case hkMotorType::Motor_SpringDamper:
mSpringDamperMotor.read(nif);
break;
case hkMotorType::Motor_None:
default:
break;
}
}
void bhkRagdollConstraintCInfo::read(NIFStream* nif)
{
mEntityData.resize(2); // Hardcoded by the format
if (nif->getBethVersion() <= 16)
{
for (EntityData& data: mEntityData)
{
nif->read(data.mPivot);
nif->read(data.mPlane);
nif->read(data.mTwist);
}
}
else
{
for (EntityData& data: mEntityData)
{
nif->read(data.mTwist);
nif->read(data.mPlane);
nif->read(data.mMotor);
nif->read(data.mPivot);
}
}
nif->read(mConeMaxAngle);
nif->read(mPlaneMinAngle);
nif->read(mPlaneMaxAngle);
nif->read(mTwistMinAngle);
nif->read(mTwistMaxAngle);
nif->read(mMaxFriction);
if (nif->getVersion() >= NIFFile::NIFVersion::VER_BGS && nif->getBethVersion() > 16)
mMotor.read(nif);
}
/// Record types
void bhkCollisionObject::read(NIFStream* nif)
@ -474,4 +556,10 @@ namespace Nif
mInfo.post(nif);
}
void bhkRagdollConstraint::read(NIFStream* nif)
{
bhkConstraint::read(nif);
mConstraint.read(nif);
}
} // Namespace

View file

@ -225,6 +225,71 @@ namespace Nif
void post(Reader& nif);
};
enum class hkMotorType : uint8_t
{
Motor_None = 0,
Motor_Position = 1,
Motor_Velocity = 2,
Motor_SpringDamper = 3
};
struct bhkPositionConstraintMotor
{
float mMinForce, mMaxForce;
float mTau;
float mDamping;
float mProportionalRecoveryVelocity;
float mConstantRecoveryVelocity;
bool mEnabled;
void read(NIFStream* nif);
};
struct bhkVelocityConstraintMotor
{
float mMinForce, mMaxForce;
float mTau;
float mTargetVelocity;
bool mUseVelocityTarget;
bool mEnabled;
void read(NIFStream* nif);
};
struct bhkSpringDamperConstraintMotor
{
float mMinForce, mMaxForce;
float mSpringConstant;
float mSpringDamping;
bool mEnabled;
void read(NIFStream* nif);
};
struct bhkConstraintMotorCInfo
{
hkMotorType mType;
bhkPositionConstraintMotor mPositionMotor;
bhkVelocityConstraintMotor mVelocityMotor;
bhkSpringDamperConstraintMotor mSpringDamperMotor;
void read(NIFStream* nif);
};
struct bhkRagdollConstraintCInfo
{
struct EntityData
{
osg::Vec4f mPivot;
osg::Vec4f mPlane;
osg::Vec4f mTwist;
osg::Vec4f mMotor;
};
std::vector<EntityData> mEntityData;
float mConeMaxAngle;
float mPlaneMinAngle, mPlaneMaxAngle;
float mTwistMinAngle, mTwistMaxAngle;
float mMaxFriction;
bhkConstraintMotorCInfo mMotor;
void read(NIFStream* nif);
};
/// Record types
// Abstract Bethesda Havok object
@ -455,5 +520,11 @@ namespace Nif
void post(Reader& nif) override;
};
struct bhkRagdollConstraint : public bhkConstraint
{
bhkRagdollConstraintCInfo mConstraint;
void read(NIFStream* nif) override;
};
} // Namespace
#endif

View file

@ -145,6 +145,7 @@ namespace Nif
RC_bhkListShape,
RC_bhkRigidBody,
RC_bhkRigidBodyT,
RC_bhkRagdollConstraint,
RC_BSLightingShaderProperty,
RC_BSEffectShaderProperty,
RC_NiClusterAccumulator,