ScriptSOP, how to modify points?

Hi all, I just read the SOP Script documentation:
“It can create, delete and modify points, primitives and their vertices.”
I’m trying to modify points using the point member of the SOP class, but it is readonly.
Can you someone please explain how to modify points?
Thank you

Are you trying to modify an existing set of points, or create a new set of points?

Just adding points you might do something like this:

def onCook(scriptOp):
	scriptOp.clear()
	
	for eachPoint in range(10):
		newP = scriptOp.appendPoint()
		newP.P = (eachPoint, 0, 0)
	
	return

The result would look like:

In that for loop you create a new Point (newP), then assign the Position attributes to that new Point by accessing the position attribute.


Let’s say instead you wanted to create a new Polygon

def onCook(scriptOp):
	scriptOp.clear()
	
	myPoly = scriptOp.appendPoly(10, closed=True, addPoints=True)
	
	for eachPoint in myPoly:
		eachPoint.point.P = (eachPoint.point.x + 1, eachPoint.point.y, eachPoint.point.z)
	
	return

That would look like this:

image

Here we first create the new polygon, then go back and loop through each of the vertices and modify their position.


If you want to modify geometry that already exists, you need to copy it to your scriptOp first like this:

def onCook(scriptOp):
	scriptOp.clear()
	
	scriptOp.copy(scriptOp.inputs[0])
	
	for eachPoint in scriptOp.points:
		eachPoint.P = (eachPoint.x + 1, eachPoint.y - 1, eachPoint.z)
	
	return

The result of this operation looks like this:

Here the first step was to copy the geometry from the first input (input index 0) to the script top, then loop through all of the points in that geometry and transform them.

The SOP Script Op is a little unwieldy at first, but it’s pretty cool what you can make with it and a little python.

Hope this helps!

1 Like

Hi Matthew, thank you for your reply.

Your examples are very useful but I was wondering if there is a way to modify an existing SOP without copy it at each cook. I was thinking to implement a special noise, based on my own criteria, to deform any existing SOP.
Or, even, to create the new point group at the first cook and then just modify points to get a better performance.

Thank you
Simone

To my knowledge I don’t think you can modify a SOP in a script SOP without copying the data into that operator. In that way the script SOP is pretty slow. You could create a group of points and only modify those pieces, then merge it back with your other surfaces, though you’ll likely end up with seams.

Other options include the expensive noise calculations at only a few key moments, then using the blend SOP to transform between them.

If you want / need a SOP for physics or collision data may end up needing to write a C++ SOP to get faster performance. The other pipelines from FaceBook are still good solutions - doing your calculations in a combination of CHOPs and TOPs then copying the data back to your SOP. The real trick for good noise operations is knowing the normal for the SOP. This helps you understand the vector for displacement.

Hi Matthew, this seems to modify the SOP SCRIPT’‘s points without reloading it each time… isn’t it?scriptSOPstep.1.toe (4.2 KB)
Just press the “Setup” button to load the grid for the first time.
Dman, I cant’ get rid of the “loop” issue! :smiley:

Hey @Simplo - I misspoke there. I assumed that you’d want changes that were up stream of your sop to trigger a cook in your script SOP. If you don’t need changes in your input geometry, then you wouldn’t need to copy the input each time. That just means that if your input geometry changes you need to manually trigger a copy to your script SOP. :grimacing:

Oh no, sorry, my english, many time, is so bad! :open_mouth:
My question was about the point member of the SOP class that is declared as READ ONLY.

Wait… point or points?

points is a read only list of all of the points, but a point can be modified in a script SOP.

1 Like

Thank you Matthew, I was trying to modify “point” using “points” :open_mouth:

1 Like

oh jeez! that one letter will get you, :slight_smile:
Excited to see what you make!

Hi Matthew, I’m actually taking advantage of you! :smiley:
Can I ask you if there is a way to modify the whole point matrix of the SOP in a single passage?
I mean, in the patch I uploaded I’m importing the null1 image in a numpyArray.
Assuming that is array is exactly same size of the object inside the scriptSOP, r and g values are all 0 and b value is the z-displacement, I would like to sum the whole grid to the point grid (via a numpy superfast function) instead of the slow iteration loop.
This z-displacement has become my obsession! :smiley:
Thank you for your patience!

I don’t think there’s an elegant way to do this:

So a crazy idea would be to explore something like this:

Setting your points z position / displacement to be a dependency object might give you a little more flexibility in terms of how to handle updates to displacement. This is more of a python deep dive, but might let you work around the current structure of the script SOP workflow.

I don’t know if how fast that would be, but it might be worth experimenting to see if it’s a workflow that you could use.

1 Like