Sign in to follow this  
xg0blin

MS3D Loading Problem

Recommended Posts

This is really confusing me. I've looked at other peoples code (theirs works) and we are doing basically the same thing, and mine works, for the most part anyways. The loader reads the vertices correctly, up until it gets to the 47th vertex, at which point it messes up z, then from there after the whole thing is screwed. Here is the part of my code where everything is messing up:
void MS3DModel::LoadMS3D(string FileName)
{
	ifstream Fin;
	Fin.open(FileName.c_str(), ios::in||ios::binary);
	if(Fin.is_open() && Fout.is_open())
	{
			HeaderMS3D MS3DHeader;

			Fin.read((char *)&MS3DHeader, sizeof(HeaderMS3D));
			Fin.read((char *)&NumVertices, sizeof(ushort));
			Vertices = new VertexMS3D[NumVertices];
	                for(int i = 0; i < NumVertices; i++)
		                Fin.read((char *)&Vertices[i], sizeof(VertexMS3D));

It reads the header, it reads the numvertices correctly, and then it reads the first 47 vertices correctly (I've used a loader that works and verifed that that is where mine is screwing it up). I don't understand how this can be. If it loads the first set of 15 bytes (the size of VertexMS3D) correctly, why not the rest? What in the hell is going on?

Share this post


Link to post
Share on other sites
You have to pack the structures into a byte boundary, its a common gotcha, add this to your code before your structure definition:


#ifdef _MSC_VER
# pragma pack( push, packing )
# pragma pack( 1 )
# define PACK_STRUCT
#elif defined( __GNUC__ )
# define PACK_STRUCT __attribute__((packed))
#else
# error you must byte-align these structures with the appropriate compiler directives
#endif


and then define your structures as (these asume you're using SDL, change UintX variables appropiatelly if you're using DX):

typedef struct PACK_STRUCT
{
char id[10]; // always "MS3D000000"
int version; // 4
} ms3d_header_t;

typedef struct PACK_STRUCT
{
Uint8 flags;// SELECTED | SELECTED2 | HIDDEN
float vertex[3];
char boneId; // -1 = no bone
Uint8 referenceCount;
} ms3d_vertex_t;
//
// nNumTriangles * sizeof (ms3d_triangle_t)
//
typedef struct PACK_STRUCT
{
Uint16 flags; // SELECTED | SELECTED2 | HIDDEN
Uint16 vertexIndices[3];
float vertexNormals[3][3];
float s[3];
float t[3];
Uint8 smoothingGroup; // 1 - 32
Uint8 groupIndex;
} ms3d_triangle_t;


//
// nNumGroups * sizeof (ms3d_group_t)
//
typedef struct PACK_STRUCT
{
Uint8 flags; // SELECTED | HIDDEN
char name[32];
Uint16 numtriangles;
Uint16 *triangleIndices;//[numtriangles];// the groups group the triangles
char materialIndex; // -1 = no material
} ms3d_group_t;


//
// nNumMaterials * sizeof (ms3d_material_t)
//
typedef struct PACK_STRUCT
{
char name[32]; //
float ambient[4]; //
float diffuse[4]; //
float specular[4]; //
float emissive[4]; //
float shininess; // 0.0f - 128.0f
float transparency; // 0.0f - 1.0f
char mode; // 0, 1, 2 is unused now
char texture[128]; // texture.bmp
char alphamap[128]; // alpha.bmp
} ms3d_material_t;



//
// nNumJoints * sizeof (ms3d_joint_t)
//
//
typedef struct PACK_STRUCT
{
float time; // time in seconds
float rotation[3]; // x, y, z angles
} ms3d_keyframe_rot_t;

typedef struct PACK_STRUCT
{
float time; // time in seconds
float position[3]; // local position
} ms3d_keyframe_pos_t;

typedef struct PACK_STRUCT
{
Uint8 flags;// SELECTED | DIRTY
char name[32];
char parentName[32];

float rotation[3];// local reference matrix
float position[3];
Uint16 numKeyFramesRot;
Uint16 numKeyFramesTrans;
// local animation matrices
ms3d_keyframe_rot_t *keyFramesRot;//[numKeyFramesRot];
// local animation matrices
ms3d_keyframe_pos_t *keyFramesTrans;//[numKeyFramesTrans];
} ms3d_joint_t;




That will work for VC++ and GCC

Share this post


Link to post
Share on other sites
No, I've done that. Like I said, it reads the Header just fine, then the number of vertices, then the first 46.66 vertex structures correctly. Then from that point on it gives me the same number no matter how long it keeps reading.

EDIT: Here, I made an output file, I'll post it here:


MS3DHeader.ID: MS3D000000
MS3DHeader.Version: 4
NumVertices: 1302

Vertices List
---------------------------------------------------------------------
Vertex 0
Flags: 0
Vertices: -34.0001 14.7175 1.52404
BoneID: -1
ReferenceID 8

Vertex 1
Flags: 0
Vertices: -33.6294 14.8621 1.24768
BoneID: -1
ReferenceID 4

Vertex 2
Flags: 0
Vertices: -34.1047 14.7702 1.21844
BoneID: -1
ReferenceID 5

Vertex 3
Flags: 0
Vertices: -32.8446 14.7657 -0.292704
BoneID: -1
ReferenceID 7

Vertex 4
Flags: 0
Vertices: -30.4681 14.3379 -0.358059
BoneID: -1
ReferenceID 6

Vertex 5
Flags: 0
Vertices: -32.7709 14.6641 -0.870893
BoneID: -1
ReferenceID 6

Vertex 6
Flags: 0
Vertices: -33.0026 13.8615 -1.42998
BoneID: -1
ReferenceID 9

Vertex 7
Flags: 0
Vertices: -31.1441 13.6979 -1.30295
BoneID: -1
ReferenceID 7

Vertex 8
Flags: 0
Vertices: -30.9061 12.8341 -1.27772
BoneID: -1
ReferenceID 4

Vertex 9
Flags: 0
Vertices: -31.1572 14.2926 -1.00094
BoneID: -1
ReferenceID 2

Vertex 10
Flags: 0
Vertices: -29.1747 14.3218 -0.884574
BoneID: -1
ReferenceID 2

Vertex 11
Flags: 0
Vertices: -31.5003 13.7036 1.98778
BoneID: -1
ReferenceID 4

Vertex 12
Flags: 0
Vertices: -33.2353 14.5791 1.70136
BoneID: -1
ReferenceID 7

Vertex 13
Flags: 0
Vertices: -32.5797 13.503 1.81474
BoneID: -1
ReferenceID 4

Vertex 14
Flags: 0
Vertices: -29.1555 13.016 -0.834617
BoneID: -1
ReferenceID 5

Vertex 15
Flags: 0
Vertices: -30.1952 12.8007 1.42691
BoneID: -1
ReferenceID 6

Vertex 16
Flags: 0
Vertices: -31.0301 12.826 -0.112222
BoneID: -1
ReferenceID 6

Vertex 17
Flags: 0
Vertices: -33.8708 14.4715 1.70389
BoneID: -1
ReferenceID 5

Vertex 18
Flags: 0
Vertices: -33.6024 14.5344 -1.30255
BoneID: -1
ReferenceID 4

Vertex 19
Flags: 0
Vertices: -33.5597 14.3928 -1.40545
BoneID: -1
ReferenceID 4

Vertex 20
Flags: 0
Vertices: -34.3526 13.2877 -1.30255
BoneID: -1
ReferenceID 7

Vertex 21
Flags: 0
Vertices: -33.6618 12.1172 -1.11471
BoneID: -1
ReferenceID 1

Vertex 22
Flags: 0
Vertices: -33.739 12.1999 -1.1661
BoneID: -1
ReferenceID 2

Vertex 23
Flags: 0
Vertices: -33.6369 12.5736 -1.12485
BoneID: -1
ReferenceID 4

Vertex 24
Flags: 0
Vertices: -30.6325 14.3931 0.670446
BoneID: -1
ReferenceID 6

Vertex 25
Flags: 0
Vertices: -32.9677 14.8038 0.492123
BoneID: -1
ReferenceID 7

Vertex 26
Flags: 0
Vertices: -33.6383 14.9543 0.398585
BoneID: -1
ReferenceID 5

Vertex 27
Flags: 0
Vertices: -33.9265 14.7961 0.736951
BoneID: -1
ReferenceID 5

Vertex 28
Flags: 0
Vertices: -33.851 14.7192 0.895779
BoneID: -1
ReferenceID 8

Vertex 29
Flags: 0
Vertices: -33.5597 14.3928 -1.40545
BoneID: -1
ReferenceID 2

Vertex 30
Flags: 0
Vertices: -32.3767 14.3632 -1.41819
BoneID: -1
ReferenceID 3

Vertex 31
Flags: 0
Vertices: -33.269 14.1266 -1.49379
BoneID: -1
ReferenceID 6

Vertex 32
Flags: 0
Vertices: -34.2928 12.3452 -0.168718
BoneID: -1
ReferenceID 6

Vertex 33
Flags: 0
Vertices: -34.6494 13.474 -0.201892
BoneID: -1
ReferenceID 5

Vertex 34
Flags: 0
Vertices: -34.6844 13.4545 -0.548705
BoneID: -1
ReferenceID 6

Vertex 35
Flags: 0
Vertices: -34.1057 12.6303 2.0338
BoneID: -1
ReferenceID 5

Vertex 36
Flags: 0
Vertices: -33.685 12.4995 1.58147
BoneID: -1
ReferenceID 2

Vertex 37
Flags: 0
Vertices: -34.0046 12.119 1.82141
BoneID: -1
ReferenceID 1

Vertex 38
Flags: 0
Vertices: -34.1702 13.2205 -1.35758
BoneID: -1
ReferenceID 4

Vertex 39
Flags: 0
Vertices: -33.8574 13.18 -1.35281
BoneID: -1
ReferenceID 7

Vertex 40
Flags: 0
Vertices: -30.8835 12.5815 1.87066
BoneID: -1
ReferenceID 5

Vertex 41
Flags: 0
Vertices: -31.5054 12.2179 2.08457
BoneID: -1
ReferenceID 5

Vertex 42
Flags: 0
Vertices: -31.512 12.7207 1.07224
BoneID: -1
ReferenceID 3

Vertex 43
Flags: 0
Vertices: -33.3185 14.1841 1.70707
BoneID: -1
ReferenceID 5

Vertex 44
Flags: 0
Vertices: -33.3245 14.0567 0.828054
BoneID: -1
ReferenceID 8

Vertex 45
Flags: 0
Vertices: -33.7563 12.5177 -1.15696
BoneID: -1
ReferenceID 7

Vertex 46
Flags: 0
Vertices: -33.9564 12.3112 -1.19828
BoneID: -1
ReferenceID 3

Vertex 47
Flags: 0
Vertices: -31.6282 13.1414 -4.30075e+008
BoneID: -51
ReferenceID 205

Vertex 48
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 49
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 50
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 51
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 52
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 53
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 54
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 55
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 56
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 57
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 58
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 59
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 60
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 61
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 62
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 63
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 64
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 65
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 66
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 67
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 68
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 69
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 70
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 71
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 72
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 73
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 74
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 75
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 76
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 77
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 78
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 79
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 80
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 81
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 82
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 83
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 84
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 85
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 86
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 87
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 88
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 89
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 90
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 91
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 92
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 93
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 94
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 95
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 96
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 97
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 98
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 99
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205

Vertex 100
Flags: 205
Vertices: -4.31602e+008 -4.31602e+008 -4.31602e+008
BoneID: -51
ReferenceID 205
...
So on and so forth




Here are my structure declarations, maybe I did something wrong? I just can't seem to find anything.

# pragma pack( push, packing )
# pragma pack( 1 )
#define PACK_STRUCT

typedef unsigned char byte;
typedef unsigned short ushort;
typedef unsigned long ulong;

struct HeaderMS3D
{
char ID[10];
int Version;
} PACK_STRUCT;

struct VertexMS3D
{
byte Flags;
float Vertex[3];
char BoneID;
byte ReferenceCount;
} PACK_STRUCT;

struct TriangleMS3D
{
ushort Flags;
ushort VertexIndex[3];
float Normals[3][3];
float S[3];
float T[3];
byte SmoothingGroup;
byte GroupIndex;
} PACK_STRUCT;

struct GroupMS3D
{
byte Flags;
char Name[32];
ushort NumTriangles;
ushort *TriangleIndicies;
char MaterialIndex;
} PACK_STRUCT;

struct MaterialMS3D
{
char Name[32];
float Ambient[4];
float Diffuse[4];
float Specular[4];
float Emissive[4];
float Shininess;
float Transparency;
char Mode;
char Texture[128];
char AlphaMap[128];
} PACK_STRUCT;

struct RotationMS3D
{
float Time;
float Rotation[3];
} PACK_STRUCT;

struct PositionMS3D
{
float Time;
float Position[3];
} PACK_STRUCT;

struct JointMS3D
{
byte Flags;
char Name[32];
char ParentName[32];
float Rotation[3];
float Position[3];
short NumKeyFramesRot;
short NumKeyFramesTrans;
RotationMS3D *KeyFramesRot;
PositionMS3D *KeyFramesTrans;
} PACK_STRUCT;

#pragma pack( pop, packing )
#undef PACK_STRUCT



I can't find anything. This really sucks.

[Edited by - xg0blin on September 3, 2004 8:18:21 PM]

Share this post


Link to post
Share on other sites
I put an

if(Fin.fail()) return;

inside of my for loop that reads the vertices. It fails at vertex 47. WTF? What would cause it to fail?

I used the terrain generator and made another model. It makes it through all of the vertices, and then the fail bit is set and it exits when reading the triangles. This is really freaking weird.

Share this post


Link to post
Share on other sites
Sweet jesus, I found it. What's wrong with this line:

Fin.open(FileName.c_str(), ios::in||ios::binary);

Yeah, that was hard to find. I put || instead of |, and it was trying to read anyways. How very odd.

Share this post


Link to post
Share on other sites
Quote:
Original post by xg0blin
Sweet jesus, I found it. What's wrong with this line:

Fin.open(FileName.c_str(), ios::in||ios::binary);

Yeah, that was hard to find. I put || instead of |, and it was trying to read anyways. How very odd.

A non-zero value logical-ORed with anything evaluates to 1, so "ios::in || ios::binary" = 1. I checked ios.h and ios::in = 1, so what your code did was open the file for reading (as it should) but in text mode. Since it is a text file, I can tell you right now that you have not solved the bug.

Look at the file. The 47th vertex is the first one that uses scientific notation.
Quote:
Vertices: -31.6282 13.1414 -4.30075e+008

You are not reading such values correctly.

Share this post


Link to post
Share on other sites
Quote:
A non-zero value logical-ORed with anything evaluates to 1, so "ios::in || ios::binary" = 1. I checked ios.h and ios::in = 1, so what your code did was open the file for reading (as it should) but in text mode. Since it is a text file, I can tell you right now that you have not solved the bug.


It fixed the bug. MS3D is a binary format. MS3DAscii is ascii. I knew better than to do that, I just didn't see it and I type || all the time so I didn't think anything about it.

My problem now though it the texture coordinates (if you know something about the way ms3d stores those). The model is loaded correctly, the textures are just all wrong, and I don't know why. In the debugger, they're negative. Weird.

Share this post


Link to post
Share on other sites
Oh, OK. I thought your vertex list was an excerpt from the model file... nevermind.

As for the texture data, I don't know about MS3D, but I know some model formats list only unique vertex positions. For example, a cube has 8 vertices, right? Actually, no... not necessarily. You might have a corner with the texture coordinate (0,1) for one face, and (1,0) for another face that shares that vertex. So you'd actually create at least two vertices there... if you don't catch that, then the end result would be a model with messed up texture coordinates. So for all I know, that could be what's happening.

Share this post


Link to post
Share on other sites
Here is the code I have for the drawing (I haven't added materials yet, I want to get textures first, and it's using the wrong textures on the wrong body parts). This code is simple enough to understand. The textures are attached to the wrong groups, and I can't figure out why. The code is pretty easy to follow. It's binding the wrong texture. I checked it in the debugger, and it acts as if it's using the right texture. I dunno. I've written other model loaders, but this is my first crack at MS3D. Thanks for the help anyways, everyone that has helped.


void MS3DModel::DisplayModel()
{
for(int i = 0; i < NumGroups; i++)
{
for(int j = 0; j < Groups[i].NumTriangles; j++)
{
int Index = Groups[i].TriangleIndicies[j];

glBindTexture(GL_TEXTURE_2D, Groups[i].MaterialIndex);
glBegin(GL_TRIANGLES);
glNormal3fv(Triangles[Index].Normals[0]);
glTexCoord2f(Triangles[Index].S[0], Triangles[Index].T[0]);
glVertex3fv(Vertices[Triangles[Index].VertexIndex[0]].Vertex);

glNormal3fv(Triangles[j].Normals[1]);
glTexCoord2f(Triangles[Index].S[1], Triangles[Index].T[1]);
glVertex3fv(Vertices[Triangles[Index].VertexIndex[1]].Vertex);

glNormal3fv(Triangles[Index].Normals[2]);
glTexCoord2f(Triangles[Index].S[2], Triangles[Index].T[2]);
glVertex3fv(Vertices[Triangles[Index].VertexIndex[2]].Vertex);
glEnd();
}
}
}

Share this post


Link to post
Share on other sites
I load the materials in with ifsteam of course (I'll post that too if you like, but it reads it right, I've checked the texture names and everything in the debugger).

Here is what I use to load my textures for the model.

void MS3DModel::LoadTextures(void)
{
for(int i = 0; i < NumMaterials; i++)
{
string Temp = "./Data/Models/MS3D/";
Temp += &Materials[i].Texture[2];
XGTexManager.LoadImage(Temp);
}
}



Anyways, I store my textures for my ms3d models in ./Data/Models/MS3D/. It has two extra characters on the beginning of Materials[i].Texture[whatever]. It has like .\Hand.bmp. I just remove those and append them to the path of where I store the textures (so I get like "./Data/Models/MS3D/Hand.bmp". I then use my TextureManager to load the images. They all load successfully. The LoadImage function actually returns an unsigned int, telling you what the ID is of the texture you've loaded, but since these are the only images I'm loading, it'll be the same number as the material index (and it is, I checked it and will fix it to work properly once I get the basics working). Thanks for your help guys, I'll take the time to rate you accordingly.

Share this post


Link to post
Share on other sites
What I meant was the code that associated the textures with the OpenGL texture identifier. This sort of thing:

glGenTextures( 1, &GLTexture );
glBindTexture( GL_TEXTURE_2D, GLTexture );

gluBuild2DMipmaps( GL_TEXTURE_2D,
3,
Picture->Width,
Picture->Height,
GL_RGB,
GL_UNSIGNED_BYTE,
Picture->RGB );


Then to draw using that texture, you bind GLTexture. If your model still doesn't display using the correct textures then it's possible your loading code (i.e. what I just posted of mine) is somehow wrong.

Share this post


Link to post
Share on other sites
I doubt it. My loading code has been tested seperately and pretty extensively with bitmap images. I made something like 400 different images of different widths, heights and depths and tested them out. That part works fine, and I'm pretty certain of it. The images are all loaded, it's just that like the jean texture is getting applied to the head, and stuff like that.

Share this post


Link to post
Share on other sites
Well, I guess just to be certain, it won't hurt too much to do a code dump. I've probably missed something somewhere that you might catch and I didn't, and I don't care if people use my code, so OK.

EDIT: *Removed the annoying code dump*

[Edited by - xg0blin on September 5, 2004 10:25:05 AM]

Share this post


Link to post
Share on other sites
I read in some tutorial that the texture coordinates MS3D uses are initially with their origin at the upper-left, and (1, 1) being at the lower right. Fine, so subtract 1 from every t. I looked at them in my debugger, and initially, they are negative values (before I do the subtraction)??? WTF?? So if I do 1.0 - Triangles[i].T[0] or whatever, I get a number that is always larger than 1. THis can't possibly be right. I've looked at my structs, and they are all fine, but there is no way these texture coordinates can be right. First, why would having an origin in the upper right make them negative (unless they go from 0 to -1, or something weird like that)? Second, why would I get texture values that are still above 2.0? Argh. The coordinates plainly are incorrect, and I don't see why.

EDIT: Holy crap, you were right CGameProgrammer, that is where the problem was, but it was something I wouldn't have guessed. I set glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP) to GL_REPEAT, and it worked. That is so freaking weird. Why would we need to wrap the coordinates? Blah.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this