Separated and cleaned interior/exterior stuff
This commit is contained in:
Submodule src/flecs updated: d4462b4cd0...57ebed1083
Submodule src/godot updated: 36a01852a7...7fbb30e55b
@@ -28,12 +28,13 @@ class Setup3DViewport : public Object {
|
|||||||
String current_graph;
|
String current_graph;
|
||||||
int current_floor;
|
int current_floor;
|
||||||
BuildingLayoutGraphUI *base;
|
BuildingLayoutGraphUI *base;
|
||||||
MeshInstance *display_mi_exterior, *display_mi_interior;
|
MeshInstance *display_mi[2];
|
||||||
Ref<MeshLibrary> layout_parts;
|
Ref<MeshLibrary> layout_parts;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
wc = memnew(ViewportContainer);
|
wc = memnew(ViewportContainer);
|
||||||
view = memnew(Viewport);
|
view = memnew(Viewport);
|
||||||
light = memnew(DirectionalLight);
|
light = memnew(DirectionalLight);
|
||||||
@@ -71,10 +72,10 @@ protected:
|
|||||||
base_mi->set_mesh(cube);
|
base_mi->set_mesh(cube);
|
||||||
base_mi->set_translation(Vector3(0, -0.5, 0));
|
base_mi->set_translation(Vector3(0, -0.5, 0));
|
||||||
view->call_deferred("add_child", base_mi);
|
view->call_deferred("add_child", base_mi);
|
||||||
display_mi_exterior = memnew(MeshInstance);
|
for (i = 0; i < 2; i++) {
|
||||||
view->call_deferred("add_child", display_mi_exterior);
|
display_mi[i] = memnew(MeshInstance);
|
||||||
display_mi_interior = memnew(MeshInstance);
|
view->call_deferred("add_child", display_mi[i]);
|
||||||
view->call_deferred("add_child", display_mi_interior);
|
}
|
||||||
}
|
}
|
||||||
void build_mesh_data()
|
void build_mesh_data()
|
||||||
{
|
{
|
||||||
@@ -96,32 +97,35 @@ protected:
|
|||||||
buildings_layout_grid_cell>()
|
buildings_layout_grid_cell>()
|
||||||
.with(flecs::ChildOf, grid_floor_e)
|
.with(flecs::ChildOf, grid_floor_e)
|
||||||
.build();
|
.build();
|
||||||
Ref<ArrayMesh> layout_mesh_exterior, layout_mesh_interior;
|
struct item_set {
|
||||||
layout_mesh_exterior.instance();
|
Ref<ArrayMesh> layout_mesh;
|
||||||
layout_mesh_interior.instance();
|
Vector<Pair<int, Transform> > items;
|
||||||
SurfaceTool tool_exterior, tool_interior;
|
Ref<Material> mat;
|
||||||
Ref<Material> mat_exterior, mat_interior;
|
SurfaceTool tool;
|
||||||
layout_mesh_exterior->set_storage_mode(Mesh::STORAGE_MODE_CPU);
|
item_set()
|
||||||
layout_mesh_interior->set_storage_mode(Mesh::STORAGE_MODE_CPU);
|
{
|
||||||
tool_exterior.create_from(layout_mesh_exterior, 0);
|
layout_mesh.instance();
|
||||||
tool_interior.create_from(layout_mesh_interior, 0);
|
layout_mesh->set_storage_mode(
|
||||||
|
Mesh::STORAGE_MODE_CPU);
|
||||||
|
tool.create_from(layout_mesh, 0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
int k;
|
||||||
|
struct item_set item_data[2];
|
||||||
Transform offset(Basis(), Vector3(-grid_size * 4 / 2, 0,
|
Transform offset(Basis(), Vector3(-grid_size * 4 / 2, 0,
|
||||||
-grid_size * 4 / 2));
|
-grid_size * 4 / 2));
|
||||||
cells_query.each([this, grid_size, offset, &tool_exterior,
|
cells_query.each([this, grid_size, offset,
|
||||||
&tool_interior, &mat_exterior, &mat_interior](
|
&item_data](flecs::entity e,
|
||||||
flecs::entity e,
|
const WorldEditor::components::
|
||||||
const WorldEditor::components::
|
buildings_layout_grid_cell
|
||||||
buildings_layout_grid_cell
|
&cell) {
|
||||||
&cell) {
|
int i, j;
|
||||||
int i;
|
|
||||||
int x = cell.index % grid_size;
|
int x = cell.index % grid_size;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
int z = cell.index / grid_size;
|
int z = cell.index / grid_size;
|
||||||
Transform base_transform(Basis(),
|
Transform base_transform(Basis(),
|
||||||
Vector3(x * 4, 0, z * 4));
|
Vector3(x * 4, 0, z * 4));
|
||||||
int matches = 0;
|
int matches = 0;
|
||||||
Vector<Pair<int, Transform> > items_exterior;
|
|
||||||
Vector<Pair<int, Transform> > items_interior;
|
|
||||||
struct pmatch {
|
struct pmatch {
|
||||||
int mask;
|
int mask;
|
||||||
String item;
|
String item;
|
||||||
@@ -187,6 +191,8 @@ protected:
|
|||||||
matches |= 64;
|
matches |= 64;
|
||||||
if (e.has<WorldEditor::components::internal_wall_east>())
|
if (e.has<WorldEditor::components::internal_wall_east>())
|
||||||
matches |= 128;
|
matches |= 128;
|
||||||
|
for (i = 0; i < 2; i++)
|
||||||
|
item_data[i].items.clear();
|
||||||
for (i = 0; i < (int)sizeof(match_data) /
|
for (i = 0; i < (int)sizeof(match_data) /
|
||||||
(int)sizeof(match_data[0]);
|
(int)sizeof(match_data[0]);
|
||||||
i++) {
|
i++) {
|
||||||
@@ -202,70 +208,54 @@ protected:
|
|||||||
item_transform.origin =
|
item_transform.origin =
|
||||||
match_data[i].offset;
|
match_data[i].offset;
|
||||||
if (match_data[i].exterior)
|
if (match_data[i].exterior)
|
||||||
items_exterior.push_back(
|
item_data[0].items.push_back(
|
||||||
{ id, item_transform });
|
{ id, item_transform });
|
||||||
else
|
else
|
||||||
items_interior.push_back(
|
item_data[1].items.push_back(
|
||||||
{ id, item_transform });
|
{ id, item_transform });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i < items_exterior.size(); i++) {
|
for (j = 0; j < 2; j++) {
|
||||||
Ref<Mesh> mesh = layout_parts->get_item_mesh(
|
for (i = 0; i < item_data[j].items.size();
|
||||||
items_exterior[i].first);
|
i++) {
|
||||||
assert(mesh.is_valid());
|
Ref<Mesh> mesh =
|
||||||
if (!mat_exterior.is_valid())
|
layout_parts->get_item_mesh(
|
||||||
mat_exterior =
|
item_data[j]
|
||||||
mesh->surface_get_material(0);
|
.items[i]
|
||||||
tool_exterior.append_from(
|
.first);
|
||||||
mesh, 0,
|
assert(mesh.is_valid());
|
||||||
offset * base_transform *
|
if (!item_data[j].mat.is_valid())
|
||||||
items_exterior[i].second);
|
item_data[j].mat =
|
||||||
}
|
mesh->surface_get_material(
|
||||||
for (i = 0; i < items_interior.size(); i++) {
|
0);
|
||||||
Ref<Mesh> mesh = layout_parts->get_item_mesh(
|
item_data[j].tool.append_from(
|
||||||
items_interior[i].first);
|
mesh, 0,
|
||||||
assert(mesh.is_valid());
|
offset * base_transform *
|
||||||
if (!mat_interior.is_valid())
|
item_data[j]
|
||||||
mat_interior =
|
.items[i]
|
||||||
mesh->surface_get_material(0);
|
.second);
|
||||||
tool_interior.append_from(
|
}
|
||||||
mesh, 0,
|
|
||||||
offset * base_transform *
|
|
||||||
items_interior[i].second);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Array arr_exterior = tool_exterior.commit_to_arrays();
|
for (k = 0; k < 2; k++) {
|
||||||
layout_mesh_exterior->add_surface_from_arrays(
|
Array arr = item_data[k].tool.commit_to_arrays();
|
||||||
Mesh::PRIMITIVE_TRIANGLES, arr_exterior, Array(),
|
item_data[k].layout_mesh->add_surface_from_arrays(
|
||||||
Mesh::ARRAY_COMPRESS_DEFAULT);
|
Mesh::PRIMITIVE_TRIANGLES, arr, Array(),
|
||||||
if (!mat_exterior.is_valid()) {
|
Mesh::ARRAY_COMPRESS_DEFAULT);
|
||||||
Ref<SpatialMaterial> spmat;
|
if (!item_data[k].mat.is_valid()) {
|
||||||
spmat.instance();
|
Ref<SpatialMaterial> spmat;
|
||||||
spmat->set_albedo(Color(1.0f, 0.6f, 0.6f));
|
spmat.instance();
|
||||||
mat_exterior = spmat;
|
spmat->set_albedo(Color(1.0f, 0.6f, 0.6f));
|
||||||
|
item_data[k].mat = spmat;
|
||||||
|
}
|
||||||
|
item_data[k].layout_mesh->surface_set_material(
|
||||||
|
0, item_data[k].mat);
|
||||||
|
display_mi[k]->hide();
|
||||||
|
display_mi[k]->set_mesh(item_data[k].layout_mesh);
|
||||||
|
item_data[k].layout_mesh->set_storage_mode(
|
||||||
|
Mesh::STORAGE_MODE_CPU_AND_GPU);
|
||||||
|
display_mi[k]->show();
|
||||||
}
|
}
|
||||||
Array arr_interior = tool_interior.commit_to_arrays();
|
|
||||||
layout_mesh_interior->add_surface_from_arrays(
|
|
||||||
Mesh::PRIMITIVE_TRIANGLES, arr_interior, Array(),
|
|
||||||
Mesh::ARRAY_COMPRESS_DEFAULT);
|
|
||||||
if (!mat_interior.is_valid()) {
|
|
||||||
Ref<SpatialMaterial> spmat;
|
|
||||||
spmat.instance();
|
|
||||||
spmat->set_albedo(Color(1.0f, 0.6f, 0.6f));
|
|
||||||
mat_interior = spmat;
|
|
||||||
}
|
|
||||||
layout_mesh_exterior->surface_set_material(0, mat_exterior);
|
|
||||||
display_mi_exterior->hide();
|
|
||||||
display_mi_exterior->set_mesh(layout_mesh_exterior);
|
|
||||||
layout_mesh_exterior->set_storage_mode(
|
|
||||||
Mesh::STORAGE_MODE_CPU_AND_GPU);
|
|
||||||
display_mi_exterior->show();
|
|
||||||
layout_mesh_interior->surface_set_material(0, mat_interior);
|
|
||||||
display_mi_interior->hide();
|
|
||||||
display_mi_interior->set_mesh(layout_mesh_interior);
|
|
||||||
layout_mesh_interior->set_storage_mode(
|
|
||||||
Mesh::STORAGE_MODE_CPU_AND_GPU);
|
|
||||||
display_mi_interior->show();
|
|
||||||
}
|
}
|
||||||
void resize()
|
void resize()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user