From 36f15b6dd944705e4e455c14a863e68e00d03d79 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 1 Sep 2024 16:13:53 +0300 Subject: [PATCH] improved model parsing --- box.cpp | 38 +- meshData.cpp | 5 +- meshData.h | 2 +- samples/models/kek.xml | 2068 ++++++++++++++++++++-------------------- script.py | 2 + xmlModelReader.cpp | 131 ++- 6 files changed, 1119 insertions(+), 1127 deletions(-) diff --git a/box.cpp b/box.cpp index 118cf2f..671656b 100755 --- a/box.cpp +++ b/box.cpp @@ -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), @@ -71,6 +67,6 @@ namespace vb01{ 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); } } diff --git a/meshData.cpp b/meshData.cpp index 7ae627d..f3d17bb 100644 --- a/meshData.cpp +++ b/meshData.cpp @@ -33,10 +33,11 @@ namespace vb01{ 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]; + if(shapeKeyOffsets) + for(int j = 0; j < 100; j++) + vertData[i].shapeKeyOffsets[j] = vertices[i].shapeKeyOffsets[j]; } return vertData; diff --git a/meshData.h b/meshData.h index a8738d8..568047f 100644 --- a/meshData.h +++ b/meshData.h @@ -14,7 +14,7 @@ namespace vb01{ std::string name; 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){} void animate(float, KeyframeChannel); }; diff --git a/samples/models/kek.xml b/samples/models/kek.xml index 25080a7..a510627 100644 --- a/samples/models/kek.xml +++ b/samples/models/kek.xml @@ -1,6 +1,6 @@ - - + + @@ -144,9 +144,9 @@ - - - + + + @@ -162,7 +162,7 @@ - + @@ -178,7 +178,7 @@ - + @@ -194,7 +194,7 @@ - + @@ -210,7 +210,7 @@ - + @@ -226,7 +226,7 @@ - + @@ -242,7 +242,7 @@ - + @@ -258,7 +258,7 @@ - + @@ -274,7 +274,7 @@ - + @@ -290,7 +290,7 @@ - + @@ -306,7 +306,7 @@ - + @@ -322,7 +322,7 @@ - + @@ -338,7 +338,7 @@ - + @@ -354,7 +354,7 @@ - + @@ -370,7 +370,7 @@ - + @@ -386,7 +386,7 @@ - + @@ -402,7 +402,7 @@ - + @@ -418,7 +418,7 @@ - + @@ -434,7 +434,7 @@ - + @@ -450,7 +450,7 @@ - + @@ -466,7 +466,7 @@ - + @@ -482,7 +482,7 @@ - + @@ -498,7 +498,7 @@ - + @@ -514,7 +514,7 @@ - + @@ -530,7 +530,7 @@ - + @@ -546,7 +546,7 @@ - + @@ -562,7 +562,7 @@ - + @@ -578,7 +578,7 @@ - + @@ -594,7 +594,7 @@ - + @@ -610,7 +610,7 @@ - + @@ -626,7 +626,7 @@ - + @@ -642,7 +642,7 @@ - + @@ -658,7 +658,7 @@ - + @@ -674,7 +674,7 @@ - + @@ -690,7 +690,7 @@ - + @@ -706,7 +706,7 @@ - + @@ -722,7 +722,7 @@ - + @@ -738,7 +738,7 @@ - + @@ -754,7 +754,7 @@ - + @@ -770,7 +770,7 @@ - + @@ -786,7 +786,7 @@ - + @@ -802,7 +802,7 @@ - + @@ -818,7 +818,7 @@ - + @@ -834,7 +834,7 @@ - + @@ -850,7 +850,7 @@ - + @@ -866,7 +866,7 @@ - + @@ -882,7 +882,7 @@ - + @@ -898,7 +898,7 @@ - + @@ -914,7 +914,7 @@ - + @@ -930,7 +930,7 @@ - + @@ -946,7 +946,7 @@ - + @@ -962,7 +962,7 @@ - + @@ -978,7 +978,7 @@ - + @@ -994,7 +994,7 @@ - + @@ -1010,7 +1010,7 @@ - + @@ -1026,7 +1026,7 @@ - + @@ -1042,7 +1042,7 @@ - + @@ -1058,7 +1058,7 @@ - + @@ -1074,7 +1074,7 @@ - + @@ -1090,7 +1090,7 @@ - + @@ -1106,7 +1106,7 @@ - + @@ -1122,7 +1122,7 @@ - + @@ -1138,7 +1138,7 @@ - + @@ -1154,7 +1154,7 @@ - + @@ -1170,7 +1170,7 @@ - + @@ -1186,7 +1186,7 @@ - + @@ -1202,7 +1202,7 @@ - + @@ -1218,7 +1218,7 @@ - + @@ -1234,7 +1234,7 @@ - + @@ -1250,7 +1250,7 @@ - + @@ -1266,7 +1266,7 @@ - + @@ -1282,7 +1282,7 @@ - + @@ -1298,7 +1298,7 @@ - + @@ -1314,7 +1314,7 @@ - + @@ -1330,7 +1330,7 @@ - + @@ -1346,7 +1346,7 @@ - + @@ -1362,7 +1362,7 @@ - + @@ -1378,7 +1378,7 @@ - + @@ -1394,7 +1394,7 @@ - + @@ -1410,7 +1410,7 @@ - + @@ -1426,7 +1426,7 @@ - + @@ -1442,7 +1442,7 @@ - + @@ -1458,7 +1458,7 @@ - + @@ -1474,7 +1474,7 @@ - + @@ -1490,7 +1490,7 @@ - + @@ -1506,7 +1506,7 @@ - + @@ -1522,7 +1522,7 @@ - + @@ -1538,7 +1538,7 @@ - + @@ -1554,7 +1554,7 @@ - + @@ -1570,7 +1570,7 @@ - + @@ -1586,7 +1586,7 @@ - + @@ -1602,7 +1602,7 @@ - + @@ -1618,7 +1618,7 @@ - + @@ -1634,7 +1634,7 @@ - + @@ -1650,7 +1650,7 @@ - + @@ -1666,7 +1666,7 @@ - + @@ -1682,7 +1682,7 @@ - + @@ -1698,7 +1698,7 @@ - + @@ -1714,7 +1714,7 @@ - + @@ -1730,7 +1730,7 @@ - + @@ -1746,7 +1746,7 @@ - + @@ -1762,7 +1762,7 @@ - + @@ -1778,7 +1778,7 @@ - + @@ -1794,7 +1794,7 @@ - + @@ -1810,7 +1810,7 @@ - + @@ -1826,7 +1826,7 @@ - + @@ -1842,7 +1842,7 @@ - + @@ -1858,7 +1858,7 @@ - + @@ -1874,7 +1874,7 @@ - + @@ -1890,7 +1890,7 @@ - + @@ -1906,7 +1906,7 @@ - + @@ -1922,7 +1922,7 @@ - + @@ -1938,7 +1938,7 @@ - + @@ -1954,7 +1954,7 @@ - + @@ -1970,7 +1970,7 @@ - + @@ -1986,7 +1986,7 @@ - + @@ -2002,7 +2002,7 @@ - + @@ -2018,7 +2018,7 @@ - + @@ -2034,7 +2034,7 @@ - + @@ -2050,7 +2050,7 @@ - + @@ -2066,7 +2066,7 @@ - + @@ -2082,7 +2082,7 @@ - + @@ -2098,7 +2098,7 @@ - + @@ -2114,7 +2114,7 @@ - + @@ -2130,7 +2130,7 @@ - + @@ -2146,7 +2146,7 @@ - + @@ -2162,7 +2162,7 @@ - + @@ -2178,7 +2178,7 @@ - + @@ -2194,7 +2194,7 @@ - + @@ -2210,7 +2210,7 @@ - + @@ -2226,7 +2226,7 @@ - + @@ -2242,7 +2242,7 @@ - + @@ -2258,7 +2258,7 @@ - + @@ -2274,7 +2274,7 @@ - + @@ -2290,7 +2290,7 @@ - + @@ -2306,7 +2306,7 @@ - + @@ -2322,7 +2322,7 @@ - + @@ -2338,7 +2338,7 @@ - + @@ -2354,7 +2354,7 @@ - + @@ -2370,7 +2370,7 @@ - + @@ -2386,7 +2386,7 @@ - + @@ -2402,7 +2402,7 @@ - + @@ -2418,7 +2418,7 @@ - + @@ -2434,7 +2434,7 @@ - + @@ -2450,7 +2450,7 @@ - + @@ -2466,7 +2466,7 @@ - + @@ -2482,7 +2482,7 @@ - + @@ -2498,7 +2498,7 @@ - + @@ -2514,7 +2514,7 @@ - + @@ -2530,7 +2530,7 @@ - + @@ -2546,7 +2546,7 @@ - + @@ -2562,7 +2562,7 @@ - + @@ -2578,7 +2578,7 @@ - + @@ -2594,7 +2594,7 @@ - + @@ -2610,7 +2610,7 @@ - + @@ -2626,7 +2626,7 @@ - + @@ -2642,7 +2642,7 @@ - + @@ -2658,7 +2658,7 @@ - + @@ -2674,7 +2674,7 @@ - + @@ -2690,7 +2690,7 @@ - + @@ -2706,7 +2706,7 @@ - + @@ -2722,7 +2722,7 @@ - + @@ -2738,7 +2738,7 @@ - + @@ -2754,7 +2754,7 @@ - + @@ -2770,7 +2770,7 @@ - + @@ -2786,7 +2786,7 @@ - + @@ -2802,7 +2802,7 @@ - + @@ -2818,7 +2818,7 @@ - + @@ -2834,7 +2834,7 @@ - + @@ -2850,7 +2850,7 @@ - + @@ -2866,7 +2866,7 @@ - + @@ -2882,7 +2882,7 @@ - + @@ -2898,7 +2898,7 @@ - + @@ -2914,7 +2914,7 @@ - + @@ -2930,7 +2930,7 @@ - + @@ -2946,7 +2946,7 @@ - + @@ -2962,7 +2962,7 @@ - + @@ -2978,7 +2978,7 @@ - + @@ -2994,7 +2994,7 @@ - + @@ -3010,7 +3010,7 @@ - + @@ -3026,7 +3026,7 @@ - + @@ -3042,7 +3042,7 @@ - + @@ -3058,7 +3058,7 @@ - + @@ -3074,7 +3074,7 @@ - + @@ -3090,7 +3090,7 @@ - + @@ -3106,7 +3106,7 @@ - + @@ -3122,7 +3122,7 @@ - + @@ -3138,7 +3138,7 @@ - + @@ -3154,7 +3154,7 @@ - + @@ -3170,7 +3170,7 @@ - + @@ -3186,7 +3186,7 @@ - + @@ -3202,7 +3202,7 @@ - + @@ -3218,7 +3218,7 @@ - + @@ -3234,7 +3234,7 @@ - + @@ -3250,7 +3250,7 @@ - + @@ -3266,7 +3266,7 @@ - + @@ -3282,7 +3282,7 @@ - + @@ -3298,7 +3298,7 @@ - + @@ -3314,7 +3314,7 @@ - + @@ -3330,7 +3330,7 @@ - + @@ -3346,7 +3346,7 @@ - + @@ -3362,7 +3362,7 @@ - + @@ -3378,7 +3378,7 @@ - + @@ -3394,7 +3394,7 @@ - + @@ -3410,7 +3410,7 @@ - + @@ -3426,7 +3426,7 @@ - + @@ -3442,7 +3442,7 @@ - + @@ -3458,7 +3458,7 @@ - + @@ -3474,7 +3474,7 @@ - + @@ -3490,7 +3490,7 @@ - + @@ -3506,7 +3506,7 @@ - + @@ -3522,7 +3522,7 @@ - + @@ -3538,7 +3538,7 @@ - + @@ -3554,7 +3554,7 @@ - + @@ -3570,7 +3570,7 @@ - + @@ -3586,7 +3586,7 @@ - + @@ -3602,7 +3602,7 @@ - + @@ -3618,7 +3618,7 @@ - + @@ -3634,7 +3634,7 @@ - + @@ -3650,7 +3650,7 @@ - + @@ -3666,7 +3666,7 @@ - + @@ -3682,7 +3682,7 @@ - + @@ -3698,7 +3698,7 @@ - + @@ -3714,7 +3714,7 @@ - + @@ -3730,7 +3730,7 @@ - + @@ -3746,7 +3746,7 @@ - + @@ -3762,7 +3762,7 @@ - + @@ -3778,7 +3778,7 @@ - + @@ -3794,7 +3794,7 @@ - + @@ -3810,7 +3810,7 @@ - + @@ -3826,7 +3826,7 @@ - + @@ -3842,7 +3842,7 @@ - + @@ -3858,7 +3858,7 @@ - + @@ -3874,7 +3874,7 @@ - + @@ -3890,7 +3890,7 @@ - + @@ -3906,7 +3906,7 @@ - + @@ -3922,7 +3922,7 @@ - + @@ -3938,7 +3938,7 @@ - + @@ -3954,7 +3954,7 @@ - + @@ -3970,7 +3970,7 @@ - + @@ -3986,7 +3986,7 @@ - + @@ -4002,7 +4002,7 @@ - + @@ -4018,7 +4018,7 @@ - + @@ -4034,7 +4034,7 @@ - + @@ -4050,7 +4050,7 @@ - + @@ -4066,7 +4066,7 @@ - + @@ -4082,7 +4082,7 @@ - + @@ -4098,7 +4098,7 @@ - + @@ -4114,7 +4114,7 @@ - + @@ -4130,7 +4130,7 @@ - + @@ -4146,7 +4146,7 @@ - + @@ -4162,7 +4162,7 @@ - + @@ -4178,7 +4178,7 @@ - + @@ -4194,7 +4194,7 @@ - + @@ -4210,7 +4210,7 @@ - + @@ -4226,7 +4226,7 @@ - + @@ -4256,61 +4256,61 @@ - - + + - - + + - - + + - - + + - + - - + + - - - + + + - - - + + + - - - - - + + + + + - - + + - + - + - + @@ -4325,311 +4325,311 @@ - - + + - + - + - - + + - + - + - + - + - - + + - + - - + + - + - + - - + + - + - - - - + + + + - - + + - + - - - - - - + + + + + + - - + + - - + + - - - + + + - - - - - - - - - - - + + + + + + + + + + + - - + + - - + + - - - - - - - - - - - + + + + + + + + + + + - - - - + + + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - + + - - + + - - - - + + + + - - + + - + - - + + - - + + - - + + - + - + - - + + - - + + - - - - + + + + - + - - + + - - + + - + - - + + - - + + - - + + - - - - - + + + + + - - + + - + - - + + - + - - + + - - - - - + + + + + - - - - - + + + + + - - + + - + - - - - - + + + + + - + - + - + - + - + - - + + - + - - + + - + - + @@ -4642,18 +4642,18 @@ - - - + + + - - + + - + - + @@ -4679,8 +4679,8 @@ - - + + @@ -4688,351 +4688,351 @@ - - + + - - + + - - + + - + - + - + - + - - + + - - + + - + - + - - + + - + - - - - + + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - - - - - - - + + + + + + + + + - - - - - + + + + + - - + + - - - - - - - - + + + + + + + + - - + + - + - + - - + + - - + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - + - - + + - - + + - - - - - - - - + + + + + + + + - - + + - - + + - - + + - + - + - + - + - + - - + + - - + + - + - - - - + + + + - - + + - + - - + + - - + + - - + + - - + + - - + + - - - - + + + + - - + + - + - - + + - - + + - - + + - - + + - + - - - - + + + + - + - - + + - - - - + + + + - - + + - + - - - - + + + + - + - - + + - - + + - - + + - + - + - - + + - + - + - + - + - + - - - - - + + + + + - + - - - - + + + + - - + + - - + + - + @@ -5041,8 +5041,8 @@ - - + + @@ -5057,312 +5057,312 @@ - + - - + + - + - + - - + + - + - + - + - + - - + + - + - - + + - + - + - + - - - + + + - + - + - - + + - - + + - - - - - + + + + + - + - + - - - - + + + + - - - - - + + + + + - - - - - + + + + + - - + + - - - - - - - - + + + + + + + + - - - - + + + + - - - - - + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - + - - + + - + - - + + - - + + - - + + - + - + - + - + - + - + - + - - + + - + - + - - - + + + - - + + - + - + - + - + - + - - + + - - + + - + - + - + - - - + + + - + - + - + - - + + - - + + - - + + - - - - - + + + + + - + - - + + - - - - + + + + - + - + - - + + - - + + - + - + - + - + - + - + @@ -5375,18 +5375,18 @@ - + - - + + - - - + + + - + @@ -5411,315 +5411,315 @@ - + - + - + - - + + - - + + - + - + - + - + - + - - + + - - + + - + - + - + - - - + + + - + - - - + + + - + - - - - + + + + - - + + - - + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - + + + + + - - + + - - + + - - - - - - - - - - - + + + + + + + + + + + - - + + - - + + - - - - - + + + + + - - + + - + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + - - + + - - + + - - + + - + - - + + - + - + - + - + - + - + - - + + - - + + - - + + - - - + + + - + - - + + - - + + - + - - - + + + - - + + - + - - + + - + - - + + - - + + - + - + - - + + - - + + - + - - + + - + - + - - - + + + - + - - + + - - - - - + + + + + - - + + - + - - + + - + - - + + - + - + - + - + @@ -6251,4 +6251,4 @@ - \ No newline at end of file + diff --git a/script.py b/script.py index 5af0a9a..a7a85e7 100644 --- a/script.py +++ b/script.py @@ -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)) diff --git a/xmlModelReader.cpp b/xmlModelReader.cpp index 8c2c879..25eeb38 100644 --- a/xmlModelReader.cpp +++ b/xmlModelReader.cpp @@ -61,48 +61,49 @@ namespace vb01{ //TODO remove the 4 literal for bone weights and indices Mesh* XmlModelReader::processMesh(XMLElement *meshEl){ - int numVertPos = 0; - vector vp; - vector 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 numVertPos = atoi(meshEl->Attribute("num_vertex_pos")); int numVertexGroups = atoi(meshEl->Attribute("num_vertex_groups")); + const char *tagName = "vertdata"; + Vector3 *vertPos = new Vector3[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++){ - vertPos[i] = vp[i]; - weights[i] = new float[4]; - boneIndices[i] = new int[4]; + 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[i] = Vector3(posX, posY, posZ); - for(int j = 0; j < 4; j++){ - weights[i][j] = 0; - //weights[i][j] = w[i * numVertexGroups + j]; - boneIndices[i][j] = -1; - } + weights[i] = new float[4]; + boneIndices[i] = new int[4]; + + 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]; 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")); @@ -111,9 +112,11 @@ namespace vb01{ u32 *indices = new u32[numVertices]; Vector3 *normals = new Vector3[numVertices]; + vector 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); float uvX = atof(vertEl->Attribute("uvx")); float uvY = atof(vertEl->Attribute("uvy")); @@ -138,14 +141,6 @@ namespace vb01{ vertex.tan = tan; 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.boneIndices = boneIndices[id]; @@ -156,43 +151,41 @@ namespace vb01{ tagName = "shapekey"; i = 0; int numShapeKeys = atoi(meshEl->Attribute("num_shape_keys")); - MeshData::ShapeKey *shapeKeys = new MeshData::ShapeKey[numShapeKeys]; - Vector3 **shapeKeyOffsets = new Vector3*[numVertPos]; + MeshData::ShapeKey *shapeKeys = nullptr; + Vector3 **shapeKeyOffsets = nullptr; - for(int i = 0; i < numVertPos; i++){ - shapeKeyOffsets[i] = new Vector3[100]; - } + if(numShapeKeys > 0){ + 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++){ - 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(int i = 0; i < numVertPos; i++) + shapeKeyOffsets[i] = new Vector3[100]; - 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 *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); - vector 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()){ - 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)); - } + int j = 0; - /* - for(int j = 0; j < numVertPos; j++){ - shapeKeyOffsets[i] = new Vector3[100]; + 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 k = 0; k < 100; k++) - shapeKeyOffsets[i][k] = shapeKeyPos[vertIds[j]] - vertPos[vertIds[j]]; - } - */ + for(int i = 0; i < numVertices; i++) + vertices[i].shapeKeyOffsets = shapeKeyOffsets[vertIds[i]]; } const char *fullSkeletonName = meshEl->Attribute("skeleton");