How I can add a moving hole in a box or ground? If I understand correctly CSG is not for animation?
Welcome aboard!
CSG can be slow, so if you want to animate per frame it may not be the way to go.
The easiest way would be to use an opacity texture with a hole inside and adjust the uOffset/vOffset properties to make it move:
But if it should be more like a golf hole where you can put objects?
More like this
https://psv4.userapi.com/c856216/u36109728/docs/d6/7304b7f07427/output.gif?extra=Dflnvvf7ehfYwlGhtxukZOP7KeRuB-tPFrcfzqMKmGnomOrRKVaiQ863HTMu9a74NaYWAbTHWn81P38HsDr50qsH3z8orwBKEiPWnRhSaqujrUpzdc8HKLu8s4BczIRF-yRm3fwjNYli1vS03eg
It won’t work for me. I want to add a hole to a scene like this (Babylon.js Playground) and a ball can fall into a hole.
Idk, maybe I should create a level in blender or something and then move an object. Is it possible? I’m new to 3d stuff
You need the hole to change position at each frame? Or is it something like a “level”, for level X the hole must be in a different location than for level Y?
If the latter, you can use CSG, as you don’t have a realtime requirement.
The first option, change position at each frame. Like in this gif. For static holes i saw the solution in this thread, but it don’t work for me
Mesh operations look realy interesting, but works only with square.
Ooo, cool. Shaders look like a solution. But if i will do it by using shaders physics engine like cannon js will allow objects fell into that holes?
Hi @pleshakovalexander and welcome from me.
An alternative using
https://doc.babylonjs.com/how_to/parametric_shapes#extruded-non-regular-polygon
Is the ground flat as in the gif? Or do you need varying terrain as well?
Thank you! This solution is much easier than shaders. I will try this one with circles first
I think for now i’ll try only with flat objects. It’s complicated enough for me)
if I add a circle hole to a cube i get this artifact. Can’t understand why.
If I add a circle hole to a circle then I have this little artifact
or use integers and multiplication in loop https://www.babylonjs-playground.com/#6KLAZJ#4
I wonder what the performance costs will be. You’ll have to dispose the meshImpostor and recreate it every frame.
True if using a physics engine. Depends on use. If just a rolling ball animation using change of position and rotation should be enough. To check for the hole use a ray to find how far centre of ball is above the surface and drop if not a number.
Wow, interesting, but so many lines. I will try it next!
And I found one more. The solution is put cylinder to 0 index of scene.meshes array and disable color writing for this cylinder
var mask_index = scene.meshes.indexOf(cylinder);
scene.meshes[mask_index] = scene.meshes[0];
scene.meshes[0] = cylinder;cylinder.registerBeforeRender(function () {
engine.setColorWrite(false);
});
cylinder.registerAfterRender(function () {
engine.setColorWrite(true);
});
From this tutorial for Unity I found out about depth masks and search abut it in Babylon. Solution was founded here