2023-09-21 13:47:30 +08:00
|
|
|
#include "BMExports.hpp"
|
2023-09-23 15:55:57 +08:00
|
|
|
#include <IronPad.hpp>
|
|
|
|
#include <set>
|
2023-10-03 21:33:00 +08:00
|
|
|
#include <type_traits>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#pragma region Help & Save Functions
|
2023-09-23 15:55:57 +08:00
|
|
|
|
2023-10-07 22:33:55 +08:00
|
|
|
static constexpr const LibCmo::CK2::CK_ID INVALID_CKID = 0;
|
|
|
|
static LibCmo::CK2::CK_ID SafeGetID(LibCmo::CK2::ObjImpls::CKObject* obj) {
|
|
|
|
if (obj == nullptr) return INVALID_CKID;
|
|
|
|
else return obj->GetID();
|
|
|
|
}
|
|
|
|
|
2023-10-02 20:54:31 +08:00
|
|
|
static bool g_IsInited = false;
|
2023-09-23 15:55:57 +08:00
|
|
|
static std::set<BMap::BMFile*> g_AllBMFiles = std::set<BMap::BMFile*>();
|
2023-10-02 20:54:31 +08:00
|
|
|
static std::set<BMap::BMMeshTransition*> g_AllBMMeshTrans = std::set<BMap::BMMeshTransition*>();
|
2023-09-21 13:47:30 +08:00
|
|
|
|
2023-10-03 21:33:00 +08:00
|
|
|
bool CheckInited() {
|
|
|
|
return g_IsInited;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CheckBMFile(BMap::BMFile* possible_bmfile) {
|
|
|
|
return (g_IsInited && possible_bmfile != nullptr && g_AllBMFiles.contains(possible_bmfile));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CheckBMMeshTrans(BMap::BMMeshTransition* possible_trans) {
|
|
|
|
return (g_IsInited && possible_trans != nullptr && g_AllBMMeshTrans.contains(possible_trans));
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Ty, std::enable_if_t<std::is_pointer_v<_Ty>, int> = 0>
|
2023-10-07 22:33:55 +08:00
|
|
|
_Ty CheckGeneralObject(BMap::BMFile* possible_bmfile, LibCmo::CK2::CK_ID possible_id, LibCmo::CK2::CK_CLASSID expected_cid) {
|
2023-10-03 21:33:00 +08:00
|
|
|
// check bm file self.
|
|
|
|
if (!CheckBMFile(possible_bmfile)) return nullptr;
|
|
|
|
// check id
|
|
|
|
LibCmo::CK2::ObjImpls::CKObject* obj = possible_bmfile->GetObjectPtr(possible_id);
|
|
|
|
// check id validation and class id
|
|
|
|
if (obj == nullptr || LibCmo::CK2::CKIsChildClassOf(obj->GetClassID(), expected_cid)) return nullptr;
|
|
|
|
|
|
|
|
return static_cast<_Ty>(obj);
|
|
|
|
}
|
|
|
|
|
2023-10-07 22:33:55 +08:00
|
|
|
#define CheckCKObject(bmfile, objid) CheckGeneralObject<LibCmo::CK2::ObjImpls::CKObject*>(bmfile, objid, LibCmo::CK2::CK_CLASSID::CKCID_OBJECT)
|
|
|
|
//#define CheckCKBeObject(bmfile, objid) CheckGeneralObject<LibCmo::CK2::ObjImpls::CKBeObject*>(bmfile, objid, LibCmo::CK2::CK_CLASSID::CKCID_BEOBJECT)
|
|
|
|
#define CheckCKGroup(bmfile, objid) CheckGeneralObject<LibCmo::CK2::ObjImpls::CKGroup*>(bmfile, objid, LibCmo::CK2::CK_CLASSID::CKCID_GROUP)
|
|
|
|
#define CheckCK3dObject(bmfile, objid) CheckGeneralObject<LibCmo::CK2::ObjImpls::CK3dObject*>(bmfile, objid, LibCmo::CK2::CK_CLASSID::CKCID_3DOBJECT)
|
|
|
|
#define CheckCKMesh(bmfile, objid) CheckGeneralObject<LibCmo::CK2::ObjImpls::CKMesh*>(bmfile, objid, LibCmo::CK2::CK_CLASSID::CKCID_MESH)
|
|
|
|
#define CheckCKMaterial(bmfile, objid) CheckGeneralObject<LibCmo::CK2::ObjImpls::CKMaterial*>(bmfile, objid, LibCmo::CK2::CK_CLASSID::CKCID_MATERIAL)
|
|
|
|
#define CheckCKTexture(bmfile, objid) CheckGeneralObject<LibCmo::CK2::ObjImpls::CKTexture*>(bmfile, objid, LibCmo::CK2::CK_CLASSID::CKCID_TEXTURE)
|
|
|
|
|
2023-10-03 21:33:00 +08:00
|
|
|
#pragma endregion
|
|
|
|
|
2023-09-21 13:47:30 +08:00
|
|
|
void BMInit() {
|
2023-09-23 15:55:57 +08:00
|
|
|
// register IronPad
|
|
|
|
IronPad::IronPadRegister();
|
|
|
|
// and startup CK environment
|
|
|
|
LibCmo::CK2::CKStartUp();
|
2023-10-03 21:33:00 +08:00
|
|
|
|
2023-10-02 20:54:31 +08:00
|
|
|
// set init
|
|
|
|
g_IsInited = true;
|
2023-09-21 13:47:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void BMDispose() {
|
2023-09-23 15:55:57 +08:00
|
|
|
// free all existed file reader / writer
|
|
|
|
for (auto ptr : g_AllBMFiles) {
|
|
|
|
delete ptr;
|
|
|
|
}
|
|
|
|
g_AllBMFiles.clear();
|
2023-10-02 20:54:31 +08:00
|
|
|
// free all mesh transition
|
|
|
|
for (auto ptr : g_AllBMMeshTrans) {
|
|
|
|
delete ptr;
|
|
|
|
}
|
|
|
|
g_AllBMMeshTrans.clear();
|
|
|
|
|
|
|
|
// disable init
|
|
|
|
g_IsInited = false;
|
2023-10-03 21:33:00 +08:00
|
|
|
|
2023-09-23 15:55:57 +08:00
|
|
|
// shutdown CK environment
|
|
|
|
LibCmo::CK2::CKShutdown();
|
|
|
|
// unregister iron pad
|
|
|
|
IronPad::IronPadUnregister();
|
2023-09-21 13:47:30 +08:00
|
|
|
}
|
2023-09-23 16:25:26 +08:00
|
|
|
|
2023-10-02 20:54:31 +08:00
|
|
|
#pragma region BMFile
|
|
|
|
|
2023-09-23 16:25:26 +08:00
|
|
|
BMap::BMFile* BMFile_Load(LibCmo::CKSTRING file_name, LibCmo::CKSTRING temp_folder, LibCmo::CKSTRING texture_folder, LibCmo::CKDWORD encoding_count, LibCmo::CKSTRING encodings[]) {
|
2023-10-03 21:33:00 +08:00
|
|
|
if (!CheckInited()) return nullptr;
|
2023-09-23 16:25:26 +08:00
|
|
|
|
2023-10-03 21:33:00 +08:00
|
|
|
// create a now one and try to load data.
|
|
|
|
std::unique_ptr<BMap::BMFile> file(new BMap::BMFile(temp_folder, texture_folder, encoding_count, encodings, false));
|
|
|
|
if (file->IsFreezed()) return nullptr;
|
|
|
|
if (!file->Load(file_name)) return nullptr;
|
|
|
|
|
|
|
|
// add into list and return
|
|
|
|
g_AllBMFiles.emplace(file.get());
|
|
|
|
return file.release();
|
2023-09-23 16:25:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
BMap::BMFile* BMFile_Create(LibCmo::CKSTRING temp_folder, LibCmo::CKSTRING texture_folder, LibCmo::CKDWORD encoding_count, LibCmo::CKSTRING encodings[]) {
|
2023-10-03 21:33:00 +08:00
|
|
|
if (!CheckInited()) return nullptr;
|
|
|
|
|
|
|
|
// create a now one
|
|
|
|
std::unique_ptr<BMap::BMFile> file(new BMap::BMFile(temp_folder, texture_folder, encoding_count, encodings, false));
|
|
|
|
if (file->IsFreezed()) return nullptr;
|
2023-09-23 16:25:26 +08:00
|
|
|
|
2023-10-03 21:33:00 +08:00
|
|
|
// add into list and return if success
|
|
|
|
g_AllBMFiles.emplace(file.get());
|
|
|
|
return file.release();
|
2023-09-23 16:25:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BMFile_Save(BMap::BMFile* map_file, LibCmo::CKSTRING file_name, LibCmo::CKINT compreess_level) {
|
2023-10-03 21:33:00 +08:00
|
|
|
if (!CheckBMFile(map_file)) return false;
|
|
|
|
|
2023-09-23 16:25:26 +08:00
|
|
|
return map_file->Save(file_name, compreess_level);
|
|
|
|
}
|
|
|
|
|
2023-10-03 21:33:00 +08:00
|
|
|
bool BMFile_Free(BMap::BMFile* map_file) {
|
|
|
|
if (!CheckBMFile(map_file)) return false;
|
2023-10-02 20:54:31 +08:00
|
|
|
|
2023-10-03 21:33:00 +08:00
|
|
|
g_AllBMFiles.erase(map_file);
|
|
|
|
delete map_file;
|
|
|
|
return true;
|
2023-10-02 20:54:31 +08:00
|
|
|
}
|
|
|
|
|
2023-10-03 21:33:00 +08:00
|
|
|
LibCmo::CKDWORD BMFile_GetGroupCount(BMap::BMFile* bmfile) {
|
|
|
|
if (!CheckBMFile(bmfile)) return 0;
|
|
|
|
return bmfile->GetGroupCount();
|
|
|
|
}
|
|
|
|
LibCmo::CK2::CK_ID BMFile_GetGroup(BMap::BMFile* bmfile, LibCmo::CKDWORD idx) {
|
|
|
|
if (!CheckBMFile(bmfile)) return 0;
|
|
|
|
return bmfile->GetGroup(idx);
|
|
|
|
}
|
2023-10-05 21:08:58 +08:00
|
|
|
LibCmo::CK2::CK_ID BMFile_CreateGroup(BMap::BMFile* bmfile) {
|
2023-10-03 21:33:00 +08:00
|
|
|
if (!CheckBMFile(bmfile)) return 0;
|
2023-10-05 21:08:58 +08:00
|
|
|
return bmfile->CreateGroup();
|
2023-10-03 21:33:00 +08:00
|
|
|
}
|
|
|
|
LibCmo::CKDWORD BMFile_Get3dObjectCount(BMap::BMFile* bmfile) {
|
|
|
|
if (!CheckBMFile(bmfile)) return 0;
|
|
|
|
return bmfile->Get3dObjectCount();
|
|
|
|
}
|
|
|
|
LibCmo::CK2::CK_ID BMFile_Get3dObject(BMap::BMFile* bmfile, LibCmo::CKDWORD idx) {
|
|
|
|
if (!CheckBMFile(bmfile)) return 0;
|
|
|
|
return bmfile->Get3dObject(idx);
|
|
|
|
}
|
2023-10-05 21:08:58 +08:00
|
|
|
LibCmo::CK2::CK_ID BMFile_Create3dObject(BMap::BMFile* bmfile) {
|
2023-10-03 21:33:00 +08:00
|
|
|
if (!CheckBMFile(bmfile)) return 0;
|
2023-10-05 21:08:58 +08:00
|
|
|
return bmfile->Create3dObject();
|
2023-10-03 21:33:00 +08:00
|
|
|
}
|
|
|
|
LibCmo::CKDWORD BMFile_GetMeshCount(BMap::BMFile* bmfile) {
|
|
|
|
if (!CheckBMFile(bmfile)) return 0;
|
|
|
|
return bmfile->GetMeshCount();
|
|
|
|
}
|
|
|
|
LibCmo::CK2::CK_ID BMFile_GetMesh(BMap::BMFile* bmfile, LibCmo::CKDWORD idx) {
|
|
|
|
if (!CheckBMFile(bmfile)) return 0;
|
|
|
|
return bmfile->GetMesh(idx);
|
|
|
|
}
|
2023-10-05 21:08:58 +08:00
|
|
|
LibCmo::CK2::CK_ID BMFile_CreateMesh(BMap::BMFile* bmfile) {
|
2023-10-03 21:33:00 +08:00
|
|
|
if (!CheckBMFile(bmfile)) return 0;
|
2023-10-05 21:08:58 +08:00
|
|
|
return bmfile->CreateMesh();
|
2023-10-03 21:33:00 +08:00
|
|
|
}
|
|
|
|
LibCmo::CKDWORD BMFile_GetMaterialCount(BMap::BMFile* bmfile) {
|
|
|
|
if (!CheckBMFile(bmfile)) return 0;
|
|
|
|
return bmfile->GetMaterialCount();
|
|
|
|
}
|
|
|
|
LibCmo::CK2::CK_ID BMFile_GetMaterial(BMap::BMFile* bmfile, LibCmo::CKDWORD idx) {
|
|
|
|
if (!CheckBMFile(bmfile)) return 0;
|
|
|
|
return bmfile->GetMaterial(idx);
|
|
|
|
}
|
2023-10-05 21:08:58 +08:00
|
|
|
LibCmo::CK2::CK_ID BMFile_CreateMaterial(BMap::BMFile* bmfile) {
|
2023-10-03 21:33:00 +08:00
|
|
|
if (!CheckBMFile(bmfile)) return 0;
|
2023-10-05 21:08:58 +08:00
|
|
|
return bmfile->CreateMaterial();
|
2023-10-03 21:33:00 +08:00
|
|
|
}
|
|
|
|
LibCmo::CKDWORD BMFile_GetTextureCount(BMap::BMFile* bmfile) {
|
|
|
|
if (!CheckBMFile(bmfile)) return 0;
|
|
|
|
return bmfile->GetTextureCount();
|
|
|
|
}
|
|
|
|
LibCmo::CK2::CK_ID BMFile_GetTexture(BMap::BMFile* bmfile, LibCmo::CKDWORD idx) {
|
|
|
|
if (!CheckBMFile(bmfile)) return 0;
|
|
|
|
return bmfile->GetTexture(idx);
|
|
|
|
}
|
2023-10-05 21:08:58 +08:00
|
|
|
LibCmo::CK2::CK_ID BMFile_CreateTexture(BMap::BMFile* bmfile) {
|
2023-10-03 21:33:00 +08:00
|
|
|
if (!CheckBMFile(bmfile)) return 0;
|
2023-10-05 21:08:58 +08:00
|
|
|
return bmfile->CreateTexture();
|
2023-10-03 21:33:00 +08:00
|
|
|
}
|
2023-10-02 20:54:31 +08:00
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
|
|
|
#pragma region BMMeshTransition
|
|
|
|
|
|
|
|
BMap::BMMeshTransition* BMMeshTrans_New() {
|
2023-10-03 21:33:00 +08:00
|
|
|
if (!CheckInited()) return nullptr;
|
|
|
|
|
|
|
|
// create new one, insert and return.
|
2023-10-02 20:54:31 +08:00
|
|
|
auto meshtrans = new BMap::BMMeshTransition();
|
|
|
|
g_AllBMMeshTrans.emplace(meshtrans);
|
|
|
|
return meshtrans;
|
|
|
|
}
|
|
|
|
|
2023-10-03 21:33:00 +08:00
|
|
|
bool BMMeshTrans_Delete(BMap::BMMeshTransition* trans) {
|
|
|
|
if (!CheckBMMeshTrans(trans)) return false;
|
|
|
|
|
|
|
|
g_AllBMMeshTrans.erase(trans);
|
|
|
|
delete trans;
|
|
|
|
return true;
|
2023-10-02 20:54:31 +08:00
|
|
|
}
|
|
|
|
|
2023-10-03 21:33:00 +08:00
|
|
|
bool BMMeshTrans_PrepareVertexCount(BMap::BMMeshTransition* trans, LibCmo::CKDWORD count) {
|
|
|
|
if (!CheckBMMeshTrans(trans)) return false;
|
|
|
|
return trans->PrepareVertexCount(count);
|
2023-10-02 20:54:31 +08:00
|
|
|
}
|
|
|
|
LibCmo::VxMath::VxVector3* BMMeshTrans_PrepareVertex(BMap::BMMeshTransition* trans) {
|
2023-10-03 21:33:00 +08:00
|
|
|
if (!CheckBMMeshTrans(trans)) return nullptr;
|
2023-10-02 20:54:31 +08:00
|
|
|
return trans->PrepareVertex();
|
|
|
|
}
|
2023-10-03 21:33:00 +08:00
|
|
|
bool BMMeshTrans_PrepareNormalCount(BMap::BMMeshTransition* trans, LibCmo::CKDWORD count) {
|
|
|
|
if (!CheckBMMeshTrans(trans)) return false;
|
|
|
|
return trans->PrepareNormalCount(count);
|
2023-10-02 20:54:31 +08:00
|
|
|
}
|
|
|
|
LibCmo::VxMath::VxVector3* BMMeshTrans_PrepareNormal(BMap::BMMeshTransition* trans) {
|
2023-10-03 21:33:00 +08:00
|
|
|
if (!CheckBMMeshTrans(trans)) return nullptr;
|
2023-10-02 20:54:31 +08:00
|
|
|
return trans->PrepareNormal();
|
|
|
|
}
|
2023-10-03 21:33:00 +08:00
|
|
|
bool BMMeshTrans_PrepareUVCount(BMap::BMMeshTransition* trans, LibCmo::CKDWORD count) {
|
|
|
|
if (!CheckBMMeshTrans(trans)) return false;
|
|
|
|
return trans->PrepareUVCount(count);
|
2023-10-02 20:54:31 +08:00
|
|
|
}
|
|
|
|
LibCmo::VxMath::VxVector2* BMMeshTrans_PrepareUV(BMap::BMMeshTransition* trans) {
|
2023-10-03 21:33:00 +08:00
|
|
|
if (!CheckBMMeshTrans(trans)) return nullptr;
|
2023-10-02 20:54:31 +08:00
|
|
|
return trans->PrepareUV();
|
|
|
|
}
|
2023-10-03 21:33:00 +08:00
|
|
|
bool BMMeshTrans_PrepareMtlSlotCount(BMap::BMMeshTransition* trans, LibCmo::CKDWORD count) {
|
|
|
|
if (!CheckBMMeshTrans(trans)) return false;
|
|
|
|
return trans->PrepareMtlSlotCount(count);
|
2023-10-02 20:54:31 +08:00
|
|
|
}
|
2023-10-05 21:08:58 +08:00
|
|
|
LibCmo::CK2::CK_ID* BMMeshTrans_PrepareMtlSlot(BMap::BMMeshTransition* trans) {
|
2023-10-03 21:33:00 +08:00
|
|
|
if (!CheckBMMeshTrans(trans)) return nullptr;
|
2023-10-02 20:54:31 +08:00
|
|
|
return trans->PrepareMtlSlot();
|
|
|
|
}
|
2023-10-03 21:33:00 +08:00
|
|
|
bool BMMeshTrans_PrepareFaceCount(BMap::BMMeshTransition* trans, LibCmo::CKDWORD count) {
|
|
|
|
if (!CheckBMMeshTrans(trans)) return false;
|
|
|
|
return trans->PrepareFaceCount(count);
|
2023-10-02 20:54:31 +08:00
|
|
|
}
|
|
|
|
LibCmo::CKDWORD* BMMeshTrans_PrepareFaceVertexIndices(BMap::BMMeshTransition* trans) {
|
2023-10-03 21:33:00 +08:00
|
|
|
if (!CheckBMMeshTrans(trans)) return nullptr;
|
2023-10-02 20:54:31 +08:00
|
|
|
return trans->PrepareFaceVertexIndices();
|
|
|
|
}
|
|
|
|
LibCmo::CKDWORD* BMMeshTrans_PrepareFaceNormalIndices(BMap::BMMeshTransition* trans) {
|
2023-10-03 21:33:00 +08:00
|
|
|
if (!CheckBMMeshTrans(trans)) return nullptr;
|
2023-10-02 20:54:31 +08:00
|
|
|
return trans->PrepareFaceNormalIndices();
|
|
|
|
}
|
|
|
|
LibCmo::CKDWORD* BMMeshTrans_PrepareFaceUVIndices(BMap::BMMeshTransition* trans) {
|
2023-10-03 21:33:00 +08:00
|
|
|
if (!CheckBMMeshTrans(trans)) return nullptr;
|
2023-10-02 20:54:31 +08:00
|
|
|
return trans->PrepareFaceUVIndices();
|
|
|
|
}
|
|
|
|
LibCmo::CKDWORD* BMMeshTrans_PrepareFaceMtlSlot(BMap::BMMeshTransition* trans) {
|
2023-10-03 21:33:00 +08:00
|
|
|
if (!CheckBMMeshTrans(trans)) return nullptr;
|
2023-10-02 20:54:31 +08:00
|
|
|
return trans->PrepareFaceMtlSlot();
|
|
|
|
}
|
|
|
|
bool BMMeshTrans_Parse(BMap::BMMeshTransition* trans, LibCmo::CK2::ObjImpls::CKMesh* write_into_mesh) {
|
2023-10-03 21:33:00 +08:00
|
|
|
if (!CheckBMMeshTrans(trans)) return false;
|
2023-10-02 20:54:31 +08:00
|
|
|
return trans->Parse(write_into_mesh);
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
2023-10-05 21:08:58 +08:00
|
|
|
#pragma region CKObject
|
|
|
|
|
2023-10-07 22:33:55 +08:00
|
|
|
LibCmo::CKSTRING BMObject_GetName(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid) {
|
|
|
|
auto obj = CheckCKObject(bmfile, objid);
|
2023-10-05 21:08:58 +08:00
|
|
|
if (obj == nullptr) return nullptr;
|
|
|
|
return obj->GetName();
|
|
|
|
}
|
|
|
|
|
2023-10-07 22:33:55 +08:00
|
|
|
bool BMObject_SetName(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid, LibCmo::CKSTRING name) {
|
|
|
|
auto obj = CheckCKObject(bmfile, objid);
|
2023-10-05 21:08:58 +08:00
|
|
|
if (obj == nullptr) return false;
|
|
|
|
obj->SetName(name);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
|
|
|
#pragma region CKGroup
|
|
|
|
|
2023-10-07 22:33:55 +08:00
|
|
|
bool BMGroup_AddObject(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid, LibCmo::CK2::CK_ID memberid) {
|
|
|
|
auto obj = CheckCKGroup(bmfile, objid);
|
|
|
|
auto memberobj = CheckCK3dObject(bmfile, memberid);
|
2023-10-05 21:08:58 +08:00
|
|
|
if (obj == nullptr || memberobj == nullptr) return false;
|
|
|
|
|
|
|
|
return obj->AddObject(memberobj) == LibCmo::CK2::CKERROR::CKERR_OK;
|
|
|
|
}
|
|
|
|
|
2023-10-07 22:33:55 +08:00
|
|
|
LibCmo::CKDWORD BMGroup_GetObjectCount(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid) {
|
|
|
|
auto obj = CheckCKGroup(bmfile, objid);
|
2023-10-05 21:08:58 +08:00
|
|
|
if (obj == nullptr) return false;
|
|
|
|
return obj->GetObjectCount();
|
|
|
|
}
|
|
|
|
|
2023-10-07 22:33:55 +08:00
|
|
|
LibCmo::CK2::CK_ID BMGroup_GetObject(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid, LibCmo::CKDWORD pos) {
|
|
|
|
auto obj = CheckCKGroup(bmfile, objid);
|
2023-10-05 21:08:58 +08:00
|
|
|
if (obj == nullptr) return 0;
|
|
|
|
|
2023-10-07 22:33:55 +08:00
|
|
|
return SafeGetID(obj->GetObject(pos));
|
2023-10-05 21:08:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
|
|
|
#pragma region CKTexture
|
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
|
|
|
#pragma region CKMaterial
|
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
|
|
|
#pragma region CKMesh
|
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
|
|
|
#pragma region CK3dObject
|
|
|
|
|
2023-10-07 22:33:55 +08:00
|
|
|
CStyleVxMatrix BM3dEntity_GetWorldMatrix(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid) {
|
|
|
|
CStyleVxMatrix result;
|
|
|
|
auto obj = CheckCK3dObject(bmfile, objid);
|
|
|
|
if (obj == nullptr) {
|
|
|
|
result.FromVxMatrix(LibCmo::VxMath::VxMatrix());
|
|
|
|
} else {
|
|
|
|
result.FromVxMatrix(obj->GetWorldMatrix());
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BM3dEntity_SetWorldMatrix(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid, CStyleVxMatrix mat) {
|
|
|
|
auto obj = CheckCK3dObject(bmfile, objid);
|
|
|
|
if (obj == nullptr) return false;
|
|
|
|
|
|
|
|
LibCmo::VxMath::VxMatrix cppmat;
|
|
|
|
mat.ToVxMatrix(cppmat);
|
|
|
|
obj->SetWorldMatrix(cppmat);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
LibCmo::CK2::CK_ID BM3dEntity_GetCurrentMesh(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid) {
|
|
|
|
auto obj = CheckCK3dObject(bmfile, objid);
|
|
|
|
if (obj == nullptr) return 0;
|
|
|
|
|
|
|
|
return SafeGetID(obj->GetCurrentMesh());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BM3dEntity_SetCurrentMesh(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid, LibCmo::CK2::CK_ID meshid) {
|
|
|
|
auto obj = CheckCK3dObject(bmfile, objid);
|
|
|
|
auto meshobj = CheckCKMesh(bmfile, meshid);
|
|
|
|
if (obj == nullptr || meshobj == nullptr) return false;
|
|
|
|
|
|
|
|
obj->SetCurrentMesh(meshobj);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-10-08 10:42:07 +08:00
|
|
|
bool BM3dEntity_GetVisibility(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid) {
|
2023-10-07 22:33:55 +08:00
|
|
|
auto obj = CheckCK3dObject(bmfile, objid);
|
|
|
|
if (obj == nullptr) return false;
|
|
|
|
|
|
|
|
return obj->IsVisible();
|
|
|
|
}
|
|
|
|
|
2023-10-08 10:42:07 +08:00
|
|
|
bool BM3dEntity_SetVisibility(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid, bool is_visible) {
|
2023-10-07 22:33:55 +08:00
|
|
|
auto obj = CheckCK3dObject(bmfile, objid);
|
|
|
|
if (obj == nullptr) return false;
|
|
|
|
|
|
|
|
obj->Show(is_visible ? LibCmo::CK2::CK_OBJECT_SHOWOPTION::CKSHOW : LibCmo::CK2::CK_OBJECT_SHOWOPTION::CKHIDE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-10-05 21:08:58 +08:00
|
|
|
#pragma endregion
|
|
|
|
|