From 83be42893d8be7e0261aa1af866f915a0eac2631 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Sat, 15 Jul 2023 06:09:34 +0300 Subject: [PATCH] Read bhkRagdollConstraint --- components/nif/niffile.cpp | 1 + components/nif/physics.cpp | 88 ++++++++++++++++++++++++++++++++++++++ components/nif/physics.hpp | 71 ++++++++++++++++++++++++++++++ components/nif/record.hpp | 1 + 4 files changed, 161 insertions(+) diff --git a/components/nif/niffile.cpp b/components/nif/niffile.cpp index 4fc624d609..71ad075704 100644 --- a/components/nif/niffile.cpp +++ b/components/nif/niffile.cpp @@ -179,6 +179,7 @@ namespace Nif { "bhkListShape", &construct }, { "bhkRigidBody", &construct }, { "bhkRigidBodyT", &construct }, + { "bhkRagdollConstraint", &construct }, { "BSLightingShaderProperty", &construct }, { "BSEffectShaderProperty", &construct }, { "NiSortAdjustNode", &construct }, diff --git a/components/nif/physics.cpp b/components/nif/physics.cpp index 2d1abeff58..3d2da2fb39 100644 --- a/components/nif/physics.cpp +++ b/components/nif/physics.cpp @@ -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(nif->get()); + 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 diff --git a/components/nif/physics.hpp b/components/nif/physics.hpp index bf1ca4c011..f6f4e7490b 100644 --- a/components/nif/physics.hpp +++ b/components/nif/physics.hpp @@ -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 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 diff --git a/components/nif/record.hpp b/components/nif/record.hpp index b5319d2b2f..22a4b6acd8 100644 --- a/components/nif/record.hpp +++ b/components/nif/record.hpp @@ -145,6 +145,7 @@ namespace Nif RC_bhkListShape, RC_bhkRigidBody, RC_bhkRigidBodyT, + RC_bhkRagdollConstraint, RC_BSLightingShaderProperty, RC_BSEffectShaderProperty, RC_NiClusterAccumulator,