ref: 06bb0cf6d6dfc0e3591222ee8564f5f1ca9aa054
dir: /obj.2.man/
.TH OBJ 2 .SH NAME objaddvertex, objaddelem, objallocelem, objaddelemidx, objfreeelem, objallocobject, objfreeobject, objpushobject, objgetobject, objfreetexture, objallocmt, objfreemt, objallocmtl, objaddmtl, objgetmtl, objparse, objfree, objmtlparse, objmtlfree, objexport, OBJMaterlistfmt, OBJfmt, OBJfmtinstall \- OBJ parser .SH SYNOPSIS .ta 0.7i +0.7i +0.7i +0.7i +0.7i +0.7i +0.7i .EX #include <u.h> #include <libc.h> #include <obj.h> /* vertex types */ enum { OBJVGeometric, OBJVTexture, OBJVNormal, OBJVParametric, OBJNVERT }; /* element types */ enum { OBJEPoint, OBJELine, OBJEFace, }; /* object hash table size */ enum { OBJHTSIZE = 17 }; typedef union OBJVertex OBJVertex; typedef struct OBJColor OBJColor; typedef struct OBJTexture OBJTexture; typedef struct OBJVertexArray OBJVertexArray; typedef struct OBJIndexArray OBJIndexArray; typedef struct OBJMaterial OBJMaterial; typedef struct OBJMaterlist OBJMaterlist; typedef struct OBJElem OBJElem; typedef struct OBJObject OBJObject; typedef struct OBJ OBJ; #pragma varargck type "O" OBJ* #pragma varargck type "M" OBJMaterlist* union OBJVertex { struct { double x, y, z, w; }; /* geometric */ struct { double u, v, vv; }; /* texture and parametric */ struct { double i, j, k; }; /* normal */ }; struct OBJColor { double r, g, b, a; }; struct OBJTexture { char *filename; Memimage *image; }; struct OBJVertexArray { OBJVertex *verts; int nvert; }; struct OBJIndexArray { int *indices; int nindex; }; struct OBJMaterial { char *name; OBJColor Ka; /* ambient color */ OBJColor Kd; /* diffuse color */ OBJColor Ks; /* specular color */ OBJColor Ke; /* emissive color */ double Ns; /* specular highlight */ double Ni; /* index of refraction */ double d; /* dissolution factor (opacity) */ int illum; /* illumination model */ OBJTexture *map_Kd; /* color texture file */ OBJTexture *map_Ks; /* specular texture file */ OBJTexture *norm; /* normal texture file */ OBJMaterial *next; }; struct OBJMaterlist { char *filename; OBJMaterial *mattab[OBJHTSIZE]; }; struct OBJElem { OBJIndexArray indextab[OBJNVERT]; int type; OBJMaterial *mtl; OBJElem *next; }; struct OBJObject { char *name; OBJElem *child; OBJElem *lastone; OBJObject *next; }; struct OBJ { OBJVertexArray vertdata[OBJNVERT]; OBJObject *objtab[OBJHTSIZE]; OBJMaterlist *materials; }; void objaddvertex(OBJ *obj, OBJVertex v, int vtype) void objaddelem(OBJObject *o, OBJElem *e) OBJElem *objallocelem(int t) void objaddelemidx(OBJElem *e, int idxtab, int idx) void objfreeelem(OBJElem *e) OBJObject *objallocobject(char *n) void objfreeobject(OBJObject *o) void objpushobject(OBJ *obj, OBJObject *o) OBJObject *objgetobject(OBJ *obj, char *n) void objfreetexture(OBJTexture *t) OBJMaterial *objallocmt(char *name) void objfreemt(OBJMaterial *m) OBJMaterlist *objallocmtl(char *file) void objaddmtl(OBJMaterlist *ml, OBJMaterial *m) OBJMaterial *objgetmtl(OBJMaterlist *ml, char *name) OBJ *objparse(char *path) void objfree(OBJ *obj) OBJMaterlist *objmtlparse(char *path) void objmtlfree(OBJMaterlist *ml) int objexport(char *dstdir, OBJ *obj) int OBJMaterlistfmt(Fmt *f) int OBJfmt(Fmt *f) void OBJfmtinstall(void) .EE .SH DESCRIPTION This library provides a parser for the Wavefront OBJ 3d scene description file format. Objects are stored in a hash table within an .B OBJ structure, along with vertex data and materials. .PP .B Objparse takes the .I path to an .B .obj file and returns a pointer to a dynamically allocated .B OBJ structure filled with its content. Object and material names, as well as material list and texture file names are preserved. .PP .B Objfree takes a pointer to a previously allocated .B OBJ structure and frees it along with all of its content, including textures (see .BR OBJTexture .) .PP .B Objmtlparse reads the .B .mtl file provided at .I path and returns a pointer to an allocated .B OBJMaterlist structure. As its name implies, it contains a list of materials, each with a name and a set of properties, including textures. .PP .B Objmtlfree takes a pointer to a previously allocated .B OBJMaterlist and releases its memory and that of its members. .PP .B OBJfmt is a formatting routine used to serialize an .B OBJ structure into text, and .B OBJMaterlistfmt does the same for .B OBJMaterlist structures. You can install them for a custom format label, or use the .B OBJfmtinstall procedure provided with this library to install them for the .B %O and .B %M labels respectively. .SH SOURCE .B /sys/src/libobj .SH SEE ALSO .IR geometry (2), .IR fmtinstall(2) .br http://paulbourke.net/dataformats/obj .br https://people.sc.fsu.edu/~jburkardt/data/obj/obj.html .br https://paulbourke.net/dataformats/mtl/ .br https://www.loc.gov/preservation/digital/formats/fdd/fdd000508.shtml .br https://people.computing.clemson.edu/~dhouse/courses/405/docs/brief-obj-file-format.html .SH DIAGNOSTICS All the routines write to .IR errstr (2) in the event of failure, and return either nil or -1. .SH BUGS There are probably some in the parser. It should be simpler. .PP Objexport uses an internal 8KB buffer for fmt(2) writes that can overflow libthread stacks. If you're getting weird errors with malloc(2) and friends after using it in your program, increase the mainstacksize.