jerome Posted April 2, 2015 Share Posted April 2, 2015 Hi people, I just PR a new very simple, but useful (I hope), basic shape : plane discvar 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] Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 2, 2015 Share Posted April 2, 2015 It is always great to add more basics shapes support ! The core foundation of babylon.js is: make it simple. So anytime the framework can handle things for developers this is great! Quote Link to comment Share on other sites More sharing options...
jerome Posted April 2, 2015 Author Share Posted April 2, 2015 Seems I spoke too fast againWrong PR. I'll re-submit it tomorrow. Quote Link to comment Share on other sites More sharing options...
jerome Posted April 3, 2015 Author Share Posted April 3, 2015 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 ? Quote Link to comment Share on other sites More sharing options...
jerome Posted April 3, 2015 Author Share Posted April 3, 2015 final attached file with .txt suffix it just refused the initial name "createDisc.ts"createDisc.txt Quote Link to comment Share on other sites More sharing options...
Wingnut Posted April 3, 2015 Share Posted April 3, 2015 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 Quote Link to comment Share on other sites More sharing options...
jerome Posted April 3, 2015 Author Share Posted April 3, 2015 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. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted April 3, 2015 Share Posted April 3, 2015 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. Quote Link to comment Share on other sites More sharing options...
jerome Posted April 3, 2015 Author Share Posted April 3, 2015 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 afterpath.push(path[0]); and you get a closed polygon at the end ! For extrusion, ExtrudeShape() does already the job (with closed or unclosed shapes) Quote Link to comment Share on other sites More sharing options...
Wingnut Posted April 3, 2015 Share Posted April 3, 2015 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...createTrianglecreateSquarecreatePentagoncreateHexagonetc. 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. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted April 3, 2015 Share Posted April 3, 2015 By the way, you told me how to create a filled plane-shape... using lines following a path. Could you show me that in the playground? Doesn't that method... eliminate the need for your CreateDisc()? Quote Link to comment Share on other sites More sharing options...
jerome Posted April 3, 2015 Author Share Posted April 3, 2015 MmmhCreateLines(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 Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted April 3, 2015 Share Posted April 3, 2015 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. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 3, 2015 Share Posted April 3, 2015 PR validated and CreateDisc is great I think as long as the doc is clear about the fact that it could also create pentagon and so on Quote Link to comment Share on other sites More sharing options...
jerome Posted April 4, 2015 Author Share Posted April 4, 2015 tinkiou I will write the relative doc as next week Quote Link to comment Share on other sites More sharing options...
Wingnut Posted April 4, 2015 Share Posted April 4, 2015 Thanks guys! Nice feature! 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.