www.xbdev.net xbdev - software development
Tuesday October 22, 2019
home | about | contact | Donations


3D File Formats

The bits and bytes...


MS3D MilkShape Format - The Basics
Author bkenwright@xbdev.net

Where going to start at the very beginning as we do with any other file format!  Basically create a test file, which in this case is going to be a cube!  Then we'll start about just reading in some of the informaiton and examining the data as we get it, check that we get what we expect.  Such as I know that when I exported the cube, it only has 8 vertices, one for each of the corner.....so of course if you open box.ms3d and suddenly start getting all sorts of crazy numbers back, then you can assume something isn't quiet right.


During the early stages of any file format, when your just reading in the data and dumping it to a txt file, you'll find that its standard c/c++, so you can compile this part on almost any platform.  Late on when we want to actually start using this data, then we'll move onto using some of the graphics librarys, like DirectX or openGl.



Complete Code - Download

#include <stdio.h>	// fopen(..), sprintf(..)
#include <stdarg.h> // va_start, va_end

//Saving debug information to a log file
void dprintf(const char *fmt, ...) 
	va_list parms;

	char buf[256];

	// Try to print in the allocated space.
	va_start(parms, fmt);
	vsprintf (buf, fmt, parms);

	// Send debug info out to the debugger

	// Write the information out to a txt file
	FILE *fp = fopen("output.txt", "a+");
	fprintf(fp, "%s", buf);

void main()
	dprintf("Welcome to the ms3d tutorial...\n");

	// Lets open the test ms3d file we are using, called box.ms3d
	FILE * fp = fopen("box.ms3d", "rb");

	// Temp buffer to store our data in, as we read it in
	char buf[256];

	// Lets read in the first 4 characters of the file are, and see what
	// they look like

	int r =				// The total number of items readed is returned.
	fread (	buf,		// void * buffer,
			4,			// size
			1,			// count,
			fp );		// FILE * stream

	// Log them to our debug txt file
	dprintf("%c %c %c %c\n", buf[0],buf[1],buf[2],buf[3]);

	// Close our File!

	// Exit

/* output.txt:

Welcome to the ms3d tutorial...
M S 3 D








 Visitor: 9534626  { } Copyright (c) 2002-2017 xbdev.net - All rights reserved.
Designated tutorial and software are the property of their respective owners.