Merge pull request #62 from devZoGok/imp-61-sep-vert-pos

Imp 61 sep vert pos
This commit is contained in:
devZoGok
2024-09-05 17:41:53 +00:00
committed by GitHub
10 changed files with 1260 additions and 1172 deletions
+20 -24
View File
@@ -9,27 +9,23 @@ namespace vb01{
void Box::setSize(Vector3 size){
this->size = size;
Vector3 pos[] = {
Vector3(size.x / 2, size.y / 2, size.z / 2),
Vector3(-size.x / 2, size.y / 2, size.z / 2),
Vector3(-size.x / 2, size.y / 2, -size.z / 2),
Vector3(size.x / 2, size.y / 2, -size.z / 2),
Vector3 *pos = new Vector3[8];
pos[0] = Vector3(size.x / 2, size.y / 2, size.z / 2);
pos[1] = Vector3(-size.x / 2, size.y / 2, size.z / 2);
pos[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(-size.x / 2, -size.y / 2, size.z / 2),
Vector3(-size.x / 2, -size.y / 2, -size.z / 2),
Vector3(size.x / 2, -size.y / 2, -size.z / 2)
};
Vector3 norm[] = {
Vector3(0, 0, 1),
Vector3(0, 1, 0),
Vector3(1, 0, 0),
Vector3(0, 0, -1),
Vector3(0, -1, 0),
Vector3(-1, 0, 0)
};
Vector3 *norm = new Vector3[6];
norm[0] = Vector3(0, 0, 1);
norm[1] = Vector3(0, 1, 0);
norm[2] = Vector3(1, 0, 0);
norm[3] = Vector3(0, 0, -1);
norm[4] = Vector3(0, -1, 0);
norm[5] = Vector3(-1, 0, 0);
Vector2 tex[] = {
Vector2(1, 1),
@@ -63,14 +59,14 @@ namespace vb01{
MeshData::Vertex *vertices = new MeshData::Vertex[3 * numTris];
for(int i = 0; i < 3 * numTris; i++){
MeshData::Vertex v;
v.pos = pos[data[3 * i]];
v.norm = norm[data[3 * i + 1]];
MeshData::Vertex v;
v.pos = &pos[data[3 * i]];
v.norm = &norm[data[3 * i + 1]];
v.uv = tex[data[3 * i + 2]];
vertices[i] = v;
indices[i] = i;
}
meshBase = MeshData(vertices, indices, numTris);
meshBase = MeshData(pos, nullptr, nullptr, nullptr, 8, norm, vertices, indices, numTris);
}
}
+17 -10
View File
@@ -44,31 +44,35 @@ namespace vb01{
glGenBuffers(1, &VBO);
glGenBuffers(1, &EBO);
u32 size = sizeof(MeshData::Vertex);
u32 size = sizeof(MeshData::GpuVertex);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, 3 * meshBase.numTris * size, meshBase.vertices, GL_DYNAMIC_DRAW);
MeshData::GpuVertex *glVertData = meshBase.toGpuVerts();
glBufferData(GL_ARRAY_BUFFER, 3 * meshBase.numTris * size, glVertData, GL_DYNAMIC_DRAW);
delete glVertData;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 3 * meshBase.numTris * sizeof(u32), meshBase.indices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, size, (void*)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(MeshData::Vertex, norm)));
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(MeshData::GpuVertex, norm)));
glEnableVertexAttribArray(1);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(MeshData::Vertex, uv)));
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(MeshData::GpuVertex, uv)));
glEnableVertexAttribArray(2);
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(MeshData::Vertex, tan)));
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(MeshData::GpuVertex, tan)));
glEnableVertexAttribArray(3);
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(MeshData::Vertex, biTan)));
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(MeshData::GpuVertex, biTan)));
glEnableVertexAttribArray(4);
glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(MeshData::Vertex, weights)));
glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(MeshData::GpuVertex, weights)));
glEnableVertexAttribArray(5);
glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(MeshData::Vertex, boneIndices)));
glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(MeshData::GpuVertex, boneIndices)));
glEnableVertexAttribArray(6);
for(int i = 0; i < meshBase.numShapeKeys; i++){
glVertexAttribPointer(7 + i, 3, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(MeshData::Vertex, shapeKeyOffsets) + 3 * i * sizeof(float)));
glVertexAttribPointer(7 + i, 3, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(MeshData::GpuVertex, shapeKeyOffsets) + 3 * i * sizeof(float)));
glEnableVertexAttribArray(7 + i);
}
}
@@ -91,7 +95,10 @@ namespace vb01{
void Mesh::updateVerts(MeshData meshData){
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferSubData(GL_ARRAY_BUFFER, 0, 3 * sizeof(MeshData::Vertex) * meshBase.numTris, meshData.vertices);
MeshData::GpuVertex *glVertData = meshBase.toGpuVerts();
glBufferSubData(GL_ARRAY_BUFFER, 0, 3 * sizeof(MeshData::GpuVertex) * meshBase.numTris, glVertData);
delete glVertData;
}
void Mesh::update(){
+23 -16
View File
@@ -17,22 +17,29 @@ namespace vb01{
}
}
MeshData::ShapeKey::ShapeKey(string name, float value, float minValue, float maxValue) : Animatable(Animatable::SHAPE_KEY, name){
this->name = name;
this->value = value;
this->minValue = minValue;
this->maxValue = maxValue;
}
MeshData::GpuVertex* MeshData::toGpuVerts(){
int numVertices = 3 * numTris;
GpuVertex *vertData = new GpuVertex[numVertices];
MeshData::MeshData(Vertex *vertices, u32 *indices, int numTris, string attachableName, string *vertexGroups, int numVertexGroups, string fullSkeletonName, ShapeKey *shapeKeys, int numShapeKeys){
this->vertices = vertices;
this->indices = indices;
this->numTris = numTris;
this->attachableName = attachableName;
this->vertexGroups = vertexGroups;
this->numVertexGroups = numVertexGroups;
this->fullSkeletonName = fullSkeletonName;
this->shapeKeys = shapeKeys;
this->numShapeKeys = numShapeKeys;
for(int i = 0; i < numVertices; i++){
vertData[i].pos = *vertices[i].pos;
vertData[i].norm = *vertices[i].norm;
vertData[i].tan = vertices[i].tan;
vertData[i].biTan = vertices[i].biTan;
vertData[i].uv = vertices[i].uv;
if(weights){
for(int j = 0; j < 4; j++){
vertData[i].weights[j] = vertices[i].weights[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];
}
return vertData;
}
}
+32 -4
View File
@@ -14,12 +14,12 @@ namespace vb01{
std::string name;
float minValue, value, maxValue;
ShapeKey(std::string, float, float, float);
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){}
void animate(float, KeyframeChannel);
};
struct Vertex{
struct GpuVertex{
Vector3 pos, norm, tan, biTan;
Vector2 uv;
float weights[4]{0, 0, 0, 0};
@@ -27,15 +27,43 @@ namespace vb01{
Vector3 shapeKeyOffsets[100];
};
struct Vertex{
Vector3 *pos = nullptr, *norm = nullptr, tan, biTan;
Vector2 uv;
float *weights = nullptr;
int *boneIndices = nullptr;
Vector3 *shapeKeyOffsets = nullptr;
};
GpuVertex* toGpuVerts();
Vector3 *positions = nullptr, *normals = nullptr, **shapeKeyOffsets = nullptr;
float **weights = nullptr;
int **boneIndices = nullptr;
Vertex *vertices;
std::string *vertexGroups = nullptr;
ShapeKey *shapeKeys = nullptr;
u32 *indices, VAO, VBO, EBO;
int numTris, numVertexGroups = 0, numShapeKeys = 0;
int numPos, numTris, numVertexGroups = 0, numShapeKeys = 0;
std::string attachableName = "", fullSkeletonName = "";
MeshData(){}
MeshData(Vertex*, u32*, int, std::string = "", std::string *vg = nullptr, int = 0, std::string = "", ShapeKey *sk = nullptr, int = 0);
MeshData(Vector3 *pos, float **w, int **bi, Vector3 **sko, int np, Vector3 *norm, Vertex *vert, u32 *ind, int nt, std::string an = "", std::string *vg = nullptr, int nvg = 0, std::string fsn = "", ShapeKey *sk = nullptr, int nsk = 0) :
positions(pos),
weights(w),
boneIndices(bi),
shapeKeyOffsets(sko),
numPos(np),
normals(norm),
vertices(vert),
indices(ind),
numTris(nt),
vertexGroups(vg),
numVertexGroups(nvg),
fullSkeletonName(fsn),
shapeKeys(sk),
numShapeKeys(nsk)
{}
};
}
+3 -3
View File
@@ -28,14 +28,14 @@ namespace vb01{
}
Model::~Model(){
delete children[0]->getMesh(0)->getMaterial();
vector<Node*> descendants;
getDescendants(descendants);
for(Node *node : descendants)
for(Mesh *mesh : node->getMeshes())
for(Mesh *mesh : node->getMeshes()){
delete mesh->getMaterial();
mesh->setMaterial(nullptr);
}
while(!children.empty()){
Node *c = children[children.size() - 1];
+52 -31
View File
@@ -1,6 +1,10 @@
#include "quad.h"
#include <algorithm>
namespace vb01{
using namespace std;
Quad::Quad(Vector3 size, bool spatial, int numVertDiv, int numHorDiv){
this->spatial = spatial;
this->numVertDiv = numVertDiv;
@@ -14,55 +18,72 @@ namespace vb01{
this->size = size;
const int numHorQuads = numVertDiv + 1, numVertQuads = numHorDiv + 1;
const int numTris = 2 * numHorQuads * numVertQuads, numVerts = 3 * numTris;
const int numVertPos = (numHorQuads + 1) * (numVertQuads + 1), numTris = 2 * numHorQuads * numVertQuads, numVerts = 3 * numTris;
Vector2 subQuadSize = Vector2(size.x / numHorQuads, size.y / numVertQuads);
MeshData::Vertex *vertices = new MeshData::Vertex[numVerts];
if(!meshBase.positions){
meshBase.positions = new Vector3[numVertPos];
meshBase.normals = new Vector3(Vector3::VEC_J);
meshBase.indices = new u32[numVerts];
for(int i = 0; i < numVerts; i++)
meshBase.indices[i] = i;
}
Vector3 *faceVertPos = meshBase.positions;
Vector3 *norm = meshBase.normals;
u32 *indices = meshBase.indices;
for(int i = 0; i < numHorQuads; i++){
for(int j = 0; j < numVertQuads; j++){
int id = i * 6 * numHorQuads + j * 6;
int vertPosId = i * (numHorQuads + 1) + j;
int vertPosId2 = (i + 1) * (numHorQuads + 1) + j;
Vector2 offset = Vector2(subQuadSize.x, subQuadSize.y);
Vector3 faceVertPos[]{
Vector3(-.5 * size.x + offset.x * j, 0, -.5 * size.y + offset.y * i),
Vector3(-.5 * size.x + offset.x * (j + 1), 0, -.5 * size.y + offset.y * (i + 1)),
Vector3(-.5 * size.x + offset.x * (j + 1), 0, -.5 * size.y + offset.y * i),
Vector3(-.5 * size.x + offset.x * j, 0, -.5 * size.y + offset.y * i),
Vector3(-.5 * size.x + offset.x * j, 0, -.5 * size.y + offset.y * (i + 1)),
Vector3(-.5 * size.x + offset.x * (j + 1), 0, -.5 * size.y + offset.y * (i + 1))
};
faceVertPos[vertPosId] = Vector3(-.5 * size.x + offset.x * i, 0, -.5 * size.y + offset.y * j);
faceVertPos[vertPosId + 1] = Vector3(-.5 * size.x + offset.x * i, 0, -.5 * size.y + offset.y * (j + 1));
faceVertPos[vertPosId2] = Vector3(-.5 * size.x + offset.x * (i + 1), 0, -.5 * size.y + offset.y * j);
faceVertPos[vertPosId2 + 1] = Vector3(-.5 * size.x + offset.x * (i + 1), 0, -.5 * size.y + offset.y * (j + 1));
if(!spatial){
int ids[4]{vertPosId, vertPosId + 1, vertPosId2, vertPosId2 + 1};
swap(faceVertPos[ids[0]].z, faceVertPos[ids[1]].z);
swap(faceVertPos[ids[2]].z, faceVertPos[ids[3]].z);
for(int k = 0; k < 4; k++){
faceVertPos[ids[k]].y = -faceVertPos[ids[k]].z;
faceVertPos[ids[k]].z = 0;
faceVertPos[ids[k]] += .5 * Vector3(size.x, size.y, 0);
}
}
Vector2 faceVertUv[]{
Vector2(float(j) / numHorQuads, float(i) / numVertQuads),
Vector2(float(j + 1) / numHorQuads, float(i + 1) / numVertQuads),
Vector2(float(j + 1) / numHorQuads, float(i) / numVertQuads),
Vector2(float(j) / numHorQuads, float(i) / numVertQuads),
Vector2(float(j) / numHorQuads, float(i + 1) / numVertQuads),
Vector2(float(j + 1) / numHorQuads, float(i + 1) / numVertQuads),
Vector2(float(i) / numHorQuads, 1 - float(j) / numVertQuads),
Vector2(float(i) / numHorQuads, 1 - float(j + 1) / numVertQuads),
Vector2(float(i + 1) / numHorQuads, 1 - float(j + 1) / numVertQuads),
Vector2(float(i + 1) / numHorQuads, 1 - float(j + 1) / numVertQuads),
Vector2(float(i + 1) / numHorQuads, 1 - float(j) / numVertQuads),
Vector2(float(i) / numHorQuads, 1 - float(j) / numVertQuads),
};
int quadId = 6 * (i * numHorQuads + j);
int vertPosIds[6]{vertPosId, vertPosId + 1, vertPosId2 + 1, vertPosId2 + 1, vertPosId2, vertPosId};
for(int k = 0; k < 6; k++){
if(!spatial){
faceVertPos[k].y = -faceVertPos[k].z;
faceVertPos[k].z = 0;
faceVertPos[k] += .5 * Vector3(size.x, size.y, 0);
}
MeshData::Vertex v;
v.pos = faceVertPos[k];
v.pos = &faceVertPos[vertPosIds[k]];
v.uv = faceVertUv[k];
v.tan = Vector3::VEC_I;
v.norm = Vector3::VEC_J;
v.norm = norm;
v.biTan = Vector3::VEC_K;
vertices[id + k] = v;
vertices[quadId + k] = v;
}
}
}
u32 *indices = new u32[numVerts];
for(int i = 0; i < numVerts; i++)
indices[i] = i;
meshBase = MeshData(vertices, indices, numTris);
meshBase = MeshData(faceVertPos, nullptr, nullptr, nullptr, 6, norm, vertices, indices, numTris);
}
}
+2 -2
View File
@@ -42,7 +42,7 @@ namespace vb01{
bool skip = false;
for(int j = 0; j < 3; j++){
Vector3 rayPosToVert = (vertices[i * 3 + j].pos - rayPos);
Vector3 rayPosToVert = (*(vertices[i * 3 + j].pos) - rayPos);
float angle = rayDir.getAngleBetween(rayPosToVert.norm());
if(angle > PI / 2) angle = PI - angle;
@@ -58,7 +58,7 @@ namespace vb01{
if(skip) continue;
}
Vector3 pointA = pos + rot * vertices[indices[i * 3]].pos, pointB = pos + rot * vertices[indices[i * 3 + 1]].pos, pointC = pos + rot * vertices[indices[i * 3 + 2]].pos;
Vector3 pointA = pos + rot * *(vertices[indices[i * 3]].pos), pointB = pos + rot * *(vertices[indices[i * 3 + 1]].pos), pointC = pos + rot * *(vertices[indices[i * 3 + 2]].pos);
Vector3 hypVec = pointA - rayPos;
Vector3 perpVec = (pointB - pointA).cross(pointC - pointA).norm();
float a1 = hypVec.norm().getAngleBetween(perpVec);
+1034 -1034
View File
File diff suppressed because it is too large Load Diff
+2
View File
@@ -166,6 +166,7 @@ def export(node, parentTag):
if node.type == 'MESH':
mesh = node.data
numVertexPos = len(mesh.vertices)
numFaces = len(mesh.polygons)
numVerts = len(mesh.vertices)
numGroups = len(node.vertex_groups)
@@ -176,6 +177,7 @@ def export(node, parentTag):
meshTag = ET.SubElement(nodeTag, 'mesh')
meshTag.set('name', node.name + mesh.name_full)
meshTag.set('num_vertex_pos', str(numVertexPos))
meshTag.set('num_faces', str(numFaces))
meshTag.set('num_vertex_groups', str(numGroups))
meshTag.set('num_shape_keys', str(numShapeKeys))
+75 -48
View File
@@ -42,6 +42,8 @@ namespace vb01{
assetRootNode->getDescendants(descendants);
setupDrivers(descendants);
delete doc;
return asset;
}
@@ -57,41 +59,61 @@ namespace vb01{
}
}
//TODO remove the 4 literal for bone weights and indices
Mesh* XmlModelReader::processMesh(XMLElement *meshEl){
vector<Vector3> vertPos, vertNorm;
vector<float> weights;
int numVertPos = atoi(meshEl->Attribute("num_vertex_pos"));
int numVertexGroups = atoi(meshEl->Attribute("num_vertex_groups"));
const char *tagName = "vertdata";
for(XMLElement *vertEl = meshEl->FirstChildElement(tagName); vertEl && strcmp(vertEl->Name(), tagName) == 0; vertEl = vertEl->NextSiblingElement()){
Vector3 *vertPos = new Vector3[numVertPos];
float **weights = new float*[numVertPos];
int **boneIndices = new int*[numVertPos], i = 0;
for(XMLElement *vertEl = meshEl->FirstChildElement(tagName); vertEl && strcmp(vertEl->Name(), tagName) == 0, i < numVertPos; vertEl = vertEl->NextSiblingElement(), i++){
float posX = atof(vertEl->Attribute("px"));
float posY = atof(vertEl->Attribute("py"));
float posZ = atof(vertEl->Attribute("pz"));
vertPos.push_back(Vector3(posX, posY, posZ));
vertPos[i] = Vector3(posX, posY, posZ);
float normX = atof(vertEl->Attribute("nx"));
float normY = atof(vertEl->Attribute("ny"));
float normZ = atof(vertEl->Attribute("nz"));
vertNorm.push_back(Vector3(normX, normY, normZ));
weights[i] = new float[4];
boneIndices[i] = new int[4];
for(XMLElement *weightEl = vertEl->FirstChildElement("weight"); weightEl; weightEl = weightEl->NextSiblingElement())
weights.push_back(atof(weightEl->Attribute("value")));
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++;
}
}
}
int numVertexGroups = atoi(meshEl->Attribute("num_vertex_groups"));
string *vertexGroups = new string[numVertexGroups];
tagName = "vertexgroup";
int i = 0;
i = 0;
for(XMLElement *vertGroupEl = meshEl->FirstChildElement(tagName); vertGroupEl && strcmp(vertGroupEl->Name(), tagName) == 0; vertGroupEl = vertGroupEl->NextSiblingElement(), i++)
vertexGroups[i] = (vertGroupEl->Attribute("name"));
if(numVertexGroups > 0)
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;
int numVertices = 3 * atoi(meshEl->Attribute("num_faces"));
MeshData::Vertex *vertices = new MeshData::Vertex[numVertices];
tagName = "vert";
vector<u32> vertIds;
u32 *indices = new u32[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++){
int id = atoi(vertEl->Attribute("id"));
vertIds.push_back(id);
@@ -110,60 +132,65 @@ namespace vb01{
float biTanZ = atof(vertEl->Attribute("bz"));
Vector3 biTan = Vector3(biTanX, biTanY, biTanZ);
normals[i] = tan.cross(biTan);
MeshData::Vertex vertex;
vertex.pos = vertPos[id];
vertex.norm = vertNorm[id];
vertex.pos = &vertPos[id];
vertex.norm = &normals[id];
vertex.uv = uv;
vertex.tan = tan;
vertex.biTan = biTan;
for(int j = 0, boneIndex = 0; j < numVertexGroups; j++){
if(weights[id * numVertexGroups + j] > 0){
vertex.boneIndices[boneIndex] = j;
vertex.weights[boneIndex] = weights[id * numVertexGroups + j];
boneIndex++;
}
}
vertex.weights = weights[id];
vertex.boneIndices = boneIndices[id];
indices[i] = i;
vertices[i] = vertex;
}
vertNorm.clear();
tagName = "shapekey";
i = 0;
int numShapeKeys = atoi(meshEl->Attribute("num_shape_keys"));
MeshData::ShapeKey *shapeKeys = new MeshData::ShapeKey[numShapeKeys];
MeshData::ShapeKey *shapeKeys = nullptr;
Vector3 **shapeKeyOffsets = nullptr;
for(XMLElement *shapeKeyEl = meshEl->FirstChildElement(tagName); shapeKeyEl && strcmp(shapeKeyEl->Name(), tagName) == 0; shapeKeyEl = shapeKeyEl->NextSiblingElement(), i++){
string name = shapeKeyEl->Attribute("name");
float minValue = atof(shapeKeyEl->Attribute("min"));
float maxValue = atof(shapeKeyEl->Attribute("max"));
shapeKeys[i] = MeshData::ShapeKey(name, minValue, minValue, maxValue);
if(numShapeKeys > 0){
shapeKeys = new MeshData::ShapeKey[numShapeKeys];
shapeKeyOffsets = new Vector3*[numVertPos];
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(int i = 0; i < numVertPos; i++)
shapeKeyOffsets[i] = new Vector3[100];
vector<Vector3> shapeKeyPos;
for(XMLElement *shapeKeyEl = meshEl->FirstChildElement(tagName); shapeKeyEl && strcmp(shapeKeyEl->Name(), tagName) == 0 && i < numShapeKeys; shapeKeyEl = shapeKeyEl->NextSiblingElement(), i++){
string name = shapeKeyEl->Attribute("name");
float minValue = atof(shapeKeyEl->Attribute("min"));
float maxValue = atof(shapeKeyEl->Attribute("max"));
shapeKeys[i] = MeshData::ShapeKey(name, minValue, minValue, maxValue);
for(XMLElement *vertEl = shapeKeyEl->FirstChildElement("vert"); vertEl; vertEl = vertEl->NextSiblingElement()){
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));
}
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(int j = 0; j < numVertices; j++)
vertices[j].shapeKeyOffsets[i] = shapeKeyPos[vertIds[j]] - vertPos[vertIds[j]];
int j = 0;
for(XMLElement *vertEl = shapeKeyEl->FirstChildElement("vert"); vertEl; vertEl = vertEl->NextSiblingElement(), j++){
float posX = atof(vertEl->Attribute("px"));
float posY = atof(vertEl->Attribute("py"));
float posZ = atof(vertEl->Attribute("pz"));
shapeKeyOffsets[j][i] = Vector3(posX, posY, posZ) - vertPos[j];
}
}
for(int i = 0; i < numVertices; i++)
vertices[i].shapeKeyOffsets = shapeKeyOffsets[vertIds[i]];
}
const char *fullSkeletonName = meshEl->Attribute("skeleton");
string name = string(meshEl->Parent()->ToElement()->Attribute("name")) + string(meshEl->Attribute("name"));
Mesh *mesh = new Mesh(MeshData(vertices, indices, numVertices / 3, name, vertexGroups, numVertexGroups, (fullSkeletonName ? fullSkeletonName : ""), shapeKeys, numShapeKeys));
Mesh *mesh = new Mesh(MeshData(vertPos, weights, boneIndices, shapeKeyOffsets, numVertPos, normals, vertices, indices, numVertices / 3, name, vertexGroups, numVertexGroups, (fullSkeletonName ? fullSkeletonName : ""), shapeKeys, numShapeKeys));
return mesh;
}
@@ -291,7 +318,7 @@ namespace vb01{
XMLElement *meshTag = xmlEl->FirstChildElement("mesh");
if(meshTag)
node->attachMesh(processMesh(meshTag));
node->attachMesh(processMesh(meshTag));
XMLElement *lightTag = xmlEl->FirstChildElement("light");