From 248b7e73859cdbb3fa96ae3a1581713cdac4e09c Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Thu, 14 Sep 2023 22:08:40 +0800 Subject: [PATCH] finish material --- LibCmo/CK2/CKGlobals.cpp | 2 ++ LibCmo/CK2/ObjImpls/CKMaterial.cpp | 38 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/LibCmo/CK2/CKGlobals.cpp b/LibCmo/CK2/CKGlobals.cpp index 2d5c65f..8fe0ceb 100644 --- a/LibCmo/CK2/CKGlobals.cpp +++ b/LibCmo/CK2/CKGlobals.cpp @@ -18,6 +18,7 @@ #include "ObjImpls/CK3dEntity.hpp" #include "ObjImpls/CK3dObject.hpp" #include "ObjImpls/CKTexture.hpp" +#include "ObjImpls/CKMaterial.hpp" namespace LibCmo::CK2 { @@ -272,6 +273,7 @@ CKClassRegister(cid, parentCid, \ EasyClassReg(ObjImpls::CK3dEntity, CK_CLASSID::CKCID_3DENTITY, CK_CLASSID::CKCID_RENDEROBJECT, "3D Entity"); EasyClassReg(ObjImpls::CK3dObject, CK_CLASSID::CKCID_3DOBJECT, CK_CLASSID::CKCID_3DENTITY, "3D Object"); EasyClassReg(ObjImpls::CKTexture, CK_CLASSID::CKCID_TEXTURE, CK_CLASSID::CKCID_BEOBJECT, "Texture"); + EasyClassReg(ObjImpls::CKMaterial, CK_CLASSID::CKCID_MATERIAL, CK_CLASSID::CKCID_BEOBJECT, "Material"); #undef EasyClassReg diff --git a/LibCmo/CK2/ObjImpls/CKMaterial.cpp b/LibCmo/CK2/ObjImpls/CKMaterial.cpp index e8322f8..6cb5b22 100644 --- a/LibCmo/CK2/ObjImpls/CKMaterial.cpp +++ b/LibCmo/CK2/ObjImpls/CKMaterial.cpp @@ -122,6 +122,44 @@ namespace LibCmo::CK2::ObjImpls { } } + // extra texture data + if (chunk->SeekIdentifier(CK_STATESAVEFLAGS_MATERIAL::CK_STATESAVE_MATDATA2)) { + // read 3 extra texture + CK_ID objid; + CKObject* tex = nullptr; + + for (size_t i = 1; i < 4; ++i) { + chunk->ReadObjectID(objid); + tex = m_Context->GetObject(objid); + if (tex != nullptr && tex->GetClassID() == CK_CLASSID::CKCID_TEXTURE) { + m_Textures[i] = static_cast(tex); + } + } + } + + // single effect + if (chunk->SeekIdentifier(CK_STATESAVEFLAGS_MATERIAL::CK_STATESAVE_MATDATA3)) { + CKDWORD data; + chunk->ReadStruct(data); + m_Effect = static_cast(data); + } + + // effect with parameter + if (chunk->SeekIdentifier(CK_STATESAVEFLAGS_MATERIAL::CK_STATESAVE_MATDATA5)) { + // MARK: i do not support CKParameter anymore. + // so we downgrade it into single effect type. + // hope this convertion will not break anything. + + // drop parameter id. + CK_ID paramid; + chunk->ReadObjectID(paramid); + + // read effect self + CKDWORD data; + chunk->ReadStruct(data); + m_Effect = static_cast(data); + } + return true; }