Jump to content

tube and extrude extra parameter


Recommended Posts

Hi people,


I don't know if some of you have played so far with the parametric tube (using radius function) or with the CustomExtrudeShape() methods...

Well, in these two methods you can pass a custom function instead of a value for radius or scaling, so your tube or your extruded shape could vary according the point positions on the axis.

Your custom function receives thus for each axis point its position and its distance from the beginning of the path.


Maybe could I add an extra user parameter k ?


Why ?

Because if you want to pass to this custom function your own parameter you have to use a closure for now.

See this radiusFunction() line 136 : http://www.babylonjs-playground.com/#29CXFN#3

I need to set the radiusFunction() each frame to give the k value  to it.


Maybe it is easier for a user to define once a radius function with his own parameter and not to use closure then :

var radiusFunction(i, distance, k) {  // do your own stuff with k and compute a radius  return radius;};

Imagine you want to compute a different radius for your tube depending on the z coordinate and the time (not i or distance point position).


So please let me know if you would like this extra parameter to be added in the custom functions (very cheap change to code, but many new possibilies so big work to write the relative documentation :wacko: ).

Else, the closure does the job and only pro coders will play with this :P

Link to comment
Share on other sites

Hi Jerome,


Um, it seems to me that k could be queried-for... from within the custom radiusFunction... only if the user needs it.  Distance, too.  Users could calc the distance between i and origin... IF they wanted-to... from within the func.  If we have i, we have everything we need, I think.  *shrug* 


And I think we can do engine.getDeltaTime() within the func, too.


Are you worried about things being within scope? 


Let's pretend MY radiusFunction needs data from a Perlin noise generator function.  Do you foresee any problems keeping the call to the noise generator... in-scope?  I can't see why there would be any problems, but maybe I am missing something. 


We won't be packing radiusFunction into a sealed sardine can and sending it to the bottom of the ocean, will we?  :)  You might be sending along unnecessary provisions on the journey to radiusFunction.


In fact, you don't need to send i, either.

var radiusFunction() {    var i = somewhere.getMeTheCurrentPathPointIndex("hurry up");    ...    return radius;};


Link to comment
Share on other sites

Ok, you are right.

I will let people do closures if they need their own values/variables.


I just keep i and distance because they are avalailble with the right values at the very moment when the radiusFunction is called each time. These two variables internally depends on the tube constructor, so it is easy to give them to the developer... far more easy than for him to recompute them from scratch.

But you are right : the developer could have computed them by himself. As he could compute the next or former point position or distance if he rather needs them.


Well, it's just a convinient way : i index (position) or distance are very often used to make the radius vary, so they are packed as there is absolutly no extra computation in the constructor to get them (avalaible values at this time).

But it's not mandatory to use them.

The only mandatory thing is to return a radius numeric value.


Thank you for your answer.

I mark this topic solved... and don't add any extra parameter to customFunctions().

Link to comment
Share on other sites

Hi J, my pleasure.  Yep, your reasoning sounds good, as best I can tell. 


Maybe you should wait for comments from people who actually know how to program, though.  Having ME comment about proper JS procedures... is like asking my advice on how to write succinct (brief) forum comments.  :D


If you asked me how to get "thump-titude" in a hard-driving country rock band, then boy, I could tell you some things.  And there is a reasonably good chance that I would be correct.  :)  Are there many musicians in my crap area of the planet... who are talented and confident enough... to drive a song up an audience's butt and make them cough it back out through their nostrils?   no.  :(  The more important issue around here:  IS there an audience?


Now everyone knows the reasons for my weird ways.  I NEED audience.  Superficial of me, eh?  I guess that's not so different from game and tool programmers who seek users/fans.  If I may quote a singer named Johnny Lee... "if you want to make a living you got to put on a good show."  :)


Around here... BJS is the guitar, amplifier, mic, and lights.  Once we learn to operate it (not too difficult at all), then anyone can do great webGL shows.  Right, Jerome?  You've been doing great shows since the first day that you picked-up the BJS guitar.  "Naturals" like you... really piss me off.  :)  (just kidding, of course).

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.

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.


  • Recently Browsing   0 members

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