# HG changeset patch # User John Tsiombikas # Date 1380193574 -10800 # Node ID f1b4c27382ce39b859f8dccdaa64c96d929f6099 # Parent 188c697b3b49aa17e4848bd58310a7dc0a047e50 blah diff -r 188c697b3b49 -r f1b4c27382ce Makefile --- a/Makefile Thu Sep 26 04:47:05 2013 +0300 +++ b/Makefile Thu Sep 26 14:06:14 2013 +0300 @@ -31,6 +31,8 @@ pic = -fPIC endif +CC = clang +CXX = clang++ CXXFLAGS = -pedantic -Wall $(dbg) $(opt) $(pic) $(extinc) LDFLAGS = $(extlibs) -lvmath -lanim @@ -41,7 +43,7 @@ $(CXX) -o $@ $(shared) $(obj) $(LDFLAGS) $(lib_a): $(obj) $(extlibs) - $(AR) rcs $@ $(obj) + $(AR) rcs $@ $(obj) $(openctm) $(openctm): $(MAKE) -C libs/openctm diff -r 188c697b3b49 -r f1b4c27382ce doc/goatfmt --- a/doc/goatfmt Thu Sep 26 04:47:05 2013 +0300 +++ b/doc/goatfmt Thu Sep 26 14:06:14 2013 +0300 @@ -28,7 +28,7 @@ | +--MESH_NAME | | +-- | +--MESH_MATERIAL - | | +-- (material name) + | | +-- (material name or index) | +--MESH_VERTEX_LIST | | +--[FLOAT3] | +--MESH_NORMAL_LIST diff -r 188c697b3b49 -r f1b4c27382ce src/goat3d.h --- a/src/goat3d.h Thu Sep 26 04:47:05 2013 +0300 +++ b/src/goat3d.h Thu Sep 26 14:06:14 2013 +0300 @@ -4,7 +4,46 @@ #include #include +#define GOAT3D_MAT_ATTR_DIFFUSE "diffuse" +#define GOAT3D_MAT_ATTR_SPECULAR "specular" +#define GOAT3D_MAT_ATTR_SHININESS "shininess" +#define GOAT3D_MAT_ATTR_NORMAL "normal" +#define GOAT3D_MAT_ATTR_BUMP "bump" +#define GOAT3D_MAT_ATTR_REFLECTION "reflection" +#define GOAT3D_MAT_ATTR_TRANSMISSION "transmission" +#define GOAT3D_MAT_ATTR_IOR "ior" + +enum goat3d_mesh_attrib { + GOAT3D_MESH_ATTR_VERTEX, + GOAT3D_MESH_ATTR_NORMAL, + GOAT3D_MESH_ATTR_TANGENT, + GOAT3D_MESH_ATTR_TEXCOORD, + GOAT3D_MESH_ATTR_SKIN_WEIGHT, + GOAT3D_MESH_ATTR_SKIN_MATRIX, + GOAT3D_MESH_ATTR_COLOR, + + NUM_GOAT3D_MESH_ATTRIBS +}; + +/* immediate mode mesh construction primitive type */ +enum goat3d_im_primitive { + GOAT3D_TRIANGLES, + GOAT3D_QUADS +}; + + +enum goat3d_option { + GOAT3D_OPT_SAVEXML, /* save in XML format */ + + NUM_GOAT3D_OPTIONS +}; + struct goat3d; +struct goat3d_material; +struct goat3d_mesh; +struct goat3d_light; +struct goat3d_camera; +struct goat3d_node; struct goat3d_io { void *cls; /* closure data */ @@ -14,18 +53,17 @@ long (*seek)(long offs, int whence, void *uptr); }; -struct goat3d_vec3 { float x, y, z; }; -struct goat3d_vec4 { float x, y, z, w; }; - - #ifdef __cplusplus extern "C" { #endif /* construction/destruction */ -struct goat3d *goat3d_create(); +struct goat3d *goat3d_create(void); void goat3d_free(struct goat3d *g); +void goat3d_setopt(struct goat3d *g, enum goat3d_option opt, int val); +int goat3d_getopt(const struct goat3d *g, enum goat3d_option opt); + /* load/save */ int goat3d_load(struct goat3d *g, const char *fname); int goat3d_save(const struct goat3d *g, const char *fname); @@ -40,12 +78,82 @@ int goat3d_set_name(struct goat3d *g, const char *name); const char *goat3d_get_name(const struct goat3d *g); -void goat3d_set_ambient(struct goat3d *g, float x, float y, float z); +void goat3d_set_ambient(struct goat3d *g, const float *ambient); +void goat3d_set_ambient3f(struct goat3d *g, float ar, float ag, float ab); +const float *goat3d_get_ambient(const struct goat3d *g); -/* helpers */ -struct goat3d_vec3 goat3d_vec3(float x, float y, float z); -struct goat3d_vec4 goat3d_vec4(float x, float y, float z, float w); +/* materials */ +struct goat3d_material *goat3d_create_mtl(void); +void goat3d_destroy_mtl(struct goat3d_material *mtl); +void goat3d_set_mtl_name(struct goat3d_material *mtl, const char *name); +const char *goat3d_get_mtl_name(const struct goat3d_material *mtl); + +void goat3d_set_mtl_attrib(struct goat3d_material *mtl, const char *attrib, const float *val); +void goat3d_set_mtl_attrib1f(struct goat3d_material *mtl, const char *attrib, float val); +void goat3d_set_mtl_attrib3f(struct goat3d_material *mtl, const char *attrib, float r, float g, float b); +void goat3d_set_mtl_attrib4f(struct goat3d_material *mtl, const char *attrib, float r, float g, float b, float a); +const float *goat3d_get_mtl_attrib(struct goat3d_material *mtl, const char *attrib); + +void goat3d_set_mtl_attrib_map(struct goat3d_material *mtl, const char *attrib, const char *mapname); +const char *goat3d_get_mtl_attrib_map(struct goat3d_material *mtl, const char *attrib); + +void goat3d_add_mtl(struct goat3d *g, struct goat3d_material *mtl); + +/* meshes */ +struct goat3d_mesh *goat3d_create_mesh(void); +void goat3d_destroy_mesh(struct goat3d_mesh *mesh); + +void goat3d_set_mesh_name(struct goat3d_mesh *mesh, const char *name); +const char *goat3d_get_mesh_name(const struct goat3d_mesh *mesh); + +void goat3d_set_mesh_mtl(struct goat3d_mesh *mesh, struct goat3d_material *mtl); +struct goat3d_material *goat3d_get_mesh_mtl(struct goat3d_mesh *mesh); + +int goat3d_get_mesh_attrib_count(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib); +int goat3d_get_mesh_face_count(struct goat3d_mesh *mesh); + +/* sets all the data for a single vertex attribute array in one go. + * vnum is the number of *vertices* to be set, not the number of floats, ints or whatever + * data is expected to be something different depending on the attribute: + * - GOAT3D_MESH_ATTR_VERTEX - 3 floats per vertex + * - GOAT3D_MESH_ATTR_NORMAL - 3 floats per vertex + * - GOAT3D_MESH_ATTR_TANGENT - 3 floats per vertex + * - GOAT3D_MESH_ATTR_TEXCOORD - 2 floats per vertex + * - GOAT3D_MESH_ATTR_SKIN_WEIGHT - 4 floats per vertex + * - GOAT3D_MESH_ATTR_SKIN_MATRIX - 4 ints per vertex + * - GOAT3D_MESH_ATTR_COLOR - 4 floats per vertex + */ +void goat3d_set_mesh_attribs(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib, const void *data, int vnum); +/* returns a pointer to the beginning of the requested mesh attribute array */ +void *goat3d_get_mesh_attribs(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib); +/* returns a pointer to the requested mesh attribute */ +void *goat3d_get_mesh_attrib(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib, int idx); + +/* sets all the faces in one go. data is an array of 3 int vertex indices per face */ +void goat3d_set_mesh_faces(struct goat3d_mesh *mesh, const int *data, int fnum); +/* returns a pointer to the beginning of the face index array */ +int *goat3d_get_mesh_faces(struct goat3d_mesh *mesh); +/* returns a pointer to a face index */ +int *goat3d_get_mesh_face(struct goat3d_mesh *mesh, int idx); + +/* immediate mode OpenGL-like interface for setting mesh data + * NOTE: using this interface will result in no vertex sharing between faces + * NOTE2: the immedate mode interface is not thread-safe, either use locks, or don't + * use it at all in multithreaded situations. + */ +void goat3d_begin(struct goat3d_mesh *mesh, enum goat3d_im_primitive prim); +void goat3d_end(void); +void goat3d_vertex3f(float x, float y, float z); +void goat3d_normal3f(float x, float y, float z); +void goat3d_tangent3f(float x, float y, float z); +void goat3d_texcoord2f(float x, float y); +void goat3d_skin_weight4f(float x, float y, float z, float w); +void goat3d_skin_matrix4i(int x, int y, int z, int w); +void goat3d_color3f(float x, float y, float z); +void goat3d_color4f(float x, float y, float z, float w); + +void goat3d_add_mesh(struct goat3d *g, struct goat3d_mesh *mesh); #ifdef __cplusplus } diff -r 188c697b3b49 -r f1b4c27382ce src/goat3d_impl.h --- a/src/goat3d_impl.h Thu Sep 26 04:47:05 2013 +0300 +++ b/src/goat3d_impl.h Thu Sep 26 14:06:14 2013 +0300 @@ -10,6 +10,8 @@ #include "material.h" #include "node.h" +extern int goat_log_level; + class Scene { private: std::string name; diff -r 188c697b3b49 -r f1b4c27382ce src/goat3d_scene.cc --- a/src/goat3d_scene.cc Thu Sep 26 04:47:05 2013 +0300 +++ b/src/goat3d_scene.cc Thu Sep 26 14:06:14 2013 +0300 @@ -198,6 +198,11 @@ return false; } +bool Scene::loadxml(goat3d_io *io) +{ + return false; +} + // Scene::save is defined in goat3d_write.cc @@ -244,7 +249,7 @@ } while(retsz <= 0); } - io->write(buf, sz, io->cls); + io->write(buf, retsz, io->cls); if(buf != smallbuf) { delete [] buf; diff -r 188c697b3b49 -r f1b4c27382ce src/goat3d_writexml.cc --- a/src/goat3d_writexml.cc Thu Sep 26 04:47:05 2013 +0300 +++ b/src/goat3d_writexml.cc Thu Sep 26 14:06:14 2013 +0300 @@ -49,7 +49,7 @@ xmlout(io, level + 2, "\n", mat->get_attrib_name(i)); const MaterialAttrib &attr = (*mat)[i]; - xmlout(io, level + 2, "\n", attr.value.x, + xmlout(io, level + 2, "\n", attr.value.x, attr.value.y, attr.value.z, attr.value.w); if(!attr.map.empty()) { xmlout(io, level + 2, "\n", attr.map.c_str()); @@ -94,15 +94,7 @@ // texture coordinates if(!mesh->texcoords.empty()) { - CTMfloat *uvarray = new CTMfloat[vnum * 2 * sizeof *uvarray]; - CTMfloat *uvptr = uvarray; - - for(int i=0; itexcoords[i].x; - *uvptr++ = mesh->texcoords[i].y; - } - ctmAddUVMap(ctm, uvarray, "texcoord", 0); - delete [] uvarray; + ctmAddUVMap(ctm, &mesh->texcoords[0].x, "texcoord", 0); } // vertex colors diff -r 188c697b3b49 -r f1b4c27382ce src/material.cc --- a/src/material.cc Thu Sep 26 04:47:05 2013 +0300 +++ b/src/material.cc Thu Sep 26 14:06:14 2013 +0300 @@ -1,5 +1,7 @@ #include "material.h" +MaterialAttrib Material::def_attr; + int Material::get_attrib_count() const { return (int)attrib.size(); diff -r 188c697b3b49 -r f1b4c27382ce src/material.h --- a/src/material.h Thu Sep 26 04:47:05 2013 +0300 +++ b/src/material.h Thu Sep 26 14:06:14 2013 +0300 @@ -8,17 +8,10 @@ struct MaterialAttrib { Vector4 value; std::string map; + + MaterialAttrib() : value(1, 1, 1, 1) {} }; -#define MAT_ATTR_DIFFUSE "diffuse" -#define MAT_ATTR_SPECULAR "specular" -#define MAT_ATTR_SHININESS "shininess" -#define MAT_ATTR_NORMAL "normal" -#define MAT_ATTR_BUMP "bump" -#define MAT_ATTR_REFLECTION "reflection" -#define MAT_ATTR_TRANSMISSION "transmission" -#define MAT_ATTR_IOR "ior" - class Material { private: static MaterialAttrib def_attr; diff -r 188c697b3b49 -r f1b4c27382ce src/mesh.cc --- a/src/mesh.cc Thu Sep 26 04:47:05 2013 +0300 +++ b/src/mesh.cc Thu Sep 26 14:06:14 2013 +0300 @@ -5,8 +5,6 @@ material = 0; } -Mesh::~Mesh() {} - void Mesh::set_material(Material *mat) { material = mat; diff -r 188c697b3b49 -r f1b4c27382ce src/mesh.h --- a/src/mesh.h Thu Sep 26 04:47:05 2013 +0300 +++ b/src/mesh.h Thu Sep 26 14:06:14 2013 +0300 @@ -22,19 +22,19 @@ std::vector vertices; std::vector normals; std::vector tangents; - std::vector texcoords; + std::vector texcoords; std::vector skin_weights; std::vector skin_matrices; std::vector colors; - std::vector bones; std::vector faces; + std::vector bones; + Mesh(); - virtual ~Mesh(); - virtual void set_material(Material *mat); - virtual Material *get_material(); - virtual const Material *get_material() const; + void set_material(Material *mat); + Material *get_material(); + const Material *get_material() const; }; #endif // MESH_H_