Repository navigation
Expand file tree
/
Copy pathMeshPose.cpp
More file actions
137 lines (101 loc) · 3.21 KB
/
Copy pathMeshPose.cpp
File metadata and controls
137 lines (101 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Mesh pose computation code
#include "common.h"
#include "meshpose.h"
#include "meshrenderer.h"
#include "renderablething.h"
#include "renderthing.h"
#include "motioncontroller.h"
#include "game.h"
void CMeshPose::UpdatePoseHierarchy(FVector p, FMatrix ori, CMESHPART *mp, IRenderableThing *t, CRenderThing *rt, SINT flags)
{
CMESHPART *rendermp;
SINT localflags=flags;
CMeshRenderer::CalculateMeshHierarchy(t,&p,&ori,mp,&rendermp,&localflags);
mPartOri[mp->mPartNumber]=ori;
mPartPos[mp->mPartNumber]=p;
mPartRenderPart[mp->mPartNumber]=rendermp->mPartNumber;
mPartFlags[mp->mPartNumber]=localflags;
// and the children
SINT c0;
for (c0 = 0; c0 < mp->mNumChildren; c0 ++)
{
UpdatePoseHierarchy(p, ori, mp->mChildren[c0], t, rt, localflags);
}
}
BOOL CMeshPose::UpdatePose(CMesh *mesh,IRenderableThing *t,CRenderThing *rt,BOOL important)
{
// Check if we've actually moved, and if not then don't bother updating the pose
int frame=(int) GAME.GetRenderFrameNumber();
if (frame==mLastUpdateFrame) // Never update twice in one render frame
return(FALSE);
// if (t && (((CThing *)t)->IsA(THING_TYPE_MECH)))
// important = TRUE;
if (((frame)<(mLastUpdateFrame+30)) && (!important)) // Only allow non-critical updates every 30 frames
return(FALSE);
CMotionController *controller=t->GetMotionController();
float fvframe=0.0f;
int animind=t->GetRealAnimIndex();
BOOL update=FALSE;
if (mLastUpdateFrame=-9999) // First update
update=TRUE;
if ((mesh->mNumAnimModes) && (animind>=0))
{
CAnimMode* am = &mesh->mAnimModes[animind];
if (am)
{
fvframe = t->GetRenderFrame();
fvframe*=am->mFrameScaler;
fvframe+=am->mStart;
}
}
if (mCurrentFVFrame!=fvframe)
update=TRUE;
if (controller)
if (controller->IsUpdateNeeded())
update=TRUE;
if (!update)
return(FALSE);
UpdatePoseHierarchy(ZERO_FVECTOR,ID_FMATRIX,mesh->GetPart(0),t,rt,0);
mLastUpdateFrame=frame;
mCurrentFVFrame=fvframe;
return(TRUE);
}
void CMeshPose::GetPoseTransforms(CRenderThing *rt,IRenderableThing *t,CMeshPart *mp,FVector &outVector,FMatrix &outMatrix,BOOL inModelSpace,BOOL important)
{
outVector=ZERO_FVECTOR;
outMatrix=ID_FMATRIX;
CMeshPose *pose=rt->GetPose();
CMESH *mesh=rt->GetRTMesh();
if (!mesh)
return;
if (!mp)
return;
if ((pose) && (GAME.mRenderFrameNumber>1)) // HACK - don't use pose controller before rendering starts because we might be in init (see Hive Boss)
{
// Use pose cache
pose->UpdatePose(mesh,t,rt,important);
outVector=pose->mPartPos[mp->mPartNumber];
outMatrix=pose->mPartOri[mp->mPartNumber];
if (!inModelSpace)
{
FVector lpos=t->GetRenderPos();
FMatrix lori=t->GetRenderOrientation();
outVector=(lori * outVector) + lpos;
outMatrix=lori * outMatrix;
}
}
else
{
// Figure it out properly :-(
if (mp)
{
SINT f1;
float offset;
if (t->GetRealAnimIndex()>=0)
f1=mp->ResolveFrameNumber(t->GetRenderFrame(),t->GetRealAnimIndex(),offset,t->GetMotionController());
else
f1=0;
mp->GetWorldTransforms(f1,f1,0.0f,t,&outMatrix,&outVector,inModelSpace?true:false,true);
}
}
}