goat3d
diff src/goat3d.cc @ 40:a5c5cec3cb88
- added mesh attribute and face append functions
- added Int4 constructor
- continued the blender exporter
- fixed a bug in clean_filename which made it produce unterminated strings
- renamed clean_filename to goat3d_clean_filename and made it extern
- added call to goat3d_clean_filename in the mesh XML export code to cleanup ctm filenames
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 13 Oct 2013 10:14:19 +0300 |
parents | d24f63e8031e |
children | da3f335e0069 |
line diff
1.1 --- a/src/goat3d.cc Wed Oct 09 16:40:59 2013 +0300 1.2 +++ b/src/goat3d.cc Sun Oct 13 10:14:19 2013 +0300 1.3 @@ -29,8 +29,6 @@ 1.4 static long write_file(const void *buf, size_t bytes, void *uptr); 1.5 static long seek_file(long offs, int whence, void *uptr); 1.6 1.7 -static std::string clean_filename(const char *str); 1.8 - 1.9 extern "C" { 1.10 1.11 struct goat3d *goat3d_create(void) 1.12 @@ -228,7 +226,7 @@ 1.13 1.14 void goat3d_set_mtl_attrib_map(struct goat3d_material *mtl, const char *attrib, const char *mapname) 1.15 { 1.16 - (*mtl)[attrib].map = clean_filename(mapname); 1.17 + (*mtl)[attrib].map = goat3d_clean_filename(mapname); 1.18 } 1.19 1.20 const char *goat3d_get_mtl_attrib_map(struct goat3d_material *mtl, const char *attrib) 1.21 @@ -333,6 +331,47 @@ 1.22 } 1.23 } 1.24 1.25 +void goat3d_add_mesh_attrib1f(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib, 1.26 + float val) 1.27 +{ 1.28 + goat3d_add_mesh_attrib4f(mesh, attrib, val, 0, 0, 1); 1.29 +} 1.30 + 1.31 +void goat3d_add_mesh_attrib3f(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib, 1.32 + float x, float y, float z) 1.33 +{ 1.34 + goat3d_add_mesh_attrib4f(mesh, attrib, x, y, z, 1); 1.35 +} 1.36 + 1.37 +void goat3d_add_mesh_attrib4f(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib, 1.38 + float x, float y, float z, float w) 1.39 +{ 1.40 + switch(attrib) { 1.41 + case GOAT3D_MESH_ATTR_VERTEX: 1.42 + mesh->vertices.push_back(Vector3(x, y, z)); 1.43 + break; 1.44 + case GOAT3D_MESH_ATTR_NORMAL: 1.45 + mesh->normals.push_back(Vector3(x, y, z)); 1.46 + break; 1.47 + case GOAT3D_MESH_ATTR_TANGENT: 1.48 + mesh->tangents.push_back(Vector3(x, y, z)); 1.49 + break; 1.50 + case GOAT3D_MESH_ATTR_TEXCOORD: 1.51 + mesh->texcoords.push_back(Vector2(x, y)); 1.52 + break; 1.53 + case GOAT3D_MESH_ATTR_SKIN_WEIGHT: 1.54 + mesh->skin_weights.push_back(Vector4(x, y, z, w)); 1.55 + break; 1.56 + case GOAT3D_MESH_ATTR_SKIN_MATRIX: 1.57 + mesh->skin_matrices.push_back(Int4(x, y, z, w)); 1.58 + break; 1.59 + case GOAT3D_MESH_ATTR_COLOR: 1.60 + mesh->colors.push_back(Vector4(x, y, z, w)); 1.61 + default: 1.62 + break; 1.63 + } 1.64 +} 1.65 + 1.66 void *goat3d_get_mesh_attribs(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib) 1.67 { 1.68 return goat3d_get_mesh_attrib(mesh, attrib, 0); 1.69 @@ -367,6 +406,15 @@ 1.70 mesh->faces = VECDATA(Face, data, num); 1.71 } 1.72 1.73 +void goat3d_add_mesh_face(struct goat3d_mesh *mesh, int a, int b, int c) 1.74 +{ 1.75 + Face face; 1.76 + face.v[0] = a; 1.77 + face.v[1] = b; 1.78 + face.v[2] = c; 1.79 + mesh->faces.push_back(face); 1.80 +} 1.81 + 1.82 int *goat3d_get_mesh_faces(struct goat3d_mesh *mesh) 1.83 { 1.84 return goat3d_get_mesh_face(mesh, 0); 1.85 @@ -738,7 +786,7 @@ 1.86 return ftell((FILE*)uptr); 1.87 } 1.88 1.89 -static std::string clean_filename(const char *str) 1.90 +std::string goat3d_clean_filename(const char *str) 1.91 { 1.92 const char *last_slash = strrchr(str, '/'); 1.93 if(!last_slash) { 1.94 @@ -755,5 +803,6 @@ 1.95 char c = *str++; 1.96 *dest++ = tolower(c); 1.97 } 1.98 + *dest = 0; 1.99 return buf; 1.100 }