Skip to content

Commit 33b8169

Browse files
committed
Fixed empty model with mesh geometry
1 parent 8bb1832 commit 33b8169

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

editor/Factory.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -740,9 +740,14 @@ std::string editor::Factory::createMeshComponent(int indentSpaces, EntityRegistr
740740
}
741741
}
742742

743-
// Skip inlining raw buffer/index data for model-backed meshes; the model
744-
// loader will repopulate the buffers at runtime from the source file.
745-
const bool hasModel = scene->findComponent<ModelComponent>(entity);
743+
// Skip inlining raw buffer/index data only for meshes backed by a model
744+
// file; the model loader will repopulate the buffers at runtime from the
745+
// source file. A ModelComponent with an empty filename loads no geometry,
746+
// so the mesh data must still be serialized to remain visible.
747+
bool hasModel = false;
748+
if (scene->findComponent<ModelComponent>(entity)) {
749+
hasModel = !scene->getComponent<ModelComponent>(entity).filename.empty();
750+
}
746751

747752
if (!hasModel && mesh.buffer.getSize() > 0){
748753
code << ind << "mesh.buffer.clearAll();\n";

editor/Stream.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2406,7 +2406,14 @@ YAML::Node editor::Stream::encodeComponents(const Entity entity, const EntityReg
24062406
}
24072407

24082408
if (signature.test(registry->getComponentId<MeshComponent>())) {
2409-
const bool isModel = signature.test(registry->getComponentId<ModelComponent>());
2409+
// Only treat the mesh as model-backed (and skip encoding its buffers and
2410+
// embedded textures) when the ModelComponent has a source file that will
2411+
// regenerate them at runtime. An empty filename loads no geometry, so the
2412+
// mesh data must still be encoded to remain visible.
2413+
bool isModel = false;
2414+
if (signature.test(registry->getComponentId<ModelComponent>())) {
2415+
isModel = !registry->getComponent<ModelComponent>(entity).filename.empty();
2416+
}
24102417
MeshComponent mesh = registry->getComponent<MeshComponent>(entity);
24112418
compNode[Catalog::getComponentName(ComponentType::MeshComponent, true)] = encodeMeshComponent(mesh, !isModel, !isModel);
24122419
}

0 commit comments

Comments
 (0)