3

Is there a way to get the actual intersection of to geometries with BabylonJS?

E.g. the intersection point of a line and a plane, the line intersection of two planes, the arc intersection of a sphere and a plane, etc...

Thanks!

leeodelion
  • 151
  • 6

1 Answers1

4

I believe what you are looking for is the CSG (Constructive Solid Geometry) tools in Babylon.js. To use it you can reference this tutorial here. Essentially what you want to do is the following:

CSG intersect (modified code from the link)

// a and b can be any mesh you define
var a = BABYLON.Mesh.CreateBox("box", 500, scene); 
var b = BABYLON.Mesh.CreateBox("box", 500, scene);

// Convert to CSG meshes
var aCSG = BABYLON.CSG.FromMesh(a);
var bCSG = BABYLON.CSG.FromMesh(b);
var subCSG = bCSG.intersect(aCSG);

// Disposing original meshes since we don't want to see them on the scene
a.dispose();
b.dispose();

// Convert back to regular mesh from CSG mesh
subCSG.toMesh("csg", new BABYLON.StandardMaterial("mat", scene), scene);

For more uses of CSG you should check out the documentation.

Svit
  • 311
  • 3
  • 7