OpenB3D online, combined with My-Basic interpreter

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

Previous topic - Next topic

markcwm

Hi Angros,

thanks for the reply. If it requires a rewrite for debug then it wouldn't be worth it, I am managing OK without it now I am understanding my-basic better.

I haven't tried it with a Javascript console as I don't know how.

Thanks for fixing UpdateWorld, it works! I cleared my browser cache and now it can animate a b3d.

Also, the default light seems to be working.



Graphics3D(600, 450)

camera=CreateCamera()
CameraClsColor (camera,100,150,200)

light=CreateLight()
RotateEntity (light,45,45,0)

cube=CreateCube()
tex=LoadTexture("crate.bmp",9)
EntityTexture (cube,tex)

mesh=LoadAnimMesh("zombie.b3d")

MoveEntity(camera,0,10,-20)

MoveEntity(mesh,0,0,5)

tics=0
Animate (mesh,1,0.1,0,0)

While tics<200
TurnEntity (cube,0.1,0.1,0.1)

UpdateWorld()
RenderWorld()
Flip()

tics=tics+1
Wend

William33

Quote from: angros47 on October 03, 2021, 17:48:41
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"

Is it possible to compile a native binary for desktop (Linux/Windows/macOS)? Looks nice but I would rather like to not use emscripten but GCC.
(I built myself two BASIC interpreters based on MY-BASIC and would like to see another one. Ok, maybe with raylib in the future ...)
AMD Ryzen 7 5700H, 32 GB RAM, RX 6600M (8 GB), Windows 11 Pro, 64-bit
AMD Ryzen 5 5500U, 8 GB RAM, Linux Mint 21.1, 64-bit
AMD Ryzen 5 5600G, 16 GB RAM, openSuse Leap 15.5, 64-bit
Apple Mac Mini M1, 8 GB RAM, macOS Sonoma

angros47

Of course it is possible.
I have made a test version (never published) on Linux using an IDE made with FLTK, for example. The bile OB3D.cpp needs few changes, the my-basic interpreter needs no change (it doesn't use any platform specific feature, so it can compiled on almost any platform with enough memory), and OpenB3D has a version for desktop. The only thing that has to be replaced is the IDE (because an IDE made for desktop is completely different from an IDE made for a web page)

I'll put the test I made on Mediafire: https://www.mediafire.com/file/m3so7n1exqanoll/ide.zip/file
The code is compiled for Linux, if you want to compile it for Windows you will have to rebuild the library as well. It should work, but I haven't tested it much, and I wasn't planning to release it, so there is no support if it doesn't work (I made it just to see if it was possible)

William33

Ok, thanks a lot. It works very well. I'll try to study the source but I prefer a standalone interpreter (without IDE)  ;)
Anyway thanks for the work, I can learn some FLT, too.  ;D
AMD Ryzen 7 5700H, 32 GB RAM, RX 6600M (8 GB), Windows 11 Pro, 64-bit
AMD Ryzen 5 5500U, 8 GB RAM, Linux Mint 21.1, 64-bit
AMD Ryzen 5 5600G, 16 GB RAM, openSuse Leap 15.5, 64-bit
Apple Mac Mini M1, 8 GB RAM, macOS Sonoma

angros47

Creating a separated executable with the interpreter could indeed be a solution. The IDE I gave you, in its current form, should not be used for writing code, because it has a severe issue: it runs in a single thread, and has no protection against segmentation faults. It means that if the code crashes (and it's pretty easy to crash it, for example by trying to perform an operation on an entity that doesn't exist), the whole interpreter closes, IDE included, and any unsaved work is lost. This is the reason why I haven't published it: it would be infuriating, and disappointing, for the final user.

If you plan to do anything with it, make sure to address this issue before releasing the interpreter.

angros47

Quote from: markcwm on July 10, 2021, 01:09:49
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.

I should have finally fixed that issue, it was a mistake in the FreeEntity function for lights. If you want to try it now, let me know if it works better

Also, I recompiled it with the option ALLOW_MEMORY_GROWTH, that should allow to load larger terrains-

markcwm

Hi Angros,

thanks for the fix, yes the light seem to work fine now but I've only tested with one light.

I tried running a simple terrain example but it gets very slow even with only 32 size terrain. Also there are terrain rendering bugs visible. So I think terrains are unusable with MyBasic.


angros47

My post was lost due to the forum being reloaded from backup... basically, the issue you describe about CreateTerrain might be because C++ doesn't initialize newly allocated memory: the first time, it is zero, since it has never been used, but the next time it might contain old data.

Surely, I could modify CreateTerrain adding a loop to set all the height to zero, but it would be just a waste of time in most cases, because if you create a terrain you will likely set all its heights with ModifyTerrain anyway, so the code would just waste time setting the heights twice.

markcwm

#23
Yes, hacked again! OK, I was saying I noticed that the terrain runs perfectly first time, then usually on the 2nd run per session it get corrupted like the screenshots below (left: 2nd run at 64, right: 3rd run, no change in camera angle) and caused the browser to slow down. The screenshots were taken after calling FreeEntity and the results were the same as when not using it. Oddly, when I tried CreateTerrain 32 or 16 the terrain didn't seem to be corrupted after repeated runs but still got slowdown.



' CreateTerrain Example

Graphics3D(600, 450)

camera=CreateCamera()
PositionEntity (camera,1,1,1)

light=CreateLight()
RotateEntity (light,90,0,0)

' Create terrain
terrain=CreateTerrain(128)

' Texture terrain
grass_tex=LoadTexture( "terrain-1.jpg" )
EntityTexture (terrain,grass_tex)

TurnEntity (camera,0,220,0)

for x=0 to 127
  for y= 0 to 127
    ModifyTerrain(terrain,x,y,RND/50)
  next
next

RenderWorld()

Flip()

FreeEntity(terrain)

angros47

Try using a nested loop, something like:
for x=0 to 31
  for y= 0 to 31
    ModifyTerrain(terrain,x,y,0)
  next
next


Also, what is the point of those "while..wend" commands? Remove them, or the program will get stuck in a never ending loop (and pressing RUN while the program has not terminated yet might fail to reinitialize the library, causing unexpected issues)

markcwm

Oh sorry, yes I wasn't incrementing my tics variable so it was getting stuck in the while wend loop, causing the slowdown.

I updated the example to run a randomly modified terrain and it works now at all terrain sizes. Except if I click Run too fast (less than 1 second) then I get some minor corruptions as shown in this screenshot.



Do you known how to get keyboard input? And how would I read a heightmap image?

angros47

Keyboard input should be implemented in OB3D.cpp, yet

About reading a heightmap image... why don't you just use LoadTerrain?

markcwm

OK thanks, yes I just wondered if it was possible to use a ReadPixel command. I can't find OB3D.cpp though, I tested GetKey() and it doesn't return anything.

Graphics3D(600, 450)

camera=CreateCamera()

light=CreateLight()
RotateEntity (light,45,45,0)

cube=CreateCube()

MoveEntity(camera,0,10,-20)

tics=0
While tics<200
value=GetKey()
TurnEntity (cube,0.1,0.1,0.1)

RenderWorld()
Flip()

print(value)
tics=tics+1
Wend

angros47

The file OB3D.cpp is inside the archive at URL:  https://sourceforge.net/projects/openb3d-online/files/

You would have to rebuild it with Emscripten.
GetKey is not implemented, at the moment (as I said, it yet has to be implemented)

ReadPixel is not a command of OpenB3D, and it has never been, you should likely address OpenGL/WebGL commands directly.

markcwm

OK thanks. I never used GetKey but isn't it like KeyDown? That would be cool to use the keyboard, I will look forward to it.