static Lib3dsBool named_object_read(Lib3dsFile *file, Lib3dsIo *io) { Lib3dsChunk c; char name[64]; Lib3dsWord chunk; Lib3dsMesh *mesh = NULL; Lib3dsCamera *camera = NULL; Lib3dsLight *light = NULL; Lib3dsDword object_flags; if (!lib3ds_chunk_read_start(&c, LIB3DS_NAMED_OBJECT, io)) { return(LIB3DS_FALSE); } if (!lib3ds_io_read_string(io, name, 64)) { return(LIB3DS_FALSE); } lib3ds_chunk_dump_info(" NAME=%s", name); lib3ds_chunk_read_tell(&c, io); object_flags = 0; while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) { switch (chunk) { case LIB3DS_N_TRI_OBJECT: { mesh=lib3ds_mesh_new(name); if (!mesh) { return(LIB3DS_FALSE); } lib3ds_chunk_read_reset(&c, io); if (!lib3ds_mesh_read(mesh, io)) { return(LIB3DS_FALSE); } lib3ds_file_insert_mesh(file, mesh); } break; case LIB3DS_N_CAMERA: { camera=lib3ds_camera_new(name); if (!camera) { return(LIB3DS_FALSE); } lib3ds_chunk_read_reset(&c, io); if (!lib3ds_camera_read(camera, io)) { return(LIB3DS_FALSE); } lib3ds_file_insert_camera(file, camera); } break; case LIB3DS_N_DIRECT_LIGHT: { light=lib3ds_light_new(name); if (!light) { return(LIB3DS_FALSE); } lib3ds_chunk_read_reset(&c, io); if (!lib3ds_light_read(light, io)) { return(LIB3DS_FALSE); } lib3ds_file_insert_light(file, light); } break; case LIB3DS_OBJ_HIDDEN: object_flags |= LIB3DS_OBJECT_HIDDEN; break; case LIB3DS_OBJ_DOESNT_CAST: object_flags |= LIB3DS_OBJECT_DOESNT_CAST; break; case LIB3DS_OBJ_VIS_LOFTER: object_flags |= LIB3DS_OBJECT_VIS_LOFTER; break; case LIB3DS_OBJ_MATTE: object_flags |= LIB3DS_OBJECT_MATTE; break; case LIB3DS_OBJ_DONT_RCVSHADOW: object_flags |= LIB3DS_OBJECT_DONT_RCVSHADOW; break; case LIB3DS_OBJ_FAST: object_flags |= LIB3DS_OBJECT_FAST; break; case LIB3DS_OBJ_FROZEN: object_flags |= LIB3DS_OBJECT_FROZEN; break; default: lib3ds_chunk_unknown(chunk); } } if (mesh) mesh->object_flags = object_flags; if (camera) camera->object_flags = object_flags; if (light) light->object_flags = object_flags; lib3ds_chunk_read_end(&c, io); return(LIB3DS_TRUE); }
static Lib3dsBool mdata_read(Lib3dsFile *file, Lib3dsIo *io) { Lib3dsChunk c; Lib3dsWord chunk; if (!lib3ds_chunk_read_start(&c, LIB3DS_MDATA, io)) { return(LIB3DS_FALSE); } while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) { switch (chunk) { case LIB3DS_MESH_VERSION: { file->mesh_version=lib3ds_io_read_intd(io); } break; case LIB3DS_MASTER_SCALE: { file->master_scale=lib3ds_io_read_float(io); } break; case LIB3DS_SHADOW_MAP_SIZE: case LIB3DS_LO_SHADOW_BIAS: case LIB3DS_HI_SHADOW_BIAS: case LIB3DS_SHADOW_SAMPLES: case LIB3DS_SHADOW_RANGE: case LIB3DS_SHADOW_FILTER: case LIB3DS_RAY_BIAS: { lib3ds_chunk_read_reset(&c, io); if (!lib3ds_shadow_read(&file->shadow, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_VIEWPORT_LAYOUT: case LIB3DS_DEFAULT_VIEW: { lib3ds_chunk_read_reset(&c, io); if (!lib3ds_viewport_read(&file->viewport, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_O_CONSTS: { int i; for (i=0; i<3; ++i) { file->construction_plane[i]=lib3ds_io_read_float(io); } } break; case LIB3DS_AMBIENT_LIGHT: { lib3ds_chunk_read_reset(&c, io); if (!ambient_read(file, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_BIT_MAP: case LIB3DS_SOLID_BGND: case LIB3DS_V_GRADIENT: case LIB3DS_USE_BIT_MAP: case LIB3DS_USE_SOLID_BGND: case LIB3DS_USE_V_GRADIENT: { lib3ds_chunk_read_reset(&c, io); if (!lib3ds_background_read(&file->background, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_FOG: case LIB3DS_LAYER_FOG: case LIB3DS_DISTANCE_CUE: case LIB3DS_USE_FOG: case LIB3DS_USE_LAYER_FOG: case LIB3DS_USE_DISTANCE_CUE: { lib3ds_chunk_read_reset(&c, io); if (!lib3ds_atmosphere_read(&file->atmosphere, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_ENTRY: { Lib3dsMaterial *material; material=lib3ds_material_new(); if (!material) { return(LIB3DS_FALSE); } lib3ds_chunk_read_reset(&c, io); if (!lib3ds_material_read(material, io)) { return(LIB3DS_FALSE); } lib3ds_file_insert_material(file, material); } break; case LIB3DS_NAMED_OBJECT: { lib3ds_chunk_read_reset(&c, io); if (!named_object_read(file, io)) { return(LIB3DS_FALSE); } } break; default: lib3ds_chunk_unknown(chunk); } } lib3ds_chunk_read_end(&c, io); return(LIB3DS_TRUE); }
/*! * \ingroup light */ static Lib3dsBool spotlight_read(Lib3dsLight *light, Lib3dsIo *io) { Lib3dsChunk c; Lib3dsWord chunk; int i; if (!lib3ds_chunk_read_start(&c, LIB3DS_DL_SPOTLIGHT, io)) { return(LIB3DS_FALSE); } light->spot_light=LIB3DS_TRUE; for (i=0; i<3; ++i) { light->spot[i]=lib3ds_io_read_float(io); } light->hot_spot = lib3ds_io_read_float(io); light->fall_off = lib3ds_io_read_float(io); lib3ds_chunk_read_tell(&c, io); while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) { switch (chunk) { case LIB3DS_DL_SPOT_ROLL: { light->roll=lib3ds_io_read_float(io); } break; case LIB3DS_DL_SHADOWED: { light->shadowed=LIB3DS_TRUE; } break; case LIB3DS_DL_LOCAL_SHADOW2: { light->shadow_bias=lib3ds_io_read_float(io); light->shadow_filter=lib3ds_io_read_float(io); light->shadow_size=lib3ds_io_read_intw(io); } break; case LIB3DS_DL_SEE_CONE: { light->see_cone=LIB3DS_TRUE; } break; case LIB3DS_DL_SPOT_RECTANGULAR: { light->rectangular_spot=LIB3DS_TRUE; } break; case LIB3DS_DL_SPOT_ASPECT: { light->spot_aspect=lib3ds_io_read_float(io); } break; case LIB3DS_DL_SPOT_PROJECTOR: { light->use_projector=LIB3DS_TRUE; if (!lib3ds_io_read_string(io, light->projector, 64)) { return(LIB3DS_FALSE); } } case LIB3DS_DL_SPOT_OVERSHOOT: { light->spot_overshoot=LIB3DS_TRUE; } break; case LIB3DS_DL_RAY_BIAS: { light->ray_bias=lib3ds_io_read_float(io); } break; case LIB3DS_DL_RAYSHAD: { light->ray_shadows=LIB3DS_TRUE; } break; default: lib3ds_chunk_unknown(chunk); } } lib3ds_chunk_read_end(&c, io); return(LIB3DS_TRUE); }
/*! * \ingroup node */ Lib3dsBool lib3ds_node_read(Lib3dsNode *node, Lib3dsFile *file, Lib3dsIo *io) { Lib3dsChunk c; Lib3dsWord chunk; ASSERT(node); if (!lib3ds_chunk_read_start(&c, 0, io)) { return(LIB3DS_FALSE); } switch (c.chunk) { case LIB3DS_AMBIENT_NODE_TAG: case LIB3DS_OBJECT_NODE_TAG: case LIB3DS_CAMERA_NODE_TAG: case LIB3DS_TARGET_NODE_TAG: case LIB3DS_LIGHT_NODE_TAG: case LIB3DS_SPOTLIGHT_NODE_TAG: case LIB3DS_L_TARGET_NODE_TAG: break; default: return(LIB3DS_FALSE); } while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) { switch (chunk) { case LIB3DS_NODE_ID: { node->node_id=lib3ds_io_read_word(io); lib3ds_chunk_dump_info(" ID = %d", (short)node->node_id); } break; case LIB3DS_NODE_HDR: { if (!lib3ds_io_read_string(io, node->name, 64)) { return(LIB3DS_FALSE); } node->flags1=lib3ds_io_read_word(io); node->flags2=lib3ds_io_read_word(io); node->parent_id=lib3ds_io_read_word(io); lib3ds_chunk_dump_info(" NAME =%s", node->name); lib3ds_chunk_dump_info(" PARENT=%d", (short)node->parent_id); } break; case LIB3DS_PIVOT: { if (node->type==LIB3DS_OBJECT_NODE) { int i; for (i=0; i<3; ++i) { node->data.object.pivot[i]=lib3ds_io_read_float(io); } } else { lib3ds_chunk_unknown(chunk); } } break; case LIB3DS_INSTANCE_NAME: { if (node->type==LIB3DS_OBJECT_NODE) { if (!lib3ds_io_read_string(io, node->data.object.instance, 64)) { return(LIB3DS_FALSE); } } else { lib3ds_chunk_unknown(chunk); } } break; case LIB3DS_BOUNDBOX: { if (node->type==LIB3DS_OBJECT_NODE) { int i; for (i=0; i<3; ++i) { node->data.object.bbox_min[i]=lib3ds_io_read_float(io); } for (i=0; i<3; ++i) { node->data.object.bbox_max[i]=lib3ds_io_read_float(io); } } else { lib3ds_chunk_unknown(chunk); } } break; case LIB3DS_COL_TRACK_TAG: { Lib3dsBool result=LIB3DS_TRUE; switch (node->type) { case LIB3DS_AMBIENT_NODE: result=lib3ds_lin3_track_read(&node->data.ambient.col_track, io); break; case LIB3DS_LIGHT_NODE: result=lib3ds_lin3_track_read(&node->data.light.col_track, io); break; default: lib3ds_chunk_unknown(chunk); } if (!result) { return(LIB3DS_FALSE); } } break; case LIB3DS_POS_TRACK_TAG: { Lib3dsBool result=LIB3DS_TRUE; switch (node->type) { case LIB3DS_OBJECT_NODE: result=lib3ds_lin3_track_read(&node->data.object.pos_track, io); break; case LIB3DS_CAMERA_NODE: result=lib3ds_lin3_track_read(&node->data.camera.pos_track, io); break; case LIB3DS_TARGET_NODE: result=lib3ds_lin3_track_read(&node->data.target.pos_track, io); break; case LIB3DS_LIGHT_NODE: result=lib3ds_lin3_track_read(&node->data.light.pos_track, io); break; case LIB3DS_SPOT_NODE: result=lib3ds_lin3_track_read(&node->data.spot.pos_track, io); break; default: lib3ds_chunk_unknown(chunk); } if (!result) { return(LIB3DS_FALSE); } } break; case LIB3DS_ROT_TRACK_TAG: { if (node->type==LIB3DS_OBJECT_NODE) { if (!lib3ds_quat_track_read(&node->data.object.rot_track, io)) { return(LIB3DS_FALSE); } } else { lib3ds_chunk_unknown(chunk); } } break; case LIB3DS_SCL_TRACK_TAG: { if (node->type==LIB3DS_OBJECT_NODE) { if (!lib3ds_lin3_track_read(&node->data.object.scl_track, io)) { return(LIB3DS_FALSE); } } else { lib3ds_chunk_unknown(chunk); } } break; case LIB3DS_FOV_TRACK_TAG: { if (node->type==LIB3DS_CAMERA_NODE) { if (!lib3ds_lin1_track_read(&node->data.camera.fov_track, io)) { return(LIB3DS_FALSE); } } else { lib3ds_chunk_unknown(chunk); } } break; case LIB3DS_HOT_TRACK_TAG: { if (node->type==LIB3DS_LIGHT_NODE) { if (!lib3ds_lin1_track_read(&node->data.light.hotspot_track, io)) { return(LIB3DS_FALSE); } } else { lib3ds_chunk_unknown(chunk); } } break; case LIB3DS_FALL_TRACK_TAG: { if (node->type==LIB3DS_LIGHT_NODE) { if (!lib3ds_lin1_track_read(&node->data.light.falloff_track, io)) { return(LIB3DS_FALSE); } } else { lib3ds_chunk_unknown(chunk); } } break; case LIB3DS_ROLL_TRACK_TAG: { Lib3dsBool result=LIB3DS_TRUE; switch (node->type) { case LIB3DS_CAMERA_NODE: result=lib3ds_lin1_track_read(&node->data.camera.roll_track, io); break; case LIB3DS_LIGHT_NODE: result=lib3ds_lin1_track_read(&node->data.light.roll_track, io); break; default: lib3ds_chunk_unknown(chunk); } if (!result) { return(LIB3DS_FALSE); } } break; case LIB3DS_HIDE_TRACK_TAG: { if (node->type==LIB3DS_OBJECT_NODE) { if (!lib3ds_bool_track_read(&node->data.object.hide_track, io)) { return(LIB3DS_FALSE); } } else { lib3ds_chunk_unknown(chunk); } } break; case LIB3DS_MORPH_SMOOTH: { if (node->type==LIB3DS_OBJECT_NODE) { node->data.object.morph_smooth=lib3ds_io_read_float(io); } else { lib3ds_chunk_unknown(chunk); } } break; case LIB3DS_MORPH_TRACK_TAG: { if (node->type==LIB3DS_OBJECT_NODE) { if (!lib3ds_morph_track_read(&node->data.object.morph_track, io)) { return(LIB3DS_FALSE); } } else { lib3ds_chunk_unknown(chunk); } } break; default: lib3ds_chunk_unknown(chunk); } } lib3ds_chunk_read_end(&c, io); return(LIB3DS_TRUE); }
void lib3ds_mesh_read(Lib3dsFile *file, Lib3dsMesh *mesh, Lib3dsIo *io) { Lib3dsChunk c; uint16_t chunk; lib3ds_chunk_read_start(&c, CHK_N_TRI_OBJECT, io); while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) { switch (chunk) { case CHK_MESH_MATRIX: { int i, j; lib3ds_matrix_identity(mesh->matrix); for (i = 0; i < 4; i++) { for (j = 0; j < 3; j++) { mesh->matrix[i][j] = lib3ds_io_read_float(io); } } break; } case CHK_MESH_COLOR: { mesh->color = lib3ds_io_read_byte(io); break; } case CHK_POINT_ARRAY: { int i; uint16_t nvertices = lib3ds_io_read_word(io); lib3ds_mesh_resize_vertices(mesh, nvertices, mesh->texcos != NULL, mesh->vflags != NULL); for (i = 0; i < mesh->nvertices; ++i) { lib3ds_io_read_vector(io, mesh->vertices[i]); } break; } case CHK_POINT_FLAG_ARRAY: { int i; uint16_t nflags = lib3ds_io_read_word(io); uint16_t nvertices = (mesh->nvertices >= nflags)? mesh->nvertices : nflags; lib3ds_mesh_resize_vertices(mesh, nvertices, mesh->texcos != NULL, 1); for (i = 0; i < nflags; ++i) { mesh->vflags[i] = lib3ds_io_read_word(io); } break; } case CHK_FACE_ARRAY: { lib3ds_chunk_read_reset(&c, io); face_array_read(file, mesh, io); break; } case CHK_MESH_TEXTURE_INFO: { int i, j; //FIXME: mesh->map_type = lib3ds_io_read_word(io); for (i = 0; i < 2; ++i) { mesh->map_tile[i] = lib3ds_io_read_float(io); } for (i = 0; i < 3; ++i) { mesh->map_pos[i] = lib3ds_io_read_float(io); } mesh->map_scale = lib3ds_io_read_float(io); lib3ds_matrix_identity(mesh->map_matrix); for (i = 0; i < 4; i++) { for (j = 0; j < 3; j++) { mesh->map_matrix[i][j] = lib3ds_io_read_float(io); } } for (i = 0; i < 2; ++i) { mesh->map_planar_size[i] = lib3ds_io_read_float(io); } mesh->map_cylinder_height = lib3ds_io_read_float(io); break; } case CHK_TEX_VERTS: { int i; uint16_t ntexcos = lib3ds_io_read_word(io); uint16_t nvertices = (mesh->nvertices >= ntexcos)? mesh->nvertices : ntexcos;; if (!mesh->texcos) { lib3ds_mesh_resize_vertices(mesh, nvertices, 1, mesh->vflags != NULL); } for (i = 0; i < ntexcos; ++i) { mesh->texcos[i][0] = lib3ds_io_read_float(io); mesh->texcos[i][1] = lib3ds_io_read_float(io); } break; } default: lib3ds_chunk_unknown(chunk, io); } } if (lib3ds_matrix_det(mesh->matrix) < 0.0) { /* Flip X coordinate of vertices if mesh matrix has negative determinant */ float inv_matrix[4][4], M[4][4]; float tmp[3]; int i; lib3ds_matrix_copy(inv_matrix, mesh->matrix); lib3ds_matrix_inv(inv_matrix); lib3ds_matrix_copy(M, mesh->matrix); lib3ds_matrix_scale(M, -1.0f, 1.0f, 1.0f); lib3ds_matrix_mult(M, M, inv_matrix); for (i = 0; i < mesh->nvertices; ++i) { lib3ds_vector_transform(tmp, M, mesh->vertices[i]); lib3ds_vector_copy(mesh->vertices[i], tmp); } } lib3ds_chunk_read_end(&c, io); }
/*! * \ingroup light */ Lib3dsBool lib3ds_light_read(Lib3dsLight *light, Lib3dsIo *io) { Lib3dsChunk c; Lib3dsWord chunk; if (!lib3ds_chunk_read_start(&c, LIB3DS_N_DIRECT_LIGHT, io)) { return(LIB3DS_FALSE); } { int i; for (i=0; i<3; ++i) { light->position[i]=lib3ds_io_read_float(io); } } lib3ds_chunk_read_tell(&c, io); while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) { switch (chunk) { case LIB3DS_COLOR_F: { int i; for (i=0; i<3; ++i) { light->color[i]=lib3ds_io_read_float(io); } } break; case LIB3DS_DL_OFF: { light->off=LIB3DS_TRUE; } break; case LIB3DS_DL_OUTER_RANGE: { light->outer_range=lib3ds_io_read_float(io); } break; case LIB3DS_DL_INNER_RANGE: { light->inner_range=lib3ds_io_read_float(io); } break; case LIB3DS_DL_MULTIPLIER: { light->multiplier=lib3ds_io_read_float(io); } break; case LIB3DS_DL_EXCLUDE: { /* FIXME: */ lib3ds_chunk_unknown(chunk); } case LIB3DS_DL_ATTENUATE: { light->attenuation=lib3ds_io_read_float(io); } break; case LIB3DS_DL_SPOTLIGHT: { lib3ds_chunk_read_reset(&c, io); if (!spotlight_read(light, io)) { return(LIB3DS_FALSE); } } break; default: lib3ds_chunk_unknown(chunk); } } lib3ds_chunk_read_end(&c, io); return(LIB3DS_TRUE); }
/*! * \ingroup viewport */ Lib3dsBool lib3ds_viewport_read(Lib3dsViewport *viewport, Lib3dsIo *io) { Lib3dsChunk c; Lib3dsWord chunk; if (!lib3ds_chunk_read_start(&c, 0, io)) { return(LIB3DS_FALSE); } switch (c.chunk) { case LIB3DS_VIEWPORT_LAYOUT: { int cur=0; viewport->layout.style=lib3ds_io_read_word(io); viewport->layout.active=lib3ds_io_read_intw(io); lib3ds_io_read_intw(io); viewport->layout.swap=lib3ds_io_read_intw(io); lib3ds_io_read_intw(io); viewport->layout.swap_prior=lib3ds_io_read_intw(io); viewport->layout.swap_view=lib3ds_io_read_intw(io); lib3ds_chunk_read_tell(&c, io); while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) { switch (chunk) { case LIB3DS_VIEWPORT_SIZE: { viewport->layout.position[0]=lib3ds_io_read_word(io); viewport->layout.position[1]=lib3ds_io_read_word(io); viewport->layout.size[0]=lib3ds_io_read_word(io); viewport->layout.size[1]=lib3ds_io_read_word(io); } break; case LIB3DS_VIEWPORT_DATA_3: { lib3ds_viewport_set_views(viewport,cur+1); lib3ds_io_read_intw(io); viewport->layout.viewL[cur].axis_lock=lib3ds_io_read_word(io); viewport->layout.viewL[cur].position[0]=lib3ds_io_read_intw(io); viewport->layout.viewL[cur].position[1]=lib3ds_io_read_intw(io); viewport->layout.viewL[cur].size[0]=lib3ds_io_read_intw(io); viewport->layout.viewL[cur].size[1]=lib3ds_io_read_intw(io); viewport->layout.viewL[cur].type=lib3ds_io_read_word(io); viewport->layout.viewL[cur].zoom=lib3ds_io_read_float(io); lib3ds_io_read_vector(io, viewport->layout.viewL[cur].center); viewport->layout.viewL[cur].horiz_angle=lib3ds_io_read_float(io); viewport->layout.viewL[cur].vert_angle=lib3ds_io_read_float(io); lib3ds_io_read(io, viewport->layout.viewL[cur].camera, 11); ++cur; } break; case LIB3DS_VIEWPORT_DATA: /* 3DS R2 & R3 chunk unsupported */ break; default: lib3ds_chunk_unknown(chunk); } } } break; case LIB3DS_DEFAULT_VIEW: { memset(&viewport->default_view,0,sizeof(Lib3dsDefaultView)); while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) { switch (chunk) { case LIB3DS_VIEW_TOP: { viewport->default_view.type=LIB3DS_VIEW_TYPE_TOP; lib3ds_io_read_vector(io, viewport->default_view.position); viewport->default_view.width=lib3ds_io_read_float(io); } break; case LIB3DS_VIEW_BOTTOM: { viewport->default_view.type=LIB3DS_VIEW_TYPE_BOTTOM; lib3ds_io_read_vector(io, viewport->default_view.position); viewport->default_view.width=lib3ds_io_read_float(io); } break; case LIB3DS_VIEW_LEFT: { viewport->default_view.type=LIB3DS_VIEW_TYPE_LEFT; lib3ds_io_read_vector(io, viewport->default_view.position); viewport->default_view.width=lib3ds_io_read_float(io); } break; case LIB3DS_VIEW_RIGHT: { viewport->default_view.type=LIB3DS_VIEW_TYPE_RIGHT; lib3ds_io_read_vector(io, viewport->default_view.position); viewport->default_view.width=lib3ds_io_read_float(io); } break; case LIB3DS_VIEW_FRONT: { viewport->default_view.type=LIB3DS_VIEW_TYPE_FRONT; lib3ds_io_read_vector(io, viewport->default_view.position); viewport->default_view.width=lib3ds_io_read_float(io); } break; case LIB3DS_VIEW_BACK: { viewport->default_view.type=LIB3DS_VIEW_TYPE_BACK; lib3ds_io_read_vector(io, viewport->default_view.position); viewport->default_view.width=lib3ds_io_read_float(io); } break; case LIB3DS_VIEW_USER: { viewport->default_view.type=LIB3DS_VIEW_TYPE_USER; lib3ds_io_read_vector(io, viewport->default_view.position); viewport->default_view.width=lib3ds_io_read_float(io); viewport->default_view.horiz_angle=lib3ds_io_read_float(io); viewport->default_view.vert_angle=lib3ds_io_read_float(io); viewport->default_view.roll_angle=lib3ds_io_read_float(io); } break; case LIB3DS_VIEW_CAMERA: { viewport->default_view.type=LIB3DS_VIEW_TYPE_CAMERA; lib3ds_io_read(io, viewport->default_view.camera, 11); } break; default: lib3ds_chunk_unknown(chunk); } } } break; } lib3ds_chunk_read_end(&c, io); return(LIB3DS_TRUE); }
static Lib3dsBool texture_map_read(Lib3dsTextureMap *map, Lib3dsIo *io) { Lib3dsChunk c; Lib3dsWord chunk; if (!lib3ds_chunk_read_start(&c, 0, io)) { return(LIB3DS_FALSE); } while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) { switch (chunk) { case LIB3DS_INT_PERCENTAGE: { map->percent=1.0f*lib3ds_io_read_intw(io)/100.0f; } break; case LIB3DS_MAT_MAPNAME: { if (!lib3ds_io_read_string(io, map->name, 64)) { return(LIB3DS_FALSE); } lib3ds_chunk_dump_info(" NAME=%s", map->name); } break; case LIB3DS_MAT_MAP_TILING: { map->flags=lib3ds_io_read_word(io); } break; case LIB3DS_MAT_MAP_TEXBLUR: { map->blur=lib3ds_io_read_float(io); } break; case LIB3DS_MAT_MAP_USCALE: { map->scale[0]=lib3ds_io_read_float(io); } break; case LIB3DS_MAT_MAP_VSCALE: { map->scale[1]=lib3ds_io_read_float(io); } break; case LIB3DS_MAT_MAP_UOFFSET: { map->offset[0]=lib3ds_io_read_float(io); } break; case LIB3DS_MAT_MAP_VOFFSET: { map->offset[1]=lib3ds_io_read_float(io); } break; case LIB3DS_MAT_MAP_ANG: { map->rotation=lib3ds_io_read_float(io); } break; case LIB3DS_MAT_MAP_COL1: { map->tint_1[0]=1.0f*lib3ds_io_read_byte(io)/255.0f; map->tint_1[1]=1.0f*lib3ds_io_read_byte(io)/255.0f; map->tint_1[2]=1.0f*lib3ds_io_read_byte(io)/255.0f; } break; case LIB3DS_MAT_MAP_COL2: { map->tint_2[0]=1.0f*lib3ds_io_read_byte(io)/255.0f; map->tint_2[1]=1.0f*lib3ds_io_read_byte(io)/255.0f; map->tint_2[2]=1.0f*lib3ds_io_read_byte(io)/255.0f; } break; case LIB3DS_MAT_MAP_RCOL: { map->tint_r[0]=1.0f*lib3ds_io_read_byte(io)/255.0f; map->tint_r[1]=1.0f*lib3ds_io_read_byte(io)/255.0f; map->tint_r[2]=1.0f*lib3ds_io_read_byte(io)/255.0f; } break; case LIB3DS_MAT_MAP_GCOL: { map->tint_g[0]=1.0f*lib3ds_io_read_byte(io)/255.0f; map->tint_g[1]=1.0f*lib3ds_io_read_byte(io)/255.0f; map->tint_g[2]=1.0f*lib3ds_io_read_byte(io)/255.0f; } break; case LIB3DS_MAT_MAP_BCOL: { map->tint_b[0]=1.0f*lib3ds_io_read_byte(io)/255.0f; map->tint_b[1]=1.0f*lib3ds_io_read_byte(io)/255.0f; map->tint_b[2]=1.0f*lib3ds_io_read_byte(io)/255.0f; } break; default: lib3ds_chunk_unknown(chunk); } } lib3ds_chunk_read_end(&c, io); return(LIB3DS_TRUE); }
static Lib3dsBool face_array_read(Lib3dsMesh *mesh, Lib3dsIo *io) { Lib3dsChunk c; Lib3dsWord chunk; int i; int faces; if (!lib3ds_chunk_read_start(&c, LIB3DS_FACE_ARRAY, io)) { return(LIB3DS_FALSE); } lib3ds_mesh_free_face_list(mesh); faces=lib3ds_io_read_word(io); if (faces) { if (!lib3ds_mesh_new_face_list(mesh, faces)) { LIB3DS_ERROR_LOG; return(LIB3DS_FALSE); } for (i=0; i<faces; ++i) { strcpy(mesh->faceL[i].material, ""); mesh->faceL[i].points[0]=lib3ds_io_read_word(io); mesh->faceL[i].points[1]=lib3ds_io_read_word(io); mesh->faceL[i].points[2]=lib3ds_io_read_word(io); mesh->faceL[i].flags=lib3ds_io_read_word(io); } lib3ds_chunk_read_tell(&c, io); while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) { switch (chunk) { case LIB3DS_SMOOTH_GROUP: { unsigned i; for (i=0; i<mesh->faces; ++i) { mesh->faceL[i].smoothing=lib3ds_io_read_dword(io); } } break; case LIB3DS_MSH_MAT_GROUP: { char name[64]; unsigned faces; unsigned i; unsigned index; if (!lib3ds_io_read_string(io, name, 64)) { return(LIB3DS_FALSE); } faces=lib3ds_io_read_word(io); for (i=0; i<faces; ++i) { index=lib3ds_io_read_word(io); ASSERT(index<mesh->faces); strcpy(mesh->faceL[index].material, name); } } break; case LIB3DS_MSH_BOXMAP: { char name[64]; if (!lib3ds_io_read_string(io, name, 64)) { return(LIB3DS_FALSE); } strcpy(mesh->box_map.front, name); if (!lib3ds_io_read_string(io, name, 64)) { return(LIB3DS_FALSE); } strcpy(mesh->box_map.back, name); if (!lib3ds_io_read_string(io, name, 64)) { return(LIB3DS_FALSE); } strcpy(mesh->box_map.left, name); if (!lib3ds_io_read_string(io, name, 64)) { return(LIB3DS_FALSE); } strcpy(mesh->box_map.right, name); if (!lib3ds_io_read_string(io, name, 64)) { return(LIB3DS_FALSE); } strcpy(mesh->box_map.top, name); if (!lib3ds_io_read_string(io, name, 64)) { return(LIB3DS_FALSE); } strcpy(mesh->box_map.bottom, name); } break; default: lib3ds_chunk_unknown(chunk); } } } lib3ds_chunk_read_end(&c, io); return(LIB3DS_TRUE); }
/*! * \ingroup mesh */ Lib3dsBool lib3ds_mesh_read(Lib3dsMesh *mesh, Lib3dsIo *io) { Lib3dsChunk c; Lib3dsWord chunk; if (!lib3ds_chunk_read_start(&c, LIB3DS_N_TRI_OBJECT, io)) { return(LIB3DS_FALSE); } while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) { switch (chunk) { case LIB3DS_MESH_MATRIX: { int i,j; lib3ds_matrix_identity(mesh->matrix); for (i=0; i<4; i++) { for (j=0; j<3; j++) { mesh->matrix[i][j]=lib3ds_io_read_float(io); } } } break; case LIB3DS_MESH_COLOR: { mesh->color=lib3ds_io_read_byte(io); } break; case LIB3DS_POINT_ARRAY: { unsigned i,j; unsigned points; lib3ds_mesh_free_point_list(mesh); points=lib3ds_io_read_word(io); if (points) { if (!lib3ds_mesh_new_point_list(mesh, points)) { LIB3DS_ERROR_LOG; return(LIB3DS_FALSE); } for (i=0; i<mesh->points; ++i) { for (j=0; j<3; ++j) { mesh->pointL[i].pos[j]=lib3ds_io_read_float(io); } } ASSERT((!mesh->flags) || (mesh->points==mesh->flags)); ASSERT((!mesh->texels) || (mesh->points==mesh->texels)); } } break; case LIB3DS_POINT_FLAG_ARRAY: { unsigned i; unsigned flags; lib3ds_mesh_free_flag_list(mesh); flags=lib3ds_io_read_word(io); if (flags) { if (!lib3ds_mesh_new_flag_list(mesh, flags)) { LIB3DS_ERROR_LOG; return(LIB3DS_FALSE); } for (i=0; i<mesh->flags; ++i) { mesh->flagL[i]=lib3ds_io_read_word(io); } ASSERT((!mesh->points) || (mesh->flags==mesh->points)); ASSERT((!mesh->texels) || (mesh->flags==mesh->texels)); } } break; case LIB3DS_FACE_ARRAY: { lib3ds_chunk_read_reset(&c, io); if (!face_array_read(mesh, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MESH_TEXTURE_INFO: { int i,j; for (i=0; i<2; ++i) { mesh->map_data.tile[i]=lib3ds_io_read_float(io); } for (i=0; i<3; ++i) { mesh->map_data.pos[i]=lib3ds_io_read_float(io); } mesh->map_data.scale=lib3ds_io_read_float(io); lib3ds_matrix_identity(mesh->map_data.matrix); for (i=0; i<4; i++) { for (j=0; j<3; j++) { mesh->map_data.matrix[i][j]=lib3ds_io_read_float(io); } } for (i=0; i<2; ++i) { mesh->map_data.planar_size[i]=lib3ds_io_read_float(io); } mesh->map_data.cylinder_height=lib3ds_io_read_float(io); } break; case LIB3DS_TEX_VERTS: { unsigned i; unsigned texels; lib3ds_mesh_free_texel_list(mesh); texels=lib3ds_io_read_word(io); if (texels) { if (!lib3ds_mesh_new_texel_list(mesh, texels)) { LIB3DS_ERROR_LOG; return(LIB3DS_FALSE); } for (i=0; i<mesh->texels; ++i) { mesh->texelL[i][0]=lib3ds_io_read_float(io); mesh->texelL[i][1]=lib3ds_io_read_float(io); } ASSERT((!mesh->points) || (mesh->texels==mesh->points)); ASSERT((!mesh->flags) || (mesh->texels==mesh->flags)); } } break; default: lib3ds_chunk_unknown(chunk); } } { unsigned j; for (j=0; j<mesh->faces; ++j) { ASSERT(mesh->faceL[j].points[0]<mesh->points); ASSERT(mesh->faceL[j].points[1]<mesh->points); ASSERT(mesh->faceL[j].points[2]<mesh->points); lib3ds_vector_normal( mesh->faceL[j].normal, mesh->pointL[mesh->faceL[j].points[0]].pos, mesh->pointL[mesh->faceL[j].points[1]].pos, mesh->pointL[mesh->faceL[j].points[2]].pos ); } } lib3ds_chunk_read_end(&c, io); return(LIB3DS_TRUE); }
static Lib3dsBool named_object_read(Lib3dsFile *file, Lib3dsIo *io) { Lib3dsChunk c; char name[64]; Lib3dsWord chunk; if (!lib3ds_chunk_read_start(&c, LIB3DS_NAMED_OBJECT, io)) { return(LIB3DS_FALSE); } if (!lib3ds_io_read_string(io, name, 64)) { return(LIB3DS_FALSE); } lib3ds_chunk_dump_info(" NAME=%s", name); lib3ds_chunk_read_tell(&c, io); while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) { switch (chunk) { case LIB3DS_N_TRI_OBJECT: { Lib3dsMesh *mesh; mesh=lib3ds_mesh_new(name); if (!mesh) { return(LIB3DS_FALSE); } lib3ds_chunk_read_reset(&c, io); if (!lib3ds_mesh_read(mesh, io)) { return(LIB3DS_FALSE); } lib3ds_file_insert_mesh(file, mesh); } break; case LIB3DS_N_CAMERA: { Lib3dsCamera *camera; camera=lib3ds_camera_new(name); if (!camera) { return(LIB3DS_FALSE); } lib3ds_chunk_read_reset(&c, io); if (!lib3ds_camera_read(camera, io)) { return(LIB3DS_FALSE); } lib3ds_file_insert_camera(file, camera); } break; case LIB3DS_N_DIRECT_LIGHT: { Lib3dsLight *light; light=lib3ds_light_new(name); if (!light) { return(LIB3DS_FALSE); } lib3ds_chunk_read_reset(&c, io); if (!lib3ds_light_read(light, io)) { return(LIB3DS_FALSE); } lib3ds_file_insert_light(file, light); } break; default: lib3ds_chunk_unknown(chunk); } } lib3ds_chunk_read_end(&c, io); return(LIB3DS_TRUE); }
static void spotlight_read(Lib3dsLight *light, Lib3dsIo *io) { Lib3dsChunk c; uint16_t chunk; int i; lib3ds_chunk_read_start(&c, CHK_DL_SPOTLIGHT, io); light->spot_light = TRUE; for (i = 0; i < 3; ++i) { light->target[i] = lib3ds_io_read_float(io); } light->hotspot = lib3ds_io_read_float(io); light->falloff = lib3ds_io_read_float(io); lib3ds_chunk_read_tell(&c, io); while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) { switch (chunk) { case CHK_DL_SPOT_ROLL: light->roll = lib3ds_io_read_float(io); break; case CHK_DL_SHADOWED: { light->shadowed = TRUE; break; } case CHK_DL_LOCAL_SHADOW2: { light->shadow_bias = lib3ds_io_read_float(io); light->shadow_filter = lib3ds_io_read_float(io); light->shadow_size = lib3ds_io_read_intw(io); break; } case CHK_DL_SEE_CONE: { light->see_cone = TRUE; break; } case CHK_DL_SPOT_RECTANGULAR: { light->rectangular_spot = TRUE; break; } case CHK_DL_SPOT_ASPECT: { light->spot_aspect = lib3ds_io_read_float(io); break; } case CHK_DL_SPOT_PROJECTOR: { light->use_projector = TRUE; lib3ds_io_read_string(io, light->projector, 64); break; } case CHK_DL_SPOT_OVERSHOOT: { light->spot_overshoot = TRUE; break; } case CHK_DL_RAY_BIAS: { light->ray_bias = lib3ds_io_read_float(io); break; } case CHK_DL_RAYSHAD: { light->ray_shadows = TRUE; break; } default: lib3ds_chunk_unknown(chunk, io); } } lib3ds_chunk_read_end(&c, io); }
/*! * \ingroup material */ Lib3dsBool lib3ds_material_read(Lib3dsMaterial *material, Lib3dsIo *io) { Lib3dsChunk c; Lib3dsWord chunk; ASSERT(material); if (!lib3ds_chunk_read_start(&c, LIB3DS_MAT_ENTRY, io)) { return(LIB3DS_FALSE); } while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) { switch (chunk) { case LIB3DS_MAT_NAME: { if (!lib3ds_io_read_string(io, material->name, 64)) { return(LIB3DS_FALSE); } lib3ds_chunk_dump_info(" NAME=%s", material->name); } break; case LIB3DS_MAT_AMBIENT: { lib3ds_chunk_read_reset(&c, io); if (!color_read(material->ambient, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_DIFFUSE: { lib3ds_chunk_read_reset(&c, io); if (!color_read(material->diffuse, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_SPECULAR: { lib3ds_chunk_read_reset(&c, io); if (!color_read(material->specular, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_SHININESS: { lib3ds_chunk_read_reset(&c, io); if (!int_percentage_read(&material->shininess, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_SHIN2PCT: { lib3ds_chunk_read_reset(&c, io); if (!int_percentage_read(&material->shin_strength, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_TRANSPARENCY: { lib3ds_chunk_read_reset(&c, io); if (!int_percentage_read(&material->transparency, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_XPFALL: { lib3ds_chunk_read_reset(&c, io); if (!int_percentage_read(&material->falloff, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_SELF_ILPCT: { lib3ds_chunk_read_reset(&c, io); if (!int_percentage_read(&material->self_ilpct, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_USE_XPFALL: { material->use_falloff=LIB3DS_TRUE; } break; case LIB3DS_MAT_REFBLUR: { lib3ds_chunk_read_reset(&c, io); if (!int_percentage_read(&material->blur, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_USE_REFBLUR: { material->use_blur=LIB3DS_TRUE; } break; case LIB3DS_MAT_SHADING: { material->shading=lib3ds_io_read_intw(io); } break; case LIB3DS_MAT_SELF_ILLUM: { material->self_illum=LIB3DS_TRUE; } break; case LIB3DS_MAT_TWO_SIDE: { material->two_sided=LIB3DS_TRUE; } break; case LIB3DS_MAT_DECAL: { material->map_decal=LIB3DS_TRUE; } break; case LIB3DS_MAT_ADDITIVE: { material->additive=LIB3DS_TRUE; } break; case LIB3DS_MAT_FACEMAP: { material->face_map=LIB3DS_TRUE; } break; case LIB3DS_MAT_PHONGSOFT: { material->soften=LIB3DS_TRUE; } break; case LIB3DS_MAT_WIRE: { material->use_wire=LIB3DS_TRUE; } break; case LIB3DS_MAT_WIREABS: { material->use_wire_abs=LIB3DS_TRUE; } break; case LIB3DS_MAT_WIRE_SIZE: { material->wire_size=lib3ds_io_read_float(io); } break; case LIB3DS_MAT_TEXMAP: { lib3ds_chunk_read_reset(&c, io); if (!texture_map_read(&material->texture1_map, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_TEXMASK: { lib3ds_chunk_read_reset(&c, io); if (!texture_map_read(&material->texture1_mask, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_TEX2MAP: { lib3ds_chunk_read_reset(&c, io); if (!texture_map_read(&material->texture2_map, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_TEX2MASK: { lib3ds_chunk_read_reset(&c, io); if (!texture_map_read(&material->texture2_mask, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_OPACMAP: { lib3ds_chunk_read_reset(&c, io); if (!texture_map_read(&material->opacity_map, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_OPACMASK: { lib3ds_chunk_read_reset(&c, io); if (!texture_map_read(&material->opacity_mask, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_BUMPMAP: { lib3ds_chunk_read_reset(&c, io); if (!texture_map_read(&material->bump_map, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_BUMPMASK: { lib3ds_chunk_read_reset(&c, io); if (!texture_map_read(&material->bump_mask, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_SPECMAP: { lib3ds_chunk_read_reset(&c, io); if (!texture_map_read(&material->specular_map, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_SPECMASK: { lib3ds_chunk_read_reset(&c, io); if (!texture_map_read(&material->specular_mask, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_SHINMAP: { lib3ds_chunk_read_reset(&c, io); if (!texture_map_read(&material->shininess_map, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_SHINMASK: { lib3ds_chunk_read_reset(&c, io); if (!texture_map_read(&material->shininess_mask, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_SELFIMAP: { lib3ds_chunk_read_reset(&c, io); if (!texture_map_read(&material->self_illum_map, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_SELFIMASK: { lib3ds_chunk_read_reset(&c, io); if (!texture_map_read(&material->self_illum_mask, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_REFLMAP: { lib3ds_chunk_read_reset(&c, io); if (!texture_map_read(&material->reflection_map, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_REFLMASK: { lib3ds_chunk_read_reset(&c, io); if (!texture_map_read(&material->reflection_mask, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_MAT_ACUBIC: { lib3ds_io_read_intb(io); material->autorefl_map.level=lib3ds_io_read_intb(io); material->autorefl_map.flags=lib3ds_io_read_intw(io); material->autorefl_map.size=lib3ds_io_read_intd(io); material->autorefl_map.frame_step=lib3ds_io_read_intd(io); } break; default: lib3ds_chunk_unknown(chunk); } } lib3ds_chunk_read_end(&c, io); return(LIB3DS_TRUE); }
static Lib3dsBool kfdata_read(Lib3dsFile *file, Lib3dsIo *io) { Lib3dsChunk c; Lib3dsWord chunk; Lib3dsDword node_number = 0; if (!lib3ds_chunk_read_start(&c, LIB3DS_KFDATA, io)) { return(LIB3DS_FALSE); } while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) { switch (chunk) { case LIB3DS_KFHDR: { file->keyf_revision=lib3ds_io_read_word(io); if (!lib3ds_io_read_string(io, file->name, 12+1)) { return(LIB3DS_FALSE); } file->frames=lib3ds_io_read_intd(io); } break; case LIB3DS_KFSEG: { file->segment_from=lib3ds_io_read_intd(io); file->segment_to=lib3ds_io_read_intd(io); } break; case LIB3DS_KFCURTIME: { file->current_frame=lib3ds_io_read_intd(io); } break; case LIB3DS_VIEWPORT_LAYOUT: case LIB3DS_DEFAULT_VIEW: { lib3ds_chunk_read_reset(&c, io); if (!lib3ds_viewport_read(&file->viewport_keyf, io)) { return(LIB3DS_FALSE); } } break; case LIB3DS_AMBIENT_NODE_TAG: { Lib3dsNode *node; node=lib3ds_node_new_ambient(); if (!node) { return(LIB3DS_FALSE); } node->node_id=node_number++; lib3ds_chunk_read_reset(&c, io); if (!lib3ds_node_read(node, file, io)) { return(LIB3DS_FALSE); } lib3ds_file_insert_node(file, node); } break; case LIB3DS_OBJECT_NODE_TAG: { Lib3dsNode *node; node=lib3ds_node_new_object(); if (!node) { return(LIB3DS_FALSE); } node->node_id=node_number++; lib3ds_chunk_read_reset(&c, io); if (!lib3ds_node_read(node, file, io)) { return(LIB3DS_FALSE); } lib3ds_file_insert_node(file, node); } break; case LIB3DS_CAMERA_NODE_TAG: { Lib3dsNode *node; node=lib3ds_node_new_camera(); if (!node) { return(LIB3DS_FALSE); } node->node_id=node_number++; lib3ds_chunk_read_reset(&c, io); if (!lib3ds_node_read(node, file, io)) { return(LIB3DS_FALSE); } lib3ds_file_insert_node(file, node); } break; case LIB3DS_TARGET_NODE_TAG: { Lib3dsNode *node; node=lib3ds_node_new_target(); if (!node) { return(LIB3DS_FALSE); } node->node_id=node_number++; lib3ds_chunk_read_reset(&c, io); if (!lib3ds_node_read(node, file, io)) { return(LIB3DS_FALSE); } lib3ds_file_insert_node(file, node); } break; case LIB3DS_LIGHT_NODE_TAG: case LIB3DS_SPOTLIGHT_NODE_TAG: { Lib3dsNode *node; node=lib3ds_node_new_light(); if (!node) { return(LIB3DS_FALSE); } node->node_id=node_number++; lib3ds_chunk_read_reset(&c, io); if (!lib3ds_node_read(node, file, io)) { return(LIB3DS_FALSE); } lib3ds_file_insert_node(file, node); } break; case LIB3DS_L_TARGET_NODE_TAG: { Lib3dsNode *node; node=lib3ds_node_new_spot(); if (!node) { return(LIB3DS_FALSE); } node->node_id=node_number++; lib3ds_chunk_read_reset(&c, io); if (!lib3ds_node_read(node, file, io)) { return(LIB3DS_FALSE); } lib3ds_file_insert_node(file, node); } break; default: lib3ds_chunk_unknown(chunk); } } lib3ds_chunk_read_end(&c, io); return(LIB3DS_TRUE); }
static void face_array_read(Lib3dsFile *file, Lib3dsMesh *mesh, Lib3dsIo *io) { Lib3dsChunk c; uint16_t chunk; int i; uint16_t nfaces; lib3ds_chunk_read_start(&c, CHK_FACE_ARRAY, io); lib3ds_mesh_resize_faces(mesh, 0); nfaces = lib3ds_io_read_word(io); if (nfaces) { lib3ds_mesh_resize_faces(mesh, nfaces); for (i = 0; i < nfaces; ++i) { mesh->faces[i].index[0] = lib3ds_io_read_word(io); mesh->faces[i].index[1] = lib3ds_io_read_word(io); mesh->faces[i].index[2] = lib3ds_io_read_word(io); mesh->faces[i].flags = lib3ds_io_read_word(io); } lib3ds_chunk_read_tell(&c, io); while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) { switch (chunk) { case CHK_MSH_MAT_GROUP: { char name[64]; unsigned n; unsigned i; int index; int material; lib3ds_io_read_string(io, name, 64); material = lib3ds_file_material_by_name(file, name); n = lib3ds_io_read_word(io); for (i = 0; i < n; ++i) { index = lib3ds_io_read_word(io); if (index < mesh->nfaces) { mesh->faces[index].material = material; } else { // TODO warning } } break; } case CHK_SMOOTH_GROUP: { int i; for (i = 0; i < mesh->nfaces; ++i) { mesh->faces[i].smoothing_group = lib3ds_io_read_dword(io); } break; } case CHK_MSH_BOXMAP: { lib3ds_io_read_string(io, mesh->box_front, 64); lib3ds_io_read_string(io, mesh->box_back, 64); lib3ds_io_read_string(io, mesh->box_left, 64); lib3ds_io_read_string(io, mesh->box_right, 64); lib3ds_io_read_string(io, mesh->box_top, 64); lib3ds_io_read_string(io, mesh->box_bottom, 64); break; } default: lib3ds_chunk_unknown(chunk,io); } } } lib3ds_chunk_read_end(&c, io); }
void lib3ds_light_read(Lib3dsLight *light, Lib3dsIo *io) { Lib3dsChunk c; uint16_t chunk; lib3ds_chunk_read_start(&c, CHK_N_DIRECT_LIGHT, io); { int i; for (i = 0; i < 3; ++i) { light->position[i] = lib3ds_io_read_float(io); } } lib3ds_chunk_read_tell(&c, io); while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) { switch (chunk) { case CHK_COLOR_F: { int i; for (i = 0; i < 3; ++i) { light->color[i] = lib3ds_io_read_float(io); } break; } case CHK_DL_OFF: light->off = TRUE; break; case CHK_DL_OUTER_RANGE: light->outer_range = lib3ds_io_read_float(io); break; case CHK_DL_INNER_RANGE: light->inner_range = lib3ds_io_read_float(io); break; case CHK_DL_MULTIPLIER: light->multiplier = lib3ds_io_read_float(io); break; case CHK_DL_EXCLUDE: { /* FIXME: */ lib3ds_chunk_unknown(chunk, io); break; } case CHK_DL_ATTENUATE: light->attenuation = lib3ds_io_read_float(io); break; case CHK_DL_SPOTLIGHT: { lib3ds_chunk_read_reset(&c, io); spotlight_read(light, io); break; } default: lib3ds_chunk_unknown(chunk, io); } } lib3ds_chunk_read_end(&c, io); }
static Lib3dsBool color_read(Lib3dsRgba rgb, Lib3dsIo *io) { Lib3dsChunk c; Lib3dsWord chunk; Lib3dsBool have_lin=LIB3DS_FALSE; if (!lib3ds_chunk_read_start(&c, 0, io)) { return(LIB3DS_FALSE); } while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) { switch (chunk) { case LIB3DS_LIN_COLOR_24: { int i; for (i=0; i<3; ++i) { rgb[i]=1.0f*lib3ds_io_read_byte(io)/255.0f; } rgb[3]=1.0f; } have_lin=LIB3DS_TRUE; break; case LIB3DS_COLOR_24: /* gamma corrected color chunk replaced in 3ds R3 by LIN_COLOR_24 */ if (!have_lin) { int i; for (i=0; i<3; ++i) { rgb[i]=1.0f*lib3ds_io_read_byte(io)/255.0f; } rgb[3]=1.0f; } break; case LIB3DS_LIN_COLOR_F: { int i; for (i=0; i<3; ++i) { rgb[i]=lib3ds_io_read_float(io); } rgb[3]=1.0f; } have_lin=LIB3DS_TRUE; break; case LIB3DS_COLOR_F: if (!have_lin) { int i; for (i=0; i<3; ++i) { rgb[i]=lib3ds_io_read_float(io); } rgb[3]=1.0f; } break; default: lib3ds_chunk_unknown(chunk); } } lib3ds_chunk_read_end(&c, io); return(LIB3DS_TRUE); }