GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — tinyobjloader/python/main.cpp at master · ezhangle/tinyobjloader Expand file tree/ Copy pathmain.cppMore file actions 148 lines (113 loc) · 4.26 KB / Copy pathmain.cppFile metadata and controls148 lines (113 loc) · 4.26 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 //python3 module for tinyobjloader // //usage: // import tinyobjloader as tol // model = tol.LoadObj(name) // print(model["shapes"]) // print(model["materials"] #include <Python.h> #include <vector> #include "../tiny_obj_loader.h" typedef std::vector<double> vectd; PyObject* pyTupleFromfloat3 (float array[3]) { int i; PyObject* tuple = PyTuple_New(3); for(i=0; i<=2 ; i++){ PyTuple_SetItem(tuple, i, PyFloat_FromDouble(array[i])); } return tuple; } extern "C" { static PyObject* pyLoadObj(PyObject* self, PyObject* args) { PyObject *rtndict, *pyshapes, *pymaterials, *current, *meshobj; char const* filename; char *current_name; vectd vect; std::vector<tinyobj::shape_t> shapes; std::vector<tinyobj::material_t> materials; if(!PyArg_ParseTuple(args, "s", &filename)) return NULL; tinyobj::LoadObj(shapes, materials, filename); pyshapes = PyDict_New(); pymaterials = PyDict_New(); rtndict = PyDict_New(); for (std::vector<tinyobj::shape_t>::iterator shape = shapes.begin() ; shape != shapes.end(); shape++) { meshobj = PyDict_New(); tinyobj::mesh_t cm = (*shape).mesh; for (int i = 0; i <= 4; i++ ) { current = PyList_New(0); switch(i) { case 0: current_name = "positions"; vect = vectd(cm.positions.begin(), cm.positions.end()); break; case 1: current_name = "normals"; vect = vectd(cm.normals.begin(), cm.normals.end()); break; case 2: current_name = "texcoords"; vect = vectd(cm.texcoords.begin(), cm.texcoords.end()); break; case 3: current_name = "indicies"; vect = vectd(cm.indices.begin(), cm.indices.end()); break; case 4: current_name = "material_ids"; vect = vectd(cm.material_ids.begin(), cm.material_ids.end()); break; } for (vectd::iterator it = vect.begin() ; it != vect.end(); it++) { PyList_Insert(current, it - vect.begin(), PyFloat_FromDouble(*it)); } PyDict_SetItemString(meshobj, current_name, current); } PyDict_SetItemString(pyshapes, (*shape).name.c_str(), meshobj); } for (std::vector<tinyobj::material_t>::iterator mat = materials.begin() ; mat != materials.end(); mat++) { PyObject *matobj = PyDict_New(); PyDict_SetItemString(matobj, "shininess", PyFloat_FromDouble((*mat).shininess)); PyDict_SetItemString(matobj, "ior", PyFloat_FromDouble((*mat).ior)); PyDict_SetItemString(matobj, "dissolve", PyFloat_FromDouble((*mat).dissolve)); PyDict_SetItemString(matobj, "illum", PyLong_FromLong((*mat).illum)); PyDict_SetItemString(matobj, "ambient_texname", PyUnicode_FromString((*mat).ambient_texname.c_str())); PyDict_SetItemString(matobj, "diffuse_texname", PyUnicode_FromString((*mat).diffuse_texname.c_str())); PyDict_SetItemString(matobj, "specular_texname", PyUnicode_FromString((*mat).specular_texname.c_str())); PyDict_SetItemString(matobj, "normal_texname", PyUnicode_FromString((*mat).normal_texname.c_str())); PyDict_SetItemString(matobj, "ambient", pyTupleFromfloat3((*mat).ambient)); PyDict_SetItemString(matobj, "diffuse", pyTupleFromfloat3((*mat).diffuse)); PyDict_SetItemString(matobj, "specular", pyTupleFromfloat3((*mat).specular)); PyDict_SetItemString(matobj, "transmittance", pyTupleFromfloat3((*mat).transmittance)); PyDict_SetItemString(matobj, "emission", pyTupleFromfloat3((*mat).emission)); PyDict_SetItemString(pymaterials, (*mat).name.c_str(), matobj); } PyDict_SetItemString(rtndict, "shapes", pyshapes); PyDict_SetItemString(rtndict, "materials", pymaterials); return rtndict; } static PyMethodDef mMethods[] = { {"LoadObj", pyLoadObj, METH_VARARGS}, {NULL, NULL, 0, NULL} }; static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, "tinyobjloader", NULL, -1, mMethods }; PyMODINIT_FUNC PyInit_tinyobjloader(void) { return PyModule_Create(&moduledef); } } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |