5
$\begingroup$

So I'm looking at using a python script to randomly move each vertex in a mesh back or forwards on the z axis.

I've got it moving on the local/global axis but I'm wondering how I can do this on the normal axis. I've tried doing the following:

for v in bm.verts:
    v.co.z += v.normal.z * random.uniform(-0.05,0.05)

But this also only seems to move the vertices up and down, not outward like they would do if moving along the normal axis manually.

Anyway I'm probably missing something pretty simple here so thanks in advance.

$\endgroup$

1 Answer 1

7
$\begingroup$

if you only change v.co.z all will follow the z axis...

Try :

for v in bm.verts:
    r = random.uniform(-0.05,0.05)
    v.co.x += v.normal.x * r
    v.co.y += v.normal.y * r
    v.co.z += v.normal.z * r

As batFINGER says in the comment, that can be written as :

for v in bm.verts:
    r = random.uniform(-0.05,0.05)
    v.co += r * v.normal
$\endgroup$
3
  • $\begingroup$ Thanks very much for the quick reply, it worked perfectly. $\endgroup$ Jul 5, 2016 at 13:55
  • 2
    $\begingroup$ v.co += r * v.normal $\endgroup$
    – batFINGER
    Jul 5, 2016 at 14:00
  • $\begingroup$ thanks @batFINGER... I don't really know Python... $\endgroup$
    – lemon
    Jul 5, 2016 at 14:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .