Jump to content

Curve3 object


jerome
 Share

Recommended Posts

Hi,

 

A new object has just been added to BJS : Curve3.

This object is to embbed complex math curves like Bezier, B-Spline, etc so users won't have to implement by themselves if they need it.

 

For now, there are only two static methods about cubic and quadratic Bezier curves (more to come) :

var bezier2 = BABYLON.Curve3.QuadraticBezier(originPoint, controlPoint, destinationPoint, nb_of_points);

and

var bezier3 = BABYLON.Curve3.CubicBezier(originPoint, controlPoint1, controlPoint2, destinationPoint, nb_of_points);

Both methods return an instantiated Curve3 object.
Then users can access the Bezier curves points with :

var points = bezier3.getPoints();

which is an array of nb_of_points successive Vector3.

This kind of array can be then used with ribbons, tubes, extrusion paths, animation paths, etc ...

 

PG, from line 50 (the code before is just for drawing axis arrows) : http://www.babylonjs-playground.com/#1PSZDF

Link to comment
Share on other sites

Thank you Jahow :)

I didn't implement more than cubic Bezier curve, because usually it's enough : people concatenate many cubic Bezier curves together to get more complex curves.

This feature is documented and should be visible as tomorrow in the Tutorials - 04 More advanced features.

 

I wish I can implement some cubic spline soon in Curve3 object.

 

I just added another geometric tool which could be useful to users, Path3D : given an array of successive _Vector3_ (as the one you could get with bezier curves) defining a path, it computes a set of vector triplet on each point of the path, keeping direction and consistency (minimizing rotations).

These triplets can then be used as local system coordinates for anything you need.

 

Visible from tomorrow and the same documentation part if validated.

Link to comment
Share on other sites

Hi guys/gals.  Yes, nice work, Jerome.

 

A little Playground training... do you see the 4 little green marks along the right side of the PG code editor?  Those indicate that you have 4 non-showstopper errors... sometimes called warnings.  :)  Click around in your code until you get the thin black line (cursor location indicator) to land-upon a little green box.

 

#1 warn - line 19 - no 'new' is used with 'create' things.  :)

#2 warn - line 27 - no 'new' is used in things like Vector3.Zero()... nor in things like Color3.Blue()

#3 & 4 warn - I'll let you discover.  :)

 

Now, speaking of 'new', should lines 52 and 59 have a 'new' used?  Just verifying.  It works with 'new' in both lines. 

 

I did a little morning reading about 'new' and supers, and subclasses, and inheriting, and prototype objects... and, to be frank, it made my morning coffee taste like crap.  :)

 

Congrats again, J.  Your "lab" is growing fast, and smelling... Jeromatic.  :)  Worldspace, localspace, and Jerospace.  :)

Link to comment
Share on other sites

Aaargg... you're right.

Laziness again : I just copied/pasted some old showAxis code I made when I was just starting to learn BJS ...and then making more errors than now (I hope)

 

Those "new" aren't needed of course.

 

Wingy Eagle Eye ! ;)

Link to comment
Share on other sites

Jerome, it's not of high importance.  I have released MANY playgrounds with green dots all over them.  I do it to challenge Dad72, who has a SUPER eagle eye.  That guy can locate bugs in arctic ice.  :)  (His eagle eye has helped the framework a TON!)

 

What's the word about... BABYLON.Curve3.QuadraticBezier and BABYLON.Curve3.CubicBezier?  No 'new' for those?  Or do we know?  :)

 

Maybe they should be BABYLON.Curve3.CreateQuadraticBezier and BABYLON.Curve3.CreateCubicBezier?

 

I have no idea what is correct.  I just look at consistency with other BJS funcs/methods, and from that, I still don't know.  :)

Link to comment
Share on other sites

You are right again.

These are static functions returning an Curve3 instance. So no new needed.

 

So CreateXXX() would have been semantically more consistent. I agree.

 

Is a curve creation the right term ? Is a logical curve created ? It's not a material object the user can display, rotate, handle, etc.

 

Maybe BABYLON.Curve3.ComputeQuadraticBezier() ?

Don't really know...

 

But you are right  : a verb is really missing here according to other BJS static functions returning an instance.

Let me know, you native english speakers, what would be the best and I'll change it (aarrg, if I achieve it : DK is becoming crazy with all the bunch of $*+&%! slags I push in every PR)

Link to comment
Share on other sites

:)  I warned DK twice about the potential fast growth of your ribbon laboratory.  I suggested a library of your own... and once every xx months, we could merge a .ts version of that library... into the framework.  But nooooo.  heh.

 

Like I know if that would work or not.  :)  I'm probably spewing crap again.  I'm known for that, ya know? 

 

It's still not too late.  The rough part is in giving you access to the playground guts (so you could put new versions of the lib... in-scope of the PG).  Or, you could keep your library on a CORS-ready server somewhere, so folks could access older and recent versions.  Playground and CYOS zips (in the index.html) could include THAT external-include url.

 

Currently, a zip from the playground... includes babylon.js, hand.js, oimo.js, and cannon.js.  It could also include jMesh.js.  Then later, when you're done playing (but let's hope that never happens)... we could do a final .ts merge-in of the library, remove it from the playground external-includes (and CYOS, as needed) , and party hard.

 

Or, maybe I have no idea what I am talking about (more likely).  :)

Link to comment
Share on other sites

Aarrff...

When talking about all the bunch of $*+&%! slags I push in every PR, well, it wasn't about the TS code itself :) : the TS code I injected in BJS is really light actually, between 20 and 40 LOC only for each feature, so not big real BJS change.

 

No... I was talking about the GitHub fetch/merge/commit/push/PR cycle which brings a lot of locally compiled JS files from my computer to Github (maybe because the linux TS compiler differs from the Windows one, don't get it) and DK needs to delete/clean up all those un-needed files (not impacting BJS, but coming along with) before merging in the nightly build each time I dare to submit something.

 

But don't worry, I won't pollute BJS ;)

So far, I just added two mesh types (ribbon and tube), a mesh tool (shape extrusion) and two geometric tools (curve3 and path3D) ... just quite little things if you compare to other contributors :D

And they are all documented with PG examples (with many green dots  :P ) so they won't look too exotic (I hope) or too complex to new users.

Link to comment
Share on other sites

I'm not worried about BJS pollution from you, at all.  I am talking about HOW OFTEN you might be doing PR's.  I figure... at YOUR top coding speed... you will be doing a PR about every 45 minutes.  :) 

 

Ok, maybe not THAT often... but... you're a mover and a shaker, J-willikers.  I purchased an extra tube of GitHub Grease just in case the git ball-bearings get too hot/dry.  ;)

Link to comment
Share on other sites

I wait the last edit with PG links to be validated first (as I just can remember the links)

 

Then I'll change the doc and the PG examples with the new CreateXXX() names.

 

btw, could someone authorized validate the pending docs ?

Link to comment
Share on other sites

Curve3 object

 

added method continue() :

 

Let's imagine you've got many curves with different origins and you want to "stick" them together one after the other without knowing/handling each curve origin and end.

Or you want a Bezier curve with 8 control points (very complex computation)... you could divide it in two cubic Bezier stuck together.

Or you want to stick your own sinus, with a line, then with an helix, then with a Bezier in order to design for instance an extrusion path, a tube path, a path3D or whatever you want ...

var myFullCurve = curve1.continue(curve2).continue(curve3).continue(curve4);

PR pending

Doc validation pending

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...