BabylonJS / Editor

Community managed visual editor for Babylon.js
http://editor.babylonjs.com/
813 stars 232 forks source link

Is it possible to access objects created with the editor with JS code? #19

Closed TobiasWehrum closed 6 years ago

TobiasWehrum commented 6 years ago

Hi Julien,

I'm currently evaluating my options regarding 3D JS frameworks. I'm not fond of visual scripting like action builder, but I'd like to have a visual scene editor for my project that can work together with me writing JS scripts. Is it possible to attach JS scripts to objects I created in this editor or otherwise write scripts, embed them in the project and access editor-created objects with it?

Cheers, Tobias

julien-moreau commented 6 years ago

Hi @TobiasWehrum It would be an excellent feature! Unfortunately it looks extremely hard to handle it. I mean (maybe you can answer): if the user creates a custom script and breaks the render loop of bjs (the user emitted an error in core), how to restart bjs correctly ?

I'm really hot to add this feature but I need a solution to counter this main problem Do you have a solution ?

Thanks ! :)

julien-moreau commented 6 years ago

Have you seen this ? https://medium.com/babylon-js/programming-with-the-babylon-js-editor-ddab887c243a?source=linkShare-e04a08da96a0-1496920387

julien-moreau commented 6 years ago

If you give a name to your object, you can get its reference using scene.getNodeById(my name);

TobiasWehrum commented 6 years ago

Thanks a lot for the fast answer!

I don't know how to solve the user error problem. If you ever have enough time and decide you want to implement that feature, you might want to look at the PlayCanvas editor the three.js editor (note: I've never used the latter, I just saw that it has the feature to add scripts to objects).

I haven't seen that article! Is it linked anywhere? That sounds like a reasonable compromise; it seems still a little bit less comfortable than attaching script components right in the scene editor, but certainly much better than not using a scene editor and a script editor at all!

julien-moreau commented 6 years ago

I tried the threejs editor and found that scripts are ran using "new Function(...)" giving a scope. In that way it is not possible to debug the scripts using the debugger. For now I invite you to follow the tutorial I have shared with you. Anyway, I'll update the editor soon to attach scripts on objects and find a solution :)

TobiasWehrum commented 6 years ago

Great! We've decided to go with PlayCanvas for this project, so it's not pressing for me, but I'm looking very much forward to try BabylonJS properly in the future. Thanks a lot for your help!

julien-moreau commented 6 years ago

Hey @TobiasWehrum as information, it is now possible to attach scripts to your objects in the Babylon.js Editor https://medium.com/babylon-js/babylon-js-editor-v1-2-0-6c760470098 Hope to see you soon :)

TobiasWehrum commented 6 years ago

Thanks for the heads-up, @julien-moreau . It's good to hear that you could integrate it, and I'm looking forward to try it out it in a future project!

(Oh, and if you have time to answer - how did you solve the problem you initially described while still allowing for debugging?)

julien-moreau commented 6 years ago

Excellent! Hope to see you soon! :)

Basically, the scripts are never executed in the editor but only in the popup window. To add these scripts, a script tag is created for each script, giving the code string and adding a comment (//# sourceURL=myDomain/myFile.js) so you can retrieve it in your devtools and then add some break points :)

TobiasWehrum commented 6 years ago

I see. Thanks for the explanation!