[Solved] Trouble with moving vertices according to math function.

Hello everyone spending time for beginner's question :)

I want to create a script that converts an object to an editable poly, and then it changes third coordinate (z) of every vertex, according to specified math function.

Let's say I want to use sin(x). Then, I want to:

1. Convert object to an editable poly.
2. In loop, get z coordinate of each subsequent vertex.
3. Move it up or down so the z value changes to sin(z).

Now, imagine triangle as half of square, placed vertically.
I want to run this script so the triangle gets a "y=sin(x)"-shaped edge, instead of "y=x"-shaped one

Here is the code:

h = $.height
obj = convertToPoly($)
subobjectlevel = 1
 
for i in 1 to obj.numVerts do
(
	pos=polyop.getVert obj i
	z=pos.z
	z/=h
	z*=pi
	z=sin(z)+1
	z/=2
	z*=h
	z-=pos.z
	u=[0,0,z]
	polyop.MoveVert obj i u
)
subobjectlevel = 0

_______________________________________________________________________________
EDIT:

Well, as soon as i have found Sword of Apollo's Function Sculptor (click here to see it), everything I wanted to achieve became really easy.

This script is the best solution I could imagine. Of course, it would be good if some minor tweaks were applied just to improve usage experience, but it works perfectly for me.

Everything I have to do now is to play with some math parameters for sin(x), for example:

sin(30*x-pi/2), so it suits perfectly for what I am actually doing.

Again, thanks to everybody who looked into this topic and wanted to help.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
miauu's picture

You can post an image where

You can post an image where the vert, triangle, x, y, are drawn, so we can understand what exactly do you need.

general_lee's picture

Is Function Sculptor a possible solution?

h is equal to height of the object.
I was going by every second vertex due to temporary reasons, it is not a bug, i just wanted to check "what happens". It doesn't matter, though.

My problem is: How to transform sin(x) so I can get result described above.
__________________________________________________________________________________
EDIT

I have found a script named Sword of Apollo's Function Sculptor (click here to see it).

Maybe it will help me do my work, sooner or later I will share my opinion and feedback about experience.

Thanks for being interested :)
__________________________________________________________________________________
EDIT

The Function Sculptor script does its job well. It is exactly what I wanted :)

miauu's picture

In your code the H is equal

In your code the H is equal to...?
ALso, you wants to move every verts, but your for loop will move 1,3,5,7.... n verts(slip the even verts). Why?
Where is the problem with your code?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.