Jump to content

CreateMesh Automatic Variable Parsing


Pryme8
 Share

Recommended Posts

So, I guess this would be considered a bug.  If you ever pass a value from a standard HTML input to like let say CreateSphere or CreateGround functions it handles them like they are strings.  So this lead me to test and sure enough the mesh creation functions do not automatically parse passed values.  Is there a reason for this?  I really see no reason for these functions to not inherently parse variables passed to them as Integers.

Link to comment
Share on other sites

Actually, no BJS CreateXXX() function parses the input parameters. If they aren't the expected type, the function crashes or behaves strangely due to JS dynamic typing.

This is not a bug neither a lack. This is a design choice : the function (and the framework) intends to be as fast, light and performant as possible. Thus, no internal parsing, nor check, nor cast, nor error message.

The doc (API + user doc) is here to explain how, when and what to use. Sometimes, it may be incomplete. Please let us know where to complete it (or feel fre to contribute ;)

It is then the user responsability to pass the right types at the right places.

 

In your case, I guess that, by default, anything coming from the DOM inputs is considered by javascript as strings. So you might first cast it to the right type before passing it to any CreateXXX() function.

Link to comment
Share on other sites

Hi,

 

you just need a middleware between your form and Babylon. Some form of validation and conversion.

Passing strings can sometimes work (due to JavaScript auto-conversion when the need arises), but due to type-matching (like the "===" operator) and other architecture choices (as jerome said) it won't be possible to fully use strings. Here is the basic scene with strings - http://www.babylonjs-playground.com/#SERR9 . You would notice that the last parameter of the ground creation function is a number. try changing it to a string and it will fail.

 

 

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