OpenB3D online, combined with My-Basic interpreter

Started by angros47, July 06, 2021, 00:12:38

Previous topic - Next topic

angros47

Want to try developing a small program in OpenB3D, without having to install/configure/compile anything?
It is now possible to use OpenB3D from a basic interpreter embedded in a web page

https://openb3d-online.sourceforge.io/

markcwm

Wow! Amazing. Works well. Had a quick play, it was fun.

How would you do a framerate limited main loop? Could it load textures?

Thanks.

angros47

Thank you!

About your questions:
1) It is possible to have a framerate limited main loop, in a way not too different from classic Blitz3D: the loop is defined with the commands do.... until (there is no "loop" keyword, in My-Basic). The loop must include somewhere inside it the command Flip(), that will take care to call the command emscripten_sleep(1). The interpreter is compiled with the ASYNCIFY option, so closed loops are allowed, no need to use time scheduled events.
Just remember that if you forget the command Flip() in the loop, the web page might hang, since the script would not give back control. Also, commands KeyHit and GetKey are implemented, and keyboard input is evaluated in the time when Flip() is called.
I considered using a separate Sleep command, instead of using the Flip one (that would have allowed me to use a parameter for it, to decide the framerate), but I preferred to keep the simplest syntax, closer to original Blitz3D

2) About loading textures (or also terrains, or 3d models): in theory, it would be possible (the code for it is implemented). Unfortunately, the files should be embedded with the interpreter itself, and at the moment no external file is embedded (I could add some free generic textures, but this would increase the size of the data to download, slowing down page loading). There is no way to use a texture file stored on your local computer, due to the default security settings of most browsers: in fact, giving a webapp access to local files would allow it to potentially read your private documents and share them online, and since a webapp can be started without user's consent, this can't be allowed.

markcwm

Thanks for the reply Angros. Yes, this has great potential but still needs a lot of work, for example KeyDown needs added.

I think this could work well if you ported some of the Blitz3d command reference examples so users could just go and tweak it to test things.

Maybe textures could be scaled down to minimize filesize, but it would only be possible if they were loaded as needed by each example program. I find the framerate too fast on my browser and have no way to set it, I would rather have the Sleep function than not be able to set it at all, the alternative would be to use: time=CreateTimer(60) and WaitTimer(time).

Also I found a bug, when I press Spacebar with lighting on the cube vanishes.

angros47

I have strange issues with lighting (it works at the first execution, but then I need to reload the page)

The changes you mention should not be too difficult to implement. Perhaps would you like if I published the source code?

markcwm

Could it be since Opengl-ES 2 needs shaders for lighting see here?

I think you would be better to keep the source as I'm not familiar with Opengl-ES so I can't see how I could help much.

angros47

In fact that's how lights are implemented in OpenB3D for web (check the file shaders.cpp). There are different shaders, depending on how many lights are implemented. The issue is that the right shader must be enabled in the right moment, and when the program is restarted, I guess they are not reset correctly. Still, you manage do render the meshes with lights (until you press space, at least), don't you?

markcwm

OK, yes I manage to render the mesh with light (I only tested one light) on the first run, it seems not just Space breaks it though, all I need to do is edit the Input window or even just click Run again and the screen goes blank.

angros47

I suspect that space will just trigger "run" another time (if the last thing you clicked was the "run" button).
Anyway, I don't know yet what is wrong, but it should be something in the reset code. Surely it is not something in the shader, otherwise it wouldn't work at first attempt, either.

angros47

Since I forgot to upload the source codes, I fixed that now:

https://sourceforge.net/projects/openb3d-online/files/

The only "original" file is OB3D.cpp, that builds the interface between My-Basic and OpenB3D. Source code of OpenB3D is not included, the file OpenB3D.o can be built from last version of OpenB3D source code using "make web"

angros47

New version: a couple of bugs fixed (terrains, geospheres and metaballs didn't work unless a texture, even an empty one, was applied to them. It should be fixed now)

It is now possible to use textures, and 3d models (in formats b3d, 3ds, md2 and text .X). Since JavaScript, for security reason, cannot access local files directly (otherwise, a web page could run a script that would access and upload local files without user's consent), to be able to use textures or 3d models it is necessary to "preload" them in a virtual file system, by using the button "Choose File" at the bottom of the page. Only files that have been preloaded in that way can be used in your program, and they can be access with commands like "LoadTexture", "LoadMesh" and so on. The files are only loaded locally, nothing is uploaded to the server-

markcwm

Hi Angros,

I just tried it out, a good addition. It worked well, loaded all the textures I tried and also fine with b3d files.

I tried to animate a mesh but it seems not to work, UpdateWorld just hangs.
If there was a texture not loaded for a b3d it would hang.
Sometimes, I'm not sure what caused it, but it would crash and I'd need to reload the page.
There doesn't seem to be any useful debugging error messages, such as error on line > UpdateWorld.

angros47

Unfortunately I haven't implemented any debug yet... since it would require a rework on the whole library.

With "animate a mesh" you mean loading an animated B3D model? Or something else? Also, can you animate a mesh with the Emscripten version in general?

angros47

You can use the JavaScript console to get some debug info: to me, it states "Too many recursion", is it the same error you get?

angros47

Ok, think I found the cause: in the file OB3D.cpp, in the function wrap_UpdateWorld I forgot the line:

mb_check(mb_attempt_open_bracket(s, l));

Now I added it, and updated the page, it should work. Be sure to reload the page completely, or it might still use the old version from your cache