Skip to content

Commit

Permalink
fixed asset import
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed Dec 6, 2024
1 parent d680018 commit 8386875
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
8 changes: 7 additions & 1 deletion src/animation/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ Controller::~Controller() {

void Controller::unload() {
for (const AnimationEntry& entry : m_animation_entries) {
if (entry.animation) entry.animation->decRefCount();
if (entry.animation) {
removeDependency(*entry.animation);
entry.animation->decRefCount();
}
}
m_animation_entries.clear();
m_bone_masks.clear();
Expand Down Expand Up @@ -122,6 +125,9 @@ bool Controller::deserialize(InputMemoryStream& stream) {
stream.read(entry.set);
const char* path = stream.readString();
entry.animation = path[0] ? m_resource_manager.getOwner().load<Animation>(Path(path)) : nullptr;
if(entry.animation) {
addDependency(*entry.animation);
}
}

NodeType type;
Expand Down
13 changes: 10 additions & 3 deletions src/editor/asset_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ struct AssetCompilerImpl : AssetCompiler {
OutputMemoryStream compressed(m_allocator);
if (data.length() > COMPRESSION_SIZE_LIMIT) {
if (!m_app.getEngine().compress(data, compressed)) {
logError("Could not compress ", path);
return false;
logWarning("Could not compress ", path, ", using uncompressed file.");
compressed.clear();
}
}

Expand All @@ -227,7 +227,7 @@ struct AssetCompilerImpl : AssetCompiler {
CompiledResourceHeader header;
header.decompressed_size = data.length();
const u32 compressed_size = (u32)compressed.size();
if (data.length() > COMPRESSION_SIZE_LIMIT && compressed_size < i32(data.length() / 4 * 3)) {
if (data.length() > COMPRESSION_SIZE_LIMIT && compressed_size > 0 && compressed_size < i32(data.length() / 4 * 3)) {
header.flags |= CompiledResourceHeader::COMPRESSED;
(void)file.write(&header, sizeof(header));
(void)file.write(compressed.data(), compressed_size);
Expand All @@ -238,6 +238,13 @@ struct AssetCompilerImpl : AssetCompiler {
}
file.close();
if (file.isError()) logError("Could not write ", out_path);
jobs::MutexGuard guard(m_resources_mutex);
auto iter = m_resources.find(path.getHash());
if (!iter.isValid()) {
// Resource scane is async, so it's not guaranteed that the resource is in the m_resources list at this point
// If it's not, we don't need to add it to the list
m_resources.insert(path.getHash(), {path, getResourceType(path), dirHash(path)});
}
return !file.isError();
}

Expand Down
15 changes: 12 additions & 3 deletions src/editor/profiler_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -900,13 +900,22 @@ struct ProfilerUIImpl final : StudioApp::GUIPlugin {
ImGui::DragScalar("##fs", ImGuiDataType_U64, &m_resource_size_filter, 1000);

ImGui::Indent();
// TODO multiple plugins can handle the same resource type (e.g. fbx plugin and gltf plugin)
// this duplicates the UI for that resource type
for (const AssetBrowser::IPlugin* plugin : m_app.getAssetBrowser().getPlugins()) {
ResourceManager* resource_manager = m_engine.getResourceManager().get(plugin->getResourceType());
if (!resource_manager) continue;
if (!ImGui::CollapsingHeader(plugin->getLabel())) continue;
ImGui::PushID(plugin);
if (!ImGui::CollapsingHeader(plugin->getLabel())) {
ImGui::PopID();
continue;
}

ResourceManager::ResourceTable& resources = resource_manager->getResourceTable();
if (!ImGui::BeginTable("resc", 4)) continue;
if (!ImGui::BeginTable("resc", 4)) {
ImGui::PopID();
continue;
}

ImGui::TableSetupColumn("Path");
ImGui::TableSetupColumn("Size");
Expand All @@ -916,7 +925,6 @@ struct ProfilerUIImpl final : StudioApp::GUIPlugin {

u64 sum = 0;
for (const Resource* res : resources) {
if (res->isEmpty()) continue;
if (!m_resource_filter.pass(res->getPath())) continue;
if (m_resource_size_filter > res->getFileSize() / 1024) continue;

Expand Down Expand Up @@ -951,6 +959,7 @@ struct ProfilerUIImpl final : StudioApp::GUIPlugin {
ImGui::TableNextColumn();

ImGui::EndTable();
ImGui::PopID();
}
ImGui::Unindent();
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/editor/fbx_importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ struct FBXImporter : ModelImporter {
if (mesh_idx >= m_meshes.size()) break;

ImportMesh& import_mesh = m_meshes[mesh_idx];
import_mesh.index_size = areIndices16Bit(import_mesh) ? 2 : 4;
const ofbx::Mesh* mesh = m_fbx_meshes[import_mesh.mesh_index];
import_mesh.vertex_size = getVertexSize(*mesh, import_mesh.is_skinned, meta);
const ofbx::GeometryData& geom = mesh->getGeometryData();
Expand Down Expand Up @@ -469,6 +468,7 @@ struct FBXImporter : ModelImporter {
}

remap(unindexed_triangles, import_mesh);
import_mesh.index_size = areIndices16Bit(import_mesh) ? 2 : 4;
}
});

Expand Down
4 changes: 2 additions & 2 deletions src/renderer/editor/model_importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ void ModelImporter::createImpostorTextures(Model* model, ImpostorTexturesContext

bool ModelImporter::write(const Path& src, const ModelMeta& meta) {
const Path filepath = Path(ResourcePath::getResource(src));
if (!writeModel(src, meta)) return false;
if (!meta.split && !writeModel(src, meta)) return false;
if (!writeMaterials(filepath, meta, false)) return false;
if (!writeAnimations(filepath, meta)) return false;
if (meta.split) {
Expand Down Expand Up @@ -1274,7 +1274,7 @@ bool ModelImporter::writeModel(const Path& src, const ModelMeta& meta) {
writeLODs(meta);

AssetCompiler& compiler = m_app.getAssetCompiler();
return compiler.writeCompiledResource(Path(src), Span(m_out_file.data(), (i32)m_out_file.size()));
return compiler.writeCompiledResource(Path(src), Span(m_out_file.data(), m_out_file.size()));
}

bool ModelImporter::writeAnimations(const Path& src, const ModelMeta& meta) {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/editor/model_importer.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct ModelImporter {
u32 vertex_size = 0xffFFffFF;
Array<AttributeDesc> attributes;
Array<u32> indices;
u32 index_size;
u32 index_size = 0;
Local<Array<u32>> autolod_indices[4];
AABB aabb;
float origin_radius_squared;
Expand Down

0 comments on commit 8386875

Please sign in to comment.