Skip to content

Commit

Permalink
improved import asset lua API
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed Apr 25, 2016
1 parent 9353d6c commit e8235c9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
48 changes: 31 additions & 17 deletions src/editor/import_asset_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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\"]";

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<const char*>(L, -1));
}
lua_pop(L, 1);

if (lua_getfield(L, 2, "srcs") == LUA_TTABLE)
{
lua_pushnil(L);
Expand Down Expand Up @@ -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<const char*>(L, -1));
}
lua_pop(L, 1); // "import"


if (lua_getfield(L, -1, "alpha_cutout") == LUA_TBOOLEAN)
{
material->alpha_cutout = Lumix::LuaWrapper::toType<bool>(L, -1);
Expand Down
1 change: 1 addition & 0 deletions src/editor/import_asset_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct ImportMaterial
bool import;
bool alpha_cutout;
int texture_count;
char shader[20];
ImportTexture textures[16];
};

Expand Down

0 comments on commit e8235c9

Please sign in to comment.