From 2ff3ce851ac95939ac68d39e196e8a19f267aac5 Mon Sep 17 00:00:00 2001 From: Segey Lapin Date: Mon, 25 Oct 2021 18:07:36 +0300 Subject: [PATCH] Added getting body parts file names from C++ code --- modules/world/characters.cpp | 45 +++++++++++++++++++++++++++++++++++- modules/world/characters.h | 7 ++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/modules/world/characters.cpp b/modules/world/characters.cpp index 9c1a702..582051d 100644 --- a/modules/world/characters.cpp +++ b/modules/world/characters.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -15,7 +16,7 @@ Characters_::Characters_() : query(memnew(DetourNavigationQuery)), initialized(false), debug(NULL), - crowd(NULL) + crowd(NULL), scenes_path("res://scenes/") { smm = NULL; no_navmesh = true; @@ -621,6 +622,7 @@ void Characters_::_notification(int p_what) set_physics_process(true); smm = memnew(SmartObjectManager); add_child(smm); + load_body_parts(scenes_path); break; } } @@ -848,3 +850,44 @@ DetourCrowdManager *Characters_::get_crowd() const return crowd; } +void Characters_::load_body_parts(const String &path) +{ + int i; + String base_path = path; + if (!path.ends_with("/")) + base_path += "/"; + String base_hair_path = base_path + "hair/"; + String base_face_path = base_path + "face/"; + String base_name_male_hair = "male-hair.tscn", base_name_female_hair = "female-hair.tscn"; + if (FileAccess::exists(base_hair_path + base_name_male_hair)) + male_hairs.push_back(base_hair_path + base_name_male_hair); + if (FileAccess::exists(base_hair_path + base_name_female_hair)) + female_hairs.push_back(base_hair_path + base_name_female_hair); + String base_name_male_face = "male-face.tscn", base_name_female_face = "female-face.tscn"; + if (FileAccess::exists(base_face_path + base_name_male_face)) + male_faces.push_back(base_face_path + base_name_male_face); + if (FileAccess::exists(base_face_path + base_name_female_face)) + female_faces.push_back(base_face_path + base_name_female_face); + + for (i = 0; i < 1000; i++) { + String fn1h = (base_hair_path + "male-hair") + itos(i) + ".tscn"; + String fn2h = (base_hair_path + "female-hair") + itos(i) + ".tscn"; + String fn2m = (base_hair_path + "hair") + itos(i) + ".tres"; + String fn1f = (base_face_path + "male-face") + itos(i) + ".tscn"; + String fn2f = (base_face_path + "female-face") + itos(i) + ".tscn"; + if (FileAccess::exists(fn1h)) + male_hairs.push_back(fn1h); + if (FileAccess::exists(fn2h)) + female_hairs.push_back(fn2h); + if (FileAccess::exists(fn2m)) + hair_materials.push_back(fn2m); + if (FileAccess::exists(fn1f)) + male_faces.push_back(fn1f); + if (FileAccess::exists(fn2f)) + female_faces.push_back(fn2f); + } + assert(male_hairs.size() > 0 && female_hairs.size() > 0); + assert(male_faces.size() > 0 && female_faces.size() > 0); + assert(hair_materials.size() > 0); +} + diff --git a/modules/world/characters.h b/modules/world/characters.h index 8e1fd3d..b0acf34 100644 --- a/modules/world/characters.h +++ b/modules/world/characters.h @@ -41,6 +41,7 @@ public: void agent_walk_stop(Object *obj); void set_root_motion_mod(const Transform &xform); Transform get_root_motion_mod() const; + void load_body_parts(const String &path); protected: void _notification(int p_what); static void _bind_methods(); @@ -60,5 +61,11 @@ protected: float arrive_precision; Transform root_motion_mod; bool no_navmesh; + PoolVector male_hairs; + PoolVector female_hairs; + PoolVector hair_materials; + PoolVector male_faces; + PoolVector female_faces; + String scenes_path; };