Skip to content

Commit

Permalink
skeleton - relative path
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed Sep 9, 2023
1 parent d6d295b commit 02c07a5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/animation/editor/animation_plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct AnimationAssetBrowserPlugin : AssetBrowser::IPlugin {
}

void deserialize(InputMemoryStream& blob) override { m_parent_meta.deserialize(blob, Path("undo/redo")); }
void serialize(OutputMemoryStream& blob) override { m_parent_meta.serialize(blob); }
void serialize(OutputMemoryStream& blob) override { m_parent_meta.serialize(blob, Path()); }

void saveUndo(bool changed) {
if (!changed) return;
Expand All @@ -101,7 +101,7 @@ struct AnimationAssetBrowserPlugin : AssetBrowser::IPlugin {

void save() {
OutputMemoryStream blob(m_app.getAllocator());
m_parent_meta.serialize(blob);
m_parent_meta.serialize(blob, m_resource->getPath());
m_app.getAssetCompiler().updateMeta(Path(Path::getResource(m_resource->getPath())), blob);
m_dirty = false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/animation/editor/controller_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1006,15 +1006,15 @@ struct ControllerEditorImpl : ControllerEditor, AssetBrowser::IPlugin, AssetComp

model_meta.skeleton = m_controller.m_skeleton;
OutputMemoryStream blob(m_allocator);
model_meta.serialize(blob);
model_meta.serialize(blob, src_path);
m_app.getAssetCompiler().updateMeta(src_path, blob);
}
else {
ModelMeta new_meta(m_allocator);
new_meta.skeleton = m_controller.m_skeleton;

OutputMemoryStream blob(m_allocator);
new_meta.serialize(blob);
new_meta.serialize(blob, src_path);
m_app.getAssetCompiler().updateMeta(src_path, blob);
}
}
Expand Down
17 changes: 15 additions & 2 deletions src/renderer/editor/model_meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct ModelMeta {

ModelMeta(IAllocator& allocator) : clips(allocator), root_motion_bone(allocator) {}

void serialize(OutputMemoryStream& blob) {
void serialize(OutputMemoryStream& blob, const Path& path) {
if(physics != FBXImporter::ImportConfig::Physics::NONE) blob << "\nphysics = \"" << toString(physics) << "\"";
blob << "\nlod_count = " << lod_count;

Expand Down Expand Up @@ -53,7 +53,16 @@ struct ModelMeta {
#undef WRITE_VALUE

if (root_motion_bone.length() > 0) blob << "\nroot_motion_bone = \"" << root_motion_bone << "\"";
if (!skeleton.isEmpty()) blob << "\nskeleton = \"" << skeleton << "\"";
if (!skeleton.isEmpty()) {
StringView dir = Path::getDir(Path::getResource(path));
if (!dir.empty() && startsWith(skeleton, dir)) {
blob << "\nskeleton_rel = \"" << skeleton.c_str() + dir.size();
}
else {
blob << "\nskeleton = \"" << skeleton;
}
blob << "\"";
}

if (!clips.empty()) {
blob << "\nclips = {";
Expand Down Expand Up @@ -141,6 +150,10 @@ struct ModelMeta {
char tmp[MAX_PATH];
if (LuaWrapper::getOptionalStringField(L, LUA_GLOBALSINDEX, "root_motion_bone", Span(tmp))) root_motion_bone = tmp;
if (LuaWrapper::getOptionalStringField(L, LUA_GLOBALSINDEX, "skeleton", Span(tmp))) skeleton = tmp;
if (LuaWrapper::getOptionalStringField(L, LUA_GLOBALSINDEX, "skeleton_rel", Span(tmp))) {
StringView dir = Path::getDir(Path::getResource(path));
skeleton = Path(dir, "/", tmp);
}
if (LuaWrapper::getOptionalStringField(L, LUA_GLOBALSINDEX, "physics", Span(tmp))) {
if (equalIStrings(tmp, "trimesh")) physics = FBXImporter::ImportConfig::Physics::TRIMESH;
else if (equalIStrings(tmp, "convex")) physics = FBXImporter::ImportConfig::Physics::CONVEX;
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/editor/render_plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,7 @@ struct ModelPlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin {
}

void deserialize(InputMemoryStream& blob) override { m_meta.deserialize(blob, Path("undo/redo")); }
void serialize(OutputMemoryStream& blob) override { m_meta.serialize(blob); }
void serialize(OutputMemoryStream& blob) override { m_meta.serialize(blob, Path()); }

void saveUndo(bool changed) {
if (!changed) return;
Expand All @@ -1934,7 +1934,7 @@ struct ModelPlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin {

void save() {
OutputMemoryStream blob(m_app.getAllocator());
m_meta.serialize(blob);
m_meta.serialize(blob, m_resource->getPath());
m_app.getAssetCompiler().updateMeta(m_resource->getPath(), blob);
m_dirty = false;
}
Expand Down

0 comments on commit 02c07a5

Please sign in to comment.