Exemple #1
0
bool texture_edit_click(d3pnt *pnt,bool double_click)
{
	int				wid,high,frame_idx,frame_count;
    char			bitmap_name[file_str_len];
	d3pnt			pt;
	d3rect			box,tbox;
	texture_type	*texture;

		// check for scrolling

	if (os_key_space_down()) {
		texture_edit_click_scroll();
		return(TRUE);
	}
	
		// regular clicks

	if (state.mode==app_mode_map) {
		texture=&map.textures[state.map.texture_edit_idx];
		frame_count=map_count_texture_frames(&map,state.map.texture_edit_idx);
	}
	else {
		texture=&model.textures[state.model.texture_edit_idx];
		frame_count=model_count_texture_frames(&model,state.model.texture_edit_idx);
	}

	texture_edit_get_box(&box);

	wid=box.rx-box.lx;
	high=box.by-box.ty;

		// move within view
		
	pnt->x-=box.lx;
	pnt->y-=box.ty;

		// clicking in return?
		
	frame_idx=-1;

	tbox.lx=wid-120;
	tbox.rx=tbox.lx+120;
	tbox.ty=high-40;
	tbox.by=tbox.ty+40;

	if ((pnt->x>=tbox.lx) && (pnt->x<=tbox.rx) && (pnt->y>=tbox.ty) && (pnt->y<=tbox.by)) {
		frame_idx=texture_edit_frame_click_return_idx;
	}

		// clicking in delete
		
	if ((frame_idx==-1) && (frame_count>0)) {
		tbox.lx=470;
		tbox.rx=600;
		tbox.ty=((texture_edit_item_high*(frame_count-1))+100)-texture_edit_scroll_pos;
		tbox.by=tbox.ty+25;

		if ((pnt->x>=tbox.lx) && (pnt->x<=tbox.rx) && (pnt->y>=tbox.ty) && (pnt->y<=tbox.by)) {
			frame_idx=texture_edit_frame_click_delete_idx;
		}
	}
	
		// clicking in item?
		
	if (frame_idx==-1) {
		frame_idx=(pnt->y+texture_edit_scroll_pos)/texture_edit_item_high;
		
		tbox.lx=0;
		tbox.rx=wid;
		tbox.ty=(frame_idx*texture_edit_item_high)-texture_edit_scroll_pos;
		tbox.by=tbox.ty+texture_edit_item_high;
		
		if ((frame_idx<0) || (frame_idx>=max_texture_frame)) return(FALSE);
	}
	
	texture_edit_frame_click_idx=frame_idx;
		
		// run the click
		
	main_wind_draw();

	while (!os_track_mouse_location(&pt,&box)) {
		if ((pt.x<tbox.lx) || (pt.x>=tbox.rx) || (pt.y<tbox.ty) || (pt.y>=tbox.by)) {
			texture_edit_frame_click_idx=-1;
		}
		else {
			texture_edit_frame_click_idx=frame_idx;
		}

		main_wind_draw();
		
		usleep(10000);
	}

	if (texture_edit_frame_click_idx==-1) return(FALSE);

	texture_edit_frame_click_idx=-1;
	main_wind_draw();
		
		// return was clicked
		
	if (frame_idx==texture_edit_frame_click_return_idx) {
		texture_edit_switch(-1);
		return(TRUE);
	}
	
		// delete
		
	if (frame_idx==texture_edit_frame_click_delete_idx) {

		os_set_wait_cursor();
		
		if (state.mode==app_mode_map) {
			map_delete_texture_frame(&map,state.map.texture_edit_idx);
		}
		else {
			model_delete_texture_frame(&model,state.model.texture_edit_idx);
		}

		os_set_arrow_cursor();
		
		main_wind_draw();
		return(TRUE);
	}
	
		// can we edit this item?
		
	if (frame_idx>frame_count) {
		os_dialog_alert("Texture Frames","This texture frame can not be edited.\nYou can only add adjancent texture frames.");
		return(FALSE);
	}
	
		// item was clicked
		
	if (texture_edit_click_bitmap_open(bitmap_name)) {
		strcpy(texture->frames[frame_idx].name,bitmap_name);

		os_set_wait_cursor();
		
		if (state.mode==app_mode_map) {
			map_refresh_textures(&map);
		}
		else {
			model_refresh_textures(&model);
		}

		os_set_arrow_cursor();
	}

	main_wind_draw();

	return(TRUE);
}
Exemple #2
0
void encode_mesh_v2_xml(model_type *model)
{
	int						i,n,k,j,frame_count;
	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;
    
        // model info
    
    xml_add_tagstart("Creator");
    xml_add_attribute_text("name","dim3 Animator");
    xml_add_attribute_text("version","1.0");
    xml_add_tagend(TRUE);
	
        // options
    
    xml_add_tagstart("Options");
	xml_add_attribute_list("deform",(char*)deform_mode_str,model->deform_mode);
    xml_add_tagend(TRUE);
 	
        // center
	
    xml_add_tagstart("Center");
    xml_add_attribute_3_coord_int("offset",model->center.x,model->center.y,model->center.z);
    xml_add_tagend(TRUE);
    
        // boxes
    
    xml_add_tagstart("View_Box");
    xml_add_attribute_3_coord_int("size",model->view_box.size.x,model->view_box.size.y,model->view_box.size.z);
    xml_add_attribute_3_coord_int("offset",model->view_box.offset.x,model->view_box.offset.y,model->view_box.offset.z);
    xml_add_tagend(TRUE);
	
		// light
	
    xml_add_tagstart("Light");

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

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

 	xml_add_attribute_model_tag("name_bone",model->tags.name_bone_tag);

	xml_add_tagend(TRUE);
	
		// hit boxes
		
    xml_add_tagstart("Hit_Boxes");
    xml_add_tagend(FALSE);
    
    hit_box=model->hit_boxes;
    
    for (i=0;i!=model->nhit_box;i++) {
		xml_add_tagstart("Hit_Box");
		xml_add_attribute_text("name",hit_box->name);
		xml_add_attribute_3_coord_int("size",hit_box->box.size.x,hit_box->box.size.y,hit_box->box.size.z);
		xml_add_attribute_3_coord_int("offset",hit_box->box.offset.x,hit_box->box.offset.y,hit_box->box.offset.z);
		xml_add_tagend(TRUE);
		
		hit_box++;
	}
	
    xml_add_tagclose("Hit_Boxes");
    
        // bones
        
    xml_add_tagstart("Bones");
    xml_add_tagend(FALSE);
    
    bone=model->bones;
    
    for (i=0;i!=model->nbone;i++) {
    
        xml_add_tagstart("Bone");
        
        xml_add_attribute_model_tag("tag",bone->tag);
		xml_add_attribute_text("name",bone->name);
		
        xml_add_attribute_3_coord_int("c3",bone->pnt.x,bone->pnt.y,bone->pnt.z);
		
        if (bone->parent_idx!=-1) xml_add_attribute_model_tag("parent",model->bones[bone->parent_idx].tag);
        
        xml_add_tagend(TRUE);
    
        bone++;
    }

    xml_add_tagclose("Bones");
	
        // meshes
        
    xml_add_tagstart("Meshes");
    xml_add_tagend(FALSE);
	
	for (j=0;j!=model->nmesh;j++) {
	
		mesh=&model->meshes[j];
	
		xml_add_tagstart("Mesh");
		xml_add_attribute_text("name",mesh->name);
		xml_add_attribute_boolean("no_lighting",mesh->no_lighting);
		xml_add_attribute_boolean("additive",mesh->blend_add);
		xml_add_attribute_boolean("tintable",mesh->tintable);
		xml_add_tagend(FALSE);
	   
			// vertexes
			
		xml_add_tagstart("Vertexes");
		xml_add_tagend(FALSE);
		
		vertex=mesh->vertexes;
		
		for (i=0;i!=mesh->nvertex;i++) {
		
			xml_add_tagstart("v");
			
			xml_add_attribute_3_coord_int("c3",vertex->pnt.x,vertex->pnt.y,vertex->pnt.z);
			xml_add_attribute_3_coord_float("n3",vertex->normal.x,vertex->normal.y,vertex->normal.z);

			if (vertex->major_bone_idx!=-1) {
				xml_add_attribute_model_tag("major",model->bones[vertex->major_bone_idx].tag);
			}
			if (vertex->minor_bone_idx!=-1) {
				xml_add_attribute_model_tag("minor",model->bones[vertex->minor_bone_idx].tag);
				xml_add_attribute_float("factor",vertex->bone_factor);
			}
			
			xml_add_tagend(TRUE);
		
			vertex++;
		}
						
		xml_add_tagclose("Vertexes");
		
			// materials
			
		xml_add_tagstart("Materials");
		xml_add_tagend(FALSE);
		
		texture=model->textures;
		material=mesh->materials;
		
		for (n=0;n!=max_model_texture;n++) {
		
			if (texture->frames[0].name[0]==0x0) {
				texture++;
				material++;
				continue;
			}
			
			xml_add_tagstart("Material");
			xml_add_tagend(FALSE);

				// triangles
				
			xml_add_tagstart("Triangles");
			xml_add_tagend(FALSE);
		
			trig=&mesh->trigs[material->trig_start];
		
			for (i=0;i!=material->trig_count;i++) {
		
				for (k=0;k!=3;k++) {
					xml_add_tagstart("v");
					
					xml_add_attribute_int("id",trig->v[k]);
					xml_add_attribute_2_coord_float("uv",trig->gx[k],trig->gy[k]);
					
					xml_add_tagend(TRUE);
				}
				
				trig++;
			}
			
			xml_add_tagclose("Triangles");
			xml_add_tagclose("Material");
			
			texture++;
			material++;
		}
		
		xml_add_tagclose("Materials");
		
		xml_add_tagclose("Mesh");
	}
	
	xml_add_tagclose("Meshes");
   
         // fills
         
    xml_add_tagstart("Fills");
    xml_add_tagend(FALSE);
    
    texture=model->textures;
    
    for (n=0;n!=max_model_texture;n++) {
    
        if (texture->frames[0].name[0]==0x0) {
            texture++;
            continue;
        }

		frame_count=model_count_texture_frames(model,n);
        
        xml_add_tagstart("Fill");
		bitmap_texture_write_xml(texture,frame_count,FALSE);
        xml_add_tagclose("Fill");
        
		texture++;
    }
    
    xml_add_tagclose("Fills");
}
Exemple #3
0
void texture_edit_draw(void)
{
	int					n,ty,by,wid,high,frame_count;
	float				vertexes[8];
	char				str[256];
	d3rect				wbox,box,tbox;
	texture_type		*texture;

		// get texture and frame count
		
	if (state.mode==app_mode_map) {
		texture=&map.textures[state.map.texture_edit_idx];
		frame_count=map_count_texture_frames(&map,state.map.texture_edit_idx);
	}
	else {
		texture=&model.textures[state.model.texture_edit_idx];
		frame_count=model_count_texture_frames(&model,state.model.texture_edit_idx);
	}

		// setup drawing

	os_get_window_box(&wbox);
	texture_edit_get_box(&box);

	wid=box.rx-box.lx;
	high=box.by-box.ty;

	glEnable(GL_SCISSOR_TEST);
	glScissor(box.lx,(wbox.by-box.by),((box.rx-box.lx)+1),(box.by-box.ty));

	glViewport(box.lx,(wbox.by-box.by),((box.rx-box.lx)+1),(box.by-box.ty));
		
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho((GLdouble)0,(GLdouble)wid,(GLdouble)high,(GLdouble)0,-1.0,1.0);
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

		// draw setup

	glDisable(GL_DEPTH_TEST);

		// the textures

	for (n=0;n!=max_texture_frame;n++) {
		ty=(texture_edit_item_high*n)-texture_edit_scroll_pos;
		by=ty+texture_edit_item_high;
		
			// the background
			
		if (n>frame_count) {
			glColor4f(0.5f,0.5f,0.5f,1.0f);
		}
		else {
			if (texture_edit_frame_click_idx==n) {
				glColor4f(0.85f,0.85f,0.85f,1.0f);
			}
			else {
				glColor4f(0.95f,0.95f,0.95f,1.0f);
			}
		}
	
		vertexes[0]=vertexes[6]=0.0f;
		vertexes[1]=vertexes[3]=(float)ty;
		vertexes[2]=vertexes[4]=(float)wid;
		vertexes[5]=vertexes[7]=(float)by;

		glVertexPointer(2,GL_FLOAT,0,vertexes);
		glDrawArrays(GL_QUADS,0,4);

			// the separator

		glColor4f(0.0f,0.0f,0.0f,1.0f);

		vertexes[0]=0.0f;
		vertexes[1]=(float)ty;
		vertexes[2]=(float)wid;
		vertexes[3]=(float)ty;

		glVertexPointer(2,GL_FLOAT,0,vertexes);
		glDrawArrays(GL_LINES,0,2);

			// the frame

		sprintf(str,"Frame %d",n);
		text_draw(5,(ty+20),15.0f,NULL,str);

			// the textures

		tbox.lx=25;
		tbox.rx=tbox.lx+100;
		tbox.ty=ty+22;
		tbox.by=tbox.ty+100;
		texture_edit_draw_bitmap(&tbox,"Bitmap",texture->frames[n].bitmap.gl_id);

		tbox.lx+=110;
		tbox.rx+=110;
		texture_edit_draw_bitmap(&tbox,"Bump",texture->frames[n].bumpmap.gl_id);

		tbox.lx+=110;
		tbox.rx+=110;
		texture_edit_draw_bitmap(&tbox,"Specular",texture->frames[n].specularmap.gl_id);

		tbox.lx+=110;
		tbox.rx+=110;
		texture_edit_draw_bitmap(&tbox,"Glow",texture->frames[n].glowmap.gl_id);

			// the info

		str[0]=0x0;
	
		if (texture->frames[n].name[0]!=0x0) {
			sprintf(str,"Name: %s",texture->frames[n].name);
			text_draw(470,(ty+35),15.0f,NULL,str);

			sprintf(str,"Size: %dx%d",texture->frames[n].bitmap.wid,texture->frames[n].bitmap.high);
			text_draw(470,(ty+55),15.0f,NULL,str);

			if (texture->frames[n].bitmap.opaque) {
				strcpy(str,"Opaque");
			}
			else {
				strcpy(str,"Transparent");
			}
			text_draw(470,(ty+75),15.0f,NULL,str);

			sprintf(str,"Wait: %d",texture->animate.wait[n]);
			text_draw(470,(ty+95),15.0f,NULL,str);
		}
		else {
			text_draw(470,(ty+35),15.0f,NULL,"Name: (empty)");
		}
		
			// delete button
		
		if (frame_count>0) {
			tbox.lx=470;
			tbox.rx=600;
			tbox.ty=ty+100;
			tbox.by=tbox.ty+25;

			if ((frame_count==1) && (n==0)) {
				texture_edit_draw_button(&tbox,15,"Delete Texture",15.0f,FALSE,texture_edit_frame_click_delete_idx);
			}
			else {
				if (n==(frame_count-1)) {
					texture_edit_draw_button(&tbox,20,"Delete Frame",15.0f,FALSE,texture_edit_frame_click_delete_idx);
				}
			}
		}
	}

		// the return button

	tbox.lx=wid-120;
	tbox.rx=tbox.lx+120;
	tbox.ty=high-40;
	tbox.by=tbox.ty+40;
	
	texture_edit_draw_button(&tbox,5,"Return",25.0f,TRUE,texture_edit_frame_click_return_idx);
}