Author: cjcollier
Date: 2006-06-18 23:03:38 -0400 (Sun, 18 Jun 2006)
New Revision: 61832
Modified:
trunk/gtkglarea-sharp/examples/MdlLoader/Engine.cs
trunk/gtkglarea-sharp/examples/MdlLoader/Makefile.am
trunk/gtkglarea-sharp/examples/MdlLoader/MdlLoader.cs
Log:
implemented methods to read the mdl_t struct and texgroup_struct[]
array
Modified: trunk/gtkglarea-sharp/examples/MdlLoader/Engine.cs
===================================================================
--- trunk/gtkglarea-sharp/examples/MdlLoader/Engine.cs 2006-06-19 03:02:08 UTC
(rev 61831)
+++ trunk/gtkglarea-sharp/examples/MdlLoader/Engine.cs 2006-06-19 03:03:38 UTC
(rev 61832)
@@ -6,6 +6,9 @@
public class Engine {
public static int Main (string[] args)
{
+ Mdl.MdlLoader loader = new Mdl.MdlLoader();
+ Mdl.Mdl myMdl =
loader.Load("/home/cjcollier/id/models/armor.mdl");
+
Gtk.Application.Init ();
GtkGL.GladeExample ge = new GtkGL.GladeExample ();
Modified: trunk/gtkglarea-sharp/examples/MdlLoader/Makefile.am
===================================================================
--- trunk/gtkglarea-sharp/examples/MdlLoader/Makefile.am 2006-06-19
03:02:08 UTC (rev 61831)
+++ trunk/gtkglarea-sharp/examples/MdlLoader/Makefile.am 2006-06-19
03:03:38 UTC (rev 61832)
@@ -29,7 +29,8 @@
-pkg:glade-sharp-2.0 \
-lib:$(srcdir)/../util \
-r:gtkglarea-sharp-util.dll \
- -resource:$(srcdir)/../resources/glwidget.glade
+ -resource:$(srcdir)/../resources/glwidget.glade \
+ -nowarn:0169
$(EXAMPLE_NAME).exe: $(SOURCE_FILES)
mcs \
Modified: trunk/gtkglarea-sharp/examples/MdlLoader/MdlLoader.cs
===================================================================
--- trunk/gtkglarea-sharp/examples/MdlLoader/MdlLoader.cs 2006-06-19
03:02:08 UTC (rev 61831)
+++ trunk/gtkglarea-sharp/examples/MdlLoader/MdlLoader.cs 2006-06-19
03:03:38 UTC (rev 61832)
@@ -1,3 +1,6 @@
+using System;
+using System.IO;
+
// created on 11/26/2005 at 3:33 PM
namespace Mdl {
enum synctype_t {
@@ -15,24 +18,23 @@
ALIAS_SKIN_GROUP
};
+ struct mdl_t {
-
- struct mdl_t {
- int ident;
- int version;
- float[] scale;
- float[] scale_origin;
- float boundingradius;
- float[] eyeposition;
- int num_texgroups;
- int texwidth;
- int texheight;
- int numverts;
- int numtris;
- int numframes;
- synctype_t synctype;
- int flags;
- float size;
+ public int ident;
+ public int version;
+ public float[] scale;
+ public float[] scale_origin;
+ public float boundingradius;
+ public float[] eyeposition;
+ public int num_texgroups;
+ public int texwidth;
+ public int texheight;
+ public int numverts;
+ public int numtris;
+ public int numframes;
+ public synctype_t synctype;
+ public int flags;
+ public float size;
};
struct stvert_t {
@@ -68,15 +70,15 @@
};
struct tex_struct {
- int[] pixel; //Pixel data
+ public byte[] pixel; //Pixel data
};
struct texgroup_struct {
- aliasskintype_t type;
+ public aliasskintype_t type;
- long numtextures; // number of pictures in
group
- float[] interval; // intervals for each
picture
- tex_struct[] texture; // texture data
+ public long numtextures; // number of
pictures in group
+ public float[] interval; // intervals for
each picture
+ public tex_struct[] texture; // texture data
};
struct pose_struct {
@@ -99,11 +101,148 @@
dtriangle_t[] triangle_data;
frame_struct[] frame;
};
+
+ class Mdl {
+ public Mdl() { }
+ }
class MdlLoader {
const int DT_FACES_FRONT = 0x0010;
+ public MdlLoader() {
+ }
+
+ public Mdl Load(string fileName) {
+ System.IO.FileStream fstream;
+
+ try {
+ fstream = File.Open(fileName,
System.IO.FileMode.Open);
+
+ } catch(IOException e) {
+ System.Console.WriteLine("Oops. We got an
exception: {0}", e.ToString());
+ return null;
+ }
+
+ mdl_t mdlTStruct = readMdlT(fstream);
+ texgroup_struct[] tgs = readTexGroupStructs(mdlTStruct,
fstream);
+ Mdl myMdl = new Mdl();
+
+ return myMdl;
+ }
+ private texgroup_struct[] readTexGroupStructs(mdl_t mdlTStruct,
System.IO.FileStream fstream)
+ {
+ texgroup_struct[] tgs = new texgroup_struct[
mdlTStruct.num_texgroups ];
+
+ for(int texgroup_num = 0; texgroup_num <
mdlTStruct.num_texgroups; texgroup_num++){
+ tgs[texgroup_num].type = (aliasskintype_t)
readInt(fstream);
+ Console.WriteLine("Type for tgs[{0}] is {1}",
texgroup_num, tgs[texgroup_num].type);
+
+ if(tgs[texgroup_num].type ==
aliasskintype_t.ALIAS_SKIN_SINGLE){
+ //if type is ALIAS_SKIN_SINGLE, set
number of textures to 1
+ tgs[texgroup_num].numtextures = 1;
+
+ //and interval[0] to 0
+ tgs[texgroup_num].interval = new
float[1];
+ tgs[texgroup_num].interval[0] = 0.0f;
+ }else{
+ // Determine how many textures there
are in this group
+ tgs[texgroup_num].numtextures =
readInt(fstream);
+ Console.WriteLine("numtextures for
tgs[{0}] is {1}", texgroup_num, tgs[texgroup_num].numtextures);
+ tgs[texgroup_num].interval = new
float[tgs[texgroup_num].numtextures];
+
+ // Read the intervals between each
texture
+ for(int i = 0; i <
tgs[texgroup_num].numtextures; i++){
+ tgs[texgroup_num].interval[i] =
readSingle(fstream);
+ }
+ }
+
+ // Read texture data
+ tgs[texgroup_num].texture = new
tex_struct[tgs[texgroup_num].numtextures];
+
+ for(int tex_num = 0; tex_num <
tgs[texgroup_num].numtextures; tex_num++){
+
tgs[texgroup_num].texture[tex_num].pixel = new byte[mdlTStruct.texheight *
mdlTStruct.texwidth];
+
fstream.Read(tgs[texgroup_num].texture[tex_num].pixel, 0, mdlTStruct.texheight
* mdlTStruct.texwidth);
+ }
+ }
+
+ return tgs;
+ }
+ private mdl_t readMdlT(System.IO.FileStream fstream)
+ {
+ mdl_t mdlTStruct = new mdl_t();
+
+ mdlTStruct.ident = readInt(fstream);
+ Console.WriteLine("Ident is {0}", mdlTStruct.ident);
+
+ mdlTStruct.version = readInt(fstream);
+ Console.WriteLine("Version is {0}", mdlTStruct.version);
+
+ mdlTStruct.scale = new float[3];
+
+ for(int i = 0; i <= 2; i++){
+ mdlTStruct.scale[i] = readSingle(fstream);
+ Console.WriteLine("Scale[{0}]: {1}", i,
mdlTStruct.scale[i]);
+ }
+
+ mdlTStruct.scale_origin = new float[3];
+ for(int i = 0; i <= 2; i++){
+ mdlTStruct.scale_origin[i] =
readSingle(fstream);
+ Console.WriteLine("scale_origin[{0}]: {1}", i,
mdlTStruct.scale_origin[i]);
+ }
+
+ mdlTStruct.boundingradius = readSingle(fstream);
+ Console.WriteLine("bounding radius is {0}",
mdlTStruct.boundingradius);
+
+ mdlTStruct.eyeposition = new float[3];
+ for(int i = 0; i <= 2; i++){
+ mdlTStruct.eyeposition[i] = readSingle(fstream);
+ Console.WriteLine("eyeposition[{0}]: {1}", i,
mdlTStruct.eyeposition[i]);
+ }
+
+ mdlTStruct.num_texgroups = readInt(fstream);
+ Console.WriteLine("Number of texgroups: {0}",
mdlTStruct.num_texgroups);
+
+ mdlTStruct.texwidth = readInt(fstream);
+ Console.WriteLine("texture width: {0}",
mdlTStruct.texwidth);
+
+ mdlTStruct.texheight = readInt(fstream);
+ Console.WriteLine("texture height: {0}",
mdlTStruct.texheight);
+
+ mdlTStruct.numverts = readInt(fstream);
+ Console.WriteLine("numverts: {0}", mdlTStruct.numverts);
+
+ mdlTStruct.numtris = readInt(fstream);
+ Console.WriteLine("numtris: {0}", mdlTStruct.numtris);
+
+ mdlTStruct.numframes = readInt(fstream);
+ Console.WriteLine("numframes: {0}",
mdlTStruct.numframes);
+
+ mdlTStruct.synctype = (synctype_t) readInt(fstream);
+ Console.WriteLine("synctype: {0}", mdlTStruct.synctype);
+
+ mdlTStruct.flags = readInt(fstream);
+ Console.WriteLine("flags: {0}", mdlTStruct.flags);
+
+ mdlTStruct.size = readSingle(fstream);
+ Console.WriteLine("size: {0}", mdlTStruct.size);
+
+ return mdlTStruct;
+ }
+
+ private float readSingle(System.IO.FileStream fstream)
+ {
+ byte[] buff = new byte[4];
+ fstream.Read(buff, 0, 4);
+ return System.BitConverter.ToSingle(buff, 0);
+ }
+
+ private int readInt(System.IO.FileStream fstream)
+ {
+ byte[] buff = new byte[4];
+ fstream.Read(buff, 0, 4);
+ return System.BitConverter.ToInt32(buff, 0);
+ }
}
}
\ No newline at end of file
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches