# How to scale cut plane d translation with rotation?

Hi there,

I’ve been looking into cut planes, and so far so good with the basics. However, I’ve got a bit stuck on trying to add an x + y rotation combined with a z translation with a visible plane.

The translations of the cut plane work great, but it looks like during my translation I need to scale the d value - in my current example whenever I apply an x and y rotation, the visible plane has an unwanted offset. I’m not sure how to remove the visible offset and I’m guessing it’s a scaling issue. I’m not sure how to remove it.

I’m using the following playground as a guide to get me going: https://www.babylonjs-playground.com/#Y6W087#68

Thanks for any help or guidance you can give

Well, it’s hard to help without a repro that fails. You should try to provide a repro where things don’t work as expected so that we can have a look.

It fails in the playground try the sliders and you ll see that both planes do not match when moving them.

Indeed!

The problem comes from the fact that the normals should be normalized after they have been transformed:

https://www.babylonjs-playground.com/#Y6W087#69

3 Likes

Long live the king @Evgeni_Popov !!! GG

2 Likes

Thank you so much @Evgeni_Popov and @sebavan - that works perfectly! I got completely muddled up were the normalisation was supposed to be. Thanks

@Evgeni_Popov and @sebavan - sorry to bug you both again.

The above example is brilliant, but I’ve managed to get stuck again.

Is there a way to rotate the cut plane at its translated position? At the moment, like in the above example, when you translate along the z, the rotation point remains to be at the scene.clipPlane3.normal vector. I’d like to move the rotation point to where the cut plane has been translated to. So that the rotation pivots about the visible plane?

Thanks again for all your help, any guidance would be greatly appreciated

I don’t really understand what you want to achieve…

It seems it’s not related to clip planes anymore but it’s more a math question? In that case, maybe @JohnK will know what you want to do(?)

Thank you @Evgeni_Popov, sorry it’s not very clear. This is all still new to me so appreciate your help so far

Hi all,

First off, I just wanted to say a huge thanks to @Evgeni_Popov and @sebavan. You’ve always gone above and beyond to show me the way. It’s a learning curve, but a good one!

I’ve finally managed to pick the above back up to see if I can further my understanding (I thought I had the maths but failed). I’ve been experimenting with the above to see how to implement cut sections with models that are off-centred in world space. Similar to the question above, but the model position is (50, 100, 1000) instead of (0,0,0).

I’ve made some progress. I’ve managed to get the Z translation and X rotation to mostly work (apart from the visible plane flipping/spinning behaviour).

The block I’ve run into is how to get the Y rotation to work with the new model coordinate. I’m guessing I’ve taken the wrong approach, and at this point, my brain keeps going round in circles.

Can anyone see where I’m going wrong? https://www.babylonjs-playground.com/#Y6W087#112

Green slider mostly works (x-rotation) as intended (excluding the visible plane flipping behaviour, not sure how to fix that either)

Red slider, no luck. I’m trying to apply the y-rotation (like the example here: https://www.babylonjs-playground.com/#Y6W087#69)

The blue slider works (z-translation).

I’m experimenting to see if I can get the cut rotations to happen in the centre of the model, instead of the world space. So it feels more fluid.

Thanks for any guidance/help

Playground

It seems it does it:

https://www.babylonjs-playground.com/#Y6W087#118

You can use `plane.transform` to apply a transform to the plane (here a translation).

1 Like

Thanks @Evgeni_Popov, that’s awesome! Learnt something new again. Thanks for your help

Sorry, I’ve got yet another follow up question. Following your direction from before, is it possible in Babylon to apply the rotation transformation of the clip plane in local space relative to the plane position? Rather than global/world space?

i.e. similar behaviour to doing `plane.translate(BABYLON.Axis.X, 2, BABYLON.Space.LOCAL);` but with the clipplane too?

The use-case (when using this playground) is when the red slider is halfway, using the green slider makes the plane just spin (due to the global Transform). I’m a bit stuck in finding a way to rotate the plane from the local normal.

I don’t understand what you would want it to do in that case?

The green button makes a Y rotation, so the plane will spin as shown here, which is expected:

Sorry I wasn’t clear - I find it hard to explain.

I’ve created a rough playground here. Hopefully, it shows better what I mean. It manipulates the visible plane with the desired effect I’m trying to achieve with the clip plane. It transforms the local vector of the visible plane. But I’m not sure how to do the same local transform with the clip plane?

So when the plane is like this

It still transforms on the local x y of the plane (and clip plane).

Thanks again for any guidance you might be able to give

If you can do what you want with a regular 3D plane, just convert this 3D plane to a `Plane` object: you just need to compute the normal and the d factor of the plane equation:

https://www.babylonjs-playground.com/#Y6W087#129

1 Like

Thank you @Evgeni_Popov, you’ve saved the day again! That’s really cool, had no idea it was possible to convert the other way. Thank you so much!