2022-02-01 00:06:54 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
2022-02-25 07:45:25 +00:00
|
|
|
#include "CStopwatch.hpp"
|
|
|
|
#include "CToken.hpp"
|
|
|
|
#include "GCNTypes.hpp"
|
|
|
|
#include "Graphics/CTexture.hpp"
|
2022-02-26 22:52:05 +00:00
|
|
|
#include "Runtime/Factory/IObjectStore.hpp"
|
2022-02-01 00:06:54 +00:00
|
|
|
|
2022-02-25 07:45:25 +00:00
|
|
|
namespace metaforce {
|
2022-02-01 00:06:54 +00:00
|
|
|
class CCubeSurface;
|
2022-02-04 08:10:09 +00:00
|
|
|
class CCubeMaterial;
|
2022-02-25 07:45:25 +00:00
|
|
|
struct CModelFlags;
|
2022-02-01 00:06:54 +00:00
|
|
|
|
2022-02-25 07:45:25 +00:00
|
|
|
enum class ESurfaceSelection {
|
|
|
|
Unsorted,
|
|
|
|
Sorted,
|
2022-02-26 07:05:59 +00:00
|
|
|
All,
|
2022-02-01 00:06:54 +00:00
|
|
|
};
|
2022-02-01 09:18:42 +00:00
|
|
|
|
2022-02-25 07:45:25 +00:00
|
|
|
// These parameters were originally float*
|
|
|
|
using TVectorRef = const std::vector<zeus::CVector3f>*;
|
2022-02-01 09:18:42 +00:00
|
|
|
|
|
|
|
class CCubeModel {
|
2022-02-25 07:45:25 +00:00
|
|
|
friend class CModel;
|
|
|
|
|
2022-02-03 15:24:41 +00:00
|
|
|
private:
|
|
|
|
class ModelInstance {
|
2022-02-25 07:45:25 +00:00
|
|
|
std::vector<CCubeSurface>* x0_surfacePtrs; // was rstl::vector<void*>*
|
|
|
|
u8* x4_materialData; //
|
|
|
|
std::vector<zeus::CVector3f>* x8_positions; // was void*
|
|
|
|
std::vector<zeus::CVector3f>* xc_normals; // was void*
|
|
|
|
std::vector<zeus::CColor>* x10_colors; // was void*
|
|
|
|
std::vector<zeus::CVector2f>* x14_texCoords; // was void*
|
|
|
|
std::vector<zeus::CVector2f>* x18_packedTexCoords; // was void*
|
2022-02-03 15:24:41 +00:00
|
|
|
|
|
|
|
public:
|
2022-02-25 07:45:25 +00:00
|
|
|
ModelInstance(std::vector<CCubeSurface>* surfaces, u8* material, std::vector<zeus::CVector3f>* positions,
|
|
|
|
std::vector<zeus::CColor>* colors, std::vector<zeus::CVector3f>* normals,
|
|
|
|
std::vector<zeus::CVector2f>* texCoords, std::vector<zeus::CVector2f>* packedTexCoords)
|
2022-02-03 15:24:41 +00:00
|
|
|
: x0_surfacePtrs(surfaces)
|
|
|
|
, x4_materialData(material)
|
|
|
|
, x8_positions(positions)
|
|
|
|
, xc_normals(normals)
|
|
|
|
, x10_colors(colors)
|
|
|
|
, x14_texCoords(texCoords)
|
|
|
|
, x18_packedTexCoords(packedTexCoords) {}
|
|
|
|
|
2022-02-25 07:45:25 +00:00
|
|
|
/*
|
|
|
|
* These functions have been slightly modified from their original to return the actual vector instead of a raw
|
2022-02-03 15:24:41 +00:00
|
|
|
* pointer
|
|
|
|
*/
|
2022-02-25 07:45:25 +00:00
|
|
|
[[nodiscard]] std::vector<CCubeSurface>* Surfaces() const { return x0_surfacePtrs; }
|
|
|
|
[[nodiscard]] u8* GetMaterialPointer() const { return x4_materialData; }
|
|
|
|
void SetMaterialPointer(u8* mat) { x4_materialData = mat; }
|
|
|
|
[[nodiscard]] TVectorRef GetVertexPointer() const { return x8_positions; }
|
|
|
|
[[nodiscard]] TVectorRef GetNormalPointer() const { return xc_normals; }
|
|
|
|
[[nodiscard]] std::vector<zeus::CColor>* GetColorPointer() const { return x10_colors; }
|
|
|
|
[[nodiscard]] std::vector<zeus::CVector2f>* GetTCPointer() const { return x14_texCoords; }
|
|
|
|
[[nodiscard]] std::vector<zeus::CVector2f>* GetPackedTCPointer() const { return x18_packedTexCoords; }
|
2022-02-03 15:24:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ModelInstance x0_modelInstance;
|
2022-02-05 15:22:30 +00:00
|
|
|
std::vector<TCachedToken<CTexture>>* x1c_textures;
|
2022-02-03 15:24:41 +00:00
|
|
|
zeus::CAABox x20_worldAABB;
|
|
|
|
CCubeSurface* x38_firstUnsortedSurf = nullptr;
|
|
|
|
CCubeSurface* x3c_firstSortedSurf = nullptr;
|
2022-02-25 07:45:25 +00:00
|
|
|
bool x40_24_texturesLoaded : 1 = false;
|
|
|
|
bool x40_25_modelVisible : 1 = false;
|
2022-02-03 15:24:41 +00:00
|
|
|
u8 x41_visorFlags;
|
|
|
|
u32 x44_idx;
|
|
|
|
|
2022-02-01 09:18:42 +00:00
|
|
|
public:
|
2022-02-25 07:45:25 +00:00
|
|
|
CCubeModel(std::vector<CCubeSurface>* surfaces, std::vector<TCachedToken<CTexture>>* textures, u8* materialData,
|
|
|
|
std::vector<zeus::CVector3f>* positions, std::vector<zeus::CColor>* colors,
|
|
|
|
std::vector<zeus::CVector3f>* normals, std::vector<zeus::CVector2f>* texCoords,
|
|
|
|
std::vector<zeus::CVector2f>* packedTexCoords, const zeus::CAABox& aabb, u8 flags, bool b1, u32 idx);
|
2022-02-01 09:18:42 +00:00
|
|
|
|
2022-02-04 08:10:09 +00:00
|
|
|
CCubeMaterial GetMaterialByIndex(u32 idx);
|
2022-02-25 07:45:25 +00:00
|
|
|
bool TryLockTextures();
|
2022-02-01 09:18:42 +00:00
|
|
|
void UnlockTextures();
|
2022-02-25 07:45:25 +00:00
|
|
|
void RemapMaterialData(u8* data, std::vector<TCachedToken<CTexture>>& textures);
|
2022-02-26 07:05:59 +00:00
|
|
|
void Draw(const CModelFlags& flags);
|
|
|
|
void DrawAlpha(const CModelFlags& flags);
|
2022-02-25 07:45:25 +00:00
|
|
|
void DrawFlat(TVectorRef positions, TVectorRef normals, ESurfaceSelection surfaces);
|
|
|
|
void DrawNormal(TVectorRef positions, TVectorRef normals, ESurfaceSelection surfaces);
|
2022-02-26 07:05:59 +00:00
|
|
|
void DrawNormal(const CModelFlags& flags);
|
|
|
|
void DrawSurface(const CCubeSurface& surface, const CModelFlags& flags);
|
2022-02-25 07:45:25 +00:00
|
|
|
void DrawSurfaceWireframe(const CCubeSurface& surface);
|
|
|
|
void SetArraysCurrent();
|
2022-02-26 07:05:59 +00:00
|
|
|
void SetUsingPackedLightmaps(bool v);
|
2022-02-25 07:45:25 +00:00
|
|
|
|
2022-02-26 07:05:59 +00:00
|
|
|
[[nodiscard]] TVectorRef GetPositions() const { return x0_modelInstance.GetVertexPointer(); }
|
|
|
|
[[nodiscard]] TVectorRef GetNormals() const { return x0_modelInstance.GetNormalPointer(); }
|
|
|
|
[[nodiscard]] TCachedToken<CTexture>& GetTexture(u32 idx) const { return x1c_textures->at(idx); }
|
2022-02-25 07:45:25 +00:00
|
|
|
|
2022-02-26 07:05:59 +00:00
|
|
|
static void EnableShadowMaps(const CTexture& shadowTex, const zeus::CTransform& textureProjXf, u8 chan0DisableMask,
|
2022-02-25 07:45:25 +00:00
|
|
|
u8 chan1EnableLightMask);
|
|
|
|
static void DisableShadowMaps();
|
|
|
|
static void MakeTexturesFromMats(const u8* ptr, std::vector<TCachedToken<CTexture>>& texture, IObjectStore* store,
|
|
|
|
bool b1);
|
|
|
|
static void SetDrawingOccluders(bool v);
|
2022-02-26 07:05:59 +00:00
|
|
|
static void SetModelWireframe(bool v);
|
2022-02-25 07:45:25 +00:00
|
|
|
static void SetNewPlayerPositionAndTime(const zeus::CVector3f& pos, const CStopwatch& time);
|
|
|
|
static void SetRenderModelBlack(bool v);
|
2022-02-01 09:18:42 +00:00
|
|
|
|
2022-02-26 07:05:59 +00:00
|
|
|
static bool sRenderModelBlack;
|
|
|
|
static bool sUsingPackedLightmaps;
|
|
|
|
static bool sRenderModelShadow;
|
|
|
|
static const CTexture* sShadowTexture;
|
|
|
|
|
2022-02-25 07:45:25 +00:00
|
|
|
private:
|
2022-02-26 07:05:59 +00:00
|
|
|
void Draw(TVectorRef positions, TVectorRef normals, const CModelFlags& flags);
|
|
|
|
void DrawAlphaSurfaces(const CModelFlags& flags);
|
|
|
|
void DrawNormalSurfaces(const CModelFlags& flags);
|
|
|
|
void DrawSurfaces(const CModelFlags& flags);
|
2022-02-25 07:45:25 +00:00
|
|
|
void SetSkinningArraysCurrent(TVectorRef positions, TVectorRef normals);
|
|
|
|
void SetStaticArraysCurrent();
|
2022-02-04 08:10:09 +00:00
|
|
|
};
|
2022-02-25 07:45:25 +00:00
|
|
|
} // namespace metaforce
|