Используемый ими Cube.gpmesh выглядит так.
Код: Выделить всё
{
"version":1,
"vertexformat":"PosNormTex",
"shader":"BasicMesh",
"textures":[
"Assets/Cube.png"
],
"specularPower":100.0,
"vertices":[
[-0.5,-0.5,-0.5,0,0,-1,0,0],
[0.5,-0.5,-0.5,0,0,-1,1,0],
[-0.5,0.5,-0.5,0,0,-1,0,-1],
[0.5,0.5,-0.5,0,0,-1,1,-1],
[-0.5,0.5,0.5,0,1,0,0,-1],
[0.5,0.5,0.5,0,1,0,1,-1],
[-0.5,-0.5,0.5,0,0,1,0,0],
[0.5,-0.5,0.5,0,0,1,1,0],
[-0.5,0.5,-0.5,0,0,-1,0,-1],
[0.5,-0.5,-0.5,0,0,-1,1,0],
[-0.5,0.5,-0.5,0,1,0,0,-1],
[0.5,0.5,-0.5,0,1,0,1,-1],
[-0.5,0.5,0.5,0,1,0,0,-1],
[-0.5,0.5,0.5,0,0,1,0,-1],
[0.5,0.5,0.5,0,0,1,1,-1],
[-0.5,-0.5,0.5,0,0,1,0,0],
[-0.5,-0.5,0.5,0,-1,0,0,0],
[0.5,-0.5,0.5,0,-1,0,1,0],
[-0.5,-0.5,-0.5,0,-1,0,0,0],
[0.5,-0.5,-0.5,0,-1,0,1,0],
[0.5,-0.5,-0.5,1,0,0,1,0],
[0.5,-0.5,0.5,1,0,0,1,0],
[0.5,0.5,-0.5,1,0,0,1,-1],
[0.5,0.5,0.5,1,0,0,1,-1],
[-0.5,-0.5,0.5,-1,0,0,0,0],
[-0.5,-0.5,-0.5,-1,0,0,0,0],
[-0.5,0.5,0.5,-1,0,0,0,-1],
[-0.5,0.5,-0.5,-1,0,0,0,-1]
],
"indices":[
[2,1,0],
[3,9,8],
[4,11,10],
[5,11,12],
[6,14,13],
[7,14,15],
[18,17,16],
[19,17,18],
[22,21,20],
[23,21,22],
[26,25,24],
[27,25,26]
]
}
И код Mesh.cpp
Код: Выделить всё
VertexArray::Layout layout = VertexArray::PosNormTex;
size_t vertSize = 8;
...
// Load in the vertices
const rapidjson::Value& vertsJson = doc["vertices"];
if (!vertsJson.IsArray() || vertsJson.Size() < 1)
{
SDL_Log("Mesh %s has no vertices", fileName.c_str());
return false;
}
std::vector vertices;
vertices.reserve(vertsJson.Size() * vertSize);
mRadius = 0.0f;
for (rapidjson::SizeType i = 0; i < vertsJson.Size(); i++)
{
// For now, just assume we have 8 elements
const rapidjson::Value& vert = vertsJson[i];
if (!vert.IsArray())
{
SDL_Log("Unexpected vertex format for %s", fileName.c_str());
return false;
}
Vector3 pos(vert[0].GetDouble(), vert[1].GetDouble(), vert[2].GetDouble());
mRadius = Math::Max(mRadius, pos.LengthSq());
mBox.UpdateMinMax(pos);
if (layout == VertexArray::PosNormTex)
{
Vertex v;
// Add the floats
for (rapidjson::SizeType j = 0; j < vert.Size(); j++)
{
v.f = static_cast(vert[j].GetDouble());
vertices.emplace_back(v);
}
}
else
{
...
}
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... ake-a-cube