dbawel Posted June 23, 2016 Share Posted June 23, 2016 Hello, I have a scene which contains a GUI and other functions to log into and set up settings for a second scene to be loaded from a seperate script. This would be similar to loading one environment from on script for a game and ipon completion of the first level - disposing of the first scene and loading a second scene (level) from a seperate script. I don't want to have every level (scene) in a single script, as the functions in each of the scripts are far too different from one another and would be very large and inefficient to contain in a single script. So I have been able to dispose of my first scene, however I have a function in my second script which is set to run when the first script disposes and sends a global variable to the second script which conditionally should cause the function in the second script to initialize a new and different environment, scene, and functions. The global variable is being passed to the function in the second script, yet the scene in the second script is not initializing. I hope someone has an example online of this or a similar process where they are callig new scenes in seperate scripts successfully; as I cannot get a second script to initialize the function loading the second scene. Any examples would be very much appriciated. Thank you, DB Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 23, 2016 Share Posted June 23, 2016 Hello David Why not using global variables? All your scripts live in the same context so this could work Quote Link to comment Share on other sites More sharing options...
DigiHz Data Posted June 24, 2016 Share Posted June 24, 2016 Hi dbawel. You mean that you want to start with 1 engine and then load differerent scenes into 1 canvas together with html, css and javascript? I have made this work on my editor i am working on for BJS. You could call it a level loader or whatever, Anyway..... It is possible to do it, and i have done it. so if you need more info how to do what you want, i might help you. Quote Link to comment Share on other sites More sharing options...
Boz Posted June 24, 2016 Share Posted June 24, 2016 What a suspens Wingnut 1 Quote Link to comment Share on other sites More sharing options...
dbawel Posted June 25, 2016 Author Share Posted June 25, 2016 Hi @DigiHz Data- What you were able to write in a couple of sentences is exactly what I'm trying to do. However, in adapting a considerable amount of code to function in this way has not been successful as of yet. If you have a link to what you are doing as well as any adice, this would be a great help to me. And thanks to @Deltakosh for looking at this, and if you have any examples as well, I can use all help right now - as I'm missing something. My code is not in any state to create a Playground scene or to simplify at this point. I would have considered this sooner, but ran into issues between HTML and WebGL in just the past few days, and need to either use the same engine, or dispose of the current engine at some point and create a new engine. But the real need regardelss of how it is accompished, is to not only call functions from different scripts (which I can certainly do with global variables), but to dispose and create different engines between scripts to create and dispose different HTML objects and toresize (change) screen resolutions when this is occuring. So any help is appriciated. Thanks, DB Quote Link to comment Share on other sites More sharing options...
DigiHz Data Posted June 26, 2016 Share Posted June 26, 2016 dbawel: Do you use php and jquery? My solution for this use php, mysql, jquery. My code for this loading routine is pretty complex, so it will not be so easy to help you out here in the forum only, Maybee we could meet in the forum chat somehow? In your last post you mentioned " but to dispose and create different engines between scripts ...." Do you mean switching engines or switching scenes? To clarify things: (My solution of loading different scenes in my project) Let's asume it is a game project with many levels. Using 1 engine, 1 scene and 1 canvas. Loading order: load in html code(global for the game) load in css code(global for the game) load in javascript(handles Babylon stuff) load in javascript code(global for the game) load in game scene css code(css code for level1) load in the babylon scene file(level1.babylon) load in game scene javascript(javascript code for level1) ------------------------------------------------------------------------ At some point you want to load level 2.... load in game scene css code( css code for level2) load in the babylon scene file(level2.babylon) load in game scene javascript( javascript code for level2) ----------------------------------------------------------------------- And so on. Quote Link to comment Share on other sites More sharing options...
dbawel Posted June 27, 2016 Author Share Posted June 27, 2016 Hi @DigiHz Data - This is what I need to achieve, however I have to finish a scene to demo Thursday and stll have to host it and run QA. If you are available later this week, I would love to have a chat and see what I might do. In the meantime, do you have a link to your code, or is it not for public consumption at this time? Thanks, DB Quote Link to comment Share on other sites More sharing options...
gryff Posted June 27, 2016 Share Posted June 27, 2016 @dbawel This of any interest David? Dynamically loading an external JavaScript or CSS file and Dynamically removing/ replacing an external JavaScript or CSS file cheers, gryff dbawel 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted June 27, 2016 Share Posted June 27, 2016 What if the .babylon file allowed a property call .stuffObj. Then the sceneLoader could check if .stuffObj exists, and if it does, hands it to the programmer after scene load success. The stuffObj has css on it, scripts, html, drugs, girls, an inflatable Ferrari, a swimming pool, a LearJet, the complete works of Marx, the... err... never-mind. But that would be interesting. Smart .babylon files. They have a JSON fanny-pack attached, and you could put your weed in there... and game logic... and anything. return leftovers; "Hey, we found this fanny pack after we processed the file. We're returning it to programmer." This carry-on luggage object... AND the scene/mesh from the STANDARD areas of the .babylon file... would be in the same scope, right? Just demented. Hanging extra stuff on your .babylon files and making the sceneLoader deliver it un-touched. hmm. "Dear Sceneloader. Would you please return any data that you don't recognize and thus don't parse... as one of the args to your callback call? (Return... to Progger - Elvis) Thanks" Okay, I'm just talking crap, here. But what if? Gamepack. Levelpack. Rides with the .babylon file. So, one load, and ya get anything ya want... from inside the attached fanny pack that YOU packed with crap! Wow! Quote Link to comment Share on other sites More sharing options...
dbawel Posted June 27, 2016 Author Share Posted June 27, 2016 @gryff - The links you sent are very helpful - if I can just find where I need to impliment and then test if it's correct. But this I will certainly attempt. @Wingnut - I think I followed about 20% of what you said - but I can never know what is rattling around in that brain of yours. Perhaps some attitude adjustment is needed on my part. I have another post named "how to load textures dynamically - no started by me. However, if I can acomplish this, I'll wait until my demos are over to jump into launching Javascript fles from a "queue". If you can, please take a look. Thanks, DB Quote Link to comment Share on other sites More sharing options...
Wingnut Posted June 27, 2016 Share Posted June 27, 2016 Think of the fanny pack as a marshaller. As soon as the scene loader finishes, it returns an object that YOU manually put into one of the .babylon file properties. The scene loader sees .marshaller prop... it contains a JSON object... and sceneloader doesn't know what to do with it, right? So it returns the object (via the sceneload callback function). You immediately [maybe after jsonparse(thatString)] RUN marshaller.init() and poom, this wench looks-up the current document.head and starts adding <link> elements that load CSS files, and adding <script> elements that bring-in code... or more .babylon mesh. It could do anything... all within current scene scope, right? All it takes is a mod to sceneLoader that says "return what you can't parse... as an arg to the callback function". Or maybe... "jsonparse and return the contents of the .marshaller property... as a JS object." That will return the "alien object" to the programmer... you. Call it's init()... and watch it dynamically load scripts, load css, inject html nodes into the DOM, and dynamically unfold itself into a ready-to-play level. A marshaller. I could be full of crap, and this could be a terrible idea. But maybe not. If sceneLoader were "nice", it would try to jsonparse(that alien string) FOR us. Then, when we receive the object from the sceneLoader, it would be a JS object ready to have it's .init() method called. *shrug* Even cooler.... IF the sceneLoad was a success, and IF there IS a property called .marshaller, and IF the string in .marshaller does a successful JSON.parse, and IF the resulting marshaller.hasMethod("init")... then marshaller.init(). The scene loader actually starts the "unfold and install" process automatically, for us. COOOOOOOL! err... maybe not. Quote Link to comment Share on other sites More sharing options...
dbawel Posted June 27, 2016 Author Share Posted June 27, 2016 @Wingnut - it sounds like a great idea, but I'm faily certain that DK will pull whatever hair he has left out of his head. I'd prepare for his answer if I were you. Cheers, DB Wingnut 1 Quote Link to comment Share on other sites More sharing options...
DigiHz Data Posted June 27, 2016 Share Posted June 27, 2016 Gryff's answer is a good start. I used that code originally and modified it to suit my needs. However....there is much more code than that to make the "level loader functionality". No link to this code yet. I am trying to get a new version finished for my Babylon JS Editor project. Everything takes time?. And my project is HUGE. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 27, 2016 Share Posted June 27, 2016 can you just share an simpler example of the problem itself..I'm having hard times figuring out what is the problem Quote Link to comment Share on other sites More sharing options...
dbawel Posted June 27, 2016 Author Share Posted June 27, 2016 15 hours ago, gryff said: Dynamically loading an external JavaScript or CSS file and Dynamically removing/ replacing an external JavaScript or CSS file cheers, gryff These links from Gryff explain exactly what I need - but I don't have anything that would make sense yet. DK - I thought you would be commenting about Wingnut's idea, which is why I thought you might pull all of your hair out. DB Wingnut 1 Quote Link to comment Share on other sites More sharing options...
DigiHz Data Posted June 27, 2016 Share Posted June 27, 2016 Hello again dbawel. I attached my javascript code here for loading scenes/levels. You can have a look at it and use it as reference, there are some important remarks in the file that also might help you. This is not the only file needed to make it work, but it is a start for you. deployed.js Boz 1 Quote Link to comment Share on other sites More sharing options...
gryff Posted June 28, 2016 Share Posted June 28, 2016 @dbawel: Gee I see @DigiHz Data beat me to posting a script Well here is a very simple example - 3 scenes each with a different shape and material. The scenes change approximately every five secs - driven by a setInterval as a trigger Three scenes The code I created just adds a new script - adjust the code to delete or replace scripts Tested with Firefox. and BJS 2.4 Here are all the files to run it on your local server : Multiscript cheers, gryff Boz and Kemal UÇAR 2 Quote Link to comment Share on other sites More sharing options...
DigiHz Data Posted June 28, 2016 Share Posted June 28, 2016 I am so very sorry gryff, i'll try to be a bit slower next time Quote Link to comment Share on other sites More sharing options...
gryff Posted June 28, 2016 Share Posted June 28, 2016 2 hours ago, DigiHz Data said: I am so very sorry gryff, i'll try to be a bit slower next time @DigiHz Data I like your style When it comes to coding, I know I'm likely to be the last to contribute But I got to try right ? cheers, gryff Quote Link to comment Share on other sites More sharing options...
dbawel Posted June 28, 2016 Author Share Posted June 28, 2016 Hello @DigiHz Data and @gryff - I really appriciate your scripts, and they appear provide everything I need. With the several versions I have now, I should have no problem setting up my scripts more efficiently. You are both awesome! Cheers, DB Quote Link to comment Share on other sites More sharing options...
DigiHz Data Posted June 29, 2016 Share Posted June 29, 2016 Thank you dbawel. I am sure gryff appriciate your thanks to. Hope it works out for you. Quote Link to comment Share on other sites More sharing options...
Boz Posted June 29, 2016 Share Posted June 29, 2016 Yeah, thanks guys, I was facing the same problem and your scripts help me to have a good global understanding Quote Link to comment Share on other sites More sharing options...
gryff Posted July 1, 2016 Share Posted July 1, 2016 On 2016-06-27 at 8:14 PM, dbawel said: however I have to finish a scene to demo Thursday @dbawel : Well David, I hope the demo went well - no matter whose code - or variants - you ended up using And maybe you could give us a demo of your final code - so that everyone here can benefit cheers, gryff Quote Link to comment Share on other sites More sharing options...
dbawel Posted July 2, 2016 Author Share Posted July 2, 2016 Hey @gryff - Unfortunately, my node.js server was unstable in running the app (due to issues with partial request functions recently added), so I postponed until I have corrected any issues and have relyable QA. So we will have a demo in a wekk if all goes well, and rescheduled for then. And yes, I'm really looking forward to providing the link to our real time simultanious multi-user app - as I've been talking about this and working on it for months now, and it sounds like fantasy anyway - but it really does work well. Of course we've been building the server for many years now, which is the core of our technology. And not to show what I've built myself, but to show what this community has provided me including a great deal of help from you personally. As well as extensions such as bGUI and castorGUI which I'm using both in the new app. So expect a link in hopefully less than 2 weeks (I'm fairly certain, as I have to deliver to Weta and am "WAY" overdue), and as always, thank you and everyone on this forum for all of your amazing help in providing me the info required to build an app which is a first of its kind, and could only be built now and using babylon.js and the supporting extensions. Thanks for asking, and I'll keep you up to date as I get closer. Cheers, DB Wingnut and gryff 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.