Files
sbox-public/engine/Definitions/resources/hmodel.def
Antoine Pilote d15dd2096e Support for multi-drawcall LODs in clutter GPU-driven path (#5308)
* Support for multi-drawcall LODs in clutter GPU-driven path

* store arg offset in variable instead of hardcoding it

* use flat draw index

* dotnet format
2026-07-15 09:27:29 -07:00

334 lines
9.1 KiB
Modula-2

#include "mathlib/ray.h"
#include "raytrace/raytrace_glue.h"
native struct MeshTraceInput
native struct MeshTraceOutput
native class CUtlVector<MeshTraceOutput> as NativeEngine.CUtlVectorMeshTraceOutput
{
void DeleteThis(); [delete]
static CUtlVectorMeshTraceOutput Create( int growsize, int initialcapacity ); [new]
int Count();
MeshTraceOutput Element( int i );
}
native enum CModelSkeleton::BoneFlags_t as NativeEngine.BoneFlags;
[ResourceHandle:HModel]
native class CModel as NativeEngine.IModel
{
stable string GetModelName();
stable string GetBaseModelName();
IModel GetBaseModel();
bool IsTranslucent();
bool IsTranslucentTwoPass();
bool HasPhysics();
KeyValues3 FindModelSubKey( string name );
// old
bool GetAttachmentTransform( StringToken name, cref out Transform tx );
stable string GetAttachmentNameFromIndex( int index );
int GetBodyPartForName( string pName );
stable string GetBodyPartName( int nPart );
int GetNumBodyParts();
int GetNumBodyPartMeshes( int nPart );
ulong GetBodyPartMask( int nPart );
ulong GetBodyPartMeshMask( int nPart, int nMesh );
int FindMeshIndexForMask( int nPart, ulong nMask );
int GetNumMeshGroups();
ulong GetDefaultMeshGroupMask();
inline string GetBodyPartMeshName( int nPart, int nMesh )
{
static thread_local CBufferString str;
self->GetBodyPartMeshName( nPart, nMesh, &str );
return str.String();
}
int GetNumMaterialGroups();
stable string GetMaterialGroupName( int iGroup );
int GetMaterialGroupIndex( StringToken nGroup );
int GetNumMaterialsInGroup( int iGroup );
IMaterial GetMaterialInGroup( int iGroup, int iIndex );
inline int GetNumSceneObjects( int iMesh )
{
const CRenderMesh *pMesh = self->GetMeshData( iMesh );
return pMesh->m_sceneObjects.Count();
}
inline int GetNumDrawCalls( int iMesh, int nSceneObject )
{
const CRenderMesh *pMesh = self->GetMeshData( iMesh );
return pMesh->m_sceneObjects[nSceneObject].m_drawCalls.Count();
}
inline IMaterial GetMaterial( int iMesh, int nSceneObject, int nDrawCall )
{
const CRenderMesh *pMesh = self->GetMeshData( iMesh );
return pMesh->m_sceneObjects[nSceneObject].m_drawCalls[nDrawCall].GetMaterial();
}
inline void GetTotalMeshCounts( out int totalVertices, out int totalTriangles, out int totalDrawCalls )
{
*totalVertices = 0;
*totalTriangles = 0;
*totalDrawCalls = 0;
for ( int i = 0; i < self->GetNumMeshes(); i++ )
{
const CRenderMesh *pMesh = self->GetMeshData( i );
if ( !pMesh ) continue;
int v, t, d;
pMesh->CalculateNumTriangles( &v, &t, &d );
*totalVertices += v;
*totalTriangles += t;
*totalDrawCalls += d;
}
}
inline void GetMeshInfo( int iMesh, out int vertexCount, out int triangleCount, out int drawCallCount, out int lodMask, out int translucencyType, out Vector3 boundsMin, out Vector3 boundsMax )
{
*vertexCount = 0;
*triangleCount = 0;
*drawCallCount = 0;
*lodMask = 0;
*translucencyType = 0;
*boundsMin = Vector( 0, 0, 0 );
*boundsMax = Vector( 0, 0, 0 );
const CRenderMesh *pMesh = self->GetMeshData( iMesh );
if ( !pMesh ) return;
pMesh->CalculateNumTriangles( vertexCount, triangleCount, drawCallCount );
*lodMask = self->GetLODMaskForMesh( iMesh );
*translucencyType = (int)pMesh->m_translucencyType;
*boundsMin = pMesh->m_vMinBounds;
*boundsMax = pMesh->m_vMaxBounds;
}
inline string GetMeshName( int iMesh )
{
const CRenderMesh *pMesh = self->GetMeshData( iMesh );
if ( !pMesh ) return "";
return pMesh->GetName();
}
inline void GetDrawCallInfo( int iMesh, int iDrawCall, out int vertexCount, out int indexCount, out int primitiveType, out float uvDensity, out int instanceCount, out int alphaBlended, out int startIndex, out int baseVertex )
{
*vertexCount = 0;
*indexCount = 0;
*primitiveType = 0;
*uvDensity = 0.0f;
*instanceCount = 0;
*alphaBlended = 0;
*startIndex = 0;
*baseVertex = 0;
const CRenderMesh *pMesh = self->GetMeshData( iMesh );
if ( !pMesh ) return;
// Flatten draw calls across scene objects to match the flat index from CalculateNumTriangles
int flatIndex = 0;
for ( int iSO = 0; iSO < pMesh->m_sceneObjects.Count(); iSO++ )
{
int nDraws = pMesh->m_sceneObjects[iSO].GetNumDrawCalls();
if ( iDrawCall < flatIndex + nDraws )
{
const CMaterialDrawDescriptor *pDraw = pMesh->m_sceneObjects[iSO].GetDrawCall( iDrawCall - flatIndex );
*vertexCount = pDraw->m_nVertexCount;
*indexCount = pDraw->m_nIndexCount;
*primitiveType = (int)pDraw->m_nPrimitiveType;
*uvDensity = pDraw->m_flUvDensity;
*instanceCount = pDraw->m_nInstanceCount;
*alphaBlended = pDraw->m_bAlphaBlendedMaterial != 0 ? 1 : 0;
*startIndex = pDraw->m_nStartIndex;
*baseVertex = pDraw->m_nBaseVertex;
return;
}
flatIndex += nDraws;
}
}
inline IMaterial GetDrawCallMaterial( int iMesh, int iDrawCall )
{
const CRenderMesh *pMesh = self->GetMeshData( iMesh );
if ( !pMesh ) return nullptr;
HMaterial result;
int flatIndex = 0;
for ( int iSO = 0; iSO < pMesh->m_sceneObjects.Count(); iSO++ )
{
int nDraws = pMesh->m_sceneObjects[iSO].GetNumDrawCalls();
if ( iDrawCall < flatIndex + nDraws )
{
result = pMesh->m_sceneObjects[iSO].GetDrawCall( iDrawCall - flatIndex )->GetMaterial();
break;
}
flatIndex += nDraws;
}
return result;
}
int GetNumMeshes();
int ComputeMaxLODLevelUsedByModel();
int LODLevelForScreenSize( float flScreenWidthInPixels, float scale );
inline int GetLODSwitchDistanceCount()
{
return self->GetLODGroupSwitchDistances().Count();
}
inline float GetLODSwitchDistance( int index )
{
return self->GetLODGroupSwitchDistances()[index];
}
BBox GetMeshBounds();
BBox GetPhysicsBounds();
BBox GetModelRenderBounds();
int NumBones();
int FindBoneIndex( string name );
stable string boneName( int iBone );
int boneParent( int iBone );
Transform GetBoneTransform( int iBone );
Vector3 bonePosParentSpace( int iBone );
Rotation boneRotParentSpace( int iBone );
int NumFlexControllers();
inline stable string GetFlexControllerName( int nFlexController )
{
return self->GetFlexControllerName( LocalFlexController_t( nFlexController ) );
}
int GetVisemeIndex( string viseme );
[nogc]
float GetVisemeMorph( int viseme, int morph );
int GetNumAnim();
stable string GetAnimationName( int nAnimation );
inline void GetSequenceNames( CUtlVectorString names )
{
for ( HSequence hSequence = self->FirstSequence(); hSequence != SEQUENCE_HANDLE_INVALID; hSequence = self->NextSequence( hSequence ) )
{
const ISequence* pSequence = self->pSeqdesc( hSequence );
if ( !pSequence ) continue;
if ( pSequence->IsHidden() ) continue;
names->AddToTail( pSequence->GetName() );
}
}
[nogc]
inline bool HasSceneObjects()
{
for ( int i = 0; i < self->GetNumMeshes(); ++i )
{
const CRenderMesh *pMesh = self->GetMeshData( i );
if ( pMesh && pMesh->m_sceneObjects.Count() > 0 )
return true;
}
return false;
}
inline bool MeshTrace( MeshTraceInput input, ref MeshTraceOutput output )
{
return self->MeshTrace( input, *output );
}
HAnimationGraph GetAnimationGraph();
CPhysicsData GetPhysicsContainer();
// Hitboxes
//int GetBoneIndexForHitboxForMesh( const CHitBox *pHitBox, int nMesh ) const;
CHitBoxSet FindHitboxSetByName( string pName, int nMesh );
int FindHitboxSetIndexByName( string pName, int nMesh );
CHitBoxSet GetHitboxSetByIndex( int nIndex, int nMesh );
int GetBoneIndexForHitbox( CHitBox pHitBox );
int GetHitboxSetCount( int nMesh );
//void GetHitboxSetsForMeshGroupMask( CHitboxSetList &hitBoxSets, MeshGroupMask_t nActiveMask, CUtlStringToken hitboxSetName = CUtlStringToken() ) const;
//void GetHitboxesForMeshGroupMask( CHitboxList &hitBoxes, MeshGroupMask_t nActiveMask, CUtlStringToken hitboxSetName = CUtlStringToken() ) const;
//int GetBoneIndexForHitbox( const HitBoxAndMesh_t &hitBox ) const;
bool HasSkinnedMeshes();
bool HasAnimationDrivenFlexes();
BoneFlags boneFlags( int iBone );
int GetNumAttachments();
inline CAttachment GetAttachment( int index )
{
AttachmentHandle_t handle = self->GetAttachmentHandleFromIndex( index );
if ( handle == ATTACHMENT_HANDLE_INVALID) return nullptr;
if ( handle == ATTACHMENT_HANDLE_UNKNOWN) return nullptr;
return self->GetAttachment( handle );
}
int GetMaterialIndexCount();
IMaterial GetMaterialByIndex( int index );
}
native class CAttachment
{
CUtlString m_name;
byte m_nInfluences;
bool m_bIgnoreRotation;
inline CUtlString GetInfluenceName( int index )
{
return self->m_influenceNames[index];
}
inline Vector3 GetInfluenceOffset( int index )
{
return self->m_vInfluenceOffsets[index];
}
inline Rotation GetInfluenceRotation( int index )
{
return self->m_vInfluenceRotations[index];
}
}
native class CHitBoxSet
{
CUtlString m_name;
CUtlString m_SourceFilename;
int numhitboxes();
CHitBox pHitbox( int nIndex );
}
native class CHitBox
{
Vector3 m_vMinBounds;
Vector3 m_vMaxBounds;
CUtlString m_name;
CUtlString m_sSurfaceProperty;
CUtlString m_sBoneName;
float m_flShapeRadius;
uint m_nBoneNameHash;
Color m_cRenderColor;
ushort m_nHitBoxIndex;
byte m_nShapeType;
bool m_bForcedTransform;
bool m_bTranslationOnly;
bool m_bVisible;
bool m_bSelected;
string GetTag( int index );
}