diff options
Diffstat (limited to 'util/meshcvt')
-rw-r--r-- | util/meshcvt/README | 32 | ||||
-rw-r--r-- | util/meshcvt/meshcvt.cpp | 216 | ||||
-rw-r--r-- | util/meshcvt/meshcvt.pro | 8 | ||||
-rw-r--r-- | util/meshcvt/teapot.txt | 340 |
4 files changed, 0 insertions, 596 deletions
diff --git a/util/meshcvt/README b/util/meshcvt/README deleted file mode 100644 index 71679eff..00000000 --- a/util/meshcvt/README +++ /dev/null @@ -1,32 +0,0 @@ -This program converts an object defined as a set of Bezier patches -into vertex array data that can be used to draw it. A Bezier patch -is a curved surface defined in terms of 16 control points. -The object is decomposed into triangles for rendering. - -The primary use for this program is to convert the patch data from -http://www.sjbaker.org/teapot/teaset.tgz for the classic 3D teapot, -but it should work on other objects defined as Bezier patches -or triangle meshes. - -The usage for this utility is: - - meshcvt mesh-filename name [depth] - -The data to represent the object will be written to standard output. -The "depth" parameter indicates the recursive depth for sub-dividing -Bezier patches into triangles. The default value is 4. - -The input file format starts with the number of patches. -The following lines contain 16 indices to define a patch. -The indices should be comma-separated. - -Following the index groups is the number of vertices, and then that -many vertex definitions. Each vertex definition consists of three -floating-point values, comma-separated. Three more comma-separated -floating-point values can appear on the line after the vertex -co-ordinates to define a vertex normal. - -The teapot.txt file provides the data for the classic 3D teapot -from the above URL as an example of what a Bezier patch definition -file looks like. The above URL also has Bezier patch data for a -teacup and a teaspoon, to complete your tea service. diff --git a/util/meshcvt/meshcvt.cpp b/util/meshcvt/meshcvt.cpp deleted file mode 100644 index e01b0452..00000000 --- a/util/meshcvt/meshcvt.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation ([email protected]) -** -** This file is part of the QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <QtGui/qvector3d.h> -#include "qarray.h" - -static void meshError(const char *filename) -{ - qWarning("%s: does not contain valid mesh data\n", filename); - exit(1); -} - -static int numPatches = 0; -static int numVertices = 0; -static int *patches = 0; - -int main(int argc, char *argv[]) -{ - int depth = 4; - int teapotAdjust = 0; - int reversePatches = 0; - char buffer[BUFSIZ]; - char *filename; - char *name; - QArray<QVector3D> vertices; - - // Validate the command-line arguments. - if (argc < 3) { - qWarning("Usage: %s [--teapot-adjust] [--reverse-patches] mesh-filename name [depth]\n", argv[0]); - return 1; - } - if (!strcmp(argv[1], "--teapot-adjust")) { - // Adjust the vertices to correctly size and position the teapot. - ++argv; - --argc; - teapotAdjust = 1; - } - if (!strcmp(argv[1], "--reverse-patches")) { - // Reverse the coordinate order of patches (fixes teacup). - ++argv; - --argc; - reversePatches = 1; - } - filename = argv[1]; - name = argv[2]; - if (argc > 3) - depth = atoi(argv[3]); - - // Read the mesh data from the input file and determine - // if it is a Bezier patch mesh or a triangle mesh. - FILE *file; - if ((file = fopen(filename, "r")) == NULL) { - perror(filename); - return 1; - } - if (fscanf(file, "%i\n", &numPatches) != 1) - meshError(filename); - patches = new int [numPatches * 17]; - for (int patch = 0; patch < numPatches; ++patch) { - int *p = patches + patch * 17; - if (!fgets(buffer, sizeof(buffer), file)) - meshError(filename); - if (sscanf(buffer, "%i, %i, %i, %i, %i, %i, %i, %i, " - "%i, %i, %i, %i, %i, %i, %i, %i, %i\n", - p, p + 1, p + 2, p + 3, - p + 4, p + 5, p + 6, p + 7, - p + 8, p + 9, p + 10, p + 11, - p + 12, p + 13, p + 14, p + 15, p + 16) != 17) { - if (sscanf(buffer, "%i, %i, %i, %i, %i, %i, %i, %i, " - "%i, %i, %i, %i, %i, %i, %i, %i\n", - p, p + 1, p + 2, p + 3, - p + 4, p + 5, p + 6, p + 7, - p + 8, p + 9, p + 10, p + 11, - p + 12, p + 13, p + 14, p + 15) != 16) { - meshError(filename); - } else { - p[16] = -1; // Use the default minimum depth value. - } - } - if (reversePatches) { - int reversed[16]; - for (int i = 0; i < 16; ++i) - reversed[i] = p[(i & 0x0C) + (3 - (i % 4))]; - for (int i = 0; i < 16; ++i) - p[i] = reversed[i]; - } - // The standard patch indices are 1-based, not 0-based. - // Correct for that problem here. - for (int offset = 0; offset < 16; ++offset) - --(p[offset]); - } - if (fscanf(file, "%i\n", &numVertices) != 1) - meshError(filename); - for (int vertex = 0; vertex < numVertices; ++vertex) { - float x, y, z, xnormal, ynormal, znormal; - if (!fgets(buffer, sizeof(buffer), file)) - meshError(filename); - if (sscanf(buffer, "%f, %f, %f, %f, %f, %f\n", - &x, &y, &z, &xnormal, &ynormal, &znormal) != 6) { - if (sscanf(buffer, "%f, %f, %f\n", &x, &y, &z) != 3) - meshError(filename); - } - if (teapotAdjust) { - // Do the equivalent of the following transformation: - // matrix.rotate(270.0f, 1.0f, 0.0f, 0.0f); - // matrix.scale(0.5f, 0.5f, 0.5f); - // matrix.translate(0.0f, 0.0f, -1.5f); - z -= 1.5f; - x *= 0.5f; - y *= 0.5f; - z *= 0.5f; - float y2 = z; - float z2 = -y; - y = y2; - z = z2; - } - vertices.append(QVector3D(x, y, z)); - } - fclose(file); - - // Generate the output data. - printf("// Generated from %s by meshcvt, depth = %d\n\n", filename, depth); - printf("#define %sBezierVertexCount %d\n", name, numVertices); - printf("#define %sPatchCount %d\n", name, numPatches); - printf("#define %sDepth %d\n", name, depth); - printf("static float const %sBezierVertexData[] = {\n", name); - for (int vertex = 0; vertex < vertices.count(); ++vertex) { - QVector3D v = vertices[vertex]; - printf(" %ff, %ff, %ff", v.x(), v.y(), v.z()); - if (vertex < (vertices.count() - 1)) - printf(",\n"); - else - printf("\n"); - } - printf("};\n\n"); - printf("static ushort const %sPatchData[] = {\n", name); - for (int patch = 0; patch < numPatches; ++patch) { - int *p = patches + patch * 17; - printf(" %d, %d, %d, %d, %d, %d, %d, %d, " - "%d, %d, %d, %d, %d, %d, %d, %d", - p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], - p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]); - if (patch < (numPatches - 1)) - printf(",\n"); - else - printf("\n"); - } - printf("};\n"); - printf("\n"); - printf("class %sPatches : public QGLBezierPatches\n{\n", name); - printf("public:\n"); - printf(" %sPatches()\n", name); - printf(" {\n"); - printf(" QVector3DArray positions;\n"); - printf(" for (int pindex = 0; pindex < %sPatchCount * 16; ++pindex) {\n", name); - printf(" int vindex = %sPatchData[pindex];\n", name); - printf(" positions.append(%sBezierVertexData[vindex * 3],\n", name); - printf(" %sBezierVertexData[vindex * 3 + 1],\n", name); - printf(" %sBezierVertexData[vindex * 3 + 2]);\n", name); - printf(" }\n"); - printf(" setPositions(positions);\n"); - printf(" setSubdivisionDepth(%sDepth);\n", name); - printf(" }\n"); - printf("};\n"); - - // Dump some statistics to stderr. - qWarning("Depth: %d\n", depth); - qWarning("Number of vertices: %d\n", numVertices); - qWarning("Number of patches: %d\n", numPatches); - int storage = numVertices * sizeof(float) * 3; - storage += numPatches * sizeof(ushort); - qWarning("Bezier storage: %d bytes\n", storage); - - return 0; -} diff --git a/util/meshcvt/meshcvt.pro b/util/meshcvt/meshcvt.pro deleted file mode 100644 index 53f336af..00000000 --- a/util/meshcvt/meshcvt.pro +++ /dev/null @@ -1,8 +0,0 @@ -TARGET = meshcvt - -CONFIG += qt3d - -SOURCES += \ - meshcvt.cpp \ - -win32:DEFINES+=_CRT_SECURE_NO_WARNINGS diff --git a/util/meshcvt/teapot.txt b/util/meshcvt/teapot.txt deleted file mode 100644 index 9f62bb5e..00000000 --- a/util/meshcvt/teapot.txt +++ /dev/null @@ -1,340 +0,0 @@ -32 -1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 -4,17,18,19,8,20,21,22,12,23,24,25,16,26,27,28 -19,29,30,31,22,32,33,34,25,35,36,37,28,38,39,40 -31,41,42,1,34,43,44,5,37,45,46,9,40,47,48,13 -13,14,15,16,49,50,51,52,53,54,55,56,57,58,59,60 -16,26,27,28,52,61,62,63,56,64,65,66,60,67,68,69 -28,38,39,40,63,70,71,72,66,73,74,75,69,76,77,78 -40,47,48,13,72,79,80,49,75,81,82,53,78,83,84,57 -57,58,59,60,85,86,87,88,89,90,91,92,93,94,95,96 -60,67,68,69,88,97,98,99,92,100,101,102,96,103,104,105 -69,76,77,78,99,106,107,108,102,109,110,111,105,112,113,114 -78,83,84,57,108,115,116,85,111,117,118,89,114,119,120,93 -121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136 -124,137,138,121,128,139,140,125,132,141,142,129,136,143,144,133 -133,134,135,136,145,146,147,148,149,150,151,152,69,153,154,155 -136,143,144,133,148,156,157,145,152,158,159,149,155,160,161,69 -162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177 -165,178,179,162,169,180,181,166,173,182,183,170,177,184,185,174 -174,175,176,177,186,187,188,189,190,191,192,193,194,195,196,197 -177,184,185,174,189,198,199,186,193,200,201,190,197,202,203,194 -204,204,204,204,207,208,209,210,211,211,211,211,212,213,214,215,4 -204,204,204,204,210,217,218,219,211,211,211,211,215,220,221,222,4 -204,204,204,204,219,224,225,226,211,211,211,211,222,227,228,229,4 -204,204,204,204,226,230,231,207,211,211,211,211,229,232,233,212,4 -212,213,214,215,234,235,236,237,238,239,240,241,242,243,244,245 -215,220,221,222,237,246,247,248,241,249,250,251,245,252,253,254 -222,227,228,229,248,255,256,257,251,258,259,260,254,261,262,263 -229,232,233,212,257,264,265,234,260,266,267,238,263,268,269,242 -270,270,270,270,279,280,281,282,275,276,277,278,271,272,273,274,4 -270,270,270,270,282,289,290,291,278,286,287,288,274,283,284,285,4 -270,270,270,270,291,298,299,300,288,295,296,297,285,292,293,294,4 -270,270,270,270,300,305,306,279,297,303,304,275,294,301,302,271,4 -306 -1.4,0.0,2.4 -1.4,-0.784,2.4 -0.784,-1.4,2.4 -0.0,-1.4,2.4 -1.3375,0.0,2.53125 -1.3375,-0.749,2.53125 -0.749,-1.3375,2.53125 -0.0,-1.3375,2.53125 -1.4375,0.0,2.53125 -1.4375,-0.805,2.53125 -0.805,-1.4375,2.53125 -0.0,-1.4375,2.53125 -1.5,0.0,2.4 -1.5,-0.84,2.4 -0.84,-1.5,2.4 -0.0,-1.5,2.4 --0.784,-1.4,2.4 --1.4,-0.784,2.4 --1.4,0.0,2.4 --0.749,-1.3375,2.53125 --1.3375,-0.749,2.53125 --1.3375,0.0,2.53125 --0.805,-1.4375,2.53125 --1.4375,-0.805,2.53125 --1.4375,0.0,2.53125 --0.84,-1.5,2.4 --1.5,-0.84,2.4 --1.5,0.0,2.4 --1.4,0.784,2.4 --0.784,1.4,2.4 -0.0,1.4,2.4 --1.3375,0.749,2.53125 --0.749,1.3375,2.53125 -0.0,1.3375,2.53125 --1.4375,0.805,2.53125 --0.805,1.4375,2.53125 -0.0,1.4375,2.53125 --1.5,0.84,2.4 --0.84,1.5,2.4 -0.0,1.5,2.4 -0.784,1.4,2.4 -1.4,0.784,2.4 -0.749,1.3375,2.53125 -1.3375,0.749,2.53125 -0.805,1.4375,2.53125 -1.4375,0.805,2.53125 -0.84,1.5,2.4 -1.5,0.84,2.4 -1.75,0.0,1.875 -1.75,-0.98,1.875 -0.98,-1.75,1.875 -0.0,-1.75,1.875 -2.0,0.0,1.35 -2.0,-1.12,1.35 -1.12,-2.0,1.35 -0.0,-2.0,1.35 -2.0,0.0,0.9 -2.0,-1.12,0.9 -1.12,-2.0,0.9 -0.0,-2.0,0.9 --0.98,-1.75,1.875 --1.75,-0.98,1.875 --1.75,0.0,1.875 --1.12,-2.0,1.35 --2.0,-1.12,1.35 --2.0,0.0,1.35 --1.12,-2.0,0.9 --2.0,-1.12,0.9 --2.0,0.0,0.9 --1.75,0.98,1.875 --0.98,1.75,1.875 -0.0,1.75,1.875 --2.0,1.12,1.35 --1.12,2.0,1.35 -0.0,2.0,1.35 --2.0,1.12,0.9 --1.12,2.0,0.9 -0.0,2.0,0.9 -0.98,1.75,1.875 -1.75,0.98,1.875 -1.12,2.0,1.35 -2.0,1.12,1.35 -1.12,2.0,0.9 -2.0,1.12,0.9 -2.0,0.0,0.45 -2.0,-1.12,0.45 -1.12,-2.0,0.45 -0.0,-2.0,0.45 -1.5,0.0,0.225 -1.5,-0.84,0.225 -0.84,-1.5,0.225 -0.0,-1.5,0.225 -1.5,0.0,0.15 -1.5,-0.84,0.15 -0.84,-1.5,0.15 -0.0,-1.5,0.15 --1.12,-2.0,0.45 --2.0,-1.12,0.45 --2.0,0.0,0.45 --0.84,-1.5,0.225 --1.5,-0.84,0.225 --1.5,0.0,0.225 --0.84,-1.5,0.15 --1.5,-0.84,0.15 --1.5,0.0,0.15 --2.0,1.12,0.45 --1.12,2.0,0.45 -0.0,2.0,0.45 --1.5,0.84,0.225 --0.84,1.5,0.225 -0.0,1.5,0.225 --1.5,0.84,0.15 --0.84,1.5,0.15 -0.0,1.5,0.15 -1.12,2.0,0.45 -2.0,1.12,0.45 -0.84,1.5,0.225 -1.5,0.84,0.225 -0.84,1.5,0.15 -1.5,0.84,0.15 --1.6,0.0,2.025 --1.6,-0.3,2.025 --1.5,-0.3,2.25 --1.5,0.0,2.25 --2.3,0.0,2.025 --2.3,-0.3,2.025 --2.5,-0.3,2.25 --2.5,0.0,2.25 --2.7,0.0,2.025 --2.7,-0.3,2.025 --3.0,-0.3,2.25 --3.0,0.0,2.25 --2.7,0.0,1.8 --2.7,-0.3,1.8 --3.0,-0.3,1.8 --3.0,0.0,1.8 --1.5,0.3,2.25 --1.6,0.3,2.025 --2.5,0.3,2.25 --2.3,0.3,2.025 --3.0,0.3,2.25 --2.7,0.3,2.025 --3.0,0.3,1.8 --2.7,0.3,1.8 --2.7,0.0,1.575 --2.7,-0.3,1.575 --3.0,-0.3,1.35 --3.0,0.0,1.35 --2.5,0.0,1.125 --2.5,-0.3,1.125 --2.65,-0.3,0.9375 --2.65,0.0,0.9375 --2.0,-0.3,0.9 --1.9,-0.3,0.6 --1.9,0.0,0.6 --3.0,0.3,1.35 --2.7,0.3,1.575 --2.65,0.3,0.9375 --2.5,0.3,1.125 --1.9,0.3,0.6 --2.0,0.3,0.9 -1.7,0.0,1.425 -1.7,-0.66,1.425 -1.7,-0.66,0.6 -1.7,0.0,0.6 -2.6,0.0,1.425 -2.6,-0.66,1.425 -3.1,-0.66,0.825 -3.1,0.0,0.825 -2.3,0.0,2.1 -2.3,-0.25,2.1 -2.4,-0.25,2.025 -2.4,0.0,2.025 -2.7,0.0,2.4 -2.7,-0.25,2.4 -3.3,-0.25,2.4 -3.3,0.0,2.4 -1.7,0.66,0.6 -1.7,0.66,1.425 -3.1,0.66,0.825 -2.6,0.66,1.425 -2.4,0.25,2.025 -2.3,0.25,2.1 -3.3,0.25,2.4 -2.7,0.25,2.4 -2.8,0.0,2.475 -2.8,-0.25,2.475 -3.525,-0.25,2.49375 -3.525,0.0,2.49375 -2.9,0.0,2.475 -2.9,-0.15,2.475 -3.45,-0.15,2.5125 -3.45,0.0,2.5125 -2.8,0.0,2.4 -2.8,-0.15,2.4 -3.2,-0.15,2.4 -3.2,0.0,2.4 -3.525,0.25,2.49375 -2.8,0.25,2.475 -3.45,0.15,2.5125 -2.9,0.15,2.475 -3.2,0.15,2.4 -2.8,0.15,2.4 -0.0,0.0,3.15 -0.0,-0.002,3.15 -0.002,0.0,3.15 -0.8,0.0,3.15 -0.8,-0.45,3.15 -0.45,-0.8,3.15 -0.0,-0.8,3.15 -0.0,0.0,2.85,0.0,0.0,1.0 -0.2,0.0,2.7 -0.2,-0.112,2.7 -0.112,-0.2,2.7 -0.0,-0.2,2.7 --0.002,0.0,3.15 --0.45,-0.8,3.15 --0.8,-0.45,3.15 --0.8,0.0,3.15 --0.112,-0.2,2.7 --0.2,-0.112,2.7 --0.2,0.0,2.7 -0.0,0.002,3.15 --0.8,0.45,3.15 --0.45,0.8,3.15 -0.0,0.8,3.15 --0.2,0.112,2.7 --0.112,0.2,2.7 -0.0,0.2,2.7 -0.45,0.8,3.15 -0.8,0.45,3.15 -0.112,0.2,2.7 -0.2,0.112,2.7 -0.4,0.0,2.55 -0.4,-0.224,2.55 -0.224,-0.4,2.55 -0.0,-0.4,2.55 -1.3,0.0,2.55 -1.3,-0.728,2.55 -0.728,-1.3,2.55 -0.0,-1.3,2.55 -1.3,0.0,2.4 -1.3,-0.728,2.4 -0.728,-1.3,2.4 -0.0,-1.3,2.4 --0.224,-0.4,2.55 --0.4,-0.224,2.55 --0.4,0.0,2.55 --0.728,-1.3,2.55 --1.3,-0.728,2.55 --1.3,0.0,2.55 --0.728,-1.3,2.4 --1.3,-0.728,2.4 --1.3,0.0,2.4 --0.4,0.224,2.55 --0.224,0.4,2.55 -0.0,0.4,2.55 --1.3,0.728,2.55 --0.728,1.3,2.55 -0.0,1.3,2.55 --1.3,0.728,2.4 --0.728,1.3,2.4 -0.0,1.3,2.4 -0.224,0.4,2.55 -0.4,0.224,2.55 -0.728,1.3,2.55 -1.3,0.728,2.55 -0.728,1.3,2.4 -1.3,0.728,2.4 -0.0,0.0,0.0,0.0,0.0,-1.0 -1.5,0.0,0.15 -1.5,0.84,0.15 -0.84,1.5,0.15 -0.0,1.5,0.15 -1.5,0.0,0.075 -1.5,0.84,0.075 -0.84,1.5,0.075 -0.0,1.5,0.075 -1.425,0.0,0.0 -1.425,0.798,0.0 -0.798,1.425,0.0 -0.0,1.425,0.0 --0.84,1.5,0.15 --1.5,0.84,0.15 --1.5,0.0,0.15 --0.84,1.5,0.075 --1.5,0.84,0.075 --1.5,0.0,0.075 --0.798,1.425,0.0 --1.425,0.798,0.0 --1.425,0.0,0.0 --1.5,-0.84,0.15 --0.84,-1.5,0.15 -0.0,-1.5,0.15 --1.5,-0.84,0.075 --0.84,-1.5,0.075 -0.0,-1.5,0.075 --1.425,-0.798,0.0 --0.798,-1.425,0.0 -0.0,-1.425,0.0 -0.84,-1.5,0.15 -1.5,-0.84,0.15 -0.84,-1.5,0.075 -1.5,-0.84,0.075 -0.798,-1.425,0.0 -1.425,-0.798,0.0 |