• Advertisement

Archived

This topic is now archived and is closed to further replies.

3ds color chunks

This topic is 5488 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How 3ds stores vertex ambient, diffuse and specualar component of the color of the material. I know that chunks: 0xa010(ambient),0xa020(diffuse) and 0xa030(specular). Does it store information only in one byte? Or in two bytes?

Share this post


Link to post
Share on other sites
Advertisement
I don''t remember, but this chunk include standart color chunks:
#define COL_RGB 0x0010
#define COL_TRU 0x0011
#define COL_TRUG 0x0012
#define COL_RGBG 0x0013
.....
/*----------------------------------------------------------------------------*/
void Model_3DS::ReadMatAmbientChunk(long length, long findex)
{
ChunkHeader h;

// move the file pointer to the beginning of the main
// chunk''s data findex + the size of the header
fseek(bin3ds, findex, SEEK_SET);

while (ftell(bin3ds) < (findex + length - 6))
{
fread(&h.id,sizeof(h.id),1,bin3ds);
fread(&h.len,sizeof(h.len),1,bin3ds);

// Determine the format of the color and load it
switch (h.id)
{
case COL_RGB :
// A rgb float color chunk
//FloatColorChunkProcessor(h.len, ftell(bin3ds), matindex);
logfile(" Found a rgb float color chunk\n");
ReadMRGBColor(ftell(bin3ds));
break;
case COL_TRU :
// A rgb int color chunk
//IntColorChunkProcessor(h.len, ftell(bin3ds), matindex);
logfile(" Found a rgb int color chunk\n");
ReadMTrueColor(ftell(bin3ds));
break;
case COL_RGBG :
// A rgb gamma corrected float color chunk
//FloatColorChunkProcessor(h.len, ftell(bin3ds), matindex);
logfile(" Found a rgb gamma corrected float color chunk\n");
ReadMRGBColor(ftell(bin3ds));
break;
case COL_TRUG :
// A rgb gamma corrected int color chunk
//IntColorChunkProcessor(h.len, ftell(bin3ds), matindex);
logfile(" Found a rgb gamma corrected int color chunk\n");
ReadMTrueColor(ftell(bin3ds));
break;
default :
break;
}

fseek(bin3ds, (h.len - 6), SEEK_CUR);
}

// move the file pointer back to where we got it so
// that the ProcessChunk() which we interrupted will read
// from the right place
fseek(bin3ds, findex, SEEK_SET);
}
.....
void Model_3DS::ReadRGBColor(long findex)
{
float r;
float g;
float b;

// move the file pointer to the beginning of the main
// chunk''s data findex + the size of the header
fseek(bin3ds, findex, SEEK_SET);

fread(&r,sizeof(r),1,bin3ds);
fread(&g,sizeof(g),1,bin3ds);
fread(&b,sizeof(b),1,bin3ds);

#ifdef __DEBUG__
logfile(" Found Color (RGB) def of: R:%5.2f,G:%5.2f,B:%5.2f\n",
r,
g,
b);
#endif

LightObjects[numLightObjects-1].color.r = (unsigned char)(r*255.0f);
LightObjects[numLightObjects-1].color.g = (unsigned char)(r*255.0f);
LightObjects[numLightObjects-1].color.b = (unsigned char)(r*255.0f);
LightObjects[numLightObjects-1].color.a = 255;


// move the file pointer back to where we got it so
// that the ProcessChunk() which we interrupted will read
// from the right place
fseek(bin3ds, findex, SEEK_SET);
}
/*----------------------------------------------------------------------------*/
void Model_3DS::ReadMRGBColor(long findex) // it the sameone(like rgb color) but for material
{
float r;
float g;
float b;

// move the file pointer to the beginning of the main
// chunk''s data findex + the size of the header
fseek(bin3ds, findex, SEEK_SET);

fread(&r,sizeof(r),1,bin3ds);
fread(&g,sizeof(g),1,bin3ds);
fread(&b,sizeof(b),1,bin3ds);

#ifdef __DEBUG__
logfile(" Found Color (24bit) def of: R:%d,G:%d,B:%d\n",
r,
g,
b);
#endif

Materials[numMaterials-1].color.r = (unsigned char)(r*255.0f);
Materials[numMaterials-1].color.g = (unsigned char)(r*255.0f);
Materials[numMaterials-1].color.b = (unsigned char)(r*255.0f);
Materials[numMaterials-1].color.a = 255;

// move the file pointer back to where we got it so
// that the ProcessChunk() which we interrupted will read
// from the right place
fseek(bin3ds, findex, SEEK_SET);
}
/*----------------------------------------------------------------------------*/
void Model_3DS::ReadTrueColor(long findex)
{
unsigned char r;
unsigned char g;
unsigned char b;

// move the file pointer to the beginning of the main
// chunk''s data findex + the size of the header
fseek(bin3ds, findex, SEEK_SET);

fread(&r,sizeof(r),1,bin3ds);
fread(&g,sizeof(g),1,bin3ds);
fread(&b,sizeof(b),1,bin3ds);

#ifdef __DEBUG__
logfile(" Found Color (24bit) def of: R:%d,G:%d,B:%d\n",
r,
g,
b);
#endif

LightObjects[numLightObjects-1].color.r = r;
LightObjects[numLightObjects-1].color.g = g;
LightObjects[numLightObjects-1].color.b = b;
LightObjects[numLightObjects-1].color.a = 255;


// move the file pointer back to where we got it so
// that the ProcessChunk() which we interrupted will read
// from the right place
fseek(bin3ds, findex, SEEK_SET);
}
/*----------------------------------------------------------------------------*/
void Model_3DS::ReadMTrueColor(long findex) // it the sameone(like true color) but for material
{
unsigned char r;
unsigned char g;
unsigned char b;

// move the file pointer to the beginning of the main
// chunk''s data findex + the size of the header
fseek(bin3ds, findex, SEEK_SET);

fread(&r,sizeof(r),1,bin3ds);
fread(&g,sizeof(g),1,bin3ds);
fread(&b,sizeof(b),1,bin3ds);

#ifdef __DEBUG__
logfile(" Found Color (24bit) def of: R:%d,G:%d,B:%d\n",
r,
g,
b);
#endif

Materials[numMaterials-1].color.r = r;
Materials[numMaterials-1].color.g = g;
Materials[numMaterials-1].color.b = b;
Materials[numMaterials-1].color.a = 255;

// move the file pointer back to where we got it so
// that the ProcessChunk() which we interrupted will read
// from the right place
fseek(bin3ds, findex, SEEK_SET);
}
.....
it''s from my class. I wrote it 2 years ago. There is many aspects of 3ds/ I cat sent it to you, if you want. But there is some error wich i catn''t find yet.

Share this post


Link to post
Share on other sites

  • Advertisement