OpenBarnyard
 
Loading...
Searching...
No Matches
AModelLoader_Skin.cpp
Go to the documentation of this file.
1#include "pch.h"
2#include "AModelLoader.h"
3
4#ifdef TOSHI_SKU_WINDOWS
8#endif // TOSHI_SKU_WINDOWS
9
10#include <Toshi/T2String.h>
12
13//-----------------------------------------------------------------------------
14// Enables memory debugging.
15// Note: Should be the last include!
16//-----------------------------------------------------------------------------
17#include <Core/TMemoryDebugOn.h>
18
20
21static TClass* s_pSkinMaterialClass = TNULL;
22
23void AModelLoader::LoadSkinLOD( Toshi::TModel* a_pModel, TINT a_iLODIndex, Toshi::TModelLOD* a_pLOD, Toshi::TTMDWin::TRBLODHeader* a_pLODHeader )
24{
26
27 auto pShader = TDYNAMICCAST( ASkinShaderHAL, ASkinShader::GetSingleton() );
28
29 TINT iMeshCount = a_pLODHeader->m_iMeshCount1 + a_pLODHeader->m_iMeshCount2;
30
31 for ( TINT i = 0; i < iMeshCount; i++ )
32 {
33 T2FormatString128 symbolName;
34 symbolName.Format( "LOD%d_Mesh_%d", a_iLODIndex, i );
35
36 auto pTRBMesh = a_pModel->CastSymbol<TTMDWin::TRBLODMesh>( symbolName.Get() );
37
38 auto pMesh = pShader->CreateMesh( TNULL );
39 pMesh->Create( 0, pTRBMesh->m_uiNumVertices, pTRBMesh->m_uiNumSubMeshes );
40
41 if ( TNULL == s_pSkinMaterialClass )
42 {
43 s_pSkinMaterialClass = TClass::Find( "ASkinMaterial" );
44 }
45
46 auto pMaterial = CreateMaterial( pShader, pTRBMesh->m_szMaterialName );
47 pMesh->SetMaterial( pMaterial );
48
49 a_pLOD->ppMeshes[ i ] = pMesh;
50
51 for ( TUINT k = 0; k < pTRBMesh->m_uiNumSubMeshes; k++ )
52 {
53 auto pSubMesh = pMesh->GetSubMesh( k );
54 auto pTRBSubMesh = &pTRBMesh->m_pSubMeshes[ k ];
55
56 TUtil::MemCopy( pSubMesh->aBones, pTRBSubMesh->m_pBones, pTRBSubMesh->m_uiNumBones * sizeof( TINT ) );
57
58 // Create index pool
59 if ( pSubMesh->pIndexPool == TNULL )
60 {
61 auto pIndexFactory = TRenderInterface::GetSingleton()->GetSystemResource<TIndexFactoryResourceInterface>( SYSRESOURCE_IFSYS );
62 TVALIDPTR( pIndexFactory );
63
64 pSubMesh->pIndexPool = pIndexFactory->CreatePoolResource( pTRBMesh->m_uiNumIndices, 9 );
65 }
66
67 pSubMesh->uiNumBones = pTRBSubMesh->m_uiNumBones;
68 pSubMesh->uiNumVertices = pTRBSubMesh->m_uiNumVertices2;
69 pSubMesh->Zero = pTRBSubMesh->m_Zero;
70 pSubMesh->Unk2 = pTRBSubMesh->m_Unk2;
71 pSubMesh->Unk3 = pTRBSubMesh->m_Unk3;
72 pSubMesh->Unk4 = pTRBSubMesh->m_Unk4;
73 pSubMesh->Unk5 = pTRBSubMesh->m_Unk5;
74 pSubMesh->Unk6 = pTRBSubMesh->m_Unk6;
75
76 if ( pTRBSubMesh->m_uiNumVertices1 != 0 )
77 {
78 auto pVertexPool = pMesh->GetVertexPool();
79
80 TVertexPoolResourceInterface::LockBuffer vertexLockBuffer;
81 TBOOL bLocked = pVertexPool->Lock( &vertexLockBuffer );
82
83 TASSERT( bLocked && "Couldn't lock vertex buffer" );
84
85 if ( bLocked )
86 {
87 TUtil::MemCopy( vertexLockBuffer.apStreams[ 0 ], pTRBSubMesh->m_pVertices, pTRBSubMesh->m_uiNumVertices1 * 40 );
88 pVertexPool->Unlock( pTRBSubMesh->m_uiNumVertices1 );
89 }
90 }
91
92 auto pIndexPool = pSubMesh->pIndexPool;
93 TVALIDPTR( pIndexPool );
94
95 if ( pTRBSubMesh->m_uiNumIndices != 0 )
96 {
97 TIndexPoolResourceInterface::LockBuffer indexLockBuffer;
98
99 pIndexPool->Lock( &indexLockBuffer );
100 TUtil::MemCopy( indexLockBuffer.pBuffer, pTRBSubMesh->m_pIndices, pTRBSubMesh->m_uiNumIndices * 2 );
101 pIndexPool->Unlock( pTRBSubMesh->m_uiNumIndices );
102 }
103 }
104 }
105}
@ SYSRESOURCE_IFSYS
Definition TRender.h:18
Rendering system interface for the Toshi engine.
#define TASSERT(X,...)
Definition Defines.h:138
#define TOSHI_NAMESPACE_USING
Definition Defines.h:46
#define TVALIDPTR(PTR)
Definition Defines.h:139
#define TPROFILER_SCOPE()
Definition Profiler.h:17
T2FormatString< 128, T2StringTraits< TCHAR > > T2FormatString128
Definition T2String.h:242
#define TDYNAMICCAST(T, OBJECT)
Definition TObject.h:227
unsigned int TUINT
Definition Typedefs.h:8
#define TNULL
Definition Typedefs.h:23
int TINT
Definition Typedefs.h:7
bool TBOOL
Definition Typedefs.h:6
T * GetSystemResource(SYSRESOURCE systemResource)
TBYTE * apStreams[TVertexFactoryFormat::MAX_NUM_STREAMS]
void Format(const CharType *a_szFormat,...)
Definition T2String.h:172
constexpr CharType * Get()
Definition T2String.h:204
Definition TClass.h:8
static TClass * Find(const TCHAR *name, TClass *parent=TNULL)
Definition TClass.cpp:110
static TFORCEINLINE TRenderInterface * GetSingleton()
Definition TSingleton.h:49
static void * MemCopy(void *dst, const void *src, TSIZE size)
Definition TUtil.h:90
static Toshi::TMaterial * CreateMaterial(Toshi::TShader *a_pShader, const TCHAR *a_szMaterialName)