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