SyntaxBomb - Indie Coders

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

Title: Christmas Project - Streaming Terrain Editor
Post by: Kronos on December 18, 2019, 10:24:57 PM
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 AM
oooh, very nice :)
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: 3DzForMe on December 19, 2019, 09:12:37 AM
Sounds Very intriguing  :o
Title: Re: Christmas Project - Streaming Terrain Editor
Post by: Kronos on December 24, 2019, 10:14:20 PM
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, 11:06:15 PM
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 AM
Quote
A 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, 05:32:07 PM
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 PM
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, 05:10:12 PM
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, 12:24:12 AM
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, 05:28:07 PM
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, 09:24:20 PM
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, 05:58:35 PM
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, 07:12:28 PM
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, 09:02:20 PM
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 AM
Quote
  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. 
 

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, 10:03:25 PM
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 AM
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, 05:02:16 PM
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.

SimplePortal 2.3.6 © 2008-2014, SimplePortal