Updated the lib3ds plugin with the new 1.1 version of lib3ds.

This commit is contained in:
Robert Osfield
2001-10-31 18:33:27 +00:00
parent 94ce36f9a3
commit 78372a5a62
30 changed files with 6700 additions and 7024 deletions

View File

@@ -4,13 +4,13 @@
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
@@ -22,168 +22,170 @@
#define LIB3DS_EXPORT
#include <readwrite.h>
/*!
* \defgroup readwrite Portable Binary Input/Ouput
*
* \author J.E. Hoffmann <je-h@gmx.net>
*/
/*!
* \ingroup readwrite
*
* Read a byte from a file stream.
* Read a byte from a file stream.
*
* \param f Input file stream.
* \param f Input file stream.
*
* \return The byte read.
* \return The byte read.
*/
Lib3dsByte
lib3ds_byte_read(FILE *f)
{
Lib3dsByte b;
Lib3dsByte b;
ASSERT(f);
fread(&b,1,1,f);
return(b);
ASSERT(f);
fread(&b,1,1,f);
return(b);
}
/**
* Read a word from a file stream in little endian format.
* Read a word from a file stream in little endian format.
*
* \param f Input file stream.
* \param f Input file stream.
*
* \return The word read.
* \return The word read.
*/
Lib3dsWord
lib3ds_word_read(FILE *f)
{
Lib3dsByte b[2];
Lib3dsWord w;
Lib3dsByte b[2];
Lib3dsWord w;
ASSERT(f);
fread(b,2,1,f);
w=((Lib3dsWord)b[1] << 8) |
((Lib3dsWord)b[0]);
return(w);
ASSERT(f);
fread(b,2,1,f);
w=((Lib3dsWord)b[1] << 8) |
((Lib3dsWord)b[0]);
return(w);
}
/*!
* \ingroup readwrite
*
* Read a dword from file a stream in little endian format.
* Read a dword from file a stream in little endian format.
*
* \param f Input file stream.
* \param f Input file stream.
*
* \return The dword read.
* \return The dword read.
*/
Lib3dsDword
lib3ds_dword_read(FILE *f)
{
Lib3dsByte b[4];
Lib3dsDword d;
ASSERT(f);
fread(b,4,1,f);
d=((Lib3dsDword)b[3] << 24) |
((Lib3dsDword)b[2] << 16) |
((Lib3dsDword)b[1] << 8) |
((Lib3dsDword)b[0]);
return(d);
Lib3dsByte b[4];
Lib3dsDword d;
ASSERT(f);
fread(b,4,1,f);
d=((Lib3dsDword)b[3] << 24) |
((Lib3dsDword)b[2] << 16) |
((Lib3dsDword)b[1] << 8) |
((Lib3dsDword)b[0]);
return(d);
}
/*!
* \ingroup readwrite
*
* Read a signed byte from a file stream.
* Read a signed byte from a file stream.
*
* \param f Input file stream.
* \param f Input file stream.
*
* \return The signed byte read.
* \return The signed byte read.
*/
Lib3dsIntb
lib3ds_intb_read(FILE *f)
{
Lib3dsIntb b;
Lib3dsIntb b;
ASSERT(f);
fread(&b,1,1,f);
return(b);
ASSERT(f);
fread(&b,1,1,f);
return(b);
}
/*!
* \ingroup readwrite
*
* Read a signed word from a file stream in little endian format.
* Read a signed word from a file stream in little endian format.
*
* \param f Input file stream.
* \param f Input file stream.
*
* \return The signed word read.
* \return The signed word read.
*/
Lib3dsIntw
lib3ds_intw_read(FILE *f)
{
Lib3dsByte b[2];
Lib3dsWord w;
Lib3dsByte b[2];
Lib3dsWord w;
ASSERT(f);
fread(b,2,1,f);
w=((Lib3dsWord)b[1] << 8) |
((Lib3dsWord)b[0]);
return((Lib3dsIntw)w);
ASSERT(f);
fread(b,2,1,f);
w=((Lib3dsWord)b[1] << 8) |
((Lib3dsWord)b[0]);
return((Lib3dsIntw)w);
}
/*!
* \ingroup readwrite
*
* Read a signed dword a from file stream in little endian format.
* Read a signed dword a from file stream in little endian format.
*
* \param f Input file stream.
* \param f Input file stream.
*
* \return The signed dword read.
* \return The signed dword read.
*/
Lib3dsIntd
lib3ds_intd_read(FILE *f)
{
Lib3dsByte b[4];
Lib3dsDword d;
ASSERT(f);
fread(b,4,1,f);
d=((Lib3dsDword)b[3] << 24) |
((Lib3dsDword)b[2] << 16) |
((Lib3dsDword)b[1] << 8) |
((Lib3dsDword)b[0]);
return((Lib3dsIntd)d);
Lib3dsByte b[4];
Lib3dsDword d;
ASSERT(f);
fread(b,4,1,f);
d=((Lib3dsDword)b[3] << 24) |
((Lib3dsDword)b[2] << 16) |
((Lib3dsDword)b[1] << 8) |
((Lib3dsDword)b[0]);
return((Lib3dsIntd)d);
}
/*!
* \ingroup readwrite
*
* Read a float from a file stream in little endian format.
* Read a float from a file stream in little endian format.
*
* \param f Input file stream.
* \param f Input file stream.
*
* \return The float read.
* \return The float read.
*/
Lib3dsFloat
lib3ds_float_read(FILE *f)
{
Lib3dsByte b[4];
Lib3dsDword d;
Lib3dsByte b[4];
Lib3dsDword d;
ASSERT(f);
fread(b,4,1,f);
d=((Lib3dsDword)b[3] << 24) |
((Lib3dsDword)b[2] << 16) |
((Lib3dsDword)b[1] << 8) |
((Lib3dsDword)b[0]);
return(*((Lib3dsFloat*)&d));
ASSERT(f);
fread(b,4,1,f);
d=((Lib3dsDword)b[3] << 24) |
((Lib3dsDword)b[2] << 16) |
((Lib3dsDword)b[1] << 8) |
((Lib3dsDword)b[0]);
return(*((Lib3dsFloat*)&d));
}
@@ -191,25 +193,24 @@ lib3ds_float_read(FILE *f)
* \ingroup readwrite
* \ingroup vector
*
* Read a vector from a file stream in little endian format.
* Read a vector from a file stream in little endian format.
*
* \param v The vector to store the data.
* \param f Input file stream.
* \param v The vector to store the data.
* \param f Input file stream.
*
* \return The float read.
* \return The float read.
*/
Lib3dsBool
lib3ds_vector_read(Lib3dsVector v, FILE *f)
{
v[0]=lib3ds_float_read(f);
v[1]=lib3ds_float_read(f);
v[2]=lib3ds_float_read(f);
v[0]=lib3ds_float_read(f);
v[1]=lib3ds_float_read(f);
v[2]=lib3ds_float_read(f);
if (ferror(f))
{
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
if (ferror(f)) {
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
}
@@ -219,15 +220,14 @@ lib3ds_vector_read(Lib3dsVector v, FILE *f)
Lib3dsBool
lib3ds_rgb_read(Lib3dsRgb rgb, FILE *f)
{
rgb[0]=lib3ds_float_read(f);
rgb[1]=lib3ds_float_read(f);
rgb[2]=lib3ds_float_read(f);
rgb[0]=lib3ds_float_read(f);
rgb[1]=lib3ds_float_read(f);
rgb[2]=lib3ds_float_read(f);
if (ferror(f))
{
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
if (ferror(f)) {
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
}
@@ -245,20 +245,17 @@ lib3ds_rgb_read(Lib3dsRgb rgb, FILE *f)
Lib3dsBool
lib3ds_string_read(char *s, int buflen, FILE *f)
{
int k=0;
ASSERT(f);
while ((*s++=fgetc(f))!=0)
{
if (++k>buflen)
{
return(LIB3DS_FALSE);
}
int k=0;
ASSERT(f);
while ((*s++=fgetc(f))!=0) {
if (++k>=buflen) {
return(LIB3DS_FALSE);
}
if (ferror(f))
{
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
}
if (ferror(f)) {
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
}
@@ -275,12 +272,11 @@ lib3ds_string_read(char *s, int buflen, FILE *f)
Lib3dsBool
lib3ds_byte_write(Lib3dsByte b, FILE *f)
{
ASSERT(f);
if (fwrite(&b,1,1,f)!=1)
{
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
ASSERT(f);
if (fwrite(&b,1,1,f)!=1) {
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
}
@@ -297,16 +293,15 @@ lib3ds_byte_write(Lib3dsByte b, FILE *f)
Lib3dsBool
lib3ds_word_write(Lib3dsWord w, FILE *f)
{
Lib3dsByte b[2];
Lib3dsByte b[2];
ASSERT(f);
b[1]=((Lib3dsWord)w & 0xFF00) >> 8;
b[0]=((Lib3dsWord)w & 0x00FF);
if (fwrite(b,2,1,f)!=1)
{
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
ASSERT(f);
b[1]=((Lib3dsWord)w & 0xFF00) >> 8;
b[0]=((Lib3dsWord)w & 0x00FF);
if (fwrite(b,2,1,f)!=1) {
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
}
@@ -323,18 +318,17 @@ lib3ds_word_write(Lib3dsWord w, FILE *f)
Lib3dsBool
lib3ds_dword_write(Lib3dsDword d, FILE *f)
{
Lib3dsByte b[4];
Lib3dsByte b[4];
ASSERT(f);
b[3]=(Lib3dsByte)(((Lib3dsDword)d & 0xFF000000) >> 24);
b[2]=(Lib3dsByte)(((Lib3dsDword)d & 0x00FF0000) >> 16);
b[1]=(Lib3dsByte)(((Lib3dsDword)d & 0x0000FF00) >> 8);
b[0]=(Lib3dsByte)(((Lib3dsDword)d & 0x000000FF));
if (fwrite(b,4,1,f)!=1)
{
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
ASSERT(f);
b[3]=(Lib3dsByte)(((Lib3dsDword)d & 0xFF000000) >> 24);
b[2]=(Lib3dsByte)(((Lib3dsDword)d & 0x00FF0000) >> 16);
b[1]=(Lib3dsByte)(((Lib3dsDword)d & 0x0000FF00) >> 8);
b[0]=(Lib3dsByte)(((Lib3dsDword)d & 0x000000FF));
if (fwrite(b,4,1,f)!=1) {
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
}
@@ -351,12 +345,11 @@ lib3ds_dword_write(Lib3dsDword d, FILE *f)
Lib3dsBool
lib3ds_intb_write(Lib3dsIntb b, FILE *f)
{
ASSERT(f);
if (fwrite(&b,1,1,f)!=1)
{
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
ASSERT(f);
if (fwrite(&b,1,1,f)!=1) {
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
}
@@ -373,16 +366,15 @@ lib3ds_intb_write(Lib3dsIntb b, FILE *f)
Lib3dsBool
lib3ds_intw_write(Lib3dsIntw w, FILE *f)
{
Lib3dsByte b[2];
Lib3dsByte b[2];
ASSERT(f);
b[1]=((Lib3dsWord)w & 0xFF00) >> 8;
b[0]=((Lib3dsWord)w & 0x00FF);
if (fwrite(b,2,1,f)!=1)
{
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
ASSERT(f);
b[1]=((Lib3dsWord)w & 0xFF00) >> 8;
b[0]=((Lib3dsWord)w & 0x00FF);
if (fwrite(b,2,1,f)!=1) {
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
}
@@ -399,18 +391,17 @@ lib3ds_intw_write(Lib3dsIntw w, FILE *f)
Lib3dsBool
lib3ds_intd_write(Lib3dsIntd d, FILE *f)
{
Lib3dsByte b[4];
Lib3dsByte b[4];
ASSERT(f);
b[3]=(Lib3dsByte)(((Lib3dsDword)d & 0xFF000000) >> 24);
b[2]=(Lib3dsByte)(((Lib3dsDword)d & 0x00FF0000) >> 16);
b[1]=(Lib3dsByte)(((Lib3dsDword)d & 0x0000FF00) >> 8);
b[0]=(Lib3dsByte)(((Lib3dsDword)d & 0x000000FF));
if (fwrite(b,4,1,f)!=1)
{
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
ASSERT(f);
b[3]=(Lib3dsByte)(((Lib3dsDword)d & 0xFF000000) >> 24);
b[2]=(Lib3dsByte)(((Lib3dsDword)d & 0x00FF0000) >> 16);
b[1]=(Lib3dsByte)(((Lib3dsDword)d & 0x0000FF00) >> 8);
b[0]=(Lib3dsByte)(((Lib3dsDword)d & 0x000000FF));
if (fwrite(b,4,1,f)!=1) {
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
}
@@ -427,20 +418,19 @@ lib3ds_intd_write(Lib3dsIntd d, FILE *f)
Lib3dsBool
lib3ds_float_write(Lib3dsFloat l, FILE *f)
{
Lib3dsByte b[4];
Lib3dsDword d;
Lib3dsByte b[4];
Lib3dsDword d;
ASSERT(f);
d=*((Lib3dsDword*)&l);
b[3]=(Lib3dsByte)(((Lib3dsDword)d & 0xFF000000) >> 24);
b[2]=(Lib3dsByte)(((Lib3dsDword)d & 0x00FF0000) >> 16);
b[1]=(Lib3dsByte)(((Lib3dsDword)d & 0x0000FF00) >> 8);
b[0]=(Lib3dsByte)(((Lib3dsDword)d & 0x000000FF));
if (fwrite(b,4,1,f)!=1)
{
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
ASSERT(f);
d=*((Lib3dsDword*)&l);
b[3]=(Lib3dsByte)(((Lib3dsDword)d & 0xFF000000) >> 24);
b[2]=(Lib3dsByte)(((Lib3dsDword)d & 0x00FF0000) >> 16);
b[1]=(Lib3dsByte)(((Lib3dsDword)d & 0x0000FF00) >> 8);
b[0]=(Lib3dsByte)(((Lib3dsDword)d & 0x000000FF));
if (fwrite(b,4,1,f)!=1) {
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
}
@@ -448,27 +438,24 @@ lib3ds_float_write(Lib3dsFloat l, FILE *f)
* \ingroup readwrite
* \ingroup vector
*
* Writes a vector into a file stream in little endian format.
* Writes a vector into a file stream in little endian format.
*
* \param v The vector to write to the file stream.
* \param f Input file stream.
* \param v The vector to write to the file stream.
* \param f Input file stream.
*/
Lib3dsBool
lib3ds_vector_write(Lib3dsVector v, FILE *f)
{
if (!lib3ds_float_write(v[0], f))
{
return(LIB3DS_FALSE);
}
if (!lib3ds_float_write(v[1], f))
{
return(LIB3DS_FALSE);
}
if (!lib3ds_float_write(v[2], f))
{
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
if (!lib3ds_float_write(v[0], f)) {
return(LIB3DS_FALSE);
}
if (!lib3ds_float_write(v[1], f)) {
return(LIB3DS_FALSE);
}
if (!lib3ds_float_write(v[2], f)) {
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
}
@@ -478,19 +465,16 @@ lib3ds_vector_write(Lib3dsVector v, FILE *f)
Lib3dsBool
lib3ds_rgb_write(Lib3dsRgb rgb, FILE *f)
{
if (!lib3ds_float_write(rgb[0], f))
{
return(LIB3DS_FALSE);
}
if (!lib3ds_float_write(rgb[1], f))
{
return(LIB3DS_FALSE);
}
if (!lib3ds_float_write(rgb[2], f))
{
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
if (!lib3ds_float_write(rgb[0], f)) {
return(LIB3DS_FALSE);
}
if (!lib3ds_float_write(rgb[1], f)) {
return(LIB3DS_FALSE);
}
if (!lib3ds_float_write(rgb[2], f)) {
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
}
@@ -507,12 +491,12 @@ lib3ds_rgb_write(Lib3dsRgb rgb, FILE *f)
Lib3dsBool
lib3ds_string_write(const char *s, FILE *f)
{
ASSERT(s);
ASSERT(f);
do fputc(*s,f); while (*s++);
if (ferror(f))
{
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
ASSERT(s);
ASSERT(f);
do fputc(*s,f); while (*s++);
if (ferror(f)) {
return(LIB3DS_FALSE);
}
return(LIB3DS_TRUE);
}