Hello, I’m currently setting this to the side, though I will come back to this later. Though if you want to take a look I’ll leave this here.
for (int i = 0; i < meshcount; i++)
{
SharedPtr<Geometry> geom(new Geometry(context_));
URHO3D_LOGINFO("RMESH LOOP: " + (String)(i + 1));
for (int j = 0; j < 2; j++)
{
byte texflag = source.ReadUByte();
if (texflag != 0)
{
String texString = ReadBlitzString(source);
if (!texString.Empty())
{
texString.Replace(".jpg", "");
texString.Replace(".png", "");
URHO3D_LOGINFO("Texture found: " + texString);
if (texString.Contains("_lm"))
{
mat = readMaterial(texString);
if (!lmMats.Contains(mat))
{
URHO3D_LOGDEBUG("Getting Lightmap!");
lmMats.Push(mat);
}
}
else
{
mat = readMaterial(texString);
brushMats.Push(mat);
}
}
}
}
//Visible
Vector<float> vertData_;
//Vector3 normal = Vector3(0, 1, 0);
int vertcount = source.ReadInt();
for (int j = 0; j < vertcount; j++)
{
//URHO3D_LOGINFO("Reading vertex loop: " + (String)(j + 1));
float x = source.ReadFloat();
float y = source.ReadFloat();
float z = source.ReadFloat();
vertices.Push(Vector3(x, y, z));
float Diffu = source.ReadFloat();
float Diffv = source.ReadFloat();
float LMu = source.ReadFloat();
float LMv = source.ReadFloat();
//URHO3D_LOGDEBUGF("UV: %s", uv.ToString());
//Gonna' see on how to make this work. -Kest
byte r = source.ReadUByte();
byte g = source.ReadUByte();
byte b = source.ReadUByte();
Color color = Color(r, g, b);
//Push into vertData_
vertData_.Push(x);
vertData_.Push(y);
vertData_.Push(z);
//vertData_.Push(normal.x_);
//vertData_.Push(normal.y_);
//vertData_.Push(normal.z_);
vertData_.Push(Diffu);
vertData_.Push(Diffv);
vertData_.Push(LMu);
vertData_.Push(LMv);
bb.Merge(Vector3(x, y, z));
}
Vector<ushort> indData_;
int tricount = source.ReadInt();
for (int j = 0; j < tricount; j++)
{
ushort tri1 = (ushort)source.ReadInt();
ushort tri2 = (ushort)source.ReadInt();
ushort tri3 = (ushort)source.ReadInt();
indData_.Push(tri1);
indData_.Push(tri2);
indData_.Push(tri3);
Vector3 v0 = vertices[tri1];
Vector3 v1 = vertices[tri2];
Vector3 v2 = vertices[tri3];
Vector3 d1 = v0 - v1;
Vector3 d2 = v2 - v1;
Vector3 normal = d1.CrossProduct(d2).Normalized();
vertData_.Push(normal.x_);
vertData_.Push(normal.y_);
vertData_.Push(normal.z_);
}
unsigned elements = MASK_POSITION | MASK_NORMAL | MASK_TEXCOORD1 | MASK_TEXCOORD2;
SharedPtr<VertexBuffer> vertexBuf(new VertexBuffer(context_));
vertexBuf->SetShadowed(true);
vertexBuf->SetSize(vertcount, elements);
vertexBuf->SetData(&vertData_[0]);
URHO3D_LOGINFOF("Vertex buffer done in loop %d.", i + 1);
SharedPtr<IndexBuffer> indexBuf(new IndexBuffer(context_));
indexBuf->SetShadowed(true);
indexBuf->SetSize(tricount * 3, false);
indexBuf->SetData(&indData_[0]);
URHO3D_LOGINFOF("Index buffer done in loop %d.", i + 1);
geom->SetVertexBuffer(0, vertexBuf);
geom->SetIndexBuffer(indexBuf);
geom->SetDrawRange(TRIANGLE_LIST, 0, tricount * 3);
URHO3D_LOGINFOF("Geometry done in loop %d, setting model geometry.", i + 1);
model->SetGeometry(i, 0, geom);
model->SetNumGeometryLodLevels(i, 1);
}