dungeon_crawler
diff prototype/src/tile.cc @ 21:0588f8a1a351
converting LIGHT meshes to lights
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 21 Aug 2012 06:33:36 +0300 |
parents | 67ae9fcb802c |
children | 7b65bba15553 |
line diff
1.1 --- a/prototype/src/tile.cc Tue Aug 21 04:57:33 2012 +0300 1.2 +++ b/prototype/src/tile.cc Tue Aug 21 06:33:36 2012 +0300 1.3 @@ -10,6 +10,7 @@ 1.4 using std::map; 1.5 1.6 static void build_nodemap(map<aiMesh*, aiNode*> *nmap, const aiScene *scn, aiNode *node); 1.7 +static PointLight *mesh_to_light(Mesh *m); 1.8 1.9 Tile::Tile(TileSet *tileset) 1.10 { 1.11 @@ -39,7 +40,7 @@ 1.12 map<aiMesh*, aiNode*> nodemap; 1.13 build_nodemap(&nodemap, scn, scn->mRootNode); 1.14 1.15 - load_lights(scn); 1.16 + //load_lights(scn); 1.17 load_meshes(scn, nodemap); 1.18 1.19 printf("loaded tile %s: %d meshes, %d lights\n", saved_fname, scn->mNumMeshes, scn->mNumLights); 1.20 @@ -55,6 +56,7 @@ 1.21 } 1.22 } 1.23 1.24 +/* 1.25 int Tile::load_lights(const aiScene *scn) 1.26 { 1.27 int count = 0; 1.28 @@ -86,6 +88,7 @@ 1.29 1.30 return count; 1.31 } 1.32 +*/ 1.33 1.34 int Tile::load_meshes(const aiScene *scn, const std::map<aiMesh*, aiNode*> &nmap) 1.35 { 1.36 @@ -117,9 +120,6 @@ 1.37 name = node->mName.data; 1.38 mesh->set_name(name); 1.39 } 1.40 - meshes.push_back(mesh); 1.41 - 1.42 - //printf(" mesh: \"%s\"", name); 1.43 1.44 // find which side is this mesh on 1.45 unsigned int side = 0; 1.46 @@ -138,10 +138,24 @@ 1.47 if(!side) { 1.48 side = TILE_ALL; 1.49 } 1.50 - //printf(" (0x0%x)\n", side); 1.51 - mesh_side.push_back(side); 1.52 1.53 - count++; 1.54 + // what a sordid hack... if the name contains "LIGHT", then make a light out of this 1.55 + // and destroy the mesh... 1.56 + if(strstr(name, "LIGHT")) { 1.57 + PointLight *lt = mesh_to_light(mesh); 1.58 + if(!lt) { 1.59 + fprintf(stderr, "failed to convert mesh %s to light\n", name); 1.60 + } else { 1.61 + lights.push_back(lt); 1.62 + light_side.push_back(side); 1.63 + } 1.64 + delete mesh; 1.65 + 1.66 + } else { 1.67 + meshes.push_back(mesh); 1.68 + mesh_side.push_back(side); 1.69 + count++; 1.70 + } 1.71 } 1.72 return count; 1.73 } 1.74 @@ -160,3 +174,16 @@ 1.75 build_nodemap(nmap, scn, node->mChildren[i]); 1.76 } 1.77 } 1.78 + 1.79 +static PointLight *mesh_to_light(Mesh *m) 1.80 +{ 1.81 + Vector3 center = m->get_bsph_center(); 1.82 + float rad = m->get_bsph_radius(); 1.83 + 1.84 + PointLight *lt = new PointLight(center); 1.85 + lt->set_radius(rad); 1.86 + 1.87 + lt->set_color(m->get_material().kd); 1.88 + 1.89 + return lt; 1.90 +}