Properly re-initializing entity on module reload, fixed mesh merging
parent
28c45e05f6
commit
fcd44dc3b9
|
@ -31,12 +31,25 @@ CharacterEntity::CharacterEntity() {
|
||||||
|
|
||||||
cout << "Creating render entity mesh ..." << endl;
|
cout << "Creating render entity mesh ..." << endl;
|
||||||
|
|
||||||
|
// Mesh* base_mesh = Mesh::sCreateUVSphere(45, 45, 0.9);
|
||||||
|
// Transform sub_transform =
|
||||||
|
// Transform::fromTransRot(
|
||||||
|
// Vector3f (4.f, 3.3f, 0.12f),
|
||||||
|
// Quaternion::fromEulerYXZ (Vector3f(1.f, 2.f, 0.f))
|
||||||
|
// );
|
||||||
|
// Mesh* quad = Mesh::sCreateCuboid(1.05, 0.1, 2.05);
|
||||||
|
//
|
||||||
|
// base_mesh->Merge (*quad, sub_transform.toMatrix());
|
||||||
|
// base_mesh->Update();
|
||||||
|
// delete quad;
|
||||||
|
|
||||||
// Build the snowman
|
// Build the snowman
|
||||||
entity->mesh.addMesh(
|
entity->mesh.addMesh(
|
||||||
- 1,
|
- 1,
|
||||||
Transform::fromTrans(
|
Transform::fromTrans(
|
||||||
Vector3f (0.0f, 0.9 * 0.5f, 0.0f)
|
Vector3f (0.0f, 0.9 * 0.5f, 0.0f)
|
||||||
),
|
),
|
||||||
|
// base_mesh
|
||||||
Mesh::sCreateUVSphere(45, 45, 0.9)
|
Mesh::sCreateUVSphere(45, 45, 0.9)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -912,8 +912,8 @@ void Mesh::Update() {
|
||||||
|
|
||||||
void Mesh::Merge (const Mesh& other, const Matrix44f &transform) {
|
void Mesh::Merge (const Mesh& other, const Matrix44f &transform) {
|
||||||
for (int i = 0; i < other.mVertices.size(); ++i) {
|
for (int i = 0; i < other.mVertices.size(); ++i) {
|
||||||
mVertices.push_back (transform * other.mVertices[i]);
|
mVertices.push_back (transform.transpose() * other.mVertices[i]);
|
||||||
mNormals.push_back (Matrix33f(transform.block<3,3>(0,0)) * other.mNormals[i]);
|
mNormals.push_back (Matrix33f(transform.block<3,3>(0,0)).transpose() * other.mNormals[i]);
|
||||||
|
|
||||||
if (other.mColors.size() == other.mVertices.size())
|
if (other.mColors.size() == other.mVertices.size())
|
||||||
mColors.push_back(other.mColors[i]);
|
mColors.push_back(other.mColors[i]);
|
||||||
|
|
|
@ -175,8 +175,6 @@ void update_character(module_state* state, float dt) {
|
||||||
static struct module_state *module_init() {
|
static struct module_state *module_init() {
|
||||||
std::cout << "Module init called" << std::endl;
|
std::cout << "Module init called" << std::endl;
|
||||||
module_state *state = (module_state*) malloc(sizeof(*state));
|
module_state *state = (module_state*) malloc(sizeof(*state));
|
||||||
state->character = new CharacterEntity;
|
|
||||||
state->character->position = Vector3f (0.f, 0.f, 0.f);
|
|
||||||
state->modules_window_selected_index = -1;
|
state->modules_window_selected_index = -1;
|
||||||
|
|
||||||
fps_camera = true;
|
fps_camera = true;
|
||||||
|
@ -205,6 +203,10 @@ static void module_reload(struct module_state *state, void* read_serializer) {
|
||||||
std::cout << "Module reload called. State: " << state << std::endl;
|
std::cout << "Module reload called. State: " << state << std::endl;
|
||||||
|
|
||||||
cout << "Creating render entity ..." << endl;
|
cout << "Creating render entity ..." << endl;
|
||||||
|
|
||||||
|
state->character = new CharacterEntity;
|
||||||
|
state->character->position = Vector3f (0.f, 0.f, 0.f);
|
||||||
|
|
||||||
// load the state of the entity
|
// load the state of the entity
|
||||||
if (read_serializer != nullptr) {
|
if (read_serializer != nullptr) {
|
||||||
module_serialize(state, static_cast<ReadSerializer*>(read_serializer));
|
module_serialize(state, static_cast<ReadSerializer*>(read_serializer));
|
||||||
|
@ -218,13 +220,7 @@ static void module_unload(struct module_state *state, void* write_serializer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
cout << "destroying render entity " << state->character->entity << endl;
|
delete state->character;
|
||||||
if (!gRenderer->destroyEntity (state->character->entity)) {
|
|
||||||
cerr << "Warning: could not destroy entity " << state->character->entity << endl;
|
|
||||||
} else {
|
|
||||||
cout << "Successfully destroyed entity " << state->character->entity << endl;
|
|
||||||
|
|
||||||
}
|
|
||||||
state->character->entity = nullptr;
|
state->character->entity = nullptr;
|
||||||
|
|
||||||
std::cout << "TestModule unloaded. State: " << state << std::endl;
|
std::cout << "TestModule unloaded. State: " << state << std::endl;
|
||||||
|
|
Loading…
Reference in New Issue