1 /* -*- c -*- */
2 #ifndef INCLUDED_LIB3DS_H
3 #define INCLUDED_LIB3DS_H
4 /*
5     Copyright (C) 1996-2008 by Jan Eric Kyprianidis <www.kyprianidis.com>
6     All rights reserved.
7 
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.
12 
13     Thisprogram  is  distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     GNU Lesser General Public License for more details.
17 
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  */
21 
22 /** @file lib3ds.h
23     Header file for public API defined by lib3ds */
24 
25 #include <stddef.h>
26 
27 #ifndef LIB3DSAPI
28     #if defined(_MSC_VER) && !defined(LIB3DS_STATIC)
29         #ifdef LIB3DS_EXPORTS
30             #define LIB3DSAPI __declspec(dllexport)
31         #else
32             #define LIB3DSAPI __declspec(dllimport)
33         #endif
34     #else
35         #define LIB3DSAPI
36     #endif
37 #endif
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /** @defgroup api API
44 	lib3ds public API. */
45 /** @{ */
46 
47 typedef enum Lib3dsIoSeek {
48     LIB3DS_SEEK_SET     = 0,
49     LIB3DS_SEEK_CUR     = 1,
50     LIB3DS_SEEK_END     = 2
51 } Lib3dsIoSeek;
52 
53 typedef enum Lib3dsLogLevel {
54     LIB3DS_LOG_ERROR    = 0,
55     LIB3DS_LOG_WARN     = 1,
56     LIB3DS_LOG_INFO     = 2,
57     LIB3DS_LOG_DEBUG    = 3
58 } Lib3dsLogLevel;
59 
60 typedef struct Lib3dsIo {
61     void*   impl;
62     void*   self;
63     long    (*seek_func) (void *self, long offset, Lib3dsIoSeek origin);
64     long    (*tell_func) (void *self);
65     size_t  (*read_func) (void *self, void *buffer, size_t size);
66     size_t  (*write_func)(void *self, const void *buffer, size_t size);
67     void    (*log_func)  (void *self, Lib3dsLogLevel level, int indent, const char *msg);
68 } Lib3dsIo;
69 
70 /* Atmosphere settings */
71 typedef struct Lib3dsAtmosphere {
72     int         use_fog;
73     float       fog_color[3];
74     int         fog_background;
75     float       fog_near_plane;
76     float       fog_near_density;
77     float       fog_far_plane;
78     float       fog_far_density;
79     int         use_layer_fog;
80     unsigned    layer_fog_flags;
81     float       layer_fog_color[3];
82     float       layer_fog_near_y;
83     float       layer_fog_far_y;
84     float       layer_fog_density;
85     int         use_dist_cue;
86     int         dist_cue_background;     /* bool */
87     float       dist_cue_near_plane;
88     float       dist_cue_near_dimming;
89     float       dist_cue_far_plane;
90     float       dist_cue_far_dimming;
91 } Lib3dsAtmosphere;
92 
93 /* Background settings */
94 typedef struct Lib3dsBackground {
95     int         use_bitmap;
96     char        bitmap_name[64];
97     int         use_solid;
98     float       solid_color[3];
99     int         use_gradient;
100     float       gradient_percent;
101     float       gradient_top[3];
102     float       gradient_middle[3];
103     float       gradient_bottom[3];
104 } Lib3dsBackground;
105 
106 /** Shadow settings */
107 typedef struct Lib3dsShadow {
108     short       map_size;           /**< Global shadow map size that ranges from 10 to 4096 */
109     float       low_bias;           /**< Global shadow low bias */
110     float       hi_bias;            /**< Global shadow hi bias */
111     float       filter;             /**< Global shadow filter that ranges from 1 (lowest) to 10 (highest) */
112     float       ray_bias;           /**< Global raytraced shadow bias */
113 } Lib3dsShadow;
114 
115 /* Layout view types */
116 typedef enum Lib3dsViewType {
117     LIB3DS_VIEW_NOT_USED   = 0,
118     LIB3DS_VIEW_TOP        = 1,
119     LIB3DS_VIEW_BOTTOM     = 2,
120     LIB3DS_VIEW_LEFT       = 3,
121     LIB3DS_VIEW_RIGHT      = 4,
122     LIB3DS_VIEW_FRONT      = 5,
123     LIB3DS_VIEW_BACK       = 6,
124     LIB3DS_VIEW_USER       = 7,
125     LIB3DS_VIEW_SPOTLIGHT  = 18,
126     LIB3DS_VIEW_CAMERA     = 65535
127 } Lib3dsViewType;
128 
129 /* Layout styles */
130 typedef enum Lib3dsLayoutStyle {
131     LIB3DS_LAYOUT_SINGLE                    = 0,
132     LIB3DS_LAYOUT_TWO_PANE_VERT_SPLIT       = 1,
133     LIB3DS_LAYOUT_TWO_PANE_HORIZ_SPLIT      = 2,
134     LIB3DS_LAYOUT_FOUR_PANE                 = 3,
135     LIB3DS_LAYOUT_THREE_PANE_LEFT_SPLIT     = 4,
136     LIB3DS_LAYOUT_THREE_PANE_BOTTOM_SPLIT   = 5,
137     LIB3DS_LAYOUT_THREE_PANE_RIGHT_SPLIT    = 6,
138     LIB3DS_LAYOUT_THREE_PANE_TOP_SPLIT      = 7,
139     LIB3DS_LAYOUT_THREE_PANE_VERT_SPLIT     = 8,
140     LIB3DS_LAYOUT_THREE_PANE_HORIZ_SPLIT    = 9,
141     LIB3DS_LAYOUT_FOUR_PANE_LEFT_SPLIT      = 10,
142     LIB3DS_LAYOUT_FOUR_PANE_RIGHT_SPLIT     = 11
143 } Lib3dsLayoutStyle;
144 
145 /* Layout view settings */
146 typedef struct Lib3dsView {
147     int         type;
148     unsigned    axis_lock;
149     short       position[2];
150     short       size[2];
151     float       zoom;
152     float       center[3];
153     float       horiz_angle;
154     float       vert_angle;
155     char        camera[11];
156 } Lib3dsView;
157 
158 #define LIB3DS_LAYOUT_MAX_VIEWS 32
159 
160 /* Viewport and default view settings */
161 typedef struct Lib3dsViewport {
162     int             layout_style;
163     int             layout_active;
164     int             layout_swap;
165     int             layout_swap_prior;
166     int             layout_swap_view;
167     unsigned short  layout_position[2];
168     unsigned short  layout_size[2];
169     int             layout_nviews;
170     Lib3dsView      layout_views[LIB3DS_LAYOUT_MAX_VIEWS];
171     int             default_type;
172     float           default_position[3];
173     float           default_width;
174     float           default_horiz_angle;
175     float           default_vert_angle;
176     float           default_roll_angle;
177     char            default_camera[64];
178 } Lib3dsViewport;
179 
180 /* Material texture map flags */
181 typedef enum Lib3dsTextureMapFlags {
182     LIB3DS_TEXTURE_DECALE       = 0x0001,
183     LIB3DS_TEXTURE_MIRROR       = 0x0002,
184     LIB3DS_TEXTURE_NEGATE       = 0x0008,
185     LIB3DS_TEXTURE_NO_TILE      = 0x0010,
186     LIB3DS_TEXTURE_SUMMED_AREA  = 0x0020,
187     LIB3DS_TEXTURE_ALPHA_SOURCE = 0x0040,
188     LIB3DS_TEXTURE_TINT         = 0x0080,
189     LIB3DS_TEXTURE_IGNORE_ALPHA = 0x0100,
190     LIB3DS_TEXTURE_RGB_TINT     = 0x0200
191 } Lib3dsTextureMapFlags;
192 
193 /* Material texture map */
194 typedef struct Lib3dsTextureMap {
195     unsigned    user_id;
196     void*       user_ptr;
197     char        name[64];
198     unsigned    flags;
199     float       percent;
200     float       blur;
201     float       scale[2];
202     float       offset[2];
203     float       rotation;
204     float       tint_1[3];
205     float       tint_2[3];
206     float       tint_r[3];
207     float       tint_g[3];
208     float       tint_b[3];
209 } Lib3dsTextureMap;
210 
211 /* Auto reflection texture map flags */
212 typedef enum Lib3dsAutoReflMapFlags {
213     LIB3DS_AUTOREFL_USE                     = 0x0001,
214     LIB3DS_AUTOREFL_READ_FIRST_FRAME_ONLY   = 0x0004,
215     LIB3DS_AUTOREFL_FLAT_MIRROR             = 0x0008
216 } Lib3dsAutoReflMapFlags;
217 
218 /* Material shading type */
219 typedef enum Lib3dsShading {
220     LIB3DS_SHADING_WIRE_FRAME = 0,
221     LIB3DS_SHADING_FLAT       = 1,
222     LIB3DS_SHADING_GOURAUD    = 2,
223     LIB3DS_SHADING_PHONG      = 3,
224     LIB3DS_SHADING_METAL      = 4
225 } Lib3dsShading;
226 
227 /** Material */
228 typedef struct Lib3dsMaterial {
229     unsigned            user_id;
230     void*               user_ptr;
231     char                name[64];           /* Material name */
232     float               ambient[3];         /* Material ambient reflectivity */
233     float               diffuse[3];         /* Material diffuse reflectivity */
234     float               specular[3];        /* Material specular reflectivity */
235     float               shininess;          /* Material specular exponent */
236     float               shin_strength;
237     int                 use_blur;
238     float               blur;
239     float               transparency;
240     float               falloff;
241     int                 is_additive;
242     int                 self_illum_flag; /* bool */
243     float               self_illum;
244     int                 use_falloff;
245     int                 shading;
246     int                 soften;         /* bool */
247     int                 face_map;       /* bool */
248     int                 two_sided;      /* Material visible from back */
249     int                 map_decal;      /* bool */
250     int                 use_wire;
251     int                 use_wire_abs;
252     float               wire_size;
253     Lib3dsTextureMap    texture1_map;
254     Lib3dsTextureMap    texture1_mask;
255     Lib3dsTextureMap    texture2_map;
256     Lib3dsTextureMap    texture2_mask;
257     Lib3dsTextureMap    opacity_map;
258     Lib3dsTextureMap    opacity_mask;
259     Lib3dsTextureMap    bump_map;
260     Lib3dsTextureMap    bump_mask;
261     Lib3dsTextureMap    specular_map;
262     Lib3dsTextureMap    specular_mask;
263     Lib3dsTextureMap    shininess_map;
264     Lib3dsTextureMap    shininess_mask;
265     Lib3dsTextureMap    self_illum_map;
266     Lib3dsTextureMap    self_illum_mask;
267     Lib3dsTextureMap    reflection_map;
268     Lib3dsTextureMap    reflection_mask;
269     unsigned            autorefl_map_flags;
270     int                 autorefl_map_anti_alias;  /* 0=None, 1=Low, 2=Medium, 3=High */
271     int                 autorefl_map_size;
272     int                 autorefl_map_frame_step;
273 } Lib3dsMaterial;
274 
275 /** Object flags for cameras, lights and meshes */
276 typedef enum Lib3dsObjectFlags {
277     LIB3DS_OBJECT_HIDDEN          = 0x01,
278     LIB3DS_OBJECT_VIS_LOFTER      = 0x02,
279     LIB3DS_OBJECT_DOESNT_CAST     = 0x04,
280     LIB3DS_OBJECT_MATTE           = 0x08,
281     LIB3DS_OBJECT_DONT_RCVSHADOW  = 0x10,
282     LIB3DS_OBJECT_FAST            = 0x20,
283     LIB3DS_OBJECT_FROZEN          = 0x40
284 } Lib3dsObjectFlags;
285 
286 /** Camera object */
287 typedef struct Lib3dsCamera {
288     unsigned    user_id;
289     void*       user_ptr;
290     char        name[64];
291     unsigned    object_flags; /*< @see Lib3dsObjectFlags */
292     float       position[3];
293     float       target[3];
294     float       roll;
295     float       fov;
296     int         see_cone;
297     float       near_range;
298     float       far_range;
299 } Lib3dsCamera;
300 
301 /** Light object */
302 typedef struct Lib3dsLight {
303     unsigned    user_id;
304     void*       user_ptr;
305     char        name[64];
306     unsigned    object_flags;
307     int         spot_light;     /* bool */
308     int         see_cone;
309     float       color[3];
310     float       position[3];
311     float       target[3];
312     float       roll;
313     int         off;              /* bool */
314     float       outer_range;
315     float       inner_range;
316     float       multiplier;
317     /*const char**  excludes;*/
318     float       attenuation;
319     int         rectangular_spot;   /* bool */
320     int         shadowed;           /* bool */
321     float       shadow_bias;
322     float       shadow_filter;
323     int         shadow_size;
324     float       spot_aspect;
325     int         use_projector;
326     char        projector[64];
327     int         spot_overshoot;      /* bool */
328     int         ray_shadows;         /* bool */
329     float       ray_bias;
330     float       hotspot;
331     float       falloff;
332 } Lib3dsLight;
333 
334 /* Texture map projection */
335 typedef enum {
336   LIB3DS_MAP_NONE           = -1,
337   LIB3DS_MAP_PLANAR         = 0,
338   LIB3DS_MAP_CYLINDRICAL    = 1,
339   LIB3DS_MAP_SPHERICAL      = 2
340 } Lib3dsMapType;
341 
342 /**  Meaning of Lib3dsFace::flags. ABC are points of the current face
343     (A: is 1st vertex, B is 2nd vertex, C is 3rd vertex) */
344 typedef enum Lib3dsFaceFlags {
345   LIB3DS_FACE_VIS_AC    = 0x01,       /**< Bit 0: Edge visibility AC */
346   LIB3DS_FACE_VIS_BC    = 0x02,       /**< Bit 1: Edge visibility BC */
347   LIB3DS_FACE_VIS_AB    = 0x04,       /**< Bit 2: Edge visibility AB */
348   LIB3DS_FACE_WRAP_U    = 0x08,       /**< Bit 3: Face is at tex U wrap seam */
349   LIB3DS_FACE_WRAP_V    = 0x10,       /**< Bit 4: Face is at tex V wrap seam */
350   LIB3DS_FACE_SELECT_3  = (1<<13),    /**< Bit 13: Selection of the face in selection 3*/
351   LIB3DS_FACE_SELECT_2  = (1<<14),    /**< Bit 14: Selection of the face in selection 2*/
352   LIB3DS_FACE_SELECT_1  = (1<<15),    /**< Bit 15: Selection of the face in selection 1*/
353 } Lib3dsFaceFlags;
354 
355 typedef struct Lib3dsFace {
356     unsigned short  index[3];
357     unsigned short  flags;
358     int             material;
359     unsigned        smoothing_group;
360 } Lib3dsFace;
361 
362 /* Triangular mesh object */
363 typedef struct Lib3dsMesh {
364     unsigned        user_id;
365     void*           user_ptr;
366     char            name[64];            /**< Mesh name. Don't use more than 8 characters  */
367     unsigned        object_flags;        /**< @see Lib3dsObjectFlags */
368     int             color;               /**< Index to editor palette [0..255] */
369     float           matrix[4][4];        /**< Transformation matrix for mesh data */
370     unsigned short  nvertices;           /**< Number of vertices in vertex array (max. 65535) */
371     float           (*vertices)[3];
372     float           (*texcos)[2];
373     unsigned short* vflags;
374     unsigned short  nfaces;              /**< Number of faces in face array (max. 65535) */
375     Lib3dsFace*     faces;
376     char            box_front[64];
377     char            box_back[64];
378     char            box_left[64];
379     char            box_right[64];
380     char            box_top[64];
381     char            box_bottom[64];
382     int             map_type;
383     float           map_pos[3];
384     float           map_matrix[4][4];
385     float           map_scale;
386     float           map_tile[2];
387     float           map_planar_size[2];
388     float           map_cylinder_height;
389 } Lib3dsMesh;
390 
391 typedef enum Lib3dsNodeType {
392     LIB3DS_NODE_AMBIENT_COLOR   = 0,
393     LIB3DS_NODE_MESH_INSTANCE   = 1,
394     LIB3DS_NODE_CAMERA          = 2,
395     LIB3DS_NODE_CAMERA_TARGET   = 3,
396     LIB3DS_NODE_OMNILIGHT       = 4,
397     LIB3DS_NODE_SPOTLIGHT       = 5,
398     LIB3DS_NODE_SPOTLIGHT_TARGET= 6
399 } Lib3dsNodeType;
400 
401 typedef enum Lib3dsNodeFlags{
402     LIB3DS_NODE_HIDDEN           = 0x000800,
403     LIB3DS_NODE_SHOW_PATH        = 0x010000,
404     LIB3DS_NODE_SMOOTHING        = 0x020000,
405     LIB3DS_NODE_MOTION_BLUR      = 0x100000,
406     LIB3DS_NODE_MORPH_MATERIALS  = 0x400000
407 } Lib3dsNodeFlags;
408 
409 typedef struct Lib3dsNode {
410     unsigned            user_id;
411     void*               user_ptr;
412     struct Lib3dsNode*  next;
413     struct Lib3dsNode*  childs;
414     struct Lib3dsNode*  parent;
415     Lib3dsNodeType      type;
416     unsigned short      node_id;            /**< 0..65535 */
417     char                name[64];
418     unsigned            flags;
419     float               matrix[4][4];
420 } Lib3dsNode;
421 
422 typedef enum Lib3dsKeyFlags {
423     LIB3DS_KEY_USE_TENS         = 0x01,
424     LIB3DS_KEY_USE_CONT         = 0x02,
425     LIB3DS_KEY_USE_BIAS         = 0x04,
426     LIB3DS_KEY_USE_EASE_TO      = 0x08,
427     LIB3DS_KEY_USE_EASE_FROM    = 0x10
428 } Lib3dsKeyFlags;
429 
430 typedef struct Lib3dsKey {
431     int         frame;
432     unsigned    flags;
433     float       tens;
434     float       cont;
435     float       bias;
436     float       ease_to;
437     float       ease_from;
438     float       value[4];
439 } Lib3dsKey;
440 
441 typedef enum Lib3dsTrackType {
442     LIB3DS_TRACK_BOOL   = 0,
443     LIB3DS_TRACK_FLOAT  = 1,
444     LIB3DS_TRACK_VECTOR = 3,
445     LIB3DS_TRACK_QUAT   = 4
446 } Lib3dsTrackType;
447 
448 typedef enum {
449     LIB3DS_TRACK_REPEAT   = 0x0001,
450     LIB3DS_TRACK_SMOOTH   = 0x0002,
451     LIB3DS_TRACK_LOCK_X   = 0x0008,
452     LIB3DS_TRACK_LOCK_Y   = 0x0010,
453     LIB3DS_TRACK_LOCK_Z   = 0x0020,
454     LIB3DS_TRACK_UNLINK_X = 0x0100,
455     LIB3DS_TRACK_UNLINK_Y = 0x0200,
456     LIB3DS_TRACK_UNLINK_Z = 0x0400
457 } Lib3dsTrackFlags;
458 
459 typedef struct Lib3dsTrack {
460     unsigned        flags;
461     Lib3dsTrackType type;
462     int             nkeys;
463     Lib3dsKey*      keys;
464 } Lib3dsTrack;
465 
466 typedef struct Lib3dsAmbientColorNode {
467     Lib3dsNode      base;
468     float           color[3];
469     Lib3dsTrack     color_track;
470 } Lib3dsAmbientColorNode;
471 
472 typedef struct Lib3dsMeshInstanceNode {
473     Lib3dsNode      base;
474     float           pivot[3];
475     char            instance_name[64];
476     float           bbox_min[3];
477     float           bbox_max[3];
478     int             hide;
479     float           pos[3];
480     float           rot[4];
481     float           scl[3];
482     float           morph_smooth;
483     char            morph[64];
484     Lib3dsTrack     pos_track;
485     Lib3dsTrack     rot_track;
486     Lib3dsTrack     scl_track;
487     Lib3dsTrack     hide_track;
488 } Lib3dsMeshInstanceNode;
489 
490 typedef struct Lib3dsCameraNode {
491     Lib3dsNode      base;
492     float           pos[3];
493     float           fov;
494     float           roll;
495     Lib3dsTrack     pos_track;
496     Lib3dsTrack     fov_track;
497     Lib3dsTrack     roll_track;
498 } Lib3dsCameraNode;
499 
500 typedef struct Lib3dsTargetNode {
501     Lib3dsNode      base;
502     float           pos[3];
503     Lib3dsTrack     pos_track;
504 } Lib3dsTargetNode;
505 
506 typedef struct Lib3dsOmnilightNode {
507     Lib3dsNode      base;
508     float           pos[3];
509     float           color[3];
510     Lib3dsTrack     pos_track;
511     Lib3dsTrack     color_track;
512 } Lib3dsOmnilightNode;
513 
514 typedef struct Lib3dsSpotlightNode {
515     Lib3dsNode      base;
516     float           pos[3];
517     float           color[3];
518     float           hotspot;
519     float           falloff;
520     float           roll;
521     Lib3dsTrack     pos_track;
522     Lib3dsTrack     color_track;
523     Lib3dsTrack     hotspot_track;
524     Lib3dsTrack     falloff_track;
525     Lib3dsTrack     roll_track;
526 } Lib3dsSpotlightNode;
527 
528 typedef struct Lib3dsFile {
529     unsigned            user_id;
530     void*               user_ptr;
531     unsigned            mesh_version;
532     unsigned            keyf_revision;
533     char                name[12+1];
534     float               master_scale;
535     float               construction_plane[3];
536     float               ambient[3];
537     Lib3dsShadow        shadow;
538     Lib3dsBackground    background;
539     Lib3dsAtmosphere    atmosphere;
540     Lib3dsViewport      viewport;
541     Lib3dsViewport      viewport_keyf;
542     int                 frames;
543     int                 segment_from;
544     int                 segment_to;
545     int                 current_frame;
546     int                 materials_size;
547     int                 nmaterials;
548     Lib3dsMaterial**    materials;
549     int                 cameras_size;
550     int                 ncameras;
551     Lib3dsCamera**      cameras;
552     int                 lights_size;
553     int                 nlights;
554     Lib3dsLight**       lights;
555     int                 meshes_size;
556     int                 nmeshes;
557     Lib3dsMesh**        meshes;
558     Lib3dsNode*         nodes;
559 } Lib3dsFile;
560 
561 extern LIB3DSAPI Lib3dsFile* lib3ds_file_open(const char *filename);
562 extern LIB3DSAPI int lib3ds_file_save(Lib3dsFile *file, const char *filename);
563 extern LIB3DSAPI Lib3dsFile* lib3ds_file_new();
564 extern LIB3DSAPI void lib3ds_file_free(Lib3dsFile *file);
565 extern LIB3DSAPI void lib3ds_file_eval(Lib3dsFile *file, float t);
566 extern LIB3DSAPI int lib3ds_file_read(Lib3dsFile *file, Lib3dsIo *io);
567 extern LIB3DSAPI int lib3ds_file_write(Lib3dsFile *file, Lib3dsIo *io);
568 extern LIB3DSAPI void lib3ds_file_reserve_materials(Lib3dsFile *file, int size, int force);
569 extern LIB3DSAPI void lib3ds_file_insert_material(Lib3dsFile *file, Lib3dsMaterial *material, int index);
570 extern LIB3DSAPI void lib3ds_file_remove_material(Lib3dsFile *file, int index);
571 extern LIB3DSAPI int lib3ds_file_material_by_name(Lib3dsFile *file, const char *name);
572 extern LIB3DSAPI void lib3ds_file_reserve_cameras(Lib3dsFile *file, int size, int force);
573 extern LIB3DSAPI void lib3ds_file_insert_camera(Lib3dsFile *file, Lib3dsCamera *camera, int index);
574 extern LIB3DSAPI void lib3ds_file_remove_camera(Lib3dsFile *file, int index);
575 extern LIB3DSAPI int lib3ds_file_camera_by_name(Lib3dsFile *file, const char *name);
576 extern LIB3DSAPI void lib3ds_file_reserve_lights(Lib3dsFile *file, int size, int force);
577 extern LIB3DSAPI void lib3ds_file_insert_light(Lib3dsFile *file, Lib3dsLight *light, int index);
578 extern LIB3DSAPI void lib3ds_file_remove_light(Lib3dsFile *file, int index);
579 extern LIB3DSAPI int lib3ds_file_light_by_name(Lib3dsFile *file, const char *name);
580 extern LIB3DSAPI void lib3ds_file_reserve_meshes(Lib3dsFile *file, int size, int force);
581 extern LIB3DSAPI void lib3ds_file_insert_mesh(Lib3dsFile *file, Lib3dsMesh *mesh, int index);
582 extern LIB3DSAPI void lib3ds_file_remove_mesh(Lib3dsFile *file, int index);
583 extern LIB3DSAPI int lib3ds_file_mesh_by_name(Lib3dsFile *file, const char *name);
584 extern LIB3DSAPI Lib3dsMesh* lib3ds_file_mesh_for_node(Lib3dsFile *file, Lib3dsNode *node);
585 extern LIB3DSAPI Lib3dsNode* lib3ds_file_node_by_name(Lib3dsFile *file, const char* name, Lib3dsNodeType type);
586 extern LIB3DSAPI Lib3dsNode* lib3ds_file_node_by_id(Lib3dsFile *file, unsigned short node_id);
587 extern LIB3DSAPI void lib3ds_file_append_node(Lib3dsFile *file, Lib3dsNode *node, Lib3dsNode *parent);
588 extern LIB3DSAPI void lib3ds_file_insert_node(Lib3dsFile *file, Lib3dsNode *node, Lib3dsNode *at);
589 extern LIB3DSAPI void lib3ds_file_remove_node(Lib3dsFile *file, Lib3dsNode *node);
590 extern LIB3DSAPI void lib3ds_file_minmax_node_id(Lib3dsFile *file, unsigned short *min_id, unsigned short *max_id);
591 extern LIB3DSAPI void lib3ds_file_create_nodes_for_meshes(Lib3dsFile *file);
592 
593 
594 /**
595     This function computes the bounding box of meshes, cameras
596     and lights defined in the 3D editor.
597 
598     \param file             The Lib3dsFile object to be examined.
599     \param include_meshes   Include meshes in bounding box calculation.
600     \param include_cameras  Include cameras in bounding box calculation.
601     \param include_lights   Include lights in bounding box calculation.
602     \param bmin             Returned minimum x,y,z values.
603     \param bmax             Returned maximum x,y,z values.
604  */
605 extern LIB3DSAPI void lib3ds_file_bounding_box_of_objects(
606     Lib3dsFile *file,
607     int include_meshes,
608     int include_cameras,
609     int include_lights,
610     float bmin[3],
611     float bmax[3]);
612 
613 /**
614     This function computes the bounding box of mesh, camera
615     and light instances defined in the Keyframer.
616 
617     \param file             The Lib3dsFile object to be examined.
618     \param include_meshes   Include meshes in bounding box calculation.
619     \param include_cameras  Include cameras in bounding box calculation.
620     \param include_lights   Include lights in bounding box calculation.
621     \param bmin             Returned minimum x,y,z values.
622     \param bmax             Returned maximum x,y,z values.
623     \param matrix           A matrix describing the coordinate system to
624                             calculate the bounding box in.
625  */
626 extern LIB3DSAPI void lib3ds_file_bounding_box_of_nodes(
627     Lib3dsFile *file,
628     int include_meshes,
629     int include_cameras,
630     int include_lights,
631     float bmin[3],
632     float bmax[3],
633     float matrix[4][4]);
634 
635 extern LIB3DSAPI Lib3dsMaterial* lib3ds_material_new(const char *name);
636 extern LIB3DSAPI void lib3ds_material_free(Lib3dsMaterial *material);
637 extern LIB3DSAPI Lib3dsCamera* lib3ds_camera_new(const char *name);
638 extern LIB3DSAPI void lib3ds_camera_free(Lib3dsCamera *mesh);
639 extern LIB3DSAPI Lib3dsLight* lib3ds_light_new(const char *name);
640 extern LIB3DSAPI void lib3ds_light_free(Lib3dsLight *mesh);
641 extern LIB3DSAPI Lib3dsMesh* lib3ds_mesh_new(const char *name);
642 extern LIB3DSAPI void lib3ds_mesh_free(Lib3dsMesh *mesh);
643 extern LIB3DSAPI void lib3ds_mesh_resize_vertices(Lib3dsMesh *mesh, int nvertices, int use_texcos, int use_flags);
644 extern LIB3DSAPI void lib3ds_mesh_resize_faces(Lib3dsMesh *mesh, int nfaces);
645 extern LIB3DSAPI void lib3ds_mesh_bounding_box(Lib3dsMesh *mesh, float bmin[3], float bmax[3]);
646 extern LIB3DSAPI void lib3ds_mesh_calculate_face_normals(Lib3dsMesh *mesh, float (*face_normals)[3]);
647 extern LIB3DSAPI void lib3ds_mesh_calculate_vertex_normals(Lib3dsMesh *mesh, float (*normals)[3]);
648 
649 extern LIB3DSAPI Lib3dsNode* lib3ds_node_new(Lib3dsNodeType type);
650 extern LIB3DSAPI Lib3dsAmbientColorNode* lib3ds_node_new_ambient_color(float color0[3]);
651 extern LIB3DSAPI Lib3dsMeshInstanceNode* lib3ds_node_new_mesh_instance(Lib3dsMesh *mesh, const char* instance_name, float pos0[3], float scl0[3], float rot0[4]);
652 extern LIB3DSAPI Lib3dsCameraNode* lib3ds_node_new_camera(Lib3dsCamera *camera);
653 extern LIB3DSAPI Lib3dsTargetNode* lib3ds_node_new_camera_target(Lib3dsCamera *camera);
654 extern LIB3DSAPI Lib3dsOmnilightNode* lib3ds_node_new_omnilight(Lib3dsLight *light);
655 extern LIB3DSAPI Lib3dsSpotlightNode* lib3ds_node_new_spotlight(Lib3dsLight *light);
656 extern LIB3DSAPI Lib3dsTargetNode* lib3ds_node_new_spotlight_target(Lib3dsLight *light);
657 extern LIB3DSAPI void lib3ds_node_free(Lib3dsNode *node);
658 extern LIB3DSAPI void lib3ds_node_eval(Lib3dsNode *node, float t);
659 extern LIB3DSAPI Lib3dsNode* lib3ds_node_by_name(Lib3dsNode *node, const char* name, Lib3dsNodeType type);
660 extern LIB3DSAPI Lib3dsNode* lib3ds_node_by_id(Lib3dsNode *node, unsigned short node_id);
661 
662 extern LIB3DSAPI Lib3dsTrack* lib3ds_track_new(Lib3dsTrackType type, int nkeys);
663 extern LIB3DSAPI void lib3ds_track_free(Lib3dsTrack *track);
664 extern LIB3DSAPI void lib3ds_track_resize(Lib3dsTrack *track, int nkeys);
665 extern LIB3DSAPI void lib3ds_track_eval_bool(Lib3dsTrack *track, int *b, float t);
666 extern LIB3DSAPI void lib3ds_track_eval_float(Lib3dsTrack *track, float *f, float t);
667 extern LIB3DSAPI void lib3ds_track_eval_vector(Lib3dsTrack *track, float v[3], float t);
668 extern LIB3DSAPI void lib3ds_track_eval_quat(Lib3dsTrack *track, float q[4], float t);
669 
670 /**
671     Calculates the ease in/out function. See Lib3dsKey for details.
672 
673     \param fp           Previous frame number.
674     \param fc           Current frame number.
675     \param fn           Next frame number.
676     \param ease_from    Ease in value [0, 1.0]
677     \param ease_to      Ease out value [0, 1.0]
678 */
679 extern LIB3DSAPI float lib3ds_math_ease(
680     float fp,
681     float fc,
682     float fn,
683     float ease_from,
684     float ease_to);
685 
686 /**
687     Computes a point on a n-dimensional cubic hermite spline.
688     \param v
689         [out] Result
690     \param a
691         [in] First point of the spline.
692     \param p
693         [in] Tangent at the first point of the spline.
694     \param q
695         [in] Tangent at the second point of the spline.
696     \param b
697         [in] Second point of the spline.
698     \param n
699         [in] Dimension
700     \param t
701         [in] Parameter value [0...1]
702 */
703 extern LIB3DSAPI void lib3ds_math_cubic_interp(
704     float *v,
705     float *a,
706     float *p,
707     float *q,
708     float *b,
709     int n,
710     float t);
711 
712 extern LIB3DSAPI void lib3ds_vector_make(
713     float c[3],
714     float x,
715     float y,
716     float z);
717 
718 /**
719     Sets all components of a vector to zero.
720     \param c
721         The Pointer to the vector.
722 */
723 extern LIB3DSAPI void lib3ds_vector_zero(
724     float c[3]);
725 
726 /**
727     Copies all components of a vector to another vector.
728     \param dst
729         [out] The destination vector.
730     \param src
731         [in] The source vector.
732 */
733 extern LIB3DSAPI void lib3ds_vector_copy(
734     float dst[3],
735     float src[3]);
736 
737 /**
738     Negates all components of a vector.
739     \param c
740         The Pointer to the vector.
741 */
742 extern LIB3DSAPI void lib3ds_vector_neg(
743     float c[3]);
744 
745 extern LIB3DSAPI void lib3ds_vector_make(float c[3], float x, float y, float z);
746 extern LIB3DSAPI void lib3ds_vector_zero(float c[3]);
747 extern LIB3DSAPI void lib3ds_vector_add(float c[3], float a[3], float b[3]);
748 extern LIB3DSAPI void lib3ds_vector_sub(float c[3], float a[3], float b[3]);
749 extern LIB3DSAPI void lib3ds_vector_scalar_mul(float c[3], float a[3], float k);
750 extern LIB3DSAPI void lib3ds_vector_cross(float c[3], float a[3], float b[3]);
751 extern LIB3DSAPI float lib3ds_vector_dot(float a[3], float b[3]);
752 extern LIB3DSAPI float lib3ds_vector_length(float c[3]);
753 extern LIB3DSAPI void lib3ds_vector_normalize(float c[3]);
754 extern LIB3DSAPI void lib3ds_vector_normal(float n[3], float a[3], float b[3], float c[3]);
755 extern LIB3DSAPI void lib3ds_vector_min(float c[3], float a[3]);
756 extern LIB3DSAPI void lib3ds_vector_max(float c[3], float a[3]);
757 extern LIB3DSAPI void lib3ds_vector_transform(float c[3], float m[4][4], float a[3]);
758 
759 extern LIB3DSAPI void lib3ds_quat_identity(float c[4]);
760 extern LIB3DSAPI void lib3ds_quat_copy(float dest[4], float src[4]);
761 extern LIB3DSAPI void lib3ds_quat_axis_angle(float c[4], float axis[3], float angle);
762 extern LIB3DSAPI void lib3ds_quat_neg(float c[4]);
763 extern LIB3DSAPI void lib3ds_quat_cnj(float c[4]);
764 extern LIB3DSAPI void lib3ds_quat_mul(float c[4], float a[4], float b[4]);
765 extern LIB3DSAPI void lib3ds_quat_scalar(float c[4], float k);
766 extern LIB3DSAPI void lib3ds_quat_normalize(float c[4]);
767 extern LIB3DSAPI void lib3ds_quat_inv(float c[4]);
768 extern LIB3DSAPI float lib3ds_quat_dot(float a[4], float b[4]);
769 extern LIB3DSAPI float lib3ds_quat_norm(float c[4]);
770 extern LIB3DSAPI void lib3ds_quat_ln(float c[4]);
771 extern LIB3DSAPI void lib3ds_quat_ln_dif(float c[4], float a[4], float b[4]);
772 extern LIB3DSAPI void lib3ds_quat_exp(float c[4]);
773 extern LIB3DSAPI void lib3ds_quat_slerp(float c[4], float a[4], float b[4], float t);
774 extern LIB3DSAPI void lib3ds_quat_squad(float c[4], float a[4], float p[4], float q[4], float b[4], float t);
775 extern LIB3DSAPI void lib3ds_quat_tangent(float c[4], float p[4], float q[4], float n[4]);
776 
777 extern LIB3DSAPI void lib3ds_matrix_zero(float m[4][4]);
778 extern LIB3DSAPI void lib3ds_matrix_identity(float  m[4][4]);
779 extern LIB3DSAPI void lib3ds_matrix_copy(float dest[4][4], float src[4][4]);
780 extern LIB3DSAPI void lib3ds_matrix_neg(float m[4][4]);
781 extern LIB3DSAPI void lib3ds_matrix_transpose(float m[4][4]);
782 extern LIB3DSAPI void lib3ds_matrix_add(float m[4][4], float a[4][4], float b[4][4]);
783 extern LIB3DSAPI void lib3ds_matrix_sub(float m[4][4], float a[4][4], float b[4][4]);
784 extern LIB3DSAPI void lib3ds_matrix_mult(float m[4][4], float a[4][4], float b[4][4]);
785 extern LIB3DSAPI void lib3ds_matrix_scalar(float m[4][4], float k);
786 extern LIB3DSAPI float lib3ds_matrix_det(float m[4][4]);
787 extern LIB3DSAPI int lib3ds_matrix_inv(float m[4][4]);
788 extern LIB3DSAPI void lib3ds_matrix_translate(float m[4][4], float x, float y, float z);
789 extern LIB3DSAPI void lib3ds_matrix_scale(float m[4][4], float x, float y, float z);
790 extern LIB3DSAPI void lib3ds_matrix_rotate_quat(float m[4][4], float q[4]);
791 extern LIB3DSAPI void lib3ds_matrix_rotate(float m[4][4], float angle, float ax, float ay, float az);
792 extern LIB3DSAPI void lib3ds_matrix_camera(float m[4][4], float pos[3], float tgt[3], float roll);
793 
794 /** @} */
795 #ifdef __cplusplus
796 }
797 #endif
798 #endif
799 
800