Skip to content
Snippets Groups Projects
Commit 826d7681 authored by D-AIRY's avatar D-AIRY
Browse files

moving to new model api

parent d4d02c16
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,6 @@ See the license in LICENSE
#include "BaseAnimating.h"
#include "gcore/sxgcore.h"
#include <xcommon/resource/IXModelProvider.h>
#include <xcommon/resource/IXResourceManager.h>
#include <xcommon/resource/IXResourceModel.h>
......@@ -22,7 +21,7 @@ BEGIN_PROPTABLE(CBaseAnimating)
EDITOR_FILE_END()
//! Масштаб модели
DEFINE_FIELD_FLOAT(m_fBaseScale, 0, "scale", "Scale", EDITOR_TEXTFIELD)
// DEFINE_FIELD_FLOAT(m_fBaseScale, 0, "scale", "Scale", EDITOR_TEXTFIELD)
//! Объект референса для цвета свечения
DEFINE_FIELD_ENTITY(m_pEntColorRef, 0, "glow_color_ref", "Glow color reference", EDITOR_TEXTFIELD)
......@@ -49,8 +48,7 @@ REGISTER_ENTITY_NOLISTING(CBaseAnimating, base_animating);
CBaseAnimating::CBaseAnimating(CEntityManager * pMgr):
BaseClass(pMgr),
m_pAnimPlayer(NULL),
m_fBaseScale(1.0f),
// m_fBaseScale(1.0f),
m_pCollideShape(NULL),
m_pRigidBody(NULL),
m_isStatic(false),
......@@ -62,26 +60,26 @@ CBaseAnimating::CBaseAnimating(CEntityManager * pMgr):
CBaseAnimating::~CBaseAnimating()
{
releasePhysics();
mem_release(m_pAnimPlayer);
mem_release(m_pModel);
}
void CBaseAnimating::getMinMax(float3 * min, float3 * max)
{
if (m_pAnimPlayer)
if(m_pModel)
{
const ISXBound * bound = m_pAnimPlayer->getBound();
bound->getMinMax(min, max);
*min = m_pModel->getLocalBoundMin();
*max = m_pModel->getLocalBoundMax();
}
}
void CBaseAnimating::getSphere(float3 * center, float * radius)
/*void CBaseAnimating::getSphere(float3 * center, float * radius)
{
if(m_pAnimPlayer)
{
const ISXBound * bound = m_pAnimPlayer->getBound();
bound->getSphere(center, radius);
}
}
}*/
bool CBaseAnimating::setKV(const char * name, const char * value)
{
......@@ -93,7 +91,7 @@ bool CBaseAnimating::setKV(const char * name, const char * value)
{
setModel(value);
}
else if(!strcmp(name, "scale"))
/*else if(!strcmp(name, "scale"))
{
releasePhysics();
if(m_pAnimPlayer)
......@@ -101,7 +99,7 @@ bool CBaseAnimating::setKV(const char * name, const char * value)
m_pAnimPlayer->setScale(m_fBaseScale);
}
initPhysics();
}
}*/
return(true);
}
......@@ -109,63 +107,36 @@ void CBaseAnimating::setModel(const char * mdl)
{
_setStrVal(&m_szModelFile, mdl);
releasePhysics();
mem_release(m_pModel);
if(!mdl[0] /*&& m_pAnimPlayer*/)
{
mem_release(m_pAnimPlayer);
return;
}
if(!m_pAnimPlayer)
{
m_pAnimPlayer = SXAnim_CreatePlayer(mdl);
m_pAnimPlayer->setCallback(this, &ThisClass::onAnimationStateChanged);
#if 0
IXResourceManager *pResourceManager = Core_GetIXCore()->getResourceManager(); // get it from somewhere
IXAnimatedModelProvider *pProvider = (IXAnimatedModelProvider*)Core_GetIXCore()->getPluginManager()->getInterface(IXANIMATEDMODELPROVIDER_GUID); // get it from somewhere
IXResourceManager *pResourceManager = Core_GetIXCore()->getResourceManager();
IXModelProvider *pProvider = (IXModelProvider*)Core_GetIXCore()->getPluginManager()->getInterface(IXMODELPROVIDER_GUID);
const IXResourceModel *pResource;
IXResourceModel *pResource;
if(pResourceManager->getModel(mdl, &pResource))
{
if(pResource->getType() == XMT_ANIMATED)
{
IXAnimatedModel *pModel;
const IXResourceModelAnimated *pAnimatedResource = pResource->asAnimated();
if(pProvider->createModel(1, &pAnimatedResource, &pModel))
{
// use model
IXAnimatedModel *pAnimated = pModel->asAnimatedModel();
if(pAnimated)
{
// ??
}
else
{
// ??
}
}
}
else
IXDynamicModel *pModel;
if(pProvider->createDynamicModel(pResource, &pModel))
{
// mem_release(pResource);
m_pModel = pModel;
}
mem_release(pResource);
}
#endif
}
else
{
m_pAnimPlayer->setModel(mdl);
}
m_pAnimPlayer->setSkin(m_iSkin);
m_pAnimPlayer->setScale(m_fBaseScale);
m_pModel->setSkin(m_iSkin);
initPhysics();
}
float3 CBaseAnimating::getAttachmentPos(int id)
{
float3 pos;
if(m_pAnimPlayer && id >= 0)
if(m_pModel && m_pModel->asAnimatedModel() && id >= 0)
{
pos = m_pAnimPlayer->getBoneTransformPos(id);
pos = m_pModel->asAnimatedModel()->getBoneTransformPos(id);
}
return(/*getOrient() * */pos/* + getPos()*/);
......@@ -174,9 +145,9 @@ float3 CBaseAnimating::getAttachmentPos(int id)
SMQuaternion CBaseAnimating::getAttachmentRot(int id)
{
SMQuaternion rot;
if(m_pAnimPlayer && id >= 0)
if(m_pModel && m_pModel->asAnimatedModel() && id >= 0)
{
rot = m_pAnimPlayer->getBoneTransformRot(id);
rot = m_pModel->asAnimatedModel()->getBoneTransformRot(id);
}
return(/*getOrient() * */rot);
......@@ -195,47 +166,47 @@ void CBaseAnimating::onSync()
// m_pRigidBody->getWorldTransform().setOrigin(F3_BTVEC(getPos()));
// m_pRigidBody->getWorldTransform().setRotation(Q4_BTQUAT(getOrient()));
}
if(m_pAnimPlayer)
if(m_pModel)
{
m_pAnimPlayer->setScale(m_fBaseScale);
m_pAnimPlayer->setPos(getPos());
m_pAnimPlayer->setOrient(getOrient());
m_pModel->setPosition(getPos());
m_pModel->setOrientation(getOrient());
float3_t vGlowColor = m_vGlowColor;
bool isGlowEnabled = m_pEntColorRef ? m_pEntColorRef->getMainColor(&vGlowColor) : m_vGlowColor.x != 0.0f || m_vGlowColor.y != 0.0f || m_vGlowColor.z != 0.0f;
m_pAnimPlayer->setGlowColor(vGlowColor);
m_pAnimPlayer->setGlowEnabled(isGlowEnabled);
//bool isGlowEnabled = m_pEntColorRef ? m_pEntColorRef->getMainColor(&vGlowColor) : m_vGlowColor.x != 0.0f || m_vGlowColor.y != 0.0f || m_vGlowColor.z != 0.0f;
m_pModel->setColor(float4(vGlowColor));
//m_pAnimPlayer->setGlowEnabled(isGlowEnabled);
}
}
void CBaseAnimating::playAnimation(const char * name, UINT iFadeTime, UINT slot)
{
if(m_pAnimPlayer)
if(m_pModel && m_pModel->asAnimatedModel())
{
m_pAnimPlayer->play(name, iFadeTime, slot);
m_pModel->asAnimatedModel()->play(name, iFadeTime, slot);
}
}
bool CBaseAnimating::playingAnimations(const char* name)
{
if(m_pAnimPlayer)
if(m_pModel && m_pModel->asAnimatedModel())
{
return(m_pAnimPlayer->playingAnimations(name));
return(m_pModel->asAnimatedModel()->isPlayingAnimation(name));
}
return(false);
}
void CBaseAnimating::playActivity(const char * name, UINT iFadeTime, UINT slot)
{
if(m_pAnimPlayer)
if(m_pModel && m_pModel->asAnimatedModel())
{
m_pAnimPlayer->startActivity(name, iFadeTime, slot);
m_pModel->asAnimatedModel()->startActivity(name, iFadeTime, slot);
}
}
void CBaseAnimating::initPhysics()
{
if(!m_pAnimPlayer)
#if 0
if(!m_pModel && m_pModel->asAnimatedModel())
{
return;
}
......@@ -269,6 +240,7 @@ void CBaseAnimating::initPhysics()
createPhysBody();
#endif
}
void CBaseAnimating::createPhysBody()
......@@ -526,9 +498,9 @@ void CBaseAnimating::inputSetSkin(inputdata_t * pInputdata)
void CBaseAnimating::setSkin(int iSkin)
{
if(m_pAnimPlayer)
if(m_pModel && m_pModel->asAnimatedModel())
{
m_pAnimPlayer->setSkin(iSkin);
m_pModel->asAnimatedModel()->setSkin(iSkin);
}
m_iSkin = iSkin;
}
......
......@@ -18,7 +18,7 @@ See the license in LICENSE
#define __BASE_ANIMATING_H
#include "BaseEntity.h"
#include <anim/sxanim.h>
#include <xcommon/resource/IXModelProvider.h>
//! Анимированный игровой объект
class CBaseAnimating: public CBaseEntity
......@@ -30,7 +30,7 @@ public:
~CBaseAnimating();
void getMinMax(float3 * min, float3 * max);
void getSphere(float3 * center, float * radius);
// void getSphere(float3 * center, float * radius);
bool setKV(const char * name, const char * value);
......@@ -70,9 +70,9 @@ protected:
void inputSetSkin(inputdata_t * pInputdata);
IAnimPlayer * m_pAnimPlayer;
IXModel *m_pModel = NULL;
const char * m_szModelFile;
float m_fBaseScale;
// float m_fBaseScale;
bool m_isStatic;
CBaseEntity *m_pEntColorRef = NULL;
......
......@@ -313,29 +313,31 @@ float CBaseCharacter::getCurrentSpread()
void CBaseCharacter::initHitboxes()
{
if(!m_pAnimPlayer)
if(!m_pModel && m_pModel->asAnimatedModel())
{
return;
}
int l = m_pAnimPlayer->getHitboxCount();
auto pAnimatedModel = m_pModel->asAnimatedModel();
int l = pAnimatedModel->getHitboxCount();
m_pHitboxBodies = new btRigidBody*[l];
const ModelHitbox * hb;
const XResourceModelHitbox * hb;
for(int i = 0; i < l; ++i)
{
hb = m_pAnimPlayer->getHitbox(i);
hb = pAnimatedModel->getHitbox(i);
btCollisionShape *pShape;
switch(hb->type)
{
case HT_BOX:
pShape = new btBoxShape(F3_BTVEC(hb->lwh * 0.5f * m_fBaseScale));
pShape = new btBoxShape(F3_BTVEC(hb->lwh * 0.5f));
break;
case HT_CAPSULE:
pShape = new btCapsuleShape(hb->lwh.y * 0.5f * m_fBaseScale, hb->lwh.z * m_fBaseScale);
pShape = new btCapsuleShape(hb->lwh.y * 0.5f, hb->lwh.z);
break;
case HT_CYLINDER:
pShape = new btCylinderShape(F3_BTVEC(hb->lwh * 0.5f * m_fBaseScale));
pShape = new btCylinderShape(F3_BTVEC(hb->lwh * 0.5f));
break;
case HT_ELIPSOID:
// @FIXME: Add actual elipsoid shape
......@@ -373,15 +375,22 @@ void CBaseCharacter::initHitboxes()
void CBaseCharacter::updateHitboxes()
{
if(!m_pAnimPlayer || !m_pHitboxBodies || !m_pAnimPlayer->playingAnimations())
if(!m_pModel || !m_pHitboxBodies)
{
return;
}
const ModelHitbox * hb;
for(int i = 0, l = m_pAnimPlayer->getHitboxCount(); i < l; ++i)
auto pAnimatedModel = m_pModel->asAnimatedModel();
if(!pAnimatedModel || !pAnimatedModel->isPlayingAnimations())
{
return;
}
//@TODO: Reimplement me
#if 0
const XResourceModelHitbox * hb;
for(int i = 0, l = pAnimatedModel->getHitboxCount(); i < l; ++i)
{
hb = m_pAnimPlayer->getHitbox(i);
hb = pAnimatedModel->getHitbox(i);
//SMMATRIX mBone = m_pAnimPlayer->getBoneTransformPos(hb->bone_id);
......@@ -389,21 +398,27 @@ void CBaseCharacter::updateHitboxes()
m_pHitboxBodies[i]->getWorldTransform().setFromOpenGLMatrix((btScalar*)&(SMMatrixRotationX(hb->rot.x)
* SMMatrixRotationY(hb->rot.y)
* SMMatrixRotationZ(hb->rot.z)
* SMMatrixTranslation(hb->pos * m_fBaseScale)
* m_pAnimPlayer->getBoneTransform(hb->bone_id, true)
* SMMatrixTranslation(hb->pos)
* pAnimatedModel->getBoneTransform(hb->bone_id, true)
* getWorldTM()
));
}
#endif
}
void CBaseCharacter::releaseHitboxes()
{
if(!m_pAnimPlayer || !m_pHitboxBodies)
if(!m_pModel || !m_pHitboxBodies)
{
return;
}
auto pAnimatedModel = m_pModel->asAnimatedModel();
if(!pAnimatedModel)
{
return;
}
for(int i = 0, l = m_pAnimPlayer->getHitboxCount(); i < l; ++i)
for(int i = 0, l = pAnimatedModel->getHitboxCount(); i < l; ++i)
{
SPhysics_RemoveShape(m_pHitboxBodies[i]);
......
......@@ -77,9 +77,9 @@ void CBaseItem::setModeInventory()
m_bWorldMode = false;
releasePhysics();
if(m_pAnimPlayer)
if(m_pModel)
{
mem_release(m_pAnimPlayer);
mem_release(m_pModel);
}
}
......
......@@ -176,11 +176,14 @@ void CBaseTool::reload()
void CBaseTool::attachHands()
{
//@TODO: Reimplement me
#if 0
if(m_pAnimPlayer)
{
m_pAnimPlayer->addModel("models/weapons/hands.dse");
m_pAnimPlayer->assembly();
}
#endif
}
void CBaseTool::dbgMove(int dir, float dy)
......@@ -220,10 +223,10 @@ void CBaseTool::onSync()
float3_t ang = ((CPlayer*)m_pOwner)->getWeaponDeltaAngles();
m_vOffsetOrient = m_qSlotRotResult * SMQuaternion(ang.x, 'x') * SMQuaternion(ang.y, 'y') * SMQuaternion(ang.z, 'z');
BaseClass::onSync();
if(m_pAnimPlayer)
if(m_pModel && m_pModel->asAnimatedModel())
{
//SPE_EffectPlayByID
float3 pos = m_pAnimPlayer->getBoneTransformPos(m_pAnimPlayer->getBone("muzzle_rifle1"));
float3 pos = m_pModel->asAnimatedModel()->getBoneTransformPos(m_pModel->asAnimatedModel()->getBoneId("muzzle_rifle1"));
SPE_EffectSetPos(m_iMuzzleFlash, &pos);
//pos = m_vOrientation * float3(0, 0, 1);
SPE_EffectSetRotQ(m_iMuzzleFlash, m_vOrientation);
......
......@@ -49,9 +49,9 @@ void CBaseTrigger::onPostLoad()
{
BaseClass::onPostLoad();
if(m_pAnimPlayer)
if(m_pModel)
{
m_pAnimPlayer->enable(false);
m_pModel->enable(false);
//m_pAnimPlayer->setOverrideMaterial("dev_trigger.dds");
}
}
......
......@@ -60,7 +60,7 @@ CNPCBase::CNPCBase(CEntityManager * pMgr):
m_bRunMode(false)
{
m_iCurrQuaidInPath = -1;
m_fBaseScale = 0.01f;
// m_fBaseScale = 0.01f;
m_idQuadCurr = -1;
m_statePath = NPC_STATE_PATH_NOTFOUND;
......@@ -89,13 +89,16 @@ void CNPCBase::setModel(const char * mdl)
{
BaseClass::setModel(mdl);
ID idBone = m_pAnimPlayer->getBone("bip01_ponytail1");
if(m_pModel && m_pModel->asAnimatedModel())
{
ID idBone = m_pModel->asAnimatedModel()->getBoneId("bip01_ponytail1");
m_pHeadEnt->setParent(this, idBone);
m_pHeadEnt->setOffsetOrient(SMQuaternion());
m_pHeadEnt->setOffsetPos(float3());
}
}
void CNPCBase::onDeath(CBaseEntity *pAttacker, CBaseEntity *pInflictor)
{
......
/***********************************************************
Copyright Vitaliy Buturlin, Evgeny Danilovich, 2017, 2018
Copyright © Vitaliy Buturlin, Evgeny Danilovich, 2017, 2018
See the license in LICENSE
***********************************************************/
#include "PropDebris.h"
/*! \skydocent prop_debris
Разбиваемый объект
*/
BEGIN_PROPTABLE(CPropDebris)
......@@ -30,6 +30,8 @@ void CPropDebris::sheduleRemove()
void CPropDebris::checkRemove(float fDT)
{
//@TODO: Reimplement me
#if 0
if(!m_pAnimPlayer->isVisibleFor(SX_ANIM_DEFAULT_VISCALCOBJ))
{
REMOVE_ENTITY(this);
......@@ -38,4 +40,5 @@ void CPropDebris::checkRemove(float fDT)
{
SET_TIMEOUT(checkRemove, randf(3.0f, 6.0f));
}
#endif
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment