Merge pull request #797 from MihailRis/update-parse-model

add skeleton_name argument to assets.parse_model
This commit is contained in:
MihailRis 2026-02-22 14:48:09 +03:00 • committed by GitHub
commit 413038dadc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 44 additions and 7 deletions

View file

@ -30,7 +30,11 @@ assets.parse_model(
-- Contents of the model file
content: str,
-- Model name after loading
name: str
name: str,
-- The skeleton name after loading. May be the same as the model name.
-- The model will be split by the named bones.
[optional]
skeleton_name: string
)
-- Creates a Canvas from a loaded texture.

View file

@ -31,7 +31,11 @@ assets.parse_model(
-- Содержимое файла модели
content: string,
-- Имя модели после загрузки
name: string
name: string,
-- Имя скелета после загрузки. Может совпадать с именем модели.
-- Модель будет разделена по именованным костям.
[опционально]
skeleton_name: string
)
-- Создаёт холст (Canvas) из загруженной текстуры

View file

@ -70,17 +70,46 @@ static int l_parse_model(lua::State* L) {
auto format = lua::require_lstring(L, 1);
auto string = lua::require_lstring(L, 2);
auto name = lua::require_string(L, 3);
std::string name = lua::require_string(L, 3);
std::string skeletonName;
if (lua::isstring(L, 4)) {
skeletonName = lua::require_string(L, 4);
}
if (format != "xml" && format != "vcm") {
throw std::runtime_error(
"unknown format " + util::quote(std::string(format))
);
}
auto vcmModel = vcm::parse(name, string, format == "xml");
if (format == "xml" || format == "vcm") {
auto vcmModel = vcm::parse(name, string, format == "xml");
if (skeletonName.empty()) {
assets.store(
std::make_unique<model::Model>(std::move(vcmModel.squash())), name
);
} else {
throw std::runtime_error(
"unknown format " + util::quote(std::string(format))
auto skeleton = std::make_unique<rigging::SkeletonConfig>(
std::move(*vcmModel.skeleton)
);
if (vcmModel.parts.size() > 1) {
for (auto& [partName, model] : vcmModel.parts) {
assets.store(
std::make_unique<model::Model>(std::move(model)),
name + "." + partName
);
}
for (auto& bone : skeleton->getBones()) {
bone->setModel(name + "." + bone->model.name);
}
} else {
assets.store(
std::make_unique<model::Model>(
std::move(vcmModel.parts["root"])), name
);
skeleton->getRoot()->setModel(name);
}
assets.store(std::move(skeleton), skeletonName);
}
return 0;
}