allow reuse/coop links within a model

master
Lee Salzman 2013-05-10 14:28:53 +03:00
parent 5b6baa1c41
commit a46d9ee122
3 changed files with 61 additions and 8 deletions

View File

@ -965,7 +965,7 @@ struct animmodel : model
LINK_REUSE
};
virtual int linktype(animmodel *m) const { return LINK_TAG; }
virtual int linktype(animmodel *m, part *p) const { return LINK_TAG; }
void intersect(int anim, int basetime, int basetime2, float pitch, const vec &axis, const vec &forward, dynent *d, modelattach *a, const vec &o, const vec &ray)
{
@ -982,7 +982,7 @@ struct animmodel : model
animmodel *m = (animmodel *)a[i].m;
if(!m || !m->loaded) continue;
part *p = m->parts[0];
switch(linktype(m))
switch(linktype(m, p))
{
case LINK_TAG:
p->index = link(p, a[i].tag, vec(0, 0, 0), a[i].anim, a[i].basetime, a[i].pos) ? index : -1;
@ -1002,12 +1002,27 @@ struct animmodel : model
animstate as[MAXANIMPARTS];
parts[0]->intersect(anim, basetime, basetime2, pitch, axis, forward, d, o, ray, as);
for(int i = 1; i < parts.length(); i++)
{
part *p = parts[i];
switch(linktype(this, p))
{
case LINK_COOP:
p->intersect(anim, basetime, basetime2, pitch, axis, forward, d, o, ray);
break;
case LINK_REUSE:
p->intersect(anim | ANIM_REUSE, basetime, basetime2, pitch, axis, forward, d, o, ray, as);
break;
}
}
if(a) for(int i = numtags-1; i >= 0; i--)
{
animmodel *m = (animmodel *)a[i].m;
if(!m || !m->loaded) continue;
part *p = m->parts[0];
switch(linktype(m))
switch(linktype(m, p))
{
case LINK_TAG:
if(p->index >= 0) unlink(p);
@ -1084,7 +1099,7 @@ struct animmodel : model
continue;
}
part *p = m->parts[0];
switch(linktype(m))
switch(linktype(m, p))
{
case LINK_TAG:
p->index = link(p, a[i].tag, vec(0, 0, 0), a[i].anim, a[i].basetime, a[i].pos) ? index : -1;
@ -1104,6 +1119,21 @@ struct animmodel : model
animstate as[MAXANIMPARTS];
parts[0]->render(anim, basetime, basetime2, pitch, axis, forward, d, as);
for(int i = 1; i < parts.length(); i++)
{
part *p = parts[i];
switch(linktype(this, p))
{
case LINK_COOP:
p->render(anim, basetime, basetime2, pitch, axis, forward, d);
break;
case LINK_REUSE:
p->render(anim | ANIM_REUSE, basetime, basetime2, pitch, axis, forward, d, as);
break;
}
}
if(a) for(int i = numtags-1; i >= 0; i--)
{
animmodel *m = (animmodel *)a[i].m;
@ -1113,7 +1143,7 @@ struct animmodel : model
continue;
}
part *p = m->parts[0];
switch(linktype(m))
switch(linktype(m, p))
{
case LINK_TAG:
if(p->index >= 0) unlink(p);
@ -1226,6 +1256,18 @@ struct animmodel : model
matrix3x4 m;
initmatrix(m);
parts[0]->gentris(tris, m);
for(int i = 1; i < parts.length(); i++)
{
part *p = parts[i];
switch(linktype(this, p))
{
case LINK_COOP:
case LINK_REUSE:
p->gentris(tris, m);
break;
}
}
}
void preloadBIH()
@ -1353,6 +1395,17 @@ struct animmodel : model
matrix3x4 m;
initmatrix(m);
parts[0]->calcbb(bbmin, bbmax, m);
for(int i = 1; i < parts.length(); i++)
{
part *p = parts[i];
switch(linktype(this, p))
{
case LINK_COOP:
case LINK_REUSE:
p->calcbb(bbmin, bbmax, m);
break;
}
}
radius = bbmax;
radius.sub(bbmin);
radius.mul(0.5f);

View File

@ -78,7 +78,7 @@ struct md2 : vertmodel, vertloader<md2>
static bool multimeshed() { return false; }
int type() const { return MDL_MD2; }
int linktype(animmodel *m) const { return LINK_COOP; }
int linktype(animmodel *m, part *p) const { return LINK_COOP; }
struct md2meshgroup : vertmeshgroup
{

View File

@ -1777,10 +1777,10 @@ struct skelmodel : animmodel
{
}
int linktype(animmodel *m) const
int linktype(animmodel *m, part *p) const
{
return type()==m->type() &&
((skelmeshgroup *)parts[0]->meshes)->skel == ((skelmeshgroup *)m->parts[0]->meshes)->skel ?
((skelmeshgroup *)parts[0]->meshes)->skel == ((skelmeshgroup *)p->meshes)->skel ?
LINK_REUSE :
LINK_TAG;
}