SyntaxBomb - Indie Coders

General Category => Worklogs => Topic started by: Kronos on December 18, 2019, 22:24:57

Title: Christmas Project - Streaming Terrain Editor
Post by: Kronos on December 18, 2019, 22:24:57
As a Christmas project I have decided to attempt a streaming terrain editor/object placer using OpenB3D and C#.  I wrote some code in Blitz3DSDK a long time ago which could load meshes in bit by bit which seemed to work ok so I am using this for the time being. I kinda wanted to do this in Python as an excuse to learn the language but have had a few issues getting OpenB3D to work with it so I will stick with C#.

Not sure how I am going to do the terrain painting yet but as this is a quick and dirty project I may be able to get away with using vertex colours.

I am using OpenTK to create the opengl context. Took a bit of time to get it working in a form but its all good now.
Having some problems getting the lighting to work properly in OpenB3D, dunno whether the normals in the meshes are messed up or whether I have forgotten some setting I need for lighting. Also could be my OpenB3D wrapper. It's been a long time since I dabbled with Blitz3D/OpenB3D... EDIT: definitely not the normals, I visualized them and they are all pointing in the expected directions.

Current progess: I can select vertices in any terrain mesh and raise them --woohoo!
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: iWasAdam on December 19, 2019, 08:13:27
oooh, very nice :)
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: 3DzForMe on December 19, 2019, 09:12:37
Sounds Very intriguing  :o
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on December 24, 2019, 22:14:20
Progress report.

Well this has certainly caused me some headaches.. I have abandoned the streaming side of things for the time being and am concentrating on getting the editor to work. I have changed how I save the terrain information from text files to images.
Annoyingly UpdateNormals in Openb3d doesn't seem to work on meshes where I have amended vertex positions until I save them and then reload them which makes terrain sculpting a bit tricky unless you are in wireframe mode.

The saved meshes appear to be losing resolution at some point. Will need to look into this. Floats converting to ints somewhere no doubt.
Also some bug with the wireframe checkbox which keeps switching on.
Will need to manually calculate the normals on the edges of each tile so no seams will be visible.

Also one of my monitors just died. Forgotten how tedious it is having to work on a single screen.

Alot happier now anyway than I was a couple of hours ago:) Here's a vid of current version.







Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Qube on December 24, 2019, 23:06:15
Looks like it progressing very well, nice one :)
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: 3DzForMe on December 26, 2019, 08:25:22
QuoteA lot happier now anyway than I was a couple of hours ago:) Here's a vid of current version.

Brilliant looking work, you're inspiring me to crack open some of my old coding exploits  ;D
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on December 28, 2019, 17:32:07
Just time for a quick update today. Changed how the heights are saved in the image so that saved tiles no longer look chunky. I convert the mesh float height value to 3 byte values in the heightmap image(rgb) which retains decimals to 3 places. Hopefully should be enough definition.
Next on the list is to look at calculating tile edge normals. Edit..not looking forward to doing this so maybe I'll do something more fun first
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on January 01, 2020, 12:17:49
Might need to rename this to "Long term" project as it is obviously going to take some time. Don't want to spend 100% of my free time working on this I just want to be able to do a couple of hours every now and again.

Had a devil of a time getting shader/texturing to work. As per normal it turns out the problem was in an entirely different place to where I was looking. Was thinking I had screwed up the shader somehow but it turns out when mesh is loaded the UV coords were being calculated as ints so all had value of 1 or 0! As an aside, looking at recent shader examples it looks like shader code format has changed yet again since I last looked at shaders. I am a bit of a shader novice. Anyway as you can see in vid below it is sort of working now.

In order for picking and lighting to work properly on any altered mesh it has to be deleted and reloaded, so next job will be to create a "refresh" function that will re-generate all currently visible tiles. I haven't "delta-timed" anything yet so should probably do that sooner rather than later. Seems to be alot more stable now which is good.

Finding that I am having to create alot of files to keep track of all the elements. I have a main header file, a log file, then for each tile I have a tile header file(currently just contains info about textures to use for this tile), heightmap,  colour map, normal map(not done yet). Not sure how I am going to store vegetation and entity info at this stage.

Anyway lots to think about  :)


Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on January 11, 2020, 17:10:12
Still putting off doing the edge normal calculations as I think it will be horrible.
Spent a couple of hours today just cleaning up the current code a bit.
Added a refresh button so that normals can be re-calculated on altered meshes on the fly. Ideally this would happen after every mesh update but I am a bit wary of constantly creating and deleting entities. However it is a bit annoying that you can't easily see the deformations as you do them due to the lighting.
Re-jigged the texture loading slightly as I discovered that I was constantly reloading same textures. This has smoothed things out a bit.
The texture painting for multiple tiles is more or less sorted.
Still getting an odd effect with the alpha channel when painting textures. Instead of the texture fading in gradually the area goes bright and then the texture fades in.
Looking forward to being able to paint vegetation.
However thats enough for today, time to go play something.
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on February 03, 2020, 00:24:12
Porting existing code over to Agk. This is contingent on me being able to get mesh creation via memblock to work which currently it isn't :( No crashes just nothing appearing on screen.

EDIT: that was a major pain in the butt to get working but I appear to have done it! I can now create meshes in AGK. >:(

Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on February 08, 2020, 17:28:07
This weeks progress..

Whilst porting code over to AGK I made the decision to scale back my ambitions somewhat so this is no longer going to be a streaming Terrain Editor as it was not working well and was causing me too many headaches. So it will just be a plain single terrain editor. This gave me an excuse to re-write alot of my previous code and I am alot happier the way its all laid out now. Vertex painting is working but as I haven't added the splatting shader yet all you see is textures. I now store all terrain tile info in text files instead of heightmaps which means I can dig deep holes in the terrain as well as build high mountains.

Next on to do list is add the splatting shader, fix those bloody edge normals(should be easier now!), add some water, and then add vegetation and objects.
As I navigate round the map using WASD and space bar keys one issue I am having is key inputs being picked up by the form controls, not sure how to fix this at the moment. Any suggestions would be welcome. Specifically after amending one of the sun/skybox controls and then pressing a key as control is  selected it doesn't like it. You can see in the video every time I change a control setting I click back to the terrain edit panel so as to de-select the control.



Title: Re: Christmas Project - Streaming Terrain Editor
Post by: 3DzForMe on February 08, 2020, 21:24:20
Oh my, impressive progress ;)  Have you any thoughts regarding using a heightmap as the base load for your editor, then tweaking the terrain from there - I sincerely mean it when I say exciting stuff.  :D

If you were to use a 'heightmap', would you be inclined to make the 'ground' of the terrain at 128 pixels - giving the option for digging down 128 graduations & up by the same amount? Or..... set the 'ground' wherever you want between 10 to 245 graduations.... the mind boggles. Sorry for my rambling.
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on February 10, 2020, 17:58:35
When I was using heightmaps before I was taking the height as 4 bytes,(pixel colours) and converting to a float to get a bigger range and +- values.

I may return to heightmaps as I am having some speed issues loading and saving to text files but have other problems to solve first.

Edit:ooh i think I just fixed my shader problem.
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on February 10, 2020, 19:12:28
While we are rambling, it's amazing how one little success can totally re-energise you. After yesterdays round of coding I was pretty despondent, many things were/are not working, I seemed to have coded some massive memory leak somewhere, couldnt get the terrain shader to work, program runs real slow on large maps etc. I was in one of those "am I wasting my time doing this, should I give up" moods.

However today after only 10 minutes I got the shader working and it's like a little ray of sunshine which has totally transformed my outlook on the project again. It's good to have a win now and again. It also makes me happy that I can pull together all those little experiments I have been coding for years and make use of them in one project. No code is ever wasted in the long run.  :)

ramble ends.
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on February 11, 2020, 21:02:20
I have identified the source of the memory leak issue when saving files and have a workaround that fixes the issues. The GetMeshMemBlockVertexRed/Green/Blue/Alpha commands seem to be the culprits.Whether this is a wrapper problem or an AGK problem I don't know.

Also found a way to dramatically increase picking speed of terrain which means the selection area can now be much bigger. Before I was pushing memblock data to the mesh after every update while the left mouse button was pressed if a change was detected. Changing this to only pushing memblock data when left mouse button is raised after a press means there is no slowdown. For terrain sculpting this is not an issue as I have the vertex selection lines to use as a guide which work off the memblock, however terrain painting has become a bit more vague as you don't see anything until mouse button is raised. The pro's outweigh the con's so I can live with it. Makes terrain painting feel more like real painting anyway.

My first attempt at fixing the tile edge normals doesn't seem to have worked so will need to re-examine when I am feeling fresh.
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: 3DzForMe on February 13, 2020, 05:11:26
QuoteHowever today after only 10 minutes I got the shader working and it's like a little ray of sunshine which has totally transformed my outlook on the project again. It's good to have a win now and again. It also makes me happy that I can pull together all those little experiments I have been coding for years and make use of them in one project. No code is ever wasted in the long run. 
 

Great stuff, my project has been kinda on hold for a bit - real life stuff getting in the way ;)  I do love the way AGK renders heightmaps though ;)
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on February 14, 2020, 22:03:25
Added shadows and water. I am using a variation of the water code Janbo posted on the AGK forums, which I think he sourced from ThinMatrix. Well worth watching his video series on Youtube  btw.

Halfway through the video I noticed that i had lost my selection lines but was able to fix afterwards. This is starting to look not half bad ;D Except for those damn tile edge normals!!

Not sure I am going to stick with the AGK skybox as it is a bit shonky. Doesn't stay in the correct position when camera goes high.

Also just figured out how to anchor my form elements so in next video screens should be much bigger. Enjoy.

Edit: Eureka fixed those normals \o/

Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on April 26, 2020, 01:12:47
Taking a break from the terrain editor which has stalled a bit as I am having problems figuring out how best to load models, and have been experimenting with some simple procedural terrain generation.

I create a 2d map using various rules which holds the terrain types(this was probably the most fun bit to do) From this I generate a heightmap and a splat texture and then use these to generate the map in 3d. I am using a texture atlas to hold 16 terrain textures and a a second texture to hold 16 splatmaps. Just using place holder models and low res textures at the moment. Been trying to follow the advice from various forums about dealing with the edges lines that appear on the textures but so far not working.

The idea is that eventually I should be able to seed structures, entities and then quests on the map.

The map creator is written using appgamekit and the 3d stuff is written in python, as I wanted to see what the language is like but still uses appgamekit as the 3d engine.

Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on May 01, 2020, 17:02:16
I have been doing some work on steering behaviours today. Quite relaxing watching the tanks milling around. They are still a bit twitchy but for the first time I kinda understand how they are supposed to work.

Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on December 03, 2023, 11:12:58
Re-visiting the terrain editor last few days. It had devolved into a bit of a mess code-wise and also wasn't a streaming terrain editor which is what I wanted. I hit a bit of block when it came to adding objects to the terrain which is why I stopped. So re-writing from scratch but pulling out chunks of previous code.

Still using AGK as the engine with the C# wrapper. Anyway at the moment the streaming part is now working fine, not async but works good enough. I can raise, lower and flatten terrain and changes are instantly saved. Next thing to do is the normal calculation and then I will think about how best to add objects before worrying about texturing terrain etc. For the texturing I plan to use a texture atlas approach, probably1 texture + 1 normal map for whole terrain initially but eventually move this down to terrain chunk level. I am trying to work with a minimalist gui(practically non existent at the moment) not sure how far I can go with this.

Not really happy with how appgamekit loads models as it doesn't seem to be able to loadchild objects in all cases and doesnt work well with alot of my old b3d/obj models so I may need to write my own  loader.
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: blinkok on December 03, 2023, 22:47:27
I get;
An error occurred. Please try again later. (Playback ID: tvYjVBGXH10eITrO)
When i try play the video
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on December 12, 2023, 21:25:27
If I could edit my posts I could try and fix that.
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on December 13, 2023, 18:28:39
Managed to put a few hours into this today. I have the basics of model loading and saving, positioning, rotating, scaling working plus a simple menu system using agk text commands.
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on December 14, 2023, 21:38:04
Add map creating, loading and saving in menu.
Add terrain vertex painting - colours only at the moment
Add background sprite to menu items so that they are more readable.

(https://www.syntaxbomb.com/gallery/92_14_12_23_9_43_05.png)
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: 3DzForMe on December 16, 2023, 04:32:32
@Kronos - cracking looking project! If you need a beta tester let me know. I don't know if 'VistaPro' means anything to you, but your project takes me back!
https://youtu.be/5UMcB8dTxPQ



Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on December 24, 2023, 17:33:22
re-did the menu code as I wasn't happy with it.
porting code from the old project - terrain texturing is now working using the old method ie non texture atlas - had some problems with this.
added reflective water plane.

Work on a separate model program so that I can load meshes into the editor with all their attributes ie textures and shaders etc defined.
Next step will be to add this format to the editor.

Kinda not happy with the "click and release" method I am using for terrain changes but can't think of any other way to do it at the moment. In Appgamekit my understanding is that you can't change a memblock linked to a mesh on the fly, you have to amend the memblock, then delete the mesh and then re-create a new mesh from the memblock. If anyone knows different please let me know. Currently I only do the mesh creation step after the mouse button is released so you cant see the actual meshs deforming or painting in realtime.  I am using lines as a substitute for when deforming meshes but painting is complete invisible at the moment until the mouse key is released.

Edit: I think I have found the command I need re the memblocks. Didn't realise that I dont have to create new meshes every time ;o
Edit2: Change was simple now it looks much better, visible terraforming and painting. I am happy and now going to bed.
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: William on December 25, 2023, 16:18:43
so, your app is with the appgamekit? presently i use rcterrain editor and importing heightmaps but i think there are other/better ones. maybe i should work on terrain soon.
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on December 25, 2023, 17:50:47

Still a long way to go but happy with progress so far.
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on December 27, 2023, 13:47:49
Added the update normals code back in, went surprisingly easy.
Started work on a vegetation layer system.
Various other tweaks and fixes.
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on December 28, 2023, 18:44:59
So after a day of struggling with adding meshes together it now appears the AddObjectMeshFromMemblock commands basically just adds the memblock mesh as a child object of the original, it does NOT merge the child mesh  into the main mesh like the Blitz3d AddMesh command does. So I am going to have to rethink my approach to this.
Edit: think I have fixed by writing my addmesh function.
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on December 30, 2023, 15:10:51
Vegetation layers is now working. Still needs some work and the process is a bit clunky. I'll probably do a demo in my next video.

Moving away from the idea of using texture atlases as I like the freedom to load any texture plus I am aware that there are certain problems with mipmapping and edges. Still want to add normal mapping to the terrain textures but not sure how at the moment. Was thinking of trying an approach where a single texture contains color and normal map.

Added physics. This slows down the loading of the terrain chunks a little.

Need to clean up and re-organise my code a little.

Also currently all the terrain files are just loose in folders so I want to compress these into a zip or into 1 big file.

Model Loader still needs some work, can't currently deal with multiple mesh objects. Also extra info for shaders may be required. mesh transformation options to correct weird rotations, scaling etc






Title: Re: Christmas Project - Streaming Terrain Editor
Post by: William on December 30, 2023, 15:45:26
:) i read your worklog. i dont know what to write, its not something i could take the time to do (write a terrain editor).

im interested in lang/app compilers like between blitz and thegamecreators. i dont know why. its neat what people do. dark basic forums were one of the places i've posted at (2001-02) i believe. someone convinced me of blitz so that is what i did. but had i gone with darkbasic maybe it would had been better. still, bmx is the freeware and it has a lot of modules like encryption, LUA and multi-platform support etcetera code archives, i really like the open source linux approach though its very indie.

i just want to write a game to play with others <3

were it not for other users, i probably would not be able to get very far on my own and would have gaven up.

so, better documentation of how to accomplish things could garner other users who have interest in.. if it can be defined what it is, blitzmax (or monkey) its kindof depends on us and especially the knowledgeable members.

i wanted to ask about appgamekit from you.
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on December 31, 2023, 15:55:16
Thanks for your interest.

Not sure I understand your question but I will try and answer. If you have never programmed before and don't intend to take programming further then appgamekit is probably a good place to start. Appgamekit forums are still active so you would get support for any questions you might have there.Its relatively current language and has alot of support for mobile programming etc.

I started with blitzmax which is alot closer to more modern object orientated languages eg c#. it has classes and methods, lists etc. Moving from blitzmax to appgamekit feels like a step backwards to me. From blitzmax I was able to move to C# without too much difficulty as blitzmax taught me alot of the core concepts of object orientated programming. I credit it with helping me to become a C# developer for a living. Unfortunately Blitzmax is pretty much dead in the water now so you might struggle to get answers if anything should crop up.

I think I already said I am writing this editor using C#, as its the language I am most comfortable with now, with the AGKSharp wrapper so that I can use its 3d graphics commands.




Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on January 01, 2024, 15:36:23
Trying to incorporate a normal shader into the terrain shading using textures that include the normal map ie top half is colour map and bottom half is normal map.
Its not really working. Not sure the normal calculations are correct plus setting generate mipmaps messes everything up. May try something else.
Also finding it exceedingly difficult to find a tree model that actually loads into Appgamekit correctly. All the models I have don't seem to work although they work fine in blitz3d. I have always found object loading in AGK problematic as it seems unable to load alot of multi-mesh files correctly.

Unfortunately back to work tomorrow so progress on this may be slow from now on.
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on January 06, 2024, 16:10:49
given up trying to add normal shading as I was getting nowhere with it.
Adding .obj loader that can handle multiple meshes as the AGK default loader is crap.
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Qube on January 06, 2024, 16:44:39
Yup, AGK's mesh handling is very fussy as I found when doing my IK+ game for the latest comp. Ripped my hair out for ages to get an animated FBX with normal maps working.

Oddly enough I found that loading my object into Blender and then exporting it out as FBX fixed many many issues I had. After that AGK would load them, I could parse through child meshes and texture + Normal as needed.
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on January 07, 2024, 22:40:18
thanks Qube. I'll look into that, might save me alot of work.
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: iWasAdam on January 08, 2024, 10:43:28
Here's something to give you a little inspiration ;)
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: 3DzForMe on January 08, 2024, 23:51:41
That is quite inspirational, its mind boggling what can be achieved these days.
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on January 17, 2024, 22:31:58
Random thoughts..

Got a workaround for the tree loading issue I was having but it has revealed another problem. I set cull mode on the tree meshes to render front and rear faces but for some reason the shadows seem to be rendered from models with only front faces turned on so parts of the shadow are missing. I will ask on the forum about this.

The tree models I have mostly have 2 material groups, one texture for the trunk and one for the foliage. Appgamekit seems to only be able to load most model formats as one mesh group so one texture will cover the entire mesh. I wrote a little program that merges the two textures into one(basically split horizontally) and then adjusts the texcoords for each material face group so that they map to correct half of the texture. Only tried it with one tree model so far but it works well. It will probably go wrong if there are any texcoords shared between the two material groups though.

Running out of texture slots for the stuff i would like to implement. Cascade shadows for instance in appgamekit takes 4 texture slots. Evolved has posted some tasty shaders on the Appgamekit forums, the parallax occlusion mapping one caught my eye. Would love to see that on my terrain but it takes 3 textures per map. I guess one way to go would be to do multiple rendering passes on the terrain. But for 4 texture layers I would have to render terrain 12 times per frame with water reflections/refractions turned on so might be quite a hit on performance. I will probably experiment with this as I like the idea of not being restricted to 4 textures per terrain chunk. Also texture atlases but I have already played around with those and they seem to cause problems with mipmapping turned on, not just the bleeding edge issue.

I have found Bard has been quite useful for laying out general principles of how to do things etc.

Wondering whether I should put my efforts into learning how to use Flax Engine rather than trying to code my own terrain engine thingy(badly).

Anyway thats enough wittering for one day. Bye for now.