Feldspar Posted March 4, 2014 Share Posted March 4, 2014 Hi guys, I wanted to share with you a custom library I made, that was very helpful on my project. It implements the basic constructive operations on meshes, like union, intersection, subtraction etc. In 3 words, it's called "constructive solid geometry". The library is an adaptation from csg.js (http://evanw.github.com/csg.js) for BabylonJS meshes. You will find this lib useful if you meet the need to dynamically build your own geometry with basic primitives. For instance you can carve cylindric holes in bigger cylinders to create pipes (wink wink to all old-school Half-Life mappers down there ). Anyhow, you can find the repository over here : https://github.com/CraigFeldspar/BabylonCSG.I'm still testing it, so feel free to signal any bug you would find.. Cheers !Feldspar. Boz, Wingnut, suresh1187 and 3 others 6 Quote Link to comment Share on other sites More sharing options...
gwenael Posted March 4, 2014 Share Posted March 4, 2014 Awesome according to pictures. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted March 4, 2014 Share Posted March 4, 2014 This is excellent. This could be integrated has babylon if Deltakosh is in agreement? Good job Quote Link to comment Share on other sites More sharing options...
davrous Posted March 5, 2014 Share Posted March 5, 2014 Very cool! Have you hosted an online demo somewhere? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 5, 2014 Share Posted March 5, 2014 I want a pull request!!!!!!! Quote Link to comment Share on other sites More sharing options...
AndyBeaulieu Posted March 5, 2014 Share Posted March 5, 2014 Very nice! Any chance a boolean operation could also update the underlying Cannon.js physics body? Quote Link to comment Share on other sites More sharing options...
Feldspar Posted March 5, 2014 Author Share Posted March 5, 2014 Thanks for your feedback ! @davrous : No demo atm, but i'm gonna set up a jsFiddle with some tweak possibilities when i get a little free time. @deltakosh : My pleasure I wasn't sure if you wanted this module to be part of Babylon, that's the reason why I created a repo. I'm still working on making it work with MultiMaterials though, the PR will follow just right after. @AndyBeaulieu : I did not think about that for now, but I guess if you apply the exact same operations to Cannon.js solid primitives, you could get some decent result. Try to convert Cannon.js objects to CSG polygons and see what happens ! Looking forward to it suresh1187 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 11, 2014 Share Posted March 11, 2014 Hello, I've just integrated your great code. My next ask would be: Could you create a small demo like this ones that showcases features of CSG ?var CreateFogScene = function(engine) { var scene = new BABYLON.Scene(engine); var camera = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(0, 0, -20), scene); var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(20, 100, 2), scene); var sphere0 = BABYLON.Mesh.CreateSphere("Sphere0", 16, 3, scene); var sphere1 = BABYLON.Mesh.CreateSphere("Sphere1", 16, 3, scene); var sphere2 = BABYLON.Mesh.CreateSphere("Sphere2", 16, 3, scene); var material0 = new BABYLON.StandardMaterial("mat0", scene); material0.diffuseColor = new BABYLON.Color3(1, 0, 0); sphere0.material = material0; sphere0.position = new BABYLON.Vector3(-10, 0, 0); var material1 = new BABYLON.StandardMaterial("mat1", scene); material1.diffuseColor = new BABYLON.Color3(1, 1, 0); sphere1.material = material1; var material2 = new BABYLON.StandardMaterial("mat2", scene); material2.diffuseColor = new BABYLON.Color3(1, 0, 1); sphere2.material = material2; sphere2.position = new BABYLON.Vector3(10, 0, 0); sphere1.convertToFlatShadedMesh(); camera.setTarget(new BABYLON.Vector3(0, 0, 0)); // Fog scene.fogMode = BABYLON.Scene.FOGMODE_EXP; scene.fogDensity = 0.1; // Animations var alpha = 0; scene.registerBeforeRender(function () { sphere0.position.z = 4 * Math.cos(alpha); sphere1.position.z = 4 * Math.sin(alpha); sphere2.position.z = 4 * Math.cos(alpha); alpha += 0.1; }); return scene;}; Artem 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 14, 2014 Share Posted March 14, 2014 Up Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 14, 2014 Share Posted March 14, 2014 OK I started a demo:) but I have issue with box.subtract(sphere). I created an issue on your github project:) Quote Link to comment Share on other sites More sharing options...
Feldspar Posted March 17, 2014 Author Share Posted March 17, 2014 Sorry, I was away for a few days, gonna have a look asap.Thanks Quote Link to comment Share on other sites More sharing options...
Feldspar Posted March 17, 2014 Author Share Posted March 17, 2014 David,I looked into it and it seems CSG did not handle degenerated triangles (3 points aligned). I patched it, and your example is now working fine for me. Can you try it and give me a notice if everything is OK ? suresh1187 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 17, 2014 Share Posted March 17, 2014 It works very well. new demo will be cool thanks a lot Quote Link to comment Share on other sites More sharing options...
Feldspar Posted March 18, 2014 Author Share Posted March 18, 2014 Awesome, thanks for making a demo for it, i'm kinda overbooked right now.Looking forward to it ! GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
AlbertoBonn Posted March 24, 2014 Share Posted March 24, 2014 Fantastic, thanx a lot! Quote Link to comment Share on other sites More sharing options...
culeaalex Posted October 5, 2014 Share Posted October 5, 2014 How can I make this work for plane? When I try to make a hole in a plane with a sphere (subtract), the result is the same plane with a dent in it. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 6, 2014 Share Posted October 6, 2014 try with a box with a really small scale on one direction Quote Link to comment Share on other sites More sharing options...
culeaalex Posted October 8, 2014 Share Posted October 8, 2014 try with a box with a really small scale on one directionI thought this will be the only sollution. Quote Link to comment Share on other sites More sharing options...
ancientholiday Posted March 25, 2016 Share Posted March 25, 2016 How to make intersect and subtract work for imported meshes? Please see file attached. I am trying to make boxes cut skull.babylon mesh however it does not work when i make var a = the scene.mesh[0]indexCSG.html thanks, Quote Link to comment Share on other sites More sharing options...
BartW Posted August 2, 2018 Share Posted August 2, 2018 This is awesome! I guess when you want to animate an object intersecting another object, the mesh needs to be regenerated each frame? Quote Link to comment Share on other sites More sharing options...
JohnK Posted August 2, 2018 Share Posted August 2, 2018 59 minutes ago, BartW said: This is awesome! I guess when you want to animate an object intersecting another object, the mesh needs to be regenerated each frame? Not necessarily, though it does depend on what you wish to achieve. If you want one mesh to move through another creating a hole in the mesh passed through then as in the following playground you can create the before and after meshes and swap them at the appropriate time https://www.babylonjs-playground.com/#FPIYDA Quote Link to comment Share on other sites More sharing options...
BartW Posted August 2, 2018 Share Posted August 2, 2018 I was thinking more in the direction of this type of mesh intersection: https://www.thisiscolossal.com/2018/06/virtual-reality-cat-explorer/ Quote Link to comment Share on other sites More sharing options...
JohnK Posted August 2, 2018 Share Posted August 2, 2018 So you need dynamic subtraction of multiple meshes. Have you tried CSG with invisible meshes? That way you might get way with just disposing of and re-creating the CSG and mesh from CSG each frame. By the way personally I would ask a new question rather than adding to this topic which is a really a demo thread. I would show the video and ask the question anew. Up to you of course. ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.