Run Babylon command trough apply / call

Hey everyone,

i’ve wrote an simple API (i hope there is currently no one, cause i didn’t find it… :D)

This API works with JSON, i call JSON functions like {“ArcRotateCamera”:{“construct”:[], “setPosition”:[], “beta”:{“Tools”:{“ToRadians”:45}}}}

It works fine at the moment, but i have one Problem now.

At the Moment i Call ArcRotateCamera like this: eval(“new Babylon.ArcrotateCamera”) but i can’t put many constructer in this, because some things doesn’t work with eval.
For other Constructors (like Meshbuilder.CreateBox) my Constructer works like this:

var mesh = eval(“new BABYLON.Meshbuilder”);
mesh[“CreateBox”].apply(mesh, [“name”, {“size”:10}])

/\ this is just a Dummy, this get buildet automaticaly from JSON.

The Question now is, HOW i can do the same with the first Constructor without any error? (TypeError: Cannot read property ‘name’ of null)

And how i can figure out if i need “new” when i call BABYLON? (at the moment i do it this way:

func = eval(“new BABYLON.” + funcname);
if(Object.keys(func).length == 0) { func = eval(“BABYLON.” + funcname); }



Sorry… What is going on here :thinking:

Why are you using eval?
Why not simply access it?

BABYLON[ funcname ]

Hey Thanks to reply.

Because i need sometimes “new” or i’am wrong?

You’ll need “new” only for constructors, like arcRotateCamera,
MeshBuilder.createbox is a static function which does not.

I don’t have time to make a sample now, but i’ll do one tonight unless someone beats me to it, :slight_smile:

1 Like

Okay, yea i need both… :smiley:

Okay thank you :slight_smile:
Until i have a answer i can do it with eval as good it will do, works for the pre-presentation :smiley:

I am pretty curious about why doing this vs code or using the .babylon format ?

how does it mean?

I Use Javascript and the Documentation.

Hey, do you have had the time for a sample? :sweat_smile:

Would you explain how you see your API being used and who by?

Hi @Rotzend

My apologies, i haven’t had time.

However, i agree with @sebavan , why not use a .babylon file?
( can be exported with the babylon exporters from 3d tools like blender, maya, 3ds max), or using the scene serializer class, or the inspector (uses serializer but offers UI button to do it)

hey, the reason is, because we don’t have anything like this ^^

We have just obj. files which we want to show and change. We have to create or if there is a good one to use a showcase.

The whole Object has to be Centered to the Camera, the User has to move arround with the mouse.

With external Buttons he need to show some Messurement lines and change size, Position and so on.

This is my Task.
If there is a functional Solution already, it where be PERFECT :smiley:

But if not, i have create one. But we have a c++ software, which our “Website” talk to and get his Tasks.

The Tasks comes with JSON. And it has to be “encoded” for complete Babylon, if possible. But at the moment i stuck, because of have a look it is a constructor or not and the MeshLoader is Async, which is not really good as well… :confused:

  1. Have you seen the Editor ?

  2. Is what you are trying to do is have a JSON file from which you can completely build a scene by describing the objects in the scene rather than a file giving for example the vertex data of an existing mesh?

  3. If 2 is true do you have to construct the JSON file so that eval is used on the objects?

  4. Given security issues around eval would an alternative be for each item in the JSON start with the type of object followed by parameters for construction and use something along the lines of

for(each item in file) {
       switch (item.type) {
       case 'box':
             var box = BABYLON.MeshBuilder.CreateBox(, {size: item.size}, scene);
        case 'arcRotateCamera':
            var camera = new BABYLON.ArcRotateCamera(, item.alpha, item.beta, item,radius,, scene);