1
0
Fork 0
mirror of https://git.rip/DMCA_FUCKER/re3.git synced 2024-06-26 15:07:36 +00:00
re3/src/modelinfo/PedModelInfo.cpp

220 lines
6.2 KiB
C++
Raw Normal View History

2019-05-15 14:52:37 +00:00
#include "common.h"
2020-04-17 13:31:11 +00:00
2021-01-24 16:14:16 +00:00
#include "main.h"
#include "RwHelper.h"
#include "General.h"
#include "Bones.h"
#include "SurfaceTable.h"
#include "Ped.h"
2019-05-15 14:52:37 +00:00
#include "NodeName.h"
#include "VisibilityPlugins.h"
#include "ModelInfo.h"
2020-08-19 14:10:22 +00:00
#include "custompipes.h"
2021-01-24 16:14:16 +00:00
#include "Streaming.h"
#include "Leeds.h"
#include "TempColModels.h"
base::cRelocatableChunkClassInfo CPedModelInfo::msClassInfo("CPedModelInfo", VTABLE_ADDR(&msClassInstance), sizeof(msClassInstance));
CPedModelInfo CPedModelInfo::msClassInstance;
2019-05-15 14:52:37 +00:00
void
CPedModelInfo::DeleteRwObject(void)
{
2021-01-24 16:14:16 +00:00
CStreaming::UnregisterPointer(&m_hitColModel, 2);
2020-05-10 11:08:02 +00:00
CClumpModelInfo::DeleteRwObject();
2021-01-24 16:14:16 +00:00
if(!gUseChunkFiles && m_hitColModel)
2019-05-15 14:52:37 +00:00
delete m_hitColModel;
m_hitColModel = nil;
}
2020-05-10 11:08:02 +00:00
// leftover...
RwObjectNameIdAssocation CPedModelInfo::m_pPedIds[PED_NODE_MAX] = {
{ "Smid", PED_MID, 0, }, // that is strange...
2019-05-15 14:52:37 +00:00
{ "Shead", PED_HEAD, 0, },
{ "Supperarml", PED_UPPERARML, 0, },
{ "Supperarmr", PED_UPPERARMR, 0, },
{ "SLhand", PED_HANDL, 0, },
{ "SRhand", PED_HANDR, 0, },
{ "Supperlegl", PED_UPPERLEGL, 0, },
{ "Supperlegr", PED_UPPERLEGR, 0, },
{ "Sfootl", PED_FOOTL, 0, },
{ "Sfootr", PED_FOOTR, 0, },
{ "Slowerlegr", PED_LOWERLEGR, 0, },
2019-06-30 10:53:39 +00:00
{ nil, 0, 0, },
2019-05-15 14:52:37 +00:00
};
void
CPedModelInfo::SetClump(RpClump *clump)
{
2020-08-19 14:10:22 +00:00
#ifdef EXTENDED_PIPELINES
CustomPipes::AttachRimPipe(clump);
#endif
2021-01-24 16:14:16 +00:00
if(!IsClumpSkinned(clump))
return;
2019-05-15 14:52:37 +00:00
CClumpModelInfo::SetClump(clump);
2020-05-10 11:08:02 +00:00
SetFrameIds(m_pPedIds); // not needed in VC actually
2019-05-15 14:52:37 +00:00
if(m_hitColModel == nil)
2020-05-10 11:08:02 +00:00
CreateHitColModelSkinned(clump);
RpClumpForAllAtomics(m_clump, SetAtomicRendererCB, (void*)CVisibilityPlugins::RenderPedCB);
2021-01-24 16:14:16 +00:00
//if(strcmp(GetModelName(), "player") == 0)
// RpClumpForAllAtomics(m_clump, SetAtomicRendererCB, (void*)CVisibilityPlugins::RenderPlayerCB);
2019-05-15 14:52:37 +00:00
}
struct ColNodeInfo
{
2020-05-11 23:24:57 +00:00
Const char *name;
2019-05-15 14:52:37 +00:00
int pedNode;
int pieceType;
float x, z;
float radius;
};
2020-05-09 15:05:26 +00:00
#define NUMPEDINFONODES 10
2019-05-15 14:52:37 +00:00
ColNodeInfo m_pColNodeInfos[NUMPEDINFONODES] = {
2020-05-09 15:05:26 +00:00
{ nil, PED_HEAD, PEDPIECE_HEAD, 0.0f, 0.05f, 0.15f },
{ nil, PED_MID, PEDPIECE_TORSO, 0.0f, 0.15f, 0.2f },
{ nil, PED_MID, PEDPIECE_TORSO, 0.0f, -0.05f, 0.25f },
{ nil, PED_MID, PEDPIECE_MID, 0.0f, -0.25f, 0.25f },
{ nil, PED_UPPERARML, PEDPIECE_LEFTARM, 0.03f, -0.05f, 0.16f },
{ nil, PED_UPPERARMR, PEDPIECE_RIGHTARM, -0.03f, -0.05f, 0.16f },
{ nil, PED_LOWERLEGL, PEDPIECE_LEFTLEG, 0.0f, 0.15f, 0.2f },
{ nil, PED_LOWERLEGR, PEDPIECE_RIGHTLEG, 0.0f, 0.15f, 0.2f },
{ nil, PED_FOOTL, PEDPIECE_LEFTLEG, 0.0f, 0.15f, 0.15f },
{ nil, PED_FOOTR, PEDPIECE_RIGHTLEG, 0.0f, 0.15f, 0.15f },
2019-05-15 14:52:37 +00:00
};
2021-01-24 16:14:16 +00:00
bool
CPedModelInfo::CreateHitColModelSkinned(RpClump *clump)
{
CColModel *colmodel = new CColModel;
CColSphere *spheres = (CColSphere*)RwMalloc(NUMPEDINFONODES*sizeof(CColSphere));
for(int i = 0; i < NUMPEDINFONODES; i++){
2021-01-24 16:14:16 +00:00
spheres[i].center.x = 0.0f;
spheres[i].center.y = 0.0f;
spheres[i].center.z = 0.0f;
2020-10-23 10:11:51 +00:00
spheres[i].radius = m_pColNodeInfos[i].radius;
spheres[i].surface = SURFACE_PED;
spheres[i].piece = m_pColNodeInfos[i].pieceType;
}
colmodel->spheres = spheres;
colmodel->numSpheres = NUMPEDINFONODES;
2020-10-23 10:11:51 +00:00
colmodel->boundingSphere.Set(2.0f, CVector(0.0f, 0.0f, 0.0f));
colmodel->boundingBox.Set(CVector(-0.5f, -0.5f, -1.2f), CVector(0.5f, 0.5f, 1.2f));
2020-07-13 14:43:09 +00:00
colmodel->level = LEVEL_GENERIC;
m_hitColModel = colmodel;
2021-01-24 16:14:16 +00:00
return true;
}
CColModel*
CPedModelInfo::AnimatePedColModelSkinned(RpClump *clump)
{
if(m_hitColModel == nil){
CreateHitColModelSkinned(clump);
2021-01-24 16:14:16 +00:00
#ifndef FIX_BUGS
return m_hitColModel;
2021-01-24 16:14:16 +00:00
#endif
// we should really animate this now
}
2021-01-24 16:14:16 +00:00
RwMatrix invmat, mat;
CColSphere *spheres = m_hitColModel->spheres;
RpHAnimHierarchy *hier = GetAnimHierarchyFromSkinClump(clump);
2021-01-24 16:14:16 +00:00
RwMatrixInvert(&invmat, RwFrameGetMatrix(RpClumpGetFrame(clump)));
for(int i = 0; i < NUMPEDINFONODES; i++){
2021-01-24 16:14:16 +00:00
mat = invmat;
int id = ConvertPedNode2BoneTag(m_pColNodeInfos[i].pedNode);
int idx = RpHAnimIDGetIndex(hier, id);
2021-01-24 16:14:16 +00:00
RwMatrixTransform(&mat, &RpHAnimHierarchyGetMatrixArray(hier)[idx], rwCOMBINEPRECONCAT);
RwV3d pos = { 0.0f, 0.0f, 0.0f }; // actually CVector
RwV3dTransformPoints(&pos, &pos, 1, &mat);
2020-10-23 10:11:51 +00:00
spheres[i].center = pos + CVector(m_pColNodeInfos[i].x, 0.0f, m_pColNodeInfos[i].z);
}
return m_hitColModel;
}
2020-05-10 11:08:02 +00:00
CColModel*
CPedModelInfo::AnimatePedColModelSkinnedWorld(RpClump *clump)
{
if(m_hitColModel == nil)
CreateHitColModelSkinned(clump);
CColSphere *spheres = m_hitColModel->spheres;
RpHAnimHierarchy *hier = GetAnimHierarchyFromSkinClump(clump);
RwMatrix *mat;
for(int i = 0; i < NUMPEDINFONODES; i++){
int id = ConvertPedNode2BoneTag(m_pColNodeInfos[i].pedNode);
int idx = RpHAnimIDGetIndex(hier, id);
mat = &RpHAnimHierarchyGetMatrixArray(hier)[idx];
2021-01-24 16:14:16 +00:00
RwV3d pos = { 0.0f, 0.0f, 0.0f }; // actually CVector
2020-05-10 11:08:02 +00:00
RwV3dTransformPoints(&pos, &pos, 1, mat);
2020-10-23 10:11:51 +00:00
spheres[i].center = pos + CVector(m_pColNodeInfos[i].x, 0.0f, m_pColNodeInfos[i].z);
2020-05-10 11:08:02 +00:00
}
return m_hitColModel;
}
2021-01-24 16:14:16 +00:00
struct PedChunk
{
CColModel *colmodel;
RpClump *clump;
};
void
CPedModelInfo::LoadModel(void *data, const void *chunk)
{
PedChunk *chk = (PedChunk*)data;
m_hitColModel = chk->colmodel;
CStreaming::RegisterPointer(&m_hitColModel, 2, true);
CClumpModelInfo::LoadModel(chk->clump, chunk);
}
void
CPedModelInfo::Write(base::cRelocatableChunkWriter &writer)
{
SetColModel(&gpTempColModels->ms_colModelPed1);
CClumpModelInfo::Write(writer);
if(m_hitColModel){
writer.AddPatch(&m_hitColModel);
m_hitColModel->Write(writer, true);
}
}
void*
CPedModelInfo::WriteModel(base::cRelocatableChunkWriter &writer)
{
PedChunk *chunk = new PedChunk; // LEAK
chunk->colmodel = nil;
chunk->clump = nil;
writer.AllocateRaw(chunk, sizeof(*chunk), sizeof(void*), false, true);
chunk->clump = (RpClump*)CClumpModelInfo::WriteModel(writer);
if(chunk->clump)
writer.AddPatch(&chunk->clump);
chunk->colmodel = m_hitColModel;
if(chunk->colmodel){
writer.AddPatch(&chunk->colmodel);
chunk->colmodel->Write(writer, true);
}
return nil;
}
void
CPedModelInfo::RcWriteThis(base::cRelocatableChunkWriter &writer)
{
writer.AllocateRaw(this, sizeof(*this), sizeof(void*), false, true);
writer.Class(VTABLE_ADDR(this), msClassInfo);
}
void
CPedModelInfo::RcWriteEmpty(base::cRelocatableChunkWriter &writer)
{
writer.AllocateRaw(this, sizeof(*this), sizeof(void*), false, true);
writer.Class(VTABLE_ADDR(this), msClassInfo);
}