[Bf-blender-cvs] [ec8b7ed] master: Fix: solved issue with make doc_py

2015-07-22 Thread Sybren A. Stüvel
Commit: ec8b7edf536a5fc9c74fc84b1b70a48763fc81e7
Author: Sybren A. Stüvel
Date:   Wed Jul 22 10:20:45 2015 +0200
Branches: master
https://developer.blender.org/rBec8b7edf536a5fc9c74fc84b1b70a48763fc81e7

Fix: solved issue with make doc_py

The error was ValueError: Function function normal_at_I0D at 0x7f2aad1feb70
has keyword-only arguments or annotations, use getfullargspec() API which can
support them, and was first seen in eeeb845d33e81afbc8ed127e6ab4ae7b18472a54

===

M   doc/python_api/sphinx_doc_gen.py

===

diff --git a/doc/python_api/sphinx_doc_gen.py b/doc/python_api/sphinx_doc_gen.py
index 32776ef..05ea0d0 100644
--- a/doc/python_api/sphinx_doc_gen.py
+++ b/doc/python_api/sphinx_doc_gen.py
@@ -631,7 +631,7 @@ def pyfunc2sphinx(ident, fw, module_name, type_name, 
identifier, py_func, is_cla
 if type(py_func) == MethodType:
 return
 
-arg_str = inspect.formatargspec(*inspect.getargspec(py_func))
+arg_str = inspect.formatargspec(*inspect.getfullargspec(py_func))
 
 if not is_class:
 func_type = function

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [3dd8f28] master: Render preview: Make preview render database lazily loaded

2015-07-22 Thread Sergey Sharybin
Commit: 3dd8f287e1fd0993eef8cac782c30a264ebb0d71
Author: Sergey Sharybin
Date:   Wed Jul 22 11:24:38 2015 +0200
Branches: master
https://developer.blender.org/rB3dd8f287e1fd0993eef8cac782c30a264ebb0d71

Render preview: Make preview render database lazily loaded

Gives about 5-10% of startup time improvement here.

===

M   source/blender/editors/include/ED_render.h
M   source/blender/editors/render/render_preview.c
M   source/blender/windowmanager/intern/wm_init_exit.c

===

diff --git a/source/blender/editors/include/ED_render.h 
b/source/blender/editors/include/ED_render.h
index ba58ae6..1898b9c 100644
--- a/source/blender/editors/include/ED_render.h
+++ b/source/blender/editors/include/ED_render.h
@@ -70,7 +70,7 @@ enum {
PR_ICON_DEFERRED = 3,
 };
 
-void ED_preview_init_dbase(void);
+void ED_preview_ensure_dbase(void);
 void ED_preview_free_dbase(void);
 
 void ED_preview_shader_job(const struct bContext *C, void *owner, struct ID 
*id, struct ID *parent, struct MTex *slot, int sizex, int sizey, int method);
diff --git a/source/blender/editors/render/render_preview.c 
b/source/blender/editors/render/render_preview.c
index 0a7455b..6dfd2b3 100644
--- a/source/blender/editors/render/render_preview.c
+++ b/source/blender/editors/render/render_preview.c
@@ -94,7 +94,10 @@
 #include ED_datafiles.h
 #include ED_render.h
 
-
+#ifndef NDEBUG
+/* Used for database init assert(). */
+#  include BLI_threads.h
+#endif
 
 ImBuf *get_brush_icon(Brush *brush)
 {
@@ -204,11 +207,16 @@ static Main *load_main_from_memory(const void *blend, int 
blend_size)
 }
 #endif
 
-void ED_preview_init_dbase(void)
+void ED_preview_ensure_dbase(void)
 {
 #ifndef WITH_HEADLESS
-   G_pr_main = load_main_from_memory(datatoc_preview_blend, 
datatoc_preview_blend_size);
-   G_pr_main_cycles = load_main_from_memory(datatoc_preview_cycles_blend, 
datatoc_preview_cycles_blend_size);
+   static bool base_initialized = false;
+   BLI_assert(BLI_thread_is_main());
+   if (!base_initialized) {
+   G_pr_main = load_main_from_memory(datatoc_preview_blend, 
datatoc_preview_blend_size);
+   G_pr_main_cycles = 
load_main_from_memory(datatoc_preview_cycles_blend, 
datatoc_preview_cycles_blend_size);
+   base_initialized = true;
+   }
 #endif
 }
 
@@ -1152,6 +1160,8 @@ void ED_preview_icon_render(Main *bmain, Scene *scene, ID 
*id, unsigned int *rec
short stop = false, update = false;
float progress = 0.0f;
 
+   ED_preview_ensure_dbase();
+
ip.bmain = bmain;
ip.scene = scene;
ip.owner = id;
@@ -1170,7 +1180,9 @@ void ED_preview_icon_job(const bContext *C, void *owner, 
ID *id, unsigned int *r
 {
wmJob *wm_job;
IconPreview *ip, *old_ip;
-   
+
+   ED_preview_ensure_dbase();
+
/* suspended start means it starts after 1 timer step, see 
WM_jobs_timer below */
wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), owner, Icon 
Preview,
 WM_JOB_EXCL_RENDER | WM_JOB_SUSPEND, 
WM_JOB_TYPE_RENDER_PREVIEW);
@@ -1212,6 +1224,8 @@ void ED_preview_shader_job(const bContext *C, void 
*owner, ID *id, ID *parent, M
return;
}
 
+   ED_preview_ensure_dbase();
+
wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), owner, 
Shader Preview,
WM_JOB_EXCL_RENDER, WM_JOB_TYPE_RENDER_PREVIEW);
sp = MEM_callocN(sizeof(ShaderPreview), shader preview);
diff --git a/source/blender/windowmanager/intern/wm_init_exit.c 
b/source/blender/windowmanager/intern/wm_init_exit.c
index ad7044c..a1d0939 100644
--- a/source/blender/windowmanager/intern/wm_init_exit.c
+++ b/source/blender/windowmanager/intern/wm_init_exit.c
@@ -229,9 +229,7 @@ void WM_init(bContext *C, int argc, const char **argv)
ED_render_clear_mtex_copybuf();
 
// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-   
-   ED_preview_init_dbase();
-   
+
wm_read_history();
 
/* allow a path of , this is what happens when making a new file */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [83e0534] temp-tangent-refactor: Fix merge conflict caused by own smartness failing

2015-07-22 Thread Antony Riakiotakis
Commit: 83e0534781b2e62ba01d9fa2a873243e9a45ba26
Author: Antony Riakiotakis
Date:   Wed Jul 22 12:39:36 2015 +0200
Branches: temp-tangent-refactor
https://developer.blender.org/rB83e0534781b2e62ba01d9fa2a873243e9a45ba26

Fix merge conflict caused by own smartness failing

===

M   source/blender/blenkernel/intern/DerivedMesh.c

===

diff --git a/source/blender/blenkernel/intern/DerivedMesh.c 
b/source/blender/blenkernel/intern/DerivedMesh.c
index e71c865..63766b7 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -3208,11 +3208,7 @@ void DM_calc_auto_bump_scale(DerivedMesh *dm)
 
 void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs 
*gattribs, DMVertexAttribs *attribs)
 {
- HEAD
-   CustomData *vdata;
-===
CustomData *vdata, *ldata;
- campbell_tangents
int a, b, layer;
 
/* From the layers requested by the GLSL shader, figure out which ones 
are
@@ -3221,10 +3217,7 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, 
GPUVertexAttribs *gattribs,
memset(attribs, 0, sizeof(DMVertexAttribs));
 
vdata = dm-vertData;
- HEAD
-===
ldata = dm-getLoopDataLayout(dm);
- campbell_tangents

/* calc auto bump scale if necessary */
if (dm-auto_bump_scale = 0.0f)
@@ -3232,15 +3225,10 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, 
GPUVertexAttribs *gattribs,
 
/* add a tangent layer if necessary */
for (b = 0; b  gattribs-totlayer; b++)
- HEAD
-   if (gattribs-layer[b].type == CD_TANGENT) {
-   CustomData *ldata = dm-getLoopDataLayout(dm);
-===
if (gattribs-layer[b].type == CD_TANGENT)
- campbell_tangents
if (CustomData_get_layer_index(ldata, CD_TANGENT) == -1)
DM_add_tangent_layer(dm);
-   }
+
for (b = 0; b  gattribs-totlayer; b++) {
if (gattribs-layer[b].type == CD_MTFACE) {
/* uv coordinates */
@@ -3336,11 +3324,6 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, 
GPUVertexAttribs *gattribs,
}
}
else if (gattribs-layer[b].type == CD_TANGENT) {
- HEAD
-   /* tangents */
-   CustomData *ldata = dm-getLoopDataLayout(dm);
-===
- campbell_tangents
layer = CustomData_get_layer_index(ldata, CD_TANGENT);
 
attribs-tottang = 1;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [1d445e4] temp-tangent-refactor: Move display code and tangent calculation to loops WIP patch by Campbell

2015-07-22 Thread Antony Riakiotakis
Commit: 1d445e48b0eafa20b2ab9248c4c83e9b2aa2ccd7
Author: Antony Riakiotakis
Date:   Wed Jul 22 12:08:20 2015 +0200
Branches: temp-tangent-refactor
https://developer.blender.org/rB1d445e48b0eafa20b2ab9248c4c83e9b2aa2ccd7

Move display code and tangent calculation to loops WIP patch by Campbell

===

M   source/blender/blenkernel/intern/DerivedMesh.c
M   source/blender/blenkernel/intern/cdderivedmesh.c

===

diff --git a/source/blender/blenkernel/intern/DerivedMesh.c 
b/source/blender/blenkernel/intern/DerivedMesh.c
index 32d0375..e71c865 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -2893,9 +2893,11 @@ void mesh_get_mapped_verts_coords(DerivedMesh *dm, float 
(*r_cos)[3], const int
 
 typedef struct {
float (*precomputedFaceNormals)[3];
-   short (*precomputedLoopNormals)[4][3];
-   MTFace *mtface; /* texture coordinates */
-   MFace *mface;   /* indices */
+   float (*precomputedLoopNormals)[3];
+   const MLoopTri *looptri;
+   MLoopUV *mloopuv;   /* texture coordinates */
+   MPoly *mpoly;   /* indices */
+   MLoop *mloop;   /* indices */
MVert *mvert;   /* vertices  normals */
float (*orco)[3];
float (*tangent)[4];/* destination */
@@ -2914,15 +2916,17 @@ static int GetNumFaces(const SMikkTSpaceContext 
*pContext)
 
 static int GetNumVertsOfFace(const SMikkTSpaceContext *pContext, const int 
face_num)
 {
-   SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) 
pContext-m_pUserData;
-   return pMesh-mface[face_num].v4 != 0 ? 4 : 3;
+   //SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) 
pContext-m_pUserData;
+   UNUSED_VARS(pContext, face_num);
+   return 3;
 }
 
 static void GetPosition(const SMikkTSpaceContext *pContext, float r_co[3], 
const int face_num, const int vert_index)
 {
//assert(vert_index = 0  vert_index  4);
SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) 
pContext-m_pUserData;
-   const float *co = 
pMesh-mvert[(pMesh-mface[face_num].v1)[vert_index]].co;
+   const MLoopTri *lt = pMesh-looptri[face_num];
+   const float *co = pMesh-mvert[pMesh-mloop[lt-tri[vert_index]].v].co;
copy_v3_v3(r_co, co);
 }
 
@@ -2930,13 +2934,14 @@ static void GetTextureCoordinate(const 
SMikkTSpaceContext *pContext, float r_uv[
 {
//assert(vert_index = 0  vert_index  4);
SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) 
pContext-m_pUserData;
+   const MLoopTri *lt = pMesh-looptri[face_num];
 
-   if (pMesh-mtface != NULL) {
-   const float *uv = pMesh-mtface[face_num].uv[vert_index];
+   if (pMesh-mloopuv != NULL) {
+   const float *uv = pMesh-mloopuv[lt-tri[vert_index]].uv;
copy_v2_v2(r_uv, uv);
}
else {
-   const float *orco = 
pMesh-orco[(pMesh-mface[face_num].v1)[vert_index]];
+   const float *orco = 
pMesh-orco[pMesh-mloop[lt-tri[vert_index]].v];
map_to_sphere(r_uv[0], r_uv[1], orco[0], orco[1], orco[2]);
}
 }
@@ -2945,41 +2950,36 @@ static void GetNormal(const SMikkTSpaceContext 
*pContext, float r_no[3], const i
 {
//assert(vert_index = 0  vert_index  4);
SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) 
pContext-m_pUserData;
-   const bool smoothnormal = (pMesh-mface[face_num].flag  ME_SMOOTH) != 
0;
+   const MLoopTri *lt = pMesh-looptri[face_num];
+   const bool smoothnormal = (pMesh-mpoly[lt-poly].flag  ME_SMOOTH) != 
0;
 
if (pMesh-precomputedLoopNormals) {
-   normal_short_to_float_v3(r_no, 
pMesh-precomputedLoopNormals[face_num][vert_index]);
+   copy_v3_v3(r_no, 
pMesh-precomputedLoopNormals[lt-tri[vert_index]]);
}
else if (!smoothnormal) {// flat
if (pMesh-precomputedFaceNormals) {
-   copy_v3_v3(r_no, 
pMesh-precomputedFaceNormals[face_num]);
+   copy_v3_v3(r_no, 
pMesh-precomputedFaceNormals[lt-poly]);
}
else {
-   MFace *mf = pMesh-mface[face_num];
-   const float *p0 = pMesh-mvert[mf-v1].co;
-   const float *p1 = pMesh-mvert[mf-v2].co;
-   const float *p2 = pMesh-mvert[mf-v3].co;
-
-   if (mf-v4) {
-   const float *p3 = pMesh-mvert[mf-v4].co;
-   normal_quad_v3(r_no, p0, p1, p2, p3);
-   }
-   else {
-   normal_tri_v3(r_no, p0, p1, p2);
-   }
+   const float *p0 = 
pMesh-mvert[pMesh-mloop[lt-tri[0]].v].co;
+   const float *p1 = 

[Bf-blender-cvs] [2910940] temp-tangent-refactor: Convert tangent layer and baking to use looptris. This is WIP code to make sure all blender uses tangents generated from loops.

2015-07-22 Thread Antony Riakiotakis
Commit: 29109403e002b0a07f7637c2b65351c3d5ec0783
Author: Antony Riakiotakis
Date:   Fri Jul 17 18:22:11 2015 +0200
Branches: temp-tangent-refactor
https://developer.blender.org/rB29109403e002b0a07f7637c2b65351c3d5ec0783

Convert tangent layer and baking to use looptris. This is WIP code
to make sure all blender uses tangents generated from loops.

===

M   source/blender/blenkernel/BKE_multires.h
M   source/blender/blenkernel/intern/DerivedMesh.c
M   source/blender/blenkernel/intern/multires.c
M   source/blender/render/intern/source/bake_api.c
M   source/blender/render/intern/source/multires_bake.c
M   source/gameengine/Converter/BL_BlenderDataConversion.cpp

===

diff --git a/source/blender/blenkernel/BKE_multires.h 
b/source/blender/blenkernel/BKE_multires.h
index a8242a5..178751d 100644
--- a/source/blender/blenkernel/BKE_multires.h
+++ b/source/blender/blenkernel/BKE_multires.h
@@ -42,6 +42,11 @@ struct MultiresModifierData;
 struct Object;
 struct Scene;
 
+struct MLoop;
+struct MVert;
+struct MPoly;
+struct MLoopTri;
+
 /* Delete mesh mdisps and grid paint masks */
 void multires_customdata_delete(struct Mesh *me);
 
@@ -114,6 +119,6 @@ void multires_topology_changed(struct Mesh *me);
 
 / interpolation stuff /
 void old_mdisps_bilinear(float out[3], float (*disps)[3], const int st, float 
u, float v);
-int mdisp_rot_face_to_crn(const int corners, const int face_side, const float 
u, const float v, float *x, float *y);
+int mdisp_rot_face_to_crn(struct MVert *mvert, struct MPoly *mpoly, struct 
MLoop *mloops, const struct MLoopTri *lt, const int face_side, const float u, 
const float v, float *x, float *y);
 
 #endif  /* __BKE_MULTIRES_H__ */
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c 
b/source/blender/blenkernel/intern/DerivedMesh.c
index 05ec83e..32d0375 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -2995,7 +2995,7 @@ void DM_add_tangent_layer(DerivedMesh *dm)
float (*fnors)[3];
short (*tlnors)[4][3];
 
-   if (CustomData_get_layer_index(dm-faceData, CD_TANGENT) != -1)
+   if (CustomData_get_layer_index(dm-loopData, CD_TANGENT) != -1)
return;
 
fnors = dm-getTessFaceDataArray(dm, CD_NORMAL);
@@ -3019,8 +3019,8 @@ void DM_add_tangent_layer(DerivedMesh *dm)
}

/* create tangent layer */
-   DM_add_tessface_layer(dm, CD_TANGENT, CD_CALLOC, NULL);
-   tangent = DM_get_tessface_data_layer(dm, CD_TANGENT);
+   DM_add_loop_layer(dm, CD_TANGENT, CD_CALLOC, NULL);
+   tangent = DM_get_loop_data_layer(dm, CD_TANGENT);

/* new computation method */
{
@@ -3202,7 +3202,7 @@ void DM_calc_auto_bump_scale(DerivedMesh *dm)
 
 void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs 
*gattribs, DMVertexAttribs *attribs)
 {
-   CustomData *vdata, *fdata, *tfdata = NULL;
+   CustomData *vdata;
int a, b, layer;
 
/* From the layers requested by the GLSL shader, figure out which ones 
are
@@ -3211,7 +3211,6 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, 
GPUVertexAttribs *gattribs,
memset(attribs, 0, sizeof(DMVertexAttribs));
 
vdata = dm-vertData;
-   fdata = tfdata = dm-getTessFaceDataLayout(dm);

/* calc auto bump scale if necessary */
if (dm-auto_bump_scale = 0.0f)
@@ -3219,10 +3218,11 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, 
GPUVertexAttribs *gattribs,
 
/* add a tangent layer if necessary */
for (b = 0; b  gattribs-totlayer; b++)
-   if (gattribs-layer[b].type == CD_TANGENT)
-   if (CustomData_get_layer_index(fdata, CD_TANGENT) == -1)
+   if (gattribs-layer[b].type == CD_TANGENT) {
+   CustomData *ldata = dm-getLoopDataLayout(dm);
+   if (CustomData_get_layer_index(ldata, CD_TANGENT) == -1)
DM_add_tangent_layer(dm);
-
+   }
for (b = 0; b  gattribs-totlayer; b++) {
if (gattribs-layer[b].type == CD_MTFACE) {
/* uv coordinates */
@@ -3328,13 +3328,14 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, 
GPUVertexAttribs *gattribs,
}
else if (gattribs-layer[b].type == CD_TANGENT) {
/* tangents */
-   layer = CustomData_get_layer_index(fdata, CD_TANGENT);
+   CustomData *ldata = dm-getLoopDataLayout(dm);
+   layer = CustomData_get_layer_index(ldata, CD_TANGENT);
 
attribs-tottang = 1;
 
if (layer != -1) {
-   attribs-tang.array = fdata-layers[layer].data;
-   

[Bf-blender-cvs] [cf60027] master: Don't make Python classes of StructRNA on startup

2015-07-22 Thread Campbell Barton
Commit: cf6002737da7a842650d47569385467f4812cb78
Author: Campbell Barton
Date:   Wed Jul 22 19:41:59 2015 +1000
Branches: master
https://developer.blender.org/rBcf6002737da7a842650d47569385467f4812cb78

Don't make Python classes of StructRNA on startup

This gives small start time speedup, classes are lazy loaded instead.

Keep existing behavior in debug builds to catch any errors early.

===

M   source/blender/python/intern/bpy_rna.c

===

diff --git a/source/blender/python/intern/bpy_rna.c 
b/source/blender/python/intern/bpy_rna.c
index d15e3b3..af4b239 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -7446,8 +7446,14 @@ static void bpy_class_free(void *pyob_ptr)
PyGILState_Release(gilstate);
 }
 
+/**
+ * \note This isn't essential to run on startup, since subtypes will lazy 
initialize.
+ * But keep running in debug mode so we get immediate notification of bad 
class hierarchy
+ * or any errors in bpy_types.py at load time, so errors don't go unnoticed.
+ */
 void pyrna_alloc_types(void)
 {
+#ifdef DEBUG
PyGILState_STATE gilstate;
 
PointerRNA ptr;
@@ -7475,6 +7481,7 @@ void pyrna_alloc_types(void)
RNA_PROP_END;
 
PyGILState_Release(gilstate);
+#endif  /* DEBUG */
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [945f32e] master: Fix crash with recent refactor of customdata writing.

2015-07-22 Thread Bastien Montagne
Commit: 945f32e66d6ada2a05b7700a197209b9c66b4682
Author: Bastien Montagne
Date:   Wed Jul 22 11:54:53 2015 +0200
Branches: master
https://developer.blender.org/rB945f32e66d6ada2a05b7700a197209b9c66b4682

Fix crash with recent refactor of customdata writing.

Caused by own rBff3d535bc2a6309 - since we now only write the exact amount of 
layers
needed to store saved customdata, we have to adjust CustomData-maxlayer too.

Otherwise, on next read, customdata code believes it has more layers allocated 
than
actual number.

Issue reported by Campbell over IRC, thanks.

===

M   source/blender/blenkernel/intern/customdata.c

===

diff --git a/source/blender/blenkernel/intern/customdata.c 
b/source/blender/blenkernel/intern/customdata.c
index abfe746..b1740d4 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -3251,6 +3251,7 @@ void CustomData_file_write_prepare(
}
}
BLI_assert(j == data-totlayer);
+   data-maxlayer = data-totlayer;  /* We only write that much of data! */
*r_write_layers = write_layers;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [4613405] master: OpenSubdiv: Resolve crash when trying to do weight mcol

2015-07-22 Thread Sergey Sharybin
Commit: 461340525eea970a9d85d3958cc58bfda07abe7b
Author: Sergey Sharybin
Date:   Wed Jul 22 11:58:48 2015 +0200
Branches: master
https://developer.blender.org/rB461340525eea970a9d85d3958cc58bfda07abe7b

OpenSubdiv: Resolve crash when trying to do weight mcol

===

M   source/blender/blenkernel/intern/DerivedMesh.c

===

diff --git a/source/blender/blenkernel/intern/DerivedMesh.c 
b/source/blender/blenkernel/intern/DerivedMesh.c
index 05ec83e..3f4b1ee 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -2186,8 +2186,12 @@ static void editbmesh_calc_modifiers(
 #if 0 /* XXX Will re-enable this when we have global mod stack options. */
const bool do_final_wmcol = (scene-toolsettings-weights_preview == 
WP_WPREVIEW_FINAL)  do_wmcol;
 #endif
+#ifndef WITH_OPENSUBDIV
const bool do_final_wmcol = false;
const bool do_init_wmcol = Mesh *)ob-data)-drawflag  
ME_DRAWEIGHT)  !do_final_wmcol);
+#else
+   const bool do_init_wmcol = false;
+#endif
const bool do_init_statvis = Mesh *)ob-data)-drawflag  
ME_DRAW_STATVIS)  !do_init_wmcol);
const bool do_mod_wmcol = do_init_wmcol;
VirtualModifierData virtualModifierData;
@@ -2480,7 +2484,7 @@ static void mesh_build_data(
 
 #ifdef WITH_OPENSUBDIV
if (calc_modifiers_skip_orco(ob)) {
-   dataMask = ~CD_MASK_ORCO;
+   dataMask = ~(CD_MASK_ORCO | CD_MASK_PREVIEW_MCOL);
}
 #endif
 
@@ -2515,7 +2519,7 @@ static void editbmesh_build_data(Scene *scene, Object 
*obedit, BMEditMesh *em, C
 
 #ifdef WITH_OPENSUBDIV
if (calc_modifiers_skip_orco(obedit)) {
-   dataMask = ~CD_MASK_ORCO;
+   dataMask = ~(CD_MASK_ORCO | CD_MASK_PREVIEW_MCOL);
}
 #endif

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [75d1723] master: OpenSubdiv: Optimize speed of topology refiner construction

2015-07-22 Thread Sergey Sharybin
Commit: 75d1723518314632ef247ebe49f677856c8bf115
Author: Sergey Sharybin
Date:   Wed Jul 22 12:48:22 2015 +0200
Branches: master
https://developer.blender.org/rB75d1723518314632ef247ebe49f677856c8bf115

OpenSubdiv: Optimize speed of topology refiner construction

Now the conversion code uses mesh element mapping to speed up lookups.
Gives really nice speed improvement here, but the cost is higher memory
usage during refiner construction.

On the dragon scene here topology refiner construction time goes down
from 5 seconds to around 0.01.

It's possible to reduce the memory footprint by allocating mapping in
stages (don't allocate all of them at once, but do it on demand only
and free them after they're not needed anymore).

===

M   source/blender/blenkernel/intern/CCGSubSurf_opensubdiv_converter.c

===

diff --git a/source/blender/blenkernel/intern/CCGSubSurf_opensubdiv_converter.c 
b/source/blender/blenkernel/intern/CCGSubSurf_opensubdiv_converter.c
index c66425b..c4317f4 100644
--- a/source/blender/blenkernel/intern/CCGSubSurf_opensubdiv_converter.c
+++ b/source/blender/blenkernel/intern/CCGSubSurf_opensubdiv_converter.c
@@ -36,10 +36,16 @@
 #include CCGSubSurf_intern.h
 
 #include BKE_DerivedMesh.h
+#include BKE_mesh_mapping.h
 
 #include opensubdiv_capi.h
 #include opensubdiv_converter_capi.h
 
+/* Use mesh element mapping structures during conversion.
+ * Uses more memory but is much faster than naive algorithm.
+ */
+#define USE_MESH_ELEMENT_MAPPING
+
 /**
  * Converter from DerivedMesh.
  */
@@ -47,11 +53,16 @@
 typedef struct ConvDMStorage {
CCGSubSurf *ss;
DerivedMesh *dm;
-} ConvDMStorage;
 
-/* TODO(sergey): Optimize this by using mesh_map, so we don't
- * do full mesh lookup for every geometry primitive.
- */
+#ifdef USE_MESH_ELEMENT_MAPPING
+   MeshElemMap *vert_edge_map,
+   *vert_poly_map,
+   *edge_poly_map;
+   int *vert_edge_mem,
+   *vert_poly_mem,
+   *edge_poly_mem;
+#endif
+} ConvDMStorage;
 
 static OpenSubdiv_SchemeType conv_dm_get_type(
 const OpenSubdiv_Converter *converter)
@@ -140,6 +151,7 @@ static int conv_dm_get_num_edge_faces(const 
OpenSubdiv_Converter *converter,
   int edge)
 {
ConvDMStorage *storage = converter-user_data;
+#ifndef USE_MESH_ELEMENT_MAPPING
DerivedMesh *dm = storage-dm;
const MLoop *ml = dm-getLoopArray(dm);
const MPoly *mp = dm-getPolyArray(dm);
@@ -156,6 +168,9 @@ static int conv_dm_get_num_edge_faces(const 
OpenSubdiv_Converter *converter,
}
}
return num;
+#else
+   return storage-edge_poly_map[edge].count;
+#endif
 }
 
 static void conv_dm_get_edge_faces(const OpenSubdiv_Converter *converter,
@@ -163,6 +178,7 @@ static void conv_dm_get_edge_faces(const 
OpenSubdiv_Converter *converter,
int *edge_faces)
 {
ConvDMStorage *storage = converter-user_data;
+#ifndef USE_MESH_ELEMENT_MAPPING
DerivedMesh *dm = storage-dm;
const MLoop *ml = dm-getLoopArray(dm);
const MPoly *mp = dm-getPolyArray(dm);
@@ -178,6 +194,11 @@ static void conv_dm_get_edge_faces(const 
OpenSubdiv_Converter *converter,
}
}
}
+#else
+   memcpy(edge_faces,
+  storage-edge_poly_map[edge].indices,
+  sizeof(int) * storage-edge_poly_map[edge].count);
+#endif
 }
 
 static float conv_dm_get_edge_sharpness(const OpenSubdiv_Converter *converter,
@@ -194,6 +215,7 @@ static int conv_dm_get_num_vert_edges(const 
OpenSubdiv_Converter *converter,
   int vert)
 {
ConvDMStorage *storage = converter-user_data;
+#ifndef USE_MESH_ELEMENT_MAPPING
DerivedMesh *dm = storage-dm;
const MEdge *me = dm-getEdgeArray(dm);
int num = 0, edge;
@@ -204,6 +226,9 @@ static int conv_dm_get_num_vert_edges(const 
OpenSubdiv_Converter *converter,
}
}
return num;
+#else
+   return storage-vert_edge_map[vert].count;
+#endif
 }
 
 static void conv_dm_get_vert_edges(const OpenSubdiv_Converter *converter,
@@ -211,6 +236,7 @@ static void conv_dm_get_vert_edges(const 
OpenSubdiv_Converter *converter,
int *vert_edges)
 {
ConvDMStorage *storage = converter-user_data;
+#ifndef USE_MESH_ELEMENT_MAPPING
DerivedMesh *dm = storage-dm;
const MEdge *me = dm-getEdgeArray(dm);
int num = 0, edge;
@@ -220,12 +246,18 @@ static void conv_dm_get_vert_edges(const 
OpenSubdiv_Converter *converter,
vert_edges[num++] = edge;
}
}
+#else
+   memcpy(vert_edges,
+  storage-vert_edge_map[vert].indices,
+  sizeof(int) * storage-vert_edge_map[vert].count);

[Bf-blender-cvs] [b604d5a] master: Add bvhtree_from_mesh_looptri utility function

2015-07-22 Thread Campbell Barton
Commit: b604d5ade0fde241c84b802b4f7b7426f12d48be
Author: Campbell Barton
Date:   Wed Jul 22 20:55:46 2015 +1000
Branches: master
https://developer.blender.org/rBb604d5ade0fde241c84b802b4f7b7426f12d48be

Add bvhtree_from_mesh_looptri utility function

===

M   source/blender/blenkernel/BKE_bvhutils.h
M   source/blender/blenkernel/intern/bvhutils.c

===

diff --git a/source/blender/blenkernel/BKE_bvhutils.h 
b/source/blender/blenkernel/BKE_bvhutils.h
index a956933a..9220082 100644
--- a/source/blender/blenkernel/BKE_bvhutils.h
+++ b/source/blender/blenkernel/BKE_bvhutils.h
@@ -56,9 +56,13 @@ typedef struct BVHTreeFromMesh {
const struct MVert *vert;
const struct MEdge *edge; /* only used for BVHTreeFromMeshEdges */
const struct MFace *face;
+   const struct MLoop *loop;
+   const struct MLoopTri *looptri;
bool vert_allocated;
bool edge_allocated;
bool face_allocated;
+   bool loop_allocated;
+   bool looptri_allocated;
 
/* radius for raycast */
float sphere_radius;
@@ -100,6 +104,16 @@ BVHTree *bvhtree_from_mesh_faces_ex(
 BLI_bitmap *mask, int numFaces_active,
 float epsilon, int tree_type, int axis);
 
+BVHTree *bvhtree_from_mesh_looptri(
+struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, float epsilon, 
int tree_type, int axis);
+BVHTree *bvhtree_from_mesh_looptri_ex(
+struct BVHTreeFromMesh *data,
+const struct MVert *vert, const bool vert_allocated,
+const struct MLoop *mloop, const bool loop_allocated,
+const struct MLoopTri *looptri, const int numFaces, const bool 
face_allocated,
+BLI_bitmap *mask, int numFaces_active,
+float epsilon, int tree_type, int axis);
+
 /**
  * Frees data allocated by a call to bvhtree_from_mesh_*.
  */
@@ -125,6 +139,7 @@ enum {
BVHTREE_FROM_EDGES   = 1,
BVHTREE_FROM_FACES   = 2,
BVHTREE_FROM_FACES_EDITMESH  = 3,
+   BVHTREE_FROM_LOOPTRI = 4,
 };
 
 typedef struct LinkNode *BVHCache;
diff --git a/source/blender/blenkernel/intern/bvhutils.c 
b/source/blender/blenkernel/intern/bvhutils.c
index 8ef2f35..e42c73f 100644
--- a/source/blender/blenkernel/intern/bvhutils.c
+++ b/source/blender/blenkernel/intern/bvhutils.c
@@ -776,6 +776,271 @@ BVHTree *bvhtree_from_mesh_faces_ex(
 /** \} */
 
 
+/*  */
+
+/** \name LoopTri Face Builder
+ * \{ */
+
+static BVHTree *bvhtree_from_mesh_looptri_create_tree(
+float epsilon, int tree_type, int axis,
+BMEditMesh *em, const MVert *vert, const MLoop *mloop, const MLoopTri 
*looptri, const int numFaces,
+BLI_bitmap *mask, int numFaces_active)
+{
+   BVHTree *tree = NULL;
+   int i;
+
+   if (numFaces) {
+   if (mask  numFaces_active  0) {
+   numFaces_active = 0;
+   for (i = 0; i  numFaces; i++) {
+   if (BLI_BITMAP_TEST_BOOL(mask, i)) {
+   numFaces_active++;
+   }
+   }
+   }
+   else if (!mask) {
+   numFaces_active = numFaces;
+   }
+
+   /* Create a bvh-tree of the given target */
+   /* printf(%s: building BVH, total=%d\n, __func__, numFaces); 
*/
+   tree = BLI_bvhtree_new(numFaces_active, epsilon, tree_type, 
axis);
+   if (tree) {
+   if (em) {
+   const struct BMLoop *(*looptris)[3] = (void 
*)em-looptris;
+
+   /* avoid double-up on face searches for 
quads-ngons */
+   bool insert_prev = false;
+   BMFace *f_prev = NULL;
+
+   /* data-em_evil is only set for snapping, and 
only for the mesh of the object
+* which is currently open in edit mode. When 
set, the bvhtree should not contain
+* faces that will interfere with snapping 
(e.g. faces that are hidden/selected
+* or faces that have selected verts). */
+
+   /* Insert BMesh-tessellation triangles into the 
bvh tree, unless they are hidden
+* and/or selected. Even if the faces 
themselves are not selected for the snapped
+* transform, having a vertex selected means 
the face (and thus it's tessellated
+* triangles) will be moving and will not be a 
good snap targets. */
+   for (i = 0; i  numFaces; i++) {
+   const BMLoop **ltri = 

[Bf-blender-cvs] [f9a6780] master: Cleanup: use struct for storing callback data

2015-07-22 Thread Campbell Barton
Commit: f9a6780dc642ced8dc73f82d0d76cf928c33a094
Author: Campbell Barton
Date:   Wed Jul 22 15:49:53 2015 +1000
Branches: master
https://developer.blender.org/rBf9a6780dc642ced8dc73f82d0d76cf928c33a094

Cleanup: use struct for storing callback data

===

M   source/blender/editors/armature/meshlaplacian.c

===

diff --git a/source/blender/editors/armature/meshlaplacian.c 
b/source/blender/editors/armature/meshlaplacian.c
index 9273093..c420253 100644
--- a/source/blender/editors/armature/meshlaplacian.c
+++ b/source/blender/editors/armature/meshlaplacian.c
@@ -1181,12 +1181,18 @@ static int meshdeform_tri_intersect(const float 
orig[3], const float end[3], con
return 1;
 }
 
+struct MeshRayCallbackData {
+   MFace *mface;
+   MeshDeformBind *mdb;
+   MeshDeformIsect *isec;
+};
+
 static void harmonic_ray_callback(void *userdata, int index, const BVHTreeRay 
*ray, BVHTreeRayHit *hit)
 {
-   void **data = userdata;
-   MeshDeformBind *mdb = data[1];
-   MFace *mface = data[0], *mf;
-   MeshDeformIsect *isec = data[2];
+   struct MeshRayCallbackData *data = userdata;
+   MeshDeformBind *mdb = data-mdb;
+   MFace *mface = data-mface, *mf;
+   MeshDeformIsect *isec = data-isec;
float no[3], co[3], end[3], uvw[3], dist, face[4][3];

mf = mface + index;
@@ -1226,8 +1232,12 @@ static MDefBoundIsect 
*meshdeform_ray_tree_intersect(MeshDeformBind *mdb, const
BVHTreeRayHit hit;
MeshDeformIsect isect_mdef;
float (*cagecos)[3];
-   void *data[3] = {mdb-cagedm-getTessFaceArray(mdb-cagedm), mdb, 
isect_mdef};
-   MFace *mface1 = data[0], *mface;
+   struct MeshRayCallbackData data = {
+   mdb-cagedm-getTessFaceArray(mdb-cagedm),
+   mdb,
+   isect_mdef,
+   };
+   MFace *mface1 = data.mface, *mface;
float vert[4][3], len, end[3];
// static float epsilon[3] = {1e-4, 1e-4, 1e-4};
 
@@ -1251,7 +1261,7 @@ static MDefBoundIsect 
*meshdeform_ray_tree_intersect(MeshDeformBind *mdb, const
hit.index = -1;
hit.dist = FLT_MAX;
if (BLI_bvhtree_ray_cast(mdb-bvhtree, isect_mdef.start, isect_mdef.vec,
-0.0, hit, harmonic_ray_callback, data) != -1)
+0.0, hit, harmonic_ray_callback, data) != -1)
{
len = isect_mdef.lambda;
isect_mdef.face = mface = mface1 + hit.index;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [df41f7b] master: Use const for BVH mesh arrays

2015-07-22 Thread Campbell Barton
Commit: df41f7bf4f1b16d833eb548e57b4512dfb1a3bfa
Author: Campbell Barton
Date:   Wed Jul 22 17:39:33 2015 +1000
Branches: master
https://developer.blender.org/rBdf41f7bf4f1b16d833eb548e57b4512dfb1a3bfa

Use const for BVH mesh arrays

===

M   source/blender/blenkernel/BKE_bvhutils.h
M   source/blender/blenkernel/intern/bvhutils.c
M   source/blender/blenkernel/intern/dynamicpaint.c

===

diff --git a/source/blender/blenkernel/BKE_bvhutils.h 
b/source/blender/blenkernel/BKE_bvhutils.h
index a360511..e78fa65 100644
--- a/source/blender/blenkernel/BKE_bvhutils.h
+++ b/source/blender/blenkernel/BKE_bvhutils.h
@@ -53,9 +53,9 @@ typedef struct BVHTreeFromMesh {
BVHTree_RayCastCallback raycast_callback;
 
/* Vertex array, so that callbacks have instante access to data */
-   struct MVert *vert;
-   struct MEdge *edge; /* only used for BVHTreeFromMeshEdges */
-   struct MFace *face;
+   const struct MVert *vert;
+   const struct MEdge *edge; /* only used for BVHTreeFromMeshEdges */
+   const struct MFace *face;
bool vert_allocated;
bool edge_allocated;
bool face_allocated;
@@ -69,7 +69,7 @@ typedef struct BVHTreeFromMesh {
 
 } BVHTreeFromMesh;
 
-/*
+/**
  * Builds a bvh tree where nodes are the relevant elements of the given mesh.
  * Configures BVHTreeFromMesh.
  *
@@ -79,18 +79,26 @@ typedef struct BVHTreeFromMesh {
  * 
  * free_bvhtree_from_mesh should be called when the tree is no longer needed.
  */
-BVHTree *bvhtree_from_mesh_verts(struct BVHTreeFromMesh *data, struct 
DerivedMesh *mesh, float epsilon, int tree_type, int axis);
-BVHTree *bvhtree_from_mesh_verts_ex(struct BVHTreeFromMesh *data, struct MVert 
*vert, const int numVerts,
-const bool vert_allocated, BLI_bitmap 
*mask, int numVerts_active,
-float epsilon, int tree_type, int axis);
-
-BVHTree *bvhtree_from_mesh_edges(struct BVHTreeFromMesh *data, struct 
DerivedMesh *mesh, float epsilon, int tree_type, int axis);
-
-BVHTree *bvhtree_from_mesh_faces(struct BVHTreeFromMesh *data, struct 
DerivedMesh *mesh, float epsilon, int tree_type, int axis);
-BVHTree *bvhtree_from_mesh_faces_ex(struct BVHTreeFromMesh *data, struct MVert 
*vert, const bool vert_allocated,
-struct MFace *face, const int numFaces, 
const bool face_allocated,
-BLI_bitmap *mask, int numFaces_active,
-float epsilon, int tree_type, int axis);
+BVHTree *bvhtree_from_mesh_verts(
+struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, float epsilon, 
int tree_type, int axis);
+BVHTree *bvhtree_from_mesh_verts_ex(
+struct BVHTreeFromMesh *data, struct MVert *vert, const int numVerts,
+const bool vert_allocated, BLI_bitmap *mask, int numVerts_active,
+float epsilon, int tree_type, int axis);
+
+BVHTree *bvhtree_from_mesh_edges(
+struct BVHTreeFromMesh *data, struct DerivedMesh *mesh,
+float epsilon, int tree_type, int axis);
+
+BVHTree *bvhtree_from_mesh_faces(
+struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, float epsilon,
+int tree_type, int axis);
+BVHTree *bvhtree_from_mesh_faces_ex(
+struct BVHTreeFromMesh *data,
+struct MVert *vert, const bool vert_allocated,
+struct MFace *face, const int numFaces, const bool face_allocated,
+BLI_bitmap *mask, int numFaces_active,
+float epsilon, int tree_type, int axis);
 
 /*
  * Frees data allocated by a call to bvhtree_from_mesh_*.
diff --git a/source/blender/blenkernel/intern/bvhutils.c 
b/source/blender/blenkernel/intern/bvhutils.c
index 1a4a4bd..4472e93 100644
--- a/source/blender/blenkernel/intern/bvhutils.c
+++ b/source/blender/blenkernel/intern/bvhutils.c
@@ -84,8 +84,8 @@ static float sphereray_tri_intersection(const BVHTreeRay 
*ray, float radius, con
 static void mesh_faces_nearest_point(void *userdata, int index, const float 
co[3], BVHTreeNearest *nearest)
 {
const BVHTreeFromMesh *data = (BVHTreeFromMesh *) userdata;
-   MVert *vert = data-vert;
-   MFace *face = data-face + index;
+   const MVert *vert = data-vert;
+   const MFace *face = data-face + index;
 
const float *t0, *t1, *t2, *t3;
t0 = vert[face-v1].co;
@@ -148,8 +148,8 @@ static void editmesh_faces_nearest_point(void *userdata, 
int index, const float
 static void mesh_faces_spherecast(void *userdata, int index, const BVHTreeRay 
*ray, BVHTreeRayHit *hit)
 {
const BVHTreeFromMesh *data = (BVHTreeFromMesh *) userdata;
-   MVert *vert = data-vert;
-   MFace *face = data-face + index;
+   const MVert *vert = data-vert;
+   const MFace *face = data-face[index];
 
const float *t0, *t1, *t2, *t3;
t0 = 

[Bf-blender-cvs] [5983280] master: Use looptri for MeshDeform modifier

2015-07-22 Thread Campbell Barton
Commit: 5983280b4f5fd41d7441b0141bfd257b9fd32a3e
Author: Campbell Barton
Date:   Wed Jul 22 21:30:02 2015 +1000
Branches: master
https://developer.blender.org/rB5983280b4f5fd41d7441b0141bfd257b9fd32a3e

Use looptri for MeshDeform modifier

===

M   source/blender/editors/armature/meshlaplacian.c

===

diff --git a/source/blender/editors/armature/meshlaplacian.c 
b/source/blender/editors/armature/meshlaplacian.c
index c420253..b504893 100644
--- a/source/blender/editors/armature/meshlaplacian.c
+++ b/source/blender/editors/armature/meshlaplacian.c
@@ -631,7 +631,6 @@ void heat_bone_weighting(Object *ob, Mesh *me, float 
(*verts)[3], int numsource,
MLoopTri *mlooptri;
MPoly *mp;
MLoop *ml;
-   MFace *mf;
float solution, weight;
int *vertsflipped = NULL, *mask = NULL;
int a, tottri, j, bbone, firstsegment, lastsegment;
@@ -644,15 +643,7 @@ void heat_bone_weighting(Object *ob, Mesh *me, float 
(*verts)[3], int numsource,
*err_str = NULL;
 
/* bone heat needs triangulated faces */
-   BKE_mesh_tessface_ensure(me);
-
-   for (tottri = 0, a = 0, mf = me-mface; a  me-totface; mf++, a++) {
-   tottri++;
-   if (mf-v4) tottri++;
-   }
-
-   if (tottri == 0)
-   return;
+   tottri = poly_to_tri_count(me-totpoly, me-totloop);
 
/* count triangles and create mask */
if (ob-mode  OB_MODE_WEIGHT_PAINT 
@@ -1062,8 +1053,8 @@ static int MESHDEFORM_OFFSET[7][3] = {
 };
 
 typedef struct MDefBoundIsect {
-   float co[3], uvw[4];
-   int nvert, v[4], facing;
+   float co[3], uvw[3];
+   int v[3], facing;
float len;
 } MDefBoundIsect;
 
@@ -1110,7 +1101,7 @@ typedef struct MeshDeformIsect {
float vec[3];
float lambda;
 
-   void *face;
+   const void *face;
int isect;
float u, v;

@@ -1182,7 +1173,10 @@ static int meshdeform_tri_intersect(const float orig[3], 
const float end[3], con
 }
 
 struct MeshRayCallbackData {
-   MFace *mface;
+   const MPoly *mpoly;
+   const MLoop *mloop;
+   const MLoopTri *looptri;
+   const float (*poly_nors)[3];
MeshDeformBind *mdb;
MeshDeformIsect *isec;
 };
@@ -1191,29 +1185,31 @@ static void harmonic_ray_callback(void *userdata, int 
index, const BVHTreeRay *r
 {
struct MeshRayCallbackData *data = userdata;
MeshDeformBind *mdb = data-mdb;
-   MFace *mface = data-mface, *mf;
+   const MLoop *mloop = data-mloop;
+   const MLoopTri *looptri = data-looptri, *lt;
+   const float (*poly_nors)[3] = data-poly_nors;
MeshDeformIsect *isec = data-isec;
-   float no[3], co[3], end[3], uvw[3], dist, face[4][3];
+   float no[3], co[3], end[3], uvw[3], dist;
+   float *face[3];

-   mf = mface + index;
+   lt = looptri[index];

-   copy_v3_v3(face[0], mdb-cagecos[mf-v1]);
-   copy_v3_v3(face[1], mdb-cagecos[mf-v2]);
-   copy_v3_v3(face[2], mdb-cagecos[mf-v3]);
-   if (mf-v4)
-   copy_v3_v3(face[3], mdb-cagecos[mf-v4]);
+   face[0] = mdb-cagecos[mloop[lt-tri[0]].v];
+   face[1] = mdb-cagecos[mloop[lt-tri[1]].v];
+   face[2] = mdb-cagecos[mloop[lt-tri[2]].v];

add_v3_v3v3(end, isec-start, isec-vec);

-   if (!meshdeform_tri_intersect(ray-origin, end, face[0], face[1], 
face[2], co, uvw)) 
-   if (!mf-v4 || !meshdeform_tri_intersect(ray-origin, end, 
face[0], face[2], face[3], co, uvw))
-   return;
-   
-   if (!mf-v4)
-   normal_tri_v3(no, face[0], face[1], face[2]);
-   else
-   normal_quad_v3(no, face[0], face[1], face[2], face[3]);
-   
+   if (!meshdeform_tri_intersect(ray-origin, end, UNPACK3(face), co, uvw))
+   return;
+
+   if (poly_nors) {
+   copy_v3_v3(no, poly_nors[lt-poly]);
+   }
+   else {
+   normal_tri_v3(no, UNPACK3(face));
+   }
+
dist = len_v3v3(ray-origin, co) / len_v3(isec-vec);
if (dist  hit-dist) {
hit-index = index;
@@ -1222,22 +1218,24 @@ static void harmonic_ray_callback(void *userdata, int 
index, const BVHTreeRay *r

isec-isect = (dot_v3v3(no, ray-direction) = 0.0f);
isec-lambda = dist;
-   isec-face = mf;
+   isec-face = lt;
}
 }
 
 static MDefBoundIsect *meshdeform_ray_tree_intersect(MeshDeformBind *mdb, 
const float co1[3], const float co2[3])
 {
-   MDefBoundIsect *isect;
BVHTreeRayHit hit;
MeshDeformIsect isect_mdef;
float (*cagecos)[3];
struct MeshRayCallbackData data = {
-   mdb-cagedm-getTessFaceArray(mdb-cagedm),
+   mdb-cagedm-getPolyArray(mdb-cagedm),
+ 

[Bf-blender-cvs] [a6f00bb] master: Use doxy sections in bvhutils

2015-07-22 Thread Campbell Barton
Commit: a6f00bb75ca8ec22f66a47782ffa2b827bb0f8e9
Author: Campbell Barton
Date:   Wed Jul 22 20:35:33 2015 +1000
Branches: master
https://developer.blender.org/rBa6f00bb75ca8ec22f66a47782ffa2b827bb0f8e9

Use doxy sections in bvhutils

===

M   source/blender/blenkernel/BKE_bvhutils.h
M   source/blender/blenkernel/intern/bvhutils.c

===

diff --git a/source/blender/blenkernel/BKE_bvhutils.h 
b/source/blender/blenkernel/BKE_bvhutils.h
index e78fa65..a956933a 100644
--- a/source/blender/blenkernel/BKE_bvhutils.h
+++ b/source/blender/blenkernel/BKE_bvhutils.h
@@ -34,7 +34,7 @@
 #include BLI_bitmap.h
 #include BLI_kdopbvh.h
 
-/*
+/**
  * This header encapsulates necessary code to buld a BVH
  */
 
@@ -42,7 +42,7 @@ struct DerivedMesh;
 struct MVert;
 struct MFace;
 
-/*
+/**
  * struct that kepts basic information about a BVHTree build from a mesh
  */
 typedef struct BVHTreeFromMesh {
@@ -100,18 +100,22 @@ BVHTree *bvhtree_from_mesh_faces_ex(
 BLI_bitmap *mask, int numFaces_active,
 float epsilon, int tree_type, int axis);
 
-/*
+/**
  * Frees data allocated by a call to bvhtree_from_mesh_*.
  */
 void free_bvhtree_from_mesh(struct BVHTreeFromMesh *data);
 
-/*
+/**
  * Math functions used by callbacks
  */
-float bvhtree_ray_tri_intersection(const BVHTreeRay *ray, const float m_dist, 
const float v0[3], const float v1[3], const float v2[3]);
-float nearest_point_in_tri_surface_squared(const float v0[3], const float 
v1[3], const float v2[3], const float p[3], int *v, int *e, float nearest[3]);
+float bvhtree_ray_tri_intersection(
+const BVHTreeRay *ray, const float m_dist,
+const float v0[3], const float v1[3], const float v2[3]);
+float nearest_point_in_tri_surface_squared(
+const float v0[3], const float v1[3], const float v2[3],
+const float p[3], int *v, int *e, float nearest[3]);
 
-/*
+/**
  * BVHCache
  */
 
@@ -126,12 +130,12 @@ enum {
 typedef struct LinkNode *BVHCache;
 
 
-/*
+/**
  * Queries a bvhcache for the cache bvhtree of the request type
  */
 BVHTree *bvhcache_find(BVHCache *cache, int type);
 
-/*
+/**
  * Inserts a BVHTree of the given type under the cache
  * After that the caller no longer needs to worry when to free the BVHTree
  * as that will be done when the cache is freed.
@@ -140,7 +144,7 @@ BVHTree *bvhcache_find(BVHCache *cache, int type);
  */
 void bvhcache_insert(BVHCache *cache, BVHTree *tree, int type);
 
-/*
+/**
  * inits and frees a bvhcache
  */
 void bvhcache_init(BVHCache *cache);
diff --git a/source/blender/blenkernel/intern/bvhutils.c 
b/source/blender/blenkernel/intern/bvhutils.c
index 4472e93..8ef2f35 100644
--- a/source/blender/blenkernel/intern/bvhutils.c
+++ b/source/blender/blenkernel/intern/bvhutils.c
@@ -48,9 +48,15 @@
 
 static ThreadRWMutex cache_rwlock = BLI_RWLOCK_INITIALIZER;
 
+/*  */
+/** \name Local Callbacks
+ * \{ */
+
 /* Math stuff for ray casting on mesh faces and for nearest surface */
 
-float bvhtree_ray_tri_intersection(const BVHTreeRay *ray, const float 
UNUSED(m_dist), const float v0[3], const float v1[3], const float v2[3])
+float bvhtree_ray_tri_intersection(
+const BVHTreeRay *ray, const float UNUSED(m_dist),
+const float v0[3], const float v1[3], const float v2[3])
 {
float dist;
 
@@ -60,7 +66,9 @@ float bvhtree_ray_tri_intersection(const BVHTreeRay *ray, 
const float UNUSED(m_d
return FLT_MAX;
 }
 
-static float sphereray_tri_intersection(const BVHTreeRay *ray, float radius, 
const float m_dist, const float v0[3], const float v1[3], const float v2[3])
+static float sphereray_tri_intersection(
+const BVHTreeRay *ray, float radius, const float m_dist,
+const float v0[3], const float v1[3], const float v2[3])
 {

float idist;
@@ -311,15 +319,22 @@ static void mesh_edges_spherecast(void *userdata, int 
index, const BVHTreeRay *r
}
 }
 
+/** \} */
+
 /*
  * BVH builders
  */
 
-/* * Vertex * */
 
-static BVHTree *bvhtree_from_mesh_verts_create_tree(float epsilon, int 
tree_type, int axis,
-MVert *vert, const int 
numVerts,
-BLI_bitmap *mask, int 
numVerts_active)
+/*  */
+
+/** \name Vertex Builder
+ * \{ */
+
+static BVHTree *bvhtree_from_mesh_verts_create_tree(
+float epsilon, int tree_type, int axis,
+MVert *vert, const int numVerts,
+BLI_bitmap *mask, int numVerts_active)
 {
BVHTree *tree = NULL;
int i;
@@ -354,8 +369,9 @@ static BVHTree *bvhtree_from_mesh_verts_create_tree(float 
epsilon, int tree_type
return tree;
 }
 
-static void bvhtree_from_mesh_verts_setup_data(BVHTreeFromMesh *data, 

[Bf-blender-cvs] [b305041] master: Add DM_get_looptri_array utility function

2015-07-22 Thread Campbell Barton
Commit: b305041ce6779f90a282283ff04bd36f1807c728
Author: Campbell Barton
Date:   Wed Jul 22 20:54:12 2015 +1000
Branches: master
https://developer.blender.org/rBb305041ce6779f90a282283ff04bd36f1807c728

Add DM_get_looptri_array utility function

===

M   source/blender/blenkernel/BKE_DerivedMesh.h
M   source/blender/blenkernel/intern/DerivedMesh.c

===

diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h 
b/source/blender/blenkernel/BKE_DerivedMesh.h
index 2c74815..369bd51 100644
--- a/source/blender/blenkernel/BKE_DerivedMesh.h
+++ b/source/blender/blenkernel/BKE_DerivedMesh.h
@@ -800,5 +800,11 @@ struct MEdge *DM_get_edge_array(struct DerivedMesh *dm, 
bool *allocated);
 struct MLoop *DM_get_loop_array(struct DerivedMesh *dm, bool *allocated);
 struct MPoly *DM_get_poly_array(struct DerivedMesh *dm, bool *allocated);
 struct MFace *DM_get_tessface_array(struct DerivedMesh *dm, bool *allocated);
+const MLoopTri *DM_get_looptri_array(
+DerivedMesh *dm,
+const MVert *mvert,
+const MPoly *mpoly, int mpoly_len,
+const MLoop *mloop, int mloop_len,
+bool *allocated);
 
 #endif  /* __BKE_DERIVEDMESH_H__ */
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c 
b/source/blender/blenkernel/intern/DerivedMesh.c
index 3f4b1ee..76cc6d0 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -3882,3 +3882,35 @@ MFace *DM_get_tessface_array(DerivedMesh *dm, bool 
*allocated)
 
return mface;
 }
+
+const MLoopTri *DM_get_looptri_array(
+DerivedMesh *dm,
+const MVert *mvert,
+const MPoly *mpoly, int mpoly_len,
+const MLoop *mloop, int mloop_len,
+bool *allocated)
+{
+   const MLoopTri *looptri = dm-getLoopTriArray(dm);
+   *allocated = false;
+
+   if (looptri == NULL) {
+   if (mpoly_len  0) {
+   const int looptris_num = poly_to_tri_count(mpoly_len, 
mloop_len);
+   MLoopTri *looptri_data;
+
+   looptri_data = MEM_mallocN(sizeof(MLoopTri) * 
looptris_num, __func__);
+
+   BKE_mesh_recalc_looptri(
+   mloop, mpoly,
+   mvert,
+   mloop_len, mpoly_len,
+   looptri_data);
+
+   looptri = looptri_data;
+
+   *allocated = true;
+   }
+   }
+
+   return looptri;
+}

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [db065e2] GPencil_Editing_Stage3: GP Sculpt: Allow randomise to offset points to either side of the line

2015-07-22 Thread Joshua Leung
Commit: db065e2ef80436139511e5bf24e9fc3801db1975
Author: Joshua Leung
Date:   Thu Jul 23 12:50:45 2015 +1200
Branches: GPencil_Editing_Stage3
https://developer.blender.org/rBdb065e2ef80436139511e5bf24e9fc3801db1975

GP Sculpt: Allow randomise to offset points to either side of the line

===

M   source/blender/editors/gpencil/gpencil_brush.c

===

diff --git a/source/blender/editors/gpencil/gpencil_brush.c 
b/source/blender/editors/gpencil/gpencil_brush.c
index f9b556e..e1fe4cc 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -564,7 +564,7 @@ static bool gp_brush_randomise_apply(tGP_BrushEditData 
*gso, bGPDstroke *gps, in
/* Amount of jitter to apply depends on the distance of the point to 
the cursor,
 * as well as the strength of the brush
 */
-   const float inf = gp_brush_influence_calc(gso, radius, co);
+   const float inf = gp_brush_influence_calc(gso, radius, co) / 2.0f;

//const float dist = (float)len_v2v2_int(gso-mval, co);
const float fac = BLI_frand() * inf;
@@ -587,8 +587,13 @@ static bool gp_brush_randomise_apply(tGP_BrushEditData 
*gso, bGPDstroke *gps, in
printf(svec = %f %f, , svec[0], svec[1]);

/* scale the displacement by the random displacement, and apply */
-   normalize_v2(svec);
-   mul_v2_fl(svec, fac);
+   //normalize_v2(svec);
+   if (BLI_frand()  0.5f) {
+   mul_v2_fl(svec, -fac);
+   }
+   else {
+   mul_v2_fl(svec, fac);
+   }

nco[0] = (float)co[0] + svec[0];
nco[1] = (float)co[1] + svec[1];

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [dcbe481] GPencil_Editing_Stage3: GP Sculpt: More WIP work to try and get this randomise brush working

2015-07-22 Thread Joshua Leung
Commit: dcbe481cfd2a0a886f58b7c56a29287199146711
Author: Joshua Leung
Date:   Thu Jul 23 01:33:21 2015 +1200
Branches: GPencil_Editing_Stage3
https://developer.blender.org/rBdcbe481cfd2a0a886f58b7c56a29287199146711

GP Sculpt: More WIP work to try and get this randomise brush working

So it turns out that the screenspace-to-3d math is a lot more convoluted now
than would be initially obvious. The brush is now behaving a lot better now
in that it somewhat does what is expected. The results aren't really what we
really want yet, so some more experimentation is still needed.

===

M   source/blender/editors/gpencil/gpencil_brush.c

===

diff --git a/source/blender/editors/gpencil/gpencil_brush.c 
b/source/blender/editors/gpencil/gpencil_brush.c
index 3f47f39..f9b556e 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -605,7 +605,23 @@ static bool gp_brush_randomise_apply(tGP_BrushEditData 
*gso, bGPDstroke *gps, in
float *rvec = ED_view3d_cursor3d_get(gso-scene, v3d);
float zfac = ED_view3d_calc_zfac(rv3d, rvec, NULL);

-   ED_view3d_win_to_delta(gso-ar, nco, pt-x, zfac);
+   float sco[2] = {(float)co[0], (float)co[1]};
+   float dvec[3], out[3];
+   
+   float *mval_f = nco;
+   float mval_prj[2];
+   
+   if (ED_view3d_project_float_global(gso-ar, rvec, 
mval_prj, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
+   sub_v2_v2v2(mval_f, mval_prj, mval_f);
+   ED_view3d_win_to_delta(gso-ar, mval_f, dvec, 
zfac);
+   sub_v3_v3v3(out, rvec, dvec);
+   }
+   else {
+   zero_v3(out);
+   }
+   
+   printf(  out vs pt = (%f, %f, %f)  - (%f, %f, %f)\n, 
out[0], out[1], out[2], pt-x, pt-y, pt-z);
+   copy_v3_v3(pt-x, out);
}
else {
/* ERROR */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [d4d3a77] GPencil_Editing_Stage3: GP Sculpt: Collapse Edit/Sculpt panels by default

2015-07-22 Thread Joshua Leung
Commit: d4d3a77a2ac0a59e41836c6c153cb3e9dbb1bba9
Author: Joshua Leung
Date:   Fri Jul 17 02:25:04 2015 +1200
Branches: GPencil_Editing_Stage3
https://developer.blender.org/rBd4d3a77a2ac0a59e41836c6c153cb3e9dbb1bba9

GP Sculpt: Collapse Edit/Sculpt panels by default

Now tha we have many more editing tools/options here now, it's better to keep
both of these collapsed, so that users have a greater chance of discovering
the existence of either/or. Furthermore, since the editing tools have been
available for a few releases now, users should be more familiar with what's on
offer there now

===

M   release/scripts/startup/bl_ui/properties_grease_pencil_common.py

===

diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py 
b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index 6e9f902..b7f828b 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -101,6 +101,7 @@ class GreasePencilStrokeEditPanel:
 bl_label = Edit Strokes
 bl_category = Grease Pencil
 bl_region_type = 'TOOLS'
+bl_options = {'DEFAULT_CLOSED'}
 
 @classmethod
 def poll(cls, context):
@@ -160,6 +161,7 @@ class GreasePencilStrokeSculptPanel:
 bl_label = Sculpt Strokes
 bl_category = Grease Pencil
 bl_region_type = 'TOOLS'
+bl_options = {'DEFAULT_CLOSED'}
 
 @classmethod
 def poll(cls, context):

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [6d5cfd181] GPencil_Editing_Stage3: GP Sculpt: Buggy attempt at building a randomise brush

2015-07-22 Thread Joshua Leung
Commit: 6d5cfd18101116c2188c88c9ea8a08aa5bf6ac4c
Author: Joshua Leung
Date:   Tue Jul 21 00:12:50 2015 +1200
Branches: GPencil_Editing_Stage3
https://developer.blender.org/rB6d5cfd18101116c2188c88c9ea8a08aa5bf6ac4c

GP Sculpt: Buggy attempt at building a randomise brush

This currently just sends the points off screen. We need another approach.

===

M   source/blender/editors/gpencil/gpencil_brush.c

===

diff --git a/source/blender/editors/gpencil/gpencil_brush.c 
b/source/blender/editors/gpencil/gpencil_brush.c
index 5bac81d..3f47f39 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -41,6 +41,7 @@
 #include BLI_blenlib.h
 #include BLI_ghash.h
 #include BLI_math.h
+#include BLI_rand.h
 #include BLI_utildefines.h
 
 #include BLF_translation.h
@@ -412,6 +413,7 @@ static void gp_brush_grab_calc_dvec(tGP_BrushEditData *gso)
}
else {
/* 2D - just copy */
+   // XXX: view2d?
gso-dvec[0] = (float)(gso-mval[0] - gso-mval_prev[0]);
gso-dvec[1] = (float)(gso-mval[1] - gso-mval_prev[1]);
gso-dvec[2] = 0.0f;  /* unused */
@@ -550,6 +552,76 @@ static bool gp_brush_pinch_apply(tGP_BrushEditData *gso, 
bGPDstroke *gps, int i,
return true;
 }
 
+/* --- */
+/* Randomise Brush */
+
+/* Apply some random jitter to the point */
+static bool gp_brush_randomise_apply(tGP_BrushEditData *gso, bGPDstroke *gps, 
int i,
+ const int radius, const int co[2])
+{
+   bGPDspoint *pt = gps-points + i;
+   
+   /* Amount of jitter to apply depends on the distance of the point to 
the cursor,
+* as well as the strength of the brush
+*/
+   const float inf = gp_brush_influence_calc(gso, radius, co);
+   
+   //const float dist = (float)len_v2v2_int(gso-mval, co);
+   const float fac = BLI_frand() * inf;
+   
+   /* Jitter is applied perpendicular to the mouse movement vector
+* - We compute all effects in screenspace (since it's easier)
+*   and then project these to get the points/distances in
+*   viewspace as needed
+*/
+   float mvec[2], svec[2], nco[2];
+   
+   /* mouse movement in ints - floats */
+   mvec[0] = (float)(gso-mval[0] - gso-mval_prev[0]);
+   mvec[1] = (float)(gso-mval[1] - gso-mval_prev[1]);
+   
+   /* rotate mvec by 90 degrees... */
+   svec[0] = -mvec[1];
+   svec[1] =  mvec[0];
+   
+   printf(svec = %f %f, , svec[0], svec[1]);
+   
+   /* scale the displacement by the random displacement, and apply */
+   normalize_v2(svec);
+   mul_v2_fl(svec, fac);
+   
+   nco[0] = (float)co[0] + svec[0];
+   nco[1] = (float)co[1] + svec[1];
+   
+   printf(%f %f (%f), nco = {%f %f}, co = %d %d\n, svec[0], svec[1], 
fac, nco[0], nco[1], co[0], co[1]);
+   
+   /* convert to dataspace */
+   // XXX: this step is going wrong!
+   if (gps-flag  GP_STROKE_3DSPACE) {
+   /* 3D: Project to 3D space */
+   if (gso-sa-spacetype == SPACE_VIEW3D) {
+   View3D *v3d = gso-sa-spacedata.first;
+   RegionView3D *rv3d = gso-ar-regiondata;
+   float *rvec = ED_view3d_cursor3d_get(gso-scene, v3d);
+   float zfac = ED_view3d_calc_zfac(rv3d, rvec, NULL);
+   
+   ED_view3d_win_to_delta(gso-ar, nco, pt-x, zfac);
+   }
+   else {
+   /* ERROR */
+   BLI_assert(3D stroke being sculpted in non-3D view);
+   }
+   }
+   else {
+   /* 2D: As-is */
+   // XXX: v2d scaling/offset?
+   copy_v2_v2(pt-x, nco);
+   }
+   
+   /* done */
+   return true;
+}
+
 /*  */
 /* Cursor drawing */
 
@@ -821,6 +893,13 @@ static void gpsculpt_brush_apply(bContext *C, wmOperator 
*op, PointerRNA *itempt
break;
}

+   case GP_EDITBRUSH_TYPE_RANDOMISE: /* Random jitter */
+   {
+   /* compute the displacement vector for the cursor (in 
data space) */
+   gp_brush_grab_calc_dvec(gso);
+   break;
+   }
+   
default:
break;
}
@@ -874,7 +953,7 @@ static void gpsculpt_brush_apply(bContext *C, wmOperator 
*op, PointerRNA *itempt

case GP_EDITBRUSH_TYPE_RANDOMISE: /* Apply jitter */
{
-   //changed |= 

[Bf-blender-cvs] [3148f82] GPencil_Editing_Stage3: GP Sculpt: Code cleanup for randomise brush

2015-07-22 Thread Joshua Leung
Commit: 3148f82e27a300fe8a460cd040a0c0b93b690f55
Author: Joshua Leung
Date:   Thu Jul 23 13:08:09 2015 +1200
Branches: GPencil_Editing_Stage3
https://developer.blender.org/rB3148f82e27a300fe8a460cd040a0c0b93b690f55

GP Sculpt: Code cleanup for randomise brush

===

M   source/blender/editors/gpencil/gpencil_brush.c

===

diff --git a/source/blender/editors/gpencil/gpencil_brush.c 
b/source/blender/editors/gpencil/gpencil_brush.c
index e1fe4cc..f8060b0 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -565,8 +565,6 @@ static bool gp_brush_randomise_apply(tGP_BrushEditData 
*gso, bGPDstroke *gps, in
 * as well as the strength of the brush
 */
const float inf = gp_brush_influence_calc(gso, radius, co) / 2.0f;
-   
-   //const float dist = (float)len_v2v2_int(gso-mval, co);
const float fac = BLI_frand() * inf;

/* Jitter is applied perpendicular to the mouse movement vector
@@ -584,10 +582,9 @@ static bool gp_brush_randomise_apply(tGP_BrushEditData 
*gso, bGPDstroke *gps, in
svec[0] = -mvec[1];
svec[1] =  mvec[0];

-   printf(svec = %f %f, , svec[0], svec[1]);
+   //printf(svec = %f %f, , svec[0], svec[1]);

/* scale the displacement by the random displacement, and apply */
-   //normalize_v2(svec);
if (BLI_frand()  0.5f) {
mul_v2_fl(svec, -fac);
}
@@ -598,10 +595,9 @@ static bool gp_brush_randomise_apply(tGP_BrushEditData 
*gso, bGPDstroke *gps, in
nco[0] = (float)co[0] + svec[0];
nco[1] = (float)co[1] + svec[1];

-   printf(%f %f (%f), nco = {%f %f}, co = %d %d\n, svec[0], svec[1], 
fac, nco[0], nco[1], co[0], co[1]);
+   //printf(%f %f (%f), nco = {%f %f}, co = %d %d\n, svec[0], svec[1], 
fac, nco[0], nco[1], co[0], co[1]);

/* convert to dataspace */
-   // XXX: this step is going wrong!
if (gps-flag  GP_STROKE_3DSPACE) {
/* 3D: Project to 3D space */
if (gso-sa-spacetype == SPACE_VIEW3D) {
@@ -610,7 +606,6 @@ static bool gp_brush_randomise_apply(tGP_BrushEditData 
*gso, bGPDstroke *gps, in
float *rvec = ED_view3d_cursor3d_get(gso-scene, v3d);
float zfac = ED_view3d_calc_zfac(rv3d, rvec, NULL);

-   float sco[2] = {(float)co[0], (float)co[1]};
float dvec[3], out[3];

float *mval_f = nco;
@@ -625,7 +620,7 @@ static bool gp_brush_randomise_apply(tGP_BrushEditData 
*gso, bGPDstroke *gps, in
zero_v3(out);
}

-   printf(  out vs pt = (%f, %f, %f)  - (%f, %f, %f)\n, 
out[0], out[1], out[2], pt-x, pt-y, pt-z);
+   //printf(  out vs pt = (%f, %f, %f)  - (%f, %f, 
%f)\n, out[0], out[1], out[2], pt-x, pt-y, pt-z);
copy_v3_v3(pt-x, out);
}
else {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [368bd34] master: Mesh Deform: support for ngons when binding

2015-07-22 Thread Campbell Barton
Commit: 368bd34573e4c1a395685283acaccaf73c76
Author: Campbell Barton
Date:   Thu Jul 23 10:47:34 2015 +1000
Branches: master
https://developer.blender.org/rB368bd34573e4c1a395685283acaccaf73c76

Mesh Deform: support for ngons when binding

Weights were calculated using tessellation data, giving slightly uneven 
weighting.
Now only use tessellation for ray-cast but weight the influences from the 
original polygons.

Also cache arrays from derived-mesh, they we're called each intersection.

===

M   source/blender/editors/armature/meshlaplacian.c

===

diff --git a/source/blender/editors/armature/meshlaplacian.c 
b/source/blender/editors/armature/meshlaplacian.c
index b504893..66490da 100644
--- a/source/blender/editors/armature/meshlaplacian.c
+++ b/source/blender/editors/armature/meshlaplacian.c
@@ -35,6 +35,7 @@
 #include BLI_edgehash.h
 #include BLI_memarena.h
 #include BLI_string.h
+#include BLI_alloca.h
 
 #include BLF_translation.h
 
@@ -1044,18 +1045,26 @@ void rigid_deform_end(int cancel)
 #define MESHDEFORM_TAG_INTERIOR 2
 #define MESHDEFORM_TAG_EXTERIOR 3
 
+/** minimum length for #MDefBoundIsect.len */
 #define MESHDEFORM_LEN_THRESHOLD 1e-6f
 
 #define MESHDEFORM_MIN_INFLUENCE 0.0005f
 
-static int MESHDEFORM_OFFSET[7][3] = {
+static const int MESHDEFORM_OFFSET[7][3] = {
{0, 0, 0}, {1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 
0, -1}
 };
 
 typedef struct MDefBoundIsect {
-   float co[3], uvw[3];
-   int v[3], facing;
+   /* intersection on the cage 'cagecos' */
+   float co[3];
+   /* non-facing intersections are considered interior */
+   bool facing;
+   /* ray-cast index aligned with MPoly (ray-hit-triangle isn't needed) */
+   int poly_index;
+   /* distance from 'co' to the ray-cast start (clamped to avoid zero 
division) */
float len;
+   /* weights aligned with the MPoly's loop indices */
+   float poly_weights[0];
 } MDefBoundIsect;
 
 typedef struct MDefBindInfluence {
@@ -1094,6 +1103,14 @@ typedef struct MeshDeformBind {

BVHTree *bvhtree;
BVHTreeFromMesh bvhdata;
+
+   /* avoid DM function calls during intersections */
+   struct {
+   const MPoly *mpoly;
+   const MLoop *mloop;
+   const MLoopTri *looptri;
+   const float (*poly_nors)[3];
+   } cagedm_cache;
 } MeshDeformBind;
 
 typedef struct MeshDeformIsect {
@@ -1101,8 +1118,7 @@ typedef struct MeshDeformIsect {
float vec[3];
float lambda;
 
-   const void *face;
-   int isect;
+   bool isect;
float u, v;

 } MeshDeformIsect;
@@ -1173,10 +1189,6 @@ static int meshdeform_tri_intersect(const float orig[3], 
const float end[3], con
 }
 
 struct MeshRayCallbackData {
-   const MPoly *mpoly;
-   const MLoop *mloop;
-   const MLoopTri *looptri;
-   const float (*poly_nors)[3];
MeshDeformBind *mdb;
MeshDeformIsect *isec;
 };
@@ -1185,9 +1197,9 @@ static void harmonic_ray_callback(void *userdata, int 
index, const BVHTreeRay *r
 {
struct MeshRayCallbackData *data = userdata;
MeshDeformBind *mdb = data-mdb;
-   const MLoop *mloop = data-mloop;
-   const MLoopTri *looptri = data-looptri, *lt;
-   const float (*poly_nors)[3] = data-poly_nors;
+   const MLoop *mloop = mdb-cagedm_cache.mloop;
+   const MLoopTri *looptri = mdb-cagedm_cache.looptri, *lt;
+   const float (*poly_nors)[3] = mdb-cagedm_cache.poly_nors;
MeshDeformIsect *isec = data-isec;
float no[3], co[3], end[3], uvw[3], dist;
float *face[3];
@@ -1218,7 +1230,6 @@ static void harmonic_ray_callback(void *userdata, int 
index, const BVHTreeRay *r

isec-isect = (dot_v3v3(no, ray-direction) = 0.0f);
isec-lambda = dist;
-   isec-face = lt;
}
 }
 
@@ -1226,17 +1237,11 @@ static MDefBoundIsect 
*meshdeform_ray_tree_intersect(MeshDeformBind *mdb, const
 {
BVHTreeRayHit hit;
MeshDeformIsect isect_mdef;
-   float (*cagecos)[3];
struct MeshRayCallbackData data = {
-   mdb-cagedm-getPolyArray(mdb-cagedm),
-   mdb-cagedm-getLoopArray(mdb-cagedm),
-   mdb-cagedm-getLoopTriArray(mdb-cagedm),
-   mdb-cagedm-getPolyDataArray(mdb-cagedm, CD_NORMAL),  /* can 
be NULL */
mdb,
isect_mdef,
};
-   const MLoopTri *looptri = data.looptri, *lt;
-   float vert[4][3], len, end[3];
+   float end[3];
// static float epsilon[3] = {1e-4, 1e-4, 1e-4};
 
/* happens binding when a cage has no faces */
@@ -1261,34 +1266,34 @@ static MDefBoundIsect 
*meshdeform_ray_tree_intersect(MeshDeformBind *mdb, const
if (BLI_bvhtree_ray_cast(mdb-bvhtree, isect_mdef.start, 

[Bf-blender-cvs] [0bf2b20] master: Add missing break checking for tangents

2015-07-22 Thread Campbell Barton
Commit: 0bf2b207e2eff7a787d1e203725b64e60f8f1683
Author: Campbell Barton
Date:   Thu Jul 23 11:51:03 2015 +1000
Branches: master
https://developer.blender.org/rB0bf2b207e2eff7a787d1e203725b64e60f8f1683

Add missing break checking for tangents

===

M   source/blender/blenkernel/intern/DerivedMesh.c

===

diff --git a/source/blender/blenkernel/intern/DerivedMesh.c 
b/source/blender/blenkernel/intern/DerivedMesh.c
index 76cc6d0..60a681d 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -3222,10 +3222,14 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, 
GPUVertexAttribs *gattribs,
DM_calc_auto_bump_scale(dm);
 
/* add a tangent layer if necessary */
-   for (b = 0; b  gattribs-totlayer; b++)
-   if (gattribs-layer[b].type == CD_TANGENT)
-   if (CustomData_get_layer_index(fdata, CD_TANGENT) == -1)
+   for (b = 0; b  gattribs-totlayer; b++) {
+   if (gattribs-layer[b].type == CD_TANGENT) {
+   if (CustomData_get_layer_index(fdata, CD_TANGENT) == 
-1) {
DM_add_tangent_layer(dm);
+   break;
+   }
+   }
+   }
 
for (b = 0; b  gattribs-totlayer; b++) {
if (gattribs-layer[b].type == CD_MTFACE) {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [717046a] master: Use looptri for volume snapping

2015-07-22 Thread Campbell Barton
Commit: 717046ad2a41c5b7d23313c77eca6ffc9f7b8762
Author: Campbell Barton
Date:   Thu Jul 23 12:56:44 2015 +1000
Branches: master
https://developer.blender.org/rB717046ad2a41c5b7d23313c77eca6ffc9f7b8762

Use looptri for volume snapping

===

M   source/blender/editors/transform/transform_snap.c

===

diff --git a/source/blender/editors/transform/transform_snap.c 
b/source/blender/editors/transform/transform_snap.c
index 99d9836..d1cd33b 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -2062,9 +2062,11 @@ static bool peelDerivedMesh(Object *ob, DerivedMesh *dm, 
float obmat[4][4],
 {
bool retval = false;
int totvert = dm-getNumVerts(dm);
-   int totface = dm-getNumTessFaces(dm);

if (totvert  0) {
+   const MLoopTri *looptri = dm-getLoopTriArray(dm);
+   const MLoop *mloop = dm-getLoopArray(dm);
+   int looptri_num = dm-getNumLoopTri(dm);
float imat[4][4];
float timat[3][3]; /* transpose inverse matrix for normals */
float ray_start_local[3], ray_normal_local[3];
@@ -2080,23 +2082,27 @@ static bool peelDerivedMesh(Object *ob, DerivedMesh 
*dm, float obmat[4][4],
/* If number of vert is more than an arbitrary limit, 
 * test against boundbox first
 * */
-   if (totface  16) {
+   if (looptri_num  16) {
struct BoundBox *bb = BKE_object_boundbox_get(ob);
test = BKE_boundbox_ray_hit_check(bb, ray_start_local, 
ray_normal_local, NULL);
}

if (test == 1) {
+   const MLoopTri *lt;
MVert *verts = dm-getVertArray(dm);
-   MFace *faces = dm-getTessFaceArray(dm);
+   float (*polynors)[3] = dm-getPolyDataArray(dm, 
CD_NORMAL);
int i;

-   for (i = 0; i  totface; i++) {
-   MFace *f = faces + i;
+   for (i = 0, lt = looptri; i  looptri_num; i++, lt++) {
+   const unsigned int vtri[3] = 
{mloop[lt-tri[0]].v, mloop[lt-tri[1]].v, mloop[lt-tri[2]].v};
float lambda;
int result;


-   result = 
isect_ray_tri_threshold_v3(ray_start_local, ray_normal_local, verts[f-v1].co, 
verts[f-v2].co, verts[f-v3].co, lambda, NULL, 0.001);
+   result = isect_ray_tri_threshold_v3(
+   ray_start_local, ray_normal_local,
+   verts[vtri[0]].co, verts[vtri[1]].co, 
verts[vtri[2]].co,
+   lambda, NULL, 0.001);

if (result) {
float location[3], normal[3];
@@ -2108,11 +2114,13 @@ static bool peelDerivedMesh(Object *ob, DerivedMesh 
*dm, float obmat[4][4],
add_v3_v3(intersect, ray_start_local);

copy_v3_v3(location, intersect);
-   
-   if (f-v4)
-   normal_quad_v3(normal, 
verts[f-v1].co, verts[f-v2].co, verts[f-v3].co, verts[f-v4].co);
-   else
-   normal_tri_v3(normal, 
verts[f-v1].co, verts[f-v2].co, verts[f-v3].co);
+
+   if (polynors) {
+   copy_v3_v3(normal, 
polynors[lt-poly]);
+   }
+   else {
+   normal_tri_v3(normal, 
verts[vtri[0]].co, verts[vtri[1]].co, verts[vtri[2]].co);
+   }
 
mul_m4_v3(obmat, location);

@@ -2123,36 +2131,6 @@ static bool peelDerivedMesh(Object *ob, DerivedMesh *dm, 
float obmat[4][4],
 
addDepthPeel(depth_peels, new_depth, 
location, normal, ob);
}
-   
-   if (f-v4  result == 0) {
-   result = 
isect_ray_tri_threshold_v3(ray_start_local, ray_normal_local, verts[f-v3].co, 
verts[f-v4].co, verts[f-v1].co, lambda, NULL, 0.001);
-

[Bf-blender-cvs] [60822ec] master: Use looptri for BVH raycast (simple cases)

2015-07-22 Thread Campbell Barton
Commit: 60822ec183a514f38f478ec3f3a167f59865f027
Author: Campbell Barton
Date:   Thu Jul 23 13:20:34 2015 +1000
Branches: master
https://developer.blender.org/rB60822ec183a514f38f478ec3f3a167f59865f027

Use looptri for BVH raycast (simple cases)

===

M   source/blender/blenkernel/intern/constraint.c
M   source/blender/blenkernel/intern/shrinkwrap.c
M   source/blender/editors/transform/transform_snap.c
M   source/blender/modifiers/intern/MOD_surface.c
M   source/blender/modifiers/intern/MOD_weightvgproximity.c

===

diff --git a/source/blender/blenkernel/intern/constraint.c 
b/source/blender/blenkernel/intern/constraint.c
index 4f08643..be466c2 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -3438,7 +3438,7 @@ static void shrinkwrap_get_tarmat(bConstraint *con, 
bConstraintOb *cob, bConstra
if (scon-shrinkType == 
MOD_SHRINKWRAP_NEAREST_VERTEX)

bvhtree_from_mesh_verts(treeData, target, 0.0, 2, 6);
else
-   
bvhtree_from_mesh_faces(treeData, target, 0.0, 2, 6);
+   
bvhtree_from_mesh_looptri(treeData, target, 0.0, 2, 6);

if (treeData.tree == NULL) {
fail = true;
@@ -3490,7 +3490,7 @@ static void shrinkwrap_get_tarmat(bConstraint *con, 
bConstraintOb *cob, bConstra
break;
}
 
-   bvhtree_from_mesh_faces(treeData, 
target, scon-dist, 4, 6);
+   bvhtree_from_mesh_looptri(treeData, 
target, scon-dist, 4, 6);
if (treeData.tree == NULL) {
fail = true;
break;
@@ -4107,7 +4107,7 @@ static void followtrack_evaluate(bConstraint *con, 
bConstraintOb *cob, ListBase
 
sub_v3_v3v3(ray_nor, ray_end, 
ray_start);
 
-   bvhtree_from_mesh_faces(treeData, 
target, 0.0f, 4, 6);
+   bvhtree_from_mesh_looptri(treeData, 
target, 0.0f, 4, 6);
 
hit.dist = FLT_MAX;
hit.index = -1;
diff --git a/source/blender/blenkernel/intern/shrinkwrap.c 
b/source/blender/blenkernel/intern/shrinkwrap.c
index 2ff81cd..5ecd2fc 100644
--- a/source/blender/blenkernel/intern/shrinkwrap.c
+++ b/source/blender/blenkernel/intern/shrinkwrap.c
@@ -279,8 +279,8 @@ static void 
shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc, bool for
}
 
/* After sucessufuly build the trees, start projection vertexs */
-   if (bvhtree_from_mesh_faces(treeData, calc-target, 0.0, 4, 6) 
-   (auxMesh == NULL || bvhtree_from_mesh_faces(auxData, auxMesh, 0.0, 
4, 6)))
+   if (bvhtree_from_mesh_looptri(treeData, calc-target, 0.0, 4, 6) 
+   (auxMesh == NULL || bvhtree_from_mesh_looptri(auxData, auxMesh, 
0.0, 4, 6)))
{
 
 #ifndef __APPLE__
@@ -381,7 +381,7 @@ static void 
shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc)
BVHTreeNearest nearest  = NULL_BVHTreeNearest;
 
/* Create a bvh-tree of the given target */
-   bvhtree_from_mesh_faces(treeData, calc-target, 0.0, 2, 6);
+   bvhtree_from_mesh_looptri(treeData, calc-target, 0.0, 2, 6);
if (treeData.tree == NULL) {
OUT_OF_MEMORY();
return;
diff --git a/source/blender/editors/transform/transform_snap.c 
b/source/blender/editors/transform/transform_snap.c
index d1cd33b..3b488fd 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -1533,7 +1533,7 @@ static bool snapDerivedMesh(short snap_mode, ARegion *ar, 
Object *ob, DerivedMes
len_diff = 0.0f;  /* In case BVHTree would fail for 
some reason... */
 
treeData.em_evil = em;
-   bvhtree_from_mesh_faces(treeData, dm, 0.0f, 2, 6);
+   bvhtree_from_mesh_looptri(treeData, dm, 0.0f, 2, 6);
if (treeData.tree != NULL) {
nearest.index = -1;
nearest.dist_sq = FLT_MAX;
@@ -1575,7 +1575,7 @@ static bool snapDerivedMesh(short snap_mode, ARegion *ar, 
Object *ob, DerivedMes
}
 
treeData.em_evil = em;
-  

[Bf-blender-cvs] [5c98848] master: Use looptri for RNA BVH functions

2015-07-22 Thread Campbell Barton
Commit: 5c98848895b5bdafd074e86948e53392bde5e6d8
Author: Campbell Barton
Date:   Thu Jul 23 15:38:50 2015 +1000
Branches: master
https://developer.blender.org/rB5c98848895b5bdafd074e86948e53392bde5e6d8

Use looptri for RNA BVH functions

===

M   source/blender/makesrna/intern/rna_object_api.c

===

diff --git a/source/blender/makesrna/intern/rna_object_api.c 
b/source/blender/makesrna/intern/rna_object_api.c
index 55f559c..e8eacb2 100644
--- a/source/blender/makesrna/intern/rna_object_api.c
+++ b/source/blender/makesrna/intern/rna_object_api.c
@@ -309,18 +309,10 @@ static void rna_Mesh_assign_verts_to_group(Object *ob, 
bDeformGroup *group, int
 #endif
 
 /* don't call inside a loop */
-static int dm_tessface_to_poly_index(DerivedMesh *dm, int tessface_index)
+static int dm_looptri_to_poly_index(DerivedMesh *dm, const MLoopTri *lt)
 {
-   if (tessface_index != ORIGINDEX_NONE) {
-   /* double lookup */
-   const int *index_mf_to_mpoly;
-   if ((index_mf_to_mpoly = dm-getTessFaceDataArray(dm, 
CD_ORIGINDEX))) {
-   const int *index_mp_to_orig = dm-getPolyDataArray(dm, 
CD_ORIGINDEX);
-   return DM_origindex_mface_mpoly(index_mf_to_mpoly, 
index_mp_to_orig, tessface_index);
-   }
-   }
-
-   return ORIGINDEX_NONE;
+   const int *index_mp_to_orig = dm-getPolyDataArray(dm, CD_ORIGINDEX);
+   return index_mp_to_orig ? index_mp_to_orig[lt-poly] : lt-poly;
 }
 
 static void rna_Object_ray_cast(Object *ob, ReportList *reports, float 
ray_start[3], float ray_end[3],
@@ -334,7 +326,7 @@ static void rna_Object_ray_cast(Object *ob, ReportList 
*reports, float ray_start
}
 
/* no need to managing allocation or freeing of the BVH data. this is 
generated and freed as needed */
-   bvhtree_from_mesh_faces(treeData, ob-derivedFinal, 0.0f, 4, 6);
+   bvhtree_from_mesh_looptri(treeData, ob-derivedFinal, 0.0f, 4, 6);
 
/* may fail if the mesh has no faces, in that case the ray-cast misses 
*/
if (treeData.tree != NULL) {
@@ -351,7 +343,7 @@ static void rna_Object_ray_cast(Object *ob, ReportList 
*reports, float ray_start
if (hit.dist = dist) {
copy_v3_v3(r_location, hit.co);
copy_v3_v3(r_normal, hit.no);
-   *index = 
dm_tessface_to_poly_index(ob-derivedFinal, hit.index);
+   *index = 
dm_looptri_to_poly_index(ob-derivedFinal, treeData.looptri[hit.index]);
free_bvhtree_from_mesh(treeData);
return;
}
@@ -376,7 +368,7 @@ static void rna_Object_closest_point_on_mesh(Object *ob, 
ReportList *reports, fl
}
 
/* no need to managing allocation or freeing of the BVH data. this is 
generated and freed as needed */
-   bvhtree_from_mesh_faces(treeData, ob-derivedFinal, 0.0f, 4, 6);
+   bvhtree_from_mesh_looptri(treeData, ob-derivedFinal, 0.0f, 4, 6);
 
if (treeData.tree == NULL) {
BKE_reportf(reports, RPT_ERROR, Object '%s' could not create 
internal data for finding nearest point,
@@ -392,7 +384,7 @@ static void rna_Object_closest_point_on_mesh(Object *ob, 
ReportList *reports, fl
if (BLI_bvhtree_find_nearest(treeData.tree, point_co, nearest, 
treeData.nearest_callback, treeData) != -1) {
copy_v3_v3(n_location, nearest.co);
copy_v3_v3(n_normal, nearest.no);
-   *index = dm_tessface_to_poly_index(ob-derivedFinal, 
nearest.index);
+   *index = dm_looptri_to_poly_index(ob-derivedFinal, 
treeData.looptri[nearest.index]);
free_bvhtree_from_mesh(treeData);
return;
}

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [6aabc1b] master: Cleanup; duplicate header

2015-07-22 Thread Campbell Barton
Commit: 6aabc1bde4ebb284a6b5c9bf1e936502b6fc1c07
Author: Campbell Barton
Date:   Thu Jul 23 15:39:36 2015 +1000
Branches: master
https://developer.blender.org/rB6aabc1bde4ebb284a6b5c9bf1e936502b6fc1c07

Cleanup; duplicate header

===

M   source/blender/blenkernel/BKE_bvhutils.h
M   source/blender/makesrna/intern/rna_nodetree.c

===

diff --git a/source/blender/blenkernel/BKE_bvhutils.h 
b/source/blender/blenkernel/BKE_bvhutils.h
index 52a659b..d8eaa35 100644
--- a/source/blender/blenkernel/BKE_bvhutils.h
+++ b/source/blender/blenkernel/BKE_bvhutils.h
@@ -110,7 +110,7 @@ BVHTree *bvhtree_from_mesh_looptri_ex(
 struct BVHTreeFromMesh *data,
 const struct MVert *vert, const bool vert_allocated,
 const struct MLoop *mloop, const bool loop_allocated,
-const struct MLoopTri *looptri, const int looptri_num, const bool 
face_allocated,
+const struct MLoopTri *looptri, const int looptri_num, const bool 
looptri_allocated,
 BLI_bitmap *mask, int looptri_num_active,
 float epsilon, int tree_type, int axis);
 
diff --git a/source/blender/makesrna/intern/rna_nodetree.c 
b/source/blender/makesrna/intern/rna_nodetree.c
index 7fc25f9..168b2ce 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -39,7 +39,6 @@
 #include DNA_node_types.h
 #include DNA_object_types.h
 #include DNA_particle_types.h
-#include DNA_scene_types.h
 #include DNA_text_types.h
 #include DNA_texture_types.h

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [8155d25] master: Utility function to get poly - looptri mapping

2015-07-22 Thread Campbell Barton
Commit: 8155d25d395c30efd7724509afe2e50fb58c6d87
Author: Campbell Barton
Date:   Thu Jul 23 15:08:27 2015 +1000
Branches: master
https://developer.blender.org/rB8155d25d395c30efd7724509afe2e50fb58c6d87

Utility function to get poly - looptri mapping

===

M   source/blender/blenkernel/BKE_mesh_mapping.h
M   source/blender/blenkernel/intern/mesh_mapping.c

===

diff --git a/source/blender/blenkernel/BKE_mesh_mapping.h 
b/source/blender/blenkernel/BKE_mesh_mapping.h
index 633bd8a..c8a1700 100644
--- a/source/blender/blenkernel/BKE_mesh_mapping.h
+++ b/source/blender/blenkernel/BKE_mesh_mapping.h
@@ -36,6 +36,7 @@ struct MEdge;
 struct MPoly;
 struct MLoop;
 struct MLoopUV;
+struct MLoopTri;
 
 /* map from uv vertex to face (for select linked, stitch, uv suburf) */
 
@@ -127,7 +128,10 @@ void BKE_mesh_origindex_map_create(
 MeshElemMap **r_map, int **r_mem,
 const int totorig,
 const int *final_origindex, const int totfinal);
-
+void BKE_mesh_origindex_map_create_looptri(
+MeshElemMap **r_map, int **r_mem,
+const struct MPoly *mpoly, const int mpoly_num,
+const struct MLoopTri *looptri, const int looptri_num);
 
 /* islands */
 
diff --git a/source/blender/blenkernel/intern/mesh_mapping.c 
b/source/blender/blenkernel/intern/mesh_mapping.c
index 1d89785..c03f1fe 100644
--- a/source/blender/blenkernel/intern/mesh_mapping.c
+++ b/source/blender/blenkernel/intern/mesh_mapping.c
@@ -406,6 +406,37 @@ void BKE_mesh_origindex_map_create(MeshElemMap **r_map, 
int **r_mem,
*r_mem = indices;
 }
 
+/**
+ * A version of #BKE_mesh_origindex_map_create that takes a looptri array.
+ * Making a poly - looptri map.
+ */
+void BKE_mesh_origindex_map_create_looptri(
+MeshElemMap **r_map, int **r_mem,
+const MPoly *mpoly, const int mpoly_num,
+const MLoopTri *looptri, const int looptri_num)
+{
+   MeshElemMap *map = MEM_callocN(sizeof(MeshElemMap) * (size_t)mpoly_num, 
poly-tessface map);
+   int *indices = MEM_mallocN(sizeof(int) * (size_t)looptri_num, 
poly-tessface map mem);
+   int *index_step;
+   int i;
+
+   /* create offsets */
+   index_step = indices;
+   for (i = 0; i  mpoly_num; i++) {
+   map[i].indices = index_step;
+   index_step += ME_POLY_TRI_TOT(mpoly[i]);
+   }
+
+   /* assign poly-tessface users */
+   for (i = 0; i  looptri_num; i++) {
+   MeshElemMap *map_ele = map[looptri[i].poly];
+   map_ele-indices[map_ele-count++] = i;
+   }
+
+   *r_map = map;
+   *r_mem = indices;
+}
+
 /** \} */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [abbd82a5] master: Use looptri for mesh remapping

2015-07-22 Thread Campbell Barton
Commit: abbd82a5040baa3950801c5be3596c0cd71c94fc
Author: Campbell Barton
Date:   Thu Jul 23 15:10:12 2015 +1000
Branches: master
https://developer.blender.org/rBabbd82a5040baa3950801c5be3596c0cd71c94fc

Use looptri for mesh remapping

===

M   source/blender/blenkernel/intern/mesh_remap.c

===

diff --git a/source/blender/blenkernel/intern/mesh_remap.c 
b/source/blender/blenkernel/intern/mesh_remap.c
index 082e0de..ec8b362 100644
--- a/source/blender/blenkernel/intern/mesh_remap.c
+++ b/source/blender/blenkernel/intern/mesh_remap.c
@@ -537,7 +537,6 @@ void BKE_mesh_remap_calc_verts_from_dm(
MPoly *polys_src = dm_src-getPolyArray(dm_src);
MLoop *loops_src = dm_src-getLoopArray(dm_src);
float (*vcos_src)[3] = MEM_mallocN(sizeof(*vcos_src) * 
(size_t)dm_src-getNumVerts(dm_src), __func__);
-   int *tessface_to_poly_map_src;
 
size_t tmp_buff_size = MREMAP_DEFAULT_BUFSIZE;
float (*vcos)[3] = MEM_mallocN(sizeof(*vcos) * 
tmp_buff_size, __func__);
@@ -545,9 +544,7 @@ void BKE_mesh_remap_calc_verts_from_dm(
float *weights = MEM_mallocN(sizeof(*weights) * 
tmp_buff_size, __func__);
 
dm_src-getVertCos(dm_src, vcos_src);
-   bvhtree_from_mesh_faces(treedata, dm_src, (mode  
MREMAP_USE_NORPROJ) ? ray_radius : 0.0f, 2, 6);
-   /* bvhtree here uses tesselated faces... */
-   tessface_to_poly_map_src = 
dm_src-getTessFaceDataArray(dm_src, CD_ORIGINDEX);
+   bvhtree_from_mesh_looptri(treedata, dm_src, (mode  
MREMAP_USE_NORPROJ) ? ray_radius : 0.0f, 2, 6);
 
if (mode == MREMAP_MODE_VERT_POLYINTERP_VNORPROJ) {
for (i = 0; i  numverts_dst; i++) {
@@ -565,7 +562,8 @@ void BKE_mesh_remap_calc_verts_from_dm(
if (mesh_remap_bvhtree_query_raycast(
treedata, rayhit, tmp_co, 
tmp_no, ray_radius, max_dist, hit_dist))
{
-   MPoly *mp_src = 
polys_src[tessface_to_poly_map_src[rayhit.index]];
+   const MLoopTri *lt = 
treedata.looptri[rayhit.index];
+   MPoly *mp_src = 
polys_src[lt-poly];
const int sources_num = 
mesh_remap_interp_poly_data_get(
mp_src, loops_src, 
(const float (*)[3])vcos_src, rayhit.co,
tmp_buff_size, vcos, 
false, indices, weights, true, NULL);
@@ -592,7 +590,8 @@ void BKE_mesh_remap_calc_verts_from_dm(
}
 
if 
(mesh_remap_bvhtree_query_nearest(treedata, nearest, tmp_co, max_dist_sq, 
hit_dist)) {
-   MPoly *mp = 
polys_src[tessface_to_poly_map_src[nearest.index]];
+   const MLoopTri *lt = 
treedata.looptri[rayhit.index];
+   MPoly *mp = 
polys_src[lt-poly];
 
if (mode == 
MREMAP_MODE_VERT_POLY_NEAREST) {
int index;
@@ -810,12 +809,9 @@ void BKE_mesh_remap_calc_edges_from_dm(
MPoly *polys_src = dm_src-getPolyArray(dm_src);
MLoop *loops_src = dm_src-getLoopArray(dm_src);
float (*vcos_src)[3] = MEM_mallocN(sizeof(*vcos_src) * 
(size_t)dm_src-getNumVerts(dm_src), __func__);
-   int *tessface_to_poly_map_src;
 
dm_src-getVertCos(dm_src, vcos_src);
-   bvhtree_from_mesh_faces(treedata, dm_src, 0.0f, 2, 6);
-   /* bvhtree here uses tesselated faces... */
-   tessface_to_poly_map_src = 
dm_src-getTessFaceDataArray(dm_src, CD_ORIGINDEX);
+   bvhtree_from_mesh_looptri(treedata, dm_src, 0.0f, 2, 
6);
 
for (i = 0; i  numedges_dst; i++) {
float tmp_co[3];
@@ -828,7 +824,8 @@ void BKE_mesh_remap_calc_edges_from_dm(
}
 
if (mesh_remap_bvhtree_query_nearest(treedata, 
nearest, tmp_co, max_dist_sq, hit_dist)) {
-   MPoly *mp_src = 
polys_src[tessface_to_poly_map_src[nearest.index]];
+   const MLoopTri *lt = 
treedata.looptri[rayhit.index];
+  

[Bf-blender-cvs] [0a249f9] master: Cleanup: arg names

2015-07-22 Thread Campbell Barton
Commit: 0a249f98534e20928d2d52c4585bff5d96ea9000
Author: Campbell Barton
Date:   Thu Jul 23 15:17:26 2015 +1000
Branches: master
https://developer.blender.org/rB0a249f98534e20928d2d52c4585bff5d96ea9000

Cleanup: arg names

===

M   source/blender/blenkernel/BKE_DerivedMesh.h
M   source/blender/blenkernel/BKE_bvhutils.h
M   source/blender/blenkernel/intern/DerivedMesh.c
M   source/blender/blenkernel/intern/bvhutils.c

===

diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h 
b/source/blender/blenkernel/BKE_DerivedMesh.h
index 369bd51..32baa45 100644
--- a/source/blender/blenkernel/BKE_DerivedMesh.h
+++ b/source/blender/blenkernel/BKE_DerivedMesh.h
@@ -795,16 +795,16 @@ BLI_INLINE int DM_origindex_mface_mpoly(
return (j != ORIGINDEX_NONE) ? (index_mp_to_orig ? index_mp_to_orig[j] 
: j) : ORIGINDEX_NONE;
 }
 
-struct MVert *DM_get_vert_array(struct DerivedMesh *dm, bool *allocated);
-struct MEdge *DM_get_edge_array(struct DerivedMesh *dm, bool *allocated);
-struct MLoop *DM_get_loop_array(struct DerivedMesh *dm, bool *allocated);
-struct MPoly *DM_get_poly_array(struct DerivedMesh *dm, bool *allocated);
-struct MFace *DM_get_tessface_array(struct DerivedMesh *dm, bool *allocated);
+struct MVert *DM_get_vert_array(struct DerivedMesh *dm, bool *r_allocated);
+struct MEdge *DM_get_edge_array(struct DerivedMesh *dm, bool *r_allocated);
+struct MLoop *DM_get_loop_array(struct DerivedMesh *dm, bool *r_allocated);
+struct MPoly *DM_get_poly_array(struct DerivedMesh *dm, bool *r_allocated);
+struct MFace *DM_get_tessface_array(struct DerivedMesh *dm, bool *r_allocated);
 const MLoopTri *DM_get_looptri_array(
 DerivedMesh *dm,
 const MVert *mvert,
 const MPoly *mpoly, int mpoly_len,
 const MLoop *mloop, int mloop_len,
-bool *allocated);
+bool *r_allocated);
 
 #endif  /* __BKE_DERIVEDMESH_H__ */
diff --git a/source/blender/blenkernel/BKE_bvhutils.h 
b/source/blender/blenkernel/BKE_bvhutils.h
index 9220082..52a659b 100644
--- a/source/blender/blenkernel/BKE_bvhutils.h
+++ b/source/blender/blenkernel/BKE_bvhutils.h
@@ -110,8 +110,8 @@ BVHTree *bvhtree_from_mesh_looptri_ex(
 struct BVHTreeFromMesh *data,
 const struct MVert *vert, const bool vert_allocated,
 const struct MLoop *mloop, const bool loop_allocated,
-const struct MLoopTri *looptri, const int numFaces, const bool 
face_allocated,
-BLI_bitmap *mask, int numFaces_active,
+const struct MLoopTri *looptri, const int looptri_num, const bool 
face_allocated,
+BLI_bitmap *mask, int looptri_num_active,
 float epsilon, int tree_type, int axis);
 
 /**
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c 
b/source/blender/blenkernel/intern/DerivedMesh.c
index 60a681d..2b4a0f4 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -3838,41 +3838,41 @@ MEdge *DM_get_edge_array(DerivedMesh *dm, bool 
*allocated)
return medge;
 }
 
-MLoop *DM_get_loop_array(DerivedMesh *dm, bool *allocated)
+MLoop *DM_get_loop_array(DerivedMesh *dm, bool *r_allocated)
 {
CustomData *loop_data = dm-getEdgeDataLayout(dm);
MLoop *mloop = CustomData_get_layer(loop_data, CD_MLOOP);
-   *allocated = false;
+   *r_allocated = false;
 
if (mloop == NULL) {
mloop = MEM_mallocN(sizeof(MLoop) * dm-getNumLoops(dm), dm 
loop data array);
dm-copyLoopArray(dm, mloop);
-   *allocated = true;
+   *r_allocated = true;
}
 
return mloop;
 }
 
-MPoly *DM_get_poly_array(DerivedMesh *dm, bool *allocated)
+MPoly *DM_get_poly_array(DerivedMesh *dm, bool *r_allocated)
 {
CustomData *poly_data = dm-getPolyDataLayout(dm);
MPoly *mpoly = CustomData_get_layer(poly_data, CD_MPOLY);
-   *allocated = false;
+   *r_allocated = false;
 
if (mpoly == NULL) {
mpoly = MEM_mallocN(sizeof(MPoly) * dm-getNumPolys(dm), dm 
poly data array);
dm-copyPolyArray(dm, mpoly);
-   *allocated = true;
+   *r_allocated = true;
}
 
return mpoly;
 }
 
-MFace *DM_get_tessface_array(DerivedMesh *dm, bool *allocated)
+MFace *DM_get_tessface_array(DerivedMesh *dm, bool *r_allocated)
 {
CustomData *tessface_data = dm-getTessFaceDataLayout(dm);
MFace *mface = CustomData_get_layer(tessface_data, CD_MFACE);
-   *allocated = false;
+   *r_allocated = false;
 
if (mface == NULL) {
int numTessFaces = dm-getNumTessFaces(dm);
@@ -3880,7 +3880,7 @@ MFace *DM_get_tessface_array(DerivedMesh *dm, bool 
*allocated)
if (numTessFaces  0) {
mface = MEM_mallocN(sizeof(MFace) * numTessFaces, bvh 
mface data array);

[Bf-blender-cvs] [748899a] master: Missed adding BVH callbacks in recent commit

2015-07-22 Thread Campbell Barton
Commit: 748899a50a0c1d83495db30a6161060cfbf420f1
Author: Campbell Barton
Date:   Thu Jul 23 13:09:14 2015 +1000
Branches: master
https://developer.blender.org/rB748899a50a0c1d83495db30a6161060cfbf420f1

Missed adding BVH callbacks in recent commit

===

M   source/blender/blenkernel/intern/bvhutils.c

===

diff --git a/source/blender/blenkernel/intern/bvhutils.c 
b/source/blender/blenkernel/intern/bvhutils.c
index e42c73f..517d060 100644
--- a/source/blender/blenkernel/intern/bvhutils.c
+++ b/source/blender/blenkernel/intern/bvhutils.c
@@ -124,6 +124,29 @@ static void mesh_faces_nearest_point(void *userdata, int 
index, const float co[3
 
} while (t2);
 }
+/* copy of function above */
+static void mesh_looptri_nearest_point(void *userdata, int index, const float 
co[3], BVHTreeNearest *nearest)
+{
+   const BVHTreeFromMesh *data = (BVHTreeFromMesh *) userdata;
+   const MVert *vert = data-vert;
+   const MLoopTri *lt = data-looptri[index];
+   const float *vtri_co[3] = {
+   vert[data-loop[lt-tri[0]].v].co,
+   vert[data-loop[lt-tri[1]].v].co,
+   vert[data-loop[lt-tri[2]].v].co,
+   };
+   float nearest_tmp[3], dist_sq;
+
+   closest_on_tri_to_point_v3(nearest_tmp, co, UNPACK3(vtri_co));
+   dist_sq = len_squared_v3v3(co, nearest_tmp);
+
+   if (dist_sq  nearest-dist_sq) {
+   nearest-index = index;
+   nearest-dist_sq = dist_sq;
+   copy_v3_v3(nearest-co, nearest_tmp);
+   normal_tri_v3(nearest-no, UNPACK3(vtri_co));
+   }
+}
 /* copy of function above (warning, should de-duplicate with editmesh_bvh.c) */
 static void editmesh_faces_nearest_point(void *userdata, int index, const 
float co[3], BVHTreeNearest *nearest)
 {
@@ -190,6 +213,32 @@ static void mesh_faces_spherecast(void *userdata, int 
index, const BVHTreeRay *r
 
} while (t2);
 }
+/* copy of function above */
+static void mesh_looptri_spherecast(void *userdata, int index, const 
BVHTreeRay *ray, BVHTreeRayHit *hit)
+{
+   const BVHTreeFromMesh *data = (BVHTreeFromMesh *) userdata;
+   const MVert *vert = data-vert;
+   const MLoopTri *lt = data-looptri[index];
+   const float *vtri_co[3] = {
+   vert[data-loop[lt-tri[0]].v].co,
+   vert[data-loop[lt-tri[1]].v].co,
+   vert[data-loop[lt-tri[2]].v].co,
+   };
+   float dist;
+
+   if (data-sphere_radius == 0.0f)
+   dist = bvhtree_ray_tri_intersection(ray, hit-dist, 
UNPACK3(vtri_co));
+   else
+   dist = sphereray_tri_intersection(ray, data-sphere_radius, 
hit-dist, UNPACK3(vtri_co));
+
+   if (dist = 0  dist  hit-dist) {
+   hit-index = index;
+   hit-dist = dist;
+   madd_v3_v3v3fl(hit-co, ray-origin, ray-direction, dist);
+
+   normal_tri_v3(hit-no, UNPACK3(vtri_co));
+   }
+}
 /* copy of function above (warning, should de-duplicate with editmesh_bvh.c) */
 static void editmesh_faces_spherecast(void *userdata, int index, const 
BVHTreeRay *ray, BVHTreeRayHit *hit)
 {
@@ -906,8 +955,8 @@ static void bvhtree_from_mesh_looptri_setup_data(
data-raycast_callback = editmesh_faces_spherecast;
}
else {
-   data-nearest_callback = mesh_faces_nearest_point;
-   data-raycast_callback = mesh_faces_spherecast;
+   data-nearest_callback = mesh_looptri_nearest_point;
+   data-raycast_callback = mesh_looptri_spherecast;
 
data-vert = vert;
data-vert_allocated = vert_allocated;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [0b7d0f9] master: Fix weight painting + mask not drawing in latest master.

2015-07-22 Thread Antony Riakiotakis
Commit: 0b7d0f913d4e5068afb15189bb077d4e84cebfda
Author: Antony Riakiotakis
Date:   Wed Jul 22 16:58:18 2015 +0200
Branches: master
https://developer.blender.org/rB0b7d0f913d4e5068afb15189bb077d4e84cebfda

Fix weight painting + mask not drawing in latest master.

Same issue as vertex painting - though one might wonder if we really
need to set material on such occasions.

===

M   source/blender/editors/space_view3d/drawmesh.c

===

diff --git a/source/blender/editors/space_view3d/drawmesh.c 
b/source/blender/editors/space_view3d/drawmesh.c
index 757eecf..ea1e317 100644
--- a/source/blender/editors/space_view3d/drawmesh.c
+++ b/source/blender/editors/space_view3d/drawmesh.c
@@ -1220,11 +1220,13 @@ static void draw_mesh_paint_light_end(void)
 void draw_mesh_paint_weight_faces(DerivedMesh *dm, const bool use_light,
   void *facemask_cb, void *user_data)
 {
+   DMSetMaterial setMaterial = GPU_object_materials_check() ? 
GPU_enable_material : NULL;
+
if (use_light) {
draw_mesh_paint_light_begin();
}
 
-   dm-drawMappedFaces(dm, (DMSetDrawOptions)facemask_cb, 
GPU_enable_material, NULL, user_data,
+   dm-drawMappedFaces(dm, (DMSetDrawOptions)facemask_cb, setMaterial, 
NULL, user_data,
DM_DRAW_USE_COLORS);
 
if (use_light) {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [0795f62] master: GPU debug: Only flush stderr if needed.

2015-07-22 Thread Antony Riakiotakis
Commit: 0795f62ddfed50d0836ab42849b791b0a0a43a0b
Author: Antony Riakiotakis
Date:   Wed Jul 22 13:57:35 2015 +0200
Branches: master
https://developer.blender.org/rB0795f62ddfed50d0836ab42849b791b0a0a43a0b

GPU debug: Only flush stderr if needed.

===

M   source/blender/gpu/intern/gpu_debug.c

===

diff --git a/source/blender/gpu/intern/gpu_debug.c 
b/source/blender/gpu/intern/gpu_debug.c
index b9a2288..15fe6ed 100644
--- a/source/blender/gpu/intern/gpu_debug.c
+++ b/source/blender/gpu/intern/gpu_debug.c
@@ -167,12 +167,14 @@ static void APIENTRY gpu_debug_proc(GLenum source, GLenum 
type, GLuint UNUSED(id
GLenum UNUSED(severity), GLsizei UNUSED(length),
const GLchar *message, GLvoid *UNUSED(userParm))
 {
-   if (source == GL_DEBUG_SOURCE_API  type == GL_DEBUG_TYPE_ERROR)
+   if (source == GL_DEBUG_SOURCE_API  type == GL_DEBUG_TYPE_ERROR) {
fprintf(stderr, GL: %s\n, message);
+   fflush(stderr);
+   }
else if (G.debug_value == 20) {
fprintf(stderr, GL: %s\n, message);
+   fflush(stderr);
}
-   fflush(stderr);
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs