11#ifdef TOSHI_SKU_WINDOWS
30 , m_uiID( ms_uiNumCreated )
31 , m_pManagedModel(
TNULL )
44 if ( m_pManagedModel )
46 delete m_pManagedModel;
53 TRenderContext* pRenderCtx = ARenderer::GetSingleton()->GetMainViewport()->GetRenderContext();
55 for (
TINT i = 0; i < m_vecInstanceRefs.Size(); i++ )
62 auto& transformScale = transform.
GetScale();
63 auto& lod = pModel->
GetLOD( 0 );
66 vecBoundingSphere.
w = lod.BoundingSphere.GetRadius() *
TMath::Max(
TMath::Max( transformScale.x, transformScale.y ), transformScale.z );
68 if ( vecBoundingSphere.
w <= 0.0f )
77 transform.GetLocalMatrixImp( transformMatrix );
104 for (
TINT i = 0; i < m_vecInstanceRefs.Size(); i++ )
106 auto& pModelInstance = m_vecInstanceRefs[ i ];
107 auto eFlags = pModelInstance->m_eFlags;
113 auto pSceneObject = pModelInstance->GetSceneObject();
114 auto pModel = pSceneObject->GetInstance()->GetModel();
116 auto& transform = pSceneObject->GetTransform();
117 auto& transformScale = transform.GetScale();
118 auto& lod = pModel->GetLOD( 0 );
121 TFLOAT fRadius = lod.BoundingSphere.GetRadius() * fRadiusScale;
124 transform.GetLocalMatrixImp( transformMatrix );
128 pSceneObject->Render( pModelInstance->GetClipFlags(), boundingPos );
141 m_pManagedModel->CreateSceneObject(),
145 m_vecInstanceRefs.PushBack( modelInstanceRef );
146 return modelInstanceRef;
152 m_vecInstanceRefs.FindAndEraseFast( a_pInstance );
157 return m_vecInstanceRefs.Size();
174 if ( filepath.
Find(
".trb" ) < 0 &&
175 filepath.
Find(
".trz" ) < 0 )
180 pModelPtr->Create( filepath, a_pTRB );
182 ASkinLightingManager::GetSingleton()->ApplySkinLight( pModelPtr,
TNULL,
TNULL );
204 iPos1 = name.
Find(
'\\', iPos1 + 1 );
205 }
while ( -1 < iPos1 );
209 iPos2 = name.
Find(
'/', iPos1 + 1 );
210 }
while ( -1 < iPos2 );
212 if ( iPos1 < 0 || name.
Length() - 1 <= iPos1 ) iPos1 = 0;
214 iPos2 = name.
Find(
'_', iPos1 );
215 if ( iPos2 < 0 ) iPos2 = name.
Length() - 1;
217 TUINT iSize = iPos2 - iPos1;
224 else if ( 8 < iSize )
236 static TUINT ms_uiDebugObjectIndex = 0;
242 debugName.
Format(
"%s%i", name.
GetString(), ms_uiDebugObjectIndex % 1000 );
243 ms_uiDebugObjectIndex += 1;
250 : m_ChangeEmitter( this )
252 TFIXME(
"Initialise some unknown members" );
254 m_Scale =
TVector4( 1.0f, 1.0f, 1.0f, 1.0f );
256 m_uiClipFlags = 0x3F;
257 m_pSceneObject = a_pSceneObject;
258 m_eFlags = Flags_ReceivesLight | Flags_UpdatingSkeleton;
260 SetSkeletonUpdating( a_bEnableSkeletonUpdate );
261 m_pSceneObject->GetInstance()->SetCustomRenderMethod( RenderInstanceCallback,
this );
266 : m_ChangeEmitter( this )
268 TFIXME(
"Initialise some unknown members" );
270 m_Scale =
TVector4( 1.0f, 1.0f, 1.0f, 1.0f );
272 m_pSceneObject =
TNULL;
273 m_uiClipFlags = 0x3F;
280 m_pSceneObject->GetTransform().SetMatrix( a_rcTransform );
284void AModelInstance::RenderInstanceCallback(
TModelInstance* a_pInstance,
void* a_pUserData )
310 TMatrix44 matTransform;
311 pGameModelInstance->
GetSceneObject()->GetTransform().GetLocalMatrixImp( matTransform );
317 TLightIDList lightIds;
318 AGlowViewport::GetSingleton()->GetInfluencingLightIDs( boundingSphere, lightIds );
320 if ( lightIds[ 0 ] != -1 )
323 pRenderContext->
AddLight( lightIds[ 0 ] );
327 static TUINT s_uiUnusedFlags;
328 if ( !( s_uiUnusedFlags & 1 ) )
329 s_uiUnusedFlags |= 1;
331 static TMatrix44 s_oOldModelViewMatrix;
332 TMatrix44 oScaledModelViewMatrix;
334 if ( pGameModelInstance )
341 oScaledModelViewMatrix.
Scale( pGameModelInstance->
GetScale() );
351 AStaticInstanceMaterial* pStaticInstanceMat = AModelLoader::ms_pDefaultStaticInstanceMaterial;
352 AWorldMaterial* pWorldMat = AModelLoader::ms_pDefaultWorldMaterial;
353 ASkinMaterial* pSkinMat = AModelLoader::ms_pDefaultSkinMaterial;
355 static constexpr TINT MAX_NUM_MATERIALS = 32;
356 TMaterial* apOldMaterials[ MAX_NUM_MATERIALS ];
366 else if ( bIsStaticInstanceMesh )
371 apOldMaterials[ i ] = pLOD->
ppMeshes[ i ]->GetMaterial();
372 pLOD->
ppMeshes[ i ]->SetMaterial( pStaticInstanceMat );
379 pLOD->
ppMeshes[ i ]->SetMaterial( apOldMaterials[ i ] );
383 else if ( bIsWorldMesh )
388 apOldMaterials[ i ] = pLOD->
ppMeshes[ i ]->GetMaterial();
389 pLOD->
ppMeshes[ i ]->SetMaterial( pWorldMat );
396 pLOD->
ppMeshes[ i ]->SetMaterial( apOldMaterials[ i ] );
405 apOldMaterials[ i ] = pLOD->
ppMeshes[ i ]->GetMaterial();
406 pLOD->
ppMeshes[ i ]->SetMaterial( pSkinMat );
413 pLOD->
ppMeshes[ i ]->SetMaterial( apOldMaterials[ i ] );
418 if ( pGameModelInstance )
432 m_pSceneObject->EnableSkeletonUpdate();
442 m_pSceneObject->DisableSkeletonUpdate();
481 return m_pModel->GetName();
Rendering system interface for the Toshi engine.
#define TSTATICCAST(POINTERTYPE, VALUE)
#define HASANYFLAG(STATE, FLAG)
#define TOSHI_NAMESPACE_USING
#define TDEFINE_CLASS(...)
Toshi::TRef< AModelInstance > AModelInstanceRef
TFORCEINLINE const T & Max(const T &a, const T &b)
static constexpr void TransformVector(TVector3 &a_rOutVector, const TMatrix44 &a_rMatrix, const TVector3 &a_rVector)
constexpr void Scale(TFLOAT a_fScalar1, TFLOAT a_fScalar2, TFLOAT a_fScalar3)
constexpr TFORCEINLINE TVector3 & GetOrigin()
TModel * GetModel() const
TSkeletonInstance * GetSkeletonInstance() const
TModelLOD & GetLOD(TUINT32 a_uiLOD)
static TBOOL CullSphereToFrustumSimple(const TSphere &a_rSphere, const TPlane *a_pPlanes, TINT a_iNumPlanes)
void SetSkeletonInstance(TSkeletonInstance *a_pSkeletonInstance)
TMatrix44 & GetModelViewMatrix()
const TPlane * GetWorldPlanes()
void AddLight(TLightID a_iLightId)
TUINT GetClipFlags() const
virtual void SetModelViewMatrix(const TMatrix44 &a_rMatrix)
TRenderContext * GetCurrentContext() const
void UpdateState(TBOOL a_bForceUpdate)
const TVector3 & GetScale() const
TFORCEINLINE const TString8 & GetString8() const
TModelInstance * GetInstance()
TTransformObject & GetTransform()
static TFORCEINLINE TRenderInterface * GetSingleton()
TString8 & Format(const TCHAR *a_pcFormat,...)
TINT Find(TCHAR character, TINT pos=0) const
void Copy(const TString8 &src, TINT size=-1)
const TCHAR * GetString(TINT a_iIndex=0) const
void SetReceivesLight(TBOOL a_bReceives)
TBOOL IsUpdatingSkeleton() const
TBOOL DrawWithDefaultMaterials() const
const Toshi::TVector4 & GetScale() const
const Toshi::TPString8 & GetModelName() const
@ ChangeEvent_DisabledSkeletonUpdate
@ ChangeEvent_EnabledSkeletonUpdate
TBOOL ReceivesLight() const
void SetTransform(const Toshi::TMatrix44 &a_rcTransform)
void SetVisible(TBOOL a_bVisible)
Toshi::TSceneObject * GetSceneObject() const
void SetClipFlags(TUINT a_uiClipFlags)
void SetSkeletonUpdating(TBOOL a_bUpdating)
void DestroyInstance(AModelInstance *a_pInstance)
AModelInstanceRef CreateInstance()
static void GetNameFromPath(const Toshi::TPString8 &a_FilePath, Toshi::TString8 &a_rName)
AModel(const Toshi::TPString8 &a_rName, Toshi::TTRB *a_pTRB)
TSIZE GetNumInstances() const
void Render(TBOOL a_bIsSomething)
void Update(TFLOAT a_fDeltaTime)
static Toshi::TManagedModel * Create(const Toshi::TPString8 &a_rFilePath, Toshi::TTRB *a_pTRB)
static Toshi::TString8 GenerateInstanceName(const Toshi::TPString8 &a_FilePath)