nuclear@0: #include "scene.h" nuclear@0: #include "opengl.h" nuclear@12: #include "goat3d.h" nuclear@0: nuclear@13: static Mesh *load_mesh(goat3d_mesh *gmesh); nuclear@13: nuclear@0: Scene::~Scene() nuclear@0: { nuclear@0: destroy(); nuclear@0: } nuclear@0: nuclear@0: void Scene::destroy() nuclear@0: { nuclear@0: for(size_t i=0; idraw(msec); nuclear@0: } nuclear@0: nuclear@0: if(objects.empty()) { nuclear@0: printf("rendering meshes directly\n"); nuclear@0: for(size_t i=0; idraw(); nuclear@0: } nuclear@0: } nuclear@0: } nuclear@13: nuclear@13: static Mesh *load_mesh(goat3d_mesh *gmesh) nuclear@13: { nuclear@13: int nverts = goat3d_get_mesh_attrib_count(gmesh, GOAT3D_MESH_ATTR_VERTEX); nuclear@13: float *data = (float*)goat3d_get_mesh_attribs(gmesh, GOAT3D_MESH_ATTR_VERTEX); nuclear@13: nuclear@13: if(!nverts || !data) { nuclear@13: return 0; nuclear@13: } nuclear@13: int nfaces = goat3d_get_mesh_face_count(gmesh); nuclear@13: nuclear@13: Mesh *mesh = new Mesh; nuclear@13: const char *name = goat3d_get_mesh_name(gmesh); nuclear@13: if(name) { nuclear@13: mesh->set_name(name); nuclear@13: } nuclear@13: nuclear@13: mesh->set_attrib_data(MESH_ATTR_VERTEX, 3, nverts, data); nuclear@13: nuclear@13: if((data = (float*)goat3d_get_mesh_attribs(gmesh, GOAT3D_MESH_ATTR_NORMAL))) { nuclear@13: mesh->set_attrib_data(MESH_ATTR_NORMAL, 3, nverts, data); nuclear@13: } nuclear@13: if((data = (float*)goat3d_get_mesh_attribs(gmesh, GOAT3D_MESH_ATTR_TANGENT))) { nuclear@13: mesh->set_attrib_data(MESH_ATTR_TANGENT, 3, nverts, data); nuclear@13: } nuclear@13: if((data = (float*)goat3d_get_mesh_attribs(gmesh, GOAT3D_MESH_ATTR_TEXCOORD))) { nuclear@13: mesh->set_attrib_data(MESH_ATTR_TEXCOORD, 2, nverts, data); nuclear@13: } nuclear@13: if((data = (float*)goat3d_get_mesh_attribs(gmesh, GOAT3D_MESH_ATTR_COLOR))) { nuclear@13: mesh->set_attrib_data(MESH_ATTR_COLOR, 4, nverts, data); nuclear@13: } nuclear@13: if((data = (float*)goat3d_get_mesh_attribs(gmesh, GOAT3D_MESH_ATTR_SKIN_WEIGHT))) { nuclear@13: mesh->set_attrib_data(MESH_ATTR_BONEWEIGHTS, 4, nverts, data); nuclear@13: } nuclear@13: int *idata = (int*)goat3d_get_mesh_attribs(gmesh, GOAT3D_MESH_ATTR_SKIN_MATRIX); nuclear@13: if(idata) { nuclear@13: for(int i=0; iset_attrib(MESH_ATTR_BONEIDX, i, Vector4(idata[0], idata[1], idata[2], idata[3])); nuclear@13: idata += 4; nuclear@13: } nuclear@13: } nuclear@13: nuclear@13: if(nfaces && !(idata = goat3d_get_mesh_faces(gmesh))) { nuclear@13: mesh->set_index_data(nfaces * 3, (unsigned int*)idata); nuclear@13: } nuclear@13: return mesh; nuclear@13: }