goat3dgfx
changeset 13:25bf39105c82
lalal
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 27 Nov 2013 08:08:59 +0200 |
parents | 1868c5975f31 |
children | 693bb1df9553 |
files | .hgignore src/goat3dgfx.cc src/scene.cc |
diffstat | 3 files changed, 56 insertions(+), 1 deletions(-) [+] |
line diff
1.1 --- a/.hgignore Sun Nov 24 18:18:38 2013 +0200 1.2 +++ b/.hgignore Wed Nov 27 08:08:59 2013 +0200 1.3 @@ -8,3 +8,5 @@ 1.4 \.ncb$ 1.5 \.suo$ 1.6 \.user$ 1.7 +^Makefile$ 1.8 +src/config\.h$
2.1 --- a/src/goat3dgfx.cc Sun Nov 24 18:18:38 2013 +0200 2.2 +++ b/src/goat3dgfx.cc Wed Nov 27 08:08:59 2013 +0200 2.3 @@ -21,4 +21,5 @@ 2.4 2.5 void shutdown_goat_graphics() 2.6 { 2.7 + vr_shutdown(); 2.8 }
3.1 --- a/src/scene.cc Sun Nov 24 18:18:38 2013 +0200 3.2 +++ b/src/scene.cc Wed Nov 27 08:08:59 2013 +0200 3.3 @@ -2,6 +2,8 @@ 3.4 #include "opengl.h" 3.5 #include "goat3d.h" 3.6 3.7 +static Mesh *load_mesh(goat3d_mesh *gmesh); 3.8 + 3.9 Scene::~Scene() 3.10 { 3.11 destroy(); 3.12 @@ -38,7 +40,10 @@ 3.13 int num_meshes = goat3d_get_mesh_count(goat); 3.14 for(int i=0; i<num_meshes; i++) { 3.15 goat3d_mesh *gmesh = goat3d_get_mesh(goat, i); 3.16 - // TODO cont... 3.17 + Mesh *mesh = load_mesh(gmesh); 3.18 + if(mesh) { 3.19 + meshes.push_back(mesh); 3.20 + } 3.21 } 3.22 3.23 goat3d_free(goat); 3.24 @@ -63,3 +68,50 @@ 3.25 } 3.26 } 3.27 } 3.28 + 3.29 +static Mesh *load_mesh(goat3d_mesh *gmesh) 3.30 +{ 3.31 + int nverts = goat3d_get_mesh_attrib_count(gmesh, GOAT3D_MESH_ATTR_VERTEX); 3.32 + float *data = (float*)goat3d_get_mesh_attribs(gmesh, GOAT3D_MESH_ATTR_VERTEX); 3.33 + 3.34 + if(!nverts || !data) { 3.35 + return 0; 3.36 + } 3.37 + int nfaces = goat3d_get_mesh_face_count(gmesh); 3.38 + 3.39 + Mesh *mesh = new Mesh; 3.40 + const char *name = goat3d_get_mesh_name(gmesh); 3.41 + if(name) { 3.42 + mesh->set_name(name); 3.43 + } 3.44 + 3.45 + mesh->set_attrib_data(MESH_ATTR_VERTEX, 3, nverts, data); 3.46 + 3.47 + if((data = (float*)goat3d_get_mesh_attribs(gmesh, GOAT3D_MESH_ATTR_NORMAL))) { 3.48 + mesh->set_attrib_data(MESH_ATTR_NORMAL, 3, nverts, data); 3.49 + } 3.50 + if((data = (float*)goat3d_get_mesh_attribs(gmesh, GOAT3D_MESH_ATTR_TANGENT))) { 3.51 + mesh->set_attrib_data(MESH_ATTR_TANGENT, 3, nverts, data); 3.52 + } 3.53 + if((data = (float*)goat3d_get_mesh_attribs(gmesh, GOAT3D_MESH_ATTR_TEXCOORD))) { 3.54 + mesh->set_attrib_data(MESH_ATTR_TEXCOORD, 2, nverts, data); 3.55 + } 3.56 + if((data = (float*)goat3d_get_mesh_attribs(gmesh, GOAT3D_MESH_ATTR_COLOR))) { 3.57 + mesh->set_attrib_data(MESH_ATTR_COLOR, 4, nverts, data); 3.58 + } 3.59 + if((data = (float*)goat3d_get_mesh_attribs(gmesh, GOAT3D_MESH_ATTR_SKIN_WEIGHT))) { 3.60 + mesh->set_attrib_data(MESH_ATTR_BONEWEIGHTS, 4, nverts, data); 3.61 + } 3.62 + int *idata = (int*)goat3d_get_mesh_attribs(gmesh, GOAT3D_MESH_ATTR_SKIN_MATRIX); 3.63 + if(idata) { 3.64 + for(int i=0; i<nverts; i++) { 3.65 + mesh->set_attrib(MESH_ATTR_BONEIDX, i, Vector4(idata[0], idata[1], idata[2], idata[3])); 3.66 + idata += 4; 3.67 + } 3.68 + } 3.69 + 3.70 + if(nfaces && !(idata = goat3d_get_mesh_faces(gmesh))) { 3.71 + mesh->set_index_data(nfaces * 3, (unsigned int*)idata); 3.72 + } 3.73 + return mesh; 3.74 +}