Skip to content

Commit

Permalink
game_shared: trace: fixed tracing model meshes with non-zero skin number
Browse files Browse the repository at this point in the history
  • Loading branch information
SNMetamorph committed Feb 28, 2024
1 parent 708225e commit 4f112dc
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion client/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ void Physic_SweepTest(cl_entity_t *pTouch, const Vector &start, const Vector &mi
scale = Vector(pev->scale);
}

trm.SetTraceMesh(pMesh, pHeadNode, pTouch->curstate.modelindex);
trm.SetTraceMesh(pMesh, pHeadNode, pTouch->curstate.modelindex, bodyMesh.GetBody(), bodyMesh.GetSkin());
trm.SetMeshOrientation(pev->origin, pev->angles, scale);
trm.SetupTrace(start, mins, maxs, end, tr);

Expand Down
2 changes: 2 additions & 0 deletions game_shared/meshdesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class CMeshDesc
// get cached collision
mmesh_t *GetMesh() { return (m_bMeshBuilt) ? &m_mesh : NULL; }
areanode_t *GetHeadNode() { return (has_tree) ? areanodes : NULL; }
int32_t GetBody() const { return m_iBodyNumber; }
int32_t GetSkin() const { return m_iSkinNumber; }

void SetDebugName(const char *name) { m_debugName = name; }
void SetModel(const model_t *mod, int32_t body, int32_t skin);
Expand Down
8 changes: 5 additions & 3 deletions game_shared/trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ extern globalvars_t *gpGlobals;
// and to avoid various numeric issues
#define SURFACE_CLIP_EPSILON (0.125)

void TraceMesh :: SetTraceMesh( mmesh_t *cached_mesh, areanode_t *tree, int modelindex )
void TraceMesh :: SetTraceMesh( mmesh_t *cached_mesh, areanode_t *tree, int modelindex, int32_t body, int32_t skin )
{
m_pModel = (model_t *)MODEL_HANDLE( modelindex );
mesh = cached_mesh;
areanodes = tree;
m_bodyNumber = body;
m_skinNumber = skin;
}

matdesc_t *TraceMesh :: GetMaterialForFacet( const mfacet_t *facet )
Expand Down Expand Up @@ -75,8 +77,8 @@ mstudiotexture_t *TraceMesh :: GetTextureForFacet( const mfacet_t *facet )
if (phdr->numtextures != 0 && phdr->textureindex != 0)
{
short *pskinref = (short *)((byte *)phdr + phdr->skinindex);
if (m_iSkin > 0 && m_iSkin < phdr->numskinfamilies)
pskinref += (m_iSkin * phdr->numskinref);
if (m_skinNumber > 0 && m_skinNumber < phdr->numskinfamilies)
pskinref += (m_skinNumber * phdr->numskinref);

return &textures[pskinref[facet->skinref]];
}
Expand Down
13 changes: 3 additions & 10 deletions game_shared/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class TraceMesh
Vector m_vecOrigin;
Vector m_vecAngles;
Vector m_vecScale;
int m_iSkin;
int m_iBody;
int32_t m_bodyNumber;
int32_t m_skinNumber;
matrix4x4 m_transform;
model_t *m_pModel;

Expand All @@ -59,17 +59,10 @@ class TraceMesh
~TraceMesh() {}

// trace stuff
void SetTraceMesh( mmesh_t *cached_mesh, areanode_t *tree, int modelindex );
void SetTraceMesh( mmesh_t *cached_mesh, areanode_t *tree, int modelindex, int32_t body, int32_t skin );
void SetMeshOrientation( const Vector &pos, const Vector &ang, const Vector &xform )
{
m_vecOrigin = pos, m_vecAngles = ang, m_vecScale = xform;
m_iBody = m_iSkin = 0; // reset it
}

void SetMeshParams( int body, int skin )
{
m_iBody = body;
m_iSkin = skin;
}

void SetupTrace( const Vector &start, const Vector &mins, const Vector &maxs, const Vector &end, trace_t *trace );
Expand Down
8 changes: 7 additions & 1 deletion server/physx/physx_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2616,6 +2616,8 @@ void CPhysicPhysX :: SweepTest( CBaseEntity *pTouch, const Vector &start, const

mmesh_t *pMesh;
areanode_t *pHeadNode;
int32_t meshBody, meshSkin;

if (mod->type == mod_studio && FBitSet(gpGlobals->trace_flags, FTRACE_MATERIAL_TRACE))
{
CMeshDesc &originalMesh = meshDescFactory.CreateObject(pTouch->pev->modelindex, pTouch->pev->body, pTouch->pev->skin, clipfile::GeometryType::Original);
Expand All @@ -2627,17 +2629,21 @@ void CPhysicPhysX :: SweepTest( CBaseEntity *pTouch, const Vector &start, const
}
}

meshBody = originalMesh.GetBody();
meshSkin = originalMesh.GetSkin();
pMesh = originalMesh.GetMesh();
pHeadNode = originalMesh.GetHeadNode();
}
else
{
meshBody = cookedMesh.GetBody();
meshSkin = cookedMesh.GetSkin();
pMesh = cookedMesh.GetMesh();
pHeadNode = cookedMesh.GetHeadNode();
}

TraceMesh trm;
trm.SetTraceMesh(pMesh, pHeadNode, pTouch->pev->modelindex);
trm.SetTraceMesh(pMesh, pHeadNode, pTouch->pev->modelindex, meshBody, meshSkin);
trm.SetMeshOrientation(pTouch->pev->origin, pTouch->pev->angles, pTouch->GetScale());
trm.SetupTrace(start, mins, maxs, end, tr);

Expand Down

0 comments on commit 4f112dc

Please sign in to comment.