Exemple #1
0
void model_piece_add_hit_box(void)
{
	int				idx;

	idx=model_hit_box_add(&model);
	if (idx==-1) {
		os_dialog_alert("Add Hit Box","You've reached the hit box limit for this model.");
		return;
	}

	state.model.hit_box=TRUE;
	state.model.cur_item=item_model_hit_box;
	state.model.cur_hit_box_idx=idx;

	model_palette_scroll_into_view(item_model_hit_box,idx);

	dialog_property_string_run(list_string_value_string,(void*)model.hit_boxes[idx].name,name_str_len,0,0);
}
Exemple #2
0
void decode_mesh_v2_xml(model_type *model,int model_head)
{
	int						i,n,k,j,bone_idx,nbone,hit_box_idx,nhit_box,
							mesh_idx,nmesh,nfill,ntrig,
							tag,hit_box_tag,meshes_tag,mesh_tag,
							vertex_tag,bone_tag,vtag,trig_tag,
							materials_tag,material_tag,fills_tag,fill_tag;
	char					tag_name[32];
	model_hit_box_type		*hit_box;
	model_mesh_type			*mesh;
    model_vertex_type		*vertex;
	model_material_type		*material;
    model_bone_type			*bone;
    model_trig_type			*trig;
    texture_type			*texture;

        // options
    
    tag=xml_findfirstchild("Options",model_head);
    if (tag!=-1) {
		model->deform_mode=xml_get_attribute_list(tag,"deform",(char*)deform_mode_str);
	}
	
        // center
    
    tag=xml_findfirstchild("Center",model_head);
    if (tag!=-1) {
		xml_get_attribute_3_coord_int(tag,"offset",&model->center.x,&model->center.y,&model->center.z);
    }
    
        // boxes
    
    tag=xml_findfirstchild("View_Box",model_head);
    if (tag!=-1) {
        xml_get_attribute_3_coord_int(tag,"size",&model->view_box.size.x,&model->view_box.size.y,&model->view_box.size.z);
        xml_get_attribute_3_coord_int(tag,"offset",&model->view_box.offset.x,&model->view_box.offset.y,&model->view_box.offset.z);
    }
	
        // light
        
    tag=xml_findfirstchild("Light",model_head);
    if (tag!=-1) {

		for (k=0;k!=max_model_light;k++) {
			if (k==0) {
				strcpy(tag_name,"light_bone");
			}
			else {
				sprintf(tag_name,"light_bone_%d",k);
			}
			model->tags.light_bone_tag[k]=xml_get_attribute_model_tag(tag,tag_name);
		}

		for (k=0;k!=max_model_halo;k++) {
			if (k==0) {
				strcpy(tag_name,"halo_bone");
			}
			else {
				sprintf(tag_name,"halo_bone_%d",k);
			}
			model->tags.halo_bone_tag[k]=xml_get_attribute_model_tag(tag,tag_name);
		}

        model->tags.name_bone_tag=xml_get_attribute_model_tag(tag,"name_bone");
    }
	
        // hit boxes
    
    hit_box_tag=xml_findfirstchild("Hit_Boxes",model_head);
	if (hit_box_tag!=-1) {
	
		nhit_box=xml_countchildren(hit_box_tag);
		tag=xml_findfirstchild("Hit_Box",hit_box_tag);
		
		for (i=0;i!=nhit_box;i++) {
 				
				// add new hit box

			hit_box_idx=model_hit_box_add(model);
			if (hit_box_idx==-1) break;

				// fill in hit box

			hit_box=&model->hit_boxes[hit_box_idx];

			xml_get_attribute_text(tag,"name",hit_box->name,64);
			xml_get_attribute_3_coord_int(tag,"size",&hit_box->box.size.x,&hit_box->box.size.y,&hit_box->box.size.z);
			xml_get_attribute_3_coord_int(tag,"offset",&hit_box->box.offset.x,&hit_box->box.offset.y,&hit_box->box.offset.z);
			
			tag=xml_findnextchild(tag);
		}
    }
	else {
		model->nhit_box=0;
	}
    
        // bones
 
    bone_tag=xml_findfirstchild("Bones",model_head);

    nbone=xml_countchildren(bone_tag);
	tag=xml_findfirstchild("Bone",bone_tag);
    
    for (i=0;i!=nbone;i++) {

 			// add new bone

		bone_idx=model_bone_add(model,0,0,0);
		if (bone_idx==-1) break;

			// fill in bone

		bone=&model->bones[bone_idx];
		
		bone->tag=xml_get_attribute_model_tag(tag,"tag");
		xml_get_attribute_text(tag,"name",bone->name,name_str_len);
        
        xml_get_attribute_3_coord_int(tag,"c3",&bone->pnt.x,&bone->pnt.y,&bone->pnt.z);
        bone_parent_tag[i]=xml_get_attribute_model_tag(tag,"parent");
    
		tag=xml_findnextchild(tag);
    }
	
		// find the light bone
		
	for (k=0;k!=max_model_light;k++) {
		model->tags.light_bone_idx[k]=model_find_bone(model,model->tags.light_bone_tag[k]);
	}

	for (k=0;k!=max_model_halo;k++) {
		model->tags.halo_bone_idx[k]=model_find_bone(model,model->tags.halo_bone_tag[k]);
	}

	model->tags.name_bone_idx=model_find_bone(model,model->tags.name_bone_tag);
		
		// reset the bones from tags to indexes
		
	bone=model->bones;
	
	for (i=0;i!=model->nbone;i++) {
		bone->parent_idx=model_find_bone(model,bone_parent_tag[i]);
		bone++;
	}
	
		// meshes
		
	meshes_tag=xml_findfirstchild("Meshes",model_head);

    nmesh=xml_countchildren(meshes_tag);
	mesh_tag=xml_findfirstchild("Mesh",meshes_tag);
	
	model->nmesh=1;				// new models have a single mesh
	
	for (j=0;j!=nmesh;j++) {
	
			// need new mesh?
			
		mesh_idx=j;
		if (j>0) {
			mesh_idx=model_mesh_add(model);
		}
		
		if (mesh_idx==-1) break;
	
			// mesh settings
			
		mesh=&model->meshes[mesh_idx];
		xml_get_attribute_text(mesh_tag,"name",mesh->name,name_str_len);
		mesh->no_lighting=xml_get_attribute_boolean(mesh_tag,"no_lighting");
		mesh->blend_add=xml_get_attribute_boolean(mesh_tag,"additive");
		mesh->tintable=xml_get_attribute_boolean(mesh_tag,"tintable");
		
			// don't allow blank mesh names
			
		if (mesh->name[0]==0x0) {
			if (mesh_idx==0) {
				strcpy(mesh->name,"Default");
			}
			else {
				sprintf(mesh->name,"Mesh %d",mesh_idx);
			}
		}
		
			// vertexes
		
		vertex_tag=xml_findfirstchild("Vertexes",mesh_tag);

		mesh->nvertex=xml_countchildren(vertex_tag);
		tag=xml_findfirstchild("v",vertex_tag);
		
		vertex=mesh->vertexes;
		
		for (i=0;i!=mesh->nvertex;i++) {
			xml_get_attribute_3_coord_int(tag,"c3",&vertex->pnt.x,&vertex->pnt.y,&vertex->pnt.z);
			xml_get_attribute_3_coord_float(tag,"n3",&vertex->normal.x,&vertex->normal.y,&vertex->normal.z);
			
			major_bone_tag[i]=xml_get_attribute_model_tag(tag,"major");
			minor_bone_tag[i]=xml_get_attribute_model_tag(tag,"minor");
			vertex->bone_factor=xml_get_attribute_float_default(tag,"factor",1);
		
			vertex++;
			tag=xml_findnextchild(tag);
		}
		
			// materials
			
		materials_tag=xml_findfirstchild("Materials",mesh_tag);
		
		ntrig=0;
		trig=mesh->trigs;

		texture=model->textures;
		material=mesh->materials;
		
		nfill=xml_countchildren(materials_tag);
		material_tag=xml_findfirstchild("Material",materials_tag);
		
		for (n=0;n!=nfill;n++) {
		
			trig_tag=xml_findfirstchild("Triangles",material_tag);
			
			material->trig_start=ntrig;
			material->trig_count=xml_countchildren(trig_tag)/3;
			
			vtag=xml_findfirstchild("v",trig_tag);
		
			for (i=0;i!=material->trig_count;i++) {
		
				for (k=0;k!=3;k++) {
					trig->v[k]=xml_get_attribute_int(vtag,"id");
					xml_get_attribute_2_coord_float(vtag,"uv",&trig->gx[k],&trig->gy[k]);

					vtag=xml_findnextchild(vtag);
				}
				
				trig++;
				ntrig++;
			}
			
			texture++;
			material++;
			
			material_tag=xml_findnextchild(material_tag);
		}
		
		mesh->ntrig=ntrig;
		
			// reset the vertexes from tags to indexes
			
		vertex=mesh->vertexes;
		
		for (i=0;i!=mesh->nvertex;i++) {
			vertex->major_bone_idx=model_find_bone(model,major_bone_tag[i]);
			vertex->minor_bone_idx=model_find_bone(model,minor_bone_tag[i]);
			if ((vertex->major_bone_idx==-1) || (vertex->minor_bone_idx==-1)) vertex->bone_factor=1;
			vertex++;
		}
		
		mesh_tag=xml_findnextchild(mesh_tag);
	}
	
	model->nmesh=nmesh;
  
        // fills

    fills_tag=xml_findfirstchild("Fills",model_head);
	nfill=xml_countchildren(fills_tag);

	texture=model->textures;
	
	fill_tag=xml_findfirstchild("Fill",fills_tag);
    
    for (n=0;n!=nfill;n++) {
	
		texture->animate.current_frame=0;
		texture->animate.total_wait=0;
		
		bitmap_texture_read_xml(texture,fill_tag,FALSE);
		texture++;
		
		fill_tag=xml_findnextchild(fill_tag);
    }
}
Exemple #3
0
void decode_mesh_v1_xml(model_type *model,int model_head)
{
	int						i,n,k,bone_idx,nbone,hit_box_idx,nhit_box,
							nfill,ntrig,frame_count,
							tag,hit_box_tag,vertex_tag,bone_tag,vtag,trig_tag,image_tag,
							fills_tag,fill_tag;
	model_hit_box_type		*hit_box;
    model_vertex_type		*vertex;
	model_material_type		*material;
    model_bone_type			*bone;
    model_trig_type			*trig;
    texture_type			*texture;
	
        // options
    
    tag=xml_findfirstchild("Options",model_head);
    if (tag!=-1) {
		model->deform_mode=xml_get_attribute_list(tag,"deform",(char*)deform_mode_str);
	}
	
        // center
    
    tag=xml_findfirstchild("Center",model_head);
    if (tag!=-1) {
		xml_get_attribute_3_coord_int(tag,"offset",&model->center.x,&model->center.y,&model->center.z);
    }
    
        // boxes
    
    tag=xml_findfirstchild("View_Box",model_head);
    if (tag!=-1) {
        xml_get_attribute_3_coord_int(tag,"size",&model->view_box.size.x,&model->view_box.size.y,&model->view_box.size.z);
        xml_get_attribute_3_coord_int(tag,"offset",&model->view_box.offset.x,&model->view_box.offset.y,&model->view_box.offset.z);
    }
	
        // light
        
    tag=xml_findfirstchild("Light",model_head);
    if (tag!=-1) {
        model->tags.light_bone_tag[0]=xml_get_attribute_model_tag(tag,"light_bone");
        model->tags.halo_bone_tag[0]=xml_get_attribute_model_tag(tag,"halo_bone");
    }
	
        // hit boxes
    
    hit_box_tag=xml_findfirstchild("Hit_Boxes",model_head);
	if (hit_box_tag!=-1) {
	
		nhit_box=xml_countchildren(hit_box_tag);
		tag=xml_findfirstchild("Hit_Box",hit_box_tag);
		
		for (i=0;i!=model->nhit_box;i++) {
 				
				// add new hit box

			hit_box_idx=model_hit_box_add(model);
			if (hit_box_idx==-1) break;

				// fill in hit box

			hit_box=&model->hit_boxes[hit_box_idx];

			xml_get_attribute_text(tag,"name",hit_box->name,64);
			xml_get_attribute_3_coord_int(tag,"size",&hit_box->box.size.x,&hit_box->box.size.y,&hit_box->box.size.z);
			xml_get_attribute_3_coord_int(tag,"offset",&hit_box->box.offset.x,&hit_box->box.offset.y,&hit_box->box.offset.z);
			
			tag=xml_findnextchild(tag);
		}
    }
	else {
		model->nhit_box=0;
	}
	
		// single mesh
		
	model->nmesh=1;
	strcpy(model->meshes[0].name,"Default");
	
        // vertexes
    
    vertex_tag=xml_findfirstchild("Vertexes",model_head);

    model->meshes[0].nvertex=xml_countchildren(vertex_tag);
	tag=xml_findfirstchild("v",vertex_tag);
	
    vertex=model->meshes[0].vertexes;
    
    for (i=0;i!=model->meshes[0].nvertex;i++) {
        xml_get_attribute_3_coord_int(tag,"c3",&vertex->pnt.x,&vertex->pnt.y,&vertex->pnt.z);
        xml_get_attribute_3_coord_float(tag,"n3",&vertex->normal.x,&vertex->normal.y,&vertex->normal.z);
		
        major_bone_tag[i]=xml_get_attribute_model_tag(tag,"major");
        minor_bone_tag[i]=xml_get_attribute_model_tag(tag,"minor");
        vertex->bone_factor=xml_get_attribute_float_default(tag,"factor",1);
    
        vertex++;
		tag=xml_findnextchild(tag);
    }
    
        // bones

    bone_tag=xml_findfirstchild("Bones",model_head);

    nbone=xml_countchildren(bone_tag);
	tag=xml_findfirstchild("Bone",bone_tag);
    
    for (i=0;i!=nbone;i++) {

			// add new bone

		bone_idx=model_bone_add(model,0,0,0);
		if (bone_idx==-1) break;

			// fill in bone

		bone=&model->bones[bone_idx];

        bone->tag=xml_get_attribute_model_tag(tag,"tag");
		xml_get_attribute_text(tag,"name",bone->name,name_str_len);
        
        xml_get_attribute_3_coord_int(tag,"c3",&bone->pnt.x,&bone->pnt.y,&bone->pnt.z);
        bone_parent_tag[i]=xml_get_attribute_model_tag(tag,"parent");
    
		tag=xml_findnextchild(tag);
    }
	
		// find the light bone
		
	model->tags.light_bone_idx[0]=model_find_bone(model,model->tags.light_bone_tag[0]);
	model->tags.halo_bone_idx[0]=model_find_bone(model,model->tags.halo_bone_tag[0]);
   
		// reset the vertexes from tags to indexes
		
	vertex=model->meshes[0].vertexes;
	
	for (i=0;i!=model->meshes[0].nvertex;i++) {
		vertex->major_bone_idx=model_find_bone(model,major_bone_tag[i]);
		vertex->minor_bone_idx=model_find_bone(model,minor_bone_tag[i]);
        if ((vertex->major_bone_idx==-1) || (vertex->minor_bone_idx==-1)) vertex->bone_factor=1;
		vertex++;
	}
		
		// reset the bones from tags to indexes
		
	bone=model->bones;
	
	for (i=0;i!=model->nbone;i++) {
		bone->parent_idx=model_find_bone(model,bone_parent_tag[i]);
		bone++;
	}
    
        // fills

	bzero(model->textures,(max_model_texture*sizeof(texture_type)));

		// count total # of trigs
		
    fills_tag=xml_findfirstchild("Fills",model_head);
	
    nfill=xml_countchildren(fills_tag);
	fill_tag=xml_findfirstchild("Fill",fills_tag);
    
	ntrig=0;
	
    for (n=0;n!=nfill;n++) {
        trig_tag=xml_findfirstchild("Triangles",fill_tag);
        ntrig+=xml_countchildren(trig_tag)/3;
		fill_tag=xml_findnextchild(fill_tag);
	}

		// load the fills and trigs
		
    ntrig=0;
    trig=model->meshes[0].trigs;

	texture=model->textures;
	material=model->meshes[0].materials;
	
	fill_tag=xml_findfirstchild("Fill",fills_tag);
    
    for (n=0;n!=nfill;n++) {
		texture->animate.current_frame=0;
		texture->animate.total_wait=0;
		
      	texture->animate.on=xml_get_attribute_boolean(fill_tag,"animate");
         
		image_tag=xml_findfirstchild("Images",fill_tag);
			
		frame_count=xml_countchildren(image_tag);
		tag=xml_findfirstchild("Image",image_tag);
		
		for (k=0;k!=frame_count;k++) {
			texture->animate.wait[k]=xml_get_attribute_int(tag,"wait");
			texture->animate.end_tick[k]=texture->animate.total_wait=texture->animate.total_wait+texture->animate.wait[k];
			xml_get_attribute_text(tag,"bitmap",texture->frames[k].name,file_str_len);
			
			tag=xml_findnextchild(tag);
		}
        
            // fill triangles
    
        trig_tag=xml_findfirstchild("Triangles",fill_tag);
        
        material->trig_start=ntrig;
        material->trig_count=xml_countchildren(trig_tag)/3;
		
		vtag=xml_findfirstchild("v",trig_tag);
    
        for (i=0;i!=material->trig_count;i++) {
    
            for (k=0;k!=3;k++) {
                trig->v[k]=xml_get_attribute_int(vtag,"id");
				xml_get_attribute_2_coord_float(vtag,"uv",&trig->gx[k],&trig->gy[k]);

				vtag=xml_findnextchild(vtag);
            }
            
            trig++;
            ntrig++;
        }
		
		texture++;
		material++;
		
		fill_tag=xml_findnextchild(fill_tag);
    }
    
    model->meshes[0].ntrig=ntrig;
}