2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Contributor(s): Nicholas Bishop
20 * ***** END GPL LICENSE BLOCK *****
25 #include "ModelReader.h"
30 void veccopy(float dst[3], const float src[3])
37 #define GET_FACE(_mesh, _n) \
38 (*(DualConFaces)(((char*)(_mesh)->faces) + ((_n) * (_mesh)->face_stride)))
40 #define GET_CO(_mesh, _n) \
41 (*(DualConCo)(((char*)(_mesh)->co) + ((_n) * (_mesh)->co_stride)))
43 class DualConInputReader : public ModelReader
46 const DualConInput *input_mesh;
47 int tottri, curface, offset;
48 float min[3], max[3], maxsize;
51 DualConInputReader(const DualConInput *mesh, float _scale)
52 : input_mesh(mesh), scale(_scale)
64 /* initialize tottri */
65 for(int i = 0; i < input_mesh->totface; i++)
66 tottri += GET_FACE(input_mesh, i)[3] ? 2 : 1;
68 veccopy(min, input_mesh->min);
69 veccopy(max, input_mesh->max);
71 /* initialize maxsize */
72 for(int i = 0; i < 3; i++) {
73 float d = max[i] - min[i];
79 for(int i = 0; i < 3; i++)
81 min[i] = (max[i] + min[i]) / 2 - maxsize / 2;
82 max[i] = (max[i] + min[i]) / 2 + maxsize / 2;
85 for(int i = 0; i < 3; i++)
86 min[i] -= maxsize * (1 / scale - 1) / 2;
90 Triangle* getNextTriangle()
92 if(curface == input_mesh->totface)
95 Triangle* t = new Triangle();
97 unsigned int *f = GET_FACE(input_mesh, curface);
99 veccopy(t->vt[0], GET_CO(input_mesh, f[0]));
100 veccopy(t->vt[1], GET_CO(input_mesh, f[1]));
101 veccopy(t->vt[2], GET_CO(input_mesh, f[2]));
104 veccopy(t->vt[0], GET_CO(input_mesh, f[2]));
105 veccopy(t->vt[1], GET_CO(input_mesh, f[3]));
106 veccopy(t->vt[2], GET_CO(input_mesh, f[0]));
109 if(offset == 0 && f[3])
119 int getNextTriangle(int t[3])
121 if(curface == input_mesh->totface)
124 unsigned int *f = GET_FACE(input_mesh, curface);
136 if(offset == 0 && f[3])
146 int getNumTriangles()
153 return input_mesh->totco;
156 float getBoundingBox(float origin[3])
158 veccopy(origin, min);
163 void getNextVertex(float v[3])
170 int getMemory() { return sizeof(DualConInputReader); }
173 void *dualcon(const DualConInput *input_mesh,
174 /* callbacks for output */
175 DualConAllocOutput alloc_output,
176 DualConAddVert add_vert,
177 DualConAddQuad add_quad,
186 DualConInputReader r(input_mesh, scale);
187 Octree o(&r, alloc_output, add_vert, add_quad,
188 flags, mode, depth, threshold, hermite_num);
190 return o.getOutputMesh();