2018-10-07 03:42:33 +00:00
|
|
|
#pragma once
|
2016-04-05 01:51:25 +00:00
|
|
|
|
2019-09-28 02:53:03 +00:00
|
|
|
#include <memory>
|
2019-06-12 02:05:17 +00:00
|
|
|
#include <optional>
|
2019-09-28 02:53:03 +00:00
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "Runtime/CToken.hpp"
|
2020-03-26 05:10:51 +00:00
|
|
|
#include "Runtime/Character/CSkinRules.hpp"
|
2019-09-28 02:53:03 +00:00
|
|
|
#include "Runtime/Graphics/CModel.hpp"
|
|
|
|
|
|
|
|
#include <zeus/CVector3f.hpp>
|
2016-04-05 01:51:25 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2016-04-05 01:51:25 +00:00
|
|
|
class CCharLayoutInfo;
|
2019-09-28 02:53:03 +00:00
|
|
|
class CModel;
|
2016-04-05 01:51:25 +00:00
|
|
|
class CPoseAsTransforms;
|
|
|
|
class CVertexMorphEffect;
|
|
|
|
class IObjectStore;
|
|
|
|
|
2022-03-10 06:33:17 +00:00
|
|
|
// Originally vert + normal workspaces were allocated together, but here separated for ease of use
|
|
|
|
struct SSkinningWorkspace {
|
|
|
|
std::vector<zeus::CVector3f> m_vertexWorkspace;
|
|
|
|
std::vector<zeus::CVector3f> m_normalWorkspace;
|
|
|
|
|
|
|
|
SSkinningWorkspace(const CSkinRules& rules) { Reset(rules); }
|
|
|
|
void Reset(const CSkinRules& rules) {
|
|
|
|
m_vertexWorkspace.clear();
|
|
|
|
m_normalWorkspace.clear();
|
|
|
|
m_vertexWorkspace.reserve(rules.GetVertexCount());
|
|
|
|
m_normalWorkspace.reserve(rules.GetNormalCount());
|
|
|
|
}
|
2022-08-09 06:10:51 +00:00
|
|
|
void Clear() {
|
|
|
|
m_vertexWorkspace.clear();
|
|
|
|
m_normalWorkspace.clear();
|
|
|
|
}
|
2022-03-10 06:33:17 +00:00
|
|
|
[[nodiscard]] bool IsEmpty() const { return m_vertexWorkspace.empty() || m_normalWorkspace.empty(); }
|
|
|
|
};
|
|
|
|
|
2022-02-25 07:45:25 +00:00
|
|
|
// Lambda instead of userdata pointer
|
2022-03-10 06:33:17 +00:00
|
|
|
using FCustomDraw = std::function<void(TConstVectorRef positions, TConstVectorRef normals)>;
|
|
|
|
using FPointGenerator = std::function<void(const SSkinningWorkspace& workspace)>;
|
2022-02-25 07:45:25 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
class CSkinnedModel {
|
|
|
|
TLockedToken<CModel> x4_model;
|
|
|
|
TLockedToken<CSkinRules> x10_skinRules;
|
|
|
|
TLockedToken<CCharLayoutInfo> x1c_layoutInfo;
|
2022-03-10 06:33:17 +00:00
|
|
|
// rstl::auto_ptr<float[]> x24_vertWorkspace;
|
|
|
|
// rstl::auto_ptr<float[]> x2c_normalWorkspace;
|
|
|
|
SSkinningWorkspace m_workspace;
|
2022-02-25 07:45:25 +00:00
|
|
|
bool x34_owned = true;
|
|
|
|
bool x35_disableWorkspaces = false;
|
2017-03-26 05:53:04 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
public:
|
2022-02-25 07:45:25 +00:00
|
|
|
enum class EDataOwnership { Unowned, Owned };
|
|
|
|
CSkinnedModel(const TLockedToken<CModel>& model, const TLockedToken<CSkinRules>& skinRules,
|
|
|
|
const TLockedToken<CCharLayoutInfo>& layoutInfo /*, EDataOwnership ownership*/);
|
|
|
|
CSkinnedModel(IObjectStore& store, CAssetId model, CAssetId skinRules, CAssetId layoutInfo);
|
2022-03-16 05:21:01 +00:00
|
|
|
virtual ~CSkinnedModel() = default;
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2022-02-25 07:45:25 +00:00
|
|
|
TLockedToken<CModel>& GetModel() { return x4_model; }
|
2018-12-08 05:30:43 +00:00
|
|
|
const TLockedToken<CModel>& GetModel() const { return x4_model; }
|
|
|
|
const TLockedToken<CSkinRules>& GetSkinRules() const { return x10_skinRules; }
|
2018-12-31 08:37:52 +00:00
|
|
|
void SetLayoutInfo(const TLockedToken<CCharLayoutInfo>& inf) { x1c_layoutInfo = inf; }
|
2018-12-08 05:30:43 +00:00
|
|
|
const TLockedToken<CCharLayoutInfo>& GetLayoutInfo() const { return x1c_layoutInfo; }
|
|
|
|
|
2022-03-10 06:33:17 +00:00
|
|
|
void AllocateStorage();
|
2022-03-10 23:56:50 +00:00
|
|
|
// Metaforce addition: Originally morphEffect is rstl::optional_object<CVertexMorphEffect>*
|
|
|
|
// This prevents constructing it as a reference to the held pointer in CPatterned, thus in
|
|
|
|
// retail it's copied in every invocation of RenderIceModelWithFlags.
|
|
|
|
void Calculate(const CPoseAsTransforms& pose, CVertexMorphEffect* morphEffect, TConstVectorRef averagedNormals,
|
|
|
|
SSkinningWorkspace* workspace);
|
2022-03-10 06:33:17 +00:00
|
|
|
void Draw(TConstVectorRef verts, TConstVectorRef normals, const CModelFlags& drawFlags);
|
2022-02-25 07:45:25 +00:00
|
|
|
void Draw(const CModelFlags& drawFlags);
|
|
|
|
void DoDrawCallback(const FCustomDraw& func) const;
|
2022-08-09 06:10:51 +00:00
|
|
|
void CalculateDefault();
|
|
|
|
// Originally returns cloned vertex workspace, with arg for cloned normal workspace
|
|
|
|
SSkinningWorkspace CloneWorkspace();
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2022-03-10 06:33:17 +00:00
|
|
|
static void SetPointGeneratorFunc(FPointGenerator func) { g_PointGenFunc = std::move(func); }
|
2018-12-08 05:30:43 +00:00
|
|
|
static void ClearPointGeneratorFunc() { g_PointGenFunc = nullptr; }
|
|
|
|
static FPointGenerator g_PointGenFunc;
|
2016-04-05 01:51:25 +00:00
|
|
|
};
|
|
|
|
|
2022-03-10 23:56:50 +00:00
|
|
|
class CSkinnedModelWithAvgNormals : public CSkinnedModel {
|
|
|
|
std::vector<zeus::CVector3f> x40_averagedNormals; // was rstl::auto_ptr<float[]>
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2016-04-15 03:02:21 +00:00
|
|
|
public:
|
2022-03-10 23:56:50 +00:00
|
|
|
CSkinnedModelWithAvgNormals(IObjectStore& store, CAssetId model, CAssetId skinRules, CAssetId layoutInfo);
|
2022-03-16 05:21:01 +00:00
|
|
|
~CSkinnedModelWithAvgNormals() override = default;
|
|
|
|
|
2022-03-10 23:56:50 +00:00
|
|
|
TConstVectorRef GetAveragedNormals() const { return &x40_averagedNormals; }
|
2016-04-15 03:02:21 +00:00
|
|
|
};
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|