From e8235c9bcc981893797958f2c547713f77c4ea94 Mon Sep 17 00:00:00 2001 From: Mikulas Florek Date: Mon, 25 Apr 2016 09:39:37 +0200 Subject: [PATCH] improved import asset lua API --- src/editor/import_asset_dialog.cpp | 48 +++++++++++++++++++----------- src/editor/import_asset_dialog.h | 1 + 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/editor/import_asset_dialog.cpp b/src/editor/import_asset_dialog.cpp index d7657598bf..11bde53aad 100644 --- a/src/editor/import_asset_dialog.cpp +++ b/src/editor/import_asset_dialog.cpp @@ -69,6 +69,22 @@ struct BillboardVertex #pragma pack() +static bool isSkinned(const aiMesh* mesh) { return mesh->mNumBones > 0; } + + +static bool isSkinned(const aiScene* scene, const aiMaterial* material) +{ + for (unsigned int i = 0; i < scene->mNumMeshes; ++i) + { + if (scene->mMaterials[scene->mMeshes[i]->mMaterialIndex] == material && isSkinned(scene->mMeshes[i])) + { + return true; + } + } + return false; +} + + static const aiNode* getOwner(const aiNode* node, int mesh_index) { for (int i = 0; i < (int)node->mNumMeshes; ++i) @@ -566,6 +582,7 @@ struct ImportTask : public Lumix::MT::Task material.alpha_cutout = false; material.material = scene->mMaterials[i]; material.texture_count = 0; + Lumix::copyString(material.shader, isSkinned(scene, scene->mMaterials[i]) ? "skinned" : "rigid"); auto types = {aiTextureType_DIFFUSE, aiTextureType_NORMALS, aiTextureType_HEIGHT}; for (auto type : types) { @@ -979,7 +996,7 @@ struct ConvertTask : public Lumix::MT::Task } file.writeText("{\n\t\"shader\" : \"shaders/"); - file.writeText(isSkinned(material.scene, material.material) ? "skinned" : "rigid"); + file.writeText(material.shader); file.writeText(".shd\"\n"); if (material.alpha_cutout) file << ",\n\t\"defines\" : [\"ALPHA_CUTOUT\"]"; @@ -1026,22 +1043,6 @@ struct ConvertTask : public Lumix::MT::Task } - static bool isSkinned(const aiMesh* mesh) { return mesh->mNumBones > 0; } - - - static bool isSkinned(const aiScene* scene, const aiMaterial* material) - { - for (unsigned int i = 0; i < scene->mNumMeshes; ++i) - { - if (scene->mMaterials[scene->mMeshes[i]->mMaterialIndex] == material && isSkinned(scene->mMeshes[i])) - { - return true; - } - } - return false; - } - - int getNodeIndex(const aiBone* bone) const { for (int i = 0; i < m_nodes.size(); ++i) @@ -2359,6 +2360,12 @@ int ImportAssetDialog::importAsset(lua_State* L) } lua_pop(L, 1); + if (lua_getfield(L, 2, "output_dir") == LUA_TSTRING) + { + Lumix::copyString(m_output_dir, Lumix::LuaWrapper::toType(L, -1)); + } + lua_pop(L, 1); + if (lua_getfield(L, 2, "srcs") == LUA_TTABLE) { lua_pushnil(L); @@ -2395,6 +2402,13 @@ int ImportAssetDialog::importAsset(lua_State* L) } lua_pop(L, 1); // "import" + if (lua_getfield(L, -1, "shader") == LUA_TSTRING) + { + Lumix::copyString(material->shader, Lumix::LuaWrapper::toType(L, -1)); + } + lua_pop(L, 1); // "import" + + if (lua_getfield(L, -1, "alpha_cutout") == LUA_TBOOLEAN) { material->alpha_cutout = Lumix::LuaWrapper::toType(L, -1); diff --git a/src/editor/import_asset_dialog.h b/src/editor/import_asset_dialog.h index fa703ad7f9..18e31c2072 100644 --- a/src/editor/import_asset_dialog.h +++ b/src/editor/import_asset_dialog.h @@ -44,6 +44,7 @@ struct ImportMaterial bool import; bool alpha_cutout; int texture_count; + char shader[20]; ImportTexture textures[16]; };