Jump to content

proposal basic shape : disc


jerome
 Share

Recommended Posts

Hi people,

 

I just PR a new very simple, but useful (I hope), basic shape : plane disc

var disc = BABYLON.Mesh.CreateDisc("disc", radius, tessellation, scene);

This just creates ... a plane disc mesh.

Or an ellipsoid plane, if you start to play with scaling properties :

disc.scaling.x = 2;disc.scaling.y = 0.5;

Actually, it creates any regular polygon according to the tessellation value :

3 is a triangle,

4 a square,

5 a pentagon,

6 a hexagon, 7 a heptagon, 8 an octogon, and so on ...

 

 

I did it just because I needed it.

I hope it will be helpful to other people too.

 

 

[under the hood : for those wanting to hack and manually morph, the first vertex is the disc center]

Link to comment
Share on other sites

As I can't compile TS any longer  for now, could someone (maybe DK ?) please copy/paste the CreateDisc() method in babylon.mesh.vertexData.ts and babylon.mesh.ts files as described in the attachment and then PR it for the next commit ?

Link to comment
Share on other sites

:)

Jerome, doesn't our current cylinder do this already... when you give it 0 height?  And it's easy to do 3, 4, 5, gazillion-sided, yes?  It "caps" via seashell fan-out and not via centerpoint and pie-shape.  The seashell method is slightly more efficient but looks goofy in wireframe mode.  *shrug*

Update:  Nope, I was wrong.  A zero-height cylinder gets defaulted to height of 1, I guess.  :)  Then we need to scale it y=0.  http://playground.babylonjs.com/#22YF7K

Link to comment
Share on other sites

Well, it could look the same indeed ...

However the caped cylinder is not a real plane, but a 3D flat mesh and I don't think the vertices are positioned the same way (for normals and uvs).

The plane disc is a real plane mesh, like plane or ground meshes. Its normals and uvs are computed to right values and it has only the needed vertices.

It's only 20 TS LOC.

 

You are right : we can do a disc with a flat cylinder. (Didn't try ...)

We can do it with a ribbon too.

There are plenty of ways to redo basic shapes from 3D mesh or parametric mesh.

But I think it is right better and simpler to use the dedicated method when it exists because it embbeds dedicated computations : normals, uvs.

Link to comment
Share on other sites

It's got factory-installed doublesiding.  :)

 

But yeah, I know what you mean.  But it should be named CreatePolygon or similar, I think.

 

Later, we can add CreatePolygonFromLines()  (lets folks draw their own polygons... using BJS Lines)  (yay)

 

And then, of course, extrudePolygon()

 

I don't know what the BJS "geometry" system is all about.  I have not investigated that puppy AT ALL.

 

Would CreatePolygon() be the same as CreateGeometry()?  *shrug*

 

Dad72 asked for a circular plane quite some time ago, and we talked and talked about it (in The Wingnut Chronicles) and then we all lost interest and went fishing.  :)

Link to comment
Share on other sites

Whatever the name.. ;)

this method just creates a plane, (regular) polygonal or disc around a center point.

 

CreatePolygonFromLines() is not really needed imho, because CreateLines(path) already does the job : when instantiating your path array, do just after

path.push(path[0]); 

and you get a closed polygon at the end !

 

For extrusion, ExtrudeShape() does already the job :) (with closed or unclosed shapes)

Link to comment
Share on other sites

Cool.  I wanted to add that http://www.html5gamedevs.com/topic/6364-circle-geometry-polygons/#entry37982 was another branch of the circle-plane conversation.

 

But "whatever the name" is very dangerous in this situation.  Not in YOUR system... but...

createTriangle

createSquare

createPentagon

createHexagon

etc.

 

That sucks, in my opinion... and it can happen.  Something like CreateShape() stops that.  :)  Again, this is not your proposal... but SOME folks think we should have CreateIcosidodecagon()  It's best to shoot such imagineers immediately.  :D

Link to comment
Share on other sites

Mmmh

CreateLines(path), with a closed path, just creates ... polygonal lines. Not a plane.

 

If you use the same path with the poly2tri tool, I guess you can create any filled plane polygon, even not regular. (Nothing to do with extrusion which is used to transform a plane shape into a volume).

 

If you need a disc plane or a regular polygon, you will have to compute by yourself this right path . Not as easy than just giving a radius for non-math players.

If you achieve it, you'll probably get a nice disc.

Well... but what about normals ? what about uvs ?

You just can't predict how the poly2tri algo will order or size the triangles on the surface, where or how much vertices will be set, etc ...

 

So... as I said before, you can always redo a basic shape with parametric tools.

It's possible, although sometimes it's difficult if you don't know enough maths.

It's ever possible. 

But you won't master anything about normals and uvs because the shape will be the result of a computation you don't master (unless you are the guy who implemented it in BJS... and even he wouldn't probably know).

 

Now, I'm addressing the incoming user, the guy who just needs, well, a disc, an ellipsoid, or a regular polygon... straight forward, right now.

No math needed, no path, intermediate array, etc, nothing but a radius.

 

He only wants the shape reflects light well and it could be textured nicely as expected, just like for other simple creation basic shapes.

Legitimate expectation, isn't it ?

You can do easily, with just one line of code, a line, a square/rectangle in BJS... so why not a circle/triangle/etc/polygon ?

 

Something directly built (one LOC) around a central point with a radius.

 

Maybe the name should be changed to something more pertinent, you are right ...

I personaly don't really care what the final name should be since this simple method can help people to build any regular polygon (+ disc) with just 1 LOC and the only knowledge of a radius  ;)

Link to comment
Share on other sites

Yeah, I guess the experts would say that...

 

createCircle/createDisc(name, radius, tess, scene)

 

...would call...

 

_makePolygon(path?path|radius, blah, blah, blah)

 

I dunno.  Expose the simple call, hide the universal polygon generator call?  *shrug*

 

I think DK likes discrete do-one-thing-only functions, where I have a tendency to make a function be over-loaded with power and versatility.

 

His way is more correct, of course, and provides better granularity.  But it promotes createPentagon, Hexagon, Octagon, etc, and that's insane...  I suspect. 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...