diff --git a/Editor/ObjectWindow.cpp b/Editor/ObjectWindow.cpp index 88b2d8085..3d031901a 100644 --- a/Editor/ObjectWindow.cpp +++ b/Editor/ObjectWindow.cpp @@ -61,8 +61,11 @@ struct Atlas_Dim uint32_t width = 0; uint32_t height = 0; }; -static Atlas_Dim GenerateMeshAtlas(MeshComponent& meshcomponent, uint32_t resolution) +static Atlas_Dim GenerateMeshAtlas(Scene& scene, Entity entity, uint32_t resolution) { + MeshComponent& meshcomponent = *scene.meshes.GetComponent(entity); + SoftBodyPhysicsComponent* softbody = scene.softbodies.GetComponent(entity); + Atlas_Dim dim; xatlas::Atlas* atlas = xatlas::Create(); @@ -114,16 +117,24 @@ static Atlas_Dim GenerateMeshAtlas(MeshComponent& meshcomponent, uint32_t resolu wi::vector positions(mesh.vertexCount); wi::vector atlas(mesh.vertexCount); wi::vector normals; + wi::vector winds; wi::vector tangents; wi::vector uvset_0; wi::vector uvset_1; wi::vector colors; wi::vector boneindices; wi::vector boneweights; + wi::vector boneindices2; + wi::vector boneweights2; + wi::vector softbodyweights; if (!meshcomponent.vertex_normals.empty()) { normals.resize(mesh.vertexCount); } + if (!meshcomponent.vertex_windweights.empty()) + { + winds.resize(mesh.vertexCount); + } if (!meshcomponent.vertex_tangents.empty()) { tangents.resize(mesh.vertexCount); @@ -148,6 +159,18 @@ static Atlas_Dim GenerateMeshAtlas(MeshComponent& meshcomponent, uint32_t resolu { boneweights.resize(mesh.vertexCount); } + if (!meshcomponent.vertex_boneindices2.empty()) + { + boneindices2.resize(mesh.vertexCount); + } + if (!meshcomponent.vertex_boneweights2.empty()) + { + boneweights2.resize(mesh.vertexCount); + } + if (softbody != nullptr && !softbody->weights.empty()) + { + softbodyweights.resize(mesh.vertexCount); + } for (uint32_t j = 0; j < mesh.indexCount; ++j) { @@ -161,6 +184,10 @@ static Atlas_Dim GenerateMeshAtlas(MeshComponent& meshcomponent, uint32_t resolu { normals[ind] = meshcomponent.vertex_normals[v.xref]; } + if (!winds.empty()) + { + winds[ind] = meshcomponent.vertex_windweights[v.xref]; + } if (!tangents.empty()) { tangents[ind] = meshcomponent.vertex_tangents[v.xref]; @@ -185,6 +212,18 @@ static Atlas_Dim GenerateMeshAtlas(MeshComponent& meshcomponent, uint32_t resolu { boneweights[ind] = meshcomponent.vertex_boneweights[v.xref]; } + if (!boneindices2.empty()) + { + boneindices2[ind] = meshcomponent.vertex_boneindices2[v.xref]; + } + if (!boneweights2.empty()) + { + boneweights2[ind] = meshcomponent.vertex_boneweights2[v.xref]; + } + if (softbody != nullptr && !softbodyweights.empty()) + { + softbodyweights[ind] = softbody->weights[v.xref]; + } } meshcomponent.vertex_positions = positions; @@ -193,6 +232,10 @@ static Atlas_Dim GenerateMeshAtlas(MeshComponent& meshcomponent, uint32_t resolu { meshcomponent.vertex_normals = normals; } + if (!winds.empty()) + { + meshcomponent.vertex_windweights = winds; + } if (!tangents.empty()) { meshcomponent.vertex_tangents = tangents; @@ -217,8 +260,29 @@ static Atlas_Dim GenerateMeshAtlas(MeshComponent& meshcomponent, uint32_t resolu { meshcomponent.vertex_boneweights = boneweights; } + if (!boneindices2.empty()) + { + meshcomponent.vertex_boneindices2 = boneindices2; + } + if (!boneweights2.empty()) + { + meshcomponent.vertex_boneweights2 = boneweights2; + } + if (softbody != nullptr && !softbodyweights.empty()) + { + softbody->weights = softbodyweights; + } meshcomponent.CreateRenderData(); + if (softbody != nullptr) + { + // Recreate softbody + softbody->physicsobject = {}; + softbody->physicsIndices.clear(); + softbody->physicsToGraphicsVertexMapping.clear(); + softbody->CreateFromMesh(meshcomponent); + } + } //// DEBUG @@ -601,7 +665,7 @@ void ObjectWindow::Create(EditorComponent* _editor) UV_GEN_TYPE gen_type = (UV_GEN_TYPE)lightmapSourceUVSetComboBox.GetSelected(); wi::unordered_set gen_objects; - wi::unordered_map gen_meshes; + wi::unordered_map gen_meshes; for (auto& x : this->editor->translator.selected) { @@ -613,7 +677,7 @@ void ObjectWindow::Create(EditorComponent* _editor) if (meshcomponent != nullptr) { gen_objects.insert(objectcomponent); - gen_meshes[meshcomponent] = Atlas_Dim(); + gen_meshes[objectcomponent->meshID] = Atlas_Dim(); } } @@ -623,7 +687,7 @@ void ObjectWindow::Create(EditorComponent* _editor) for (auto& it : gen_meshes) { - MeshComponent& mesh = *it.first; + MeshComponent& mesh = *scene.meshes.GetComponent(it.first); if (gen_type == UV_GEN_COPY_UVSET_0) { mesh.vertex_atlas = mesh.vertex_uvset_0; @@ -637,7 +701,7 @@ void ObjectWindow::Create(EditorComponent* _editor) else if (gen_type == UV_GEN_GENERATE_ATLAS) { wi::jobsystem::Execute(ctx, [&](wi::jobsystem::JobArgs args) { - it.second = GenerateMeshAtlas(mesh, (uint32_t)lightmapResolutionSlider.GetValue()); + it.second = GenerateMeshAtlas(scene, it.first, (uint32_t)lightmapResolutionSlider.GetValue()); }); } } @@ -646,11 +710,10 @@ void ObjectWindow::Create(EditorComponent* _editor) for (auto& x : gen_objects) { x->ClearLightmap(); - MeshComponent* meshcomponent = scene.meshes.GetComponent(x->meshID); if (gen_type == UV_GEN_GENERATE_ATLAS) { - x->lightmapWidth = gen_meshes.at(meshcomponent).width; - x->lightmapHeight = gen_meshes.at(meshcomponent).height; + x->lightmapWidth = gen_meshes.at(x->meshID).width; + x->lightmapHeight = gen_meshes.at(x->meshID).height; } else {