mirror of
https://github.com/nillerusr/source-engine.git
synced 2025-01-27 23:34:31 +00:00
improve collision loading, fix wrong axes
This commit is contained in:
parent
16b4da144f
commit
58ff2f3a72
@ -320,6 +320,32 @@ struct moppheader_t : public physcollideheader_t
|
||||
};
|
||||
#endif
|
||||
|
||||
class CPhysCollidePx : public CPhysCollide
|
||||
{
|
||||
public:
|
||||
CPhysCollidePx(PxShape *shape)
|
||||
{
|
||||
m_pPxShape = shape;
|
||||
}
|
||||
|
||||
virtual PxShape *GetPxShape()
|
||||
{
|
||||
return m_pPxShape;
|
||||
}
|
||||
|
||||
IVP_SurfaceManager *CreateSurfaceManager( short & ) const { return NULL; }
|
||||
virtual void GetAllLedges( IVP_U_BigVector<IVP_Compact_Ledge> &ledges ) const {}
|
||||
unsigned int GetSerializationSize() { return 0; }
|
||||
int GetVCollideIndex() const { return 0; }
|
||||
Vector GetMassCenter() const { return Vector(0, 0, 0); }
|
||||
void SetMassCenter( const Vector &massCenter ) {}
|
||||
void OutputDebugInfo() const {}
|
||||
unsigned int GetSerializationSize() const { return 0; }
|
||||
unsigned int SerializeToBuffer( char *pDest, bool bSwap = false ) const { return 0; }
|
||||
private:
|
||||
PxShape *m_pPxShape;
|
||||
};
|
||||
|
||||
class CPhysCollideCompactSurface : public CPhysCollide
|
||||
{
|
||||
public:
|
||||
@ -1829,7 +1855,7 @@ float CPhysicsCollision::CollideSurfaceArea( CPhysCollide *pCollide )
|
||||
return area;
|
||||
}
|
||||
|
||||
PxConvexMesh *IVPLedgeToConvexShape( const ivp_compat::compactledge_t *pLedge )
|
||||
PxShape *IVPLedgeToConvexShape( const ivp_compat::compactledge_t *pLedge )
|
||||
{
|
||||
if ( !pLedge->n_triangles )
|
||||
return nullptr;
|
||||
@ -1852,7 +1878,7 @@ PxConvexMesh *IVPLedgeToConvexShape( const ivp_compat::compactledge_t *pLedge )
|
||||
const int nIndex = pTriangles[ i ].c_three_edges[ j ].start_point_index;
|
||||
const float *pVertex = reinterpret_cast< const float * >( pVertices + ( nIndex * IVPAlignedVectorSize ) );
|
||||
|
||||
convexVerts[ ( i * 3 ) + j ] = PxVec3( IVP2HL(pVertex[0]), IVP2HL(pVertex[1]), IVP2HL(pVertex[2]) );
|
||||
convexVerts[ ( i * 3 ) + j ] = PxVec3( IVP2HL(pVertex[0]), IVP2HL(pVertex[2]), -IVP2HL(pVertex[1]) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -1870,19 +1896,19 @@ PxConvexMesh *IVPLedgeToConvexShape( const ivp_compat::compactledge_t *pLedge )
|
||||
PxDefaultMemoryInputData input(buf.getData(), buf.getSize());
|
||||
PxConvexMesh* convexMesh = gPxPhysics->createConvexMesh(input);
|
||||
|
||||
|
||||
PxMaterial *mat = gPxPhysics->createMaterial(0.5f, 0.5f, 0.6f);
|
||||
PxShape *shape = gPxPhysics->createShape( PxConvexMeshGeometry(convexMesh), *mat );
|
||||
|
||||
Msg("Cooking success %u!\n", convexMesh->getNbVertices());
|
||||
if( shape )
|
||||
Msg("Cooking success %u!\n", convexMesh->getNbVertices());
|
||||
|
||||
//pConvexShape->SetUserData( pLedge->client_data );
|
||||
return convexMesh;
|
||||
return shape;
|
||||
}
|
||||
|
||||
|
||||
static void GetAllIVPEdges(const ivp_compat::compactledgenode_t *pNode, CUtlVector<const ivp_compat::compactledge_t *> *vecOut)
|
||||
{
|
||||
|
||||
|
||||
if (!pNode || !vecOut) return;
|
||||
|
||||
if ( !pNode->IsTerminal() )
|
||||
@ -1902,20 +1928,27 @@ CPhysCollide *DeserializeIVP_Poly( const ivp_compat::compactsurface_t* pSurface
|
||||
CUtlVector< const ivp_compat::compactledge_t * > ledges;
|
||||
GetAllIVPEdges( pFirstLedgeNode, &ledges );
|
||||
|
||||
Msg("ledge count - %d\n", ledges.Count());
|
||||
// if( ledges.Count() <= 5 )
|
||||
// return NULL;
|
||||
|
||||
PxShape *mesh = IVPLedgeToConvexShape( ledges[0] );
|
||||
mesh->userData = NULL;
|
||||
|
||||
if( ledges.Count() == 1 )
|
||||
return new CPhysCollidePx( mesh );
|
||||
|
||||
// if( ledges.Count() > 5 )
|
||||
// return NULL;
|
||||
|
||||
PxShape *prevMesh = mesh;
|
||||
for( int i = 1; i < ledges.Count(); i++ )
|
||||
{
|
||||
PxConvexMesh *mesh = IVPLedgeToConvexShape( ledges[0] );
|
||||
return (CPhysCollide*)mesh;
|
||||
PxShape *nextMesh = IVPLedgeToConvexShape( ledges[i] );
|
||||
prevMesh->userData = nextMesh;
|
||||
prevMesh = nextMesh;
|
||||
}
|
||||
|
||||
for( int i = 0; ledges.Count(); i++ )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return new CPhysCollidePx( mesh );
|
||||
}
|
||||
|
||||
CPhysCollide *DeserializeIVP_Poly( const ivp_compat::collideheader_t *pCollideHeader )
|
||||
@ -1953,10 +1986,12 @@ void CPhysicsCollision::VCollideLoad( vcollide_t *pOutput, int solidCount, const
|
||||
if ( pCollideHeader->version != VPHYSICS_COLLISION_VERSION )
|
||||
Warning( "Solid with unknown version: 0x%x, may crash!\n", pCollideHeader->version );
|
||||
|
||||
CPhysCollide *collide;
|
||||
switch ( pCollideHeader->modelType )
|
||||
{
|
||||
case COLLIDE_POLY:
|
||||
pOutput->solids[ i ] = DeserializeIVP_Poly( pCollideHeader );
|
||||
collide = DeserializeIVP_Poly( pCollideHeader );
|
||||
pOutput->solids[ i ] = collide;
|
||||
break;
|
||||
default:
|
||||
Warning( "Unsupported solid type 0x%x on solid %d. Skipping...\n", (int)pCollideHeader->modelType, i );
|
||||
|
0
vphysics-physx/physics_collide.h
Normal file
0
vphysics-physx/physics_collide.h
Normal file
@ -1062,9 +1062,12 @@ CPhysicsObject *CreatePhysicsObject( CPhysicsEnvironment *pEnvironment, const CP
|
||||
|
||||
CPhysicsObject *pObject = new CPhysicsObject();
|
||||
short collideType;
|
||||
IVP_SurfaceManager *pSurman = CreateSurfaceManager( pCollisionModel, collideType );
|
||||
if ( !pSurman )
|
||||
return NULL;
|
||||
|
||||
// IVP_SurfaceManager *pSurman = CreateSurfaceManager( pCollisionModel, collideType );
|
||||
|
||||
// if ( !pSurman )
|
||||
// return NULL;
|
||||
|
||||
pObject->m_collideType = collideType;
|
||||
pObject->m_asleepSinceCreation = true;
|
||||
|
||||
@ -1072,9 +1075,31 @@ CPhysicsObject *CreatePhysicsObject( CPhysicsEnvironment *pEnvironment, const CP
|
||||
|
||||
// IVP_Polygon *realObject = pEnvironment->GetIVPEnvironment()->create_polygon(pSurman, &objectTemplate, &rotation, &pos);
|
||||
|
||||
PxScene *scene = pEnvironment->GetPxScene();
|
||||
PxConvexMesh *mesh = (PxConvexMesh*)pCollisionModel;
|
||||
if( !pCollisionModel )
|
||||
return NULL;
|
||||
|
||||
PxScene *scene = pEnvironment->GetPxScene();
|
||||
PxShape *shape = pCollisionModel->GetPxShape();
|
||||
|
||||
if( shape )
|
||||
{
|
||||
RadianEuler radian(angles);
|
||||
Quaternion qw(radian);
|
||||
|
||||
PxQuat q( qw.x, qw.y, qw.z, qw.w );
|
||||
|
||||
PxTransform t(PxVec3(position.x, position.y, position.z), q);
|
||||
PxRigidStatic* body = gPxPhysics->createRigidStatic(t);
|
||||
|
||||
while( shape )
|
||||
{
|
||||
body->attachShape( *shape );
|
||||
shape = (PxShape*)shape->userData;
|
||||
}
|
||||
|
||||
scene->addActor(*body);
|
||||
}
|
||||
#if 0
|
||||
if( pCollisionModel && mesh->getNbVertices() != 0 )
|
||||
{
|
||||
RadianEuler radian(angles);
|
||||
@ -1094,9 +1119,8 @@ CPhysicsObject *CreatePhysicsObject( CPhysicsEnvironment *pEnvironment, const CP
|
||||
|
||||
scene->addActor(*body);
|
||||
}
|
||||
//PxRigidActorExt::createExclusiveShape(*aConvexActor,
|
||||
// PxConvexMeshGeometry(mesh), aMaterial);
|
||||
}
|
||||
#endif
|
||||
|
||||
pObject->Init( pCollisionModel, NULL, materialIndex, pParams->volume, pParams->dragCoefficient, pParams->dragCoefficient );
|
||||
pObject->SetGameData( pParams->pGameData );
|
||||
|
@ -11,6 +11,7 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "physics_globals.h"
|
||||
|
||||
class Vector;
|
||||
class QAngle;
|
||||
@ -49,6 +50,7 @@ public:
|
||||
virtual void SetOrthographicAreas( const Vector &areas ) = 0;
|
||||
virtual float GetSphereRadius() const = 0;
|
||||
virtual void OutputDebugInfo() const = 0;
|
||||
virtual PxShape *GetPxShape() = 0;
|
||||
};
|
||||
|
||||
#define LEAFMAP_HAS_CUBEMAP 0x0001
|
||||
@ -138,6 +140,7 @@ public:
|
||||
virtual void ComputeOrthographicAreas( float epsilon ) {}
|
||||
virtual void SetOrthographicAreas( const Vector &areas ) {}
|
||||
virtual const collidemap_t *GetCollideMap() const { return NULL; }
|
||||
virtual PxShape *GetPxShape() { return NULL; }
|
||||
};
|
||||
|
||||
class ITraceObject
|
||||
|
Loading…
x
Reference in New Issue
Block a user