patch [#24577] MESH_OT_noise. Adds missing 2.4x noise vertex displace functionality.
authorCampbell Barton <ideasman42@gmail.com>
Sun, 7 Nov 2010 03:56:58 +0000 (03:56 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 7 Nov 2010 03:56:58 +0000 (03:56 +0000)
from Dan Eicher (dna)

Also added a factor option so you can adjust the amount of noise applied.

release/scripts/ui/space_view3d_toolbar.py
source/blender/editors/mesh/editmesh_mods.c
source/blender/editors/mesh/mesh_intern.h
source/blender/editors/mesh/mesh_ops.c

index d2c6300eddc678fe386dce109259a70fc6cdf224..12ecc24ed2dd71457c866d487c38601d91a0f905 100644 (file)
@@ -96,6 +96,7 @@ class VIEW3D_PT_tools_meshedit(View3DPanel, bpy.types.Panel):
         col.label(text="Deform:")
         col.operator("transform.edge_slide")
         col.operator("mesh.rip_move")
+        col.operator("mesh.noise")
         col.operator("mesh.vertices_smooth")
 
         col = layout.column(align=True)
index 309ee6b57e2c6e6baba0a1d03ef0342cbfd43ec1..d83f25299be1b78ec6a21d8c3ef663ebcbce0d02 100644 (file)
@@ -59,6 +59,7 @@ editmesh_mods.c, UI level access, no geometry changes
 #include "BKE_material.h"
 #include "BKE_paint.h"
 #include "BKE_report.h"
+#include "BKE_texture.h"
 
 #include "IMB_imbuf_types.h"
 #include "IMB_imbuf.h"
@@ -4425,48 +4426,76 @@ void MESH_OT_vertices_smooth(wmOperatorType *ot)
        RNA_def_boolean(ot->srna, "zaxis", 1, "Z-Axis", "Smooth along the Z axis.");
 }
 
-void vertexnoise(Object *obedit, EditMesh *em)
+static int mesh_noise_exec(bContext *C, wmOperator *op)
 {
+       Object *obedit= CTX_data_edit_object(C);
+       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
        Material *ma;
        Tex *tex;
        EditVert *eve;
-       float b2, ofs, vec[3];
+       float fac= RNA_float_get(op->ptr, "factor");
+
+       if(em==NULL) return OPERATOR_FINISHED;
 
-       if(em==NULL) return;
-       
        ma= give_current_material(obedit, obedit->actcol);
        if(ma==0 || ma->mtex[0]==0 || ma->mtex[0]->tex==0) {
-               return;
+               return OPERATOR_FINISHED;
        }
-       tex= ma->mtex[0]->tex;
-       
-       ofs= tex->turbul/200.0;
-       
-       eve= (struct EditVert *)em->verts.first;
-       while(eve) {
-               if(eve->f & SELECT) {
-                       
-                       if(tex->type==TEX_STUCCI) {
-                               
+       tex= give_current_material_texture(ma);
+
+
+       if(tex->type==TEX_STUCCI) {
+               float b2, vec[3];
+               float ofs= tex->turbul/200.0;
+               for(eve= em->verts.first; eve; eve= eve->next) {
+                       if(eve->f & SELECT) {
                                b2= BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1], eve->co[2]);
                                if(tex->stype) ofs*=(b2*b2);
-                               vec[0]= 0.2*(b2-BLI_hnoise(tex->noisesize, eve->co[0]+ofs, eve->co[1], eve->co[2]));
-                               vec[1]= 0.2*(b2-BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1]+ofs, eve->co[2]));
-                               vec[2]= 0.2*(b2-BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1], eve->co[2]+ofs));
+                               vec[0]= fac*(b2-BLI_hnoise(tex->noisesize, eve->co[0]+ofs, eve->co[1], eve->co[2]));
+                               vec[1]= fac*(b2-BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1]+ofs, eve->co[2]));
+                               vec[2]= fac*(b2-BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1], eve->co[2]+ofs));
                                
                                add_v3_v3(eve->co, vec);
                        }
-                       else {
+               }
+       }
+       else {
+               for(eve= em->verts.first; eve; eve= eve->next) {
+                       if(eve->f & SELECT) {
                                float tin, dum;
                                externtex(ma->mtex[0], eve->co, &tin, &dum, &dum, &dum, &dum, 0);
-                               eve->co[2]+= 0.05*tin;
+                               eve->co[2]+= fac*tin;
                        }
                }
-               eve= eve->next;
        }
 
        recalc_editnormals(em);
-//     DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
+
+       BKE_mesh_end_editmesh(obedit->data, em);
+
+       DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+
+       return OPERATOR_FINISHED;
+}
+
+void MESH_OT_noise(wmOperatorType *ot)
+{
+       PropertyRNA *prop;
+       
+       /* identifiers */
+       ot->name= "Noise";
+       ot->description= "Use vertex coordinate as texture coordinate";
+       ot->idname= "MESH_OT_noise";
+
+       /* api callbacks */
+       ot->exec= mesh_noise_exec;
+       ot->poll= ED_operator_editmesh;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       prop= RNA_def_float(ot->srna, "factor", 0.1f, -FLT_MAX, FLT_MAX, "Factor", "", 0.0f, 1.0f);
 
 }
 
index fcd1eb40a02eb05bace7d07c3a5943bbf6bfd366..e80176586d9d058caaaa2200e94b0de8fc052b5d 100644 (file)
@@ -165,6 +165,7 @@ void MESH_OT_loop_multi_select(struct wmOperatorType *ot);
 void MESH_OT_mark_seam(struct wmOperatorType *ot);
 void MESH_OT_mark_sharp(struct wmOperatorType *ot);
 void MESH_OT_vertices_smooth(struct wmOperatorType *ot);
+void MESH_OT_noise(struct wmOperatorType *ot);
 void MESH_OT_flip_normals(struct wmOperatorType *ot);
 void MESH_OT_solidify(struct wmOperatorType *ot);
 void MESH_OT_select_nth(struct wmOperatorType *ot);
index 2ff7095cfeaa5903d222763cf45a1f70558ae022..e3ddc2e550c2c2e31b7e8b3811d5d7d4874c04bb 100644 (file)
@@ -123,6 +123,7 @@ void ED_operatortypes_mesh(void)
        WM_operatortype_append(MESH_OT_mark_seam);
        WM_operatortype_append(MESH_OT_mark_sharp);
        WM_operatortype_append(MESH_OT_vertices_smooth);
+       WM_operatortype_append(MESH_OT_noise);
        WM_operatortype_append(MESH_OT_flip_normals);
        WM_operatortype_append(MESH_OT_knife_cut);
        WM_operatortype_append(MESH_OT_rip);