public PSKFile(DAILibWV.Frostbite.Mesh m) { psk = new PSKContainer(); psk.materials = new List<PSKMaterial>(); psk.points = new List<PSKPoint>(); psk.edges = new List<PSKEdge>(); psk.faces = new List<PSKFace>(); psk.bones = new List<PSKBone>(); psk.weights = new List<PSKWeight>(); psk.extrauv1 = new List<PSKExtraUV>(); psk.extrauv2 = new List<PSKExtraUV>(); psk.extrauv3 = new List<PSKExtraUV>(); DAILibWV.Frostbite.Mesh.MeshLOD l = null; foreach (DAILibWV.Frostbite.Mesh.MeshLOD lod in m.header.LODs) if(l == null) foreach(DAILibWV.Frostbite.Mesh.MeshSection sec in lod.Sections) if (sec.VertexBuffer.Count != 0) { l = lod; break; } if (l != null) { int pointcount = 0; byte count = 0; foreach (DAILibWV.Frostbite.Mesh.MeshSection sec in l.Sections) { psk.materials.Add(new PSKMaterial("Material" + count.ToString("d2"), count)); int index = 0; foreach (DAILibWV.Frostbite.Mesh.Vertex v in sec.VertexBuffer) { psk.points.Add(new PSKPoint(v.Position.x, v.Position.y, v.Position.z)); psk.edges.Add(new PSKEdge((short)(pointcount + index++), v.TexCoords.x, v.TexCoords.y, count)); } foreach (DAILibWV.Frostbite.Mesh.Triangle t in sec.IndexBuffer) psk.faces.Add(new PSKFace(pointcount + t.i1, pointcount + t.i0, pointcount + t.i2, count)); pointcount += sec.VertexBuffer.Count; count++; } } }
public MeshRenderObject(DAILibWV.Frostbite.Mesh m) { mesh = m; foreach (DAILibWV.Frostbite.Mesh.MeshLOD lod in mesh.header.LODs) { if (lod.Sections == null || lod.Sections.Count == 0 || lod.Sections[0].VertexBuffer == null) continue; RawTriangles = new List<CustomVertex.PositionTextured[]>(); foreach (DAILibWV.Frostbite.Mesh.MeshSection sec in lod.Sections) { List<CustomVertex.PositionTextured> list = new List<CustomVertex.PositionTextured>(); for (int i = 0; i < sec.TriangleCount; i++) { list.Add(DAI2DX(sec.VertexBuffer[sec.IndexBuffer[i].i0])); list.Add(DAI2DX(sec.VertexBuffer[sec.IndexBuffer[i].i1])); list.Add(DAI2DX(sec.VertexBuffer[sec.IndexBuffer[i].i2])); } RawTriangles.Add(list.ToArray()); } break; } float inf = 10000000000f; min = new Vector3(inf, inf, inf); max = new Vector3(-inf, -inf, -inf); foreach (CustomVertex.PositionTextured[] list in RawTriangles) { foreach (CustomVertex.PositionTextured v in list) { if (v.X > max.X) max.X = v.X; if (v.Y > max.Y) max.Y = v.Y; if (v.Z > max.Z) max.Z = v.Z; if (v.X < min.X) min.X = v.X; if (v.Y < min.Y) min.Y = v.Y; if (v.Z < min.Z) min.Z = v.Z; } } center = (max + min) * 0.5f; }
public CustomVertex.PositionTextured DAI2DX(DAILibWV.Frostbite.Mesh.Vertex p) { return new CustomVertex.PositionTextured(new Vector3(p.Position.x, p.Position.z, p.Position.y), p.TexCoords.x, p.TexCoords.y); }