FProceduralMeshTriData CreatureCore::GetProcMeshData() { if (!creature_manager) { FProceduralMeshTriData ret_data(nullptr, nullptr, nullptr, 0, 0, ®ion_alphas, update_lock); return ret_data; } auto cur_creature = creature_manager->GetCreature(); int32 num_points = cur_creature->GetTotalNumPoints(); int32 num_indices = cur_creature->GetTotalNumIndices(); glm::uint32 * cur_idx = cur_creature->GetGlobalIndices(); glm::float32 * cur_pts = cur_creature->GetRenderPts(); glm::float32 * cur_uvs = cur_creature->GetGlobalUvs(); if (region_alphas.Num() != num_points) { region_alphas.SetNum(num_points); } FProceduralMeshTriData ret_data(cur_idx, cur_pts, cur_uvs, num_points, num_indices, ®ion_alphas, update_lock); return ret_data; }
void ACreatureActor::UpdateCreatureRender() { auto cur_creature = creature_manager->GetCreature(); int num_triangles = cur_creature->GetTotalNumIndices() / 3; glm::uint32 * cur_idx = cur_creature->GetGlobalIndices(); glm::float32 * cur_pts = cur_creature->GetRenderPts(); glm::float32 * cur_uvs = cur_creature->GetGlobalUvs(); // Update depth per region std::vector<meshRenderRegion *>& cur_regions = cur_creature->GetRenderComposition()->getRegions(); float region_z = 0.0f, delta_z = -0.01f; for (auto& single_region : cur_regions) { glm::float32 * region_pts = cur_pts + (single_region->getStartPtIndex() * 3); for (size_t i = 0; i < single_region->getNumPts(); i++) { region_pts[2] = region_z; region_pts += 3; } region_z += delta_z; } // Build render triangles TArray<FProceduralMeshTriangle>& write_triangles = mesh->GetProceduralTriangles(); static const FColor White(255, 255, 255, 255); int cur_pt_idx = 0, cur_uv_idx = 0; for (int i = 0; i < num_triangles; i++) { int real_idx_1 = cur_idx[0]; int real_idx_2 = cur_idx[1]; int real_idx_3 = cur_idx[2]; FProceduralMeshTriangle triangle; cur_pt_idx = real_idx_1 * 3; cur_uv_idx = real_idx_1 * 2; triangle.Vertex0.Position.Set(cur_pts[cur_pt_idx], cur_pts[cur_pt_idx + 1], cur_pts[cur_pt_idx + 2]); triangle.Vertex0.Color = White; triangle.Vertex0.U = cur_uvs[cur_uv_idx]; triangle.Vertex0.V = cur_uvs[cur_uv_idx + 1]; cur_pt_idx = real_idx_2 * 3; cur_uv_idx = real_idx_2 * 2; triangle.Vertex1.Position.Set(cur_pts[cur_pt_idx], cur_pts[cur_pt_idx + 1], cur_pts[cur_pt_idx + 2]); triangle.Vertex1.Color = White; triangle.Vertex1.U = cur_uvs[cur_uv_idx]; triangle.Vertex1.V = cur_uvs[cur_uv_idx + 1]; cur_pt_idx = real_idx_3 * 3; cur_uv_idx = real_idx_3 * 2; triangle.Vertex2.Position.Set(cur_pts[cur_pt_idx], cur_pts[cur_pt_idx + 1], cur_pts[cur_pt_idx + 2]); triangle.Vertex2.Color = White; triangle.Vertex2.U = cur_uvs[cur_uv_idx]; triangle.Vertex2.V = cur_uvs[cur_uv_idx + 1]; write_triangles[i] = triangle; cur_idx += 3; } //mesh->SetProceduralMeshTriangles(draw_triangles); mesh->ForceAnUpdate(); }
void CreatureCore::UpdateCreatureRender() { auto cur_creature = creature_manager->GetCreature(); int num_triangles = cur_creature->GetTotalNumIndices() / 3; glm::uint32 * cur_idx = cur_creature->GetGlobalIndices(); glm::float32 * cur_pts = cur_creature->GetRenderPts(); glm::float32 * cur_uvs = cur_creature->GetGlobalUvs(); // Update depth per region std::vector<meshRenderRegion *>& cur_regions = cur_creature->GetRenderComposition()->getRegions(); float region_z = 0.0f, delta_z = region_overlap_z_delta; if (region_custom_order.Num() != cur_regions.size()) { // Normal update in default order for (auto& single_region : cur_regions) { glm::float32 * region_pts = cur_pts + (single_region->getStartPtIndex() * 3); for (size_t i = 0; i < single_region->getNumPts(); i++) { region_pts[2] = region_z; region_pts += 3; } region_z += delta_z; } } else { // Custom order update auto& regions_map = cur_creature->GetRenderComposition()->getRegionsMap(); for (auto& custom_region_name : region_custom_order) { auto real_name = ConvertToString(custom_region_name); if (regions_map.count(real_name) > 0) { auto single_region = regions_map[real_name]; glm::float32 * region_pts = cur_pts + (single_region->getStartPtIndex() * 3); for (size_t i = 0; i < single_region->getNumPts(); i++) { region_pts[2] = region_z; region_pts += 3; } region_z += delta_z; } } } // Build render triangles /* TArray<FProceduralMeshTriangle>& write_triangles = draw_tris; static const FColor White(255, 255, 255, 255); int cur_pt_idx = 0, cur_uv_idx = 0; const int x_id = 0; const int y_id = 2; const int z_id = 1; for (int i = 0; i < num_triangles; i++) { int real_idx_1 = cur_idx[0]; int real_idx_2 = cur_idx[1]; int real_idx_3 = cur_idx[2]; FProceduralMeshTriangle triangle; cur_pt_idx = real_idx_1 * 3; cur_uv_idx = real_idx_1 * 2; triangle.Vertex0.Position.Set(cur_pts[cur_pt_idx + x_id], cur_pts[cur_pt_idx + y_id], cur_pts[cur_pt_idx + z_id]); triangle.Vertex0.Color = White; triangle.Vertex0.U = cur_uvs[cur_uv_idx]; triangle.Vertex0.V = cur_uvs[cur_uv_idx + 1]; cur_pt_idx = real_idx_2 * 3; cur_uv_idx = real_idx_2 * 2; triangle.Vertex1.Position.Set(cur_pts[cur_pt_idx + x_id], cur_pts[cur_pt_idx + y_id], cur_pts[cur_pt_idx + z_id]); triangle.Vertex1.Color = White; triangle.Vertex1.U = cur_uvs[cur_uv_idx]; triangle.Vertex1.V = cur_uvs[cur_uv_idx + 1]; cur_pt_idx = real_idx_3 * 3; cur_uv_idx = real_idx_3 * 2; triangle.Vertex2.Position.Set(cur_pts[cur_pt_idx + x_id], cur_pts[cur_pt_idx + y_id], cur_pts[cur_pt_idx + z_id]); triangle.Vertex2.Color = White; triangle.Vertex2.U = cur_uvs[cur_uv_idx]; triangle.Vertex2.V = cur_uvs[cur_uv_idx + 1]; write_triangles[i] = triangle; cur_idx += 3; } */ // process the render regions ProcessRenderRegions(); }