[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50787] trunk/blender: calculate sticky wasnt working very well and had a few glites -
Campbell Barton
ideasman42 at gmail.com
Fri Sep 21 08:37:42 CEST 2012
Revision: 50787
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50787
Author: campbellbarton
Date: 2012-09-21 06:37:42 +0000 (Fri, 21 Sep 2012)
Log Message:
-----------
calculate sticky wasnt working very well and had a few glites -
updating data was only being done on the active object but sticly was being calculated for the selection.
split this into 2 operators, one that works on the selection and another that operates on the active object - so we can have a button in the mesh panels that calculates sticky.
also note that there was no way to calculate sticky from the UI - perhaps this feature should die a quiet death?
anyway - it works better then it used to for now.
Modified Paths:
--------------
trunk/blender/release/scripts/startup/bl_ui/properties_data_mesh.py
trunk/blender/source/blender/editors/mesh/mesh_data.c
trunk/blender/source/blender/editors/mesh/mesh_intern.h
trunk/blender/source/blender/editors/mesh/mesh_ops.c
trunk/blender/source/blender/render/extern/include/RE_render_ext.h
trunk/blender/source/blender/render/intern/source/convertblender.c
Modified: trunk/blender/release/scripts/startup/bl_ui/properties_data_mesh.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/properties_data_mesh.py 2012-09-21 06:14:22 UTC (rev 50786)
+++ trunk/blender/release/scripts/startup/bl_ui/properties_data_mesh.py 2012-09-21 06:37:42 UTC (rev 50787)
@@ -326,9 +326,9 @@
# me = context.mesh
col = layout.column(align=True)
- # row = col.row(align=True)
- # row.operator("mesh.customdata_add_sticky", icon='ZOOMIN')
- col.operator("mesh.customdata_clear_sticky", icon='X')
+ row = col.row(align=True)
+ row.operator("mesh.customdata_create_sticky")
+ row.operator("mesh.customdata_clear_sticky", icon='X')
col.operator("mesh.customdata_clear_mask", icon='X')
col.operator("mesh.customdata_clear_skin", icon='X')
Modified: trunk/blender/source/blender/editors/mesh/mesh_data.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/mesh_data.c 2012-09-21 06:14:22 UTC (rev 50786)
+++ trunk/blender/source/blender/editors/mesh/mesh_data.c 2012-09-21 06:37:42 UTC (rev 50787)
@@ -47,6 +47,8 @@
#include "BLI_array.h"
#include "BLI_math.h"
#include "BLI_edgehash.h"
+#include "BLI_linklist.h"
+#include "BLI_listbase.h"
#include "BKE_context.h"
#include "BKE_depsgraph.h"
@@ -143,24 +145,10 @@
int i, actindex, rndindex, cloneindex, stencilindex, tot;
if (layer->type == CD_MLOOPCOL || layer->type == CD_MLOOPUV) {
- if (me->edit_btmesh) {
- data = &me->edit_btmesh->bm->ldata;
- tot = me->edit_btmesh->bm->totloop;
- }
- else {
- data = &me->ldata;
- tot = me->totloop;
- }
+ data = mesh_customdata_get_type(me, BM_LOOP, &tot);
}
else {
- if (me->edit_btmesh) {
- data = &me->edit_btmesh->bm->pdata;
- tot = me->edit_btmesh->bm->totface;
- }
- else {
- data = &me->pdata;
- tot = me->totpoly;
- }
+ data = mesh_customdata_get_type(me, BM_FACE, &tot);
}
index = CustomData_get_layer_index(data, type);
@@ -761,43 +749,116 @@
/*********************** sticky operators ************************/
-/* FIXME - this operator is broken - only updates active but operates on selected */
-static int mesh_sticky_add_exec(bContext *C, wmOperator *UNUSED(op))
+static Object *mesh_customdata_get_camera_for_sticky(wmOperator *op, Scene *scene, View3D *v3d)
{
+ /* report an error if we can't find the camera */
+
+ Object *camera = NULL;
+ if (scene->obedit) {
+ BKE_report(op->reports, RPT_ERROR, "Unable to make sticky in Edit Mode");
+ }
+ else {
+ if (v3d) camera = V3D_CAMERA_LOCAL(v3d);
+ if (camera == NULL) camera = scene->camera;
+
+ if (camera == NULL) {
+ BKE_report(op->reports, RPT_ERROR, "Need camera to make sticky");
+ }
+ }
+
+ return camera;
+}
+
+static int mesh_customdata_add_sticky_selected_exec(bContext *C, wmOperator *op)
+{
Scene *scene = CTX_data_scene(C);
View3D *v3d = CTX_wm_view3d(C);
- Object *ob = ED_object_context(C);
- Mesh *me = ob->data;
+ Object *camera = mesh_customdata_get_camera_for_sticky(op, scene, v3d);
+ LinkNode *objects = NULL;
+ LinkNode *ob_iter;
- /* why is this commented out? */
-#if 0
- if (me->msticky)
+ if (camera == NULL) {
return OPERATOR_CANCELLED;
-#endif
+ }
- RE_make_sticky(scene, v3d);
+ CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects)
+ {
+ if (ob->type == OB_MESH) {
+ BLI_linklist_prepend(&objects, ob);
+ }
+ }
+ CTX_DATA_END;
- DAG_id_tag_update(&me->id, 0);
- WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
+ if (objects == NULL) {
+ return OPERATOR_CANCELLED;
+ }
+ RE_make_sticky(scene, camera, objects);
+
+ for (ob_iter = objects; ob_iter; ob_iter = ob_iter->next) {
+ Object *ob = ob_iter->link;
+ DAG_id_tag_update(ob->data, 0);
+ WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
+ }
+
+ BLI_linklist_free(objects, NULL);
+
return OPERATOR_FINISHED;
}
-void MESH_OT_customdata_add_sticky(wmOperatorType *ot)
+void MESH_OT_customdata_create_sticky_selected(wmOperatorType *ot)
{
/* identifiers */
- ot->name = "Add Sticky";
- ot->description = "Add sticky UV texture layer";
- ot->idname = "MESH_OT_customdata_add_sticky";
-
+ ot->name = "Calculate Sticky for Selection";
+ ot->description = "Calculate sticky UV texture layer from the camera on selected objects";
+ ot->idname = "MESH_OT_customdata_create_sticky_selected";
+
/* api callbacks */
ot->poll = layers_poll;
- ot->exec = mesh_sticky_add_exec;
+ ot->exec = mesh_customdata_add_sticky_selected_exec;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
+static int mesh_customdata_add_sticky_exec(bContext *C, wmOperator *op)
+{
+ Object *obedit = ED_object_context(C);
+ Scene *scene = CTX_data_scene(C);
+ View3D *v3d = CTX_wm_view3d(C);
+ Object *camera = mesh_customdata_get_camera_for_sticky(op, scene, v3d);
+ LinkNode objects = {NULL};
+
+ if (camera == NULL) {
+ return OPERATOR_CANCELLED; /* error is set */
+ }
+
+ objects.link = obedit;
+ objects.next = NULL;
+
+ RE_make_sticky(scene, camera, &objects);
+
+ DAG_id_tag_update(obedit->data, 0);
+ WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
+
+ return OPERATOR_FINISHED;
+}
+
+void MESH_OT_customdata_create_sticky(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Calculate Sticky";
+ ot->description = "Calculate sticky UV texture layer from the camera";
+ ot->idname = "MESH_OT_customdata_create_sticky";
+
+ /* api callbacks */
+ ot->poll = layers_poll;
+ ot->exec = mesh_customdata_add_sticky_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
/* *** CustomData clear functions, we need an operator for each *** */
static int mesh_customdata_clear_exec__internal(bContext *C,
Modified: trunk/blender/source/blender/editors/mesh/mesh_intern.h
===================================================================
--- trunk/blender/source/blender/editors/mesh/mesh_intern.h 2012-09-21 06:14:22 UTC (rev 50786)
+++ trunk/blender/source/blender/editors/mesh/mesh_intern.h 2012-09-21 06:37:42 UTC (rev 50787)
@@ -187,9 +187,10 @@
void MESH_OT_uv_texture_remove(struct wmOperatorType *ot);
void MESH_OT_vertex_color_add(struct wmOperatorType *ot);
void MESH_OT_vertex_color_remove(struct wmOperatorType *ot);
-void MESH_OT_customdata_add_sticky(struct wmOperatorType *ot);
+void MESH_OT_customdata_create_sticky_selected(struct wmOperatorType *ot);
+void MESH_OT_customdata_create_sticky(struct wmOperatorType *ot);
void MESH_OT_customdata_clear_sticky(struct wmOperatorType *ot);
-/* no add mask yet */
+/* no create_mask yet */
void MESH_OT_customdata_clear_mask(struct wmOperatorType *ot);
void MESH_OT_customdata_clear_skin(struct wmOperatorType *ot);
Modified: trunk/blender/source/blender/editors/mesh/mesh_ops.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/mesh_ops.c 2012-09-21 06:14:22 UTC (rev 50786)
+++ trunk/blender/source/blender/editors/mesh/mesh_ops.c 2012-09-21 06:37:42 UTC (rev 50787)
@@ -143,7 +143,8 @@
WM_operatortype_append(MESH_OT_uv_texture_remove);
WM_operatortype_append(MESH_OT_vertex_color_add);
WM_operatortype_append(MESH_OT_vertex_color_remove);
- WM_operatortype_append(MESH_OT_customdata_add_sticky);
+ WM_operatortype_append(MESH_OT_customdata_create_sticky_selected);
+ WM_operatortype_append(MESH_OT_customdata_create_sticky);
WM_operatortype_append(MESH_OT_customdata_clear_sticky);
WM_operatortype_append(MESH_OT_customdata_clear_mask);
WM_operatortype_append(MESH_OT_customdata_clear_skin);
Modified: trunk/blender/source/blender/render/extern/include/RE_render_ext.h
===================================================================
--- trunk/blender/source/blender/render/extern/include/RE_render_ext.h 2012-09-21 06:14:22 UTC (rev 50786)
+++ trunk/blender/source/blender/render/extern/include/RE_render_ext.h 2012-09-21 06:37:42 UTC (rev 50787)
@@ -39,10 +39,11 @@
/* called by meshtools */
struct View3D;
struct Scene;
+struct LinkNode;
-void RE_make_sticky(struct Scene *scene, struct View3D *v3d);
-
-/* for radiosity module */
+void RE_make_sticky(struct Scene *scene, struct Object *camera, struct LinkNode *objects);
+
+/* for radiosity module */
struct RadView;
struct RNode;
struct Render;
Modified: trunk/blender/source/blender/render/intern/source/convertblender.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/convertblender.c 2012-09-21 06:14:22 UTC (rev 50786)
+++ trunk/blender/source/blender/render/intern/source/convertblender.c 2012-09-21 06:37:42 UTC (rev 50787)
@@ -41,6 +41,7 @@
#include "BLI_rand.h"
#include "BLI_memarena.h"
#include "BLI_ghash.h"
+#include "BLI_linklist.h"
#include "DNA_armature_types.h"
#include "DNA_camera_types.h"
@@ -5819,36 +5820,43 @@
/* Sticky texture coords */
/* ------------------------------------------------------------------------- */
-void RE_make_sticky(Scene *scene, View3D *v3d)
+static void re_make_sticky_object(Render *re, Object *ob)
{
- Object *ob;
- Base *base;
MVert *mvert;
Mesh *me;
MSticky *ms;
- Render *re;
- float ho[4], mat[4][4];
+ float mat[4][4];
+ float ho[4];
int a;
- Object *camera= NULL;
- if (v3d==NULL) {
- printf("Need a 3d view to make sticky\n");
- return;
+ me = ob->data;
+ mvert = me->mvert;
+
+ if (me->msticky) {
+ CustomData_free_layer_active(&me->vdata, CD_MSTICKY, me->totvert);
}
- if (v3d) camera= V3D_CAMERA_LOCAL(v3d);
- if (camera == NULL) camera= scene->camera;
+ me->msticky = CustomData_add_layer(&me->vdata, CD_MSTICKY, CD_CALLOC, NULL, me->totvert);
- if (camera==NULL) {
- printf("Need camera to make sticky\n");
- return;
+ mult_m4_m4m4(mat, re->viewmat, ob->obmat);
+
+ ms = me->msticky;
+ for (a=0; a < me->totvert; a++, ms++, mvert++) {
+ copy_v3_v3(ho, mvert->co);
+ mul_m4_v3(mat, ho);
+ projectverto(ho, re->winmat, ho);
+ ms->co[0] = ho[0] / ho[3];
+ ms->co[1] = ho[1] / ho[3];
}
- if (scene->obedit) {
- printf("Unable to make sticky in Edit Mode\n");
- return;
- }
-
- re= RE_NewRender("_make sticky_");
+}
+
+void RE_make_sticky(Scene *scene, Object *camera, LinkNode *objects)
+{
+ Render *re;
+ float mat[4][4];
+ LinkNode *ob_iter;
+
+ re = RE_NewRender("_make sticky_");
RE_InitState(re, NULL, &scene->r, NULL, scene->r.xsch, scene->r.ysch, NULL);
/* use renderdata and camera to set viewplane */
@@ -5859,31 +5867,8 @@
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list