|
|
|
@@ -31,18 +31,17 @@ Ref<MeshSliceState> MeshEditingLibrary::slice_mesh(const Ref<MeshEditSliceInput>
|
|
|
|
|
return fresh_state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MeshEditingLibrary::slice_mesh_init(Ref<MeshSliceState> state)
|
|
|
|
|
float MeshEditingLibrary::slice_mesh_init(Ref<MeshSliceState> state)
|
|
|
|
|
{
|
|
|
|
|
{ // Initialise the state here
|
|
|
|
|
// const Time *time = Time::get_singleton();
|
|
|
|
|
const Time *time = Time::get_singleton();
|
|
|
|
|
const float start_time = time->get_ticks_msec();
|
|
|
|
|
|
|
|
|
|
// PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Started slicing mesh at ", time->get_ticks_msec(), "ms");
|
|
|
|
|
{ // Initialise the state here
|
|
|
|
|
PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Started slicing mesh at ", time->get_ticks_msec(), "ms");
|
|
|
|
|
|
|
|
|
|
state->original_mesh = state->input->mesh_instance->get_mesh();
|
|
|
|
|
state->num_surfaces = state->original_mesh->get_surface_count();
|
|
|
|
|
|
|
|
|
|
// PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Got skinned vertices at ", time->get_ticks_msec(), "ms");
|
|
|
|
|
|
|
|
|
|
state->surface_arrays_list.resize(state->num_surfaces);
|
|
|
|
|
state->skinned_vertex_positions.resize(state->num_surfaces);
|
|
|
|
|
state->skinned_vertex_transforms.resize(state->num_surfaces);
|
|
|
|
@@ -90,7 +89,8 @@ void MeshEditingLibrary::slice_mesh_init(Ref<MeshSliceState> state)
|
|
|
|
|
|
|
|
|
|
for (state->surface; state->surface < state->num_surfaces; state->surface++)
|
|
|
|
|
{
|
|
|
|
|
state->skinned_vertex_positions[state->surface] = MeshEditingLibrary::get_skinned_vertex_positions(state->surface, state->original_mesh, state->input->skeleton, state->skinned_vertex_transforms[state->surface]);
|
|
|
|
|
// if ((time->get_ticks_msec() - start_time) > MESH_EDITING_SLICE_LOOP_LIMIT)
|
|
|
|
|
// return time->get_ticks_msec() - start_time;
|
|
|
|
|
|
|
|
|
|
state->surface_arrays_list[state->surface] = state->original_mesh->surface_get_arrays(state->surface);
|
|
|
|
|
const PackedVector3Array &surface_vertex_array = state->surface_arrays_list[state->surface][ArrayMesh::ARRAY_VERTEX];
|
|
|
|
@@ -127,15 +127,24 @@ void MeshEditingLibrary::slice_mesh_init(Ref<MeshSliceState> state)
|
|
|
|
|
state->num_custom0_per_vertex[state->surface] = surface_num_custom0_per_vertex;
|
|
|
|
|
|
|
|
|
|
state->vertex_distances[state->surface].resize(num_vertices);
|
|
|
|
|
|
|
|
|
|
state->skinned_vertex_positions[state->surface] = MeshEditingLibrary::get_skinned_vertex_positions(state->surface, state->original_mesh, state->input->skeleton, state->skinned_vertex_transforms[state->surface]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Got skinned vertices at ", time->get_ticks_msec(), "ms");
|
|
|
|
|
|
|
|
|
|
state->surface = 0;
|
|
|
|
|
state->element = 0;
|
|
|
|
|
state->current_stage = MeshEditSliceStage::SLICE_STAGE_PLANE_SPLIT;
|
|
|
|
|
|
|
|
|
|
return time->get_ticks_msec() - start_time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MeshEditingLibrary::slice_mesh_plane_split(Ref<MeshSliceState> state)
|
|
|
|
|
float MeshEditingLibrary::slice_mesh_plane_split(Ref<MeshSliceState> state)
|
|
|
|
|
{
|
|
|
|
|
const Time *time = Time::get_singleton();
|
|
|
|
|
const float start_time = time->get_ticks_msec();
|
|
|
|
|
|
|
|
|
|
for (state->surface; state->surface < state->num_surfaces; state->surface++)
|
|
|
|
|
{
|
|
|
|
|
const PackedVector3Array &surface_vertex_array = state->surface_arrays_list[state->surface][ArrayMesh::ARRAY_VERTEX];
|
|
|
|
@@ -170,6 +179,9 @@ void MeshEditingLibrary::slice_mesh_plane_split(Ref<MeshSliceState> state)
|
|
|
|
|
|
|
|
|
|
for (state->element; state->element < num_vertices; state->element++)
|
|
|
|
|
{
|
|
|
|
|
if ((time->get_ticks_msec() - start_time) > MESH_EDITING_SLICE_LOOP_LIMIT)
|
|
|
|
|
return time->get_ticks_msec() - start_time;
|
|
|
|
|
|
|
|
|
|
vertex_distances[state->element] = state->input->local_plane.distance_to(state->skinned_vertex_positions[state->surface][state->element]);
|
|
|
|
|
|
|
|
|
|
if (vertex_distances[state->element] >= 0.0f)
|
|
|
|
@@ -246,7 +258,7 @@ void MeshEditingLibrary::slice_mesh_plane_split(Ref<MeshSliceState> state)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Surface ", surface, " sorted by plane distance at ", time->get_ticks_msec(), "ms");
|
|
|
|
|
PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Surface ", state->surface, " sorted by plane distance at ", time->get_ticks_msec(), "ms");
|
|
|
|
|
|
|
|
|
|
state->element = 0;
|
|
|
|
|
}
|
|
|
|
@@ -255,14 +267,17 @@ void MeshEditingLibrary::slice_mesh_plane_split(Ref<MeshSliceState> state)
|
|
|
|
|
|
|
|
|
|
state->surface = 0;
|
|
|
|
|
state->current_stage = MeshEditSliceStage::SLICE_STAGE_EDGE_SPLIT;
|
|
|
|
|
|
|
|
|
|
return time->get_ticks_msec() - start_time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MeshEditingLibrary::slice_mesh_edge_split(Ref<MeshSliceState> state)
|
|
|
|
|
float MeshEditingLibrary::slice_mesh_edge_split(Ref<MeshSliceState> state)
|
|
|
|
|
{
|
|
|
|
|
const Time *time = Time::get_singleton();
|
|
|
|
|
const float start_time = time->get_ticks_msec();
|
|
|
|
|
|
|
|
|
|
for (state->surface; state->surface < state->num_surfaces; state->surface++)
|
|
|
|
|
{
|
|
|
|
|
Ref<Material> original_material = state->original_mesh->surface_get_material(state->surface);
|
|
|
|
|
|
|
|
|
|
const PackedVector3Array &surface_vertex_array = state->surface_arrays_list[state->surface][ArrayMesh::ARRAY_VERTEX];
|
|
|
|
|
const PackedVector3Array &surface_normal_array = state->surface_arrays_list[state->surface][ArrayMesh::ARRAY_NORMAL];
|
|
|
|
|
const PackedFloat32Array &surface_tangent_array = state->surface_arrays_list[state->surface][ArrayMesh::ARRAY_TANGENT];
|
|
|
|
@@ -307,6 +322,9 @@ void MeshEditingLibrary::slice_mesh_edge_split(Ref<MeshSliceState> state)
|
|
|
|
|
const uint32_t num_triangles = surface_index_array.size();
|
|
|
|
|
for (state->element; state->element < num_triangles; state->element += 3)
|
|
|
|
|
{
|
|
|
|
|
if ((time->get_ticks_msec() - start_time) > MESH_EDITING_SLICE_LOOP_LIMIT)
|
|
|
|
|
return time->get_ticks_msec() - start_time;
|
|
|
|
|
|
|
|
|
|
uint32_t base_v[3];
|
|
|
|
|
std::map<uint32_t, uint32_t>::iterator sliced_v[3];
|
|
|
|
|
std::map<uint32_t, uint32_t>::iterator sliced_other_v[3];
|
|
|
|
@@ -570,6 +588,8 @@ void MeshEditingLibrary::slice_mesh_edge_split(Ref<MeshSliceState> state)
|
|
|
|
|
state->element = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ref<Material> original_material = state->original_mesh->surface_get_material(state->surface);
|
|
|
|
|
|
|
|
|
|
int64_t array_format_bit_mask = Mesh::ARRAY_FORMAT_VERTEX;
|
|
|
|
|
if (has_normal) array_format_bit_mask |= Mesh::ARRAY_FORMAT_NORMAL;
|
|
|
|
|
if (has_tangent) array_format_bit_mask |= Mesh::ARRAY_FORMAT_TANGENT;
|
|
|
|
@@ -621,28 +641,29 @@ void MeshEditingLibrary::slice_mesh_edge_split(Ref<MeshSliceState> state)
|
|
|
|
|
state->other_half->surface_set_material(next_surface, original_material);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Surface ", surface, " split edges at ", time->get_ticks_msec(), "ms");
|
|
|
|
|
PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Surface ", state->surface, " split edges at ", time->get_ticks_msec(), "ms");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
state->surface = 0;
|
|
|
|
|
state->current_stage = MeshEditSliceStage::SLICE_STAGE_APPLY_CAP;
|
|
|
|
|
|
|
|
|
|
return time->get_ticks_msec() - start_time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MeshEditingLibrary::slice_mesh_apply_cap(Ref<MeshSliceState> state)
|
|
|
|
|
float MeshEditingLibrary::slice_mesh_apply_cap(Ref<MeshSliceState> state)
|
|
|
|
|
{
|
|
|
|
|
const Time *time = Time::get_singleton();
|
|
|
|
|
const float start_time = time->get_ticks_msec();
|
|
|
|
|
|
|
|
|
|
if (state->clip_edges.size() > 0)
|
|
|
|
|
{
|
|
|
|
|
MeshSlicePlaneOrientation uv_plane = MeshSlicePlaneOrientation::Z;
|
|
|
|
|
const Basis &mesh_instance_basis = state->input->mesh_instance->get_basis();
|
|
|
|
|
const Vector3 &local_plane_normal = state->input->local_plane.get_normal();
|
|
|
|
|
if (UtilityFunctions::absf(local_plane_normal.dot(mesh_instance_basis.xform(Vector3(0.0f, 1.0f, 0.0f)))) > 0.5f)
|
|
|
|
|
{
|
|
|
|
|
uv_plane = MeshSlicePlaneOrientation::Y;
|
|
|
|
|
}
|
|
|
|
|
else if (UtilityFunctions::absf(local_plane_normal.dot(mesh_instance_basis.xform(Vector3(1.0f, 0.0f, 0.0f)))) > 0.5f)
|
|
|
|
|
{
|
|
|
|
|
uv_plane = MeshSlicePlaneOrientation::X;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SurfaceTool *surface_tool_first_half = memnew(SurfaceTool);
|
|
|
|
|
SurfaceTool *surface_tool_other_half = memnew(SurfaceTool);
|
|
|
|
@@ -770,17 +791,17 @@ void MeshEditingLibrary::slice_mesh_apply_cap(Ref<MeshSliceState> state)
|
|
|
|
|
|
|
|
|
|
memdelete(surface_tool_first_half);
|
|
|
|
|
memdelete(surface_tool_other_half);
|
|
|
|
|
|
|
|
|
|
// PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Created cap surfaces at ", time->get_ticks_msec(), "ms");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Generated final cap surface at ", time->get_ticks_msec(), "ms");
|
|
|
|
|
PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Generated final cap surface at ", time->get_ticks_msec(), "ms");
|
|
|
|
|
|
|
|
|
|
state->output->original_skeleton = state->input->skeleton;
|
|
|
|
|
state->output->main_half = state->first_half;
|
|
|
|
|
state->output->secondary_half = state->other_half;
|
|
|
|
|
|
|
|
|
|
state->current_stage = MeshEditSliceStage::SLICE_STAGE_COMPLETE;
|
|
|
|
|
|
|
|
|
|
return time->get_ticks_msec() - start_time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|