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:
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
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…
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?
If 2 is true do you have to construct the JSON file so that eval is used on the objects?
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(item.name, {size: item.size}, scene);
break
case 'arcRotateCamera':
var camera = new BABYLON.ArcRotateCamera(item.name, item.alpha, item.beta, item,radius, item.target, scene);
break
}