Example #1
0
void C3DS::ReadMeshFaces(stChunk* Chunk)
{
    unsigned int iNumberFaces = 0; //= Chunk->length - 6;
    Chunk->bytesRead += (unsigned int)fread(&iNumberFaces, 1, 2, m_fp);

    // Each face is 3 points A TRIANGLE!..WOW
    struct stXFace{ unsigned short vertIds[3], visibityflag; };
    stXFace *pFaces = new stXFace[iNumberFaces];

    Chunk->bytesRead += (unsigned int)fread(pFaces, 1, iNumberFaces*sizeof(stXFace), m_fp);

    stMesh* pMesh = &(m_pMeshs[m_iNumMeshs - 1]);
    pMesh->pFaces = new stFace[iNumberFaces];
    pMesh->iNumFaces = iNumberFaces;

    for( unsigned int i=0; i<iNumberFaces; i++ )
    {
        for(int y=0; y < 3; y++){
            pMesh->pFaces[i].vertIds[y] = pFaces[i].vertIds[y];
        }
    }

    delete[] pFaces;


    // Our face material information is a sub-chunk.
    ParseChunk(Chunk);
}
Example #2
0
__regargs PaletteT *LoadPalette(const char *filename) {
  PaletteT *palette = NULL;
  IffFileT iff;

  if (OpenIff(&iff, filename)) {
    if (iff.header.type == ID_ILBM) {
      while (ParseChunk(&iff)) {
        switch (iff.chunk.type) {
          case ID_CMAP:
            palette = NewPalette(iff.chunk.length / sizeof(ColorT));
            ReadChunk(&iff, palette->colors);
            break;

          default:
            SkipChunk(&iff);
            break;
        }
      }
    }

    CloseIff(&iff);
  }

  return palette;
}
//-----------------------------------------------------------------------------
// Purpose: Bastardized construction routine.  This is just to avoid complex
//			constructor functions so code can be shared more easily by sub-classes
// Input  : *pFormatBuffer - RIFF header
//			formatSize - header size
//			&walk - RIFF file
//-----------------------------------------------------------------------------
void CAudioSourceWave::Setup( const char *pFormatBuffer, int formatSize, IterateRIFF &walk )
{
	Init( pFormatBuffer, formatSize );

	while ( walk.ChunkAvailable() )
	{
		ParseChunk( walk, walk.ChunkName() );
		walk.ChunkNext();
	}
}
Example #4
0
void C3DS::GetMeshObjectName(stChunk* Chunk)
{
    // The strange thing is, the next few parts of this chunk represent
    // the name of the object.  Then we start chunking again.
    char str[256];
    unsigned int characterlen = GetString(str);
    Chunk->bytesRead += characterlen;

    stMesh* pMesh = &(m_pMeshs[m_iNumMeshs - 1]);
    strcpy( pMesh->szMeshName, str );

    ParseChunk(Chunk);
}
Example #5
0
bool C3DS::load(char* szFileName){
    m_fp = fopen(szFileName, "rb");

    stChunk Chunk = {0, 0, 0};
    ReadChunk(&Chunk);

    ParseChunk(&Chunk );

    fclose(m_fp);

    this->calculateNormal();
    this->compile();

    return true;
}
Example #6
0
bool C3DS::Create(char* szFileName)
{
	m_fp = fopen(szFileName, "rb");
	if (m_fp == NULL)
		return false;
	
	stChunk Chunk = {0};
	ReadChunk(&Chunk);

	ParseChunk(&Chunk );
	
	fclose(m_fp);

	return true;
}
Example #7
0
void Load3DSTriangleList (char *filename, triangle_t **pptri, int *numtriangles)
{
	FILE        *input;
	short int	tshort;

	bytesread = 0;
	level = 0;
	numtris = 0;
	totaltris = 0;
	vertsfound = 0;
	trisfound = 0;

	if ((input = fopen(filename, "rb")) == 0) {
		fprintf(stderr,"reader: could not open file '%s'\n", filename);
		exit(0);
	}

	fread(&tshort, sizeof(tshort), 1, input);

// should only be MAIN3DS, but some files seem to start with EDIT3DS, with
// no MAIN3DS
	if ((tshort != MAIN3DS) && (tshort != EDIT3DS)) {
		fprintf(stderr,"File is not a 3DS file.\n");
		exit(0);
	}

// back to top of file so we can parse the first chunk descriptor
	fseek(input, 0, SEEK_SET);

	ptri = malloc (MAXTRIANGLES * sizeof(triangle_t));

	*pptri = ptri;

// parse through looking for the relevant chunk tree (MAIN3DS | EDIT3DS | EDIT_OBJECT |
// OBJ_TRIMESH | {TRI_VERTEXL, TRI_FACEL1}) and skipping other chunks
	ParseChunk (input);

	if (vertsfound || trisfound)
		Error ("Incomplete triangle set");

	*numtriangles = totaltris;

	fclose (input);
}
Example #8
0
int main() {
  UWORD len = __commandlen;
  STRPTR filename = __builtin_alloca(len);
  IffFileT iff;

  memcpy(filename, __commandline, len--);
  filename[len] = '\0';

  OpenIff(&iff, filename);
  Log("Parsing '%s':\n", filename);
  Log("%.4s %ld\n", (STRPTR)&iff.header.type, iff.header.length);

  while (ParseChunk(&iff)) {
    Log(".%.4s %ld\n", (STRPTR)&iff.chunk.type, iff.chunk.length);
    SkipChunk(&iff);
  }

  CloseIff(&iff);

  return 0;
}
Example #9
0
__regargs BitmapT *LoadILBM(const char *filename, BOOL interleaved) {
  BitmapT *bitmap = NULL;
  PaletteT *palette = NULL;
  IffFileT iff;

  if (OpenIff(&iff, filename)) {
    if (iff.header.type == ID_ILBM) {
      BOOL compression = FALSE;

      while (ParseChunk(&iff)) {
        BitmapHeaderT bmhd;

        switch (iff.chunk.type) {
          case ID_BMHD:
            ReadChunk(&iff, &bmhd);
            bitmap = NewBitmap(bmhd.w, bmhd.h, bmhd.nPlanes, interleaved);
            compression = bmhd.compression;
            break;

          case ID_CMAP:
            palette = NewPalette(iff.chunk.length / sizeof(ColorT));
            ReadChunk(&iff, palette->colors);
            break;
        
          case ID_BODY:
            {
              BYTE *data = MemAlloc(iff.chunk.length, MEMF_PUBLIC);
              LONG size = iff.chunk.length;

              ReadChunk(&iff, data);

              if (compression) {
                LONG newSize = bitmap->bplSize * bitmap->depth;
                BYTE *uncompressed = MemAlloc(newSize, MEMF_PUBLIC);

                UnRLE(data, size, uncompressed);
                MemFree(data, size);

                data = uncompressed;
                size = newSize;
              }

              if (!interleaved)
                Deinterleave(data, bitmap);
              else
                memcpy(bitmap->planes[0], data, bitmap->bplSize * bitmap->depth);

              MemFree(data, size);
            }
            break;

          default:
            SkipChunk(&iff);
            break;
        }
      }

      if (bitmap)
        bitmap->palette = palette;
    }

    CloseIff(&iff);
  } else {
    Log("File '%s' missing.\n", filename);
  }

  return bitmap;
}
Example #10
0
void C3DS::ParseChunk(stChunk* Chunk){
    while(Chunk->bytesRead < Chunk->length){
        stChunk tempChunk = {0, 0, 0};
        ReadChunk(&tempChunk);

        switch( tempChunk.ID){
        // HEADER OUR ENTRY POINT
        case EDIT3DS: //0x3D3D
            ParseChunk(&tempChunk);
            break;

            // MATERIALS
        case MATERIAL: //0xAFFF
            stMaterial newMaterial;
            m_pMaterials.push_back(newMaterial);
            m_iNumMaterials++;
            ParseChunk(&tempChunk);
            break;
        case MAT_NAME: //0xA000 - sz for hte material name "e.g. default 2"
            GetMaterialName(&tempChunk);
            break;
        case MAT_DIFFUSE:  // Diffuse Colour  //0xA020
            GetDiffuseColour(&tempChunk);
            break;
        case MAT_TEXMAP:  //0xA200 - if there's a texture wrapped to it where here
            ParseChunk(&tempChunk);
            break;
        case MAT_TEXFLNM: // 0xA300 -  get filename of the material
            GetTexFileName(&tempChunk);
            break;

            // OBJECT - MESH'S
        case NAMED_OBJECT:{
            stMesh newMesh;
            m_pMeshs.push_back(newMesh);
            m_iNumMeshs++;
            GetMeshObjectName(&tempChunk);
        }
            break;
        case OBJ_MESH:     //0x4100
            ParseChunk(&tempChunk);
            break;
        case MESH_VERTICES: //0x4110
            ReadMeshVertices(&tempChunk);
            break;
        case MESH_FACES: //0x4120
            ReadMeshFaces(&tempChunk);
            break;
        case MESH_TEX_VERT: //0x4140
            ReadMeshTexCoords(&tempChunk);
            break;
        case MESH_MATER: //0x4130
            ReadMeshMaterials(&tempChunk);
            break;

        default:
            SkipChunk(&tempChunk);
        }

        Chunk->bytesRead += tempChunk.length;
    }
}
Example #11
0
void C3DS::ParseChunk(stChunk* Chunk)
{
	while(Chunk->bytesRead < Chunk->length)
	{
		stChunk tempChunk = {0};
		ReadChunk(&tempChunk);

		// DEBUG CHUNKS
		//char buf[2000];
		//sprintf(buf, "Chunk ID: %.4x\t Size: %d\n", tempChunk.ID, tempChunk.length);
		//debug_op(buf);

		switch( tempChunk.ID)
		{
		// HEADER OUR ENTRY POINT
		case EDIT3DS: //0x3D3D
			ParseChunk(&tempChunk);
			break;

		// MATERIALS
		case MATERIAL: //0xAFFF
			{
			stMaterial newMaterial;
			m_pMaterials.push_back(newMaterial);
			m_iNumMaterials++;
			}
			ParseChunk(&tempChunk);
			break;
		case MAT_NAME: //0xA000 - sz for hte material name "e.g. default 2"
			GetMaterialName(&tempChunk);
			break;
		case MAT_AMBIENT:
			GetAmbientColour(&tempChunk);
			break;
		case MAT_SPECULAR:
			GetSpecularColour(&tempChunk);
			break;
		case MAT_DIFFUSE:  // Diffuse Colour  //0xA020
			GetDiffuseColour(&tempChunk);
			break;
		case MAT_TEXMAP:  //0xA200 - if there's a texture wrapped to it where here
			ParseChunk(&tempChunk);
			break;
		case MAT_TEXFLNM: // 0xA300 -  get filename of the material
			GetTexFileName(&tempChunk);
			break;

		// OBJECT - MESH'S
		case NAMED_OBJECT: //0x4000
			{
			stMesh newMesh;
			m_pMeshs.push_back(newMesh);
			m_iNumMeshs++;
			GetMeshObjectName(&tempChunk);
			}
			break;
		case OBJ_MESH:     //0x4100
			ParseChunk(&tempChunk);
			break;
		case MESH_VERTICES: //0x4110
			ReadMeshVertices(&tempChunk);
			break;
		case MESH_FACES: //0x4120
			ReadMeshFaces(&tempChunk);
			break;
		case MESH_TEX_VERT: //0x4140
			ReadMeshTexCoords(&tempChunk);
			break;
		case MESH_MATER: //0x4130
			ReadMeshMaterials(&tempChunk);
			break;

		// ANIMATION
		case KEYF3DS:	//0xB000
			ParseChunk(&tempChunk);
			break;
		case ANIM_S_E_TIME:   //0xB008
			StartEndFrames(&tempChunk);
			break;
		case ANIM_OBJ:	//0xB002
			{
				stAnimation newAnimation;
				m_pAnimation.push_back(newAnimation);
				m_iNumAnimObjects++;
			}
			ParseChunk(&tempChunk);
			break;
		case ANIM_NAME:
			ReadNameOfObjectToAnimate(&tempChunk);
			break;
		case ANIM_PIVOT: // 0xB013
			ReadPivotPoint(&tempChunk);
			break;
		case ANIM_POS: // 0xB020
			ReadAnimPos(&tempChunk);
			break;
		case ANIM_ROT: //		0xB021
			ReadAnimRot(&tempChunk);
			break;
		case ANIM_SCALE: // 0xB022
			ReadAnimScale(&tempChunk); 
			break;

		default:
			SkipChunk(&tempChunk);
		}
		
		Chunk->bytesRead += tempChunk.length;
	}
}
Example #12
0
int ParseChunk (FILE *input)
{
#define BLOCK_SIZE	4096
	char			temp[BLOCK_SIZE];
	unsigned short	type;
	int				i, length, w, t, retval;

	level++;
	retval = 0;

// chunk type
	if (feof(input))
		Error ("Error: unexpected end of file");

	fread(&type, sizeof(type), 1, input);
	bytesread += sizeof(type);

// chunk length
	if (feof(input))
		Error ("Error: unexpected end of file");

	fread (&length, sizeof(length), 1, input);
	bytesread += sizeof(length);
	w = length - 6;

// process chunk if we care about it, otherwise skip it
	switch (type)
	{
	case TRI_VERTEXL:
		w -= ParseVertexL (input);
		goto ParseSubchunk;

	case TRI_FACEL1:
		w -= ParseFaceL1 (input);
		goto ParseSubchunk;

	case EDIT_OBJECT:
	// read the name
		i = 0;

		do
		{
			if (feof(input))
				Error ("Error: unexpected end of file");

			fread (&temp[i], 1, 1, input);
			i++;
			w--;
			bytesread++;
		} while (temp[i-1]);

	case MAIN3DS:
	case OBJ_TRIMESH:
	case EDIT3DS:
	// parse through subchunks
ParseSubchunk:
		while (w > 0)
		{
			w -= ParseChunk (input);
		}

		retval = length;
		goto Done;

	default:
	// skip other chunks
		while (w > 0)
		{
			t = w;

			if (t > BLOCK_SIZE)
				t = BLOCK_SIZE;

			if (feof(input))
				Error ("Error: unexpected end of file");

			fread (&temp, t, 1, input);
			bytesread += t;

			w -= t;
		}

		retval = length;
		goto Done;
	}

Done:
	level--;
	return retval;
}