first blood
This commit is contained in:
1 parent
78b528c0af
commit
91d5cabd26
40 files changed
+3861
No files matched your search
@@ -0,0 +1,18 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2012-06-01T11:21:21
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui
|
||||
|
||||
TARGET = Bn1An1Converter
|
||||
TEMPLATE = app
|
||||
|
||||
|
||||
SOURCES += main.cpp\
|
||||
mainwindow.cpp
|
||||
|
||||
HEADERS += mainwindow.h
|
||||
|
||||
FORMS += mainwindow.ui
|
||||
@@ -0,0 +1,11 @@
|
||||
#include <QtGui/QApplication>
|
||||
#include "mainwindow.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
@@ -0,0 +1,387 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QTextStream>
|
||||
|
||||
|
||||
struct TBoneStruct
|
||||
{
|
||||
float v[3];
|
||||
float q[4];
|
||||
float len;
|
||||
|
||||
QString parentBoneName;
|
||||
};
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
QObject::connect(ui->ConvertAn1, SIGNAL(clicked()), this, SLOT(CallConvertAn1()));
|
||||
QObject::connect(ui->ConvertBn1, SIGNAL(clicked()), this, SLOT(CallConvertBn1()));
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::CallConvertAn1()
|
||||
{
|
||||
QFileDialog dialog(this);
|
||||
dialog.setFileMode(QFileDialog::AnyFile);
|
||||
dialog.setAcceptMode(QFileDialog::AcceptOpen);
|
||||
|
||||
if (dialog.exec())
|
||||
{
|
||||
QMessageBox msgBox1;
|
||||
msgBox1.setText("Begin");
|
||||
msgBox1.exec();
|
||||
|
||||
QFile file(dialog.selectedFiles()[0]);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText("Fail");
|
||||
msgBox.exec();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QFileDialog dialogSave(this);
|
||||
dialogSave.setFileMode(QFileDialog::AnyFile);
|
||||
dialogSave.setAcceptMode(QFileDialog::AcceptSave);
|
||||
|
||||
if (!dialogSave.exec())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray saveArr;
|
||||
|
||||
|
||||
QFile saveFile(dialogSave.selectedFiles()[0]);
|
||||
if (!saveFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText("Fail");
|
||||
msgBox.exec();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
QTextStream in(&file);
|
||||
QString line;
|
||||
|
||||
//======= Go file parsing
|
||||
|
||||
saveArr.push_back('A');
|
||||
saveArr.push_back('N');
|
||||
saveArr.push_back((char)0);
|
||||
saveArr.push_back((char)1);
|
||||
|
||||
line = in.readLine();
|
||||
|
||||
int frameCount = line.remove("Frames ").toInt();
|
||||
|
||||
line = in.readLine();
|
||||
|
||||
int boneCount = line.remove("Bones ").toInt();
|
||||
|
||||
saveArr.insert(saveArr.size(), (char*)&boneCount, 4);
|
||||
saveArr.insert(saveArr.size(), (char*)&frameCount, 4);
|
||||
|
||||
QStringList splited;
|
||||
|
||||
float v[3];
|
||||
float q[4];
|
||||
|
||||
float len;
|
||||
|
||||
for (int i=0; i<frameCount; i++)
|
||||
{
|
||||
|
||||
line = in.readLine();
|
||||
|
||||
for (int j=0; j<boneCount; j++)
|
||||
{
|
||||
|
||||
line = in.readLine();
|
||||
splited = line.split(" ", QString::SkipEmptyParts);
|
||||
|
||||
v[0] = splited.at(0).toFloat()*0.1;
|
||||
v[1] = splited.at(2).toFloat()*0.1;
|
||||
v[2] = -splited.at(1).toFloat()*0.1;
|
||||
|
||||
line = in.readLine();
|
||||
splited = line.split(" ", QString::SkipEmptyParts);
|
||||
|
||||
q[0] = splited.at(0).toFloat();
|
||||
q[1] = splited.at(2).toFloat();
|
||||
q[2] = -splited.at(1).toFloat();
|
||||
q[3] = splited.at(3).toFloat();
|
||||
|
||||
line = in.readLine();
|
||||
len = line.toFloat()*0.1;
|
||||
|
||||
saveArr.insert(saveArr.size(), (char*)v, 12);
|
||||
saveArr.insert(saveArr.size(), (char*)q, 16);
|
||||
saveArr.insert(saveArr.size(), (char*)&len, 4);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
saveFile.write(saveArr);
|
||||
|
||||
//======= End file parsing
|
||||
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText("End");
|
||||
msgBox.exec();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::CallConvertBn1()
|
||||
{
|
||||
QFileDialog dialog(this);
|
||||
dialog.setFileMode(QFileDialog::AnyFile);
|
||||
dialog.setAcceptMode(QFileDialog::AcceptOpen);
|
||||
|
||||
if (dialog.exec())
|
||||
{
|
||||
QMessageBox msgBox1;
|
||||
msgBox1.setText("Begin");
|
||||
msgBox1.exec();
|
||||
|
||||
QFile file(dialog.selectedFiles()[0]);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText("Fail");
|
||||
msgBox.exec();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
QFileDialog dialogSave(this);
|
||||
dialogSave.setFileMode(QFileDialog::AnyFile);
|
||||
dialogSave.setAcceptMode(QFileDialog::AcceptSave);
|
||||
|
||||
if (!dialogSave.exec())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray saveArr;
|
||||
|
||||
|
||||
QFile saveFile(dialogSave.selectedFiles()[0]);
|
||||
if (!saveFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText("Fail");
|
||||
msgBox.exec();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
saveArr.push_back('B');
|
||||
saveArr.push_back('N');
|
||||
saveArr.push_back((char)0);
|
||||
saveArr.push_back((char)2);
|
||||
|
||||
|
||||
QTextStream in(&file);
|
||||
QString line;
|
||||
|
||||
int boneCount;
|
||||
|
||||
QString boneName;
|
||||
QString parentBoneName;
|
||||
|
||||
float v[3];
|
||||
float q[4];
|
||||
|
||||
float len;
|
||||
|
||||
QStringList splited;
|
||||
|
||||
std::map<QString, int> boneNameMap;
|
||||
|
||||
//======= Go file parsing
|
||||
|
||||
line = in.readLine();
|
||||
|
||||
boneCount = line.remove("Bones ").toInt();
|
||||
|
||||
std::vector<TBoneStruct> boneStructMap;
|
||||
|
||||
for (int i=0; i<boneCount; i++)
|
||||
{
|
||||
|
||||
TBoneStruct b;
|
||||
|
||||
line = in.readLine();
|
||||
boneName = line;
|
||||
|
||||
boneNameMap[boneName] = i;
|
||||
|
||||
line = in.readLine();
|
||||
splited = line.split(" ", QString::SkipEmptyParts);
|
||||
|
||||
b.v[0] = splited.at(0).toFloat()*0.1;
|
||||
b.v[1] = splited.at(2).toFloat()*0.1;
|
||||
b.v[2] = -splited.at(1).toFloat()*0.1;
|
||||
|
||||
line = in.readLine();
|
||||
splited = line.split(" ", QString::SkipEmptyParts);
|
||||
|
||||
b.q[0] = splited.at(0).toFloat();
|
||||
b.q[1] = splited.at(2).toFloat();
|
||||
b.q[2] = -splited.at(1).toFloat();
|
||||
b.q[3] = splited.at(3).toFloat();
|
||||
|
||||
line = in.readLine();
|
||||
b.len = line.toFloat()*0.1;
|
||||
|
||||
line = in.readLine();
|
||||
b.parentBoneName = line;
|
||||
|
||||
boneStructMap.push_back(b);
|
||||
|
||||
/*
|
||||
saveArr.insert(saveArr.size(), (char*)v, 12);
|
||||
saveArr.insert(saveArr.size(), (char*)q, 16);
|
||||
|
||||
saveArr.insert(saveArr.size(), (char*)&len, 4);
|
||||
|
||||
saveArr.insert(saveArr.size(), (char*)&len, 4);*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
line = in.readLine();
|
||||
|
||||
int vertexCount = line.remove("Vertices ").toInt();
|
||||
|
||||
saveArr.insert(saveArr.size(), (char*)&boneCount, 4);
|
||||
saveArr.insert(saveArr.size(), (char*)&vertexCount, 4);
|
||||
|
||||
for (int i=0; i<boneCount; i++)
|
||||
{
|
||||
|
||||
saveArr.insert(saveArr.size(), (char*)boneStructMap[i].v, 12);
|
||||
saveArr.insert(saveArr.size(), (char*)boneStructMap[i].q, 16);
|
||||
|
||||
saveArr.insert(saveArr.size(), (char*)&boneStructMap[i].len, 4);
|
||||
|
||||
int parentBoneIndex;
|
||||
if (boneNameMap.count(boneStructMap[i].parentBoneName) == 0)
|
||||
{
|
||||
parentBoneIndex = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
parentBoneIndex = boneNameMap[boneStructMap[i].parentBoneName];
|
||||
}
|
||||
saveArr.insert(saveArr.size(), (char*)&parentBoneIndex, 4);
|
||||
}
|
||||
|
||||
int wcount;
|
||||
float weight;
|
||||
|
||||
for (int i=0; i<vertexCount; i++)
|
||||
{
|
||||
line = in.readLine();
|
||||
wcount = line.remove("WCount ").toInt();
|
||||
|
||||
saveArr.insert(saveArr.size(), (char*)&wcount, 4);
|
||||
|
||||
|
||||
for (int j=0; j<wcount; j++)
|
||||
{
|
||||
line = in.readLine();
|
||||
int lastSpacebarPos = line.lastIndexOf(" ");
|
||||
line[lastSpacebarPos] = '|';
|
||||
splited = line.split("|", QString::SkipEmptyParts);
|
||||
boneName = splited.at(0);
|
||||
weight = splited.at(1).toFloat();
|
||||
|
||||
int boneIndex = boneNameMap[boneName];
|
||||
|
||||
saveArr.insert(saveArr.size(), (char*)&boneIndex, 4);
|
||||
saveArr.insert(saveArr.size(), (char*)&weight, 4);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
line = in.readLine();
|
||||
|
||||
int frameCount = line.remove("Frames ").toInt();
|
||||
|
||||
line = in.readLine();
|
||||
|
||||
int boneCount = line.remove("Bones ").toInt();
|
||||
|
||||
QStringList splited;
|
||||
|
||||
float v[3];
|
||||
float q[4];
|
||||
|
||||
float len;
|
||||
|
||||
for (int i=0; i<frameCount; i++)
|
||||
{
|
||||
|
||||
line = in.readLine();
|
||||
|
||||
for (int j=0; j<boneCount; j++)
|
||||
{
|
||||
|
||||
line = in.readLine();
|
||||
splited = line.split(" ", QString::SkipEmptyParts);
|
||||
|
||||
v[0] = splited.at(0).toFloat();
|
||||
v[1] = splited.at(1).toFloat();
|
||||
v[2] = splited.at(2).toFloat();
|
||||
|
||||
line = in.readLine();
|
||||
splited = line.split(" ", QString::SkipEmptyParts);
|
||||
|
||||
q[0] = splited.at(0).toFloat();
|
||||
q[1] = splited.at(1).toFloat();
|
||||
q[2] = splited.at(2).toFloat();
|
||||
q[3] = splited.at(3).toFloat();
|
||||
|
||||
line = in.readLine();
|
||||
len = line.toFloat();
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
saveFile.write(saveArr);
|
||||
|
||||
//======= End file parsing
|
||||
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText("End");
|
||||
msgBox.exec();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
public slots:
|
||||
void CallConvertAn1();
|
||||
void CallConvertBn1();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
@@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<widget class="QPushButton" name="ConvertAn1">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>20</y>
|
||||
<width>121</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Convert An1</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="ConvertBn1">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>60</y>
|
||||
<width>121</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Convert Bn1</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menuBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="mainToolBar">
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in new issue
Block a user