All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Go to the documentation of this file.
1 /* -*- c -*- */
4 /*
5  Copyright (C) 1996-2008 by Jan Eric Kyprianidis <www.kyprianidis.com>
6  All rights reserved.
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published
10  by the Free Software Foundation, either version 2.1 of the License, or
11  (at your option) any later version.
13  Thisprogram is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  GNU Lesser General Public License for more details.
18  You should have received a copy of the GNU Lesser General Public License
19  along with this program; If not, see <http://www.gnu.org/licenses/>.
20 */
22 #include "lib3ds.h"
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <stdarg.h>
26 #include <string.h>
27 #include <math.h>
28 #include <float.h>
29 #include <assert.h>
30 #include <setjmp.h>
31 #include <stdarg.h>
33 #ifdef _MSC_VER
34 #pragma warning ( disable : 4996 )
35 #endif
37 #ifndef _MSC_VER
38 #include <stdint.h>
39 #else
40 typedef unsigned __int8 uint8_t;
41 typedef unsigned __int16 uint16_t;
42 typedef unsigned __int32 uint32_t;
43 typedef signed __int8 int8_t;
44 typedef signed __int16 int16_t;
45 typedef signed __int32 int32_t;
46 #endif
48 #ifndef TRUE
49 #define TRUE 1
50 #endif
51 #ifndef FALSE
52 #define FALSE 0
53 #endif
55 #define LIB3DS_EPSILON (1e-5)
56 #define LIB3DS_PI 3.14159265358979323846
57 #define LIB3DS_TWOPI (2.0*LIB3DS_PI)
58 #define LIB3DS_HALFPI (LIB3DS_PI/2.0)
59 #define LIB3DS_RAD_TO_DEG(x) ((180.0/LIB3DS_PI)*(x))
60 #define LIB3DS_DEG_TO_RAD(x) ((LIB3DS_PI/180.0)*(x))
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
66 typedef enum Lib3dsChunks {
67  CHK_NULL_CHUNK =0x0000,
68  CHK_M3DMAGIC =0x4D4D, /*3DS file*/
69  CHK_SMAGIC =0x2D2D,
70  CHK_LMAGIC =0x2D3D,
71  CHK_MLIBMAGIC =0x3DAA, /*MLI file*/
73  CHK_CMAGIC =0xC23D, /*PRJ file*/
74  CHK_M3D_VERSION =0x0002,
77  CHK_COLOR_F =0x0010,
78  CHK_COLOR_24 =0x0011,
80  CHK_LIN_COLOR_F =0x0013,
84  CHK_MDATA =0x3D3D,
93  CHK_RAY_BIAS =0x1460,
94  CHK_O_CONSTS =0x1500,
96  CHK_BIT_MAP =0x1100,
97  CHK_SOLID_BGND =0x1200,
98  CHK_V_GRADIENT =0x1300,
99  CHK_USE_BIT_MAP =0x1101,
102  CHK_FOG =0x2200,
103  CHK_FOG_BGND =0x2210,
104  CHK_LAYER_FOG =0x2302,
106  CHK_DCUE_BGND =0x2310,
107  CHK_USE_FOG =0x2201,
112  CHK_MAT_NAME =0xA000,
119  CHK_MAT_XPFALL =0xA052,
126  CHK_MAT_DECAL =0xA082,
129  CHK_MAT_WIRE =0xA085,
134  CHK_MAT_TEXMAP =0xA200,
165  CHK_MAT_ACUBIC =0xA310,
182  CHK_DL_OFF =0x4620,
186  CHK_DL_EXCLUDE =0x4654,
198  CHK_DL_RAYSHAD =0x4627,
199  CHK_N_CAMERA =0x4700,
201  CHK_CAM_RANGES =0x4720,
202  CHK_OBJ_HIDDEN =0x4010,
206  CHK_OBJ_MATTE =0x4013,
207  CHK_OBJ_FAST =0x4014,
209  CHK_OBJ_FROZEN =0x4016,
213  CHK_FACE_ARRAY =0x4120,
216  CHK_MSH_BOXMAP =0x4190,
217  CHK_TEX_VERTS =0x4140,
219  CHK_MESH_COLOR =0x4165,
222  CHK_KFDATA =0xB000,
223  CHK_KFHDR =0xB00A,
224  CHK_KFSEG =0xB008,
225  CHK_KFCURTIME =0xB009,
233  CHK_NODE_ID =0xB030,
234  CHK_NODE_HDR =0xB010,
235  CHK_PIVOT =0xB013,
238  CHK_BOUNDBOX =0xB014,
250  CHK_POLY_2D = 0x5000,
251  CHK_SHAPE_OK = 0x5010,
253  CHK_SHAPE_HOOK = 0x5020,
254  CHK_PATH_3D = 0x6000,
255  CHK_PATH_MATRIX = 0x6005,
256  CHK_SHAPE_2D = 0x6010,
257  CHK_M_SCALE = 0x6020,
258  CHK_M_TWIST = 0x6030,
259  CHK_M_TEETER = 0x6040,
260  CHK_M_FIT = 0x6050,
261  CHK_M_BEVEL = 0x6060,
262  CHK_XZ_CURVE = 0x6070,
263  CHK_YZ_CURVE = 0x6080,
264  CHK_INTERPCT = 0x6090,
267  CHK_USE_CONTOUR = 0x6100,
268  CHK_USE_TWEEN = 0x6110,
269  CHK_USE_SCALE = 0x6120,
270  CHK_USE_TWIST = 0x6130,
271  CHK_USE_TEETER = 0x6140,
272  CHK_USE_FIT = 0x6150,
273  CHK_USE_BEVEL = 0x6160,
276  CHK_VIEW_TOP = 0x3010,
277  CHK_VIEW_BOTTOM = 0x3020,
278  CHK_VIEW_LEFT = 0x3030,
279  CHK_VIEW_RIGHT = 0x3040,
280  CHK_VIEW_FRONT = 0x3050,
281  CHK_VIEW_BACK = 0x3060,
282  CHK_VIEW_USER = 0x3070,
283  CHK_VIEW_CAMERA = 0x3080,
284  CHK_VIEW_WINDOW = 0x3090,
293 } Lib3dsChunks;
295 typedef struct Lib3dsChunk {
300 } Lib3dsChunk;
302 extern void lib3ds_chunk_read(Lib3dsChunk *c, Lib3dsIo *io);
304 extern void lib3ds_chunk_read_tell(Lib3dsChunk *c, Lib3dsIo *io);
306 extern void lib3ds_chunk_read_reset(Lib3dsChunk *c, Lib3dsIo *io);
307 extern void lib3ds_chunk_read_end(Lib3dsChunk *c, Lib3dsIo *io);
308 extern void lib3ds_chunk_write(Lib3dsChunk *c, Lib3dsIo *io);
310 extern void lib3ds_chunk_write_end(Lib3dsChunk *c, Lib3dsIo *io);
311 extern const char* lib3ds_chunk_name(uint16_t chunk);
312 extern void lib3ds_chunk_unknown(uint16_t chunk, Lib3dsIo *io);
314 typedef struct Lib3dsIoImpl {
315  jmp_buf jmpbuf;
317  void *tmp_mem;
319 } Lib3dsIoImpl;
321 extern void lib3ds_io_setup(Lib3dsIo *io);
322 extern void lib3ds_io_cleanup(Lib3dsIo *io);
324 extern long lib3ds_io_seek(Lib3dsIo *io, long offset, Lib3dsIoSeek origin);
325 extern long lib3ds_io_tell(Lib3dsIo *io);
326 extern size_t lib3ds_io_read(Lib3dsIo *io, void *buffer, size_t size);
327 extern size_t lib3ds_io_write(Lib3dsIo *io, const void *buffer, size_t size);
328 extern void lib3ds_io_log(Lib3dsIo *io, Lib3dsLogLevel level, const char *format, ...);
329 extern void lib3ds_io_log_indent(Lib3dsIo *io, int indent);
330 extern void lib3ds_io_read_error(Lib3dsIo *io);
331 extern void lib3ds_io_write_error(Lib3dsIo *io);
339 extern float lib3ds_io_read_float(Lib3dsIo *io);
340 extern void lib3ds_io_read_vector(Lib3dsIo *io, float v[3]);
341 extern void lib3ds_io_read_rgb(Lib3dsIo *io, float rgb[3]);
342 extern void lib3ds_io_read_string(Lib3dsIo *io, char *s, int buflen);
344 extern void lib3ds_io_write_byte(Lib3dsIo *io, uint8_t b);
345 extern void lib3ds_io_write_word(Lib3dsIo *io, uint16_t w);
346 extern void lib3ds_io_write_dword(Lib3dsIo *io, uint32_t d);
347 extern void lib3ds_io_write_intb(Lib3dsIo *io, int8_t b);
348 extern void lib3ds_io_write_intw(Lib3dsIo *io, int16_t w);
349 extern void lib3ds_io_write_intd(Lib3dsIo *io, int32_t d);
350 extern void lib3ds_io_write_float(Lib3dsIo *io, float l);
351 extern void lib3ds_io_write_vector(Lib3dsIo *io, float v[3]);
352 extern void lib3ds_io_write_rgb(Lib3dsIo *io, float rgb[3]);
353 extern void lib3ds_io_write_string(Lib3dsIo *io, const char *s);
355 extern void lib3ds_atmosphere_read(Lib3dsAtmosphere *atmosphere, Lib3dsIo *io);
356 extern void lib3ds_atmosphere_write(Lib3dsAtmosphere *atmosphere, Lib3dsIo *io);
357 extern void lib3ds_background_read(Lib3dsBackground *background, Lib3dsIo *io);
358 extern void lib3ds_background_write(Lib3dsBackground *background, Lib3dsIo *io);
359 extern void lib3ds_shadow_read(Lib3dsShadow *shadow, Lib3dsIo *io);
360 extern void lib3ds_shadow_write(Lib3dsShadow *shadow, Lib3dsIo *io);
361 extern void lib3ds_viewport_read(Lib3dsViewport *viewport, Lib3dsIo *io);
362 extern void lib3ds_viewport_write(Lib3dsViewport *viewport, Lib3dsIo *io);
363 extern void lib3ds_material_read(Lib3dsMaterial *material, Lib3dsIo *io);
364 extern void lib3ds_material_write(Lib3dsMaterial *material, Lib3dsIo *io);
365 extern void lib3ds_camera_read(Lib3dsCamera *camera, Lib3dsIo *io);
366 extern void lib3ds_camera_write(Lib3dsCamera *camera, Lib3dsIo *io);
367 extern void lib3ds_light_read(Lib3dsLight *light, Lib3dsIo *io);
368 extern void lib3ds_light_write(Lib3dsLight *light, Lib3dsIo *io);
369 extern void lib3ds_mesh_read(Lib3dsFile *file, Lib3dsMesh *mesh, Lib3dsIo *io);
370 extern void lib3ds_mesh_write(Lib3dsFile *file, Lib3dsMesh *mesh, Lib3dsIo *io);
371 extern void lib3ds_track_read(Lib3dsTrack *track, Lib3dsIo *io);
372 extern void lib3ds_track_write(Lib3dsTrack *track, Lib3dsIo *io);
373 extern void lib3ds_node_read(Lib3dsNode *node, Lib3dsIo *io);
374 extern void lib3ds_node_write(Lib3dsNode *node, uint16_t node_id, uint16_t parent_id, Lib3dsIo *io);
376 typedef void (*Lib3dsFreeFunc)(void *ptr);
378 extern void* lib3ds_util_realloc_array(void *ptr, int old_size, int new_size, int element_size);
379 extern void lib3ds_util_reserve_array(void ***ptr, int *n, int *size, int new_size, int force, Lib3dsFreeFunc free_func);
380 extern void lib3ds_util_insert_array(void ***ptr, int *n, int *size, void *element, int index);
381 extern void lib3ds_util_remove_array(void ***ptr, int *n, int index, Lib3dsFreeFunc free_func);
383 #ifdef __cplusplus
384 }
385 #endif
386 #endif
void lib3ds_io_write_intw(Lib3dsIo *io, int16_t w)
Definition: lib3ds_io.c:368
int16_t lib3ds_io_read_intw(Lib3dsIo *io)
Definition: lib3ds_io.c:203
GLdouble s
Definition: glew.h:1376
else Out of place iCCP chunk
Definition: pngrutil.c:1260
size_t lib3ds_io_read(Lib3dsIo *io, void *buffer, size_t size)
Definition: lib3ds_io.c:72
void lib3ds_io_write_intd(Lib3dsIo *io, int32_t d)
Definition: lib3ds_io.c:384
const char * lib3ds_chunk_name(uint16_t chunk)
void lib3ds_background_write(Lib3dsBackground *background, Lib3dsIo *io)
int32_t lib3ds_io_read_intd(Lib3dsIo *io)
Definition: lib3ds_io.c:219
const GLubyte GLuint GLuint GLuint GLuint alpha GLboolean GLboolean GLboolean GLboolean alpha GLint GLint GLsizei GLsizei GLenum type GLenum GLint GLenum GLint GLint GLsizei GLsizei GLint border GLenum GLint GLint GLint GLint GLint GLsizei GLsizei height GLsizei GLsizei GLenum GLenum const GLvoid *pixels GLenum GLint GLint GLint GLint j2 GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar GLenum light
Definition: SDL_glfuncs.h:144
Definition: glew.h:1824
struct Lib3dsChunk Lib3dsChunk
Definition: lib3ds_impl.h:66
unsigned short uint16_t
GLclampd n
Definition: glew.h:7287
void lib3ds_io_write_error(Lib3dsIo *io)
Definition: lib3ds_io.c:134
void lib3ds_viewport_write(Lib3dsViewport *viewport, Lib3dsIo *io)
void lib3ds_io_write_byte(Lib3dsIo *io, uint8_t b)
Definition: lib3ds_io.c:310
uint32_t cur
Definition: lib3ds_impl.h:299
void lib3ds_io_read_vector(Lib3dsIo *io, float v[3])
Definition: lib3ds_io.c:258
void lib3ds_camera_read(Lib3dsCamera *camera, Lib3dsIo *io)
Definition: lib3ds_camera.c:72
void lib3ds_light_read(Lib3dsLight *light, Lib3dsIo *io)
Definition: lib3ds_light.c:124
FILE * file
Definition: visualinfo.c:88
void lib3ds_viewport_read(Lib3dsViewport *viewport, Lib3dsIo *io)
void lib3ds_node_read(Lib3dsNode *node, Lib3dsIo *io)
Definition: lib3ds_node.c:535
void lib3ds_chunk_unknown(uint16_t chunk, Lib3dsIo *io)
Definition: lib3ds_chunk.c:140
void lib3ds_chunk_read(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:34
void lib3ds_atmosphere_read(Lib3dsAtmosphere *atmosphere, Lib3dsIo *io)
int8_t lib3ds_io_read_intb(Lib3dsIo *io)
Definition: lib3ds_io.c:190
long int32_t
Definition: types.h:9
return Display return Display Bool Bool int d
Definition: SDL_x11sym.h:30
uint32_t lib3ds_io_read_dword(Lib3dsIo *io)
Definition: lib3ds_io.c:172
void lib3ds_io_write_intb(Lib3dsIo *io, int8_t b)
Definition: lib3ds_io.c:356
uint32_t size
Definition: lib3ds_impl.h:297
void lib3ds_shadow_read(Lib3dsShadow *shadow, Lib3dsIo *io)
Definition: lib3ds_shadow.c:22
size_t lib3ds_io_write(Lib3dsIo *io, const void *buffer, size_t size)
Definition: lib3ds_io.c:82
uint16_t lib3ds_chunk_read_next(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:68
void lib3ds_io_read_error(Lib3dsIo *io)
Definition: lib3ds_io.c:128
void lib3ds_track_read(Lib3dsTrack *track, Lib3dsIo *io)
Definition: lib3ds_track.c:422
void lib3ds_mesh_write(Lib3dsFile *file, Lib3dsMesh *mesh, Lib3dsIo *io)
Definition: lib3ds_mesh.c:610
void lib3ds_io_setup(Lib3dsIo *io)
Definition: lib3ds_io.c:28
void lib3ds_io_write_string(Lib3dsIo *io, const char *s)
Definition: lib3ds_io.c:443
void lib3ds_material_write(Lib3dsMaterial *material, Lib3dsIo *io)
void lib3ds_chunk_write_start(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:119
EGLContext EGLenum EGLClientBuffer buffer
Definition: eglext.h:87
void lib3ds_io_write_vector(Lib3dsIo *io, float v[3])
Definition: lib3ds_io.c:422
uint8_t lib3ds_io_read_byte(Lib3dsIo *io)
Definition: lib3ds_io.c:143
long lib3ds_io_tell(Lib3dsIo *io)
Definition: lib3ds_io.c:62
void lib3ds_io_write_float(Lib3dsIo *io, float l)
Definition: lib3ds_io.c:402
const GLdouble * v
Definition: glew.h:1377
void lib3ds_node_write(Lib3dsNode *node, uint16_t node_id, uint16_t parent_id, Lib3dsIo *io)
Definition: lib3ds_node.c:797
Definition: lib3ds.h:43
void lib3ds_chunk_read_reset(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:90
jmp_buf jmpbuf
Definition: lib3ds_impl.h:315
void lib3ds_light_write(Lib3dsLight *light, Lib3dsIo *io)
Definition: lib3ds_light.c:190
uint32_t end
Definition: lib3ds_impl.h:298
void(* Lib3dsFreeFunc)(void *ptr)
Definition: lib3ds_impl.h:376
const GLfloat * c
Definition: glew.h:14913
struct Lib3dsIoImpl Lib3dsIoImpl
void * lib3ds_util_realloc_array(void *ptr, int old_size, int new_size, int element_size)
Definition: lib3ds_util.c:21
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl2ext.h:845
uint16_t lib3ds_io_read_word(Lib3dsIo *io)
Definition: lib3ds_io.c:156
Definition: lib3ds.h:49
GLuint index
Definition: glew.h:1800
void lib3ds_material_read(Lib3dsMaterial *material, Lib3dsIo *io)
float lib3ds_io_read_float(Lib3dsIo *io)
Definition: lib3ds_io.c:237
short int16_t
Definition: types.h:8
void lib3ds_chunk_read_end(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:96
void lib3ds_io_cleanup(Lib3dsIo *io)
Definition: lib3ds_io.c:35
void lib3ds_chunk_read_tell(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:62
void lib3ds_io_log_indent(Lib3dsIo *io, int indent)
Definition: lib3ds_io.c:119
unsigned char uint8_t
unsigned int uint32_t
GLdouble l
Definition: glew.h:8383
void * tmp_mem
Definition: lib3ds_impl.h:317
signed char int8_t
void lib3ds_io_read_string(Lib3dsIo *io, char *s, int buflen)
Definition: lib3ds_io.c:285
GLintptr offset
Definition: glew.h:1668
void lib3ds_util_reserve_array(void ***ptr, int *n, int *size, int new_size, int force, Lib3dsFreeFunc free_func)
Definition: lib3ds_util.c:34
void lib3ds_io_read_rgb(Lib3dsIo *io, float rgb[3])
Definition: lib3ds_io.c:267
void lib3ds_util_remove_array(void ***ptr, int *n, int index, Lib3dsFreeFunc free_func)
Definition: lib3ds_util.c:79
void lib3ds_util_insert_array(void ***ptr, int *n, int *size, void *element, int index)
Definition: lib3ds_util.c:53
void lib3ds_io_log(Lib3dsIo *io, Lib3dsLogLevel level, const char *format,...)
Definition: lib3ds_io.c:100
void lib3ds_chunk_write(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:111
GLint level
Definition: gl2ext.h:845
void lib3ds_shadow_write(Lib3dsShadow *shadow, Lib3dsIo *io)
Definition: lib3ds_shadow.c:56
void lib3ds_chunk_read_start(Lib3dsChunk *c, uint16_t chunk, Lib3dsIo *io)
Definition: lib3ds_chunk.c:50
Lib3dsNode * tmp_node
Definition: lib3ds_impl.h:318
GLdouble GLdouble GLdouble b
Definition: glew.h:8383
GLint GLint GLint GLint GLint w
Definition: gl2ext.h:1215
void lib3ds_background_read(Lib3dsBackground *background, Lib3dsIo *io)
long lib3ds_io_seek(Lib3dsIo *io, long offset, Lib3dsIoSeek origin)
Definition: lib3ds_io.c:52
uint16_t chunk
Definition: lib3ds_impl.h:296
void lib3ds_track_write(Lib3dsTrack *track, Lib3dsIo *io)
Definition: lib3ds_track.c:501
void lib3ds_io_write_dword(Lib3dsIo *io, uint32_t d)
Definition: lib3ds_io.c:338
void lib3ds_camera_write(Lib3dsCamera *camera, Lib3dsIo *io)
void lib3ds_mesh_read(Lib3dsFile *file, Lib3dsMesh *mesh, Lib3dsIo *io)
Definition: lib3ds_mesh.c:311
void lib3ds_io_write_rgb(Lib3dsIo *io, float rgb[3])
Definition: lib3ds_io.c:431
void lib3ds_chunk_write_end(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:129
void lib3ds_atmosphere_write(Lib3dsAtmosphere *atmosphere, Lib3dsIo *io)
GLsizei size
Definition: gl2ext.h:1467
void lib3ds_io_write_word(Lib3dsIo *io, uint16_t w)
Definition: lib3ds_io.c:322