How to assign the "slice" plane in local coordinates?

I'm trying to add a "Slice" modifier through script.
The source object (to which the modifier is being added), is a sphere. It has been rotated randomly.
There is another object, let's say a plane.
I want the slice modifier gizmo to have the same orientation and position as the plane.

How do I do it?

The catch is that the gizmo transform should be mentioned in the local space of the sphere.
effectively, i need to represent the orientation and position of the plane as local coordinates of the sphere.

Thanks

Comments

Comment viewing options

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

With the Sphere object named

With the Sphere object named "Sphere01" and the Plane object "Plane01", and with the Slice Modifier being at pos 1 in the modifier stack of the Sphere the following script seems to work.

(
a = $Plane01.rotation
b = $Sphere01.rotation

$Sphere01.modifiers[1].slice_plane.controller[2].controller.value = b-a

c = $Plane01.pos[3]
d = $Sphere01.pos[3]

$Sphere01.modifiers[1].slice_plane.controller[1].controller[3].value = c-d
)

the first two lines apply values to the variables a and b, taken from the rotation of each object.

the third line rotates the slice modifier to correct orientation by subtracting the plane's rotation (a) from the sphere's rotation (b) - and then applying it to the rotation matrix of the slice modifier.

the lines after do a similar process with purely the z co-ordinate in each object, thus positioning the slice modifier correctly in z co-ordinates to the sphere driven by the plane.

Hope this is what you were looking for, makes sense, and you can alter and use it as need be.

Martin
www.martinskinner.co.uk

martinskinner's picture

I'd have thought it would be

I'd have thought it would be as easy as finding the transforms of the plane in relation to the plane, and then applying them to the gizmo of the slice modifier used on the sphere in relation to the sphere.

I'll have a look and get back to you.

Comment viewing options

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