Browse Source

Merge branch 'meshUpdates'

master
cinnaboot 8 years ago
parent
commit
fa6c883ae1
  1. 269
      data/SPIDBOT1.dae
  2. 99
      data/block2.dae
  3. 208
      data/catepillar.dae
  4. 3
      src/hexgame.cpp
  5. 42
      src/mesh.cpp
  6. 2
      src/render_group.cpp

269
data/SPIDBOT1.dae

File diff suppressed because one or more lines are too long

99
data/block2.dae

@ -0,0 +1,99 @@
<?xml version="1.0" encoding="utf-8"?>
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<asset>
<contributor>
<author>Blender User</author>
<authoring_tool>Blender 2.79.0 commit date:2018-05-26, commit time:21:51, hash:32432d91bbe</authoring_tool>
</contributor>
<created>2018-08-25T18:17:18</created>
<modified>2018-08-25T18:17:18</modified>
<unit name="meter" meter="1"/>
<up_axis>Z_UP</up_axis>
</asset>
<library_images/>
<library_effects>
<effect id="Material_001-effect">
<profile_COMMON>
<technique sid="common">
<phong>
<emission>
<color sid="emission">0 0 0 1</color>
</emission>
<ambient>
<color sid="ambient">0 0 0 1</color>
</ambient>
<diffuse>
<color sid="diffuse">0.5199632 0.64 0.2266682 1</color>
</diffuse>
<specular>
<color sid="specular">0.5 0.5 0.5 1</color>
</specular>
<shininess>
<float sid="shininess">50</float>
</shininess>
<index_of_refraction>
<float sid="index_of_refraction">1</float>
</index_of_refraction>
</phong>
</technique>
</profile_COMMON>
</effect>
</library_effects>
<library_materials>
<material id="Material_001-material" name="Material_001">
<instance_effect url="#Material_001-effect"/>
</material>
</library_materials>
<library_geometries>
<geometry id="Cube-mesh" name="Cube">
<mesh>
<source id="Cube-mesh-positions">
<float_array id="Cube-mesh-positions-array" count="294">-1 -1 -1 -1 -1 1 -1 1 -1 -1 1 1 1 -1 -1 1 -1 1 1 1 -1 1 1 1 -1 0 -1 -1 -1 0 -1 0 1 -1 1 0 0 1 -1 0 1 1 1 1 0 1 0 -1 1 0 1 1 -1 0 0 -1 -1 0 -1 1 0 0 0.75 0 0 -0.75 0 -0.75 0 0.75 0 0 0 0.75 0 -0.75 0 0 -1 -0.5 -1 -1 -1 0.5 -1 0.5 1 -1 1 -0.5 -0.5 1 -1 0.5 1 1 1 1 -0.5 1 0.5 -1 1 -0.5 1 1 -1 -0.5 0.5 -1 -1 -0.5 -1 1 -1 0.5 -1 -1 -1 -0.5 -1 -0.5 1 -1 1 0.5 0.5 1 -1 -0.5 1 1 1 1 0.5 1 -0.5 -1 1 0.5 1 1 -1 0.5 -0.5 -1 -1 0.5 -1 1 0 -0.5 0.75 0 0.5 0.75 0.5 0 0.75 -0.5 0 0.75 0 -0.5 -0.75 0 0.5 -0.75 -0.5 0 -0.75 0.5 0 -0.75 -0.5 -0.75 0 0.5 -0.75 0 0 -0.75 -0.5 0 -0.75 0.5 0.75 -0.5 0 0.75 0.5 0 0.75 0 -0.5 0.75 0 0.5 0.5 0.75 0 -0.5 0.75 0 0 0.75 -0.5 0 0.75 0.5 -0.75 0.5 0 -0.75 -0.5 0 -0.75 0 -0.5 -0.75 0 0.5 -0.75 -0.5 0.5 -0.75 -0.5 -0.5 -0.75 0.5 -0.5 -0.5 0.75 0.5 -0.5 0.75 -0.5 0.5 0.75 -0.5 0.75 0.5 0.5 0.75 0.5 -0.5 0.75 -0.5 -0.5 0.5 -0.75 0.5 0.5 -0.75 -0.5 -0.5 -0.75 -0.5 0.5 0.5 -0.75 -0.5 0.5 -0.75 -0.5 -0.5 -0.75 -0.5 0.5 0.75 0.5 0.5 0.75 0.5 -0.5 0.75 -0.5 -0.5 0.75 0.5 -0.5 -0.75 -0.5 -0.75 0.5 0.75 -0.5 0.5 0.5 0.75 0.5 -0.75 0.5 0.5</float_array>
<technique_common>
<accessor source="#Cube-mesh-positions-array" count="98" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="Cube-mesh-normals">
<float_array id="Cube-mesh-normals-array" count="162">-0.8164967 -0.4082483 -0.4082483 -0.4082483 0.8164967 -0.4082483 0.8164967 0.4082483 -0.4082483 0.4082483 -0.8164967 -0.4082483 -0.4082483 0.4082483 -0.8164967 0.4082483 0.4082483 0.8164967 0 0.4472137 0.8944273 0 0 1 0.4472137 0 0.8944273 0 0.4472137 -0.8944273 0 0 -1 -0.4472137 0 -0.8944273 0.4472137 -0.8944273 0 0 -1 0 0 -0.8944273 -0.4472137 0.8944273 0.4472137 0 1 0 0 0.8944273 0 -0.4472137 -0.4472137 0.8944273 0 0 1 0 0 0.8944273 -0.4472137 -0.8944273 -0.4472137 0 -1 0 0 -0.8944273 0 -0.4472137 -0.8944273 0.4472137 0 -0.8164967 0.4082483 -0.4082483 -0.8944273 0 0.4472137 0.4472137 0.8944273 0 0.4082483 0.8164967 -0.4082483 0 0.8944273 0.4472137 0.8944273 -0.4472137 0 0.8164967 -0.4082483 -0.4082483 0.8944273 0 0.4472137 -0.4472137 -0.8944273 0 -0.4082483 -0.8164967 -0.4082483 0 -0.8944273 0.4472137 0 -0.4472137 -0.8944273 -0.4082483 -0.4082483 -0.8164967 0.4472137 0 -0.8944273 0 -0.4472137 0.8944273 0.4082483 -0.4082483 0.8164967 -0.4472137 0 0.8944273 -0.8164967 0.4082483 0.4082483 -0.8164967 -0.4082483 0.4082483 0.4082483 0.8164967 0.4082483 -0.4082483 0.8164967 0.4082483 0.8164967 -0.4082483 0.4082483 0.8164967 0.4082483 0.4082483 -0.4082483 -0.8164967 0.4082483 0.4082483 -0.8164967 0.4082483 0.4082483 -0.4082483 -0.8164967 0.4082483 0.4082483 -0.8164967 -0.4082483 -0.4082483 0.8164967 -0.4082483 0.4082483 0.8164967</float_array>
<technique_common>
<accessor source="#Cube-mesh-normals-array" count="54" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<vertices id="Cube-mesh-vertices">
<input semantic="POSITION" source="#Cube-mesh-positions"/>
</vertices>
<triangles material="Material_001-material" count="192">
<input semantic="VERTEX" source="#Cube-mesh-vertices" offset="0"/>
<input semantic="NORMAL" source="#Cube-mesh-normals" offset="1"/>
<p>28 0 41 0 97 0 31 1 44 1 96 1 34 2 47 2 95 2 37 3 27 3 94 3 45 4 36 4 93 4 40 5 37 5 92 5 50 6 49 6 91 6 51 7 52 7 90 7 28 8 53 8 89 8 54 9 48 9 88 9 55 10 56 10 87 10 33 11 57 11 86 11 58 12 39 12 85 12 59 13 60 13 84 13 49 14 61 14 83 14 62 15 35 15 82 15 63 16 64 16 81 16 46 17 65 17 80 17 66 18 32 18 79 18 67 19 68 19 78 19 43 20 69 20 77 20 70 21 29 21 76 21 71 22 72 22 75 22 40 23 73 23 74 23 74 22 25 22 71 22 27 24 71 24 9 24 27 25 40 25 74 25 75 26 8 26 26 26 39 22 26 22 0 22 9 24 75 24 39 24 38 22 29 22 2 22 72 26 38 26 8 26 25 22 76 22 72 22 77 19 24 19 67 19 41 27 67 27 11 27 41 28 43 28 77 28 78 29 12 29 30 29 29 19 30 19 2 19 11 27 78 27 29 27 42 19 32 19 6 19 68 29 42 29 12 29 24 19 79 19 68 19 80 16 23 16 63 16 44 30 63 30 14 30 44 31 46 31 80 31 81 32 15 32 33 32 32 16 33 16 6 16 14 30 81 30 32 30 45 16 35 16 4 16 64 32 45 32 15 32 23 16 82 16 64 16 83 13 22 13 59 13 47 33 59 33 17 33 47 34 49 34 83 34 84 35 18 35 36 35 35 13 36 13 4 13 17 33 84 33 35 33 48 13 39 13 0 13 60 35 48 35 18 35 22 13 85 13 60 13 86 10 21 10 55 10 42 36 55 36 12 36 42 37 33 37 86 37 87 38 8 38 38 38 30 10 38 10 2 10 12 36 87 36 30 36 26 10 48 10 0 10 56 38 26 38 8 38 21 10 88 10 56 10 89 7 20 7 51 7 43 39 51 39 13 39 43 40 28 40 89 40 90 41 16 41 46 41 31 7 46 7 7 7 13 39 90 39 31 39 34 7 49 7 5 7 52 41 34 41 16 41 20 7 91 7 52 7 92 6 19 6 50 6 53 7 50 7 20 7 10 8 92 8 53 8 93 9 18 9 54 9 57 10 54 10 21 10 15 11 93 11 57 11 94 12 9 12 58 12 61 13 58 13 22 13 19 14 94 14 61 14 95 15 17 15 62 15 65 16 62 16 23 16 16 17 95 17 65 17 96 18 14 18 66 18 69 19 66 19 24 19 13 20 96 20 69 20 97 21 11 21 70 21 73 22 70 22 25 22 10 23 97 23 73 23 28 22 3 22 41 22 31 19 7 19 44 19 34 16 5 16 47 16 37 13 1 13 27 13 45 10 4 10 36 10 40 7 1 7 37 7 50 6 19 6 49 6 51 7 20 7 52 7 28 8 10 8 53 8 54 9 18 9 48 9 55 10 21 10 56 10 33 11 15 11 57 11 58 12 9 12 39 12 59 13 22 13 60 13 49 14 19 14 61 14 62 15 17 15 35 15 63 16 23 16 64 16 46 17 16 17 65 17 66 18 14 18 32 18 67 19 24 19 68 19 43 20 13 20 69 20 70 21 11 21 29 21 71 22 25 22 72 22 40 23 10 23 73 23 74 22 73 22 25 22 27 24 74 24 71 24 27 22 1 22 40 22 75 26 72 26 8 26 39 42 75 42 26 42 9 24 71 24 75 24 38 43 76 43 29 43 72 26 76 26 38 26 25 22 70 22 76 22 77 19 69 19 24 19 41 27 77 27 67 27 41 19 3 19 43 19 78 29 68 29 12 29 29 44 78 44 30 44 11 27 67 27 78 27 42 45 79 45 32 45 68 29 79 29 42 29 24 19 66 19 79 19 80 16 65 16 23 16 44 30 80 30 63 30 44 16 7 16 46 16 81 32 64 32 15 32 32 46 81 46 33 46 14 30 63 30 81 30 45 47 82 47 35 47 64 32 82 32 45 32 23 16 62 16 82 16 83 13 61 13 22 13 47 33 83 33 59 33 47 13 5 13 49 13 84 35 60 35 18 35 35 48 84 48 36 48 17 33 59 33 84 33 48 49 85 49 39 49 60 35 85 35 48 35 22 13 58 13 85 13 86 10 57 10 21 10 42 36 86 36 55 36 42 10 6 10 33 10 87 38 56 38 8 38 30 50 87 50 38 50 12 36 55 36 87 36 26 51 88 51 48 51 56 38 88 38 26 38 21 10 54 10 88 10 89 7 53 7 20 7 43 39 89 39 51 39 43 7 3 7 28 7 90 41 52 41 16 41 31 52 90 52 46 52 13 39 51 39 90 39 34 53 91 53 49 53 52 41 91 41 34 41 20 7 50 7 91 7 92 6 37 6 19 6 53 7 92 7 50 7 10 8 40 8 92 8 93 9 36 9 18 9 57 10 93 10 54 10 15 11 45 11 93 11 94 12 27 12 9 12 61 13 94 13 58 13 19 14 37 14 94 14 95 15 47 15 17 15 65 16 95 16 62 16 16 17 34 17 95 17 96 18 44 18 14 18 69 19 96 19 66 19 13 20 31 20 96 20 97 21 41 21 11 21 73 22 97 22 70 22 10 23 28 23 97 23</p>
</triangles>
</mesh>
</geometry>
</library_geometries>
<library_controllers/>
<library_visual_scenes>
<visual_scene id="Scene" name="Scene">
<node id="Cube" name="Cube" type="NODE">
<matrix sid="transform">1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1</matrix>
<instance_geometry url="#Cube-mesh" name="Cube">
<bind_material>
<technique_common>
<instance_material symbol="Material_001-material" target="#Material_001-material"/>
</technique_common>
</bind_material>
</instance_geometry>
</node>
</visual_scene>
</library_visual_scenes>
<scene>
<instance_visual_scene url="#Scene"/>
</scene>
</COLLADA>

208
data/catepillar.dae

File diff suppressed because one or more lines are too long

3
src/hexgame.cpp

@ -547,7 +547,8 @@ int main(int argc, char* argv[])
Entity* e = (Entity*) std::calloc(1000, sizeof(Entity));
render_state* r = g_render_state;
r->entities = e;
const char* test_file = "../data/animated.block.dae";
//const char* test_file = "../data/animated.block.dae";
const char* test_file = "../data/catepillar.dae";
meMeshInfo* mesh = meLoadFromFile(test_file);
if (mesh != nullptr) {

42
src/mesh.cpp

@ -43,47 +43,53 @@ meLoadFromFile(const char* filename)
if (scene->mNumMeshes != 1) {
LOG(ERROR) << "We Can only handle 1 mesh per entity atm\n";
#if 0
return nullptr;
#else
LOG(DEBUG) << "num meshes: " << scene->mNumMeshes << "\n";
LOG(DEBUG) << "num materials: " << scene->mNumMaterials << "\n";
#endif
}
meMeshInfo* mesh = (meMeshInfo*) std::calloc(1, sizeof(meMeshInfo));
meMeshInfo* mi = (meMeshInfo*) std::calloc(1, sizeof(meMeshInfo));
// TODO: using hard coded model transform for now
mesh->model_transform = glm::scale(glm::mat4(1), glm::vec3(100, 100, 100));
mi->model_transform = glm::scale(glm::mat4(1), glm::vec3(100, 100, 100));
// allocate buffers for vertex and index data from mesh
mesh->num_vertices = scene->mMeshes[0]->mNumVertices;
mesh->vertices = (glm::vec3 *) std::calloc(mesh->num_vertices, sizeof(glm::vec3));
mesh->normals = (glm::vec3 *) std::calloc(mesh->num_vertices, sizeof(glm::vec3));
mesh->num_indices = scene->mMeshes[0]->mNumFaces * 3; // NOTE: assume 3 vertices per face
mesh->indices = (uint *) std::calloc(mesh->num_indices, sizeof(uint));
aiMesh* mesh = scene->mMeshes[2];
mi->num_vertices = mesh->mNumVertices;
mi->vertices = (glm::vec3 *) std::calloc(mi->num_vertices, sizeof(glm::vec3));
mi->normals = (glm::vec3 *) std::calloc(mi->num_vertices, sizeof(glm::vec3));
mi->num_indices = mesh->mNumFaces * 3; // NOTE: assume 3 vertices per face
mi->indices = (uint *) std::calloc(mi->num_indices, sizeof(uint));
// copy vertices and normals
for (uint i = 0; i < mesh->num_vertices; i++) {
copyVector(scene->mMeshes[0]->mVertices[i], mesh->vertices[i]);
for (uint i = 0; i < mi->num_vertices; i++) {
copyVector(mesh->mVertices[i], mi->vertices[i]);
if (scene->mMeshes[0]->HasNormals())
copyVector(scene->mMeshes[0]->mNormals[i], mesh->normals[i]);
if (mesh->HasNormals())
copyVector(mesh->mNormals[i], mi->normals[i]);
}
// copy indices
for (uint i = 0; i < scene->mMeshes[0]->mNumFaces; i++)
for (uint i = 0; i < mesh->mNumFaces; i++)
for (uint j = 0; j < 3; j++)
mesh->indices[i * 3 + j] = scene->mMeshes[0]->mFaces[i].mIndices[j];
mi->indices[i * 3 + j] = mesh->mFaces[i].mIndices[j];
// material
aiMaterial* mat = scene->mMaterials[0];
aiMaterial* mat = scene->mMaterials[1];
aiColor3D color(0.f, 0.f, 0.f);
if (AI_SUCCESS != mat->Get(AI_MATKEY_COLOR_DIFFUSE, color)) {
LOG(ERROR) << "Some Assimp-type-error\n";
} else {
mesh->diffuse_color.r = color.r;
mesh->diffuse_color.g = color.g;
mesh->diffuse_color.b = color.b;
mi->diffuse_color.r = color.r;
mi->diffuse_color.g = color.g;
mi->diffuse_color.b = color.b;
}
// free memeory from assimp
aiReleaseImport(scene);
return mesh;
return mi;
}
void

2
src/render_group.cpp

@ -129,7 +129,7 @@ rgFillColorBuffer(GLfloat buf[], int len, std::vector<hex_info>* hexes)
}
}
// Copy assimp data to our structures for openGL
// NOTE: Copy assimp data to our structures for openGL
bool
rgInitEntity(gl_render_group* rg, Entity* e)
{

Loading…
Cancel
Save