Exemple #1
0
static void GPU_buffer_copy_uvedge(DerivedMesh *dm, float *varray, int *UNUSED(index), int *UNUSED(mat_orig_to_new), void *UNUSED(user))
{
	MTFace *tf = DM_get_face_data_layer(dm, CD_MTFACE);
	int i, j=0;

	if(!tf)
		return;

	for(i = 0; i < dm->numFaceData; i++, tf++) {
		MFace mf;
		dm->getFace(dm,i,&mf);

		copy_v2_v2(&varray[j],tf->uv[0]);
		copy_v2_v2(&varray[j+2],tf->uv[1]);

		copy_v2_v2(&varray[j+4],tf->uv[1]);
		copy_v2_v2(&varray[j+6],tf->uv[2]);

		if(!mf.v4) {
			copy_v2_v2(&varray[j+8],tf->uv[2]);
			copy_v2_v2(&varray[j+10],tf->uv[0]);
			j+=12;
		} else {
			copy_v2_v2(&varray[j+8],tf->uv[2]);
			copy_v2_v2(&varray[j+10],tf->uv[3]);

			copy_v2_v2(&varray[j+12],tf->uv[3]);
			copy_v2_v2(&varray[j+14],tf->uv[0]);
			j+=16;
		}
	}
}
Exemple #2
0
static void GPU_buffer_copy_uv(DerivedMesh *dm, float *varray, int *index, int *mat_orig_to_new, void *UNUSED(user))
{
	int start;
	int i, totface;

	MTFace *mtface;
	MFace *f;

	if(!(mtface = DM_get_face_data_layer(dm, CD_MTFACE)))
		return;
	f = dm->getFaceArray(dm);
		
	totface = dm->getNumFaces(dm);
	for(i = 0; i < totface; i++, f++) {
		start = index[mat_orig_to_new[f->mat_nr]];

		/* v1 v2 v3 */
		copy_v2_v2(&varray[start],mtface[i].uv[0]);
		copy_v2_v2(&varray[start+2],mtface[i].uv[1]);
		copy_v2_v2(&varray[start+4],mtface[i].uv[2]);
		index[mat_orig_to_new[f->mat_nr]] += 6;

		if(f->v4) {
			/* v3 v4 v1 */
			copy_v2_v2(&varray[start+6],mtface[i].uv[2]);
			copy_v2_v2(&varray[start+8],mtface[i].uv[3]);
			copy_v2_v2(&varray[start+10],mtface[i].uv[0]);
			index[mat_orig_to_new[f->mat_nr]] += 6;
		}
	}
}
Exemple #3
0
/* get the DerivedMesh's MCols; choose (in decreasing order of
   preference) from CD_ID_MCOL, CD_WEIGHT_MCOL, or CD_MCOL */
static MCol *gpu_buffer_color_type(DerivedMesh *dm)
{
	MCol *c;
	int type;

	type = CD_ID_MCOL;
	c = DM_get_face_data_layer(dm, type);
	if(!c) {
		type = CD_WEIGHT_MCOL;
		c = DM_get_face_data_layer(dm, type);
		if(!c) {
			type = CD_MCOL;
			c = DM_get_face_data_layer(dm, type);
		}
	}

	dm->drawObject->colType = type;
	return c;
}
Exemple #4
0
/* call gpu_buffer_setup with settings for a particular type of buffer */
static GPUBuffer *gpu_buffer_setup_type(DerivedMesh *dm, GPUBufferType type)
{
	const GPUBufferTypeSettings *ts;
	void *user_data = NULL;
	GPUBuffer *buf;

	ts = &gpu_buffer_type_settings[type];

	/* special handling for MCol and UV buffers */
	if(type == GPU_BUFFER_COLOR) {
		if(!(user_data = gpu_buffer_color_type(dm)))
			return NULL;
	}
	else if(type == GPU_BUFFER_UV) {
		if(!DM_get_face_data_layer(dm, CD_MTFACE))
			return NULL;
	}

	buf = gpu_buffer_setup(dm, dm->drawObject, ts->vector_size,
			       gpu_buffer_size_from_type(dm, type),
			       ts->gl_buffer_type, user_data, ts->copy);

	return buf;
}
Exemple #5
0
static void do_multires_bake(MultiresBakeRender *bkr, Image* ima, MPassKnownData passKnownData,
                             MInitBakeData initBakeData, MApplyBakeData applyBakeData, MFreeBakeData freeBakeData)
{
	DerivedMesh *dm= bkr->lores_dm;
	ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
	const int lvl= bkr->lvl;
	const int tot_face= dm->getNumFaces(dm);
	MVert *mvert= dm->getVertArray(dm);
	MFace *mface= dm->getFaceArray(dm);
	MTFace *mtface= dm->getFaceDataArray(dm, CD_MTFACE);
	float *pvtangent= NULL;

	if(CustomData_get_layer_index(&dm->faceData, CD_TANGENT) == -1)
		DM_add_tangent_layer(dm);

	pvtangent= DM_get_face_data_layer(dm, CD_TANGENT);

	if(tot_face > 0) {  /* sanity check */
		int f= 0;
		MBakeRast bake_rast;
		MResolvePixelData data={NULL};

		data.mface= mface;
		data.mvert= mvert;
		data.mtface= mtface;
		data.pvtangent= pvtangent;
		data.precomputed_normals= dm->getFaceDataArray(dm, CD_NORMAL);	/* don't strictly need this */
		data.w= ibuf->x;
		data.h= ibuf->y;
		data.lores_dm= dm;
		data.hires_dm= bkr->hires_dm;
		data.lvl= lvl;
		data.pass_data= passKnownData;

		if(initBakeData)
			data.bake_data= initBakeData(bkr, ima);

		init_bake_rast(&bake_rast, ibuf, &data, flush_pixel);

		for(f= 0; f<tot_face; f++) {
			MTFace *mtfate= &mtface[f];
			int verts[3][2], nr_tris, t;

			if(multiresbake_test_break(bkr))
				break;

			if(mtfate->tpage!=ima)
				continue;

			data.face_index= f;

			/* might support other forms of diagonal splits later on such as
			   split by shortest diagonal.*/
			verts[0][0]=0;
			verts[1][0]=1;
			verts[2][0]=2;

			verts[0][1]=0;
			verts[1][1]=2;
			verts[2][1]=3;

			nr_tris= mface[f].v4!=0 ? 2 : 1;
			for(t= 0; t<nr_tris; t++) {
				data.i0= verts[0][t];
				data.i1= verts[1][t];
				data.i2 =verts[2][t];

				bake_rasterize(&bake_rast, mtfate->uv[data.i0], mtfate->uv[data.i1], mtfate->uv[data.i2]);
			}

			bkr->baked_faces++;

			if(bkr->do_update)
				*bkr->do_update= 1;

			if(bkr->progress)
				*bkr->progress= ((float)bkr->baked_objects + (float)bkr->baked_faces / tot_face) / bkr->tot_obj;
		}

		if(applyBakeData)
			applyBakeData(data.bake_data);

		if(freeBakeData)
			freeBakeData(data.bake_data);
	}
}