Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2012-01-22 03:01:25 +0400
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2012-01-22 03:01:25 +0400
commit68ae82bb479a79de72cf174763f3244f64e28bb0 (patch)
tree159f1f1a8211ff2d2d89a80f94739cc0f0dfe696 /source/blender
parent3667cddf1ada28b6964bc9beeb7cce31f04e18a8 (diff)
parentb95beea539b22baeb68013c4e65fb0455b968890 (diff)
Merged changes in the trunk up to revision 43585.
Conflicts resolved: source/blender/editors/include/UI_resources.h source/blender/editors/interface/resources.c source/blender/makesrna/intern/rna_scene.c
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/BKE_DerivedMesh.h5
-rw-r--r--source/blender/blenkernel/BKE_armature.h4
-rw-r--r--source/blender/blenkernel/BKE_array_mallocn.h85
-rw-r--r--source/blender/blenkernel/BKE_blender.h2
-rw-r--r--source/blender/blenkernel/BKE_global.h2
-rw-r--r--source/blender/blenkernel/BKE_image.h2
-rw-r--r--source/blender/blenkernel/BKE_main.h2
-rw-r--r--source/blender/blenkernel/BKE_mesh.h38
-rw-r--r--source/blender/blenkernel/BKE_text.h57
-rw-r--r--source/blender/blenkernel/BKE_utildefines.h6
-rw-r--r--source/blender/blenkernel/CMakeLists.txt1
-rw-r--r--source/blender/blenkernel/intern/DerivedMesh.c76
-rw-r--r--source/blender/blenkernel/intern/armature.c332
-rw-r--r--source/blender/blenkernel/intern/brush.c31
-rw-r--r--source/blender/blenkernel/intern/constraint.c15
-rw-r--r--source/blender/blenkernel/intern/curve.c5
-rw-r--r--source/blender/blenkernel/intern/dynamicpaint.c337
-rw-r--r--source/blender/blenkernel/intern/image.c6
-rw-r--r--source/blender/blenkernel/intern/image_gen.c15
-rw-r--r--source/blender/blenkernel/intern/key.c2
-rw-r--r--source/blender/blenkernel/intern/mesh.c12
-rw-r--r--source/blender/blenkernel/intern/movieclip.c2
-rw-r--r--source/blender/blenkernel/intern/node.c48
-rw-r--r--source/blender/blenkernel/intern/paint.c5
-rw-r--r--source/blender/blenkernel/intern/scene.c4
-rw-r--r--source/blender/blenkernel/intern/sequencer.c4
-rw-r--r--source/blender/blenkernel/intern/softbody.c4
-rw-r--r--source/blender/blenkernel/intern/subsurf_ccg.c45
-rw-r--r--source/blender/blenkernel/intern/text.c825
-rw-r--r--source/blender/blenlib/BLI_math_color.h9
-rw-r--r--source/blender/blenlib/BLI_math_geom.h5
-rw-r--r--source/blender/blenlib/BLI_math_vector.h4
-rw-r--r--source/blender/blenlib/intern/BLI_ghash.c2
-rw-r--r--source/blender/blenlib/intern/boxpack2d.c2
-rw-r--r--source/blender/blenlib/intern/math_color.c37
-rw-r--r--source/blender/blenlib/intern/math_color_inline.c16
-rw-r--r--source/blender/blenlib/intern/math_geom.c55
-rw-r--r--source/blender/blenlib/intern/math_rotation.c2
-rw-r--r--source/blender/blenlib/intern/math_vector.c14
-rw-r--r--source/blender/blenlib/intern/math_vector_inline.c30
-rw-r--r--source/blender/blenloader/BLO_readfile.h2
-rw-r--r--source/blender/blenloader/intern/readfile.c51
-rw-r--r--source/blender/blenloader/intern/writefile.c8
-rw-r--r--source/blender/blenpluginapi/iff.h2
-rw-r--r--source/blender/editors/animation/anim_channels_defines.c2
-rw-r--r--source/blender/editors/animation/anim_channels_edit.c17
-rw-r--r--source/blender/editors/animation/anim_markers.c10
-rw-r--r--source/blender/editors/animation/keyframing.c2
-rw-r--r--source/blender/editors/armature/armature_ops.c27
-rw-r--r--source/blender/editors/armature/editarmature_retarget.c2
-rw-r--r--source/blender/editors/curve/curve_ops.c20
-rw-r--r--source/blender/editors/gpencil/gpencil_ops.c3
-rw-r--r--source/blender/editors/include/ED_image.h5
-rw-r--r--source/blender/editors/include/ED_mesh.h7
-rw-r--r--source/blender/editors/include/ED_uvedit.h2
-rw-r--r--source/blender/editors/include/ED_view3d.h4
-rw-r--r--source/blender/editors/include/UI_interface_icons.h2
-rw-r--r--source/blender/editors/include/UI_resources.h77
-rw-r--r--source/blender/editors/interface/interface.c73
-rw-r--r--source/blender/editors/interface/interface_handlers.c17
-rw-r--r--source/blender/editors/interface/interface_icons.c4
-rw-r--r--source/blender/editors/interface/interface_intern.h3
-rw-r--r--source/blender/editors/interface/interface_layout.c37
-rw-r--r--source/blender/editors/interface/interface_ops.c4
-rw-r--r--source/blender/editors/interface/interface_panel.c3
-rw-r--r--source/blender/editors/interface/interface_regions.c44
-rw-r--r--source/blender/editors/interface/interface_templates.c14
-rw-r--r--source/blender/editors/interface/interface_widgets.c2
-rw-r--r--source/blender/editors/interface/resources.c40
-rw-r--r--source/blender/editors/interface/view2d.c7
-rw-r--r--source/blender/editors/interface/view2d_ops.c9
-rw-r--r--source/blender/editors/mesh/editmesh_lib.c230
-rw-r--r--source/blender/editors/mesh/editmesh_loop.c324
-rw-r--r--source/blender/editors/mesh/editmesh_tools.c2
-rw-r--r--source/blender/editors/mesh/loopcut.c10
-rw-r--r--source/blender/editors/mesh/mesh_data.c82
-rw-r--r--source/blender/editors/mesh/mesh_ops.c13
-rw-r--r--source/blender/editors/metaball/mball_ops.c8
-rw-r--r--source/blender/editors/object/object_add.c2
-rw-r--r--source/blender/editors/object/object_bake.c25
-rw-r--r--source/blender/editors/object/object_edit.c6
-rw-r--r--source/blender/editors/object/object_ops.c78
-rw-r--r--source/blender/editors/physics/physics_ops.c24
-rw-r--r--source/blender/editors/render/render_opengl.c6
-rw-r--r--source/blender/editors/screen/screen_ops.c26
-rw-r--r--source/blender/editors/sculpt_paint/CMakeLists.txt3
-rw-r--r--source/blender/editors/sculpt_paint/SConscript2
-rw-r--r--source/blender/editors/sculpt_paint/paint_cursor.c607
-rw-r--r--source/blender/editors/sculpt_paint/paint_image.c109
-rw-r--r--source/blender/editors/sculpt_paint/paint_intern.h8
-rw-r--r--source/blender/editors/sculpt_paint/paint_ops.c140
-rw-r--r--source/blender/editors/sculpt_paint/paint_stroke.c553
-rw-r--r--source/blender/editors/sculpt_paint/paint_utils.c2
-rw-r--r--source/blender/editors/sculpt_paint/sculpt.c30
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_intern.h2
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_uv.c780
-rw-r--r--source/blender/editors/space_buttons/buttons_context.c1
-rw-r--r--source/blender/editors/space_clip/clip_graph_draw.c7
-rw-r--r--source/blender/editors/space_clip/clip_graph_ops.c13
-rw-r--r--source/blender/editors/space_clip/clip_ops.c2
-rw-r--r--source/blender/editors/space_clip/clip_utils.c2
-rw-r--r--source/blender/editors/space_clip/space_clip.c39
-rw-r--r--source/blender/editors/space_clip/tracking_ops.c6
-rw-r--r--source/blender/editors/space_console/space_console.c11
-rw-r--r--source/blender/editors/space_file/filelist.c9
-rw-r--r--source/blender/editors/space_file/space_file.c8
-rw-r--r--source/blender/editors/space_graph/graph_ops.c3
-rw-r--r--source/blender/editors/space_image/image_draw.c40
-rw-r--r--source/blender/editors/space_image/image_ops.c40
-rw-r--r--source/blender/editors/space_image/space_image.c8
-rw-r--r--source/blender/editors/space_info/info_ops.c2
-rw-r--r--source/blender/editors/space_nla/nla_ops.c14
-rw-r--r--source/blender/editors/space_node/node_edit.c2
-rw-r--r--source/blender/editors/space_node/node_ops.c26
-rw-r--r--source/blender/editors/space_node/node_templates.c11
-rw-r--r--source/blender/editors/space_outliner/outliner_intern.h2
-rw-r--r--source/blender/editors/space_outliner/outliner_ops.c25
-rw-r--r--source/blender/editors/space_outliner/outliner_select.c75
-rw-r--r--source/blender/editors/space_script/script_edit.c2
-rw-r--r--source/blender/editors/space_sequencer/sequencer_draw.c2
-rw-r--r--source/blender/editors/space_sequencer/sequencer_edit.c4
-rw-r--r--source/blender/editors/space_sequencer/sequencer_ops.c38
-rw-r--r--source/blender/editors/space_text/space_text.c27
-rw-r--r--source/blender/editors/space_text/text_draw.c224
-rw-r--r--source/blender/editors/space_text/text_intern.h3
-rw-r--r--source/blender/editors/space_text/text_ops.c339
-rw-r--r--source/blender/editors/space_view3d/drawarmature.c49
-rw-r--r--source/blender/editors/space_view3d/drawmesh.c7
-rw-r--r--source/blender/editors/space_view3d/drawobject.c28
-rw-r--r--source/blender/editors/space_view3d/drawvolume.c7
-rw-r--r--source/blender/editors/space_view3d/space_view3d.c6
-rw-r--r--source/blender/editors/space_view3d/view3d_draw.c57
-rw-r--r--source/blender/editors/space_view3d/view3d_edit.c307
-rw-r--r--source/blender/editors/space_view3d/view3d_fly.c54
-rw-r--r--source/blender/editors/space_view3d/view3d_header.c2
-rw-r--r--source/blender/editors/space_view3d/view3d_intern.h3
-rw-r--r--source/blender/editors/space_view3d/view3d_ops.c9
-rw-r--r--source/blender/editors/space_view3d/view3d_select.c4
-rw-r--r--source/blender/editors/space_view3d/view3d_snap.c15
-rw-r--r--source/blender/editors/space_view3d/view3d_view.c13
-rw-r--r--source/blender/editors/transform/transform_conversions.c343
-rw-r--r--source/blender/editors/transform/transform_generics.c15
-rw-r--r--source/blender/editors/transform/transform_ops.c74
-rw-r--r--source/blender/editors/uvedit/CMakeLists.txt1
-rw-r--r--source/blender/editors/uvedit/uvedit_draw.c110
-rw-r--r--source/blender/editors/uvedit/uvedit_intern.h58
-rw-r--r--source/blender/editors/uvedit/uvedit_ops.c462
-rw-r--r--source/blender/editors/uvedit/uvedit_parametrizer.c18
-rw-r--r--source/blender/editors/uvedit/uvedit_smart_stitch.c1467
-rw-r--r--source/blender/editors/uvedit/uvedit_unwrap_ops.c228
-rw-r--r--source/blender/gpu/intern/gpu_codegen.c3
-rw-r--r--source/blender/gpu/intern/gpu_draw.c156
-rw-r--r--source/blender/imbuf/IMB_imbuf_types.h2
-rw-r--r--source/blender/imbuf/intern/IMB_anim.h6
-rw-r--r--source/blender/imbuf/intern/IMB_indexer.h2
-rw-r--r--source/blender/imbuf/intern/divers.c55
-rw-r--r--source/blender/makesdna/DNA_ID.h4
-rw-r--r--source/blender/makesdna/DNA_brush_types.h2
-rw-r--r--source/blender/makesdna/DNA_customdata_types.h2
-rw-r--r--source/blender/makesdna/DNA_dynamicpaint_types.h13
-rw-r--r--source/blender/makesdna/DNA_fileglobal_types.h2
-rw-r--r--source/blender/makesdna/DNA_image_types.h3
-rw-r--r--source/blender/makesdna/DNA_modifier_types.h2
-rw-r--r--source/blender/makesdna/DNA_movieclip_types.h4
-rw-r--r--source/blender/makesdna/DNA_node_types.h12
-rw-r--r--source/blender/makesdna/DNA_object_fluidsim.h4
-rw-r--r--source/blender/makesdna/DNA_object_force.h2
-rw-r--r--source/blender/makesdna/DNA_scene_types.h33
-rw-r--r--source/blender/makesdna/DNA_sequence_types.h18
-rw-r--r--source/blender/makesdna/DNA_sound_types.h2
-rw-r--r--source/blender/makesdna/DNA_space_types.h22
-rw-r--r--source/blender/makesdna/DNA_texture_types.h4
-rw-r--r--source/blender/makesdna/DNA_tracking_types.h7
-rw-r--r--source/blender/makesdna/DNA_userdef_types.h37
-rw-r--r--source/blender/makesdna/DNA_vfont_types.h2
-rw-r--r--source/blender/makesrna/RNA_access.h1
-rw-r--r--source/blender/makesrna/intern/SConscript4
-rw-r--r--source/blender/makesrna/intern/rna_controller.c19
-rw-r--r--source/blender/makesrna/intern/rna_dynamicpaint.c25
-rw-r--r--source/blender/makesrna/intern/rna_fluidsim.c6
-rw-r--r--source/blender/makesrna/intern/rna_main.c4
-rw-r--r--source/blender/makesrna/intern/rna_mesh.c16
-rw-r--r--source/blender/makesrna/intern/rna_nodetree.c2
-rw-r--r--source/blender/makesrna/intern/rna_object_api.c62
-rw-r--r--source/blender/makesrna/intern/rna_scene.c73
-rw-r--r--source/blender/makesrna/intern/rna_sculpt_paint.c15
-rw-r--r--source/blender/makesrna/intern/rna_sensor.c21
-rw-r--r--source/blender/makesrna/intern/rna_tracking.c2
-rw-r--r--source/blender/makesrna/intern/rna_ui.c2
-rw-r--r--source/blender/makesrna/intern/rna_userdef.c48
-rw-r--r--source/blender/modifiers/intern/MOD_boolean.c1
-rw-r--r--source/blender/modifiers/intern/MOD_build.c151
-rw-r--r--source/blender/modifiers/intern/MOD_solidify.c2
-rw-r--r--source/blender/nodes/NOD_socket.h33
-rw-r--r--source/blender/nodes/intern/node_common.c195
-rw-r--r--source/blender/nodes/intern/node_socket.c355
-rw-r--r--source/blender/python/intern/bpy_interface.c5
-rw-r--r--source/blender/python/intern/bpy_props.c111
-rw-r--r--source/blender/python/intern/bpy_rna.c34
-rw-r--r--source/blender/python/mathutils/mathutils_Matrix.c9
-rw-r--r--source/blender/render/extern/include/RE_shader_ext.h4
-rw-r--r--source/blender/render/intern/source/imagetexture.c6
-rw-r--r--source/blender/render/intern/source/render_texture.c3
-rw-r--r--source/blender/render/intern/source/rendercore.c38
-rw-r--r--source/blender/windowmanager/WM_types.h4
-rw-r--r--source/blender/windowmanager/intern/wm_dragdrop.c2
-rw-r--r--source/blender/windowmanager/intern/wm_keymap.c9
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c3
208 files changed, 8077 insertions, 3629 deletions
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h
index 5f451ce7821..0c47c833cb3 100644
--- a/source/blender/blenkernel/BKE_DerivedMesh.h
+++ b/source/blender/blenkernel/BKE_DerivedMesh.h
@@ -584,5 +584,10 @@ void DM_calc_auto_bump_scale(DerivedMesh *dm);
/* Set object's bounding box based on DerivedMesh min/max data */
void DM_set_object_boundbox(struct Object *ob, DerivedMesh *dm);
+/* debug only */
+#ifndef NDEBUG
+char *DM_debug_info(DerivedMesh *dm);
+void DM_debug_print(DerivedMesh *dm);
#endif
+#endif
diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h
index b301b7cf03b..a89bfbd50b1 100644
--- a/source/blender/blenkernel/BKE_armature.h
+++ b/source/blender/blenkernel/BKE_armature.h
@@ -114,6 +114,10 @@ void pchan_apply_mat4(struct bPoseChannel *pchan, float mat[][4], short use_coma
void pchan_to_mat4(struct bPoseChannel *pchan, float chan_mat[4][4]);
void pchan_calc_mat(struct bPoseChannel *pchan);
+/* Get the "pchan to pose" transform matrix. These matrices apply the effects of
+ * HINGE/NO_SCALE/NO_LOCAL_LOCATION options over the pchan loc/rot/scale transformations. */
+void pchan_to_pose_mat(struct bPoseChannel *pchan, float rotscale_mat[][4], float loc_mat[][4]);
+
/* Rotation Mode Conversions - Used for PoseChannels + Objects... */
void BKE_rotMode_change_values(float quat[4], float eul[3], float axis[3], float *angle, short oldMode, short newMode);
diff --git a/source/blender/blenkernel/BKE_array_mallocn.h b/source/blender/blenkernel/BKE_array_mallocn.h
deleted file mode 100644
index 0f312360521..00000000000
--- a/source/blender/blenkernel/BKE_array_mallocn.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef BKE_ARRAY_MALLOCN_H
-#define BKE_ARRAY_MALLOCN_H
-
-/** \file BKE_array_mallocn.h
- * \ingroup bke
- * \brief little array macro library.
- */
-
-/* example of usage:
- *
- * int *arr = NULL;
- * V_DECLARE(arr);
- * int i;
- *
- * for (i=0; i<10; i++) {
- * V_GROW(arr);
- * arr[i] = something;
- * }
- * V_FREE(arr);
- *
- * arrays are buffered, using double-buffering (so on each reallocation,
- * the array size is doubled). supposedly this should give good Big Oh
- * behaviour, though it may not be the best in practice.
- */
-
-#define V_DECLARE(vec) int _##vec##_count=0; void *_##vec##_tmp
-
-/* in the future, I plan on having V_DECLARE allocate stack memory it'll
- * use at first, and switch over to heap when it needs more. that'll mess
- * up cases where you'd want to use this API to build a dynamic list for
- * non-local use, so all such cases should use this macro.*/
-#define V_DYNDECLARE(vec) V_DECLARE(vec)
-
-/*this returns the entire size of the array, including any buffering.*/
-#define V_SIZE(vec) ((signed int)((vec)==NULL ? 0 : MEM_allocN_len(vec) / sizeof(*vec)))
-
-/*this returns the logical size of the array, not including buffering.*/
-#define V_COUNT(vec) _##vec##_count
-
-/*grow the array by one. zeroes the new elements.*/
-#define V_GROW(vec) \
- V_SIZE(vec) > _##vec##_count ? _##vec##_count++ : \
- ((_##vec##_tmp = MEM_callocN(sizeof(*vec)*(_##vec##_count*2+2), #vec " " __FILE__ " ")),\
- (void)(vec && memcpy(_##vec##_tmp, vec, sizeof(*vec) * _##vec##_count)),\
- (void)(vec && (MEM_freeN(vec),1)),\
- (vec = _##vec##_tmp),\
- _##vec##_count++)
-
-#define V_FREE(vec) if (vec) MEM_freeN(vec);
-
-/*resets the logical size of an array to zero, but doesn't
- free the memory.*/
-#define V_RESET(vec) _##vec##_count=0
-
-/*set the count of the array*/
-#define V_SETCOUNT(vec, count) _##vec##_count = (count)
-
-#endif // BKE_ARRAY_MALLOCN_H
diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h
index 3632eb33717..f24687e0fc9 100644
--- a/source/blender/blenkernel/BKE_blender.h
+++ b/source/blender/blenkernel/BKE_blender.h
@@ -42,7 +42,7 @@ extern "C" {
* and keep comment above the defines.
* Use STRINGIFY() rather than defining with quotes */
#define BLENDER_VERSION 261
-#define BLENDER_SUBVERSION 2
+#define BLENDER_SUBVERSION 3
#define BLENDER_MINVERSION 250
#define BLENDER_MINSUBVERSION 0
diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h
index 7668d5392da..ee3edbb47e7 100644
--- a/source/blender/blenkernel/BKE_global.h
+++ b/source/blender/blenkernel/BKE_global.h
@@ -53,7 +53,7 @@ typedef struct Global {
struct Main *main;
/* strings: lastsaved */
- char ima[256], lib[256];
+ char ima[1024], lib[1024]; /* 1024 = FILE_MAX */
/* flag: if != 0 G.main->name contains valid relative base path */
int relbase_valid;
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index c829fc69b05..5cdc3537f5b 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -186,7 +186,7 @@ void BKE_image_merge(struct Image *dest, struct Image *source);
int BKE_image_has_alpha(struct Image *image);
/* image_gen.c */
-void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, int height, float color[4]);
+void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, int height, const float color[4]);
void BKE_image_buf_fill_checker(unsigned char *rect, float *rect_float, int height, int width);
void BKE_image_buf_fill_checker_color(unsigned char *rect, float *rect_float, int height, int width);
diff --git a/source/blender/blenkernel/BKE_main.h b/source/blender/blenkernel/BKE_main.h
index ada0761f7d2..7a7f6dfb6f9 100644
--- a/source/blender/blenkernel/BKE_main.h
+++ b/source/blender/blenkernel/BKE_main.h
@@ -50,7 +50,7 @@ struct Library;
typedef struct Main {
struct Main *next, *prev;
- char name[240];
+ char name[1024]; /* 1024 = FILE_MAX */
short versionfile, subversionfile;
short minversionfile, minsubversionfile;
int revision; /* svn revision of binary that saved file */
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 53ff7d873ad..30a4b154e31 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -52,7 +52,10 @@ struct CustomData;
struct DerivedMesh;
struct Scene;
struct MLoopUV;
-
+struct UvVertMap;
+struct UvMapVert;
+struct UvElementMap;
+struct UvElement;
#ifdef __cplusplus
extern "C" {
#endif
@@ -126,6 +129,39 @@ typedef struct UvMapVert {
unsigned char tfindex, separate, flag;
} UvMapVert;
+typedef struct UvElementMap {
+ /* address UvElements by their vertex */
+ struct UvElement **vert;
+ /* UvElement Store */
+ struct UvElement *buf;
+ /* Total number of UVs in the layer. Useful to know */
+ int totalUVs;
+ /* Number of Islands in the mesh */
+ int totalIslands;
+ /* Stores the starting index in buf where each island begins */
+ int *islandIndices;
+} UvElementMap;
+
+typedef struct UvElement {
+ /* Next UvElement corresponding to same vertex */
+ struct UvElement *next;
+ /* Face the element belongs to */
+ struct EditFace *face;
+ /* Index in the editFace of the uv */
+ unsigned char tfindex;
+ /* Whether this element is the first of coincident elements */
+ unsigned char separate;
+ /* general use flag */
+ unsigned char flag;
+ /* If generating element map with island sorting, this stores the island index */
+ unsigned short island;
+} UvElement;
+
+/* invalid island index is max short. If any one has the patience
+ * to make that many islands, he can bite me :p */
+#define INVALID_ISLAND 0xFFFF
+
+
UvVertMap *make_uv_vert_map(struct MFace *mface, struct MTFace *tface, unsigned int totface, unsigned int totvert, int selected, float *limit);
UvMapVert *get_uv_map_vert(UvVertMap *vmap, unsigned int v);
void free_uv_vert_map(UvVertMap *vmap);
diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h
index a951347d946..f0c054560c4 100644
--- a/source/blender/blenkernel/BKE_text.h
+++ b/source/blender/blenkernel/BKE_text.h
@@ -46,7 +46,8 @@ void free_text (struct Text *text);
void txt_set_undostate (int u);
int txt_get_undostate (void);
struct Text* add_empty_text (const char *name);
-int reopen_text (struct Text *text);
+int txt_extended_ascii_as_utf8(char **str);
+int reopen_text (struct Text *text);
struct Text* add_text (const char *file, const char *relpath);
struct Text* copy_text (struct Text *ta);
void unlink_text (struct Main *bmain, struct Text *text);
@@ -59,6 +60,8 @@ void txt_order_cursors (struct Text *text);
int txt_find_string (struct Text *text, const char *findstr, int wrap, int match_case);
int txt_has_sel (struct Text *text);
int txt_get_span (struct TextLine *from, struct TextLine *to);
+int txt_utf8_offset_to_index(char *str, int offset);
+int txt_utf8_index_to_offset(char *str, int index);
void txt_move_up (struct Text *text, short sel);
void txt_move_down (struct Text *text, short sel);
void txt_move_left (struct Text *text, short sel);
@@ -86,9 +89,9 @@ void txt_do_redo (struct Text *text);
void txt_split_curline (struct Text *text);
void txt_backspace_char (struct Text *text);
void txt_backspace_word (struct Text *text);
-int txt_add_char (struct Text *text, char add);
-int txt_add_raw_char (struct Text *text, char add);
-int txt_replace_char (struct Text *text, char add);
+int txt_add_char (struct Text *text, unsigned int add);
+int txt_add_raw_char (struct Text *text, unsigned int add);
+int txt_replace_char (struct Text *text, unsigned int add);
void txt_export_to_object(struct Text *text);
void txt_export_to_objects(struct Text *text);
void txt_unindent (struct Text *text);
@@ -127,34 +130,48 @@ int text_check_whitespace(char ch);
#define UNDO_SLEFT 005
#define UNDO_SRIGHT 006
#define UNDO_SUP 007
-#define UNDO_SDOWN 021
+#define UNDO_SDOWN 010
/* Complex movement (opcode is followed
* by 4 character line ID + a 2 character
* position ID and opcode (repeat)) */
-#define UNDO_CTO 022
-#define UNDO_STO 023
-
-/* Complex editing (opcode is followed
- * by 1 character ID and opcode (repeat)) */
-#define UNDO_INSERT 024
-#define UNDO_BS 025
-#define UNDO_DEL 026
+#define UNDO_CTO 011
+#define UNDO_STO 012
+
+/* Complex editing */
+/* 1 - opcode is followed by 1 byte for ascii character and opcode (repeat)) */
+/* 2 - opcode is followed by 2 bytes for utf-8 character and opcode (repeat)) */
+/* 3 - opcode is followed by 3 bytes for utf-8 character and opcode (repeat)) */
+/* 4 - opcode is followed by 4 bytes for unicode character and opcode (repeat)) */
+#define UNDO_INSERT_1 013
+#define UNDO_INSERT_2 014
+#define UNDO_INSERT_3 015
+#define UNDO_INSERT_4 016
+
+#define UNDO_BS_1 017
+#define UNDO_BS_2 020
+#define UNDO_BS_3 021
+#define UNDO_BS_4 022
+
+#define UNDO_DEL_1 023
+#define UNDO_DEL_2 024
+#define UNDO_DEL_3 025
+#define UNDO_DEL_4 026
/* Text block (opcode is followed
* by 4 character length ID + the text
* block itself + the 4 character length
* ID (repeat) and opcode (repeat)) */
-#define UNDO_DBLOCK 027 /* Delete block */
-#define UNDO_IBLOCK 030 /* Insert block */
+#define UNDO_DBLOCK 027 /* Delete block */
+#define UNDO_IBLOCK 030 /* Insert block */
/* Misc */
-#define UNDO_SWAP 031 /* Swap cursors */
+#define UNDO_SWAP 031 /* Swap cursors */
-#define UNDO_INDENT 032
-#define UNDO_UNINDENT 033
-#define UNDO_COMMENT 034
-#define UNDO_UNCOMMENT 035
+#define UNDO_INDENT 032
+#define UNDO_UNINDENT 033
+#define UNDO_COMMENT 034
+#define UNDO_UNCOMMENT 035
/* Marker flags */
#define TMARK_TEMP 0x01 /* Remove on non-editing events, don't save */
diff --git a/source/blender/blenkernel/BKE_utildefines.h b/source/blender/blenkernel/BKE_utildefines.h
index b5b3c7e67eb..a6a9bb0c0f6 100644
--- a/source/blender/blenkernel/BKE_utildefines.h
+++ b/source/blender/blenkernel/BKE_utildefines.h
@@ -43,9 +43,9 @@ extern "C" {
/* these values need to be hardcoded in structs, dna does not recognize defines */
/* also defined in DNA_space_types.h */
#ifndef FILE_MAXDIR
-#define FILE_MAXDIR 160
-#define FILE_MAXFILE 80
-#define FILE_MAX 240
+#define FILE_MAXDIR 768
+#define FILE_MAXFILE 256
+#define FILE_MAX 1024
#endif
/* this weirdo pops up in two places ... */
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 86530d18c9b..1d5bdb36de7 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -158,7 +158,6 @@ set(SRC
BKE_anim.h
BKE_animsys.h
BKE_armature.h
- BKE_array_mallocn.h
BKE_blender.h
BKE_bmesh.h
BKE_bmeshCustomData.h
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 0ff46045f78..b670a360a6a 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -2313,3 +2313,79 @@ static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm)
#endif /* WITH_GAMEENGINE */
/* --- NAVMESH (end) --- */
+
+
+/* derivedmesh info printing function,
+ * to help track down differences DM output */
+
+#ifndef NDEBUG
+#include "BLI_dynstr.h"
+
+static void dm_debug_info_layers(DynStr *dynstr, DerivedMesh *dm, void *(*getElemDataArray)(DerivedMesh *, int))
+{
+ int type;
+
+ for (type = 0; type < CD_NUMTYPES; type++) {
+ /* note: doesnt account for multiple layers */
+ void *pt = getElemDataArray(dm, type);
+ if (pt) {
+ const char *name = CustomData_layertype_name(type);
+ const int size = CustomData_sizeof(type);
+ const char *structname;
+ int structnum;
+ CustomData_file_write_info(type, &structname, &structnum);
+ BLI_dynstr_appendf(dynstr,
+ " dict(name='%s', struct='%s', type=%d, ptr='%p', elem=%d, length=%d),\n",
+ name, structname, type, (void *)pt, size, (int)(MEM_allocN_len(pt) / size));
+ }
+ }
+}
+
+char *DM_debug_info(DerivedMesh *dm)
+{
+ DynStr *dynstr= BLI_dynstr_new();
+ char *ret;
+ const char *tstr;
+
+ BLI_dynstr_appendf(dynstr, "{\n");
+ BLI_dynstr_appendf(dynstr, " 'ptr': '%p',\n", (void *)dm);
+ switch (dm->type) {
+ case DM_TYPE_CDDM: tstr = "DM_TYPE_CDDM"; break;
+ case DM_TYPE_EDITMESH: tstr = "DM_TYPE_EDITMESH"; break;
+ case DM_TYPE_CCGDM: tstr = "DM_TYPE_CCGDM"; break;
+ default: tstr = "UNKNOWN"; break;
+ }
+ BLI_dynstr_appendf(dynstr, " 'type': '%s',\n", tstr);
+ BLI_dynstr_appendf(dynstr, " 'numVertData': %d,\n", dm->numVertData);
+ BLI_dynstr_appendf(dynstr, " 'numEdgeData': %d,\n", dm->numEdgeData);
+ BLI_dynstr_appendf(dynstr, " 'numFaceData': %d,\n", dm->numFaceData);
+ BLI_dynstr_appendf(dynstr, " 'deformedOnly': %d,\n", dm->deformedOnly);
+
+ BLI_dynstr_appendf(dynstr, " 'vertexLayers': (\n");
+ dm_debug_info_layers(dynstr, dm, dm->getVertDataArray);
+ BLI_dynstr_appendf(dynstr, " ),\n");
+
+ BLI_dynstr_appendf(dynstr, " 'edgeLayers': (\n");
+ dm_debug_info_layers(dynstr, dm, dm->getEdgeDataArray);
+ BLI_dynstr_appendf(dynstr, " ),\n");
+
+ BLI_dynstr_appendf(dynstr, " 'faceLayers': (\n");
+ dm_debug_info_layers(dynstr, dm, dm->getFaceDataArray);
+ BLI_dynstr_appendf(dynstr, " ),\n");
+
+ BLI_dynstr_appendf(dynstr, "}\n");
+
+ ret = BLI_dynstr_get_cstring(dynstr);
+ BLI_dynstr_free(dynstr);
+ return ret;
+}
+
+void DM_debug_print(DerivedMesh *dm)
+{
+ char *str = DM_debug_info(dm);
+ printf("%s", str);
+ fflush(stdout);
+ MEM_freeN(str);
+}
+
+#endif /* NDEBUG */
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index ae04b7760c2..4f83bcf7e7f 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -590,7 +590,7 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest)
/* ************ Armature Deform ******************* */
typedef struct bPoseChanDeform {
- Mat4 *b_bone_mats;
+ Mat4 *b_bone_mats;
DualQuat *dual_quat;
DualQuat *b_bone_dual_quats;
} bPoseChanDeform;
@@ -1123,66 +1123,183 @@ void armature_loc_world_to_pose(Object *ob, float *inloc, float *outloc)
copy_v3_v3(outloc, nLocMat[3]);
}
-/* Convert Pose-Space Matrix to Bone-Space Matrix
- * NOTE: this cannot be used to convert to pose-space transforms of the supplied
- * pose-channel into its local space (i.e. 'visual'-keyframing)
+/* Construct the matrices (rot/scale and loc) to apply the PoseChannels into the armature (object) space.
+ * I.e. (roughly) the "pose_mat(b-1) * yoffs(b-1) * d_root(b) * bone_mat(b)" in the
+ * pose_mat(b)= pose_mat(b-1) * yoffs(b-1) * d_root(b) * bone_mat(b) * chan_mat(b)
+ * ...function.
+ *
+ * This allows to get the transformations of a bone in its object space, *before* constraints (and IK)
+ * get applied (used by pose evaluation code).
+ * And reverse: to find pchan transformations needed to place a bone at a given loc/rot/scale
+ * in object space (used by interactive transform, and snapping code).
+ *
+ * Note that, with the HINGE/NO_SCALE/NO_LOCAL_LOCATION options, the location matrix
+ * will differ from the rotation/scale matrix...
+ *
+ * NOTE: This cannot be used to convert to pose-space transforms of the supplied
+ * pose-channel into its local space (i.e. 'visual'-keyframing).
+ * (note: I don't understand that, so I keep it :p --mont29).
*/
-void armature_mat_pose_to_bone(bPoseChannel *pchan, float inmat[][4], float outmat[][4])
+void pchan_to_pose_mat(bPoseChannel *pchan, float rotscale_mat[][4], float loc_mat[][4])
{
- float pc_trans[4][4], inv_trans[4][4];
- float pc_posemat[4][4], inv_posemat[4][4];
- float pose_mat[4][4];
-
- /* paranoia: prevent crashes with no pose-channel supplied */
- if (pchan==NULL) return;
-
- /* default flag */
- if((pchan->bone->flag & BONE_NO_LOCAL_LOCATION)==0) {
- /* get the inverse matrix of the pchan's transforms */
- switch(pchan->rotmode) {
- case ROT_MODE_QUAT:
- loc_quat_size_to_mat4(pc_trans, pchan->loc, pchan->quat, pchan->size);
- break;
- case ROT_MODE_AXISANGLE:
- loc_axisangle_size_to_mat4(pc_trans, pchan->loc, pchan->rotAxis, pchan->rotAngle, pchan->size);
- break;
- default: /* euler */
- loc_eul_size_to_mat4(pc_trans, pchan->loc, pchan->eul, pchan->size);
+ Bone *bone, *parbone;
+ bPoseChannel *parchan;
+
+ /* set up variables for quicker access below */
+ bone= pchan->bone;
+ parbone= bone->parent;
+ parchan= pchan->parent;
+
+ if(parchan) {
+ float offs_bone[4][4]; /* yoffs(b-1) + root(b) + bonemat(b). */
+
+ /* Bone transform itself. */
+ copy_m4_m3(offs_bone, bone->bone_mat);
+
+ /* The bone's root offset (is in the parent's coordinate system). */
+ copy_v3_v3(offs_bone[3], bone->head);
+
+ /* Get the length translation of parent (length along y axis). */
+ offs_bone[3][1]+= parbone->length;
+
+ /* Compose the rotscale matrix for this bone. */
+ if((bone->flag & BONE_HINGE) && (bone->flag & BONE_NO_SCALE)) {
+ /* Parent rest rotation and scale. */
+ mult_m4_m4m4(rotscale_mat, parbone->arm_mat, offs_bone);
}
+ else if(bone->flag & BONE_HINGE) {
+ /* Parent rest rotation and pose scale. */
+ float tmat[4][4], tscale[3];
- copy_m4_m4(pose_mat, pchan->pose_mat);
- }
- else {
- /* local location, this is not default, different calculation
- * note: only tested for location with pose bone snapping.
- * If this is not useful in other cases the BONE_NO_LOCAL_LOCATION
- * case may have to be split into its own function. */
- unit_m4(pc_trans);
- copy_v3_v3(pc_trans[3], pchan->loc);
+ /* Extract the scale of the parent pose matrix. */
+ mat4_to_size(tscale, parchan->pose_mat);
+ size_to_mat4(tmat, tscale);
+
+ /* Applies the parent pose scale to the rest matrix. */
+ mult_m4_m4m4(tmat, tmat, parbone->arm_mat);
+
+ mult_m4_m4m4(rotscale_mat, tmat, offs_bone);
+ }
+ else if(bone->flag & BONE_NO_SCALE) {
+ /* Parent pose rotation and rest scale (i.e. no scaling). */
+ float tmat[4][4];
+ copy_m4_m4(tmat, parchan->pose_mat);
+ normalize_m4(tmat);
+ mult_m4_m4m4(rotscale_mat, tmat, offs_bone);
+ }
+ else
+ mult_m4_m4m4(rotscale_mat, parchan->pose_mat, offs_bone);
+
+# if 1
+ /* Compose the loc matrix for this bone. */
+ /* NOTE: That version deos not modify bone's loc when HINGE/NO_SCALE options are set. */
- /* use parents rotation/scale space + own absolute position */
- if(pchan->parent) copy_m4_m4(pose_mat, pchan->parent->pose_mat);
- else unit_m4(pose_mat);
+ /* In this case, use the object's space *orientation*. */
+ if(bone->flag & BONE_NO_LOCAL_LOCATION) {
+ /* XXX I'm sure that code can be simplified! */
+ float bone_loc[4][4], bone_rotscale[3][3], tmat4[4][4], tmat3[3][3];
+ unit_m4(bone_loc);
+ unit_m4(loc_mat);
+ unit_m4(tmat4);
+
+ mul_v3_m4v3(bone_loc[3], parchan->pose_mat, offs_bone[3]);
+
+ unit_m3(bone_rotscale);
+ copy_m3_m4(tmat3, parchan->pose_mat);
+ mul_m3_m3m3(bone_rotscale, tmat3, bone_rotscale);
+
+ copy_m4_m3(tmat4, bone_rotscale);
+ mult_m4_m4m4(loc_mat, bone_loc, tmat4);
+ }
+ /* Those flags do not affect position, use plain parent transform space! */
+ else if(bone->flag & (BONE_HINGE|BONE_NO_SCALE)) {
+ mult_m4_m4m4(loc_mat, parchan->pose_mat, offs_bone);
+ }
+ /* Else (i.e. default, usual case), just use the same matrix for rotation/scaling, and location. */
+ else
+ copy_m4_m4(loc_mat, rotscale_mat);
+# endif
+# if 0
+ /* Compose the loc matrix for this bone. */
+ /* NOTE: That version modifies bone's loc when HINGE/NO_SCALE options are set. */
+
+ /* In these cases we need to compute location separately */
+ if(bone->flag & (BONE_HINGE|BONE_NO_SCALE|BONE_NO_LOCAL_LOCATION)) {
+ float bone_loc[4][4], bone_rotscale[3][3], tmat4[4][4], tmat3[3][3];
+ unit_m4(bone_loc);
+ unit_m4(loc_mat);
+ unit_m4(tmat4);
+
+ mul_v3_m4v3(bone_loc[3], parchan->pose_mat, offs_bone[3]);
+
+ /* "No local location" is not transformed by bone matrix. */
+ /* This only affects orientations (rotations), as scale is always 1.0 here. */
+ if(bone->flag & BONE_NO_LOCAL_LOCATION)
+ unit_m3(bone_rotscale);
+ else
+ /* We could also use bone->bone_mat directly, here... */
+ copy_m3_m4(bone_rotscale, offs_bone);
+
+ if(bone->flag & BONE_HINGE) {
+ copy_m3_m4(tmat3, parbone->arm_mat);
+ /* for hinge-only, we use armature *rotation*, but pose mat *scale*! */
+ if(!(bone->flag & BONE_NO_SCALE)) {
+ float size[3], tsmat[3][3];
+ mat4_to_size(size, parchan->pose_mat);
+ size_to_mat3(tsmat, size);
+ mul_m3_m3m3(tmat3, tsmat, tmat3);
+ }
+ mul_m3_m3m3(bone_rotscale, tmat3, bone_rotscale);
+ }
+ else if(bone->flag & BONE_NO_SCALE) {
+ /* For no-scale only, normalized parent pose mat is enough! */
+ copy_m3_m4(tmat3, parchan->pose_mat);
+ normalize_m3(tmat3);
+ mul_m3_m3m3(bone_rotscale, tmat3, bone_rotscale);
+ }
+ /* NO_LOCAL_LOCATION only. */
+ else {
+ copy_m3_m4(tmat3, parchan->pose_mat);
+ mul_m3_m3m3(bone_rotscale, tmat3, bone_rotscale);
+ }
- copy_v3_v3(pose_mat[3], pchan->pose_mat[3]);
+ copy_m4_m3(tmat4, bone_rotscale);
+ mult_m4_m4m4(loc_mat, bone_loc, tmat4);
+ }
+ /* Else, just use the same matrix for rotation/scaling, and location. */
+ else
+ copy_m4_m4(loc_mat, rotscale_mat);
+# endif
}
+ /* Root bones. */
+ else {
+ /* Rotation/scaling. */
+ copy_m4_m4(rotscale_mat, pchan->bone->arm_mat);
+ /* Translation. */
+ if(pchan->bone->flag & BONE_NO_LOCAL_LOCATION) {
+ /* Translation of arm_mat, without the rotation. */
+ unit_m4(loc_mat);
+ copy_v3_v3(loc_mat[3], pchan->bone->arm_mat[3]);
+ }
+ else
+ copy_m4_m4(loc_mat, rotscale_mat);
+ }
+}
+
+/* Convert Pose-Space Matrix to Bone-Space Matrix.
+ * NOTE: this cannot be used to convert to pose-space transforms of the supplied
+ * pose-channel into its local space (i.e. 'visual'-keyframing)
+ */
+void armature_mat_pose_to_bone(bPoseChannel *pchan, float inmat[][4], float outmat[][4])
+{
+ float rotscale_mat[4][4], loc_mat[4][4];
+ pchan_to_pose_mat(pchan, rotscale_mat, loc_mat);
+ invert_m4(rotscale_mat);
+ invert_m4(loc_mat);
- invert_m4_m4(inv_trans, pc_trans);
-
- /* Remove the pchan's transforms from it's pose_mat.
- * This should leave behind the effects of restpose +
- * parenting + constraints
- */
- mult_m4_m4m4(pc_posemat, pose_mat, inv_trans);
-
- /* get the inverse of the leftovers so that we can remove
- * that component from the supplied matrix
- */
- invert_m4_m4(inv_posemat, pc_posemat);
-
- /* get the new matrix */
- mult_m4_m4m4(outmat, inv_posemat, inmat);
+ mult_m4_m4m4(outmat, rotscale_mat, inmat);
+ mul_v3_m4v3(outmat[3], loc_mat, inmat[3]);
}
/* Convert Pose-Space Location to Bone-Space Location
@@ -2263,98 +2380,30 @@ void where_is_pose_bone_tail(bPoseChannel *pchan)
*/
void where_is_pose_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float ctime, int do_extra)
{
- Bone *bone, *parbone;
- bPoseChannel *parchan;
- float vec[3];
-
- /* set up variables for quicker access below */
- bone= pchan->bone;
- parbone= bone->parent;
- parchan= pchan->parent;
-
- /* this gives a chan_mat with actions (ipos) results */
- if(do_extra) pchan_calc_mat(pchan);
- else unit_m4(pchan->chan_mat);
+ /* This gives a chan_mat with actions (ipos) results. */
+ if(do_extra)
+ pchan_calc_mat(pchan);
+ else
+ unit_m4(pchan->chan_mat);
- /* construct the posemat based on PoseChannels, that we do before applying constraints */
+ /* Construct the posemat based on PoseChannels, that we do before applying constraints. */
/* pose_mat(b)= pose_mat(b-1) * yoffs(b-1) * d_root(b) * bone_mat(b) * chan_mat(b) */
-
- if(parchan) {
- float offs_bone[4][4]; // yoffs(b-1) + root(b) + bonemat(b)
-
- /* bone transform itself */
- copy_m4_m3(offs_bone, bone->bone_mat);
-
- /* The bone's root offset (is in the parent's coordinate system) */
- copy_v3_v3(offs_bone[3], bone->head);
-
- /* Get the length translation of parent (length along y axis) */
- offs_bone[3][1]+= parbone->length;
-
- /* Compose the matrix for this bone */
- if((bone->flag & BONE_HINGE) && (bone->flag & BONE_NO_SCALE)) { // uses restposition rotation, but actual position
- float tmat[4][4];
- /* the rotation of the parent restposition */
- copy_m4_m4(tmat, parbone->arm_mat);
- mul_serie_m4(pchan->pose_mat, tmat, offs_bone, pchan->chan_mat, NULL, NULL, NULL, NULL, NULL);
- }
- else if(bone->flag & BONE_HINGE) { // same as above but apply parent scale
- float tmat[4][4];
-
- /* apply the parent matrix scale */
- float tsmat[4][4], tscale[3];
-
- /* the rotation of the parent restposition */
- copy_m4_m4(tmat, parbone->arm_mat);
-
- /* extract the scale of the parent matrix */
- mat4_to_size(tscale, parchan->pose_mat);
- size_to_mat4(tsmat, tscale);
- mult_m4_m4m4(tmat, tsmat, tmat);
-
- mul_serie_m4(pchan->pose_mat, tmat, offs_bone, pchan->chan_mat, NULL, NULL, NULL, NULL, NULL);
- }
- else if(bone->flag & BONE_NO_SCALE) {
- float orthmat[4][4];
-
- /* do transform, with an ortho-parent matrix */
- copy_m4_m4(orthmat, parchan->pose_mat);
- normalize_m4(orthmat);
- mul_serie_m4(pchan->pose_mat, orthmat, offs_bone, pchan->chan_mat, NULL, NULL, NULL, NULL, NULL);
- }
- else
- mul_serie_m4(pchan->pose_mat, parchan->pose_mat, offs_bone, pchan->chan_mat, NULL, NULL, NULL, NULL, NULL);
-
- /* in these cases we need to compute location separately */
- if(bone->flag & (BONE_HINGE|BONE_NO_SCALE|BONE_NO_LOCAL_LOCATION)) {
- float bone_loc[3], chan_loc[3];
-
- mul_v3_m4v3(bone_loc, parchan->pose_mat, offs_bone[3]);
- copy_v3_v3(chan_loc, pchan->chan_mat[3]);
-
- /* no local location is not transformed by bone matrix */
- if(!(bone->flag & BONE_NO_LOCAL_LOCATION))
- mul_mat3_m4_v3(offs_bone, chan_loc);
-
- /* for hinge we use armature instead of pose mat */
- if(bone->flag & BONE_HINGE) mul_mat3_m4_v3(parbone->arm_mat, chan_loc);
- else mul_mat3_m4_v3(parchan->pose_mat, chan_loc);
-
- add_v3_v3v3(pchan->pose_mat[3], bone_loc, chan_loc);
- }
- }
- else {
- mult_m4_m4m4(pchan->pose_mat, bone->arm_mat, pchan->chan_mat);
-
- /* optional location without arm_mat rotation */
- if(bone->flag & BONE_NO_LOCAL_LOCATION)
- add_v3_v3v3(pchan->pose_mat[3], bone->arm_mat[3], pchan->chan_mat[3]);
-
- /* only rootbones get the cyclic offset (unless user doesn't want that) */
- if ((bone->flag & BONE_NO_CYCLICOFFSET) == 0)
+ {
+ float rotscale_mat[4][4], loc_mat[4][4];
+ pchan_to_pose_mat(pchan, rotscale_mat, loc_mat);
+ /* Rotation and scale. */
+ mult_m4_m4m4(pchan->pose_mat, rotscale_mat, pchan->chan_mat);
+ /* Location. */
+ mul_v3_m4v3(pchan->pose_mat[3], loc_mat, pchan->chan_mat[3]);
+ }
+
+ /* Only rootbones get the cyclic offset (unless user doesn't want that). */
+ /* XXX That could be a problem for snapping and other "reverse transform" features... */
+ if(!pchan->parent) {
+ if((pchan->bone->flag & BONE_NO_CYCLICOFFSET) == 0)
add_v3_v3(pchan->pose_mat[3], ob->pose->cyclic_offset);
}
-
+
if(do_extra) {
#if 0 /* XXX OLD ANIMSYS, NLASTRIPS ARE NO LONGER USED */
@@ -2365,6 +2414,7 @@ void where_is_pose_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float cti
/* Do constraints */
if (pchan->constraints.first) {
bConstraintOb *cob;
+ float vec[3];
/* make a copy of location of PoseChannel for later */
copy_v3_v3(vec, pchan->pose_mat[3]);
@@ -2388,7 +2438,7 @@ void where_is_pose_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float cti
}
}
}
-
+
/* calculate head */
copy_v3_v3(pchan->pose_head, pchan->pose_mat[3]);
/* calculate tail */
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 362fa6e5e9a..f2514c1030b 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -527,7 +527,7 @@ void brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall,
float xy[2], rgba[4], *dstf;
int x, y, rowbytes, xoff, yoff, imbflag;
const int radius= brush_size(scene, brush);
- char *dst, crgb[3];
+ unsigned char *dst, crgb[3];
const float alpha= brush_alpha(scene, brush);
float brush_rgb[3];
@@ -571,10 +571,10 @@ void brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall,
}
else {
float alpha_f; /* final float alpha to convert to char */
- F3TOCHAR3(brush->rgb, crgb);
+ rgb_float_to_uchar(crgb, brush->rgb);
for (y=0; y < ibuf->y; y++) {
- dst = (char*)ibuf->rect + y*rowbytes;
+ dst = (unsigned char *)ibuf->rect + y*rowbytes;
for (x=0; x < ibuf->x; x++, dst+=4) {
xy[0] = x + xoff;
@@ -590,19 +590,15 @@ void brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall,
}
else if (texfall == 1) {
brush_sample_tex(scene, brush, xy, rgba, 0);
- dst[0] = FTOCHAR(rgba[0]);
- dst[1] = FTOCHAR(rgba[1]);
- dst[2] = FTOCHAR(rgba[2]);
- dst[3] = FTOCHAR(rgba[3]);
+ rgba_float_to_uchar(dst, rgba);
}
else if (texfall == 2) {
brush_sample_tex(scene, brush, xy, rgba, 0);
mul_v3_v3(rgba, brush->rgb);
alpha_f = rgba[3] * alpha * brush_curve_strength_clamp(brush, len_v2(xy), radius);
- dst[0] = FTOCHAR(rgba[0]);
- dst[1] = FTOCHAR(rgba[1]);
- dst[2] = FTOCHAR(rgba[2]);
+ rgb_float_to_uchar(dst, rgba);
+
dst[3] = FTOCHAR(alpha_f);
}
else {
@@ -843,7 +839,7 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf, i
Brush *brush= painter->brush;
ImBuf *ibuf, *maskibuf, *texibuf;
float *bf, *mf, *tf, *otf=NULL, xoff, yoff, xy[2], rgba[4];
- char *b, *m, *t, *ot= NULL;
+ unsigned char *b, *m, *t, *ot= NULL;
int dotexold, origx= x, origy= y;
const int radius= brush_size(painter->scene, brush);
@@ -895,12 +891,12 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf, i
}
else {
for (; y < h; y++) {
- b = (char*)ibuf->rect + (y*ibuf->x + origx)*4;
- t = (char*)texibuf->rect + (y*texibuf->x + origx)*4;
- m = (char*)maskibuf->rect + (y*maskibuf->x + origx)*4;
+ b = (unsigned char *)ibuf->rect + (y*ibuf->x + origx)*4;
+ t = (unsigned char *)texibuf->rect + (y*texibuf->x + origx)*4;
+ m = (unsigned char *)maskibuf->rect + (y*maskibuf->x + origx)*4;
if (dotexold)
- ot = (char*)oldtexibuf->rect + ((y - origy + yt)*oldtexibuf->x + xt)*4;
+ ot = (unsigned char *)oldtexibuf->rect + ((y - origy + yt)*oldtexibuf->x + xt)*4;
for (x=origx; x < w; x++, b+=4, m+=4, t+=4) {
if (dotexold) {
@@ -915,10 +911,7 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf, i
xy[1] = y + yoff;
brush_sample_tex(scene, brush, xy, rgba, 0);
- t[0]= FTOCHAR(rgba[0]);
- t[1]= FTOCHAR(rgba[1]);
- t[2]= FTOCHAR(rgba[2]);
- t[3]= FTOCHAR(rgba[3]);
+ rgba_float_to_uchar(t, rgba);
}
b[0] = t[0]*m[0]/255;
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 77a4a6a429c..2bda3066af0 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -2775,13 +2775,14 @@ static void stretchto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *
/* store Z orientation before destroying obmat */
normalize_v3_v3(zz, cob->matrix[2]);
- sub_v3_v3v3(vec, cob->matrix[3], ct->matrix[3]);
- vec[0] /= size[0];
- vec[1] /= size[1];
- vec[2] /= size[2];
-
- dist = normalize_v3(vec);
- //dist = len_v3v3( ob->obmat[3], targetmat[3]);
+ dist = len_v3v3(cob->matrix[3], ct->matrix[3]);
+ /* XXX What was all that for??? Makes the constraint buggy with scaled objects, see #29940. */
+/* sub_v3_v3v3(vec, cob->matrix[3], ct->matrix[3]);*/
+/* vec[0] /= size[0];*/
+/* vec[1] /= size[1];*/
+/* vec[2] /= size[2];*/
+
+/* dist = normalize_v3(vec);*/
/* data->orglength==0 occurs on first run, and after 'R' button is clicked */
if (data->orglength == 0)
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index 0f1c73c59c1..6536dfb529e 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -368,9 +368,8 @@ void tex_space_curve(Curve *cu)
dl= cu->disp.first;
while(dl) {
- if(dl->type==DL_INDEX3 || dl->type==DL_INDEX3) tot= dl->nr;
- else tot= dl->nr*dl->parts;
-
+ tot = ELEM(dl->type, DL_INDEX3, DL_INDEX4) ? dl->nr : dl->nr * dl->parts;
+
if(tot) doit= 1;
fp= dl->verts;
while(tot--) {
diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c
index f93aee80ab8..6a2207d455c 100644
--- a/source/blender/blenkernel/intern/dynamicpaint.c
+++ b/source/blender/blenkernel/intern/dynamicpaint.c
@@ -101,9 +101,10 @@ static int neighY[8] = {0,1,1, 1, 0,-1,-1,-1};
#define EFF_MOVEMENT_PER_FRAME 0.05f
/* initial wave time factor */
#define WAVE_TIME_FAC (1.0f/24.f)
-#define WAVE_INIT_SIZE 5.0f
+#define CANVAS_REL_SIZE 5.0f
/* drying limits */
#define MIN_WETNESS 0.001f
+#define MAX_WETNESS 5.0f
/* dissolve macro */
#define VALUE_DISSOLVE(VALUE, TIME, SCALE, LOG) (VALUE) = (LOG) ? (VALUE) * (pow(MIN_WETNESS,1.0f/(1.2f*((float)(TIME))/(SCALE)))) : (VALUE) - 1.0f/(TIME)*(SCALE)
@@ -187,11 +188,12 @@ typedef struct ImgSeqFormatData {
Vec3f *barycentricWeights; /* b-weights for all pixel samples */
} ImgSeqFormatData;
+#if 0 /* UNUSED */
typedef struct EffVelPoint {
float previous_pos[3];
float previous_vel[3];
} EffVelPoint;
-
+#endif
/* adjacency data flags */
#define ADJ_ON_MESH_EDGE (1<<0)
@@ -422,15 +424,31 @@ static void blendColors(float t_color[3], float t_alpha, float s_color[3], float
result[3] = f_alpha;
}
-/* assumes source alpha > 0.0f or results NaN colors */
-static void mixColors(float *t_color, float t_alpha, float *s_color, float s_alpha)
+/* Mix two alpha weighed colors by a defined ratio. output is saved at a_color */
+static float mixColors(float a_color[3], float a_weight, float b_color[3], float b_weight, float ratio)
{
- float factor = (s_alpha<t_alpha) ? 1.0f : t_alpha/s_alpha;
+ float weight_ratio, factor;
+ if (b_weight) {
+ /* if first value has no weight just use b_color */
+ if (!a_weight) {
+ copy_v3_v3(a_color, b_color);
+ return b_weight*ratio;
+ }
+ weight_ratio = b_weight/(a_weight+b_weight);
+ }
+ else return a_weight*(1.0f-ratio);
- /* set initial color depending on existing alpha */
- interp_v3_v3v3(t_color, s_color, t_color, factor);
+ /* calculate final interpolation factor */
+ if (ratio<=0.5f) {
+ factor = weight_ratio*(ratio*2.0f);
+ }
+ else {
+ ratio = (ratio*2.0f - 1.0f);
+ factor = weight_ratio*(1.0f-ratio) + ratio;
+ }
/* mix final color */
- interp_v3_v3v3(t_color, t_color, s_color, s_alpha);
+ interp_v3_v3v3(a_color, a_color, b_color, factor);
+ return (1.0f-factor)*a_weight + factor*b_weight;
}
/* set "ignore cache" flag for all caches on this object */
@@ -617,6 +635,12 @@ static void boundInsert(Bounds3D *b, float point[3])
}
}
+float getSurfaceDimension(PaintSurfaceData *sData)
+{
+ Bounds3D *mb = &sData->bData->mesh_bounds;
+ return MAX3((mb->max[0]-mb->min[0]), (mb->max[1]-mb->min[1]), (mb->max[2]-mb->min[2]));
+}
+
static void freeGrid(PaintSurfaceData *data)
{
PaintBakeData *bData = data->bData;
@@ -959,17 +983,21 @@ struct DynamicPaintSurface *dynamicPaint_createNewSurface(DynamicPaintCanvasSett
/* Set initial values */
surface->flags = MOD_DPAINT_ANTIALIAS | MOD_DPAINT_MULALPHA | MOD_DPAINT_DRY_LOG | MOD_DPAINT_DISSOLVE_LOG |
- MOD_DPAINT_ACTIVE | MOD_DPAINT_PREVIEW | MOD_DPAINT_OUT1;
+ MOD_DPAINT_ACTIVE | MOD_DPAINT_PREVIEW | MOD_DPAINT_OUT1 | MOD_DPAINT_USE_DRYING;
surface->effect = 0;
surface->effect_ui = 1;
surface->diss_speed = 250;
surface->dry_speed = 500;
+ surface->color_dry_threshold = 1.0f;
surface->depth_clamp = 0.0f;
surface->disp_factor = 1.0f;
surface->disp_type = MOD_DPAINT_DISP_DISPLACE;
surface->image_fileformat = MOD_DPAINT_IMGFORMAT_PNG;
+ surface->influence_scale = 1.0f;
+ surface->radius_scale = 1.0f;
+
surface->init_color[0] = 1.0f;
surface->init_color[1] = 1.0f;
surface->init_color[2] = 1.0f;
@@ -1508,7 +1536,7 @@ static int dynamicPaint_checkSurfaceData(DynamicPaintSurface *surface)
/* apply displacing vertex surface to the derived mesh */
-static void dynamicPaint_applySurfaceDisplace(DynamicPaintSurface *surface, DerivedMesh *result, int update_normals)
+static void dynamicPaint_applySurfaceDisplace(DynamicPaintSurface *surface, DerivedMesh *result)
{
PaintSurfaceData *sData = surface->data;
@@ -1531,10 +1559,6 @@ static void dynamicPaint_applySurfaceDisplace(DynamicPaintSurface *surface, Deri
mvert[i].co[2] -= normal[2]*val;
}
}
- else return;
-
- if (update_normals)
- CDDM_calc_normals(result);
}
/*
@@ -1549,6 +1573,7 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData
if(pmd->canvas && !(pmd->canvas->flags & MOD_DPAINT_BAKING)) {
DynamicPaintSurface *surface = pmd->canvas->surfaces.first;
+ int update_normals = 0;
pmd->canvas->flags &= ~MOD_DPAINT_PREVIEW_READY;
/* loop through surfaces */
@@ -1589,11 +1614,11 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData
if (col) {
#pragma omp parallel for schedule(static)
for (i=0; i<numOfFaces; i++) {
- int j=0;
+ int j = (mface[i].v4) ? 4 : 3;
Material *material = give_current_material(ob, mface[i].mat_nr+1);
- for (; j<((mface[i].v4)?4:3); j++) {
- int index = (j==0)?mface[i].v1: (j==1)?mface[i].v2: (j==2)?mface[i].v3: mface[i].v4;
+ while (j--) {
+ int index = *((&mface[i].v1)+j);
if (surface->preview_id == MOD_DPAINT_SURFACE_PREV_PAINT) {
float c[3];
@@ -1642,9 +1667,9 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData
if (col) {
#pragma omp parallel for schedule(static)
for (i=0; i<numOfFaces; i++) {
- int j=0;
- for (; j<((mface[i].v4)?4:3); j++) {
- int index = (j==0)?mface[i].v1: (j==1)?mface[i].v2: (j==2)?mface[i].v3: mface[i].v4;
+ int j = (mface[i].v4) ? 4 : 3;
+ while (j--) {
+ int index = *((&mface[i].v1)+j);
index *= 4;
col[i*4+j].a = FTOCHAR(fcolor[index+3]);
@@ -1666,10 +1691,9 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData
if (col) {
#pragma omp parallel for schedule(static)
for (i=0; i<numOfFaces; i++) {
- int j=0;
-
- for (; j<((mface[i].v4)?4:3); j++) {
- int index = (j==0)?mface[i].v1: (j==1)?mface[i].v2: (j==2)?mface[i].v3: mface[i].v4;
+ int j = (mface[i].v4) ? 4 : 3;
+ while (j--) {
+ int index = *((&mface[i].v1)+j);
col[i*4+j].a = 255;
col[i*4+j].r =
col[i*4+j].g =
@@ -1697,9 +1721,9 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData
#pragma omp parallel for schedule(static)
for (i=0; i<numOfFaces; i++) {
float temp_color[3];
- int j=0;
- for (; j<((mface[i].v4)?4:3); j++) {
- int index = (j==0)?mface[i].v1: (j==1)?mface[i].v2: (j==2)?mface[i].v3: mface[i].v4;
+ int j = (mface[i].v4) ? 4 : 3;
+ while (j--) {
+ int index = *((&mface[i].v1)+j);
weight_to_rgb(temp_color, weight[index]);
col[i*4+j].r = FTOCHAR(temp_color[2]);
@@ -1748,14 +1772,20 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData
normal_short_to_float_v3(normal, mvert[i].no);
madd_v3_v3fl(mvert[i].co, normal, wPoint[i].height);
}
- CDDM_calc_normals(result);
+ update_normals = 1;
}
/* displace */
- dynamicPaint_applySurfaceDisplace(surface, result, 1);
+ if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE) {
+ dynamicPaint_applySurfaceDisplace(surface, result);
+ update_normals = 1;
+ }
}
}
}
+
+ if (update_normals)
+ CDDM_calc_normals(result);
}
/* make a copy of dm to use as brush data */
if (pmd->brush) {
@@ -2574,14 +2604,8 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char* filenam
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) {
PaintPoint *point = &((PaintPoint*)sData->type_data)[index];
- ibuf->rect_float[pos] = point->color[0];
- ibuf->rect_float[pos+1] = point->color[1];
- ibuf->rect_float[pos+2] = point->color[2];
- /* mix wet layer */
- if (point->e_alpha) mixColors(&ibuf->rect_float[pos], point->alpha, point->e_color, point->e_alpha);
-
- /* use highest alpha */
- ibuf->rect_float[pos+3] = (point->e_alpha > point->alpha) ? point->e_alpha : point->alpha;
+ /* blend wet and dry layers */
+ blendColors(point->color, point->alpha, point->e_color, point->e_alpha, &ibuf->rect_float[pos]);
/* Multiply color by alpha if enabled */
if (surface->flags & MOD_DPAINT_MULALPHA) {
@@ -2912,7 +2936,13 @@ static void dynamicPaint_updatePointData(DynamicPaintSurface *surface, unsigned
float paint[3], float influence, float depth, float vel_factor, float timescale)
{
PaintSurfaceData *sData = surface->data;
- float strength = influence * brush->alpha;
+ float strength;
+
+ /* apply influence scale */
+ influence *= surface->influence_scale;
+ depth *= surface->influence_scale;
+
+ strength = influence * brush->alpha;
CLAMP(strength, 0.0f, 1.0f);
/* Sample velocity colorband if required */
@@ -2991,12 +3021,12 @@ static void dynamicPaint_updatePointData(DynamicPaintSurface *surface, unsigned
}
/* checks whether surface and brush bounds intersect depending on brush type */
-static int meshBrush_boundsIntersect(Bounds3D *b1, Bounds3D *b2, DynamicPaintBrushSettings *brush)
+static int meshBrush_boundsIntersect(Bounds3D *b1, Bounds3D *b2, DynamicPaintBrushSettings *brush, float brush_radius)
{
if (brush->collision == MOD_DPAINT_COL_VOLUME)
return boundsIntersect(b1, b2);
else if (brush->collision == MOD_DPAINT_COL_DIST || brush->collision == MOD_DPAINT_COL_VOLDIST)
- return boundsIntersectDist(b1, b2, brush->paint_distance);
+ return boundsIntersectDist(b1, b2, brush_radius);
else return 1;
}
@@ -3123,6 +3153,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
{
BVHTreeFromMesh treeData = {0};
float avg_brushNor[3] = {0.0f};
+ float brush_radius = brush->paint_distance * surface->radius_scale;
int numOfVerts;
int ii;
Bounds3D mesh_bb = {0};
@@ -3141,7 +3172,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
boundInsert(&mesh_bb, mvert[ii].co);
/* for project brush calculate average normal */
- if (brush->collision & MOD_DPAINT_COL_DIST && brush->flags & MOD_DPAINT_PROX_PROJECT) {
+ if (brush->flags & MOD_DPAINT_PROX_PROJECT) {
float nor[3];
normal_short_to_float_v3(nor, mvert[ii].no);
mul_mat3_m4_v3(brushOb->obmat, nor);
@@ -3151,7 +3182,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
}
}
- if (brush->collision & MOD_DPAINT_COL_DIST && brush->flags & MOD_DPAINT_PROX_PROJECT) {
+ if (brush->flags & MOD_DPAINT_PROX_PROJECT) {
mul_v3_fl(avg_brushNor, 1.0f/(float)numOfVerts);
/* instead of null vector use positive z */
if (!(MIN3(avg_brushNor[0],avg_brushNor[1],avg_brushNor[2])))
@@ -3161,7 +3192,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
}
/* check bounding box collision */
- if(grid && meshBrush_boundsIntersect(&grid->grid_bounds, &mesh_bb, brush))
+ if(grid && meshBrush_boundsIntersect(&grid->grid_bounds, &mesh_bb, brush, brush_radius))
/* Build a bvh tree from transformed vertices */
if (bvhtree_from_mesh_faces(&treeData, dm, 0.0f, 4, 8))
{
@@ -3173,7 +3204,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
int id;
/* check grid cell bounding box */
- if (!grid->s_num[c_index] || !meshBrush_boundsIntersect(&grid->bounds[c_index], &mesh_bb, brush))
+ if (!grid->s_num[c_index] || !meshBrush_boundsIntersect(&grid->bounds[c_index], &mesh_bb, brush, brush_radius))
continue;
/* loop through cell points and process brush */
@@ -3234,7 +3265,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
hit.index = -1;
hit.dist = 9999;
nearest.index = -1;
- nearest.dist = brush->paint_distance * brush->paint_distance; /* find_nearest uses squared distance */
+ nearest.dist = brush_radius * brush_radius; /* find_nearest uses squared distance */
/* Check volume collision */
if (brush->collision == MOD_DPAINT_COL_VOLUME || brush->collision == MOD_DPAINT_COL_VOLDIST)
@@ -3292,9 +3323,9 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
if (inner_proximity && !hit_found) continue;
/* If pure distance proximity, find the nearest point on the mesh */
- if (brush->collision != MOD_DPAINT_COL_DIST || !(brush->flags & MOD_DPAINT_PROX_PROJECT)) {
+ if (!(brush->flags & MOD_DPAINT_PROX_PROJECT)) {
if (BLI_bvhtree_find_nearest(treeData.tree, ray_start, &nearest, mesh_faces_nearest_point_dp, &treeData) != -1) {
- proxDist = sqrt(nearest.dist);
+ proxDist = sqrtf(nearest.dist);
copy_v3_v3(hitCo, nearest.co);
hQuad = (nearest.no[0] == 1.0f);
face = nearest.index;
@@ -3314,7 +3345,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
proj_ray[2] = 1.0f;
}
hit.index = -1;
- hit.dist = brush->paint_distance;
+ hit.dist = brush_radius;
/* Do a face normal directional raycast, and use that distance */
if(BLI_bvhtree_ray_cast(treeData.tree, ray_start, proj_ray, 0.0f, &hit, mesh_faces_spherecast_dp, &treeData) != -1)
@@ -3327,8 +3358,8 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
}
/* If a hit was found, calculate required values */
- if (proxDist >= 0.0f && proxDist <= brush->paint_distance) {
- proximity_factor = proxDist / brush->paint_distance;
+ if (proxDist >= 0.0f && proxDist <= brush_radius) {
+ proximity_factor = proxDist / brush_radius;
CLAMP(proximity_factor, 0.0f, 1.0f);
if (!inner_proximity)
proximity_factor = 1.0f - proximity_factor;
@@ -3514,8 +3545,8 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface,
int invalidParticles = 0;
int p = 0;
- float solidradius = (brush->flags & MOD_DPAINT_PART_RAD) ? psys->part->size : brush->particle_radius;
- float smooth = brush->particle_smooth;
+ float solidradius = surface->radius_scale*((brush->flags & MOD_DPAINT_PART_RAD) ? psys->part->size : brush->particle_radius);
+ float smooth = brush->particle_smooth*surface->radius_scale;
float range = solidradius + smooth;
float particle_timestep = 0.04f * part->timetweak;
@@ -3744,6 +3775,7 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po
Object *brushOb, BrushMaterials *bMats, Scene *scene, float timescale)
{
int index;
+ float brush_radius = brush->paint_distance * surface->radius_scale;
PaintSurfaceData *sData = surface->data;
PaintBakeData *bData = sData->bData;
Vec3f brushVel;
@@ -3761,13 +3793,13 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po
float colorband[4] = {0.0f};
float strength;
- if (distance>brush->paint_distance) continue;
+ if (distance > brush_radius) continue;
/* Smooth range or color ramp */
if (brush->proximity_falloff == MOD_DPAINT_PRFALL_SMOOTH ||
brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP) {
- strength = 1.0f - distance / brush->paint_distance;
+ strength = 1.0f - distance / brush_radius;
CLAMP(strength, 0.0f, 1.0f);
}
else strength = 1.0f;
@@ -3832,8 +3864,8 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po
else if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE ||
surface->type == MOD_DPAINT_SURFACE_T_WAVE) {
/* get displace depth */
- float disp_intersect = (1.0f - sqrtf((brush->paint_distance-distance) / brush->paint_distance)) * brush->paint_distance;
- depth = (brush->paint_distance - disp_intersect) / bData->bNormal[index].normal_scale;
+ float disp_intersect = (1.0f - sqrtf((brush_radius-distance) / brush_radius)) * brush_radius;
+ depth = (brush_radius - disp_intersect) / bData->bNormal[index].normal_scale;
if (depth<0.0f) depth = 0.0f;
}
dynamicPaint_updatePointData(surface, index, brush, paintColor, strength, depth, velocity_val, timescale);
@@ -3936,7 +3968,7 @@ void surface_determineForceTargetPoints(PaintSurfaceData *sData, int index, floa
if (closest_id[1] != -1) {
float force_proj[3];
float tangent[3];
- float neigh_diff = acos(dot_v3v3(bNeighs[closest_id[0]].dir, bNeighs[closest_id[1]].dir));
+ float neigh_diff = acosf(dot_v3v3(bNeighs[closest_id[0]].dir, bNeighs[closest_id[1]].dir));
float force_intersect;
float temp;
@@ -4008,7 +4040,6 @@ static void dynamicPaint_doSmudge(DynamicPaintSurface *surface, DynamicPaintBrus
if (n_index != -1 && closest_d[i]>0.0f) {
float dir_dot = closest_d[i], dir_factor;
float speed_scale = eff_scale*smudge_str/bNeighs[n_index].dist;
- float mix;
PaintPoint *ePoint = &((PaintPoint*)sData->type_data)[sData->adj_data->n_target[n_index]];
/* just skip if angle is too extreme */
@@ -4018,13 +4049,11 @@ static void dynamicPaint_doSmudge(DynamicPaintSurface *surface, DynamicPaintBrus
if (dir_factor > brush->smudge_strength) dir_factor = brush->smudge_strength;
/* mix new color and alpha */
- mix = dir_factor*pPoint->alpha;
- if (mix) mixColors(ePoint->color, ePoint->alpha, pPoint->color, mix);
+ mixColors(ePoint->color, ePoint->alpha, pPoint->color, pPoint->alpha, dir_factor);
ePoint->alpha = ePoint->alpha*(1.0f-dir_factor) + pPoint->alpha*dir_factor;
/* smudge "wet layer" */
- mix = dir_factor*pPoint->e_alpha;
- if (mix) mixColors(ePoint->e_color, ePoint->e_alpha, pPoint->e_color, mix);
+ mixColors(ePoint->e_color, ePoint->e_alpha, pPoint->e_color, pPoint->e_alpha, dir_factor);
ePoint->e_alpha = ePoint->e_alpha*(1.0f-dir_factor) + pPoint->e_alpha*dir_factor;
pPoint->wetness *= (1.0f-dir_factor);
}
@@ -4041,7 +4070,7 @@ static int dynamicPaint_prepareEffectStep(DynamicPaintSurface *surface, Scene *s
{
double average_force = 0.0f;
float shrink_speed=0.0f, spread_speed=0.0f;
- float fastest_effect;
+ float fastest_effect, avg_dist;
int steps;
PaintSurfaceData *sData = surface->data;
PaintBakeData *bData = sData->bData;
@@ -4118,9 +4147,10 @@ static int dynamicPaint_prepareEffectStep(DynamicPaintSurface *surface, Scene *s
shrink_speed = surface->shrink_speed;
fastest_effect = MAX3(spread_speed, shrink_speed, average_force);
+ avg_dist = bData->average_dist*CANVAS_REL_SIZE/getSurfaceDimension(sData);
- steps = (int)ceil(1.5f*EFF_MOVEMENT_PER_FRAME*fastest_effect/bData->average_dist*timescale);
- CLAMP(steps, 1, 14);
+ steps = (int)ceil(1.5f*EFF_MOVEMENT_PER_FRAME*fastest_effect/avg_dist*timescale);
+ CLAMP(steps, 1, 20);
return steps;
}
@@ -4132,6 +4162,7 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force
{
PaintSurfaceData *sData = surface->data;
BakeNeighPoint *bNeighs = sData->bData->bNeighs;
+ float distance_scale = getSurfaceDimension(sData)/CANVAS_REL_SIZE;
int index;
timescale /= steps;
@@ -4141,7 +4172,7 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force
* Spread Effect
*/
if (surface->effect & MOD_DPAINT_EFFECT_DO_SPREAD) {
- float eff_scale = EFF_MOVEMENT_PER_FRAME*surface->spread_speed*timescale;
+ float eff_scale = distance_scale*EFF_MOVEMENT_PER_FRAME*surface->spread_speed*timescale;
/* Copy current surface to the previous points array to read unmodified values */
memcpy(prevPoint, sData->type_data, sData->total_points*sizeof(struct PaintPoint));
@@ -4151,7 +4182,6 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force
{
int i;
int numOfNeighs = sData->adj_data->n_num[index];
- float totalAlpha = 0.0f;
PaintPoint *pPoint = &((PaintPoint*)sData->type_data)[index];
/* Only reads values from the surface copy (prevPoint[]),
@@ -4160,39 +4190,23 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force
/* Loop through neighbouring points */
for (i=0; i<numOfNeighs; i++) {
int n_index = sData->adj_data->n_index[index]+i;
- float w_factor, alphaAdd = 0.0f;
+ float w_factor /* , p_alpha = pPoint->e_alpha */ /* UNUSED */;
PaintPoint *ePoint = &prevPoint[sData->adj_data->n_target[n_index]];
float speed_scale = (bNeighs[n_index].dist<eff_scale) ? 1.0f : eff_scale/bNeighs[n_index].dist;
- float color_mix = (MIN2(ePoint->wetness, pPoint->wetness))*0.25f*surface->color_spread_speed;
-
- totalAlpha += ePoint->e_alpha;
+ float color_mix = (MIN3(ePoint->wetness, pPoint->wetness, 1.0f))*0.25f*surface->color_spread_speed;
/* do color mixing */
- if (color_mix > MIN_WETNESS) mixColors(pPoint->e_color, pPoint->e_alpha, ePoint->e_color, color_mix);
-
- /* Check if neighbouring point has higher wetness,
- * if so, add it's wetness to this point as well*/
- if (ePoint->wetness <= pPoint->wetness) continue;
- w_factor = ePoint->wetness/numOfNeighs * (ePoint->wetness - pPoint->wetness) * speed_scale;
- if (w_factor <= MIN_WETNESS) continue;
-
- if (ePoint->e_alpha > pPoint->e_alpha) {
- alphaAdd = ePoint->e_alpha/numOfNeighs * (ePoint->wetness*ePoint->e_alpha - pPoint->wetness*pPoint->e_alpha) * speed_scale;
- }
+ if (color_mix) mixColors(pPoint->e_color, pPoint->e_alpha, ePoint->e_color, ePoint->e_alpha, color_mix);
- /* mix new color */
- mixColors(pPoint->e_color, pPoint->e_alpha, ePoint->e_color, w_factor);
+ /* Only continue if surrounding point has higher wetness */
+ if (ePoint->wetness<pPoint->wetness || ePoint->wetness<MIN_WETNESS) continue;
- pPoint->e_alpha += alphaAdd;
- pPoint->wetness += w_factor;
+ w_factor = 1.0f/numOfNeighs * MIN2(ePoint->wetness, 1.0f) * speed_scale;
+ CLAMP(w_factor, 0.0f, 1.0f);
- if (pPoint->e_alpha > 1.0f) pPoint->e_alpha = 1.0f;
- }
-
- /* For antialiasing sake, don't let alpha go much higher than average alpha of neighbours */
- if (pPoint->e_alpha > (totalAlpha/numOfNeighs+0.25f)) {
- pPoint->e_alpha = (totalAlpha/numOfNeighs+0.25f);
- if (pPoint->e_alpha>1.0f) pPoint->e_alpha = 1.0f;
+ /* mix new wetness and color */
+ pPoint->wetness = (1.0f-w_factor)*pPoint->wetness + w_factor*ePoint->wetness;
+ pPoint->e_alpha = mixColors(pPoint->e_color, pPoint->e_alpha, ePoint->e_color, ePoint->e_alpha, w_factor);
}
}
}
@@ -4201,7 +4215,7 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force
* Shrink Effect
*/
if (surface->effect & MOD_DPAINT_EFFECT_DO_SHRINK) {
- float eff_scale = EFF_MOVEMENT_PER_FRAME*surface->shrink_speed*timescale;
+ float eff_scale = distance_scale*EFF_MOVEMENT_PER_FRAME*surface->shrink_speed*timescale;
/* Copy current surface to the previous points array to read unmodified values */
memcpy(prevPoint, sData->type_data, sData->total_points*sizeof(struct PaintPoint));
@@ -4251,7 +4265,7 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force
*/
if (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP && force)
{
- float eff_scale = EFF_MOVEMENT_PER_FRAME*timescale/2.0f;
+ float eff_scale = distance_scale*EFF_MOVEMENT_PER_FRAME*timescale/2.0f;
/* Copy current surface to the previous points array to read unmodified values */
memcpy(prevPoint, sData->type_data, sData->total_points*sizeof(struct PaintPoint));
@@ -4264,8 +4278,9 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force
float closest_d[2];
/* adjust drip speed depending on wetness */
- float w_factor = pPoint_prev->wetness*0.5f - 0.025f;
+ float w_factor = pPoint_prev->wetness - 0.025f;
if (w_factor <= 0) continue;
+ CLAMP(w_factor, 0.0f, 1.0f);
/* get force affect points */
surface_determineForceTargetPoints(sData, index, &force[index*4], closest_d, closest_id);
@@ -4274,41 +4289,38 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force
for (i=0; i<2; i++) {
int n_index = closest_id[i];
if (n_index != -1 && closest_d[i]>0.0f) {
- float dir_dot = closest_d[i], dir_factor;
+ float dir_dot = closest_d[i], dir_factor, a_factor;
float speed_scale = eff_scale*force[index*4+3]/bNeighs[n_index].dist;
PaintPoint *ePoint = &((PaintPoint*)sData->type_data)[sData->adj_data->n_target[n_index]];
+ float e_wet = ePoint->wetness;
/* just skip if angle is too extreme */
if (dir_dot <= 0.0f) continue;
- dir_factor = dir_dot * speed_scale * w_factor;
- if (dir_factor > (0.5f/steps)) dir_factor = (0.5f/steps);
+ dir_factor = dir_dot * MIN2(speed_scale, 1.0f) * w_factor;
+ if (dir_factor > 0.5f) dir_factor = 0.5f;
- /* mix new color */
- if (dir_factor) mixColors(ePoint->e_color, ePoint->e_alpha, pPoint->e_color, dir_factor);
-
- ePoint->e_alpha += dir_factor;
+ /* mix new wetness*/
ePoint->wetness += dir_factor;
- if (ePoint->e_alpha > 1.0f) ePoint->e_alpha = 1.0f;
+ CLAMP(ePoint->wetness, 0.0f, MAX_WETNESS);
- /* and decrease paint wetness on current point */
- pPoint->wetness -= dir_factor;
+ /* mix new color */
+ a_factor = dir_factor / pPoint_prev->wetness;
+ CLAMP(a_factor, 0.0f, 1.0f);
+ mixColors(ePoint->e_color, ePoint->e_alpha, pPoint_prev->e_color, pPoint_prev->e_alpha, a_factor);
+ /* dripping is supposed to preserve alpha level */
+ if (pPoint_prev->e_alpha > ePoint->e_alpha) {
+ ePoint->e_alpha += a_factor * pPoint_prev->e_alpha;
+ if (ePoint->e_alpha > pPoint_prev->e_alpha)
+ ePoint->e_alpha = pPoint_prev->e_alpha;
+ }
+
+ /* decrease paint wetness on current point */
+ pPoint->wetness -= (ePoint->wetness - e_wet);
+ CLAMP(pPoint->wetness, 0.0f, MAX_WETNESS);
}
}
}
-
- /* Keep values within acceptable range */
- #pragma omp parallel for schedule(static)
- for (index = 0; index < sData->total_points; index++)
- {
- PaintPoint *cPoint = &((PaintPoint*)sData->type_data)[index];
-
- if (cPoint->e_alpha > 1.0f) cPoint->e_alpha=1.0f;
- if (cPoint->wetness > 2.0f) cPoint->wetness=2.0f;
-
- if (cPoint->e_alpha < 0.0f) cPoint->e_alpha=0.0f;
- if (cPoint->wetness < 0.0f) cPoint->wetness=0.0f;
- }
}
}
@@ -4323,7 +4335,7 @@ void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescale)
double average_dist = 0.0f;
Bounds3D *mb = &sData->bData->mesh_bounds;
float canvas_size = MAX3((mb->max[0]-mb->min[0]), (mb->max[1]-mb->min[1]), (mb->max[2]-mb->min[2]));
- float wave_scale = WAVE_INIT_SIZE/canvas_size;
+ float wave_scale = CANVAS_REL_SIZE/canvas_size;
/* allocate memory */
PaintWavePoint *prevPoint = MEM_mallocN(sData->total_points*sizeof(PaintWavePoint), "Temp previous points for wave simulation");
@@ -4436,48 +4448,53 @@ static void dynamicPaint_surfacePreStep(DynamicPaintSurface *surface, float time
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) {
PaintPoint *pPoint = &((PaintPoint*)sData->type_data)[index];
/* drying */
- if (pPoint->wetness >= MIN_WETNESS) {
- int i;
- float dry_ratio, f_color[4];
- float p_wetness = pPoint->wetness;
- VALUE_DISSOLVE(pPoint->wetness, surface->dry_speed, timescale, (surface->flags & MOD_DPAINT_DRY_LOG));
- if (pPoint->wetness<0.0f) pPoint->wetness=0.0f;
- dry_ratio = pPoint->wetness/p_wetness;
+ if (surface->flags & MOD_DPAINT_USE_DRYING) {
+ if (pPoint->wetness >= MIN_WETNESS) {
+ int i;
+ float dry_ratio, f_color[4];
+ float p_wetness = pPoint->wetness;
+ VALUE_DISSOLVE(pPoint->wetness, surface->dry_speed, timescale, (surface->flags & MOD_DPAINT_DRY_LOG));
+ if (pPoint->wetness<0.0f) pPoint->wetness=0.0f;
- /*
- * Slowly "shift" paint from wet layer to dry layer as it drys:
- */
- /* make sure alpha values are within proper range */
- CLAMP(pPoint->alpha, 0.0f, 1.0f);
- CLAMP(pPoint->e_alpha, 0.0f, 1.0f);
-
- /* get current final blended color of these layers */
- blendColors(pPoint->color, pPoint->alpha, pPoint->e_color, pPoint->e_alpha, f_color);
- /* reduce wet layer alpha by dry factor */
- pPoint->e_alpha *= dry_ratio;
-
- /* now calculate new alpha for dry layer that keeps final blended color unchanged */
- pPoint->alpha = (f_color[3] - pPoint->e_alpha)/(1.0f-pPoint->e_alpha);
- /* for each rgb component, calculate a new dry layer color that keeps the final blend color
- * with these new alpha values. (wet layer color doesnt change)*/
- if (pPoint->alpha) {
- for (i=0; i<3; i++) {
- pPoint->color[i] = (f_color[i]*f_color[3] - pPoint->e_color[i]*pPoint->e_alpha)/(pPoint->alpha*(1.0f-pPoint->e_alpha));
+ if (pPoint->wetness < surface->color_dry_threshold) {
+ dry_ratio = pPoint->wetness/p_wetness;
+
+ /*
+ * Slowly "shift" paint from wet layer to dry layer as it drys:
+ */
+ /* make sure alpha values are within proper range */
+ CLAMP(pPoint->alpha, 0.0f, 1.0f);
+ CLAMP(pPoint->e_alpha, 0.0f, 1.0f);
+
+ /* get current final blended color of these layers */
+ blendColors(pPoint->color, pPoint->alpha, pPoint->e_color, pPoint->e_alpha, f_color);
+ /* reduce wet layer alpha by dry factor */
+ pPoint->e_alpha *= dry_ratio;
+
+ /* now calculate new alpha for dry layer that keeps final blended color unchanged */
+ pPoint->alpha = (f_color[3] - pPoint->e_alpha)/(1.0f-pPoint->e_alpha);
+ /* for each rgb component, calculate a new dry layer color that keeps the final blend color
+ * with these new alpha values. (wet layer color doesnt change)*/
+ if (pPoint->alpha) {
+ for (i=0; i<3; i++) {
+ pPoint->color[i] = (f_color[i]*f_color[3] - pPoint->e_color[i]*pPoint->e_alpha)/(pPoint->alpha*(1.0f-pPoint->e_alpha));
+ }
+ }
}
- }
- pPoint->state = DPAINT_PAINT_WET;
- }
- /* in case of just dryed paint, just mix it to the dry layer and mark it empty */
- else if (pPoint->state > 0) {
- float f_color[4];
- blendColors(pPoint->color, pPoint->alpha, pPoint->e_color, pPoint->e_alpha, f_color);
- copy_v3_v3(pPoint->color, f_color);
- pPoint->alpha = f_color[3];
- /* clear wet layer */
- pPoint->wetness = 0.0f;
- pPoint->e_alpha = 0.0f;
- pPoint->state = DPAINT_PAINT_DRY;
+ pPoint->state = DPAINT_PAINT_WET;
+ }
+ /* in case of just dryed paint, just mix it to the dry layer and mark it empty */
+ else if (pPoint->state > 0) {
+ float f_color[4];
+ blendColors(pPoint->color, pPoint->alpha, pPoint->e_color, pPoint->e_alpha, f_color);
+ copy_v3_v3(pPoint->color, f_color);
+ pPoint->alpha = f_color[3];
+ /* clear wet layer */
+ pPoint->wetness = 0.0f;
+ pPoint->e_alpha = 0.0f;
+ pPoint->state = DPAINT_PAINT_DRY;
+ }
}
if (surface->flags & MOD_DPAINT_DISSOLVE) {
@@ -4925,7 +4942,7 @@ int dynamicPaint_calculateFrame(DynamicPaintSurface *surface, Scene *scene, Obje
/* apply previous displace on derivedmesh if incremental surface */
if (surface->flags & MOD_DPAINT_DISP_INCREMENTAL)
- dynamicPaint_applySurfaceDisplace(surface, surface->canvas->dm, 0);
+ dynamicPaint_applySurfaceDisplace(surface, surface->canvas->dm);
/* update bake data */
dynamicPaint_generateBakeData(surface, scene, cObject);
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 9e5917f0b07..0a80e8a3d56 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -1111,9 +1111,9 @@ int BKE_add_image_extension(char *string, const char imtype)
if(BLI_testextensie_array(string, imb_ext_image)
|| (G.have_quicktime && BLI_testextensie_array(string, imb_ext_image_qt))) {
return BLI_replace_extension(string, FILE_MAX, extension);
- } else {
+ }
+ else {
return BLI_ensure_extension(string, FILE_MAX, extension);
- return TRUE;
}
}
@@ -1608,7 +1608,7 @@ int BKE_write_ibuf(ImBuf *ibuf, const char *name, ImageFormatData *imf)
return(ok);
}
-/* same as BKE_write_ibuf_as but crappy workaround not to perminantly modify
+/* same as BKE_write_ibuf() but crappy workaround not to perminantly modify
* _some_, values in the imbuf */
int BKE_write_ibuf_as(ImBuf *ibuf, const char *name, ImageFormatData *imf,
const short save_copy)
diff --git a/source/blender/blenkernel/intern/image_gen.c b/source/blender/blenkernel/intern/image_gen.c
index a93d0221cf0..c6cb8c9582a 100644
--- a/source/blender/blenkernel/intern/image_gen.c
+++ b/source/blender/blenkernel/intern/image_gen.c
@@ -33,7 +33,7 @@
#include "BLI_math_base.h"
#include "BLF_api.h"
-void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, int height, float color[4])
+void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, int height, const float color[4])
{
int x, y;
@@ -41,22 +41,17 @@ void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width,
if(rect_float) {
for(y= 0; y<height; y++) {
for(x= 0; x<width; x++) {
- rect_float[0]= color[0];
- rect_float[1]= color[1];
- rect_float[2]= color[2];
- rect_float[3]= color[3];
+ copy_v4_v4(rect_float, color);
rect_float+= 4;
}
}
}
if(rect) {
- char ccol[4];
+ unsigned char ccol[4];
+
+ rgba_float_to_uchar(ccol, color);
- ccol[0]= (char)(color[0]*255.0f);
- ccol[1]= (char)(color[1]*255.0f);
- ccol[2]= (char)(color[2]*255.0f);
- ccol[3]= (char)(color[3]*255.0f);
for(y= 0; y<height; y++) {
for(x= 0; x<width; x++) {
diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c
index eb7d07a6f7d..b2385a5cdb8 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -377,7 +377,7 @@ static int setkeys(float fac, ListBase *lb, KeyBlock *k[], float *t, int cycl)
if(k1->next==NULL) k[0]=k1;
k1=k1->next;
}
- k1= k[1];
+ /* k1= k[1]; */ /* UNUSED */
t[0]= k[0]->pos;
t[1]+= dpos;
t[2]= k[2]->pos + dpos;
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index ef2249409f0..cba92e7a14c 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -42,12 +42,12 @@
#include "DNA_meshdata_types.h"
#include "DNA_ipo_types.h"
+#include "BLI_utildefines.h"
#include "BLI_blenlib.h"
#include "BLI_bpath.h"
#include "BLI_editVert.h"
#include "BLI_math.h"
#include "BLI_edgehash.h"
-#include "BLI_utildefines.h"
#include "BKE_animsys.h"
#include "BKE_main.h"
@@ -1292,11 +1292,11 @@ float (*mesh_getVertexCos(Mesh *me, int *numVerts_r))[3]
{
int i, numVerts = me->totvert;
float (*cos)[3] = MEM_mallocN(sizeof(*cos)*numVerts, "vertexcos1");
-
+
if (numVerts_r) *numVerts_r = numVerts;
for (i=0; i<numVerts; i++)
- VECCOPY(cos[i], me->mvert[i].co);
-
+ copy_v3_v3(cos[i], me->mvert[i].co);
+
return cos;
}
@@ -1589,7 +1589,7 @@ int mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata,
mesh_loops_to_mface_corners(fdata, ldata, pdata,
lindex, k, i, 3,
numTex, numCol, hasWCol);
- test_index_face(mf, fdata, totface, 3);
+ test_index_face(mf, fdata, k, 3);
}
else {
/*sort loop indices to ensure winding is correct*/
@@ -1609,7 +1609,7 @@ int mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata,
mesh_loops_to_mface_corners(fdata, ldata, pdata,
lindex, k, i, 4,
numTex, numCol, hasWCol);
- test_index_face(mf, fdata, totface, 4);
+ test_index_face(mf, fdata, k, 4);
}
mf->edcode= 0;
diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c
index 3b1dc2973ad..bb8e420451f 100644
--- a/source/blender/blenkernel/intern/movieclip.c
+++ b/source/blender/blenkernel/intern/movieclip.c
@@ -981,7 +981,7 @@ static void movieclip_build_proxy_ibuf(MovieClip *clip, ImBuf *ibuf, int cfra, i
{
char name[FILE_MAX];
int quality, rectx, recty;
- int size= size= rendersize_to_number(proxy_render_size);
+ int size= rendersize_to_number(proxy_render_size);
ImBuf *scaleibuf;
get_proxy_fname(clip, proxy_render_size, undistorted, cfra, name);
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index 359470eecf2..96ee2bd0349 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -159,7 +159,6 @@ void ntreeInitTypes(bNodeTree *ntree)
static bNodeSocket *make_socket(bNodeTree *UNUSED(ntree), int in_out, const char *name, int type)
{
- bNodeSocketType *stype= ntreeGetSocketType(type);
bNodeSocket *sock;
sock= MEM_callocN(sizeof(bNodeSocket), "sock");
@@ -169,8 +168,8 @@ static bNodeSocket *make_socket(bNodeTree *UNUSED(ntree), int in_out, const char
sock->type= type;
sock->storage = NULL;
- if (stype->value_structsize > 0)
- sock->default_value = MEM_callocN(stype->value_structsize, "default socket value");
+ sock->default_value = node_socket_make_default_value(type);
+ node_socket_init_default_value(type, sock->default_value);
return sock;
}
@@ -216,8 +215,7 @@ void nodeRemoveSocket(bNodeTree *ntree, bNode *node, bNodeSocket *sock)
BLI_remlink(&node->inputs, sock);
BLI_remlink(&node->outputs, sock);
- if (sock->default_value)
- MEM_freeN(sock->default_value);
+ node_socket_free_default_value(sock->type, sock->default_value);
MEM_freeN(sock);
node->update |= NODE_UPDATE;
@@ -236,13 +234,10 @@ void nodeRemoveAllSockets(bNodeTree *ntree, bNode *node)
}
for (sock=node->inputs.first; sock; sock=sock->next)
- if (sock->default_value)
- MEM_freeN(sock->default_value);
+ node_socket_free_default_value(sock->type, sock->default_value);
BLI_freelistN(&node->inputs);
for (sock=node->outputs.first; sock; sock=sock->next)
- if (sock->default_value)
- MEM_freeN(sock->default_value);
-
+ node_socket_free_default_value(sock->type, sock->default_value);
BLI_freelistN(&node->outputs);
node->update |= NODE_UPDATE;
@@ -396,7 +391,8 @@ bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node)
oldsock->new_sock= sock;
sock->stack_index= 0;
- sock->default_value = (oldsock->default_value ? MEM_dupallocN(oldsock->default_value) : NULL);
+ sock->default_value = node_socket_make_default_value(oldsock->type);
+ node_socket_copy_default_value(oldsock->type, sock->default_value, oldsock->default_value);
/* XXX some compositor node (e.g. image, render layers) still store
* some persistent buffer data here, need to clear this to avoid dangling pointers.
@@ -410,7 +406,8 @@ bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node)
oldsock->new_sock= sock;
sock->stack_index= 0;
- sock->default_value = (oldsock->default_value ? MEM_dupallocN(oldsock->default_value) : NULL);
+ sock->default_value = node_socket_make_default_value(oldsock->type);
+ node_socket_copy_default_value(oldsock->type, sock->default_value, oldsock->default_value);
/* XXX some compositor node (e.g. image, render layers) still store
* some persistent buffer data here, need to clear this to avoid dangling pointers.
@@ -658,13 +655,15 @@ bNodeTree *ntreeCopyTree(bNodeTree *ntree)
for(gsock= newtree->inputs.first, oldgsock= ntree->inputs.first; gsock; gsock=gsock->next, oldgsock=oldgsock->next) {
oldgsock->new_sock= gsock;
gsock->groupsock = (oldgsock->groupsock ? oldgsock->groupsock->new_sock : NULL);
- gsock->default_value = (oldgsock->default_value ? MEM_dupallocN(oldgsock->default_value) : NULL);
+ gsock->default_value = node_socket_make_default_value(oldgsock->type);
+ node_socket_copy_default_value(oldgsock->type, gsock->default_value, oldgsock->default_value);
}
BLI_duplicatelist(&newtree->outputs, &ntree->outputs);
for(gsock= newtree->outputs.first, oldgsock= ntree->outputs.first; gsock; gsock=gsock->next, oldgsock=oldgsock->next) {
oldgsock->new_sock= gsock;
gsock->groupsock = (oldgsock->groupsock ? oldgsock->groupsock->new_sock : NULL);
- gsock->default_value = (oldgsock->default_value ? MEM_dupallocN(oldgsock->default_value) : NULL);
+ gsock->default_value = node_socket_make_default_value(oldgsock->type);
+ node_socket_copy_default_value(oldgsock->type, gsock->default_value, oldgsock->default_value);
}
/* copy links */
@@ -790,16 +789,11 @@ void nodeAddToPreview(bNode *node, float *col, int x, int y, int do_manage)
unsigned char *tar= preview->rect+ 4*((preview->xsize*y) + x);
if(do_manage) {
- tar[0]= FTOCHAR(linearrgb_to_srgb(col[0]));
- tar[1]= FTOCHAR(linearrgb_to_srgb(col[1]));
- tar[2]= FTOCHAR(linearrgb_to_srgb(col[2]));
+ linearrgb_to_srgb_uchar4(tar, col);
}
else {
- tar[0]= FTOCHAR(col[0]);
- tar[1]= FTOCHAR(col[1]);
- tar[2]= FTOCHAR(col[2]);
+ rgba_float_to_uchar(tar, col);
}
- tar[3]= FTOCHAR(col[3]);
}
//else printf("prv out bound x y %d %d\n", x, y);
}
@@ -868,14 +862,12 @@ void nodeFreeNode(bNodeTree *ntree, bNode *node)
for (sock=node->inputs.first; sock; sock = nextsock) {
nextsock = sock->next;
- if (sock->default_value)
- MEM_freeN(sock->default_value);
+ node_socket_free_default_value(sock->type, sock->default_value);
MEM_freeN(sock);
}
for (sock=node->outputs.first; sock; sock = nextsock) {
nextsock = sock->next;
- if (sock->default_value)
- MEM_freeN(sock->default_value);
+ node_socket_free_default_value(sock->type, sock->default_value);
MEM_freeN(sock);
}
@@ -929,12 +921,10 @@ void ntreeFreeTree(bNodeTree *ntree)
}
for (sock=ntree->inputs.first; sock; sock=sock->next)
- if (sock->default_value)
- MEM_freeN(sock->default_value);
+ node_socket_free_default_value(sock->type, sock->default_value);
BLI_freelistN(&ntree->inputs);
for (sock=ntree->outputs.first; sock; sock=sock->next)
- if (sock->default_value)
- MEM_freeN(sock->default_value);
+ node_socket_free_default_value(sock->type, sock->default_value);
BLI_freelistN(&ntree->outputs);
}
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index fe848f3d76c..2b3f792f777 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -66,6 +66,11 @@ Paint *paint_get_active(Scene *sce)
return &ts->wpaint->paint;
case OB_MODE_TEXTURE_PAINT:
return &ts->imapaint.paint;
+ case OB_MODE_EDIT:
+ if(ts->use_uv_sculpt)
+ return &ts->uvsculpt->paint;
+ else
+ return &ts->imapaint.paint;
}
}
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 7ea4fd751c4..d6b85b80f20 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -304,6 +304,10 @@ void free_scene(Scene *sce)
free_paint(&sce->toolsettings->sculpt->paint);
MEM_freeN(sce->toolsettings->sculpt);
}
+ if(sce->toolsettings->uvsculpt) {
+ free_paint(&sce->toolsettings->uvsculpt->paint);
+ MEM_freeN(sce->toolsettings->uvsculpt);
+ }
free_paint(&sce->toolsettings->imapaint.paint);
MEM_freeN(sce->toolsettings);
diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c
index 71377799651..08b53115919 100644
--- a/source/blender/blenkernel/intern/sequencer.c
+++ b/source/blender/blenkernel/intern/sequencer.c
@@ -1690,10 +1690,10 @@ static ImBuf * input_preprocess(
if(rct) {
float rgb[3];
for (i = ibuf->x * ibuf->y; i > 0; i--, rct+=4) {
- rgb_byte_to_float(rct, rgb);
+ rgb_uchar_to_float(rgb, rct);
rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
hsv_to_rgb(hsv[0], hsv[1] * sat, hsv[2], rgb, rgb+1, rgb+2);
- rgb_float_to_byte(rgb, rct);
+ rgb_float_to_uchar(rct, rgb);
}
}
diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c
index 8d20a06d009..46a3f776e43 100644
--- a/source/blender/blenkernel/intern/softbody.c
+++ b/source/blender/blenkernel/intern/softbody.c
@@ -3468,7 +3468,7 @@ static void makelatticesprings(Lattice *lt, BodySpring *bs, int dostiff,Object *
bs->len= globallen((bp-dw-dv-1)->vec, bp->vec,ob);
bs++;
}
- if( (v < lt->pntsv-1) && (u) ) {
+ if( (v < lt->pntsv-1) && (u != 0) ) {
bs->v1 = bpc;
bs->v2 = bpc-dw+dv-1;
bs->springtype=SB_BEND;
@@ -3485,7 +3485,7 @@ static void makelatticesprings(Lattice *lt, BodySpring *bs, int dostiff,Object *
bs->len= globallen((bp+dw-dv-1)->vec, bp->vec,ob);
bs++;
}
- if( (v < lt->pntsv-1) && (u) ) {
+ if( (v < lt->pntsv-1) && (u != 0) ) {
bs->v1 = bpc;
bs->v2 = bpc+dw+dv-1;
bs->springtype=SB_BEND;
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index f7acdc78749..e4fa2bde63b 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -92,9 +92,17 @@ static void arena_release(CCGAllocatorHDL a) {
BLI_memarena_free(a);
}
-static CCGSubSurf *_getSubSurf(CCGSubSurf *prevSS, int subdivLevels, int useAging, int useArena, int UNUSED(useFlatSubdiv)) {
+typedef enum {
+ CCG_USE_AGING = 1,
+ CCG_USE_ARENA = 2,
+ CCG_CALC_NORMALS = 4,
+} CCGFlags;
+
+static CCGSubSurf *_getSubSurf(CCGSubSurf *prevSS, int subdivLevels, CCGFlags flags) {
CCGMeshIFC ifc;
CCGSubSurf *ccgSS;
+ int useAging = !!(flags & CCG_USE_AGING);
+ int useArena = flags & CCG_USE_ARENA;
/* subdivLevels==0 is not allowed */
subdivLevels = MAX2(subdivLevels, 1);
@@ -102,7 +110,6 @@ static CCGSubSurf *_getSubSurf(CCGSubSurf *prevSS, int subdivLevels, int useAgin
if (prevSS) {
int oldUseAging;
- useAging = !!useAging;
ccgSubSurf_getUseAgeCounts(prevSS, &oldUseAging, NULL, NULL, NULL);
if (oldUseAging!=useAging) {
@@ -119,7 +126,7 @@ static CCGSubSurf *_getSubSurf(CCGSubSurf *prevSS, int subdivLevels, int useAgin
} else {
ifc.vertUserSize = ifc.edgeUserSize = ifc.faceUserSize = 8;
}
- ifc.vertDataSize = sizeof(DMGridData);
+ ifc.vertDataSize = sizeof(float) * (flags & CCG_CALC_NORMALS ? 6 : 3);
if (useArena) {
CCGAllocatorIFC allocatorIFC;
@@ -139,7 +146,10 @@ static CCGSubSurf *_getSubSurf(CCGSubSurf *prevSS, int subdivLevels, int useAgin
ccgSubSurf_setUseAgeCounts(ccgSS, 1, 8, 8, 8);
}
- ccgSubSurf_setCalcVertexNormals(ccgSS, 1, offsetof(DMGridData, no));
+ if (flags & CCG_CALC_NORMALS)
+ ccgSubSurf_setCalcVertexNormals(ccgSS, 1, offsetof(DMGridData, no));
+ else
+ ccgSubSurf_setCalcVertexNormals(ccgSS, 0, 0);
return ccgSS;
}
@@ -322,7 +332,7 @@ static void set_subsurf_uv(CCGSubSurf *ss, DerivedMesh *dm, DerivedMesh *result,
return;
/* create a CCGSubSurf from uv's */
- uvss = _getSubSurf(NULL, ccgSubSurf_getSubdivisionLevels(ss), 0, 1, 0);
+ uvss = _getSubSurf(NULL, ccgSubSurf_getSubdivisionLevels(ss), CCG_USE_ARENA);
if(!ss_sync_from_uv(uvss, ss, dm, dmtface)) {
ccgSubSurf_free(uvss);
@@ -353,14 +363,14 @@ static void set_subsurf_uv(CCGSubSurf *ss, DerivedMesh *dm, DerivedMesh *result,
int numVerts = ccgSubSurf_getFaceNumVerts(f);
for (S=0; S<numVerts; S++) {
- DMGridData *faceGridData= ccgSubSurf_getFaceGridDataArray(uvss, f, S);
+ float (*faceGridData)[3]= ccgSubSurf_getFaceGridDataArray(uvss, f, S);
for(y = 0; y < gridFaces; y++) {
for(x = 0; x < gridFaces; x++) {
- copy_v2_v2(tf->uv[0], faceGridData[(y + 0)*gridSize + x + 0].co);
- copy_v2_v2(tf->uv[1], faceGridData[(y + 1)*gridSize + x + 0].co);
- copy_v2_v2(tf->uv[2], faceGridData[(y + 1)*gridSize + x + 1].co);
- copy_v2_v2(tf->uv[3], faceGridData[(y + 0)*gridSize + x + 1].co);
+ copy_v2_v2(tf->uv[0], faceGridData[(y + 0)*gridSize + x + 0]);
+ copy_v2_v2(tf->uv[1], faceGridData[(y + 1)*gridSize + x + 0]);
+ copy_v2_v2(tf->uv[2], faceGridData[(y + 1)*gridSize + x + 1]);
+ copy_v2_v2(tf->uv[3], faceGridData[(y + 0)*gridSize + x + 1]);
tf++;
}
@@ -2773,7 +2783,7 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
int isFinalCalc, int forEditMode, int inEditMode)
{
int useSimple = smd->subdivType == ME_SIMPLE_SUBSURF;
- int useAging = smd->flags & eSubsurfModifierFlag_DebugIncr;
+ CCGFlags useAging = smd->flags & eSubsurfModifierFlag_DebugIncr ? CCG_USE_AGING : 0;
int useSubsurfUv = smd->flags & eSubsurfModifierFlag_SubsurfUv;
int drawInteriorEdges = !(smd->flags & eSubsurfModifierFlag_ControlEdges);
CCGDerivedMesh *result;
@@ -2781,8 +2791,7 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
if(forEditMode) {
int levels= (smd->modifier.scene)? get_render_subsurf_level(&smd->modifier.scene->r, smd->levels): smd->levels;
- smd->emCache = _getSubSurf(smd->emCache, levels, useAging, 0,
- useSimple);
+ smd->emCache = _getSubSurf(smd->emCache, levels, useAging|CCG_CALC_NORMALS);
ss_sync_from_derivedmesh(smd->emCache, dm, vertCos, useSimple);
result = getCCGDerivedMesh(smd->emCache,
@@ -2796,7 +2805,7 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
if(levels == 0)
return dm;
- ss = _getSubSurf(NULL, levels, 0, 1, useSimple);
+ ss = _getSubSurf(NULL, levels, CCG_USE_ARENA|CCG_CALC_NORMALS);
ss_sync_from_derivedmesh(ss, dm, vertCos, useSimple);
@@ -2806,7 +2815,6 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
result->freeSS = 1;
} else {
int useIncremental = (smd->flags & eSubsurfModifierFlag_Incremental);
- int useAging = smd->flags & eSubsurfModifierFlag_DebugIncr;
int levels= (smd->modifier.scene)? get_render_subsurf_level(&smd->modifier.scene->r, smd->levels): smd->levels;
CCGSubSurf *ss;
@@ -2827,8 +2835,7 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
}
if(useIncremental && isFinalCalc) {
- smd->mCache = ss = _getSubSurf(smd->mCache, levels,
- useAging, 0, useSimple);
+ smd->mCache = ss = _getSubSurf(smd->mCache, levels, useAging|CCG_CALC_NORMALS);
ss_sync_from_derivedmesh(ss, dm, vertCos, useSimple);
@@ -2841,7 +2848,7 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
smd->mCache = NULL;
}
- ss = _getSubSurf(NULL, levels, 0, 1, useSimple);
+ ss = _getSubSurf(NULL, levels, CCG_USE_ARENA|CCG_CALC_NORMALS);
ss_sync_from_derivedmesh(ss, dm, vertCos, useSimple);
result = getCCGDerivedMesh(ss, drawInteriorEdges, useSubsurfUv, dm);
@@ -2863,7 +2870,7 @@ void subsurf_calculate_limit_positions(Mesh *me, float (*positions_r)[3])
* calculated vert positions is incorrect for the verts
* on the boundary of the mesh.
*/
- CCGSubSurf *ss = _getSubSurf(NULL, 1, 0, 1, 0);
+ CCGSubSurf *ss = _getSubSurf(NULL, 1, CCG_USE_ARENA);
float edge_sum[3], face_sum[3];
CCGVertIterator *vi;
DerivedMesh *dm = CDDM_from_mesh(me, NULL);
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c
index 7e102bc9854..8e5cc8c48e3 100644
--- a/source/blender/blenkernel/intern/text.c
+++ b/source/blender/blenkernel/intern/text.c
@@ -33,6 +33,8 @@
#include <string.h> /* strstr */
#include <sys/types.h>
#include <sys/stat.h>
+#include <wchar.h>
+#include <wctype.h>
#include "MEM_guardedalloc.h"
@@ -215,8 +217,48 @@ Text *add_empty_text(const char *name)
return ta;
}
+/* this function replaces extended ascii characters */
+/* to a valid utf-8 sequences */
+int txt_extended_ascii_as_utf8(char **str)
+{
+ int bad_char, added= 0, i= 0;
+ int length = strlen(*str);
+
+ while ((*str)[i]) {
+ if((bad_char= BLI_utf8_invalid_byte(*str+i, length-i)) == -1)
+ break;
+
+ added++;
+ i+= bad_char + 1;
+ }
+
+ if (added != 0) {
+ char *newstr = MEM_mallocN(length+added+1, "text_line");
+ int mi = 0;
+ i= 0;
+
+ while ((*str)[i]) {
+ if((bad_char= BLI_utf8_invalid_byte((*str)+i, length-i)) == -1) {
+ memcpy(newstr+mi, (*str)+i, length - i + 1);
+ break;
+ }
+
+ memcpy(newstr+mi, (*str)+i, bad_char);
+
+ BLI_str_utf8_from_unicode((*str)[i+bad_char], newstr+mi+bad_char);
+ i+= bad_char+1;
+ mi+= bad_char+2;
+ }
+ newstr[length+added] = '\0';
+ MEM_freeN(*str);
+ *str = newstr;
+ }
+
+ return added;
+}
+
// this function removes any control characters from
-// a textline
+// a textline and fixes invalid utf-8 sequences
static void cleanup_textline(TextLine * tl)
{
@@ -229,6 +271,7 @@ static void cleanup_textline(TextLine * tl)
i--;
}
}
+ tl->len+= txt_extended_ascii_as_utf8(&tl->line);
}
int reopen_text(Text *text)
@@ -689,16 +732,10 @@ static void txt_make_dirty (Text *text)
}
/* 0:whitespace, 1:punct, 2:alphanumeric */
-static short txt_char_type (char ch)
-{
- if (ch <= ' ') return 0; /* 32 */
- if (ch <= '/') return 1; /* 47 */
- if (ch <= '9') return 2; /* 57 */
- if (ch <= '@') return 1; /* 64 */
- if (ch <= 'Z') return 2; /* 90 */
- if (ch == '_') return 2; /* 95, dont delimit '_' */
- if (ch <= '`') return 1; /* 96 */
- if (ch <= 'z') return 2; /* 122 */
+static short txt_char_type(unsigned int ch)
+{
+ if (iswspace(ch)) return 0;
+ if (iswalpha(ch) || iswdigit(ch)) return 2;
return 1;
}
@@ -731,9 +768,42 @@ static void txt_curs_first (Text *text, TextLine **linep, int *charp)
}
}
-/****************************/
+/*****************************/
/* Cursor movement functions */
-/****************************/
+/*****************************/
+
+int txt_utf8_offset_to_index(char *str, int offset)
+{
+ int index= 0, pos= 0;
+ while (pos != offset) {
+ pos += BLI_str_utf8_size(str + pos);
+ index++;
+ }
+ return index;
+}
+
+int txt_utf8_index_to_offset(char *str, int index)
+{
+ int offset= 0, pos= 0;
+ while (pos != index) {
+ offset += BLI_str_utf8_size(str + offset);
+ pos++;
+ }
+ return offset;
+}
+
+/* returns the real number of characters in string */
+/* not the same as BLI_strlen_utf8, which returns length for wide characters */
+static int txt_utf8_len(const char *src)
+{
+ int len;
+
+ for (len=0; *src; len++) {
+ src += BLI_str_utf8_size(src);
+ }
+
+ return len;
+}
void txt_move_up(Text *text, short sel)
{
@@ -747,13 +817,13 @@ void txt_move_up(Text *text, short sel)
old= *charp;
if((*linep)->prev) {
+ int index = txt_utf8_offset_to_index((*linep)->line, *charp);
*linep= (*linep)->prev;
- if (*charp > (*linep)->len) {
- *charp= (*linep)->len;
- if(!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, (*linep)->next), old, txt_get_span(text->lines.first, *linep), (unsigned short) *charp);
- } else {
- if(!undoing) txt_undo_add_op(text, sel?UNDO_SUP:UNDO_CUP);
- }
+ if (index > txt_utf8_len((*linep)->line)) *charp= (*linep)->len;
+ else *charp= txt_utf8_index_to_offset((*linep)->line, index);
+
+ if(!undoing)
+ txt_undo_add_op(text, sel?UNDO_SUP:UNDO_CUP);
} else {
txt_move_bol(text, sel);
}
@@ -773,12 +843,13 @@ void txt_move_down(Text *text, short sel)
old= *charp;
if((*linep)->next) {
+ int index = txt_utf8_offset_to_index((*linep)->line, *charp);
*linep= (*linep)->next;
- if (*charp > (*linep)->len) {
- *charp= (*linep)->len;
- if(!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, (*linep)->prev), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp);
- } else
- if(!undoing) txt_undo_add_op(text, sel?UNDO_SDOWN:UNDO_CDOWN);
+ if (index > txt_utf8_len((*linep)->line)) *charp= (*linep)->len;
+ else *charp= txt_utf8_index_to_offset((*linep)->line, index);
+
+ if(!undoing)
+ txt_undo_add_op(text, sel?UNDO_SDOWN:UNDO_CDOWN);
} else {
txt_move_eol(text, sel);
}
@@ -790,7 +861,7 @@ void txt_move_left(Text *text, short sel)
{
TextLine **linep;
int *charp, oundoing= undoing;
- int tabsize = 1, i=0;
+ int tabsize= 0, i= 0;
if (!text) return;
if(sel) txt_curs_sel(text, &linep, &charp);
@@ -799,32 +870,36 @@ void txt_move_left(Text *text, short sel)
undoing= 1;
- // do nice left only if there are only spaces
- // TXT_TABSIZE hardcoded in DNA_text_types.h
- if (text->flags & TXT_TABSTOSPACES) {
- tabsize = TXT_TABSIZE;
-
- if (*charp < tabsize)
- tabsize = *charp;
- else {
- for (i=0;i<(*charp);i++)
+ if (*charp== 0) {
+ if ((*linep)->prev) {
+ txt_move_up(text, sel);
+ *charp= (*linep)->len;
+ }
+ }
+ else {
+ // do nice left only if there are only spaces
+ // TXT_TABSIZE hardcoded in DNA_text_types.h
+ if (text->flags & TXT_TABSTOSPACES) {
+ tabsize= (*charp < TXT_TABSIZE) ? *charp : TXT_TABSIZE;
+
+ for (i=0; i<(*charp); i++)
if ((*linep)->line[i] != ' ') {
- tabsize = 1;
+ tabsize= 0;
break;
}
+
// if in the middle of the space-tab
- if ((*charp) % tabsize != 0)
- tabsize = ((*charp) % tabsize);
+ if (tabsize && (*charp) % TXT_TABSIZE != 0)
+ tabsize= ((*charp) % TXT_TABSIZE);
}
- }
-
- if (*charp== 0) {
- if ((*linep)->prev) {
- txt_move_up(text, sel);
- *charp= (*linep)->len;
+
+ if (tabsize)
+ (*charp)-= tabsize;
+ else {
+ const char *prev= BLI_str_prev_char_utf8((*linep)->line + *charp);
+ *charp= prev - (*linep)->line;
}
}
- else (*charp)-= tabsize;
undoing= oundoing;
if(!undoing) txt_undo_add_op(text, sel?UNDO_SLEFT:UNDO_CLEFT);
@@ -835,8 +910,7 @@ void txt_move_left(Text *text, short sel)
void txt_move_right(Text *text, short sel)
{
TextLine **linep;
- int *charp, oundoing= undoing;
- int tabsize=1, i=0;
+ int *charp, oundoing= undoing, do_tab= 0, i;
if (!text) return;
if(sel) txt_curs_sel(text, &linep, &charp);
@@ -845,32 +919,33 @@ void txt_move_right(Text *text, short sel)
undoing= 1;
- // do nice right only if there are only spaces
- // spaces hardcoded in DNA_text_types.h
- if (text->flags & TXT_TABSTOSPACES) {
- tabsize = TXT_TABSIZE;
-
- if ((*charp) + tabsize > (*linep)->len)
- tabsize = 1;
- else {
- for (i=0;i<(*charp) + tabsize - ((*charp) % tabsize);i++)
- if ((*linep)->line[i] != ' ') {
- tabsize = 1;
- break;
- }
- // if in the middle of the space-tab
- tabsize -= (*charp) % tabsize;
- }
- }
-
if (*charp== (*linep)->len) {
if ((*linep)->next) {
txt_move_down(text, sel);
*charp= 0;
}
- } else {
- (*charp)+=tabsize;
+ }
+ else {
+ // do nice right only if there are only spaces
+ // spaces hardcoded in DNA_text_types.h
+ if (text->flags & TXT_TABSTOSPACES && (*linep)->line[*charp]== ' ') {
+ do_tab= 1;
+ for (i=0; i<*charp; i++)
+ if ((*linep)->line[i]!= ' ') {
+ do_tab= 0;
+ break;
+ }
+ }
+
+ if (do_tab) {
+ int tabsize= (*charp) % TXT_TABSIZE + 1;
+ for (i=*charp+1; (*linep)->line[i]==' ' && tabsize<TXT_TABSIZE; i++)
+ tabsize++;
+ (*charp)= i;
+ }
+ else (*charp)+= BLI_str_utf8_size((*linep)->line + *charp);
}
+
undoing= oundoing;
if(!undoing) txt_undo_add_op(text, sel?UNDO_SRIGHT:UNDO_CRIGHT);
@@ -896,9 +971,12 @@ void txt_jump_left(Text *text, short sel)
count= 0;
for (i=0; i<3; i++) {
if (count < 2) {
- while (*charp>0 && txt_char_type((*linep)->line[*charp-1])==i) {
- txt_move_left(text, sel);
- count++;
+ while (*charp>0) {
+ char *sym= BLI_str_prev_char_utf8((*linep)->line + *charp);
+ if (txt_char_type(BLI_str_utf8_as_unicode(sym))==i) {
+ txt_move_left(text, sel);
+ count++;
+ } else break;
}
}
}
@@ -927,9 +1005,12 @@ void txt_jump_right(Text *text, short sel)
count= 0;
for (i=0; i<3; i++) {
if (count < 2) {
- while (*charp<(*linep)->len && txt_char_type((*linep)->line[*charp])==i) {
- txt_move_right(text, sel);
- count++;
+ while (*charp<(*linep)->len) {
+ char *sym= (*linep)->line + *charp;
+ if (txt_char_type(BLI_str_utf8_as_unicode(sym))==i) {
+ txt_move_right(text, sel);
+ count++;
+ } else break;
}
}
}
@@ -1014,6 +1095,7 @@ void txt_move_toline (Text *text, unsigned int line, short sel)
txt_move_to(text, line, 0, sel);
}
+/* Moves to a certain byte in a line, not a certain utf8-character! */
void txt_move_to (Text *text, unsigned int line, unsigned int ch, short sel)
{
TextLine **linep, *oldl;
@@ -1396,42 +1478,45 @@ static void txt_shift_markers(Text *text, int lineno, int count)
void txt_insert_buf(Text *text, const char *in_buffer)
{
- int i=0, l=0, j, u, len, lineno= -1, count= 0;
+ int l=0, u, len, lineno= -1, count= 0;
+ size_t i=0, j;
TextLine *add;
+ char *buffer;
if (!text) return;
if (!in_buffer) return;
txt_delete_sel(text);
- if(!undoing) txt_undo_add_block (text, UNDO_IBLOCK, in_buffer);
+ len= strlen(in_buffer);
+ buffer= BLI_strdupn(in_buffer, len);
+ len+= txt_extended_ascii_as_utf8(&buffer);
+
+ if(!undoing) txt_undo_add_block(text, UNDO_IBLOCK, buffer);
u= undoing;
undoing= 1;
/* Read the first line (or as close as possible */
- while (in_buffer[i] && in_buffer[i]!='\n') {
- txt_add_raw_char(text, in_buffer[i]);
- i++;
- }
+ while (buffer[i] && buffer[i]!='\n')
+ txt_add_raw_char(text, BLI_str_utf8_as_unicode_step(buffer, &i));
- if (in_buffer[i]=='\n') txt_split_curline(text);
- else { undoing = u; return; }
+ if (buffer[i]=='\n') txt_split_curline(text);
+ else { undoing = u; MEM_freeN(buffer); return; }
i++;
/* Read as many full lines as we can */
- len= strlen(in_buffer);
lineno= txt_get_span(text->lines.first, text->curl);
while (i<len) {
l=0;
- while (in_buffer[i] && in_buffer[i]!='\n') {
+ while (buffer[i] && buffer[i]!='\n') {
i++; l++;
}
- if(in_buffer[i]=='\n') {
- add= txt_new_linen(in_buffer +(i-l), l);
+ if(buffer[i]=='\n') {
+ add= txt_new_linen(buffer +(i-l), l);
BLI_insertlinkbefore(&text->lines, text->curl, add);
i++;
count++;
@@ -1441,21 +1526,19 @@ void txt_insert_buf(Text *text, const char *in_buffer)
count= 0;
}
- for (j= i-l; j<i && j<(int)strlen(in_buffer); j++) {
- txt_add_raw_char(text, in_buffer[j]);
- }
+ for (j= i-l; j<i && j<len; )
+ txt_add_raw_char(text, BLI_str_utf8_as_unicode_step(buffer, &j));
break;
}
}
+
+ MEM_freeN(buffer);
if(count) {
txt_shift_markers(text, lineno, count);
- count= 0;
}
undoing= u;
-
- (void)count;
}
/******************/
@@ -1525,12 +1608,30 @@ void txt_print_undo(Text *text)
ops= "Selection ";
} else if (op==UNDO_CTO) {
ops= "Cursor ";
- } else if (op==UNDO_INSERT) {
- ops= "Insert";
- } else if (op==UNDO_BS) {
- ops= "Backspace";
- } else if (op==UNDO_DEL) {
- ops= "Delete";
+ } else if (op==UNDO_INSERT_1) {
+ ops= "Insert ascii ";
+ } else if (op==UNDO_INSERT_2) {
+ ops= "Insert 2 bytes ";
+ } else if (op==UNDO_INSERT_3) {
+ ops= "Insert 3 bytes ";
+ } else if (op==UNDO_INSERT_4) {
+ ops= "Insert unicode ";
+ } else if (op==UNDO_BS_1) {
+ ops= "Backspace for ascii ";
+ } else if (op==UNDO_BS_2) {
+ ops= "Backspace for 2 bytes ";
+ } else if (op==UNDO_BS_3) {
+ ops= "Backspace for 3 bytes ";
+ } else if (op==UNDO_BS_4) {
+ ops= "Backspace for unicode ";
+ } else if (op==UNDO_DEL_1) {
+ ops= "Delete ascii ";
+ } else if (op==UNDO_DEL_2) {
+ ops= "Delete 2 bytes ";
+ } else if (op==UNDO_DEL_3) {
+ ops= "Delete 3 bytes ";
+ } else if (op==UNDO_DEL_4) {
+ ops= "Delete unicode ";
} else if (op==UNDO_SWAP) {
ops= "Cursor swap";
} else if (op==UNDO_DBLOCK) {
@@ -1550,10 +1651,35 @@ void txt_print_undo(Text *text)
}
printf ("Op (%o) at %d = %s", op, i, ops);
- if (op==UNDO_INSERT || op==UNDO_BS || op==UNDO_DEL) {
- i++;
- printf (" - Char is %c", text->undo_buf[i]);
+ if (op >= UNDO_INSERT_1 && op <= UNDO_DEL_4) {
i++;
+ printf (" - Char is ");
+ switch (op) {
+ case UNDO_INSERT_1: case UNDO_BS_1: case UNDO_DEL_1:
+ printf ("%c", text->undo_buf[i]);
+ i++;
+ break;
+ case UNDO_INSERT_2: case UNDO_BS_2: case UNDO_DEL_2:
+ printf ("%c%c", text->undo_buf[i], text->undo_buf[i+1]);
+ i+=2;
+ break;
+ case UNDO_INSERT_3: case UNDO_BS_3: case UNDO_DEL_3:
+ printf ("%c%c%c", text->undo_buf[i], text->undo_buf[i+1], text->undo_buf[i+2]);
+ i+=3;
+ break;
+ case UNDO_INSERT_4: case UNDO_BS_4: case UNDO_DEL_4: {
+ unsigned int uc;
+ char c[BLI_UTF8_MAX+1];
+ size_t c_len;
+ uc= text->undo_buf[i]; i++;
+ uc= uc+(text->undo_buf[i]<<8); i++;
+ uc= uc+(text->undo_buf[i]<<16); i++;
+ uc= uc+(text->undo_buf[i]<<24); i++;
+ c_len= BLI_str_utf8_from_unicode(uc, c);
+ c[c_len]= '\0';
+ printf ("%s", c);
+ }
+ }
} else if (op==UNDO_STO || op==UNDO_CTO) {
i++;
@@ -1635,40 +1761,43 @@ static void txt_undo_add_op(Text *text, int op)
text->undo_buf[text->undo_pos+1]= 0;
}
+static void txt_undo_store_uint16(char *undo_buf, int *undo_pos, unsigned short value)
+{
+ undo_buf[*undo_pos]= (value)&0xff;
+ (*undo_pos)++;
+ undo_buf[*undo_pos]= (value>>8)&0xff;
+ (*undo_pos)++;
+}
+
+static void txt_undo_store_uint32(char *undo_buf, int *undo_pos, unsigned int value)
+{
+ undo_buf[*undo_pos]= (value)&0xff;
+ (*undo_pos)++;
+ undo_buf[*undo_pos]= (value>>8)&0xff;
+ (*undo_pos)++;
+ undo_buf[*undo_pos]= (value>>16)&0xff;
+ (*undo_pos)++;
+ undo_buf[*undo_pos]= (value>>24)&0xff;
+ (*undo_pos)++;
+}
+
static void txt_undo_add_block(Text *text, int op, const char *buf)
{
- int length;
-
- length= strlen(buf);
+ unsigned int length= strlen(buf);
if(!max_undo_test(text, length+11))
return;
text->undo_pos++;
text->undo_buf[text->undo_pos]= op;
-
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (length)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (length>>8)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (length>>16)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (length>>24)&0xff;
-
text->undo_pos++;
+
+ txt_undo_store_uint32(text->undo_buf, &text->undo_pos, length);
+
strncpy(text->undo_buf+text->undo_pos, buf, length);
text->undo_pos+=length;
- text->undo_buf[text->undo_pos]= (length)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (length>>8)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (length>>16)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (length>>24)&0xff;
-
- text->undo_pos++;
+ txt_undo_store_uint32(text->undo_buf, &text->undo_pos, length);
text->undo_buf[text->undo_pos]= op;
text->undo_buf[text->undo_pos+1]= 0;
@@ -1685,51 +1814,143 @@ void txt_undo_add_toop(Text *text, int op, unsigned int froml, unsigned short fr
text->undo_buf[text->undo_pos]= op;
text->undo_pos++;
- text->undo_buf[text->undo_pos]= (fromc)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (fromc>>8)&0xff;
+
+ txt_undo_store_uint16(text->undo_buf, &text->undo_pos, fromc);
+ txt_undo_store_uint32(text->undo_buf, &text->undo_pos, froml);
+ txt_undo_store_uint16(text->undo_buf, &text->undo_pos, toc);
+ txt_undo_store_uint32(text->undo_buf, &text->undo_pos, tol);
+
+ text->undo_buf[text->undo_pos]= op;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (froml)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (froml>>8)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (froml>>16)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (froml>>24)&0xff;
+ text->undo_buf[text->undo_pos+1]= 0;
+}
+static void txt_undo_add_charop(Text *text, int op_start, unsigned int c)
+{
+ char utf8[BLI_UTF8_MAX];
+ size_t i, utf8_size = BLI_str_utf8_from_unicode(c, utf8);
+
+ if(!max_undo_test(text, 3 + utf8_size))
+ return;
+
text->undo_pos++;
- text->undo_buf[text->undo_pos]= (toc)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (toc>>8)&0xff;
+
+ if (utf8_size < 4) {
+ text->undo_buf[text->undo_pos]= op_start + utf8_size - 1;
+ text->undo_pos++;
+
+ for (i = 0; i < utf8_size; i++) {
+ text->undo_buf[text->undo_pos]= utf8[i];
+ text->undo_pos++;
+ }
+
+ text->undo_buf[text->undo_pos]= op_start + utf8_size - 1;
+ } else {
+ text->undo_buf[text->undo_pos]= op_start + 3;
+ text->undo_pos++;
+ txt_undo_store_uint32(text->undo_buf, &text->undo_pos, c);
+ text->undo_buf[text->undo_pos]= op_start + 3;
+ }
+
+ text->undo_buf[text->undo_pos+1]= 0;
+}
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (tol)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (tol>>8)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (tol>>16)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (tol>>24)&0xff;
+static unsigned short txt_undo_read_uint16(const char *undo_buf, int *undo_pos)
+{
+ unsigned short val;
+ val= undo_buf[*undo_pos]; (*undo_pos)--;
+ val= (val<<8)+undo_buf[*undo_pos]; (*undo_pos)--;
+ return val;
+}
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= op;
+static unsigned int txt_undo_read_uint32(const char *undo_buf, int *undo_pos)
+{
+ unsigned int val;
+ val= undo_buf[*undo_pos]; (*undo_pos)--;
+ val= (val<<8)+undo_buf[*undo_pos]; (*undo_pos)--;
+ val= (val<<8)+undo_buf[*undo_pos]; (*undo_pos)--;
+ val= (val<<8)+undo_buf[*undo_pos]; (*undo_pos)--;
+ return val;
+}
- text->undo_buf[text->undo_pos+1]= 0;
+static unsigned int txt_undo_read_unicode(const char *undo_buf, int *undo_pos, short bytes)
+{
+ unsigned int unicode;
+ char utf8[BLI_UTF8_MAX+1];
+
+ switch (bytes) {
+ case 1: /* ascii */
+ unicode = undo_buf[*undo_pos]; (*undo_pos)--;
+ break;
+ case 2: /* 2-byte symbol */
+ utf8[2] = '\0';
+ utf8[1] = undo_buf[*undo_pos]; (*undo_pos)--;
+ utf8[0] = undo_buf[*undo_pos]; (*undo_pos)--;
+ unicode= BLI_str_utf8_as_unicode(utf8);
+ break;
+ case 3: /* 3-byte symbol */
+ utf8[3] = '\0';
+ utf8[2] = undo_buf[*undo_pos]; (*undo_pos)--;
+ utf8[1] = undo_buf[*undo_pos]; (*undo_pos)--;
+ utf8[0] = undo_buf[*undo_pos]; (*undo_pos)--;
+ unicode= BLI_str_utf8_as_unicode(utf8);
+ break;
+ case 4: /* 32-bit unicode symbol */
+ unicode= txt_undo_read_uint32(undo_buf, undo_pos);
+ }
+
+ return unicode;
}
-static void txt_undo_add_charop(Text *text, int op, char c)
+static unsigned short txt_redo_read_uint16(const char *undo_buf, int *undo_pos)
{
- if(!max_undo_test(text, 4))
- return;
+ unsigned short val;
+ val = undo_buf[*undo_pos]; (*undo_pos)++;
+ val = val+(undo_buf[*undo_pos]<<8); (*undo_pos)++;
+ return val;
+}
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= op;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= c;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= op;
- text->undo_buf[text->undo_pos+1]= 0;
+static unsigned int txt_redo_read_uint32(const char *undo_buf, int *undo_pos)
+{
+ unsigned int val;
+ val= undo_buf[*undo_pos]; (*undo_pos)++;
+ val= val+(undo_buf[*undo_pos]<<8); (*undo_pos)++;
+ val= val+(undo_buf[*undo_pos]<<16); (*undo_pos)++;
+ val= val+(undo_buf[*undo_pos]<<24); (*undo_pos)++;
+ return val;
+}
+
+static unsigned int txt_redo_read_unicode(const char *undo_buf, int *undo_pos, short bytes)
+{
+ unsigned int unicode;
+ char utf8[BLI_UTF8_MAX+1];
+
+ switch (bytes) {
+ case 1: /* ascii */
+ unicode = undo_buf[*undo_pos]; (*undo_pos)++;
+ break;
+ case 2: /* 2-byte symbol */
+ utf8[0] = undo_buf[*undo_pos]; (*undo_pos)++;
+ utf8[1] = undo_buf[*undo_pos]; (*undo_pos)++;
+ utf8[2] = '\0';
+ unicode= BLI_str_utf8_as_unicode(utf8);
+ break;
+ case 3: /* 3-byte symbol */
+ utf8[0] = undo_buf[*undo_pos]; (*undo_pos)++;
+ utf8[1] = undo_buf[*undo_pos]; (*undo_pos)++;
+ utf8[2] = undo_buf[*undo_pos]; (*undo_pos)++;
+ utf8[3] = '\0';
+ unicode= BLI_str_utf8_as_unicode(utf8);
+ break;
+ case 4: /* 32-bit unicode symbol */
+ unicode= txt_undo_read_uint32(undo_buf, undo_pos);
+ default:
+ /* should never happen */
+ BLI_assert(0);
+ unicode= 0;
+ }
+
+ return unicode;
}
void txt_do_undo(Text *text)
@@ -1792,13 +2013,8 @@ void txt_do_undo(Text *text)
text->undo_pos--;
text->undo_pos--;
- linep= text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
-
- charp= text->undo_buf[text->undo_pos]; text->undo_pos--;
- charp= (charp<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
+ linep= txt_undo_read_uint32(text->undo_buf, &text->undo_pos);
+ charp= txt_undo_read_uint16(text->undo_buf, &text->undo_pos);
if (op==UNDO_CTO) {
txt_move_toline(text, linep, 0);
@@ -1812,23 +2028,23 @@ void txt_do_undo(Text *text)
text->undo_pos--;
break;
- case UNDO_INSERT:
+ case UNDO_INSERT_1: case UNDO_INSERT_2: case UNDO_INSERT_3: case UNDO_INSERT_4:
txt_backspace_char(text);
- text->undo_pos--;
+ text->undo_pos-= op - UNDO_INSERT_1 + 1;
text->undo_pos--;
break;
- case UNDO_BS:
- txt_add_char(text, text->undo_buf[text->undo_pos]);
+ case UNDO_BS_1: case UNDO_BS_2: case UNDO_BS_3: case UNDO_BS_4:
+ charp = op - UNDO_BS_1 + 1;
+ txt_add_char(text, txt_undo_read_unicode(text->undo_buf, &text->undo_pos, charp));
text->undo_pos--;
- text->undo_pos--;
- break;
-
- case UNDO_DEL:
- txt_add_char(text, text->undo_buf[text->undo_pos]);
+ break;
+
+ case UNDO_DEL_1: case UNDO_DEL_2: case UNDO_DEL_3: case UNDO_DEL_4:
+ charp = op - UNDO_DEL_1 + 1;
+ txt_add_char(text, txt_undo_read_unicode(text->undo_buf, &text->undo_pos, charp));
txt_move_left(text, 0);
text->undo_pos--;
- text->undo_pos--;
break;
case UNDO_SWAP:
@@ -1836,10 +2052,7 @@ void txt_do_undo(Text *text)
break;
case UNDO_DBLOCK:
- linep= text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
+ linep= txt_undo_read_uint32(text->undo_buf, &text->undo_pos);
buf= MEM_mallocN(linep+1, "dblock buffer");
for (i=0; i < linep; i++){
@@ -1863,25 +2076,31 @@ void txt_do_undo(Text *text)
}
text->curc= holdc;
- linep= text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
+ text->undo_pos--;
+ text->undo_pos--;
+ text->undo_pos--;
+ text->undo_pos--;
text->undo_pos--;
break;
case UNDO_IBLOCK:
- linep= text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
-
+ linep= txt_undo_read_uint32(text->undo_buf, &text->undo_pos);
txt_delete_sel(text);
+
+ /* txt_backspace_char removes utf8-characters, not bytes */
+ buf= MEM_mallocN(linep+1, "iblock buffer");
+ for (i=0; i < linep; i++){
+ buf[(linep-1)-i]= text->undo_buf[text->undo_pos];
+ text->undo_pos--;
+ }
+ buf[i]= 0;
+ linep= txt_utf8_len(buf);
+ MEM_freeN(buf);
+
while (linep>0) {
txt_backspace_char(text);
- text->undo_pos--;
linep--;
}
@@ -1897,30 +2116,23 @@ void txt_do_undo(Text *text)
case UNDO_UNINDENT:
case UNDO_COMMENT:
case UNDO_UNCOMMENT:
- linep= text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep = (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep = (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep = (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
+ linep= txt_undo_read_uint32(text->undo_buf, &text->undo_pos);
//linep is now the end line of the selection
- charp = text->undo_buf[text->undo_pos]; text->undo_pos--;
- charp = (charp<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
+ charp = txt_undo_read_uint16(text->undo_buf, &text->undo_pos);
//charp is the last char selected or text->line->len
- //set the selcetion for this now
+
+ //set the selection for this now
text->selc = charp;
text->sell = text->lines.first;
for (i= 0; i < linep; i++) {
text->sell = text->sell->next;
}
- linep= text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep = (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep = (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep = (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
+ linep= txt_undo_read_uint32(text->undo_buf, &text->undo_pos);
//first line to be selected
- charp = text->undo_buf[text->undo_pos]; text->undo_pos--;
- charp = (charp<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
+ charp = txt_undo_read_uint16(text->undo_buf, &text->undo_pos);
//first postion to be selected
text->curc = charp;
text->curl = text->lines.first;
@@ -2014,22 +2226,22 @@ void txt_do_redo(Text *text)
txt_move_down(text, 1);
break;
- case UNDO_INSERT:
- text->undo_pos++;
- txt_add_char(text, text->undo_buf[text->undo_pos]);
+ case UNDO_INSERT_1: case UNDO_INSERT_2: case UNDO_INSERT_3: case UNDO_INSERT_4:
text->undo_pos++;
+ charp = op - UNDO_INSERT_1 + 1;
+ txt_add_char(text, txt_redo_read_unicode(text->undo_buf, &text->undo_pos, charp));
break;
- case UNDO_BS:
+ case UNDO_BS_1: case UNDO_BS_2: case UNDO_BS_3: case UNDO_BS_4:
text->undo_pos++;
txt_backspace_char(text);
- text->undo_pos++;
+ text->undo_pos+= op - UNDO_BS_1 + 1;
break;
- case UNDO_DEL:
+ case UNDO_DEL_1: case UNDO_DEL_2: case UNDO_DEL_3: case UNDO_DEL_4:
text->undo_pos++;
txt_delete_char(text);
- text->undo_pos++;
+ text->undo_pos+= op - UNDO_DEL_1 + 1;
break;
case UNDO_SWAP:
@@ -2049,15 +2261,8 @@ void txt_do_redo(Text *text)
text->undo_pos++;
- charp= text->undo_buf[text->undo_pos];
- text->undo_pos++;
- charp= charp+(text->undo_buf[text->undo_pos]<<8);
-
- text->undo_pos++;
- linep= text->undo_buf[text->undo_pos]; text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<8); text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<16); text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<24); text->undo_pos++;
+ charp= txt_redo_read_uint16(text->undo_buf, &text->undo_pos);
+ linep= txt_redo_read_uint32(text->undo_buf, &text->undo_pos);
if (op==UNDO_CTO) {
txt_move_toline(text, linep, 0);
@@ -2072,12 +2277,9 @@ void txt_do_redo(Text *text)
case UNDO_DBLOCK:
text->undo_pos++;
- linep= text->undo_buf[text->undo_pos]; text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<8); text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<16); text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<24); text->undo_pos++;
-
+ linep= txt_redo_read_uint32(text->undo_buf, &text->undo_pos);
txt_delete_sel(text);
+
text->undo_pos+=linep;
text->undo_pos++;
@@ -2089,10 +2291,7 @@ void txt_do_redo(Text *text)
case UNDO_IBLOCK:
text->undo_pos++;
- linep= text->undo_buf[text->undo_pos]; text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<8); text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<16); text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<24); text->undo_pos++;
+ linep= txt_redo_read_uint32(text->undo_buf, &text->undo_pos);
buf= MEM_mallocN(linep+1, "iblock buffer");
memcpy (buf, &text->undo_buf[text->undo_pos], linep);
@@ -2102,26 +2301,21 @@ void txt_do_redo(Text *text)
txt_insert_buf(text, buf);
MEM_freeN(buf);
- linep= text->undo_buf[text->undo_pos]; text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<8); text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<16); text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<24); text->undo_pos++;
- (void)linep;
-
+ text->undo_pos++;
+ text->undo_pos++;
+ text->undo_pos++;
+ text->undo_pos++;
break;
+
case UNDO_INDENT:
case UNDO_UNINDENT:
case UNDO_COMMENT:
case UNDO_UNCOMMENT:
text->undo_pos++;
- charp = text->undo_buf[text->undo_pos]; text->undo_pos++;
- charp = charp+(text->undo_buf[text->undo_pos]<<8); text->undo_pos++;
+ charp = txt_redo_read_uint16(text->undo_buf, &text->undo_pos);
//charp is the first char selected or 0
- linep= text->undo_buf[text->undo_pos]; text->undo_pos++;
- linep = linep+(text->undo_buf[text->undo_pos]<<8); text->undo_pos++;
- linep = linep+(text->undo_buf[text->undo_pos]<<16); text->undo_pos++;
- linep = linep+(text->undo_buf[text->undo_pos]<<24); text->undo_pos++;
+ linep= txt_redo_read_uint32(text->undo_buf, &text->undo_pos);
//linep is now the first line of the selection
//set the selcetion for this now
text->curc = charp;
@@ -2130,13 +2324,10 @@ void txt_do_redo(Text *text)
text->curl = text->curl->next;
}
- charp = text->undo_buf[text->undo_pos]; text->undo_pos++;
- charp = charp+(text->undo_buf[text->undo_pos]<<8); text->undo_pos++;
+ charp = txt_redo_read_uint16(text->undo_buf, &text->undo_pos);
//last postion to be selected
- linep= text->undo_buf[text->undo_pos]; text->undo_pos++;
- linep = linep+(text->undo_buf[text->undo_pos]<<8); text->undo_pos++;
- linep = linep+(text->undo_buf[text->undo_pos]<<16); text->undo_pos++;
- linep = linep+(text->undo_buf[text->undo_pos]<<24); text->undo_pos++;
+
+ linep= txt_redo_read_uint32(text->undo_buf, &text->undo_pos);
//Last line to be selected
text->selc = charp;
@@ -2203,8 +2394,7 @@ void txt_split_curline (Text *text)
left[text->curc]=0;
right= MEM_mallocN(text->curl->len - text->curc+1, "textline_string");
- if (text->curl->len - text->curc) memcpy(right, text->curl->line+text->curc, text->curl->len-text->curc);
- right[text->curl->len - text->curc]=0;
+ memcpy(right, text->curl->line+text->curc, text->curl->len-text->curc+1);
MEM_freeN(text->curl->line);
if (text->curl->format) MEM_freeN(text->curl->format);
@@ -2228,7 +2418,7 @@ void txt_split_curline (Text *text)
txt_clean_text(text);
txt_pop_sel(text);
- if(!undoing) txt_undo_add_charop(text, UNDO_INSERT, '\n');
+ if(!undoing) txt_undo_add_charop(text, UNDO_INSERT_1, '\n');
}
static void txt_delete_line (Text *text, TextLine *line)
@@ -2296,9 +2486,9 @@ static void txt_combine_lines (Text *text, TextLine *linea, TextLine *lineb)
txt_clean_text(text);
}
-void txt_delete_char (Text *text)
+void txt_delete_char(Text *text)
{
- char c='\n';
+ unsigned int c='\n';
if (!text) return;
if (!text->curl) return;
@@ -2314,12 +2504,14 @@ void txt_delete_char (Text *text)
txt_pop_sel(text);
}
} else { /* Just deleting a char */
- int i= text->curc;
+ size_t c_len = 0;
+ TextMarker *mrk;
+ c= BLI_str_utf8_as_unicode_and_size(text->curl->line + text->curc, &c_len);
- TextMarker *mrk= txt_find_marker_region(text, text->curl, i-1, text->curl->len, 0, 0);
+ mrk= txt_find_marker_region(text, text->curl, text->curc - c_len, text->curl->len, 0, 0);
if (mrk) {
int lineno= mrk->lineno;
- if (mrk->end==i) {
+ if (mrk->end==text->curc) {
if ((mrk->flags & TMARK_TEMP) && !(mrk->flags & TMARK_EDITALL)) {
txt_clear_markers(text, mrk->group, TMARK_TEMP);
} else {
@@ -2328,18 +2520,15 @@ void txt_delete_char (Text *text)
return;
}
do {
- if (mrk->start>i) mrk->start--;
- mrk->end--;
+ if (mrk->start>text->curc) mrk->start-= c_len;
+ mrk->end-= c_len;
mrk= mrk->next;
} while (mrk && mrk->lineno==lineno);
}
- c= text->curl->line[i];
- while(i< text->curl->len) {
- text->curl->line[i]= text->curl->line[i+1];
- i++;
- }
- text->curl->len--;
+ memmove(text->curl->line+text->curc, text->curl->line+text->curc+c_len, text->curl->len-text->curc-c_len+1);
+
+ text->curl->len-= c_len;
txt_pop_sel(text);
}
@@ -2347,7 +2536,7 @@ void txt_delete_char (Text *text)
txt_make_dirty(text);
txt_clean_text(text);
- if(!undoing) txt_undo_add_charop(text, UNDO_DEL, c);
+ if(!undoing) txt_undo_add_charop(text, UNDO_DEL_1, c);
}
void txt_delete_word (Text *text)
@@ -2358,7 +2547,7 @@ void txt_delete_word (Text *text)
void txt_backspace_char (Text *text)
{
- char c='\n';
+ unsigned int c='\n';
if (!text) return;
if (!text->curl) return;
@@ -2378,12 +2567,15 @@ void txt_backspace_char (Text *text)
txt_pop_sel(text);
}
else { /* Just backspacing a char */
- int i= text->curc-1;
+ size_t c_len = 0;
+ TextMarker *mrk;
+ char *prev = BLI_str_prev_char_utf8(text->curl->line + text->curc);
+ c= BLI_str_utf8_as_unicode_and_size(prev, &c_len);
- TextMarker *mrk= txt_find_marker_region(text, text->curl, i, text->curl->len, 0, 0);
+ mrk= txt_find_marker_region(text, text->curl, text->curc - c_len, text->curl->len, 0, 0);
if (mrk) {
int lineno= mrk->lineno;
- if (mrk->start==i+1) {
+ if (mrk->start==text->curc) {
if ((mrk->flags & TMARK_TEMP) && !(mrk->flags & TMARK_EDITALL)) {
txt_clear_markers(text, mrk->group, TMARK_TEMP);
} else {
@@ -2392,19 +2584,16 @@ void txt_backspace_char (Text *text)
return;
}
do {
- if (mrk->start>i) mrk->start--;
- mrk->end--;
+ if (mrk->start>text->curc - c_len) mrk->start-= c_len;
+ mrk->end-= c_len;
mrk= mrk->next;
} while (mrk && mrk->lineno==lineno);
}
- c= text->curl->line[i];
- while(i< text->curl->len) {
- text->curl->line[i]= text->curl->line[i+1];
- i++;
- }
- text->curl->len--;
- text->curc--;
+ memcpy(text->curl->line + text->curc - c_len, text->curl->line + text->curc, text->curl->len-text->curc+1);
+
+ text->curl->len-= c_len;
+ text->curc-= c_len;
txt_pop_sel(text);
}
@@ -2412,7 +2601,7 @@ void txt_backspace_char (Text *text)
txt_make_dirty(text);
txt_clean_text(text);
- if(!undoing) txt_undo_add_charop(text, UNDO_BS, c);
+ if(!undoing) txt_undo_add_charop(text, UNDO_BS_1, c);
}
void txt_backspace_word (Text *text)
@@ -2436,11 +2625,12 @@ static void txt_convert_tab_to_spaces (Text *text)
txt_insert_buf(text, sb);
}
-static int txt_add_char_intern (Text *text, char add, int replace_tabs)
+static int txt_add_char_intern (Text *text, unsigned int add, int replace_tabs)
{
- int len, lineno;
- char *tmp;
+ int lineno;
+ char *tmp, ch[BLI_UTF8_MAX];
TextMarker *mrk;
+ size_t add_len;
if (!text) return 0;
if (!text->curl) return 0;
@@ -2458,43 +2648,42 @@ static int txt_add_char_intern (Text *text, char add, int replace_tabs)
txt_delete_sel(text);
+ add_len = BLI_str_utf8_from_unicode(add, ch);
mrk= txt_find_marker_region(text, text->curl, text->curc-1, text->curl->len, 0, 0);
if (mrk) {
lineno= mrk->lineno;
do {
- if (mrk->start>text->curc) mrk->start++;
- mrk->end++;
+ if (mrk->start>text->curc) mrk->start+= add_len;
+ mrk->end+= add_len;
mrk= mrk->next;
} while (mrk && mrk->lineno==lineno);
}
- tmp= MEM_mallocN(text->curl->len+2, "textline_string");
+ tmp= MEM_mallocN(text->curl->len+add_len+1, "textline_string");
- if(text->curc) memcpy(tmp, text->curl->line, text->curc);
- tmp[text->curc]= add;
-
- len= text->curl->len - text->curc;
- if(len>0) memcpy(tmp+text->curc+1, text->curl->line+text->curc, len);
- tmp[text->curl->len+1]=0;
+ memcpy(tmp, text->curl->line, text->curc);
+ memcpy(tmp+text->curc, ch, add_len);
+ memcpy(tmp+text->curc+add_len, text->curl->line+text->curc, text->curl->len-text->curc+1);
+
make_new_line(text->curl, tmp);
- text->curc++;
+ text->curc+= add_len;
txt_pop_sel(text);
txt_make_dirty(text);
txt_clean_text(text);
- if(!undoing) txt_undo_add_charop(text, UNDO_INSERT, add);
+ if(!undoing) txt_undo_add_charop(text, UNDO_INSERT_1, add);
return 1;
}
-int txt_add_char (Text *text, char add)
+int txt_add_char (Text *text, unsigned int add)
{
return txt_add_char_intern(text, add, text->flags & TXT_TABSTOSPACES);
}
-int txt_add_raw_char (Text *text, char add)
+int txt_add_raw_char (Text *text, unsigned int add)
{
return txt_add_char_intern(text, add, 0);
}
@@ -2505,34 +2694,48 @@ void txt_delete_selected(Text *text)
txt_make_dirty(text);
}
-int txt_replace_char (Text *text, char add)
+int txt_replace_char (Text *text, unsigned int add)
{
- char del;
+ unsigned int del;
+ size_t del_size = 0, add_size;
+ char ch[BLI_UTF8_MAX];
if (!text) return 0;
if (!text->curl) return 0;
/* If text is selected or we're at the end of the line just use txt_add_char */
if (text->curc==text->curl->len || txt_has_sel(text) || add=='\n') {
- TextMarker *mrk;
int i= txt_add_char(text, add);
- mrk= txt_find_marker(text, text->curl, text->curc, 0, 0);
- if (mrk && mrk->end==text->curc) mrk->end--;
+ TextMarker *mrk= txt_find_marker(text, text->curl, text->curc, 0, 0);
+ if (mrk) BLI_freelinkN(&text->markers, mrk);
return i;
}
- del= text->curl->line[text->curc];
- text->curl->line[text->curc]= (unsigned char) add;
- text->curc++;
- txt_pop_sel(text);
+ del= BLI_str_utf8_as_unicode_and_size(text->curl->line + text->curc, &del_size);
+ add_size= BLI_str_utf8_from_unicode(add, ch);
+ if (add_size > del_size) {
+ char *tmp= MEM_mallocN(text->curl->len+add_size-del_size+1, "textline_string");
+ memcpy(tmp, text->curl->line, text->curc);
+ memcpy(tmp+text->curc+add_size, text->curl->line+text->curc+del_size, text->curl->len-text->curc-del_size+1);
+ MEM_freeN(text->curl->line);
+ text->curl->line = tmp;
+ } else if (add_size < del_size) {
+ char *tmp= text->curl->line;
+ memmove(tmp+text->curc+add_size, tmp+text->curc+del_size, text->curl->len-text->curc-del_size+1);
+ }
+
+ memcpy(text->curl->line + text->curc, ch, add_size);
+ text->curc+= add_size;
+
+ txt_pop_sel(text);
txt_make_dirty(text);
txt_clean_text(text);
/* Should probably create a new op for this */
if(!undoing) {
- txt_undo_add_charop(text, UNDO_DEL, del);
- txt_undo_add_charop(text, UNDO_INSERT, add);
+ txt_undo_add_charop(text, UNDO_DEL_1, del);
+ txt_undo_add_charop(text, UNDO_INSERT_1, add);
}
return 1;
}
@@ -2548,15 +2751,19 @@ void txt_indent(Text *text)
/* hardcoded: TXT_TABSIZE = 4 spaces: */
int spaceslen = TXT_TABSIZE;
+ if (ELEM3(NULL, text, text->curl, text->sell)) {
+ return;
+ }
+
+ if (!text) return;
+ if (!text->curl) return;
+ if (!text->sell) return;
+
/* insert spaces rather than tabs */
if (text->flags & TXT_TABSTOSPACES){
add = tab_to_spaces;
indentlen = spaceslen;
}
-
- if (!text) return;
- if (!text->curl) return;
- if (!text->sell) return;
num = 0;
while (TRUE)
@@ -2609,16 +2816,16 @@ void txt_unindent(Text *text)
/* hardcoded: TXT_TABSIZE = 4 spaces: */
int spaceslen = TXT_TABSIZE;
+ if (!text) return;
+ if (!text->curl) return;
+ if (!text->sell) return;
+
/* insert spaces rather than tabs */
if (text->flags & TXT_TABSTOSPACES){
remove = tab_to_spaces;
indent = spaceslen;
}
- if (!text) return;
- if (!text->curl) return;
- if (!text->sell) return;
-
while(TRUE)
{
int i = 0;
diff --git a/source/blender/blenlib/BLI_math_color.h b/source/blender/blenlib/BLI_math_color.h
index 6d37aabd6ab..f4d6882b5d8 100644
--- a/source/blender/blenlib/BLI_math_color.h
+++ b/source/blender/blenlib/BLI_math_color.h
@@ -91,6 +91,9 @@ MINLINE void linearrgb_to_srgb_v4(float srgb[4], const float linear[4]);
MINLINE void srgb_to_linearrgb_predivide_v4(float linear[4], const float srgb[4]);
MINLINE void linearrgb_to_srgb_predivide_v4(float srgb[4], const float linear[4]);
+MINLINE void linearrgb_to_srgb_uchar3(unsigned char srgb[3], const float linear[3]);
+MINLINE void linearrgb_to_srgb_uchar4(unsigned char srgb[4], const float linear[4]);
+
void BLI_init_srgb_conversion(void);
/************************** Other *************************/
@@ -101,8 +104,10 @@ void minmax_rgb(short c[3]);
void rgb_float_set_hue_float_offset(float * rgb, float hue_offset);
void rgb_byte_set_hue_float_offset(unsigned char * rgb, float hue_offset);
-void rgb_byte_to_float(const unsigned char in[3], float out[3]);
-void rgb_float_to_byte(const float in[3], unsigned char out[3]);
+void rgb_uchar_to_float(float col_r[3], const unsigned char col_ub[3]);
+void rgba_uchar_to_float(float col_r[4], const unsigned char col_ub[4]);
+void rgb_float_to_uchar(unsigned char col_r[3], const float col_f[3]);
+void rgba_float_to_uchar(unsigned char col_r[4], const float col_f[4]);
/***************** lift/gamma/gain / ASC-CDL conversion *****************/
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index 27da6c1025d..8d18f5253c4 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -54,6 +54,8 @@ float area_tri_v3(const float a[3], const float b[3], const float c[3]);
float area_quad_v3(const float a[3], const float b[3], const float c[3], const float d[3]);
float area_poly_v3(int nr, float verts[][3], const float normal[3]);
+int is_quad_convex_v3(const float *v1, const float *v2, const float *v3, const float *v4);
+
/********************************* Distance **********************************/
float dist_to_line_v2(const float p[2], const float l1[2], const float l2[2]);
@@ -221,6 +223,9 @@ void accumulate_vertex_normals(float n1[3], float n2[3], float n3[3],
float n4[3], const float f_no[3], const float co1[3], const float co2[3],
const float co3[3], const float co4[3]);
+void accumulate_vertex_normals_poly(float **vertnos, float polyno[3],
+ float **vertcos, float vdiffs[][3], int nverts);
+
/********************************* Tangents **********************************/
typedef struct VertexTangent {
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index e9e44ed7b2c..12a0b1892a1 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -116,9 +116,10 @@ MINLINE void star_m3_v3(float rmat[3][3],float a[3]);
/*********************************** Length **********************************/
+MINLINE float len_squared_v2(const float v[2]);
MINLINE float len_v2(const float a[2]);
MINLINE float len_v2v2(const float a[2], const float b[2]);
-MINLINE float len_squared_v2v2(const float a[3], const float b[3]);
+MINLINE float len_squared_v2v2(const float a[2], const float b[2]);
MINLINE float len_v3(const float a[3]);
MINLINE float len_v3v3(const float a[3], const float b[3]);
MINLINE float len_squared_v3v3(const float a[3], const float b[3]);
@@ -170,6 +171,7 @@ float angle_v3v3v3(const float a[3], const float b[3], const float c[3]);
float angle_normalized_v3v3(const float v1[3], const float v2[3]);
void angle_tri_v3(float angles[3], const float v1[3], const float v2[3], const float v3[3]);
void angle_quad_v3(float angles[4], const float v1[3], const float v2[3], const float v3[3], const float v4[3]);
+void angle_poly_v3(float* angles, const float* verts[3], int len);
/********************************* Geometry **********************************/
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c
index 9f388b68c38..e10082348be 100644
--- a/source/blender/blenlib/intern/BLI_ghash.c
+++ b/source/blender/blenlib/intern/BLI_ghash.c
@@ -40,8 +40,8 @@
// #include "BLI_blenlib.h"
-#include "BLI_mempool.h"
#include "BLI_utildefines.h"
+#include "BLI_mempool.h"
#include "BLI_ghash.h"
#include "BLO_sys_types.h" // for intptr_t support
diff --git a/source/blender/blenlib/intern/boxpack2d.c b/source/blender/blenlib/intern/boxpack2d.c
index 073b4b5d0c6..cf18fbd57cd 100644
--- a/source/blender/blenlib/intern/boxpack2d.c
+++ b/source/blender/blenlib/intern/boxpack2d.c
@@ -390,7 +390,7 @@ void boxPack2D(boxPack *boxarray, const int len, float *tot_width, float *tot_he
} else if ( vert->trb && vert->brb &&
(box == vert->trb || box == vert->brb) ) {
if (vert->trb->w > vert->brb->w) {
- vert->brb->v[TR]->free &= ~(TRF|TRF);
+ vert->brb->v[TR]->free &= ~(TLF|TRF);
} else if (vert->trb->w < vert->brb->w) {
vert->trb->v[BR]->free &= ~(BLF|BRF);
} else { /*same*/
diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c
index 20df893015d..ca2aeca8f36 100644
--- a/source/blender/blenlib/intern/math_color.c
+++ b/source/blender/blenlib/intern/math_color.c
@@ -337,24 +337,29 @@ void cpack_to_rgb(unsigned int col, float *r, float *g, float *b)
*b /= 255.0f;
}
-void rgb_byte_to_float(const unsigned char in[3], float out[3])
+void rgb_uchar_to_float(float col_r[3], const unsigned char col_ub[3])
{
- out[0]= ((float)in[0]) / 255.0f;
- out[1]= ((float)in[1]) / 255.0f;
- out[2]= ((float)in[2]) / 255.0f;
+ col_r[0]= ((float)col_ub[0]) / 255.0f;
+ col_r[1]= ((float)col_ub[1]) / 255.0f;
+ col_r[2]= ((float)col_ub[2]) / 255.0f;
}
-void rgb_float_to_byte(const float in[3], unsigned char out[3])
+void rgba_uchar_to_float(float col_r[4], const unsigned char col_ub[4])
{
- int r, g, b;
-
- r= (int)(in[0] * 255.0f);
- g= (int)(in[1] * 255.0f);
- b= (int)(in[2] * 255.0f);
-
- out[0]= (char)((r <= 0)? 0 : (r >= 255)? 255 : r);
- out[1]= (char)((g <= 0)? 0 : (g >= 255)? 255 : g);
- out[2]= (char)((b <= 0)? 0 : (b >= 255)? 255 : b);
+ col_r[0]= ((float)col_ub[0]) / 255.0f;
+ col_r[1]= ((float)col_ub[1]) / 255.0f;
+ col_r[2]= ((float)col_ub[2]) / 255.0f;
+ col_r[3]= ((float)col_ub[3]) / 255.0f;
+}
+
+void rgb_float_to_uchar(unsigned char col_r[3], const float col_f[3])
+{
+ F3TOCHAR3(col_f, col_r);
+}
+
+void rgba_float_to_uchar(unsigned char col_r[4], const float col_f[4])
+{
+ F4TOCHAR4(col_f, col_r);
}
/* ********************************* color transforms ********************************* */
@@ -490,9 +495,9 @@ void rgb_byte_set_hue_float_offset(unsigned char rgb[3], float hue_offset)
{
float rgb_float[3];
- rgb_byte_to_float(rgb, rgb_float);
+ rgb_uchar_to_float(rgb_float, rgb);
rgb_float_set_hue_float_offset(rgb_float, hue_offset);
- rgb_float_to_byte(rgb_float, rgb);
+ rgb_float_to_uchar(rgb, rgb_float);
}
diff --git a/source/blender/blenlib/intern/math_color_inline.c b/source/blender/blenlib/intern/math_color_inline.c
index 1247632cf79..386452ed592 100644
--- a/source/blender/blenlib/intern/math_color_inline.c
+++ b/source/blender/blenlib/intern/math_color_inline.c
@@ -62,6 +62,22 @@ MINLINE void linearrgb_to_srgb_v4(float srgb[4], const float linear[4])
srgb[3] = linear[3];
}
+MINLINE void linearrgb_to_srgb_uchar3(unsigned char srgb[3], const float linear[3])
+{
+ float srgb_f[3];
+
+ linearrgb_to_srgb_v3_v3(srgb_f, linear);
+ F3TOCHAR3(srgb_f, srgb);
+}
+
+MINLINE void linearrgb_to_srgb_uchar4(unsigned char srgb[4], const float linear[4])
+{
+ float srgb_f[4];
+
+ linearrgb_to_srgb_v4(srgb_f, linear);
+ F4TOCHAR4(srgb_f, srgb);
+}
+
/* predivide versions to work on associated/premultipled alpha. if this should
be done or not depends on the background the image will be composited over,
ideally you would never do color space conversion on an image with alpha
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index ef04e5e9bce..d7880e40626 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -2382,6 +2382,38 @@ void accumulate_vertex_normals(float n1[3], float n2[3], float n3[3],
}
}
+/* Add weighted face normal component into normals of the face vertices.
+ Caller must pass pre-allocated vdiffs of nverts length. */
+void accumulate_vertex_normals_poly(float **vertnos, float polyno[3],
+ float **vertcos, float vdiffs[][3], int nverts)
+{
+ int i;
+
+ /* calculate normalized edge directions for each edge in the poly */
+ for (i = 0; i < nverts; i++) {
+ sub_v3_v3v3(vdiffs[i], vertcos[(i+1) % nverts], vertcos[i]);
+ normalize_v3(vdiffs[i]);
+ }
+
+ /* accumulate angle weighted face normal */
+ {
+ const float *prev_edge = vdiffs[nverts-1];
+ int i;
+
+ for(i=0; i<nverts; i++) {
+ const float *cur_edge = vdiffs[i];
+
+ /* calculate angle between the two poly edges incident on
+ this vertex */
+ const float fac= saacos(-dot_v3v3(cur_edge, prev_edge));
+
+ /* accumulate */
+ madd_v3_v3fl(vertnos[i], polyno, fac);
+ prev_edge = cur_edge;
+ }
+ }
+}
+
/********************************* Tangents **********************************/
/* For normal map tangents we need to detect uv boundaries, and only average
@@ -3038,3 +3070,26 @@ float form_factor_hemi_poly(float p[3], float n[3], float v1[3], float v2[3], fl
return contrib;
}
+
+/* evaluate if entire quad is a proper convex quad */
+ int is_quad_convex_v3(const float *v1, const float *v2, const float *v3, const float *v4)
+ {
+ float nor[3], nor1[3], nor2[3], vec[4][2];
+ int axis_a, axis_b;
+
+ /* define projection, do both trias apart, quad is undefined! */
+ normal_tri_v3(nor1, v1, v2, v3);
+ normal_tri_v3(nor2, v1, v3, v4);
+ add_v3_v3v3(nor, nor1, nor2);
+
+ axis_dominant_v3(&axis_a, &axis_b, nor);
+
+ vec[0][0]= v1[axis_a]; vec[0][1]= v1[axis_b];
+ vec[1][0]= v2[axis_a]; vec[1][1]= v2[axis_b];
+
+ vec[2][0]= v3[axis_a]; vec[2][1]= v3[axis_b];
+ vec[3][0]= v4[axis_a]; vec[3][1]= v4[axis_b];
+
+ /* linetests, the 2 diagonals have to instersect to be convex */
+ return (isect_line_line_v2(vec[0], vec[2], vec[1], vec[3]) > 0) ? 1 : 0;
+}
diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c
index 5596b6f9f22..b0e6fe51810 100644
--- a/source/blender/blenlib/intern/math_rotation.c
+++ b/source/blender/blenlib/intern/math_rotation.c
@@ -811,7 +811,7 @@ void single_axis_angle_to_mat3(float mat[3][3], const char axis, const float ang
mat[2][2] = 1.0f;
break;
default:
- assert("invalid axis");
+ assert(0);
}
}
diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c
index 590a48e8085..47deb705def 100644
--- a/source/blender/blenlib/intern/math_vector.c
+++ b/source/blender/blenlib/intern/math_vector.c
@@ -239,6 +239,20 @@ void angle_quad_v3(float angles[4], const float v1[3], const float v2[3], const
angles[3]= (float)M_PI - angle_normalized_v3v3(ed4, ed1);
}
+void angle_poly_v3(float *angles, const float *verts[3], int len)
+{
+ int i;
+ float vec[3][3];
+
+ sub_v3_v3v3(vec[2], verts[len-1], verts[0]);
+ normalize_v3(vec[2]);
+ for (i = 0; i < len; i++) {
+ sub_v3_v3v3(vec[i%3], verts[i%len], verts[(i+1)%len]);
+ normalize_v3(vec[i%3]);
+ angles[i] = (float)M_PI - angle_normalized_v3v3(vec[(i+2)%3], vec[i%3]);
+ }
+}
+
/********************************* Geometry **********************************/
/* Project v1 on v2 */
diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c
index 4570bd5e99e..9c5d8f3261f 100644
--- a/source/blender/blenlib/intern/math_vector_inline.c
+++ b/source/blender/blenlib/intern/math_vector_inline.c
@@ -429,6 +429,11 @@ MINLINE void star_m3_v3(float rmat[][3], float a[3])
/*********************************** Length **********************************/
+MINLINE float len_squared_v2(const float v[2])
+{
+ return v[0]*v[0] + v[1]*v[1];
+}
+
MINLINE float len_v2(const float v[2])
{
return (float)sqrtf(v[0]*v[0] + v[1]*v[1]);
@@ -448,7 +453,7 @@ MINLINE float len_v3(const float a[3])
return sqrtf(dot_v3v3(a, a));
}
-MINLINE float len_squared_v2v2(const float a[3], const float b[3])
+MINLINE float len_squared_v2v2(const float a[2], const float b[2])
{
float d[2];
@@ -510,6 +515,29 @@ MINLINE float normalize_v3_v3(float r[3], const float a[3])
return d;
}
+MINLINE double normalize_v3_d(double n[3])
+{
+ double d= n[0]*n[0] + n[1]*n[1] + n[2]*n[2];
+
+ /* a larger value causes normalize errors in a
+ scaled down models with camera xtreme close */
+ if(d > 1.0e-35) {
+ double mul;
+
+ d= sqrt(d);
+ mul = 1.0 / d;
+
+ n[0] *= mul;
+ n[1] *= mul;
+ n[2] *= mul;
+ } else {
+ n[0] = n[1] = n[2] = 0;
+ d= 0.0;
+ }
+
+ return d;
+}
+
MINLINE float normalize_v3(float n[3])
{
return normalize_v3_v3(n, n);
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h
index 38925ea5238..d63baca883e 100644
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@ -65,7 +65,7 @@ typedef struct BlendFileData {
int fileflags;
int displaymode;
int globalf;
- char filename[240]; /* 240 = FILE_MAX */
+ char filename[1024]; /* 1024 = FILE_MAX */
struct bScreen* curscreen;
struct Scene* curscene;
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index fffe6a737a4..b28fba06ef2 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -98,9 +98,9 @@
#include "MEM_guardedalloc.h"
+#include "BLI_utildefines.h"
#include "BLI_blenlib.h"
#include "BLI_math.h"
-#include "BLI_utildefines.h"
#include "BKE_anim.h"
#include "BKE_action.h"
@@ -136,6 +136,7 @@
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_sequencer.h"
+#include "BKE_text.h" // for txt_extended_ascii_as_utf8
#include "BKE_texture.h" // for open_plugin_tex
#include "BKE_tracking.h"
#include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND
@@ -4716,7 +4717,7 @@ static void lib_link_scene(FileData *fd, Main *main)
link_paint(fd, sce, &sce->toolsettings->vpaint->paint);
link_paint(fd, sce, &sce->toolsettings->wpaint->paint);
link_paint(fd, sce, &sce->toolsettings->imapaint.paint);
-
+ link_paint(fd, sce, &sce->toolsettings->uvsculpt->paint);
sce->toolsettings->skgen_template = newlibadr(fd, sce->id.lib, sce->toolsettings->skgen_template);
for(base= sce->base.first; base; base= next) {
@@ -4851,6 +4852,7 @@ static void direct_link_scene(FileData *fd, Scene *sce)
direct_link_paint(fd, (Paint**)&sce->toolsettings->sculpt);
direct_link_paint(fd, (Paint**)&sce->toolsettings->vpaint);
direct_link_paint(fd, (Paint**)&sce->toolsettings->wpaint);
+ direct_link_paint(fd, (Paint**)&sce->toolsettings->uvsculpt);
sce->toolsettings->imapaint.paintcursor= NULL;
sce->toolsettings->particle.paintcursor= NULL;
@@ -13162,6 +13164,49 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
}
}
}
+
+ if (main->versionfile < 261 || (main->versionfile == 261 && main->subversionfile < 3))
+ {
+ {
+ /* convert extended ascii to utf-8 for text editor */
+ Text *text;
+ for (text= main->text.first; text; text= text->id.next)
+ if(!(text->flags & TXT_ISEXT)) {
+ TextLine *tl;
+
+ for (tl= text->lines.first; tl; tl= tl->next) {
+ int added= txt_extended_ascii_as_utf8(&tl->line);
+ tl->len+= added;
+
+ /* reset cursor position if line was changed */
+ if (added && tl == text->curl)
+ text->curc = 0;
+ }
+ }
+ }
+ {
+ /* set new dynamic paint values */
+ Object *ob;
+ for(ob = main->object.first; ob; ob = ob->id.next) {
+ ModifierData *md;
+ for(md= ob->modifiers.first; md; md= md->next) {
+ if (md->type == eModifierType_DynamicPaint) {
+ DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md;
+ if(pmd->canvas)
+ {
+ DynamicPaintSurface *surface = pmd->canvas->surfaces.first;
+ for (; surface; surface=surface->next) {
+ surface->color_dry_threshold = 1.0f;
+ surface->influence_scale = 1.0f;
+ surface->radius_scale = 1.0f;
+ surface->flags |= MOD_DPAINT_USE_DRYING;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
/* put compatibility code here until next subversion bump */
{
@@ -14679,7 +14724,7 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
/* allow typing in a new lib path */
if(G.rt==-666) {
while(fd==NULL) {
- char newlib_path[240] = { 0 };
+ char newlib_path[FILE_MAX] = { 0 };
printf("Missing library...'\n");
printf(" current file: %s\n", G.main->name);
printf(" absolute lib: %s\n", mainptr->curlib->filepath);
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 015b74e5a7d..5eb7034ed65 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -89,6 +89,9 @@ Any case: direct data is ALWAYS after the lib block
#include "BLI_winstuff.h"
#endif
+/* allow writefile to use deprecated functionality (for forward compatibility code) */
+#define DNA_DEPRECATED_ALLOW
+
#include "DNA_anim_types.h"
#include "DNA_armature_types.h"
#include "DNA_actuator_types.h"
@@ -654,7 +657,7 @@ static void write_node_socket(WriteData *wd, bNodeSocket *sock)
/* forward compatibility code, so older blenders still open */
sock->stack_type = 1;
-
+
if(sock->default_value) {
bNodeSocketValueFloat *valfloat;
bNodeSocketValueVector *valvector;
@@ -1966,6 +1969,9 @@ static void write_scenes(WriteData *wd, ListBase *scebase)
if(tos->sculpt) {
writestruct(wd, DATA, "Sculpt", 1, tos->sculpt);
}
+ if(tos->uvsculpt) {
+ writestruct(wd, DATA, "UvSculpt", 1, tos->uvsculpt);
+ }
// write_paint(wd, &tos->imapaint.paint);
diff --git a/source/blender/blenpluginapi/iff.h b/source/blender/blenpluginapi/iff.h
index 6bd4e5bb2b0..f07e80b36ce 100644
--- a/source/blender/blenpluginapi/iff.h
+++ b/source/blender/blenpluginapi/iff.h
@@ -63,7 +63,7 @@ typedef struct ImBuf {
int channels; /**< amount of channels in rect_float (0 = 4 channel default) */
float dither; /**< random dither value, for conversion from float -> byte rect */
short profile; /** color space/profile preset that the byte rect buffer represents */
- char profile_filename[256]; /** to be implemented properly, specific filename for custom profiles */
+ char profile_filename[1024]; /** to be implemented properly, specific filename for custom profiles */
/* mipmapping */
struct ImBuf *mipmap[IB_MIPMAP_LEVELS]; /**< MipMap levels, a series of halved images */
diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c
index eab71323494..e6be35c48a7 100644
--- a/source/blender/editors/animation/anim_channels_defines.c
+++ b/source/blender/editors/animation/anim_channels_defines.c
@@ -187,7 +187,7 @@ static void acf_generic_channel_color(bAnimContext *ac, bAnimListElem *ale, floa
}
/* copy the colors over, transforming from bytes to floats */
- rgb_byte_to_float(cp, color);
+ rgb_uchar_to_float(color, cp);
}
else {
// FIXME: what happens when the indention is 1 greater than what it should be (due to grouping)?
diff --git a/source/blender/editors/animation/anim_channels_edit.c b/source/blender/editors/animation/anim_channels_edit.c
index 32021447d6a..9122bc277d9 100644
--- a/source/blender/editors/animation/anim_channels_edit.c
+++ b/source/blender/editors/animation/anim_channels_edit.c
@@ -2429,20 +2429,21 @@ void ED_operatortypes_animchannels(void)
void ED_keymap_animchannels(wmKeyConfig *keyconf)
{
wmKeyMap *keymap = WM_keymap_find(keyconf, "Animation Channels", 0, 0);
-
+ wmKeyMapItem *kmi;
+
/* selection */
/* click-select */
// XXX for now, only leftmouse....
WM_keymap_add_item(keymap, "ANIM_OT_channels_click", LEFTMOUSE, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_click", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1);
- RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_click", LEFTMOUSE, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "children_only", 1);
+ RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_click", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", TRUE);
+ RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_click", LEFTMOUSE, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "children_only", TRUE);
/* rename */
WM_keymap_add_item(keymap, "ANIM_OT_channels_rename", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
/* deselect all */
WM_keymap_add_item(keymap, "ANIM_OT_channels_select_all_toggle", AKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_select_all_toggle", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "invert", 1);
+ RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_select_all_toggle", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "invert", TRUE);
/* borderselect */
WM_keymap_add_item(keymap, "ANIM_OT_channels_select_border", BKEY, KM_PRESS, 0, 0);
@@ -2464,9 +2465,11 @@ void ED_keymap_animchannels(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "ANIM_OT_channels_expand", PADPLUSKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "ANIM_OT_channels_collapse", PADMINUS, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_expand", PADPLUSKEY, KM_PRESS, KM_CTRL, 0)->ptr, "all", 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_collapse", PADMINUS, KM_PRESS, KM_CTRL, 0)->ptr, "all", 0);
-
+ kmi = WM_keymap_add_item(keymap, "ANIM_OT_channels_expand", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
+ RNA_boolean_set(kmi->ptr, "all", FALSE);
+ kmi = WM_keymap_add_item(keymap, "ANIM_OT_channels_collapse", PADMINUS, KM_PRESS, KM_CTRL, 0);
+ RNA_boolean_set(kmi->ptr, "all", FALSE);
+
/* rearranging */
RNA_enum_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_move", PAGEUPKEY, KM_PRESS, 0, 0)->ptr, "direction", REARRANGE_ANIMCHAN_UP);
RNA_enum_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_move", PAGEDOWNKEY, KM_PRESS, 0, 0)->ptr, "direction", REARRANGE_ANIMCHAN_DOWN);
diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c
index cc1fae170d0..216bb8d0e08 100644
--- a/source/blender/editors/animation/anim_markers.c
+++ b/source/blender/editors/animation/anim_markers.c
@@ -1490,15 +1490,17 @@ void ED_marker_keymap(wmKeyConfig *keyconf)
WM_keymap_verify_item(keymap, "MARKER_OT_move", EVT_TWEAK_S, KM_ANY, 0, 0);
WM_keymap_verify_item(keymap, "MARKER_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_verify_item(keymap, "MARKER_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "MARKER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1);
+ kmi = WM_keymap_add_item(keymap, "MARKER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
#ifdef DURIAN_CAMERA_SWITCH
kmi= WM_keymap_add_item(keymap, "MARKER_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
- RNA_boolean_set(kmi->ptr, "camera", 1);
+ RNA_boolean_set(kmi->ptr, "extend", FALSE);
+ RNA_boolean_set(kmi->ptr, "camera", TRUE);
kmi= WM_keymap_add_item(keymap, "MARKER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
- RNA_boolean_set(kmi->ptr, "extend", 1);
- RNA_boolean_set(kmi->ptr, "camera", 1);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
+ RNA_boolean_set(kmi->ptr, "camera", TRUE);
#else
(void)kmi;
#endif
diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c
index 54314980e03..84206c4275e 100644
--- a/source/blender/editors/animation/keyframing.c
+++ b/source/blender/editors/animation/keyframing.c
@@ -1200,7 +1200,7 @@ static int insert_key_menu_invoke (bContext *C, wmOperator *op, wmEvent *UNUSED(
else {
/* just call the exec() on the active keyingset */
RNA_enum_set(op->ptr, "type", 0);
- RNA_boolean_set(op->ptr, "confirm_success", 1);
+ RNA_boolean_set(op->ptr, "confirm_success", TRUE);
return op->type->exec(C, op);
}
diff --git a/source/blender/editors/armature/armature_ops.c b/source/blender/editors/armature/armature_ops.c
index 81482466a30..7379a278d01 100644
--- a/source/blender/editors/armature/armature_ops.c
+++ b/source/blender/editors/armature/armature_ops.c
@@ -182,7 +182,7 @@ void ED_operatormacros_armature(void)
if(ot) {
ot->description= "Create new bones from the selected joints and move them";
otmacro=WM_operatortype_macro_define(ot, "ARMATURE_OT_extrude");
- RNA_boolean_set(otmacro->ptr, "forked", 0);
+ RNA_boolean_set(otmacro->ptr, "forked", FALSE);
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_enum_set(otmacro->ptr, "proportional", 0);
}
@@ -193,7 +193,7 @@ void ED_operatormacros_armature(void)
if(ot) {
ot->description= "Create new bones from the selected joints and move them";
otmacro=WM_operatortype_macro_define(ot, "ARMATURE_OT_extrude");
- RNA_boolean_set(otmacro->ptr, "forked", 1);
+ RNA_boolean_set(otmacro->ptr, "forked", TRUE);
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_enum_set(otmacro->ptr, "proportional", 0);
}
@@ -220,16 +220,17 @@ void ED_keymap_armature(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "SKETCH_OT_gesture", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "SKETCH_OT_draw_stroke", LEFTMOUSE, KM_PRESS, 0, 0);
kmi = WM_keymap_add_item(keymap, "SKETCH_OT_draw_stroke", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
- RNA_boolean_set(kmi->ptr, "snap", 1);
+ RNA_boolean_set(kmi->ptr, "snap", TRUE);
WM_keymap_add_item(keymap, "SKETCH_OT_draw_preview", MOUSEMOVE, KM_ANY, 0, 0);
kmi = WM_keymap_add_item(keymap, "SKETCH_OT_draw_preview", MOUSEMOVE, KM_ANY, KM_CTRL, 0);
- RNA_boolean_set(kmi->ptr, "snap", 1);
+ RNA_boolean_set(kmi->ptr, "snap", TRUE);
/* only set in editmode armature, by space_view3d listener */
kmi = WM_keymap_add_item(keymap, "ARMATURE_OT_hide", HKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(kmi->ptr, "unselected", FALSE);
+ RNA_boolean_set(kmi->ptr, "unselected", FALSE);
kmi= WM_keymap_add_item(keymap, "ARMATURE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_boolean_set(kmi->ptr, "unselected", TRUE);
+ RNA_boolean_set(kmi->ptr, "unselected", TRUE);
+
WM_keymap_add_item(keymap, "ARMATURE_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "ARMATURE_OT_align", AKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
WM_keymap_add_item(keymap, "ARMATURE_OT_calculate_roll", NKEY, KM_PRESS, KM_CTRL, 0);
@@ -304,9 +305,11 @@ void ED_keymap_armature(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "OBJECT_OT_parent_set", PKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_menu(keymap, "INFO_MT_add", AKEY, KM_PRESS, KM_SHIFT, 0);
- WM_keymap_add_item(keymap, "POSE_OT_hide", HKEY, KM_PRESS, 0, 0);
- kmi= WM_keymap_add_item(keymap, "POSE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_boolean_set(kmi->ptr, "unselected", 1);
+ kmi = WM_keymap_add_item(keymap, "POSE_OT_hide", HKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", FALSE);
+ kmi = WM_keymap_add_item(keymap, "POSE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", TRUE);
+
WM_keymap_add_item(keymap, "POSE_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_menu(keymap, "VIEW3D_MT_pose_apply", AKEY, KM_PRESS, KM_CTRL, 0);
@@ -321,9 +324,11 @@ void ED_keymap_armature(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "POSE_OT_rotation_mode_set", RKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "POSE_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "POSE_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
+ kmi = WM_keymap_add_item(keymap, "POSE_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
+ RNA_boolean_set(kmi->ptr, "flipped", FALSE);
+
kmi= WM_keymap_add_item(keymap, "POSE_OT_paste", VKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
- RNA_boolean_set(kmi->ptr, "flipped", 1);
+ RNA_boolean_set(kmi->ptr, "flipped", TRUE);
kmi = WM_keymap_add_item(keymap, "POSE_OT_select_all", AKEY, KM_PRESS, 0, 0);
RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
diff --git a/source/blender/editors/armature/editarmature_retarget.c b/source/blender/editors/armature/editarmature_retarget.c
index 9ec27b69835..a8978a0bbde 100644
--- a/source/blender/editors/armature/editarmature_retarget.c
+++ b/source/blender/editors/armature/editarmature_retarget.c
@@ -450,7 +450,7 @@ static void renameTemplateBone(char *name, char *template_name, ListBase *editbo
{
int i, j;
- for (i = 0, j = 0; template_name[i] != '\0' && i < (MAXBONENAME-1) && j < (MAXBONENAME-1); i++)
+ for (i = 0, j = 0; i < (MAXBONENAME-1) && j < (MAXBONENAME-1) && template_name[i] != '\0'; i++)
{
if (template_name[i] == '&')
{
diff --git a/source/blender/editors/curve/curve_ops.c b/source/blender/editors/curve/curve_ops.c
index 60fca7ae4bd..b213f797d47 100644
--- a/source/blender/editors/curve/curve_ops.c
+++ b/source/blender/editors/curve/curve_ops.c
@@ -145,14 +145,14 @@ void ED_operatormacros_curve(void)
WM_operatortype_macro_define(ot, "CURVE_OT_duplicate");
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_enum_set(otmacro->ptr, "proportional", 0);
- RNA_boolean_set(otmacro->ptr, "mirror", 0);
+ RNA_boolean_set(otmacro->ptr, "mirror", FALSE);
ot= WM_operatortype_append_macro("CURVE_OT_extrude_move", "Extrude Curve and Move", OPTYPE_UNDO|OPTYPE_REGISTER);
ot->description = "Extrude curve and move result";
WM_operatortype_macro_define(ot, "CURVE_OT_extrude");
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_enum_set(otmacro->ptr, "proportional", 0);
- RNA_boolean_set(otmacro->ptr, "mirror", 0);
+ RNA_boolean_set(otmacro->ptr, "mirror", FALSE);
}
void ED_keymap_curve(wmKeyConfig *keyconf)
@@ -210,7 +210,8 @@ void ED_keymap_curve(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "FONT_OT_line_break", RETKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "FONT_OT_text_insert", KM_TEXTINPUT, KM_ANY, KM_ANY, 0); // last!
- RNA_boolean_set(WM_keymap_add_item(keymap, "FONT_OT_text_insert", BACKSPACEKEY, KM_PRESS, KM_ALT, 0)->ptr, "accent", 1); // accented characters
+ kmi = WM_keymap_add_item(keymap, "FONT_OT_text_insert", BACKSPACEKEY, KM_PRESS, KM_ALT, 0);
+ RNA_boolean_set(kmi->ptr, "accent", TRUE); /* accented characters */
/* only set in editmode curve, by space_view3d listener */
keymap= WM_keymap_find(keyconf, "Curve", 0, 0);
@@ -231,8 +232,11 @@ void ED_keymap_curve(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "CURVE_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "CURVE_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "CURVE_OT_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "CURVE_OT_select_linked_pick", LKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "CURVE_OT_select_linked_pick", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "deselect", 1);
+
+ kmi = WM_keymap_add_item(keymap, "CURVE_OT_select_linked_pick", LKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "deselect", FALSE);
+ kmi = WM_keymap_add_item(keymap, "CURVE_OT_select_linked_pick", LKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "deselect", TRUE);
WM_keymap_add_item(keymap, "CURVE_OT_separate", PKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "CURVE_OT_extrude_move", EKEY, KM_PRESS, 0, 0);
@@ -248,8 +252,10 @@ void ED_keymap_curve(wmKeyConfig *keyconf)
RNA_enum_set(WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, KM_ALT, 0)->ptr, "mode", TFM_CURVE_SHRINKFATTEN);
WM_keymap_add_item(keymap, "CURVE_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0);
- WM_keymap_add_item(keymap, "CURVE_OT_hide", HKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "CURVE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1);
+ kmi = WM_keymap_add_item(keymap, "CURVE_OT_hide", HKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", FALSE);
+ kmi = WM_keymap_add_item(keymap, "CURVE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", TRUE);
WM_keymap_add_item(keymap, "OBJECT_OT_vertex_parent_set", PKEY, KM_PRESS, KM_CTRL, 0);
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index 150e0ba90e4..954c79bb17d 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -55,7 +55,8 @@ void ED_keymap_gpencil(wmKeyConfig *keyconf)
/* Draw */
/* draw */
- WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, 0, DKEY);
+ kmi=WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, 0, DKEY);
+ RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_DRAW);
/* draw - straight lines */
kmi=WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, KM_CTRL, DKEY);
RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_DRAW_STRAIGHT);
diff --git a/source/blender/editors/include/ED_image.h b/source/blender/editors/include/ED_image.h
index 957b58b141c..05cde05f25c 100644
--- a/source/blender/editors/include/ED_image.h
+++ b/source/blender/editors/include/ED_image.h
@@ -53,6 +53,7 @@ void ED_space_image_zoom(struct SpaceImage *sima, struct ARegion *ar, float *zoo
void ED_space_image_uv_aspect(struct SpaceImage *sima, float *aspx, float *aspy);
void ED_space_image_paint_update(struct wmWindowManager *wm, struct ToolSettings *settings);
+void ED_space_image_uv_sculpt_update(struct wmWindowManager *wm, struct ToolSettings *settings);
void ED_image_size(struct Image *ima, int *width, int *height);
void ED_image_aspect(struct Image *ima, float *aspx, float *aspy);
@@ -66,8 +67,8 @@ int ED_space_image_show_uvshadow(struct SpaceImage *sima, struct Object *obedit)
/* UI level image (texture) updating... render calls own stuff (too) */
void ED_image_update_frame(const struct Main *mainp, int cfra);
-void ED_image_draw_info(struct ARegion *ar, int color_manage, int channels,
- int x, int y, const char cp[4], const float fp[4], int *zp, float *zpf);
+void ED_image_draw_info(struct ARegion *ar, int color_manage, int channels, int x, int y,
+ const unsigned char cp[4], const float fp[4], int *zp, float *zpf);
#endif /* ED_IMAGE_H */
diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h
index 6b374274205..160e3eea6cc 100644
--- a/source/blender/editors/include/ED_mesh.h
+++ b/source/blender/editors/include/ED_mesh.h
@@ -155,6 +155,9 @@ struct UvVertMap *EM_make_uv_vert_map(struct EditMesh *em, int selected, int do_
struct UvMapVert *EM_get_uv_map_vert(struct UvVertMap *vmap, unsigned int v);
void EM_free_uv_vert_map(struct UvVertMap *vmap);
+struct UvElementMap *EM_make_uv_element_map(struct EditMesh *em, int selected, int doIslands);
+void EM_free_uv_element_map(struct UvElementMap *vmap);
+
void EM_add_data_layer(struct EditMesh *em, struct CustomData *data, int type, const char *name);
void EM_free_data_layer(struct EditMesh *em, struct CustomData *data, int type);
@@ -232,6 +235,10 @@ void ED_mesh_faces_add(struct Mesh *mesh, struct ReportList *reports, int count)
void ED_mesh_edges_add(struct Mesh *mesh, struct ReportList *reports, int count);
void ED_mesh_vertices_add(struct Mesh *mesh, struct ReportList *reports, int count);
+void ED_mesh_faces_remove(struct Mesh *mesh, struct ReportList *reports, int count);
+void ED_mesh_edges_remove(struct Mesh *mesh, struct ReportList *reports, int count);
+void ED_mesh_vertices_remove(struct Mesh *mesh, struct ReportList *reports, int count);
+
void ED_mesh_transform(struct Mesh *me, float *mat);
void ED_mesh_calc_normals(struct Mesh *me);
void ED_mesh_material_link(struct Mesh *me, struct Material *ma);
diff --git a/source/blender/editors/include/ED_uvedit.h b/source/blender/editors/include/ED_uvedit.h
index 0666884351a..bc8a12c97cc 100644
--- a/source/blender/editors/include/ED_uvedit.h
+++ b/source/blender/editors/include/ED_uvedit.h
@@ -81,7 +81,7 @@ void ED_uvedit_live_unwrap_end(short cancel);
void ED_unwrap_lscm(struct Scene *scene, struct Object *obedit, const short sel);
/* uvedit_draw.c */
-void draw_uvedit_main(struct SpaceImage *sima, struct ARegion *ar, struct Scene *scene, struct Object *obedit);
+void draw_uvedit_main(struct SpaceImage *sima, struct ARegion *ar, struct Scene *scene, struct Object *obedit, struct Object *obact);
/* uvedit_buttons.c */
void ED_uvedit_buttons_register(struct ARegionType *art);
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index 2148b0d04a6..f087cdc7442 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -279,10 +279,10 @@ void ED_view3d_draw_offscreen(struct Scene *scene, struct View3D *v3d, struct AR
int winx, int winy, float viewmat[][4], float winmat[][4]);
struct ImBuf *ED_view3d_draw_offscreen_imbuf(struct Scene *scene, struct View3D *v3d, struct ARegion *ar, int sizex, int sizey, unsigned int flag, char err_out[256]);
-struct ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Scene *scene, struct Object *camera, int width, int height, unsigned int flag, int drawtype, char err_out[256]);
+struct ImBuf *ED_view3d_draw_offscreen_imbuf_simple(struct Scene *scene, struct Object *camera, int width, int height, unsigned int flag, int drawtype, char err_out[256]);
-Base *ED_view3d_give_base_under_cursor(struct bContext *C, const int mval[2]);
+struct Base *ED_view3d_give_base_under_cursor(struct bContext *C, const int mval[2]);
void ED_view3d_quadview_update(struct ScrArea *sa, struct ARegion *ar, short do_clip);
int ED_view3d_lock(struct RegionView3D *rv3d);
diff --git a/source/blender/editors/include/UI_interface_icons.h b/source/blender/editors/include/UI_interface_icons.h
index e9c213dec35..e5ad51169a8 100644
--- a/source/blender/editors/include/UI_interface_icons.h
+++ b/source/blender/editors/include/UI_interface_icons.h
@@ -41,7 +41,7 @@ struct Material;
typedef struct IconFile {
struct IconFile *next, *prev;
- char filename[80]; // FILE_MAXFILE size
+ char filename[256]; // FILE_MAXFILE size
int index;
} IconFile;
diff --git a/source/blender/editors/include/UI_resources.h b/source/blender/editors/include/UI_resources.h
index 683d35daf66..75aa996088f 100644
--- a/source/blender/editors/include/UI_resources.h
+++ b/source/blender/editors/include/UI_resources.h
@@ -45,79 +45,10 @@ typedef enum {
} BIFIconID;
#define BIFICONID_FIRST (ICON_NONE)
-#define BIFNICONIDS (BIFICONID_LAST-BIFICONID_FIRST + 1)
#undef DEF_ICON
#undef DEF_VICO
-
-typedef enum {
-#define BIFCOLORSHADE_FIRST (COLORSHADE_DARK)
- COLORSHADE_DARK,
- COLORSHADE_GREY,
- COLORSHADE_MEDIUM,
- COLORSHADE_HILITE,
- COLORSHADE_LIGHT,
- COLORSHADE_WHITE
-#define BIFCOLORSHADE_LAST (COLORSHADE_WHITE)
-#define BIFNCOLORSHADES (BIFCOLORSHADE_LAST-BIFCOLORSHADE_FIRST + 1)
-} BIFColorShade;
-
-typedef enum {
-#define BIFCOLORID_FIRST (BUTGREY)
- BUTGREY = 0,
- BUTGREEN,
- BUTBLUE,
- BUTSALMON,
- MIDGREY,
- BUTPURPLE,
- BUTYELLOW,
- REDALERT,
- BUTRUST,
- BUTWHITE,
- BUTDBLUE,
- BUTPINK,
- BUTDPINK,
- BUTMACTIVE,
-
- BUTIPO,
- BUTAUDIO,
- BUTCAMERA,
- BUTRANDOM,
- BUTEDITOBJECT,
- BUTPROPERTY,
- BUTSCENE,
- BUTMOTION,
- BUTMESSAGE,
- BUTACTION,
- BUTCD,
- BUTGAME,
- BUTVISIBILITY,
- BUTYUCK,
- BUTSEASICK,
- BUTCHOKE,
- BUTIMPERIAL,
-
- BUTTEXTCOLOR,
- BUTTEXTPRESSED,
- BUTSBACKGROUND,
-
- VIEWPORTBACKCOLOR,
- VIEWPORTGRIDCOLOR,
- VIEWPORTACTIVECOLOR,
- VIEWPORTSELECTEDCOLOR,
- VIEWPORTUNSELCOLOR,
-
- EDITVERTSEL,
- EDITVERTUNSEL,
- EDITEDGESEL,
- EDITEDGEUNSEL
-
-#define BIFCOLORID_LAST (EDITEDGEUNSEL)
-#define BIFNCOLORIDS (BIFCOLORID_LAST-BIFCOLORID_FIRST + 1)
-
-} BIFColorID;
-
enum {
TH_REDALERT,
@@ -256,6 +187,14 @@ enum {
TH_PATH_AFTER,
TH_CAMERA_PATH,
TH_LOCK_MARKER,
+
+ TH_STITCH_PREVIEW_FACE,
+ TH_STITCH_PREVIEW_EDGE,
+ TH_STITCH_PREVIEW_VERT,
+ TH_STITCH_PREVIEW_STITCHABLE,
+ TH_STITCH_PREVIEW_UNSTITCHABLE,
+ TH_STITCH_PREVIEW_ACTIVE,
+
TH_FREESTYLE_EDGE_MARK,
TH_FREESTYLE_FACE_MARK
};
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 7ff69277843..c112918833e 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -1693,10 +1693,15 @@ static int ui_set_but_string_eval_num_unit(bContext *C, uiBut *but, const char *
return (BPY_button_exec(C, str_unit_convert, value, TRUE) != -1);
}
-static int ui_set_but_string_eval_num(bContext *C, uiBut *but, const char *str, double *value)
+#endif /* WITH_PYTHON */
+
+
+int ui_set_but_string_eval_num(bContext *C, uiBut *but, const char *str, double *value)
{
int ok= FALSE;
+#ifdef WITH_PYTHON
+
if(str[0] != '\0') {
int is_unit_but= ui_is_but_unit(but);
/* only enable verbose if we won't run again with units */
@@ -1718,10 +1723,16 @@ static int ui_set_but_string_eval_num(bContext *C, uiBut *but, const char *str,
}
}
+#else /* WITH_PYTHON */
+
+ value= atof(str);
+ ok = TRUE;
+
+#endif /* WITH_PYTHON */
+
return ok;
}
-#endif // WITH_PYTHON
int ui_set_but_string(bContext *C, uiBut *but, const char *str)
{
@@ -1788,13 +1799,9 @@ int ui_set_but_string(bContext *C, uiBut *but, const char *str)
/* number editing */
double value;
-#ifdef WITH_PYTHON
if(ui_set_but_string_eval_num(C, but, str, &value) == FALSE) {
return 0;
}
-#else
- value= atof(str);
-#endif // WITH_PYTHON
if(!ui_is_but_float(but)) value= (int)floor(value + 0.5);
if(but->type==NUMABS) value= fabs(value);
@@ -1939,21 +1946,32 @@ static void ui_free_but(const bContext *C, uiBut *but)
WM_operator_properties_free(but->opptr);
MEM_freeN(but->opptr);
}
- if(but->func_argN) MEM_freeN(but->func_argN);
+
+ if(but->func_argN) {
+ MEM_freeN(but->func_argN);
+ }
+
if(but->active) {
/* XXX solve later, buttons should be free-able without context ideally,
* however they may have open tooltips or popup windows, which need to
* be closed using a context pointer */
- if(C)
+ if (C) {
ui_button_active_free(C, but);
- else
- if(but->active)
+ }
+ else {
+ if(but->active) {
MEM_freeN(but->active);
+ }
+ }
+ }
+ if (but->str && but->str != but->strdata) {
+ MEM_freeN(but->str);
}
- if(but->str && but->str != but->strdata) MEM_freeN(but->str);
ui_free_link(but->link);
- if((but->type == BUT_IMAGE) && but->poin) IMB_freeImBuf((struct ImBuf *)but->poin);
+ if ((but->type == BUT_IMAGE) && but->poin) {
+ IMB_freeImBuf((struct ImBuf *)but->poin);
+ }
MEM_freeN(but);
}
@@ -1968,11 +1986,13 @@ void uiFreeBlock(const bContext *C, uiBlock *block)
ui_free_but(C, but);
}
- if(block->unit)
+ if (block->unit) {
MEM_freeN(block->unit);
+ }
- if(block->func_argN)
+ if (block->func_argN) {
MEM_freeN(block->func_argN);
+ }
CTX_store_free_list(&block->contexts);
@@ -2639,8 +2659,9 @@ static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *s
str= BLI_dynstr_get_cstring(dynstr);
BLI_dynstr_free(dynstr);
- if(free)
+ if (free) {
MEM_freeN(item);
+ }
freestr= 1;
}
@@ -2656,10 +2677,12 @@ static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *s
}
}
- if(!str)
- str= RNA_property_ui_name(prop);
- if(free)
+ if (!str) {
+ str = RNA_property_ui_name(prop);
+ }
+ if (free) {
MEM_freeN(item);
+ }
}
else {
str= RNA_property_ui_name(prop);
@@ -2739,9 +2762,10 @@ static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *s
but->a1= ui_get_but_step_unit(but, but->a1);
}
- if(freestr)
+ if (freestr) {
MEM_freeN((void *)str);
-
+ }
+
return but;
}
@@ -3353,8 +3377,9 @@ void uiBlockSetFunc(uiBlock *block, uiButHandleFunc func, void *arg1, void *arg2
void uiBlockSetNFunc(uiBlock *block, uiButHandleFunc func, void *argN, void *arg2)
{
- if(block->func_argN)
+ if (block->func_argN) {
MEM_freeN(block->func_argN);
+ }
block->funcN= func;
block->func_argN= argN;
@@ -3383,8 +3408,9 @@ void uiButSetFunc(uiBut *but, uiButHandleFunc func, void *arg1, void *arg2)
void uiButSetNFunc(uiBut *but, uiButHandleNFunc funcN, void *argN, void *arg2)
{
- if(but->func_argN)
+ if (but->func_argN) {
MEM_freeN(but->func_argN);
+ }
but->funcN= funcN;
but->func_argN= argN;
@@ -3422,8 +3448,9 @@ uiBut *uiDefBlockButN(uiBlock *block, uiBlockCreateFunc func, void *argN, const
{
uiBut *but= ui_def_but(block, BLOCK, 0, str, x1, y1, x2, y2, NULL, 0.0, 0.0, 0.0, 0.0, tip);
but->block_create_func= func;
- if(but->func_argN)
+ if (but->func_argN) {
MEM_freeN(but->func_argN);
+ }
but->func_argN= argN;
ui_check_but(but);
return but;
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 3a19bb2a90c..311f0f87b50 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -1115,8 +1115,7 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
{
static ColorBand but_copypaste_coba = {0};
char buf[UI_MAX_DRAW_STR+1]= {0};
- double val;
-
+
if(mode=='v' && but->lock)
return;
@@ -1140,17 +1139,16 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
if(but->poin==NULL && but->rnapoin.data==NULL);
else if(mode=='c') {
- if(ui_is_but_float(but))
- BLI_snprintf(buf, sizeof(buf), "%f", ui_get_but_val(but));
- else
- BLI_snprintf(buf, sizeof(buf), "%d", (int)ui_get_but_val(but));
-
+ ui_get_but_string(but, buf, sizeof(buf));
WM_clipboard_text_set(buf, 0);
}
else {
- if (sscanf(buf, " %lf ", &val) == 1) {
+ double val;
+
+ if (ui_set_but_string_eval_num(C, but, buf, &val)) {
button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
data->value= val;
+ ui_set_but_string(C, but, buf);
button_activate_state(C, but, BUTTON_STATE_EXIT);
}
}
@@ -1703,8 +1701,9 @@ static int ui_textedit_copypaste(uiBut *but, uiHandleButtonData *data, int paste
changed= 1;
}
- if(pbuf)
+ if (pbuf) {
MEM_freeN(pbuf);
+ }
}
/* cut & copy */
else if (copy || cut) {
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index a7d8c688f43..3feda5d4db4 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -665,7 +665,9 @@ static void init_iconfile_list(struct ListBase *list)
for(; i>=0; i--){
MEM_freeN(dir[i].relname);
MEM_freeN(dir[i].path);
- if (dir[i].string) MEM_freeN(dir[i].string);
+ if (dir[i].string) {
+ MEM_freeN(dir[i].string);
+ }
}
free(dir);
dir= NULL;
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index e31d7e39d89..2980b28d522 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -163,7 +163,7 @@ struct uiBut {
float hardmin, hardmax, softmin, softmax;
float a1, a2;
float aspect;
- char col[4];
+ unsigned char col[4];
uiButHandleFunc func;
void *func_arg1;
@@ -356,6 +356,7 @@ extern void ui_get_but_string(uiBut *but, char *str, size_t maxlen);
extern void ui_convert_to_unit_alt_name(uiBut *but, char *str, size_t maxlen);
extern int ui_set_but_string(struct bContext *C, uiBut *but, const char *str);
extern int ui_get_but_string_max_length(uiBut *but);
+extern int ui_set_but_string_eval_num(struct bContext *C, uiBut *but, const char *str, double *value);
extern void ui_set_but_default(struct bContext *C, short all);
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index a01efa25d19..eb55cf912d6 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -320,7 +320,7 @@ static void ui_layer_but_cb(bContext *C, void *arg_but, void *arg_index)
int len= RNA_property_array_length(ptr, prop);
if(!shift) {
- RNA_property_boolean_set_index(ptr, prop, index, 1);
+ RNA_property_boolean_set_index(ptr, prop, index, TRUE);
for(i=0; i<len; i++)
if(i != index)
@@ -499,8 +499,9 @@ static void ui_item_enum_expand(uiLayout *layout, uiBlock *block, PointerRNA *pt
}
uiBlockSetCurLayout(block, layout);
- if(free)
+ if (free) {
MEM_freeN(item);
+ }
}
/* callback for keymap item change button */
@@ -705,12 +706,15 @@ static const char *ui_menu_enumpropname(uiLayout *layout, const char *opname, co
RNA_property_enum_items_gettexted(layout->root->block->evil_C, &ptr, prop, &item, &totitem, &free);
if(RNA_enum_name(item, retval, &name)) {
- if(free) MEM_freeN(item);
+ if (free) {
+ MEM_freeN(item);
+ }
return name;
}
- if(free)
+ if (free) {
MEM_freeN(item);
+ }
}
return "";
@@ -792,8 +796,9 @@ void uiItemsFullEnumO(uiLayout *layout, const char *opname, const char *propname
}
}
- if(free)
+ if (free) {
MEM_freeN(item);
+ }
}
}
@@ -845,13 +850,16 @@ void uiItemEnumO_string(uiLayout *layout, const char *name, int icon, const char
if((prop= RNA_struct_find_property(&ptr, propname))) {
RNA_property_enum_items_gettexted(layout->root->block->evil_C, &ptr, prop, &item, NULL, &free);
if(item==NULL || RNA_enum_value_from_id(item, value_str, &value)==0) {
- if(free) MEM_freeN(item);
+ if(free) {
+ MEM_freeN(item);
+ }
RNA_warning("%s.%s, enum %s not found", RNA_struct_identifier(ptr.type), propname, value_str);
return;
}
- if(free)
+ if (free) {
MEM_freeN(item);
+ }
}
else {
RNA_warning("%s.%s not found", RNA_struct_identifier(ptr.type), propname);
@@ -1096,7 +1104,9 @@ void uiItemEnumR_string(uiLayout *layout, struct PointerRNA *ptr, const char *pr
RNA_property_enum_items_gettexted(layout->root->block->evil_C, ptr, prop, &item, NULL, &free);
if(!RNA_enum_value_from_id(item, value, &ivalue)) {
- if(free) MEM_freeN(item);
+ if (free) {
+ MEM_freeN(item);
+ }
ui_item_disabled(layout, propname);
RNA_warning("enum property value not found: %s", value);
return;
@@ -1109,8 +1119,9 @@ void uiItemEnumR_string(uiLayout *layout, struct PointerRNA *ptr, const char *pr
}
}
- if(free)
+ if (free) {
MEM_freeN(item);
+ }
}
void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propname)
@@ -1160,8 +1171,9 @@ void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propname
}
}
- if(free)
+ if (free) {
MEM_freeN(item);
+ }
}
}
@@ -2731,8 +2743,9 @@ const char *uiLayoutIntrospect(uiLayout *layout)
{
DynStr *ds= BLI_dynstr_new();
- if(str)
+ if (str) {
MEM_freeN(str);
+ }
ui_intro_uiLayout(ds, layout);
@@ -2783,7 +2796,7 @@ void uiLayoutOperatorButs(const bContext *C, uiLayout *layout, wmOperator *op,in
WM_operator_properties_create(&op_ptr, "WM_OT_operator_preset_add");
RNA_string_set(&op_ptr, "operator", op->type->idname);
- RNA_boolean_set(&op_ptr, "remove_active", 1);
+ RNA_boolean_set(&op_ptr, "remove_active", TRUE);
op_ptr= uiItemFullO(row, "WM_OT_operator_preset_add", "", ICON_ZOOMOUT, op_ptr.data, WM_OP_INVOKE_DEFAULT, 0);
}
diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c
index b50df29918d..40cf0213203 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -494,7 +494,7 @@ struct uiEditSourceStore {
} uiEditSourceStore;
struct uiEditSourceButStore {
- char py_dbg_fn[240];
+ char py_dbg_fn[FILE_MAX];
int py_dbg_ln;
} uiEditSourceButStore;
@@ -584,7 +584,7 @@ void UI_editsource_active_but_test(uiBut *but)
/* editsource operator component */
static int editsource_text_edit(bContext *C, wmOperator *op,
- char filepath[240], int line)
+ char filepath[FILE_MAX], int line)
{
struct Main *bmain= CTX_data_main(C);
Text *text;
diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c
index c21bc09ff27..d802c8640b8 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -772,8 +772,9 @@ static int uiAlignPanelStep(ScrArea *sa, ARegion *ar, float fac, int drag)
ui_panel_copy_offset(pa, pa->paneltab);
/* free panelsort array */
- for(ps= panelsort, a=0; a<tot; a++, ps++)
+ for (ps = panelsort, a = 0; a < tot; a++, ps++) {
MEM_freeN(ps->pa);
+ }
MEM_freeN(panelsort);
return done;
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c
index 0c5aed83c1b..8e336a363df 100644
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@ -138,8 +138,9 @@ static void menudata_add_item(MenuData *md, const char *str, int retval, int ico
static void menudata_free(MenuData *md)
{
MEM_freeN((void *)md->instr);
- if (md->items)
+ if (md->items) {
MEM_freeN(md->items);
+ }
MEM_freeN(md);
}
@@ -394,8 +395,9 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
}
}
- if(free)
+ if (free) {
MEM_freeN(item);
+ }
}
}
@@ -982,8 +984,9 @@ static void ui_searchbox_region_free_cb(ARegion *ar)
int a;
/* free search data */
- for(a=0; a<data->items.maxitem; a++)
+ for (a = 0; a < data->items.maxitem; a++) {
MEM_freeN(data->items.names[a]);
+ }
MEM_freeN(data->items.names);
MEM_freeN(data->items.pointers);
MEM_freeN(data->items.icons);
@@ -1182,8 +1185,9 @@ void ui_but_search_test(uiBut *but)
uiButSetFlag(but, UI_BUT_REDALERT);
}
- for(x1=0; x1<items->maxitem; x1++)
+ for (x1 = 0; x1 < items->maxitem; x1++) {
MEM_freeN(items->names[x1]);
+ }
MEM_freeN(items->names);
MEM_freeN(items);
}
@@ -1611,6 +1615,7 @@ static void ui_block_func_MENUSTR(bContext *UNUSED(C), uiLayout *layout, void *a
MenuEntry *entry;
const char *instr= arg_str;
int columns, rows, a, b;
+ int column_start= 0, column_end= 0;
uiBlockSetFlag(block, UI_BLOCK_MOVEMOUSE_QUIT);
@@ -1654,17 +1659,30 @@ static void ui_block_func_MENUSTR(bContext *UNUSED(C), uiLayout *layout, void *a
/* create items */
split= uiLayoutSplit(layout, 0, 0);
- for(a=0, b=0; a<md->nitems; a++, b++) {
+ for(a=0; a<md->nitems; a++) {
+ if(a == column_end) {
+ /* start new column, and find out where it ends in advance, so we
+ can flip the order of items properly per column */
+ column_start= a;
+ column_end= md->nitems;
+
+ for(b=a+1; b<md->nitems; b++) {
+ entry= &md->items[b];
+
+ /* new column on N rows or on separation label */
+ if(((b-a) % rows == 0) || (entry->sepr && entry->str[0])) {
+ column_end = b;
+ break;
+ }
+ }
+
+ column= uiLayoutColumn(split, 0);
+ }
+
if(block->flag & UI_BLOCK_NO_FLIP)
entry= &md->items[a];
else
- entry= &md->items[md->nitems-a-1];
-
- /* new column on N rows or on separation label */
- if((b % rows == 0) || (entry->sepr && entry->str[0])) {
- column= uiLayoutColumn(split, 0);
- b= 0;
- }
+ entry= &md->items[column_start + column_end-1-a];
if(entry->sepr) {
uiItemL(column, entry->str, entry->icon);
@@ -2460,7 +2478,7 @@ static void confirm_operator(bContext *C, wmOperator *op, const char *title, con
char *s, buf[512];
s= buf;
- if (title) s+= sprintf(s, "%s%%t|%s", title, item);
+ if (title) s+= BLI_snprintf(s, sizeof(buf), "%s%%t|%s", title, item);
(void)s;
handle= ui_popup_menu_create(C, NULL, NULL, NULL, NULL, buf);
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 3a72c98e8f0..ba481f49abc 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -1958,10 +1958,10 @@ static void handle_layer_buttons(bContext *C, void *arg1, void *arg2)
tot= RNA_property_array_length(&but->rnapoin, but->rnaprop);
/* Normally clicking only selects one layer */
- RNA_property_boolean_set_index(&but->rnapoin, but->rnaprop, cur, 1);
+ RNA_property_boolean_set_index(&but->rnapoin, but->rnaprop, cur, TRUE);
for(i = 0; i < tot; ++i) {
if(i != cur)
- RNA_property_boolean_set_index(&but->rnapoin, but->rnaprop, i, 0);
+ RNA_property_boolean_set_index(&but->rnapoin, but->rnaprop, i, FALSE);
}
}
@@ -2268,8 +2268,9 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe
uiItemL(sub, name, icon); /* fails, backdrop LISTROW... */
/* free name */
- if(namebuf)
+ if (namebuf) {
MEM_freeN(namebuf);
+ }
}
void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, PointerRNA *activeptr, const char *activepropname, const char *prop_list, int rows, int maxrows, int listtype)
@@ -2373,8 +2374,9 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *
icon= list_item_icon_get(C, &itemptr, rnaicon, 0);
uiItemL(row, (name)? name: "", icon);
- if(name)
+ if (name) {
MEM_freeN((void *)name);
+ }
}
i++;
@@ -2627,9 +2629,7 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
uiBlockBeginAlign(block);
but= uiDefBut(block, ROUNDBOX, 0, "", 0, 0, UI_UNIT_X+10, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "");
/* set the report's bg color in but->col - ROUNDBOX feature */
- but->col[0]= FTOCHAR(rti->col[0]);
- but->col[1]= FTOCHAR(rti->col[1]);
- but->col[2]= FTOCHAR(rti->col[2]);
+ rgb_float_to_uchar(but->col, rti->col);
but->col[3]= 255;
but= uiDefBut(block, ROUNDBOX, 0, "", UI_UNIT_X+10, 0, UI_UNIT_X+width, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "");
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index f5c62f65512..19acfaccaa3 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -2501,7 +2501,7 @@ static void widget_swatch(uiBut *but, uiWidgetColors *wcol, rcti *rect, int stat
if (color_profile)
linearrgb_to_srgb_v3_v3(col, col);
- F4TOCHAR4(col, wcol->inner);
+ rgba_float_to_uchar((unsigned char *)wcol->inner, col);
wcol->shaded = 0;
wcol->alpha_check = (wcol->inner[3] < 255);
diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c
index 53a48e17698..472e2088d43 100644
--- a/source/blender/editors/interface/resources.c
+++ b/source/blender/editors/interface/resources.c
@@ -414,6 +414,28 @@ const unsigned char *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colo
cp= ts->preview_back;
break;
+ case TH_STITCH_PREVIEW_FACE:
+ cp = ts->preview_stitch_face;
+ break;
+
+ case TH_STITCH_PREVIEW_EDGE:
+ cp = ts->preview_stitch_edge;
+ break;
+
+ case TH_STITCH_PREVIEW_VERT:
+ cp = ts->preview_stitch_vert;
+ break;
+
+ case TH_STITCH_PREVIEW_STITCHABLE:
+ cp = ts->preview_stitch_stitchable;
+ break;
+
+ case TH_STITCH_PREVIEW_UNSTITCHABLE:
+ cp = ts->preview_stitch_unstitchable;
+ break;
+ case TH_STITCH_PREVIEW_ACTIVE:
+ cp = ts->preview_stitch_active;
+ break;
case TH_MARKER_OUTLINE:
cp= ts->marker_outline; break;
case TH_MARKER:
@@ -752,6 +774,11 @@ void ui_theme_init_default(void)
SETCOL(btheme->tima.face_select, 255, 133, 0, 60);
SETCOL(btheme->tima.editmesh_active, 255, 255, 255, 128);
SETCOLF(btheme->tima.preview_back, 0.45, 0.45, 0.45, 1.0);
+ SETCOLF(btheme->tima.preview_stitch_face, 0.5, 0.5, 0.0, 0.2);
+ SETCOLF(btheme->tima.preview_stitch_edge, 1.0, 0.0, 1.0, 0.2);
+ SETCOLF(btheme->tima.preview_stitch_vert, 0.0, 0.0, 1.0, 0.2);
+ SETCOLF(btheme->tima.preview_stitch_stitchable, 0.0, 1.0, 0.0, 1.0);
+ SETCOLF(btheme->tima.preview_stitch_unstitchable, 1.0, 0.0, 0.0, 1.0);
/* space text */
btheme->text= btheme->tv3d;
@@ -1685,6 +1712,19 @@ void init_userdef_do_versions(void)
}
}
+ if (bmain->versionfile < 262){
+ bTheme *btheme;
+ for(btheme= U.themes.first; btheme; btheme= btheme->next) {
+ SETCOLF(btheme->tima.preview_stitch_face, 0.071, 0.259, 0.694, 0.150);
+ SETCOLF(btheme->tima.preview_stitch_edge, 1.0, 0.522, 0.0, 0.7);
+ SETCOLF(btheme->tima.preview_stitch_vert, 1.0, 0.522, 0.0, 0.5);
+ SETCOLF(btheme->tima.preview_stitch_stitchable, 0.0, 1.0, 0.0, 1.0);
+ SETCOLF(btheme->tima.preview_stitch_unstitchable, 1.0, 0.0, 0.0, 1.0);
+ SETCOLF(btheme->tima.preview_stitch_active, 0.886, 0.824, 0.765, 0.140);
+ }
+ U.use_16bit_textures = 0;
+ }
+
/* Freestyle color settings */
{
bTheme *btheme;
diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c
index b8201d762df..3eb8aba7334 100644
--- a/source/blender/editors/interface/view2d.c
+++ b/source/blender/editors/interface/view2d.c
@@ -1339,8 +1339,9 @@ void UI_view2d_grid_size(View2DGrid *grid, float *r_dx, float *r_dy)
void UI_view2d_grid_free(View2DGrid *grid)
{
/* only free if there's a grid */
- if (grid)
+ if (grid) {
MEM_freeN(grid);
+ }
}
/* *********************************************************************** */
@@ -1754,7 +1755,9 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
void UI_view2d_scrollers_free(View2DScrollers *scrollers)
{
/* need to free grid as well... */
- if (scrollers->grid) MEM_freeN(scrollers->grid);
+ if (scrollers->grid) {
+ MEM_freeN(scrollers->grid);
+ }
MEM_freeN(scrollers);
}
diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c
index 2959d525cfb..234b2733bd3 100644
--- a/source/blender/editors/interface/view2d_ops.c
+++ b/source/blender/editors/interface/view2d_ops.c
@@ -1689,7 +1689,8 @@ void UI_view2d_operatortypes(void)
void UI_view2d_keymap(wmKeyConfig *keyconf)
{
wmKeyMap *keymap= WM_keymap_find(keyconf, "View2D", 0, 0);
-
+ wmKeyMapItem *kmi;
+
/* scrollers */
WM_keymap_add_item(keymap, "VIEW2D_OT_scroller_activate", LEFTMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "VIEW2D_OT_scroller_activate", MIDDLEMOUSE, KM_PRESS, 0, 0);
@@ -1750,8 +1751,10 @@ void UI_view2d_keymap(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", WHEELDOWNMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", WHEELUPMOUSE, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", PAGEDOWNKEY, KM_PRESS, 0, 0)->ptr, "page", 1);
- RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", PAGEUPKEY, KM_PRESS, 0, 0)->ptr, "page", 1);
+ kmi = WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", PAGEDOWNKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "page", TRUE);
+ kmi = WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", PAGEUPKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "page", TRUE);
WM_keymap_add_item(keymap, "VIEW2D_OT_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "VIEW2D_OT_zoom", MOUSEZOOM, 0, 0, 0);
diff --git a/source/blender/editors/mesh/editmesh_lib.c b/source/blender/editors/mesh/editmesh_lib.c
index 8dea636f0b6..5ec147a742b 100644
--- a/source/blender/editors/mesh/editmesh_lib.c
+++ b/source/blender/editors/mesh/editmesh_lib.c
@@ -2322,7 +2322,7 @@ UvVertMap *EM_make_uv_vert_map(EditMesh *em, int selected, int do_face_idx_array
for(a=0, ev=em->verts.first; ev; a++, ev= ev->next) {
UvMapVert *newvlist= NULL, *vlist=vmap->vert[a];
UvMapVert *iterv, *v, *lastv, *next;
- float *uv, *uv2, uvdiff[2];
+ float *uv, *uv2;
while(vlist) {
v= vlist;
@@ -2332,8 +2332,8 @@ UvVertMap *EM_make_uv_vert_map(EditMesh *em, int selected, int do_face_idx_array
efa = EM_get_face_for_index(v->f);
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
- uv = tf->uv[v->tfindex];
-
+ uv = tf->uv[v->tfindex];
+
lastv= NULL;
iterv= vlist;
@@ -2342,8 +2342,6 @@ UvVertMap *EM_make_uv_vert_map(EditMesh *em, int selected, int do_face_idx_array
efa = EM_get_face_for_index(iterv->f);
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
uv2 = tf->uv[iterv->tfindex];
-
- sub_v2_v2v2(uvdiff, uv2, uv);
if(fabsf(uv[0]-uv2[0]) < limit[0] && fabsf(uv[1]-uv2[1]) < limit[1]) {
if(lastv) lastv->next= next;
@@ -2353,22 +2351,224 @@ UvVertMap *EM_make_uv_vert_map(EditMesh *em, int selected, int do_face_idx_array
}
else
lastv=iterv;
-
iterv= next;
}
-
newvlist->separate = 1;
}
-
vmap->vert[a]= newvlist;
}
-
+
+
if (do_face_idx_array)
EM_free_index_arrays();
-
+
+ return vmap;
+}
+
+/* A specialized vert map used by stitch operator */
+UvElementMap *EM_make_uv_element_map(EditMesh *em, int selected, int do_islands)
+{
+ EditVert *ev;
+ EditFace *efa;
+
+ /* vars from original func */
+ UvElementMap *vmap;
+ UvElement *buf;
+ UvElement *islandbuf;
+ MTFace *tf;
+ unsigned int a;
+ int i,j, totuv, nverts, nislands = 0, islandbufsize = 0;
+ unsigned int *map;
+ /* for uv island creation */
+ EditFace **stack;
+ int stacksize = 0;
+
+ /* we need the vert */
+ for(ev = em->verts.first, i = 0; ev; ev = ev->next, i++)
+ ev->tmp.l = i;
+
+ totuv = 0;
+
+ for(efa = em->faces.first; efa; efa = efa->next)
+ if(!selected || ((!efa->h) && (efa->f & SELECT)))
+ totuv += (efa->v4)? 4: 3;
+
+ if(totuv == 0)
+ return NULL;
+
+ vmap = (UvElementMap *)MEM_callocN(sizeof(*vmap), "UvVertElementMap");
+ if(!vmap)
+ return NULL;
+
+ vmap->vert = (UvElement**)MEM_callocN(sizeof(*vmap->vert)*em->totvert, "UvElementVerts");
+ buf = vmap->buf = (UvElement*)MEM_callocN(sizeof(*vmap->buf)*totuv, "UvElement");
+
+ if(!vmap->vert || !vmap->buf) {
+ EM_free_uv_element_map(vmap);
+ return NULL;
+ }
+
+ vmap->totalUVs = totuv;
+
+ for(efa = em->faces.first; efa; a++, efa = efa->next) {
+ if(!selected || ((!efa->h) && (efa->f & SELECT))) {
+ nverts = (efa->v4)? 4: 3;
+
+ for(i = 0; i<nverts; i++) {
+ buf->tfindex = i;
+ buf->face = efa;
+ buf->separate = 0;
+ buf->island = INVALID_ISLAND;
+
+ buf->next = vmap->vert[(*(&efa->v1 + i))->tmp.l];
+ vmap->vert[(*(&efa->v1 + i))->tmp.l] = buf;
+
+ buf++;
+ }
+ }
+
+ efa->tmp.l = INVALID_ISLAND;
+ }
+
+ /* sort individual uvs for each vert */
+ for(a = 0, ev = em->verts.first; ev; a++, ev = ev->next) {
+ UvElement *newvlist = NULL, *vlist = vmap->vert[a];
+ UvElement *iterv, *v, *lastv, *next;
+ float *uv, *uv2;
+
+ while(vlist) {
+ v= vlist;
+ vlist= vlist->next;
+ v->next= newvlist;
+ newvlist= v;
+
+ efa = v->face;
+ tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+ uv = tf->uv[v->tfindex];
+
+ lastv= NULL;
+ iterv= vlist;
+
+ while(iterv) {
+ next= iterv->next;
+ efa = iterv->face;
+ tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+ uv2 = tf->uv[iterv->tfindex];
+
+ if(fabsf(uv[0]-uv2[0]) < STD_UV_CONNECT_LIMIT && fabsf(uv[1]-uv2[1]) < STD_UV_CONNECT_LIMIT) {
+ if(lastv) lastv->next = next;
+ else vlist = next;
+ iterv->next = newvlist;
+ newvlist = iterv;
+ }
+ else
+ lastv = iterv;
+
+ iterv = next;
+ }
+
+ newvlist->separate = 1;
+ }
+
+ vmap->vert[a] = newvlist;
+ }
+
+ if(do_islands) {
+ /* at this point, every UvElement in vert points to a UvElement sharing the same vertex. Now we should sort uv's in islands. */
+
+ /* map holds the map from current vmap->buf to the new, sorted map*/
+ map = MEM_mallocN(sizeof(*map)*totuv, "uvelement_remap");
+ stack = MEM_mallocN(sizeof(*stack)*em->totface, "uv_island_face_stack");
+ islandbuf = MEM_callocN(sizeof(*islandbuf)*totuv, "uvelement_island_buffer");
+
+ for(i = 0; i < totuv; i++) {
+ if(vmap->buf[i].island == INVALID_ISLAND) {
+ vmap->buf[i].island = nislands;
+ stack[0] = vmap->buf[i].face;
+ stack[0]->tmp.l = nislands;
+ stacksize=1;
+
+ while(stacksize > 0) {
+ efa = stack[--stacksize];
+ nverts = efa->v4? 4 : 3;
+
+ for(j = 0; j < nverts; j++) {
+ UvElement *element, *initelement = vmap->vert[(*(&efa->v1 + j))->tmp.l];
+
+ for(element = initelement; element; element = element->next) {
+ if(element->separate)
+ initelement = element;
+
+ if(element->face == efa) {
+ /* found the uv corresponding to our face and vertex. Now fill it to the buffer */
+ element->island = nislands;
+ map[element - vmap->buf] = islandbufsize;
+ islandbuf[islandbufsize].tfindex = element->tfindex;
+ islandbuf[islandbufsize].face = element->face;
+ islandbuf[islandbufsize].separate = element->separate;
+ islandbuf[islandbufsize].island = nislands;
+ islandbufsize++;
+
+ for(element = initelement; element; element = element->next) {
+ if(element->separate && element != initelement)
+ break;
+
+ if(element->face->tmp.l == INVALID_ISLAND) {
+ stack[stacksize++] = element->face;
+ element->face->tmp.l = nislands;
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
+
+ nislands++;
+ }
+ }
+
+ /* remap */
+ for(i = 0; i < em->totvert; i++) {
+ /* important since we may do selection only. Some of these may be NULL */
+ if(vmap->vert[i])
+ vmap->vert[i] = &islandbuf[map[vmap->vert[i] - vmap->buf]];
+ }
+
+ vmap->islandIndices = MEM_callocN(sizeof(*vmap->islandIndices)*nislands,"UvVertMap2_island_indices");
+ if(!vmap->islandIndices) {
+ MEM_freeN(islandbuf);
+ MEM_freeN(stack);
+ MEM_freeN(map);
+ EM_free_uv_element_map(vmap);
+ }
+
+ j = 0;
+ for(i = 0; i < totuv; i++) {
+ UvElement *element = vmap->buf[i].next;
+ if(element == NULL)
+ islandbuf[map[i]].next = NULL;
+ else
+ islandbuf[map[i]].next = &islandbuf[map[element - vmap->buf]];
+
+ if(islandbuf[i].island != j) {
+ j++;
+ vmap->islandIndices[j] = i;
+ }
+ }
+
+ MEM_freeN(vmap->buf);
+
+ vmap->buf = islandbuf;
+ vmap->totalIslands = nislands;
+ MEM_freeN(stack);
+ MEM_freeN(map);
+ }
+
return vmap;
}
+
UvMapVert *EM_get_uv_map_vert(UvVertMap *vmap, unsigned int v)
{
return vmap->vert[v];
@@ -2383,6 +2583,16 @@ void EM_free_uv_vert_map(UvVertMap *vmap)
}
}
+void EM_free_uv_element_map(UvElementMap *vmap)
+{
+ if (vmap) {
+ if (vmap->vert) MEM_freeN(vmap->vert);
+ if (vmap->buf) MEM_freeN(vmap->buf);
+ if (vmap->islandIndices) MEM_freeN(vmap->islandIndices);
+ MEM_freeN(vmap);
+ }
+}
+
/* poll call for mesh operators requiring a view3d context */
int EM_view3d_poll(bContext *C)
{
diff --git a/source/blender/editors/mesh/editmesh_loop.c b/source/blender/editors/mesh/editmesh_loop.c
index 70cbbf5a93c..d9854ea7678 100644
--- a/source/blender/editors/mesh/editmesh_loop.c
+++ b/source/blender/editors/mesh/editmesh_loop.c
@@ -56,7 +56,6 @@ editmesh_loop: tools with own drawing subloops, select, knife, subdiv
#include "BKE_context.h"
#include "BKE_depsgraph.h"
#include "BKE_mesh.h"
-#include "BKE_array_mallocn.h"
#include "PIL_time.h"
@@ -77,329 +76,6 @@ editmesh_loop: tools with own drawing subloops, select, knife, subdiv
static void error(const char *UNUSED(arg)) {}
/* **** XXX ******** */
-#if 0 /* UNUSED 2.5 */
-static void edgering_sel(EditMesh *em, EditEdge *startedge, int select, int previewlines)
-{
- EditEdge *eed;
- EditFace *efa;
- EditVert *v[2][2];
- float co[2][3];
- int looking= 1,i;
-
- /* in eed->f1 we put the valence (amount of faces in edge) */
- /* in eed->f2 we put tagged flag as correct loop */
- /* in efa->f1 we put tagged flag as correct to select */
-
- for(eed= em->edges.first; eed; eed= eed->next) {
- eed->f1= 0;
- eed->f2= 0;
- }
- for(efa= em->faces.first; efa; efa= efa->next) {
- efa->f1= 0;
- if(efa->h==0) {
- efa->e1->f1++;
- efa->e2->f1++;
- efa->e3->f1++;
- if(efa->e4) efa->e4->f1++;
- }
- }
-
- // tag startedge OK
- startedge->f2= 1;
-
- while(looking) {
- looking= 0;
-
- for(efa= em->faces.first; efa; efa= efa->next) {
- if(efa->e4 && efa->f1==0 && efa->h == 0) { // not done quad
- if(efa->e1->f1<=2 && efa->e2->f1<=2 && efa->e3->f1<=2 && efa->e4->f1<=2) { // valence ok
-
- // if edge tagged, select opposing edge and mark face ok
- if(efa->e1->f2) {
- efa->e3->f2= 1;
- efa->f1= 1;
- looking= 1;
- }
- else if(efa->e2->f2) {
- efa->e4->f2= 1;
- efa->f1= 1;
- looking= 1;
- }
- if(efa->e3->f2) {
- efa->e1->f2= 1;
- efa->f1= 1;
- looking= 1;
- }
- if(efa->e4->f2) {
- efa->e2->f2= 1;
- efa->f1= 1;
- looking= 1;
- }
- }
- }
- }
- }
-
- if(previewlines > 0 && select == 0){
-// XXX persp(PERSP_VIEW);
-// XXX glPushMatrix();
-// XXX mymultmatrix(obedit->obmat);
-
- for(efa= em->faces.first; efa; efa= efa->next) {
- if(efa->v4 == NULL) { continue; }
- if(efa->h == 0){
- if(efa->e1->f2 == 1){
- if(efa->e1->h == 1 || efa->e3->h == 1 )
- continue;
-
- v[0][0] = efa->v1;
- v[0][1] = efa->v2;
- v[1][0] = efa->v4;
- v[1][1] = efa->v3;
- } else if(efa->e2->f2 == 1){
- if(efa->e2->h == 1 || efa->e4->h == 1)
- continue;
- v[0][0] = efa->v2;
- v[0][1] = efa->v3;
- v[1][0] = efa->v1;
- v[1][1] = efa->v4;
- } else { continue; }
-
- for(i=1;i<=previewlines;i++){
- co[0][0] = (v[0][1]->co[0] - v[0][0]->co[0])*(i/((float)previewlines+1))+v[0][0]->co[0];
- co[0][1] = (v[0][1]->co[1] - v[0][0]->co[1])*(i/((float)previewlines+1))+v[0][0]->co[1];
- co[0][2] = (v[0][1]->co[2] - v[0][0]->co[2])*(i/((float)previewlines+1))+v[0][0]->co[2];
-
- co[1][0] = (v[1][1]->co[0] - v[1][0]->co[0])*(i/((float)previewlines+1))+v[1][0]->co[0];
- co[1][1] = (v[1][1]->co[1] - v[1][0]->co[1])*(i/((float)previewlines+1))+v[1][0]->co[1];
- co[1][2] = (v[1][1]->co[2] - v[1][0]->co[2])*(i/((float)previewlines+1))+v[1][0]->co[2];
- glColor3ub(255, 0, 255);
- glBegin(GL_LINES);
- glVertex3f(co[0][0],co[0][1],co[0][2]);
- glVertex3f(co[1][0],co[1][1],co[1][2]);
- glEnd();
- }
- }
- }
- glPopMatrix();
- } else {
-
- /* (de)select the edges */
- for(eed= em->edges.first; eed; eed= eed->next) {
- if(eed->f2) EM_select_edge(eed, select);
- }
- }
-}
-
-static void CutEdgeloop(Object *obedit, wmOperator *op, EditMesh *em, int numcuts)
-{
- ViewContext vc; // XXX
- EditEdge *nearest=NULL, *eed;
- float fac;
- int keys = 0, holdnum=0, selectmode, dist;
- int mvalo[2] = {0, 0}, mval[2] = {0, 0};
- short event=0, val, choosing=1, cancel=0, cuthalf = 0, smooth=0;
- short hasHidden = 0;
- char msg[128];
-
- selectmode = em->selectmode;
-
- if(em->selectmode & SCE_SELECT_FACE){
- em->selectmode = SCE_SELECT_EDGE;
- EM_selectmode_set(em);
- }
-
-
- BIF_undo_push("Loopcut Begin");
- while(choosing && !cancel){
-// XXX getmouseco_areawin(mval);
- if (mval[0] != mvalo[0] || mval[1] != mvalo[1]) {
- mvalo[0] = mval[0];
- mvalo[1] = mval[1];
- dist= 50;
- nearest = findnearestedge(&vc, &dist); // returns actual distance in dist
-// scrarea_do_windraw(curarea); // after findnearestedge, backbuf!
-
- BLI_snprintf(msg, sizeof(msg),"Number of Cuts: %d (S)mooth: %s", numcuts, smooth ? "on":"off");
-
-// headerprint(msg);
- /* Need to figure preview */
- if(nearest){
- edgering_sel(em, nearest, 0, numcuts);
- }
-// XXX screen_swapbuffers();
-
- /* backbuffer refresh for non-apples (no aux) */
-#ifndef __APPLE__
-// XXX if(G.vd->drawtype>OB_WIRE && (G.vd->flag & V3D_ZBUF_SELECT)) {
-// backdrawview3d(0);
-// }
-#endif
- }
- else PIL_sleep_ms(10); // idle
-
-
- while(qtest())
- {
- val=0;
-// XXX event= extern_qread(&val);
- if(val && (event == MOUSEX || event == MOUSEY)){ ; }
- else if(val && ((event==LEFTMOUSE || event==RETKEY) || (event == MIDDLEMOUSE || event==PADENTER)))
- {
- if(event == MIDDLEMOUSE){
- cuthalf = 1;
- }
- if (nearest==NULL)
- cancel = 1;
- choosing=0;
- mvalo[0] = -1;
- }
- else if(val && (event==ESCKEY || event==RIGHTMOUSE ))
- {
- choosing=0;
- cancel = 1;
- mvalo[0] = -1;
- }
- else if(val && (event==PADPLUSKEY || event==WHEELUPMOUSE))
- {
- numcuts++;
- mvalo[0] = -1;
- }
- else if(val && (event==PADMINUS || event==WHEELDOWNMOUSE))
- {
- if(numcuts > 1){
- numcuts--;
- mvalo[0] = -1;
- }
- }
- else if(val && event==SKEY)
- {
- if(smooth){smooth=0;}
- else { smooth=1; }
- mvalo[0] = -1;
- }
-
- else if(val){
- holdnum = -1;
- switch(event){
- case PAD9:
- case NINEKEY:
- holdnum = 9; break;
- case PAD8:
- case EIGHTKEY:
- holdnum = 8;break;
- case PAD7:
- case SEVENKEY:
- holdnum = 7;break;
- case PAD6:
- case SIXKEY:
- holdnum = 6;break;
- case PAD5:
- case FIVEKEY:
- holdnum = 5;break;
- case PAD4:
- case FOURKEY:
- holdnum = 4;break;
- case PAD3:
- case THREEKEY:
- holdnum = 3; break;
- case PAD2:
- case TWOKEY:
- holdnum = 2;break;
- case PAD1:
- case ONEKEY:
- holdnum = 1; break;
- case PAD0:
- case ZEROKEY:
- holdnum = 0;break;
- case BACKSPACEKEY:
- holdnum = -2;break;
- }
- if(holdnum >= 0 && numcuts*10 < 130){
- if(keys == 0){ // first level numeric entry
- if(holdnum > 0){
- numcuts = holdnum;
- keys++;
- }
- } else if(keys > 0){//highrt level numeric entry
- numcuts *= 10;
- numcuts += holdnum;
- keys++;
- }
- } else if (holdnum == -2){// backspace
- if (keys > 1){
- numcuts /= 10;
- keys--;
- } else {
- numcuts=1;
- keys = 0;
- }
- }
- mvalo[0] = -1;
- break;
- } // End Numeric Entry
- } //End while(qtest())
- } // End Choosing
-
- if(cancel){
- return;
- }
- /* clean selection */
- for(eed=em->edges.first; eed; eed = eed->next){
- EM_select_edge(eed,0);
- }
- /* select edge ring */
- edgering_sel(em, nearest, 1, 0);
-
- /* now cut the loops */
- if(smooth){
- fac= 1.0f;
-// XXX if(fbutton(&fac, 0.0f, 5.0f, 10, 10, "Smooth:")==0) return;
- fac= 0.292f*fac;
- esubdivideflag(obedit, em, SELECT,fac,0,B_SMOOTH,numcuts, SUBDIV_CORNER_PATH, SUBDIV_SELECT_LOOPCUT);
- } else {
- esubdivideflag(obedit, em, SELECT,0,0,0,numcuts,SUBDIV_CORNER_PATH, SUBDIV_SELECT_LOOPCUT);
- }
- /* if this was a single cut, enter edgeslide mode */
- if(numcuts == 1 && hasHidden == 0){
- if(cuthalf)
- EdgeSlide(em, op, 1,0.0);
- else {
- if(EdgeSlide(em, op, 0,0.0) == -1){
- BIF_undo();
- }
- }
- }
-
- if(em->selectmode != selectmode){
- em->selectmode = selectmode;
- EM_selectmode_set(em);
- }
-
-// DAG_id_tag_update(obedit->data, 0);
- return;
-}
-#endif
-
-/* *************** LOOP SELECT ************* */
-#if 0
-static short edgeFaces(EditMesh *em, EditEdge *e)
-{
- EditFace *search=NULL;
- short count = 0;
-
- search = em->faces.first;
- while(search){
- if((search->e1 == e || search->e2 == e) || (search->e3 == e || search->e4 == e))
- count++;
- search = search->next;
- }
- return count;
-}
-#endif
-
-
-
/* ***************** TRAIL ************************
Read a trail of mouse coords and return them as an array of CutCurve structs
diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c
index f0687031bae..48b96eaf927 100644
--- a/source/blender/editors/mesh/editmesh_tools.c
+++ b/source/blender/editors/mesh/editmesh_tools.c
@@ -4279,7 +4279,7 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event)
BKE_mesh_end_editmesh(obedit->data, em);
// RNA_enum_set(op->ptr, "proportional", 0);
-// RNA_boolean_set(op->ptr, "mirror", 0);
+// RNA_boolean_set(op->ptr, "mirror", FALSE);
// WM_operator_name_call(C, "TRANSFORM_OT_translate", WM_OP_INVOKE_REGION_WIN, op->ptr);
return OPERATOR_FINISHED;
diff --git a/source/blender/editors/mesh/loopcut.c b/source/blender/editors/mesh/loopcut.c
index 42728eb7ea1..6ff62b16bde 100644
--- a/source/blender/editors/mesh/loopcut.c
+++ b/source/blender/editors/mesh/loopcut.c
@@ -45,6 +45,7 @@
#include "PIL_time.h"
+#include "BLI_array.h"
#include "BLI_blenlib.h"
#include "BLI_dynstr.h" /*for WM_operator_pystring */
#include "BLI_editVert.h"
@@ -58,7 +59,6 @@
#include "BKE_modifier.h"
#include "BKE_report.h"
#include "BKE_scene.h"
-#include "BKE_array_mallocn.h"
#include "BIF_gl.h"
#include "BIF_glutil.h" /* for paint cursor */
@@ -138,7 +138,7 @@ static void edgering_sel(tringselOpData *lcd, int previewlines, int select)
EditFace *efa;
EditVert *v[2][2];
float (*edges)[2][3] = NULL;
- V_DYNDECLARE(edges);
+ BLI_array_declare(edges);
float co[2][3];
int looking=1, i, tot=0;
@@ -240,9 +240,9 @@ static void edgering_sel(tringselOpData *lcd, int previewlines, int select)
co[1][1] = (v[1][1]->co[1] - v[1][0]->co[1])*(i/((float)previewlines+1))+v[1][0]->co[1];
co[1][2] = (v[1][1]->co[2] - v[1][0]->co[2])*(i/((float)previewlines+1))+v[1][0]->co[2];
- V_GROW(edges);
- VECCOPY(edges[tot][0], co[0]);
- VECCOPY(edges[tot][1], co[1]);
+ BLI_array_growone(edges);
+ copy_v3_v3(edges[tot][0], co[0]);
+ copy_v3_v3(edges[tot][1], co[1]);
tot++;
}
}
diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c
index e40c806fd17..d752d90ffdd 100644
--- a/source/blender/editors/mesh/mesh_data.c
+++ b/source/blender/editors/mesh/mesh_data.c
@@ -695,6 +695,46 @@ static void mesh_add_faces(Mesh *mesh, int len)
mesh->totface= totface;
}
+static void mesh_remove_verts(Mesh *mesh, int len)
+{
+ int totvert;
+
+ if(len == 0)
+ return;
+
+ totvert= mesh->totvert - len;
+ CustomData_free_elem(&mesh->vdata, totvert, len);
+
+ /* set final vertex list size */
+ mesh->totvert= totvert;
+}
+
+static void mesh_remove_edges(Mesh *mesh, int len)
+{
+ int totedge;
+
+ if(len == 0)
+ return;
+
+ totedge= mesh->totedge - len;
+ CustomData_free_elem(&mesh->edata, totedge, len);
+
+ mesh->totedge= totedge;
+}
+
+static void mesh_remove_faces(Mesh *mesh, int len)
+{
+ int totface;
+
+ if(len == 0)
+ return;
+
+ totface= mesh->totface - len; /* new face count */
+ CustomData_free_elem(&mesh->fdata, totface, len);
+
+ mesh->totface= totface;
+}
+
/*
void ED_mesh_geometry_add(Mesh *mesh, ReportList *reports, int verts, int edges, int faces)
{
@@ -742,6 +782,48 @@ void ED_mesh_vertices_add(Mesh *mesh, ReportList *reports, int count)
mesh_add_verts(mesh, count);
}
+void ED_mesh_faces_remove(Mesh *mesh, ReportList *reports, int count)
+{
+ if(mesh->edit_mesh) {
+ BKE_report(reports, RPT_ERROR, "Can't remove faces in edit mode");
+ return;
+ }
+ else if(count > mesh->totface) {
+ BKE_report(reports, RPT_ERROR, "Can't remove more faces than the mesh contains");
+ return;
+ }
+
+ mesh_remove_faces(mesh, count);
+}
+
+void ED_mesh_edges_remove(Mesh *mesh, ReportList *reports, int count)
+{
+ if(mesh->edit_mesh) {
+ BKE_report(reports, RPT_ERROR, "Can't remove edges in edit mode");
+ return;
+ }
+ else if(count > mesh->totedge) {
+ BKE_report(reports, RPT_ERROR, "Can't remove more edges than the mesh contains");
+ return;
+ }
+
+ mesh_remove_edges(mesh, count);
+}
+
+void ED_mesh_vertices_remove(Mesh *mesh, ReportList *reports, int count)
+{
+ if(mesh->edit_mesh) {
+ BKE_report(reports, RPT_ERROR, "Can't remove vertices in edit mode");
+ return;
+ }
+ else if(count > mesh->totvert) {
+ BKE_report(reports, RPT_ERROR, "Can't remove more vertices than the mesh contains");
+ return;
+ }
+
+ mesh_remove_verts(mesh, count);
+}
+
void ED_mesh_calc_normals(Mesh *me)
{
mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL);
diff --git a/source/blender/editors/mesh/mesh_ops.c b/source/blender/editors/mesh/mesh_ops.c
index 21f44ff89bc..e6268d80c21 100644
--- a/source/blender/editors/mesh/mesh_ops.c
+++ b/source/blender/editors/mesh/mesh_ops.c
@@ -190,14 +190,14 @@ void ED_operatormacros_mesh(void)
WM_operatortype_macro_define(ot, "MESH_OT_duplicate");
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_enum_set(otmacro->ptr, "proportional", 0);
- RNA_boolean_set(otmacro->ptr, "mirror", 0);
+ RNA_boolean_set(otmacro->ptr, "mirror", FALSE);
ot= WM_operatortype_append_macro("MESH_OT_rip_move", "Rip", OPTYPE_UNDO|OPTYPE_REGISTER);
ot->description = "Rip polygons and move the result";
WM_operatortype_macro_define(ot, "MESH_OT_rip");
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_enum_set(otmacro->ptr, "proportional", 0);
- RNA_boolean_set(otmacro->ptr, "mirror", 0);
+ RNA_boolean_set(otmacro->ptr, "mirror", FALSE);
ot= WM_operatortype_append_macro("MESH_OT_extrude_region_move", "Extrude Region and Move", OPTYPE_UNDO|OPTYPE_REGISTER);
ot->description = "Extrude region and move result";
@@ -205,7 +205,7 @@ void ED_operatormacros_mesh(void)
RNA_enum_set(otmacro->ptr, "type", 1);
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_enum_set(otmacro->ptr, "proportional", 0);
- RNA_boolean_set(otmacro->ptr, "mirror", 0);
+ RNA_boolean_set(otmacro->ptr, "mirror", FALSE);
ot= WM_operatortype_append_macro("MESH_OT_extrude_faces_move", "Extrude Individual Faces and Move", OPTYPE_UNDO|OPTYPE_REGISTER);
ot->description = "Extrude faces and move result";
@@ -213,7 +213,7 @@ void ED_operatormacros_mesh(void)
RNA_enum_set(otmacro->ptr, "type", 2);
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_shrink_fatten");
RNA_enum_set(otmacro->ptr, "proportional", 0);
- RNA_boolean_set(otmacro->ptr, "mirror", 0);
+ RNA_boolean_set(otmacro->ptr, "mirror", FALSE);
ot= WM_operatortype_append_macro("MESH_OT_extrude_edges_move", "Extrude Only Edges and Move", OPTYPE_UNDO|OPTYPE_REGISTER);
ot->description = "Extrude edges and move result";
@@ -221,7 +221,7 @@ void ED_operatormacros_mesh(void)
RNA_enum_set(otmacro->ptr, "type", 3);
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_enum_set(otmacro->ptr, "proportional", 0);
- RNA_boolean_set(otmacro->ptr, "mirror", 0);
+ RNA_boolean_set(otmacro->ptr, "mirror", FALSE);
ot= WM_operatortype_append_macro("MESH_OT_extrude_vertices_move", "Extrude Only Vertices and Move", OPTYPE_UNDO|OPTYPE_REGISTER);
ot->description = "Extrude vertices and move result";
@@ -229,7 +229,7 @@ void ED_operatormacros_mesh(void)
RNA_enum_set(otmacro->ptr, "type", 4);
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_enum_set(otmacro->ptr, "proportional", 0);
- RNA_boolean_set(otmacro->ptr, "mirror", 0);
+ RNA_boolean_set(otmacro->ptr, "mirror", FALSE);
}
/* note mesh keymap also for other space? */
@@ -302,6 +302,7 @@ void ED_keymap_mesh(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "MESH_OT_fill", FKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "MESH_OT_beautify_fill", FKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0);
+
WM_keymap_add_item(keymap, "MESH_OT_quads_convert_to_tris", TKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "MESH_OT_tris_convert_to_quads", JKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "MESH_OT_edge_flip", FKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
diff --git a/source/blender/editors/metaball/mball_ops.c b/source/blender/editors/metaball/mball_ops.c
index 4c69bb3e559..c7635bcf2cc 100644
--- a/source/blender/editors/metaball/mball_ops.c
+++ b/source/blender/editors/metaball/mball_ops.c
@@ -37,6 +37,8 @@
#include "ED_mball.h"
#include "ED_screen.h"
+#include "BLI_utildefines.h"
+
#include "mball_intern.h"
void ED_operatortypes_metaball(void)
@@ -62,8 +64,10 @@ void ED_keymap_metaball(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "OBJECT_OT_metaball_add", AKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "MBALL_OT_reveal_metaelems", HKEY, KM_PRESS, KM_ALT, 0);
- WM_keymap_add_item(keymap, "MBALL_OT_hide_metaelems", HKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "MBALL_OT_hide_metaelems", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1);
+ kmi = WM_keymap_add_item(keymap, "MBALL_OT_hide_metaelems", HKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", FALSE);
+ kmi = WM_keymap_add_item(keymap, "MBALL_OT_hide_metaelems", HKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", TRUE);
WM_keymap_add_item(keymap, "MBALL_OT_delete_metaelems", XKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "MBALL_OT_delete_metaelems", DELKEY, KM_PRESS, 0, 0);
diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
index c53549728f6..64bbf604f67 100644
--- a/source/blender/editors/object/object_add.c
+++ b/source/blender/editors/object/object_add.c
@@ -484,7 +484,7 @@ static int object_camera_add_exec(bContext *C, wmOperator *op)
float loc[3], rot[3];
/* force view align for cameras */
- RNA_boolean_set(op->ptr, "view_align", 1);
+ RNA_boolean_set(op->ptr, "view_align", TRUE);
object_add_generic_invoke_options(C, op);
diff --git a/source/blender/editors/object/object_bake.c b/source/blender/editors/object/object_bake.c
index a02b90a1d16..2fe2e71f2d9 100644
--- a/source/blender/editors/object/object_bake.c
+++ b/source/blender/editors/object/object_bake.c
@@ -807,10 +807,8 @@ static void apply_tangmat_callback(DerivedMesh *lores_dm, DerivedMesh *hires_dm,
ibuf->userflags= IB_RECT_INVALID;
} else {
- char *rrgb= (char*)ibuf->rect + pixel*4;
- rrgb[0]= FTOCHAR(vec[0]);
- rrgb[1]= FTOCHAR(vec[1]);
- rrgb[2]= FTOCHAR(vec[2]);
+ unsigned char *rrgb= (unsigned char *)ibuf->rect + pixel*4;
+ rgb_float_to_uchar(rrgb, vec);
rrgb[3]= 255;
}
}
@@ -1257,7 +1255,7 @@ typedef struct BakeRender {
Main *main;
Scene *scene;
struct Object *actob;
- int tot, ready;
+ int result, ready;
ReportList *reports;
@@ -1330,7 +1328,7 @@ static void finish_bake_internal(BakeRender *bkr)
if(bkr->prev_r_raytrace == 0)
bkr->scene->r.mode &= ~R_RAYTRACE;
- if(bkr->tot) {
+ if(bkr->result==BAKE_RESULT_OK) {
Image *ima;
/* force OpenGL reload and mipmap recalc */
for(ima= G.main->image.first; ima; ima= ima->id.next) {
@@ -1357,7 +1355,7 @@ static void *do_bake_render(void *bake_v)
{
BakeRender *bkr= bake_v;
- bkr->tot= RE_bake_shade_all_selected(bkr->re, bkr->scene->r.bake_mode, bkr->actob, NULL, bkr->progress);
+ bkr->result= RE_bake_shade_all_selected(bkr->re, bkr->scene->r.bake_mode, bkr->actob, NULL, bkr->progress);
bkr->ready= 1;
return NULL;
@@ -1379,7 +1377,7 @@ static void bake_startjob(void *bkv, short *stop, short *do_update, float *progr
RE_Database_Baking(bkr->re, bmain, scene, scene->lay, scene->r.bake_mode, bkr->actob);
/* baking itself is threaded, cannot use test_break in threads. we also update optional imagewindow */
- bkr->tot= RE_bake_shade_all_selected(bkr->re, scene->r.bake_mode, bkr->actob, bkr->do_update, bkr->progress);
+ bkr->result= RE_bake_shade_all_selected(bkr->re, scene->r.bake_mode, bkr->actob, bkr->do_update, bkr->progress);
}
static void bake_update(void *bkv)
@@ -1398,7 +1396,11 @@ static void bake_freejob(void *bkv)
BakeRender *bkr= bkv;
finish_bake_internal(bkr);
- if(bkr->tot==0) BKE_report(bkr->reports, RPT_ERROR, "No objects or images found to bake to");
+ if(bkr->result==BAKE_RESULT_NO_OBJECTS)
+ BKE_report(bkr->reports, RPT_ERROR, "No objects or images found to bake to");
+ else if(bkr->result==BAKE_RESULT_FEEDBACK_LOOP)
+ BKE_report(bkr->reports, RPT_WARNING, "Feedback loop detected");
+
MEM_freeN(bkr);
G.rendering = 0;
}
@@ -1515,7 +1517,10 @@ static int bake_image_exec(bContext *C, wmOperator *op)
}
BLI_end_threads(&threads);
- if(bkr.tot==0) BKE_report(op->reports, RPT_ERROR, "No valid images found to bake to");
+ if(bkr.result==BAKE_RESULT_NO_OBJECTS)
+ BKE_report(op->reports, RPT_ERROR, "No valid images found to bake to");
+ else if(bkr.result==BAKE_RESULT_FEEDBACK_LOOP)
+ BKE_report(op->reports, RPT_ERROR, "Feedback loop detected");
finish_bake_internal(&bkr);
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index 61ba54e7d36..2dc170a8a23 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -88,7 +88,7 @@
#include "ED_object.h"
#include "ED_screen.h"
#include "ED_util.h"
-
+#include "ED_image.h"
#include "RNA_access.h"
#include "RNA_define.h"
@@ -513,11 +513,15 @@ void ED_object_enter_editmode(bContext *C, int flag)
static int editmode_toggle_exec(bContext *C, wmOperator *UNUSED(op))
{
+ ToolSettings *toolsettings = CTX_data_tool_settings(C);
+
if(!CTX_data_edit_object(C))
ED_object_enter_editmode(C, EM_WAITCURSOR);
else
ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* had EM_DO_UNDO but op flag calls undo too [#24685] */
+ ED_space_image_uv_sculpt_update(CTX_wm_manager(C), toolsettings);
+
return OPERATOR_FINISHED;
}
diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c
index 99eeaf334a8..09ae6365363 100644
--- a/source/blender/editors/object/object_ops.c
+++ b/source/blender/editors/object/object_ops.c
@@ -235,7 +235,7 @@ void ED_operatormacros_object(void)
if(ot) {
ot->description = "Duplicate selected objects and move them";
otmacro= WM_operatortype_macro_define(ot, "OBJECT_OT_duplicate");
- RNA_boolean_set(otmacro->ptr, "linked", 1);
+ RNA_boolean_set(otmacro->ptr, "linked", TRUE);
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_enum_set(otmacro->ptr, "proportional", PROP_EDIT_OFF);
}
@@ -268,20 +268,20 @@ void ED_keymap_object(wmKeyConfig *keyconf)
/* Note: this keymap works disregarding mode */
kmi = WM_keymap_add_item(keymap, "OBJECT_OT_mode_set", TABKEY, KM_PRESS, 0, 0);
- RNA_enum_set(kmi->ptr, "mode", OB_MODE_EDIT);
- RNA_boolean_set(kmi->ptr, "toggle", 1);
+ RNA_enum_set(kmi->ptr, "mode", OB_MODE_EDIT);
+ RNA_boolean_set(kmi->ptr, "toggle", TRUE);
kmi = WM_keymap_add_item(keymap, "OBJECT_OT_mode_set", TABKEY, KM_PRESS, KM_CTRL, 0);
- RNA_enum_set(kmi->ptr, "mode", OB_MODE_POSE);
- RNA_boolean_set(kmi->ptr, "toggle", 1);
+ RNA_enum_set(kmi->ptr, "mode", OB_MODE_POSE);
+ RNA_boolean_set(kmi->ptr, "toggle", TRUE);
kmi = WM_keymap_add_item(keymap, "OBJECT_OT_mode_set", VKEY, KM_PRESS, 0, 0);
- RNA_enum_set(kmi->ptr, "mode", OB_MODE_VERTEX_PAINT);
- RNA_boolean_set(kmi->ptr, "toggle", 1);
+ RNA_enum_set(kmi->ptr, "mode", OB_MODE_VERTEX_PAINT);
+ RNA_boolean_set(kmi->ptr, "toggle", TRUE);
kmi = WM_keymap_add_item(keymap, "OBJECT_OT_mode_set", TABKEY, KM_PRESS, KM_CTRL, 0);
- RNA_enum_set(kmi->ptr, "mode", OB_MODE_WEIGHT_PAINT);
- RNA_boolean_set(kmi->ptr, "toggle", 1);
+ RNA_enum_set(kmi->ptr, "mode", OB_MODE_WEIGHT_PAINT);
+ RNA_boolean_set(kmi->ptr, "toggle", TRUE);
WM_keymap_add_item(keymap, "OBJECT_OT_origin_set", CKEY, KM_PRESS, KM_ALT|KM_SHIFT|KM_CTRL, 0);
@@ -296,27 +296,29 @@ void ED_keymap_object(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "VIEW3D_OT_game_start", PKEY, KM_PRESS, 0, 0);
kmi = WM_keymap_add_item(keymap, "OBJECT_OT_select_all", AKEY, KM_PRESS, 0, 0);
- RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
+ RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
kmi = WM_keymap_add_item(keymap, "OBJECT_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
- RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
+ RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
WM_keymap_add_item(keymap, "OBJECT_OT_select_linked", LKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "OBJECT_OT_select_grouped", GKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "OBJECT_OT_select_mirror", MKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
- kmi= WM_keymap_add_item(keymap, "OBJECT_OT_select_hierarchy", LEFTBRACKETKEY, KM_PRESS, 0, 0);
- RNA_enum_set_identifier(kmi->ptr, "direction", "PARENT");
- RNA_boolean_set(kmi->ptr, "extend", FALSE);
- kmi= WM_keymap_add_item(keymap, "OBJECT_OT_select_hierarchy", LEFTBRACKETKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_enum_set_identifier(kmi->ptr, "direction", "PARENT");
- RNA_boolean_set(kmi->ptr, "extend", TRUE);
-
- kmi= WM_keymap_add_item(keymap, "OBJECT_OT_select_hierarchy", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
- RNA_enum_set_identifier(kmi->ptr, "direction", "CHILD");
- RNA_boolean_set(kmi->ptr, "extend", FALSE);
- kmi= WM_keymap_add_item(keymap, "OBJECT_OT_select_hierarchy", RIGHTBRACKETKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_enum_set_identifier(kmi->ptr, "direction", "CHILD");
- RNA_boolean_set(kmi->ptr, "extend", TRUE);
+ kmi = WM_keymap_add_item(keymap, "OBJECT_OT_select_hierarchy", LEFTBRACKETKEY, KM_PRESS, 0, 0);
+ RNA_enum_set_identifier(kmi->ptr, "direction", "PARENT");
+ RNA_boolean_set(kmi->ptr, "extend", FALSE);
+
+ kmi = WM_keymap_add_item(keymap, "OBJECT_OT_select_hierarchy", LEFTBRACKETKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_enum_set_identifier(kmi->ptr, "direction", "PARENT");
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
+
+ kmi = WM_keymap_add_item(keymap, "OBJECT_OT_select_hierarchy", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
+ RNA_enum_set_identifier(kmi->ptr, "direction", "CHILD");
+ RNA_boolean_set(kmi->ptr, "extend", FALSE);
+
+ kmi = WM_keymap_add_item(keymap, "OBJECT_OT_select_hierarchy", RIGHTBRACKETKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_enum_set_identifier(kmi->ptr, "direction", "CHILD");
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
WM_keymap_verify_item(keymap, "OBJECT_OT_parent_set", PKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_verify_item(keymap, "OBJECT_OT_parent_no_inverse_set", PKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
@@ -333,20 +335,34 @@ void ED_keymap_object(wmKeyConfig *keyconf)
WM_keymap_verify_item(keymap, "OBJECT_OT_origin_clear", OKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "OBJECT_OT_hide_view_clear", HKEY, KM_PRESS, KM_ALT, 0);
- WM_keymap_add_item(keymap, "OBJECT_OT_hide_view_set", HKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "OBJECT_OT_hide_view_set", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1);
+ kmi = WM_keymap_add_item(keymap, "OBJECT_OT_hide_view_set", HKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", FALSE);
+
+ kmi = WM_keymap_add_item(keymap, "OBJECT_OT_hide_view_set", HKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", TRUE);
/* same as above but for rendering */
WM_keymap_add_item(keymap, "OBJECT_OT_hide_render_clear", HKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
WM_keymap_add_item(keymap, "OBJECT_OT_hide_render_set", HKEY, KM_PRESS, KM_CTRL, 0);
-// RNA_boolean_set(WM_keymap_add_item(keymap, "OBJECT_OT_hide_render_set", HKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "unselected", 1); // conflicts, removing
+
+ /* conflicts, removing */
+#if 0
+ kmi = WM_keymap_add_item(keymap, "OBJECT_OT_hide_render_set", HKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)
+ RNA_boolean_set(kmi->ptr, "unselected", TRUE);
+#endif
WM_keymap_add_item(keymap, "OBJECT_OT_move_to_layer", MKEY, KM_PRESS, 0, 0);
- WM_keymap_add_item(keymap, "OBJECT_OT_delete", XKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "OBJECT_OT_delete", XKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "use_global", TRUE);
+ kmi = WM_keymap_add_item(keymap, "OBJECT_OT_delete", XKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "use_global", FALSE);
+
+ kmi = WM_keymap_add_item(keymap, "OBJECT_OT_delete", XKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "use_global", TRUE);
+
WM_keymap_add_item(keymap, "OBJECT_OT_delete", DELKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "OBJECT_OT_delete", DELKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "use_global", TRUE);
+ RNA_boolean_set(kmi->ptr, "use_global", FALSE);
+ kmi = WM_keymap_add_item(keymap, "OBJECT_OT_delete", DELKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "use_global", TRUE);
WM_keymap_add_menu(keymap, "INFO_MT_add", AKEY, KM_PRESS, KM_SHIFT, 0);
@@ -392,7 +408,7 @@ void ED_keymap_object(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "OBJECT_OT_vertex_parent_set", PKEY, KM_PRESS, KM_CTRL, 0);
- /* menus */
+ /* menus */
WM_keymap_add_menu(keymap, "VIEW3D_MT_hook", HKEY, KM_PRESS, KM_CTRL, 0);
ED_object_generic_keymap(keyconf, keymap, 2);
diff --git a/source/blender/editors/physics/physics_ops.c b/source/blender/editors/physics/physics_ops.c
index 09f99a58dd7..473ed50b5e2 100644
--- a/source/blender/editors/physics/physics_ops.c
+++ b/source/blender/editors/physics/physics_ops.c
@@ -39,8 +39,11 @@
#include "ED_physics.h"
#include "ED_object.h"
+#include "BLI_utildefines.h"
+
#include "physics_intern.h" // own include
+
/***************************** particles ***********************************/
static void operatortypes_particle(void)
@@ -93,23 +96,30 @@ static void keymap_particle(wmKeyConfig *keyconf)
keymap= WM_keymap_find(keyconf, "Particle", 0, 0);
keymap->poll= PE_poll;
- WM_keymap_add_item(keymap, "PARTICLE_OT_select_all", AKEY, KM_PRESS, 0, 0);
- RNA_enum_set(WM_keymap_add_item(keymap, "PARTICLE_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "action", SEL_INVERT);
+ kmi = WM_keymap_add_item(keymap, "PARTICLE_OT_select_all", AKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
+ kmi = WM_keymap_add_item(keymap, "PARTICLE_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
+ RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
WM_keymap_add_item(keymap, "PARTICLE_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "PARTICLE_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "PARTICLE_OT_select_linked", LKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "PARTICLE_OT_select_linked", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "deselect", 1);
+
+ kmi = WM_keymap_add_item(keymap, "PARTICLE_OT_select_linked", LKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "deselect", FALSE);
+ kmi = WM_keymap_add_item(keymap, "PARTICLE_OT_select_linked", LKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "deselect", TRUE);
WM_keymap_add_item(keymap, "PARTICLE_OT_delete", XKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "PARTICLE_OT_delete", DELKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "PARTICLE_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0);
- WM_keymap_add_item(keymap, "PARTICLE_OT_hide", HKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "PARTICLE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1);
+ kmi = WM_keymap_add_item(keymap, "PARTICLE_OT_hide", HKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", FALSE);
+ kmi = WM_keymap_add_item(keymap, "PARTICLE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", TRUE);
kmi = WM_keymap_verify_item(keymap, "VIEW3D_OT_manipulator", LEFTMOUSE, KM_PRESS, KM_ANY, 0);
- RNA_boolean_set(kmi->ptr, "release_confirm", 1);
+ RNA_boolean_set(kmi->ptr, "release_confirm", TRUE);
WM_keymap_add_item(keymap, "PARTICLE_OT_brush_edit", LEFTMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "PARTICLE_OT_brush_edit", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c
index 06e15f4a5f6..13383445c93 100644
--- a/source/blender/editors/render/render_opengl.c
+++ b/source/blender/editors/render/render_opengl.c
@@ -240,7 +240,7 @@ static void screen_opengl_render_apply(OGLRender *oglrender)
}
BKE_makepicstring(name, scene->r.pic, oglrender->bmain->name, scene->r.cfra, scene->r.im_format.imtype, scene->r.scemode & R_EXTENSION, FALSE);
- ok= BKE_write_ibuf(ibuf, name, &scene->r.im_format); /* no need to stamp here */
+ ok= BKE_write_ibuf_as(ibuf, name, &scene->r.im_format, TRUE); /* no need to stamp here */
if(ok) printf("OpenGL Render written to '%s'\n", name);
else printf("OpenGL Render failed to write '%s'\n", name);
}
@@ -272,8 +272,8 @@ static int screen_opengl_render_init(bContext *C, wmOperator *op)
/* ensure we have a 3d view */
if(!ED_view3d_context_activate(C)) {
- RNA_boolean_set(op->ptr, "view_context", 0);
- is_view_context= 0;
+ RNA_boolean_set(op->ptr, "view_context", FALSE);
+ is_view_context = 0;
}
/* only one render job at a time */
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index 2632c239625..0d724dc1b28 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -3492,7 +3492,7 @@ void ED_keymap_screen(wmKeyConfig *keyconf)
{
ListBase *lb;
wmKeyMap *keymap;
- //wmKeyMapItem *kmi;
+ wmKeyMapItem *kmi;
/* Screen Editing ------------------------------------------------ */
keymap= WM_keymap_find(keyconf, "Screen Editing", 0, 0);
@@ -3559,7 +3559,8 @@ void ED_keymap_screen(wmKeyConfig *keyconf)
/* render */
WM_keymap_add_item(keymap, "RENDER_OT_render", F12KEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "RENDER_OT_render", F12KEY, KM_PRESS, KM_CTRL, 0)->ptr, "animation", 1);
+ kmi = WM_keymap_add_item(keymap, "RENDER_OT_render", F12KEY, KM_PRESS, KM_CTRL, 0);
+ RNA_boolean_set(kmi->ptr, "animation", TRUE);
WM_keymap_add_item(keymap, "RENDER_OT_view_cancel", ESCKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "RENDER_OT_view_show", F11KEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "RENDER_OT_play_rendered_anim", F11KEY, KM_PRESS, KM_CTRL, 0);
@@ -3583,20 +3584,21 @@ void ED_keymap_screen(wmKeyConfig *keyconf)
RNA_int_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_offset", WHEELDOWNMOUSE, KM_PRESS, KM_ALT, 0)->ptr, "delta", 1);
RNA_int_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_offset", WHEELUPMOUSE, KM_PRESS, KM_ALT, 0)->ptr, "delta", -1);
- RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_jump", UPARROWKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "end", 1);
- RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_jump", DOWNARROWKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "end", 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_jump", RIGHTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "end", 1);
- RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_jump", LEFTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "end", 0);
+ RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_jump", UPARROWKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "end", TRUE);
+ RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_jump", DOWNARROWKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "end", FALSE);
+ RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_jump", RIGHTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "end", TRUE);
+ RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_jump", LEFTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "end", FALSE);
WM_keymap_add_item(keymap, "SCREEN_OT_keyframe_jump", UPARROWKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_keyframe_jump", DOWNARROWKEY, KM_PRESS, 0, 0)->ptr, "next", 0);
+ RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_keyframe_jump", DOWNARROWKEY, KM_PRESS, 0, 0)->ptr, "next", FALSE);
WM_keymap_add_item(keymap, "SCREEN_OT_keyframe_jump", MEDIALAST, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_keyframe_jump", MEDIAFIRST, KM_PRESS, 0, 0)->ptr, "next", 0);
+ kmi = WM_keymap_add_item(keymap, "SCREEN_OT_keyframe_jump", MEDIAFIRST, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "next", FALSE);
/* play (forward and backwards) */
WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", AKEY, KM_PRESS, KM_ALT, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", AKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0)->ptr, "reverse", 1);
+ RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", AKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0)->ptr, "reverse", TRUE);
WM_keymap_add_item(keymap, "SCREEN_OT_animation_cancel", ESCKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", MEDIAPLAY, KM_PRESS, 0, 0);
@@ -3606,11 +3608,11 @@ void ED_keymap_screen(wmKeyConfig *keyconf)
#if 0 // XXX: disabled for restoring later... bad implementation
keymap= WM_keymap_find(keyconf, "Frames", 0, 0);
kmi = WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", RIGHTARROWKEY, KM_PRESS, KM_ALT, 0);
- RNA_boolean_set(kmi->ptr, "cycle_speed", 1);
+ RNA_boolean_set(kmi->ptr, "cycle_speed", TRUE);
kmi = WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", LEFTARROWKEY, KM_PRESS, KM_ALT, 0);
- RNA_boolean_set(kmi->ptr, "reverse", 1);
- RNA_boolean_set(kmi->ptr, "cycle_speed", 1);
+ RNA_boolean_set(kmi->ptr, "reverse", TRUE);
+ RNA_boolean_set(kmi->ptr, "cycle_speed", TRUE);
WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", DOWNARROWKEY, KM_PRESS, KM_ALT, 0);
#endif
diff --git a/source/blender/editors/sculpt_paint/CMakeLists.txt b/source/blender/editors/sculpt_paint/CMakeLists.txt
index 30f49264e90..9fa91af7aec 100644
--- a/source/blender/editors/sculpt_paint/CMakeLists.txt
+++ b/source/blender/editors/sculpt_paint/CMakeLists.txt
@@ -27,6 +27,7 @@ set(INC
../../imbuf
../../makesdna
../../makesrna
+ ../uvedit
../../render/extern/include
../../windowmanager
../../../../intern/guardedalloc
@@ -37,6 +38,7 @@ set(INC_SYS
)
set(SRC
+ paint_cursor.c
paint_image.c
paint_ops.c
paint_stroke.c
@@ -45,6 +47,7 @@ set(SRC
paint_vertex.c
sculpt.c
sculpt_undo.c
+ sculpt_uv.c
paint_intern.h
sculpt_intern.h
diff --git a/source/blender/editors/sculpt_paint/SConscript b/source/blender/editors/sculpt_paint/SConscript
index b3927fcee68..dd82e01240b 100644
--- a/source/blender/editors/sculpt_paint/SConscript
+++ b/source/blender/editors/sculpt_paint/SConscript
@@ -8,7 +8,7 @@ defs = []
incs = '../include ../../blenlib ../../blenkernel ../../makesdna ../../imbuf'
incs += ' ../../windowmanager #/intern/guardedalloc #/extern/glew/include'
incs += ' ../../render/extern/include'
-incs += ' ../../gpu ../../makesrna ../../blenloader'
+incs += ' ../../gpu ../../makesrna ../../blenloader ../uvedit'
if env['OURPLATFORM'] == 'linux':
cflags='-pthread'
diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c
new file mode 100644
index 00000000000..0148f11b930
--- /dev/null
+++ b/source/blender/editors/sculpt_paint/paint_cursor.c
@@ -0,0 +1,607 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2009 by Nicholas Bishop
+ * All rights reserved.
+ *
+ * Contributor(s): Jason Wilkins, Tom Musgrove.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ *
+ */
+
+/** \file blender/editors/sculpt_paint/paint_cursor.c
+ * \ingroup edsculpt
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
+
+#include "DNA_brush_types.h"
+#include "DNA_color_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_userdef_types.h"
+
+#include "BKE_brush.h"
+#include "BKE_context.h"
+#include "BKE_paint.h"
+
+#include "WM_api.h"
+
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
+
+#include "ED_view3d.h"
+
+#include "paint_intern.h"
+/* still needed for sculpt_stroke_get_location, should be
+ removed eventually (TODO) */
+#include "sculpt_intern.h"
+
+/* TODOs:
+
+ Some of the cursor drawing code is doing non-draw stuff
+ (e.g. updating the brush rake angle). This should be cleaned up
+ still.
+
+ There is also some ugliness with sculpt-specific code.
+ */
+
+typedef struct Snapshot {
+ float size[3];
+ float ofs[3];
+ float rot;
+ int brush_size;
+ int winx;
+ int winy;
+ int brush_map_mode;
+ int curve_changed_timestamp;
+} Snapshot;
+
+static int same_snap(Snapshot* snap, Brush* brush, ViewContext* vc)
+{
+ MTex* mtex = &brush->mtex;
+
+ return (((mtex->tex) &&
+ equals_v3v3(mtex->ofs, snap->ofs) &&
+ equals_v3v3(mtex->size, snap->size) &&
+ mtex->rot == snap->rot) &&
+
+ /* make brush smaller shouldn't cause a resample */
+ ((mtex->brush_map_mode == MTEX_MAP_MODE_FIXED &&
+ (brush_size(vc->scene, brush) <= snap->brush_size)) ||
+ (brush_size(vc->scene, brush) == snap->brush_size)) &&
+
+ (mtex->brush_map_mode == snap->brush_map_mode) &&
+ (vc->ar->winx == snap->winx) &&
+ (vc->ar->winy == snap->winy));
+}
+
+static void make_snap(Snapshot* snap, Brush* brush, ViewContext* vc)
+{
+ if (brush->mtex.tex) {
+ snap->brush_map_mode = brush->mtex.brush_map_mode;
+ copy_v3_v3(snap->ofs, brush->mtex.ofs);
+ copy_v3_v3(snap->size, brush->mtex.size);
+ snap->rot = brush->mtex.rot;
+ }
+ else {
+ snap->brush_map_mode = -1;
+ snap->ofs[0]= snap->ofs[1]= snap->ofs[2]= -1;
+ snap->size[0]= snap->size[1]= snap->size[2]= -1;
+ snap->rot = -1;
+ }
+
+ snap->brush_size = brush_size(vc->scene, brush);
+ snap->winx = vc->ar->winx;
+ snap->winy = vc->ar->winy;
+}
+
+static int load_tex(Sculpt *sd, Brush* br, ViewContext* vc)
+{
+ static GLuint overlay_texture = 0;
+ static int init = 0;
+ static int tex_changed_timestamp = -1;
+ static int curve_changed_timestamp = -1;
+ static Snapshot snap;
+ static int old_size = -1;
+
+ GLubyte* buffer = NULL;
+
+ int size;
+ int j;
+ int refresh;
+
+#ifndef _OPENMP
+ (void)sd; /* quied unused warning */
+#endif
+
+ if (br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED && !br->mtex.tex) return 0;
+
+ refresh =
+ !overlay_texture ||
+ (br->mtex.tex &&
+ (!br->mtex.tex->preview ||
+ br->mtex.tex->preview->changed_timestamp[0] != tex_changed_timestamp)) ||
+ !br->curve ||
+ br->curve->changed_timestamp != curve_changed_timestamp ||
+ !same_snap(&snap, br, vc);
+
+ if (refresh) {
+ if (br->mtex.tex && br->mtex.tex->preview)
+ tex_changed_timestamp = br->mtex.tex->preview->changed_timestamp[0];
+
+ if (br->curve)
+ curve_changed_timestamp = br->curve->changed_timestamp;
+
+ make_snap(&snap, br, vc);
+
+ if (br->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) {
+ int s = brush_size(vc->scene, br);
+ int r = 1;
+
+ for (s >>= 1; s > 0; s >>= 1)
+ r++;
+
+ size = (1<<r);
+
+ if (size < 256)
+ size = 256;
+
+ if (size < old_size)
+ size = old_size;
+ }
+ else
+ size = 512;
+
+ if (old_size != size) {
+ if (overlay_texture) {
+ glDeleteTextures(1, &overlay_texture);
+ overlay_texture = 0;
+ }
+
+ init = 0;
+
+ old_size = size;
+ }
+
+ buffer = MEM_mallocN(sizeof(GLubyte)*size*size, "load_tex");
+
+ #pragma omp parallel for schedule(static) if (sd->flags & SCULPT_USE_OPENMP)
+ for (j= 0; j < size; j++) {
+ int i;
+ float y;
+ float len;
+
+ for (i= 0; i < size; i++) {
+
+ // largely duplicated from tex_strength
+
+ const float rotation = -br->mtex.rot;
+ float radius = brush_size(vc->scene, br);
+ int index = j*size + i;
+ float x;
+ float avg;
+
+ x = (float)i/size;
+ y = (float)j/size;
+
+ x -= 0.5f;
+ y -= 0.5f;
+
+ if (br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED) {
+ x *= vc->ar->winx / radius;
+ y *= vc->ar->winy / radius;
+ }
+ else {
+ x *= 2;
+ y *= 2;
+ }
+
+ len = sqrtf(x*x + y*y);
+
+ if ((br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED) || len <= 1) {
+ /* it is probably worth optimizing for those cases where
+ the texture is not rotated by skipping the calls to
+ atan2, sqrtf, sin, and cos. */
+ if (br->mtex.tex && (rotation > 0.001f || rotation < -0.001f)) {
+ const float angle = atan2f(y, x) + rotation;
+
+ x = len * cosf(angle);
+ y = len * sinf(angle);
+ }
+
+ x *= br->mtex.size[0];
+ y *= br->mtex.size[1];
+
+ x += br->mtex.ofs[0];
+ y += br->mtex.ofs[1];
+
+ avg = br->mtex.tex ? paint_get_tex_pixel(br, x, y) : 1;
+
+ avg += br->texture_sample_bias;
+
+ if (br->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED)
+ avg *= brush_curve_strength(br, len, 1); /* Falloff curve */
+
+ buffer[index] = 255 - (GLubyte)(255*avg);
+ }
+ else {
+ buffer[index] = 0;
+ }
+ }
+ }
+
+ if (!overlay_texture)
+ glGenTextures(1, &overlay_texture);
+ }
+ else {
+ size= old_size;
+ }
+
+ glBindTexture(GL_TEXTURE_2D, overlay_texture);
+
+ if (refresh) {
+ if (!init) {
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, size, size, 0, GL_ALPHA, GL_UNSIGNED_BYTE, buffer);
+ init = 1;
+ }
+ else {
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size, size, GL_ALPHA, GL_UNSIGNED_BYTE, buffer);
+ }
+
+ if (buffer)
+ MEM_freeN(buffer);
+ }
+
+ glEnable(GL_TEXTURE_2D);
+
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ if (br->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
+ }
+
+ return 1;
+}
+
+static int project_brush_radius(ViewContext *vc,
+ float radius,
+ const float location[3])
+{
+ float view[3], nonortho[3], ortho[3], offset[3], p1[2], p2[2];
+
+ ED_view3d_global_to_vector(vc->rv3d, location, view);
+
+ // create a vector that is not orthogonal to view
+
+ if (fabsf(view[0]) < 0.1f) {
+ nonortho[0] = view[0] + 1.0f;
+ nonortho[1] = view[1];
+ nonortho[2] = view[2];
+ }
+ else if (fabsf(view[1]) < 0.1f) {
+ nonortho[0] = view[0];
+ nonortho[1] = view[1] + 1.0f;
+ nonortho[2] = view[2];
+ }
+ else {
+ nonortho[0] = view[0];
+ nonortho[1] = view[1];
+ nonortho[2] = view[2] + 1.0f;
+ }
+
+ // get a vector in the plane of the view
+ cross_v3_v3v3(ortho, nonortho, view);
+ normalize_v3(ortho);
+
+ // make a point on the surface of the brush tagent to the view
+ mul_v3_fl(ortho, radius);
+ add_v3_v3v3(offset, location, ortho);
+
+ // project the center of the brush, and the tangent point to the view onto the screen
+ project_float(vc->ar, location, p1);
+ project_float(vc->ar, offset, p2);
+
+ // the distance between these points is the size of the projected brush in pixels
+ return len_v2v2(p1, p2);
+}
+
+static int sculpt_get_brush_geometry(bContext* C, ViewContext *vc,
+ int x, int y, int* pixel_radius,
+ float location[3])
+{
+ Scene *scene = CTX_data_scene(C);
+ Paint *paint = paint_get_active(scene);
+ Brush *brush = paint_brush(paint);
+ float window[2];
+ int hit;
+
+ window[0] = x + vc->ar->winrct.xmin;
+ window[1] = y + vc->ar->winrct.ymin;
+
+ if(vc->obact->sculpt && vc->obact->sculpt->pbvh &&
+ sculpt_stroke_get_location(C, location, window)) {
+ *pixel_radius =
+ project_brush_radius(vc,
+ brush_unprojected_radius(scene, brush),
+ location);
+
+ if (*pixel_radius == 0)
+ *pixel_radius = brush_size(scene, brush);
+
+ mul_m4_v3(vc->obact->obmat, location);
+
+ hit = 1;
+ }
+ else {
+ Sculpt* sd = CTX_data_tool_settings(C)->sculpt;
+ Brush* brush = paint_brush(&sd->paint);
+
+ *pixel_radius = brush_size(scene, brush);
+ hit = 0;
+ }
+
+ return hit;
+}
+
+/* Draw an overlay that shows what effect the brush's texture will
+ have on brush strength */
+/* TODO: sculpt only for now */
+static void paint_draw_alpha_overlay(Sculpt *sd, Brush *brush,
+ ViewContext *vc, int x, int y)
+{
+ rctf quad;
+
+ /* check for overlay mode */
+ if(!(brush->flag & BRUSH_TEXTURE_OVERLAY) ||
+ !(ELEM(brush->mtex.brush_map_mode, MTEX_MAP_MODE_FIXED, MTEX_MAP_MODE_TILED)))
+ return;
+
+ /* save lots of GL state
+ TODO: check on whether all of these are needed? */
+ glPushAttrib(GL_COLOR_BUFFER_BIT|
+ GL_CURRENT_BIT|
+ GL_DEPTH_BUFFER_BIT|
+ GL_ENABLE_BIT|
+ GL_LINE_BIT|
+ GL_POLYGON_BIT|
+ GL_STENCIL_BUFFER_BIT|
+ GL_TRANSFORM_BIT|
+ GL_VIEWPORT_BIT|
+ GL_TEXTURE_BIT);
+
+ if(load_tex(sd, brush, vc)) {
+ glEnable(GL_BLEND);
+
+ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ glDepthMask(GL_FALSE);
+ glDepthFunc(GL_ALWAYS);
+
+ glMatrixMode(GL_TEXTURE);
+ glPushMatrix();
+ glLoadIdentity();
+
+ if(brush->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) {
+ /* brush rotation */
+ glTranslatef(0.5, 0.5, 0);
+ glRotatef((double)RAD2DEGF((brush->flag & BRUSH_RAKE) ?
+ sd->last_angle : sd->special_rotation),
+ 0.0, 0.0, 1.0);
+ glTranslatef(-0.5f, -0.5f, 0);
+
+ /* scale based on tablet pressure */
+ if(sd->draw_pressure && brush_use_size_pressure(vc->scene, brush)) {
+ glTranslatef(0.5f, 0.5f, 0);
+ glScalef(1.0f/sd->pressure_value, 1.0f/sd->pressure_value, 1);
+ glTranslatef(-0.5f, -0.5f, 0);
+ }
+
+ if(sd->draw_anchored) {
+ const float *aim = sd->anchored_initial_mouse;
+ const rcti *win = &vc->ar->winrct;
+ quad.xmin = aim[0]-sd->anchored_size - win->xmin;
+ quad.ymin = aim[1]-sd->anchored_size - win->ymin;
+ quad.xmax = aim[0]+sd->anchored_size - win->xmin;
+ quad.ymax = aim[1]+sd->anchored_size - win->ymin;
+ }
+ else {
+ const int radius= brush_size(vc->scene, brush);
+ quad.xmin = x - radius;
+ quad.ymin = y - radius;
+ quad.xmax = x + radius;
+ quad.ymax = y + radius;
+ }
+ }
+ else {
+ quad.xmin = 0;
+ quad.ymin = 0;
+ quad.xmax = vc->ar->winrct.xmax - vc->ar->winrct.xmin;
+ quad.ymax = vc->ar->winrct.ymax - vc->ar->winrct.ymin;
+ }
+
+ /* set quad color */
+ glColor4f(U.sculpt_paint_overlay_col[0],
+ U.sculpt_paint_overlay_col[1],
+ U.sculpt_paint_overlay_col[2],
+ brush->texture_overlay_alpha / 100.0f);
+
+ /* draw textured quad */
+ glBegin(GL_QUADS);
+ glTexCoord2f(0, 0);
+ glVertex2f(quad.xmin, quad.ymin);
+ glTexCoord2f(1, 0);
+ glVertex2f(quad.xmax, quad.ymin);
+ glTexCoord2f(1, 1);
+ glVertex2f(quad.xmax, quad.ymax);
+ glTexCoord2f(0, 1);
+ glVertex2f(quad.xmin, quad.ymax);
+ glEnd();
+
+ glPopMatrix();
+ }
+
+ glPopAttrib();
+}
+
+/* Special actions taken when paint cursor goes over mesh */
+/* TODO: sculpt only for now */
+static void paint_cursor_on_hit(Sculpt *sd, Brush *brush, ViewContext *vc,
+ const float location[3])
+{
+ float unprojected_radius, projected_radius;
+
+ /* update the brush's cached 3D radius */
+ if(!brush_use_locked_size(vc->scene, brush)) {
+ /* get 2D brush radius */
+ if(sd->draw_anchored)
+ projected_radius = sd->anchored_size;
+ else {
+ if(brush->flag & BRUSH_ANCHORED)
+ projected_radius = 8;
+ else
+ projected_radius = brush_size(vc->scene, brush);
+ }
+
+ /* convert brush radius from 2D to 3D */
+ unprojected_radius = paint_calc_object_space_radius(vc, location,
+ projected_radius);
+
+ /* scale 3D brush radius by pressure */
+ if(sd->draw_pressure && brush_use_size_pressure(vc->scene, brush))
+ unprojected_radius *= sd->pressure_value;
+
+ /* set cached value in either Brush or UnifiedPaintSettings */
+ brush_set_unprojected_radius(vc->scene, brush, unprojected_radius);
+ }
+}
+
+static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
+{
+ Scene *scene = CTX_data_scene(C);
+ Paint *paint = paint_get_active(scene);
+ Brush *brush = paint_brush(paint);
+ ViewContext vc;
+ float final_radius;
+ float translation[2];
+ float outline_alpha, *outline_col;
+
+ /* set various defaults */
+ translation[0] = x;
+ translation[1] = y;
+ outline_alpha = 0.5;
+ outline_col = brush->add_col;
+ final_radius = brush_size(scene, brush);
+
+ /* check that brush drawing is enabled */
+ if(!(paint->flags & PAINT_SHOW_BRUSH))
+ return;
+
+ /* can't use stroke vc here because this will be called during
+ mouse over too, not just during a stroke */
+ view3d_set_viewcontext(C, &vc);
+
+ /* TODO: as sculpt and other paint modes are unified, this
+ special mode of drawing will go away */
+ if(vc.obact->sculpt) {
+ Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
+ float location[3];
+ int pixel_radius, hit;
+
+ /* this is probably here so that rake takes into
+ account the brush movements before the stroke
+ starts, but this doesn't really belong in draw code
+ (TODO) */
+ {
+ const float u = 0.5f;
+ const float v = 1 - u;
+ const float r = 20;
+
+ const float dx = sd->last_x - x;
+ const float dy = sd->last_y - y;
+
+ if(dx*dx + dy*dy >= r*r) {
+ sd->last_angle = atan2(dx, dy);
+
+ sd->last_x = u*sd->last_x + v*x;
+ sd->last_y = u*sd->last_y + v*y;
+ }
+ }
+
+ /* test if brush is over the mesh */
+ hit = sculpt_get_brush_geometry(C, &vc, x, y, &pixel_radius, location);
+
+ /* draw overlay */
+ paint_draw_alpha_overlay(sd, brush, &vc, x, y);
+
+ if(brush_use_locked_size(scene, brush))
+ brush_set_size(scene, brush, pixel_radius);
+
+ /* check if brush is subtracting, use different color then */
+ /* TODO: no way currently to know state of pen flip or
+ invert key modifier without starting a stroke */
+ if((!(brush->flag & BRUSH_INVERTED) ^
+ !(brush->flag & BRUSH_DIR_IN)) &&
+ ELEM5(brush->sculpt_tool, SCULPT_TOOL_DRAW,
+ SCULPT_TOOL_INFLATE, SCULPT_TOOL_CLAY,
+ SCULPT_TOOL_PINCH, SCULPT_TOOL_CREASE))
+ outline_col = brush->sub_col;
+
+ /* only do if brush is over the mesh */
+ if(hit)
+ paint_cursor_on_hit(sd, brush, &vc, location);
+
+ if(sd->draw_anchored) {
+ final_radius = sd->anchored_size;
+ translation[0] = sd->anchored_initial_mouse[0] - vc.ar->winrct.xmin;
+ translation[1] = sd->anchored_initial_mouse[1] - vc.ar->winrct.ymin;
+ }
+ }
+
+ /* make lines pretty */
+ glEnable(GL_BLEND);
+ glEnable(GL_LINE_SMOOTH);
+
+ /* set brush color */
+ glColor4f(outline_col[0], outline_col[1], outline_col[2], outline_alpha);
+
+ /* draw brush outline */
+ glTranslatef(translation[0], translation[1], 0);
+ glutil_draw_lined_arc(0.0, M_PI*2.0, final_radius, 40);
+ glTranslatef(-translation[0], -translation[1], 0);
+
+ /* restore GL state */
+ glDisable(GL_BLEND);
+ glDisable(GL_LINE_SMOOTH);
+}
+
+/* Public API */
+
+void paint_cursor_start(bContext *C, int (*poll)(bContext *C))
+{
+ Paint *p = paint_get_active(CTX_data_scene(C));
+
+ if(p && !p->paint_cursor)
+ p->paint_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), poll, paint_draw_cursor, NULL);
+}
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c
index 8eeca2e4e15..a5b79d0c974 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -50,6 +50,7 @@
#include "BLI_memarena.h"
#include "BLI_threads.h"
#include "BLI_utildefines.h"
+#include "BLI_editVert.h"
#include "PIL_time.h"
@@ -80,6 +81,8 @@
#include "BKE_paint.h"
#include "BKE_report.h"
#include "BKE_scene.h"
+#include "BKE_global.h"
+#include "BKE_deform.h"
#include "BIF_gl.h"
#include "BIF_glutil.h"
@@ -91,6 +94,7 @@
#include "ED_sculpt.h"
#include "ED_uvedit.h"
#include "ED_view3d.h"
+#include "ED_mesh.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -100,6 +104,7 @@
#include "RNA_enum_types.h"
#include "GPU_draw.h"
+#include "GPU_extensions.h"
#include "paint_intern.h"
@@ -3742,15 +3747,13 @@ static void do_projectpaint_smear(ProjPaintState *ps, ProjPixel *projPixel, floa
static void do_projectpaint_smear_f(ProjPaintState *ps, ProjPixel *projPixel, float alpha, float mask, MemArena *smearArena, LinkNode **smearPixels_f, float co[2])
{
- unsigned char rgba_ub[4];
- unsigned char rgba_smear[4];
+ float rgba[4];
- if (project_paint_PickColor(ps, co, NULL, rgba_ub, 1)==0)
+ if (project_paint_PickColor(ps, co, rgba, NULL, 1)==0)
return;
- IMAPAINT_FLOAT_RGBA_TO_CHAR(rgba_smear, projPixel->pixel.f_pt);
/* (ProjPixelClone *)projPixel)->clonepx.uint = IMB_blend_color(*((unsigned int *)rgba_smear), *((unsigned int *)rgba_ub), (int)(alpha*mask*255), ps->blend); */
- blend_color_mix(((ProjPixelClone *)projPixel)->clonepx.ch, rgba_smear, (rgba_ub), (int)(alpha*mask*255));
+ blend_color_mix_float(((ProjPixelClone *)projPixel)->clonepx.f, projPixel->pixel.f_pt, rgba, alpha*mask);
BLI_linklist_prepend_arena(smearPixels_f, (void *)projPixel, smearArena);
}
@@ -3782,8 +3785,8 @@ static void do_projectpaint_draw_f(ProjPaintState *ps, ProjPixel *projPixel, flo
{
if (ps->is_texbrush) {
/* rgba already holds a texture result here from higher level function */
- float rgba_br[3];
if(use_color_correction){
+ float rgba_br[3];
srgb_to_linearrgb_v3_v3(rgba_br, ps->brush->rgb);
mul_v3_v3(rgba, rgba_br);
}
@@ -3999,7 +4002,7 @@ static void *do_projectpaint_thread(void *ph_v)
for (node= smearPixels_f; node; node= node->next) {
projPixel = node->link;
- IMAPAINT_CHAR_RGBA_TO_FLOAT(projPixel->pixel.f_pt, ((ProjPixelClone *)projPixel)->clonepx.ch);
+ copy_v4_v4(projPixel->pixel.f_pt, ((ProjPixelClone *)projPixel)->clonepx.f);
}
BLI_memarena_free(smearArena);
@@ -4167,7 +4170,8 @@ static void imapaint_image_update(SpaceImage *sima, Image *image, ImBuf *ibuf, s
if(texpaint || (sima && sima->lock)) {
int w = imapaintpartial.x2 - imapaintpartial.x1;
int h = imapaintpartial.y2 - imapaintpartial.y1;
- GPU_paint_update_image(image, imapaintpartial.x1, imapaintpartial.y1, w, h, !texpaint);
+ /* Testing with partial update in uv editor too */
+ GPU_paint_update_image(image, imapaintpartial.x1, imapaintpartial.y1, w, h, 0);//!texpaint);
}
}
@@ -4606,6 +4610,16 @@ static Brush *image_paint_brush(bContext *C)
return paint_brush(&settings->imapaint.paint);
}
+static Brush *uv_sculpt_brush(bContext *C)
+{
+ Scene *scene= CTX_data_scene(C);
+ ToolSettings *settings= scene->toolsettings;
+
+ if(!settings->uvsculpt)
+ return NULL;
+ return paint_brush(&settings->uvsculpt->paint);
+}
+
static int image_paint_poll(bContext *C)
{
Object *obact = CTX_data_active_object(C);
@@ -4630,6 +4644,31 @@ static int image_paint_poll(bContext *C)
return 0;
}
+static int uv_sculpt_brush_poll(bContext *C)
+{
+ EditMesh *em;
+ int ret;
+ Object *obedit = CTX_data_edit_object(C);
+ SpaceImage *sima= CTX_wm_space_image(C);
+ Scene *scene = CTX_data_scene(C);
+ ToolSettings *toolsettings = scene->toolsettings;
+
+ if(!uv_sculpt_brush(C) || !obedit || obedit->type != OB_MESH)
+ return 0;
+
+ em = BKE_mesh_get_editmesh(obedit->data);
+ ret = EM_texFaceCheck(em);
+ BKE_mesh_end_editmesh(obedit->data, em);
+
+ if(ret && sima) {
+ ARegion *ar= CTX_wm_region(C);
+ if((toolsettings->use_uv_sculpt) && ar->regiontype==RGN_TYPE_WINDOW)
+ return 1;
+ }
+
+ return 0;
+}
+
static int image_paint_3d_poll(bContext *C)
{
if(CTX_wm_region_view3d(C))
@@ -5086,7 +5125,7 @@ void PAINT_OT_image_paint(wmOperatorType *ot)
RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", "");
}
-static int get_imapaint_zoom(bContext *C, float *zoomx, float *zoomy)
+int get_imapaint_zoom(bContext *C, float *zoomx, float *zoomy)
{
RegionView3D *rv3d= CTX_wm_region_view3d(C);
@@ -5112,16 +5151,27 @@ static void brush_drawcursor(bContext *C, int x, int y, void *UNUSED(customdata)
#define PX_SIZE_FADE_MIN 4.0f
Scene *scene= CTX_data_scene(C);
- Brush *brush= image_paint_brush(C);
+ //Brush *brush= image_paint_brush(C);
Paint *paint= paint_get_active(scene);
+ Brush *brush= paint_brush(paint);
if(paint && brush && paint->flags & PAINT_SHOW_BRUSH) {
+ ToolSettings *ts;
float zoomx, zoomy;
const float size= (float)brush_size(scene, brush);
const short use_zoom= get_imapaint_zoom(C, &zoomx, &zoomy);
- const float pixel_size= MAX2(size * zoomx, size * zoomy);
+ float pixel_size;
float alpha= 0.5f;
+ ts = scene->toolsettings;
+
+ if(use_zoom && !ts->use_uv_sculpt){
+ pixel_size = MAX2(size * zoomx, size * zoomy);
+ }
+ else {
+ pixel_size = size;
+ }
+
/* fade out the brush (cheap trick to work around brush interfearing with sampling [#])*/
if(pixel_size < PX_SIZE_FADE_MIN) {
return;
@@ -5134,7 +5184,8 @@ static void brush_drawcursor(bContext *C, int x, int y, void *UNUSED(customdata)
glTranslatef((float)x, (float)y, 0.0f);
- if(use_zoom)
+ /* No need to scale for uv sculpting, on the contrary it might be useful to keep unscaled */
+ if(use_zoom && !ts->use_uv_sculpt)
glScalef(zoomx, zoomy, 1.0f);
glColor4f(brush->add_col[0], brush->add_col[1], brush->add_col[2], alpha);
@@ -5152,14 +5203,16 @@ static void brush_drawcursor(bContext *C, int x, int y, void *UNUSED(customdata)
static void toggle_paint_cursor(bContext *C, int enable)
{
- ToolSettings *settings= CTX_data_scene(C)->toolsettings;
+ wmWindowManager *wm= CTX_wm_manager(C);
+ Scene *scene = CTX_data_scene(C);
+ ToolSettings *settings= scene->toolsettings;
if(settings->imapaint.paintcursor && !enable) {
- WM_paint_cursor_end(CTX_wm_manager(C), settings->imapaint.paintcursor);
+ WM_paint_cursor_end(wm, settings->imapaint.paintcursor);
settings->imapaint.paintcursor = NULL;
}
else if(enable)
- settings->imapaint.paintcursor= WM_paint_cursor_activate(CTX_wm_manager(C), image_paint_poll, brush_drawcursor, NULL);
+ settings->imapaint.paintcursor= WM_paint_cursor_activate(wm, image_paint_poll, brush_drawcursor, NULL);
}
/* enable the paint cursor if it isn't already.
@@ -5178,6 +5231,27 @@ void ED_space_image_paint_update(wmWindowManager *wm, ToolSettings *settings)
}
}
+
+void ED_space_image_uv_sculpt_update(wmWindowManager *wm, ToolSettings *settings)
+{
+ if(settings->use_uv_sculpt) {
+ if(!settings->uvsculpt) {
+ settings->uvsculpt = MEM_callocN(sizeof(*settings->uvsculpt), "UV Smooth paint");
+ settings->uv_sculpt_tool = UV_SCULPT_TOOL_GRAB;
+ settings->uv_sculpt_settings = UV_SCULPT_LOCK_BORDERS | UV_SCULPT_ALL_ISLANDS;
+ settings->uv_relax_method = UV_SCULPT_TOOL_RELAX_LAPLACIAN;
+ }
+
+ paint_init(&settings->uvsculpt->paint, PAINT_CURSOR_SCULPT);
+
+ WM_paint_cursor_activate(wm, uv_sculpt_brush_poll,
+ brush_drawcursor, NULL);
+ }
+ else {
+ if(settings->uvsculpt)
+ settings->uvsculpt->paint.flags &= ~PAINT_SHOW_BRUSH;
+ }
+}
/************************ grab clone operator ************************/
typedef struct GrabClone {
@@ -5499,6 +5573,11 @@ int image_texture_paint_poll(bContext *C)
return (texture_paint_poll(C) || image_paint_poll(C));
}
+int uv_sculpt_poll(bContext *C)
+{
+ return uv_sculpt_brush_poll(C);
+}
+
int facemask_paint_poll(bContext *C)
{
return paint_facesel_test(CTX_data_active_object(C));
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h
index a5e68f9a244..73dc1e236f6 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -50,7 +50,7 @@ struct wmOperator;
struct wmOperatorType;
/* paint_stroke.c */
-typedef int (*StrokeGetLocation)(struct bContext *C, struct PaintStroke *stroke, float location[3], float mouse[2]);
+typedef int (*StrokeGetLocation)(struct bContext *C, float location[3], float mouse[2]);
typedef int (*StrokeTestStart)(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
typedef void (*StrokeUpdateStep)(struct bContext *C, struct PaintStroke *stroke, struct PointerRNA *itemptr);
typedef void (*StrokeDone)(struct bContext *C, struct PaintStroke *stroke);
@@ -103,6 +103,10 @@ void PAINT_OT_texture_paint_toggle(struct wmOperatorType *ot);
void PAINT_OT_project_image(struct wmOperatorType *ot);
void PAINT_OT_image_from_view(struct wmOperatorType *ot);
+/* uv sculpting */
+int uv_sculpt_poll(struct bContext *C);
+
+void SCULPT_OT_uv_sculpt_stroke(struct wmOperatorType *ot);
/* paint_utils.c */
@@ -126,7 +130,7 @@ void paint_calc_redraw_planes(float planes[4][4],
const struct rcti *screen_rect);
void projectf(struct bglMats *mats, const float v[3], float p[2]);
-float paint_calc_object_space_radius(struct ViewContext *vc, float center[3], float pixel_radius);
+float paint_calc_object_space_radius(struct ViewContext *vc, const float center[3], float pixel_radius);
float paint_get_tex_pixel(struct Brush* br, float u, float v);
int imapaint_pick_face(struct ViewContext *vc, struct Mesh *me, const int mval[2], unsigned int *index);
void imapaint_pick_uv(struct Scene *scene, struct Object *ob, unsigned int faceindex, const int xy[2], float uv[2]);
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c
index e81e1f6dc77..c2026b30ab2 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -340,6 +340,39 @@ static void BRUSH_OT_image_tool_set(wmOperatorType *ot)
}
+static int brush_uv_sculpt_tool_set_exec(bContext *C, wmOperator *op)
+{
+ Brush *brush;
+ Scene *scene= CTX_data_scene(C);
+ ToolSettings *ts = scene->toolsettings;
+ ts->uv_sculpt_tool = RNA_enum_get(op->ptr, "tool");
+ brush = ts->uvsculpt->paint.brush;
+ /* To update toolshelf */
+ WM_event_add_notifier(C, NC_BRUSH|NA_EDITED, brush);
+
+ return OPERATOR_FINISHED;
+}
+
+static void BRUSH_OT_uv_sculpt_tool_set(wmOperatorType *ot)
+{
+ /* from rna_scene.c */
+ extern EnumPropertyItem uv_sculpt_tool_items[];
+ /* identifiers */
+ ot->name = "UV Sculpt Tool Set";
+ ot->description = "Set the uv sculpt tool";
+ ot->idname = "BRUSH_OT_uv_sculpt_tool_set";
+
+ /* api callbacks */
+ ot->exec = brush_uv_sculpt_tool_set_exec;
+ ot->poll = uv_sculpt_poll;
+
+ /* flags */
+ ot->flag = 0;
+
+ /* props */
+ ot->prop = RNA_def_enum(ot->srna, "tool", uv_sculpt_tool_items, 0, "Tool", "");
+}
+
/**************************** registration **********************************/
void ED_operatortypes_paint(void)
@@ -355,6 +388,7 @@ void ED_operatortypes_paint(void)
WM_operatortype_append(BRUSH_OT_vertex_tool_set);
WM_operatortype_append(BRUSH_OT_weight_tool_set);
WM_operatortype_append(BRUSH_OT_image_tool_set);
+ WM_operatortype_append(BRUSH_OT_uv_sculpt_tool_set);
/* image */
WM_operatortype_append(PAINT_OT_texture_paint_toggle);
@@ -373,6 +407,9 @@ void ED_operatortypes_paint(void)
WM_operatortype_append(PAINT_OT_weight_sample);
WM_operatortype_append(PAINT_OT_weight_sample_group);
+ /* uv */
+ WM_operatortype_append(SCULPT_OT_uv_sculpt_stroke);
+
/* vertex selection */
WM_operatortype_append(PAINT_OT_vert_select_all);
WM_operatortype_append(PAINT_OT_vert_select_inverse);
@@ -395,67 +432,14 @@ void ED_operatortypes_paint(void)
static void ed_keymap_paint_brush_switch(wmKeyMap *keymap, const char *mode)
{
wmKeyMapItem *kmi;
-
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", ONEKEY, KM_PRESS, 0, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 0);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", TWOKEY, KM_PRESS, 0, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 1);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", THREEKEY, KM_PRESS, 0, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 2);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", FOURKEY, KM_PRESS, 0, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 3);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", FIVEKEY, KM_PRESS, 0, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 4);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", SIXKEY, KM_PRESS, 0, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 5);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", SEVENKEY, KM_PRESS, 0, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 6);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", EIGHTKEY, KM_PRESS, 0, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 7);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", NINEKEY, KM_PRESS, 0, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 8);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", ZEROKEY, KM_PRESS, 0, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 9);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", ONEKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 10);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", TWOKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 11);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", THREEKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 12);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", FOURKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 13);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", FIVEKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 14);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", SIXKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 15);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", SEVENKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 16);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", EIGHTKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 17);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", NINEKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 18);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", ZEROKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 19);
+ int i;
+ /* index 0-9 (zero key is tenth), shift key for index 10-19 */
+ for (i = 0; i < 20; i++) {
+ kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set",
+ ZEROKEY + ((i + 1) % 10), KM_PRESS, i < 10 ? 0 : KM_SHIFT, 0);
+ RNA_string_set(kmi->ptr, "mode", mode);
+ RNA_int_set(kmi->ptr, "index", i);
+ }
}
static void ed_keymap_paint_brush_size(wmKeyMap *keymap, const char *UNUSED(path))
@@ -556,11 +540,11 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
/* multires switch */
kmi= WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", PAGEUPKEY, KM_PRESS, 0, 0);
RNA_int_set(kmi->ptr, "level", 1);
- RNA_boolean_set(kmi->ptr, "relative", 1);
+ RNA_boolean_set(kmi->ptr, "relative", TRUE);
kmi= WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", PAGEDOWNKEY, KM_PRESS, 0, 0);
RNA_int_set(kmi->ptr, "level", -1);
- RNA_boolean_set(kmi->ptr, "relative", 1);
+ RNA_boolean_set(kmi->ptr, "relative", TRUE);
ed_keymap_paint_brush_switch(keymap, "sculpt");
ed_keymap_paint_brush_size(keymap, "tool_settings.sculpt.brush.size");
@@ -636,8 +620,10 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "PAINT_OT_vert_select_all", AKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "PAINT_OT_vert_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "VIEW3D_OT_select_border", BKEY, KM_PRESS, 0, 0);
- WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_SHIFT|KM_CTRL, 0)->ptr, "deselect", 1);
+ kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL, 0);
+ RNA_boolean_set(kmi->ptr, "deselect", FALSE);
+ kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_SHIFT|KM_CTRL, 0);
+ RNA_boolean_set(kmi->ptr, "deselect", TRUE);
WM_keymap_add_item(keymap, "VIEW3D_OT_select_circle", CKEY, KM_PRESS, 0, 0);
/* Image/Texture Paint mode */
@@ -662,10 +648,30 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "PAINT_OT_face_select_all", AKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "PAINT_OT_face_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1);
+ kmi = WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", FALSE);
+ kmi = WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", TRUE);
WM_keymap_add_item(keymap, "PAINT_OT_face_select_reveal", HKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked_pick", LKEY, KM_PRESS, 0, 0);
+
+ keymap= WM_keymap_find(keyconf, "UV Sculpt", 0, 0);
+ keymap->poll= uv_sculpt_poll;
+
+ kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", QKEY, KM_PRESS, 0, 0);
+ RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_uv_sculpt");
+
+ RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, 0, 0)->ptr, "mode", BRUSH_STROKE_NORMAL);
+ RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, KM_CTRL, 0)->ptr, "mode", BRUSH_STROKE_INVERT);
+ RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", BRUSH_STROKE_SMOOTH);
+
+ ed_keymap_paint_brush_size(keymap, "tool_settings.uv_sculpt.brush.size");
+ ed_keymap_paint_brush_radial_control(keymap, "uv_sculpt", 0);
+
+ RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_uv_sculpt_tool_set", SKEY, KM_PRESS, 0, 0)->ptr, "tool", UV_SCULPT_TOOL_RELAX);
+ RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_uv_sculpt_tool_set", PKEY, KM_PRESS, 0, 0)->ptr, "tool", UV_SCULPT_TOOL_PINCH);
+ RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_uv_sculpt_tool_set", GKEY, KM_PRESS, 0, 0)->ptr, "tool", UV_SCULPT_TOOL_GRAB);
+
}
diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c
index c3e0c35f524..cd8262f06bd 100644
--- a/source/blender/editors/sculpt_paint/paint_stroke.c
+++ b/source/blender/editors/sculpt_paint/paint_stroke.c
@@ -56,9 +56,6 @@
#include "ED_view3d.h"
#include "paint_intern.h"
-/* still needed for sculpt_stroke_get_location, should be
- removed eventually (TODO) */
-#include "sculpt_intern.h"
#include <float.h>
#include <math.h>
@@ -108,545 +105,6 @@ static void paint_draw_smooth_stroke(bContext *C, int x, int y, void *customdata
glDisable(GL_LINE_SMOOTH);
}
-typedef struct Snapshot {
- float size[3];
- float ofs[3];
- float rot;
- int brush_size;
- int winx;
- int winy;
- int brush_map_mode;
- int curve_changed_timestamp;
-} Snapshot;
-
-static int same_snap(Snapshot* snap, Brush* brush, ViewContext* vc)
-{
- MTex* mtex = &brush->mtex;
-
- return (((mtex->tex) &&
- equals_v3v3(mtex->ofs, snap->ofs) &&
- equals_v3v3(mtex->size, snap->size) &&
- mtex->rot == snap->rot) &&
-
- /* make brush smaller shouldn't cause a resample */
- ((mtex->brush_map_mode == MTEX_MAP_MODE_FIXED &&
- (brush_size(vc->scene, brush) <= snap->brush_size)) ||
- (brush_size(vc->scene, brush) == snap->brush_size)) &&
-
- (mtex->brush_map_mode == snap->brush_map_mode) &&
- (vc->ar->winx == snap->winx) &&
- (vc->ar->winy == snap->winy));
-}
-
-static void make_snap(Snapshot* snap, Brush* brush, ViewContext* vc)
-{
- if (brush->mtex.tex) {
- snap->brush_map_mode = brush->mtex.brush_map_mode;
- copy_v3_v3(snap->ofs, brush->mtex.ofs);
- copy_v3_v3(snap->size, brush->mtex.size);
- snap->rot = brush->mtex.rot;
- }
- else {
- snap->brush_map_mode = -1;
- snap->ofs[0]= snap->ofs[1]= snap->ofs[2]= -1;
- snap->size[0]= snap->size[1]= snap->size[2]= -1;
- snap->rot = -1;
- }
-
- snap->brush_size = brush_size(vc->scene, brush);
- snap->winx = vc->ar->winx;
- snap->winy = vc->ar->winy;
-}
-
-static int load_tex(Sculpt *sd, Brush* br, ViewContext* vc)
-{
- static GLuint overlay_texture = 0;
- static int init = 0;
- static int tex_changed_timestamp = -1;
- static int curve_changed_timestamp = -1;
- static Snapshot snap;
- static int old_size = -1;
-
- GLubyte* buffer = NULL;
-
- int size;
- int j;
- int refresh;
-
-#ifndef _OPENMP
- (void)sd; /* quied unused warning */
-#endif
-
- if (br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED && !br->mtex.tex) return 0;
-
- refresh =
- !overlay_texture ||
- (br->mtex.tex &&
- (!br->mtex.tex->preview ||
- br->mtex.tex->preview->changed_timestamp[0] != tex_changed_timestamp)) ||
- !br->curve ||
- br->curve->changed_timestamp != curve_changed_timestamp ||
- !same_snap(&snap, br, vc);
-
- if (refresh) {
- if (br->mtex.tex && br->mtex.tex->preview)
- tex_changed_timestamp = br->mtex.tex->preview->changed_timestamp[0];
-
- if (br->curve)
- curve_changed_timestamp = br->curve->changed_timestamp;
-
- make_snap(&snap, br, vc);
-
- if (br->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) {
- int s = brush_size(vc->scene, br);
- int r = 1;
-
- for (s >>= 1; s > 0; s >>= 1)
- r++;
-
- size = (1<<r);
-
- if (size < 256)
- size = 256;
-
- if (size < old_size)
- size = old_size;
- }
- else
- size = 512;
-
- if (old_size != size) {
- if (overlay_texture) {
- glDeleteTextures(1, &overlay_texture);
- overlay_texture = 0;
- }
-
- init = 0;
-
- old_size = size;
- }
-
- buffer = MEM_mallocN(sizeof(GLubyte)*size*size, "load_tex");
-
- #pragma omp parallel for schedule(static) if (sd->flags & SCULPT_USE_OPENMP)
- for (j= 0; j < size; j++) {
- int i;
- float y;
- float len;
-
- for (i= 0; i < size; i++) {
-
- // largely duplicated from tex_strength
-
- const float rotation = -br->mtex.rot;
- float radius = brush_size(vc->scene, br);
- int index = j*size + i;
- float x;
- float avg;
-
- x = (float)i/size;
- y = (float)j/size;
-
- x -= 0.5f;
- y -= 0.5f;
-
- if (br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED) {
- x *= vc->ar->winx / radius;
- y *= vc->ar->winy / radius;
- }
- else {
- x *= 2;
- y *= 2;
- }
-
- len = sqrtf(x*x + y*y);
-
- if ((br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED) || len <= 1) {
- /* it is probably worth optimizing for those cases where
- the texture is not rotated by skipping the calls to
- atan2, sqrtf, sin, and cos. */
- if (br->mtex.tex && (rotation > 0.001f || rotation < -0.001f)) {
- const float angle = atan2f(y, x) + rotation;
-
- x = len * cosf(angle);
- y = len * sinf(angle);
- }
-
- x *= br->mtex.size[0];
- y *= br->mtex.size[1];
-
- x += br->mtex.ofs[0];
- y += br->mtex.ofs[1];
-
- avg = br->mtex.tex ? paint_get_tex_pixel(br, x, y) : 1;
-
- avg += br->texture_sample_bias;
-
- if (br->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED)
- avg *= brush_curve_strength(br, len, 1); /* Falloff curve */
-
- buffer[index] = 255 - (GLubyte)(255*avg);
- }
- else {
- buffer[index] = 0;
- }
- }
- }
-
- if (!overlay_texture)
- glGenTextures(1, &overlay_texture);
- }
- else {
- size= old_size;
- }
-
- glBindTexture(GL_TEXTURE_2D, overlay_texture);
-
- if (refresh) {
- if (!init) {
- glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, size, size, 0, GL_ALPHA, GL_UNSIGNED_BYTE, buffer);
- init = 1;
- }
- else {
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size, size, GL_ALPHA, GL_UNSIGNED_BYTE, buffer);
- }
-
- if (buffer)
- MEM_freeN(buffer);
- }
-
- glEnable(GL_TEXTURE_2D);
-
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
- if (br->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
- }
-
- return 1;
-}
-
-static int project_brush_radius(RegionView3D* rv3d, float radius, float location[3], bglMats* mats)
-{
- float view[3], nonortho[3], ortho[3], offset[3], p1[2], p2[2];
-
- ED_view3d_global_to_vector(rv3d, location, view);
-
- // create a vector that is not orthogonal to view
-
- if (fabsf(view[0]) < 0.1f) {
- nonortho[0] = view[0] + 1.0f;
- nonortho[1] = view[1];
- nonortho[2] = view[2];
- }
- else if (fabsf(view[1]) < 0.1f) {
- nonortho[0] = view[0];
- nonortho[1] = view[1] + 1.0f;
- nonortho[2] = view[2];
- }
- else {
- nonortho[0] = view[0];
- nonortho[1] = view[1];
- nonortho[2] = view[2] + 1.0f;
- }
-
- // get a vector in the plane of the view
- cross_v3_v3v3(ortho, nonortho, view);
- normalize_v3(ortho);
-
- // make a point on the surface of the brush tagent to the view
- mul_v3_fl(ortho, radius);
- add_v3_v3v3(offset, location, ortho);
-
- // project the center of the brush, and the tagent point to the view onto the screen
- projectf(mats, location, p1);
- projectf(mats, offset, p2);
-
- // the distance between these points is the size of the projected brush in pixels
- return len_v2v2(p1, p2);
-}
-
-static int sculpt_get_brush_geometry(bContext* C, int x, int y, int* pixel_radius,
- float location[3])
-{
- struct PaintStroke *stroke;
- const Scene *scene = CTX_data_scene(C);
- float window[2];
- int hit;
-
- stroke = paint_stroke_new(C, NULL, NULL, NULL, NULL, 0);
-
- window[0] = x + stroke->vc.ar->winrct.xmin;
- window[1] = y + stroke->vc.ar->winrct.ymin;
-
- if(stroke->vc.obact->sculpt && stroke->vc.obact->sculpt->pbvh &&
- sculpt_stroke_get_location(C, stroke, location, window)) {
- *pixel_radius = project_brush_radius(stroke->vc.rv3d,
- brush_unprojected_radius(scene, stroke->brush),
- location, &stroke->mats);
-
- if (*pixel_radius == 0)
- *pixel_radius = brush_size(scene, stroke->brush);
-
- mul_m4_v3(stroke->vc.obact->obmat, location);
-
- hit = 1;
- }
- else {
- Sculpt* sd = CTX_data_tool_settings(C)->sculpt;
- Brush* brush = paint_brush(&sd->paint);
-
- *pixel_radius = brush_size(scene, brush);
- hit = 0;
- }
-
- paint_stroke_free(stroke);
-
- return hit;
-}
-
-/* Draw an overlay that shows what effect the brush's texture will
- have on brush strength */
-/* TODO: sculpt only for now */
-static void paint_draw_alpha_overlay(Sculpt *sd, Brush *brush,
- ViewContext *vc, int x, int y)
-{
- rctf quad;
-
- /* check for overlay mode */
- if(!(brush->flag & BRUSH_TEXTURE_OVERLAY) ||
- !(ELEM(brush->mtex.brush_map_mode, MTEX_MAP_MODE_FIXED, MTEX_MAP_MODE_TILED)))
- return;
-
- /* save lots of GL state
- TODO: check on whether all of these are needed? */
- glPushAttrib(GL_COLOR_BUFFER_BIT|
- GL_CURRENT_BIT|
- GL_DEPTH_BUFFER_BIT|
- GL_ENABLE_BIT|
- GL_LINE_BIT|
- GL_POLYGON_BIT|
- GL_STENCIL_BUFFER_BIT|
- GL_TRANSFORM_BIT|
- GL_VIEWPORT_BIT|
- GL_TEXTURE_BIT);
-
- if(load_tex(sd, brush, vc)) {
- glEnable(GL_BLEND);
-
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- glDepthMask(GL_FALSE);
- glDepthFunc(GL_ALWAYS);
-
- glMatrixMode(GL_TEXTURE);
- glPushMatrix();
- glLoadIdentity();
-
- if(brush->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) {
- /* brush rotation */
- glTranslatef(0.5, 0.5, 0);
- glRotatef((double)RAD2DEGF((brush->flag & BRUSH_RAKE) ?
- sd->last_angle : sd->special_rotation),
- 0.0, 0.0, 1.0);
- glTranslatef(-0.5f, -0.5f, 0);
-
- /* scale based on tablet pressure */
- if(sd->draw_pressure && brush_use_size_pressure(vc->scene, brush)) {
- glTranslatef(0.5f, 0.5f, 0);
- glScalef(1.0f/sd->pressure_value, 1.0f/sd->pressure_value, 1);
- glTranslatef(-0.5f, -0.5f, 0);
- }
-
- if(sd->draw_anchored) {
- const float *aim = sd->anchored_initial_mouse;
- const rcti *win = &vc->ar->winrct;
- quad.xmin = aim[0]-sd->anchored_size - win->xmin;
- quad.ymin = aim[1]-sd->anchored_size - win->ymin;
- quad.xmax = aim[0]+sd->anchored_size - win->xmin;
- quad.ymax = aim[1]+sd->anchored_size - win->ymin;
- }
- else {
- const int radius= brush_size(vc->scene, brush);
- quad.xmin = x - radius;
- quad.ymin = y - radius;
- quad.xmax = x + radius;
- quad.ymax = y + radius;
- }
- }
- else {
- quad.xmin = 0;
- quad.ymin = 0;
- quad.xmax = vc->ar->winrct.xmax - vc->ar->winrct.xmin;
- quad.ymax = vc->ar->winrct.ymax - vc->ar->winrct.ymin;
- }
-
- /* set quad color */
- glColor4f(U.sculpt_paint_overlay_col[0],
- U.sculpt_paint_overlay_col[1],
- U.sculpt_paint_overlay_col[2],
- brush->texture_overlay_alpha / 100.0f);
-
- /* draw textured quad */
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0);
- glVertex2f(quad.xmin, quad.ymin);
- glTexCoord2f(1, 0);
- glVertex2f(quad.xmax, quad.ymin);
- glTexCoord2f(1, 1);
- glVertex2f(quad.xmax, quad.ymax);
- glTexCoord2f(0, 1);
- glVertex2f(quad.xmin, quad.ymax);
- glEnd();
-
- glPopMatrix();
- }
-
- glPopAttrib();
-}
-
-/* Special actions taken when paint cursor goes over mesh */
-/* TODO: sculpt only for now */
-static void paint_cursor_on_hit(Sculpt *sd, Brush *brush, ViewContext *vc,
- float location[3], float *visual_strength)
-{
- float unprojected_radius, projected_radius;
-
- /* TODO: check whether this should really only be done when
- brush is over mesh? */
- if(sd->draw_pressure && brush_use_alpha_pressure(vc->scene, brush))
- (*visual_strength) *= sd->pressure_value;
-
- if(sd->draw_anchored)
- projected_radius = sd->anchored_size;
- else {
- if(brush->flag & BRUSH_ANCHORED)
- projected_radius = 8;
- else
- projected_radius = brush_size(vc->scene, brush);
- }
- unprojected_radius = paint_calc_object_space_radius(vc, location,
- projected_radius);
-
- if(sd->draw_pressure && brush_use_size_pressure(vc->scene, brush))
- unprojected_radius *= sd->pressure_value;
-
- if(!brush_use_locked_size(vc->scene, brush))
- brush_set_unprojected_radius(vc->scene, brush, unprojected_radius);
-}
-
-static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
-{
- Scene *scene = CTX_data_scene(C);
- Paint *paint = paint_get_active(scene);
- Brush *brush = paint_brush(paint);
- ViewContext vc;
- float final_radius;
- float translation[2];
- float outline_alpha, *outline_col;
-
- /* set various defaults */
- translation[0] = x;
- translation[1] = y;
- outline_alpha = 0.5;
- outline_col = brush->add_col;
- final_radius = brush_size(scene, brush);
-
- /* check that brush drawing is enabled */
- if(!(paint->flags & PAINT_SHOW_BRUSH))
- return;
-
- /* can't use stroke vc here because this will be called during
- mouse over too, not just during a stroke */
- view3d_set_viewcontext(C, &vc);
-
- /* TODO: as sculpt and other paint modes are unified, this
- special mode of drawing will go away */
- if(vc.obact->sculpt) {
- Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
- float location[3];
- int pixel_radius, hit;
- const float root_alpha = brush_alpha(scene, brush);
- float visual_strength = root_alpha*root_alpha;
- const float min_alpha = 0.20f;
- const float max_alpha = 0.80f;
-
- /* this is probably here so that rake takes into
- account the brush movements before the stroke
- starts, but this doesn't really belong in draw code
- (TODO) */
- {
- const float u = 0.5f;
- const float v = 1 - u;
- const float r = 20;
-
- const float dx = sd->last_x - x;
- const float dy = sd->last_y - y;
-
- if(dx*dx + dy*dy >= r*r) {
- sd->last_angle = atan2(dx, dy);
-
- sd->last_x = u*sd->last_x + v*x;
- sd->last_y = u*sd->last_y + v*y;
- }
- }
-
- /* test if brush is over the mesh */
- hit = sculpt_get_brush_geometry(C, x, y, &pixel_radius, location);
-
- /* draw overlay */
- paint_draw_alpha_overlay(sd, brush, &vc, x, y);
-
- if(brush_use_locked_size(scene, brush))
- brush_set_size(scene, brush, pixel_radius);
-
- /* check if brush is subtracting, use different color then */
- /* TODO: no way currently to know state of pen flip or
- invert key modifier without starting a stroke */
- if((!(brush->flag & BRUSH_INVERTED) ^
- !(brush->flag & BRUSH_DIR_IN)) &&
- ELEM5(brush->sculpt_tool, SCULPT_TOOL_DRAW,
- SCULPT_TOOL_INFLATE, SCULPT_TOOL_CLAY,
- SCULPT_TOOL_PINCH, SCULPT_TOOL_CREASE))
- outline_col = brush->sub_col;
-
- /* only do if brush is over the mesh */
- if(hit)
- paint_cursor_on_hit(sd, brush, &vc, location, &visual_strength);
-
- /* don't show effect of strength past the soft limit */
- if(visual_strength > 1)
- visual_strength = 1;
-
- outline_alpha = ((paint->flags & PAINT_SHOW_BRUSH_ON_SURFACE) ?
- min_alpha + (visual_strength*(max_alpha-min_alpha)) : 0.50f);
-
- if(sd->draw_anchored) {
- final_radius = sd->anchored_size;
- translation[0] = sd->anchored_initial_mouse[0] - vc.ar->winrct.xmin;
- translation[1] = sd->anchored_initial_mouse[1] - vc.ar->winrct.ymin;
- }
- }
-
- /* make lines pretty */
- glEnable(GL_BLEND);
- glEnable(GL_LINE_SMOOTH);
-
- /* set brush color */
- glColor4f(outline_col[0], outline_col[1], outline_col[2], outline_alpha);
-
- /* draw brush outline */
- glTranslatef(translation[0], translation[1], 0);
- glutil_draw_lined_arc(0.0, M_PI*2.0, final_radius, 40);
- glTranslatef(-translation[0], -translation[1], 0);
-
- /* restore GL state */
- glDisable(GL_BLEND);
- glDisable(GL_LINE_SMOOTH);
-}
-
/* if this is a tablet event, return tablet pressure and set *pen_flip
to 1 if the eraser tool is being used, 0 otherwise */
static float event_tablet_data(wmEvent *event, int *pen_flip)
@@ -705,7 +163,7 @@ static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *ev
/* TODO: can remove the if statement once all modes have this */
if(stroke->get_location)
- stroke->get_location(C, stroke, location, mouse);
+ stroke->get_location(C, location, mouse);
else
zero_v3(location);
@@ -969,12 +427,3 @@ int paint_poll(bContext *C)
CTX_wm_area(C)->spacetype == SPACE_VIEW3D &&
CTX_wm_region(C)->regiontype == RGN_TYPE_WINDOW;
}
-
-void paint_cursor_start(bContext *C, int (*poll)(bContext *C))
-{
- Paint *p = paint_get_active(CTX_data_scene(C));
-
- if(p && !p->paint_cursor)
- p->paint_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), poll, paint_draw_cursor, NULL);
-}
-
diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c
index fdacc2d15f5..0705ea29985 100644
--- a/source/blender/editors/sculpt_paint/paint_utils.c
+++ b/source/blender/editors/sculpt_paint/paint_utils.c
@@ -152,7 +152,7 @@ void projectf(bglMats *mats, const float v[3], float p[2])
p[1]= uy;
}
-float paint_calc_object_space_radius(ViewContext *vc, float center[3],
+float paint_calc_object_space_radius(ViewContext *vc, const float center[3],
float pixel_radius)
{
Object *ob = vc->obact;
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 27a0bc8f502..ce84e43955b 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -3105,7 +3105,7 @@ static void sculpt_update_cache_variants(bContext *C, Sculpt *sd, Object *ob,
halfway[0] = (float)dx * 0.5f + cache->initial_mouse[0];
halfway[1] = (float)dy * 0.5f + cache->initial_mouse[1];
- if (sculpt_stroke_get_location(C, stroke, out, halfway)) {
+ if (sculpt_stroke_get_location(C, out, halfway)) {
copy_v3_v3(sd->anchored_location, out);
copy_v2_v2(sd->anchored_initial_mouse, halfway);
copy_v2_v2(cache->tex_mouse, halfway);
@@ -3207,23 +3207,29 @@ static void sculpt_raycast_cb(PBVHNode *node, void *data_v, float* tmin)
(This allows us to ignore the GL depth buffer)
Returns 0 if the ray doesn't hit the mesh, non-zero otherwise
*/
-int sculpt_stroke_get_location(bContext *C, struct PaintStroke *stroke, float out[3], float mouse[2])
+int sculpt_stroke_get_location(bContext *C, float out[3], float mouse[2])
{
- ViewContext *vc = paint_stroke_view_context(stroke);
- Object *ob = vc->obact;
- SculptSession *ss= ob->sculpt;
- StrokeCache *cache= ss->cache;
+ ViewContext vc;
+ Object *ob;
+ SculptSession *ss;
+ StrokeCache *cache;
float ray_start[3], ray_end[3], ray_normal[3], dist;
float obimat[4][4];
float mval[2];
SculptRaycastData srd;
- mval[0] = mouse[0] - vc->ar->winrct.xmin;
- mval[1] = mouse[1] - vc->ar->winrct.ymin;
+ view3d_set_viewcontext(C, &vc);
+
+ ob = vc.obact;
+ ss = ob->sculpt;
+ cache = ss->cache;
sculpt_stroke_modifiers_check(C, ob);
- ED_view3d_win_to_segment_clip(vc->ar, vc->v3d, mval, ray_start, ray_end);
+ mval[0] = mouse[0] - vc.ar->winrct.xmin;
+ mval[1] = mouse[1] - vc.ar->winrct.ymin;
+
+ ED_view3d_win_to_segment_clip(vc.ar, vc.v3d, mval, ray_start, ray_end);
invert_m4_m4(obimat, ob->obmat);
mul_m4_v3(obimat, ray_start);
@@ -3232,7 +3238,7 @@ int sculpt_stroke_get_location(bContext *C, struct PaintStroke *stroke, float ou
sub_v3_v3v3(ray_normal, ray_end, ray_start);
dist= normalize_v3(ray_normal);
- srd.ss = vc->obact->sculpt;
+ srd.ss = vc.obact->sculpt;
srd.ray_start = ray_start;
srd.ray_normal = ray_normal;
srd.dist = dist;
@@ -3371,14 +3377,14 @@ static void sculpt_flush_update(bContext *C)
/* Returns whether the mouse/stylus is over the mesh (1)
or over the background (0) */
-static int over_mesh(bContext *C, struct wmOperator *op, float x, float y)
+static int over_mesh(bContext *C, struct wmOperator *UNUSED(op), float x, float y)
{
float mouse[2], co[3];
mouse[0] = x;
mouse[1] = y;
- return sculpt_stroke_get_location(C, op->customdata, co, mouse);
+ return sculpt_stroke_get_location(C, co, mouse);
}
static int sculpt_stroke_test_start(bContext *C, struct wmOperator *op,
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index 42205a8da04..275d1d52355 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -73,7 +73,7 @@ void sculpt_stroke_free(struct SculptStroke *);
void sculpt_stroke_add_point(struct SculptStroke *, const short x, const short y);
void sculpt_stroke_apply(struct Sculpt *sd, struct SculptStroke *);
void sculpt_stroke_apply_all(struct Sculpt *sd, struct SculptStroke *);
-int sculpt_stroke_get_location(bContext *C, struct PaintStroke *stroke, float out[3], float mouse[2]);
+int sculpt_stroke_get_location(bContext *C, float out[3], float mouse[2]);
/* Undo */
diff --git a/source/blender/editors/sculpt_paint/sculpt_uv.c b/source/blender/editors/sculpt_paint/sculpt_uv.c
new file mode 100644
index 00000000000..bf8cb58a2f5
--- /dev/null
+++ b/source/blender/editors/sculpt_paint/sculpt_uv.c
@@ -0,0 +1,780 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) Blender Foundation, 2002-2009
+ * All rights reserved.
+ *
+ * Contributor(s): Antony Riakiotakis
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ *
+ * UV Sculpt tools
+ *
+ */
+
+/** \file blender/editors/sculpt_paint/sculpt_uv.c
+ * \ingroup edsculpt
+ */
+
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_editVert.h"
+#include "BLI_math.h"
+#include "BLI_ghash.h"
+
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_brush_types.h"
+#include "DNA_meshdata_types.h"
+
+#include "BKE_brush.h"
+#include "BKE_paint.h"
+#include "BKE_context.h"
+#include "BKE_main.h"
+#include "BKE_depsgraph.h"
+#include "BKE_mesh.h"
+#include "BKE_customdata.h"
+
+#include "ED_screen.h"
+#include "ED_image.h"
+#include "ED_mesh.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+#include "RNA_enum_types.h"
+
+#include "paint_intern.h"
+#include "uvedit_intern.h"
+
+#include "UI_view2d.h"
+
+#define MARK_BOUNDARY 1
+
+typedef struct UvAdjacencyElement {
+ /* pointer to original uvelement */
+ UvElement *element;
+ /* uv pointer for convenience. Caution, this points to the original UVs! */
+ float *uv;
+ /* general use flag (Used to check if Element is boundary here) */
+ char flag;
+} UvAdjacencyElement;
+
+typedef struct UvEdge {
+ unsigned int uv1;
+ unsigned int uv2;
+ /* general use flag (Used to check if edge is boundary here, and propagates to adjacency elements) */
+ char flag;
+}UvEdge;
+
+typedef struct UVInitialStrokeElement{
+ /* index to unique uv */
+ int uv;
+
+ /* strength of brush on initial position */
+ float strength;
+
+ /* initial uv position */
+ float initial_uv[2];
+}UVInitialStrokeElement;
+
+typedef struct UVInitialStroke{
+ /* Initial Selection,for grab brushes for instance */
+ UVInitialStrokeElement *initialSelection;
+
+ /* total initially selected UVs*/
+ int totalInitialSelected;
+
+ /* initial mouse coordinates */
+ float init_coord[2];
+}UVInitialStroke;
+
+
+/* custom data for uv smoothing brush */
+typedef struct UvSculptData{
+ /* Contains the first of each set of coincident uvs.
+ * These will be used to perform smoothing on and propagate the changes
+ * to their coincident uvs */
+ UvAdjacencyElement *uv;
+
+ /* ...Is what it says */
+ int totalUniqueUvs;
+
+ /* Edges used for adjacency info, used with laplacian smoothing */
+ UvEdge *uvedges;
+
+ /* need I say more? */
+ int totalUvEdges;
+
+ /* data for initial stroke, used by tools like grab */
+ UVInitialStroke *initial_stroke;
+
+ /* timer to be used for airbrush-type brush */
+ wmTimer *timer;
+
+ /* to determine quickly adjacent uvs */
+ UvElementMap *elementMap;
+
+ /* uvsmooth Paint for fast reference */
+ Paint *uvsculpt;
+
+ /* tool to use. duplicating here to change if modifier keys are pressed */
+ char tool;
+
+ /* store invert flag here */
+ char invert;
+}UvSculptData;
+
+/*********** Improved Laplacian Relaxation Operator ************************/
+/* original code by Raul Fernandez Hernandez "farsthary" *
+ * adapted to uv smoothing by Antony Riakiatakis *
+ ***************************************************************************/
+
+typedef struct Temp_UvData{
+ float sum_co[2], p[2], b[2], sum_b[2];
+ int ncounter;
+}Temp_UVData;
+
+
+
+void HC_relaxation_iteration_uv(EditMesh *em, UvSculptData *sculptdata, float mouse_coord[2], float alpha, float radius, float aspectRatio){
+ Temp_UVData *tmp_uvdata;
+ float diff[2];
+ int i;
+ float radius_root = sqrt(radius);
+ Brush *brush = paint_brush(sculptdata->uvsculpt);
+
+ tmp_uvdata = (Temp_UVData *)MEM_callocN(sculptdata->totalUniqueUvs * sizeof(Temp_UVData), "Temporal data");
+
+ /* counting neighbors */
+ for (i = 0; i < sculptdata->totalUvEdges; i++){
+ UvEdge *tmpedge = sculptdata->uvedges+i;
+ tmp_uvdata[tmpedge->uv1].ncounter++;
+ tmp_uvdata[tmpedge->uv2].ncounter++;
+
+ add_v2_v2(tmp_uvdata[tmpedge->uv2].sum_co, sculptdata->uv[tmpedge->uv1].uv);
+ add_v2_v2(tmp_uvdata[tmpedge->uv1].sum_co, sculptdata->uv[tmpedge->uv2].uv);
+ }
+
+ for (i = 0; i < sculptdata->totalUniqueUvs; i++){
+ copy_v2_v2(diff,tmp_uvdata[i].sum_co);
+ mul_v2_fl(diff,1.f/tmp_uvdata[i].ncounter);
+ copy_v2_v2(tmp_uvdata[i].p,diff);
+
+ tmp_uvdata[i].b[0] = diff[0] - sculptdata->uv[i].uv[0];
+ tmp_uvdata[i].b[1] = diff[1] - sculptdata->uv[i].uv[1];
+ }
+
+ for (i = 0; i < sculptdata->totalUvEdges; i++){
+ UvEdge *tmpedge = sculptdata->uvedges+i;
+ add_v2_v2(tmp_uvdata[tmpedge->uv1].sum_b, tmp_uvdata[tmpedge->uv2].b);
+ add_v2_v2(tmp_uvdata[tmpedge->uv2].sum_b, tmp_uvdata[tmpedge->uv1].b);
+ }
+
+ for (i = 0; i < sculptdata->totalUniqueUvs; i++){
+ float dist;
+ /* This is supposed to happen only if "Pin Edges" is on, since we have initialization on stroke start
+ * If ever uv brushes get their own mode we should check for toolsettings option too */
+ if((sculptdata->uv[i].flag & MARK_BOUNDARY)){
+ continue;
+ }
+
+ sub_v2_v2v2(diff, sculptdata->uv[i].uv, mouse_coord);
+ diff[1] /= aspectRatio;
+ if((dist = dot_v2v2(diff, diff)) <= radius){
+ UvElement *element;
+ float strength;
+ strength = alpha*brush_curve_strength(brush, sqrt(dist), radius_root);
+
+ sculptdata->uv[i].uv[0] = (1.0-strength)*sculptdata->uv[i].uv[0] + strength*(tmp_uvdata[i].p[0] - 0.5f*(tmp_uvdata[i].b[0] + tmp_uvdata[i].sum_b[0]/tmp_uvdata[i].ncounter));
+ sculptdata->uv[i].uv[1] = (1.0-strength)*sculptdata->uv[i].uv[1] + strength*(tmp_uvdata[i].p[1] - 0.5f*(tmp_uvdata[i].b[1] + tmp_uvdata[i].sum_b[1]/tmp_uvdata[i].ncounter));
+
+ for(element = sculptdata->uv[i].element; element; element = element->next){
+ MTFace *mt;
+ if(element->separate && element != sculptdata->uv[i].element)
+ break;
+ mt = CustomData_em_get(&em->fdata, element->face->data, CD_MTFACE);
+ copy_v2_v2(mt->uv[element->tfindex], sculptdata->uv[i].uv);
+ }
+ }
+ }
+
+ MEM_freeN(tmp_uvdata);
+
+ return;
+}
+
+static void laplacian_relaxation_iteration_uv(EditMesh *em, UvSculptData *sculptdata, float mouse_coord[2], float alpha, float radius, float aspectRatio)
+{
+ Temp_UVData *tmp_uvdata;
+ float diff[2];
+ int i;
+ float radius_root = sqrt(radius);
+ Brush *brush = paint_brush(sculptdata->uvsculpt);
+
+ tmp_uvdata = (Temp_UVData *)MEM_callocN(sculptdata->totalUniqueUvs * sizeof(Temp_UVData), "Temporal data");
+
+ /* counting neighbors */
+ for (i = 0; i < sculptdata->totalUvEdges; i++){
+ UvEdge *tmpedge = sculptdata->uvedges+i;
+ tmp_uvdata[tmpedge->uv1].ncounter++;
+ tmp_uvdata[tmpedge->uv2].ncounter++;
+
+ add_v2_v2(tmp_uvdata[tmpedge->uv2].sum_co, sculptdata->uv[tmpedge->uv1].uv);
+ add_v2_v2(tmp_uvdata[tmpedge->uv1].sum_co, sculptdata->uv[tmpedge->uv2].uv);
+ }
+
+ /* Original Lacplacian algorithm included removal of normal component of translation. here it is not
+ * needed since we translate along the UV plane always.*/
+ for (i = 0; i < sculptdata->totalUniqueUvs; i++){
+ copy_v2_v2(tmp_uvdata[i].p, tmp_uvdata[i].sum_co);
+ mul_v2_fl(tmp_uvdata[i].p, 1.f/tmp_uvdata[i].ncounter);
+ }
+
+ for (i = 0; i < sculptdata->totalUniqueUvs; i++){
+ float dist;
+ /* This is supposed to happen only if "Pin Edges" is on, since we have initialization on stroke start
+ * If ever uv brushes get their own mode we should check for toolsettings option too */
+ if((sculptdata->uv[i].flag & MARK_BOUNDARY)){
+ continue;
+ }
+
+ sub_v2_v2v2(diff, sculptdata->uv[i].uv, mouse_coord);
+ diff[1] /= aspectRatio;
+ if((dist = dot_v2v2(diff, diff)) <= radius){
+ UvElement *element;
+ float strength;
+ strength = alpha*brush_curve_strength(brush, sqrt(dist), radius_root);
+
+ sculptdata->uv[i].uv[0] = (1.0-strength)*sculptdata->uv[i].uv[0] + strength*tmp_uvdata[i].p[0];
+ sculptdata->uv[i].uv[1] = (1.0-strength)*sculptdata->uv[i].uv[1] + strength*tmp_uvdata[i].p[1];
+
+ for(element = sculptdata->uv[i].element; element; element = element->next){
+ MTFace *mt;
+ if(element->separate && element != sculptdata->uv[i].element)
+ break;
+ mt = CustomData_em_get(&em->fdata, element->face->data, CD_MTFACE);
+ copy_v2_v2(mt->uv[element->tfindex], sculptdata->uv[i].uv);
+ }
+ }
+ }
+
+ MEM_freeN(tmp_uvdata);
+
+ return;
+}
+
+
+static void uv_sculpt_stroke_apply(bContext *C, wmOperator *op, wmEvent *event, Object *obedit)
+{
+ float co[2], radius, radius_root;
+ Scene *scene = CTX_data_scene(C);
+ ARegion *ar = CTX_wm_region(C);
+ EditMesh *em = BKE_mesh_get_editmesh(obedit->data);
+ unsigned int tool;
+ UvSculptData *sculptdata = (UvSculptData *)op->customdata;
+ SpaceImage *sima;
+ int invert;
+ int width, height;
+ float aspectRatio;
+ float alpha, zoomx, zoomy;
+ Brush *brush = paint_brush(sculptdata->uvsculpt);
+ ToolSettings *toolsettings = CTX_data_tool_settings(C);
+ tool = sculptdata->tool;
+ invert = sculptdata->invert? -1 : 1;
+ alpha = brush_alpha(scene, brush);
+ UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &co[0], &co[1]);
+
+ sima = CTX_wm_space_image(C);
+ ED_space_image_size(sima, &width, &height);
+ ED_space_image_zoom(sima, ar, &zoomx, &zoomy);
+
+ radius = brush_size(scene, brush)/(width*zoomx);
+ aspectRatio = width/(float)height;
+
+ /* We will compare squares to save some computation */
+ radius = radius*radius;
+ radius_root = sqrt(radius);
+
+ /*
+ * Pinch Tool
+ */
+ if(tool == UV_SCULPT_TOOL_PINCH){
+ int i;
+ alpha *= invert;
+ for (i = 0; i < sculptdata->totalUniqueUvs; i++){
+ float dist, diff[2];
+ /* This is supposed to happen only if "Lock Borders" is on, since we have initialization on stroke start
+ * If ever uv brushes get their own mode we should check for toolsettings option too */
+ if(sculptdata->uv[i].flag & MARK_BOUNDARY){
+ continue;
+ }
+
+ sub_v2_v2v2(diff, sculptdata->uv[i].uv, co);
+ diff[1] /= aspectRatio;
+ if((dist = dot_v2v2(diff, diff)) <= radius){
+ UvElement *element;
+ float strength;
+ strength = alpha*brush_curve_strength(brush, sqrt(dist), radius_root);
+ normalize_v2(diff);
+
+ sculptdata->uv[i].uv[0] -= strength*diff[0]*0.001;
+ sculptdata->uv[i].uv[1] -= strength*diff[1]*0.001;
+
+ for(element = sculptdata->uv[i].element; element; element = element->next){
+ MTFace *mt;
+ if(element->separate && element != sculptdata->uv[i].element)
+ break;
+ mt = CustomData_em_get(&em->fdata, element->face->data, CD_MTFACE);
+ copy_v2_v2(mt->uv[element->tfindex], sculptdata->uv[i].uv);
+ }
+ }
+ }
+ }
+
+ /*
+ * Smooth Tool
+ */
+ else if(tool == UV_SCULPT_TOOL_RELAX){
+ unsigned int method = toolsettings->uv_relax_method;
+ if(method == UV_SCULPT_TOOL_RELAX_HC){
+ HC_relaxation_iteration_uv(em, sculptdata, co, alpha, radius, aspectRatio);
+ }else{
+ laplacian_relaxation_iteration_uv(em, sculptdata, co, alpha, radius, aspectRatio);
+ }
+ }
+
+ /*
+ * Grab Tool
+ */
+ else if(tool == UV_SCULPT_TOOL_GRAB){
+ int i;
+ float diff[2];
+ sub_v2_v2v2(diff, co, sculptdata->initial_stroke->init_coord);
+
+ for(i = 0; i < sculptdata->initial_stroke->totalInitialSelected; i++ ){
+ UvElement *element;
+ int uvindex = sculptdata->initial_stroke->initialSelection[i].uv;
+ float strength = sculptdata->initial_stroke->initialSelection[i].strength;
+ sculptdata->uv[uvindex].uv[0] = sculptdata->initial_stroke->initialSelection[i].initial_uv[0] + strength*diff[0];
+ sculptdata->uv[uvindex].uv[1] = sculptdata->initial_stroke->initialSelection[i].initial_uv[1] + strength*diff[1];
+
+ for(element = sculptdata->uv[uvindex].element; element; element = element->next){
+ MTFace *mt;
+ if(element->separate && element != sculptdata->uv[uvindex].element)
+ break;
+ mt = CustomData_em_get(&em->fdata, element->face->data, CD_MTFACE);
+ copy_v2_v2(mt->uv[element->tfindex], sculptdata->uv[uvindex].uv);
+ }
+ }
+ }
+
+ BKE_mesh_end_editmesh(obedit->data, em);
+}
+
+
+static void uv_sculpt_stroke_exit(bContext *C, wmOperator *op)
+{
+ UvSculptData *data = op->customdata;
+ if(data->timer){
+ WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), data->timer);
+ }
+ if(data->elementMap)
+ {
+ EM_free_uv_element_map(data->elementMap);
+ }
+ if(data->uv){
+ MEM_freeN(data->uv);
+ }
+ if(data->uvedges){
+ MEM_freeN(data->uvedges);
+ }
+ if(data->initial_stroke){
+ if(data->initial_stroke->initialSelection){
+ MEM_freeN(data->initial_stroke->initialSelection);
+ }
+ MEM_freeN(data->initial_stroke);
+ }
+
+ MEM_freeN(data);
+ op->customdata = NULL;
+}
+
+static int get_uv_element_offset_from_face(UvElementMap *map, EditFace *efa, int index, int island_index, int doIslands){
+ UvElement *element = ED_get_uv_element(map, efa, index);
+ if(!element || (doIslands && element->island != island_index)){
+ return -1;
+ }
+ return element - map->buf;
+}
+
+
+static unsigned int uv_edge_hash(const void *key){
+ UvEdge *edge = (UvEdge *)key;
+ return
+ BLI_ghashutil_inthash(SET_INT_IN_POINTER(edge->uv2)) +
+ BLI_ghashutil_inthash(SET_INT_IN_POINTER(edge->uv1));
+}
+
+static int uv_edge_compare(const void *a, const void *b){
+ UvEdge *edge1 = (UvEdge *)a;
+ UvEdge *edge2 = (UvEdge *)b;
+
+ if((edge1->uv1 == edge2->uv1) && (edge1->uv2 == edge2->uv2)){
+ return 0;
+ }
+ return 1;
+}
+
+
+static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, wmEvent *event)
+{
+ Scene *scene = CTX_data_scene(C);
+ Object *obedit = CTX_data_edit_object(C);
+ ToolSettings *ts = scene->toolsettings;
+ UvSculptData *data = MEM_callocN(sizeof(*data), "UV Smooth Brush Data");
+ EditMesh *em = BKE_mesh_get_editmesh(obedit->data);
+
+ op->customdata = data;
+
+ if(data){
+ int counter = 0, i;
+ ARegion *ar= CTX_wm_region(C);
+ float co[2];
+ EditFace *efa;
+ UvEdge *edges;
+ GHash *edgeHash;
+ GHashIterator* ghi;
+ MTFace *mt;
+ int do_island_optimization = !(ts->uv_sculpt_settings & UV_SCULPT_ALL_ISLANDS);
+ int island_index = 0;
+ /* Holds, for each UvElement in elementMap, a pointer to its unique uv.*/
+ int *uniqueUv;
+ data->tool = (RNA_enum_get(op->ptr, "mode") == BRUSH_STROKE_SMOOTH)? UV_SCULPT_TOOL_RELAX : ts->uv_sculpt_tool;
+ data->invert = (RNA_enum_get(op->ptr, "mode") == BRUSH_STROKE_INVERT)? 1 : 0;
+
+ data->uvsculpt = &ts->uvsculpt->paint;
+
+ if(do_island_optimization){
+ /* We will need island information */
+ if(ts->uv_flag & UV_SYNC_SELECTION){
+ data->elementMap = EM_make_uv_element_map(em, 0, 1);
+ }else{
+ data->elementMap = EM_make_uv_element_map(em, 1, 1);
+ }
+ }else {
+ if(ts->uv_flag & UV_SYNC_SELECTION){
+ data->elementMap = EM_make_uv_element_map(em, 0, 0);
+ }else{
+ data->elementMap = EM_make_uv_element_map(em, 1, 0);
+ }
+ }
+
+ if(!data->elementMap){
+ uv_sculpt_stroke_exit(C, op);
+ return NULL;
+ }
+
+ /* Mouse coordinates, useful for some functions like grab and sculpt all islands */
+ UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &co[0], &co[1]);
+
+ /* we need to find the active island here */
+ if(do_island_optimization){
+ UvElement *element;
+ NearestHit hit;
+ Image *ima= CTX_data_edit_image(C);
+ uv_find_nearest_vert(scene, ima, em, co, NULL, &hit);
+
+ element = ED_get_uv_element(data->elementMap, hit.efa, hit.uv);
+ island_index = element->island;
+ }
+
+
+ /* Count 'unique' uvs */
+ for(i = 0; i < data->elementMap->totalUVs; i++){
+ if(data->elementMap->buf[i].separate
+ && (!do_island_optimization || data->elementMap->buf[i].island == island_index)){
+ counter++;
+ }
+ }
+
+ /* Allocate the unique uv buffers */
+ data->uv = MEM_mallocN(sizeof(*data->uv)*counter, "uv_brush_unique_uvs");
+ uniqueUv = MEM_mallocN(sizeof(*uniqueUv)*data->elementMap->totalUVs, "uv_brush_unique_uv_map");
+ edgeHash = BLI_ghash_new(uv_edge_hash, uv_edge_compare, "uv_brush_edge_hash");
+ /* we have at most totalUVs edges */
+ edges = MEM_mallocN(sizeof(*edges)*data->elementMap->totalUVs, "uv_brush_all_edges");
+ if(!data->uv || !uniqueUv || !edgeHash || !edges){
+ if(edges){
+ MEM_freeN(edges);
+ }
+ if(uniqueUv){
+ MEM_freeN(uniqueUv);
+ }
+ if(edgeHash){
+ MEM_freeN(edgeHash);
+ }
+ uv_sculpt_stroke_exit(C, op);
+ return NULL;
+ }
+
+ data->totalUniqueUvs = counter;
+ /* So that we can use this as index for the UvElements */
+ counter = -1;
+ /* initialize the unique UVs */
+ for(i = 0; i < em->totvert; i++){
+ UvElement *element = data->elementMap->vert[i];
+ for(; element; element = element->next){
+ if(element->separate){
+ if(do_island_optimization && (element->island != island_index)){
+ /* skip this uv if not on the active island */
+ for(; element->next && !(element->next->separate); element = element->next)
+ ;
+ continue;
+ }
+ efa = element->face;
+ mt = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+
+ counter++;
+ data->uv[counter].element = element;
+ data->uv[counter].flag = 0;
+ data->uv[counter].uv = mt->uv[element->tfindex];
+ }
+ /* pointer arithmetic to the rescue, as always :)*/
+ uniqueUv[element - data->elementMap->buf] = counter;
+ }
+ }
+
+ /* Now, on to generate our uv connectivity data */
+ for(efa = em->faces.first, counter = 0; efa; efa = efa->next){
+ int nverts = efa->v4 ? 4 : 3;
+ for(i = 0; i < nverts; i++){
+ int offset1, itmp1 = get_uv_element_offset_from_face(data->elementMap, efa, i, island_index, do_island_optimization);
+ int offset2, itmp2 = get_uv_element_offset_from_face(data->elementMap, efa, (i+1)%nverts, island_index, do_island_optimization);
+
+ /* Skip edge if not found(unlikely) or not on valid island */
+ if(itmp1 == -1 || itmp2 == -1)
+ continue;
+
+ offset1 = uniqueUv[itmp1];
+ offset2 = uniqueUv[itmp2];
+
+ edges[counter].flag = 0;
+ /* using an order policy, sort uvs according to address space. This avoids
+ * Having two different UvEdges with the same uvs on different positions */
+ if(offset1 < offset2){
+ edges[counter].uv1 = offset1;
+ edges[counter].uv2 = offset2;
+ }
+ else{
+ edges[counter].uv1 = offset2;
+ edges[counter].uv2 = offset1;
+ }
+ /* Hack! Set the value of the key to its flag. Now we can set the flag when an edge exists twice :) */
+ if(BLI_ghash_haskey(edgeHash, &edges[counter])){
+ char *flag = BLI_ghash_lookup(edgeHash, &edges[counter]);
+ *flag = 1;
+ }
+ else{
+ /* Hack mentioned */
+ BLI_ghash_insert(edgeHash, &edges[counter], &edges[counter].flag);
+ }
+ counter++;
+ }
+ }
+ MEM_freeN(uniqueUv);
+
+ /* Allocate connectivity data, we allocate edges once */
+ data->uvedges = MEM_mallocN(sizeof(*data->uvedges)*BLI_ghash_size(edgeHash), "uv_brush_edge_connectivity_data");
+ if(!data->uvedges){
+ BLI_ghash_free(edgeHash, NULL, NULL);
+ MEM_freeN(edges);
+ uv_sculpt_stroke_exit(C, op);
+ return NULL;
+ }
+ ghi = BLI_ghashIterator_new(edgeHash);
+ if(!ghi){
+ BLI_ghash_free(edgeHash, NULL, NULL);
+ MEM_freeN(edges);
+ uv_sculpt_stroke_exit(C, op);
+ return NULL;
+ }
+ /* fill the edges with data */
+ for(i = 0; !BLI_ghashIterator_isDone(ghi); BLI_ghashIterator_step(ghi)){
+ data->uvedges[i++] = *((UvEdge *)BLI_ghashIterator_getKey(ghi));
+ }
+ data->totalUvEdges = BLI_ghash_size(edgeHash);
+
+ /* cleanup temporary stuff */
+ BLI_ghashIterator_free(ghi);
+ BLI_ghash_free(edgeHash, NULL, NULL);
+ MEM_freeN(edges);
+
+ /* transfer boundary edge property to uvs */
+ if(ts->uv_sculpt_settings & UV_SCULPT_LOCK_BORDERS){
+ for(i = 0; i < data->totalUvEdges; i++){
+ if(!data->uvedges[i].flag){
+ data->uv[data->uvedges[i].uv1].flag |= MARK_BOUNDARY;
+ data->uv[data->uvedges[i].uv2].flag |= MARK_BOUNDARY;
+ }
+ }
+ }
+
+ /* Allocate initial selection for grab tool */
+ if(data->tool){
+ float radius, radius_root;
+ UvSculptData *sculptdata = (UvSculptData *)op->customdata;
+ SpaceImage *sima;
+ int width, height;
+ float aspectRatio;
+ float alpha, zoomx, zoomy;
+ Brush *brush = paint_brush(sculptdata->uvsculpt);
+
+ alpha = brush_alpha(scene, brush);
+
+ radius = brush_size(scene, brush);
+ sima = CTX_wm_space_image(C);
+ ED_space_image_size(sima, &width, &height);
+ ED_space_image_zoom(sima, ar, &zoomx, &zoomy);
+
+ aspectRatio = width/(float)height;
+ radius /= (width*zoomx);
+ radius = radius*radius;
+ radius_root = sqrt(radius);
+
+ /* Allocate selection stack */
+ data->initial_stroke = MEM_mallocN(sizeof(*data->initial_stroke), "uv_sculpt_initial_stroke");
+ if(!data->initial_stroke){
+ uv_sculpt_stroke_exit(C, op);
+ }
+ data->initial_stroke->initialSelection = MEM_mallocN(sizeof(*data->initial_stroke->initialSelection)*data->totalUniqueUvs, "uv_sculpt_initial_selection");
+ if(!data->initial_stroke->initialSelection){
+ uv_sculpt_stroke_exit(C, op);
+ }
+
+ copy_v2_v2(data->initial_stroke->init_coord, co);
+
+ counter = 0;
+
+ for(i = 0; i < data->totalUniqueUvs; i++){
+ float dist, diff[2];
+ if(data->uv[i].flag & MARK_BOUNDARY){
+ continue;
+ }
+
+ sub_v2_v2v2(diff, data->uv[i].uv, co);
+ diff[1] /= aspectRatio;
+ if((dist = dot_v2v2(diff, diff)) <= radius){
+ float strength;
+ strength = alpha*brush_curve_strength(brush, sqrt(dist), radius_root);
+
+ data->initial_stroke->initialSelection[counter].uv = i;
+ data->initial_stroke->initialSelection[counter].strength = strength;
+ copy_v2_v2(data->initial_stroke->initialSelection[counter].initial_uv, data->uv[i].uv);
+ counter++;
+ }
+ }
+
+ data->initial_stroke->totalInitialSelected = counter;
+ }
+ }
+
+ return op->customdata;
+}
+
+static int uv_sculpt_stroke_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+ UvSculptData *data;
+ Object *obedit = CTX_data_edit_object(C);
+
+ if(!(data = uv_sculpt_stroke_init(C, op, event))) {
+ return OPERATOR_CANCELLED;
+ }
+
+ uv_sculpt_stroke_apply(C, op, event, obedit);
+
+ data->timer= WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.001f);
+
+ if(!data->timer){
+ uv_sculpt_stroke_exit(C, op);
+ return OPERATOR_CANCELLED;
+ }
+ WM_event_add_modal_handler(C, op);
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+
+static int uv_sculpt_stroke_modal(bContext *C, wmOperator *op, wmEvent *event)
+{
+ UvSculptData *data = (UvSculptData *)op->customdata;
+ Object *obedit = CTX_data_edit_object(C);
+
+ switch(event->type) {
+ case LEFTMOUSE:
+ case MIDDLEMOUSE:
+ case RIGHTMOUSE:
+ uv_sculpt_stroke_exit(C, op);
+ return OPERATOR_FINISHED;
+
+ case MOUSEMOVE:
+ case INBETWEEN_MOUSEMOVE:
+ uv_sculpt_stroke_apply(C, op, event, obedit);
+ break;
+ case TIMER:
+ if(event->customdata == data->timer)
+ uv_sculpt_stroke_apply(C, op, event, obedit);
+ break;
+ default:
+ return OPERATOR_RUNNING_MODAL;
+ }
+
+ ED_region_tag_redraw(CTX_wm_region(C));
+ WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+ DAG_id_tag_update(obedit->data, 0);
+ return OPERATOR_RUNNING_MODAL;
+}
+
+void SCULPT_OT_uv_sculpt_stroke(wmOperatorType *ot)
+{
+ static EnumPropertyItem stroke_mode_items[] = {
+ {BRUSH_STROKE_NORMAL, "NORMAL", 0, "Normal", "Apply brush normally"},
+ {BRUSH_STROKE_INVERT, "INVERT", 0, "Invert", "Invert action of brush for duration of stroke"},
+ {BRUSH_STROKE_SMOOTH, "RELAX", 0, "Relax", "Switch brush to relax mode for duration of stroke"},
+ {0}
+ };
+
+ /* identifiers */
+ ot->name = "Sculpt UVs";
+ ot->description = "Sculpt UVs using a brush";
+ ot->idname = "SCULPT_OT_uv_sculpt_stroke";
+
+ /* api callbacks */
+ ot->invoke = uv_sculpt_stroke_invoke;
+ ot->modal = uv_sculpt_stroke_modal;
+ ot->poll = uv_sculpt_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ /* props */
+ RNA_def_enum(ot->srna, "mode", stroke_mode_items, BRUSH_STROKE_NORMAL, "Mode", "Stroke Mode");
+}
diff --git a/source/blender/editors/space_buttons/buttons_context.c b/source/blender/editors/space_buttons/buttons_context.c
index 4c028612320..57981431492 100644
--- a/source/blender/editors/space_buttons/buttons_context.c
+++ b/source/blender/editors/space_buttons/buttons_context.c
@@ -1061,7 +1061,6 @@ ID *buttons_context_id_path(const bContext *C)
if(ptr->id.data) {
return ptr->id.data;
- break;
}
}
}
diff --git a/source/blender/editors/space_clip/clip_graph_draw.c b/source/blender/editors/space_clip/clip_graph_draw.c
index 9aba6db0c80..e913ae77f05 100644
--- a/source/blender/editors/space_clip/clip_graph_draw.c
+++ b/source/blender/editors/space_clip/clip_graph_draw.c
@@ -155,15 +155,16 @@ void tracking_segment_end_cb(void *UNUSED(userdata))
}
static void tracking_segment_knot_cb(void *userdata, MovieTrackingTrack *track,
- MovieTrackingMarker *marker, int UNUSED(coord), float val)
+ MovieTrackingMarker *marker, int coord, float val)
{
struct { MovieTrackingTrack *act_track; int sel; float xscale, yscale, hsize; } *data = userdata;
- int sel= 0;
+ int sel= 0, sel_flag;
if(track!=data->act_track)
return;
- sel= (marker->flag&MARKER_GRAPH_SEL) ? 1 : 0;
+ sel_flag= coord == 0 ? MARKER_GRAPH_SEL_X : MARKER_GRAPH_SEL_Y;
+ sel= (marker->flag & sel_flag) ? 1 : 0;
if(sel == data->sel) {
if(sel) UI_ThemeColor(TH_HANDLE_VERTEX_SELECT);
diff --git a/source/blender/editors/space_clip/clip_graph_ops.c b/source/blender/editors/space_clip/clip_graph_ops.c
index 08d6bcf47bc..8be5e520b1f 100644
--- a/source/blender/editors/space_clip/clip_graph_ops.c
+++ b/source/blender/editors/space_clip/clip_graph_ops.c
@@ -68,13 +68,13 @@ static void toggle_selection_cb(void *userdata, MovieTrackingMarker *marker)
switch(data->action) {
case SEL_SELECT:
- marker->flag|= MARKER_GRAPH_SEL;
+ marker->flag|= (MARKER_GRAPH_SEL_X|MARKER_GRAPH_SEL_Y);
break;
case SEL_DESELECT:
- marker->flag&= ~MARKER_GRAPH_SEL;
+ marker->flag&= ~(MARKER_GRAPH_SEL_X|MARKER_GRAPH_SEL_Y);
break;
case SEL_INVERT:
- marker->flag^= MARKER_GRAPH_SEL;
+ marker->flag^= (MARKER_GRAPH_SEL_X|MARKER_GRAPH_SEL_Y);
break;
}
}
@@ -177,7 +177,10 @@ static int mouse_select_knot(bContext *C, float co[2], int extend)
clip_graph_tracking_iterate(sc, &selectdata, toggle_selection_cb);
}
- userdata.marker->flag|= MARKER_GRAPH_SEL;
+ if(userdata.coord==0)
+ userdata.marker->flag|= MARKER_GRAPH_SEL_X;
+ else
+ userdata.marker->flag|= MARKER_GRAPH_SEL_Y;
return 1;
}
@@ -335,7 +338,7 @@ static int delete_knot_exec(bContext *C, wmOperator *UNUSED(op))
while(a<act_track->markersnr) {
MovieTrackingMarker *marker= &act_track->markers[a];
- if(marker->flag&MARKER_GRAPH_SEL)
+ if(marker->flag & (MARKER_GRAPH_SEL_X|MARKER_GRAPH_SEL_Y))
clip_delete_marker(C, clip, tracksbase, act_track, marker);
else
a++;
diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c
index 45c7043c44c..06dd96603ef 100644
--- a/source/blender/editors/space_clip/clip_ops.c
+++ b/source/blender/editors/space_clip/clip_ops.c
@@ -999,5 +999,5 @@ void ED_operatormacros_clip(void)
ot->description = "Add new marker and slide it with mouse until mouse button release";
WM_operatortype_macro_define(ot, "CLIP_OT_add_marker");
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
- RNA_boolean_set(otmacro->ptr, "release_confirm", 1);
+ RNA_boolean_set(otmacro->ptr, "release_confirm", TRUE);
}
diff --git a/source/blender/editors/space_clip/clip_utils.c b/source/blender/editors/space_clip/clip_utils.c
index 3ca8fc35c7f..46442d39a7b 100644
--- a/source/blender/editors/space_clip/clip_utils.c
+++ b/source/blender/editors/space_clip/clip_utils.c
@@ -95,7 +95,7 @@ void clip_graph_tracking_values_iterate_track(SpaceClip *sc, MovieTrackingTrack
}
/* value is a pixels per frame speed */
- val= (marker->pos[coord] - prevval) * ((i==0) ? (width) : (height));
+ val= (marker->pos[coord] - prevval) * ((coord==0) ? (width) : (height));
val/= marker->framenr-prevfra;
if(func)
diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c
index 82da9b3b956..04871156412 100644
--- a/source/blender/editors/space_clip/space_clip.c
+++ b/source/blender/editors/space_clip/space_clip.c
@@ -399,22 +399,24 @@ static void clip_keymap(struct wmKeyConfig *keyconf)
/* 2d tracking */
kmi= WM_keymap_add_item(keymap, "CLIP_OT_track_markers", LEFTARROWKEY, KM_PRESS, KM_ALT, 0);
- RNA_boolean_set(kmi->ptr, "backwards", 1);
+ RNA_boolean_set(kmi->ptr, "backwards", TRUE);
+ RNA_boolean_set(kmi->ptr, "sequence", FALSE);
WM_keymap_add_item(keymap, "CLIP_OT_track_markers", RIGHTARROWKEY, KM_PRESS, KM_ALT, 0);
kmi= WM_keymap_add_item(keymap, "CLIP_OT_track_markers", TKEY, KM_PRESS, KM_CTRL, 0);
- RNA_boolean_set(kmi->ptr, "sequence", 1);
+ RNA_boolean_set(kmi->ptr, "backwards", FALSE);
+ RNA_boolean_set(kmi->ptr, "sequence", TRUE);
kmi= WM_keymap_add_item(keymap, "CLIP_OT_track_markers", TKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
- RNA_boolean_set(kmi->ptr, "backwards", 1);
- RNA_boolean_set(kmi->ptr, "sequence", 1);
+ RNA_boolean_set(kmi->ptr, "backwards", TRUE);
+ RNA_boolean_set(kmi->ptr, "sequence", TRUE);
/* mode */
kmi= WM_keymap_add_item(keymap, "CLIP_OT_mode_set", TABKEY, KM_PRESS, 0, 0);
RNA_enum_set(kmi->ptr, "mode", SC_MODE_RECONSTRUCTION);
- RNA_boolean_set(kmi->ptr, "toggle", 1);
+ RNA_boolean_set(kmi->ptr, "toggle", TRUE);
kmi= WM_keymap_add_item(keymap, "CLIP_OT_mode_set", TABKEY, KM_PRESS, KM_CTRL, 0);
RNA_enum_set(kmi->ptr, "mode", SC_MODE_DISTORTION);
- RNA_boolean_set(kmi->ptr, "toggle", 1);
+ RNA_boolean_set(kmi->ptr, "toggle", TRUE);
/* ******** Hotkeys avalaible for main region only ******** */
@@ -461,10 +463,14 @@ static void clip_keymap(struct wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "CLIP_OT_change_frame", LEFTMOUSE, KM_PRESS, 0, 0);
/* selection */
- WM_keymap_add_item(keymap, "CLIP_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "CLIP_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1);
- WM_keymap_add_item(keymap, "CLIP_OT_select_all", AKEY, KM_PRESS, 0, 0);
- RNA_enum_set(WM_keymap_add_item(keymap, "CLIP_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "action", SEL_INVERT);
+ kmi = WM_keymap_add_item(keymap, "CLIP_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "extend", FALSE);
+ kmi = WM_keymap_add_item(keymap, "CLIP_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
+ kmi = WM_keymap_add_item(keymap, "CLIP_OT_select_all", AKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
+ kmi = WM_keymap_add_item(keymap, "CLIP_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
+ RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
WM_keymap_add_item(keymap, "CLIP_OT_select_border", BKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "CLIP_OT_select_circle", CKEY, KM_PRESS, 0, 0);
WM_keymap_add_menu(keymap, "CLIP_MT_select_grouped", GKEY, KM_PRESS, KM_SHIFT, 0);
@@ -490,10 +496,11 @@ static void clip_keymap(struct wmKeyConfig *keyconf)
kmi= WM_keymap_add_item(keymap, "CLIP_OT_lock_tracks", LKEY, KM_PRESS, KM_ALT, 0);
RNA_enum_set(kmi->ptr, "action", 1); /* unlock */
- WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks", HKEY, KM_PRESS, 0, 0);
+ kmi= WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks", HKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", FALSE);
kmi= WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks", HKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_boolean_set(kmi->ptr, "unselected", 1);
+ RNA_boolean_set(kmi->ptr, "unselected", TRUE);
WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks_clear", HKEY, KM_PRESS, KM_ALT, 0);
@@ -527,8 +534,10 @@ static void clip_keymap(struct wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "CLIP_OT_change_frame", ACTIONMOUSE, KM_PRESS, 0, 0);
/* selection */
- WM_keymap_add_item(keymap, "CLIP_OT_graph_select", SELECTMOUSE, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "CLIP_OT_graph_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1);
+ kmi = WM_keymap_add_item(keymap, "CLIP_OT_graph_select", SELECTMOUSE, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "extend", FALSE);
+ kmi = WM_keymap_add_item(keymap, "CLIP_OT_graph_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
/* delete */
WM_keymap_add_item(keymap, "CLIP_OT_graph_delete_curve", DELKEY, KM_PRESS, 0, 0);
@@ -536,6 +545,8 @@ static void clip_keymap(struct wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "CLIP_OT_graph_delete_knot", DELKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "CLIP_OT_graph_delete_knot", XKEY, KM_PRESS, KM_SHIFT, 0);
+
+ transform_keymap_for_space(keyconf, keymap, SPACE_CLIP);
}
const char *clip_context_dir[]= {"edit_movieclip", NULL};
diff --git a/source/blender/editors/space_clip/tracking_ops.c b/source/blender/editors/space_clip/tracking_ops.c
index b67fac69745..6cf8a988571 100644
--- a/source/blender/editors/space_clip/tracking_ops.c
+++ b/source/blender/editors/space_clip/tracking_ops.c
@@ -2520,9 +2520,8 @@ static int set_scale_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
{
SpaceClip *sc= CTX_wm_space_clip(C);
MovieClip *clip= ED_space_clip(sc);
- float dist= RNA_float_get(op->ptr, "distance");
- if(dist==0.0f)
+ if(!RNA_struct_property_is_set(op->ptr, "distance"))
RNA_float_set(op->ptr, "distance", clip->tracking.settings.dist);
return set_scale_exec(C, op);
@@ -2573,9 +2572,8 @@ static int set_solution_scale_invoke(bContext *C, wmOperator *op, wmEvent *UNUSE
{
SpaceClip *sc= CTX_wm_space_clip(C);
MovieClip *clip= ED_space_clip(sc);
- float dist= RNA_float_get(op->ptr, "distance");
- if(dist==0.0f)
+ if(!RNA_struct_property_is_set(op->ptr, "distance"))
RNA_float_set(op->ptr, "distance", clip->tracking.settings.object_distance);
return set_solution_scale_exec(C, op);
diff --git a/source/blender/editors/space_console/space_console.c b/source/blender/editors/space_console/space_console.c
index c713317aa7e..3df8e98be3a 100644
--- a/source/blender/editors/space_console/space_console.c
+++ b/source/blender/editors/space_console/space_console.c
@@ -276,24 +276,25 @@ static void console_keymap(struct wmKeyConfig *keyconf)
kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", WHEELUPMOUSE, KM_PRESS, KM_CTRL, 0);
RNA_string_set(kmi->ptr, "data_path", "space_data.font_size");
- RNA_boolean_set(kmi->ptr, "reverse", 0);
+ RNA_boolean_set(kmi->ptr, "reverse", FALSE);
kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", WHEELDOWNMOUSE, KM_PRESS, KM_CTRL, 0);
RNA_string_set(kmi->ptr, "data_path", "space_data.font_size");
- RNA_boolean_set(kmi->ptr, "reverse", 1);
+ RNA_boolean_set(kmi->ptr, "reverse", TRUE);
kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
RNA_string_set(kmi->ptr, "data_path", "space_data.font_size");
- RNA_boolean_set(kmi->ptr, "reverse", 0);
+ RNA_boolean_set(kmi->ptr, "reverse", FALSE);
kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", PADMINUS, KM_PRESS, KM_CTRL, 0);
RNA_string_set(kmi->ptr, "data_path", "space_data.font_size");
- RNA_boolean_set(kmi->ptr, "reverse", 1);
+ RNA_boolean_set(kmi->ptr, "reverse", TRUE);
RNA_enum_set(WM_keymap_add_item(keymap, "CONSOLE_OT_move", LEFTARROWKEY, KM_PRESS, 0, 0)->ptr, "type", PREV_CHAR);
RNA_enum_set(WM_keymap_add_item(keymap, "CONSOLE_OT_move", RIGHTARROWKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_CHAR);
- RNA_boolean_set(WM_keymap_add_item(keymap, "CONSOLE_OT_history_cycle", UPARROWKEY, KM_PRESS, 0, 0)->ptr, "reverse", 1);
+ kmi = WM_keymap_add_item(keymap, "CONSOLE_OT_history_cycle", UPARROWKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "reverse", TRUE);
WM_keymap_add_item(keymap, "CONSOLE_OT_history_cycle", DOWNARROWKEY, KM_PRESS, 0, 0);
/*
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index dee8db88d49..23250fc6696 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -586,7 +586,7 @@ const char * filelist_dir(struct FileList* filelist)
void filelist_setdir(struct FileList* filelist, const char *dir)
{
- BLI_strncpy(filelist->dir, dir, FILE_MAX);
+ BLI_strncpy(filelist->dir, dir, sizeof(filelist->dir));
}
void filelist_imgsize(struct FileList* filelist, short w, short h)
@@ -853,10 +853,9 @@ static void filelist_read_library(struct FileList* filelist)
for(num=0; num<filelist->numfiles; num++, file++) {
if(BLO_has_bfile_extension(file->relname)) {
char name[FILE_MAX];
-
- BLI_strncpy(name, filelist->dir, sizeof(name));
- strcat(name, file->relname);
-
+
+ BLI_join_dirfile(name, sizeof(name), filelist->dir, file->relname);
+
/* prevent current file being used as acceptable dir */
if (BLI_path_cmp(G.main->name, name) != 0) {
file->type &= ~S_IFMT;
diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c
index 7bc71e333ea..02c9728348e 100644
--- a/source/blender/editors/space_file/space_file.c
+++ b/source/blender/editors/space_file/space_file.c
@@ -410,13 +410,13 @@ static void file_keymap(struct wmKeyConfig *keyconf)
/* keys for main area */
keymap= WM_keymap_find(keyconf, "File Browser Main", SPACE_FILE, 0);
kmi= WM_keymap_add_item(keymap, "FILE_OT_execute", LEFTMOUSE, KM_DBL_CLICK, 0, 0);
- RNA_boolean_set(kmi->ptr, "need_active", 1);
+ RNA_boolean_set(kmi->ptr, "need_active", TRUE);
WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_CLICK, 0, 0);
kmi = WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_CLICK, KM_SHIFT, 0);
- RNA_boolean_set(kmi->ptr, "extend", 1);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
kmi = WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_CLICK, KM_ALT, 0);
- RNA_boolean_set(kmi->ptr, "extend", 1);
- RNA_boolean_set(kmi->ptr, "fill", 1);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
+ RNA_boolean_set(kmi->ptr, "fill", TRUE);
WM_keymap_add_item(keymap, "FILE_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "FILE_OT_refresh", PADPERIOD, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "FILE_OT_select_border", BKEY, KM_PRESS, 0, 0);
diff --git a/source/blender/editors/space_graph/graph_ops.c b/source/blender/editors/space_graph/graph_ops.c
index aa245585d11..aba58098563 100644
--- a/source/blender/editors/space_graph/graph_ops.c
+++ b/source/blender/editors/space_graph/graph_ops.c
@@ -383,7 +383,8 @@ static void graphedit_keymap_keyframes (wmKeyConfig *keyconf, wmKeyMap *keymap)
WM_keymap_add_item(keymap, "GRAPH_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
/* F-Modifiers */
- RNA_boolean_set(WM_keymap_add_item(keymap, "GRAPH_OT_fmodifier_add", MKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "only_active", 0);
+ kmi = WM_keymap_add_item(keymap, "GRAPH_OT_fmodifier_add", MKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "only_active", FALSE);
/* animation module */
/* channels list
diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c
index 41fc861f8e4..9ec9c5ef0e0 100644
--- a/source/blender/editors/space_image/image_draw.c
+++ b/source/blender/editors/space_image/image_draw.c
@@ -111,7 +111,8 @@ static void draw_render_info(Scene *scene, Image *ima, ARegion *ar)
}
/* used by node view too */
-void ED_image_draw_info(ARegion *ar, int color_manage, int channels, int x, int y, const char cp[4], const float fp[4], int *zp, float *zpf)
+void ED_image_draw_info(ARegion *ar, int color_manage, int channels, int x, int y,
+ const unsigned char cp[4], const float fp[4], int *zp, float *zpf)
{
char str[256];
float dx= 6;
@@ -211,39 +212,46 @@ void ED_image_draw_info(ARegion *ar, int color_manage, int channels, int x, int
/* color rectangle */
if (channels==1) {
- if (fp)
+ if (fp) {
col[0] = col[1] = col[2] = fp[0];
- else if (cp)
+ }
+ else if (cp) {
col[0] = col[1] = col[2] = (float)cp[0]/255.0f;
- else
+ }
+ else {
col[0] = col[1] = col[2] = 0.0f;
+ }
+ col[3] = 1.0f;
}
else if (channels==3) {
- if (fp)
+ if (fp) {
copy_v3_v3(col, fp);
+ }
else if (cp) {
- col[0] = (float)cp[0]/255.0f;
- col[1] = (float)cp[1]/255.0f;
- col[2] = (float)cp[2]/255.0f;
+ rgb_uchar_to_float(col, cp);
}
- else
+ else {
zero_v3(col);
+ }
+ col[3] = 1.0f;
}
else if (channels==4) {
if (fp)
copy_v4_v4(col, fp);
else if (cp) {
- col[0] = (float)cp[0]/255.0f;
- col[1] = (float)cp[1]/255.0f;
- col[2] = (float)cp[2]/255.0f;
- col[3] = (float)cp[3]/255.0f;
+ rgba_uchar_to_float(col, cp);
}
- else
+ else {
zero_v4(col);
+ }
}
+ else {
+ BLI_assert(0);
+ zero_v4(col);
+ }
+
if (color_manage) {
- linearrgb_to_srgb_v3_v3(finalcol, col);
- finalcol[3] = col[3];
+ linearrgb_to_srgb_v4(finalcol, col);
}
else {
copy_v4_v4(finalcol, col);
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 06674513868..1ac5ba56145 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -178,6 +178,30 @@ int space_image_main_area_poll(bContext *C)
return 0;
}
+/* For IMAGE_OT_curves_point_set to avoid sampling when in uv smooth mode */
+int space_image_main_area_not_uv_brush_poll(bContext *C)
+{
+ SpaceImage *sima= CTX_wm_space_image(C);
+
+ ToolSettings *toolsettings = CTX_data_scene(C)->toolsettings;
+ if(sima && !toolsettings->uvsculpt)
+ return 1;
+
+ return 0;
+}
+
+static int space_image_image_sample_poll(bContext *C)
+{
+ SpaceImage *sima= CTX_wm_space_image(C);
+ Object *obedit= CTX_data_edit_object(C);
+ ToolSettings *toolsettings = CTX_data_scene(C)->toolsettings;
+
+ if(obedit){
+ if(ED_space_image_show_uvedit(sima, obedit) && (toolsettings->use_uv_sculpt))
+ return 0;
+ }
+ return space_image_main_area_poll(C);
+}
/********************** view pan operator *********************/
typedef struct ViewPanData {
@@ -858,7 +882,9 @@ static int image_replace_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
RNA_string_get(op->ptr, "filepath", str);
- BLI_strncpy(sima->image->name, str, sizeof(sima->image->name)); /* we cant do much if the str is longer then 240 :/ */
+
+ /* we cant do much if the str is longer then FILE_MAX :/ */
+ BLI_strncpy(sima->image->name, str, sizeof(sima->image->name));
/* XXX unpackImage frees image buffers */
ED_preview_kill_jobs(C);
@@ -1754,12 +1780,12 @@ typedef struct ImageSampleInfo {
int x, y;
int channels;
- char col[4];
+ unsigned char col[4];
float colf[4];
int z;
float zf;
- char *colp;
+ unsigned char *colp;
float *colfp;
int *zp;
float *zfp;
@@ -1794,7 +1820,7 @@ static void image_sample_apply(bContext *C, wmOperator *op, wmEvent *event)
if(fx>=0.0f && fy>=0.0f && fx<1.0f && fy<1.0f) {
float *fp;
- char *cp;
+ unsigned char *cp;
int x= (int)(fx*ibuf->x), y= (int)(fy*ibuf->y);
CLAMP(x, 0, ibuf->x-1);
@@ -1811,7 +1837,7 @@ static void image_sample_apply(bContext *C, wmOperator *op, wmEvent *event)
info->zfp= NULL;
if(ibuf->rect) {
- cp= (char *)(ibuf->rect + y*ibuf->x + x);
+ cp= (unsigned char *)(ibuf->rect + y*ibuf->x + x);
info->col[0]= cp[0];
info->col[1]= cp[1];
@@ -1947,7 +1973,7 @@ void IMAGE_OT_sample(wmOperatorType *ot)
ot->invoke= image_sample_invoke;
ot->modal= image_sample_modal;
ot->cancel= image_sample_cancel;
- ot->poll= space_image_main_area_poll;
+ ot->poll= space_image_image_sample_poll;
/* flags */
ot->flag= OPTYPE_BLOCKING;
@@ -2084,7 +2110,7 @@ void IMAGE_OT_curves_point_set(wmOperatorType *ot)
ot->invoke= image_sample_invoke;
ot->modal= image_sample_modal;
ot->cancel= image_sample_cancel;
- ot->poll= space_image_main_area_poll;
+ ot->poll= space_image_main_area_not_uv_brush_poll;
/* properties */
RNA_def_enum(ot->srna, "point", point_items, 0, "Point", "Set black point or white point for curves");
diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c
index 4421ad8e4f9..fd7895052f1 100644
--- a/source/blender/editors/space_image/space_image.c
+++ b/source/blender/editors/space_image/space_image.c
@@ -543,7 +543,7 @@ static void image_keymap(struct wmKeyConfig *keyconf)
/* toggle editmode is handy to have while UV unwrapping */
kmi= WM_keymap_add_item(keymap, "OBJECT_OT_mode_set", TABKEY, KM_PRESS, 0, 0);
RNA_enum_set(kmi->ptr, "mode", OB_MODE_EDIT);
- RNA_boolean_set(kmi->ptr, "toggle", 1);
+ RNA_boolean_set(kmi->ptr, "toggle", TRUE);
}
/* dropboxes */
@@ -773,6 +773,9 @@ static void image_main_area_init(wmWindowManager *wm, ARegion *ar)
keymap= WM_keymap_find(wm->defaultconf, "UV Editor", 0, 0);
WM_event_add_keymap_handler(&ar->handlers, keymap);
+ keymap= WM_keymap_find(wm->defaultconf, "UV Sculpt", 0, 0);
+ WM_event_add_keymap_handler(&ar->handlers, keymap);
+
/* own keymaps */
keymap= WM_keymap_find(wm->defaultconf, "Image Generic", SPACE_IMAGE, 0);
WM_event_add_keymap_handler(&ar->handlers, keymap);
@@ -785,6 +788,7 @@ static void image_main_area_draw(const bContext *C, ARegion *ar)
{
/* draw entirely, view changes should be handled here */
SpaceImage *sima= CTX_wm_space_image(C);
+ Object *obact= CTX_data_active_object(C);
Object *obedit= CTX_data_edit_object(C);
Scene *scene= CTX_data_scene(C);
View2D *v2d= &ar->v2d;
@@ -810,7 +814,7 @@ static void image_main_area_draw(const bContext *C, ARegion *ar)
/* and uvs in 0.0-1.0 space */
UI_view2d_view_ortho(v2d);
- draw_uvedit_main(sima, ar, scene, obedit);
+ draw_uvedit_main(sima, ar, scene, obedit, obact);
ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
diff --git a/source/blender/editors/space_info/info_ops.c b/source/blender/editors/space_info/info_ops.c
index 2090b4eae0a..87f9a5d65aa 100644
--- a/source/blender/editors/space_info/info_ops.c
+++ b/source/blender/editors/space_info/info_ops.c
@@ -124,7 +124,7 @@ static const EnumPropertyItem unpack_all_method_items[] = {
{PF_USE_ORIGINAL, "USE_ORIGINAL", 0, "Use files in original location (create when necessary)", ""},
{PF_WRITE_ORIGINAL, "WRITE_ORIGINAL", 0, "Write files to original location (overwrite existing files)", ""},
{PF_KEEP, "KEEP", 0, "Disable AutoPack, keep all packed files", ""},
- {PF_ASK, "ASK", 0, "Ask for each file", ""},
+ /* {PF_ASK, "ASK", 0, "Ask for each file", ""}, */
{0, NULL, 0, NULL, NULL}};
static int unpack_all_exec(bContext *C, wmOperator *op)
diff --git a/source/blender/editors/space_nla/nla_ops.c b/source/blender/editors/space_nla/nla_ops.c
index f173a3d3835..55831de876c 100644
--- a/source/blender/editors/space_nla/nla_ops.c
+++ b/source/blender/editors/space_nla/nla_ops.c
@@ -169,17 +169,23 @@ void nla_operatortypes(void)
static void nla_keymap_channels(wmKeyMap *keymap)
{
+ wmKeyMapItem *kmi;
+
/* NLA-specific (different to standard channels keymap) -------------------------- */
/* selection */
/* click-select */
// XXX for now, only leftmouse....
- WM_keymap_add_item(keymap, "NLA_OT_channels_click", LEFTMOUSE, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "NLA_OT_channels_click", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1);
+ kmi = WM_keymap_add_item(keymap, "NLA_OT_channels_click", LEFTMOUSE, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "extend", FALSE);
+ kmi = WM_keymap_add_item(keymap, "NLA_OT_channels_click", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
/* channel operations */
/* add tracks */
- WM_keymap_add_item(keymap, "NLA_OT_tracks_add", AKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "NLA_OT_tracks_add", AKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "above_selected", 1);
+ kmi = WM_keymap_add_item(keymap, "NLA_OT_tracks_add", AKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "above_selected", FALSE);
+ kmi = WM_keymap_add_item(keymap, "NLA_OT_tracks_add", AKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "above_selected", TRUE);
/* delete tracks */
WM_keymap_add_item(keymap, "NLA_OT_delete_tracks", XKEY, KM_PRESS, 0, 0);
diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c
index 5beac4ea212..3301f89ab7a 100644
--- a/source/blender/editors/space_node/node_edit.c
+++ b/source/blender/editors/space_node/node_edit.c
@@ -1334,7 +1334,7 @@ typedef struct ImageSampleInfo {
int channels;
int color_manage;
- char col[4];
+ unsigned char col[4];
float colf[4];
int draw;
diff --git a/source/blender/editors/space_node/node_ops.c b/source/blender/editors/space_node/node_ops.c
index b71776f4266..508021540b5 100644
--- a/source/blender/editors/space_node/node_ops.c
+++ b/source/blender/editors/space_node/node_ops.c
@@ -114,8 +114,10 @@ void ED_operatormacros_node(void)
/* modified operator call for duplicating with input links */
ot= WM_operatortype_append_macro("NODE_OT_duplicate_move_keep_inputs", "Duplicate", OPTYPE_UNDO|OPTYPE_REGISTER);
ot->description = "Duplicate selected nodes keeping input links and move them";
+
mot = WM_operatortype_macro_define(ot, "NODE_OT_duplicate");
- RNA_boolean_set(mot->ptr, "keep_inputs", 1);
+ RNA_boolean_set(mot->ptr, "keep_inputs", TRUE);
+
WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
ot= WM_operatortype_append_macro("NODE_OT_select_link_viewer", "Link Viewer", OPTYPE_UNDO);
@@ -144,11 +146,12 @@ void node_keymap(struct wmKeyConfig *keyconf)
RNA_boolean_set(kmi->ptr, "extend", FALSE);
kmi = WM_keymap_add_item(keymap, "NODE_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
RNA_boolean_set(kmi->ptr, "extend", FALSE);
- kmi= WM_keymap_add_item(keymap, "NODE_OT_select", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0);
+ kmi = WM_keymap_add_item(keymap, "NODE_OT_select", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0);
RNA_boolean_set(kmi->ptr, "extend", TRUE);
- kmi= WM_keymap_add_item(keymap, "NODE_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
+ kmi = WM_keymap_add_item(keymap, "NODE_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
RNA_boolean_set(kmi->ptr, "extend", TRUE);
- RNA_boolean_set(WM_keymap_add_item(keymap, "NODE_OT_select_border", EVT_TWEAK_S, KM_ANY, 0, 0)->ptr, "tweak", 1);
+ kmi = WM_keymap_add_item(keymap, "NODE_OT_select_border", EVT_TWEAK_S, KM_ANY, 0, 0);
+ RNA_boolean_set(kmi->ptr, "tweak", TRUE);
/* each of these falls through if not handled... */
WM_keymap_add_item(keymap, "NODE_OT_link", LEFTMOUSE, KM_PRESS, 0, 0);
@@ -163,10 +166,12 @@ void node_keymap(struct wmKeyConfig *keyconf)
kmi= WM_keymap_add_item(keymap, "NODE_OT_backimage_zoom", VKEY, KM_PRESS, KM_ALT, 0);
RNA_float_set(kmi->ptr, "factor", 1.2f);
WM_keymap_add_item(keymap, "NODE_OT_backimage_sample", ACTIONMOUSE, KM_PRESS, KM_ALT, 0);
-
- WM_keymap_add_item(keymap, "NODE_OT_link_make", FKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "NODE_OT_link_make", FKEY, KM_PRESS, KM_CTRL, 0)->ptr, "replace", 1);
-
+
+ kmi = WM_keymap_add_item(keymap, "NODE_OT_link_make", FKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "replace", FALSE);
+ kmi = WM_keymap_add_item(keymap, "NODE_OT_link_make", FKEY, KM_PRESS, KM_CTRL, 0);
+ RNA_boolean_set(kmi->ptr, "replace", TRUE);
+
WM_keymap_add_menu(keymap, "NODE_MT_add", AKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "NODE_OT_duplicate_move", DKEY, KM_PRESS, KM_SHIFT, 0);
/* modified operator call for duplicating with input links */
@@ -180,7 +185,10 @@ void node_keymap(struct wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "NODE_OT_show_cyclic_dependencies", CKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "NODE_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
- WM_keymap_add_item(keymap, "NODE_OT_select_border", BKEY, KM_PRESS, 0, 0);
+
+ kmi = WM_keymap_add_item(keymap, "NODE_OT_select_border", BKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "tweak", FALSE);
+
WM_keymap_add_item(keymap, "NODE_OT_delete", XKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "NODE_OT_delete", DELKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "NODE_OT_delete_reconnect", XKEY, KM_PRESS, KM_CTRL, 0);
diff --git a/source/blender/editors/space_node/node_templates.c b/source/blender/editors/space_node/node_templates.c
index a733d45c20b..8d82dd3fb53 100644
--- a/source/blender/editors/space_node/node_templates.c
+++ b/source/blender/editors/space_node/node_templates.c
@@ -49,6 +49,8 @@
#include "RNA_access.h"
+#include "NOD_socket.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -205,12 +207,9 @@ static void node_socket_add_replace(Main *bmain, bNodeTree *ntree, bNode *node_t
nodeRemLink(ntree, link);
}
- if(sock_prev->default_value) {
- if(sock_from->default_value)
- MEM_freeN(sock_from->default_value);
-
- sock_from->default_value = MEM_dupallocN(sock_prev->default_value);
- }
+ node_socket_free_default_value(sock_from->type, sock_from->default_value);
+ sock_from->default_value = node_socket_make_default_value(sock_from->type);
+ node_socket_copy_default_value(sock_from->type, sock_from->default_value, sock_prev->default_value);
}
}
}
diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h
index 4065b3e2e0b..3b6b4334880 100644
--- a/source/blender/editors/space_outliner/outliner_intern.h
+++ b/source/blender/editors/space_outliner/outliner_intern.h
@@ -198,6 +198,8 @@ void OUTLINER_OT_show_one_level(struct wmOperatorType *ot);
void OUTLINER_OT_show_active(struct wmOperatorType *ot);
void OUTLINER_OT_show_hierarchy(struct wmOperatorType *ot);
+void OUTLINER_OT_select_border(struct wmOperatorType *ot);
+
void OUTLINER_OT_selected_toggle(struct wmOperatorType *ot);
void OUTLINER_OT_expanded_toggle(struct wmOperatorType *ot);
diff --git a/source/blender/editors/space_outliner/outliner_ops.c b/source/blender/editors/space_outliner/outliner_ops.c
index 0d3f2e85414..0de26cece93 100644
--- a/source/blender/editors/space_outliner/outliner_ops.c
+++ b/source/blender/editors/space_outliner/outliner_ops.c
@@ -38,6 +38,7 @@
#include "RNA_access.h"
+#include "BLI_utildefines.h"
#include "outliner_intern.h"
@@ -48,6 +49,7 @@
void outliner_operatortypes(void)
{
WM_operatortype_append(OUTLINER_OT_item_activate);
+ WM_operatortype_append(OUTLINER_OT_select_border);
WM_operatortype_append(OUTLINER_OT_item_openclose);
WM_operatortype_append(OUTLINER_OT_item_rename);
WM_operatortype_append(OUTLINER_OT_operation);
@@ -80,14 +82,21 @@ void outliner_operatortypes(void)
void outliner_keymap(wmKeyConfig *keyconf)
{
wmKeyMap *keymap= WM_keymap_find(keyconf, "Outliner", SPACE_OUTLINER, 0);
+ wmKeyMapItem *kmi;
WM_keymap_add_item(keymap, "OUTLINER_OT_item_rename", LEFTMOUSE, KM_DBL_CLICK, 0, 0);
+
+ kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_item_activate", LEFTMOUSE, KM_CLICK, 0, 0);
+ RNA_boolean_set(kmi->ptr, "extend", FALSE);
+ kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_item_activate", LEFTMOUSE, KM_CLICK, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
+
+ WM_keymap_add_item(keymap, "OUTLINER_OT_select_border", BKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "OUTLINER_OT_item_activate", LEFTMOUSE, KM_CLICK, 0, 0)->ptr, "extend", 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "OUTLINER_OT_item_activate", LEFTMOUSE, KM_CLICK, KM_SHIFT, 0)->ptr, "extend", 1);
-
- RNA_boolean_set(WM_keymap_add_item(keymap, "OUTLINER_OT_item_openclose", RETKEY, KM_PRESS, 0, 0)->ptr, "all", 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "OUTLINER_OT_item_openclose", RETKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "all", 1);
+ kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_item_openclose", RETKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "all", FALSE);
+ kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_item_openclose", RETKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "all", TRUE);
WM_keymap_add_item(keymap, "OUTLINER_OT_item_rename", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "OUTLINER_OT_operation", RIGHTMOUSE, KM_PRESS, 0, 0);
@@ -98,10 +107,12 @@ void outliner_keymap(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "OUTLINER_OT_show_active", PADPERIOD, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "OUTLINER_OT_scroll_page", PAGEDOWNKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "OUTLINER_OT_scroll_page", PAGEUPKEY, KM_PRESS, 0, 0)->ptr, "up", 1);
+ kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_scroll_page", PAGEUPKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "up", TRUE);
WM_keymap_add_item(keymap, "OUTLINER_OT_show_one_level", PADPLUSKEY, KM_PRESS, 0, 0); /* open */
- RNA_boolean_set(WM_keymap_add_item(keymap, "OUTLINER_OT_show_one_level", PADMINUS, KM_PRESS, 0, 0)->ptr, "open", 0); /* close */
+ kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_show_one_level", PADMINUS, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "open", FALSE); /* close */
WM_keymap_verify_item(keymap, "OUTLINER_OT_selected_toggle", AKEY, KM_PRESS, 0, 0);
WM_keymap_verify_item(keymap, "OUTLINER_OT_expanded_toggle", AKEY, KM_PRESS, KM_SHIFT, 0);
diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c
index bf570c929cc..345e7a835f4 100644
--- a/source/blender/editors/space_outliner/outliner_select.c
+++ b/source/blender/editors/space_outliner/outliner_select.c
@@ -875,3 +875,78 @@ void OUTLINER_OT_item_activate(wmOperatorType *ot)
}
/* ****************************************************** */
+
+/* **************** Border Select Tool ****************** */
+static void outliner_item_border_select(Scene *scene, SpaceOops *soops, rctf *rectf, TreeElement *te, int gesture_mode)
+{
+ TreeStoreElem *tselem= TREESTORE(te);
+
+ if (te->ys <= rectf->ymax && te->ys + UI_UNIT_Y >= rectf->ymin) {
+ if (gesture_mode == GESTURE_MODAL_SELECT) {
+ tselem->flag |= TSE_SELECTED;
+ }
+ else {
+ tselem->flag &= ~TSE_SELECTED;
+ }
+ }
+
+ /* Look at its children. */
+ if ((tselem->flag & TSE_CLOSED) == 0) {
+ for (te = te->subtree.first; te; te = te->next) {
+ outliner_item_border_select(scene, soops, rectf, te, gesture_mode);
+ }
+ }
+ return;
+}
+
+static int outliner_border_select_exec(bContext *C, wmOperator *op)
+{
+ Scene *scene= CTX_data_scene(C);
+ SpaceOops *soops= CTX_wm_space_outliner(C);
+ ARegion *ar= CTX_wm_region(C);
+ TreeElement *te;
+ rcti rect;
+ rctf rectf;
+ int gesture_mode= RNA_int_get(op->ptr, "gesture_mode");
+
+ rect.xmin= RNA_int_get(op->ptr, "xmin");
+ rect.ymin= RNA_int_get(op->ptr, "ymin");
+ UI_view2d_region_to_view(&ar->v2d, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin);
+
+ rect.xmax= RNA_int_get(op->ptr, "xmax");
+ rect.ymax= RNA_int_get(op->ptr, "ymax");
+ UI_view2d_region_to_view(&ar->v2d, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax);
+
+ for(te= soops->tree.first; te; te= te->next) {
+ outliner_item_border_select(scene, soops, &rectf, te, gesture_mode);
+ }
+
+ WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
+ ED_region_tag_redraw(ar);
+
+ return OPERATOR_FINISHED;
+}
+
+void OUTLINER_OT_select_border(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Border Select";
+ ot->idname= "OUTLINER_OT_select_border";
+ ot->description= "Use box selection to select tree elements";
+
+ /* api callbacks */
+ ot->invoke= WM_border_select_invoke;
+ ot->exec= outliner_border_select_exec;
+ ot->modal= WM_border_select_modal;
+ ot->cancel= WM_border_select_cancel;
+
+ ot->poll= ED_operator_outliner_active;
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ /* rna */
+ WM_operator_properties_gesture_border(ot, FALSE);
+}
+
+/* ****************************************************** */
diff --git a/source/blender/editors/space_script/script_edit.c b/source/blender/editors/space_script/script_edit.c
index b0c2de390a2..7702e952e24 100644
--- a/source/blender/editors/space_script/script_edit.c
+++ b/source/blender/editors/space_script/script_edit.c
@@ -96,8 +96,8 @@ static int script_reload_exec(bContext *C, wmOperator *UNUSED(op))
return OPERATOR_FINISHED;
#else
(void)C; /* unused */
-#endif
return OPERATOR_CANCELLED;
+#endif
}
void SCRIPT_OT_reload(wmOperatorType *ot)
diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c
index 176ffd91e3b..511f1524fae 100644
--- a/source/blender/editors/space_sequencer/sequencer_draw.c
+++ b/source/blender/editors/space_sequencer/sequencer_draw.c
@@ -143,7 +143,7 @@ static void get_seq_color3ubv(Scene *curscene, Sequence *seq, unsigned char col[
case SEQ_COLOR:
if (colvars->col) {
- rgb_float_to_byte(colvars->col, col);
+ rgb_float_to_uchar(col, colvars->col);
} else {
col[0] = col[1] = col[2] = 128;
}
diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c
index 56c2e0ee4d1..c46a1eebc2e 100644
--- a/source/blender/editors/space_sequencer/sequencer_edit.c
+++ b/source/blender/editors/space_sequencer/sequencer_edit.c
@@ -3034,10 +3034,10 @@ static int sequencer_change_path_invoke(bContext *C, wmOperator *op, wmEvent *UN
/* set default display depending on seq type */
if(seq->type == SEQ_IMAGE) {
- RNA_boolean_set(op->ptr, "filter_movie", 0);
+ RNA_boolean_set(op->ptr, "filter_movie", FALSE);
}
else {
- RNA_boolean_set(op->ptr, "filter_image", 0);
+ RNA_boolean_set(op->ptr, "filter_image", FALSE);
}
WM_event_add_fileselect(C, op);
diff --git a/source/blender/editors/space_sequencer/sequencer_ops.c b/source/blender/editors/space_sequencer/sequencer_ops.c
index a6d8b6c2612..ec9f8bb36d9 100644
--- a/source/blender/editors/space_sequencer/sequencer_ops.c
+++ b/source/blender/editors/space_sequencer/sequencer_ops.c
@@ -136,9 +136,11 @@ void sequencer_keymap(wmKeyConfig *keyconf)
RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
-
- RNA_enum_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_cut", KKEY, KM_PRESS, 0, 0)->ptr, "type", SEQ_CUT_SOFT);
- RNA_enum_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_cut", KKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", SEQ_CUT_HARD);
+
+ kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_cut", KKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "type", SEQ_CUT_SOFT);
+ kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_cut", KKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_enum_set(kmi->ptr, "type", SEQ_CUT_HARD);
kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_mute", HKEY, KM_PRESS, 0, 0);
RNA_boolean_set(kmi->ptr, "unselected", FALSE);
@@ -212,25 +214,27 @@ void sequencer_keymap(wmKeyConfig *keyconf)
/* 2.4x method, now use Alt for handles and select the side based on which handle was selected */
/*
- RNA_boolean_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL, 0)->ptr, "linked_left", 1);
- RNA_boolean_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_ALT, 0)->ptr, "linked_right", 1);
+ kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
+ RNA_boolean_set(kmi->ptr, "linked_left", TRUE);
+ kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
+ RNA_boolean_set(kmi->ptr, "linked_right", TRUE);
kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL|KM_ALT, 0);
- RNA_boolean_set(kmi->ptr, "linked_left", 1);
- RNA_boolean_set(kmi->ptr, "linked_right", 1);
+ RNA_boolean_set(kmi->ptr, "linked_left", TRUE);
+ RNA_boolean_set(kmi->ptr, "linked_right", TRUE);
kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_CTRL|KM_ALT, 0);
- RNA_boolean_set(kmi->ptr, "extend", 1);
- RNA_boolean_set(kmi->ptr, "linked_left", 1);
- RNA_boolean_set(kmi->ptr, "linked_right", 1);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
+ RNA_boolean_set(kmi->ptr, "linked_left", TRUE);
+ RNA_boolean_set(kmi->ptr, "linked_right", TRUE);
kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
- RNA_boolean_set(kmi->ptr, "extend", 1);
- RNA_boolean_set(kmi->ptr, "linked_left", 1);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
+ RNA_boolean_set(kmi->ptr, "linked_left", TRUE);
kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_ALT, 0);
- RNA_boolean_set(kmi->ptr, "extend", 1);
- RNA_boolean_set(kmi->ptr, "linked_right", 1);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
+ RNA_boolean_set(kmi->ptr, "linked_right", TRUE);
*/
/* 2.5 method, Alt and use selected handle */
@@ -263,8 +267,10 @@ void sequencer_keymap(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "SEQUENCER_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "SEQUENCER_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "SEQUENCER_OT_select_linked_pick", LKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_select_linked_pick", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1);
+ kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select_linked_pick", LKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "extend", FALSE);
+ kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select_linked_pick", LKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
WM_keymap_add_item(keymap, "SEQUENCER_OT_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c
index 7e6af8ea789..314afeac0e6 100644
--- a/source/blender/editors/space_text/space_text.c
+++ b/source/blender/editors/space_text/space_text.c
@@ -268,19 +268,19 @@ static void text_keymap(struct wmKeyConfig *keyconf)
kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", WHEELUPMOUSE, KM_PRESS, KM_CTRL, 0);
RNA_string_set(kmi->ptr, "data_path", "space_data.font_size");
- RNA_boolean_set(kmi->ptr, "reverse", 0);
+ RNA_boolean_set(kmi->ptr, "reverse", FALSE);
kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", WHEELDOWNMOUSE, KM_PRESS, KM_CTRL, 0);
RNA_string_set(kmi->ptr, "data_path", "space_data.font_size");
- RNA_boolean_set(kmi->ptr, "reverse", 1);
+ RNA_boolean_set(kmi->ptr, "reverse", TRUE);
kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
RNA_string_set(kmi->ptr, "data_path", "space_data.font_size");
- RNA_boolean_set(kmi->ptr, "reverse", 0);
+ RNA_boolean_set(kmi->ptr, "reverse", FALSE);
kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", PADMINUS, KM_PRESS, KM_CTRL, 0);
RNA_string_set(kmi->ptr, "data_path", "space_data.font_size");
- RNA_boolean_set(kmi->ptr, "reverse", 1);
+ RNA_boolean_set(kmi->ptr, "reverse", TRUE);
WM_keymap_add_item(keymap, "TEXT_OT_new", NKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "TEXT_OT_open", OKEY, KM_PRESS, KM_ALT, 0);
@@ -298,8 +298,10 @@ static void text_keymap(struct wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "TEXT_OT_copy", INSERTKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "TEXT_OT_paste", INSERTKEY, KM_PRESS, KM_SHIFT, 0);
- if(U.uiflag & USER_MMB_PASTE) // XXX not dynamic
- RNA_boolean_set(WM_keymap_add_item(keymap, "TEXT_OT_paste", MIDDLEMOUSE, KM_PRESS, 0, 0)->ptr, "selection", 1);
+ if(U.uiflag & USER_MMB_PASTE) { // XXX not dynamic
+ kmi = WM_keymap_add_item(keymap, "TEXT_OT_paste", MIDDLEMOUSE, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "selection", TRUE);
+ }
WM_keymap_add_item(keymap, "TEXT_OT_jump", JKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "TEXT_OT_find", GKEY, KM_PRESS, KM_CTRL, 0);
@@ -307,8 +309,10 @@ static void text_keymap(struct wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "TEXT_OT_properties", FKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "TEXT_OT_replace", HKEY, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "TEXT_OT_to_3d_object", MKEY, KM_PRESS, KM_ALT, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "TEXT_OT_to_3d_object", MKEY, KM_PRESS, KM_CTRL, 0)->ptr, "split_lines", 1);
+ kmi = WM_keymap_add_item(keymap, "TEXT_OT_to_3d_object", MKEY, KM_PRESS, KM_ALT, 0);
+ RNA_boolean_set(kmi->ptr, "split_lines", FALSE);
+ kmi = WM_keymap_add_item(keymap, "TEXT_OT_to_3d_object", MKEY, KM_PRESS, KM_CTRL, 0);
+ RNA_boolean_set(kmi->ptr, "split_lines", TRUE);
WM_keymap_add_item(keymap, "TEXT_OT_select_all", AKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "TEXT_OT_select_line", AKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
@@ -357,12 +361,15 @@ static void text_keymap(struct wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "TEXT_OT_overwrite_toggle", INSERTKEY, KM_PRESS, 0, 0);
+ WM_keymap_add_item(keymap, "TEXT_OT_scroll_bar", LEFTMOUSE, KM_PRESS, 0, 0);
+ WM_keymap_add_item(keymap, "TEXT_OT_scroll_bar", MIDDLEMOUSE, KM_PRESS, 0, 0);
+
WM_keymap_add_item(keymap, "TEXT_OT_scroll", MIDDLEMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "TEXT_OT_scroll", MOUSEPAN, 0, 0, 0);
- WM_keymap_add_item(keymap, "TEXT_OT_scroll_bar", LEFTMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "TEXT_OT_selection_set", EVT_TWEAK_L, KM_ANY, 0, 0);
WM_keymap_add_item(keymap, "TEXT_OT_cursor_set", LEFTMOUSE, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "TEXT_OT_selection_set", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "select", 1);
+ kmi = WM_keymap_add_item(keymap, "TEXT_OT_selection_set", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "select", TRUE);
RNA_int_set(WM_keymap_add_item(keymap, "TEXT_OT_scroll", WHEELUPMOUSE, KM_PRESS, 0, 0)->ptr, "lines", -1);
RNA_int_set(WM_keymap_add_item(keymap, "TEXT_OT_scroll", WHEELDOWNMOUSE, KM_PRESS, 0, 0)->ptr, "lines", 1);
diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c
index 25b9c2f2864..8a78f236fea 100644
--- a/source/blender/editors/space_text/text_draw.c
+++ b/source/blender/editors/space_text/text_draw.c
@@ -72,7 +72,7 @@ static void text_font_end(SpaceText *UNUSED(st))
{
}
-static int text_font_draw(SpaceText *UNUSED(st), int x, int y, char *str)
+static int text_font_draw(SpaceText *UNUSED(st), int x, int y, const char *str)
{
BLF_position(mono, x, y, 0);
BLF_draw(mono, str, BLF_DRAW_STR_DUMMY_MAX);
@@ -92,19 +92,28 @@ static int text_font_draw_character(SpaceText *st, int x, int y, char c)
return st->cwidth;
}
-int text_font_width(SpaceText *UNUSED(st), const char *str)
+static int text_font_draw_character_utf8(SpaceText *st, int x, int y, const char *c)
{
- return BLF_width(mono, str);
+ char str[BLI_UTF8_MAX+1];
+ size_t len = BLI_str_utf8_size(c);
+ memcpy(str, c, len);
+ str[len]= '\0';
+
+ BLF_position(mono, x, y, 0);
+ BLF_draw(mono, str, len);
+
+ return st->cwidth;
}
/****************** flatten string **********************/
-static void flatten_string_append(FlattenString *fs, char c, int accum)
+static void flatten_string_append(FlattenString *fs, const char *c, int accum, int len)
{
- if(fs->pos>=fs->len && fs->pos>=sizeof(fs->fixedbuf)-1) {
+ int i;
+
+ if(fs->pos+len > fs->len) {
char *nbuf; int *naccum;
- if(fs->len) fs->len*= 2;
- else fs->len= sizeof(fs->fixedbuf) * 2;
+ fs->len*= 2;
nbuf= MEM_callocN(sizeof(*fs->buf)*fs->len, "fs->buf");
naccum= MEM_callocN(sizeof(*fs->accum)*fs->len, "fs->accum");
@@ -121,35 +130,45 @@ static void flatten_string_append(FlattenString *fs, char c, int accum)
fs->accum= naccum;
}
- fs->buf[fs->pos]= c;
- fs->accum[fs->pos]= accum;
-
- fs->pos++;
+ for (i = 0; i < len; i++)
+ {
+ fs->buf[fs->pos+i]= c[i];
+ fs->accum[fs->pos+i]= accum;
+ }
+
+ fs->pos+= len;
}
int flatten_string(SpaceText *st, FlattenString *fs, const char *in)
{
- int r = 0, i = 0;
+ int r, i, total = 0;
memset(fs, 0, sizeof(FlattenString));
fs->buf= fs->fixedbuf;
fs->accum= fs->fixedaccum;
-
- for(r=0, i=0; *in; r++, in++) {
- if(*in=='\t') {
- if(fs->pos && *(in-1)=='\t')
- i= st->tabnumber;
- else if(st->tabnumber > 0)
- i= st->tabnumber - (fs->pos%st->tabnumber);
+ fs->len = sizeof(fs->fixedbuf);
+ for(r = 0, i = 0; *in; r++) {
+ if(*in=='\t') {
+ i= st->tabnumber - (total%st->tabnumber);
+ total+= i;
+
while(i--)
- flatten_string_append(fs, ' ', r);
+ flatten_string_append(fs, " ", r, 1);
+
+ in++;
+ }
+ else {
+ size_t len= BLI_str_utf8_size(in);
+ flatten_string_append(fs, in, r, len);
+ in += len;
+ total++;
}
- else
- flatten_string_append(fs, *in, r);
}
+
+ flatten_string_append(fs, "\0", r, 1);
- return fs->pos;
+ return total;
}
void flatten_string_free(FlattenString *fs)
@@ -304,9 +323,8 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
}
else orig = 0xFF;
- flatten_string(st, &fs, line->line);
+ len = flatten_string(st, &fs, line->line);
str = fs.buf;
- len = strlen(str);
if(!text_check_format_len(line, len)) {
flatten_string_free(&fs);
return;
@@ -318,7 +336,7 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
if(*str == '\\') {
*fmt = prev; fmt++; str++;
if(*str == '\0') break;
- *fmt = prev; fmt++; str++;
+ *fmt = prev; fmt++; str += BLI_str_utf8_size(str);
continue;
}
/* Handle continuations */
@@ -339,14 +357,16 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
}
*fmt = 'l';
+ str += BLI_str_utf8_size(str) - 1;
}
/* Not in a string... */
else {
/* Deal with comments first */
- if(prev == '#' || *str == '#')
+ if(prev == '#' || *str == '#') {
*fmt = '#';
- /* Strings */
- else if(*str == '"' || *str == '\'') {
+ str += BLI_str_utf8_size(str) - 1;
+ } else if(*str == '"' || *str == '\'') {
+ /* Strings */
find = *str;
cont = (*str== '"') ? TXT_DBLQUOTSTR : TXT_SNGQUOTSTR;
if(*(str+1) == find && *(str+2) == find) {
@@ -371,14 +391,18 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
}
*fmt = 'n';
}
- else
+ else {
+ str += BLI_str_utf8_size(str) - 1;
*fmt = 'q';
+ }
/* Punctuation */
else if(text_check_delim(*str))
*fmt = '!';
/* Identifiers and other text (no previous ws. or delims. so text continues) */
- else if(prev == 'q')
+ else if(prev == 'q') {
+ str += BLI_str_utf8_size(str) - 1;
*fmt = 'q';
+ }
/* Not ws, a digit, punct, or continuing text. Must be new, check for special words */
else {
/* Special vars(v) or built-in keywords(b) */
@@ -395,8 +419,10 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
}
*fmt = prev;
}
- else
+ else {
+ str += BLI_str_utf8_size(str) - 1;
*fmt = 'q';
+ }
}
}
prev = *fmt;
@@ -408,14 +434,11 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
*fmt = '\0'; fmt++;
*fmt = cont;
- /* Debugging */
- //print_format(st, line);
-
/* If continuation has changed and we're allowed, process the next line */
if(cont!=orig && do_next && line->next) {
txt_format_line(st, line->next, do_next);
}
-
+
flatten_string_free(&fs);
}
@@ -539,13 +562,14 @@ void wrap_offset(SpaceText *st, ARegion *ar, TextLine *linein, int cursin, int *
}
max= wrap_width(st, ar);
+ cursin = txt_utf8_offset_to_index(linein->line, cursin);
while(linep) {
start= 0;
end= max;
chop= 1;
*offc= 0;
- for(i=0, j=0; linep->line[j]!='\0'; j++) {
+ for(i=0, j=0; linep->line[j]; j+=BLI_str_utf8_size(linep->line+j)) {
int chars;
/* Mimic replacement of tabs */
@@ -591,6 +615,7 @@ void wrap_offset(SpaceText *st, ARegion *ar, TextLine *linein, int cursin, int *
}
}
+/* cursin - mem, offc - view */
void wrap_offset_in_line(SpaceText *st, ARegion *ar, TextLine *linein, int cursin, int *offl, int *offc)
{
int i, j, start, end, chars, max, chop;
@@ -607,8 +632,9 @@ void wrap_offset_in_line(SpaceText *st, ARegion *ar, TextLine *linein, int cursi
end= max;
chop= 1;
*offc= 0;
+ cursin = txt_utf8_offset_to_index(linein->line, cursin);
- for(i=0, j=0; linein->line[j]!='\0'; j++) {
+ for(i=0, j=0; linein->line[j]; j += BLI_str_utf8_size(linein->line + j)) {
/* Mimic replacement of tabs */
ch= linein->line[j];
@@ -653,7 +679,7 @@ int text_get_char_pos(SpaceText *st, const char *line, int cur)
{
int a=0, i;
- for(i=0; i<cur && line[i]; i++) {
+ for(i=0; i<cur && line[i]; i += BLI_str_utf8_size(line + i)) {
if(line[i]=='\t')
a += st->tabnumber-a%st->tabnumber;
else
@@ -662,54 +688,65 @@ int text_get_char_pos(SpaceText *st, const char *line, int cur)
return a;
}
-static int text_draw_wrapped(SpaceText *st, char *str, int x, int y, int w, char *format, int skip)
+static const char *txt_utf8_get_nth(const char *str, int n)
+{
+ int pos= 0;
+ while (str[pos] && n--) {
+ pos+= BLI_str_utf8_size(str + pos);
+ }
+ return str + pos;
+}
+
+static int text_draw_wrapped(SpaceText *st, const char *str, int x, int y, int w, const char *format, int skip)
{
FlattenString fs;
- int basex, i, a, len, start, end, max, lines;
+ int basex, i, a, start, end, max, lines; /* view */
+ int mi, ma, mstart, mend; /* mem */
- len= flatten_string(st, &fs, str);
+ flatten_string(st, &fs, str);
str= fs.buf;
max= w/st->cwidth;
if(max<8) max= 8;
basex= x;
-
lines= 1;
- start= 0;
- end= max;
- for(i=0; i<len; i++) {
+
+ start= 0; mstart= 0;
+ end= max; mend= txt_utf8_get_nth(str, max) - str;
+
+ for(i=0, mi=0; str[mi]; i++, mi+=BLI_str_utf8_size(str+mi)) {
if(i-start >= max) {
/* skip hidden part of line */
if(skip) {
skip--;
- start= end;
- end += max;
+ start= end; mstart= mend;
+ end += max; mend= txt_utf8_get_nth(str+mend, max) - str;
continue;
}
/* Draw the visible portion of text on the overshot line */
- for(a=start; a<end; a++) {
+ for(a=start, ma=mstart; a<end; a++, ma+=BLI_str_utf8_size(str+ma)) {
if(st->showsyntax && format) format_draw_color(format[a]);
- x += text_font_draw_character(st, x, y, str[a]);
+ x += text_font_draw_character_utf8(st, x, y, str + ma);
}
y -= st->lheight;
x= basex;
lines++;
- start= end;
- end += max;
+ start= end; mstart= mend;
+ end += max; mend= txt_utf8_get_nth(str+mend, max) - str;
if(y<=0) break;
}
- else if(str[i]==' ' || str[i]=='-') {
- end = i+1;
+ else if(str[mi]==' ' || str[mi]=='-') {
+ end = i+1; mend = mi+1;
}
}
/* Draw the remaining text */
- for(a=start; a<len && y > 0; a++) {
+ for(a=start, ma=mstart; str[ma] && y > 0; a++, ma+=BLI_str_utf8_size(str+ma)) {
if(st->showsyntax && format)
format_draw_color(format[a]);
- x += text_font_draw_character(st, x, y, str[a]);
+ x += text_font_draw_character_utf8(st, x, y, str+ma);
}
flatten_string_free(&fs);
@@ -717,45 +754,36 @@ static int text_draw_wrapped(SpaceText *st, char *str, int x, int y, int w, char
return lines;
}
-static int text_draw(SpaceText *st, char *str, int cshift, int maxwidth, int draw, int x, int y, char *format)
+static int text_draw(SpaceText *st, char *str, int cshift, int maxwidth, int draw, int x, int y, const char *format)
{
FlattenString fs;
- int r=0, w= 0, amount;
- int *acc;
- char *in;
+ int *acc, r=0;
+ const char *in;
- w= flatten_string(st, &fs, str);
+ int w= flatten_string(st, &fs, str);
if(w < cshift) {
flatten_string_free(&fs);
return 0; /* String is shorter than shift */
}
- in= fs.buf+cshift;
+ in= txt_utf8_get_nth(fs.buf, cshift);
acc= fs.accum+cshift;
w= w-cshift;
if(draw) {
+ int amount = maxwidth ? MIN2(w, maxwidth) : w;
+
if(st->showsyntax && format) {
- int a;
+ int a, str_shift= 0;
format = format+cshift;
-
- amount = strlen(in);
- if(maxwidth)
- amount= MIN2(amount, maxwidth);
-
+
for(a = 0; a < amount; a++) {
format_draw_color(format[a]);
- x += text_font_draw_character(st, x, y, in[a]);
+ x += text_font_draw_character_utf8(st, x, y, in + str_shift);
+ str_shift += BLI_str_utf8_size(in + str_shift);
}
}
- else {
- amount = strlen(in);
- if(maxwidth)
- amount= MIN2(amount, maxwidth);
-
- in[amount]= 0;
- text_font_draw(st, x, y, in);
- }
+ else text_font_draw(st, x, y, in);
}
else {
while(w-- && *acc++ < maxwidth)
@@ -976,8 +1004,8 @@ int text_get_visible_lines(SpaceText *st, ARegion *ar, const char *str)
max= wrap_width(st, ar);
lines= 1;
start= 0;
- end= max;
- for(i= 0, j= 0; str[j] != '\0'; j++) {
+ end= max;
+ for(i= 0, j= 0; str[j]; j+=BLI_str_utf8_size(str+j)) {
/* Mimic replacement of tabs */
ch= str[j];
if(ch=='\t') {
@@ -1421,7 +1449,7 @@ static void draw_suggestion_list(SpaceText *st, ARegion *ar)
BLI_strncpy(str, item->name, SUGG_LIST_WIDTH);
- w = text_font_width(st, str);
+ w = BLF_width(mono, str);
if(item == sel) {
UI_ThemeColor(TH_SHADE2);
@@ -1496,8 +1524,6 @@ static void draw_cursor(SpaceText *st, ARegion *ar)
glRecti(x-4, y, ar->winx, y-st->lheight), y-=st->lheight;
glRecti(x-4, y, x+toc*st->cwidth, y-st->lheight); y-=st->lheight;
-
- (void)y;
}
}
else {
@@ -1569,8 +1595,9 @@ static void draw_brackets(SpaceText *st, ARegion *ar)
{
TextLine *startl, *endl, *linep;
Text *text = st->text;
- int b, c, startc, endc, find, stack;
- int viewc, viewl, offl, offc, x, y;
+ int b, fc, find, stack, viewc, viewl, offl, offc, x, y;
+ int startc, endc, c;
+
char ch;
// showsyntax must be on or else the format string will be null
@@ -1584,21 +1611,23 @@ static void draw_brackets(SpaceText *st, ARegion *ar)
linep= startl;
c= startc;
+ fc= txt_utf8_offset_to_index(linep->line, startc);
endl= NULL;
endc= -1;
find= -b;
stack= 0;
/* Dont highlight backets if syntax HL is off or bracket in string or comment. */
- if(!linep->format || linep->format[c] == 'l' || linep->format[c] == '#')
+ if(!linep->format || linep->format[fc] == 'l' || linep->format[fc] == '#')
return;
if(b>0) {
/* opening bracket, search forward for close */
- c++;
+ fc++;
+ c+= BLI_str_utf8_size(linep->line+c);
while(linep) {
while(c<linep->len) {
- if(linep->format && linep->format[c] != 'l' && linep->format[c] != '#') {
+ if(linep->format && linep->format[fc] != 'l' && linep->format[fc] != '#') {
b= text_check_bracket(linep->line[c]);
if(b==find) {
if(stack==0) {
@@ -1612,19 +1641,22 @@ static void draw_brackets(SpaceText *st, ARegion *ar)
stack++;
}
}
- c++;
+ fc++;
+ c+= BLI_str_utf8_size(linep->line+c);
}
if(endl) break;
linep= linep->next;
c= 0;
+ fc= 0;
}
}
else {
/* closing bracket, search backward for open */
- c--;
+ fc--;
+ if (c>0) c -= linep->line+c-BLI_str_prev_char_utf8(linep->line+c);
while(linep) {
- while(c>=0) {
- if(linep->format && linep->format[c] != 'l' && linep->format[c] != '#') {
+ while(fc>=0) {
+ if(linep->format && linep->format[fc] != 'l' && linep->format[fc] != '#') {
b= text_check_bracket(linep->line[c]);
if(b==find) {
if(stack==0) {
@@ -1638,11 +1670,17 @@ static void draw_brackets(SpaceText *st, ARegion *ar)
stack++;
}
}
- c--;
+ fc--;
+ if (c>0) c -= linep->line+c-BLI_str_prev_char_utf8(linep->line+c);
}
if(endl) break;
linep= linep->prev;
- if(linep) c= linep->len-1;
+ if(linep) {
+ if (linep->format) fc= strlen(linep->format)-1;
+ else fc= -1;
+ if (linep->len) c= BLI_str_prev_char_utf8(linep->line+linep->len)-linep->line;
+ else fc= -1;
+ }
}
}
diff --git a/source/blender/editors/space_text/text_intern.h b/source/blender/editors/space_text/text_intern.h
index 62cd4fedf0e..043fb97547b 100644
--- a/source/blender/editors/space_text/text_intern.h
+++ b/source/blender/editors/space_text/text_intern.h
@@ -47,9 +47,6 @@ struct wmWindowManager;
/* text_draw.c */
void draw_text_main(struct SpaceText *st, struct ARegion *ar);
-int text_font_width_character(struct SpaceText *st);
-int text_font_width(struct SpaceText *st, const char *str);
-
void text_update_line_edited(struct TextLine *line);
void text_update_edited(struct Text *text);
void text_update_character_width(struct SpaceText *st);
diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c
index e8ad6e19fd4..eab06474546 100644
--- a/source/blender/editors/space_text/text_ops.c
+++ b/source/blender/editors/space_text/text_ops.c
@@ -1420,7 +1420,7 @@ static int text_get_cursor_rel(SpaceText* st, ARegion *ar, TextLine *linein, int
end= max;
chop= loop= 1;
- for(i=0, j=0; loop; j++) {
+ for(i=0, j=0; loop; j+=BLI_str_utf8_size(linein->line+j)) {
int chars;
/* Mimic replacement of tabs */
ch= linein->line[j];
@@ -1595,7 +1595,7 @@ static void txt_wrap_move_bol(SpaceText *st, ARegion *ar, short sel)
chop= loop= 1;
*charp= 0;
- for(i=0, j=0; loop; j++) {
+ for(i=0, j=0; loop; j+=BLI_str_utf8_size((*linep)->line+j)) {
int chars;
/* Mimic replacement of tabs */
ch= (*linep)->line[j];
@@ -1610,7 +1610,7 @@ static void txt_wrap_move_bol(SpaceText *st, ARegion *ar, short sel)
*charp= endj;
if(j>=oldc) {
- if(ch=='\0') *charp= start;
+ if(ch=='\0') *charp= txt_utf8_index_to_offset((*linep)->line, start);
loop= 0;
break;
}
@@ -1623,7 +1623,7 @@ static void txt_wrap_move_bol(SpaceText *st, ARegion *ar, short sel)
}
else if(ch==' ' || ch=='-' || ch=='\0') {
if(j>=oldc) {
- *charp= start;
+ *charp= txt_utf8_index_to_offset((*linep)->line, start);
loop= 0;
break;
}
@@ -1663,7 +1663,7 @@ static void txt_wrap_move_eol(SpaceText *st, ARegion *ar, short sel)
chop= loop= 1;
*charp= 0;
- for(i=0, j=0; loop; j++) {
+ for(i=0, j=0; loop; j+=BLI_str_utf8_size((*linep)->line+j)) {
int chars;
/* Mimic replacement of tabs */
ch= (*linep)->line[j];
@@ -1675,7 +1675,7 @@ static void txt_wrap_move_eol(SpaceText *st, ARegion *ar, short sel)
while(chars--) {
if(i-start>=max) {
- if(chop) endj= j-1;
+ if(chop) endj= BLI_str_prev_char_utf8((*linep)->line+j)-(*linep)->line;
if(endj>=oldc) {
if(ch=='\0') *charp= (*linep)->len;
@@ -2232,8 +2232,8 @@ static int text_scroll_invoke(bContext *C, wmOperator *op, wmEvent *event)
text_scroll_apply(C, op, event);
scroll_exit(C, op);
return OPERATOR_FINISHED;
- }
-
+ }
+
WM_event_add_modal_handler(C, op);
return OPERATOR_RUNNING_MODAL;
@@ -2314,9 +2314,20 @@ static int text_scroll_bar_invoke(bContext *C, wmOperator *op, wmEvent *event)
tsc->scrollbar= 1;
tsc->zone= zone;
op->customdata= tsc;
-
st->flags|= ST_SCROLL_SELECT;
+ /* jump scroll, works in v2d but needs to be added here too :S */
+ if (event->type == MIDDLEMOUSE) {
+ tsc->old[0] = ar->winrct.xmin + (st->txtbar.xmax + st->txtbar.xmin) / 2;
+ tsc->old[1] = ar->winrct.ymin + (st->txtbar.ymax + st->txtbar.ymin) / 2;
+
+ tsc->delta[0] = 0;
+ tsc->delta[1] = 0;
+ tsc->first = 0;
+ tsc->zone= SCROLLHANDLE_BAR;
+ text_scroll_apply(C, op, event);
+ }
+
WM_event_add_modal_handler(C, op);
return OPERATOR_RUNNING_MODAL;
@@ -2353,148 +2364,183 @@ typedef struct SetSelection {
short old[2];
} SetSelection;
-static void text_cursor_set_to_pos(SpaceText *st, ARegion *ar, int x, int y, int sel)
+static int flatten_len(SpaceText *st, const char *str)
{
- FlattenString fs;
- Text *text= st->text;
- TextLine **linep;
- int *charp;
- int w;
-
- text_update_character_width(st);
+ int i, total = 0;
- if(sel) { linep= &text->sell; charp= &text->selc; }
- else { linep= &text->curl; charp= &text->curc; }
+ for(i = 0; str[i]; i += BLI_str_utf8_size(str+i)) {
+ if(str[i]=='\t') {
+ total += st->tabnumber - total%st->tabnumber;
+ }
+ else total++;
+ }
- y= (ar->winy - 2 - y)/st->lheight;
-
- if(st->showlinenrs)
- x-= TXT_OFFSET+TEXTXLOC;
- else
- x-= TXT_OFFSET;
+ return total;
+}
- if(x<0) x= 0;
- x = (x/st->cwidth) + st->left;
+static int flatten_index_to_offset(SpaceText *st, const char *str, int index)
+{
+ int i, j;
+ for (i= 0, j= 0; i < index; j += BLI_str_utf8_size(str+j))
+ if(str[j]=='\t')
+ i += st->tabnumber - i%st->tabnumber;
+ else
+ i++;
- if(st->wordwrap) {
- int i, j, endj, curs, max, chop, start, end, loop, found;
- char ch;
-
- /* Point to first visible line */
- *linep= text->lines.first;
- i= st->top;
- while(i>0 && *linep) {
- int lines= text_get_visible_lines(st, ar, (*linep)->line);
+ return j;
+}
- if (i-lines<0) {
- y+= i;
- break;
- } else {
- *linep= (*linep)->next;
- i-= lines;
- }
+static TextLine *get_first_visible_line(SpaceText *st, ARegion *ar, int *y)
+{
+ TextLine *linep = st->text->lines.first;
+ int i;
+ for (i = st->top; i > 0 && linep; ) {
+ int lines = text_get_visible_lines(st, ar, linep->line);
+
+ if (i-lines < 0) {
+ *y += i;
+ break;
+ } else {
+ linep = linep->next;
+ i -= lines;
}
+ }
+ return linep;
+}
- max= wrap_width(st, ar);
-
- loop= 1;
- found= 0;
- while(loop && *linep) {
- start= 0;
- end= max;
- chop= 1;
- curs= 0;
- endj= 0;
- for(i=0, j=0; loop; j++) {
- int chars;
-
- /* Mimic replacement of tabs */
- ch= (*linep)->line[j];
- if(ch=='\t') {
- chars= st->tabnumber-i%st->tabnumber;
- ch= ' ';
- }
- else
- chars= 1;
-
- while(chars--) {
- /* Gone too far, go back to last wrap point */
- if(y<0) {
- *charp= endj;
- loop= 0;
- break;
+static void text_cursor_set_to_pos_wrapped(SpaceText *st, ARegion *ar, int x, int y, int sel)
+{
+ Text *text = st->text;
+ int max = wrap_width(st, ar); /* view */
+ int charp; /* mem */
+ int loop = 1, found = 0; /* flags */
+ char ch;
+
+ /* Point to first visible line */
+ TextLine *linep = get_first_visible_line(st, ar, &y);
+
+ while(loop && linep) {
+ int i = 0, start = 0, end = max; /* view */
+ int j = 0, curs = 0, endj = 0; /* mem */
+ int chop = 1; /* flags */
+
+ for (; loop; j += BLI_str_utf8_size(linep->line+j)) {
+ int chars;
+
+ /* Mimic replacement of tabs */
+ ch = linep->line[j];
+ if(ch == '\t') {
+ chars = st->tabnumber - i%st->tabnumber;
+ ch = ' ';
+ }
+ else chars = 1;
+
+ while (chars--) {
+ /* Gone too far, go back to last wrap point */
+ if (y < 0) {
+ charp = endj;
+ loop = 0;
+ break;
/* Exactly at the cursor */
- }
- else if(y==0 && i-start==x) {
- /* current position could be wrapped to next line */
- /* this should be checked when end of current line would be reached */
- *charp= curs= j;
- found= 1;
+ }
+ else if (y == 0 && i-start == x) {
+ /* current position could be wrapped to next line */
+ /* this should be checked when end of current line would be reached */
+ charp = curs= j;
+ found = 1;
/* Prepare curs for next wrap */
+ }
+ else if(i - end == x) {
+ curs = j;
+ }
+ if (i - start >= max) {
+ if (found) {
+ /* exact cursor position was found, check if it's */
+ /* still on needed line (hasn't been wrapped) */
+ if (charp > endj && !chop && ch!='\0') charp = endj;
+ loop = 0;
+ break;
}
- else if(i-end==x) {
- curs= j;
+
+ if(chop) endj = j;
+ start = end;
+ end += max;
+
+ if(j < linep->len)
+ y--;
+
+ chop = 1;
+ if (y == 0 && i-start >= x) {
+ charp = curs;
+ loop = 0;
+ break;
}
- if(i-start>=max) {
- if(found) {
- /* exact cursor position was found, check if it's */
- /* still on needed line (hasn't been wrapped) */
- if(*charp>endj && !chop && ch!='\0') (*charp)= endj;
- loop= 0;
- break;
- }
-
- if(chop) endj= j;
- start= end;
- end += max;
-
- if(j<(*linep)->len)
- y--;
-
- chop= 1;
- if(y==0 && i-start>=x) {
- *charp= curs;
- loop= 0;
- break;
- }
+ }
+ else if (ch == ' ' || ch == '-' || ch == '\0') {
+ if (found) {
+ loop = 0;
+ break;
}
- else if(ch==' ' || ch=='-' || ch=='\0') {
- if(found) {
- loop= 0;
- break;
- }
-
- if(y==0 && i-start>=x) {
- *charp= curs;
- loop= 0;
- break;
- }
- end = i+1;
- endj = j;
- chop= 0;
+
+ if(y == 0 && i-start >= x) {
+ charp = curs;
+ loop = 0;
+ break;
}
- i++;
+ end = i + 1;
+ endj = j;
+ chop = 0;
}
- if(ch=='\0') break;
+ i++;
}
- if(!loop || found) break;
+
+ if(ch == '\0') break;
+ }
+
+ if(!loop || found) break;
+
+ if(!linep->next) {
+ charp = linep->len;
+ break;
+ }
+
+ /* On correct line but didn't meet cursor, must be at end */
+ if (y == 0) {
+ charp = linep->len;
+ break;
+ }
+ linep = linep->next;
+
+ y--;
+ }
+
+ if(sel) { text->sell = linep; text->selc = charp; }
+ else { text->curl = linep; text->curc = charp; }
+}
- if(!(*linep)->next) {
- *charp= (*linep)->len;
- break;
- }
+static void text_cursor_set_to_pos(SpaceText *st, ARegion *ar, int x, int y, int sel)
+{
+ Text *text= st->text;
+ text_update_character_width(st);
+ y= (ar->winy - 2 - y)/st->lheight;
- /* On correct line but didn't meet cursor, must be at end */
- if(y==0) {
- *charp= (*linep)->len;
- break;
- }
- *linep= (*linep)->next;
- y--;
- }
+ if(st->showlinenrs) x-= TXT_OFFSET+TEXTXLOC;
+ else x-= TXT_OFFSET;
+ if(x<0) x= 0;
+ x = (x/st->cwidth) + st->left;
+
+ if(st->wordwrap) {
+ text_cursor_set_to_pos_wrapped(st, ar, x, y, sel);
}
else {
+ TextLine **linep;
+ int *charp;
+ int w;
+
+ if(sel) { linep= &text->sell; charp= &text->selc; }
+ else { linep= &text->curl; charp= &text->curc; }
+
y-= txt_get_span(text->lines.first, *linep) - st->top;
if(y>0) {
@@ -2505,10 +2551,9 @@ static void text_cursor_set_to_pos(SpaceText *st, ARegion *ar, int x, int y, int
}
- w= flatten_string(st, &fs, (*linep)->line);
- if(x<w) *charp= fs.accum[x];
+ w= flatten_len(st, (*linep)->line);
+ if(x<w) *charp= flatten_index_to_offset(st, (*linep)->line, x);
else *charp= (*linep)->len;
- flatten_string_free(&fs);
}
if(!sel) txt_pop_sel(text);
}
@@ -2751,19 +2796,23 @@ static int text_insert_exec(bContext *C, wmOperator *op)
SpaceText *st= CTX_wm_space_text(C);
Text *text= CTX_data_edit_text(C);
char *str;
- int done = 0, i;
+ int done = 0;
+ size_t i = 0;
+ unsigned int code;
text_drawcache_tag_update(st, 0);
str= RNA_string_get_alloc(op->ptr, "text", NULL, 0);
if(st && st->overwrite) {
- for(i=0; str[i]; i++) {
- done |= txt_replace_char(text, str[i]);
+ while (str[i]) {
+ code = BLI_str_utf8_as_unicode_step(str, &i);
+ done |= txt_replace_char(text, code);
}
} else {
- for(i=0; str[i]; i++) {
- done |= txt_add_char(text, str[i]);
+ while (str[i]) {
+ code = BLI_str_utf8_as_unicode_step(str, &i);
+ done |= txt_add_char(text, code);
}
}
@@ -2791,9 +2840,17 @@ static int text_insert_invoke(bContext *C, wmOperator *op, wmEvent *event)
return OPERATOR_PASS_THROUGH;
}
else {
- char str[2];
- str[0]= event->ascii;
- str[1]= '\0';
+ char str[BLI_UTF8_MAX+1];
+ size_t len;
+
+ if (event->utf8_buf[0]) {
+ len = BLI_str_utf8_size(event->utf8_buf);
+ memcpy(str, event->utf8_buf, len);
+ } else {
+ /* in theory, ghost can set value to extended ascii here */
+ len = BLI_str_utf8_from_unicode(event->ascii, str);
+ }
+ str[len]= '\0';
RNA_string_set(op->ptr, "text", str);
}
}
diff --git a/source/blender/editors/space_view3d/drawarmature.c b/source/blender/editors/space_view3d/drawarmature.c
index 17cb1ce2995..599e113ba97 100644
--- a/source/blender/editors/space_view3d/drawarmature.c
+++ b/source/blender/editors/space_view3d/drawarmature.c
@@ -526,7 +526,8 @@ static void draw_bone_solid_octahedral(void)
glEnableClientState(GL_VERTEX_ARRAY);
glNormalPointer(GL_FLOAT, 0, bone_octahedral_solid_normals);
glVertexPointer(3, GL_FLOAT, 0, bone_octahedral_verts);
- glDrawElements(GL_TRIANGLES, sizeof(bone_octahedral_solid_tris)/sizeof(unsigned int), GL_UNSIGNED_INT, bone_octahedral_solid_tris);
+ glDrawElements(GL_TRIANGLES, sizeof(bone_octahedral_solid_tris)/sizeof(unsigned int),
+ GL_UNSIGNED_INT, bone_octahedral_solid_tris);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
#endif
@@ -738,7 +739,9 @@ static void draw_sphere_bone_dist(float smat[][4], float imat[][4], bPoseChannel
/* smat, imat = mat & imat to draw screenaligned */
-static void draw_sphere_bone_wire(float smat[][4], float imat[][4], int armflag, int boneflag, short constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone)
+static void draw_sphere_bone_wire(float smat[][4], float imat[][4],
+ int armflag, int boneflag, short constflag, unsigned int id,
+ bPoseChannel *pchan, EditBone *ebone)
{
float head, tail /*, length*/;
float *headvec, *tailvec, dirvec[3];
@@ -843,7 +846,8 @@ static void draw_sphere_bone_wire(float smat[][4], float imat[][4], int armflag,
}
/* does wire only for outline selecting */
-static void draw_sphere_bone(int dt, int armflag, int boneflag, short constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone)
+static void draw_sphere_bone(int dt, int armflag, int boneflag, short constflag, unsigned int id,
+ bPoseChannel *pchan, EditBone *ebone)
{
GLUquadricObj *qobj;
float head, tail, length;
@@ -973,7 +977,8 @@ static GLubyte bm_dot5[]= {0x0, 0x0, 0x10, 0x38, 0x7c, 0x38, 0x10, 0x0};
static GLubyte bm_dot7[]= {0x0, 0x38, 0x7C, 0xFE, 0xFE, 0xFE, 0x7C, 0x38};
-static void draw_line_bone(int armflag, int boneflag, short constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone)
+static void draw_line_bone(int armflag, int boneflag, short constflag, unsigned int id,
+ bPoseChannel *pchan, EditBone *ebone)
{
float length;
@@ -1107,7 +1112,8 @@ static void draw_b_bone_boxes(int dt, bPoseChannel *pchan, float xwidth, float l
}
}
-static void draw_b_bone(int dt, int armflag, int boneflag, short constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone)
+static void draw_b_bone(int dt, int armflag, int boneflag, short constflag, unsigned int id,
+ bPoseChannel *pchan, EditBone *ebone)
{
float xwidth, length, zwidth;
@@ -1220,7 +1226,8 @@ static void draw_wire_bone_segments(bPoseChannel *pchan, Mat4 *bbones, float len
}
}
-static void draw_wire_bone(int dt, int armflag, int boneflag, short constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone)
+static void draw_wire_bone(int dt, int armflag, int boneflag, short constflag, unsigned int id,
+ bPoseChannel *pchan, EditBone *ebone)
{
Mat4 *bbones = NULL;
int segments = 0;
@@ -1340,7 +1347,8 @@ static void draw_bone(int dt, int armflag, int boneflag, short constflag, unsign
}
}
-static void draw_custom_bone(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, int dt, int armflag, int boneflag, unsigned int id, float length)
+static void draw_custom_bone(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob,
+ int dt, int armflag, int boneflag, unsigned int id, float length)
{
if(ob==NULL) return;
@@ -1573,7 +1581,8 @@ static void draw_pose_dofs(Object *ob)
glColor3ub(50, 50, 255); // blue, Z axis limit
glBegin(GL_LINE_STRIP);
for (a=-16; a<=16; a++) {
- float fac= ((float)a)/16.0f * 0.5f; /* *0.5f here comes from M_PI/360.0f when rotations were still in degrees */
+ /* *0.5f here comes from M_PI/360.0f when rotations were still in degrees */
+ float fac= ((float)a)/16.0f * 0.5f;
phi= fac * (pchan->limitmax[2] - pchan->limitmin[2]);
@@ -1596,7 +1605,8 @@ static void draw_pose_dofs(Object *ob)
glColor3ub(255, 50, 50); // Red, X axis limit
glBegin(GL_LINE_STRIP);
for (a=-16; a<=16; a++) {
- float fac= ((float)a)/16.0f * 0.5f; /* *0.5f here comes from M_PI/360.0f when rotations were still in degrees */
+ /* *0.5f here comes from M_PI/360.0f when rotations were still in degrees */
+ float fac= ((float)a)/16.0f * 0.5f;
phi= (float)(0.5*M_PI) + fac * (pchan->limitmax[0] - pchan->limitmin[0]);
i= (a == -16) ? 2 : 3;
@@ -1630,7 +1640,8 @@ static void bone_matrix_translate_y(float mat[][4], float y)
}
/* assumes object is Armature with pose */
-static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, int dt, const short is_ghost, const short is_outline)
+static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, int dt,
+ const short is_ghost, const short is_outline)
{
RegionView3D *rv3d= ar->regiondata;
Object *ob= base->object;
@@ -1730,10 +1741,13 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
if (use_custom) {
/* if drawwire, don't try to draw in solid */
- if (pchan->bone->flag & BONE_DRAWWIRE)
+ if (pchan->bone->flag & BONE_DRAWWIRE) {
draw_wire= 1;
- else
- draw_custom_bone(scene, v3d, rv3d, pchan->custom, OB_SOLID, arm->flag, flag, index, bone->length);
+ }
+ else {
+ draw_custom_bone(scene, v3d, rv3d, pchan->custom,
+ OB_SOLID, arm->flag, flag, index, bone->length);
+ }
}
else if (arm->drawtype==ARM_LINE)
; /* nothing in solid */
@@ -1817,7 +1831,8 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
if (bone == arm->act_bone)
flag |= BONE_DRAW_ACTIVE;
- draw_custom_bone(scene, v3d, rv3d, pchan->custom, OB_WIRE, arm->flag, flag, index, bone->length);
+ draw_custom_bone(scene, v3d, rv3d, pchan->custom,
+ OB_WIRE, arm->flag, flag, index, bone->length);
glPopMatrix();
}
@@ -1966,7 +1981,7 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
unsigned char col[4];
float col_f[4];
glGetFloatv(GL_CURRENT_COLOR, col_f); /* incase this is not set below */
- rgb_float_to_byte(col_f, col);
+ rgb_float_to_uchar(col, col_f);
col[3]= 255;
if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
@@ -2580,7 +2595,3 @@ int draw_armature(Scene *scene, View3D *v3d, ARegion *ar, Base *base, int dt, in
return retval;
}
-
-/* *************** END Armature drawing ******************* */
-
-
diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c
index b1842578c20..5f521cc3dd1 100644
--- a/source/blender/editors/space_view3d/drawmesh.c
+++ b/source/blender/editors/space_view3d/drawmesh.c
@@ -349,11 +349,8 @@ static void draw_textured_begin(Scene *scene, View3D *v3d, RegionView3D *rv3d, O
Gtexdraw.islit= GPU_scene_object_lights(scene, ob, v3d->lay, rv3d->viewmat, !rv3d->is_persp);
}
- obcol[0]= CLAMPIS(ob->col[0]*255, 0, 255);
- obcol[1]= CLAMPIS(ob->col[1]*255, 0, 255);
- obcol[2]= CLAMPIS(ob->col[2]*255, 0, 255);
- obcol[3]= CLAMPIS(ob->col[3]*255, 0, 255);
-
+ rgba_float_to_uchar(obcol, ob->col);
+
glCullFace(GL_BACK); glEnable(GL_CULL_FACE);
if(solidtex || v3d->drawtype==OB_TEXTURE) istex= 1;
else istex= 0;
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index afe11cdd37f..fd0338c8206 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -2707,10 +2707,14 @@ static void draw_em_measure_stats(View3D *v3d, Object *ob, EditMesh *em, UnitSet
mul_mat3_m4_v3(ob->obmat, v1);
mul_mat3_m4_v3(ob->obmat, v2);
}
- if(unit->system)
- bUnit_AsString(numstr, sizeof(numstr), len_v3v3(v1, v2)*unit->scale_length, 3, unit->system, B_UNIT_LENGTH, do_split, FALSE);
- else
+
+ if(unit->system) {
+ bUnit_AsString(numstr, sizeof(numstr), len_v3v3(v1, v2) * unit->scale_length, 3,
+ unit->system, B_UNIT_LENGTH, do_split, FALSE);
+ }
+ else {
sprintf(numstr, conv_float, len_v3v3(v1, v2));
+ }
view3d_cached_text_draw_add(vmid, numstr, 0, V3D_CACHE_TEXT_ASCII, col);
}
@@ -2718,7 +2722,7 @@ static void draw_em_measure_stats(View3D *v3d, Object *ob, EditMesh *em, UnitSet
}
if(me->drawflag & ME_DRAWEXTRA_FACEAREA) {
-// XXX extern int faceselectedOR(EditFace *efa, int flag); // editmesh.h shouldn't be in this file... ok for now?
+// XXX extern int faceselectedOR(EditFace *efa, int flag); // editmesh.h shouldn't be in this file... ok for now?
UI_GetThemeColor3ubv(TH_DRAWEXTRA_FACEAREA, col);
for(efa= em->faces.first; efa; efa= efa->next) {
@@ -2741,10 +2745,14 @@ static void draw_em_measure_stats(View3D *v3d, Object *ob, EditMesh *em, UnitSet
else
area = area_tri_v3(v1, v2, v3);
- if(unit->system)
- bUnit_AsString(numstr, sizeof(numstr), area*unit->scale_length, 3, unit->system, B_UNIT_LENGTH, do_split, FALSE); // XXX should be B_UNIT_AREA
- else
+ if(unit->system) {
+ // XXX should be B_UNIT_AREA
+ bUnit_AsString(numstr, sizeof(numstr), area * unit->scale_length, 3,
+ unit->system, B_UNIT_LENGTH, do_split, FALSE);
+ }
+ else {
sprintf(numstr, conv_float, area);
+ }
view3d_cached_text_draw_add(efa->cent, numstr, 0, V3D_CACHE_TEXT_ASCII, col);
}
@@ -4126,7 +4134,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
if(v3d->zbuf) glDepthMask(1);
if((ma) && (part->draw_col == PART_DRAW_COL_MAT)) {
- rgb_float_to_byte(&(ma->r), tcol);
+ rgb_float_to_uchar(tcol, &(ma->r));
copy_v3_v3(ma_col, &ma->r);
}
@@ -6178,7 +6186,7 @@ static void drawRBpivot(bRigidBodyJointConstraint *data)
float curcol[4];
unsigned char tcol[4];
glGetFloatv(GL_CURRENT_COLOR, curcol);
- rgb_float_to_byte(curcol, tcol);
+ rgb_float_to_uchar(tcol, curcol);
tcol[3]= 255;
eul_to_mat4(mat,&data->axX);
@@ -6801,7 +6809,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
float curcol[4];
unsigned char tcol[4];
glGetFloatv(GL_CURRENT_COLOR, curcol);
- rgb_float_to_byte(curcol, tcol);
+ rgb_float_to_uchar(tcol, curcol);
tcol[3]= 255;
view3d_cached_text_draw_add(zero, ob->id.name+2, 10, 0, tcol);
}
diff --git a/source/blender/editors/space_view3d/drawvolume.c b/source/blender/editors/space_view3d/drawvolume.c
index 8308a4a9ccf..1ed8e44a26b 100644
--- a/source/blender/editors/space_view3d/drawvolume.c
+++ b/source/blender/editors/space_view3d/drawvolume.c
@@ -170,7 +170,8 @@ void draw_volume(ARegion *ar, GPUTexture *tex, float *min, float *max, int res[3
float cor[3] = {1.,1.,1.};
int gl_depth = 0, gl_blend = 0;
- /* draw slices of smoke is adapted from c++ code authored by: Johannes Schmid and Ingemar Rask, 2006, johnny@grob.org */
+ /* draw slices of smoke is adapted from c++ code authored
+ * by: Johannes Schmid and Ingemar Rask, 2006, johnny@grob.org */
float cv[][3] = {
{1.0f, 1.0f, 1.0f}, {-1.0f, 1.0f, 1.0f}, {-1.0f, -1.0f, 1.0f}, {1.0f, -1.0f, 1.0f},
{1.0f, 1.0f, -1.0f}, {-1.0f, 1.0f, -1.0f}, {-1.0f, -1.0f, -1.0f}, {1.0f, -1.0f, -1.0f}
@@ -424,7 +425,9 @@ void draw_volume(ARegion *ar, GPUTexture *tex, float *min, float *max, int res[3
glBegin(GL_POLYGON);
glColor3f(1.0, 1.0, 1.0);
for (i = 0; i < numpoints; i++) {
- glTexCoord3d((points[i * 3 + 0] - min[0] )*cor[0]/size[0], (points[i * 3 + 1] - min[1])*cor[1]/size[1], (points[i * 3 + 2] - min[2])*cor[2]/size[2]);
+ glTexCoord3d((points[i * 3 + 0] - min[0]) * cor[0] / size[0],
+ (points[i * 3 + 1] - min[1]) * cor[1] / size[1],
+ (points[i * 3 + 2] - min[2]) * cor[2] / size[2]);
glVertex3f(points[i * 3 + 0], points[i * 3 + 1], points[i * 3 + 2]);
}
glEnd();
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index f2906ca9559..94ab847c91b 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -1023,7 +1023,8 @@ static void space_view3d_listener(struct ScrArea *sa, struct wmNotifier *wmn)
break;
}
-#if 0 // removed since BKE_image_user_calc_frame is now called in draw_bgpic because screen_ops doesnt call the notifier.
+ // removed since BKE_image_user_calc_frame is now called in draw_bgpic because screen_ops doesnt call the notifier.
+#if 0
if (wmn->category == NC_SCENE && wmn->data == ND_FRAME) {
View3D *v3d = area->spacedata.first;
BGpic *bgpic = v3d->bgpicbase.first;
@@ -1048,7 +1049,8 @@ static int view3d_context(const bContext *C, const char *member, bContextDataRes
View3D *v3d= CTX_wm_view3d(C);
Scene *scene= CTX_data_scene(C);
Base *base;
- unsigned int lay = v3d ? v3d->lay:scene->lay; /* fallback to the scene layer, allows duplicate and other oject operators to run outside the 3d view */
+ /* fallback to the scene layer, allows duplicate and other object operators to run outside the 3d view */
+ unsigned int lay = v3d ? v3d->lay:scene->lay;
if(CTX_data_dir(member)) {
CTX_data_dir_set(result, view3d_context_dir);
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index ad85ff6dea8..4f46a746b9e 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -471,7 +471,8 @@ static void drawfloor(Scene *scene, View3D *v3d, const char **grid_unit)
/* emphasise division lines lighter instead of darker, if background is darker than grid */
UI_GetColorPtrShade3ubv(col_grid, col_grid_light, 10);
UI_GetColorPtrShade3ubv(col_grid, col_grid_emphasise,
- (((col_grid[0]+col_grid[1]+col_grid[2])+30) > (col_bg[0]+col_bg[1]+col_bg[2])) ? 20 : -10);
+ (((col_grid[0]+col_grid[1]+col_grid[2])+30) >
+ (col_bg[0]+col_bg[1]+col_bg[2])) ? 20 : -10);
/* set fixed axis */
vert[0][0]= vert[2][1]= grid;
@@ -923,7 +924,8 @@ static void draw_selected_name(Scene *scene, Object *ob)
BLF_draw_default(offset, 10, 0.0f, info, sizeof(info));
}
-static void view3d_camera_border(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, rctf *viewborder_r, short no_shift, short no_zoom)
+static void view3d_camera_border(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d,
+ rctf *viewborder_r, short no_shift, short no_zoom)
{
CameraParams params;
rctf rect_view, rect_camera;
@@ -962,7 +964,8 @@ void ED_view3d_calc_camera_border_size(Scene *scene, ARegion *ar, View3D *v3d, R
size_r[1]= viewborder.ymax - viewborder.ymin;
}
-void ED_view3d_calc_camera_border(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, rctf *viewborder_r, short no_shift)
+void ED_view3d_calc_camera_border(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d,
+ rctf *viewborder_r, short no_shift)
{
view3d_camera_border(scene, ar, v3d, rv3d, viewborder_r, no_shift, FALSE);
}
@@ -1097,7 +1100,9 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
setlinestyle(0);
+
UI_ThemeColor(TH_BACK);
+
glRectf(x1i, y1i, x2i, y2i);
#ifdef VIEW3D_CAMERA_BORDER_HACK
@@ -1109,6 +1114,13 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
#endif
setlinestyle(3);
+
+ /* outer line not to confuse with object selecton */
+ if (v3d->flag2 & V3D_LOCK_CAMERA) {
+ UI_ThemeColor(TH_REDALERT);
+ glRectf(x1i - 1, y1i - 1, x2i + 1, y2i + 1);
+ }
+
UI_ThemeColor(TH_WIRE);
glRectf(x1i, y1i, x2i, y2i);
@@ -1386,7 +1398,12 @@ ImBuf *view3d_read_backbuf(ViewContext *vc, short xmin, short ymin, short xmax,
view3d_validate_backbuf(vc);
- glReadPixels(vc->ar->winrct.xmin+xminc, vc->ar->winrct.ymin+yminc, (xmaxc-xminc+1), (ymaxc-yminc+1), GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
+ glReadPixels(vc->ar->winrct.xmin + xminc,
+ vc->ar->winrct.ymin + yminc,
+ (xmaxc-xminc + 1),
+ (ymaxc-yminc + 1),
+ GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
+
glReadBuffer(GL_BACK);
if(ENDIAN_ORDER==B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf);
@@ -1810,11 +1827,13 @@ static void draw_dupli_objects_color(Scene *scene, ARegion *ar, View3D *v3d, Bas
* offset feature (used in group-duplicate.blend but no longer works in 2.5)
* so for now it should be ok to - campbell */
- if( (dob_next==NULL || dob_next->ob != dob->ob) || /* if this is the last no need to make a displist */
- (dob->ob->type == OB_LAMP) || /* lamp drawing messes with matrices, could be handled smarter... but this works */
- (dob->type == OB_DUPLIGROUP && dob->animated) ||
- !(bb_tmp= object_get_boundbox(dob->ob))
- ) {
+ if ( /* if this is the last no need to make a displist */
+ (dob_next==NULL || dob_next->ob != dob->ob) ||
+ /* lamp drawing messes with matrices, could be handled smarter... but this works */
+ (dob->ob->type == OB_LAMP) ||
+ (dob->type == OB_DUPLIGROUP && dob->animated) ||
+ !(bb_tmp= object_get_boundbox(dob->ob)))
+ {
// printf("draw_dupli_objects_color: skipping displist for %s\n", dob->ob->id.name+2);
use_displist= 0;
}
@@ -2142,7 +2161,8 @@ typedef struct View3DShadow {
GPULamp *lamp;
} View3DShadow;
-static void gpu_render_lamp_update(Scene *scene, View3D *v3d, Object *ob, Object *par, float obmat[][4], ListBase *shadows)
+static void gpu_render_lamp_update(Scene *scene, View3D *v3d, Object *ob, Object *par,
+ float obmat[][4], ListBase *shadows)
{
GPULamp *lamp;
Lamp *la = (Lamp*)ob->data;
@@ -2236,7 +2256,9 @@ CustomDataMask ED_view3d_datamask(Scene *scene, View3D *v3d)
{
CustomDataMask mask= 0;
- if(ELEM(v3d->drawtype, OB_TEXTURE, OB_MATERIAL) || ((v3d->drawtype == OB_SOLID) && (v3d->flag2 & V3D_SOLID_TEX))) {
+ if ( ELEM(v3d->drawtype, OB_TEXTURE, OB_MATERIAL) ||
+ ((v3d->drawtype == OB_SOLID) && (v3d->flag2 & V3D_SOLID_TEX)))
+ {
mask |= CD_MASK_MTFACE | CD_MASK_MCOL;
if(scene_use_new_shading_nodes(scene)) {
@@ -2344,7 +2366,8 @@ static void view3d_main_area_setup_view(Scene *scene, View3D *v3d, ARegion *ar,
glLoadMatrixf(rv3d->viewmat);
}
-void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar, int winx, int winy, float viewmat[][4], float winmat[][4])
+void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar,
+ int winx, int winy, float viewmat[][4], float winmat[][4])
{
RegionView3D *rv3d= ar->regiondata;
Base *base;
@@ -2469,13 +2492,15 @@ void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar, int winx,
glPopMatrix();
- glColor4ub(255, 255, 255, 255); // XXX, without this the sequencer flickers with opengl draw enabled, need to find out why - campbell
+ // XXX, without this the sequencer flickers with opengl draw enabled, need to find out why - campbell
+ glColor4ub(255, 255, 255, 255);
G.f &= ~G_RENDER_OGL;
}
/* utility func for ED_view3d_draw_offscreen */
-ImBuf *ED_view3d_draw_offscreen_imbuf(Scene *scene, View3D *v3d, ARegion *ar, int sizex, int sizey, unsigned int flag, char err_out[256])
+ImBuf *ED_view3d_draw_offscreen_imbuf(Scene *scene, View3D *v3d, ARegion *ar,
+ int sizex, int sizey, unsigned int flag, char err_out[256])
{
RegionView3D *rv3d= ar->regiondata;
ImBuf *ibuf;
@@ -2530,7 +2555,8 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Scene *scene, View3D *v3d, ARegion *ar, in
}
/* creates own 3d views, used by the sequencer */
-ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Scene *scene, Object *camera, int width, int height, unsigned int flag, int drawtype, char err_out[256])
+ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Scene *scene, Object *camera, int width, int height,
+ unsigned int flag, int drawtype, char err_out[256])
{
View3D v3d= {NULL};
ARegion ar= {NULL};
@@ -2889,6 +2915,7 @@ static void view3d_main_area_draw_info(const bContext *C, ARegion *ar, const cha
else if(U.uiflag & USER_SHOW_VIEWPORTNAME) {
draw_viewport_name(ar, v3d);
}
+
if (grid_unit) { /* draw below the viewport name */
char numstr[32]= "";
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index 224df5b9f80..2620fe4ac71 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -208,10 +208,9 @@ static void view3d_boxview_clip(ScrArea *sa)
normal_tri_v3( clip[5],bb->vec[0], bb->vec[2], bb->vec[1]);
/* then plane equations */
- for(val=0; val<5; val++) {
- clip[val][3]= - clip[val][0]*bb->vec[val][0] - clip[val][1]*bb->vec[val][1] - clip[val][2]*bb->vec[val][2];
+ for(val=0; val<6; val++) {
+ clip[val][3] = -dot_v3v3(clip[val], bb->vec[val % 5]);
}
- clip[5][3]= - clip[5][0]*bb->vec[0][0] - clip[5][1]*bb->vec[0][1] - clip[5][2]*bb->vec[0][2];
/* create bounding box */
for(ar= sa->regionbase.first; ar; ar= ar->next) {
@@ -519,52 +518,54 @@ static void viewops_data_free(bContext *C, wmOperator *op)
static const float thres = 0.93f; //cos(20 deg);
-#define COS45 0.70710678118654746
+#define COS45 0.7071068
#define SIN45 COS45
-static float snapquats[39][5] = {
+#define NUM_SNAP_QUATS 39
+
+static const float snapquats[NUM_SNAP_QUATS][5] = {
/*{q0, q1, q3, q4, view}*/
- {COS45, -SIN45, 0.0, 0.0, RV3D_VIEW_FRONT}, //front
- {0.0, 0.0, -SIN45, -SIN45, RV3D_VIEW_BACK}, //back
- {1.0, 0.0, 0.0, 0.0, RV3D_VIEW_TOP}, //top
- {0.0, -1.0, 0.0, 0.0, RV3D_VIEW_BOTTOM}, //bottom
- {0.5, -0.5, -0.5, -0.5, RV3D_VIEW_RIGHT}, //left
- {0.5, -0.5, 0.5, 0.5, RV3D_VIEW_LEFT}, //right
+ {COS45, -SIN45, 0.0, 0.0, RV3D_VIEW_FRONT},
+ {0.0, 0.0, -SIN45, -SIN45, RV3D_VIEW_BACK},
+ {1.0, 0.0, 0.0, 0.0, RV3D_VIEW_TOP},
+ {0.0, -1.0, 0.0, 0.0, RV3D_VIEW_BOTTOM},
+ {0.5, -0.5, -0.5, -0.5, RV3D_VIEW_RIGHT},
+ {0.5, -0.5, 0.5, 0.5, RV3D_VIEW_LEFT},
/* some more 45 deg snaps */
- {0.65328145027160645, -0.65328145027160645, 0.27059805393218994, 0.27059805393218994, 0},
- {0.92387950420379639, 0.0, 0.0, 0.38268342614173889, 0},
- {0.0, -0.92387950420379639, 0.38268342614173889, 0.0, 0},
- {0.35355335474014282, -0.85355335474014282, 0.35355338454246521, 0.14644660055637360, 0},
- {0.85355335474014282, -0.35355335474014282, 0.14644660055637360, 0.35355338454246521, 0},
- {0.49999994039535522, -0.49999994039535522, 0.49999997019767761, 0.49999997019767761, 0},
- {0.27059802412986755, -0.65328145027160645, 0.65328145027160645, 0.27059802412986755, 0},
- {0.65328145027160645, -0.27059802412986755, 0.27059802412986755, 0.65328145027160645, 0},
- {0.27059799432754517, -0.27059799432754517, 0.65328139066696167, 0.65328139066696167, 0},
- {0.38268336653709412, 0.0, 0.0, 0.92387944459915161, 0},
- {0.0, -0.38268336653709412, 0.92387944459915161, 0.0, 0},
- {0.14644658565521240, -0.35355335474014282, 0.85355335474014282, 0.35355335474014282, 0},
- {0.35355335474014282, -0.14644658565521240, 0.35355335474014282, 0.85355335474014282, 0},
- {0.0, 0.0, 0.92387944459915161, 0.38268336653709412, 0},
- {-0.0, 0.0, 0.38268336653709412, 0.92387944459915161, 0},
- {-0.27059802412986755, 0.27059802412986755, 0.65328133106231689, 0.65328133106231689, 0},
- {-0.38268339633941650, 0.0, 0.0, 0.92387938499450684, 0},
- {0.0, 0.38268339633941650, 0.92387938499450684, 0.0, 0},
- {-0.14644658565521240, 0.35355338454246521, 0.85355329513549805, 0.35355332493782043, 0},
- {-0.35355338454246521, 0.14644658565521240, 0.35355332493782043, 0.85355329513549805, 0},
- {-0.49999991059303284, 0.49999991059303284, 0.49999985098838806, 0.49999985098838806, 0},
- {-0.27059799432754517, 0.65328145027160645, 0.65328139066696167, 0.27059799432754517, 0},
- {-0.65328145027160645, 0.27059799432754517, 0.27059799432754517, 0.65328139066696167, 0},
- {-0.65328133106231689, 0.65328133106231689, 0.27059793472290039, 0.27059793472290039, 0},
- {-0.92387932538986206, 0.0, 0.0, 0.38268333673477173, 0},
- {0.0, 0.92387932538986206, 0.38268333673477173, 0.0, 0},
- {-0.35355329513549805, 0.85355329513549805, 0.35355329513549805, 0.14644657075405121, 0},
- {-0.85355329513549805, 0.35355329513549805, 0.14644657075405121, 0.35355329513549805, 0},
- {-0.38268330693244934, 0.92387938499450684, 0.0, 0.0, 0},
- {-0.92387938499450684, 0.38268330693244934, 0.0, 0.0, 0},
- {-COS45, 0.0, 0.0, SIN45, 0},
- {COS45, 0.0, 0.0, SIN45, 0},
- {0.0, 0.0, 0.0, 1.0, 0}
+ { 0.6532815, -0.6532815, 0.2705981, 0.2705981, 0},
+ { 0.9238795, 0.0, 0.0, 0.3826834, 0},
+ { 0.0, -0.9238795, 0.3826834, 0.0, 0},
+ { 0.3535534, -0.8535534, 0.3535534, 0.1464466, 0},
+ { 0.8535534, -0.3535534, 0.1464466, 0.3535534, 0},
+ { 0.4999999, -0.4999999, 0.5, 0.5, 0},
+ { 0.2705980, -0.6532815, 0.6532815, 0.2705980, 0},
+ { 0.6532815, -0.2705980, 0.2705980, 0.6532815, 0},
+ { 0.2705978, -0.2705980, 0.6532814, 0.6532814, 0},
+ { 0.3826834, 0.0, 0.0, 0.9238794, 0},
+ { 0.0, -0.3826834, 0.9238794, 0.0, 0},
+ { 0.1464466, -0.3535534, 0.8535534, 0.3535534, 0},
+ { 0.3535534, -0.1464466, 0.3535534, 0.8535534, 0},
+ { 0.0, 0.0, 0.9238794, 0.3826834, 0},
+ {-0.0, 0.0, 0.3826834, 0.9238794, 0},
+ {-0.2705980, 0.2705980, 0.6532813, 0.6532813, 0},
+ {-0.3826834, 0.0, 0.0, 0.9238794, 0},
+ { 0.0, 0.3826834, 0.9238794, 0.0, 0},
+ {-0.1464466, 0.3535534, 0.8535533, 0.3535533, 0},
+ {-0.3535534, 0.1464466, 0.3535533, 0.8535533, 0},
+ {-0.4999999, 0.4999999, 0.4999999, 0.4999999, 0},
+ {-0.2705980, 0.6532815, 0.6532814, 0.2705980, 0},
+ {-0.6532815, 0.2705980, 0.2705980, 0.6532814, 0},
+ {-0.6532813, 0.6532813, 0.2705979, 0.2705979, 0},
+ {-0.9238793, 0.0, 0.0, 0.3826833, 0},
+ { 0.0, 0.9238793, 0.3826833, 0.0, 0},
+ {-0.3535533, 0.8535533, 0.3535533, 0.1464466, 0},
+ {-0.8535533, 0.3535533, 0.1464466, 0.3535533, 0},
+ {-0.3826833, 0.9238794, 0.0, 0.0, 0},
+ {-0.9238794, 0.3826833, 0.0, 0.0, 0},
+ {-COS45, 0.0, 0.0, SIN45, 0},
+ { COS45, 0.0, 0.0, SIN45, 0},
+ { 0.0, 0.0, 0.0, 1.0, 0}
};
enum {
@@ -725,7 +726,7 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y)
mul_qt_v3(viewquat_inv, zaxis);
- for (i = 0 ; i < 39; i++){
+ for (i = 0 ; i < NUM_SNAP_QUATS; i++){
float view = (int)snapquats[i][4];
float viewquat_inv_test[4];
@@ -921,6 +922,22 @@ static int view3d_camera_active_poll(bContext *C)
return 0;
}
+/* test for unlocked camera view in quad view */
+static int view3d_camera_user_poll(bContext *C)
+{
+ View3D *v3d;
+ ARegion *ar;
+
+ if (ED_view3d_context_user_region(C, &v3d, &ar)) {
+ RegionView3D *rv3d = ar->regiondata;
+ if(rv3d->persp==RV3D_CAMOB) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
static int viewrotate_cancel(bContext *C, wmOperator *op)
{
viewops_data_free(C, op);
@@ -946,8 +963,9 @@ void VIEW3D_OT_rotate(wmOperatorType *ot)
ot->flag= OPTYPE_BLOCKING|OPTYPE_GRAB_POINTER;
}
-// NDOF utility functions
-// (should these functions live in this file?)
+/* NDOF utility functions
+ * (should these functions live in this file?)
+ */
float ndof_to_axis_angle(struct wmNDOFMotionData* ndof, float axis[3])
{
return ndof->dt * normalize_v3_v3(axis, ndof->rvec);
@@ -958,7 +976,7 @@ void ndof_to_quat(struct wmNDOFMotionData* ndof, float q[4])
float axis[3];
float angle;
- angle= ndof_to_axis_angle(ndof, axis);
+ angle = ndof_to_axis_angle(ndof, axis);
axis_angle_to_quat(q, axis, angle);
}
@@ -968,69 +986,67 @@ void ndof_to_quat(struct wmNDOFMotionData* ndof, float q[4])
*/
static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
{
- if (event->type != NDOF_MOTION) {
+ if (event->type != NDOF_MOTION)
return OPERATOR_CANCELLED;
- }
else {
- View3D *v3d= CTX_wm_view3d(C);
+ View3D *v3d = CTX_wm_view3d(C);
RegionView3D* rv3d = CTX_wm_region_view3d(C);
wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata;
ED_view3d_camera_lock_init(v3d, rv3d);
- rv3d->rot_angle = 0.f; // off by default, until changed later this function
+ rv3d->rot_angle = 0.f; /* off by default, until changed later this function */
if (ndof->progress != P_FINISHING) {
const float dt = ndof->dt;
-
- // tune these until everything feels right
+
+ /* tune these until everything feels right */
const float rot_sensitivity = 1.f;
const float zoom_sensitivity = 1.f;
const float pan_sensitivity = 1.f;
-
- // rather have bool, but...
- int has_rotation = rv3d->viewlock != RV3D_LOCKED && !is_zero_v3(ndof->rvec);
-
+
+ const int has_rotation = rv3d->viewlock != RV3D_LOCKED && !is_zero_v3(ndof->rvec);
+
float view_inv[4];
invert_qt_qt(view_inv, rv3d->viewquat);
-
- //#define DEBUG_NDOF_MOTION
+
+ /* #define DEBUG_NDOF_MOTION */
#ifdef DEBUG_NDOF_MOTION
printf("ndof: T=(%.2f,%.2f,%.2f) R=(%.2f,%.2f,%.2f) dt=%.3f delivered to 3D view\n",
ndof->tx, ndof->ty, ndof->tz, ndof->rx, ndof->ry, ndof->rz, ndof->dt);
#endif
-
- if (ndof->tvec[2]) {
- // Zoom!
- // velocity should be proportional to the linear velocity attained by rotational motion of same strength
- // [got that?]
- // proportional to arclength = radius * angle
-
- float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tvec[2];
+
+ if (ndof->tz) {
+ /* Zoom!
+ * velocity should be proportional to the linear velocity attained by rotational motion of same strength
+ * [got that?]
+ * proportional to arclength = radius * angle
+ */
+ float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tz;
if (U.ndof_flag & NDOF_ZOOM_INVERT)
zoom_distance = -zoom_distance;
rv3d->dist += zoom_distance;
}
-
+
if (rv3d->viewlock == RV3D_LOCKED) {
/* rotation not allowed -- explore panning options instead */
- float pan_vec[3] = {ndof->tvec[0], ndof->tvec[1], 0.0f};
+ float pan_vec[3] = {ndof->tx, ndof->ty, 0.0f};
mul_v3_fl(pan_vec, pan_sensitivity * rv3d->dist * dt);
-
+
/* transform motion from view to world coordinates */
invert_qt_qt(view_inv, rv3d->viewquat);
mul_qt_v3(view_inv, pan_vec);
-
+
/* move center of view opposite of hand motion (this is camera mode, not object mode) */
sub_v3_v3(rv3d->ofs, pan_vec);
}
-
+
if (has_rotation) {
-
+
rv3d->view = RV3D_VIEW_USER;
-
+
if (U.flag & USER_TRACKBALL) {
float rot[4];
float axis[3];
@@ -1045,44 +1061,46 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event
if (U.ndof_flag & NDOF_ROTATE_INVERT_AXIS)
axis[1] = -axis[1];
- // transform rotation axis from view to world coordinates
+ /* transform rotation axis from view to world coordinates */
mul_qt_v3(view_inv, axis);
-
- // update the onscreen doo-dad
+
+ /* update the onscreen doo-dad */
rv3d->rot_angle = angle;
copy_v3_v3(rv3d->rot_axis, axis);
-
+
axis_angle_to_quat(rot, axis, angle);
- // apply rotation
+ /* apply rotation */
mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
+
} else {
+
/* turntable view code by John Aughey, adapted for 3D mouse by [mce] */
float angle, rot[4];
float xvec[3] = {1,0,0};
-
+
/* Determine the direction of the x vector (for rotating up and down) */
mul_qt_v3(view_inv, xvec);
-
+
/* Perform the up/down rotation */
- angle = rot_sensitivity * dt * ndof->rvec[0];
+ angle = rot_sensitivity * dt * ndof->rx;
if (U.ndof_flag & NDOF_TILT_INVERT_AXIS)
angle = -angle;
rot[0] = cos(angle);
mul_v3_v3fl(rot+1, xvec, sin(angle));
mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
-
+
/* Perform the orbital rotation */
- angle = rot_sensitivity * dt * ndof->rvec[1];
+ angle = rot_sensitivity * dt * ndof->ry;
if (U.ndof_flag & NDOF_ROTATE_INVERT_AXIS)
angle = -angle;
-
- // update the onscreen doo-dad
+
+ /* update the onscreen doo-dad */
rv3d->rot_angle = angle;
rv3d->rot_axis[0] = 0;
rv3d->rot_axis[1] = 0;
rv3d->rot_axis[2] = 1;
-
+
rot[0] = cos(angle);
rot[1] = rot[2] = 0.0;
rot[3] = sin(angle);
@@ -1119,9 +1137,8 @@ void VIEW3D_OT_ndof_orbit(struct wmOperatorType *ot)
*/
static int ndof_pan_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
{
- if (event->type != NDOF_MOTION) {
+ if (event->type != NDOF_MOTION)
return OPERATOR_CANCELLED;
- }
else {
View3D *v3d= CTX_wm_view3d(C);
RegionView3D* rv3d = CTX_wm_region_view3d(C);
@@ -1129,13 +1146,13 @@ static int ndof_pan_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
ED_view3d_camera_lock_init(v3d, rv3d);
- rv3d->rot_angle = 0.f; // we're panning here! so erase any leftover rotation from other operators
+ rv3d->rot_angle = 0.f; /* we're panning here! so erase any leftover rotation from other operators */
if (ndof->progress != P_FINISHING) {
const float dt = ndof->dt;
float view_inv[4];
-#if 0 // ------------------------------------------- zoom with Z
- // tune these until everything feels right
+#if 0 /* ------------------------------------------- zoom with Z */
+ /* tune these until everything feels right */
const float zoom_sensitivity = 1.f;
const float pan_sensitivity = 1.f;
@@ -1143,18 +1160,18 @@ static int ndof_pan_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
ndof->tx, ndof->ty, 0
};
- // "zoom in" or "translate"? depends on zoom mode in user settings?
+ /* "zoom in" or "translate"? depends on zoom mode in user settings? */
if (ndof->tz) {
float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tz;
rv3d->dist += zoom_distance;
}
-
+
mul_v3_fl(pan_vec, pan_sensitivity * rv3d->dist * dt);
-#else // ------------------------------------------------------- dolly with Z
- float speed = 10.f; // blender units per second
- // ^^ this is ok for default cube scene, but should scale with.. something
+#else /* ------------------------------------------------------- dolly with Z */
+ float speed = 10.f; /* blender units per second */
+ /* ^^ this is ok for default cube scene, but should scale with.. something */
- // tune these until everything feels right
+ /* tune these until everything feels right */
const float forward_sensitivity = 1.f;
const float vertical_sensitivity = 0.4f;
const float lateral_sensitivity = 0.6f;
@@ -2075,8 +2092,8 @@ void VIEW3D_OT_view_all(wmOperatorType *ot)
RNA_def_boolean(ot->srna, "center", 0, "Center", "");
}
-
-static int viewselected_exec(bContext *C, wmOperator *UNUSED(op)) /* like a localview without local!, was centerview() in 2.4x */
+/* like a localview without local!, was centerview() in 2.4x */
+static int viewselected_exec(bContext *C, wmOperator *UNUSED(op))
{
ARegion *ar= CTX_wm_region(C);
View3D *v3d = CTX_wm_view3d(C);
@@ -2257,13 +2274,18 @@ void VIEW3D_OT_view_center_cursor(wmOperatorType *ot)
static int view3d_center_camera_exec(bContext *C, wmOperator *UNUSED(op)) /* was view3d_home() in 2.4x */
{
- ARegion *ar= CTX_wm_region(C);
- RegionView3D *rv3d= CTX_wm_region_view3d(C);
- View3D *v3d= CTX_wm_view3d(C);
Scene *scene= CTX_data_scene(C);
float xfac, yfac;
float size[2];
+ View3D *v3d;
+ ARegion *ar;
+ RegionView3D *rv3d;
+
+ /* no NULL check is needed, poll checks */
+ ED_view3d_context_user_region(C, &v3d, &ar);
+ rv3d = ar->regiondata;
+
rv3d->camdx= rv3d->camdy= 0.0f;
ED_view3d_calc_camera_border_size(scene, ar, v3d, rv3d, size);
@@ -2289,7 +2311,7 @@ void VIEW3D_OT_view_center_camera(wmOperatorType *ot)
/* api callbacks */
ot->exec= view3d_center_camera_exec;
- ot->poll= view3d_camera_active_poll;
+ ot->poll= view3d_camera_user_poll;
/* flags */
ot->flag= 0;
@@ -2430,9 +2452,15 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
/* convert border to 3d coordinates */
- if (( !gluUnProject(cent[0], cent[1], depth_close, mats.modelview, mats.projection, (GLint *)mats.viewport, &p[0], &p[1], &p[2])) ||
- ( !gluUnProject((double)rect.xmin, (double)rect.ymin, depth_close, mats.modelview, mats.projection, (GLint *)mats.viewport, &p_corner[0], &p_corner[1], &p_corner[2])))
+ if ( (!gluUnProject(cent[0], cent[1], depth_close,
+ mats.modelview, mats.projection, (GLint *)mats.viewport,
+ &p[0], &p[1], &p[2])) ||
+ (!gluUnProject((double)rect.xmin, (double)rect.ymin, depth_close,
+ mats.modelview, mats.projection, (GLint *)mats.viewport,
+ &p_corner[0], &p_corner[1], &p_corner[2])))
+ {
return OPERATOR_CANCELLED;
+ }
dvec[0] = p[0]-p_corner[0];
dvec[1] = p[1]-p_corner[1];
@@ -2453,7 +2481,10 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
new_dist = rv3d->dist;
/* convert the drawn rectangle into 3d space */
- if (depth_close!=FLT_MAX && gluUnProject(cent[0], cent[1], depth_close, mats.modelview, mats.projection, (GLint *)mats.viewport, &p[0], &p[1], &p[2])) {
+ if (depth_close != FLT_MAX && gluUnProject(cent[0], cent[1], depth_close,
+ mats.modelview, mats.projection, (GLint *)mats.viewport,
+ &p[0], &p[1], &p[2]))
+ {
new_ofs[0] = -p[0];
new_ofs[1] = -p[1];
new_ofs[2] = -p[2];
@@ -2543,11 +2574,16 @@ static void view3d_set_1_to_1_viewborder(Scene *scene, ARegion *ar, View3D *v3d)
static int view3d_zoom_1_to_1_camera_exec(bContext *C, wmOperator *UNUSED(op))
{
Scene *scene= CTX_data_scene(C);
- ARegion *ar= CTX_wm_region(C);
- view3d_set_1_to_1_viewborder(scene, ar, CTX_wm_view3d(C));
+ View3D *v3d;
+ ARegion *ar;
- WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, CTX_wm_view3d(C));
+ /* no NULL check is needed, poll checks */
+ ED_view3d_context_user_region(C, &v3d, &ar);
+
+ view3d_set_1_to_1_viewborder(scene, ar, v3d);
+
+ WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, v3d);
return OPERATOR_FINISHED;
}
@@ -2561,7 +2597,7 @@ void VIEW3D_OT_zoom_camera_1_to_1(wmOperatorType *ot)
/* api callbacks */
ot->exec= view3d_zoom_1_to_1_camera_exec;
- ot->poll= view3d_camera_active_poll;
+ ot->poll= view3d_camera_user_poll;
/* flags */
ot->flag= 0;
@@ -2582,7 +2618,9 @@ static EnumPropertyItem prop_view_items[] = {
/* would like to make this a generic function - outside of transform */
-static void axis_set_view(bContext *C, View3D *v3d, ARegion *ar, float q1, float q2, float q3, float q4, short view, int perspo, int align_active)
+static void axis_set_view(bContext *C, View3D *v3d, ARegion *ar,
+ float q1, float q2, float q3, float q4,
+ short view, int perspo, int align_active)
{
RegionView3D *rv3d= ar->regiondata; /* no NULL check is needed, poll checks */
float new_quat[4];
@@ -2660,6 +2698,7 @@ static int viewnumpad_exec(bContext *C, wmOperator *op)
static int perspo = RV3D_PERSP;
int viewnum, align_active, nextperspo;
+ /* no NULL check is needed, poll checks */
ED_view3d_context_user_region(C, &v3d, &ar);
rv3d = ar->regiondata;
@@ -2680,27 +2719,33 @@ static int viewnumpad_exec(bContext *C, wmOperator *op)
switch (viewnum) {
case RV3D_VIEW_BOTTOM :
- axis_set_view(C, v3d, ar, 0.0, -1.0, 0.0, 0.0, viewnum, nextperspo, align_active);
+ axis_set_view(C, v3d, ar, 0.0, -1.0, 0.0, 0.0,
+ viewnum, nextperspo, align_active);
break;
case RV3D_VIEW_BACK:
- axis_set_view(C, v3d, ar, 0.0, 0.0, (float)-cos(M_PI/4.0), (float)-cos(M_PI/4.0), viewnum, nextperspo, align_active);
+ axis_set_view(C, v3d, ar, 0.0, 0.0, (float)-cos(M_PI/4.0), (float)-cos(M_PI/4.0),
+ viewnum, nextperspo, align_active);
break;
case RV3D_VIEW_LEFT:
- axis_set_view(C, v3d, ar, 0.5, -0.5, 0.5, 0.5, viewnum, nextperspo, align_active);
+ axis_set_view(C, v3d, ar, 0.5, -0.5, 0.5, 0.5,
+ viewnum, nextperspo, align_active);
break;
case RV3D_VIEW_TOP:
- axis_set_view(C, v3d, ar, 1.0, 0.0, 0.0, 0.0, viewnum, nextperspo, align_active);
+ axis_set_view(C, v3d, ar, 1.0, 0.0, 0.0, 0.0,
+ viewnum, nextperspo, align_active);
break;
case RV3D_VIEW_FRONT:
- axis_set_view(C, v3d, ar, (float)cos(M_PI/4.0), (float)-sin(M_PI/4.0), 0.0, 0.0, viewnum, nextperspo, align_active);
+ axis_set_view(C, v3d, ar, (float)cos(M_PI/4.0), (float)-sin(M_PI/4.0), 0.0, 0.0,
+ viewnum, nextperspo, align_active);
break;
case RV3D_VIEW_RIGHT:
- axis_set_view(C, v3d, ar, 0.5, -0.5, -0.5, -0.5, viewnum, nextperspo, align_active);
+ axis_set_view(C, v3d, ar, 0.5, -0.5, -0.5, -0.5,
+ viewnum, nextperspo, align_active);
break;
case RV3D_VIEW_CAMERA:
@@ -2762,7 +2807,9 @@ static int viewnumpad_exec(bContext *C, wmOperator *op)
else{
/* return to settings of last view */
/* does smooth_view too */
- axis_set_view(C, v3d, ar, rv3d->lviewquat[0], rv3d->lviewquat[1], rv3d->lviewquat[2], rv3d->lviewquat[3], rv3d->lview, rv3d->lpersp, 0);
+ axis_set_view(C, v3d, ar,
+ rv3d->lviewquat[0], rv3d->lviewquat[1], rv3d->lviewquat[2], rv3d->lviewquat[3],
+ rv3d->lview, rv3d->lpersp, 0);
}
}
break;
@@ -3194,6 +3241,7 @@ static int set_3dcursor_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *eve
/* re initialize */
project_int_noclip(ar, fp, mval);
flip= initgrabz(rv3d, fp[0], fp[1], fp[2]);
+ (void)flip;
}
if(mval[0]!=IS_CLIPPED) {
@@ -3358,7 +3406,7 @@ static float view_autodist_depth_margin(ARegion *ar, const int mval[2], int marg
}
/* XXX todo Zooms in on a border drawn by the user */
-int ED_view3d_autodist(Scene *scene, ARegion *ar, View3D *v3d, const int mval[2], float mouse_worldloc[3] ) //, float *autodist )
+int ED_view3d_autodist(Scene *scene, ARegion *ar, View3D *v3d, const int mval[2], float mouse_worldloc[3])
{
bglMats mats; /* ZBuffer depth vars */
float depth_close= FLT_MAX;
@@ -3376,8 +3424,11 @@ int ED_view3d_autodist(Scene *scene, ARegion *ar, View3D *v3d, const int mval[2]
cent[0] = (double)mval[0];
cent[1] = (double)mval[1];
- if (!gluUnProject(cent[0], cent[1], depth_close, mats.modelview, mats.projection, (GLint *)mats.viewport, &p[0], &p[1], &p[2]))
+ if (!gluUnProject(cent[0], cent[1], depth_close,
+ mats.modelview, mats.projection, (GLint *)mats.viewport, &p[0], &p[1], &p[2]))
+ {
return 0;
+ }
mouse_worldloc[0] = (float)p[0];
mouse_worldloc[1] = (float)p[1];
@@ -3401,7 +3452,8 @@ int ED_view3d_autodist_init(Scene *scene, ARegion *ar, View3D *v3d, int mode) //
}
// no 4x4 sampling, run view_autodist_init first
-int ED_view3d_autodist_simple(ARegion *ar, const int mval[2], float mouse_worldloc[3], int margin, float *force_depth) //, float *autodist )
+int ED_view3d_autodist_simple(ARegion *ar, const int mval[2], float mouse_worldloc[3],
+ int margin, float *force_depth) //, float *autodist )
{
bglMats mats; /* ZBuffer depth vars, could cache? */
float depth;
@@ -3420,8 +3472,12 @@ int ED_view3d_autodist_simple(ARegion *ar, const int mval[2], float mouse_worldl
cent[1] = (double)mval[1];
bgl_get_mats(&mats);
- if (!gluUnProject(cent[0], cent[1], depth, mats.modelview, mats.projection, (GLint *)mats.viewport, &p[0], &p[1], &p[2]))
+
+ if (!gluUnProject(cent[0], cent[1], depth,
+ mats.modelview, mats.projection, (GLint *)mats.viewport, &p[0], &p[1], &p[2]))
+ {
return 0;
+ }
mouse_worldloc[0] = (float)p[0];
mouse_worldloc[1] = (float)p[1];
@@ -3456,7 +3512,8 @@ static int depth_segment_cb(int x, int y, void *userData)
}
}
-int ED_view3d_autodist_depth_seg(struct ARegion *ar, const int mval_sta[2], const int mval_end[2], int margin, float *depth)
+int ED_view3d_autodist_depth_seg(struct ARegion *ar, const int mval_sta[2], const int mval_end[2],
+ int margin, float *depth)
{
struct { struct ARegion *ar; int margin; float depth; } data = {NULL};
int p1[2];
diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c
index 981d46774dc..801f2d5c8eb 100644
--- a/source/blender/editors/space_view3d/view3d_fly.c
+++ b/source/blender/editors/space_view3d/view3d_fly.c
@@ -135,7 +135,8 @@ void fly_modal_keymap(wmKeyConfig *keyconf)
WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, KM_ANY, 0, FLY_MODAL_DECELERATE);
WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_PRESS, KM_ANY, 0, FLY_MODAL_PAN_ENABLE);
- WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, KM_ANY, 0, FLY_MODAL_PAN_DISABLE); /* XXX - Bug in the event system, middle mouse release doesnt work */
+ /* XXX - Bug in the event system, middle mouse release doesnt work */
+ WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, KM_ANY, 0, FLY_MODAL_PAN_DISABLE);
/* WASD */
WM_modalkeymap_add_item(keymap, WKEY, KM_PRESS, 0, 0, FLY_MODAL_DIR_FORWARD);
@@ -170,7 +171,8 @@ typedef struct FlyInfo {
short state;
short redraw;
unsigned char use_precision;
- unsigned char use_freelook; /* if the user presses shift they can look about without movinf the direction there looking */
+ unsigned char use_freelook; /* if the user presses shift they can look about
+ * without moving the direction there looking */
int mval[2]; /* latest 2D mouse values */
wmNDOFMotionData* ndof; /* latest 3D mouse values */
@@ -195,7 +197,8 @@ typedef struct FlyInfo {
/* backup values */
float dist_backup; /* backup the views distance since we use a zero dist for fly mode */
float ofs_backup[3]; /* backup the views offset incase the user cancels flying in non camera mode */
- float rot_backup[4]; /* backup the views quat incase the user cancels flying in non camera mode. (quat for view, eul for camera) */
+ float rot_backup[4]; /* backup the views quat incase the user cancels flying in non camera mode.
+ * (quat for view, eul for camera) */
short persp_backup; /* remember if were ortho or not, only used for restoring the view if it was a ortho view */
short is_ortho_cam; /* are we flying an ortho camera in perspective view,
@@ -580,7 +583,8 @@ static void flyEvent(FlyInfo *fly, wmEvent *event)
/* impliment WASD keys */
case FLY_MODAL_DIR_FORWARD:
if (fly->speed < 0.0f) fly->speed= -fly->speed; /* flip speed rather than stopping, game like motion */
- else if (fly->axis==2) fly->speed += fly->grid; /* increse like mousewheel if were already moving in that difection*/
+ else if (fly->axis==2) fly->speed += fly->grid; /* increse like mousewheel if were already
+ * moving in that difection*/
fly->axis= 2;
break;
case FLY_MODAL_DIR_BACKWARD:
@@ -738,8 +742,10 @@ static int flyApply(bContext *C, FlyInfo *fly)
xmargin, ymargin; /* x and y margin are define the safe area where the mouses movement wont rotate the view */
#ifdef NDOF_FLY_DEBUG
- static unsigned int iteration = 1;
- printf("fly timer %d\n", iteration++);
+ {
+ static unsigned int iteration = 1;
+ printf("fly timer %d\n", iteration++);
+ }
#endif
@@ -782,7 +788,11 @@ static int flyApply(bContext *C, FlyInfo *fly)
}
/* Should we redraw? */
- if (fly->speed != 0.0f || moffset[0] || moffset[1] || fly->zlock || fly->xlock || dvec[0] || dvec[1] || dvec[2] ) {
+ if ( (fly->speed != 0.0f) ||
+ moffset[0] || moffset[1] ||
+ fly->zlock || fly->xlock ||
+ dvec[0] || dvec[1] || dvec[2])
+ {
float dvec_tmp[3];
double time_current; /*time how fast it takes for us to redraw, this is so simple scenes dont fly too fast */
float time_redraw;
@@ -792,7 +802,7 @@ static int flyApply(bContext *C, FlyInfo *fly)
#endif
time_current= PIL_check_seconds_timer();
time_redraw= (float)(time_current - fly->time_lastdraw);
- time_redraw_clamped= MIN2(0.05f, time_redraw); /* clamt the redraw time to avoid jitter in roll correction */
+ time_redraw_clamped= MIN2(0.05f, time_redraw); /* clamp redraw time to avoid jitter in roll correction */
fly->time_lastdraw= time_current;
/*fprintf(stderr, "%f\n", time_redraw);*/ /* 0.002 is a small redraw 0.02 is larger */
@@ -818,7 +828,8 @@ static int flyApply(bContext *C, FlyInfo *fly)
mul_v3_fl(dvec_tmp, time_redraw * 200.0f * fly->grid);
}
else {
- float roll; /* similar to the angle between the camera's up and the Z-up, but its very rough so just roll*/
+ float roll; /* similar to the angle between the camera's up and the Z-up,
+ * but its very rough so just roll*/
/* rotate about the X axis- look up/down */
if (moffset[1]) {
@@ -826,7 +837,8 @@ static int flyApply(bContext *C, FlyInfo *fly)
upvec[1]=0;
upvec[2]=0;
mul_m3_v3(mat, upvec);
- axis_angle_to_quat( tmp_quat, upvec, (float)moffset[1] * time_redraw * -FLY_ROTATE_FAC); /* Rotate about the relative up vec */
+ /* Rotate about the relative up vec */
+ axis_angle_to_quat( tmp_quat, upvec, (float)moffset[1] * time_redraw * -FLY_ROTATE_FAC);
mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat);
if (fly->xlock) fly->xlock = 2; /*check for rotation*/
@@ -859,7 +871,8 @@ static int flyApply(bContext *C, FlyInfo *fly)
mul_m3_v3(mat, upvec);
}
- axis_angle_to_quat(tmp_quat, upvec, (float)moffset[0] * time_redraw * FLY_ROTATE_FAC); /* Rotate about the relative up vec */
+ /* Rotate about the relative up vec */
+ axis_angle_to_quat(tmp_quat, upvec, (float)moffset[0] * time_redraw * FLY_ROTATE_FAC);
mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat);
if (fly->xlock) fly->xlock = 2;/*check for rotation*/
@@ -880,7 +893,9 @@ static int flyApply(bContext *C, FlyInfo *fly)
upvec[2]= 1.0f;
mul_m3_v3(mat, upvec);
- axis_angle_to_quat( tmp_quat, upvec, roll*time_redraw_clamped*fly->zlock_momentum * FLY_ZUP_CORRECT_FAC); /* Rotate about the relative up vec */
+ /* Rotate about the relative up vec */
+ axis_angle_to_quat(tmp_quat, upvec,
+ roll * time_redraw_clamped * fly->zlock_momentum * FLY_ZUP_CORRECT_FAC);
mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat);
fly->zlock_momentum += FLY_ZUP_CORRECT_ACCEL;
@@ -906,7 +921,8 @@ static int flyApply(bContext *C, FlyInfo *fly)
mul_m3_v3(mat, upvec);
- axis_angle_to_quat( tmp_quat, upvec, roll*time_redraw_clamped*fly->xlock_momentum*0.1f); /* Rotate about the relative up vec */
+ /* Rotate about the relative up vec */
+ axis_angle_to_quat( tmp_quat, upvec, roll*time_redraw_clamped*fly->xlock_momentum*0.1f);
mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat);
fly->xlock_momentum += 0.05f;
@@ -949,18 +965,6 @@ static int flyApply(bContext *C, FlyInfo *fly)
add_v3_v3(rv3d->ofs, dvec);
- /* todo, dynamic keys */
-#if 0
- if (fly->zlock && fly->xlock)
- ED_area_headerprint(fly->ar, "FlyKeys Speed:(+/- | Wheel), Upright Axis:X on/Z on, Slow:Shift, Direction:WASDRF, Ok:LMB, Pan:MMB, Cancel:RMB");
- else if (fly->zlock)
- ED_area_headerprint(fly->ar, "FlyKeys Speed:(+/- | Wheel), Upright Axis:X off/Z on, Slow:Shift, Direction:WASDRF, Ok:LMB, Pan:MMB, Cancel:RMB");
- else if (fly->xlock)
- ED_area_headerprint(fly->ar, "FlyKeys Speed:(+/- | Wheel), Upright Axis:X on/Z off, Slow:Shift, Direction:WASDRF, Ok:LMB, Pan:MMB, Cancel:RMB");
- else
- ED_area_headerprint(fly->ar, "FlyKeys Speed:(+/- | Wheel), Upright Axis:X off/Z off, Slow:Shift, Direction:WASDRF, Ok:LMB, Pan:MMB, Cancel:RMB");
-#endif
-
if (rv3d->persp==RV3D_CAMOB)
move_camera(C, rv3d, fly, (fly->xlock || fly->zlock || moffset[0] || moffset[1]), fly->speed);
diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c
index 315da0423d1..00bb8d16943 100644
--- a/source/blender/editors/space_view3d/view3d_header.c
+++ b/source/blender/editors/space_view3d/view3d_header.c
@@ -230,7 +230,7 @@ static int view3d_layers_invoke(bContext *C, wmOperator *op, wmEvent *event)
return OPERATOR_PASS_THROUGH;
if(event->shift)
- RNA_boolean_set(op->ptr, "extend", 1);
+ RNA_boolean_set(op->ptr, "extend", TRUE);
if(event->alt) {
int nr= RNA_int_get(op->ptr, "nr") + 10;
diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h
index e7c9a1bd3a0..f6c82b0ba9d 100644
--- a/source/blender/editors/space_view3d/view3d_intern.h
+++ b/source/blender/editors/space_view3d/view3d_intern.h
@@ -164,7 +164,8 @@ void VIEW3D_OT_game_start(struct wmOperatorType *ot);
int ED_view3d_boundbox_clip(RegionView3D *rv3d, float obmat[][4], struct BoundBox *bb);
-void smooth_view(struct bContext *C, struct View3D *v3d, struct ARegion *ar, struct Object *, struct Object *, float *ofs, float *quat, float *dist, float *lens);
+void smooth_view(struct bContext *C, struct View3D *v3d, struct ARegion *ar, struct Object *, struct Object *,
+ float *ofs, float *quat, float *dist, float *lens);
void setwinmatrixview3d(ARegion *ar, View3D *v3d, rctf *rect); /* rect: for picking */
void setviewmatrixview3d(Scene *scene, View3D *v3d, RegionView3D *rv3d);
diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c
index 4594544b4f8..759f3edf20f 100644
--- a/source/blender/editors/space_view3d/view3d_ops.c
+++ b/source/blender/editors/space_view3d/view3d_ops.c
@@ -121,7 +121,7 @@ void view3d_keymap(wmKeyConfig *keyconf)
keymap= WM_keymap_find(keyconf, "3D View", SPACE_VIEW3D, 0);
kmi = WM_keymap_verify_item(keymap, "VIEW3D_OT_manipulator", LEFTMOUSE, KM_PRESS, KM_ANY, 0);
- RNA_boolean_set(kmi->ptr, "release_confirm", 1);
+ RNA_boolean_set(kmi->ptr, "release_confirm", TRUE);
/*
* Doesn't work with KM_SHIFT, have to use KM_ANY and filter in invoke
* */
@@ -160,8 +160,11 @@ void view3d_keymap(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "VIEW3D_OT_zoom_camera_1_to_1", PADENTER, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "VIEW3D_OT_view_center_camera", HOMEKEY, KM_PRESS, 0, 0); /* only with camera view */
- RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", HOMEKEY, KM_PRESS, 0, 0)->ptr, "center", 0); /* only without camera view */
- RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", CKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "center", 1);
+
+ kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "center", FALSE); /* only without camera view */
+ kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", CKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "center", TRUE);
/* numpad view hotkeys*/
RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD0, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_CAMERA);
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index ce93ca56a65..1b153d03e45 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -257,7 +257,9 @@ static int view3d_selectable_data(bContext *C)
if (ob->mode & OB_MODE_SCULPT) {
return 0;
}
- if (ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT) && !paint_facesel_test(ob) && !paint_vertsel_test(ob)) {
+ if ((ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT)) &&
+ !paint_facesel_test(ob) && !paint_vertsel_test(ob))
+ {
return 0;
}
}
diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c
index 6bc1b3acce6..3665b0b13c3 100644
--- a/source/blender/editors/space_view3d/view3d_snap.c
+++ b/source/blender/editors/space_view3d/view3d_snap.c
@@ -505,7 +505,6 @@ static int snap_sel_to_grid(bContext *C, wmOperator *UNUSED(op))
if(pchan->bone->layer & arm->layer) {
if((pchan->bone->flag & BONE_CONNECTED)==0) {
float nLoc[3];
- float inv_restmat[4][4];
/* get nearest grid point to snap to */
copy_v3_v3(nLoc, pchan->pose_mat[3]);
@@ -517,9 +516,8 @@ static int snap_sel_to_grid(bContext *C, wmOperator *UNUSED(op))
/* Back in object space... */
mul_m4_v3(ob->imat, vec);
- /* get location of grid point in *rest* bone-space */
- invert_m4_m4(inv_restmat, pchan->bone->arm_mat);
- mul_m4_v3(inv_restmat, vec);
+ /* Get location of grid point in pose space. */
+ armature_loc_pose_to_bone(pchan, vec, vec);
/* adjust location */
if ((pchan->protectflag & OB_LOCK_LOCX)==0)
@@ -642,12 +640,9 @@ static int snap_sel_to_curs(bContext *C, wmOperator *UNUSED(op))
if(pchan->bone->flag & BONE_SELECTED) {
if(pchan->bone->layer & arm->layer) {
if((pchan->bone->flag & BONE_CONNECTED)==0) {
- float inv_restmat[4][4];
-
- /* get location of cursor in *rest* bone-space */
- invert_m4_m4(inv_restmat, pchan->bone->arm_mat);
- mul_m4_v3(inv_restmat, vec);
-
+ /* Get position in pchan (pose) space. */
+ armature_loc_pose_to_bone(pchan, vec, vec);
+
/* copy new position */
if ((pchan->protectflag & OB_LOCK_LOCX)==0)
pchan->loc[0]= vec[0];
diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c
index 11492ee7804..f57d8a5ec1b 100644
--- a/source/blender/editors/space_view3d/view3d_view.c
+++ b/source/blender/editors/space_view3d/view3d_view.c
@@ -120,7 +120,8 @@ struct SmoothViewStore {
/* will start timer if appropriate */
/* the arguments are the desired situation */
-void smooth_view(bContext *C, View3D *v3d, ARegion *ar, Object *oldcamera, Object *camera, float *ofs, float *quat, float *dist, float *lens)
+void smooth_view(bContext *C, View3D *v3d, ARegion *ar, Object *oldcamera, Object *camera,
+ float *ofs, float *quat, float *dist, float *lens)
{
wmWindowManager *wm= CTX_wm_manager(C);
wmWindow *win= CTX_wm_window(C);
@@ -998,7 +999,8 @@ int ED_view3d_clip_range_get(View3D *v3d, RegionView3D *rv3d, float *clipsta, fl
}
/* also exposed in previewrender.c */
-int ED_view3d_viewplane_get(View3D *v3d, RegionView3D *rv3d, int winx, int winy, rctf *viewplane, float *clipsta, float *clipend)
+int ED_view3d_viewplane_get(View3D *v3d, RegionView3D *rv3d, int winx, int winy,
+ rctf *viewplane, float *clipsta, float *clipend)
{
CameraParams params;
@@ -1023,7 +1025,12 @@ void setwinmatrixview3d(ARegion *ar, View3D *v3d, rctf *rect) /* rect: for pick
orth= ED_view3d_viewplane_get(v3d, rv3d, ar->winx, ar->winy, &viewplane, &clipsta, &clipend);
rv3d->is_persp= !orth;
- // printf("%d %d %f %f %f %f %f %f\n", winx, winy, viewplane.xmin, viewplane.ymin, viewplane.xmax, viewplane.ymax, clipsta, clipend);
+#if 0
+ printf("%s: %d %d %f %f %f %f %f %f\n", __func__, winx, winy,
+ viewplane.xmin, viewplane.ymin, viewplane.xmax, viewplane.ymax,
+ clipsta, clipend);
+#endif
+
x1= viewplane.xmin;
y1= viewplane.ymin;
x2= viewplane.xmax;
diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c
index 44dc909314a..0563cc3adf5 100644
--- a/source/blender/editors/transform/transform_conversions.c
+++ b/source/blender/editors/transform/transform_conversions.c
@@ -515,7 +515,7 @@ static short apply_targetless_ik(Object *ob)
static void add_pose_transdata(TransInfo *t, bPoseChannel *pchan, Object *ob, TransData *td)
{
Bone *bone= pchan->bone;
- float pmat[3][3], omat[3][3], bmat[3][3];
+ float pmat[3][3], omat[3][3];
float cmat[3][3], tmat[3][3];
float vec[3];
@@ -569,39 +569,71 @@ static void add_pose_transdata(TransInfo *t, bPoseChannel *pchan, Object *ob, Tr
copy_qt_qt(td->ext->iquat, pchan->quat);
}
td->ext->rotOrder= pchan->rotmode;
-
+
/* proper way to get parent transform + own transform + constraints transform */
copy_m3_m4(omat, ob->obmat);
+ /* New code, using "generic" pchan_to_pose_mat(). */
+ {
+ float rotscale_mat[4][4], loc_mat[4][4];
+
+ pchan_to_pose_mat(pchan, rotscale_mat, loc_mat);
+ if (t->mode == TFM_TRANSLATION)
+ copy_m3_m4(pmat, loc_mat);
+ else
+ copy_m3_m4(pmat, rotscale_mat);
+
+ if (constraints_list_needinv(t, &pchan->constraints)) {
+ copy_m3_m4(tmat, pchan->constinv);
+ invert_m3_m3(cmat, tmat);
+ mul_serie_m3(td->mtx, pmat, omat, cmat, NULL,NULL,NULL,NULL,NULL);
+ }
+ else
+ mul_serie_m3(td->mtx, pmat, omat, NULL, NULL,NULL,NULL,NULL,NULL);
+ }
+
+ /* XXX Old code. Will remove it later. */
+#if 0
if (ELEM(t->mode, TFM_TRANSLATION, TFM_RESIZE) && (pchan->bone->flag & BONE_NO_LOCAL_LOCATION))
unit_m3(bmat);
else
copy_m3_m3(bmat, pchan->bone->bone_mat);
if (pchan->parent) {
- if(pchan->bone->flag & BONE_HINGE)
+ if(pchan->bone->flag & BONE_HINGE) {
copy_m3_m4(pmat, pchan->parent->bone->arm_mat);
- else
+ if(!(pchan->bone->flag & BONE_NO_SCALE)) {
+ float tsize[3], tsmat[3][3];
+ mat4_to_size(tsize, pchan->parent->pose_mat);
+ size_to_mat3(tsmat, tsize);
+ mul_m3_m3m3(pmat, tsmat, pmat);
+ }
+ }
+ else {
copy_m3_m4(pmat, pchan->parent->pose_mat);
+ if(pchan->bone->flag & BONE_NO_SCALE)
+ normalize_m3(pmat);
+ }
if (constraints_list_needinv(t, &pchan->constraints)) {
copy_m3_m4(tmat, pchan->constinv);
invert_m3_m3(cmat, tmat);
- mul_serie_m3(td->mtx, bmat, pmat, omat, cmat, NULL,NULL,NULL,NULL); // dang mulserie swaps args
+ mul_serie_m3(td->mtx, bmat, pmat, omat, cmat, NULL,NULL,NULL,NULL);
}
else
- mul_serie_m3(td->mtx, bmat, pmat, omat, NULL,NULL,NULL,NULL,NULL); // dang mulserie swaps args
+ mul_serie_m3(td->mtx, bmat, pmat, omat, NULL,NULL,NULL,NULL,NULL);
}
else {
if (constraints_list_needinv(t, &pchan->constraints)) {
copy_m3_m4(tmat, pchan->constinv);
invert_m3_m3(cmat, tmat);
- mul_serie_m3(td->mtx, bmat, omat, cmat, NULL,NULL,NULL,NULL,NULL); // dang mulserie swaps args
+ mul_serie_m3(td->mtx, bmat, omat, cmat, NULL,NULL,NULL,NULL,NULL);
}
else
- mul_m3_m3m3(td->mtx, omat, bmat); // Mat3MulMat3 has swapped args!
+ mul_m3_m3m3(td->mtx, omat, bmat);
}
+# endif
invert_m3_m3(td->smtx, td->mtx);
@@ -2268,6 +2300,18 @@ void flushTransSeq(TransInfo *t)
seq_prev= seq;
}
+
+ if (ELEM(t->mode, TFM_SEQ_SLIDE, TFM_TIME_TRANSLATE)) { /* originally TFM_TIME_EXTEND, transform changes */
+ /* Special annoying case here, need to calc metas with TFM_TIME_EXTEND only */
+ seq= seqbasep->first;
+
+ while(seq) {
+ if (seq->type == SEQ_META && seq->flag & SELECT)
+ calc_sequence(t->scene, seq);
+ seq= seq->next;
+ }
+ }
+
/* need to do the overlap check in a new loop otherwise adjacent strips
* will not be updated and we'll get false positives */
seq_prev= NULL;
@@ -2287,17 +2331,6 @@ void flushTransSeq(TransInfo *t)
}
seq_prev= seq;
}
-
- if (t->mode == TFM_SEQ_SLIDE) { /* originally TFM_TIME_EXTEND, transform changes */
- /* Special annoying case here, need to calc metas with TFM_TIME_EXTEND only */
- seq= seqbasep->first;
-
- while(seq) {
- if (seq->type == SEQ_META && seq->flag & SELECT)
- calc_sequence(t->scene, seq);
- seq= seq->next;
- }
- }
}
/* ********************* UV ****************** */
@@ -5297,7 +5330,15 @@ static void createTransNodeData(bContext *C, TransInfo *t)
/* *** CLIP EDITOR *** */
+enum {
+ transDataTracking_ModeTracks = 0,
+ transDataTracking_ModeCurves = 1,
+} transDataTracking_Mode;
+
typedef struct TransDataTracking {
+ int mode, flag;
+
+ /* tracks transformation from main window */
int area;
float *relative, *loc;
float soffset[2], srelative[2];
@@ -5306,6 +5347,10 @@ typedef struct TransDataTracking {
float (*smarkers)[2];
int markersnr;
MovieTrackingMarker *markers;
+
+ /* marker transformation from curves editor */
+ float *prev_pos, scale;
+ short coord;
} TransDataTracking;
static void markerToTransDataInit(TransData *td, TransData2D *td2d,
@@ -5313,6 +5358,8 @@ static void markerToTransDataInit(TransData *td, TransData2D *td2d,
{
int anchor = area==TRACK_AREA_POINT && off;
+ tdt->mode = transDataTracking_ModeTracks;
+
if(anchor) {
td2d->loc[0] = rel[0]; /* hold original location */
td2d->loc[1] = rel[1];
@@ -5367,8 +5414,7 @@ static void trackToTransData(SpaceClip *sc, TransData *td, TransData2D *td2d,
{
MovieTrackingMarker *marker= BKE_tracking_ensure_marker(track, sc->user.framenr);
- track->transflag= marker->flag;
-
+ tdt->flag= marker->flag;
marker->flag&= ~(MARKER_DISABLED|MARKER_TRACKED);
markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_POINT, track->offset, marker->pos, track->offset);
@@ -5397,7 +5443,7 @@ static void transDataTrackingFree(TransInfo *t)
}
}
-static void createTransTrackingData(bContext *C, TransInfo *t)
+static void createTransTrackingTracksData(bContext *C, TransInfo *t)
{
TransData *td;
TransData2D *td2d;
@@ -5409,11 +5455,6 @@ static void createTransTrackingData(bContext *C, TransInfo *t)
TransDataTracking *tdt;
int framenr = sc->user.framenr;
- if(!clip || !BKE_movieclip_has_frame(clip, &sc->user)) {
- t->total = 0;
- return;
- }
-
/* count */
t->total = 0;
@@ -5422,13 +5463,11 @@ static void createTransTrackingData(bContext *C, TransInfo *t)
if(TRACK_VIEW_SELECTED(sc, track) && (track->flag&TRACK_LOCKED)==0) {
marker= BKE_tracking_get_marker(track, framenr);
- if(marker) {
- t->total++; /* offset */
+ t->total++; /* offset */
- if(track->flag&SELECT) t->total++;
- if(track->pat_flag&SELECT) t->total+= 2;
- if(track->search_flag&SELECT) t->total+= 2;
- }
+ if(track->flag&SELECT) t->total++;
+ if(track->pat_flag&SELECT) t->total+= 2;
+ if(track->search_flag&SELECT) t->total+= 2;
}
track = track->next;
@@ -5478,6 +5517,194 @@ static void createTransTrackingData(bContext *C, TransInfo *t)
}
}
+static void markerToTransCurveDataInit(TransData *td, TransData2D *td2d, TransDataTracking *tdt,
+ MovieTrackingMarker *marker, MovieTrackingMarker *prev_marker,
+ short coord, float size)
+{
+ float frames_delta = (marker->framenr - prev_marker->framenr);
+
+ tdt->flag = marker->flag;
+ marker->flag &= ~MARKER_TRACKED;
+
+ tdt->mode = transDataTracking_ModeCurves;
+ tdt->coord = coord;
+ tdt->scale = 1.0f / size * frames_delta;
+ tdt->prev_pos = prev_marker->pos;
+
+ /* calculate values depending on marker's speed */
+ td2d->loc[0] = marker->framenr;
+ td2d->loc[1] = (marker->pos[coord] - prev_marker->pos[coord]) * size / frames_delta;
+ td2d->loc[2] = 0.0f;
+
+ td2d->loc2d = marker->pos; /* current location */
+
+ td->flag = 0;
+ td->loc = td2d->loc;
+ VECCOPY(td->center, td->loc);
+ VECCOPY(td->iloc, td->loc);
+
+ memset(td->axismtx, 0, sizeof(td->axismtx));
+ td->axismtx[2][2] = 1.0f;
+
+ td->ext= NULL; td->val= NULL;
+
+ td->flag |= TD_SELECTED;
+ td->dist= 0.0;
+
+ unit_m3(td->mtx);
+ unit_m3(td->smtx);
+}
+
+static void createTransTrackingCurvesData(bContext *C, TransInfo *t)
+{
+ TransData *td;
+ TransData2D *td2d;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip(sc);
+ ListBase *tracksbase= BKE_tracking_get_tracks(&clip->tracking);
+ MovieTrackingTrack *track;
+ MovieTrackingMarker *marker, *prev_marker;
+ TransDataTracking *tdt;
+ int i, width, height;
+
+ BKE_movieclip_get_size(clip, &sc->user, &width, &height);
+
+ /* count */
+ t->total = 0;
+
+ track = tracksbase->first;
+ while(track) {
+ if(TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED)==0) {
+ for(i = 1; i < track->markersnr; i++) {
+ marker = &track->markers[i];
+ prev_marker = &track->markers[i-1];
+
+ if((marker->flag & MARKER_DISABLED) || (prev_marker->flag & MARKER_DISABLED))
+ continue;
+
+ if(marker->flag & MARKER_GRAPH_SEL_X)
+ t->total += 1;
+
+ if(marker->flag & MARKER_GRAPH_SEL_Y)
+ t->total += 1;
+ }
+ }
+
+ track = track->next;
+ }
+
+ if(t->total==0)
+ return;
+
+ td = t->data = MEM_callocN(t->total*sizeof(TransData), "TransTracking TransData");
+ td2d = t->data2d = MEM_callocN(t->total*sizeof(TransData2D), "TransTracking TransData2D");
+ tdt = t->customData = MEM_callocN(t->total*sizeof(TransDataTracking), "TransTracking TransDataTracking");
+
+ t->customFree = transDataTrackingFree;
+
+ /* create actual data */
+ track = tracksbase->first;
+ while(track) {
+ if(TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED)==0) {
+ for(i = 1; i < track->markersnr; i++) {
+ marker = &track->markers[i];
+ prev_marker = &track->markers[i-1];
+
+ if((marker->flag & MARKER_DISABLED) || (prev_marker->flag & MARKER_DISABLED))
+ continue;
+
+ if(marker->flag & MARKER_GRAPH_SEL_X) {
+ markerToTransCurveDataInit(td, td2d, tdt, marker, &track->markers[i-1], 0, width);
+ td += 1;
+ td2d += 1;
+ tdt += 1;
+ }
+
+ if(marker->flag & MARKER_GRAPH_SEL_Y) {
+ markerToTransCurveDataInit(td, td2d, tdt, marker, &track->markers[i-1], 1, height);
+
+ td += 1;
+ td2d += 1;
+ tdt += 1;
+ }
+ }
+ }
+
+ track = track->next;
+ }
+}
+
+static void createTransTrackingData(bContext *C, TransInfo *t)
+{
+ ARegion *ar = CTX_wm_region(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip(sc);
+
+ if(!clip || !BKE_movieclip_has_frame(clip, &sc->user)) {
+ t->total = 0;
+ return;
+ }
+
+ if(ar->regiontype == RGN_TYPE_PREVIEW) {
+ /* transformation was called from graph editor */
+ createTransTrackingCurvesData(C, t);
+ }
+ else {
+ createTransTrackingTracksData(C, t);
+ }
+}
+
+static void cancelTransTracking(TransInfo *t)
+{
+ TransDataTracking *tdt = t->customData;
+ SpaceClip *sc= t->sa->spacedata.first;
+ MovieClip *clip= ED_space_clip(sc);
+ ListBase *tracksbase= BKE_tracking_get_tracks(&clip->tracking);
+ MovieTrackingTrack *track;
+ MovieTrackingMarker *marker;
+ int a, framenr = sc->user.framenr;
+
+ if(tdt->mode == transDataTracking_ModeTracks) {
+ track = tracksbase->first;
+ while(track) {
+ if(TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED)==0) {
+ marker = BKE_tracking_get_marker(track, framenr);
+ marker->flag = tdt->flag;
+
+ tdt++;
+
+ if(track->flag&SELECT) tdt++;
+ if(track->pat_flag&SELECT) tdt += 2;
+ if(track->search_flag&SELECT) tdt += 2;
+ }
+
+ track = track->next;
+ }
+ }
+ else if(tdt->mode == transDataTracking_ModeCurves) {
+ MovieTrackingMarker *prev_marker;
+
+ track = tracksbase->first;
+ while(track) {
+ if(TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED)==0) {
+ for(a = 1; a < track->markersnr; a++) {
+ marker = &track->markers[a];
+ prev_marker = &track->markers[a-1];
+
+ if((marker->flag & MARKER_DISABLED) || (prev_marker->flag & MARKER_DISABLED))
+ continue;
+
+ if(marker->flag & (MARKER_GRAPH_SEL_X|MARKER_GRAPH_SEL_Y)) {
+ marker->flag = tdt->flag;
+ }
+ }
+ }
+
+ track = track->next;
+ }
+ }
+}
+
void flushTransTracking(TransInfo *t)
{
TransData *td;
@@ -5485,36 +5712,44 @@ void flushTransTracking(TransInfo *t)
TransDataTracking *tdt;
int a;
+ if(t->state == TRANS_CANCEL)
+ cancelTransTracking(t);
+
/* flush to 2d vector from internally used 3d vector */
for(a=0, td= t->data, td2d= t->data2d, tdt= t->customData; a<t->total; a++, td2d++, td++, tdt++) {
- if(t->flag&T_ALT_TRANSFORM) {
- if(tdt->area==TRACK_AREA_POINT && tdt->relative) {
- float d[2], d2[2];
-
- if(!tdt->smarkers) {
- tdt->smarkers= MEM_callocN(sizeof(*tdt->smarkers)*tdt->markersnr, "flushTransTracking markers");
- for(a= 0; a<tdt->markersnr; a++)
- copy_v2_v2(tdt->smarkers[a], tdt->markers[a].pos);
- }
+ if(tdt->mode == transDataTracking_ModeTracks) {
+ if(t->flag&T_ALT_TRANSFORM) {
+ if(tdt->area==TRACK_AREA_POINT && tdt->relative) {
+ float d[2], d2[2];
+
+ if(!tdt->smarkers) {
+ tdt->smarkers= MEM_callocN(sizeof(*tdt->smarkers)*tdt->markersnr, "flushTransTracking markers");
+ for(a= 0; a<tdt->markersnr; a++)
+ copy_v2_v2(tdt->smarkers[a], tdt->markers[a].pos);
+ }
- sub_v2_v2v2(d, td2d->loc, tdt->soffset);
- sub_v2_v2(d, tdt->srelative);
+ sub_v2_v2v2(d, td2d->loc, tdt->soffset);
+ sub_v2_v2(d, tdt->srelative);
- sub_v2_v2v2(d2, td2d->loc, tdt->srelative);
+ sub_v2_v2v2(d2, td2d->loc, tdt->srelative);
- for(a= 0; a<tdt->markersnr; a++)
- add_v2_v2v2(tdt->markers[a].pos, tdt->smarkers[a], d2);
+ for(a= 0; a<tdt->markersnr; a++)
+ add_v2_v2v2(tdt->markers[a].pos, tdt->smarkers[a], d2);
- negate_v2_v2(td2d->loc2d, d);
+ negate_v2_v2(td2d->loc2d, d);
+ }
}
- }
- if(tdt->area!=TRACK_AREA_POINT || tdt->relative==0) {
- td2d->loc2d[0] = td2d->loc[0];
- td2d->loc2d[1] = td2d->loc[1];
+ if(tdt->area!=TRACK_AREA_POINT || tdt->relative==0) {
+ td2d->loc2d[0] = td2d->loc[0];
+ td2d->loc2d[1] = td2d->loc[1];
- if(tdt->relative)
- sub_v2_v2(td2d->loc2d, tdt->relative);
+ if(tdt->relative)
+ sub_v2_v2(td2d->loc2d, tdt->relative);
+ }
+ }
+ else if(tdt->mode == transDataTracking_ModeCurves) {
+ td2d->loc2d[tdt->coord] = tdt->prev_pos[tdt->coord] + td2d->loc[1] * tdt->scale;
}
}
}
diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c
index fff683b1ef6..3c019c1680f 100644
--- a/source/blender/editors/transform/transform_generics.c
+++ b/source/blender/editors/transform/transform_generics.c
@@ -644,24 +644,11 @@ static void recalcData_clip(TransInfo *t)
ListBase *tracksbase= BKE_tracking_get_tracks(&clip->tracking);
MovieTrackingTrack *track;
- if(t->state == TRANS_CANCEL) {
- track= tracksbase->first;
- while(track) {
- if(TRACK_VIEW_SELECTED(sc, track)) {
- MovieTrackingMarker *marker= BKE_tracking_ensure_marker(track, sc->user.framenr);
-
- marker->flag= track->transflag;
- }
-
- track= track->next;
- }
- }
-
flushTransTracking(t);
track= tracksbase->first;
while(track) {
- if(TRACK_VIEW_SELECTED(sc, track)) {
+ if(TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED)==0) {
if (t->mode == TFM_TRANSLATION) {
if(TRACK_AREA_SELECTED(track, TRACK_AREA_PAT))
BKE_tracking_clamp_track(track, CLAMP_PAT_POS);
diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c
index b7aba109cdd..1843768bcd7 100644
--- a/source/blender/editors/transform/transform_ops.c
+++ b/source/blender/editors/transform/transform_ops.c
@@ -843,7 +843,7 @@ void transform_operatortypes(void)
void transform_keymap_for_space(wmKeyConfig *keyconf, wmKeyMap *keymap, int spaceid)
{
- wmKeyMapItem *km;
+ wmKeyMapItem *kmi;
wmKeyMap *modalmap;
/* transform.c, only adds modal map once, checks if it's there */
@@ -879,71 +879,71 @@ void transform_keymap_for_space(wmKeyConfig *keyconf, wmKeyMap *keymap, int spac
WM_keymap_add_item(keymap, "TRANSFORM_OT_select_orientation", SPACEKEY, KM_PRESS, KM_ALT, 0);
- km = WM_keymap_add_item(keymap, "TRANSFORM_OT_create_orientation", SPACEKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
- RNA_boolean_set(km->ptr, "use", 1);
+ kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_create_orientation", SPACEKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
+ RNA_boolean_set(kmi->ptr, "use", TRUE);
WM_keymap_add_item(keymap, OP_MIRROR, MKEY, KM_PRESS, KM_CTRL, 0);
- km = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(km->ptr, "data_path", "tool_settings.use_snap");
+ kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
WM_keymap_add_item(keymap, "TRANSFORM_OT_snap_type", TABKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
- km = WM_keymap_add_item(keymap, OP_TRANSLATION, TKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_boolean_set(km->ptr, "texture_space", 1);
+ kmi = WM_keymap_add_item(keymap, OP_TRANSLATION, TKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "texture_space", TRUE);
- km = WM_keymap_add_item(keymap, OP_RESIZE, TKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0);
- RNA_boolean_set(km->ptr, "texture_space", 1);
+ kmi = WM_keymap_add_item(keymap, OP_RESIZE, TKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0);
+ RNA_boolean_set(kmi->ptr, "texture_space", TRUE);
break;
case SPACE_ACTION:
- km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
- RNA_enum_set(km->ptr, "mode", TFM_TIME_TRANSLATE);
+ kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "mode", TFM_TIME_TRANSLATE);
- km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
- RNA_enum_set(km->ptr, "mode", TFM_TIME_TRANSLATE);
+ kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
+ RNA_enum_set(kmi->ptr, "mode", TFM_TIME_TRANSLATE);
- km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
- RNA_enum_set(km->ptr, "mode", TFM_TIME_EXTEND);
+ kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
- km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
- RNA_enum_set(km->ptr, "mode", TFM_TIME_SCALE);
+ kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SCALE);
- km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", TKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_enum_set(km->ptr, "mode", TFM_TIME_SLIDE);
+ kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", TKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SLIDE);
break;
case SPACE_IPO:
WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
- km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
- RNA_enum_set(km->ptr, "mode", TFM_TIME_EXTEND);
+ kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
break;
case SPACE_NLA:
- km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
- RNA_enum_set(km->ptr, "mode", TFM_TRANSLATION);
+ kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "mode", TFM_TRANSLATION);
- km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
- RNA_enum_set(km->ptr, "mode", TFM_TRANSLATION);
+ kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
+ RNA_enum_set(kmi->ptr, "mode", TFM_TRANSLATION);
- km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
- RNA_enum_set(km->ptr, "mode", TFM_TIME_EXTEND);
+ kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
- km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
- RNA_enum_set(km->ptr, "mode", TFM_TIME_SCALE);
+ kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SCALE);
break;
case SPACE_NODE:
WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
- km= WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_A, KM_ANY, 0, 0);
- RNA_boolean_set(km->ptr, "release_confirm", 1);
- km= WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
- RNA_boolean_set(km->ptr, "release_confirm", 1);
+ kmi= WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_A, KM_ANY, 0, 0);
+ RNA_boolean_set(kmi->ptr, "release_confirm", TRUE);
+ kmi= WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
+ RNA_boolean_set(kmi->ptr, "release_confirm", TRUE);
WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
@@ -954,8 +954,8 @@ void transform_keymap_for_space(wmKeyConfig *keyconf, wmKeyMap *keymap, int spac
WM_keymap_add_item(keymap, OP_SEQ_SLIDE, EVT_TWEAK_S, KM_ANY, 0, 0);
- km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
- RNA_enum_set(km->ptr, "mode", TFM_TIME_EXTEND);
+ kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
break;
case SPACE_IMAGE:
WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
@@ -970,8 +970,8 @@ void transform_keymap_for_space(wmKeyConfig *keyconf, wmKeyMap *keymap, int spac
WM_keymap_add_item(keymap, "TRANSFORM_OT_mirror", MKEY, KM_PRESS, KM_CTRL, 0);
- km = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(km->ptr, "data_path", "tool_settings.use_snap");
+ kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
break;
case SPACE_CLIP:
WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
diff --git a/source/blender/editors/uvedit/CMakeLists.txt b/source/blender/editors/uvedit/CMakeLists.txt
index ce078c2b1f1..a747c2ac6bd 100644
--- a/source/blender/editors/uvedit/CMakeLists.txt
+++ b/source/blender/editors/uvedit/CMakeLists.txt
@@ -39,6 +39,7 @@ set(SRC
uvedit_draw.c
uvedit_ops.c
uvedit_parametrizer.c
+ uvedit_smart_stitch.c
uvedit_unwrap_ops.c
uvedit_intern.h
diff --git a/source/blender/editors/uvedit/uvedit_draw.c b/source/blender/editors/uvedit/uvedit_draw.c
index 0da3f66fc6f..6ced91f0d01 100644
--- a/source/blender/editors/uvedit/uvedit_draw.c
+++ b/source/blender/editors/uvedit/uvedit_draw.c
@@ -380,12 +380,9 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, EditMesh *em, MTFac
}
}
-static void draw_uvs_other(Scene *scene, Object *obedit, MTFace *activetf)
+static void draw_uvs_other(Scene *scene, Object *obedit, Image *curimage)
{
Base *base;
- Image *curimage;
-
- curimage= (activetf)? activetf->tpage: NULL;
glColor3ub(96, 96, 96);
@@ -419,6 +416,34 @@ static void draw_uvs_other(Scene *scene, Object *obedit, MTFace *activetf)
}
}
+static void draw_uvs_texpaint(SpaceImage *sima, Scene *scene, Object *ob)
+{
+ Mesh *me= ob->data;
+ Image *curimage = ED_space_image(sima);
+
+ if(sima->flag & SI_DRAW_OTHER)
+ draw_uvs_other(scene, ob, curimage);
+
+ glColor3ub(112, 112, 112);
+
+ if(me->mtface) {
+ MFace *mface= me->mface;
+ MTFace *tface= me->mtface;
+ int a;
+
+ for(a=me->totface; a>0; a--, tface++, mface++) {
+ if(tface->tpage == curimage) {
+ glBegin(GL_LINE_LOOP);
+ glVertex2fv(tface->uv[0]);
+ glVertex2fv(tface->uv[1]);
+ glVertex2fv(tface->uv[2]);
+ if(mface->v4) glVertex2fv(tface->uv[3]);
+ glEnd();
+ }
+ }
+ }
+}
+
/* draws uv's in the image space */
static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
{
@@ -432,6 +457,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
float pointsize;
int drawfaces, interpedges;
Image *ima= sima->image;
+ StitchPreviewer *stitch_preview = uv_get_stitch_previewer();
em= BKE_mesh_get_editmesh(me);
activetf= EM_get_active_mtface(em, &efa_act, NULL, 0); /* will be set to NULL if hidden */
@@ -445,8 +471,11 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
interpedges= (ts->uv_selectmode == UV_SELECT_VERTEX);
/* draw other uvs */
- if(sima->flag & SI_DRAW_OTHER)
- draw_uvs_other(scene, obedit, activetf);
+ if(sima->flag & SI_DRAW_OTHER) {
+ Image *curimage= (activetf)? activetf->tpage: NULL;
+
+ draw_uvs_other(scene, obedit, curimage);
+ }
/* 1. draw shadow mesh */
@@ -522,7 +551,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
}
}
-
+
/* 3. draw active face stippled */
if(activetf) {
@@ -831,24 +860,81 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
bglEnd();
}
+ /* finally draw stitch preview */
+ if(stitch_preview) {
+ glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
+ glEnableClientState(GL_VERTEX_ARRAY);
+
+ glEnable(GL_BLEND);
+
+ UI_ThemeColor4(TH_STITCH_PREVIEW_ACTIVE);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ glVertexPointer(2, GL_FLOAT, 0, stitch_preview->static_tris);
+ glDrawArrays(GL_TRIANGLES, 0, stitch_preview->num_static_tris*3);
+
+ glVertexPointer(2, GL_FLOAT, 0, stitch_preview->static_quads);
+ glDrawArrays(GL_QUADS, 0, stitch_preview->num_static_quads*4);
+
+ glVertexPointer(2, GL_FLOAT, 0, stitch_preview->preview_tris);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ UI_ThemeColor4(TH_STITCH_PREVIEW_FACE);
+ glDrawArrays(GL_TRIANGLES, 0, stitch_preview->num_tris*3);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+ UI_ThemeColor4(TH_STITCH_PREVIEW_EDGE);
+ glDrawArrays(GL_TRIANGLES, 0, stitch_preview->num_tris*3);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
+ /*UI_ThemeColor4(TH_STITCH_PREVIEW_VERT);
+ glDrawArrays(GL_TRIANGLES, 0, stitch_preview->num_tris*3);*/
+
+ glVertexPointer(2, GL_FLOAT, 0, stitch_preview->preview_quads);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ UI_ThemeColor4(TH_STITCH_PREVIEW_FACE);
+ glDrawArrays(GL_QUADS, 0, stitch_preview->num_quads*4);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+ UI_ThemeColor4(TH_STITCH_PREVIEW_EDGE);
+ glDrawArrays(GL_QUADS, 0, stitch_preview->num_quads*4);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
+ /*UI_ThemeColor4(TH_STITCH_PREVIEW_VERT);
+ glDrawArrays(GL_QUADS, 0, stitch_preview->num_quads*4);*/
+
+ glDisable(GL_BLEND);
+
+ /* draw vert preview */
+ glPointSize(pointsize*2.0);
+ UI_ThemeColor4(TH_STITCH_PREVIEW_STITCHABLE);
+ glVertexPointer(2, GL_FLOAT, 0, stitch_preview->preview_stitchable);
+ glDrawArrays(GL_POINTS, 0, stitch_preview->num_stitchable);
+
+ UI_ThemeColor4(TH_STITCH_PREVIEW_UNSTITCHABLE);
+ glVertexPointer(2, GL_FLOAT, 0, stitch_preview->preview_unstitchable);
+ glDrawArrays(GL_POINTS, 0, stitch_preview->num_unstitchable);
+
+ glPopClientAttrib();
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ }
+
glPointSize(1.0);
BKE_mesh_end_editmesh(obedit->data, em);
}
-void draw_uvedit_main(SpaceImage *sima, ARegion *ar, Scene *scene, Object *obedit)
+void draw_uvedit_main(SpaceImage *sima, ARegion *ar, Scene *scene, Object *obedit, Object *obact)
{
- int show_uvedit, show_uvshadow;
+ ToolSettings *toolsettings = scene->toolsettings;
+ int show_uvedit, show_uvshadow, show_texpaint_uvshadow;
+ show_texpaint_uvshadow = (obact && obact->type == OB_MESH && obact->mode == OB_MODE_TEXTURE_PAINT);
show_uvedit= ED_space_image_show_uvedit(sima, obedit);
show_uvshadow= ED_space_image_show_uvshadow(sima, obedit);
- if(show_uvedit || show_uvshadow) {
+ if(show_uvedit || show_uvshadow || show_texpaint_uvshadow) {
if(show_uvshadow)
draw_uvs_shadow(obedit);
- else
+ else if(show_uvedit)
draw_uvs(sima, scene, obedit);
+ else
+ draw_uvs_texpaint(sima, scene, obact);
- if(show_uvedit)
+ if(show_uvedit && !(toolsettings->use_uv_sculpt))
drawcursor_sima(sima, ar);
}
}
diff --git a/source/blender/editors/uvedit/uvedit_intern.h b/source/blender/editors/uvedit/uvedit_intern.h
index 7d83f529d92..ef25159a3af 100644
--- a/source/blender/editors/uvedit/uvedit_intern.h
+++ b/source/blender/editors/uvedit/uvedit_intern.h
@@ -32,25 +32,74 @@
#ifndef ED_UVEDIT_INTERN_H
#define ED_UVEDIT_INTERN_H
-struct SpaceImage;
struct EditFace;
-struct MTFace;
-struct Scene;
+struct EditMesh;
struct Image;
+struct MTFace;
struct Object;
+struct Scene;
+struct SpaceImage;
+struct UvElementMap;
struct wmOperatorType;
/* id can be from 0 to 3 */
#define TF_PIN_MASK(id) (TF_PIN1 << id)
#define TF_SEL_MASK(id) (TF_SEL1 << id)
-
/* geometric utilities */
+
void uv_center(float uv[][2], float cent[2], int quad);
float uv_area(float uv[][2], int quad);
void uv_copy_aspect(float uv_orig[][2], float uv[][2], float aspx, float aspy);
+/* find nearest */
+
+typedef struct NearestHit {
+ struct EditFace *efa;
+ struct MTFace *tf;
+
+ int vert, uv;
+ int edge, vert2;
+} NearestHit;
+
+void uv_find_nearest_vert(struct Scene *scene, struct Image *ima, struct EditMesh *em, float co[2], float penalty[2], struct NearestHit *hit);
+void uv_find_nearest_edge(struct Scene *scene, struct Image *ima, struct EditMesh *em, float co[2], struct NearestHit *hit);
+
+/* utility tool functions */
+
+struct UvElement *ED_get_uv_element(struct UvElementMap *map, struct EditFace *efa, int index);
+void uvedit_live_unwrap_update(struct SpaceImage *sima, struct Scene *scene, struct Object *obedit);
+
+/* smart stitch */
+
+/* object that stores display data for previewing before accepting stitching */
+typedef struct StitchPreviewer {
+ /* OpenGL requires different calls for Triangles and Quads.
+ * here we'll store the quads of the mesh */
+ float *preview_quads;
+ /* ...and here we'll store the triangles*/
+ float *preview_tris;
+ /* preview data. These will be either the previewed vertices or edges depending on stitch mode settings */
+ float *preview_stitchable;
+ float *preview_unstitchable;
+ /* here we'll store the number of triangles and quads to be drawn */
+ unsigned int num_tris;
+ unsigned int num_quads;
+ unsigned int num_stitchable;
+ unsigned int num_unstitchable;
+
+ /* store static island Quads */
+ float *static_quads;
+ /* ...and here we'll store the triangles*/
+ float *static_tris;
+ unsigned int num_static_tris;
+ unsigned int num_static_quads;
+} StitchPreviewer;
+
+StitchPreviewer *uv_get_stitch_previewer(void);
+
/* operators */
+
void UV_OT_average_islands_scale(struct wmOperatorType *ot);
void UV_OT_cube_project(struct wmOperatorType *ot);
void UV_OT_cylinder_project(struct wmOperatorType *ot);
@@ -60,6 +109,7 @@ void UV_OT_pack_islands(struct wmOperatorType *ot);
void UV_OT_reset(struct wmOperatorType *ot);
void UV_OT_sphere_project(struct wmOperatorType *ot);
void UV_OT_unwrap(struct wmOperatorType *ot);
+void UV_OT_stitch(struct wmOperatorType *ot);
#endif /* ED_UVEDIT_INTERN_H */
diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c
index 7d56d5c479f..5f836ec4ca7 100644
--- a/source/blender/editors/uvedit/uvedit_ops.c
+++ b/source/blender/editors/uvedit/uvedit_ops.c
@@ -20,7 +20,7 @@
*
* The Original Code is: all of this file.
*
- * Contributor(s): none yet.
+ * Contributor(s): Antony Riakiotakis.
*
* ***** END GPL LICENSE BLOCK *****
*/
@@ -94,6 +94,28 @@ int ED_uvedit_test(Object *obedit)
return ret;
}
+static int ED_operator_uvedit_can_uv_sculpt(struct bContext *C)
+{
+ SpaceImage *sima= CTX_wm_space_image(C);
+ ToolSettings *toolsettings = CTX_data_tool_settings(C);
+ Object *obedit= CTX_data_edit_object(C);
+
+ return ED_space_image_show_uvedit(sima, obedit) && !(toolsettings->use_uv_sculpt);
+}
+
+static int UNUSED_FUNCTION(ED_operator_uvmap_mesh)(bContext *C)
+{
+ Object *ob= CTX_data_active_object(C);
+
+ if(ob && ob->type==OB_MESH) {
+ Mesh *me = ob->data;
+
+ if(CustomData_get_layer(&me->fdata, CD_MTFACE) != NULL)
+ return 1;
+ }
+
+ return 0;
+}
/**************************** object active image *****************************/
static int is_image_texture_node(bNode *node)
@@ -400,7 +422,7 @@ void uvedit_uv_deselect(Scene *scene, EditFace *efa, MTFace *tf, int i)
/*********************** live unwrap utilities ***********************/
-static void uvedit_live_unwrap_update(SpaceImage *sima, Scene *scene, Object *obedit)
+void uvedit_live_unwrap_update(SpaceImage *sima, Scene *scene, Object *obedit)
{
if(sima && (sima->flag & SI_LIVE_UNWRAP)) {
ED_uvedit_live_unwrap_begin(scene, obedit);
@@ -527,15 +549,7 @@ static int uvedit_center(Scene *scene, Image *ima, Object *obedit, float *cent,
/************************** find nearest ****************************/
-typedef struct NearestHit {
- EditFace *efa;
- MTFace *tf;
-
- int vert, uv;
- int edge, vert2;
-} NearestHit;
-
-static void find_nearest_uv_edge(Scene *scene, Image *ima, EditMesh *em, float co[2], NearestHit *hit)
+void uv_find_nearest_edge(Scene *scene, Image *ima, EditMesh *em, float co[2], NearestHit *hit)
{
MTFace *tf;
EditFace *efa;
@@ -633,7 +647,7 @@ static int nearest_uv_between(MTFace *tf, int nverts, int id, float co[2], float
return (c1*c2 >= 0.0f);
}
-static void find_nearest_uv_vert(Scene *scene, Image *ima, EditMesh *em, float co[2], float penalty[2], NearestHit *hit)
+void uv_find_nearest_vert(Scene *scene, Image *ima, EditMesh *em, float co[2], float penalty[2], NearestHit *hit)
{
EditFace *efa;
EditVert *eve;
@@ -750,6 +764,17 @@ static UvMapVert *uv_vertex_map_get(UvVertMap *vmap, EditFace *efa, int a)
return NULL;
}
+UvElement *ED_get_uv_element(UvElementMap *map, EditFace *efa, int index)
+{
+ UvElement *element = map->vert[(*(&efa->v1 + index))->tmp.l];
+
+ for(; element; element = element->next)
+ if(element->face == efa)
+ return element;
+
+ return NULL;
+}
+
static int uv_edge_tag_faces(UvMapVert *first1, UvMapVert *first2, int *totface)
{
UvMapVert *iterv1, *iterv2;
@@ -1296,197 +1321,6 @@ static void UV_OT_weld(wmOperatorType *ot)
ot->poll= ED_operator_uvedit;
}
-/* ******************** stitch operator **************** */
-
-/* just for averaging UVs */
-typedef struct UVVertAverage {
- float uv[2];
- int count;
-} UVVertAverage;
-
-static int stitch_exec(bContext *C, wmOperator *op)
-{
- SpaceImage *sima;
- Scene *scene;
- Object *obedit;
- EditMesh *em;
- EditFace *efa;
- EditVert *eve;
- Image *ima;
- MTFace *tf;
-
- scene= CTX_data_scene(C);
- obedit= CTX_data_edit_object(C);
- em= BKE_mesh_get_editmesh((Mesh*)obedit->data);
- ima= CTX_data_edit_image(C);
- sima= CTX_wm_space_image(C);
-
- if(RNA_boolean_get(op->ptr, "use_limit")) {
- UvVertMap *vmap;
- UvMapVert *vlist, *iterv;
- float newuv[2], limit[2];
- int a, vtot;
-
- limit[0]= RNA_float_get(op->ptr, "limit");
- limit[1]= limit[0];
-
- EM_init_index_arrays(em, 0, 0, 1);
- vmap= EM_make_uv_vert_map(em, 1, 0, limit);
-
- if(vmap == NULL) {
- BKE_mesh_end_editmesh(obedit->data, em);
- return OPERATOR_CANCELLED;
- }
-
- for(a=0, eve= em->verts.first; eve; a++, eve= eve->next) {
- vlist= EM_get_uv_map_vert(vmap, a);
-
- while(vlist) {
- newuv[0]= 0; newuv[1]= 0;
- vtot= 0;
-
- for(iterv=vlist; iterv; iterv=iterv->next) {
- if((iterv != vlist) && iterv->separate)
- break;
-
- efa = EM_get_face_for_index(iterv->f);
- tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
-
- if(uvedit_uv_selected(scene, efa, tf, iterv->tfindex)) {
- newuv[0] += tf->uv[iterv->tfindex][0];
- newuv[1] += tf->uv[iterv->tfindex][1];
- vtot++;
- }
- }
-
- if(vtot > 1) {
- newuv[0] /= vtot; newuv[1] /= vtot;
-
- for(iterv=vlist; iterv; iterv=iterv->next) {
- if((iterv != vlist) && iterv->separate)
- break;
-
- efa = EM_get_face_for_index(iterv->f);
- tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
-
- if(uvedit_uv_selected(scene, efa, tf, iterv->tfindex)) {
- tf->uv[iterv->tfindex][0]= newuv[0];
- tf->uv[iterv->tfindex][1]= newuv[1];
- }
- }
- }
-
- vlist= iterv;
- }
- }
-
- EM_free_uv_vert_map(vmap);
- EM_free_index_arrays();
- }
- else {
- UVVertAverage *uv_average, *uvav;
- int count;
-
- // index and count verts
- for(count=0, eve=em->verts.first; eve; count++, eve= eve->next)
- eve->tmp.l = count;
-
- uv_average= MEM_callocN(sizeof(UVVertAverage)*count, "Stitch");
-
- // gather uv averages per vert
- for(efa= em->faces.first; efa; efa= efa->next) {
- tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
-
- if(uvedit_face_visible(scene, ima, efa, tf)) {
- if(uvedit_uv_selected(scene, efa, tf, 0)) {
- uvav = uv_average + efa->v1->tmp.l;
- uvav->count++;
- uvav->uv[0] += tf->uv[0][0];
- uvav->uv[1] += tf->uv[0][1];
- }
-
- if(uvedit_uv_selected(scene, efa, tf, 1)) {
- uvav = uv_average + efa->v2->tmp.l;
- uvav->count++;
- uvav->uv[0] += tf->uv[1][0];
- uvav->uv[1] += tf->uv[1][1];
- }
-
- if(uvedit_uv_selected(scene, efa, tf, 2)) {
- uvav = uv_average + efa->v3->tmp.l;
- uvav->count++;
- uvav->uv[0] += tf->uv[2][0];
- uvav->uv[1] += tf->uv[2][1];
- }
-
- if(efa->v4 && uvedit_uv_selected(scene, efa, tf, 3)) {
- uvav = uv_average + efa->v4->tmp.l;
- uvav->count++;
- uvav->uv[0] += tf->uv[3][0];
- uvav->uv[1] += tf->uv[3][1];
- }
- }
- }
-
- // apply uv welding
- for(efa= em->faces.first; efa; efa= efa->next) {
- tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
-
- if(uvedit_face_visible(scene, ima, efa, tf)) {
- if(uvedit_uv_selected(scene, efa, tf, 0)) {
- uvav = uv_average + efa->v1->tmp.l;
- tf->uv[0][0] = uvav->uv[0]/uvav->count;
- tf->uv[0][1] = uvav->uv[1]/uvav->count;
- }
-
- if(uvedit_uv_selected(scene, efa, tf, 1)) {
- uvav = uv_average + efa->v2->tmp.l;
- tf->uv[1][0] = uvav->uv[0]/uvav->count;
- tf->uv[1][1] = uvav->uv[1]/uvav->count;
- }
-
- if(uvedit_uv_selected(scene, efa, tf, 2)) {
- uvav = uv_average + efa->v3->tmp.l;
- tf->uv[2][0] = uvav->uv[0]/uvav->count;
- tf->uv[2][1] = uvav->uv[1]/uvav->count;
- }
-
- if(efa->v4 && uvedit_uv_selected(scene, efa, tf, 3)) {
- uvav = uv_average + efa->v4->tmp.l;
- tf->uv[3][0] = uvav->uv[0]/uvav->count;
- tf->uv[3][1] = uvav->uv[1]/uvav->count;
- }
- }
- }
-
- MEM_freeN(uv_average);
- }
-
- uvedit_live_unwrap_update(sima, scene, obedit);
- DAG_id_tag_update(obedit->data, 0);
- WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
-
- BKE_mesh_end_editmesh(obedit->data, em);
- return OPERATOR_FINISHED;
-}
-
-static void UV_OT_stitch(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name= "Stitch";
- ot->description= "Stitch selected UV vertices by proximity";
- ot->idname= "UV_OT_stitch";
- ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-
- /* api callbacks */
- ot->exec= stitch_exec;
- ot->poll= ED_operator_uvedit;
-
- /* properties */
- RNA_def_boolean(ot->srna, "use_limit", 1, "Use Limit", "Stitch UVs within a specified limit distance");
- RNA_def_float(ot->srna, "limit", 0.01f, 0.0f, FLT_MAX, "Limit", "Limit distance in normalized coordinates", -FLT_MAX, FLT_MAX);
-}
-
/* ******************** (de)select all operator **************** */
static void select_all_perform(bContext *C, int action)
@@ -1660,7 +1494,7 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop)
/* find nearest element */
if(loop) {
/* find edge */
- find_nearest_uv_edge(scene, ima, em, co, &hit);
+ uv_find_nearest_edge(scene, ima, em, co, &hit);
if(hit.efa == NULL) {
BKE_mesh_end_editmesh(obedit->data, em);
return OPERATOR_CANCELLED;
@@ -1668,7 +1502,7 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop)
}
else if(selectmode == UV_SELECT_VERTEX) {
/* find vertex */
- find_nearest_uv_vert(scene, ima, em, co, penalty, &hit);
+ uv_find_nearest_vert(scene, ima, em, co, penalty, &hit);
if(hit.efa == NULL) {
BKE_mesh_end_editmesh(obedit->data, em);
return OPERATOR_CANCELLED;
@@ -1683,7 +1517,7 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop)
}
else if(selectmode == UV_SELECT_EDGE) {
/* find edge */
- find_nearest_uv_edge(scene, ima, em, co, &hit);
+ uv_find_nearest_edge(scene, ima, em, co, &hit);
if(hit.efa == NULL) {
BKE_mesh_end_editmesh(obedit->data, em);
return OPERATOR_CANCELLED;
@@ -1723,7 +1557,7 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop)
else hitv[3]= 0xFFFFFFFF;
}
else if(selectmode == UV_SELECT_ISLAND) {
- find_nearest_uv_vert(scene, ima, em, co, NULL, &hit);
+ uv_find_nearest_vert(scene, ima, em, co, NULL, &hit);
if(hit.efa==NULL) {
BKE_mesh_end_editmesh(obedit->data, em);
@@ -2015,7 +1849,7 @@ static int select_linked_internal(bContext *C, wmOperator *op, wmEvent *event, i
RNA_float_get_array(op->ptr, "location", co);
}
- find_nearest_uv_vert(scene, ima, em, co, NULL, &hit);
+ uv_find_nearest_vert(scene, ima, em, co, NULL, &hit);
hit_p= &hit;
}
@@ -3312,6 +3146,180 @@ static void UV_OT_tile_set(wmOperatorType *ot)
RNA_def_int_vector(ot->srna, "tile", 2, NULL, 0, INT_MAX, "Tile", "Tile coordinate", 0, 10);
}
+
+static int seams_from_islands_exec(bContext *C, wmOperator *op)
+{
+ UvVertMap *vmap;
+ Object *ob = CTX_data_edit_object(C);
+ Mesh *me= (Mesh*)ob->data;
+ EditMesh *em;
+ EditEdge *editedge;
+ float limit[2] = {STD_UV_CONNECT_LIMIT, STD_UV_CONNECT_LIMIT};
+ char mark_seams = RNA_boolean_get(op->ptr, "mark_seams");
+ char mark_sharp = RNA_boolean_get(op->ptr, "mark_sharp");
+
+ em = BKE_mesh_get_editmesh(me);
+
+ if(!EM_texFaceCheck(em)) {
+ BKE_mesh_end_editmesh(ob->data, em);
+ return OPERATOR_CANCELLED;
+ }
+
+ /* This code sets editvert->tmp.l to the index. This will be useful later on. */
+ EM_init_index_arrays(em, 0, 0, 1);
+ vmap = EM_make_uv_vert_map(em, 0, 0, limit);
+
+ for(editedge = em->edges.first; editedge; editedge = editedge->next) {
+ /* flags to determine if we uv is separated from first editface match */
+ char separated1 = 0, separated2;
+ /* set to denote edge must be flagged as seam */
+ char faces_separated = 0;
+ /* flag to keep track if uv1 is disconnected from first editface match */
+ char v1coincident = 1;
+ /* For use with v1coincident. v1coincident will change only if we've had commonFaces */
+ int commonFaces = 0;
+
+ EditFace *efa1, *efa2;
+
+ UvMapVert *mv1, *mvinit1, *mv2, *mvinit2, *mviter;
+ /* mv2cache stores the first of the list of coincident uv's for later comparison
+ * mv2sep holds the last separator and is copied to mv2cache when a hit is first found */
+ UvMapVert *mv2cache = NULL, *mv2sep = NULL;
+
+ mvinit1 = vmap->vert[editedge->v1->tmp.l];
+ if(mark_seams)
+ editedge->seam = 0;
+
+ for(mv1 = mvinit1; mv1 && !faces_separated; mv1 = mv1->next) {
+ if(mv1->separate && commonFaces)
+ v1coincident = 0;
+
+ separated2 = 0;
+ efa1 = EM_get_face_for_index(mv1->f);
+ mvinit2 = vmap->vert[editedge->v2->tmp.l];
+
+ for(mv2 = mvinit2; mv2; mv2 = mv2->next) {
+ if(mv2->separate)
+ mv2sep = mv2;
+
+ efa2 = EM_get_face_for_index(mv2->f);
+ if(efa1 == efa2) {
+ /* if v1 is not coincident no point in comparing */
+ if(v1coincident) {
+ /* have we found previously anything? */
+ if(mv2cache) {
+ /* flag seam unless proved to be coincident with previous hit */
+ separated2 = 1;
+ for(mviter = mv2cache; mviter; mviter = mviter->next) {
+ if(mviter->separate && mviter != mv2cache)
+ break;
+ /* coincident with previous hit, do not flag seam */
+ if(mviter == mv2)
+ separated2 = 0;
+ }
+ }
+ /* First hit case, store the hit in the cache */
+ else {
+ mv2cache = mv2sep;
+ commonFaces = 1;
+ }
+ }
+ else
+ separated1 = 1;
+
+ if(separated1 || separated2) {
+ faces_separated = 1;
+ break;
+ }
+ }
+ }
+ }
+
+ if(faces_separated) {
+ if(mark_seams)
+ editedge->seam = 1;
+ if(mark_sharp)
+ editedge->sharp = 1;
+ }
+ }
+
+ me->drawflag |= ME_DRAWSEAMS;
+
+ EM_free_uv_vert_map(vmap);
+ EM_free_index_arrays();
+ BKE_mesh_end_editmesh(me, em);
+
+ DAG_id_tag_update(&me->id, 0);
+ WM_event_add_notifier(C, NC_GEOM|ND_DATA, me);
+
+ return OPERATOR_FINISHED;
+}
+
+
+static void UV_OT_seams_from_islands(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Seams From Islands";
+ ot->description= "Set mesh seams according to island setup in the UV editor";
+ ot->idname= "UV_OT_seams_from_islands";
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ /* api callbacks */
+ ot->exec= seams_from_islands_exec;
+ ot->poll= ED_operator_uvedit;
+
+ RNA_def_boolean(ot->srna, "mark_seams", 1, "Mark Seams", "Mark boundary edges as seams");
+ RNA_def_boolean(ot->srna, "mark_sharp", 0, "Mark Sharp", "Mark boundary edges as sharp");
+}
+
+static int mark_seam_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ Object *ob = CTX_data_edit_object(C);
+ Scene *scene = CTX_data_scene(C);
+ Mesh *me= (Mesh*)ob->data;
+ EditMesh *em= BKE_mesh_get_editmesh(me);
+ EditFace *efa;
+
+ for(efa = em->faces.first; efa; efa = efa->next) {
+ MTFace *mt = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+ int i, nverts = efa->v4? 4 : 3;
+
+ for(i = 0; i < nverts; i++)
+ if(uvedit_edge_selected(scene, efa, mt, i))
+ (*(&efa->e1 + i))->seam = 1;
+ }
+
+ me->drawflag |= ME_DRAWSEAMS;
+
+ if(scene->toolsettings->edge_mode_live_unwrap)
+ ED_unwrap_lscm(scene, ob, FALSE);
+
+ BKE_mesh_end_editmesh(me, em);
+
+ DAG_id_tag_update(&me->id, 0);
+ WM_event_add_notifier(C, NC_GEOM|ND_DATA, me);
+
+ return OPERATOR_FINISHED;
+}
+
+static void UV_OT_mark_seam(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Mark Seams";
+ ot->description= "Mark selected UV edges as seams";
+ ot->idname= "UV_OT_mark_seam";
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ /* api callbacks */
+ ot->exec= mark_seam_exec;
+ ot->poll= ED_operator_uvedit;
+}
+
+
/* ************************** registration **********************************/
void ED_operatortypes_uvedit(void)
@@ -3331,6 +3339,8 @@ void ED_operatortypes_uvedit(void)
WM_operatortype_append(UV_OT_align);
WM_operatortype_append(UV_OT_stitch);
+ WM_operatortype_append(UV_OT_seams_from_islands);
+ WM_operatortype_append(UV_OT_mark_seam);
WM_operatortype_append(UV_OT_weld);
WM_operatortype_append(UV_OT_pin);
@@ -3357,7 +3367,14 @@ void ED_keymap_uvedit(wmKeyConfig *keyconf)
wmKeyMapItem *kmi;
keymap= WM_keymap_find(keyconf, "UV Editor", 0, 0);
- keymap->poll= ED_operator_uvedit;
+ keymap->poll= ED_operator_uvedit_can_uv_sculpt;
+
+ /* Uv sculpt toggle */
+ kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", QKEY, KM_PRESS, 0, 0);
+ RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_uv_sculpt");
+
+ /* Mark edge seam */
+ WM_keymap_add_item(keymap, "UV_OT_mark_seam", EKEY, KM_PRESS, KM_CTRL, 0);
/* pick selection */
RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select", SELECTMOUSE, KM_PRESS, 0, 0)->ptr, "extend", FALSE);
@@ -3366,8 +3383,11 @@ void ED_keymap_uvedit(wmKeyConfig *keyconf)
RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select_loop", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_ALT, 0)->ptr, "extend", TRUE);
/* border/circle selection */
- WM_keymap_add_item(keymap, "UV_OT_select_border", BKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select_border", BKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "pinned", 1);
+ kmi = WM_keymap_add_item(keymap, "UV_OT_select_border", BKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "pinned", FALSE);
+ kmi = WM_keymap_add_item(keymap, "UV_OT_select_border", BKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "pinned", TRUE);
+
WM_keymap_add_item(keymap, "UV_OT_circle_select", CKEY, KM_PRESS, 0, 0);
/* selection manipulation */
@@ -3377,16 +3397,21 @@ void ED_keymap_uvedit(wmKeyConfig *keyconf)
RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select_linked_pick", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", TRUE);
WM_keymap_add_item(keymap, "UV_OT_unlink_selected", LKEY, KM_PRESS, KM_ALT, 0);
- WM_keymap_add_item(keymap, "UV_OT_select_all", AKEY, KM_PRESS, 0, 0);
- RNA_enum_set(WM_keymap_add_item(keymap, "UV_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "action", SEL_INVERT);
+ kmi = WM_keymap_add_item(keymap, "UV_OT_select_all", AKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
+ kmi = WM_keymap_add_item(keymap, "UV_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
+ RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
+
WM_keymap_add_item(keymap, "UV_OT_select_pinned", PKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_menu(keymap, "IMAGE_MT_uvs_weldalign", WKEY, KM_PRESS, 0, 0);
/* uv operations */
WM_keymap_add_item(keymap, "UV_OT_stitch", VKEY, KM_PRESS, 0, 0);
- WM_keymap_add_item(keymap, "UV_OT_pin", PKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_pin", PKEY, KM_PRESS, KM_ALT, 0)->ptr, "clear", 1);
+ kmi = WM_keymap_add_item(keymap, "UV_OT_pin", PKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "clear", FALSE);
+ kmi = WM_keymap_add_item(keymap, "UV_OT_pin", PKEY, KM_PRESS, KM_ALT, 0);
+ RNA_boolean_set(kmi->ptr, "clear", TRUE);
/* unwrap */
WM_keymap_add_item(keymap, "UV_OT_unwrap", EKEY, KM_PRESS, 0, 0);
@@ -3395,8 +3420,11 @@ void ED_keymap_uvedit(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "UV_OT_average_islands_scale", AKEY, KM_PRESS, KM_CTRL, 0);
/* hide */
- WM_keymap_add_item(keymap, "UV_OT_hide", HKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1);
+ kmi = WM_keymap_add_item(keymap, "UV_OT_hide", HKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", FALSE);
+ kmi = WM_keymap_add_item(keymap, "UV_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", TRUE);
+
WM_keymap_add_item(keymap, "UV_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0);
/* cursor */
diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c b/source/blender/editors/uvedit/uvedit_parametrizer.c
index 7ad573231c9..d651a17b624 100644
--- a/source/blender/editors/uvedit/uvedit_parametrizer.c
+++ b/source/blender/editors/uvedit/uvedit_parametrizer.c
@@ -91,7 +91,7 @@ typedef struct PVert {
} u;
struct PEdge *edge;
- float *co;
+ float co[3];
float uv[2];
unsigned char flag;
@@ -655,11 +655,15 @@ static void p_face_backup_uvs(PFace *f)
{
PEdge *e1 = f->edge, *e2 = e1->next, *e3 = e2->next;
- if (e1->orig_uv && e2->orig_uv && e3->orig_uv) {
+ if (e1->orig_uv) {
e1->old_uv[0] = e1->orig_uv[0];
e1->old_uv[1] = e1->orig_uv[1];
+ }
+ if (e2->orig_uv) {
e2->old_uv[0] = e2->orig_uv[0];
e2->old_uv[1] = e2->orig_uv[1];
+ }
+ if (e3->orig_uv) {
e3->old_uv[0] = e3->orig_uv[0];
e3->old_uv[1] = e3->orig_uv[1];
}
@@ -669,11 +673,15 @@ static void p_face_restore_uvs(PFace *f)
{
PEdge *e1 = f->edge, *e2 = e1->next, *e3 = e2->next;
- if (e1->orig_uv && e2->orig_uv && e3->orig_uv) {
+ if (e1->orig_uv) {
e1->orig_uv[0] = e1->old_uv[0];
e1->orig_uv[1] = e1->old_uv[1];
+ }
+ if (e2->orig_uv) {
e2->orig_uv[0] = e2->old_uv[0];
e2->orig_uv[1] = e2->old_uv[1];
+ }
+ if (e3->orig_uv) {
e3->orig_uv[0] = e3->old_uv[0];
e3->orig_uv[1] = e3->old_uv[1];
}
@@ -684,7 +692,7 @@ static void p_face_restore_uvs(PFace *f)
static PVert *p_vert_add(PHandle *handle, PHashKey key, float *co, PEdge *e)
{
PVert *v = (PVert*)BLI_memarena_alloc(handle->arena, sizeof *v);
- v->co = co;
+ copy_v3_v3(v->co, co);
v->u.key = key;
v->edge = e;
v->flag = 0;
@@ -708,7 +716,7 @@ static PVert *p_vert_copy(PChart *chart, PVert *v)
{
PVert *nv = (PVert*)BLI_memarena_alloc(chart->handle->arena, sizeof *nv);
- nv->co = v->co;
+ copy_v3_v3(nv->co, v->co);
nv->uv[0] = v->uv[0];
nv->uv[1] = v->uv[1];
nv->u.key = v->u.key;
diff --git a/source/blender/editors/uvedit/uvedit_smart_stitch.c b/source/blender/editors/uvedit/uvedit_smart_stitch.c
new file mode 100644
index 00000000000..3731d348522
--- /dev/null
+++ b/source/blender/editors/uvedit/uvedit_smart_stitch.c
@@ -0,0 +1,1467 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Antony Riakiotakis.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/uvedit/uvedit_stitch.c
+ * \ingroup eduv
+ */
+
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_object_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_scene_types.h"
+
+#include "BLI_editVert.h"
+#include "BLI_ghash.h"
+#include "BLI_math.h"
+#include "BLI_math_vector.h"
+#include "BLI_string.h"
+
+#include "BKE_context.h"
+#include "BKE_customdata.h"
+#include "BKE_depsgraph.h"
+#include "BKE_mesh.h"
+
+#include "ED_mesh.h"
+#include "ED_uvedit.h"
+#include "ED_screen.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "UI_view2d.h"
+
+#include "uvedit_intern.h"
+
+/* ********************** smart stitch operator *********************** */
+
+
+struct IslandStitchData;
+
+/* This is a straightforward implementation, count the uv's in the island that will move and take the mean displacement/rotation and apply it to all
+ * elements of the island except from the stitchable */
+typedef struct IslandStitchData{
+ /* rotation can be used only for edges, for vertices there is no such notion */
+ float rotation;
+ float translation[2];
+ /* Used for rotation, the island will rotate around this point */
+ float medianPoint[2];
+ int numOfElements;
+ int num_rot_elements;
+ /* flag to remember if island has been added for preview */
+ char addedForPreview;
+ /* flag an island to be considered for determining static island */
+ char stitchableCandidate;
+ /* if edge rotation is used, flag so that vertex rotation is not used */
+ char use_edge_rotation;
+}IslandStitchData;
+
+/* just for averaging UVs */
+typedef struct UVVertAverage {
+ float uv[2];
+ unsigned short count;
+} UVVertAverage;
+
+typedef struct UvEdge {
+ /* index to uv buffer */
+ unsigned int uv1;
+ unsigned int uv2;
+ /* general use flag (Used to check if edge is boundary here, and propagates to adjacency elements) */
+ char flag;
+ /* element that guarantees element->face has the face on element->tfindex and element->tfindex+1 is the second uv */
+ UvElement *element;
+}UvEdge;
+
+
+/* stitch state object */
+typedef struct StitchState {
+ /* use limit flag */
+ char use_limit;
+ /* limit to operator, same as original operator */
+ float limit_dist;
+ /* snap uv islands together during stitching */
+ char snap_islands;
+ /* stich at midpoints or at islands */
+ char midpoints;
+ /* editmesh, cached for use in modal handler */
+ EditMesh *em;
+ /* element map for getting info about uv connectivity */
+ UvElementMap *element_map;
+ /* edge container */
+ UvEdge *uvedges;
+ /* container of first of a group of coincident uvs, these will be operated upon */
+ UvElement **uvs;
+ /* maps uvelements to their first coincident uv */
+ int *map;
+ /* 2D normals per uv to calculate rotation for snapping */
+ float *normals;
+ /* edge storage */
+ UvEdge *edges;
+
+ /* count of separate uvs and edges */
+ int total_boundary_edges;
+ int total_separate_uvs;
+ /* hold selection related information */
+ UvElement **selection_stack;
+ int selection_size;
+ /* island that stays in place */
+ int static_island;
+ /* store number of primitives per face so that we can allocate the active island buffer later */
+ unsigned int *quads_per_island;
+ unsigned int *tris_per_island;
+} StitchState;
+
+
+/*
+ * defines for UvElement flags
+ */
+#define STITCH_SELECTED 1
+#define STITCH_STITCHABLE 2
+#define STITCH_PROCESSED 4
+#define STITCH_BOUNDARY 8
+#define STITCH_STITCHABLE_CANDIDATE 16
+
+#define STITCH_NO_PREVIEW -1
+
+/* previewer stuff (see uvedit_intern.h for more info) */
+static StitchPreviewer *_stitch_preview;
+
+/* constructor */
+static StitchPreviewer * stitch_preview_init(void)
+{
+ _stitch_preview = MEM_mallocN(sizeof(StitchPreviewer), "stitch_previewer");
+ _stitch_preview->preview_quads = NULL;
+ _stitch_preview->preview_tris = NULL;
+ _stitch_preview->preview_stitchable = NULL;
+ _stitch_preview->preview_unstitchable = NULL;
+
+ _stitch_preview->num_quads = 0;
+ _stitch_preview->num_tris = 0;
+ _stitch_preview->num_stitchable = 0;
+ _stitch_preview->num_unstitchable = 0;
+
+ _stitch_preview->static_quads = NULL;
+ _stitch_preview->static_tris = NULL;
+
+ _stitch_preview->num_static_tris = 0;
+ _stitch_preview->num_static_quads = 0;
+
+ return _stitch_preview;
+}
+
+/* destructor...yeah this should be C++ :) */
+static void stitch_preview_delete(void)
+{
+ if(_stitch_preview)
+ {
+ if(_stitch_preview->preview_quads){
+ MEM_freeN(_stitch_preview->preview_quads);
+ _stitch_preview->preview_quads = NULL;
+ }
+ if(_stitch_preview->preview_tris){
+ MEM_freeN(_stitch_preview->preview_tris);
+ _stitch_preview->preview_tris = NULL;
+ }
+ if(_stitch_preview->preview_stitchable){
+ MEM_freeN(_stitch_preview->preview_stitchable);
+ _stitch_preview->preview_stitchable = NULL;
+ }
+ if(_stitch_preview->preview_unstitchable){
+ MEM_freeN(_stitch_preview->preview_unstitchable);
+ _stitch_preview->preview_unstitchable = NULL;
+ }
+ if(_stitch_preview->static_quads){
+ MEM_freeN(_stitch_preview->static_quads);
+ _stitch_preview->static_quads = NULL;
+ }
+ if(_stitch_preview->static_tris){
+ MEM_freeN(_stitch_preview->static_tris);
+ _stitch_preview->static_tris = NULL;
+ }
+ MEM_freeN(_stitch_preview);
+ _stitch_preview = NULL;
+ }
+}
+
+
+/* "getter method" */
+StitchPreviewer *uv_get_stitch_previewer(void)
+{
+ return _stitch_preview;
+}
+
+#define HEADER_LENGTH 256
+
+/* This function updates the header of the UV editor when the stitch tool updates its settings */
+static void stitch_update_header(StitchState *stitch_state, bContext *C)
+{
+ static char str[] = "(S)nap %s, (M)idpoints %s, (L)imit %.2f (Alt Wheel adjust) %s, Switch (I)sland, shift select vertices";
+
+ char msg[HEADER_LENGTH];
+ ScrArea *sa= CTX_wm_area(C);
+
+ if(sa) {
+ BLI_snprintf(msg, HEADER_LENGTH, str,
+ stitch_state->snap_islands? "On" : "Off",
+ stitch_state->midpoints? "On": "Off",
+ stitch_state->limit_dist,
+ stitch_state->use_limit? "On" : "Off");
+
+ ED_area_headerprint(sa, msg);
+ }
+}
+
+static int getNumOfIslandUvs(UvElementMap *elementMap, int island){
+ if(island == elementMap->totalIslands-1){
+ return elementMap->totalUVs - elementMap->islandIndices[island];
+ }else{
+ return elementMap->islandIndices[island+1] - elementMap->islandIndices[island];
+ }
+}
+
+static void stitch_uv_rotate(float rotation, float medianPoint[2], float uv[2]){
+ float uv_rotation_result[2];
+
+ uv[0] -= medianPoint[0];
+ uv[1] -= medianPoint[1];
+
+ uv_rotation_result[0] = cos(rotation)*uv[0] - sin(rotation)*uv[1];
+ uv_rotation_result[1] = sin(rotation)*uv[0] + cos(rotation)*uv[1];
+
+ uv[0] = uv_rotation_result[0] + medianPoint[0];
+ uv[1] = uv_rotation_result[1] + medianPoint[1];
+}
+
+static int stitch_check_uvs_stitchable(UvElement *element, UvElement *element_iter, StitchState *state){
+ float limit;
+ int do_limit;
+
+ if(element_iter == element){
+ return 0;
+ }
+
+ limit = state->limit_dist;
+ do_limit = state->use_limit;
+
+ if(do_limit){
+ MTFace *mtface_orig = CustomData_em_get(&state->em->fdata, element->face->data, CD_MTFACE);
+ MTFace *mtface_iter = CustomData_em_get(&state->em->fdata, element_iter->face->data, CD_MTFACE);
+
+ if(fabs(mtface_orig->uv[element->tfindex][0] - mtface_iter->uv[element_iter->tfindex][0]) < limit
+ && fabs(mtface_orig->uv[element->tfindex][1] - mtface_iter->uv[element_iter->tfindex][1]) < limit){
+ return 1;
+ }else
+ return 0;
+ }else
+ return 1;
+}
+
+
+static int stitch_check_uvs_state_stitchable(UvElement *element, UvElement *element_iter, StitchState *state){
+ if(state->snap_islands && element->island == element_iter->island)
+ return 0;
+
+ return stitch_check_uvs_stitchable(element, element_iter, state);
+}
+
+
+/* calculate snapping for islands */
+static void stitch_calculate_island_snapping(StitchState *state, StitchPreviewer *preview, IslandStitchData *island_stitch_data, int final){
+ int i;
+ EditFace *efa;
+ MTFace *mt;
+ UvElement *element;
+
+ for(i = 0; i < state->element_map->totalIslands; i++){
+ if(island_stitch_data[i].addedForPreview){
+ int numOfIslandUVs = 0, j;
+
+ /* check to avoid divide by 0 */
+ if(island_stitch_data[i].num_rot_elements>0){
+ island_stitch_data[i].rotation /= island_stitch_data[i].num_rot_elements;
+ island_stitch_data[i].medianPoint[0] /= island_stitch_data[i].numOfElements;
+ island_stitch_data[i].medianPoint[1] /= island_stitch_data[i].numOfElements;
+ }
+ island_stitch_data[i].translation[0] /= island_stitch_data[i].numOfElements;
+ island_stitch_data[i].translation[1] /= island_stitch_data[i].numOfElements;
+ numOfIslandUVs = getNumOfIslandUvs(state->element_map, i);
+ element = &state->element_map->buf[state->element_map->islandIndices[i]];
+ for(j = 0; j < numOfIslandUVs; j++, element++){
+ /* stitchable uvs have already been processed, don't process */
+ if(!(element->flag & STITCH_PROCESSED)){
+ efa = element->face;
+ mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+ if(final){
+
+ stitch_uv_rotate(island_stitch_data[i].rotation, island_stitch_data[i].medianPoint, mt->uv[element->tfindex]);
+
+ mt->uv[element->tfindex][0] += island_stitch_data[i].translation[0];
+ mt->uv[element->tfindex][1] += island_stitch_data[i].translation[1];
+ }
+ else if(efa->tmp.l != STITCH_NO_PREVIEW){
+ if(efa->v4){
+
+ stitch_uv_rotate(island_stitch_data[i].rotation, island_stitch_data[i].medianPoint, &preview->preview_quads[efa->tmp.l + 2*element->tfindex]);
+
+ preview->preview_quads[efa->tmp.l + 2*element->tfindex] += island_stitch_data[i].translation[0];
+ preview->preview_quads[efa->tmp.l + 2*element->tfindex + 1] += island_stitch_data[i].translation[1];
+ }
+ else {
+
+ stitch_uv_rotate(island_stitch_data[i].rotation, island_stitch_data[i].medianPoint, &preview->preview_tris[efa->tmp.l + 2*element->tfindex]);
+
+ preview->preview_tris[efa->tmp.l + 2*element->tfindex] += island_stitch_data[i].translation[0];
+ preview->preview_tris[efa->tmp.l + 2*element->tfindex + 1] += island_stitch_data[i].translation[1];
+ }
+ }
+ }
+ /* cleanup */
+ element->flag &= STITCH_SELECTED;
+ }
+ }
+ }
+}
+
+
+
+static void stitch_island_calculate_edge_rotation(UvEdge *edge, StitchState *state, UVVertAverage *uv_average, unsigned int *uvfinal_map, IslandStitchData *island_stitch_data)
+{
+ UvElement *element1, *element2;
+ EditFace *efa1;
+ EditFace *efa2;
+ MTFace *mt1;
+ MTFace *mt2;
+ float uv1[2], uv2[2];
+ float edgecos, edgesin;
+ int index1, index2;
+ float rotation;
+
+ element1 = state->uvs[edge->uv1];
+ element2 = state->uvs[edge->uv2];
+
+ efa1 = element1->face;
+ mt1 = CustomData_em_get(&state->em->fdata, efa1->data, CD_MTFACE);
+ efa2 = element2->face;
+ mt2 = CustomData_em_get(&state->em->fdata, efa2->data, CD_MTFACE);
+
+ index1 = uvfinal_map[element1 - state->element_map->buf];
+ index2 = uvfinal_map[element2 - state->element_map->buf];
+
+ /* the idea here is to take the directions of the edges and find the rotation between final and initial
+ * direction. This, using inner and outer vector products, gives the angle. Directions are differences so... */
+ uv1[0] = mt2->uv[element2->tfindex][0] - mt1->uv[element1->tfindex][0];
+ uv1[1] = mt2->uv[element2->tfindex][1] - mt1->uv[element1->tfindex][1];
+
+ uv2[0] = uv_average[index2].uv[0] - uv_average[index1].uv[0];
+ uv2[1] = uv_average[index2].uv[1] - uv_average[index1].uv[1];
+
+ normalize_v2(uv1);
+ normalize_v2(uv2);
+
+ edgecos = uv1[0]*uv2[0] + uv1[1]*uv2[1];
+ edgesin = uv1[0]*uv2[1] - uv2[0]*uv1[1];
+
+ rotation = (edgesin > 0)? acos(MAX2(-1.0, MIN2(1.0, edgecos))): -acos(MAX2(-1.0, MIN2(1.0, edgecos)));
+
+ island_stitch_data[element1->island].num_rot_elements++;
+ island_stitch_data[element1->island].rotation += rotation;
+}
+
+
+static void stitch_island_calculate_vert_rotation(UvElement *element, StitchState *state, IslandStitchData *island_stitch_data)
+{
+ float edgecos = 1, edgesin = 0;
+ int index;
+ UvElement *element_iter;
+ float rotation = 0;
+
+ if(element->island == state->static_island && !state->midpoints)
+ return;
+
+ index = (*(&element->face->v1 + element->tfindex))->tmp.l;
+
+ element_iter = state->element_map->vert[index];
+
+ for(; element_iter; element_iter = element_iter->next){
+ if(element_iter->separate && stitch_check_uvs_state_stitchable(element, element_iter, state)){
+ int index_tmp1, index_tmp2;
+ float normal[2];
+ /* easily possible*/
+
+ index_tmp1 = element_iter - state->element_map->buf;
+ index_tmp1 = state->map[index_tmp1];
+ index_tmp2 = element - state->element_map->buf;
+ index_tmp2 = state->map[index_tmp2];
+
+ negate_v2_v2(normal, state->normals + index_tmp2*2);
+ edgecos = dot_v2v2(normal, state->normals + index_tmp1*2);
+ edgesin = cross_v2v2(normal, state->normals + index_tmp1*2);
+ rotation += (edgesin > 0)? acos(edgecos): -acos(edgecos);
+ }
+ }
+
+ if(state->midpoints)
+ rotation /= 2.0;
+ island_stitch_data[element->island].num_rot_elements++;
+ island_stitch_data[element->island].rotation += rotation;
+}
+
+
+static void stitch_state_delete(StitchState *stitch_state)
+{
+ if(stitch_state){
+ if(stitch_state->element_map){
+ EM_free_uv_element_map(stitch_state->element_map);
+ }
+ if(stitch_state->uvs){
+ MEM_freeN(stitch_state->uvs);
+ }
+ if(stitch_state->selection_stack){
+ MEM_freeN(stitch_state->selection_stack);
+ }
+ if(stitch_state->quads_per_island){
+ MEM_freeN(stitch_state->quads_per_island);
+ }
+ if(stitch_state->tris_per_island){
+ MEM_freeN(stitch_state->tris_per_island);
+ }
+ if(stitch_state->map){
+ MEM_freeN(stitch_state->map);
+ }
+ if(stitch_state->normals){
+ MEM_freeN(stitch_state->normals);
+ }
+ if(stitch_state->edges){
+ MEM_freeN(stitch_state->edges);
+ }
+ MEM_freeN(stitch_state);
+ }
+}
+
+
+
+/* checks for remote uvs that may be stitched with a certain uv, flags them if stitchable. */
+static void determine_uv_stitchability(UvElement *element, StitchState *state, IslandStitchData *island_stitch_data){
+ int vert_index;
+ UvElement *element_iter;
+
+ vert_index = (*(&element->face->v1 + element->tfindex))->tmp.l;
+ element_iter = state->element_map->vert[vert_index];
+
+ for(; element_iter; element_iter = element_iter->next){
+ if(element_iter->separate){
+ if(element_iter == element){
+ continue;
+ }
+ if(stitch_check_uvs_stitchable(element, element_iter, state)){
+ island_stitch_data[element_iter->island].stitchableCandidate = 1;
+ island_stitch_data[element->island].stitchableCandidate = 1;
+ element->flag |= STITCH_STITCHABLE_CANDIDATE;
+ }
+ }
+ }
+}
+
+
+/* set preview buffer position of UV face in editface->tmp.l */
+static void stitch_set_face_preview_buffer_position(EditFace *efa, StitchPreviewer *preview)
+{
+ if(efa->tmp.l == STITCH_NO_PREVIEW)
+ {
+ if(efa->v4)
+ {
+ efa->tmp.l = preview->num_quads*8;
+ preview->num_quads++;
+ } else {
+ efa->tmp.l = preview->num_tris*6;
+ preview->num_tris++;
+ }
+ }
+}
+
+
+/* setup face preview for all coincident uvs and their faces */
+static void stitch_setup_face_preview_for_uv_group(UvElement *element, StitchState *state, IslandStitchData *island_stitch_data){
+ StitchPreviewer *preview = uv_get_stitch_previewer();
+
+ /* static island does not change so returning immediately */
+ if(state->snap_islands && !state->midpoints && state->static_island == element->island)
+ return;
+
+ if(state->snap_islands){
+ island_stitch_data[element->island].addedForPreview = 1;
+ }
+
+ do{
+ stitch_set_face_preview_buffer_position(element->face, preview);
+ element = element->next;
+ }while(element && !element->separate);
+}
+
+
+/* checks if uvs are indeed stitchable and registers so that they can be shown in preview */
+static void stitch_validate_stichability(UvElement *element, StitchState *state, IslandStitchData *island_stitch_data){
+ UvElement *element_iter;
+ StitchPreviewer *preview;
+
+ preview = uv_get_stitch_previewer();
+ element_iter = state->element_map->vert[(*(&element->face->v1 + element->tfindex))->tmp.l];
+
+ for(; element_iter; element_iter = element_iter->next){
+ if(element_iter->separate){
+ if(element_iter == element)
+ continue;
+ if(stitch_check_uvs_stitchable(element, element_iter, state)){
+ if(((element_iter->island == state->static_island) || (element->island == state->static_island)) &&
+ !((element_iter->island == element->island) && state->snap_islands)){
+ element->flag |= STITCH_STITCHABLE;
+ preview->num_stitchable++;
+ stitch_setup_face_preview_for_uv_group(element, state, island_stitch_data);
+ return;
+ }
+ }
+ }
+ }
+
+ /* this can happen if the uvs to be stitched are not on a stitchable island */
+ if(!(element->flag & STITCH_STITCHABLE)){
+ preview->num_unstitchable++;
+ }
+}
+
+/* main processing function. It calculates preview and final positions. */
+static int stitch_process_data(StitchState *state, Scene *scene, int final)
+{
+ int i;
+ StitchPreviewer *preview = uv_get_stitch_previewer();
+ IslandStitchData *island_stitch_data = NULL;
+ int previous_island = state->static_island;
+ EditFace *efa;
+ EditVert *ev;
+ UVVertAverage *final_position;
+ char stitch_midpoints = state->midpoints;
+ /* used to map uv indices to uvaverage indices for selection */
+ unsigned int *uvfinal_map;
+
+ /* cleanup previous preview */
+ stitch_preview_delete();
+ preview = stitch_preview_init();
+ if(preview == NULL)
+ return 0;
+ /* each face holds its position in the preview buffer in tmp. -1 is uninitialized */
+ for(efa = state->em->faces.first; efa; efa = efa->next){
+ efa->tmp.l = STITCH_NO_PREVIEW;
+ }
+
+ island_stitch_data = MEM_callocN(sizeof(*island_stitch_data)*state->element_map->totalIslands, "stitch_island_data");
+ if(!island_stitch_data){
+ return 0;
+ }
+
+ /* store indices to editVerts. */
+ for(ev = state->em->verts.first, i = 0; ev; ev = ev->next, i++){
+ ev->tmp.l = i;
+ }
+
+ /*****************************************
+ * First determine stitchability of uvs *
+ *****************************************/
+
+ for(i = 0; i < state->selection_size; i++){
+ UvElement *element = state->selection_stack[i];
+ determine_uv_stitchability(element, state, island_stitch_data);
+ }
+
+ /* set static island to one that is added for preview */
+ state->static_island %= state->element_map->totalIslands;
+ while(!(island_stitch_data[state->static_island].stitchableCandidate)){
+ state->static_island++;
+ state->static_island %= state->element_map->totalIslands;
+ /* this is entirely possible if for example limit stitching with no stitchable verts or no selection */
+ if(state->static_island == previous_island)
+ break;
+ }
+
+ for(i = 0; i < state->selection_size; i++){
+ UvElement *element = state->selection_stack[i];
+ if(element->flag & STITCH_STITCHABLE_CANDIDATE){
+ element->flag &= ~STITCH_STITCHABLE_CANDIDATE;
+ stitch_validate_stichability(element, state, island_stitch_data);
+ }else{
+ /* add to preview for unstitchable */
+ preview->num_unstitchable++;
+ }
+ }
+
+ /*****************************************
+ * Setup preview for stitchable islands *
+ *****************************************/
+ if(state->snap_islands){
+ for(i = 0; i < state->element_map->totalIslands; i++){
+ if(island_stitch_data[i].addedForPreview){
+ int numOfIslandUVs = 0, j;
+ UvElement *element;
+ numOfIslandUVs = getNumOfIslandUvs(state->element_map, i);
+ element = &state->element_map->buf[state->element_map->islandIndices[i]];
+ for(j = 0; j < numOfIslandUVs; j++, element++){
+ stitch_set_face_preview_buffer_position(element->face, preview);
+ }
+ }
+ }
+ }
+
+ /*********************************************************************
+ * Setup the preview buffers and fill them with the appropriate data *
+ *********************************************************************/
+ if(!final){
+ unsigned int tricount = 0, quadcount = 0;
+ int stitchBufferIndex = 0, unstitchBufferIndex = 0;
+ /* initialize the preview buffers */
+ preview->preview_quads = (float *)MEM_mallocN(preview->num_quads*sizeof(float)*8, "quad_uv_stitch_prev");
+ preview->preview_tris = (float *)MEM_mallocN(preview->num_tris*sizeof(float)*6, "tri_uv_stitch_prev");
+
+ preview->preview_stitchable = (float *)MEM_mallocN(preview->num_stitchable*sizeof(float)*2, "stitch_preview_stichable_data");
+ preview->preview_unstitchable = (float *)MEM_mallocN(preview->num_unstitchable*sizeof(float)*2, "stitch_preview_unstichable_data");
+
+ preview->static_quads = (float *)MEM_mallocN(state->quads_per_island[state->static_island]*sizeof(float)*8, "static_island_preview_quads");
+ preview->static_tris = (float *)MEM_mallocN(state->tris_per_island[state->static_island]*sizeof(float)*6, "static_island_preview_tris");
+
+ preview->num_static_quads = state->quads_per_island[state->static_island];
+ preview->num_static_tris = state->tris_per_island[state->static_island];
+ /* will cause cancel and freeing of all data structures so OK */
+ if(!preview->preview_quads || !preview->preview_tris || !preview->preview_stitchable || !preview->preview_unstitchable){
+ return 0;
+ }
+
+ /* copy data from MTFaces to the preview display buffers */
+ for(efa = state->em->faces.first; efa; efa = efa->next){
+ MTFace *mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+ UvElement *element = ED_get_uv_element(state->element_map, efa, 0);
+
+ if(element){
+ if(efa->tmp.l != STITCH_NO_PREVIEW){
+ if(efa->v4) {
+ memcpy(preview->preview_quads+efa->tmp.l, &mt->uv[0][0], 8*sizeof(float));
+ } else {
+ memcpy(preview->preview_tris+efa->tmp.l, &mt->uv[0][0], 6*sizeof(float));
+ }
+ }
+
+ if(element->island == state->static_island){
+ if(efa->v4) {
+ memcpy(preview->static_quads + quadcount*8, &mt->uv[0][0], 8*sizeof(float));
+ quadcount++;
+ } else {
+ memcpy(preview->static_tris + tricount*6, &mt->uv[0][0], 6*sizeof(float));
+ tricount++;
+ }
+ }
+ }
+ }
+
+ /* fill the appropriate preview buffers */
+ for(i = 0; i < state->total_separate_uvs; i++){
+ UvElement *element = (UvElement *)state->uvs[i];
+ if(element->flag & STITCH_STITCHABLE){
+ MTFace *mt;
+ efa = element->face;
+ mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+
+ preview->preview_stitchable[stitchBufferIndex*2] = mt->uv[element->tfindex][0];
+ preview->preview_stitchable[stitchBufferIndex*2 + 1] = mt->uv[element->tfindex][1];
+ stitchBufferIndex++;
+ }
+ else if(element->flag & STITCH_SELECTED){
+ MTFace *mt;
+ efa = element->face;
+ mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+
+ preview->preview_unstitchable[unstitchBufferIndex*2] = mt->uv[element->tfindex][0];
+ preview->preview_unstitchable[unstitchBufferIndex*2 + 1] = mt->uv[element->tfindex][1];
+ unstitchBufferIndex++;
+ }
+ }
+ }
+
+ /******************************************************
+ * Here we calculate the final coordinates of the uvs *
+ ******************************************************/
+
+ final_position = MEM_callocN(state->selection_size*sizeof(*final_position), "stitch_uv_average");
+ uvfinal_map = MEM_mallocN(state->element_map->totalUVs*sizeof(*uvfinal_map), "stitch_uv_final_map");
+
+ /* first pass, calculate final position for stitchable uvs of the static island */
+ for(i = 0; i < state->selection_size; i++){
+ UvElement *element = state->selection_stack[i];
+ if(element->flag & STITCH_STITCHABLE){
+ MTFace *mt;
+
+ UvElement *element_iter;
+
+ uvfinal_map[element - state->element_map->buf] = i;
+
+ efa = element->face;
+ mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+
+ final_position[i].uv[0] = mt->uv[element->tfindex][0];
+ final_position[i].uv[1] = mt->uv[element->tfindex][1];
+ final_position[i].count = 1;
+
+ if(state->snap_islands && element->island == state->static_island && !stitch_midpoints)
+ continue;
+
+ element_iter = state->element_map->vert[(*(&element->face->v1 + element->tfindex))->tmp.l];
+
+ for(;element_iter; element_iter = element_iter->next){
+ if(element_iter->separate){
+ if(stitch_check_uvs_state_stitchable(element, element_iter, state)){
+ efa = element_iter->face;
+ mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+ if(stitch_midpoints){
+ final_position[i].uv[0] += mt->uv[element_iter->tfindex][0];
+ final_position[i].uv[1] += mt->uv[element_iter->tfindex][1];
+ final_position[i].count++;
+ }else if(element_iter->island == state->static_island){
+ /* if multiple uvs on the static island exist,
+ * last checked remains. to disambiguate we need to limit or use
+ * edge stitch */
+ final_position[i].uv[0] = mt->uv[element_iter->tfindex][0];
+ final_position[i].uv[1] = mt->uv[element_iter->tfindex][1];
+ }
+ }
+ }
+ }
+ }
+ if(stitch_midpoints){
+ final_position[i].uv[0] /= final_position[i].count;
+ final_position[i].uv[1] /= final_position[i].count;
+ }
+ }
+
+ /* second pass, calculate island rotation and translation before modifying any uvs */
+ if(state->snap_islands){
+ for(i = 0; i < state->selection_size; i++){
+ UvElement *element = state->selection_stack[i];
+ if(element->flag & STITCH_STITCHABLE){
+ MTFace *mt;
+ efa = element->face;
+ mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+
+ /* accumulate each islands' translation from stitchable elements. it is important to do here
+ * because in final pass MTFaces get modified and result is zero. */
+ island_stitch_data[element->island].translation[0] += final_position[i].uv[0] - mt->uv[element->tfindex][0];
+ island_stitch_data[element->island].translation[1] += final_position[i].uv[1] - mt->uv[element->tfindex][1];
+ island_stitch_data[element->island].medianPoint[0] += mt->uv[element->tfindex][0];
+ island_stitch_data[element->island].medianPoint[1] += mt->uv[element->tfindex][1];
+ island_stitch_data[element->island].numOfElements++;
+ }
+ }
+
+ /* only calculate rotation when an edge has been fully selected */
+ for(i = 0; i < state->total_boundary_edges; i++){
+ UvEdge *edge = state->edges+i;
+ if((state->uvs[edge->uv1]->flag & STITCH_STITCHABLE) && (state->uvs[edge->uv2]->flag & STITCH_STITCHABLE)){
+ stitch_island_calculate_edge_rotation(edge, state, final_position, uvfinal_map, island_stitch_data);
+ island_stitch_data[state->uvs[edge->uv1]->island].use_edge_rotation = 1;
+ }
+ }
+
+ for(i = 0; i < state->selection_size; i++){
+ UvElement *element = state->selection_stack[i];
+ if(!island_stitch_data[element->island].use_edge_rotation){
+ if(element->flag & STITCH_STITCHABLE){
+ stitch_island_calculate_vert_rotation(element, state, island_stitch_data);
+ }
+ }
+ }
+
+ }
+
+ /* third pass, propagate changes to coincident uvs */
+ for(i = 0; i < state->selection_size; i++){
+ UvElement *element = state->selection_stack[i];
+ if(element->flag & STITCH_STITCHABLE){
+ UvElement *element_iter = element;
+ /* propagate to coincident uvs */
+ do{
+ MTFace *mt;
+
+ efa = element_iter->face;
+ mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+
+ element_iter->flag |= STITCH_PROCESSED;
+ /* either flush to preview or to the MTFace, if final */
+ if(final){
+ mt->uv[element_iter->tfindex][0] = final_position[i].uv[0];
+ mt->uv[element_iter->tfindex][1] = final_position[i].uv[1];
+
+ uvedit_uv_select(scene, efa, mt, element_iter->tfindex);
+ }else if(efa->tmp.l != STITCH_NO_PREVIEW){
+ if(efa->v4){
+ *(preview->preview_quads+efa->tmp.l + element_iter->tfindex*2) = final_position[i].uv[0];
+ *(preview->preview_quads+efa->tmp.l + element_iter->tfindex*2 + 1) = final_position[i].uv[1];
+ }else{
+ *(preview->preview_tris+efa->tmp.l + element_iter->tfindex*2) = final_position[i].uv[0];
+ *(preview->preview_tris+efa->tmp.l + element_iter->tfindex*2 + 1) = final_position[i].uv[1];
+ }
+ }
+
+ /* end of calculations, keep only the selection flag */
+ if( (!state->snap_islands) || ((!stitch_midpoints) && (element_iter->island == state->static_island))) {
+ element_iter->flag &= STITCH_SELECTED;
+ }
+
+ element_iter = element_iter->next;
+ }while(element_iter && !element_iter->separate);
+ }
+ }
+
+ /* final pass, calculate Island translation/rotation if needed */
+ if(state->snap_islands){
+ stitch_calculate_island_snapping(state, preview, island_stitch_data, final);
+ }
+
+ MEM_freeN(final_position);
+ MEM_freeN(uvfinal_map);
+ MEM_freeN(island_stitch_data);
+
+ return 1;
+}
+
+/* Stitch hash initialisation functions */
+static unsigned int uv_edge_hash(const void *key){
+ UvEdge *edge = (UvEdge *)key;
+ return
+ BLI_ghashutil_inthash(SET_INT_IN_POINTER(edge->uv2)) +
+ BLI_ghashutil_inthash(SET_INT_IN_POINTER(edge->uv1));
+}
+
+static int uv_edge_compare(const void *a, const void *b){
+ UvEdge *edge1 = (UvEdge *)a;
+ UvEdge *edge2 = (UvEdge *)b;
+
+ if((edge1->uv1 == edge2->uv1) && (edge1->uv2 == edge2->uv2)){
+ return 0;
+ }
+ return 1;
+}
+
+
+/* Select all common uvs */
+static void stitch_select_uv(UvElement *element, StitchState *stitch_state, int always_select)
+{
+ /* This works due to setting of tmp in find nearest uv vert */
+ UvElement *element_iter;
+ UvElement **selection_stack = stitch_state->selection_stack;
+
+ element_iter = stitch_state->element_map->vert[(*(&element->face->v1 + element->tfindex))->tmp.l];
+ /* first deselect all common uvs */
+ for(; element_iter; element_iter = element_iter->next){
+ if(element_iter->separate){
+ /* only separators go to selection */
+ if(element_iter->flag & STITCH_SELECTED){
+ int i;
+ if(always_select)
+ continue;
+
+ element_iter->flag &= ~STITCH_SELECTED;
+ for(i = 0; i < stitch_state->selection_size; i++){
+ if(selection_stack[i] == element_iter){
+ (stitch_state->selection_size)--;
+ selection_stack[i] = selection_stack[stitch_state->selection_size];
+ break;
+ }
+ }
+ }else{
+ element_iter->flag |= STITCH_SELECTED;
+ selection_stack[(stitch_state->selection_size)++] = element_iter;
+ }
+ }
+ }
+}
+
+static void stitch_calculate_edge_normal(EditMesh *em, UvEdge *edge, float *normal)
+{
+ UvElement *element = edge->element;
+ EditFace *efa = element->face;
+ MTFace *mt = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+ int nverts = efa->v4?4 : 3;
+ int index = (element->tfindex + 2)%nverts;
+ float tangent[2], internal[2];
+
+ sub_v2_v2v2(tangent, mt->uv[(element->tfindex + 1)%nverts], mt->uv[element->tfindex]);
+ sub_v2_v2v2(internal, mt->uv[index], mt->uv[element->tfindex]);
+
+ /* choose one of the normals */
+ normal[0] = tangent[1];
+ normal[1] = -tangent[0];
+
+ /* if normal points inside the face, invert */
+ if(dot_v2v2(normal, internal) > 0){
+ normal[0] = -tangent[1];
+ normal[1] = tangent[0];
+ }
+
+ normalize_v2(normal);
+}
+
+static int stitch_init(bContext *C, wmOperator *op)
+{
+ /* for fast edge lookup... */
+ GHash *edgeHash;
+ /* ...and actual edge storage */
+ UvEdge *edges;
+ int total_edges;
+ /* maps uvelements to their first coincident uv */
+ int *map;
+ int counter = 0, i;
+ EditFace *efa;
+ EditMesh *em;
+ GHashIterator* ghi;
+ UvEdge *all_edges;
+ StitchState *state = MEM_mallocN(sizeof(StitchState), "stitch state");
+ Scene *scene = CTX_data_scene(C);
+ ToolSettings *ts = scene->toolsettings;
+
+ Object *obedit = CTX_data_edit_object(C);
+
+ op->customdata = state;
+
+ if(!state)
+ return 0;
+
+ /* initialize state */
+ state->use_limit = RNA_boolean_get(op->ptr, "use_limit");
+ state->limit_dist = RNA_float_get(op->ptr, "limit");
+ state->em = em = BKE_mesh_get_editmesh((Mesh*)obedit->data);
+ state->snap_islands = RNA_boolean_get(op->ptr, "snap_islands");
+ state->static_island = RNA_int_get(op->ptr, "static_island");
+ state->midpoints = RNA_boolean_get(op->ptr, "midpoint_snap");
+ /* in uv synch selection, all uv's are visible */
+ if(ts->uv_flag & UV_SYNC_SELECTION){
+ state->element_map = EM_make_uv_element_map(state->em, 0, 1);
+ }else{
+ state->element_map = EM_make_uv_element_map(state->em, 1, 1);
+ }
+ if(!state->element_map){
+ stitch_state_delete(state);
+ return 0;
+ }
+
+ /* Entirely possible if redoing last operator that static island is bigger than total number of islands.
+ * This ensures we get no hang in the island checking code in stitch_process_data. */
+ state->static_island %= state->element_map->totalIslands;
+
+ /* Count 'unique' uvs */
+ for(i = 0; i < state->element_map->totalUVs; i++){
+ if(state->element_map->buf[i].separate){
+ counter++;
+ }
+ }
+
+ /* Allocate the unique uv buffers */
+ state->uvs = MEM_mallocN(sizeof(*state->uvs)*counter, "uv_stitch_unique_uvs");
+ /* internal uvs need no normals but it is hard and slow to keep a map of
+ * normals only for boundary uvs, so allocating for all uvs */
+ state->normals = MEM_callocN(sizeof(*state->normals)*counter*2, "uv_stitch_normals");
+ state->total_separate_uvs = counter;
+ /* we can at most have totalUVs edges or uvs selected. Actually they are less, considering we store only
+ * unique uvs for processing but I am accounting for all bizarre cases, especially for edges, this way */
+ state->selection_stack = MEM_mallocN(sizeof(*state->selection_stack)*counter, "uv_stitch_selection_stack");
+ state->map = map = MEM_mallocN(sizeof(*map)*state->element_map->totalUVs, "uv_stitch_unique_map");
+ /* Allocate the edge stack */
+ edgeHash = BLI_ghash_new(uv_edge_hash, uv_edge_compare, "stitch_edge_hash");
+ all_edges = MEM_mallocN(sizeof(*all_edges)*state->element_map->totalUVs, "stitch_all_edges");
+
+ if(!state->selection_stack || !state->uvs || !map || !edgeHash || !all_edges){
+ stitch_state_delete(state);
+ return 0;
+ }
+
+ /* So that we can use this as index for the UvElements */
+ counter = -1;
+ /* initialize the unique UVs and map */
+ for(i = 0; i < state->em->totvert; i++){
+ UvElement *element = state->element_map->vert[i];
+ for(; element; element = element->next){
+ if(element->separate){
+ counter++;
+ state->uvs[counter] = element;
+ }
+ /* pointer arithmetic to the rescue, as always :)*/
+ map[element - state->element_map->buf] = counter;
+ }
+ }
+
+ /* Now, on to generate our uv connectivity data */
+ for(efa = state->em->faces.first, counter = 0; efa; efa = efa->next){
+ if((ts->uv_flag & UV_SYNC_SELECTION) || (!efa->h && efa->f & SELECT)){
+ int nverts = efa->v4 ? 4 : 3;
+
+ for(i = 0; i < nverts; i++){
+ UvElement *element = ED_get_uv_element(state->element_map, efa, i);
+ int offset1, itmp1 = element - state->element_map->buf;
+ int offset2, itmp2 = ED_get_uv_element(state->element_map, efa, (i+1)%nverts) - state->element_map->buf;
+
+ offset1 = map[itmp1];
+ offset2 = map[itmp2];
+
+ all_edges[counter].flag = 0;
+ all_edges[counter].element = element;
+ /* using an order policy, sort uvs according to address space. This avoids
+ * Having two different UvEdges with the same uvs on different positions */
+ if(offset1 < offset2){
+ all_edges[counter].uv1 = offset1;
+ all_edges[counter].uv2 = offset2;
+ }
+ else{
+ all_edges[counter].uv1 = offset2;
+ all_edges[counter].uv2 = offset1;
+ }
+
+ if(BLI_ghash_haskey(edgeHash, &all_edges[counter])){
+ char *flag = BLI_ghash_lookup(edgeHash, &all_edges[counter]);
+ *flag = 0;
+ }
+ else{
+ BLI_ghash_insert(edgeHash, &all_edges[counter], &(all_edges[counter].flag));
+ all_edges[counter].flag = STITCH_BOUNDARY;
+ }
+ counter++;
+ }
+ }
+ }
+
+
+ ghi = BLI_ghashIterator_new(edgeHash);
+ total_edges = 0;
+ /* fill the edges with data */
+ for(; !BLI_ghashIterator_isDone(ghi); BLI_ghashIterator_step(ghi)){
+ UvEdge *edge = ((UvEdge *)BLI_ghashIterator_getKey(ghi));
+ if(edge->flag & STITCH_BOUNDARY){
+ total_edges++;
+ }
+ }
+ state->edges = edges = MEM_mallocN(sizeof(*edges)*total_edges, "stitch_edges");
+ if(!ghi || !edges){
+ MEM_freeN(all_edges);
+ stitch_state_delete(state);
+ return 0;
+ }
+
+ state->total_boundary_edges = total_edges;
+
+ /* fill the edges with data */
+ for(i = 0, BLI_ghashIterator_init(ghi, edgeHash); !BLI_ghashIterator_isDone(ghi); BLI_ghashIterator_step(ghi)){
+ UvEdge *edge = ((UvEdge *)BLI_ghashIterator_getKey(ghi));
+ if(edge->flag & STITCH_BOUNDARY){
+ edges[i++] = *((UvEdge *)BLI_ghashIterator_getKey(ghi));
+ }
+ }
+
+ /* cleanup temporary stuff */
+ BLI_ghashIterator_free(ghi);
+ MEM_freeN(all_edges);
+
+ /* refill hash with new pointers to cleanup duplicates */
+ BLI_ghash_free(edgeHash, NULL, NULL);
+
+ /***** calculate 2D normals for boundary uvs *****/
+
+ /* we use boundary edges to calculate 2D normals.
+ * to disambiguate the direction of the normal, we also need
+ * a point "inside" the island, that can be provided by
+ * the opposite uv for a quad, or the next uv for a triangle. */
+
+ for(i = 0; i < total_edges; i++){
+ float normal[2];
+ stitch_calculate_edge_normal(em, edges + i, normal);
+
+ add_v2_v2(state->normals + edges[i].uv1*2, normal);
+ add_v2_v2(state->normals + edges[i].uv2*2, normal);
+
+ normalize_v2(state->normals + edges[i].uv1*2);
+ normalize_v2(state->normals + edges[i].uv2*2);
+ }
+
+
+ /***** fill selection stack *******/
+
+ state->selection_size = 0;
+
+ /* Load old selection if redoing operator with different settings */
+ if(RNA_struct_property_is_set(op->ptr, "selection")){
+ int faceIndex, elementIndex;
+ UvElement *element;
+
+ EM_init_index_arrays(em, 0, 0, 1);
+
+
+ RNA_BEGIN(op->ptr, itemptr, "selection") {
+ faceIndex = RNA_int_get(&itemptr, "face_index");
+ elementIndex = RNA_int_get(&itemptr, "element_index");
+ efa = EM_get_face_for_index(faceIndex);
+ element = ED_get_uv_element(state->element_map, efa, elementIndex);
+ stitch_select_uv(element, state, 1);
+ }
+ RNA_END;
+
+ EM_free_index_arrays();
+ /* Clear the selection */
+ RNA_collection_clear(op->ptr, "selection");
+
+ } else {
+ for(efa = state->em->faces.first ; efa; efa = efa->next){
+ int numOfVerts;
+ MTFace *mt;
+ mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+ numOfVerts = efa->v4 ? 4 : 3;
+
+ for(i = 0; i < numOfVerts; i++){
+ if(uvedit_uv_selected(scene, efa, mt, i)){
+ UvElement *element = ED_get_uv_element(state->element_map, efa, i);
+ stitch_select_uv(element, state, 1);
+ }
+ }
+ }
+ }
+
+ /***** initialise static island preview data *****/
+
+ state->quads_per_island = MEM_mallocN(sizeof(*state->quads_per_island)*state->element_map->totalIslands,
+ "stitch island quads");
+ state->tris_per_island = MEM_mallocN(sizeof(*state->tris_per_island)*state->element_map->totalIslands,
+ "stitch island tris");
+ for(i = 0; i < state->element_map->totalIslands; i++){
+ state->quads_per_island[i] = 0;
+ state->tris_per_island[i] = 0;
+ }
+
+ for(efa = state->em->faces.first; efa; efa = efa->next){
+ UvElement *element = ED_get_uv_element(state->element_map, efa, 0);
+
+ if(element){
+ if(efa->v4){
+ state->quads_per_island[element->island]++;
+ }
+ else {
+ state->tris_per_island[element->island]++;
+ }
+ }
+ }
+
+ if(!stitch_process_data(state, scene, 0)){
+ stitch_state_delete(state);
+ return 0;
+ }
+
+ stitch_update_header(state, C);
+ return 1;
+}
+
+static int stitch_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
+{
+ Object *obedit = CTX_data_edit_object(C);
+ if(!stitch_init(C, op))
+ return OPERATOR_CANCELLED;
+
+ WM_event_add_modal_handler(C, op);
+ WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static void stitch_exit(bContext *C, wmOperator *op, int finished)
+{
+ StitchState *stitch_state;
+ Scene *scene;
+ SpaceImage *sima;
+ ScrArea *sa= CTX_wm_area(C);
+ Object *obedit;
+
+ scene= CTX_data_scene(C);
+ obedit= CTX_data_edit_object(C);
+ sima= CTX_wm_space_image(C);
+
+ stitch_state = (StitchState *)op->customdata;
+
+ if(finished){
+ EditFace *efa;
+ int i;
+
+ RNA_float_set(op->ptr, "limit", stitch_state->limit_dist);
+ RNA_boolean_set(op->ptr, "use_limit", stitch_state->use_limit);
+ RNA_boolean_set(op->ptr, "snap_islands", stitch_state->snap_islands);
+ RNA_int_set(op->ptr, "static_island", stitch_state->static_island);
+ RNA_boolean_set(op->ptr, "midpoint_snap", stitch_state->midpoints);
+
+ for(i = 0, efa = stitch_state->em->faces.first; efa; efa = efa->next, i++){
+ efa->tmp.l = i;
+ }
+
+ /* Store selection for re-execution of stitch */
+ for(i = 0; i < stitch_state->selection_size; i++){
+ PointerRNA itemptr;
+ UvElement *element = stitch_state->selection_stack[i];
+
+ RNA_collection_add(op->ptr, "selection", &itemptr);
+
+ RNA_int_set(&itemptr, "face_index", element->face->tmp.l);
+ RNA_int_set(&itemptr, "element_index", element->tfindex);
+ }
+
+
+ uvedit_live_unwrap_update(sima, scene, obedit);
+ }
+
+ if(sa)
+ ED_area_headerprint(sa, NULL);
+
+ DAG_id_tag_update(obedit->data, 0);
+ WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+ BKE_mesh_end_editmesh(obedit->data, stitch_state->em);
+
+ stitch_state_delete(stitch_state);
+ op->customdata = NULL;
+
+ stitch_preview_delete();
+}
+
+
+static int stitch_cancel(bContext *C, wmOperator *op)
+{
+ stitch_exit(C, op, 0);
+ return OPERATOR_CANCELLED;
+}
+
+
+static int stitch_exec(bContext *C, wmOperator *op)
+{
+ Scene *scene = CTX_data_scene(C);
+
+ if(!stitch_init(C, op))
+ return OPERATOR_CANCELLED;
+ if(stitch_process_data((StitchState *)op->customdata, scene, 1)){
+ stitch_exit(C, op, 1);
+ return OPERATOR_FINISHED;
+ }else {
+ return stitch_cancel(C, op);
+ }
+}
+
+static void stitch_select(bContext *C, Scene *scene, wmEvent *event, StitchState *stitch_state){
+ /* add uv under mouse to processed uv's */
+ float co[2];
+ NearestHit hit;
+ ARegion *ar= CTX_wm_region(C);
+ Image *ima= CTX_data_edit_image(C);
+
+ UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &co[0], &co[1]);
+ uv_find_nearest_vert(scene, ima, stitch_state->em, co, NULL, &hit);
+
+ if(hit.efa)
+ {
+ /* Add vertex to selection, deselect all common uv's of vert other
+ * than selected and update the preview. This behavior was decided so that
+ * you can do stuff like deselect the opposite stitchable vertex and the initial still gets deselected */
+
+ /* This works due to setting of tmp in find nearest uv vert */
+ UvElement *element = ED_get_uv_element(stitch_state->element_map, hit.efa, hit.uv);
+ stitch_select_uv(element, stitch_state, 0);
+
+ }
+}
+
+static int stitch_modal(bContext *C, wmOperator *op, wmEvent *event)
+{
+ StitchState *stitch_state;
+ Scene *scene = CTX_data_scene(C);
+
+ stitch_state = (StitchState *)op->customdata;
+
+ switch(event->type){
+ case MIDDLEMOUSE:
+ return OPERATOR_PASS_THROUGH;
+
+ /* Cancel */
+ case ESCKEY:
+ return stitch_cancel(C, op);
+
+
+ case LEFTMOUSE:
+ if(event->shift && (U.flag & USER_LMOUSESELECT)){
+ if(event->val == KM_RELEASE){
+ stitch_select(C, scene, event, stitch_state);
+
+ if(!stitch_process_data(stitch_state, scene, 0)){
+ return stitch_cancel(C, op);
+ }
+ }
+ break;
+ }
+ case PADENTER:
+ case RETKEY:
+ if(stitch_process_data(stitch_state, scene, 1)){
+ stitch_exit(C, op, 1);
+ return OPERATOR_FINISHED;
+ }
+ else {
+ return stitch_cancel(C, op);
+ }
+
+ /* Increase limit */
+ case PADPLUSKEY:
+ case WHEELUPMOUSE:
+ if(event->alt){
+ stitch_state->limit_dist += 0.01;
+ if(!stitch_process_data(stitch_state, scene, 0)){
+ return stitch_cancel(C, op);
+ }
+ break;
+ }
+ else{
+ return OPERATOR_PASS_THROUGH;
+ }
+ /* Decrease limit */
+ case PADMINUS:
+ case WHEELDOWNMOUSE:
+ if(event->alt){
+ stitch_state->limit_dist -= 0.01;
+ stitch_state->limit_dist = MAX2(0.01, stitch_state->limit_dist);
+ if(!stitch_process_data(stitch_state, scene, 0)){
+ return stitch_cancel(C, op);
+ }
+ break;
+ }else{
+ return OPERATOR_PASS_THROUGH;
+ }
+
+ /* Use Limit (Default off)*/
+ case LKEY:
+ if(event->val == KM_PRESS){
+ stitch_state->use_limit = !stitch_state->use_limit;
+ if(!stitch_process_data(stitch_state, scene, 0)){
+ return stitch_cancel(C, op);
+ }
+ break;
+ }
+ return OPERATOR_RUNNING_MODAL;
+
+ case IKEY:
+ if(event->val == KM_PRESS){
+ stitch_state->static_island++;
+ stitch_state->static_island %= stitch_state->element_map->totalIslands;
+
+ if(!stitch_process_data(stitch_state, scene, 0)){
+ return stitch_cancel(C, op);
+ }
+ break;
+ }
+ return OPERATOR_RUNNING_MODAL;
+
+ case MKEY:
+ if(event->val == KM_PRESS){
+ stitch_state->midpoints = !stitch_state->midpoints;
+ if(!stitch_process_data(stitch_state, scene, 0)){
+ return stitch_cancel(C, op);
+ }
+ }
+ break;
+
+ /* Select geometry*/
+ case RIGHTMOUSE:
+ if(!event->shift){
+ return stitch_cancel(C, op);
+ }
+ if(event->val == KM_RELEASE && !(U.flag & USER_LMOUSESELECT)){
+ stitch_select(C, scene, event, stitch_state);
+
+ if(!stitch_process_data(stitch_state, scene, 0)){
+ return stitch_cancel(C, op);
+ }
+ break;
+ }
+ return OPERATOR_RUNNING_MODAL;
+
+ /* snap islands on/off */
+ case SKEY:
+ if(event->val == KM_PRESS){
+ stitch_state->snap_islands = !stitch_state->snap_islands;
+ if(!stitch_process_data(stitch_state, scene, 0)){
+ return stitch_cancel(C, op);
+ }
+ break;
+ } else
+ return OPERATOR_RUNNING_MODAL;
+
+ default:
+ return OPERATOR_RUNNING_MODAL;
+ }
+
+ /* if updated settings, renew feedback message */
+ stitch_update_header(stitch_state, C);
+ ED_region_tag_redraw(CTX_wm_region(C));
+ return OPERATOR_RUNNING_MODAL;
+}
+
+void UV_OT_stitch(wmOperatorType *ot)
+{
+ PropertyRNA *prop;
+
+ /* identifiers */
+ ot->name = "Stitch";
+ ot->description = "Stitch selected UV vertices by proximity";
+ ot->idname = "UV_OT_stitch";
+ ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ /* api callbacks */
+ ot->invoke = stitch_invoke;
+ ot->modal = stitch_modal;
+ ot->exec = stitch_exec;
+ ot->cancel = stitch_cancel;
+ ot->poll= ED_operator_uvedit;
+
+ /* properties */
+ RNA_def_boolean(ot->srna, "use_limit", 0, "Use Limit", "Stitch UVs within a specified limit distance");
+ RNA_def_boolean(ot->srna, "snap_islands", 1, "Snap Islands", "Snap islands together. On edge stitch mode, rotates the islands too");
+
+ RNA_def_float(ot->srna, "limit", 0.01f, 0.0f, FLT_MAX, "Limit", "Limit distance in normalized coordinates", 0.0, FLT_MAX);
+ RNA_def_int(ot->srna, "static_island", 0, 0, INT_MAX, "Static Island", "Island that stays in place when stitching islands", 0, INT_MAX);
+ RNA_def_boolean(ot->srna, "midpoint_snap", 0, "Snap At Midpoint", "Uv's are stitched at midpoint instead of at static island");
+ prop = RNA_def_collection_runtime(ot->srna, "selection", &RNA_SelectedUvElement, "Selection", "");
+ /* Selection should not be editable or viewed in toolbar */
+ RNA_def_property_flag(prop, PROP_HIDDEN);
+}
+
+
diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
index 17e5bebd6b0..3ed4df66778 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@ -40,6 +40,7 @@
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
+#include "DNA_modifier_types.h"
#include "BLI_math.h"
#include "BLI_edgehash.h"
@@ -48,12 +49,15 @@
#include "BLI_utildefines.h"
#include "BLI_string.h"
+#include "BKE_cdderivedmesh.h"
+#include "BKE_subsurf.h"
#include "BKE_context.h"
#include "BKE_customdata.h"
#include "BKE_depsgraph.h"
#include "BKE_image.h"
#include "BKE_main.h"
#include "BKE_mesh.h"
+#include "BKE_report.h"
#include "PIL_time.h"
@@ -272,6 +276,201 @@ static ParamHandle *construct_param_handle(Scene *scene, EditMesh *em, short imp
return handle;
}
+
+static void texface_from_original_index(EditFace *editFace, MTFace *texFace, int index, float **uv, ParamBool *pin, ParamBool *select, Scene *scene)
+{
+ int i, nverts = (editFace->v4)? 4: 3;
+
+ *uv = NULL;
+ *pin = 0;
+ *select = 1;
+
+ if(index == ORIGINDEX_NONE)
+ return;
+
+ for(i = 0; i < nverts; i++) {
+ if((*(&editFace->v1 + i))->tmp.t == index) {
+ *uv = texFace->uv[i];
+ *pin = ((texFace->unwrap & TF_PIN_MASK(i)) != 0);
+ *select = (uvedit_uv_selected(scene, editFace, texFace, i) != 0);
+ }
+ }
+}
+
+/* unwrap handle initialization for subsurf aware-unwrapper. The many modifications required to make the original function(see above)
+ * work justified the existence of a new function. */
+static ParamHandle *construct_param_handle_subsurfed(Scene *scene, EditMesh *editMesh, short fill, short sel, short correct_aspect)
+{
+ ParamHandle *handle;
+ /* index pointers */
+ MFace *face;
+ MEdge *edge;
+ EditVert *editVert;
+ MTFace *texface;
+ EditFace *editFace, **editFaceTmp;
+ EditEdge *editEdge, **editEdgeTmp;
+ int i;
+
+ /* modifier initialization data, will control what type of subdivision will happen*/
+ SubsurfModifierData smd = {{0}};
+ /* Used to hold subsurfed Mesh */
+ DerivedMesh *derivedMesh, *initialDerived;
+ /* holds original indices for subsurfed mesh */
+ int *origVertIndices, *origFaceIndices, *origEdgeIndices;
+ /* Holds vertices of subsurfed mesh */
+ MVert *subsurfedVerts;
+ MEdge *subsurfedEdges;
+ MFace *subsurfedFaces;
+ MTFace *subsurfedTexfaces;
+ /* number of vertices and faces for subsurfed mesh*/
+ int numOfEdges, numOfFaces;
+
+ /* holds a map to editfaces for every subsurfed MFace. These will be used to get hidden/ selected flags etc. */
+ EditFace **faceMap;
+ /* Mini container to hold all EditFaces so that they may be indexed easily and fast. */
+ EditFace **editFaceArray;
+ /* similar to the above, we need a way to map edges to their original ones */
+ EditEdge **edgeMap;
+ EditEdge **editEdgeArray;
+
+ handle = param_construct_begin();
+
+ if(correct_aspect) {
+ EditFace *eface = EM_get_actFace(editMesh, 1);
+
+ if(eface) {
+ float aspx, aspy;
+ texface= CustomData_em_get(&editMesh->fdata, eface->data, CD_MTFACE);
+
+ ED_image_uv_aspect(texface->tpage, &aspx, &aspy);
+
+ if(aspx!=aspy)
+ param_aspect_ratio(handle, aspx, aspy);
+ }
+ }
+
+ /* number of subdivisions to perform */
+ smd.levels = scene->toolsettings->uv_subsurf_level;
+ smd.subdivType = ME_CC_SUBSURF;
+
+ initialDerived = CDDM_from_editmesh(editMesh, NULL);
+ derivedMesh = subsurf_make_derived_from_derived(initialDerived, &smd,
+ 0, NULL, 0, 0, 1);
+
+ initialDerived->release(initialDerived);
+
+ /* get the derived data */
+ subsurfedVerts = derivedMesh->getVertArray(derivedMesh);
+ subsurfedEdges = derivedMesh->getEdgeArray(derivedMesh);
+ subsurfedFaces = derivedMesh->getFaceArray(derivedMesh);
+
+ origVertIndices = derivedMesh->getVertDataArray(derivedMesh, CD_ORIGINDEX);
+ origEdgeIndices = derivedMesh->getEdgeDataArray(derivedMesh, CD_ORIGINDEX);
+ origFaceIndices = derivedMesh->getFaceDataArray(derivedMesh, CD_ORIGINDEX);
+
+ subsurfedTexfaces = derivedMesh->getFaceDataArray(derivedMesh, CD_MTFACE);
+
+ numOfEdges = derivedMesh->getNumEdges(derivedMesh);
+ numOfFaces = derivedMesh->getNumFaces(derivedMesh);
+
+ faceMap = MEM_mallocN(numOfFaces*sizeof(EditFace *), "unwrap_edit_face_map");
+ editFaceArray = MEM_mallocN(editMesh->totface*sizeof(EditFace *), "unwrap_editFaceArray");
+
+ /* fill edit face array with edit faces */
+ for(editFace = editMesh->faces.first, editFaceTmp = editFaceArray; editFace; editFace= editFace->next, editFaceTmp++)
+ *editFaceTmp = editFace;
+
+ /* map subsurfed faces to original editFaces */
+ for(i = 0; i < numOfFaces; i++)
+ faceMap[i] = editFaceArray[origFaceIndices[i]];
+
+ MEM_freeN(editFaceArray);
+
+ edgeMap = MEM_mallocN(numOfEdges*sizeof(EditEdge *), "unwrap_edit_edge_map");
+ editEdgeArray = MEM_mallocN(editMesh->totedge*sizeof(EditEdge *), "unwrap_editEdgeArray");
+
+ /* fill edit edge array with edit edges */
+ for(editEdge = editMesh->edges.first, editEdgeTmp = editEdgeArray; editEdge; editEdge= editEdge->next, editEdgeTmp++)
+ *editEdgeTmp = editEdge;
+
+ /* map subsurfed edges to original editEdges */
+ for(i = 0; i < numOfEdges; i++) {
+ /* not all edges correspond to an old edge */
+ edgeMap[i] = (origEdgeIndices[i] != -1)?
+ editEdgeArray[origEdgeIndices[i]] : NULL;
+ }
+
+ MEM_freeN(editEdgeArray);
+
+ /* we need the editvert indices too */
+ for(editVert = editMesh->verts.first, i=0; editVert; editVert = editVert->next, i++)
+ editVert->tmp.t = i;
+
+ /* Prepare and feed faces to the solver */
+ for(i = 0; i < numOfFaces; i++) {
+ ParamKey key, vkeys[4];
+ ParamBool pin[4], select[4];
+ float *co[4];
+ float *uv[4];
+ EditFace *origFace = faceMap[i];
+ MTFace *origtexface = (MTFace *)CustomData_em_get(&editMesh->fdata, origFace->data, CD_MTFACE);
+
+ face = subsurfedFaces+i;
+
+ if(scene->toolsettings->uv_flag & UV_SYNC_SELECTION) {
+ if(origFace->h)
+ continue;
+ }
+ else {
+ if((origFace->h) || (sel && (origFace->f & SELECT)==0))
+ continue;
+ }
+
+ /* Now we feed the rest of the data from the subsurfed faces */
+ texface= subsurfedTexfaces+i;
+
+ /* We will not check for v4 here. Subsurfed mfaces always have 4 vertices. */
+ key = (ParamKey)face;
+ vkeys[0] = (ParamKey)face->v1;
+ vkeys[1] = (ParamKey)face->v2;
+ vkeys[2] = (ParamKey)face->v3;
+ vkeys[3] = (ParamKey)face->v4;
+
+ co[0] = subsurfedVerts[face->v1].co;
+ co[1] = subsurfedVerts[face->v2].co;
+ co[2] = subsurfedVerts[face->v3].co;
+ co[3] = subsurfedVerts[face->v4].co;
+
+ /* This is where all the magic is done. If the vertex exists in the, we pass the original uv pointer to the solver, thus
+ * flushing the solution to the edit mesh. */
+ texface_from_original_index(origFace, origtexface, origVertIndices[face->v1], &uv[0], &pin[0], &select[0], scene);
+ texface_from_original_index(origFace, origtexface, origVertIndices[face->v2], &uv[1], &pin[1], &select[1], scene);
+ texface_from_original_index(origFace, origtexface, origVertIndices[face->v3], &uv[2], &pin[2], &select[2], scene);
+ texface_from_original_index(origFace, origtexface, origVertIndices[face->v4], &uv[3], &pin[3], &select[3], scene);
+
+ param_face_add(handle, key, 4, vkeys, co, uv, pin, select);
+ }
+
+ /* these are calculated from original mesh too */
+ for(edge = subsurfedEdges, i = 0; i < numOfEdges; i++, edge++) {
+ if((edgeMap[i] != NULL) && edgeMap[i]->seam) {
+ ParamKey vkeys[2];
+ vkeys[0] = (ParamKey)edge->v1;
+ vkeys[1] = (ParamKey)edge->v2;
+ param_edge_set_seam(handle, vkeys);
+ }
+ }
+
+ param_construct_end(handle, fill, 0);
+
+ /* cleanup */
+ MEM_freeN(faceMap);
+ MEM_freeN(edgeMap);
+ derivedMesh->release(derivedMesh);
+
+ return handle;
+}
+
/* ******************** Minimize Stretch operator **************** */
typedef struct MinStretch {
@@ -582,13 +781,17 @@ void ED_uvedit_live_unwrap_begin(Scene *scene, Object *obedit)
EditMesh *em= BKE_mesh_get_editmesh((Mesh*)obedit->data);
short abf = scene->toolsettings->unwrapper == 0;
short fillholes = scene->toolsettings->uvcalc_flag & UVCALC_FILLHOLES;
+ short use_subsurf = scene->toolsettings->uvcalc_flag & UVCALC_USESUBSURF;
if(!ED_uvedit_test(obedit)) {
BKE_mesh_end_editmesh(obedit->data, em);
return;
}
- liveHandle = construct_param_handle(scene, em, 0, fillholes, 0, 1);
+ if(use_subsurf)
+ liveHandle = construct_param_handle_subsurfed(scene, em, fillholes, 0, 1);
+ else
+ liveHandle = construct_param_handle(scene, em, 0, fillholes, 0, 1);
param_lscm_begin(liveHandle, PARAM_TRUE, abf);
BKE_mesh_end_editmesh(obedit->data, em);
@@ -900,14 +1103,17 @@ static void uv_map_clip_correct(EditMesh *em, wmOperator *op)
/* assumes UV Map is checked, doesn't run update funcs */
void ED_unwrap_lscm(Scene *scene, Object *obedit, const short sel)
{
- EditMesh *em= BKE_mesh_get_editmesh((Mesh*)obedit->data);
ParamHandle *handle;
+ EditMesh *em= BKE_mesh_get_editmesh((Mesh*)obedit->data);
const short fill_holes= scene->toolsettings->uvcalc_flag & UVCALC_FILLHOLES;
const short correct_aspect= !(scene->toolsettings->uvcalc_flag & UVCALC_NO_ASPECT_CORRECT);
- short implicit= 0;
+ const short use_subsurf = scene->toolsettings->uvcalc_flag & UVCALC_USESUBSURF;
- handle= construct_param_handle(scene, em, implicit, fill_holes, sel, correct_aspect);
+ if(use_subsurf)
+ handle = construct_param_handle_subsurfed(scene, em, fill_holes, sel, correct_aspect);
+ else
+ handle= construct_param_handle(scene, em, 0, fill_holes, sel, correct_aspect);
param_lscm_begin(handle, PARAM_FALSE, scene->toolsettings->unwrapper == 0);
param_lscm_solve(handle);
@@ -930,6 +1136,9 @@ static int unwrap_exec(bContext *C, wmOperator *op)
int method = RNA_enum_get(op->ptr, "method");
int fill_holes = RNA_boolean_get(op->ptr, "fill_holes");
int correct_aspect = RNA_boolean_get(op->ptr, "correct_aspect");
+ int use_subsurf = RNA_boolean_get(op->ptr, "use_subsurf_data");
+ int subsurf_level = RNA_int_get(op->ptr, "uv_subsurf_level");
+ float obsize[3], unitsize[3] = {1.0f, 1.0f, 1.0f};
short implicit= 0;
if(!uvedit_have_selection(scene, em, implicit)) {
@@ -944,8 +1153,14 @@ static int unwrap_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
+ mat4_to_size(obsize, obedit->obmat);
+ if(!compare_v3v3(obsize, unitsize, 1e-4f))
+ BKE_report(op->reports, RPT_INFO, "Object scale is not 1.0. Unwrap will operate on a non-scaled version of the mesh.");
+
/* remember last method for live unwrap */
scene->toolsettings->unwrapper = method;
+
+ scene->toolsettings->uv_subsurf_level = subsurf_level;
if(fill_holes) scene->toolsettings->uvcalc_flag |= UVCALC_FILLHOLES;
else scene->toolsettings->uvcalc_flag &= ~UVCALC_FILLHOLES;
@@ -953,6 +1168,9 @@ static int unwrap_exec(bContext *C, wmOperator *op)
if(correct_aspect) scene->toolsettings->uvcalc_flag &= ~UVCALC_NO_ASPECT_CORRECT;
else scene->toolsettings->uvcalc_flag |= UVCALC_NO_ASPECT_CORRECT;
+ if(use_subsurf) scene->toolsettings->uvcalc_flag |= UVCALC_USESUBSURF;
+ else scene->toolsettings->uvcalc_flag &= ~UVCALC_USESUBSURF;
+
/* execute unwrap */
ED_unwrap_lscm(scene, obedit, TRUE);
@@ -986,6 +1204,8 @@ void UV_OT_unwrap(wmOperatorType *ot)
"Virtual fill holes in mesh before unwrapping, to better avoid overlaps and preserve symmetry");
RNA_def_boolean(ot->srna, "correct_aspect", 1, "Correct Aspect",
"Map UVs taking image aspect ratio into account");
+ RNA_def_boolean(ot->srna, "use_subsurf_data", 0, "Use Subsurf Data", "Map UV's taking vertex position after subsurf into account");
+ RNA_def_int(ot->srna, "uv_subsurf_level", 1, 1, 6, "SubSurf Target", "Number of times to subdivide before calculating UV's", 1, 6);
}
/**************** Project From View operator **************/
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index d623697921c..203fd00538f 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -653,7 +653,7 @@ static char *code_generate_vertex(ListBase *nodes)
int GPU_bicubic_bump_support(void)
{
- return GLEW_ARB_texture_gather && GLEW_ARB_texture_query_lod && GLEW_VERSION_3_0;
+ return GLEW_ARB_texture_query_lod && GLEW_VERSION_3_0;
}
void GPU_code_generate_glsl_lib(void)
@@ -669,7 +669,6 @@ void GPU_code_generate_glsl_lib(void)
if(GPU_bicubic_bump_support()){
BLI_dynstr_append(ds, "/* These are needed for high quality bump mapping */\n"
"#version 130\n"
- "#extension GL_ARB_texture_gather: enable\n"
"#extension GL_ARB_texture_query_lod: enable\n"
"#define BUMP_BICUBIC\n");
}
diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c
index 5d36ba169f3..59802f2cf58 100644
--- a/source/blender/gpu/intern/gpu_draw.c
+++ b/source/blender/gpu/intern/gpu_draw.c
@@ -410,9 +410,12 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
ImBuf *ibuf = NULL;
unsigned int *bind = NULL;
int rectw, recth, tpx=0, tpy=0, y;
- unsigned int *rectrow, *tilerectrow;
unsigned int *tilerect= NULL, *scalerect= NULL, *rect= NULL;
+ float *ftilerect= NULL, *fscalerect = NULL, *frect = NULL;
+ float *srgb_frect = NULL;
short texwindx, texwindy, texwinsx, texwinsy;
+ /* flag to determine whether high resolution format is used */
+ int use_high_bit_depth = FALSE, do_color_management = FALSE;
/* initialize tile mode and number of repeats */
GTS.ima = ima;
@@ -462,9 +465,20 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
if(ibuf==NULL)
return 0;
- /* ensure we have a char buffer and not only float */
- if ((ibuf->rect==NULL) && ibuf->rect_float)
- IMB_rect_from_float(ibuf);
+ if(ibuf->rect_float) {
+ if(U.use_16bit_textures) {
+ /* use high precision textures. This is relatively harmless because OpenGL gives us
+ a high precision format only if it is available */
+ use_high_bit_depth = TRUE;
+ }
+
+ /* TODO unneeded when float images are correctly treated as linear always */
+ if(ibuf->profile == IB_PROFILE_LINEAR_RGB)
+ do_color_management = TRUE;
+
+ if(ibuf->rect==NULL)
+ IMB_rect_from_float(ibuf);
+ }
/* currently, tpage refresh is used by ima sequences */
if(ima->tpageflag & IMA_TPAGE_REFRESH) {
@@ -498,17 +512,39 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
tpx= texwindx;
tpy= texwindy;
- rect= ibuf->rect + texwinsy*ibuf->x + texwinsx;
+ if(use_high_bit_depth) {
+ if(do_color_management) {
+ srgb_frect = MEM_mallocN(ibuf->x*ibuf->y*sizeof(float)*4, "floar_buf_col_cor");
+ IMB_buffer_float_from_float(srgb_frect, ibuf->rect_float,
+ ibuf->channels, IB_PROFILE_SRGB, ibuf->profile, 0,
+ ibuf->x, ibuf->y, ibuf->x, ibuf->x);
+ frect= srgb_frect + texwinsy*ibuf->x + texwinsx;
+ }
+ else
+ frect= ibuf->rect_float + texwinsy*ibuf->x + texwinsx;
+ }
+ else
+ rect= ibuf->rect + texwinsy*ibuf->x + texwinsx;
}
}
else {
/* regular image mode */
bind= &ima->bindcode;
-
+
if(*bind==0) {
tpx= ibuf->x;
tpy= ibuf->y;
rect= ibuf->rect;
+ if(use_high_bit_depth) {
+ if(do_color_management) {
+ frect = srgb_frect = MEM_mallocN(ibuf->x*ibuf->y*sizeof(*srgb_frect)*4, "floar_buf_col_cor");
+ IMB_buffer_float_from_float(srgb_frect, ibuf->rect_float,
+ ibuf->channels, IB_PROFILE_SRGB, ibuf->profile, 0,
+ ibuf->x, ibuf->y, ibuf->x, ibuf->x);
+ }
+ else
+ frect= ibuf->rect_float;
+ }
}
}
@@ -523,26 +559,57 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
/* for tiles, copy only part of image into buffer */
if (GTS.tilemode) {
- tilerect= MEM_mallocN(rectw*recth*sizeof(*tilerect), "tilerect");
+ if(use_high_bit_depth) {
+ float *frectrow, *ftilerectrow;
- for (y=0; y<recth; y++) {
- rectrow= &rect[y*ibuf->x];
- tilerectrow= &tilerect[y*rectw];
-
- memcpy(tilerectrow, rectrow, tpx*sizeof(*rectrow));
+ ftilerect= MEM_mallocN(rectw*recth*sizeof(*ftilerect), "tilerect");
+
+ for (y=0; y<recth; y++) {
+ frectrow= &frect[y*ibuf->x];
+ ftilerectrow= &ftilerect[y*rectw];
+
+ memcpy(ftilerectrow, frectrow, tpx*sizeof(*frectrow));
+ }
+
+ frect= ftilerect;
}
+ else {
+ unsigned int *rectrow, *tilerectrow;
+
+ tilerect= MEM_mallocN(rectw*recth*sizeof(*tilerect), "tilerect");
+
+ for (y=0; y<recth; y++) {
+ rectrow= &rect[y*ibuf->x];
+ tilerectrow= &tilerect[y*rectw];
+
+ memcpy(tilerectrow, rectrow, tpx*sizeof(*rectrow));
+ }
- rect= tilerect;
+ rect= tilerect;
+ }
}
- /* scale if not a power of two */
+ /* scale if not a power of two. this is not strictly necessary for newer
+ GPUs (OpenGL version >= 2.0) since they support non-power-of-two-textures */
if (!is_pow2_limit(rectw) || !is_pow2_limit(recth)) {
rectw= smaller_pow2_limit(rectw);
recth= smaller_pow2_limit(recth);
- scalerect= MEM_mallocN(rectw*recth*sizeof(*scalerect), "scalerect");
- gluScaleImage(GL_RGBA, tpx, tpy, GL_UNSIGNED_BYTE, rect, rectw, recth, GL_UNSIGNED_BYTE, scalerect);
- rect= scalerect;
+ if(use_high_bit_depth) {
+ fscalerect= MEM_mallocN(rectw*recth*sizeof(*fscalerect)*4, "fscalerect");
+ gluScaleImage(GL_RGBA, tpx, tpy, GL_FLOAT, frect, rectw, recth, GL_FLOAT, fscalerect);
+ /* frect will refer to ibuf->rect_float when not color converting. We don't want to free that */
+ if(do_color_management)
+ MEM_freeN(frect);
+
+ frect = fscalerect;
+ }
+ else {
+ scalerect= MEM_mallocN(rectw*recth*sizeof(*scalerect), "scalerect");
+ gluScaleImage(GL_RGBA, tpx, tpy, GL_UNSIGNED_BYTE, rect, rectw, recth, GL_UNSIGNED_BYTE, scalerect);
+
+ rect= scalerect;
+ }
}
/* create image */
@@ -550,12 +617,18 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
glBindTexture( GL_TEXTURE_2D, *bind);
if (!(gpu_get_mipmap() && mipmap)) {
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, rectw, recth, 0, GL_RGBA, GL_UNSIGNED_BYTE, rect);
+ if(use_high_bit_depth)
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, rectw, recth, 0, GL_RGBA, GL_FLOAT, frect);
+ else
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, rectw, recth, 0, GL_RGBA, GL_UNSIGNED_BYTE, rect);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
}
else {
- gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, rectw, recth, GL_RGBA, GL_UNSIGNED_BYTE, rect);
+ if(use_high_bit_depth)
+ gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA16, rectw, recth, GL_RGBA, GL_FLOAT, frect);
+ else
+ gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, rectw, recth, GL_RGBA, GL_UNSIGNED_BYTE, rect);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
@@ -570,9 +643,14 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
/* clean up */
if (tilerect)
MEM_freeN(tilerect);
+ if (ftilerect)
+ MEM_freeN(ftilerect);
if (scalerect)
MEM_freeN(scalerect);
-
+ if (fscalerect)
+ MEM_freeN(fscalerect);
+ if (srgb_frect)
+ MEM_freeN(srgb_frect);
return *bind;
}
@@ -692,23 +770,21 @@ void GPU_paint_update_image(Image *ima, int x, int y, int w, int h, int mipmap)
glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skip_pixels);
glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skip_rows);
- if (ibuf->rect_float){
- /*This case needs a whole new buffer*/
- if(ibuf->rect==NULL) {
- IMB_rect_from_float(ibuf);
- }
- else {
- /* Do partial drawing. 'buffer' holds only the changed part. Needed for color corrected result */
- float *buffer = (float *)MEM_mallocN(w*h*sizeof(float)*4, "temp_texpaint_float_buf");
- IMB_partial_rect_from_float(ibuf, buffer, x, y, w, h);
- glBindTexture(GL_TEXTURE_2D, ima->bindcode);
- glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA,
+ /* if color correction is needed, we must update the part that needs updating. */
+ if(ibuf->rect_float && (!U.use_16bit_textures || (ibuf->profile == IB_PROFILE_LINEAR_RGB))) {
+ float *buffer = MEM_mallocN(w*h*sizeof(float)*4, "temp_texpaint_float_buf");
+ IMB_partial_rect_from_float(ibuf, buffer, x, y, w, h);
+
+ glBindTexture(GL_TEXTURE_2D, ima->bindcode);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA,
GL_FLOAT, buffer);
- MEM_freeN(buffer);
- if(ima->tpageflag & IMA_MIPMAP_COMPLETE)
- ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
- return;
- }
+
+ MEM_freeN(buffer);
+
+ if(ima->tpageflag & IMA_MIPMAP_COMPLETE)
+ ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
+
+ return;
}
glBindTexture(GL_TEXTURE_2D, ima->bindcode);
@@ -717,8 +793,12 @@ void GPU_paint_update_image(Image *ima, int x, int y, int w, int h, int mipmap)
glPixelStorei(GL_UNPACK_SKIP_PIXELS, x);
glPixelStorei(GL_UNPACK_SKIP_ROWS, y);
- glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA,
- GL_UNSIGNED_BYTE, ibuf->rect);
+ if(ibuf->rect_float)
+ glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA,
+ GL_FLOAT, ibuf->rect_float);
+ else
+ glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA,
+ GL_UNSIGNED_BYTE, ibuf->rect);
glPixelStorei(GL_UNPACK_ROW_LENGTH, row_length);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, skip_pixels);
diff --git a/source/blender/imbuf/IMB_imbuf_types.h b/source/blender/imbuf/IMB_imbuf_types.h
index adf6f4a143b..cb5d6721566 100644
--- a/source/blender/imbuf/IMB_imbuf_types.h
+++ b/source/blender/imbuf/IMB_imbuf_types.h
@@ -50,7 +50,7 @@
struct ImMetaData;
#define IB_MIPMAP_LEVELS 20
-#define IB_FILENAME_SIZE 1023
+#define IB_FILENAME_SIZE 1024
/**
* \ingroup imbuf
diff --git a/source/blender/imbuf/intern/IMB_anim.h b/source/blender/imbuf/intern/IMB_anim.h
index b627baf99bd..a9f020c94e8 100644
--- a/source/blender/imbuf/intern/IMB_anim.h
+++ b/source/blender/imbuf/intern/IMB_anim.h
@@ -136,9 +136,9 @@ struct anim {
int x, y;
/* voor op nummer */
- char name[256];
+ char name[1024];
/* voor sequence */
- char first[256];
+ char first[1024];
/* movie */
void *movie;
@@ -189,7 +189,7 @@ struct anim {
struct redcode_handle * redcodeCtx;
#endif
- char index_dir[256];
+ char index_dir[768];
int proxies_tried;
int indices_tried;
diff --git a/source/blender/imbuf/intern/IMB_indexer.h b/source/blender/imbuf/intern/IMB_indexer.h
index 62608cbbd79..f9d90208078 100644
--- a/source/blender/imbuf/intern/IMB_indexer.h
+++ b/source/blender/imbuf/intern/IMB_indexer.h
@@ -62,7 +62,7 @@ typedef struct anim_index_entry {
} anim_index_entry;
struct anim_index {
- char name[256];
+ char name[1024];
int num_entries;
struct anim_index_entry * entries;
diff --git a/source/blender/imbuf/intern/divers.c b/source/blender/imbuf/intern/divers.c
index 442309ccf7a..a8ca282de66 100644
--- a/source/blender/imbuf/intern/divers.c
+++ b/source/blender/imbuf/intern/divers.c
@@ -164,19 +164,6 @@ MINLINE unsigned char dither_value(unsigned short v_in, DitherContext *di, int i
/************************* Generic Buffer Conversion *************************/
-MINLINE void byte_to_float_v4(float f[4], const uchar b[4])
-{
- f[0]= b[0] * (1.0f/255.0f);
- f[1]= b[1] * (1.0f/255.0f);
- f[2]= b[2] * (1.0f/255.0f);
- f[3]= b[3] * (1.0f/255.0f);
-}
-
-MINLINE void float_to_byte_v4(uchar b[4], const float f[4])
-{
- F4TOCHAR4(f, b);
-}
-
MINLINE void ushort_to_byte_v4(uchar b[4], const unsigned short us[4])
{
b[0]= USHORTTOUCHAR(us[0]);
@@ -233,7 +220,7 @@ void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from,
if(profile_to == profile_from) {
/* no color space conversion */
for(x = 0; x < width; x++, from+=3, to+=4) {
- F3TOCHAR3(from, to);
+ rgb_float_to_uchar(to, from);
to[3] = 255;
}
}
@@ -241,7 +228,7 @@ void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from,
/* convert from linear to sRGB */
for(x = 0; x < width; x++, from+=3, to+=4) {
linearrgb_to_srgb_v3_v3(tmp, from);
- F3TOCHAR3(tmp, to);
+ rgb_float_to_uchar(to, tmp);
to[3] = 255;
}
}
@@ -249,7 +236,7 @@ void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from,
/* convert from sRGB to linear */
for(x = 0; x < width; x++, from+=3, to+=4) {
srgb_to_linearrgb_v3_v3(tmp, from);
- F3TOCHAR3(tmp, to);
+ rgb_float_to_uchar(to, tmp);
to[3] = 255;
}
}
@@ -267,7 +254,7 @@ void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from,
}
else {
for(x = 0; x < width; x++, from+=4, to+=4)
- float_to_byte_v4(to, from);
+ rgba_float_to_uchar(to, from);
}
}
else if(profile_to == IB_PROFILE_SRGB) {
@@ -316,13 +303,13 @@ void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from,
else if(predivide) {
for(x = 0; x < width; x++, from+=4, to+=4) {
srgb_to_linearrgb_predivide_v4(tmp, from);
- float_to_byte_v4(to, tmp);
+ rgba_float_to_uchar(to, tmp);
}
}
else {
for(x = 0; x < width; x++, from+=4, to+=4) {
srgb_to_linearrgb_v4(tmp, from);
- float_to_byte_v4(to, tmp);
+ rgba_float_to_uchar(to, tmp);
}
}
}
@@ -358,7 +345,7 @@ void IMB_buffer_float_from_byte(float *rect_to, const uchar *rect_from,
if(profile_to == profile_from) {
/* no color space conversion */
for(x = 0; x < width; x++, from+=4, to+=4)
- byte_to_float_v4(to, from);
+ rgba_uchar_to_float(to, from);
}
else if(profile_to == IB_PROFILE_LINEAR_RGB) {
/* convert sRGB to linear */
@@ -377,13 +364,13 @@ void IMB_buffer_float_from_byte(float *rect_to, const uchar *rect_from,
/* convert linear to sRGB */
if(predivide) {
for(x = 0; x < width; x++, from+=4, to+=4) {
- byte_to_float_v4(tmp, from);
+ rgba_uchar_to_float(tmp, from);
linearrgb_to_srgb_predivide_v4(to, tmp);
}
}
else {
for(x = 0; x < width; x++, from+=4, to+=4) {
- byte_to_float_v4(tmp, from);
+ rgba_uchar_to_float(tmp, from);
linearrgb_to_srgb_v4(to, tmp);
}
}
@@ -502,16 +489,16 @@ void IMB_buffer_byte_from_byte(uchar *rect_to, const uchar *rect_from,
/* convert to sRGB to linear */
if(predivide) {
for(x = 0; x < width; x++, from+=4, to+=4) {
- byte_to_float_v4(tmp, from);
+ rgba_uchar_to_float(tmp, from);
srgb_to_linearrgb_predivide_v4(tmp, tmp);
- float_to_byte_v4(to, tmp);
+ rgba_float_to_uchar(to, tmp);
}
}
else {
for(x = 0; x < width; x++, from+=4, to+=4) {
- byte_to_float_v4(tmp, from);
+ rgba_uchar_to_float(tmp, from);
srgb_to_linearrgb_v4(tmp, tmp);
- float_to_byte_v4(to, tmp);
+ rgba_float_to_uchar(to, tmp);
}
}
}
@@ -519,16 +506,16 @@ void IMB_buffer_byte_from_byte(uchar *rect_to, const uchar *rect_from,
/* convert from linear to sRGB */
if(predivide) {
for(x = 0; x < width; x++, from+=4, to+=4) {
- byte_to_float_v4(tmp, from);
+ rgba_uchar_to_float(tmp, from);
linearrgb_to_srgb_predivide_v4(tmp, tmp);
- float_to_byte_v4(to, tmp);
+ rgba_float_to_uchar(to, tmp);
}
}
else {
for(x = 0; x < width; x++, from+=4, to+=4) {
- byte_to_float_v4(tmp, from);
+ rgba_uchar_to_float(tmp, from);
linearrgb_to_srgb_v4(tmp, tmp);
- float_to_byte_v4(to, tmp);
+ rgba_float_to_uchar(to, tmp);
}
}
}
@@ -658,15 +645,19 @@ void IMB_convert_profile(ImBuf *ibuf, int profile)
profile_from = IB_PROFILE_LINEAR_RGB;
else if(ELEM(ibuf->profile, IB_PROFILE_SRGB, IB_PROFILE_NONE))
profile_from = IB_PROFILE_SRGB;
- else
+ else {
BLI_assert(0);
+ profile_from = IB_PROFILE_SRGB; /* dummy, should never happen */
+ }
if(profile == IB_PROFILE_LINEAR_RGB)
profile_to = IB_PROFILE_LINEAR_RGB;
else if(ELEM(profile, IB_PROFILE_SRGB, IB_PROFILE_NONE))
profile_to = IB_PROFILE_SRGB;
- else
+ else {
BLI_assert(0);
+ profile_to = IB_PROFILE_SRGB; /* dummy, should never happen */
+ }
/* do conversion */
if(ibuf->rect_float) {
diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h
index 0e58ca6bd61..97b88692822 100644
--- a/source/blender/makesdna/DNA_ID.h
+++ b/source/blender/makesdna/DNA_ID.h
@@ -128,8 +128,8 @@ typedef struct Library {
ID id;
ID *idblock;
struct FileData *filedata;
- char name[240]; /* path name used for reading, can be relative and edited in the outliner */
- char filepath[240]; /* absolute filepath, this is only for convenience,
+ char name[1024]; /* path name used for reading, can be relative and edited in the outliner */
+ char filepath[1024]; /* absolute filepath, this is only for convenience,
* 'name' is the real path used on file read but in
* some cases its useful to access the absolute one,
* This is set on file read.
diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h
index 6e7385d683d..690c3c95964 100644
--- a/source/blender/makesdna/DNA_brush_types.h
+++ b/source/blender/makesdna/DNA_brush_types.h
@@ -59,7 +59,7 @@ typedef struct Brush {
struct ImBuf *icon_imbuf;
PreviewImage *preview;
- char icon_filepath[240];
+ char icon_filepath[1024]; /* 1024 = FILE_MAX */
float normal_weight;
diff --git a/source/blender/makesdna/DNA_customdata_types.h b/source/blender/makesdna/DNA_customdata_types.h
index 00a0cf8881f..a4bb5715174 100644
--- a/source/blender/makesdna/DNA_customdata_types.h
+++ b/source/blender/makesdna/DNA_customdata_types.h
@@ -55,7 +55,7 @@ typedef struct CustomDataLayer {
#define MAX_CUSTOMDATA_LAYER_NAME 64
typedef struct CustomDataExternal {
- char filename[240]; /* FILE_MAX */
+ char filename[1024]; /* FILE_MAX */
} CustomDataExternal;
/** structure which stores custom element data associated with mesh elements
diff --git a/source/blender/makesdna/DNA_dynamicpaint_types.h b/source/blender/makesdna/DNA_dynamicpaint_types.h
index cee8e5cd8d7..aff4607da51 100644
--- a/source/blender/makesdna/DNA_dynamicpaint_types.h
+++ b/source/blender/makesdna/DNA_dynamicpaint_types.h
@@ -55,6 +55,7 @@ struct PaintSurfaceData;
#define MOD_DPAINT_WAVE_OPEN_BORDERS (1<<7) /* passes waves through mesh edges */
#define MOD_DPAINT_DISP_INCREMENTAL (1<<8) /* builds displace on top of earlier values */
+#define MOD_DPAINT_USE_DRYING (1<<9) /* use drying */
#define MOD_DPAINT_OUT1 (1<<10) /* output primary surface */
#define MOD_DPAINT_OUT2 (1<<11) /* output secondary surface */
@@ -69,8 +70,8 @@ struct PaintSurfaceData;
/* effect */
#define MOD_DPAINT_EFFECT_DO_SPREAD (1<<0) /* do spread effect */
-#define MOD_DPAINT_EFFECT_DO_DRIP (1<<1) /* do spread effect */
-#define MOD_DPAINT_EFFECT_DO_SHRINK (1<<2) /* do spread effect */
+#define MOD_DPAINT_EFFECT_DO_DRIP (1<<1) /* do drip effect */
+#define MOD_DPAINT_EFFECT_DO_SHRINK (1<<2) /* do shrink effect */
/* preview_id */
#define MOD_DPAINT_SURFACE_PREV_PAINT 0
@@ -114,18 +115,20 @@ typedef struct DynamicPaintSurface {
char init_layername[64]; /* MAX_CUSTOMDATA_LAYER_NAME */
int dry_speed, diss_speed;
+ float color_dry_threshold;
float depth_clamp, disp_factor;
float spread_speed, color_spread_speed, shrink_speed;
float drip_vel, drip_acc;
+ /* per surface brush settings */
+ float influence_scale, radius_scale;
+
/* wave settings */
float wave_damping, wave_speed, wave_timescale, wave_spring;
- int pad_;
-
char uvlayer_name[64]; /* MAX_CUSTOMDATA_LAYER_NAME */
- char image_output_path[240];
+ char image_output_path[1024]; /* 1024 = FILE_MAX */
char output_name[64]; /* MAX_CUSTOMDATA_LAYER_NAME */
char output_name2[64]; /* MAX_CUSTOMDATA_LAYER_NAME */ /* some surfaces have 2 outputs */
diff --git a/source/blender/makesdna/DNA_fileglobal_types.h b/source/blender/makesdna/DNA_fileglobal_types.h
index 31ad628d630..ed9f3cec987 100644
--- a/source/blender/makesdna/DNA_fileglobal_types.h
+++ b/source/blender/makesdna/DNA_fileglobal_types.h
@@ -51,7 +51,7 @@ typedef struct FileGlobal {
int revision; /* svn revision from buildinfo */
int pad;
/* file path where this was saved, for recover */
- char filename[240]; /* 240 = FILE_MAX */
+ char filename[1024]; /* 1024 = FILE_MAX */
} FileGlobal;
diff --git a/source/blender/makesdna/DNA_image_types.h b/source/blender/makesdna/DNA_image_types.h
index a1b0ab06ecd..8f6cc5bf354 100644
--- a/source/blender/makesdna/DNA_image_types.h
+++ b/source/blender/makesdna/DNA_image_types.h
@@ -69,7 +69,7 @@ typedef struct ImageUser {
typedef struct Image {
ID id;
- char name[240]; /* file path */
+ char name[1024]; /* file path, 1024 = FILE_MAX */
ListBase ibufs; /* not written in file */
struct GPUTexture *gputexture; /* not written in file */
@@ -120,6 +120,7 @@ typedef struct Image {
#define IMA_DEPRECATED 64
#define IMA_OLD_PREMUL 128
#define IMA_CM_PREDIVIDE 256
+#define IMA_USED_FOR_RENDER 512
/* Image.tpageflag */
#define IMA_TILES 1
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index e310f148110..dca401f12e8 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -773,7 +773,7 @@ typedef struct OceanModifierData {
int bakestart;
int bakeend;
- char cachepath[240]; // FILE_MAX
+ char cachepath[1024]; // FILE_MAX
char foamlayername[64]; /* MAX_CUSTOMDATA_LAYER_NAME */
char cached;
char geometry_mode;
diff --git a/source/blender/makesdna/DNA_movieclip_types.h b/source/blender/makesdna/DNA_movieclip_types.h
index 5d2f2f5978f..1a56c273922 100644
--- a/source/blender/makesdna/DNA_movieclip_types.h
+++ b/source/blender/makesdna/DNA_movieclip_types.h
@@ -51,7 +51,7 @@ typedef struct MovieClipUser {
} MovieClipUser;
typedef struct MovieClipProxy {
- char dir[160]; /* custom directory for index and proxy files (defaults to BL_proxy) */
+ char dir[768]; /* custom directory for index and proxy files (defaults to BL_proxy) */
short tc; /* time code in use */
short quality; /* proxy build quality */
@@ -64,7 +64,7 @@ typedef struct MovieClipProxy {
typedef struct MovieClip {
ID id;
- char name[240]; /* file path */
+ char name[1024]; /* file path, 1024 = FILE_MAX */
int source; /* sequence or movie */
int lastframe; /* last accessed frame number */
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index fe4f6905f42..33ac75912fa 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -85,19 +85,21 @@ typedef struct bNodeSocket {
/* execution data */
short stack_index; /* local stack index */
- short stack_type; /* deprecated, kept for forward compatibility */
+ /* XXX deprecated, kept for forward compatibility */
+ short stack_type DNA_DEPRECATED;
int pad3;
void *cache; /* cached data from execution */
/* internal data to retrieve relations and groups */
int own_index; /* group socket identifiers, to find matching pairs after reading files */
- int to_index DNA_DEPRECATED; /* XXX deprecated, only used for restoring old group node links */
+ /* XXX deprecated, only used for restoring old group node links */
+ int to_index DNA_DEPRECATED;
struct bNodeSocket *groupsock;
struct bNodeLink *link; /* a link pointer, set in ntreeUpdateTree */
- /* DEPRECATED only needed for do_versions */
- bNodeStack ns; /* custom data for inputs, only UI writes in this */
+ /* XXX deprecated, socket input values are stored in default_value now. kept for forward compatibility */
+ bNodeStack ns DNA_DEPRECATED; /* custom data for inputs, only UI writes in this */
} bNodeSocket;
/* sock->type */
@@ -347,7 +349,7 @@ typedef struct NodeHueSat {
} NodeHueSat;
typedef struct NodeImageFile {
- char name[256];
+ char name[1024]; /* 1024 = FILE_MAX */
struct ImageFormatData im_format;
int sfra, efra;
} NodeImageFile;
diff --git a/source/blender/makesdna/DNA_object_fluidsim.h b/source/blender/makesdna/DNA_object_fluidsim.h
index 022dc53848f..3f87f8a3e9c 100644
--- a/source/blender/makesdna/DNA_object_fluidsim.h
+++ b/source/blender/makesdna/DNA_object_fluidsim.h
@@ -89,8 +89,8 @@ typedef struct FluidsimSettings {
struct Mesh *meshBB;
/* store output path, and file prefix for baked fluid surface */
- /* strlens; 80= FILE_MAXFILE, 160= FILE_MAXDIR */
- char surfdataPath[240];
+ /* strlens; 256= FILE_MAXFILE, 768= FILE_MAXDIR */
+ char surfdataPath[1024];
/* store start coords of axis aligned bounding box together with size */
/* values are inited during derived mesh display */
diff --git a/source/blender/makesdna/DNA_object_force.h b/source/blender/makesdna/DNA_object_force.h
index 28c28bbf329..1707c0d3929 100644
--- a/source/blender/makesdna/DNA_object_force.h
+++ b/source/blender/makesdna/DNA_object_force.h
@@ -195,7 +195,7 @@ typedef struct PointCache {
char name[64];
char prev_name[64];
char info[64];
- char path[240]; /* file path */
+ char path[1024]; /* file path, 1024 = FILE_MAX */
char *cached_frames; /* array of length endframe-startframe+1 with flags to indicate cached frames */
/* can be later used for other per frame flags too if needed */
struct ListBase mem_cache;
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index 5cb6fca7c5e..52cd9d3c09b 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -476,14 +476,14 @@ typedef struct RenderData {
float bake_maxdist, bake_biasdist, bake_pad;
/* path to render output */
- char pic[240];
+ char pic[1024]; /* 1024 = FILE_MAX */
/* stamps flags. */
int stamp;
short stamp_font_id, pad3; /* select one of blenders bitmap fonts */
/* stamp info user data. */
- char stamp_udata[160];
+ char stamp_udata[768];
/* foreground/background color. */
float fg_stamp[4];
@@ -676,10 +676,20 @@ typedef struct GameData {
#define GAME_MAT_MULTITEX 1
#define GAME_MAT_GLSL 2
-/* *************************************************************** */
+/* UV Paint */
+#define UV_SCULPT_LOCK_BORDERS 1
+#define UV_SCULPT_ALL_ISLANDS 2
+
+#define UV_SCULPT_TOOL_PINCH 1
+#define UV_SCULPT_TOOL_RELAX 2
+#define UV_SCULPT_TOOL_GRAB 3
+
+#define UV_SCULPT_TOOL_RELAX_LAPLACIAN 1
+#define UV_SCULPT_TOOL_RELAX_HC 2
+
/* Markers */
-typedef struct TimeMarker {
+typedef struct TimeMarker {
struct TimeMarker *next, *prev;
int frame;
char name[64];
@@ -785,6 +795,9 @@ typedef struct Sculpt {
int pad;
} Sculpt;
+typedef struct UvSculpt {
+ Paint paint;
+} UvSculpt;
/* ------------------------------------------- */
/* Vertex Paint */
@@ -860,6 +873,7 @@ typedef struct ToolSettings {
VPaint *vpaint; /* vertex paint */
VPaint *wpaint; /* weight paint */
Sculpt *sculpt;
+ UvSculpt *uvsculpt; /* uv smooth */
/* Vertex groups */
float vgroup_weight;
@@ -899,7 +913,7 @@ typedef struct ToolSettings {
short uvcalc_mapalign;
short uvcalc_flag;
short uv_flag, uv_selectmode;
- short uv_pad;
+ short uv_subsurf_level;
/* Grease Pencil */
short gpencil_flags;
@@ -971,10 +985,14 @@ typedef struct ToolSettings {
char auto_normalize; /*auto normalizing mode in wpaint*/
char multipaint; /* paint multiple bones in wpaint */
+ /* UV painting */
+ int use_uv_sculpt;
+ int uv_sculpt_settings;
+ int uv_sculpt_tool;
+ int uv_relax_method;
/* XXX: these sculpt_paint_* fields are deprecated, use the
unified_paint_settings field instead! */
- short sculpt_paint_settings DNA_DEPRECATED;
- short pad1;
+ short sculpt_paint_settings DNA_DEPRECATED; short pad1;
int sculpt_paint_unified_size DNA_DEPRECATED;
float sculpt_paint_unified_unprojected_radius DNA_DEPRECATED;
float sculpt_paint_unified_alpha DNA_DEPRECATED;
@@ -1427,6 +1445,7 @@ typedef enum SculptFlags {
#define UVCALC_FILLHOLES 1
#define UVCALC_NO_ASPECT_CORRECT 2 /* would call this UVCALC_ASPECT_CORRECT, except it should be default with old file */
#define UVCALC_TRANSFORM_CORRECT 4 /* adjust UV's while transforming to avoid distortion */
+#define UVCALC_USESUBSURF 8 /* Use mesh data after subsurf to compute UVs*/
/* toolsettings->uv_flag */
#define UV_SYNC_SELECTION 1
diff --git a/source/blender/makesdna/DNA_sequence_types.h b/source/blender/makesdna/DNA_sequence_types.h
index fa501de8d6d..20399e541d7 100644
--- a/source/blender/makesdna/DNA_sequence_types.h
+++ b/source/blender/makesdna/DNA_sequence_types.h
@@ -41,10 +41,10 @@ struct Ipo;
struct Scene;
struct bSound;
-/* strlens; 80= FILE_MAXFILE, 160= FILE_MAXDIR */
+/* strlens; 256= FILE_MAXFILE, 768= FILE_MAXDIR */
typedef struct StripElem {
- char name[80];
+ char name[256];
int orig_width, orig_height;
} StripElem;
@@ -71,10 +71,10 @@ typedef struct StripColorBalance {
} StripColorBalance;
typedef struct StripProxy {
- char dir[160]; // custom directory for index and proxy files
+ char dir[768]; // custom directory for index and proxy files
// (defaults to BL_proxy)
- char file[80]; // custom file
+ char file[256]; // custom file
struct anim *anim; // custom proxy anim file
short tc; // time code in use
@@ -91,7 +91,7 @@ typedef struct Strip {
int rt, len, us, done;
int startstill, endstill;
StripElem *stripdata;
- char dir[160];
+ char dir[768];
StripProxy *proxy;
StripCrop *crop;
StripTransform *transform;
@@ -100,7 +100,7 @@ typedef struct Strip {
typedef struct PluginSeq {
- char name[256];
+ char name[1024]; /* 1024 = FILE_MAX */
void *handle;
char *pname;
@@ -191,8 +191,8 @@ typedef struct Editing {
/* Context vars, used to be static */
Sequence *act_seq;
- char act_imagedir[256];
- char act_sounddir[256];
+ char act_imagedir[1024]; /* 1024 = FILE_MAX */
+ char act_sounddir[1024]; /* 1024 = FILE_MAX */
int over_ofs, over_cfra;
int over_flag, pad;
@@ -353,7 +353,7 @@ typedef struct SpeedControlVars {
*/
-#define SEQ_HAS_PATH(_seq) (ELEM5((_seq)->type, SEQ_MOVIE, SEQ_IMAGE, SEQ_SOUND, SEQ_RAM_SOUND, SEQ_HD_SOUND))
+#define SEQ_HAS_PATH(_seq) (ELEM4((_seq)->type, SEQ_MOVIE, SEQ_IMAGE, SEQ_RAM_SOUND, SEQ_HD_SOUND))
#endif
diff --git a/source/blender/makesdna/DNA_sound_types.h b/source/blender/makesdna/DNA_sound_types.h
index f530730a544..1dab9effa9e 100644
--- a/source/blender/makesdna/DNA_sound_types.h
+++ b/source/blender/makesdna/DNA_sound_types.h
@@ -49,7 +49,7 @@ typedef struct bSound {
/**
* The path to the sound file.
*/
- char name[240];
+ char name[1024]; /* 1024 = FILE_MAX */
/**
* The packed file.
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index aa7a84c577b..8f986a5f7cc 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -174,10 +174,11 @@ typedef struct SpaceSeq {
typedef struct FileSelectParams {
char title[32]; /* title, also used for the text of the execute button */
- char dir[240]; /* directory */
- char file[80]; /* file */
- char renamefile[80];
- char renameedit[80]; /* annoying but the first is only used for initialization */
+ char dir[1056]; /* directory, FILE_MAX_LIBEXTRA, 1024 + 32, this is for extreme case when 1023 length path
+ * needs to be linked in, where foo.blend/Armature need adding */
+ char file[256]; /* file */
+ char renamefile[256];
+ char renameedit[256]; /* annoying but the first is only used for initialization */
char filter_glob[64]; /* list of filetypes to filter */
@@ -343,8 +344,9 @@ typedef struct Script {
void *py_globaldict;
int flags, lastspace;
- char scriptname[256]; /* store the script file here so we can re-run it on loading blender, if "Enable Scripts" is on */
- char scriptarg[256];
+ /* store the script file here so we can re-run it on loading blender, if "Enable Scripts" is on */
+ char scriptname[1024]; /* 1024 = FILE_MAX */
+ char scriptarg[256]; /* 1024 = FILE_MAX */
} Script;
#define SCRIPT_SET_NULL(_script) _script->py_draw = _script->py_event = _script->py_button = _script->py_browsercallback = _script->py_globaldict = NULL; _script->flags = 0;
@@ -622,9 +624,11 @@ enum FileSortTypeE {
/* these values need to be hardcoded in structs, dna does not recognize defines */
/* also defined in BKE */
-#define FILE_MAXDIR 160
-#define FILE_MAXFILE 80
-#define FILE_MAX 240
+#define FILE_MAXDIR 768
+#define FILE_MAXFILE 256
+#define FILE_MAX 1024
+
+#define FILE_MAX_LIBEXTRA (FILE_MAX + 32)
/* filesel types */
#define FILE_UNIX 8
diff --git a/source/blender/makesdna/DNA_texture_types.h b/source/blender/makesdna/DNA_texture_types.h
index e711124d39c..de844fd2d7f 100644
--- a/source/blender/makesdna/DNA_texture_types.h
+++ b/source/blender/makesdna/DNA_texture_types.h
@@ -105,7 +105,7 @@ typedef unsigned short dna_ushort_fix;
#endif
typedef struct PluginTex {
- char name[160];
+ char name[1024];
void *handle;
char *pname;
@@ -200,7 +200,7 @@ typedef struct VoxelData {
struct Object *object; /* for rendering smoke sims */
float int_multiplier;
int still_frame;
- char source_path[240];
+ char source_path[1024]; /* 1024 = FILE_MAX */
/* temporary data */
float *dataset;
diff --git a/source/blender/makesdna/DNA_tracking_types.h b/source/blender/makesdna/DNA_tracking_types.h
index a8b3a7183cf..6ab8b5524ff 100644
--- a/source/blender/makesdna/DNA_tracking_types.h
+++ b/source/blender/makesdna/DNA_tracking_types.h
@@ -91,12 +91,8 @@ typedef struct MovieTrackingTrack {
float bundle_pos[3]; /* reconstructed position */
float error; /* average track reprojection error */
- int pad;
-
/* ** UI editing ** */
int flag, pat_flag, search_flag; /* flags (selection, ...) */
- short transflag; /* transform flags */
- char pad3[2];
float color[3]; /* custom color for track */
/* tracking algorithm to use; can be KLT or SAD */
@@ -213,7 +209,8 @@ enum {
/* MovieTrackingMarker->flag */
#define MARKER_DISABLED (1<<0)
#define MARKER_TRACKED (1<<1)
-#define MARKER_GRAPH_SEL (1<<2)
+#define MARKER_GRAPH_SEL_X (1<<2)
+#define MARKER_GRAPH_SEL_Y (1<<3)
/* MovieTrackingTrack->flag */
#define TRACK_HAS_BUNDLE (1<<1)
diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h
index 5be3799a419..cf7aa79de1b 100644
--- a/source/blender/makesdna/DNA_userdef_types.h
+++ b/source/blender/makesdna/DNA_userdef_types.h
@@ -60,7 +60,7 @@ struct ColorBand;
/* first font is the default (index 0), others optional */
typedef struct uiFont {
struct uiFont *next, *prev;
- char filename[256];
+ char filename[1024];/* 1024 = FILE_MAX */
short blf_id; /* from blfont lib */
short uifont_id; /* own id */
short r_to_l; /* fonts that read from left to right */
@@ -158,7 +158,7 @@ typedef struct ThemeUI {
uiPanelColors panel;
- char iconfile[80]; // FILE_MAXFILE length
+ char iconfile[256]; // FILE_MAXFILE length
float icon_alpha;
float pad;
@@ -253,7 +253,12 @@ typedef struct ThemeSpace {
char hpad[7];
char preview_back[4];
-
+ char preview_stitch_face[4];
+ char preview_stitch_edge[4];
+ char preview_stitch_vert[4];
+ char preview_stitch_stitchable[4];
+ char preview_stitch_unstitchable[4];
+ char preview_stitch_active[4];
} ThemeSpace;
@@ -319,16 +324,16 @@ typedef struct SolidLight {
typedef struct UserDef {
int flag, dupflag;
int savetime;
- char tempdir[160]; // FILE_MAXDIR length
- char fontdir[160];
- char renderdir[240]; // FILE_MAX length
- char textudir[160];
- char plugtexdir[160];
- char plugseqdir[160];
- char pythondir[160];
- char sounddir[160];
- char image_editor[240]; // FILE_MAX length
- char anim_player[240]; // FILE_MAX length
+ char tempdir[768]; /* FILE_MAXDIR length */
+ char fontdir[768];
+ char renderdir[1024]; /* FILE_MAX length */
+ char textudir[768];
+ char plugtexdir[768];
+ char plugseqdir[768];
+ char pythondir[768];
+ char sounddir[768];
+ char image_editor[1024]; /* 1024 = FILE_MAX */
+ char anim_player[1024]; /* 1024 = FILE_MAX */
int anim_player_preset;
short v2d_min_gridsize; /* minimum spacing between gridlines in View2D grids */
@@ -392,19 +397,17 @@ typedef struct UserDef {
short widget_unit; /* defaults to 20 for 72 DPI setting */
short anisotropic_filter;
- /*short pad[3]; */
+ short use_16bit_textures, pad8;
float ndof_sensitivity; /* overall sensitivity of 3D mouse */
int ndof_flag; /* flags for 3D mouse */
- char versemaster[160];
- char verseuser[160];
float glalphaclip;
short autokey_mode; /* autokeying mode */
short autokey_flag; /* flags for autokeying */
- short text_render, pad9[3]; /*options for text rendering*/
+ short text_render, pad9; /*options for text rendering*/
struct ColorBand coba_weight; /* from texture.h */
diff --git a/source/blender/makesdna/DNA_vfont_types.h b/source/blender/makesdna/DNA_vfont_types.h
index 7132751848d..d6168af6028 100644
--- a/source/blender/makesdna/DNA_vfont_types.h
+++ b/source/blender/makesdna/DNA_vfont_types.h
@@ -42,7 +42,7 @@ struct VFontData;
typedef struct VFont {
ID id;
- char name[256];
+ char name[1024]; /* 1024 = FILE_MAX */
struct VFontData *data;
struct PackedFile * packedfile;
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 3996e109b2c..7487a4429b1 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -451,6 +451,7 @@ extern StructRNA RNA_Scopes;
extern StructRNA RNA_Screen;
extern StructRNA RNA_ScrewModifier;
extern StructRNA RNA_Sculpt;
+extern StructRNA RNA_SelectedUvElement;
extern StructRNA RNA_Sensor;
extern StructRNA RNA_Sequence;
extern StructRNA RNA_SequenceColorBalance;
diff --git a/source/blender/makesrna/intern/SConscript b/source/blender/makesrna/intern/SConscript
index b74972b204c..26fa793de9d 100644
--- a/source/blender/makesrna/intern/SConscript
+++ b/source/blender/makesrna/intern/SConscript
@@ -101,6 +101,10 @@ if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'):
if env['WITH_BF_INTERNATIONAL']:
defs.append('WITH_INTERNATIONAL')
+if not env['BF_DEBUG']:
+ defs.append('NDEBUG')
+
+
makesrna_tool.Append(CPPDEFINES=defs)
makesrna_tool.Append (CPPPATH = Split(incs))
diff --git a/source/blender/makesrna/intern/rna_controller.c b/source/blender/makesrna/intern/rna_controller.c
index 5278c1e3532..7dfb3597a29 100644
--- a/source/blender/makesrna/intern/rna_controller.c
+++ b/source/blender/makesrna/intern/rna_controller.c
@@ -48,6 +48,7 @@ EnumPropertyItem controller_type_items[] ={
#ifdef RNA_RUNTIME
#include "BKE_sca.h"
+#include "DNA_actuator_types.h"
static struct StructRNA* rna_Controller_refine(struct PointerRNA *ptr)
{
@@ -132,6 +133,18 @@ static void rna_Controller_state_number_set(struct PointerRNA *ptr, const int va
cont->state_mask = (1 << (value - 1));
}
+static void rna_Controller_actuators_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+{
+ bController *cont = (bController *)ptr->data;
+ rna_iterator_array_begin(iter, cont->links, sizeof(bActuator *), (int)cont->totlinks, 0, NULL);
+}
+
+static int rna_Controller_actuators_length(PointerRNA *ptr)
+{
+ bController *cont = (bController *)ptr->data;
+ return (int) cont->totlinks;
+}
+
#if 0 /* editable is set to false, comment for now. */
static void rna_Controller_state_get(PointerRNA *ptr, int *values)
{
@@ -212,6 +225,12 @@ void RNA_def_controller(BlenderRNA *brna)
RNA_def_property_ui_icon(prop, ICON_BOOKMARKS, 1);
RNA_def_property_update(prop, NC_LOGIC, NULL);
+ prop= RNA_def_property(srna, "actuators", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "links", NULL);
+ RNA_def_property_struct_type(prop, "Actuator");
+ RNA_def_property_ui_text(prop, "Actuators", "The list containing the actuators connected to the controller");
+ RNA_def_property_collection_funcs(prop, "rna_Controller_actuators_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_dereference_get", "rna_Controller_actuators_length", NULL, NULL, NULL);
+
/* State */
// array of OB_MAX_STATES
diff --git a/source/blender/makesrna/intern/rna_dynamicpaint.c b/source/blender/makesrna/intern/rna_dynamicpaint.c
index 4886a4f30b1..95770685077 100644
--- a/source/blender/makesrna/intern/rna_dynamicpaint.c
+++ b/source/blender/makesrna/intern/rna_dynamicpaint.c
@@ -395,6 +395,10 @@ static void rna_def_canvas_surface(BlenderRNA *brna)
RNA_def_property_range(prop, 1.0, 10000.0);
RNA_def_property_ui_range(prop, 1.0, 10000.0, 5, 0);
RNA_def_property_ui_text(prop, "Dissolve Speed", "Approximately in how many frames should dissolve happen");
+
+ prop= RNA_def_property(srna, "use_drying", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_DPAINT_USE_DRYING);
+ RNA_def_property_ui_text(prop, "Dry", "Enable to make surface wetness dry over time");
prop= RNA_def_property(srna, "dry_speed", PROP_INT, PROP_NONE);
RNA_def_property_range(prop, 1.0, 10000.0);
@@ -443,6 +447,20 @@ static void rna_def_canvas_surface(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Anti-aliasing", "Use 5x multisampling to smoothen paint edges");
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_DynamicPaintSurface_reset");
+ prop= RNA_def_property(srna, "brush_influence_scale", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_sdna(prop, NULL, "influence_scale");
+ RNA_def_property_range(prop, 0.0, 1.0);
+ RNA_def_property_ui_range(prop, 0.0, 1.0, 1, 2);
+ RNA_def_property_ui_text(prop, "Influence Scale", "Adjust influence brush objects have on this surface");
+ RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_DynamicPaint_redoModifier");
+
+ prop= RNA_def_property(srna, "brush_radius_scale", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_sdna(prop, NULL, "radius_scale");
+ RNA_def_property_range(prop, 0.0, 10.0);
+ RNA_def_property_ui_range(prop, 0.0, 1.0, 1, 2);
+ RNA_def_property_ui_text(prop, "Radius Scale", "Adjust radius of proximity brushes or particles for this surface");
+ RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_DynamicPaint_redoModifier");
+
/*
* Initial Color
*/
@@ -454,6 +472,7 @@ static void rna_def_canvas_surface(BlenderRNA *brna)
RNA_def_property_update(prop, NC_MATERIAL|ND_SHADING_DRAW|ND_MODIFIER, "rna_DynamicPaintSurface_initialcolortype");
prop= RNA_def_property(srna, "init_color", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_array(prop, 4);
RNA_def_property_ui_text(prop, "Color", "Initial color of the surface");
RNA_def_property_update(prop, NC_MATERIAL|ND_SHADING_DRAW|ND_MODIFIER, "rna_DynamicPaintSurface_reset");
@@ -495,6 +514,12 @@ static void rna_def_canvas_surface(BlenderRNA *brna)
RNA_def_property_ui_range(prop, 0.01, 5.0, 1, 2);
RNA_def_property_ui_text(prop, "Spread Speed", "How fast spread effect moves on the canvas surface");
+ prop= RNA_def_property(srna, "color_dry_threshold", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_sdna(prop, NULL, "color_dry_threshold");
+ RNA_def_property_range(prop, 0.0, 1.0);
+ RNA_def_property_ui_range(prop, 0.0, 1.0, 1, 2);
+ RNA_def_property_ui_text(prop, "Color Dry", "The wetness level when colors start to shift to the background");
+
prop= RNA_def_property(srna, "color_spread_speed", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "color_spread_speed");
RNA_def_property_range(prop, 0.0, 2.0);
diff --git a/source/blender/makesrna/intern/rna_fluidsim.c b/source/blender/makesrna/intern/rna_fluidsim.c
index 428f56b5130..f853e7b8dd9 100644
--- a/source/blender/makesrna/intern/rna_fluidsim.c
+++ b/source/blender/makesrna/intern/rna_fluidsim.c
@@ -304,7 +304,7 @@ static void rna_def_fluidsim_domain(BlenderRNA *brna)
RNA_def_property_update(prop, 0, "rna_fluid_find_enframe");
prop= RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
- RNA_def_property_string_maxlength(prop, 240);
+ RNA_def_property_string_maxlength(prop, FILE_MAX);
RNA_def_property_string_sdna(prop, NULL, "surfdataPath");
RNA_def_property_ui_text(prop, "Path", "Directory (and/or filename prefix) to store baked fluid simulation files in");
RNA_def_property_update(prop, 0, "rna_fluid_update");
@@ -381,7 +381,7 @@ static void rna_def_fluidsim_domain(BlenderRNA *brna)
RNA_def_property_int_sdna(prop, NULL, "surfaceSubdivs");
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_range(prop, 0, 5);
- RNA_def_property_ui_text(prop, "Surface Subdivisions", "Number of isosurface subdivisions (this is necessary for the inclusion of particles into the surface generation - WARNING: can lead to longer computation times !)");
+ RNA_def_property_ui_text(prop, "Surface Subdivisions", "Number of isosurface subdivisions (this is necessary for the inclusion of particles into the surface generation - WARNING: can lead to longer computation times !)");
prop= RNA_def_property(srna, "use_speed_vectors", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "domainNovecgen", 0);
@@ -554,7 +554,7 @@ static void rna_def_fluidsim_particle(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Alpha Influence", "Amount of particle alpha change, inverse of size influence: 0=off (all same alpha), 1=full (large particles get lower alphas, smaller ones higher values)");
prop= RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
- RNA_def_property_string_maxlength(prop, 240);
+ RNA_def_property_string_maxlength(prop, FILE_MAX);
RNA_def_property_string_sdna(prop, NULL, "surfdataPath");
RNA_def_property_ui_text(prop, "Path", "Directory (and/or filename prefix) to store and load particles from");
RNA_def_property_update(prop, 0, "rna_fluid_update");
diff --git a/source/blender/makesrna/intern/rna_main.c b/source/blender/makesrna/intern/rna_main.c
index 2af4c04d1ce..d5f39dbd28a 100644
--- a/source/blender/makesrna/intern/rna_main.c
+++ b/source/blender/makesrna/intern/rna_main.c
@@ -32,6 +32,8 @@
#include "rna_internal.h"
+#include "BKE_utildefines.h"
+
#ifdef RNA_RUNTIME
#include "BKE_main.h"
@@ -330,7 +332,7 @@ void RNA_def_main(BlenderRNA *brna)
RNA_def_struct_ui_icon(srna, ICON_BLENDER);
prop= RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
- RNA_def_property_string_maxlength(prop, 240);
+ RNA_def_property_string_maxlength(prop, FILE_MAX);
RNA_def_property_string_funcs(prop, "rna_Main_filepath_get", "rna_Main_filepath_length", "rna_Main_filepath_set");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Filename", "Path to the .blend file");
diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c
index 74620b11d50..be4cfd583a9 100644
--- a/source/blender/makesrna/intern/rna_mesh.c
+++ b/source/blender/makesrna/intern/rna_mesh.c
@@ -1709,6 +1709,10 @@ static void rna_def_mesh_vertices(BlenderRNA *brna, PropertyRNA *cprop)
func= RNA_def_function(srna, "add", "ED_mesh_vertices_add");
RNA_def_function_flag(func, FUNC_USE_REPORTS);
RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of vertices to add", 0, INT_MAX);
+
+ func= RNA_def_function(srna, "remove", "ED_mesh_vertices_remove");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of vertices to remove", 0, INT_MAX);
}
/* mesh.edges */
@@ -1727,7 +1731,11 @@ static void rna_def_mesh_edges(BlenderRNA *brna, PropertyRNA *cprop)
func= RNA_def_function(srna, "add", "ED_mesh_edges_add");
RNA_def_function_flag(func, FUNC_USE_REPORTS);
- RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of vertices to add", 0, INT_MAX);
+ RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of edges to add", 0, INT_MAX);
+
+ func= RNA_def_function(srna, "remove", "ED_mesh_edges_remove");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of edges to remove", 0, INT_MAX);
}
/* mesh.faces */
@@ -1756,7 +1764,11 @@ static void rna_def_mesh_faces(BlenderRNA *brna, PropertyRNA *cprop)
func= RNA_def_function(srna, "add", "ED_mesh_faces_add");
RNA_def_function_flag(func, FUNC_USE_REPORTS);
- RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of vertices to add", 0, INT_MAX);
+ RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of faces to add", 0, INT_MAX);
+
+ func= RNA_def_function(srna, "remove", "ED_mesh_faces_remove");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of faces to remove", 0, INT_MAX);
}
/* mesh.vertex_colors */
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index a04ddec2098..989202f785c 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -3071,7 +3071,7 @@ static void rna_def_node_socket_subtype(BlenderRNA *brna, int type, int subtype,
};
#undef SUBTYPE
- #define SUBTYPE(socktype, stypename, id, idname) if (subtype==PROP_##id) propsubtype = PROP_##id;
+ #define SUBTYPE(socktype, stypename, id, idname) if (subtype == (PROP_##id)) propsubtype = PROP_##id;
NODE_DEFINE_SUBTYPES
#undef SUBTYPE
diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c
index 877da130357..0246e22d928 100644
--- a/source/blender/makesrna/intern/rna_object_api.c
+++ b/source/blender/makesrna/intern/rna_object_api.c
@@ -63,6 +63,7 @@
#include "BKE_font.h"
#include "BKE_mball.h"
#include "BKE_modifier.h"
+#include "BKE_cdderivedmesh.h"
#include "DNA_mesh_types.h"
#include "DNA_scene_types.h"
@@ -470,6 +471,44 @@ int rna_Object_is_modified(Object *ob, Scene *scene, int settings)
return object_is_modified(scene, ob) & settings;
}
+#ifndef NDEBUG
+void rna_Object_dm_info(struct Object *ob, int type, char *result)
+{
+ DerivedMesh *dm = NULL;
+ int dm_release = FALSE;
+ char *ret = NULL;
+
+ result[0] = '\0';
+
+ switch(type) {
+ case 0:
+ if (ob->type == OB_MESH) {
+ dm = CDDM_from_mesh(ob->data, ob);
+ ret = DM_debug_info(dm);
+ dm_release = TRUE;
+ }
+ break;
+ case 1:
+ dm = ob->derivedDeform;
+ break;
+ case 2:
+ dm = ob->derivedFinal;
+ break;
+ }
+
+ if (dm) {
+ ret = DM_debug_info(dm);
+ if (dm_release) {
+ dm->release(dm);
+ }
+ if (ret) {
+ strcpy(result, ret);
+ MEM_freeN(ret);
+ }
+ }
+}
+#endif /* NDEBUG */
+
#else
void RNA_api_object(StructRNA *srna)
@@ -483,6 +522,15 @@ void RNA_api_object(StructRNA *srna)
{0, NULL, 0, NULL, NULL}
};
+#ifndef NDEBUG
+ static EnumPropertyItem mesh_dm_info_items[] = {
+ {0, "SOURCE", 0, "Source", "Source mesh"},
+ {1, "DEFORM", 0, "Deform", "Objects deform mesh"},
+ {2, "FINAL", 0, "Final", "Objects final mesh"},
+ {0, NULL, 0, NULL, NULL}
+ };
+#endif
+
/* mesh */
func= RNA_def_function(srna, "to_mesh", "rna_Object_to_mesh");
RNA_def_function_ui_description(func, "Create a Mesh datablock with modifiers applied");
@@ -585,6 +633,20 @@ void RNA_api_object(StructRNA *srna)
RNA_def_property_flag(parm, PROP_REQUIRED);
parm= RNA_def_boolean(func, "result", 0, "", "Object visibility");
RNA_def_function_return(func, parm);
+
+
+#ifndef NDEBUG
+ /* mesh */
+ func= RNA_def_function(srna, "dm_info", "rna_Object_dm_info");
+ RNA_def_function_ui_description(func, "Returns a string for derived mesh data");
+
+ parm= RNA_def_enum(func, "type", mesh_dm_info_items, 0, "", "Modifier settings to apply");
+ RNA_def_property_flag(parm, PROP_REQUIRED);
+ /* weak!, no way to return dynamic string type */
+ parm= RNA_def_string(func, "result", "result", 16384, "result", "");
+ RNA_def_property_flag(parm, PROP_THICK_WRAP); /* needed for string return value */
+ RNA_def_function_output(func, parm);
+#endif /* NDEBUG */
}
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index e8b6e9e05d3..9be42ad13af 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -64,6 +64,18 @@
#include "BLI_threads.h"
+EnumPropertyItem uv_sculpt_relaxation_items[] = {
+ {UV_SCULPT_TOOL_RELAX_LAPLACIAN, "LAPLACIAN", 0, "Laplacian", "Use Laplacian method for relaxation"},
+ {UV_SCULPT_TOOL_RELAX_HC, "HC", 0, "HC", "Use HC method for relaxation"},
+ {0, NULL, 0, NULL, NULL}};
+
+EnumPropertyItem uv_sculpt_tool_items[] = {
+ {UV_SCULPT_TOOL_PINCH, "PINCH", 0, "Pinch", "Pinch UVs"},
+ {UV_SCULPT_TOOL_RELAX, "RELAX", 0, "Relax", "Relax UVs"},
+ {UV_SCULPT_TOOL_GRAB, "GRAB", 0, "Grab", "Grab UVs"},
+ {0, NULL, 0, NULL, NULL}};
+
+
EnumPropertyItem snap_target_items[] = {
{SCE_SNAP_TARGET_CLOSEST, "CLOSEST", 0, "Closest", "Snap closest point onto target"},
{SCE_SNAP_TARGET_CENTER, "CENTER", 0, "Center", "Snap center onto target"},
@@ -268,11 +280,17 @@ EnumPropertyItem image_color_depth_items[] = {
#include "ED_view3d.h"
#include "ED_mesh.h"
#include "ED_keyframing.h"
+#include "ED_image.h"
#include "RE_engine.h"
#include "FRS_freestyle.h"
+static void rna_SpaceImageEditor_uv_sculpt_update(Main *bmain, Scene *scene, PointerRNA *UNUSED(ptr))
+{
+ ED_space_image_uv_sculpt_update(bmain->wm.first, scene->toolsettings);
+}
+
static int rna_Scene_object_bases_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr)
{
Scene *scene= (Scene*)ptr->data;
@@ -872,6 +890,7 @@ static EnumPropertyItem *rna_RenderSettings_qtcodecsettings_audiocodecType_itemf
#endif
#endif
+#ifdef WITH_FFMPEG
static void rna_FFmpegSettings_lossless_output_set(PointerRNA *ptr, int value)
{
Scene *scene = (Scene *) ptr->id.data;
@@ -881,10 +900,9 @@ static void rna_FFmpegSettings_lossless_output_set(PointerRNA *ptr, int value)
rd->ffcodecdata.flags |= FFMPEG_LOSSLESS_OUTPUT;
else
rd->ffcodecdata.flags &= ~FFMPEG_LOSSLESS_OUTPUT;
-#ifdef WITH_FFMPEG
ffmpeg_verify_lossless_format(rd, &rd->im_format);
-#endif
}
+#endif
static int rna_RenderSettings_active_layer_index_get(PointerRNA *ptr)
{
@@ -1476,10 +1494,38 @@ static void rna_def_tool_settings(BlenderRNA *brna)
RNA_def_property_pointer_sdna(prop, NULL, "imapaint");
RNA_def_property_ui_text(prop, "Image Paint", "");
+ prop= RNA_def_property(srna, "uv_sculpt", PROP_POINTER, PROP_NONE);
+ RNA_def_property_pointer_sdna(prop, NULL, "uvsculpt");
+ RNA_def_property_ui_text(prop, "UV Sculpt", "");
+
prop= RNA_def_property(srna, "particle_edit", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "particle");
RNA_def_property_ui_text(prop, "Particle Edit", "");
+ prop= RNA_def_property(srna, "use_uv_sculpt", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "use_uv_sculpt", 1);
+ RNA_def_property_ui_text(prop, "UV Sculpt", "Enable brush for uv sculpting");
+ RNA_def_property_ui_icon(prop, ICON_TPAINT_HLT, 0);
+ RNA_def_property_update(prop, NC_SPACE|ND_SPACE_IMAGE, "rna_SpaceImageEditor_uv_sculpt_update");
+
+ prop= RNA_def_property(srna, "uv_sculpt_lock_borders", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "uv_sculpt_settings", UV_SCULPT_LOCK_BORDERS);
+ RNA_def_property_ui_text(prop, "Lock Borders", "Disables editing of boundary edges");
+
+ prop= RNA_def_property(srna, "uv_sculpt_all_islands", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "uv_sculpt_settings", UV_SCULPT_ALL_ISLANDS);
+ RNA_def_property_ui_text(prop, "Sculpt All Islands", "Brush operates on all islands");
+
+ prop= RNA_def_property(srna, "uv_sculpt_tool", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "uv_sculpt_tool");
+ RNA_def_property_enum_items(prop, uv_sculpt_tool_items);
+ RNA_def_property_ui_text(prop, "UV Sculpt Tools", "Select Tools for the UV sculpt brushes");
+
+ prop= RNA_def_property(srna, "uv_relax_method", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "uv_relax_method");
+ RNA_def_property_enum_items(prop, uv_sculpt_relaxation_items);
+ RNA_def_property_ui_text(prop, "Relaxation Method", "Algorithm used for UV relaxation");
+
/* Transform */
prop= RNA_def_property(srna, "proportional_edit", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "proportional");
@@ -4285,6 +4331,28 @@ static void rna_def_scene_keying_sets_all(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_property_update(prop, NC_SCENE|ND_KEYINGSET, NULL);
}
+/* Runtime property, used to remember uv indices, used only in UV stitch for now.
+ */
+static void rna_def_selected_uv_element(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna= RNA_def_struct(brna, "SelectedUvElement", "PropertyGroup");
+ RNA_def_struct_ui_text(srna, "Selected Uv Element", "");
+
+ /* store the index to the UV element selected */
+ prop= RNA_def_property(srna, "element_index", PROP_INT, PROP_UNSIGNED);
+ RNA_def_property_flag(prop, PROP_IDPROPERTY);
+ RNA_def_property_ui_text(prop, "Element Index", "");
+
+ prop= RNA_def_property(srna, "face_index", PROP_INT, PROP_UNSIGNED);
+ RNA_def_property_flag(prop, PROP_IDPROPERTY);
+ RNA_def_property_ui_text(prop, "Face Index", "");
+}
+
+
+
void RNA_def_scene(BlenderRNA *brna)
{
StructRNA *srna;
@@ -4618,6 +4686,7 @@ void RNA_def_scene(BlenderRNA *brna)
rna_def_scene_game_data(brna);
rna_def_scene_render_layer(brna);
rna_def_transform_orientation(brna);
+ rna_def_selected_uv_element(brna);
/* Scene API */
RNA_api_scene(srna);
diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c b/source/blender/makesrna/intern/rna_sculpt_paint.c
index cd929d3aeda..67304997571 100644
--- a/source/blender/makesrna/intern/rna_sculpt_paint.c
+++ b/source/blender/makesrna/intern/rna_sculpt_paint.c
@@ -289,6 +289,16 @@ static void rna_def_sculpt(BlenderRNA *brna)
RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Sculpt_update");
}
+
+static void rna_def_uv_sculpt(BlenderRNA *brna)
+{
+ StructRNA *srna;
+
+ srna= RNA_def_struct(brna, "UvSculpt", "Paint");
+ RNA_def_struct_ui_text(srna, "UV Sculpting", "");
+}
+
+
/* use for weight paint too */
static void rna_def_vertex_paint(BlenderRNA *brna)
{
@@ -466,12 +476,12 @@ static void rna_def_particle_edit(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Brush", "");
prop= RNA_def_property(srna, "draw_step", PROP_INT, PROP_NONE);
- RNA_def_property_range(prop, 2, 10);
+ RNA_def_property_range(prop, 1, 10);
RNA_def_property_ui_text(prop, "Steps", "How many steps to draw the path with");
RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_ParticleEdit_redo");
prop= RNA_def_property(srna, "fade_frames", PROP_INT, PROP_NONE);
- RNA_def_property_range(prop, 2, 100);
+ RNA_def_property_range(prop, 1, 100);
RNA_def_property_ui_text(prop, "Frames", "How many frames to fade");
RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_ParticleEdit_update");
@@ -548,6 +558,7 @@ void RNA_def_sculpt_paint(BlenderRNA *brna)
{
rna_def_paint(brna);
rna_def_sculpt(brna);
+ rna_def_uv_sculpt(brna);
rna_def_vertex_paint(brna);
rna_def_image_paint(brna);
rna_def_particle_edit(brna);
diff --git a/source/blender/makesrna/intern/rna_sensor.c b/source/blender/makesrna/intern/rna_sensor.c
index 6459c145a3a..4413eee9395 100644
--- a/source/blender/makesrna/intern/rna_sensor.c
+++ b/source/blender/makesrna/intern/rna_sensor.c
@@ -61,6 +61,7 @@ EnumPropertyItem sensor_type_items[] ={
#ifdef RNA_RUNTIME
#include "BKE_sca.h"
+#include "DNA_controller_types.h"
static StructRNA* rna_Sensor_refine(struct PointerRNA *ptr)
{
@@ -125,6 +126,19 @@ static void rna_Sensor_type_set(struct PointerRNA *ptr, int value)
}
/* Always keep in alphabetical order */
+
+static void rna_Sensor_controllers_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+{
+ bSensor *sens = (bSensor *)ptr->data;
+ rna_iterator_array_begin(iter, sens->links, sizeof(bController *), (int)sens->totlinks, 0, NULL);
+}
+
+static int rna_Sensor_controllers_length(PointerRNA *ptr)
+{
+ bSensor *sens = (bSensor *)ptr->data;
+ return (int) sens->totlinks;
+}
+
EnumPropertyItem *rna_Sensor_type_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), int *free)
{
EnumPropertyItem *item= NULL;
@@ -327,6 +341,13 @@ static void rna_def_sensor(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Tap", "Trigger controllers only for an instant, even while the sensor remains true");
RNA_def_property_update(prop, NC_LOGIC, NULL);
+ prop= RNA_def_property(srna, "controllers", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "links", NULL);
+ RNA_def_property_struct_type(prop, "Controller");
+ RNA_def_property_ui_text(prop, "Controllers", "The list containing the controllers connected to the sensor");
+ RNA_def_property_collection_funcs(prop, "rna_Sensor_controllers_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_dereference_get", "rna_Sensor_controllers_length", NULL, NULL, NULL);
+
+
RNA_api_sensor(srna);
}
diff --git a/source/blender/makesrna/intern/rna_tracking.c b/source/blender/makesrna/intern/rna_tracking.c
index 01f3889d684..5573ceccf8f 100644
--- a/source/blender/makesrna/intern/rna_tracking.c
+++ b/source/blender/makesrna/intern/rna_tracking.c
@@ -1232,7 +1232,7 @@ static void rna_def_trackingObjects(BlenderRNA *brna, PropertyRNA *cprop)
func= RNA_def_function(srna, "remove", "rna_trackingObject_remove");
RNA_def_function_ui_description(func, "Remove tracking object from this movie clip");
- parm= RNA_def_pointer(func, "object", "MovieTrackingObject", "", "Motion tracking object to be removed");
+ RNA_def_pointer(func, "object", "MovieTrackingObject", "", "Motion tracking object to be removed");
/* active object */
prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c
index be0fec41aa1..8e3178a6298 100644
--- a/source/blender/makesrna/intern/rna_ui.c
+++ b/source/blender/makesrna/intern/rna_ui.c
@@ -823,7 +823,7 @@ static void rna_def_menu(BlenderRNA *brna)
"class name is \"OBJECT_MT_hello\", and bl_idname is not set by the "
"script, then bl_idname = \"OBJECT_MT_hello\")");
- prop= RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
+ prop= RNA_def_property(srna, "bl_label", PROP_STRING, PROP_TRANSLATE);
RNA_def_property_string_sdna(prop, NULL, "type->label");
RNA_def_property_flag(prop, PROP_REGISTER);
RNA_def_property_ui_text(prop, "Label", "The menu label");
diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c
index 160787556ed..dad58ddbef6 100644
--- a/source/blender/makesrna/intern/rna_userdef.c
+++ b/source/blender/makesrna/intern/rna_userdef.c
@@ -37,6 +37,7 @@
#include "DNA_userdef_types.h"
#include "DNA_brush_types.h"
#include "DNA_view3d_types.h"
+#include "DNA_scene_types.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -147,6 +148,12 @@ static void rna_userdef_gl_texture_limit_update(Main *bmain, Scene *scene, Point
rna_userdef_update(bmain, scene, ptr);
}
+static void rna_userdef_gl_use_16bit_textures(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+ GPU_free_images();
+ rna_userdef_update(bmain, scene, ptr);
+}
+
static void rna_userdef_select_mouse_set(PointerRNA *ptr,int value)
{
UserDef *userdef = (UserDef*)ptr->data;
@@ -1633,6 +1640,42 @@ static void rna_def_userdef_theme_space_image(BlenderRNA *brna)
RNA_def_property_array(prop, 4);
RNA_def_property_ui_text(prop, "Scope region background color", "");
RNA_def_property_update(prop, 0, "rna_userdef_update");
+
+ prop= RNA_def_property(srna, "preview_stitch_face", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_float_sdna(prop, NULL, "preview_stitch_face");
+ RNA_def_property_array(prop, 4);
+ RNA_def_property_ui_text(prop, "Stitch preview face color", "");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
+
+ prop= RNA_def_property(srna, "preview_stitch_edge", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_float_sdna(prop, NULL, "preview_stitch_edge");
+ RNA_def_property_array(prop, 4);
+ RNA_def_property_ui_text(prop, "Stitch preview edge color", "");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
+
+ prop= RNA_def_property(srna, "preview_stitch_vert", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_float_sdna(prop, NULL, "preview_stitch_vert");
+ RNA_def_property_array(prop, 4);
+ RNA_def_property_ui_text(prop, "Stitch preview vertex color", "");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
+
+ prop= RNA_def_property(srna, "preview_stitch_stitchable", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_float_sdna(prop, NULL, "preview_stitch_stitchable");
+ RNA_def_property_array(prop, 4);
+ RNA_def_property_ui_text(prop, "Stitch preview stitchable color", "");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
+
+ prop= RNA_def_property(srna, "preview_stitch_unstitchable", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_float_sdna(prop, NULL, "preview_stitch_unstitchable");
+ RNA_def_property_array(prop, 4);
+ RNA_def_property_ui_text(prop, "Stitch preview unstitchable color", "");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
+
+ prop= RNA_def_property(srna, "preview_stitch_active", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_float_sdna(prop, NULL, "preview_stitch_active");
+ RNA_def_property_array(prop, 4);
+ RNA_def_property_ui_text(prop, "Stitch preview active island", "");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
}
static void rna_def_userdef_theme_space_seq(BlenderRNA *brna)
@@ -2910,6 +2953,11 @@ static void rna_def_userdef_system(BlenderRNA *brna)
"Scale textures for the 3D View (looks nicer but uses more memory and slows image reloading)");
RNA_def_property_update(prop, 0, "rna_userdef_mipmap_update");
+ prop= RNA_def_property(srna, "use_16bit_textures", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "use_16bit_textures", 1);
+ RNA_def_property_ui_text(prop, "16 Bit Float Textures", "Use 16 bit per component texture for float images");
+ RNA_def_property_update(prop, 0, "rna_userdef_gl_use_16bit_textures");
+
prop= RNA_def_property(srna, "use_vertex_buffer_objects", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "gameflags", USER_DISABLE_VBO);
RNA_def_property_ui_text(prop, "VBOs", "Use Vertex Buffer Objects (or Vertex Arrays, if unsupported) for viewport rendering");
diff --git a/source/blender/modifiers/intern/MOD_boolean.c b/source/blender/modifiers/intern/MOD_boolean.c
index e502878fca5..16f0912bd9b 100644
--- a/source/blender/modifiers/intern/MOD_boolean.c
+++ b/source/blender/modifiers/intern/MOD_boolean.c
@@ -47,7 +47,6 @@
#include "MOD_boolean_util.h"
#include "MOD_util.h"
-
static void copyData(ModifierData *md, ModifierData *target)
{
BooleanModifierData *bmd = (BooleanModifierData*) md;
diff --git a/source/blender/modifiers/intern/MOD_build.c b/source/blender/modifiers/intern/MOD_build.c
index 119934ea2f0..ebb5bd9ab9b 100644
--- a/source/blender/modifiers/intern/MOD_build.c
+++ b/source/blender/modifiers/intern/MOD_build.c
@@ -76,135 +76,150 @@ static int dependsOnTime(ModifierData *UNUSED(md))
}
static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
- DerivedMesh *derivedData,
- int UNUSED(useRenderParams),
- int UNUSED(isFinalCalc))
+ DerivedMesh *derivedData,
+ int UNUSED(useRenderParams),
+ int UNUSED(isFinalCalc))
{
DerivedMesh *dm = derivedData;
DerivedMesh *result;
BuildModifierData *bmd = (BuildModifierData*) md;
int i;
- int numFaces, numEdges;
+ int numFaces_dst, numEdges_dst;
int *vertMap, *edgeMap, *faceMap;
float frac;
GHashIterator *hashIter;
/* maps vert indices in old mesh to indices in new mesh */
GHash *vertHash = BLI_ghash_new(BLI_ghashutil_inthash,
- BLI_ghashutil_intcmp, "build ve apply gh");
+ BLI_ghashutil_intcmp, "build ve apply gh");
/* maps edge indices in new mesh to indices in old mesh */
GHash *edgeHash = BLI_ghash_new(BLI_ghashutil_inthash,
- BLI_ghashutil_intcmp, "build ed apply gh");
+ BLI_ghashutil_intcmp, "build ed apply gh");
- const int maxVerts= dm->getNumVerts(dm);
- const int maxEdges= dm->getNumEdges(dm);
- const int maxFaces= dm->getNumFaces(dm);
+ const int numVert_src= dm->getNumVerts(dm);
+ const int numEdge_src= dm->getNumEdges(dm);
+ const int numFace_src= dm->getNumFaces(dm);
- vertMap = MEM_callocN(sizeof(*vertMap) * maxVerts, "build modifier vertMap");
- for(i = 0; i < maxVerts; ++i) vertMap[i] = i;
- edgeMap = MEM_callocN(sizeof(*edgeMap) * maxEdges, "build modifier edgeMap");
- for(i = 0; i < maxEdges; ++i) edgeMap[i] = i;
- faceMap = MEM_callocN(sizeof(*faceMap) * maxFaces, "build modifier faceMap");
- for(i = 0; i < maxFaces; ++i) faceMap[i] = i;
+ vertMap = MEM_callocN(sizeof(*vertMap) * numVert_src, "build modifier vertMap");
+ for (i = 0; i < numVert_src; i++) vertMap[i] = i;
+ edgeMap = MEM_callocN(sizeof(*edgeMap) * numEdge_src, "build modifier edgeMap");
+ for (i = 0; i < numEdge_src; i++) edgeMap[i] = i;
+ faceMap = MEM_callocN(sizeof(*faceMap) * numFace_src, "build modifier faceMap");
+ for (i = 0; i < numFace_src; i++) faceMap[i] = i;
frac = (BKE_curframe(md->scene) - bmd->start) / bmd->length;
CLAMP(frac, 0.0f, 1.0f);
- numFaces = dm->getNumFaces(dm) * frac;
- numEdges = dm->getNumEdges(dm) * frac;
+ numFaces_dst = dm->getNumFaces(dm) * frac;
+ numEdges_dst = dm->getNumEdges(dm) * frac;
/* if there's at least one face, build based on faces */
- if(numFaces) {
- if(bmd->randomize)
+ if (numFaces_dst) {
+ if (bmd->randomize) {
BLI_array_randomize(faceMap, sizeof(*faceMap),
- maxFaces, bmd->seed);
+ numFace_src, bmd->seed);
+ }
/* get the set of all vert indices that will be in the final mesh,
- * mapped to the new indices
- */
- for(i = 0; i < numFaces; ++i) {
+ * mapped to the new indices
+ */
+ for (i = 0; i < numFaces_dst; i++) {
MFace mf;
dm->getFace(dm, faceMap[i], &mf);
- if(!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v1)))
+ if (!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v1))) {
BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(mf.v1),
- SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
- if(!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v2)))
+ SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
+ }
+ if (!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v2))) {
BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(mf.v2),
- SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
- if(!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v3)))
+ SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
+ }
+ if (!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v3))) {
BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(mf.v3),
- SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
- if(mf.v4 && !BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v4)))
+ SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
+ }
+ if (mf.v4 && !BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v4))) {
BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(mf.v4),
- SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
+ SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
+ }
}
/* get the set of edges that will be in the new mesh (i.e. all edges
- * that have both verts in the new mesh)
- */
- for(i = 0; i < maxEdges; ++i) {
+ * that have both verts in the new mesh)
+ */
+ for (i = 0; i < numEdge_src; i++) {
MEdge me;
dm->getEdge(dm, i, &me);
- if(BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me.v1))
- && BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me.v2)))
- BLI_ghash_insert(edgeHash,
- SET_INT_IN_POINTER(BLI_ghash_size(edgeHash)), SET_INT_IN_POINTER(i));
+ if ( BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me.v1)) &&
+ BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me.v2)))
+ {
+ BLI_ghash_insert(edgeHash, SET_INT_IN_POINTER(BLI_ghash_size(edgeHash)),
+ SET_INT_IN_POINTER(i));
+ }
}
- } else if(numEdges) {
- if(bmd->randomize)
+ }
+ else if (numEdges_dst) {
+ if (bmd->randomize) {
BLI_array_randomize(edgeMap, sizeof(*edgeMap),
- maxEdges, bmd->seed);
+ numEdge_src, bmd->seed);
+ }
/* get the set of all vert indices that will be in the final mesh,
- * mapped to the new indices
- */
- for(i = 0; i < numEdges; ++i) {
+ * mapped to the new indices
+ */
+ for (i = 0; i < numEdges_dst; i++) {
MEdge me;
dm->getEdge(dm, edgeMap[i], &me);
- if(!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me.v1)))
+ if (!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me.v1))) {
BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(me.v1),
- SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
- if(!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me.v2)))
+ SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
+ }
+ if (!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me.v2))) {
BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(me.v2),
- SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
+ SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
+ }
}
/* get the set of edges that will be in the new mesh
- */
- for(i = 0; i < numEdges; ++i) {
+ */
+ for (i = 0; i < numEdges_dst; i++) {
MEdge me;
dm->getEdge(dm, edgeMap[i], &me);
BLI_ghash_insert(edgeHash, SET_INT_IN_POINTER(BLI_ghash_size(edgeHash)),
- SET_INT_IN_POINTER(edgeMap[i]));
+ SET_INT_IN_POINTER(edgeMap[i]));
}
- } else {
+ }
+ else {
int numVerts = dm->getNumVerts(dm) * frac;
- if(bmd->randomize)
+ if (bmd->randomize) {
BLI_array_randomize(vertMap, sizeof(*vertMap),
- maxVerts, bmd->seed);
+ numVert_src, bmd->seed);
+ }
/* get the set of all vert indices that will be in the final mesh,
* mapped to the new indices
*/
- for(i = 0; i < numVerts; ++i)
- BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(vertMap[i]), SET_INT_IN_POINTER(i));
+ for (i = 0; i < numVerts; i++) {
+ BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(vertMap[i]),
+ SET_INT_IN_POINTER(i));
+ }
}
/* now we know the number of verts, edges and faces, we can create
- * the mesh
- */
+ * the mesh
+ */
result = CDDM_from_template(dm, BLI_ghash_size(vertHash),
- BLI_ghash_size(edgeHash), numFaces);
+ BLI_ghash_size(edgeHash), numFaces_dst);
/* copy the vertices across */
- for( hashIter = BLI_ghashIterator_new(vertHash);
- !BLI_ghashIterator_isDone(hashIter);
- BLI_ghashIterator_step(hashIter)
- ) {
+ for ( hashIter = BLI_ghashIterator_new(vertHash);
+ !BLI_ghashIterator_isDone(hashIter);
+ BLI_ghashIterator_step(hashIter))
+ {
MVert source;
MVert *dest;
int oldIndex = GET_INT_FROM_POINTER(BLI_ghashIterator_getKey(hashIter));
@@ -219,7 +234,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
BLI_ghashIterator_free(hashIter);
/* copy the edges across, remapping indices */
- for(i = 0; i < BLI_ghash_size(edgeHash); ++i) {
+ for (i = 0; i < BLI_ghash_size(edgeHash); i++) {
MEdge source;
MEdge *dest;
int oldIndex = GET_INT_FROM_POINTER(BLI_ghash_lookup(edgeHash, SET_INT_IN_POINTER(i)));
@@ -235,7 +250,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
}
/* copy the faces across, remapping indices */
- for(i = 0; i < numFaces; ++i) {
+ for (i = 0; i < numFaces_dst; i++) {
MFace source;
MFace *dest;
int orig_v4;
@@ -248,7 +263,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
source.v1 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v1)));
source.v2 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v2)));
source.v3 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v3)));
- if(source.v4)
+ if (source.v4)
source.v4 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v4)));
DM_copy_face_data(dm, result, faceMap[i], i, 1);
@@ -258,14 +273,14 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
}
CDDM_calc_normals(result);
-
+
BLI_ghash_free(vertHash, NULL, NULL);
BLI_ghash_free(edgeHash, NULL, NULL);
MEM_freeN(vertMap);
MEM_freeN(edgeMap);
MEM_freeN(faceMap);
-
+
return result;
}
diff --git a/source/blender/modifiers/intern/MOD_solidify.c b/source/blender/modifiers/intern/MOD_solidify.c
index 99f5117e3cd..d16fa0c503c 100644
--- a/source/blender/modifiers/intern/MOD_solidify.c
+++ b/source/blender/modifiers/intern/MOD_solidify.c
@@ -583,7 +583,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
/* faces */
mf= mface + (numFaces * 2);
- origindex= result->getFaceDataArray(result, CD_ORIGINDEX);
+
for(i=0; i<newFaces; i++, mf++) {
int eidx= new_edge_arr[i];
int fidx= edge_users[eidx];
diff --git a/source/blender/nodes/NOD_socket.h b/source/blender/nodes/NOD_socket.h
index 6a6413d508f..fb3946bae6c 100644
--- a/source/blender/nodes/NOD_socket.h
+++ b/source/blender/nodes/NOD_socket.h
@@ -47,26 +47,19 @@ struct bNodeStack;
void node_socket_type_init(struct bNodeSocketType *types[]);
-struct bNodeSocket *nodeAddInputInt(struct bNodeTree *ntree, struct bNode *node, const char *name, PropertySubType subtype, int value, int min, int max);
-struct bNodeSocket *nodeAddOutputInt(struct bNodeTree *ntree, struct bNode *node, const char *name);
-
-struct bNodeSocket *nodeAddInputFloat(struct bNodeTree *ntree, struct bNode *node, const char *name, PropertySubType subtype, float value, float min, float max);
-struct bNodeSocket *nodeAddOutputFloat(struct bNodeTree *ntree, struct bNode *node, const char *name);
-
-struct bNodeSocket *nodeAddInputBoolean(struct bNodeTree *ntree, struct bNode *node, const char *name, char value);
-struct bNodeSocket *nodeAddOutputBoolean(struct bNodeTree *ntree, struct bNode *node, const char *name);
-
-struct bNodeSocket *nodeAddInputVector(struct bNodeTree *ntree, struct bNode *node, const char *name, PropertySubType subtype, float x, float y, float z, float min, float max);
-struct bNodeSocket *nodeAddOutputVector(struct bNodeTree *ntree, struct bNode *node, const char *name);
-
-struct bNodeSocket *nodeAddInputRGBA(struct bNodeTree *ntree, struct bNode *node, const char *name, float r, float g, float b, float a);
-struct bNodeSocket *nodeAddOutputRGBA(struct bNodeTree *ntree, struct bNode *node, const char *name);
-
-struct bNodeSocket *nodeAddInputShader(struct bNodeTree *ntree, struct bNode *node, const char *name);
-struct bNodeSocket *nodeAddOutputShader(struct bNodeTree *ntree, struct bNode *node, const char *name);
-
-struct bNodeSocket *nodeAddInputMesh(struct bNodeTree *ntree, struct bNode *node, const char *name);
-struct bNodeSocket *nodeAddOutputMesh(struct bNodeTree *ntree, struct bNode *node, const char *name);
+void *node_socket_make_default_value(int type);
+void node_socket_free_default_value(int type, void *default_value);
+void node_socket_init_default_value(int type, void *default_value);
+void node_socket_copy_default_value(int type, void *to_default_value, void *from_default_value);
+void node_socket_convert_default_value(int to_type, void *to_default_value, int from_type, void *from_default_value);
+
+void node_socket_set_default_value_int(void *default_value, PropertySubType subtype, int value, int min, int max);
+void node_socket_set_default_value_float(void *default_value, PropertySubType subtype, float value, float min, float max);
+void node_socket_set_default_value_boolean(void *default_value, char value);
+void node_socket_set_default_value_vector(void *default_value, PropertySubType subtype, float x, float y, float z, float min, float max);
+void node_socket_set_default_value_rgba(void *default_value, float r, float g, float b, float a);
+void node_socket_set_default_value_shader(void *default_value);
+void node_socket_set_default_value_mesh(void *default_value);
struct bNodeSocket *node_add_input_from_template(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocketTemplate *stemp);
struct bNodeSocket *node_add_output_from_template(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocketTemplate *stemp);
diff --git a/source/blender/nodes/intern/node_common.c b/source/blender/nodes/intern/node_common.c
index 5a6cebb51ce..e5571b19614 100644
--- a/source/blender/nodes/intern/node_common.c
+++ b/source/blender/nodes/intern/node_common.c
@@ -100,8 +100,8 @@ bNodeSocket *node_group_add_extern_socket(bNodeTree *UNUSED(ntree), ListBase *lb
sock->groupsock = gsock;
sock->limit = (in_out==SOCK_IN ? 1 : 0xFFF);
- if (gsock->default_value)
- sock->default_value = MEM_dupallocN(gsock->default_value);
+ sock->default_value = node_socket_make_default_value(sock->type);
+ node_socket_copy_default_value(sock->type, sock->default_value, gsock->default_value);
if(lb)
BLI_addtail(lb, sock);
@@ -247,177 +247,6 @@ bNode *node_group_make_from_selected(bNodeTree *ntree)
return gnode;
}
-/* XXX This is a makeshift function to have useful initial group socket values.
- * In the end this should be implemented by a flexible socket data conversion system,
- * which is yet to be implemented. The idea is that beside default standard conversions,
- * such as int-to-float, it should be possible to quickly select a conversion method or
- * a chain of conversions for each input, whenever there is more than one option.
- * E.g. a vector-to-float conversion could use either of the x/y/z components or
- * the vector length.
- *
- * In the interface this could be implemented by a pseudo-script textbox on linked inputs,
- * with quick selection from a predefined list of conversion options. Some Examples:
- * - vector component 'z' (vector->float): "z"
- * - greyscale color (float->color): "grey"
- * - color luminance (color->float): "lum"
- * - matrix column 2 length (matrix->vector->float): "col[1].len"
- * - mesh vertex coordinate 'y' (mesh->vertex->vector->float): "vertex.co.y"
- *
- * The actual conversion is then done by a series of conversion functions,
- * which are defined in the socket type structs.
- */
-static void convert_socket_value(bNodeSocket *from, bNodeSocket *to)
-{
- /* XXX only one of these pointers is valid! just putting them here for convenience */
- bNodeSocketValueFloat *fromfloat= (bNodeSocketValueFloat*)from->default_value;
- bNodeSocketValueInt *fromint= (bNodeSocketValueInt*)from->default_value;
- bNodeSocketValueBoolean *frombool= (bNodeSocketValueBoolean*)from->default_value;
- bNodeSocketValueVector *fromvector= (bNodeSocketValueVector*)from->default_value;
- bNodeSocketValueRGBA *fromrgba= (bNodeSocketValueRGBA*)from->default_value;
-
- bNodeSocketValueFloat *tofloat= (bNodeSocketValueFloat*)to->default_value;
- bNodeSocketValueInt *toint= (bNodeSocketValueInt*)to->default_value;
- bNodeSocketValueBoolean *tobool= (bNodeSocketValueBoolean*)to->default_value;
- bNodeSocketValueVector *tovector= (bNodeSocketValueVector*)to->default_value;
- bNodeSocketValueRGBA *torgba= (bNodeSocketValueRGBA*)to->default_value;
-
- switch (from->type) {
- case SOCK_FLOAT:
- switch (to->type) {
- case SOCK_FLOAT:
- tofloat->value = fromfloat->value;
- break;
- case SOCK_INT:
- toint->value = (int)fromfloat->value;
- break;
- case SOCK_BOOLEAN:
- tobool->value = (fromfloat->value > 0.0f);
- break;
- case SOCK_VECTOR:
- tovector->value[0] = tovector->value[1] = tovector->value[2] = fromfloat->value;
- break;
- case SOCK_RGBA:
- torgba->value[0] = torgba->value[1] = torgba->value[2] = torgba->value[3] = fromfloat->value;
- break;
- }
- break;
- case SOCK_INT:
- switch (to->type) {
- case SOCK_FLOAT:
- tofloat->value = (float)fromint->value;
- break;
- case SOCK_INT:
- toint->value = fromint->value;
- break;
- case SOCK_BOOLEAN:
- tobool->value = (fromint->value > 0);
- break;
- case SOCK_VECTOR:
- tovector->value[0] = tovector->value[1] = tovector->value[2] = (float)fromint->value;
- break;
- case SOCK_RGBA:
- torgba->value[0] = torgba->value[1] = torgba->value[2] = torgba->value[3] = (float)fromint->value;
- break;
- }
- break;
- case SOCK_BOOLEAN:
- switch (to->type) {
- case SOCK_FLOAT:
- tofloat->value = (float)frombool->value;
- break;
- case SOCK_INT:
- toint->value = (int)frombool->value;
- break;
- case SOCK_BOOLEAN:
- tobool->value = frombool->value;
- break;
- case SOCK_VECTOR:
- tovector->value[0] = tovector->value[1] = tovector->value[2] = (float)frombool->value;
- break;
- case SOCK_RGBA:
- torgba->value[0] = torgba->value[1] = torgba->value[2] = torgba->value[3] = (float)frombool->value;
- break;
- }
- break;
- case SOCK_VECTOR:
- switch (to->type) {
- case SOCK_FLOAT:
- tofloat->value = fromvector->value[0];
- break;
- case SOCK_INT:
- toint->value = (int)fromvector->value[0];
- break;
- case SOCK_BOOLEAN:
- tobool->value = (fromvector->value[0] > 0.0f);
- break;
- case SOCK_VECTOR:
- copy_v3_v3(tovector->value, fromvector->value);
- break;
- case SOCK_RGBA:
- copy_v3_v3(torgba->value, fromvector->value);
- torgba->value[3] = 1.0f;
- break;
- }
- break;
- case SOCK_RGBA:
- switch (to->type) {
- case SOCK_FLOAT:
- tofloat->value = fromrgba->value[0];
- break;
- case SOCK_INT:
- toint->value = (int)fromrgba->value[0];
- break;
- case SOCK_BOOLEAN:
- tobool->value = (fromrgba->value[0] > 0.0f);
- break;
- case SOCK_VECTOR:
- copy_v3_v3(tovector->value, fromrgba->value);
- break;
- case SOCK_RGBA:
- copy_v4_v4(torgba->value, fromrgba->value);
- break;
- }
- break;
- }
-}
-
-static void copy_socket_value(bNodeSocket *from, bNodeSocket *to)
-{
- /* XXX only one of these pointers is valid! just putting them here for convenience */
- bNodeSocketValueFloat *fromfloat= (bNodeSocketValueFloat*)from->default_value;
- bNodeSocketValueInt *fromint= (bNodeSocketValueInt*)from->default_value;
- bNodeSocketValueBoolean *frombool= (bNodeSocketValueBoolean*)from->default_value;
- bNodeSocketValueVector *fromvector= (bNodeSocketValueVector*)from->default_value;
- bNodeSocketValueRGBA *fromrgba= (bNodeSocketValueRGBA*)from->default_value;
-
- bNodeSocketValueFloat *tofloat= (bNodeSocketValueFloat*)to->default_value;
- bNodeSocketValueInt *toint= (bNodeSocketValueInt*)to->default_value;
- bNodeSocketValueBoolean *tobool= (bNodeSocketValueBoolean*)to->default_value;
- bNodeSocketValueVector *tovector= (bNodeSocketValueVector*)to->default_value;
- bNodeSocketValueRGBA *torgba= (bNodeSocketValueRGBA*)to->default_value;
-
- if (from->type != to->type)
- return;
-
- switch (from->type) {
- case SOCK_FLOAT:
- *tofloat = *fromfloat;
- break;
- case SOCK_INT:
- *toint = *fromint;
- break;
- case SOCK_BOOLEAN:
- *tobool = *frombool;
- break;
- case SOCK_VECTOR:
- *tovector = *fromvector;
- break;
- case SOCK_RGBA:
- *torgba = *fromrgba;
- break;
- }
-}
-
/* returns 1 if its OK */
int node_group_ungroup(bNodeTree *ntree, bNode *gnode)
{
@@ -489,7 +318,7 @@ int node_group_ungroup(bNodeTree *ntree, bNode *gnode)
}
else {
/* copy the default input value from the group socket default to the external socket */
- convert_socket_value(gsock, link->tosock);
+ node_socket_convert_default_value(link->tosock->type, link->tosock->default_value, gsock->type, gsock->default_value);
}
}
}
@@ -517,7 +346,7 @@ int node_group_ungroup(bNodeTree *ntree, bNode *gnode)
}
else {
/* copy the default input value from the group node socket default to the internal socket */
- convert_socket_value(insock, link->tosock);
+ node_socket_convert_default_value(link->tosock->type, link->tosock->default_value, insock->type, insock->default_value);
nodeRemLink(wgroup, link);
}
}
@@ -600,7 +429,7 @@ bNodeSocket *node_group_expose_socket(bNodeTree *ngroup, bNodeSocket *sock, int
bNodeSocket *gsock= node_group_add_socket(ngroup, sock->name, sock->type, in_out);
/* initialize the default value. */
- copy_socket_value(sock, gsock);
+ node_socket_copy_default_value(gsock->type, gsock->default_value, sock->default_value);
return gsock;
}
@@ -616,7 +445,7 @@ void node_group_expose_all_sockets(bNodeTree *ngroup)
gsock = node_group_add_socket(ngroup, sock->name, sock->type, SOCK_IN);
/* initialize the default value. */
- copy_socket_value(sock, gsock);
+ node_socket_copy_default_value(gsock->type, gsock->default_value, sock->default_value);
sock->link = nodeAddLink(ngroup, NULL, gsock, node, sock);
}
@@ -626,7 +455,7 @@ void node_group_expose_all_sockets(bNodeTree *ngroup)
gsock = node_group_add_socket(ngroup, sock->name, sock->type, SOCK_OUT);
/* initialize the default value. */
- copy_socket_value(sock, gsock);
+ node_socket_copy_default_value(gsock->type, gsock->default_value, sock->default_value);
gsock->link = nodeAddLink(ngroup, node, sock, NULL, gsock);
}
@@ -832,11 +661,12 @@ bNodeTemplate node_forloop_template(bNode *node)
void node_forloop_init(bNodeTree *ntree, bNode *node, bNodeTemplate *ntemp)
{
- /* bNodeSocket *sock; */ /* UNUSED */
+ bNodeSocket *sock;
node->id = (ID*)ntemp->ngroup;
- /* sock = */ nodeAddInputFloat(ntree, node, "Iterations", PROP_UNSIGNED, 1, 0, 10000);
+ sock = nodeAddSocket(ntree, node, SOCK_IN, "Iterations", SOCK_FLOAT);
+ node_socket_set_default_value_float(sock->default_value, PROP_UNSIGNED, 1, 0, 10000);
/* NB: group socket input/output roles are inverted internally!
* Group "inputs" work as outputs in links and vice versa.
@@ -938,11 +768,12 @@ void node_loop_update_tree(bNodeTree *ngroup)
void node_whileloop_init(bNodeTree *ntree, bNode *node, bNodeTemplate *ntemp)
{
- /* bNodeSocket *sock; */ /* UNUSED */
+ bNodeSocket *sock;
node->id = (ID*)ntemp->ngroup;
- /* sock = */ nodeAddInputFloat(ntree, node, "Condition", PROP_NONE, 1, 0, 1);
+ sock = nodeAddSocket(ntree, node, SOCK_IN, "Condition", SOCK_FLOAT);
+ node_socket_set_default_value_float(sock->default_value, PROP_NONE, 1, 0, 1);
/* max iterations */
node->custom1 = 10000;
diff --git a/source/blender/nodes/intern/node_socket.c b/source/blender/nodes/intern/node_socket.c
index 9381eff30dd..f03aff8fb92 100644
--- a/source/blender/nodes/intern/node_socket.c
+++ b/source/blender/nodes/intern/node_socket.c
@@ -29,6 +29,7 @@
* \ingroup nodes
*/
+#include <limits.h>
#include "DNA_node_types.h"
@@ -172,171 +173,311 @@ void node_socket_type_init(bNodeSocketType *types[])
#undef INIT_TYPE
}
-struct bNodeSocket *nodeAddInputInt(struct bNodeTree *ntree, struct bNode *node, const char *name, PropertySubType subtype,
- int value, int min, int max)
+void *node_socket_make_default_value(int type)
{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_IN, name, SOCK_INT);
- bNodeSocketValueInt *dval= (bNodeSocketValueInt*)sock->default_value;
- dval->subtype = subtype;
- dval->value = value;
- dval->min = min;
- dval->max = max;
- return sock;
-}
-struct bNodeSocket *nodeAddOutputInt(struct bNodeTree *ntree, struct bNode *node, const char *name)
-{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_OUT, name, SOCK_INT);
- return sock;
+ /* XXX currently just allocates from stype->structsize.
+ * it might become necessary to do more complex allocations for later types.
+ */
+ bNodeSocketType *stype = ntreeGetSocketType(type);
+ if (stype->value_structsize > 0) {
+ void *default_value = MEM_callocN(stype->value_structsize, "default socket value");
+ return default_value;
+ }
+ else
+ return NULL;
}
-struct bNodeSocket *nodeAddInputFloat(struct bNodeTree *ntree, struct bNode *node, const char *name, PropertySubType subtype,
- float value, float min, float max)
-{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_IN, name, SOCK_FLOAT);
- bNodeSocketValueFloat *dval= (bNodeSocketValueFloat*)sock->default_value;
- dval->subtype = subtype;
- dval->value = value;
- dval->min = min;
- dval->max = max;
- return sock;
-}
-struct bNodeSocket *nodeAddOutputFloat(struct bNodeTree *ntree, struct bNode *node, const char *name)
+void node_socket_free_default_value(int UNUSED(type), void *default_value)
{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_OUT, name, SOCK_FLOAT);
- return sock;
+ /* XXX can just free the pointee for all current socket types. */
+ if (default_value)
+ MEM_freeN(default_value);
}
-struct bNodeSocket *nodeAddInputBoolean(struct bNodeTree *ntree, struct bNode *node, const char *name, char value)
-{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_IN, name, SOCK_BOOLEAN);
- bNodeSocketValueBoolean *dval= (bNodeSocketValueBoolean*)sock->default_value;
- dval->value = value;
- return sock;
-}
-struct bNodeSocket *nodeAddOutputBoolean(struct bNodeTree *ntree, struct bNode *node, const char *name)
+void node_socket_init_default_value(int type, void *default_value)
{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_OUT, name, SOCK_BOOLEAN);
- return sock;
+ switch (type) {
+ case SOCK_FLOAT:
+ node_socket_set_default_value_float(default_value, PROP_NONE, 0.0f, -FLT_MAX, FLT_MAX);
+ break;
+ case SOCK_INT:
+ node_socket_set_default_value_int(default_value, PROP_NONE, 0, INT_MIN, INT_MAX);
+ break;
+ case SOCK_BOOLEAN:
+ node_socket_set_default_value_boolean(default_value, FALSE);
+ break;
+ case SOCK_VECTOR:
+ node_socket_set_default_value_vector(default_value, PROP_NONE, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX);
+ break;
+ case SOCK_RGBA:
+ node_socket_set_default_value_rgba(default_value, 0.0f, 0.0f, 0.0f, 1.0f);
+ break;
+ case SOCK_SHADER:
+ node_socket_set_default_value_shader(default_value);
+ break;
+ case SOCK_MESH:
+ node_socket_set_default_value_mesh(default_value);
+ break;
+ }
}
-struct bNodeSocket *nodeAddInputVector(struct bNodeTree *ntree, struct bNode *node, const char *name, PropertySubType subtype,
- float x, float y, float z, float min, float max)
+void node_socket_set_default_value_int(void *default_value, PropertySubType subtype, int value, int min, int max)
{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_IN, name, SOCK_VECTOR);
- bNodeSocketValueVector *dval= (bNodeSocketValueVector*)sock->default_value;
- dval->subtype = subtype;
- dval->value[0] = x;
- dval->value[1] = y;
- dval->value[2] = z;
- dval->min = min;
- dval->max = max;
- return sock;
-}
-struct bNodeSocket *nodeAddOutputVector(struct bNodeTree *ntree, struct bNode *node, const char *name)
-{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_OUT, name, SOCK_VECTOR);
- return sock;
+ bNodeSocketValueInt *val = default_value;
+ val->subtype = subtype;
+ val->value = value;
+ val->min = min;
+ val->max = max;
}
-struct bNodeSocket *nodeAddInputRGBA(struct bNodeTree *ntree, struct bNode *node, const char *name,
- float r, float g, float b, float a)
+void node_socket_set_default_value_float(void *default_value, PropertySubType subtype, float value, float min, float max)
{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_IN, name, SOCK_RGBA);
- bNodeSocketValueRGBA *dval= (bNodeSocketValueRGBA*)sock->default_value;
- dval->value[0] = r;
- dval->value[1] = g;
- dval->value[2] = b;
- dval->value[3] = a;
- return sock;
+ bNodeSocketValueFloat *val = default_value;
+ val->subtype = subtype;
+ val->value = value;
+ val->min = min;
+ val->max = max;
}
-struct bNodeSocket *nodeAddOutputRGBA(struct bNodeTree *ntree, struct bNode *node, const char *name)
+
+void node_socket_set_default_value_boolean(void *default_value, char value)
{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_OUT, name, SOCK_RGBA);
- return sock;
+ bNodeSocketValueBoolean *val = default_value;
+ val->value = value;
}
-struct bNodeSocket *nodeAddInputShader(struct bNodeTree *ntree, struct bNode *node, const char *name)
+void node_socket_set_default_value_vector(void *default_value, PropertySubType subtype, float x, float y, float z, float min, float max)
{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_IN, name, SOCK_SHADER);
- return sock;
+ bNodeSocketValueVector *val = default_value;
+ val->subtype = subtype;
+ val->value[0] = x;
+ val->value[1] = y;
+ val->value[2] = z;
+ val->min = min;
+ val->max = max;
}
-struct bNodeSocket *nodeAddOutputShader(struct bNodeTree *ntree, struct bNode *node, const char *name)
+
+void node_socket_set_default_value_rgba(void *default_value, float r, float g, float b, float a)
{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_OUT, name, SOCK_SHADER);
- return sock;
+ bNodeSocketValueRGBA *val = default_value;
+ val->value[0] = r;
+ val->value[1] = g;
+ val->value[2] = b;
+ val->value[3] = a;
}
-struct bNodeSocket *nodeAddInputMesh(struct bNodeTree *ntree, struct bNode *node, const char *name)
+void node_socket_set_default_value_shader(void *UNUSED(default_value))
{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_IN, name, SOCK_MESH);
- return sock;
}
-struct bNodeSocket *nodeAddOutputMesh(struct bNodeTree *ntree, struct bNode *node, const char *name)
+
+void node_socket_set_default_value_mesh(void *UNUSED(default_value))
{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_OUT, name, SOCK_MESH);
- return sock;
}
-struct bNodeSocket *node_add_input_from_template(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocketTemplate *stemp)
+
+void node_socket_copy_default_value(int type, void *to_default_value, void *from_default_value)
{
- bNodeSocket *sock;
- switch (stemp->type) {
- case SOCK_INT:
- sock = nodeAddInputInt(ntree, node, stemp->name, stemp->subtype, (int)stemp->val1, (int)stemp->min, (int)stemp->max);
- break;
+ /* XXX only one of these pointers is valid! just putting them here for convenience */
+ bNodeSocketValueFloat *fromfloat= (bNodeSocketValueFloat*)from_default_value;
+ bNodeSocketValueInt *fromint= (bNodeSocketValueInt*)from_default_value;
+ bNodeSocketValueBoolean *frombool= (bNodeSocketValueBoolean*)from_default_value;
+ bNodeSocketValueVector *fromvector= (bNodeSocketValueVector*)from_default_value;
+ bNodeSocketValueRGBA *fromrgba= (bNodeSocketValueRGBA*)from_default_value;
+
+ bNodeSocketValueFloat *tofloat= (bNodeSocketValueFloat*)to_default_value;
+ bNodeSocketValueInt *toint= (bNodeSocketValueInt*)to_default_value;
+ bNodeSocketValueBoolean *tobool= (bNodeSocketValueBoolean*)to_default_value;
+ bNodeSocketValueVector *tovector= (bNodeSocketValueVector*)to_default_value;
+ bNodeSocketValueRGBA *torgba= (bNodeSocketValueRGBA*)to_default_value;
+
+ switch (type) {
case SOCK_FLOAT:
- sock = nodeAddInputFloat(ntree, node, stemp->name, stemp->subtype, stemp->val1, stemp->min, stemp->max);
+ *tofloat = *fromfloat;
+ break;
+ case SOCK_INT:
+ *toint = *fromint;
break;
case SOCK_BOOLEAN:
- sock = nodeAddInputBoolean(ntree, node, stemp->name, (char)stemp->val1);
+ *tobool = *frombool;
break;
case SOCK_VECTOR:
- sock = nodeAddInputVector(ntree, node, stemp->name, stemp->subtype, stemp->val1, stemp->val2, stemp->val3, stemp->min, stemp->max);
+ *tovector = *fromvector;
break;
case SOCK_RGBA:
- sock = nodeAddInputRGBA(ntree, node, stemp->name, stemp->val1, stemp->val2, stemp->val3, stemp->val4);
+ *torgba = *fromrgba;
break;
- case SOCK_SHADER:
- sock = nodeAddInputShader(ntree, node, stemp->name);
+ }
+}
+
+/* XXX This is a makeshift function to have useful initial group socket values.
+ * In the end this should be implemented by a flexible socket data conversion system,
+ * which is yet to be implemented. The idea is that beside default standard conversions,
+ * such as int-to-float, it should be possible to quickly select a conversion method or
+ * a chain of conversions for each input, whenever there is more than one option.
+ * E.g. a vector-to-float conversion could use either of the x/y/z components or
+ * the vector length.
+ *
+ * In the interface this could be implemented by a pseudo-script textbox on linked inputs,
+ * with quick selection from a predefined list of conversion options. Some Examples:
+ * - vector component 'z' (vector->float): "z"
+ * - greyscale color (float->color): "grey"
+ * - color luminance (color->float): "lum"
+ * - matrix column 2 length (matrix->vector->float): "col[1].len"
+ * - mesh vertex coordinate 'y' (mesh->vertex->vector->float): "vertex.co.y"
+ *
+ * The actual conversion is then done by a series of conversion functions,
+ * which are defined in the socket type structs.
+ */
+void node_socket_convert_default_value(int to_type, void *to_default_value, int from_type, void *from_default_value)
+{
+ /* XXX only one of these pointers is valid! just putting them here for convenience */
+ bNodeSocketValueFloat *fromfloat= (bNodeSocketValueFloat*)from_default_value;
+ bNodeSocketValueInt *fromint= (bNodeSocketValueInt*)from_default_value;
+ bNodeSocketValueBoolean *frombool= (bNodeSocketValueBoolean*)from_default_value;
+ bNodeSocketValueVector *fromvector= (bNodeSocketValueVector*)from_default_value;
+ bNodeSocketValueRGBA *fromrgba= (bNodeSocketValueRGBA*)from_default_value;
+
+ bNodeSocketValueFloat *tofloat= (bNodeSocketValueFloat*)to_default_value;
+ bNodeSocketValueInt *toint= (bNodeSocketValueInt*)to_default_value;
+ bNodeSocketValueBoolean *tobool= (bNodeSocketValueBoolean*)to_default_value;
+ bNodeSocketValueVector *tovector= (bNodeSocketValueVector*)to_default_value;
+ bNodeSocketValueRGBA *torgba= (bNodeSocketValueRGBA*)to_default_value;
+
+ switch (from_type) {
+ case SOCK_FLOAT:
+ switch (to_type) {
+ case SOCK_FLOAT:
+ tofloat->value = fromfloat->value;
+ break;
+ case SOCK_INT:
+ toint->value = (int)fromfloat->value;
+ break;
+ case SOCK_BOOLEAN:
+ tobool->value = (fromfloat->value > 0.0f);
+ break;
+ case SOCK_VECTOR:
+ tovector->value[0] = tovector->value[1] = tovector->value[2] = fromfloat->value;
+ break;
+ case SOCK_RGBA:
+ torgba->value[0] = torgba->value[1] = torgba->value[2] = torgba->value[3] = fromfloat->value;
+ break;
+ }
break;
- case SOCK_MESH:
- sock = nodeAddInputMesh(ntree, node, stemp->name);
+ case SOCK_INT:
+ switch (to_type) {
+ case SOCK_FLOAT:
+ tofloat->value = (float)fromint->value;
+ break;
+ case SOCK_INT:
+ toint->value = fromint->value;
+ break;
+ case SOCK_BOOLEAN:
+ tobool->value = (fromint->value > 0);
+ break;
+ case SOCK_VECTOR:
+ tovector->value[0] = tovector->value[1] = tovector->value[2] = (float)fromint->value;
+ break;
+ case SOCK_RGBA:
+ torgba->value[0] = torgba->value[1] = torgba->value[2] = torgba->value[3] = (float)fromint->value;
+ break;
+ }
+ break;
+ case SOCK_BOOLEAN:
+ switch (to_type) {
+ case SOCK_FLOAT:
+ tofloat->value = (float)frombool->value;
+ break;
+ case SOCK_INT:
+ toint->value = (int)frombool->value;
+ break;
+ case SOCK_BOOLEAN:
+ tobool->value = frombool->value;
+ break;
+ case SOCK_VECTOR:
+ tovector->value[0] = tovector->value[1] = tovector->value[2] = (float)frombool->value;
+ break;
+ case SOCK_RGBA:
+ torgba->value[0] = torgba->value[1] = torgba->value[2] = torgba->value[3] = (float)frombool->value;
+ break;
+ }
+ break;
+ case SOCK_VECTOR:
+ switch (to_type) {
+ case SOCK_FLOAT:
+ tofloat->value = fromvector->value[0];
+ break;
+ case SOCK_INT:
+ toint->value = (int)fromvector->value[0];
+ break;
+ case SOCK_BOOLEAN:
+ tobool->value = (fromvector->value[0] > 0.0f);
+ break;
+ case SOCK_VECTOR:
+ copy_v3_v3(tovector->value, fromvector->value);
+ break;
+ case SOCK_RGBA:
+ copy_v3_v3(torgba->value, fromvector->value);
+ torgba->value[3] = 1.0f;
+ break;
+ }
+ break;
+ case SOCK_RGBA:
+ switch (to_type) {
+ case SOCK_FLOAT:
+ tofloat->value = fromrgba->value[0];
+ break;
+ case SOCK_INT:
+ toint->value = (int)fromrgba->value[0];
+ break;
+ case SOCK_BOOLEAN:
+ tobool->value = (fromrgba->value[0] > 0.0f);
+ break;
+ case SOCK_VECTOR:
+ copy_v3_v3(tovector->value, fromrgba->value);
+ break;
+ case SOCK_RGBA:
+ copy_v4_v4(torgba->value, fromrgba->value);
+ break;
+ }
break;
- default:
- sock = nodeAddSocket(ntree, node, SOCK_IN, stemp->name, stemp->type);
}
- sock->flag |= stemp->flag;
- return sock;
}
-struct bNodeSocket *node_add_output_from_template(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocketTemplate *stemp)
+
+struct bNodeSocket *node_add_input_from_template(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocketTemplate *stemp)
{
- bNodeSocket *sock;
+ bNodeSocket *sock = nodeAddSocket(ntree, node, SOCK_IN, stemp->name, stemp->type);
+ sock->flag |= stemp->flag;
+
switch (stemp->type) {
case SOCK_INT:
- sock = nodeAddOutputInt(ntree, node, stemp->name);
+ node_socket_set_default_value_int(sock->default_value, stemp->subtype, (int)stemp->val1, (int)stemp->min, (int)stemp->max);
break;
case SOCK_FLOAT:
- sock = nodeAddOutputFloat(ntree, node, stemp->name);
+ node_socket_set_default_value_float(sock->default_value, stemp->subtype, stemp->val1, stemp->min, stemp->max);
break;
case SOCK_BOOLEAN:
- sock = nodeAddOutputBoolean(ntree, node, stemp->name);
+ node_socket_set_default_value_boolean(sock->default_value, (char)stemp->val1);
break;
case SOCK_VECTOR:
- sock = nodeAddOutputVector(ntree, node, stemp->name);
+ node_socket_set_default_value_vector(sock->default_value, stemp->subtype, stemp->val1, stemp->val2, stemp->val3, stemp->min, stemp->max);
break;
case SOCK_RGBA:
- sock = nodeAddOutputRGBA(ntree, node, stemp->name);
+ node_socket_set_default_value_rgba(sock->default_value, stemp->val1, stemp->val2, stemp->val3, stemp->val4);
break;
case SOCK_SHADER:
- sock = nodeAddOutputShader(ntree, node, stemp->name);
+ node_socket_set_default_value_shader(sock->default_value);
break;
case SOCK_MESH:
- sock = nodeAddOutputMesh(ntree, node, stemp->name);
+ node_socket_set_default_value_mesh(sock->default_value);
break;
- default:
- sock = nodeAddSocket(ntree, node, SOCK_OUT, stemp->name, stemp->type);
}
+
+ return sock;
+}
+
+struct bNodeSocket *node_add_output_from_template(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocketTemplate *stemp)
+{
+ bNodeSocket *sock = nodeAddSocket(ntree, node, SOCK_OUT, stemp->name, stemp->type);
return sock;
}
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index 6c961d8e6a8..72c072c13d5 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -267,9 +267,10 @@ void BPY_python_start(int argc, const char **argv)
pyrna_alloc_types();
+#ifndef WITH_PYTHON_MODULE
+ /* py module runs atexit when bpy is freed */
BPY_atexit_register(); /* this can init any time */
-#ifndef WITH_PYTHON_MODULE
py_tstate = PyGILState_GetThisThreadState();
PyEval_ReleaseThread(py_tstate);
#endif
@@ -288,7 +289,9 @@ void BPY_python_end(void)
bpy_intern_string_exit();
+#ifndef WITH_PYTHON_MODULE
BPY_atexit_unregister(); /* without this we get recursive calls to WM_exit */
+#endif
Py_Finalize();
diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c
index d94ba8b9441..414ebe47e97 100644
--- a/source/blender/python/intern/bpy_props.c
+++ b/source/blender/python/intern/bpy_props.c
@@ -374,7 +374,12 @@ static int bpy_struct_id_used(StructRNA *srna, char *identifier)
* but being abused from C so we can pass the srna along.
* This isnt incorrect since its a python object - but be careful */
PyDoc_STRVAR(BPy_BoolProperty_doc,
-".. function:: BoolProperty(name=\"\", description=\"\", default=False, options={'ANIMATABLE'}, subtype='NONE', update=None)\n"
+".. function:: BoolProperty(name=\"\", "
+ "description=\"\", "
+ "default=False, "
+ "options={'ANIMATABLE'}, "
+ "subtype='NONE', "
+ "update=None)\n"
"\n"
" Returns a new boolean property definition.\n"
"\n"
@@ -438,7 +443,13 @@ static PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
}
PyDoc_STRVAR(BPy_BoolVectorProperty_doc,
-".. function:: BoolVectorProperty(name=\"\", description=\"\", default=(False, False, False), options={'ANIMATABLE'}, subtype='NONE', size=3, update=None)\n"
+".. function:: BoolVectorProperty(name=\"\", "
+ "description=\"\", "
+ "default=(False, False, False), "
+ "options={'ANIMATABLE'}, "
+ "subtype='NONE', "
+ "size=3, "
+ "update=None)\n"
"\n"
" Returns a new vector boolean property definition.\n"
"\n"
@@ -448,7 +459,9 @@ BPY_PROPDEF_DESC_DOC
" :type default: sequence\n"
" :arg options: Enumerator in ['HIDDEN', 'SKIP_SAVE', 'ANIMATABLE'].\n"
" :type options: set\n"
-" :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', 'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', 'XYZ', 'COLOR_GAMMA', 'LAYER', 'NONE'].\n"
+" :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', "
+ "'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', "
+ "'XYZ', 'COLOR_GAMMA', 'LAYER', 'NONE'].\n"
" :type subtype: string\n"
" :arg size: Vector dimensions in [1, and " STRINGIFY(PYRNA_STACK_ARRAY) "].\n"
" :type size: int\n"
@@ -520,7 +533,15 @@ static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject
}
PyDoc_STRVAR(BPy_IntProperty_doc,
-".. function:: IntProperty(name=\"\", description=\"\", default=0, min=-sys.maxint, max=sys.maxint, soft_min=-sys.maxint, soft_max=sys.maxint, step=1, options={'ANIMATABLE'}, subtype='NONE', update=None)\n"
+".. function:: IntProperty(name=\"\", "
+ "description=\"\", "
+ "default=0, "
+ "min=-sys.maxint, max=sys.maxint, "
+ "soft_min=-sys.maxint, soft_max=sys.maxint, "
+ "step=1, "
+ "options={'ANIMATABLE'}, "
+ "subtype='NONE', "
+ "update=None)\n"
"\n"
" Returns a new int property definition.\n"
"\n"
@@ -540,7 +561,8 @@ static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
if (srna) {
static const char *kwlist[] = {"attr", "name", "description", "default",
- "min", "max", "soft_min", "soft_max", "step", "options", "subtype", "update", NULL};
+ "min", "max", "soft_min", "soft_max",
+ "step", "options", "subtype", "update", NULL};
const char *id = NULL, *name = NULL, *description = "";
int id_len;
int min = INT_MIN, max = INT_MAX, soft_min = INT_MIN, soft_max = INT_MAX, step = 1, def = 0;
@@ -586,7 +608,15 @@ static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
}
PyDoc_STRVAR(BPy_IntVectorProperty_doc,
-".. function:: IntVectorProperty(name=\"\", description=\"\", default=(0, 0, 0), min=-sys.maxint, max=sys.maxint, soft_min=-sys.maxint, soft_max=sys.maxint, options={'ANIMATABLE'}, subtype='NONE', size=3, update=None)\n"
+".. function:: IntVectorProperty(name=\"\", "
+ "description=\"\", "
+ "default=(0, 0, 0), min=-sys.maxint, max=sys.maxint, "
+ "soft_min=-sys.maxint, "
+ "soft_max=sys.maxint, "
+ "options={'ANIMATABLE'}, "
+ "subtype='NONE', "
+ "size=3, "
+ "update=None)\n"
"\n"
" Returns a new vector int property definition.\n"
"\n"
@@ -596,7 +626,9 @@ BPY_PROPDEF_DESC_DOC
" :type default: sequence\n"
" :arg options: Enumerator in ['HIDDEN', 'SKIP_SAVE', 'ANIMATABLE'].\n"
" :type options: set\n"
-" :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', 'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', 'XYZ', 'COLOR_GAMMA', 'LAYER', 'NONE'].\n"
+" :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', "
+ "'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', "
+ "'XYZ', 'COLOR_GAMMA', 'LAYER', 'NONE'].\n"
" :type subtype: string\n"
" :arg size: Vector dimensions in [1, and " STRINGIFY(PYRNA_STACK_ARRAY) "].\n"
" :type size: int\n"
@@ -673,7 +705,17 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject
PyDoc_STRVAR(BPy_FloatProperty_doc,
-".. function:: FloatProperty(name=\"\", description=\"\", default=0.0, min=sys.float_info.min, max=sys.float_info.max, soft_min=sys.float_info.min, soft_max=sys.float_info.max, step=3, precision=2, options={'ANIMATABLE'}, subtype='NONE', unit='NONE', update=None)\n"
+".. function:: FloatProperty(name=\"\", "
+ "description=\"\", "
+ "default=0.0, "
+ "min=sys.float_info.min, max=sys.float_info.max, "
+ "soft_min=sys.float_info.min, soft_max=sys.float_info.max, "
+ "step=3, "
+ "precision=2, "
+ "options={'ANIMATABLE'}, "
+ "subtype='NONE', "
+ "unit='NONE', "
+ "update=None)\n"
"\n"
" Returns a new float property definition.\n"
"\n"
@@ -750,7 +792,17 @@ static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
}
PyDoc_STRVAR(BPy_FloatVectorProperty_doc,
-".. function:: FloatVectorProperty(name=\"\", description=\"\", default=(0.0, 0.0, 0.0), min=sys.float_info.min, max=sys.float_info.max, soft_min=sys.float_info.min, soft_max=sys.float_info.max, step=3, precision=2, options={'ANIMATABLE'}, subtype='NONE', size=3, update=None)\n"
+".. function:: FloatVectorProperty(name=\"\", "
+ "description=\"\", "
+ "default=(0.0, 0.0, 0.0), "
+ "min=sys.float_info.min, max=sys.float_info.max, "
+ "soft_min=sys.float_info.min, soft_max=sys.float_info.max, "
+ "step=3, "
+ "precision=2, "
+ "options={'ANIMATABLE'}, "
+ "subtype='NONE', "
+ "size=3, "
+ "update=None)\n"
"\n"
" Returns a new vector float property definition.\n"
"\n"
@@ -760,7 +812,9 @@ BPY_PROPDEF_DESC_DOC
" :type default: sequence\n"
" :arg options: Enumerator in ['HIDDEN', 'SKIP_SAVE', 'ANIMATABLE'].\n"
" :type options: set\n"
-" :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', 'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', 'XYZ', 'COLOR_GAMMA', 'LAYER', 'NONE'].\n"
+" :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', "
+ "'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', 'XYZ', "
+ "'COLOR_GAMMA', 'LAYER', 'NONE'].\n"
" :type subtype: string\n"
BPY_PROPDEF_UNIT_DOC
" :arg size: Vector dimensions in [1, and " STRINGIFY(PYRNA_STACK_ARRAY) "].\n"
@@ -779,7 +833,8 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
"step", "precision", "options", "subtype", "unit", "size", "update", NULL};
const char *id = NULL, *name = NULL, *description = "";
int id_len;
- float min = -FLT_MAX, max = FLT_MAX, soft_min = -FLT_MAX, soft_max = FLT_MAX, step = 3, def[PYRNA_STACK_ARRAY] = {0.0f};
+ float min = -FLT_MAX, max = FLT_MAX, soft_min = -FLT_MAX, soft_max = FLT_MAX, step = 3;
+ float def[PYRNA_STACK_ARRAY] = {0.0f};
int precision = 2, size = 3;
PropertyRNA *prop;
PyObject *pydef = NULL;
@@ -843,7 +898,13 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
}
PyDoc_STRVAR(BPy_StringProperty_doc,
-".. function:: StringProperty(name=\"\", description=\"\", default=\"\", maxlen=0, options={'ANIMATABLE'}, subtype='NONE', update=None)\n"
+".. function:: StringProperty(name=\"\", "
+ "description=\"\", "
+ "default=\"\", "
+ "maxlen=0, "
+ "options={'ANIMATABLE'}, "
+ "subtype='NONE', "
+ "update=None)\n"
"\n"
" Returns a new string property definition.\n"
"\n"
@@ -978,7 +1039,8 @@ static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, i
(tmp.identifier = _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 0), &id_str_size)) &&
(tmp.name = _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 1), &name_str_size)) &&
(tmp.description = _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 2), &desc_str_size)) &&
- (item_size < 4 || py_long_as_int(PyTuple_GET_ITEM(item, 3), &tmp.value) != -1)) /* TODO, number isnt ensured to be unique from the script author */
+ /* TODO, number isnt ensured to be unique from the script author */
+ (item_size < 4 || py_long_as_int(PyTuple_GET_ITEM(item, 3), &tmp.value) != -1))
{
if (is_enum_flag) {
if (item_size < 4) {
@@ -1105,7 +1167,8 @@ static EnumPropertyItem *bpy_props_enum_itemf(struct bContext *C, PointerRNA *pt
err = -1;
}
else {
- eitems = enum_items_from_py(items_fast, NULL, &defvalue_dummy, (RNA_property_flag(prop) & PROP_ENUM_FLAG) != 0);
+ eitems = enum_items_from_py(items_fast, NULL, &defvalue_dummy,
+ (RNA_property_flag(prop) & PROP_ENUM_FLAG) != 0);
Py_DECREF(items_fast);
@@ -1132,7 +1195,12 @@ static EnumPropertyItem *bpy_props_enum_itemf(struct bContext *C, PointerRNA *pt
}
PyDoc_STRVAR(BPy_EnumProperty_doc,
-".. function:: EnumProperty(items, name=\"\", description=\"\", default=\"\", options={'ANIMATABLE'}, update=None)\n"
+".. function:: EnumProperty(items, "
+ "name=\"\", "
+ "description=\"\", "
+ "default=\"\", "
+ "options={'ANIMATABLE'}, "
+ "update=None)\n"
"\n"
" Returns a new enumerator property definition.\n"
"\n"
@@ -1218,7 +1286,8 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL;
}
- eitems = enum_items_from_py(items_fast, def, &defvalue, (opts & PROP_ENUM_FLAG) != 0);
+ eitems = enum_items_from_py(items_fast, def, &defvalue,
+ (opts & PROP_ENUM_FLAG) != 0);
Py_DECREF(items_fast);
@@ -1287,7 +1356,10 @@ static StructRNA *pointer_type_from_py(PyObject *value, const char *error_prefix
}
PyDoc_STRVAR(BPy_PointerProperty_doc,
-".. function:: PointerProperty(type=\"\", description=\"\", options={'ANIMATABLE'}, update=None)\n"
+".. function:: PointerProperty(type=\"\", "
+ "description=\"\", "
+ "options={'ANIMATABLE'}, "
+ "update=None)\n"
"\n"
" Returns a new pointer property definition.\n"
"\n"
@@ -1349,7 +1421,10 @@ static PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *k
}
PyDoc_STRVAR(BPy_CollectionProperty_doc,
-".. function:: CollectionProperty(items, type=\"\", description=\"\", default=\"\", options={'ANIMATABLE'})\n"
+".. function:: CollectionProperty(items, "
+ "type=\"\", "
+ "description=\"\", "
+ "options={'ANIMATABLE'})\n"
"\n"
" Returns a new collection property definition.\n"
"\n"
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 4940c53551e..bfb79ea6531 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -7158,8 +7158,25 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class
const char *identifier;
PyObject *py_cls_meth;
+ if (!PyType_Check(py_class)) {
+ PyErr_Format(PyExc_ValueError,
+ "register_class(...): "
+ "expected a class argument, not '%.200s'", Py_TYPE(py_class)->tp_name);
+ return NULL;
+ }
+
if (PyDict_GetItem(((PyTypeObject *)py_class)->tp_dict, bpy_intern_str_bl_rna)) {
- PyErr_SetString(PyExc_AttributeError, "register_class(...): already registered as a subclass");
+ PyErr_SetString(PyExc_ValueError,
+ "register_class(...): "
+ "already registered as a subclass");
+ return NULL;
+ }
+
+ if (!pyrna_write_check()) {
+ PyErr_Format(PyExc_RuntimeError,
+ "register_class(...): "
+ "can't run in readonly state '%.200s'",
+ ((PyTypeObject *)py_class)->tp_name);
return NULL;
}
@@ -7284,12 +7301,27 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla
StructRNA *srna;
PyObject *py_cls_meth;
+ if (!PyType_Check(py_class)) {
+ PyErr_Format(PyExc_ValueError,
+ "register_class(...): "
+ "expected a class argument, not '%.200s'", Py_TYPE(py_class)->tp_name);
+ return NULL;
+ }
+
/*if (PyDict_GetItem(((PyTypeObject *)py_class)->tp_dict, bpy_intern_str_bl_rna) == NULL) {
PWM_cursor_wait(0);
PyErr_SetString(PyExc_ValueError, "unregister_class(): not a registered as a subclass");
return NULL;
}*/
+ if (!pyrna_write_check()) {
+ PyErr_Format(PyExc_RuntimeError,
+ "unregister_class(...): "
+ "can't run in readonly state '%.200s'",
+ ((PyTypeObject *)py_class)->tp_name);
+ return NULL;
+ }
+
srna = pyrna_struct_as_srna(py_class, 0, "unregister_class(...):");
if (srna == NULL)
return NULL;
diff --git a/source/blender/python/mathutils/mathutils_Matrix.c b/source/blender/python/mathutils/mathutils_Matrix.c
index f10d8c48c92..7fe4b5ba5dd 100644
--- a/source/blender/python/mathutils/mathutils_Matrix.c
+++ b/source/blender/python/mathutils/mathutils_Matrix.c
@@ -1939,13 +1939,6 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2)
Py_TYPE(m1)->tp_name, Py_TYPE(m2)->tp_name);
return NULL;
}
-static PyObject *Matrix_inv(MatrixObject *self)
-{
- if (BaseMath_ReadCallback(self) == -1)
- return NULL;
-
- return Matrix_invert(self);
-}
/*-----------------PROTOCOL DECLARATIONS--------------------------*/
static PySequenceMethods Matrix_SeqMethods = {
@@ -2049,7 +2042,7 @@ static PyNumberMethods Matrix_NumMethods = {
(unaryfunc) 0, /*tp_positive*/
(unaryfunc) 0, /*tp_absolute*/
(inquiry) 0, /*tp_bool*/
- (unaryfunc) Matrix_inv, /*nb_invert*/
+ (unaryfunc) Matrix_inverted, /*nb_invert*/
NULL, /*nb_lshift*/
(binaryfunc)0, /*nb_rshift*/
NULL, /*nb_and*/
diff --git a/source/blender/render/extern/include/RE_shader_ext.h b/source/blender/render/extern/include/RE_shader_ext.h
index dd0a0f308ce..2f585f91d44 100644
--- a/source/blender/render/extern/include/RE_shader_ext.h
+++ b/source/blender/render/extern/include/RE_shader_ext.h
@@ -210,4 +210,8 @@ int RE_bake_shade_all_selected(struct Render *re, int type, struct Object *actob
struct Image *RE_bake_shade_get_image(void);
void RE_bake_ibuf_filter(struct ImBuf *ibuf, char *mask, const int filter);
+#define BAKE_RESULT_OK 0
+#define BAKE_RESULT_NO_OBJECTS 1
+#define BAKE_RESULT_FEEDBACK_LOOP 2
+
#endif /* RE_SHADER_EXT_H */
diff --git a/source/blender/render/intern/source/imagetexture.c b/source/blender/render/intern/source/imagetexture.c
index 0b6e1b8ee01..2d64828b6b3 100644
--- a/source/blender/render/intern/source/imagetexture.c
+++ b/source/blender/render/intern/source/imagetexture.c
@@ -131,6 +131,8 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul
return retval;
ibuf= BKE_image_get_ibuf(ima, &tex->iuser);
+
+ ima->flag|= IMA_USED_FOR_RENDER;
}
if(ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL))
return retval;
@@ -1441,6 +1443,8 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const
return retval;
ibuf= BKE_image_get_ibuf(ima, &tex->iuser);
+
+ ima->flag|= IMA_USED_FOR_RENDER;
}
if(ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL))
return retval;
@@ -1812,6 +1816,8 @@ void image_sample(Image *ima, float fx, float fy, float dx, float dy, float *res
if( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) )
ibuf->rect-= (ibuf->x*ibuf->y);
+
+ ima->flag|= IMA_USED_FOR_RENDER;
}
void ibuf_sample(ImBuf *ibuf, float fx, float fy, float dx, float dy, float *result)
diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c
index 5fba0bba48c..95cad5a4e46 100644
--- a/source/blender/render/intern/source/render_texture.c
+++ b/source/blender/render/intern/source/render_texture.c
@@ -2127,7 +2127,8 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T
fMagnitude *= len_v3(vN);
}
- for(xyz=0; xyz<3; xyz++)
+ if(ntap_bump->fPrevMagnitude > 0.0f)
+ for(xyz=0; xyz<3; xyz++)
ntap_bump->vNacc[xyz] *= fMagnitude / ntap_bump->fPrevMagnitude;
ntap_bump->fPrevMagnitude = fMagnitude;
diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c
index 630acf3d88a..2d3837acbfa 100644
--- a/source/blender/render/intern/source/rendercore.c
+++ b/source/blender/render/intern/source/rendercore.c
@@ -2166,21 +2166,13 @@ static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int UNUSED(qua
}
}
else {
- char *col= (char *)(bs->rect + bs->rectx*y + x);
+ unsigned char *col= (unsigned char *)(bs->rect + bs->rectx*y + x);
if (ELEM(bs->type, RE_BAKE_ALL, RE_BAKE_TEXTURE) && (R.r.color_mgt_flag & R_COLOR_MANAGEMENT)) {
- float srgb[3];
- srgb[0]= linearrgb_to_srgb(shr.combined[0]);
- srgb[1]= linearrgb_to_srgb(shr.combined[1]);
- srgb[2]= linearrgb_to_srgb(shr.combined[2]);
-
- col[0]= FTOCHAR(srgb[0]);
- col[1]= FTOCHAR(srgb[1]);
- col[2]= FTOCHAR(srgb[2]);
- } else {
- col[0]= FTOCHAR(shr.combined[0]);
- col[1]= FTOCHAR(shr.combined[1]);
- col[2]= FTOCHAR(shr.combined[2]);
+ linearrgb_to_srgb_uchar3(col, shr.combined);
+ }
+ else {
+ rgb_float_to_uchar(col, shr.combined);
}
if (ELEM(bs->type, RE_BAKE_ALL, RE_BAKE_TEXTURE)) {
@@ -2212,9 +2204,7 @@ static void bake_displacement(void *handle, ShadeInput *UNUSED(shi), float dist,
col[3]= 1.0f;
} else {
char *col= (char *)(bs->rect + bs->rectx*y + x);
- col[0]= FTOCHAR(disp);
- col[1]= FTOCHAR(disp);
- col[2]= FTOCHAR(disp);
+ col[0] = col[1] = col[2] = FTOCHAR(disp);
col[3]= 255;
}
if (bs->rect_mask) {
@@ -2450,6 +2440,11 @@ static int get_next_bake_face(BakeShade *bs)
if(ibuf->rect_float && !(ibuf->channels==0 || ibuf->channels==4))
continue;
+ if(ima->flag & IMA_USED_FOR_RENDER) {
+ ima->id.flag &= ~LIB_DOIT;
+ continue;
+ }
+
/* find the image for the first time? */
if(ima->id.flag & LIB_DOIT) {
ima->id.flag &= ~LIB_DOIT;
@@ -2594,7 +2589,7 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_up
BakeShade *handles;
ListBase threads;
Image *ima;
- int a, vdone=0, usemask=0;
+ int a, vdone=0, usemask=0, result=BAKE_RESULT_OK;
/* initialize render global */
R= *re;
@@ -2611,6 +2606,7 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_up
for(ima= G.main->image.first; ima; ima= ima->id.next) {
ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
ima->id.flag |= LIB_DOIT;
+ ima->flag&= ~IMA_USED_FOR_RENDER;
if(ibuf) {
ibuf->userdata = NULL; /* use for masking if needed */
if(ibuf->rect_float)
@@ -2669,6 +2665,9 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_up
if((ima->id.flag & LIB_DOIT)==0) {
ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
+ if(ima->flag & IMA_USED_FOR_RENDER)
+ result= BAKE_RESULT_FEEDBACK_LOOP;
+
if(!ibuf)
continue;
@@ -2689,7 +2688,10 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_up
BLI_end_threads(&threads);
- return vdone;
+ if(vdone==0)
+ result= BAKE_RESULT_NO_OBJECTS;
+
+ return result;
}
struct Image *RE_bake_shade_get_image(void)
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index 758cf7bd61c..357eaf2633b 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -526,14 +526,14 @@ typedef struct wmDrag {
int icon, type; /* type, see WM_DRAG defines above */
void *poin;
- char path[240]; /* FILE_MAX */
+ char path[1024]; /* FILE_MAX */
double value;
struct ImBuf *imb; /* if no icon but imbuf should be drawn around cursor */
float scale;
int sx, sy;
- char opname[240]; /* FILE_MAX */ /* if set, draws operator name*/
+ char opname[200]; /* if set, draws operator name*/
} wmDrag;
/* dropboxes are like keymaps, part of the screen/area/region definition */
diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c
index 94f6eb19e2c..299266154dd 100644
--- a/source/blender/windowmanager/intern/wm_dragdrop.c
+++ b/source/blender/windowmanager/intern/wm_dragdrop.c
@@ -248,7 +248,7 @@ void wm_drags_check_ops(bContext *C, wmEvent *event)
/* ************** draw ***************** */
-static void wm_drop_operator_draw(char *name, int x, int y)
+static void wm_drop_operator_draw(const char *name, int x, int y)
{
int width= UI_GetStringWidth(name);
diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c
index 24af3ffedc1..661bd90435c 100644
--- a/source/blender/windowmanager/intern/wm_keymap.c
+++ b/source/blender/windowmanager/intern/wm_keymap.c
@@ -1213,7 +1213,14 @@ wmKeyMap *WM_keymap_guess_opname(const bContext *C, const char *opname)
km = WM_keymap_find_all(C, "Pose", 0, 0);
}
else if (strstr(opname, "SCULPT_OT")) {
- km = WM_keymap_find_all(C, "Sculpt", 0, 0);
+ switch(CTX_data_mode_enum(C)) {
+ case OB_MODE_SCULPT:
+ km = WM_keymap_find_all(C, "Sculpt", 0, 0);
+ break;
+ case OB_MODE_EDIT:
+ km = WM_keymap_find_all(C, "UV Sculpt", 0, 0);
+ break;
+ }
}
else if (strstr(opname, "MBALL_OT")) {
km = WM_keymap_find_all(C, "Metaball", 0, 0);
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index edd822bd2da..3a3be292f07 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -3807,6 +3807,7 @@ static void gesture_border_modal_keymap(wmKeyConfig *keyconf)
WM_modalkeymap_assign(keymap, "MARKER_OT_select_border");
WM_modalkeymap_assign(keymap, "NLA_OT_select_border");
WM_modalkeymap_assign(keymap, "NODE_OT_select_border");
+ WM_modalkeymap_assign(keymap, "OUTLINER_OT_select_border");
// WM_modalkeymap_assign(keymap, "SCREEN_OT_border_select"); // template
WM_modalkeymap_assign(keymap, "SEQUENCER_OT_select_border");
WM_modalkeymap_assign(keymap, "SEQUENCER_OT_view_ghost_border");
@@ -3882,7 +3883,7 @@ void wm_window_keymap(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "WM_OT_save_as_mainfile", SKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
WM_keymap_add_item(keymap, "WM_OT_save_as_mainfile", F2KEY, KM_PRESS, 0, 0);
kmi= WM_keymap_add_item(keymap, "WM_OT_save_as_mainfile", SKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
- RNA_boolean_set(kmi->ptr, "copy", 1);
+ RNA_boolean_set(kmi->ptr, "copy", TRUE);
WM_keymap_verify_item(keymap, "WM_OT_window_fullscreen_toggle", F11KEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "WM_OT_quit_blender", QKEY, KM_PRESS, KM_CTRL, 0);