seb75 Posted March 20, 2018 Share Posted March 20, 2018 Hey, I use a mesh representing an surface, defined with customMesh. I want to crop the part of this surfacic mesh which goes outside of a given solid defined by an extruded polygon. I tried to do this using BABYLON.CSG, but my mesh is not a solid, only a surface, so iI does not work. Do you know any method to crop a mesh given a closed mesh ? thanks! Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted March 20, 2018 Share Posted March 20, 2018 PlayGround please. Quote Link to comment Share on other sites More sharing options...
adam Posted March 20, 2018 Share Posted March 20, 2018 You might be able to do something with CustomMaterial: https://playground.babylonjs.com/#AFRP1L seb75 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted March 21, 2018 Share Posted March 21, 2018 @adam hmmm, that's in interesting idea I wonder if you could raymarch clipping shapes. Quote Link to comment Share on other sites More sharing options...
JohnK Posted March 21, 2018 Share Posted March 21, 2018 Hi @seb75 and welcome to the forum. Just a thought, as you are creating your own custom mesh you could create it as a thin 'solid' mesh rather than a surface then you could use CSG. https://www.babylonjs-playground.com/#RS3L95 seb75 1 Quote Link to comment Share on other sites More sharing options...
seb75 Posted March 21, 2018 Author Share Posted March 21, 2018 @adam thanks, the CustomMaterial function would be working, but i'm unable to use custom function within the condition of the function. https://playground.babylonjs.com/#AFRP1L This simple example is working, but not when I change the vPositionW.x -vPositionW.z > 5 test to a more complex one using one my my own function. mat.Fragment_Custom_Diffuse('if( vPositionW.x -vPositionW.z > 5.){ discard; }'); Do you have any idea how to use custom function in this .Fragment_Custom_Diffuse ? @JohnK thanks for the idea to create a solid instead of a surface. However, as I'm using several hundred copies of the same mesh, I think performances would be worse if I complexify the mesh from a surface to a solid, isn"t it ? Quote Link to comment Share on other sites More sharing options...
JohnK Posted March 21, 2018 Share Posted March 21, 2018 4 minutes ago, seb75 said: I think performances would be worse if I complexify the mesh from a surface to a solid, isn"t it ? Possible, however if your surface is already double side you would use single sided for 'top and 'bottom' and you would only be increasing the number of indices when forming the edges not the number of vertices so performance may not be worsened too much. Also using the solid particle system for your copies would help. Here is an example with 1000 cropped meshes https://www.babylonjs-playground.com/#RS3L95#1 Quote Link to comment Share on other sites More sharing options...
JohnK Posted March 21, 2018 Share Posted March 21, 2018 44 minutes ago, seb75 said: This simple example is working, but not when I change the vPositionW.x -vPositionW.z > 5 test to a more complex one using one my my own function. This is because the value of 5. gives a plane not intersecting the torus. It is a matter of getting the correct condition. https://playground.babylonjs.com/#AFRP1L#9 Quote Link to comment Share on other sites More sharing options...
seb75 Posted March 21, 2018 Author Share Posted March 21, 2018 @JohnK you're right, the plane is not intersecting the torus, it was just an example. I tried to use a custom function checking if the contemplated point is within a polygon, such function being defined somewhere else in my code, but I'm unsure about how to use this function within Fragment_Custom_Diffuse function. Is it possible to give as condition a custom function returning a boolean ? 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.