sop

所属分类:OpenGL
开发工具:C
文件大小:0KB
下载次数:0
上传日期:2016-04-17 19:15:08
上 传 者sh-1993
说明:  简单OBJ分析器,
(Simple OBJ Parser,)

文件列表:
LICENSE (1090, 2016-04-17)
Makefile (1124, 2016-04-17)
example/ (0, 2016-04-17)
example/Makefile (429, 2016-04-17)
example/glisy.c (10404, 2016-04-17)
example/obj/ (0, 2016-04-17)
example/obj/sphere.mtl (260, 2016-04-17)
example/shader/ (0, 2016-04-17)
example/shader/fragment.glsl (132, 2016-04-17)
example/shader/vertex.glsl (190, 2016-04-17)
include/ (0, 2016-04-17)
include/sop/ (0, 2016-04-17)
include/sop/sop.h (5118, 2016-04-17)
package.json (441, 2016-04-17)
src/ (0, 2016-04-17)
src/sop.c (11411, 2016-04-17)
test/ (0, 2016-04-17)
test/Makefile (391, 2016-04-17)
test/fixtures/ (0, 2016-04-17)
test/fixtures/cube.mtl (958, 2016-04-17)
test/fixtures/teapot.obj (210614, 2016-04-17)
test/fixtures/teddy.obj (91538, 2016-04-17)
test/material.c (4958, 2016-04-17)
test/simple.c (4415, 2016-04-17)
test/teapot.c (2312, 2016-04-17)
test/teddy.c (2303, 2016-04-17)
test/test.c (171, 2016-04-17)
test/test.h (317, 2016-04-17)

# Simple OBJ Parser (SOP) Simple OBJ File Format Parser written in C99. This library makes it easy to parse OBJ files for quickly loading simple models in OpenGL. The parser provides a callback interfaces giving the consumer the responsibility of storing Geometric Vertices (v), Texture Vertices (vt), Vertext Normals (vn), and Face Indices (f). This library can be built from source or consumed with [clib](https://github.com/clibs/clib). ## Installation ### Building from source Building from source is simple: * Clone the repository `git clone git@github.com:littlstar/sop.git` * Change directory to project directory `cd sop` * Build the library `make` * Run tests `make test` * Install into system `make install` (Uninstall with `make uninstall`) * or copy static libary into your project with the headers found in `include/` ### Adding to your clib project #### Installing library source into your project ```sh $ clib install littlstar/sop --save ``` #### Adding source to your project ##### In a Makefile Append to the source explicitly: ```Makefile SRC += $(wildcard deps/sop/*.c) ``` or everything found in `deps/`: ```Makefile SRC += $(wildcard deps/*/*.c) ``` Append include path to `CFLAGS` explicitly: ```Makefile CFLAGS += -Ideps ``` ##### From the command line ``` $ gcc -Ideps deps/sop/*.c *.c ``` ### Usage/Example Consider this simple model describing a cube ```obj ## This is a comment v -0.5 -0.5 +0.5 v +0.5 -0.5 +0.5 v -0.5 +0.5 +0.5 v +0.5 +0.5 +0.5 v -0.5 -0.5 -0.5 v +0.5 -0.5 -0.5 v -0.5 +0.5 -0.5 v +0.5 +0.5 -0.5 f 0 1 3 f 0 3 2 f 1 5 7 f 1 7 3 f 5 4 6 f 5 6 7 f 4 0 2 f 4 2 6 f 4 5 1 f 4 1 0 f 2 3 7 f 2 7 6 ``` ```c #include #include #include #include static int oncomment(const sop_parser_state_t *state, const sop_parser_line_state_t line); static int onvertex(const sop_parser_state_t *state, const sop_parser_line_state_t line); static int onface(const sop_parser_state_t *state, const sop_parser_line_state_t line); int main(void) { const char *src = fs_read("cube.obj"); sop_parser_t parser; sop_parser_options_t options = { .callbacks = { .oncomment = oncomment, .ontexture = ontexture, .onvertex = onvertex, .onface = onface } }; assert(SOP_EOK == sop_parser_init(&parser, &options)); assert(SOP_EOK == sop_parser_execute(&parser, src, strlen(src))); return 0; } static int oncomment(const sop_parser_state_t *state, const sop_parser_line_state_t line) { char message[BUFSIZ]; TestState.counters.comments++; if (line.data && strlen((char *) line.data)) { // do something with comment } return SOP_EOK; } static int onvertex(const sop_parser_state_t *state, const sop_parser_line_state_t line) { // (x y z) - we ignore w component float vertex[3]; if (line.data) { memcpy(vertex, line.data, sizeof(vertex)); // do something vertex data } return SOP_EOK; } static int onface(const sop_parser_state_t *state, const sop_parser_line_state_t line) { int faces[3][3]; int vf[3], vtf[3], vnf[3]; // vertex, texture, & normal faces if (line.data) { memcpy(faces, line.data, sizeof(faces)); memcpy(vf, faces[0], sizeof(faces[0])); memcpy(vtf, faces[1], sizeof(faces[1])); memcpy(vnf, faces[2], sizeof(faces[2])); // do something face data } return SOP_EOK; } ``` ## License MIT

近期下载者

相关文件


收藏者