[Bf-blender-cvs] [b24fb7a] cycles-ptex-24: Cycles fixes

Nicholas Bishop noreply at git.blender.org
Fri Jan 30 18:00:53 CET 2015


Commit: b24fb7a4ed389b05890525f44ca5a4fc74513efd
Author: Nicholas Bishop
Date:   Wed Jan 28 14:43:32 2015 +0100
Branches: cycles-ptex-24
https://developer.blender.org/rBb24fb7a4ed389b05890525f44ca5a4fc74513efd

Cycles fixes

===================================================================

M	source/blender/blenkernel/intern/mesh.c
M	source/blender/blenkernel/intern/mesh_evaluate.c

===================================================================

diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index a47f289..87eca1c 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -52,6 +52,7 @@
 #include "BKE_material.h"
 #include "BKE_modifier.h"
 #include "BKE_multires.h"
+#include "BKE_ptex.h"
 #include "BKE_key.h"
 #include "BKE_mball.h"
 #include "BKE_depsgraph.h"
@@ -2240,7 +2241,7 @@ Mesh *BKE_mesh_new_from_object(
 					mask |= CD_MASK_ORCO;
 
 				// TODO
-				mask |= CD_LOOP_PTEX;
+				mask |= CD_MASK_LOOP_PTEX;
 
 				/* Write the display mesh into the dummy mesh */
 				if (render)
@@ -2249,18 +2250,39 @@ Mesh *BKE_mesh_new_from_object(
 					dm = mesh_create_derived_view(sce, ob, mask);
 
 				tmpmesh = BKE_mesh_add(bmain, "Mesh");
-				DM_to_mesh(dm, tmpmesh, ob, mask);
+				DM_to_mesh(dm, tmpmesh, ob, mask | CD_MASK_TESSFACE_PTEX);
 				dm->release(dm);
 
 				// TODO: very TODO
 				{
-					MLoopPtex *dst_loop_ptex = CustomData_get_layer
-						(&tmpmesh->ldata, CD_LOOP_PTEX);
 					Mesh *src_me = ob->data;
-					MLoopPtex *src_loop_ptex = CustomData_get_layer
-						(&src_me->ldata, CD_LOOP_PTEX);
-					if (src_loop_ptex && dst_loop_ptex) {
-						dst_loop_ptex[0].image = src_loop_ptex[0].image;
+					const int num_layers =
+						CustomData_number_of_layers(&tmpmesh->ldata, CD_LOOP_PTEX);
+					/* const int off = CustomData_get_offset(&tmpmesh->ldata, */
+					/* 									  CD_LOOP_PTEX); */
+					int i;
+
+					BLI_assert(CustomData_number_of_layers(&src_me->ldata,
+														   CD_LOOP_PTEX) ==
+							   num_layers);
+
+					for (i = 0; i < num_layers; i++) {
+						const char *name = CustomData_get_layer_name(&tmpmesh->ldata,
+																	 CD_LOOP_PTEX, i);
+						MLoopPtex *dst = CustomData_get_layer_n
+							(&tmpmesh->ldata, CD_LOOP_PTEX, i);
+						
+						const MLoopPtex *src = CustomData_get_layer_n
+							(&src_me->ldata, CD_LOOP_PTEX, i);
+
+						if (src && dst && name) {
+							if (src->image) {
+								dst->image = src->image;
+							}
+							else {
+								dst->image = BKE_ptex_mesh_image_get(ob, name);
+							}
+						}
 					}
 				}
 			}
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c
index 4f19589..ed19a17 100644
--- a/source/blender/blenkernel/intern/mesh_evaluate.c
+++ b/source/blender/blenkernel/intern/mesh_evaluate.c
@@ -50,6 +50,7 @@
 #include "BKE_customdata.h"
 #include "BKE_mesh.h"
 #include "BKE_multires.h"
+#include "BKE_ptex.h"
 #include "BKE_report.h"
 
 #include "BLI_strict_flags.h"
@@ -1306,6 +1307,59 @@ void BKE_mesh_loops_to_mface_corners(
 	}
 }
 
+// TODO: de-dup with subsurf_ccg.c
+static int choose_weight_index(const MLoopInterp *loop_interp,
+							   const unsigned int *loop_indices,
+							   const int num_loop_indices)
+{
+	int highest = 0;
+	int i;
+
+	// TODO could assert that there's no tie
+
+	for (i = 0; i < num_loop_indices; i++) {
+		const MLoopInterp *src = &loop_interp[loop_indices[i]];
+		int j;
+
+		/* Find highest-weighted corner index */
+		for (j = 0; j < src->num_loops; j++) {
+			if (src->weights[j] > src->weights[highest]) {
+				highest = j;
+			}
+		}
+	}
+
+	return highest;
+}
+
+// TODO: de-dup with subsurf_ccg.c
+// TODO
+static void tess_corner_ptex_uv_interp(MTessFacePtex *tess_face_ptex,
+									   const MLoopInterp *loop_interp,
+									   const unsigned int *loop_indices,
+									   const int num_loop_indices)
+{
+	const int highest = choose_weight_index(loop_interp, loop_indices,
+											num_loop_indices);
+	int i;
+	/* TODO: outer bias */
+
+	for (i = 0; i < num_loop_indices; i++) {
+		const MLoopInterp *src = &loop_interp[loop_indices[i]];
+		const int num_loops = src->num_loops;
+		MLoopPtexUV *dst = &tess_face_ptex->corners[i];
+		float weights[3] = {0, 0, 0};
+
+		weights[0] = src->weights[(highest + num_loops - 1) % num_loops];
+		weights[1] = src->weights[highest];
+		weights[2] = src->weights[(highest + 1) % num_loops];
+
+		dst->uv[0] = weights[0] / weights[1];
+		dst->uv[1] = weights[2] / weights[1];
+		dst->id = src->orig_loop_indices[highest];
+	}
+}
+
 /**
  * Convert all CD layers from loop/poly to tessface data.
  *
@@ -1325,7 +1379,7 @@ void BKE_mesh_loops_to_tessdata(CustomData *fdata, CustomData *ldata, CustomData
 	const bool hasPCol = CustomData_has_layer(ldata, CD_PREVIEW_MLOOPCOL);
 	const bool hasOrigSpace = CustomData_has_layer(ldata, CD_ORIGSPACE_MLOOP);
 	const bool hasLoopNormal = CustomData_has_layer(ldata, CD_NORMAL);
-	const bool hasPtex = CustomData_has_layer(ldata, CD_LOOP_PTEX_UV);
+	const bool hasPtex = CustomData_has_layer(ldata, CD_LOOP_INTERP);
 	int findex, i, j;
 	const int *pidx;
 	unsigned int (*lidx)[4];
@@ -1393,12 +1447,18 @@ void BKE_mesh_loops_to_tessdata(CustomData *fdata, CustomData *ldata, CustomData
 
 	if (hasPtex) {
 		MTessFacePtex *dst = CustomData_get_layer(fdata, CD_TESSFACE_PTEX);
-		const MLoopPtexUV *src = CustomData_get_layer(ldata, CD_LOOP_PTEX_UV);
+		//const MLoopPtexUV *src = CustomData_get_layer(ldata, CD_LOOP_PTEX_UV);
+		const MLoopInterp *src = CustomData_get_layer(ldata, CD_LOOP_INTERP);
 
 		for (findex = 0, lidx = loopindices; findex < num_faces; lidx++, findex++, dst++) {
-			for (j = (mface ? mface[findex].v4 : (*lidx)[3]) ? 4 : 3; j--;) {
-				dst->corners[j] = src[(*lidx)[j]];
-			}
+			const int num_indices = ((mface ? mface[findex].v4 : (*lidx)[3]) ? 4 : 3);
+
+			tess_corner_ptex_uv_interp(dst, src, *lidx, num_indices);
+
+			/* for (j = (mface ? mface[findex].v4 : (*lidx)[3]) ? 4 : 3; j--;) { */
+			/* 	tess_face_ptex */
+			/* 	// dst->corners[j] = src[(*lidx)[j]]; */
+			/* } */
 		}
 	}
 }




More information about the Bf-blender-cvs mailing list