diff --git a/LEGO1/tgl/d3drm/group.cpp b/LEGO1/tgl/d3drm/group.cpp index 74c988f8..a9df8fd6 100644 --- a/LEGO1/tgl/d3drm/group.cpp +++ b/LEGO1/tgl/d3drm/group.cpp @@ -86,11 +86,10 @@ Result GroupImpl::Add(const Group* pGroup) } // FUNCTION: LEGO1 0x100a3430 -Result GroupImpl::Add(const Mesh* pMesh) +Result GroupImpl::Add(const MeshBuilder* pMeshBuilder) { - const MeshImpl* pMeshImpl = static_cast<const MeshImpl*>(pMesh); - // TODO: Incorrect structure - return ResultVal(m_data->AddVisual((IDirect3DRMMesh*) pMeshImpl->ImplementationData())); + const MeshBuilderImpl* pMeshBuilderImpl = static_cast<const MeshBuilderImpl*>(pMeshBuilder); + return ResultVal(m_data->AddVisual(pMeshBuilderImpl->ImplementationData())); } // FUNCTION: LEGO1 0x100a3450 diff --git a/LEGO1/tgl/d3drm/impl.h b/LEGO1/tgl/d3drm/impl.h index 6fcce72f..480f9266 100644 --- a/LEGO1/tgl/d3drm/impl.h +++ b/LEGO1/tgl/d3drm/impl.h @@ -321,7 +321,7 @@ public: Result Add(const Group*) override; // vtable+0x20 - Result Add(const Mesh*) override; + Result Add(const MeshBuilder*) override; Result Remove(const Group*) override; Result Remove(const MeshBuilder*) override; Result RemoveAll() override; diff --git a/LEGO1/tgl/tgl.h b/LEGO1/tgl/tgl.h index 4a087c14..42f5d398 100644 --- a/LEGO1/tgl/tgl.h +++ b/LEGO1/tgl/tgl.h @@ -298,7 +298,7 @@ public: virtual Result GetTexture(Texture*&) = 0; virtual Result SetMaterialMode(MaterialMode) = 0; virtual Result Add(const Group*) = 0; - virtual Result Add(const Mesh*) = 0; + virtual Result Add(const MeshBuilder*) = 0; virtual Result Remove(const Group*) = 0; virtual Result Remove(const MeshBuilder*) = 0; virtual Result RemoveAll() = 0; diff --git a/LEGO1/viewmanager/viewlod.h b/LEGO1/viewmanager/viewlod.h index a9aa9ac9..7bf68b52 100644 --- a/LEGO1/viewmanager/viewlod.h +++ b/LEGO1/viewmanager/viewlod.h @@ -28,6 +28,7 @@ public: Tgl::MeshBuilder* GetMeshBuilder() { return m_meshBuilder; } const Tgl::MeshBuilder* GetMeshBuilder() const { return m_meshBuilder; } + undefined4 GetUnknown0x08() { return m_unk0x08; } unsigned char GetUnknown0x08Test4() { return m_unk0x08 & 0xffffff04; } unsigned char GetUnknown0x08Test8() { return m_unk0x08 & 0xffffff08; } diff --git a/LEGO1/viewmanager/viewmanager.cpp b/LEGO1/viewmanager/viewmanager.cpp index fb235a47..2ed3b448 100644 --- a/LEGO1/viewmanager/viewmanager.cpp +++ b/LEGO1/viewmanager/viewmanager.cpp @@ -24,6 +24,7 @@ float g_unk0x1010105c = 0.000125F; // GLOBAL: LEGO1 0x10101060 float g_elapsedSeconds = 0; +inline void SetAppData(ViewROI* p_roi, DWORD data); inline undefined4 GetD3DRM(IDirect3DRM2*& d3drm, Tgl::Renderer* pRenderer); inline undefined4 GetFrame(IDirect3DRMFrame2*& frame, Tgl::Group* scene); @@ -106,10 +107,57 @@ void ViewManager::RemoveAll(ViewROI* p_roi) } } -// STUB: LEGO1 0x100a65b0 +// FUNCTION: LEGO1 0x100a65b0 void ViewManager::FUN_100a65b0(ViewROI* p_roi, int p_und) { - // TODO + if (p_roi->GetLODCount() <= p_und) { + p_und = p_roi->GetLODCount() - 1; + } + + int unk0xe0 = p_roi->GetUnknown0xe0(); + + if (unk0xe0 == p_und) { + return; + } + + Tgl::Group* group = p_roi->GetGeometry(); + Tgl::MeshBuilder* meshBuilder; + ViewLOD* lod; + + if (unk0xe0 < 0) { + lod = (ViewLOD*) p_roi->GetLOD(p_und); + + if (lod->GetUnknown0x08() & ViewLOD::c_bit4) { + scene->Add((Tgl::MeshBuilder*) group); + SetAppData(p_roi, (DWORD) p_roi); + } + } + else { + lod = (ViewLOD*) p_roi->GetLOD(unk0xe0); + + if (lod != NULL) { + meshBuilder = lod->GetMeshBuilder(); + + if (meshBuilder != NULL) { + group->Remove(meshBuilder); + } + } + + lod = (ViewLOD*) p_roi->GetLOD(p_und); + } + + if (lod->GetUnknown0x08() & ViewLOD::c_bit4) { + meshBuilder = lod->GetMeshBuilder(); + + if (meshBuilder != NULL) { + group->Add(meshBuilder); + SetAppData(p_roi, (DWORD) p_roi); + p_roi->SetUnknown0xe0(p_und); + return; + } + } + + p_roi->SetUnknown0xe0(-1); } // FUNCTION: LEGO1 0x100a66a0 @@ -399,6 +447,15 @@ ViewROI* ViewManager::Pick(Tgl::View* p_view, unsigned long x, unsigned long y) return NULL; } +inline void SetAppData(ViewROI* p_roi, DWORD data) +{ + IDirect3DRMFrame2* frame = NULL; + + if (GetFrame(frame, p_roi->GetGeometry()) == 0) { + frame->SetAppData(data); + } +} + inline undefined4 GetD3DRM(IDirect3DRM2*& d3drm, Tgl::Renderer* pRenderer) { d3drm = ((TglImpl::RendererImpl*) pRenderer)->ImplementationData();