Commit: 8543536b89ddbbf68a55b1accdd46a0fa0dc18cc
Author: Nicholas Bishop
Date:   Mon Jan 19 15:59:55 2015 +0100
Branches: cycles-ptex-19
https://developer.blender.org/rB8543536b89ddbbf68a55b1accdd46a0fa0dc18cc

Add a couple new CustomData layers for Ptex

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

M       source/blender/blenkernel/intern/customdata.c
M       source/blender/makesdna/DNA_customdata_types.h

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

diff --git a/source/blender/blenkernel/intern/customdata.c 
b/source/blender/blenkernel/intern/customdata.c
index a259958..4d9107b 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -60,6 +60,7 @@
 #include "BKE_mesh_mapping.h"
 #include "BKE_mesh_remap.h"
 #include "BKE_multires.h"
+#include "BKE_ptex.h"
 
 #include "bmesh.h"
 
@@ -1141,6 +1142,133 @@ static void layerSwap_flnor(void *data, const int 
*corner_indices)
        memcpy(flnors, nors, sizeof(nors));
 }
 
+/*** CD_LOOP_PTEX ***/
+
+static void layerCopy_loop_ptex(const void *src, void *dst, int count)
+{
+       const MLoopPtex *loop_ptex_src = src;
+       MLoopPtex *loop_ptex_dst = dst;
+       int i;
+
+       memcpy(loop_ptex_dst, loop_ptex_src, sizeof(*loop_ptex_dst) * count);
+       for (i = 0; i < count; i++) {
+               loop_ptex_dst[i].rect = MEM_dupallocN(loop_ptex_dst[i].rect);
+       }
+}
+
+static void layerDefault_loop_ptex(void *data, int count)
+{
+       MLoopPtex *loop_ptex = data;
+       int i;
+
+       memset(loop_ptex, 0, sizeof(*loop_ptex) * count);
+       for (i = 0; i < count; i++) {
+               loop_ptex[i].texel_info.data_type = MPTEX_DATA_TYPE_UINT8;
+               loop_ptex[i].texel_info.num_channels = 4;
+       }
+}
+
+static void layerFree_loop_ptex(void *data, int count, int UNUSED(size))
+{
+       MLoopPtex *loop_ptex = data;
+       int i;
+
+       for (i = 0; i < count; i++) {
+               BKE_loop_ptex_free(&loop_ptex[i]);
+       }
+}
+
+/********************/
+
+/*** CD_LOOP_INTERP ***/
+
+static void layerCopy_loop_interp(const void *src, void *dst, int count)
+{
+       const MLoopInterp *loop_interp_src = src;
+       MLoopInterp *loop_interp_dst = dst;
+       int i;
+
+       memcpy(loop_interp_dst, loop_interp_src, sizeof(*loop_interp_dst) * 
count);
+       for (i = 0; i < count; i++) {
+               loop_interp_dst[i].weights = 
MEM_dupallocN(loop_interp_dst[i].weights);
+               loop_interp_dst[i].orig_loop_indices = 
MEM_dupallocN(loop_interp_dst[i].orig_loop_indices);
+       }
+}
+
+static void layerFree_loop_interp(void *data, int count, int UNUSED(size))
+{
+       MLoopInterp *loop_interp = data;
+       int i;
+
+       for (i = 0; i < count; i++) {
+               if (loop_interp[i].num_loops) {
+                       MEM_freeN(loop_interp[i].weights);
+                       MEM_freeN(loop_interp[i].orig_loop_indices);
+               }
+       }
+}
+
+static void layerInterp_loop_interp(void **sources, const float *weights,
+                                                                       const 
float *sub_weights, const int count,
+                                                                       void 
*dst)
+{
+       MLoopInterp *dst_loop_interp = dst;
+       int num_loops = -1;
+       int i;
+
+       /* TODO */
+       BLI_assert(weights);
+       BLI_assert(!sub_weights);
+       BLI_assert(dst_loop_interp->weights == NULL);
+       BLI_assert(dst_loop_interp->num_loops == 0);
+
+       for (i = 1; i < count; i++) {
+               const MLoopInterp *a = sources[0];
+               const MLoopInterp *b = sources[i];
+               BLI_assert(a->num_loops == b->num_loops);
+               BLI_assert(memcmp(a->orig_loop_indices, b->orig_loop_indices,
+                                                 sizeof(*a->orig_loop_indices) 
*
+                                                 a->num_loops) == 0);
+               num_loops = a->num_loops;
+
+               //BLI_assert(a->primary_loop == b->primary_loop);
+       }
+
+       BLI_assert(num_loops > 0);
+       dst_loop_interp->num_loops = num_loops;
+       dst_loop_interp->weights =
+               MEM_callocN(sizeof(*dst_loop_interp->weights) *
+                                       dst_loop_interp->num_loops,
+                                       "layerInterp_loop_interp");
+
+       dst_loop_interp->orig_loop_indices =
+               MEM_dupallocN(((MLoopInterp*)sources[0])->orig_loop_indices);
+
+       for (i = 0; i < count; i++) {
+               const MLoopInterp *src_loop_interp = sources[i];
+               const float w = weights[i];
+               int j;
+
+               for (j = 0; j < dst_loop_interp->num_loops; j++) {
+                       dst_loop_interp->weights[j] += 
src_loop_interp->weights[j] * w;
+               }
+       }
+
+       /* delay writing to the destination incase dest is in sources */
+       /* TODO */
+}
+
+static void layerDefault_loop_interp(void *data, int count)
+{
+       MLoopInterp *loop_interp = data;
+       // int i;
+
+       memset(loop_interp, 0, sizeof(*loop_interp) * count);
+       /* TODO */
+}
+
+/**********************/
+
 static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
        /* 0: CD_MVERT */
        {sizeof(MVert), "MVert", 1, NULL, NULL, NULL, NULL, NULL, NULL},
@@ -1255,6 +1383,15 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
        {sizeof(float[4]), "", 0, NULL, NULL, NULL, NULL, NULL, NULL},
        /* 40: CD_TESSLOOPNORMAL */
        {sizeof(short[4][3]), "", 0, NULL, NULL, NULL, NULL, layerSwap_flnor, 
NULL},
+       /* 41: CD_LOOP_INTERP */
+       {sizeof(MLoopInterp), "", 0, NULL, layerCopy_loop_interp,
+        layerFree_loop_interp, layerInterp_loop_interp, NULL,
+        layerDefault_loop_interp},
+       /* 42: CD_TESSFACE_PTEX */
+       {sizeof(MTessFacePtex), "MTessFacePtex", 1, NULL, NULL, NULL, NULL, 
NULL, NULL},
+       /* 43: CD_LOOP_PTEX */
+       {sizeof(MLoopPtex), "MLoopPtex", 1, N_("Ptex"), layerCopy_loop_ptex,
+        layerFree_loop_ptex, NULL, NULL, layerDefault_loop_ptex},
 };
 
 /* note, numbers are from trunk and need updating for bmesh */
@@ -1271,9 +1408,11 @@ static const char *LAYERTYPENAMES[CD_NUMTYPES] = {
        /* 30-34 */ "CDSubSurfCrease", "CDOrigSpaceLoop", "CDPreviewLoopCol", 
"CDBMElemPyPtr", "CDPaintMask",
        /* 35-36 */ "CDGridPaintMask", "CDMVertSkin",
        /* 37-40 */ "CDFreestyleEdge", "CDFreestyleFace", "CDMLoopTangent", 
"CDTessLoopNormal",
+       /* 41-43 */ "CDLoopInterp", "CDTessFacePtex", "CDLoopPtex",
 };
 
-
+/* TODO(nicholasbishop): some day I'll figure out what the hell these
+ * are intended to mean */
 const CustomDataMask CD_MASK_BAREMESH =
     CD_MASK_MVERT | CD_MASK_MEDGE | CD_MASK_MFACE | CD_MASK_MLOOP | 
CD_MASK_MPOLY | CD_MASK_BWEIGHT;
 const CustomDataMask CD_MASK_MESH =
@@ -1282,7 +1421,8 @@ const CustomDataMask CD_MASK_MESH =
     CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS |
     CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MPOLY | CD_MASK_MLOOP |
     CD_MASK_MTEXPOLY | CD_MASK_RECAST | CD_MASK_PAINT_MASK |
-    CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | 
CD_MASK_FREESTYLE_FACE;
+    CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | 
CD_MASK_FREESTYLE_FACE |
+       CD_MASK_TESSFACE_PTEX | CD_MASK_LOOP_PTEX | CD_MASK_LOOP_INTERP;
 const CustomDataMask CD_MASK_EDITMESH =
     CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MLOOPUV |
     CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | CD_MASK_SHAPE_KEYINDEX |
@@ -1295,13 +1435,16 @@ const CustomDataMask CD_MASK_DERIVEDMESH =
     CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | 
CD_MASK_PREVIEW_MLOOPCOL |
     CD_MASK_PROP_STR | CD_MASK_ORIGSPACE | CD_MASK_ORIGSPACE_MLOOP | 
CD_MASK_ORCO | CD_MASK_TANGENT |
     CD_MASK_PREVIEW_MCOL | CD_MASK_SHAPEKEY | CD_MASK_RECAST |
-    CD_MASK_ORIGINDEX | CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | 
CD_MASK_FREESTYLE_FACE;
+    CD_MASK_ORIGINDEX | CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | 
CD_MASK_FREESTYLE_FACE |
+       CD_MASK_TESSFACE_PTEX | CD_MASK_LOOP_PTEX | CD_MASK_LOOP_INTERP;
 const CustomDataMask CD_MASK_BMESH =
     CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY |
     CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_PROP_FLT | 
CD_MASK_PROP_INT |
     CD_MASK_PROP_STR | CD_MASK_SHAPEKEY | CD_MASK_SHAPE_KEYINDEX | 
CD_MASK_MDISPS |
     CD_MASK_CREASE | CD_MASK_BWEIGHT | CD_MASK_RECAST | CD_MASK_PAINT_MASK |
-    CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | 
CD_MASK_FREESTYLE_FACE;
+    CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | 
CD_MASK_FREESTYLE_FACE |
+    CD_MASK_LOOP_PTEX |
+       CD_MASK_LOOP_INTERP;
 const CustomDataMask CD_MASK_FACECORNERS =  /* XXX Not used anywhere! */
     CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_MTEXPOLY | CD_MASK_MLOOPUV |
     CD_MASK_MLOOPCOL | CD_MASK_NORMAL | CD_MASK_MLOOPTANGENT;
@@ -1316,7 +1459,8 @@ const CustomDataMask CD_MASK_EVERYTHING =
     /* BMESH ONLY END */
     CD_MASK_PAINT_MASK | CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN |
     CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE |
-    CD_MASK_MLOOPTANGENT | CD_MASK_TESSLOOPNORMAL;
+    CD_MASK_MLOOPTANGENT | CD_MASK_TESSLOOPNORMAL |
+       CD_MASK_TESSFACE_PTEX | CD_MASK_LOOP_PTEX | CD_MASK_LOOP_INTERP;
 
 static const LayerTypeInfo *layerType_getInfo(int type)
 {
@@ -2407,6 +2551,9 @@ void CustomData_from_bmeshpoly(CustomData *fdata, 
CustomData *pdata, CustomData
                else if (ldata->layers[i].type == CD_NORMAL) {
                        CustomData_add_layer_named(fdata, CD_TESSLOOPNORMAL, 
CD_CALLOC, NULL, total, ldata->layers[i].name);
                }
+               else if (ldata->layers[i].type == CD_LOOP_INTERP) {
+                       CustomData_add_layer_named(fdata, CD_TESSFACE_PTEX, 
CD_CALLOC, NULL, total, ldata->layers[i].name);
+               }
        }
 
        CustomData_bmesh_update_active_layers(fdata, pdata, ldata);
diff --git a/source/blender/makesdna/DNA_customdata_types.h 
b/source/blender/makesdna/DNA_customdata_types.h
index 7fedad2..b69f40a 100644
--- a/source/blender/makesdna/DNA_customdata_types.h
+++ b/source/blender/makesdna/DNA_customdata_types.h
@@ -63,9 +63,10 @@ typedef struct CustomDataExternal {
  * layers, each with a data type (e.g. MTFace, MDeformVert, etc.). */
 typedef struct CustomData {
        CustomDataLayer *layers;      /* CustomDataLayers, ordered by type */
-       int typemap[41];              /* runtime only! - maps types to indices 
of first layer of that type,
+       int typemap[44];              /* runtime only! - maps types to indices 
of first layer of that type,
                                       * MUST be >= CD_NUMTYPES, but we cant 
use a define here.
                                       * Correct size is ensured in 
CustomData_update_typemap assert() */
+       int pad;
        int totlayer, maxlayer;       /* number of layers, size of layers array 
*/
        int totsize;                  /* in editmode, total size of all data 
layers */
        struct BLI_mempool *pool;     /* (BMesh Only): Memory pool for 
allocation of blocks */
@@ -120,7 +121,11 @@ typedef enum CustomDataType {
        CD_MLOOPTANGENT     = 39,
        CD_TESSLOOPNORMAL   = 40,
 
-       CD_NUMTYPES         = 41
+       CD_LOOP_INTERP      = 41,
+       CD_TESSFACE_PTEX    = 42,
+       CD_LOOP_PTEX        = 43,
+
+       CD_NUMTYPES         = 44
 } CustomDataType;
 
 /* Bits for CustomDataMask */
@@ -168,6 +173,10 @@ typedef enum CustomDataType {
 #define CD_MASK_MLOOPTANGENT    (1LL << CD_MLOOPTANGENT)
 #define CD_MASK_TESSLOOPNORMAL  (1LL << CD_TESSLOOPNORMAL)
 
+#define CD_MASK_TESSFACE_PTEX   (1LL << CD_TESSFACE_PTEX)
+#define CD_MASK_LOOP_PTEX       (1LL << CD_LOOP_PTEX)
+#define CD_MASK_LOOP_INTERP     (1L

@@ Diff output truncated at 10240 characters. @@

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

Reply via email to