# HG changeset patch # User John Tsiombikas # Date 1380480783 -10800 # Node ID 3d669155709df0c7f26fcf79c5e74a96308e069f # Parent 9ba3e2fb8a337bd356d469fadcc523d3adaf214d - switched the unix build to use the internal vmath/anim as well - fixed a memory corruption issue which was caused by including the system-wide installed version of the anim.h header file - started the ass2goat assimp->goat3d converter diff -r 9ba3e2fb8a33 -r 3d669155709d .hgignore --- a/.hgignore Sun Sep 29 08:46:19 2013 +0300 +++ b/.hgignore Sun Sep 29 21:53:03 2013 +0300 @@ -14,3 +14,4 @@ \.ctm$ goatprim$ goatview$ +ass2goat$ diff -r 9ba3e2fb8a33 -r 3d669155709d Makefile --- a/Makefile Sun Sep 29 08:46:19 2013 +0300 +++ b/Makefile Sun Sep 29 21:53:03 2013 +0300 @@ -10,9 +10,11 @@ openctm = libs/openctm/libopenctm.a tinyxml2 = libs/tinyxml2/libtinyxml2.a +vmath = libs/vmath/libvmath.a +anim = libs/anim/libanim.a -extinc = -Ilibs/openctm -Ilibs/tinyxml2 -extlibs = $(openctm) $(tinyxml2) +extinc = -Ilibs/openctm -Ilibs/tinyxml2 -Ilibs/anim +extlibs = $(openctm) $(tinyxml2) $(anim) $(vmath) name = goat3d so_major = 0 @@ -35,7 +37,7 @@ CC = clang CXX = clang++ CXXFLAGS = -pedantic -Wall $(dbg) $(opt) $(pic) $(extinc) -LDFLAGS = $(extlibs) -lvmath -lanim +LDFLAGS = $(extlibs) .PHONY: all all: $(lib_so) $(lib_a) @@ -44,7 +46,7 @@ $(CXX) -o $@ $(shared) $(obj) $(LDFLAGS) $(lib_a): $(obj) $(extlibs) - $(AR) rcs $@ $(obj) $(openctm) + $(AR) rcs $@ $(obj) $(extlibs) $(openctm): $(MAKE) -C libs/openctm @@ -52,6 +54,12 @@ $(tinyxml2): $(MAKE) -C libs/tinyxml2 +$(vmath): + $(MAKE) -C libs/vmath + +$(anim): + $(MAKE) -C libs/anim + -include $(dep) %.d: %.cc @@ -64,3 +72,26 @@ .PHONY: cleandep cleandep: rm -f $(dep) + +.PHONY: install +install: $(lib_so) $(lib_a) + mkdir -p $(DESTDIR)$(PREFIX)/lib $(DESTDIR)$(PREFIX)/include + cp src/goat3d.h $(DESTDIR)$(PREFIX)/include/goat3d.h + cp $(lib_a) $(DESTDIR)$(PREFIX)/lib/$(lib_a) + cp $(lib_so) $(DESTDIR)$(PREFIX)/lib/$(lib_so) + [ -n "$(devlink)" ] && \ + cd $(DESTDIR)$(PREFIX)/lib && \ + rm -f $(soname) $(devlink) && \ + ln -s $(lib_so) $(soname) && \ + ln -s $(soname) $(devlink) || \ + true + +.PHONY: uninstall +uninstall: + rm -f $(DESTDIR)$(PREFIX)/include/goat3d.h + rm -f $(DESTDIR)$(PREFIX)/lib/$(lib_so) + rm -f $(DESTDIR)$(PREFIX)/lib/$(lib_a) + [ -n "$(devlink)" ] && \ + rm -f $(DESTDIR)$(PREFIX)/lib/$(soname) && \ + rm -f $(DESTDIR)$(PREFIX)/lib/$(devlink) || \ + true diff -r 9ba3e2fb8a33 -r 3d669155709d converters/ass2goat/.clang_complete --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/converters/ass2goat/.clang_complete Sun Sep 29 21:53:03 2013 +0300 @@ -0,0 +1,2 @@ +-I../../src +-I/usr/local/include diff -r 9ba3e2fb8a33 -r 3d669155709d converters/ass2goat/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/converters/ass2goat/Makefile Sun Sep 29 21:53:03 2013 +0300 @@ -0,0 +1,25 @@ +src = $(wildcard src/*.c) +obj = $(src:.c=.o) +dep = $(obj:.o=.d) +bin = ass2goat + +CC = clang +CPP = clang -E +CFLAGS = -pedantic -Wall -g $(goatinc) +LDFLAGS = -lgoat3d -lassimp + +$(bin): $(obj) + $(CC) -o $@ $(obj) $(LDFLAGS) + +-include $(dep) + +%.d: %.c + @$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@ + +.PHONY: clean +clean: + rm -f $(obj) $(bin) + +.PHONY: cleandep +cleandep: + rm -f $(dep) diff -r 9ba3e2fb8a33 -r 3d669155709d converters/ass2goat/src/main.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/converters/ass2goat/src/main.c Sun Sep 29 21:53:03 2013 +0300 @@ -0,0 +1,147 @@ +#include +#include +#include "goat3d.h" +#include "assimp/cimport.h" +#include "assimp/postprocess.h" +#include "assimp/scene.h" + +int convert(const char *infname, const char *outfname); +void process_material(struct goat3d_material *mtl, struct aiMaterial *aimtl); +void process_node(struct goat3d *goat, struct goat3d_node *parent, struct aiNode *ainode); + +int main(int argc, char **argv) +{ + int i, num_done = 0; + + for(i=1; i %s\n", argv[i], outfname); + convert(argv[i], outfname); + num_done++; + } + } + + if(!num_done) { + fprintf(stderr, "you must specify a 3D scene file to convert\n"); + return 1; + } + + return 0; +} + +#define PPFLAGS \ + (aiProcess_Triangulate | \ + aiProcess_GenNormals | \ + aiProcess_JoinIdenticalVertices | \ + aiProcess_CalcTangentSpace | \ + aiProcess_LimitBoneWeights | \ + aiProcess_GenUVCoords) + +int convert(const char *infname, const char *outfname) +{ + int i; + const struct aiScene *aiscn; + struct goat3d *goat; + + if(!(aiscn = aiImportFile(infname, PPFLAGS))) { + fprintf(stderr, "failed to import %s\n", infname); + return -1; + } + + goat = goat3d_create(); + + for(i=0; i<(int)aiscn->mNumMaterials; i++) { + struct aiMaterial *aimat = aiscn->mMaterials[i]; + struct goat3d_material *mat = goat3d_create_mtl(); + + process_material(mat, aimat); + goat3d_add_mtl(goat, mat); + } + + for(i=0; i<(int)aiscn->mRootNode->mNumChildren; i++) { + process_node(goat, 0, aiscn->mRootNode->mChildren[i]); + } + + goat3d_save(goat, outfname); + goat3d_free(goat); + aiReleaseImport(aiscn); + return 0; +} + +void process_material(struct goat3d_material *mtl, struct aiMaterial *aimtl) +{ + struct aiString aistr; + struct aiColor4D color; + float val; + + if(aiGetMaterialString(aimtl, AI_MATKEY_NAME, &aistr) == aiReturn_SUCCESS) { + goat3d_set_mtl_name(mtl, aistr.data); + } + + if(aiGetMaterialColor(aimtl, AI_MATKEY_COLOR_DIFFUSE, &color) == aiReturn_SUCCESS) { + goat3d_set_mtl_attrib3f(mtl, GOAT3D_MAT_ATTR_DIFFUSE, color.r, color.g, color.b); + } + + if(aiGetMaterialColor(aimtl, AI_MATKEY_COLOR_SPECULAR, &color) == aiReturn_SUCCESS) { + float sstr = 1.0; + aiGetMaterialFloatArray(aimtl, AI_MATKEY_SHININESS_STRENGTH, &sstr, 0); + goat3d_set_mtl_attrib3f(mtl, GOAT3D_MAT_ATTR_SPECULAR, color.r * sstr, color.g * sstr, color.b * sstr); + } + + if(aiGetMaterialFloatArray(aimtl, AI_MATKEY_BUMPSCALING, &val, 0) == aiReturn_SUCCESS) { + goat3d_set_mtl_attrib3f(mtl, GOAT3D_MAT_ATTR_BUMP, val, val, val); + } + + if(aiGetMaterialFloatArray(aimtl, AI_MATKEY_REFLECTIVITY, &val, 0) == aiReturn_SUCCESS) { + goat3d_set_mtl_attrib1f(mtl, GOAT3D_MAT_ATTR_REFLECTION, val); + } + + if(aiGetMaterialFloatArray(aimtl, AI_MATKEY_OPACITY, &val, 0) == aiReturn_SUCCESS) { + goat3d_set_mtl_attrib1f(mtl, GOAT3D_MAT_ATTR_TRANSMISSION, 1.0 - val); + } + + if(aiGetMaterialString(aimtl, AI_MATKEY_TEXTURE_DIFFUSE(0), &aistr) == aiReturn_SUCCESS) { + goat3d_set_mtl_attrib_map(mtl, GOAT3D_MAT_ATTR_DIFFUSE, aistr.data); + } + if(aiGetMaterialString(aimtl, AI_MATKEY_TEXTURE_SPECULAR(0), &aistr) == aiReturn_SUCCESS) { + goat3d_set_mtl_attrib_map(mtl, GOAT3D_MAT_ATTR_SPECULAR, aistr.data); + } + if(aiGetMaterialString(aimtl, AI_MATKEY_TEXTURE_SHININESS(0), &aistr) == aiReturn_SUCCESS) { + goat3d_set_mtl_attrib_map(mtl, GOAT3D_MAT_ATTR_SHININESS, aistr.data); + } + if(aiGetMaterialString(aimtl, AI_MATKEY_TEXTURE_NORMALS(0), &aistr) == aiReturn_SUCCESS) { + goat3d_set_mtl_attrib_map(mtl, GOAT3D_MAT_ATTR_NORMAL, aistr.data); + } + if(aiGetMaterialString(aimtl, AI_MATKEY_TEXTURE_REFLECTION(0), &aistr) == aiReturn_SUCCESS) { + goat3d_set_mtl_attrib_map(mtl, GOAT3D_MAT_ATTR_REFLECTION, aistr.data); + } + if(aiGetMaterialString(aimtl, AI_MATKEY_TEXTURE_OPACITY(0), &aistr) == aiReturn_SUCCESS) { + // TODO this is semantically inverted... maybe add an alpha attribute? + goat3d_set_mtl_attrib_map(mtl, GOAT3D_MAT_ATTR_TRANSMISSION, aistr.data); + } +} + +void process_node(struct goat3d *goat, struct goat3d_node *parent, struct aiNode *ainode) +{ + int i; + struct goat3d_node *node; + + node = goat3d_create_node(); + goat3d_set_node_name(node, ainode->mName.data); + + for(i=0; imNumChildren; i++) { + process_node(goat, node, ainode->mChildren[i]); + } + + goat3d_add_node(goat, node); +} diff -r 9ba3e2fb8a33 -r 3d669155709d libs/anim/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libs/anim/Makefile Sun Sep 29 21:53:03 2013 +0300 @@ -0,0 +1,17 @@ +src = $(wildcard *.c) +obj = $(src:.c=.o) +lib = libanim.a + +ifneq ($(shell uname -s), Darwin) + pic = -fPIC +endif + +CFLAGS = -pedantic -Wall -g $(pic) +CXXFLAGS = -pedantic -Wall -g $(pic) + +$(lib): $(obj) + $(AR) rcs $@ $(obj) + +.PHONY: clean +clean: + rm -f $(obj) $(lib) diff -r 9ba3e2fb8a33 -r 3d669155709d libs/vmath/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libs/vmath/Makefile Sun Sep 29 21:53:03 2013 +0300 @@ -0,0 +1,18 @@ +csrc = $(wildcard *.c) +ccsrc = $(wildcard *.cc) +obj = $(csrc:.c=.o) $(ccsrc:.cc=.o) +lib = libvmath.a + +ifneq ($(shell uname -s), Darwin) + pic = -fPIC +endif + +CFLAGS = -pedantic -Wall -g $(pic) +CXXFLAGS = -pedantic -Wall -g $(pic) + +$(lib): $(obj) + $(AR) rcs $@ $(obj) + +.PHONY: clean +clean: + rm -f $(obj) $(lib) diff -r 9ba3e2fb8a33 -r 3d669155709d src/goat3d.cc --- a/src/goat3d.cc Sun Sep 29 08:46:19 2013 +0300 +++ b/src/goat3d.cc Sun Sep 29 21:53:03 2013 +0300 @@ -27,6 +27,8 @@ goat3d *goat = new goat3d; goat->flags = 0; goat->scn = new Scene; + + goat3d_setopt(goat, GOAT3D_OPT_SAVEXML, 1); return goat; } diff -r 9ba3e2fb8a33 -r 3d669155709d src/xform_node.cc --- a/src/xform_node.cc Sun Sep 29 08:46:19 2013 +0300 +++ b/src/xform_node.cc Sun Sep 29 21:53:03 2013 +0300 @@ -1,8 +1,8 @@ #include #include #include "xform_node.h" -#include "anim/anim.h" -#include "anim/track.h" +#include "anim.h" +#include "track.h" static inline anm_interpolator track_interpolator(Interp in); static inline anm_extrapolator track_extrapolator(Extrap ex);