Implement TglImpl::MeshBuilder::CreateMesh (#635)

* WIP

* Change

* Fix

* Improve match

* Rename class

* Fix function

* Fix annotation

* Fix annotations

* Fix annotation
This commit is contained in:
Christian Semmler
2024-03-08 11:55:25 -05:00
committed by GitHub
parent 53e2353f78
commit 873926afe2
12 changed files with 260 additions and 117 deletions

View File

@@ -94,11 +94,10 @@ Result GroupImpl::Add(const Mesh* pMesh)
}
// FUNCTION: LEGO1 0x100a3450
Result GroupImpl::Remove(const Unk* pUnk)
Result GroupImpl::Remove(const MeshBuilder* pMeshBuilder)
{
const UnkImpl* pUnkImpl = static_cast<const UnkImpl*>(pUnk);
// TODO: Incorrect structure
return ResultVal(m_data->DeleteVisual((IDirect3DRMMesh*) pUnkImpl->ImplementationData()));
const MeshBuilderImpl* pMeshBuilderImpl = static_cast<const MeshBuilderImpl*>(pMeshBuilder);
return ResultVal(m_data->DeleteVisual(pMeshBuilderImpl->ImplementationData()));
}
// FUNCTION: LEGO1 0x100a3480

View File

@@ -34,7 +34,7 @@ class CameraImpl;
class GroupImpl;
class MeshImpl;
class TextureImpl;
class UnkImpl;
class MeshBuilderImpl;
// VTABLE: LEGO1 0x100db910
class RendererImpl : public Renderer {
@@ -62,7 +62,7 @@ public:
Group* CreateGroup(const Group* pParent) override;
// vtable+0x20
Unk* CreateUnk() override;
MeshBuilder* CreateMeshBuilder() override;
Texture* CreateTexture(
int width,
int height,
@@ -273,24 +273,27 @@ public:
// vtable+0x10
Result GetTexture(Texture*&) override;
Result SetTextureMappingMode(ProjectionType) override;
Result SetTextureMappingMode(TextureMappingMode) override;
Result SetShadingModel(ShadingModel) override;
Mesh* DeepClone(Unk*) override;
Mesh* DeepClone(MeshBuilder*) override;
// vtable+0x20
Mesh* ShallowClone(Unk*) override;
Mesh* ShallowClone(MeshBuilder*) override;
struct MeshData {
IDirect3DRMMesh* groupMesh;
D3DRMGROUPINDEX groupIndex;
};
inline MeshData* ImplementationData() const { return m_data; }
typedef MeshData* MeshDataType;
inline const MeshDataType& ImplementationData() const { return m_data; }
inline MeshDataType& ImplementationData() { return m_data; }
friend class RendererImpl;
private:
MeshData* m_data;
MeshDataType m_data;
};
// VTABLE: LEGO1 0x100dba68
@@ -320,7 +323,7 @@ public:
// vtable+0x20
Result Add(const Mesh*) override;
Result Remove(const Group*) override;
Result Remove(const Unk*) override;
Result Remove(const MeshBuilder*) override;
Result RemoveAll() override;
// vtable+0x30
@@ -335,10 +338,10 @@ private:
};
// VTABLE: LEGO1 0x100dbb18
class UnkImpl : public Unk {
class MeshBuilderImpl : public MeshBuilder {
public:
UnkImpl() : m_data(0) {}
~UnkImpl() override
MeshBuilderImpl() : m_data(0) {}
~MeshBuilderImpl() override
{
if (m_data) {
m_data->Release();
@@ -349,7 +352,7 @@ public:
void* ImplementationDataPtr() override;
// vtable+0x08
Tgl::Mesh* CreateMesh(
Mesh* CreateMesh(
unsigned long faceCount,
unsigned long vertexCount,
float (*pPositions)[3],
@@ -357,18 +360,30 @@ public:
float (*pTextureCoordinates)[2],
unsigned long (*pFaceIndices)[3],
unsigned long (*pTextureIndices)[3],
Tgl::ShadingModel shadingModel
ShadingModel shadingModel
) override;
Result GetBoundingBox(float min[3], float max[3]) override;
// vtable+0x10
Unk* Clone() override;
MeshBuilder* Clone() override;
inline IDirect3DRMMesh* ImplementationData() const { return m_data; }
friend class RendererImpl;
private:
inline Result CreateMeshImpl(
MeshImpl* pMeshImpl,
unsigned long faceCount,
unsigned long vertexCount,
float (*pPositions)[3],
float (*pNormals)[3],
float (*pTextureCoordinates)[2],
unsigned long (*pFaceIndices)[3],
unsigned long (*pTextureIndices)[3],
ShadingModel shadingModel
);
IDirect3DRMMesh* m_data;
};
@@ -514,7 +529,7 @@ inline D3DRMMATRIX4D* Translate(FloatMatrix4& tglMatrix4x4, D3DRMMATRIX4D& rD3DR
// TglImpl::LightImpl::`scalar deleting destructor'
// SYNTHETIC: LEGO1 0x100a2720
// TglImpl::UnkImpl::`scalar deleting destructor'
// TglImpl::MeshBuilderImpl::`scalar deleting destructor'
// SYNTHETIC: LEGO1 0x100a2800
// TglImpl::TextureImpl::`scalar deleting destructor'

View File

@@ -38,9 +38,9 @@ Result MeshImpl::SetTexture(const Texture* pTexture)
}
// FUNCTION: LEGO1 0x100a3f80
Result MeshImpl::SetTextureMappingMode(ProjectionType projType)
Result MeshImpl::SetTextureMappingMode(TextureMappingMode mode)
{
if (projType == Perspective) {
if (mode == PerspectiveCorrect) {
return ResultVal(m_data->groupMesh->SetGroupMapping(m_data->groupIndex, D3DRMMAP_PERSPCORRECT));
}
else {
@@ -73,7 +73,7 @@ Result MeshImpl::SetShadingModel(ShadingModel model)
}
// FUNCTION: LEGO1 0x100a4030
Mesh* MeshImpl::DeepClone(Unk* pUnk)
Mesh* MeshImpl::DeepClone(MeshBuilder* pMeshBuilder)
{
// Create group
MeshImpl* newMesh = new MeshImpl();
@@ -96,7 +96,7 @@ Mesh* MeshImpl::DeepClone(Unk* pUnk)
D3DCOLOR color = m_data->groupMesh->GetGroupColor(m_data->groupIndex);
// Push information to new group
UnkImpl* target = static_cast<UnkImpl*>(pUnk);
MeshBuilderImpl* target = static_cast<MeshBuilderImpl*>(pMeshBuilder);
D3DRMGROUPINDEX index;
target->ImplementationData()->AddGroup(vcount, fcount, vperface, faceBuffer, &index);
newMesh->m_data->groupIndex = index;
@@ -118,14 +118,14 @@ Mesh* MeshImpl::DeepClone(Unk* pUnk)
}
// FUNCTION: LEGO1 0x100a4240
Mesh* MeshImpl::ShallowClone(Unk* pUnk)
Mesh* MeshImpl::ShallowClone(MeshBuilder* pMeshBuilder)
{
MeshImpl* newGroup = new MeshImpl();
MeshData* newData = new MeshData();
newGroup->m_data = newData;
if (newData) {
newData->groupIndex = m_data->groupIndex;
newData->groupMesh = static_cast<UnkImpl*>(pUnk)->ImplementationData();
newData->groupMesh = static_cast<MeshBuilderImpl*>(pMeshBuilder)->ImplementationData();
}
else {
delete newGroup;

View File

@@ -0,0 +1,187 @@
#include "impl.h"
using namespace TglImpl;
DECOMP_SIZE_ASSERT(MeshBuilder, 0x04);
DECOMP_SIZE_ASSERT(MeshBuilderImpl, 0x08);
// FUNCTION: LEGO1 0x100a3830
void* MeshBuilderImpl::ImplementationDataPtr()
{
return reinterpret_cast<void*>(&m_data);
}
// FUNCTION: LEGO1 0x100a3840
Mesh* MeshBuilderImpl::CreateMesh(
unsigned long faceCount,
unsigned long vertexCount,
float (*pPositions)[3],
float (*pNormals)[3],
float (*pTextureCoordinates)[2],
unsigned long (*pFaceIndices)[3],
unsigned long (*pTextureIndices)[3],
ShadingModel shadingModel
)
{
MeshImpl* pMeshImpl = new MeshImpl;
if (CreateMeshImpl(
pMeshImpl,
faceCount,
vertexCount,
pPositions,
pNormals,
pTextureCoordinates,
pFaceIndices,
pTextureIndices,
shadingModel
) == Error) {
delete pMeshImpl;
pMeshImpl = NULL;
}
return pMeshImpl;
}
inline Result MeshSetTextureMappingMode(MeshImpl::MeshData* pMesh, TextureMappingMode mode)
{
if (mode == PerspectiveCorrect) {
return ResultVal(pMesh->groupMesh->SetGroupMapping(pMesh->groupIndex, D3DRMMAP_PERSPCORRECT));
}
else {
return ResultVal(pMesh->groupMesh->SetGroupMapping(pMesh->groupIndex, 0));
}
}
inline Result CreateMesh(
IDirect3DRMMesh* pD3DRM,
unsigned long faceCount,
unsigned long vertexCount,
float (*pPositions)[3],
float (*pNormals)[3],
float (*pTextureCoordinates)[2],
unsigned long (*pFaceIndices)[3],
unsigned long (*pTextureIndices)[3],
ShadingModel shadingModel,
MeshImpl::MeshDataType& rpMesh
)
{
unsigned long* faceIndices = (unsigned long*) pFaceIndices;
D3DRMGROUPINDEX groupIndex = 0;
int count = faceCount * 3;
int index = 0;
unsigned int* fData = new unsigned int[count];
D3DRMVERTEX* vertices = new D3DRMVERTEX[vertexCount];
memset(vertices, 0, sizeof(*vertices) * vertexCount);
rpMesh = new MeshImpl::MeshData;
rpMesh->groupMesh = pD3DRM;
for (int i = 0; i < count; i++) {
if ((*((unsigned short*) &faceIndices[i] + 1) >> 0x0f) & 0x01) {
unsigned long j = *(unsigned short*) &faceIndices[i];
vertices[index].position.x = pPositions[j][0];
vertices[index].position.y = pPositions[j][1];
vertices[index].position.z = pPositions[j][2];
j = *((unsigned short*) &faceIndices[i] + 1) & MAXSHORT;
vertices[index].normal.x = pNormals[j][0];
vertices[index].normal.y = pNormals[j][1];
vertices[index].normal.z = pNormals[j][2];
if (pTextureIndices != NULL && pTextureCoordinates != NULL) {
j = ((unsigned long*) pTextureIndices)[i];
vertices[index].tu = pTextureCoordinates[j][0];
vertices[index].tv = pTextureCoordinates[j][1];
}
fData[i] = index;
index++;
}
else {
fData[i] = *(unsigned short*) &faceIndices[i];
}
}
Result result;
result = ResultVal(pD3DRM->AddGroup(vertexCount, faceCount, 3, fData, &groupIndex));
if (Succeeded(result)) {
rpMesh->groupIndex = groupIndex;
result = ResultVal(pD3DRM->SetVertices(groupIndex, 0, vertexCount, vertices));
}
if (!Succeeded(result)) {
if (rpMesh) {
delete rpMesh;
}
rpMesh = NULL;
}
else {
result = MeshSetTextureMappingMode(rpMesh, PerspectiveCorrect);
}
if (fData != NULL) {
delete[] fData;
}
if (vertices != NULL) {
delete[] vertices;
}
return result;
}
inline Result MeshBuilderImpl::CreateMeshImpl(
MeshImpl* pMeshImpl,
unsigned long faceCount,
unsigned long vertexCount,
float (*pPositions)[3],
float (*pNormals)[3],
float (*pTextureCoordinates)[2],
unsigned long (*pFaceIndices)[3],
unsigned long (*pTextureIndices)[3],
ShadingModel shadingModel
)
{
return ::CreateMesh(
m_data,
faceCount,
vertexCount,
pPositions,
pNormals,
pTextureCoordinates,
pFaceIndices,
pTextureIndices,
shadingModel,
pMeshImpl->ImplementationData()
);
}
// FUNCTION: LEGO1 0x100a3ae0
Result MeshBuilderImpl::GetBoundingBox(float min[3], float max[3])
{
D3DRMBOX box;
Result result = ResultVal(m_data->GetBox(&box));
if (result == Success) {
min[0] = box.min.x;
min[1] = box.min.y;
min[2] = box.min.z;
max[0] = box.max.x;
max[1] = box.max.y;
max[2] = box.max.z;
}
return result;
}
// FUNCTION: LEGO1 0x100a3b40
MeshBuilder* MeshBuilderImpl::Clone()
{
MeshBuilderImpl* mesh = new MeshBuilderImpl();
int ret = m_data->Clone(0, IID_IDirect3DRMMeshBuilder, (void**) &mesh->m_data);
if (ret < 0) {
delete mesh;
mesh = NULL;
}
return mesh;
}

View File

@@ -209,20 +209,14 @@ Light* RendererImpl::CreateLight(LightType type, float r, float g, float b)
}
// FUNCTION: LEGO1 0x100a1e90
Unk* RendererImpl::CreateUnk()
MeshBuilder* RendererImpl::CreateMeshBuilder()
{
// Note: I'm fairly certain that Unknown is not what Tgl calls a
// "Mesh", because the methods on Mesh in the Tgl leak line up much
// more closely with a different vtable than the one assigned in
// this method (meaning this method is not creating a Mesh).
// Maybe this method is something like CreateMeshBuilder where the
// Mesh data type in the Tgl leak was split into builder/result?
UnkImpl* unknown = new UnkImpl();
if (FAILED(m_data->CreateMesh(&unknown->m_data))) {
delete unknown;
unknown = NULL;
MeshBuilderImpl* meshBuilder = new MeshBuilderImpl();
if (FAILED(m_data->CreateMesh(&meshBuilder->m_data))) {
delete meshBuilder;
meshBuilder = NULL;
}
return unknown;
return meshBuilder;
}
inline Result RendererCreateTexture(

View File

@@ -1,55 +0,0 @@
#include "impl.h"
using namespace TglImpl;
DECOMP_SIZE_ASSERT(Unk, 0x04);
DECOMP_SIZE_ASSERT(UnkImpl, 0x08);
// FUNCTION: LEGO1 0x100a3830
void* UnkImpl::ImplementationDataPtr()
{
return reinterpret_cast<void*>(&m_data);
}
// STUB: LEGO1 0x100a3840
Tgl::Mesh* UnkImpl::CreateMesh(
unsigned long faceCount,
unsigned long vertexCount,
float (*pPositions)[3],
float (*pNormals)[3],
float (*pTextureCoordinates)[2],
unsigned long (*pFaceIndices)[3],
unsigned long (*pTextureIndices)[3],
Tgl::ShadingModel shadingModel
)
{
return NULL;
}
// FUNCTION: LEGO1 0x100a3ae0
Result UnkImpl::GetBoundingBox(float min[3], float max[3])
{
D3DRMBOX box;
Result result = ResultVal(m_data->GetBox(&box));
if (result == Success) {
min[0] = box.min.x;
min[1] = box.min.y;
min[2] = box.min.z;
max[0] = box.max.x;
max[1] = box.max.y;
max[2] = box.max.z;
}
return result;
}
// FUNCTION: LEGO1 0x100a3b40
Unk* UnkImpl::Clone()
{
UnkImpl* mesh = new UnkImpl();
int ret = m_data->Clone(0, IID_IDirect3DRMMeshBuilder, (void**) &mesh->m_data);
if (ret < 0) {
delete mesh;
mesh = NULL;
}
return mesh;
}