From 111e5905c7d753321a48948d6957a7f56b8230af Mon Sep 17 00:00:00 2001 From: slack Date: Mon, 11 Jan 2010 04:16:43 +0100 Subject: [PATCH] md5mesh file parser should work now --- Makefile | 224 ----------------------------------------------- mainwindow.ui | 2 +- md5joint.h | 1 + md5mesh.h | 13 +++ md5model.cpp | 134 +++++++++++++++++++++++++++- md5model.h | 6 +- md5tri.h | 5 ++ md5triangle.h | 17 ++++ md5vertex.h | 15 ++++ md5view.pro | 5 +- md5view.pro.user | 32 +++---- md5weight.h | 17 ++++ viewerwidget.cpp | 9 +- viewerwidget.h | 3 + 14 files changed, 236 insertions(+), 247 deletions(-) delete mode 100644 Makefile create mode 100644 md5tri.h create mode 100644 md5triangle.h create mode 100644 md5vertex.h create mode 100644 md5weight.h diff --git a/Makefile b/Makefile deleted file mode 100644 index 4aaff0a..0000000 --- a/Makefile +++ /dev/null @@ -1,224 +0,0 @@ -############################################################################# -# Makefile for building: md5view -# Generated by qmake (2.01a) (Qt 4.5.2) on: Sun Jan 10 04:17:42 2010 -# Project: md5view.pro -# Template: app -# Command: /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile md5view.pro -############################################################################# - -####### Compiler, tools and options - -CC = gcc -CXX = g++ -DEFINES = -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -CFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES) -CXXFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES) -INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I/usr/X11R6/include -I. -I. -LINK = g++ -LFLAGS = -LIBS = $(SUBLIBS) -L/usr/lib -L/usr/X11R6/lib -lQtOpenGL -lQtGui -lQtCore -lGLU -lGL -lpthread -AR = ar cqs -RANLIB = -QMAKE = /usr/bin/qmake-qt4 -TAR = tar -cf -COMPRESS = gzip -9f -COPY = cp -f -SED = sed -COPY_FILE = $(COPY) -COPY_DIR = $(COPY) -r -INSTALL_FILE = install -m 644 -p -INSTALL_DIR = $(COPY_DIR) -INSTALL_PROGRAM = install -m 755 -p -DEL_FILE = rm -f -SYMLINK = ln -sf -DEL_DIR = rmdir -MOVE = mv -f -CHK_DIR_EXISTS= test -d -MKDIR = mkdir -p - -####### Output directory - -OBJECTS_DIR = ./ - -####### Files - -SOURCES = main.cpp \ - mainwindow.cpp \ - viewerwidget.cpp moc_mainwindow.cpp -OBJECTS = main.o \ - mainwindow.o \ - viewerwidget.o \ - moc_mainwindow.o -DIST = /usr/share/qt4/mkspecs/common/g++.conf \ - /usr/share/qt4/mkspecs/common/unix.conf \ - /usr/share/qt4/mkspecs/common/linux.conf \ - /usr/share/qt4/mkspecs/qconfig.pri \ - /usr/share/qt4/mkspecs/features/qt_functions.prf \ - /usr/share/qt4/mkspecs/features/qt_config.prf \ - /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ - /usr/share/qt4/mkspecs/features/default_pre.prf \ - /usr/share/qt4/mkspecs/features/debug.prf \ - /usr/share/qt4/mkspecs/features/default_post.prf \ - /usr/share/qt4/mkspecs/features/warn_on.prf \ - /usr/share/qt4/mkspecs/features/qt.prf \ - /usr/share/qt4/mkspecs/features/unix/opengl.prf \ - /usr/share/qt4/mkspecs/features/unix/thread.prf \ - /usr/share/qt4/mkspecs/features/moc.prf \ - /usr/share/qt4/mkspecs/features/resources.prf \ - /usr/share/qt4/mkspecs/features/uic.prf \ - /usr/share/qt4/mkspecs/features/yacc.prf \ - /usr/share/qt4/mkspecs/features/lex.prf \ - /usr/share/qt4/mkspecs/features/include_source_dir.prf \ - md5view.pro -QMAKE_TARGET = md5view -DESTDIR = -TARGET = md5view - -first: all -####### Implicit rules - -.SUFFIXES: .o .c .cpp .cc .cxx .C - -.cpp.o: - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" - -.cc.o: - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" - -.cxx.o: - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" - -.C.o: - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" - -.c.o: - $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<" - -####### Build rules - -all: Makefile $(TARGET) - -$(TARGET): ui_mainwindow.h $(OBJECTS) - $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS) - -Makefile: md5view.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/mkspecs/common/g++.conf \ - /usr/share/qt4/mkspecs/common/unix.conf \ - /usr/share/qt4/mkspecs/common/linux.conf \ - /usr/share/qt4/mkspecs/qconfig.pri \ - /usr/share/qt4/mkspecs/features/qt_functions.prf \ - /usr/share/qt4/mkspecs/features/qt_config.prf \ - /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ - /usr/share/qt4/mkspecs/features/default_pre.prf \ - /usr/share/qt4/mkspecs/features/debug.prf \ - /usr/share/qt4/mkspecs/features/default_post.prf \ - /usr/share/qt4/mkspecs/features/warn_on.prf \ - /usr/share/qt4/mkspecs/features/qt.prf \ - /usr/share/qt4/mkspecs/features/unix/opengl.prf \ - /usr/share/qt4/mkspecs/features/unix/thread.prf \ - /usr/share/qt4/mkspecs/features/moc.prf \ - /usr/share/qt4/mkspecs/features/resources.prf \ - /usr/share/qt4/mkspecs/features/uic.prf \ - /usr/share/qt4/mkspecs/features/yacc.prf \ - /usr/share/qt4/mkspecs/features/lex.prf \ - /usr/share/qt4/mkspecs/features/include_source_dir.prf \ - /usr/lib/libQtOpenGL.prl \ - /usr/lib/libQtGui.prl \ - /usr/lib/libQtCore.prl - $(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile md5view.pro -/usr/share/qt4/mkspecs/common/g++.conf: -/usr/share/qt4/mkspecs/common/unix.conf: -/usr/share/qt4/mkspecs/common/linux.conf: -/usr/share/qt4/mkspecs/qconfig.pri: -/usr/share/qt4/mkspecs/features/qt_functions.prf: -/usr/share/qt4/mkspecs/features/qt_config.prf: -/usr/share/qt4/mkspecs/features/exclusive_builds.prf: -/usr/share/qt4/mkspecs/features/default_pre.prf: -/usr/share/qt4/mkspecs/features/debug.prf: -/usr/share/qt4/mkspecs/features/default_post.prf: -/usr/share/qt4/mkspecs/features/warn_on.prf: -/usr/share/qt4/mkspecs/features/qt.prf: -/usr/share/qt4/mkspecs/features/unix/opengl.prf: -/usr/share/qt4/mkspecs/features/unix/thread.prf: -/usr/share/qt4/mkspecs/features/moc.prf: -/usr/share/qt4/mkspecs/features/resources.prf: -/usr/share/qt4/mkspecs/features/uic.prf: -/usr/share/qt4/mkspecs/features/yacc.prf: -/usr/share/qt4/mkspecs/features/lex.prf: -/usr/share/qt4/mkspecs/features/include_source_dir.prf: -/usr/lib/libQtOpenGL.prl: -/usr/lib/libQtGui.prl: -/usr/lib/libQtCore.prl: -qmake: FORCE - @$(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile md5view.pro - -dist: - @$(CHK_DIR_EXISTS) .tmp/md5view1.0.0 || $(MKDIR) .tmp/md5view1.0.0 - $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/md5view1.0.0/ && $(COPY_FILE) --parents mainwindow.h viewerwidget.h .tmp/md5view1.0.0/ && $(COPY_FILE) --parents main.cpp mainwindow.cpp viewerwidget.cpp .tmp/md5view1.0.0/ && $(COPY_FILE) --parents mainwindow.ui .tmp/md5view1.0.0/ && (cd `dirname .tmp/md5view1.0.0` && $(TAR) md5view1.0.0.tar md5view1.0.0 && $(COMPRESS) md5view1.0.0.tar) && $(MOVE) `dirname .tmp/md5view1.0.0`/md5view1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/md5view1.0.0 - - -clean:compiler_clean - -$(DEL_FILE) $(OBJECTS) - -$(DEL_FILE) *~ core *.core - - -####### Sub-libraries - -distclean: clean - -$(DEL_FILE) $(TARGET) - -$(DEL_FILE) Makefile - - -mocclean: compiler_moc_header_clean compiler_moc_source_clean - -mocables: compiler_moc_header_make_all compiler_moc_source_make_all - -compiler_moc_header_make_all: moc_mainwindow.cpp -compiler_moc_header_clean: - -$(DEL_FILE) moc_mainwindow.cpp -moc_mainwindow.cpp: mainwindow.h - /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) mainwindow.h -o moc_mainwindow.cpp - -compiler_rcc_make_all: -compiler_rcc_clean: -compiler_image_collection_make_all: qmake_image_collection.cpp -compiler_image_collection_clean: - -$(DEL_FILE) qmake_image_collection.cpp -compiler_moc_source_make_all: -compiler_moc_source_clean: -compiler_uic_make_all: ui_mainwindow.h -compiler_uic_clean: - -$(DEL_FILE) ui_mainwindow.h -ui_mainwindow.h: mainwindow.ui - /usr/bin/uic-qt4 mainwindow.ui -o ui_mainwindow.h - -compiler_yacc_decl_make_all: -compiler_yacc_decl_clean: -compiler_yacc_impl_make_all: -compiler_yacc_impl_clean: -compiler_lex_make_all: -compiler_lex_clean: -compiler_clean: compiler_moc_header_clean compiler_uic_clean - -####### Compile - -main.o: main.cpp mainwindow.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp - -mainwindow.o: mainwindow.cpp mainwindow.h \ - ui_mainwindow.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o mainwindow.o mainwindow.cpp - -viewerwidget.o: viewerwidget.cpp viewerwidget.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o viewerwidget.o viewerwidget.cpp - -moc_mainwindow.o: moc_mainwindow.cpp - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_mainwindow.o moc_mainwindow.cpp - -####### Install - -install: FORCE - -uninstall: FORCE - -FORCE: - diff --git a/mainwindow.ui b/mainwindow.ui index e0acbec..288f08c 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -30,7 +30,7 @@ - 200 + 500 0 diff --git a/md5joint.h b/md5joint.h index 72ad08f..bc3be1e 100644 --- a/md5joint.h +++ b/md5joint.h @@ -17,6 +17,7 @@ public: MD5Joint(QString name, int parent, float px, float py, float pz, float ox, float oy, float oz); + MD5Joint(){} }; #endif // MD5JOINT_H diff --git a/md5mesh.h b/md5mesh.h index 461990d..ceb6a33 100644 --- a/md5mesh.h +++ b/md5mesh.h @@ -2,12 +2,25 @@ #define MD5MESH_H #include +#include + +#include "md5vertex.h" +#include "md5triangle.h" +#include "md5weight.h" class MD5Mesh { public: QString shader; + int numVertices; + int numTriangles; + int numWeights; + + QVector vertices; + QVector triangles; + QVector weights; + MD5Mesh(); }; diff --git a/md5model.cpp b/md5model.cpp index 7954c15..1d4a42d 100644 --- a/md5model.cpp +++ b/md5model.cpp @@ -1,5 +1,137 @@ #include "md5model.h" -MD5Model::MD5Model() +#include +#include +#include +#include +#include + +#define EXPECT(it, token) do{ if(it.next() != token) { log += QString("ERROR:expected \"")+token+"\"\n"; return; }} while (0) + +MD5Model::MD5Model(const QString& filename) { + QFile file(filename); + QString str, tmp; + + log += "Reading " + filename + "\n"; + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + log += "Error\n"; + return; + } + + QTextStream in(&file); + while(!in.atEnd()) { + tmp = in.readLine(); + tmp.replace(QRegExp("//.*"), ""); + tmp.replace(QRegExp("([(){}\"])"), " \\1 "); + str.append(tmp); + //log += tmp + "\n"; + str.append(" "); + } + + QStringList list=str.split(QRegExp("\\s+"), QString::SkipEmptyParts); + QStringListIterator it(list); + + // check header + if (it.next() != "MD5Version" || it.next() != "10") { + log += "Not an MD5 v.10 file\n"; + return; + } + + // skip commandline + if (it.next() == "commandline") { + it.next(); // skip opening quotes + while(it.next() != "\"") {} + } + + EXPECT(it, "numJoints"); + numJoints = it.next().toInt(); + + EXPECT(it, "numMeshes"); + numMeshes = it.next().toInt(); + + log += QString("numJoints=")+QString::number(numJoints)+" numMeshes="+QString::number(numMeshes)+"\n"; + + EXPECT(it, "joints"); + EXPECT(it, "{"); + for (int i=0; i #include #include "md5joint.h" +#include "md5mesh.h" class MD5Model { + int numJoints; + int numMeshes; QVector joints; QVector meshes; public: - MD5Model(); + MD5Model(const QString& filename); + QString log; }; #endif // MD5MODEL_H diff --git a/md5tri.h b/md5tri.h new file mode 100644 index 0000000..1389190 --- /dev/null +++ b/md5tri.h @@ -0,0 +1,5 @@ +#ifndef MD5TRI_H +#define MD5TRI_H + + +#endif // MD5TRI_H diff --git a/md5triangle.h b/md5triangle.h new file mode 100644 index 0000000..5ff8088 --- /dev/null +++ b/md5triangle.h @@ -0,0 +1,17 @@ +#ifndef MD5TRIANGLE_H +#define MD5TRIANGLE_H + +struct MD5Triangle +{ + int indices[3]; + + MD5Triangle() {} + MD5Triangle(int a, int b, int c) { + indices[0]=a; + indices[1]=b; + indices[2]=c; + } +}; + + +#endif // MD5TRIANGLE_H diff --git a/md5vertex.h b/md5vertex.h new file mode 100644 index 0000000..a20393e --- /dev/null +++ b/md5vertex.h @@ -0,0 +1,15 @@ +#ifndef MD5VERTEX_H +#define MD5VERTEX_H + +struct MD5Vertex +{ + float s, t; // texture coordinates + int startWeight; + int countWeight; + + MD5Vertex(){} + MD5Vertex(float s, float t, int startWeight, int countWeight): + s(s), t(t), startWeight(startWeight), countWeight(countWeight) {} +}; + +#endif // MD5VERTEX_H diff --git a/md5view.pro b/md5view.pro index c814c03..7d12422 100644 --- a/md5view.pro +++ b/md5view.pro @@ -14,5 +14,8 @@ HEADERS += mainwindow.h \ viewerwidget.h \ md5model.h \ md5joint.h \ - md5mesh.h + md5mesh.h \ + md5vertex.h \ + md5triangle.h \ + md5weight.h FORMS += mainwindow.ui diff --git a/md5view.pro.user b/md5view.pro.user index 91dadb7..be52368 100644 --- a/md5view.pro.user +++ b/md5view.pro.user @@ -76,15 +76,15 @@ Debug - DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-Dj3Bbe55NG,guid=c59e58cab9ff6389416a749d4b491a91 + DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-bsAmm1MSNh,guid=a5f27d3b4c48a519c47248434b49ef0d DESKTOP_SESSION=gnome DISPLAY=:0.0 GDMSESSION=gnome GDM_KEYBOARD_LAYOUT=es GDM_LANG=es_ES.UTF-8 GNOME_DESKTOP_SESSION_ID=this-is-deprecated - GNOME_KEYRING_PID=2234 - GNOME_KEYRING_SOCKET=/tmp/keyring-iuKvkY/socket + GNOME_KEYRING_PID=2194 + GNOME_KEYRING_SOCKET=/tmp/keyring-kLJQOr/socket GTK_MODULES=canberra-gtk-module GTK_RC_FILES=/etc/gtk/gtkrc:/home/slack/.gtkrc-1.2-gnome2 HOME=/home/slack @@ -96,16 +96,16 @@ PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games PWD=/home/slack QTDIR=/usr/share/qt4 - SESSION_MANAGER=local/ommadawn:@/tmp/.ICE-unix/2249,unix/ommadawn:/tmp/.ICE-unix/2249 + SESSION_MANAGER=local/ommadawn:@/tmp/.ICE-unix/2209,unix/ommadawn:/tmp/.ICE-unix/2209 SHELL=/bin/bash SPEECHD_PORT=7560 - SSH_AGENT_PID=2300 - SSH_AUTH_SOCK=/tmp/keyring-iuKvkY/socket.ssh + SSH_AGENT_PID=2260 + SSH_AUTH_SOCK=/tmp/keyring-kLJQOr/socket.ssh USER=slack USERNAME=slack - XAUTHORITY=/var/run/gdm/auth-for-slack-dbUjQ9/database + XAUTHORITY=/var/run/gdm/auth-for-slack-AEj533/database XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/ - XDG_SESSION_COOKIE=b95e9de5c0255c87d4458400462bf263-1263082128.724084-492310790 + XDG_SESSION_COOKIE=b95e9de5c0255c87d4458400462bf263-1263136524.238355-1968136452 /home/slack/md5view/md5view.pro @@ -124,15 +124,15 @@ Debug - DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-Dj3Bbe55NG,guid=c59e58cab9ff6389416a749d4b491a91 + DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-bsAmm1MSNh,guid=a5f27d3b4c48a519c47248434b49ef0d DESKTOP_SESSION=gnome DISPLAY=:0.0 GDMSESSION=gnome GDM_KEYBOARD_LAYOUT=es GDM_LANG=es_ES.UTF-8 GNOME_DESKTOP_SESSION_ID=this-is-deprecated - GNOME_KEYRING_PID=2234 - GNOME_KEYRING_SOCKET=/tmp/keyring-iuKvkY/socket + GNOME_KEYRING_PID=2194 + GNOME_KEYRING_SOCKET=/tmp/keyring-kLJQOr/socket GTK_MODULES=canberra-gtk-module GTK_RC_FILES=/etc/gtk/gtkrc:/home/slack/.gtkrc-1.2-gnome2 HOME=/home/slack @@ -144,16 +144,16 @@ PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games PWD=/home/slack QTDIR=/usr/share/qt4 - SESSION_MANAGER=local/ommadawn:@/tmp/.ICE-unix/2249,unix/ommadawn:/tmp/.ICE-unix/2249 + SESSION_MANAGER=local/ommadawn:@/tmp/.ICE-unix/2209,unix/ommadawn:/tmp/.ICE-unix/2209 SHELL=/bin/bash SPEECHD_PORT=7560 - SSH_AGENT_PID=2300 - SSH_AUTH_SOCK=/tmp/keyring-iuKvkY/socket.ssh + SSH_AGENT_PID=2260 + SSH_AUTH_SOCK=/tmp/keyring-kLJQOr/socket.ssh USER=slack USERNAME=slack - XAUTHORITY=/var/run/gdm/auth-for-slack-dbUjQ9/database + XAUTHORITY=/var/run/gdm/auth-for-slack-AEj533/database XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/ - XDG_SESSION_COOKIE=b95e9de5c0255c87d4458400462bf263-1263082128.724084-492310790 + XDG_SESSION_COOKIE=b95e9de5c0255c87d4458400462bf263-1263136524.238355-1968136452 false diff --git a/md5weight.h b/md5weight.h new file mode 100644 index 0000000..e6bafc9 --- /dev/null +++ b/md5weight.h @@ -0,0 +1,17 @@ +#ifndef MD5WEIGHT_H +#define MD5WEIGHT_H + +#include "glm/glm.hpp" + +struct MD5Weight +{ + int joint; + float bias; + glm::vec3 position; + + MD5Weight(){} + MD5Weight(int joint, float bias, float px, float py, float pz): + joint(joint), bias(bias), position(px,py,pz) {} +}; + +#endif // MD5WEIGHT_H diff --git a/viewerwidget.cpp b/viewerwidget.cpp index a535333..3c8c169 100644 --- a/viewerwidget.cpp +++ b/viewerwidget.cpp @@ -2,16 +2,19 @@ #include #include "mainwindow.h" +#include "md5model.h" ViewerWidget::ViewerWidget(MainWindow *parent): QGLWidget(parent) { mainWindow = parent; + model = new MD5Model("meshes/imp.md5mesh"); + mainWindow->writeLog(model->log); } void ViewerWidget::initializeGL() -{ +{ mainWindow->writeLog("Initializing...\n"); if (context()->format().openGLVersionFlags() & QGLFormat::OpenGL_Version_2_1) mainWindow->writeLog("OpenGL 2.1 is available :)\n"); @@ -32,9 +35,9 @@ void ViewerWidget::initializeGL() glAttachShader(shaderProgramID, fragmentShaderID); glEnableVertexAttribArray(0); - glBindAttribLocation(shaderprogram, 0, "in_Position"); + glBindAttribLocation(shaderProgramID, 0, "in_Position"); - glLinkProgram(); + glLinkProgram(shaderProgramID); // Set up the rendering context, define display lists etc.: diff --git a/viewerwidget.h b/viewerwidget.h index d6a28cf..03a0860 100644 --- a/viewerwidget.h +++ b/viewerwidget.h @@ -1,11 +1,13 @@ #ifndef VIEWERWIDGET_H #define VIEWERWIDGET_H +#define GL_GLEXT_PROTOTYPES #include #include #include class MainWindow; +class MD5Model; class ViewerWidget : public QGLWidget { @@ -20,6 +22,7 @@ protected: private: QByteArray readFile(QString filename); MainWindow *mainWindow; + MD5Model *model; QByteArray vertexShaderSource; QByteArray fragmentShaderSource; -- 2.34.1