Closing an extruded shape generated over a circular path

I’m trying to generate a circular shape from a simple triangle by extruding it along a circular path generated using a for loop like a shaped torus or revolution solid. In this example, the path has only 6 points to illustrate the issue.

Currently, I am using the function ExtrudeShapeCustom with the “closePath” option to close the final figure. However, I need it to form a perfect hexagon in this case. (In other cases, I use more points like 24 or 36.)

You can find the example here: https://playground.babylonjs.com/#ZMKN5T#294

The problem is that I can’t close the path correctly without affecting the polygons that make up the shape. Consequently, it shows a residual side that doesn’t go along with the shape. It is also visible that the first and the final extrusions are not parallel with the opposite sides and seems to be in a more opened angle

Furthermore, when I attempt a CSG operation to subtract this shape from a cylinder, it generates a residual inner grid of polygons. I think that this problem also comes from the previous one.

Hi and welcome to the Community,
I believe the residual side comes from the adding of the last point when closing the shape.
Here is an alternate version (slightly) different I’ve used in my scene to quickly create different shapes, based on a circle
.

On the other hand, if all you want is an hexagon with a volume, you could simply create a disc with a tesselation:

var disc = BABYLON.MeshBuilder.CreateCylinder("disc", { diameter:20, height:3, tessellation: 6 }, scene);

I hope this helps and again, welcome to the Forum and have a great day :sunglasses:

3 Likes

Hi again, @mawa! Thank you for the fast response.

Unfortunately, the solution did not solve this particular case. The issue is that I need to rotate the original shape around an axis (in this case, the Z axis) in a variable number of steps to create a circular filled shape with it. It’s similar to a torus, but with the body of the original shape. When the loop reaches the last point, it doesn’t close the extruded figure properly. Instead, it attempts an erratic interpolation to close it.

I have tried pushing the first point, but it goes beyond the original one and doesn’t close it properly either. I have also tried not pushing the first point, but it only makes the situation worse.

If you need another example, I can create another playground.

Thanks in advance and thank you for the welcoming message! :slight_smile:

yes, an example would be best. Though from the reading, couldn’t it be that you do not have the same number of points?

Hi again @mawa , here is a new playground representing all the steps involved:

  1. We create a regular shape.
  2. Then we create a reolved shape based on the triangle, by rotating it around the Z axis with a tesselation of 6 points.
  3. We do a subtraction and represent the final figure.

You can tell that I need the triangle (or any other shape) to subtract the revolved form from a cylinder. If we increase the tesselation variable, you’ll see it creates a circular shape, but it’s hard to see the closing error properly. So, to show you that I reduced the points from 24 to 6.

Thanks again for your time,
I appreciate the help a lot.

I’m sorry, I’m still not sure what exactly is incorrect with your shape. Better said, I don’t know what your shape should look like? May be you could draw it for my/our understanding.
I suppose you based your logic on this featured PG from the section of the doc for parametric shape extrusion, is it?

That PG works for me so yes, I’m afraid I’m unable to spot the problem vs your expectations.

May be the fresh look of somebody with higher skills than mine will help here. Let me just cc @Evgeni_Popov

I’m not familiar with the extrusion code. After some tests, I noticed that using an equilateral triangle with a dimension=20 makes it work (at least I think it is the result you want?):

Hi @Evgeni_Popov , @mawa
yes, in theory the shape is correctly generated (however i need it to be applied to any other drawn 2D shape). But if you take a closer look to the inner wireframe it seems that something is not right. Here you can see the wireframes of the generated figures, when you try doing the CSG operation it generates an inner wireframe that adds an overhead of inner points.

I tried the same operation with a cylinder of the same tesselation as the extruded shape and it appears to do a similar thing.

I’m afraid I can’t help you any further. Let’s see if someone else with more knowledge on the subject can enlighten us.

I can see it. I think you have a point there but to be honest I never used it this way so I have no faen clue why it does that. Sorry.

Any idea who this person might be so we can call him/her in?

I don’t know, I don’t think anyone on the team has much experience with the extrusion code, so it can only come from someone in the community.

Hope you are well,
Still stuck with this? Looks like nobody kicked-in so far, so I quickly had another look this morning. Sadly with no real success/answer, I have to admit :smiling_face_with_tear:
May be this post could help you. It has a slightly different approach but might become an alternative if the solution does not come.

Sadly, we lost johnK a few months ago. A great loss for our Community and then of course, for his family and friends. I’m sure he would have had some interesting input on this.

Else, I believe there’s still another way to create a torus/donut shape like extrusion. In fact, it’s the solution I would have picked although there’s indeed a downside to it. I would create an extrusion of a circle with incurvation on a complete revolution. The downside being that where it connects it would still have a noticeable start/end. It can be lowered quite a bit working the texture, but since it doesn’t just close (only connect), I guess it will always remain noticeable.

Let’s just hope the weekend will bring new people to try solve your issue. Meanwhile, have a great weekend (anyways) :sunglasses:

1 Like

you code has an error in the triangle points ( your bevel ) , you supplied 4 values to one of the vector 3 objects. This causes the top point to be displaced along the z axis making it not aligned to any of the default axis planes. I have not looked at baylons code but I have experience with this type of geometry generation and it is almost always expected that the bevel should be axis aligned is some way

If you fix that it generates the shape along the path just fine , but closing it needs some investigation :

also , because you bevel is displaced from the origin you get unexpected displacement in the generated geometry , here i adjusted that as well , have a look :

Im looking into the closing aspect now … be right back

edit :

also your path is closing itself , so two points in the same place , so next fix is to shorten the path by one point , so closing makes sense , quick hack :

path.length = path.length-1

but there are still issues with the bevel orientation , looking into it …

so here is the current state , all should be good to just close the path :

but … that has errors now , the normals are not getting averaged ? if you set :

closePath: true

in the above pg … it can be observed that the geometry is closed but the orientation of the bevel path remains perpedicular ( cross product ) to the edge on the start and close points , as if the path was open. What should happen here is those two normals need to be averaged

2 Likes

Here is something that works … but oddly has a bug with the normals when not closing the path LOL :

This uses , createRibbon , I just found a PG and made some edits to rotate the points to see if it is averaging the normals when using the option :

closePath:true

which works correctly but as pointed out … this function has its own related bug in that if you set this option to false , the normals are still averaged , when they should not be.

so :

MeshBuilder.ExtrudeShapeCustom :

Open path - start and end normals correct
Closed path - start and end normals INCORRECT

MeshBuilder.CreateRibbon:

Open path - start and end normals INCORRECT
Closed path - start and end normals correct

3 Likes

my half cent:
you can now this type:
const axes = new BABYLON.AxesViewer(scene, .25);

thanks , its good to know, I think when someone actually creates a PG from scratch we can use this info

but obviously in this instance ( like most others ) what you see is simply whatever working PG first presented itself when searching the web that a user could mod for testing with minimal editing.

it’s just that i like simple code so very much
you want to focus on what’s important, specially in the PG
(thought I’d give you the hint)

I sort of agree with you but also with shaderbytes. Obviously, many PGs are based on a featured.
Having the original code in the PG (and knowing about this PGs), you can often tell what it was based on, which might also gives some clues about the logic. So, in short ‘YES’ and ‘YES’ (to both) :grin:

1 Like

that’s why i called it just half a cent - not the proverbial 2 cents
was completely off topic too

1 Like

Hi again @shaderbytes ,

I have been trying your solution and it works pretty well. Thanks for the help.

However I have noticed that an extra grid is being generated after doing the CSG operation. Here you have a playground where you can see that.

It adds several points to the final form, overcharging the generated mesh. I am trying to reduce the amount of generated points but I can’t manage to get rid of this inner grid. Is this a normal behaviour?

Thanks again for your time and help!