public override void Render(Matrix4 v) { //Console.WriteLine("Rendering " + Text); GL.UseProgram(BFRES.shader.programID); GL.UniformMatrix4(BFRES.shader.getAttribute("modelview"), false, ref v); FSKL skel = ((FMDL)shapes[0].Parent).skel; Matrix4[] f = skel.getBoneTransforms(); int[] bind = skel.bindId; GL.UniformMatrix4(BFRES.shader.getAttribute("bones"), f.Length, false, ref f[0].Row0.X); if (bind.Length != 0) { GL.Uniform1(BFRES.shader.getAttribute("bonematch"), bind.Length, ref bind[0]); } BFRES.shader.enableAttrib(); foreach (FSHP shape in shapes) { FVTX vert = vertattr[shape.fvtxindex]; //Textures are disabled atm string tex = mats[shape.fmatIndex].tex[0].Text; // find it in textures foreach (TreeNode n in ((BFRES)Parent.Parent).Nodes) { if (n.Text.Equals("Embedded Files")) { foreach (TreeNode no in n.Nodes) { foreach (TreeNode tn in no.Nodes) { foreach (TreeNode T in tn.Nodes) { if (T.Text.Equals(tex)) { Console.WriteLine("Binding " + T.Text); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, ((BRTI)T).tex.id); GL.Uniform1(BFRES.shader.getAttribute("tex"), 0); break; } } } } break; } } GL.BindBuffer(BufferTarget.ArrayBuffer, vert.gl_vbo); GL.VertexAttribPointer(BFRES.shader.getAttribute("_p0"), 3, VertexAttribPointerType.Float, false, BaseRenderData.Vertex.Stride, 0); GL.VertexAttribPointer(BFRES.shader.getAttribute("_n0"), 3, VertexAttribPointerType.Float, false, BaseRenderData.Vertex.Stride, 12); GL.VertexAttribPointer(BFRES.shader.getAttribute("_u0"), 2, VertexAttribPointerType.Float, false, BaseRenderData.Vertex.Stride, 24); GL.VertexAttribPointer(BFRES.shader.getAttribute("_i0"), 4, VertexAttribPointerType.Float, false, BaseRenderData.Vertex.Stride, 32); GL.VertexAttribPointer(BFRES.shader.getAttribute("_w0"), 4, VertexAttribPointerType.Float, false, BaseRenderData.Vertex.Stride, 48); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); // bind attributes //Console.WriteLine(shape.Text + " " + shape.singleBind); GL.Uniform1(BFRES.shader.getAttribute("single"), shape.singleBind); /*foreach (BFRESAttribute att in vert.attributes) * { * int size = 0; * BFRESBuffer buffer = vert.buffers[att.bufferIndex]; * float[] data = att.data.ToArray(); * //Console.WriteLine(att.Text + " " + ((int)(att.format)).ToString("x")); * switch (att.Text) * { * case "_p0": GL.BindBuffer(BufferTarget.ArrayBuffer, vbo_po); size = 4; break; * case "_n0": GL.BindBuffer(BufferTarget.ArrayBuffer, vbo_n0); size = 4; break; * case "_i0": * GL.BindBuffer(BufferTarget.ArrayBuffer, vbo_i0); * if (att.format == 256) { size = 1; } else * if (att.format == 260) { size = 2; } else * //if (att.format == 261) { size = 4; } else * if (att.format == 266) { size = 4; } else * if (att.format == 268) { size = 2; } * //else if (att.format == 272) { size = 4; } * else { Console.WriteLine("Unused bone type "); } * GL.Uniform1(BFRES.shader.getAttribute("boneSize"), size); * * for (int i = 0; i < att.data.Count; i++) * { * if (data[i] < skel.bindId.Count) * data[i] = skel.bindId[(int)data[i]]; * } * break; * case "_w0": * GL.BindBuffer(BufferTarget.ArrayBuffer, vbo_w0); * if (att.format == 4) { size = 2; } * if (att.format == 10) { size = 4; } * if (att.format == 2061) { size = 2; } * break; * default: continue; * } * //Console.WriteLine(buffer.stride); * GL.BufferData<float>(BufferTarget.ArrayBuffer, (IntPtr)(data.Length * sizeof(float)), data, BufferUsageHint.StaticDraw); * GL.VertexAttribPointer(BFRES.shader.getAttribute(att.Text), size, VertexAttribPointerType.Float, false, * buffer.stride * BFRESAttribute.formatStrideMultiplyer[att.format], att.bufferOffset);// * }*/ // draw models foreach (LODModel mod in shape.lodModels) { GL.BindBuffer(BufferTarget.ElementArrayBuffer, ibo); if (mod.type == DrawElementsType.UnsignedShort) { GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mod.data.Length * sizeof(ushort)), mod.data, BufferUsageHint.StaticDraw); GL.DrawElements(PrimitiveType.Triangles, mod.fcount, mod.type, mod.skip * sizeof(ushort)); } else if (mod.type == DrawElementsType.UnsignedInt) { GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mod.data.Length * sizeof(uint)), mod.data, BufferUsageHint.StaticDraw); GL.DrawElements(PrimitiveType.Triangles, mod.fcount, mod.type, mod.skip * sizeof(uint)); } break; // only draw first one } } BFRES.shader.disableAttrib(); GL.UseProgram(0); GL.Disable(EnableCap.DepthTest); skel.Render(v); GL.Enable(EnableCap.DepthTest); }
public FMDL(FileData f) { ImageKey = "model"; SelectedImageKey = "model"; f.skip(4); // MAGIC f.skip(8); // Header Length f.skip(4); // padding Text = f.readString(f.readOffset() + 2, -1); f.skip(4); // padding int EndOfStringTable = f.readOffset(); f.skip(4); // padding int FSKLOffset = f.readOffset(); f.skip(4); // padding int FVTXOffset = f.readOffset(); f.skip(4); // padding int FSHPOffset = f.readOffset(); f.skip(4); // padding int FSHPDict = f.readOffset(); f.skip(4); // padding int FMATOffset = f.readOffset(); f.skip(4); // padding int FMATDict = f.readOffset(); f.skip(4); // padding int UserDataOffset = f.readOffset(); f.skip(20); // padding int FVTXCount = f.readShort(); int FSHPCount = f.readShort(); int FMATCount = f.readShort(); int UserData = f.readShort(); int TotalAmountOfVerticies = f.readShort(); f.skip(4); // padding // FSKL for skeleton f.seek(FSKLOffset); skel = new FSKL(); skel.Read(f); Nodes.Add(skel); // FMAT is obs materials for (int i = 0; i < FMATCount; i++) { f.seek(FMATOffset + (i * 184)); mats.Add(new FMAT(f)); } // FVTX is the vertex buffer object attributes for (int i = 0; i < FVTXCount; i++) { f.seek(FVTXOffset + (i * 96)); vertattr.Add(new FVTX(f)); } // FSHP is the mesh objects for (int i = 0; i < FSHPCount; i++) { f.seek(FSHPOffset + (i * 112)); shapes.Add(new FSHP(f)); } Nodes.AddRange(shapes.ToArray()); Nodes.AddRange(vertattr.ToArray()); Nodes.AddRange(mats.ToArray()); GL.GenBuffers(1, out ibo); }
public FMDL(FileData f) { ImageKey = "model"; SelectedImageKey = "model"; f.skip(4); // MAGIC int fnameOffset = f.readOffset(); Text = f.readString(fnameOffset, -1); f.skip(4); // pointer to end of string table? int FSKLOffset = f.readOffset(); int FVTXOffset = f.readOffset(); int FSHPOffset = f.readOffset(); int FMATOffset = f.readOffset(); int PARAMOffset = f.readOffset(); int FVTXCount = f.readShort(); int FSHPCount = f.readShort(); int FMATCount = f.readShort(); int PARAMCount = f.readShort(); f.skip(4); // unknown possible facecount or something? // firstly Imma do the skeleton f.seek(FSKLOffset); skel = new FSKL(); skel.Read(f); Nodes.Add(skel); // FMAT is obs materials f.seek(FMATOffset); IndexGroup fmatGroup = new IndexGroup(f); for (int i = 0; i < FMATCount; i++) { f.seek(fmatGroup.dataOffsets[i]); mats.Add(new FMAT(f)); } // FVTX is the vertex buffer object attributes f.seek(FVTXOffset); for (int i = 0; i < FVTXCount; i++) { vertattr.Add(new FVTX(f)); } // FSHP is the mesh objects f.seek(FSHPOffset); IndexGroup fmdlGroup = new IndexGroup(f); for (int i = 0; i < FSHPCount; i++) { f.seek(fmdlGroup.dataOffsets[i]); shapes.Add(new FSHP(f)); } Nodes.AddRange(shapes.ToArray()); Nodes.AddRange(vertattr.ToArray()); Nodes.AddRange(mats.ToArray()); GL.GenBuffers(1, out ibo); }