Commit: 23f60c36454093453ffffc87aafd4b23b632b537
Author: Nicholas Bishop
Date:   Wed Jan 28 14:43:32 2015 +0100
Branches: cycles-ptex-19
https://developer.blender.org/rB23f60c36454093453ffffc87aafd4b23b632b537

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..44b5511 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,7 +2250,7 @@ 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
@@ -2260,7 +2261,15 @@ Mesh *BKE_mesh_new_from_object(
                                        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;
+                                               if (src_loop_ptex->image) {
+                                                       dst_loop_ptex->image =
+                                                               
src_loop_ptex->image;
+                                               }
+                                               else {
+                                                       dst_loop_ptex->image =
+                                                               
BKE_ptex_mesh_image_get(ob);
+                                               }
+                                               
                                        }
                                }
                        }
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]]; */
+                       /* } */
                }
        }
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to