Added getting body parts file names from C++ code

This commit is contained in:
Segey Lapin
2021-10-25 18:07:36 +03:00
parent 2754dea132
commit 2ff3ce851a
2 changed files with 51 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
#include <cassert>
#include <cstdio>
#include <core/list.h>
#include <core/os/file_access.h>
#include <scene/3d/spatial.h>
#include <scene/3d/physics_body.h>
#include <scene/3d/immediate_geometry.h>
@@ -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);
}

View File

@@ -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<String> male_hairs;
PoolVector<String> female_hairs;
PoolVector<String> hair_materials;
PoolVector<String> male_faces;
PoolVector<String> female_faces;
String scenes_path;
};