I see...
you just rewrote the main classes

however, I noticed you only got to the triangle strips when you couldn't work with it anymore...

one thing I've had much trouble with is accessing coords stored in a variable...
I can't for the life of me, figure out how to store a file in a var...

I'll give you some hints,
in the C++ version, the mdl0 file is loaded as (pointer to) a char array, and you know char is basically an unsigned byte.
So just open the file in python, and for each character in there, convert it to an integer using ord() so you have an array of integers.
Then manipulate the file.

I'll give you some hints,
in the C++ version, the mdl0 file is loaded as (pointer to) a char array, and you know char is basically an unsigned byte.
So just open the file in python, and for each character in there, convert it to an integer using ord() so you have an array of integers.
Then manipulate the file.

Probably most effective way for this is to use one of these modules:

  • array
  • numpy
  • blist

There is also basic bytearray:

>>> a=bytearray((123,12,24))
>>> a
bytearray(b'{\x0c\x18')
>>> a[0]
123
>>>

What is happening here is, the mdl0 file is read and its info values are loaded into its defined concrete types Vec3, Vec2, Vertex, etc. as floats, chars, and bools, etc(?). Then, the export class gets the mdl0file object (which is a loaded mdl0 file) and creates a dae object and writes from the mdl0file to it in the specific format.

It is possible to implement in Python.

See here

daeElement* float_array = source->add("float_array");
	string arrayPosName(posName + "-array");
	float_array->setAttribute("id", arrayPosName.c_str());
	float_array->setAttribute("count", intToString(group->size() * 3).c_str());

	ostringstream strm;
	for (uint i = 0; i < group->size(); i++) {  //iterates through "group" for Vec3's
		Vec3 vec = (*group)[i];  //dereferences the pointer to get Vec3 at index i
		strm << -vec.X() << " " << vec.Y() << " " << vec.Z() << "\n";  //write to stream
	}
	float_array->setCharData(strm.str()); //this writes from the stream to the daeElement
	//the daeElement is what eventually the output file

source is a daeelement,
and group is a pointer to a collection of Vec3's loaded from the Mdl0.

I'm too busy right now in China to examine very closely, but hopefully this helps

Something else is,
do you have some way in Python to do something like:

fl_array = mydaefile.add("float-array")
fl_array.setAttribute("attr","value")
fl_array.setCharData(my_byte_array)

because that comes with the dae library in C++. there's no easy way to replace that.

I forget what to read it with, but you can import the C++ module and use it as a python module... :/

or...

would this help:

that's ok :)
maybe I'll use this thread to develope my import/export script...
nah... I'll make a new thread when I get around to posting it...

just letting everyone know I've made the thread :)
http://www.daniweb.com/forums/thread302929.html

I will be developing my script here as well

can I just ask for parts I need converted, so I can work with them in python??

eg:

uint32_t BigUInt32(const char* data, unsigned int offset) {
	union {
		uint32_t u;
		unsigned char b[4];
	} dat;

	dat.b[0] = data[offset + 3];
	dat.b[1] = data[offset + 2];
	dat.b[2] = data[offset + 1];
	dat.b[3] = data[offset];
	return dat.u;
}

I can understand the second half "dat.b[0] = data[offset + 3];" etc...

but it's the first half that confuses me
I tried doing research on C++ unions...
and well...
I'm still confused...

can anyone tell me how that function is supposed to work??
(with a supposed hex string of say 'FE 08')

can I just ask for parts I need converted, so I can work with them in python??

eg:

uint32_t BigUInt32(const char* data, unsigned int offset) {
	union {
		uint32_t u;
		unsigned char b[4];
	} dat;

	dat.b[0] = data[offset + 3];
	dat.b[1] = data[offset + 2];
	dat.b[2] = data[offset + 1];
	dat.b[3] = data[offset];
	return dat.u;
}

I can understand the second half "dat.b[0] = data[offset + 3];" etc...

but it's the first half that confuses me
I tried doing research on C++ unions...
and well...
I'm still confused...

can anyone tell me how that function is supposed to work??
(with a supposed hex string of say 'FE 08')

You see, this union has two members,
b and u.
u is an unsigned integer (IMPORTANT - uint is 4 bytes!)
and b is an array of 4 chars which are bytes.
b and u overlap because this is a union!

So what this function does is it gets the big-endian int of the offset data.
Hopefully that clears it a little.

EDIT:
So let's say you have in your data,
... 59 3A FF 1E ...
so you call this function, (with the offset etc)
so you see, in the function,
data[offset] = 59
data[offset+1] = 3A
data[offset+2] = FF
data[offset+3] = 1E

Now, 59 3A FF 1E should evaluate to int("593AFF1E",16).
But what if that is in big endian, and you want it's integer representation in little endian?
Then just convert it by flipping it
first create a union (in C++, you are working with bytes like this)
so the union "dat" has a size of 4bytes,
and dat.u is the unsigned integer representation of those 4 bytes.
dat.b[0] is the first byte of that uint/union,
dat.b[1] is the second...

you have to understand that the uint's 4bytes and the char array (which is a byte array)'s bytes overlap!

Then, it's easy to understand how the flipping works.

And to see how to do similar things in Python see struct module.

And to see how to do similar things in Python see struct module.

No need for making structs, C++ way of flipping the bytes is making a union, in Python making a union requires ctypes and is too complicated.
Just do something like data[offset:offset+3][::-1].

so this would pretty much be the equivelent??

import Struct

def BigUInt32(hexstring):
	hexstring = n[3] + n[2] + n[1] + n[0] #flip
	number= Struct.unpack(  "<h", S.pack( "<H", int( ( hexstring.encode('hex')), 16 ) )  )[0]
	return float(number)


file = open("filename","rb")
num = BigUInt32(file.read(4))

credit to Revel8n for the code: Struct.unpack("<h",S.pack("<H",int((hexstring.encode('hex')), 16)))[0]

so this would pretty much be the equivelent??

import Struct

def func(hexstring):
	hexstring = n[3] + n[2] + n[1] + n[0] #flip
	number= Struct.unpack(  "<h", S.pack( "<H", int( ( hexstring.encode('hex')), 16 ) )  )[0]
	return float(number)


file = open("filename","rb")
num = func(file.read(4))

No, from the docs,
"H" is short, you need uint.
In your function, if the data has a value that is larger than the max value for short, then it will fail when it shouldn't.
Why don't you flip the string, then call int( ,16).
Struct can be useful, but you aren't using the big-endian (">") format, so it's useless as far as I know.

Just do something like

BigUInt32 = lambda x: int(x[::-1],16)

can I get a more descriptive example??

I've never used lambda before...
and I never understood the ':'
(even though I have about 50 tutorials to lead me) :icon_redface:

so something like this??

n = n[3] + n[2] + n[1] + n[0]
n = str(n.encode('hex'))
h = lambda n: int(n[::-1],16)

return h * 0.0001

can I get a more descriptive example??

I've never used lambda before...
and I never understood the ':'
(even though I have about 50 tutorials to lead me) :icon_redface:

so something like this??

n = n[3] + n[2] + n[1] + n[0]
n = str(n.encode('hex'))
h = lambda n: int(n[::-1],16)

return h * 0.0001
BigUInt32 = lambda x: int(x[::-1],16)

is the same as

def BigUInt32(x):
    return int(x[::-1],16)

but I've just realized it should be

BigUInt32 = lambda x: int(x[::-1].encode('hex'), 16)

well...
I can officially say I'm making progress :icon_biggrin:

http://lh5.ggpht.com/_IteXPmeC6ek/TGyXp0UloJI/AAAAAAAABo4/WhKNmp8dPzM/take1.jpg

this image is actually done with my last code...
the code you gave me jcao219, does the exact same thing...
but it's alot shorter...
thanx :icon_smile:

I actually had to mod it to make it work...

return int(str(n).encode('hex'),16)

and I didn't have to reverse the bytes either :icon_biggrin:


so like...
[::-1] = reverse byte order??

EDIT:
here's a fresh import of what it looks like:
http://lh5.ggpht.com/_IteXPmeC6ek/TGysUCege3I/AAAAAAAABpM/o8GkoKX3Z4w/take1_2.jpg
the verts are scattered apart in sections...

you can see where I use the code...
now I just need something a little better...

anyone think they can help?

I found the code I was looking for:

bool MDL0File::loadVec3Group(const char* data, Vec3Group* group) {
	bool boundingbox = data[23];
	char datatype = data[27];
	char fixedpointbits = data[28];
	uint16_t datacount = BigUInt16(data, 30);

	int datastart = 32;
	if (boundingbox) {
		float minx = BigFloat(data, 32);
		float miny = BigFloat(data, 36);
		float minz = BigFloat(data, 40);
		float maxx = BigFloat(data, 44);
		float maxy = BigFloat(data, 48);
		float maxz = BigFloat(data, 52);

		group->SetBound(Vec3(minx, miny, minz), Vec3(maxx, maxy, maxz));

		datastart = 64;
	} else {
		group->SetBound(Vec3(0, 0, 0), Vec3(0, 0, 0));
	}

	switch (datatype) {
	case 0: // fixed point u8
		for (int i = 0; i < datacount; i++) {
			float x = (unsigned char) data[datastart + i * 6] / pow(2.0f,
					fixedpointbits);
			float y = (unsigned char) data[datastart + 1 + i * 6] / pow(2.0f,
					fixedpointbits);
			float z = (unsigned char) data[datastart + 2 + i * 6] / pow(2.0f,
					fixedpointbits);
			group->push_back(Vec3(x, y, z));
		}
		break;
	case 1: // fixed point s8
		for (int i = 0; i < datacount; i++) {
			float x = data[datastart + i * 6] / pow(2.0f, fixedpointbits);
			float y = data[datastart + 1 + i * 6] / pow(2.0f, fixedpointbits);
			float z = data[datastart + 2 + i * 6] / pow(2.0f, fixedpointbits);
			group->push_back(Vec3(x, y, z));
		}
		break;
	case 2: // fixed point u16
		for (int i = 0; i < datacount; i++) {
			float x = BigUInt16(data, datastart + i * 6) / pow(2.0f,
					fixedpointbits);
			float y = BigUInt16(data, datastart + 2 + i * 6) / pow(2.0f,
					fixedpointbits);
			float z = BigUInt16(data, datastart + 4 + i * 6) / pow(2.0f,
					fixedpointbits);
			group->push_back(Vec3(x, y, z));
		}
		break;
	case 3: // fixed point s16
		for (int i = 0; i < datacount; i++) {
			float x = BigSInt16(data, datastart + i * 6) / pow(2.0f,
					fixedpointbits);
			float y = BigSInt16(data, datastart + 2 + i * 6) / pow(2.0f,
					fixedpointbits);
			float z = BigSInt16(data, datastart + 4 + i * 6) / pow(2.0f,
					fixedpointbits);
			group->push_back(Vec3(x, y, z));
		}
		break;
	case 4: // floating point
		for (int i = 0; i < datacount; i++) {
			float x = BigFloat(data, datastart + i * 12);
			float y = BigFloat(data, datastart + 4 + i * 12);
			float z = BigFloat(data, datastart + 8 + i * 12);
			group->push_back(Vec3(x, y, z));
		}
		break;
	default:
		return false;
	}

	return true;
}

this is what does the vert conversion...
I see it uses the bounding box as coords for the verts...

maybe I should move this thread to my other thread, since that's what this is turning into :P

this code looks like it could be an easy equivilent in py...
but IDK for sure... :(
would anyone mind translating this??

I prbly could (and would) do it myself if I understood C++ and python a little more...
I'm sry if I'm putting a burden on you guys...
I hate putting my work off on other people :(

I found the code I was looking for:

bool MDL0File::loadVec3Group(const char* data, Vec3Group* group) {
	bool boundingbox = data[23];
	char datatype = data[27];
	char fixedpointbits = data[28];
	uint16_t datacount = BigUInt16(data, 30);

	int datastart = 32;
	if (boundingbox) {
		float minx = BigFloat(data, 32);
		float miny = BigFloat(data, 36);
		float minz = BigFloat(data, 40);
		float maxx = BigFloat(data, 44);
		float maxy = BigFloat(data, 48);
		float maxz = BigFloat(data, 52);

		group->SetBound(Vec3(minx, miny, minz), Vec3(maxx, maxy, maxz));

		datastart = 64;
	} else {
		group->SetBound(Vec3(0, 0, 0), Vec3(0, 0, 0));
	}

	switch (datatype) {
	case 0: // fixed point u8
		for (int i = 0; i < datacount; i++) {
			float x = (unsigned char) data[datastart + i * 6] / pow(2.0f,
					fixedpointbits);
			float y = (unsigned char) data[datastart + 1 + i * 6] / pow(2.0f,
					fixedpointbits);
			float z = (unsigned char) data[datastart + 2 + i * 6] / pow(2.0f,
					fixedpointbits);
			group->push_back(Vec3(x, y, z));
		}
		break;
	case 1: // fixed point s8
		for (int i = 0; i < datacount; i++) {
			float x = data[datastart + i * 6] / pow(2.0f, fixedpointbits);
			float y = data[datastart + 1 + i * 6] / pow(2.0f, fixedpointbits);
			float z = data[datastart + 2 + i * 6] / pow(2.0f, fixedpointbits);
			group->push_back(Vec3(x, y, z));
		}
		break;
	case 2: // fixed point u16
		for (int i = 0; i < datacount; i++) {
			float x = BigUInt16(data, datastart + i * 6) / pow(2.0f,
					fixedpointbits);
			float y = BigUInt16(data, datastart + 2 + i * 6) / pow(2.0f,
					fixedpointbits);
			float z = BigUInt16(data, datastart + 4 + i * 6) / pow(2.0f,
					fixedpointbits);
			group->push_back(Vec3(x, y, z));
		}
		break;
	case 3: // fixed point s16
		for (int i = 0; i < datacount; i++) {
			float x = BigSInt16(data, datastart + i * 6) / pow(2.0f,
					fixedpointbits);
			float y = BigSInt16(data, datastart + 2 + i * 6) / pow(2.0f,
					fixedpointbits);
			float z = BigSInt16(data, datastart + 4 + i * 6) / pow(2.0f,
					fixedpointbits);
			group->push_back(Vec3(x, y, z));
		}
		break;
	case 4: // floating point
		for (int i = 0; i < datacount; i++) {
			float x = BigFloat(data, datastart + i * 12);
			float y = BigFloat(data, datastart + 4 + i * 12);
			float z = BigFloat(data, datastart + 8 + i * 12);
			group->push_back(Vec3(x, y, z));
		}
		break;
	default:
		return false;
	}

	return true;
}

this is what does the vert conversion...
I see it uses the bounding box as coords for the verts...

maybe I should move this thread to my other thread, since that's what this is turning into :P

this code looks like it could be an easy equivilent in py...
but IDK for sure... :(
would anyone mind translating this??

I prbly could (and would) do it myself if I understood C++ and python a little more...
I'm sry if I'm putting a burden on you guys...
I hate putting my work off on other people :(

import struct

#assuming you have something like this
class Vec3Group(list):
	"""A list of Vecs"""
	
	def __init__(self, *args, **kwargs):
		super(VecGroup, self).__init__(*args, **kwargs)
		self.set = False
		
	def SetBound(self, min, max):  
		if not self.set:
			self.__min = min
			self.__max = max
			self.__set = True
			
	@property
	def BoundingMin(self):
		return self.__min
		
	@property
	def BoundingMax(self):
		return self.__max
        
class Vec3(object):
	def __init__(self, x = 0.0, y = 0.0, z = 0.0):
		self.__x = x
		self.__y = y
		self.__z = y
		
	@property
	def X(self):
		return self.__x
	
	@property
	def Y(self):
		return self.__y
		
	@property
	def Z(self):
		return self.__y


def bytes_to_float(fourbytes):
    #the ">f" might be a "<f", i'm not sure about the endianness
    #of the data
    return struct.unpack(">f",fourbytes) 
    
def sbyte_to_int(thebyte):
    return struct.unpack("b", thebyte)
    
def ushort_to_int(twobytes):
    # may be <, I'm not sure
    return struct.unpack(">H", twobytes)
    
def short_to_int(twobytes):
    # may be <, I'm not sure
    return struct.unpack(">h", twobytes)

def loadVec3Group(databytes, group):
    #where databytes is a string, group is a Vec3Group
    boundingbox = bool(int(databytes[23].encode('hex'), 16))
    datatype = ord(databytes[27])
    fixedpointbits = ord(databytes[28])
    datacount = int(databytes[30:32].encode('hex'), 16)
    #might be datacount = int(databytes[31:29:-1].encode('hex'), 16)
    datastart = 32
    if boundingbox:
        minx = bytes_to_float(databytes[32:36])
        miny = bytes_to_float(databytes[36:40])
        minz = bytes_to_float(databytes[40:44])
        maxx = bytes_to_float(databytes[44:48])
        maxy = bytes_to_float(databytes[48:52])
        maxz = bytes_to_float(databytes[52:56])
        
        group.SetBound(Vec3(minx, miny, minz), Vec3(maxx, maxy, maxz))
        
        datastart = 64
    else:
        group.SetBound(Vec3(0., 0., 0.), Vec3(0., 0., 0.))
    
    if datatype == 0: #unsigned byte
        for i in range(datacount):
            x = ord(databytes[datastart + i * 6]) / (2.0 ** fixedpointbits)
            y = ord(databytes[datastart + 1 + i*6]) / (2.0 ** fixedpointbits)
            z = ord(databytes[datastart + 2 + i*6]) / (2.0 ** fixedpointbits)
            group.append(Vec3(x,y,z))
            
    elif datatype == 1:  #signed byte
        for i in range(datacount):
            x = sbyte_to_int(databytes[datastart + i * 6]) / (2.0 ** fixedpointbits)
            y = sbyte_to_int(databytes[datastart + 1 + i*6]) / (2.0 ** fixedpointbits)
            z = sbyte_to_int(databytes[datastart + 2 + i*6]) / (2.0 ** fixedpointbits)
            group.append(Vec3(x,y,z))
    
    elif datatype == 2:  #unsigned short
        for i in range(datacount):
            x = ushort_to_int(databytes[datastart + i * 6:(datastart + i * 6) + 2]) / (2.0 ** fixedpointbits)
            y = ushort_to_int(databytes[datastart + 2 + i * 6:(datastart + 2 + i * 6) + 2]) / (2.0 ** fixedpointbits)
            z = ushort_to_int(databytes[datastart + 4 + i * 6:(datastart + 4 + i * 6) + 2]) / (2.0 ** fixedpointbits)
            
            group.append(Vec3(x,y,z))
            
    elif datatype == 3:
        for i in range(datacount):
            x = short_to_int(databytes[datastart + i * 6:(datastart + i * 6) + 2]) / (2.0 ** fixedpointbits)
            y = short_to_int(databytes[datastart + 2 + i * 6:(datastart + 2 + i * 6) + 2]) / (2.0 ** fixedpointbits)
            z = short_to_int(databytes[datastart + 4 + i * 6:(datastart + 4 + i * 6) + 2]) / (2.0 ** fixedpointbits)
            
            group.append(Vec3(x,y,z))
        
    elif datatype == 4:
        for i in range(datacount):
            x = bytes_to_float(databytes[datastart + i * 12: (datastart + i * 12) + 4])
            y = bytes_to_float(databytes[datastart + 4 + i * 12: (datastart + 4 + i * 12) + 4])
            z = bytes_to_float(databytes[datastart + 8 + i * 12: (datastart + 8 + i * 12) + 4])
    
            group.append(Vec3(x,y,z))
    else:
        return False
        
    return True

does anyone have any note on rewriting C/C++ programs in Python??
google and bing give me the exact opposite, and I've got a headache from searching...

please note that I can't read C++

if you need the program I'm rewriting, please let me know

About 18 years ago, I was peering over a guys shoulder watching him code, and I mumbled something about 'oh, that's what your doing', he turned to me and said 'C is a write only language, if you think you know what I'm doing your full of shit..', and smiled.... LOL stuck with me to this day.

Cheers..

thanx both of you... :icon_smile:

@jcao

I don't know if it makes any differance...
but I noticed you changed functions that linked to this code:

extern float BigFloat(const char* data, unsigned int offset=0);
extern uint32_t BigUInt32(const char* data, unsigned int offset=0);
extern uint16_t BigUInt16(const char* data, unsigned int offset=0);
extern int16_t BigSInt16(const char* data, unsigned int offset=0); 


float BigFloat(const char* data, unsigned int offset) {
	union {
		float f;
		unsigned char b[4];
	} dat;

	dat.b[0] = data[offset + 3];
	dat.b[1] = data[offset + 2];
	dat.b[2] = data[offset + 1];
	dat.b[3] = data[offset];
	return dat.f;
}

uint32_t BigUInt32(const char* data, unsigned int offset) {
	union {
		uint32_t u;
		unsigned char b[4];
	} dat;

	dat.b[0] = data[offset + 3];
	dat.b[1] = data[offset + 2];
	dat.b[2] = data[offset + 1];
	dat.b[3] = data[offset];
	return dat.u;
}

uint16_t BigUInt16(const char* data, unsigned int offset) {
	union {
		uint16_t u;
		unsigned char b[2];
	} dat;

	dat.b[0] = data[offset + 1];
	dat.b[1] = data[offset];
	return dat.u;
}

int16_t BigSInt16(const char* data, unsigned int offset) {
	union {
		int16_t u;
		unsigned char b[2];
	} dat;

	dat.b[0] = data[offset + 1];
	dat.b[1] = data[offset];
	return dat.u;
}

sry I forgot to add this... :/

bool MDL0File::loadVec3Group(const char* data, Vec3Group* group) {
	bool boundingbox = data[23];
	char datatype = data[27];
	char fixedpointbits = data[28];
	uint16_t datacount = BigUInt16(data, 30);

	int datastart = 32;
	if (boundingbox) {
		float minx = BigFloat(data, 32);
		float miny = BigFloat(data, 36);
		float minz = BigFloat(data, 40);
		float maxx = BigFloat(data, 44);
		float maxy = BigFloat(data, 48);
		float maxz = BigFloat(data, 52);

		group->SetBound(Vec3(minx, miny, minz), Vec3(maxx, maxy, maxz));

		datastart = 64;
	} else {
		group->SetBound(Vec3(0, 0, 0), Vec3(0, 0, 0));
	}

	switch (datatype) {
	case 0: // fixed point u8
		for (int i = 0; i < datacount; i++) {
			float x = (unsigned char) data[datastart + i * 6] / pow(2.0f,
					fixedpointbits);
			float y = (unsigned char) data[datastart + 1 + i * 6] / pow(2.0f,
					fixedpointbits);
			float z = (unsigned char) data[datastart + 2 + i * 6] / pow(2.0f,
					fixedpointbits);
			group->push_back(Vec3(x, y, z));
		}
		break;
	case 1: // fixed point s8
		for (int i = 0; i < datacount; i++) {
			float x = data[datastart + i * 6] / pow(2.0f, fixedpointbits);
			float y = data[datastart + 1 + i * 6] / pow(2.0f, fixedpointbits);
			float z = data[datastart + 2 + i * 6] / pow(2.0f, fixedpointbits);
			group->push_back(Vec3(x, y, z));
		}
		break;
	case 2: // fixed point u16
		for (int i = 0; i < datacount; i++) {
			float x = BigUInt16(data, datastart + i * 6) / pow(2.0f,
					fixedpointbits);
			float y = BigUInt16(data, datastart + 2 + i * 6) / pow(2.0f,
					fixedpointbits);
			float z = BigUInt16(data, datastart + 4 + i * 6) / pow(2.0f,
					fixedpointbits);
			group->push_back(Vec3(x, y, z));
		}
		break;
	case 3: // fixed point s16
		for (int i = 0; i < datacount; i++) {
			float x = BigSInt16(data, datastart + i * 6) / pow(2.0f,
					fixedpointbits);
			float y = BigSInt16(data, datastart + 2 + i * 6) / pow(2.0f,
					fixedpointbits);
			float z = BigSInt16(data, datastart + 4 + i * 6) / pow(2.0f,
					fixedpointbits);
			group->push_back(Vec3(x, y, z));
		}
		break;
	case 4: // floating point
		for (int i = 0; i < datacount; i++) {
			float x = BigFloat(data, datastart + i * 12);
			float y = BigFloat(data, datastart + 4 + i * 12);
			float z = BigFloat(data, datastart + 8 + i * 12);
			group->push_back(Vec3(x, y, z));
		}
		break;
	default:
		return false;
	}

	return true;
}

BigFloat is a function... now that I showed it <_<
look back to this post for more referances:
http://www.daniweb.com/forums/post1296716.html#post1296716
I don't think there's anymore though... :icon_smile:

and now seeing that...
do you need to make any changes??

btw...
I don't use struct anymore... :icon_lol:

thanx both of you... :icon_smile:

@jcao

I don't know if it makes any differance...
but I noticed you changed functions that linked to this code:

extern float BigFloat(const char* data, unsigned int offset=0);
extern uint32_t BigUInt32(const char* data, unsigned int offset=0);
extern uint16_t BigUInt16(const char* data, unsigned int offset=0);
extern int16_t BigSInt16(const char* data, unsigned int offset=0); 


float BigFloat(const char* data, unsigned int offset) {
	union {
		float f;
		unsigned char b[4];
	} dat;

	dat.b[0] = data[offset + 3];
	dat.b[1] = data[offset + 2];
	dat.b[2] = data[offset + 1];
	dat.b[3] = data[offset];
	return dat.f;
}

uint32_t BigUInt32(const char* data, unsigned int offset) {
	union {
		uint32_t u;
		unsigned char b[4];
	} dat;

	dat.b[0] = data[offset + 3];
	dat.b[1] = data[offset + 2];
	dat.b[2] = data[offset + 1];
	dat.b[3] = data[offset];
	return dat.u;
}

uint16_t BigUInt16(const char* data, unsigned int offset) {
	union {
		uint16_t u;
		unsigned char b[2];
	} dat;

	dat.b[0] = data[offset + 1];
	dat.b[1] = data[offset];
	return dat.u;
}

int16_t BigSInt16(const char* data, unsigned int offset) {
	union {
		int16_t u;
		unsigned char b[2];
	} dat;

	dat.b[0] = data[offset + 1];
	dat.b[1] = data[offset];
	return dat.u;
}

sry I forgot to add this... :/

bool MDL0File::loadVec3Group(const char* data, Vec3Group* group) {
	bool boundingbox = data[23];
	char datatype = data[27];
	char fixedpointbits = data[28];
	uint16_t datacount = BigUInt16(data, 30);

	int datastart = 32;
	if (boundingbox) {
		float minx = BigFloat(data, 32);
		float miny = BigFloat(data, 36);
		float minz = BigFloat(data, 40);
		float maxx = BigFloat(data, 44);
		float maxy = BigFloat(data, 48);
		float maxz = BigFloat(data, 52);

		group->SetBound(Vec3(minx, miny, minz), Vec3(maxx, maxy, maxz));

		datastart = 64;
	} else {
		group->SetBound(Vec3(0, 0, 0), Vec3(0, 0, 0));
	}

	switch (datatype) {
	case 0: // fixed point u8
		for (int i = 0; i < datacount; i++) {
			float x = (unsigned char) data[datastart + i * 6] / pow(2.0f,
					fixedpointbits);
			float y = (unsigned char) data[datastart + 1 + i * 6] / pow(2.0f,
					fixedpointbits);
			float z = (unsigned char) data[datastart + 2 + i * 6] / pow(2.0f,
					fixedpointbits);
			group->push_back(Vec3(x, y, z));
		}
		break;
	case 1: // fixed point s8
		for (int i = 0; i < datacount; i++) {
			float x = data[datastart + i * 6] / pow(2.0f, fixedpointbits);
			float y = data[datastart + 1 + i * 6] / pow(2.0f, fixedpointbits);
			float z = data[datastart + 2 + i * 6] / pow(2.0f, fixedpointbits);
			group->push_back(Vec3(x, y, z));
		}
		break;
	case 2: // fixed point u16
		for (int i = 0; i < datacount; i++) {
			float x = BigUInt16(data, datastart + i * 6) / pow(2.0f,
					fixedpointbits);
			float y = BigUInt16(data, datastart + 2 + i * 6) / pow(2.0f,
					fixedpointbits);
			float z = BigUInt16(data, datastart + 4 + i * 6) / pow(2.0f,
					fixedpointbits);
			group->push_back(Vec3(x, y, z));
		}
		break;
	case 3: // fixed point s16
		for (int i = 0; i < datacount; i++) {
			float x = BigSInt16(data, datastart + i * 6) / pow(2.0f,
					fixedpointbits);
			float y = BigSInt16(data, datastart + 2 + i * 6) / pow(2.0f,
					fixedpointbits);
			float z = BigSInt16(data, datastart + 4 + i * 6) / pow(2.0f,
					fixedpointbits);
			group->push_back(Vec3(x, y, z));
		}
		break;
	case 4: // floating point
		for (int i = 0; i < datacount; i++) {
			float x = BigFloat(data, datastart + i * 12);
			float y = BigFloat(data, datastart + 4 + i * 12);
			float z = BigFloat(data, datastart + 8 + i * 12);
			group->push_back(Vec3(x, y, z));
		}
		break;
	default:
		return false;
	}

	return true;
}

BigFloat is a function... now that I showed it <_<
look back to this post for more referances:
http://www.daniweb.com/forums/post1296716.html#post1296716
I don't think there's anymore though... :icon_smile:

and now seeing that...
do you need to make any changes??

btw...
I don't use struct anymore... :icon_lol:

Oh I've seen those already

Oh I've seen those already

so was changing those functions neccesary??
or could you have kept those functions??

or do your new functions do the same thing as the old functions??

so was changing those functions neccesary??
or could you have kept those functions??

or do your new functions do the same thing as the old functions??

Do you mean the old C++ functions?
The ones I wrote in Python should do about the same thing.

KK thanx :)

I'll come back for more code when I need it :)
thanx again

KK thanx :)

I'll come back for more code when I need it :)
thanx again

Try to correct any mistakes I could have made there.
The ">" for the struct unpacking could be changed to "<", I'm not sure about the endianness of the data.

can I ask a favor??

can you add any method I don't have listed??
this is just a simple byte calculator (8,16, and 32 bit)

import struct as S
import binascii as B
a = 1
while a:
    char = B.unhexlify(''.join(input().split()))
    if (len(char)==1):
        print '  b: ' + str(S.unpack("b", char)[0])
        print 'dec: ' + str(int(char.encode('hex'),16))
        print''
        
    if (len(char)==2):
        print ' >h: ' + str(S.unpack(">h", char)[0])
        print ' <h: ' + str(S.unpack("<h", char)[0])
        print''
        
    if (len(char)==4):
        print ' >l: ' + str(S.unpack(">l", char)[0])
        print ' <l: ' + str(S.unpack("<l", char)[0])
        print ' >f: ' + str(S.unpack(">f", char)[0])
        print ' <f: ' + str(S.unpack("<f", char)[0])
        print ''

(just add, don't delete anything)

you can add 64 bit if you want :P
I just want to know what I'm missing...
and I'm not sure of how to name them...

my hurr durr moment{

differance between:
short and long
signed and unsigned
big and little endian

}

alright...
major help needed...

this is prbly very simple to do...

void MDL0File::Unload() {}

PolyGroup* MDL0File::GetPolygonGroup(int id) {
	if (id < polyGroupCount)
		return &polyGroups[id];
	else
		return NULL;
}

int MDL0File::PolygonGroupCount() {
	return polyGroupCount;
}

Vec3Group* MDL0File::GetVertexGroup(int id) {
	if (id < vertexGroupCount)
		return &vertexGroups[id];
	else
		return NULL;
}

int MDL0File::VertexGroupCount() {
	return vertexGroupCount;
}

RGBAGroup* MDL0File::GetColorGroup(int id) {
	if (id < colorGroupCount)
		return &colorGroups[id];
	else
		return NULL;
}

int MDL0File::ColorGroupCount() {
	return colorGroupCount;
}

Vec3Group* MDL0File::GetNormalGroup(int id) {
	if (id < normalGroupCount)
		return &normalGroups[id];
	else
		return NULL;
}

int MDL0File::NormalGroupCount() {
	return normalGroupCount;
}

Vec2Group* MDL0File::GetUVGroup(int id) {
	if (id < uvGroupCount)
		return &uvGroups[id];
	else
		return NULL;
}

int MDL0File::UVGroupCount() {
	return uvGroupCount;
}

bool MDL0File::loadGroup(const char* data, int type) {
	uint32_t itemcount = BigUInt32(data, 4);

	switch (type) {
	case 0: // unknown
		break;
	case 1: // probably bones, don't know how to load yet
		break;
	case 2: // vertices
		vertexGroups = new Vec3Group[itemcount];
		vertexGroupCount = itemcount;
		break;
	case 3: // normals
		normalGroups = new Vec3Group[itemcount];
		normalGroupCount = itemcount;
		break;
	case 4: // colors
		colorGroups = new RGBAGroup[itemcount];
		colorGroupCount = itemcount;
		break;
	case 5: // uv coordinates
		uvGroups = new Vec2Group[itemcount];
		uvGroupCount = itemcount;
		break;
	case 6: // unknown
		break;
	case 7: // unknown
		break;
	case 8: // polygon groups
		polyGroups = new PolyGroup[itemcount];
		polyGroupCount = itemcount;
		break;
	case 9: // unknown
		break;
	case 10: // unknown
		break;
	}

	for (uint i = 0; i < itemcount; i++) {
		uint32_t dataoffset = BigUInt32(data, 36 + 16 * i);

		switch (type) {
		case 0: // unknown
			break;
		case 1: // probably bones, don't know how to load yet
			break;
		case 2: // vertices
			if (!loadVec3Group(data + dataoffset, &vertexGroups[i]))
				return false;
			break;
		case 3: // normals
			if (!loadVec3Group(data + dataoffset, &normalGroups[i]))
				return false;
			break;
		case 4: // colors
			if (!loadRGBAGroup(data + dataoffset, &colorGroups[i]))
				return false;
			break;
		case 5: // uv coordinates
			if (!loadVec2Group(data + dataoffset, &uvGroups[i]))
				return false;
			break;
		case 6: // unknown
			break;
		case 7: // unknown
			break;
		case 8: // polygon groups
			if (!loadPolyGroup(data + dataoffset, &polyGroups[i]))
				return false;
			break;
		case 9: // unknown
			break;
		case 10: // unknown
			break;
		}
	}

	return true;
}

I know I shouldn't by now...
but I still feel like I'm shoving my work on you guys...
and I'm sry if anyone takes it as that :icon_sad:

but this will help me to get my last successful attempt imported strait from the mdl0
the last attempt at importing the verts is complete so far...
(I've got beta testers trying out vert exports from different mdl0 files)

but now I want to stop the vert export part and just go strait to the mdl0
(see if I can't import the vert offsets from there)

hey...
I could really use some help on this guys <:/

Sorry, I have been so busy that I haven't been on Daniweb in a week or two. Maybe when school settles down a little I'll look it this again.

What you want Tcll, the conversion of the case?

How are you reading the values?

Cheers and Happy coding

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.