mirror of
https://github.com/devZoGok/vb01.git
synced 2026-08-26 19:43:30 +00:00
improved model parsing
This commit is contained in:
@@ -9,27 +9,23 @@ namespace vb01{
|
|||||||
void Box::setSize(Vector3 size){
|
void Box::setSize(Vector3 size){
|
||||||
this->size = size;
|
this->size = size;
|
||||||
|
|
||||||
Vector3 pos[] = {
|
Vector3 *pos = new Vector3[8];
|
||||||
Vector3(size.x / 2, size.y / 2, size.z / 2),
|
pos[0] = Vector3(size.x / 2, size.y / 2, size.z / 2);
|
||||||
Vector3(-size.x / 2, size.y / 2, size.z / 2),
|
pos[1] = Vector3(-size.x / 2, size.y / 2, size.z / 2);
|
||||||
Vector3(-size.x / 2, size.y / 2, -size.z / 2),
|
pos[2] = Vector3(-size.x / 2, size.y / 2, -size.z / 2);
|
||||||
Vector3(size.x / 2, size.y / 2, -size.z / 2),
|
pos[3] = Vector3(size.x / 2, size.y / 2, -size.z / 2);
|
||||||
|
pos[4] = Vector3(size.x / 2, -size.y / 2, size.z / 2);
|
||||||
|
pos[5] = Vector3(-size.x / 2, -size.y / 2, size.z / 2);
|
||||||
|
pos[6] = Vector3(-size.x / 2, -size.y / 2, -size.z / 2);
|
||||||
|
pos[7] = Vector3(size.x / 2, -size.y / 2, -size.z / 2);
|
||||||
|
|
||||||
Vector3(size.x / 2, -size.y / 2, size.z / 2),
|
Vector3 *norm = new Vector3[6];
|
||||||
Vector3(-size.x / 2, -size.y / 2, size.z / 2),
|
norm[0] = Vector3(0, 0, 1);
|
||||||
Vector3(-size.x / 2, -size.y / 2, -size.z / 2),
|
norm[1] = Vector3(0, 1, 0);
|
||||||
Vector3(size.x / 2, -size.y / 2, -size.z / 2)
|
norm[2] = Vector3(1, 0, 0);
|
||||||
};
|
norm[3] = Vector3(0, 0, -1);
|
||||||
|
norm[4] = Vector3(0, -1, 0);
|
||||||
Vector3 norm[] = {
|
norm[5] = Vector3(-1, 0, 0);
|
||||||
Vector3(0, 0, 1),
|
|
||||||
Vector3(0, 1, 0),
|
|
||||||
Vector3(1, 0, 0),
|
|
||||||
|
|
||||||
Vector3(0, 0, -1),
|
|
||||||
Vector3(0, -1, 0),
|
|
||||||
Vector3(-1, 0, 0)
|
|
||||||
};
|
|
||||||
|
|
||||||
Vector2 tex[] = {
|
Vector2 tex[] = {
|
||||||
Vector2(1, 1),
|
Vector2(1, 1),
|
||||||
@@ -71,6 +67,6 @@ namespace vb01{
|
|||||||
indices[i] = i;
|
indices[i] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
meshBase = MeshData((Vector3*)pos, nullptr, nullptr, nullptr, 8, (Vector3*)norm, vertices, indices, numTris);
|
meshBase = MeshData(pos, nullptr, nullptr, nullptr, 8, norm, vertices, indices, numTris);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -33,10 +33,11 @@ namespace vb01{
|
|||||||
vertData[i].weights[j] = vertices[i].weights[j];
|
vertData[i].weights[j] = vertices[i].weights[j];
|
||||||
vertData[i].boneIndices[j] = vertices[i].boneIndices[j];
|
vertData[i].boneIndices[j] = vertices[i].boneIndices[j];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//if(shapeKeyOffsets) for(int j = 0; j < 100; j++) vertData[i].shapeKeyOffsets[j] = vertices[i].shapeKeyOffsets[j];
|
if(shapeKeyOffsets)
|
||||||
|
for(int j = 0; j < 100; j++)
|
||||||
|
vertData[i].shapeKeyOffsets[j] = vertices[i].shapeKeyOffsets[j];
|
||||||
}
|
}
|
||||||
|
|
||||||
return vertData;
|
return vertData;
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ namespace vb01{
|
|||||||
std::string name;
|
std::string name;
|
||||||
float minValue, value, maxValue;
|
float minValue, value, maxValue;
|
||||||
|
|
||||||
ShapeKey(std::string n, float v, float mnv, float mxv) : name(n), value(v), minValue(mnv), maxValue(mxv), Animatable(Animatable::SHAPE_KEY, name){}
|
ShapeKey(std::string n, float v, float mnv, float mxv) : name(n), value(v), minValue(mnv), maxValue(mxv), Animatable(Animatable::SHAPE_KEY, n){}
|
||||||
ShapeKey() : Animatable(Animatable::SHAPE_KEY){}
|
ShapeKey() : Animatable(Animatable::SHAPE_KEY){}
|
||||||
void animate(float, KeyframeChannel);
|
void animate(float, KeyframeChannel);
|
||||||
};
|
};
|
||||||
|
|||||||
+1033
-1033
File diff suppressed because it is too large
Load Diff
@@ -166,6 +166,7 @@ def export(node, parentTag):
|
|||||||
|
|
||||||
if node.type == 'MESH':
|
if node.type == 'MESH':
|
||||||
mesh = node.data
|
mesh = node.data
|
||||||
|
numVertexPos = len(mesh.vertices)
|
||||||
numFaces = len(mesh.polygons)
|
numFaces = len(mesh.polygons)
|
||||||
numVerts = len(mesh.vertices)
|
numVerts = len(mesh.vertices)
|
||||||
numGroups = len(node.vertex_groups)
|
numGroups = len(node.vertex_groups)
|
||||||
@@ -176,6 +177,7 @@ def export(node, parentTag):
|
|||||||
|
|
||||||
meshTag = ET.SubElement(nodeTag, 'mesh')
|
meshTag = ET.SubElement(nodeTag, 'mesh')
|
||||||
meshTag.set('name', node.name + mesh.name_full)
|
meshTag.set('name', node.name + mesh.name_full)
|
||||||
|
meshTag.set('num_vertex_pos', str(numVertexPos))
|
||||||
meshTag.set('num_faces', str(numFaces))
|
meshTag.set('num_faces', str(numFaces))
|
||||||
meshTag.set('num_vertex_groups', str(numGroups))
|
meshTag.set('num_vertex_groups', str(numGroups))
|
||||||
meshTag.set('num_shape_keys', str(numShapeKeys))
|
meshTag.set('num_shape_keys', str(numShapeKeys))
|
||||||
|
|||||||
+62
-69
@@ -61,48 +61,49 @@ namespace vb01{
|
|||||||
|
|
||||||
//TODO remove the 4 literal for bone weights and indices
|
//TODO remove the 4 literal for bone weights and indices
|
||||||
Mesh* XmlModelReader::processMesh(XMLElement *meshEl){
|
Mesh* XmlModelReader::processMesh(XMLElement *meshEl){
|
||||||
int numVertPos = 0;
|
int numVertPos = atoi(meshEl->Attribute("num_vertex_pos"));
|
||||||
vector<Vector3> vp;
|
|
||||||
vector<float> w;
|
|
||||||
const char *tagName = "vertdata";
|
|
||||||
|
|
||||||
for(XMLElement *vertEl = meshEl->FirstChildElement(tagName); vertEl && strcmp(vertEl->Name(), tagName) == 0; vertEl = vertEl->NextSiblingElement(), numVertPos++){
|
|
||||||
float posX = atof(vertEl->Attribute("px"));
|
|
||||||
float posY = atof(vertEl->Attribute("py"));
|
|
||||||
float posZ = atof(vertEl->Attribute("pz"));
|
|
||||||
vp.push_back(Vector3(posX, posY, posZ));
|
|
||||||
|
|
||||||
for(XMLElement *weightEl = vertEl->FirstChildElement("weight"); weightEl; weightEl = weightEl->NextSiblingElement())
|
|
||||||
w.push_back(atof(weightEl->Attribute("value")));
|
|
||||||
}
|
|
||||||
|
|
||||||
int numVertexGroups = atoi(meshEl->Attribute("num_vertex_groups"));
|
int numVertexGroups = atoi(meshEl->Attribute("num_vertex_groups"));
|
||||||
|
|
||||||
|
const char *tagName = "vertdata";
|
||||||
|
|
||||||
Vector3 *vertPos = new Vector3[numVertPos];
|
Vector3 *vertPos = new Vector3[numVertPos];
|
||||||
float **weights = new float*[numVertPos];
|
float **weights = new float*[numVertPos];
|
||||||
int **boneIndices = new int*[numVertPos];
|
int **boneIndices = new int*[numVertPos], i = 0;
|
||||||
|
|
||||||
for(int i = 0; i < vp.size(); i++){
|
for(XMLElement *vertEl = meshEl->FirstChildElement(tagName); vertEl && strcmp(vertEl->Name(), tagName) == 0, i < numVertPos; vertEl = vertEl->NextSiblingElement(), i++){
|
||||||
vertPos[i] = vp[i];
|
float posX = atof(vertEl->Attribute("px"));
|
||||||
weights[i] = new float[4];
|
float posY = atof(vertEl->Attribute("py"));
|
||||||
boneIndices[i] = new int[4];
|
float posZ = atof(vertEl->Attribute("pz"));
|
||||||
|
vertPos[i] = Vector3(posX, posY, posZ);
|
||||||
|
|
||||||
for(int j = 0; j < 4; j++){
|
weights[i] = new float[4];
|
||||||
weights[i][j] = 0;
|
boneIndices[i] = new int[4];
|
||||||
//weights[i][j] = w[i * numVertexGroups + j];
|
|
||||||
boneIndices[i][j] = -1;
|
for(int j = 0; j < 4; j++){
|
||||||
}
|
weights[i][j] = 0;
|
||||||
|
boneIndices[i][j] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int boneIndex = 0, j = 0;
|
||||||
|
|
||||||
|
for(XMLElement *weightEl = vertEl->FirstChildElement("weight"); weightEl, j < numVertexGroups; weightEl = weightEl->NextSiblingElement(), j++){
|
||||||
|
float w = atof(weightEl->Attribute("value"));
|
||||||
|
|
||||||
|
if(w > 0){
|
||||||
|
weights[i][boneIndex] = w;
|
||||||
|
boneIndices[i][boneIndex] = j;
|
||||||
|
boneIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vp.clear();
|
|
||||||
w.clear();
|
|
||||||
|
|
||||||
string *vertexGroups = new string[numVertexGroups];
|
string *vertexGroups = new string[numVertexGroups];
|
||||||
tagName = "vertexgroup";
|
tagName = "vertexgroup";
|
||||||
int i = 0;
|
i = 0;
|
||||||
|
|
||||||
for(XMLElement *vertGroupEl = meshEl->FirstChildElement(tagName); vertGroupEl && strcmp(vertGroupEl->Name(), tagName) == 0; vertGroupEl = vertGroupEl->NextSiblingElement(), i++)
|
if(numVertexGroups > 0)
|
||||||
vertexGroups[i] = (vertGroupEl->Attribute("name"));
|
for(XMLElement *vertGroupEl = meshEl->FirstChildElement(tagName); vertGroupEl && strcmp(vertGroupEl->Name(), tagName) == 0 && i < numVertexGroups; vertGroupEl = vertGroupEl->NextSiblingElement(), i++)
|
||||||
|
vertexGroups[i] = vertGroupEl->Attribute("name");
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
int numVertices = 3 * atoi(meshEl->Attribute("num_faces"));
|
int numVertices = 3 * atoi(meshEl->Attribute("num_faces"));
|
||||||
@@ -111,9 +112,11 @@ namespace vb01{
|
|||||||
u32 *indices = new u32[numVertices];
|
u32 *indices = new u32[numVertices];
|
||||||
|
|
||||||
Vector3 *normals = new Vector3[numVertices];
|
Vector3 *normals = new Vector3[numVertices];
|
||||||
|
vector<int> vertIds;
|
||||||
|
|
||||||
for(XMLElement *vertEl = meshEl->FirstChildElement(tagName); vertEl && strcmp(vertEl->Name(), tagName) == 0; vertEl = vertEl->NextSiblingElement(), i++){
|
for(XMLElement *vertEl = meshEl->FirstChildElement(tagName); vertEl && strcmp(vertEl->Name(), tagName) == 0; vertEl = vertEl->NextSiblingElement(), i++){
|
||||||
int id = atoi(vertEl->Attribute("id"));
|
int id = atoi(vertEl->Attribute("id"));
|
||||||
|
vertIds.push_back(id);
|
||||||
|
|
||||||
float uvX = atof(vertEl->Attribute("uvx"));
|
float uvX = atof(vertEl->Attribute("uvx"));
|
||||||
float uvY = atof(vertEl->Attribute("uvy"));
|
float uvY = atof(vertEl->Attribute("uvy"));
|
||||||
@@ -138,14 +141,6 @@ namespace vb01{
|
|||||||
vertex.tan = tan;
|
vertex.tan = tan;
|
||||||
vertex.biTan = biTan;
|
vertex.biTan = biTan;
|
||||||
|
|
||||||
for(int j = 0, boneIndex = 0; j < numVertexGroups; j++){
|
|
||||||
if(weights[id][j] > 0){
|
|
||||||
boneIndices[id][boneIndex] = j;
|
|
||||||
//weights[id][boneIndex] = weights[id * numVertexGroups + j];
|
|
||||||
boneIndex++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vertex.weights = weights[id];
|
vertex.weights = weights[id];
|
||||||
vertex.boneIndices = boneIndices[id];
|
vertex.boneIndices = boneIndices[id];
|
||||||
|
|
||||||
@@ -156,43 +151,41 @@ namespace vb01{
|
|||||||
tagName = "shapekey";
|
tagName = "shapekey";
|
||||||
i = 0;
|
i = 0;
|
||||||
int numShapeKeys = atoi(meshEl->Attribute("num_shape_keys"));
|
int numShapeKeys = atoi(meshEl->Attribute("num_shape_keys"));
|
||||||
MeshData::ShapeKey *shapeKeys = new MeshData::ShapeKey[numShapeKeys];
|
MeshData::ShapeKey *shapeKeys = nullptr;
|
||||||
Vector3 **shapeKeyOffsets = new Vector3*[numVertPos];
|
Vector3 **shapeKeyOffsets = nullptr;
|
||||||
|
|
||||||
for(int i = 0; i < numVertPos; i++){
|
if(numShapeKeys > 0){
|
||||||
shapeKeyOffsets[i] = new Vector3[100];
|
shapeKeys = new MeshData::ShapeKey[numShapeKeys];
|
||||||
}
|
shapeKeyOffsets = new Vector3*[numVertPos];
|
||||||
|
|
||||||
for(XMLElement *shapeKeyEl = meshEl->FirstChildElement(tagName); shapeKeyEl && strcmp(shapeKeyEl->Name(), tagName) == 0; shapeKeyEl = shapeKeyEl->NextSiblingElement(), i++){
|
for(int i = 0; i < numVertPos; i++)
|
||||||
string name = shapeKeyEl->Attribute("name");
|
shapeKeyOffsets[i] = new Vector3[100];
|
||||||
float minValue = atof(shapeKeyEl->Attribute("min"));
|
|
||||||
float maxValue = atof(shapeKeyEl->Attribute("max"));
|
|
||||||
shapeKeys[i] = MeshData::ShapeKey(name, minValue, minValue, maxValue);
|
|
||||||
|
|
||||||
XMLElement *driverEl = shapeKeyEl->FirstChildElement("driver");
|
for(XMLElement *shapeKeyEl = meshEl->FirstChildElement(tagName); shapeKeyEl && strcmp(shapeKeyEl->Name(), tagName) == 0 && i < numShapeKeys; shapeKeyEl = shapeKeyEl->NextSiblingElement(), i++){
|
||||||
KeyframeChannel channel = processKeyframeChannells(driverEl)[0];
|
string name = shapeKeyEl->Attribute("name");
|
||||||
const char *nodeName = driverEl->Attribute("obj");
|
float minValue = atof(shapeKeyEl->Attribute("min"));
|
||||||
const char *boneName = driverEl->Attribute("bone");
|
float maxValue = atof(shapeKeyEl->Attribute("max"));
|
||||||
Driver::VariableType type = Driver::getDriverVariableType(driverEl->Attribute("type"));
|
shapeKeys[i] = MeshData::ShapeKey(name, minValue, minValue, maxValue);
|
||||||
driversByNodeNames.push_back(make_pair(string(nodeName) + (boneName ? "." + string(boneName) : ""), new Driver(&shapeKeys[i], channel, type)));
|
|
||||||
|
|
||||||
vector<Vector3> shapeKeyPos;
|
XMLElement *driverEl = shapeKeyEl->FirstChildElement("driver");
|
||||||
|
KeyframeChannel channel = processKeyframeChannells(driverEl)[0];
|
||||||
|
const char *nodeName = driverEl->Attribute("obj");
|
||||||
|
const char *boneName = driverEl->Attribute("bone");
|
||||||
|
Driver::VariableType type = Driver::getDriverVariableType(driverEl->Attribute("type"));
|
||||||
|
driversByNodeNames.push_back(make_pair(string(nodeName) + (boneName ? "." + string(boneName) : ""), new Driver(&shapeKeys[i], channel, type)));
|
||||||
|
|
||||||
for(XMLElement *vertEl = shapeKeyEl->FirstChildElement("vert"); vertEl; vertEl = vertEl->NextSiblingElement()){
|
int j = 0;
|
||||||
float posX = atof(vertEl->Attribute("px"));
|
|
||||||
float posY = atof(vertEl->Attribute("py"));
|
|
||||||
float posZ = atof(vertEl->Attribute("pz"));
|
|
||||||
shapeKeyPos.push_back(Vector3(posX, posY, posZ));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
for(XMLElement *vertEl = shapeKeyEl->FirstChildElement("vert"); vertEl; vertEl = vertEl->NextSiblingElement(), j++){
|
||||||
for(int j = 0; j < numVertPos; j++){
|
float posX = atof(vertEl->Attribute("px"));
|
||||||
shapeKeyOffsets[i] = new Vector3[100];
|
float posY = atof(vertEl->Attribute("py"));
|
||||||
|
float posZ = atof(vertEl->Attribute("pz"));
|
||||||
|
shapeKeyOffsets[j][i] = Vector3(posX, posY, posZ) - vertPos[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for(int k = 0; k < 100; k++)
|
for(int i = 0; i < numVertices; i++)
|
||||||
shapeKeyOffsets[i][k] = shapeKeyPos[vertIds[j]] - vertPos[vertIds[j]];
|
vertices[i].shapeKeyOffsets = shapeKeyOffsets[vertIds[i]];
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *fullSkeletonName = meshEl->Attribute("skeleton");
|
const char *fullSkeletonName = meshEl->Attribute("skeleton");
|
||||||
|
|||||||
Reference in New Issue
Block a user