Exemplo n.º 1
0
bool map_mesh_poly_punch_hole(map_type *map,int mesh_idx,int poly_idx,d3pnt *extrude_pnt)
{
    int						n,ptsz,mx,my,mz,
                            px[8],py[8],pz[8],
                            k,kx[4],ky[4],kz[4];
    float					gx[8],gy[8],mgx,mgy,
                            k_gx[4],k_gy[4];
    d3pnt					*pt;
    map_mesh_type			*mesh;
    map_mesh_poly_type		*poly;

    mesh=&map->mesh.meshes[mesh_idx];
    poly=&mesh->polys[poly_idx];

    ptsz=poly->ptsz;

    // new hole vertexes

    mx=my=mz=0;
    mgx=mgy=0.0f;

    for (n=0; n!=ptsz; n++) {
        pt=&mesh->vertexes[poly->v[n]];

        px[n]=pt->x;
        py[n]=pt->y;
        pz[n]=pt->z;

        gx[n]=poly->uv[0].x[n];
        gy[n]=poly->uv[0].y[n];

        mx+=pt->x;
        my+=pt->y;
        mz+=pt->z;

        mgx+=gx[n];
        mgy+=gy[n];
    }

    mx/=ptsz;
    my/=ptsz;
    mz/=ptsz;

    mgx=mgx/(float)ptsz;
    mgy=mgy/(float)ptsz;

    for (n=0; n!=ptsz; n++) {
        px[n]=((px[n]-mx)/2)+mx;
        py[n]=((py[n]-my)/2)+my;
        pz[n]=((pz[n]-mz)/2)+mz;

        gx[n]=((gx[n]-mgx)/2.0f)+mgx;
        gy[n]=((gy[n]-mgy)/2.0f)+mgy;
    }

    // new polygon for each vertex

    for (n=0; n!=ptsz; n++) {

        poly=&mesh->polys[poly_idx];			// add might force memory move, need to always rebuild pointer

        k=n+1;
        if (k==ptsz) k=0;

        pt=&mesh->vertexes[poly->v[n]];
        kx[0]=pt->x;
        ky[0]=pt->y;
        kz[0]=pt->z;

        pt=&mesh->vertexes[poly->v[k]];
        kx[1]=pt->x;
        ky[1]=pt->y;
        kz[1]=pt->z;

        kx[2]=px[k];
        ky[2]=py[k];
        kz[2]=pz[k];

        kx[3]=px[n];
        ky[3]=py[n];
        kz[3]=pz[n];

        k_gx[0]=poly->uv[0].x[n];
        k_gy[0]=poly->uv[0].y[n];

        k_gx[1]=poly->uv[0].x[k];
        k_gy[1]=poly->uv[0].y[k];

        k_gx[2]=gx[k];
        k_gy[2]=gy[k];

        k_gx[3]=gx[n];
        k_gy[3]=gy[n];

        if (map_mesh_add_poly(map,mesh_idx,4,kx,ky,kz,k_gx,k_gy,poly->txt_idx)==-1) return(FALSE);
    }

    // extruded polys

    if (extrude_pnt!=NULL) {

        for (n=0; n!=ptsz; n++) {

            poly=&mesh->polys[poly_idx];			// add might force memory move, need to always rebuild pointer

            k=n+1;
            if (k==ptsz) k=0;

            kx[0]=px[n]+extrude_pnt->x;
            ky[0]=py[n]+extrude_pnt->y;
            kz[0]=pz[n]+extrude_pnt->z;

            kx[1]=px[n];
            ky[1]=py[n];
            kz[1]=pz[n];

            kx[2]=px[k];
            ky[2]=py[k];
            kz[2]=pz[k];

            kx[3]=px[k]+extrude_pnt->x;
            ky[3]=py[k]+extrude_pnt->y;
            kz[3]=pz[k]+extrude_pnt->z;

            k_gx[0]=0.0f;
            k_gy[0]=0.0f;

            k_gx[1]=1.0f;
            k_gy[1]=0.0f;

            k_gx[2]=1.0f;
            k_gy[2]=1.0f;

            k_gx[3]=0.0f;
            k_gy[3]=1.0f;

            if (map_mesh_add_poly(map,mesh_idx,4,kx,ky,kz,k_gx,k_gy,poly->txt_idx)==-1) return(FALSE);
        }
    }

    // finish by deleting original polygon

    return(map_mesh_delete_poly(map,mesh_idx,poly_idx));
}
Exemplo n.º 2
0
void piece_delete(void)
{
	int				n,i,k,nsel_count,
					type,main_idx,sub_idx;
	unsigned char	*mesh_mask;
	
	map_undo_push();
	
		// sort segment so higher indexes are deleted first
		
	select_sort();
	
		// selections have multiple polygons in them
		// so keep a mesh list
	
	mesh_mask=(unsigned char*)malloc(map.mesh.nmesh);
	if (mesh_mask==NULL) return;
	
	bzero(mesh_mask,map.mesh.nmesh);
	
		// delete selection
	
	nsel_count=select_count();
	
	for (n=0;n!=nsel_count;n++) {
		select_get(n,&type,&main_idx,&sub_idx);
	
		switch (type) {
			
			case item_map_mesh:
				if (state.map.select_mode==select_mode_polygon) {
					map_mesh_delete_poly(&map,main_idx,sub_idx);
					select_delete_move_index(item_map_mesh,main_idx,sub_idx);
					break;
				}
				if (state.map.select_mode==select_mode_mesh) {
					if (mesh_mask[main_idx]==0x0) map_mesh_delete(&map,main_idx);
					mesh_mask[main_idx]=0x1;
					break;
				}
				break;
				
			case item_map_liquid:
				map_liquid_delete(&map,main_idx);
				break;
				
			case item_map_spot:
				for (i=main_idx;i<map.nspot;i++) {
					map.spots[i]=map.spots[i+1];
				}
				map.nspot--;
				break;
				
			case item_map_scenery:
				for (i=main_idx;i<map.nscenery;i++) {
					map.sceneries[i]=map.sceneries[i+1];
				}
				map.nscenery--;
				break;
				
			case item_map_node:
				for (i=0;i!=map.nnode;i++) {			// clear all linkage
					if (i==main_idx) continue;

					for (k=0;k!=max_node_link;k++) {
						if (map.nodes[i].link[k]==main_idx) map.nodes[i].link[k]=-1;
						if (map.nodes[i].link[k]>main_idx) map.nodes[i].link[k]--;
					}
				}

				for (i=main_idx;i<map.nnode;i++) {
					map.nodes[i]=map.nodes[i+1];
				}
				
				map.nnode--;
				break;
				
			case item_map_light:
				for (i=main_idx;i<map.nlight;i++) {
					map.lights[i]=map.lights[i+1];
				}
				map.nlight--;
				break;
				
			case item_map_sound:
				for (i=main_idx;i<map.nsound;i++) {
					map.sounds[i]=map.sounds[i+1];
				}
				map.nsound--;
				break;
				
			case item_map_particle:
				for (i=main_idx;i<map.nparticle;i++) {
					map.particles[i]=map.particles[i+1];
				}
				map.nparticle--;
				break;
				
		}
	}
	
	free(mesh_mask);
	
	select_clear();
	
	map_palette_reset();
    
	main_wind_draw();
}