This commit is contained in:
Christian Semmler 2024-03-08 10:32:51 -05:00
parent 53e2353f78
commit 96cd48d3e0
4 changed files with 163 additions and 12 deletions

View File

@ -97,8 +97,7 @@ Result GroupImpl::Add(const Mesh* pMesh)
Result GroupImpl::Remove(const Unk* pUnk) Result GroupImpl::Remove(const Unk* pUnk)
{ {
const UnkImpl* pUnkImpl = static_cast<const UnkImpl*>(pUnk); const UnkImpl* pUnkImpl = static_cast<const UnkImpl*>(pUnk);
// TODO: Incorrect structure return ResultVal(m_data->DeleteVisual(pUnkImpl->ImplementationData()));
return ResultVal(m_data->DeleteVisual((IDirect3DRMMesh*) pUnkImpl->ImplementationData()));
} }
// FUNCTION: LEGO1 0x100a3480 // FUNCTION: LEGO1 0x100a3480

View File

@ -285,12 +285,15 @@ class MeshImpl : public Mesh {
D3DRMGROUPINDEX groupIndex; 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; friend class RendererImpl;
private: private:
MeshData* m_data; MeshDataType m_data;
}; };
// VTABLE: LEGO1 0x100dba68 // VTABLE: LEGO1 0x100dba68
@ -349,7 +352,7 @@ class UnkImpl : public Unk {
void* ImplementationDataPtr() override; void* ImplementationDataPtr() override;
// vtable+0x08 // vtable+0x08
Tgl::Mesh* CreateMesh( Mesh* CreateMesh(
unsigned long faceCount, unsigned long faceCount,
unsigned long vertexCount, unsigned long vertexCount,
float (*pPositions)[3], float (*pPositions)[3],
@ -357,7 +360,7 @@ class UnkImpl : public Unk {
float (*pTextureCoordinates)[2], float (*pTextureCoordinates)[2],
unsigned long (*pFaceIndices)[3], unsigned long (*pFaceIndices)[3],
unsigned long (*pTextureIndices)[3], unsigned long (*pTextureIndices)[3],
Tgl::ShadingModel shadingModel ShadingModel shadingModel
) override; ) override;
Result GetBoundingBox(float min[3], float max[3]) override; Result GetBoundingBox(float min[3], float max[3]) override;
@ -369,6 +372,18 @@ class UnkImpl : public Unk {
friend class RendererImpl; friend class RendererImpl;
private: private:
inline Result CreateMeshImpl(
MeshImpl* mesh,
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; IDirect3DRMMesh* m_data;
}; };

View File

@ -11,8 +11,8 @@ void* UnkImpl::ImplementationDataPtr()
return reinterpret_cast<void*>(&m_data); return reinterpret_cast<void*>(&m_data);
} }
// STUB: LEGO1 0x100a3840 // FUNCTION: LEGO1 0x100a3840
Tgl::Mesh* UnkImpl::CreateMesh( Mesh* UnkImpl::CreateMesh(
unsigned long faceCount, unsigned long faceCount,
unsigned long vertexCount, unsigned long vertexCount,
float (*pPositions)[3], float (*pPositions)[3],
@ -20,10 +20,144 @@ Tgl::Mesh* UnkImpl::CreateMesh(
float (*pTextureCoordinates)[2], float (*pTextureCoordinates)[2],
unsigned long (*pFaceIndices)[3], unsigned long (*pFaceIndices)[3],
unsigned long (*pTextureIndices)[3], unsigned long (*pTextureIndices)[3],
Tgl::ShadingModel shadingModel ShadingModel shadingModel
) )
{ {
return NULL; MeshImpl* mesh = new MeshImpl();
if (CreateMeshImpl(
mesh,
faceCount,
vertexCount,
pPositions,
pNormals,
pTextureCoordinates,
pFaceIndices,
pTextureIndices,
shadingModel
) == Error) {
delete mesh;
mesh = NULL;
}
return mesh;
}
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 char*) &faceIndices[i] + 3) & 0x80) {
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)) {
delete rpMesh->groupMesh;
rpMesh->groupMesh = NULL;
}
else {
result = MeshSetTextureMappingMode(rpMesh, PerspectiveCorrect);
}
if (fData != NULL) {
delete[] fData;
}
if (vertices != NULL) {
delete[] vertices;
}
if (!Succeeded(result)) {
delete rpMesh;
}
return result;
}
inline Result UnkImpl::CreateMeshImpl(
MeshImpl* mesh,
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,
mesh->ImplementationData()
);
} }
// FUNCTION: LEGO1 0x100a3ae0 // FUNCTION: LEGO1 0x100a3ae0

View File

@ -269,6 +269,9 @@ class Light : public Object {
// VTABLE: LEGO1 0x100dbbb0 // VTABLE: LEGO1 0x100dbbb0
class Mesh : public Object { class Mesh : public Object {
public: public:
// SYNTHETIC: LEGO1 0x100a3e10
// Tgl::Mesh::~Mesh
virtual Result SetColor(float r, float g, float b, float a) = 0; virtual Result SetColor(float r, float g, float b, float a) = 0;
virtual Result SetTexture(const Texture*) = 0; virtual Result SetTexture(const Texture*) = 0;
virtual Result GetTexture(Texture*&) = 0; virtual Result GetTexture(Texture*&) = 0;
@ -317,7 +320,7 @@ class Group : public Object {
// VTABLE: LEGO1 0x100dbb30 // VTABLE: LEGO1 0x100dbb30
class Unk : public Object { class Unk : public Object {
public: public:
virtual Tgl::Mesh* CreateMesh( virtual Mesh* CreateMesh(
unsigned long faceCount, unsigned long faceCount,
unsigned long vertexCount, unsigned long vertexCount,
float (*pPositions)[3], float (*pPositions)[3],
@ -325,7 +328,7 @@ class Unk : public Object {
float (*pTextureCoordinates)[2], float (*pTextureCoordinates)[2],
unsigned long (*pFaceIndices)[3], unsigned long (*pFaceIndices)[3],
unsigned long (*pTextureIndices)[3], unsigned long (*pTextureIndices)[3],
Tgl::ShadingModel shadingModel ShadingModel shadingModel
) = 0; ) = 0;
virtual Result GetBoundingBox(float min[3], float max[3]) = 0; virtual Result GetBoundingBox(float min[3], float max[3]) = 0;
virtual Unk* Clone() = 0; virtual Unk* Clone() = 0;