Wednesday, 31 July 2019

Relearning Everything I Did Not Know About Blender3D

Whilst I wistfully gaze at my still unopened Tax Return, with it's passive-aggressive "PLEASE OPEN IMMEDIATELY" and not so passively aggressive bright red stamp of "31ST OCTOBER IS THE PAPER FILING DEADLINE", my mind turns back to the problems of character modelling, drifting past the bottle of SA Chenin Blanc, into the mysteries of rigging shoulders correctly so they don't deform into some sort of monstrous mockery of Quasimodo, and other general 3D shenanigans.

 Me, trying to get a mesh friendly to weight painting ...

Now I have done all of this before - in very low poly - on the version of Blender3D which I am used to using. That version is 2.44 which came with it's own custom plugin for the DYNAMIX THREE SPACE file format exporter 0.964. You remember Dynamix? They were that video game company founded in 1984. They made Rise Of The Dragon in 1990, a futuristic detective, adventure game which ripped off Bladerunner and I never understood what the hell I was supposed to be doing whilst playing it ...

Anyway, that version of Blender3D dates back to around 2007, which is at least 100 years ago... so there's probably been some improvements and changes since then. And it turns out there has been. In fact I already knew that there had been as I've been tentatively using version 2.78c for a while, ever since they created the normal editing modifier to stop foliage and especially grass, from looking like complete shizen.

Turns out it was February 2016 and still no finished game fml ...

So first up, how do I into character modelling? I can not even into character modelling!

Hello makeHuman! makeHuman is a 3D character/human body generator which I played with years ago and never got back to. However it has one important thing going for it - it exports with a various skeletal armatures and comes pre-weight painted for bones nodes.

After quite a bit of fiddling around, I had previously managed to make a fairly accurate rendition of Toobz in makeHuman (though the fatassed robut needed more ass fattening and the legs slider was never going to be long enough) (and I added extra oppai) and exported it into Blender3D with a rigged skeleton and then slapped some cat ears on it.

makeHuman created a near perfect replica of Nier: Automata's 2B but the butt slider maxed out ...

So next up ... I need said model with cat ears slapping into a harness which would ultimately be attached to some sort of steampunk propeller pack. Cue searching for tutorial videos on all the other changes to Blender3D's modifiers. One of these I have already found out by testing - is that the decimate modifier, which turns your overly high poly mesh into something more video game and Level Of Detail (LOD) distance friendly, now keeps the weight painting data for bones in the armature. Ye olde 2.44 version used to just kill the vertex information, leaving you with an unanimatable (that's not a word is it?) model, so I used to have to do my LODs for Airship Dragoon by hand/eye manually ... which was a real pain in the Shizener. So this improvement was another major reason to finally upgrade to a newer version of Blender3D.

 How character modelling usually turns out without using a proven work flow ...

The model I have been working with is somewhat overly high-poly for in-game. It is also overly rigged, with many bones that I do not require for gameplay. However I am hoping to do a few high poly "cut scenes", so I am currently concentrating on making an intermediate model I can both "poly up and down" later as needs be.

So, this harness then ... I mooched around the internet (as usually but this time trying to be useful) and found a load of video tutorials from 2011 about making a static character model - which is still a lot newer than my 2007 knowledge. And it had this amazing thing called the "shrink wrap modifier"!. Basically I make clothing too big, and then "shrink to fit". And it works pretty good.

Shrink to fit, just like that baggy T-Shirt and a hot bucket of water

So that wasn't too bad, I made horribly baggy mesh around the model for tight fitting clothing, and got it to reduce to the model's topography with an offset with the push of a button (after much experimenting). Next up was building various straps over the new harness mesh manually.

Extra strappiness to stop overly excited catgirls from falling out

And this is when I hit (another problem). I had previously been using the mirror modifier so I only needed to create half the harness, then apply it and shrink wrap. But now I noticed that the buckles/clasps above the waist were not perfectly symmetrical. makeHuman exported the pose with a slight kink in the spine, so everything above the waist is slightly to one side. Straightening the pose manually was easy enough in Blender3D, but it didn't make the mesh perfectly straight, and it was still off. Note to self; check this sort of thing before you start working on it.

Bravely/stubbornly/being past caring* (delete as applicable) I continued, ad libbing (which turns out to be 2 words) as I went and continued. Now the whole idea of the character is that they ski around the level with a propeller driven backpack - hence the strappy harness. The rotors/propellers themselves are going to be flat, animated textures - so that saves some polygons and drawcalls.

Propeller area in dark grey, green is a gauge

 Next up I needed some sort of under clothing, rather like a skin suit or leotard or boobtube (which was a thing in the 1980s). I attempted some sort of vague modelling by hand/eye co-ordination, which is not that great at the best of times, and then went off to find some more video tutorials on Blender3D to see if they would help. This is when I discovered physics. Now I studied physics at school, by which I meant the teacher didn't care if anyone learnt anything or not as he got paid all the same, and thus let me sleep in class (this was the 1980s, the greatest decade in history). I got an E grade which was surprisingly better than I thought I would get for doing nothing.

Anyway, back to the physics inside Blender3D. With a bit of jiggery-pokery it can be used to create clothing that falls into place with gravity (note: T-pose is best for this or it slips down the arms and falls off). I made a whole series of tests, but only screenshotted the final result. This was a bit "flappy" so I ended up tying down the bottom manually. This looked rubbish, so I ended up extending the character mesh out to meet the material which didn't look so great either so I ended up faffing until I had some sort of boobtube, carved a few dints into the middle and called it quits.

Physics in action! Meaning the one physic of gravity

By this time I had decided I did not like the propeller casings being so high and had dropped them into the mainframe of the jetpack - or should that be proppack?

And now to merge the two meshes into one - whilst also deleting all geometry hidden behind the harness in one fell swoop! First up duplicate the original character model, because if everything goes horribly wrong we might need the original again later (wise, wise words). I sealed all the open sections of the harness, thus cutting into the character model and then used the boolean modifier (named after George Boole, tricorn hats off to you, sir) to remove all the unnecessary bits of character mesh that was hiding behind the brown harness mesh.

This created abject chaos.

Firstly, it severs straight through the target mesh, which is exactly what you want ... kind of. It creates F-Gons (a plane with more than 4 vertices)- which are nasty planes surrounded in loose vertexes everywhere. Hunting all of these down to manually fix them to the edge of the source mesh is a nightmare. And it will have to be manually, because the automated remove doubles is distance based and will just eat up random geometry. Secondly the target mesh seals itself where it's cut, creating lots more elongated planes which have to be deleted. After much faffing around with the first problem I decided to try a different tack.

I selected all the visible planes of the source model around the harness and deleted the rest. Merging both objects I manually merged vertices when close enough and built new planes so elsewhere so the source mesh and harness mesh became one. Whilst this was somewhat labour intensive, it was easier and faster than dealing with over nine thousand F-Gons.

So, finally I have a single mesh, at least of the character body and the harness. Next up, data transfer to get the original makeHuman bone weights into my new Frankenmodel. Playing around with the system I found that using "Nearest Face Interpolated" filled out the weight painting to the entire model, whilst some of the others left the buckles of the straps unfilled with weight data.

Great success! Glad I didn't have to do that manually!

So, that's about it for this month. We had a heatwave and I got a great tan. Next up, hair, because what I have been using in all of these pictures is a placeholder, and then to start on UV mapping and textures. I also need to rig that backpack.

There is a new version of Blender3D out, it's 2.80! As it's taken me ~15 years to upgrade to 2.78c ... I might wait a bit ...

Sunday, 30 June 2019

Assimp Does Magic Stuff And I Get Distracted

This was a bit of a surprise.

 That says Blend file that does

Whilst playing around and looking for bugs in the latest beta of open sourced Torque3D game engine, I accidentally imported a BLEND file from free open source(ish) Blender3D modelling program. Obviously this by accident, because I would never have thought that it would work.

I had found some ripped game models and other sculpts (see Tifa above) and was looking at them in Blender3D for modelling reference. I had experimented with various export options and was loading them into the engine when I accidentally double clicked the Blend file rather than the exported DAE file. Et voila, it actually loaded with all materials correctly mapped.

This is due to the new Assimp importer which appears to be able to read pretty much anything and import it because magic.

Literally my understand of how Assimp works ...

Assimp also comes with a metric ton of options - none of which I really understand so I just kept using the defaults except for maybe rotating the up axis to Z when needed - and it kept importing models fine as long as I had multiple mesh objects set to be read as a single sized LOD.

When the Beat-Em Up waifus are extra thicc

I had tried various other model formats and found FBX and BLEND to be the easiest at automagically loading the corrects textures into the material slots. Amusingly - or not as the case may be - the original DAE importer was the worst and created the most hassle. Not all the models I had found on the internets had their textures setup for a standard PBR material, hence the rather off colour Chunners.

DAE->OBJ->FBX->BLEND

I had also seen someone using the normals editing tool in Blender in a way that I had not thought of before. For foliage and tree leaves they had placed the mesh inside of a huge sphere object and then targeted it. This made the leaf faces orient outwards to the nearest sphere point. For my current project all leaf and foliage mesh faces are orientated nearly vertically upwards, targeting a node high above, because that's pretty much where the player's camera is for a top-down perspective.

No normal editing target->Vertical target->Spherical target

Did I mention distraction? Yes I did. I had been harassed by "The Idea Fairy" and suddenly had the urge to make a Dieselpunk Ace Combat style game. I ended up writing up a design document and fairly in depth statistics of how the whole thing would play, utilising real world 1930s and 1940s aircraft. I imagined it would play rather like the old Freespace space combat simulator, only in high altitude clouds rather than space. Aircraft would ... well, aircraft, and airships would make up an equivalent of a real world navy. I also ended up playing through Freespace 2 and the original Freespace mod for it. For the first time ever, I have a state of the art gaming PC and use it for playing 20 year old games.

This thing needs keeping on a short leash ...

So that was the distraction that stymied this month's progress. I did however get some work done on the current project, the one that I am supposed to be working on, by transferring some heavily used scripts for targeting to C++ code to take a bit of weight off the processor when they are called so often. I also added went mad for statistics and added rankings for player performance on to the already percentaged data. I went for the Japanese obsession with S which may or may not mean SPECIAL, so the highest rank is SSS, SS, S before getting into a more standard alphabetical descent, and it goes down all the way to F for FAILED MISERABLY.

Yo Dawg I heard you like Statistics ...

Of course the real reason I did all of this stuff was simply to avoid having to model 3D hair because it's boring. Yep, that was it. An entire month of obfuscation to not doing something that is time consuming and dull. I also got poisoned with a chemical gas leak for two weeks having had an engineer out to investigate a gas leak, then getting a methane detector thinking that it was a gas buildup in the drains before eventually finding the source leaking out of a vat, and I was also immobilised with a back injury for another week, which was caused by just bending over the sink. So not a great month in general.

Next month, getting back to what I should have been doing this month ... allegedly ...

Friday, 31 May 2019

Level Design And Level Redesign And Level Redux

Environmental level creation continues in earnest.

Level 4 is a grassland, inspired by the Asian Steppe. Originally the grass was going to be green, but the previous level was predominately green, so for variation I changed it to a more prairie yellowish-brown.

 The Steppe, home to deer-monster, Wendigo-type, thingies ...

Grasslands, by their very nature are somewhat ... well, bland. There's a lot of grass and low rolling hills with more grass and not very much else. The level is mostly wide and flat open spaces, with high, dark, rock walls to limit the playable environments outer reaches. I added a few extra rock outcrops to break up the vast expanse and created a central "hub" mountain which dominates the centre of the map to create a vaguely circular map with a lot of open space. To disrupt the near constant flow of grass I threw in a few autumn coloured bushes which help add variance to the monotony, and clumps of violet flowers for a colour deviation. The violet flowers are all clumped around the central mountain, whilst the red and yellow bushes tend to crowd towards the outer edges of the map. This helps the player orientate themselves a little to their position in the wide expanses.

Whilst planning level design I realised that as the game progressed, the levels were getting too big too quickly. I do a lot of heavy playtesting - because, well, no one else is, so it's the only way to spot issues with things. By level 3 I was getting lost quite easily in the various narrow alleyways of the canyon level.

Whilst developing the gameplay and enemies for each level, I had been using my test level with grid textures for each of the consecutive level maps. This meant that I had always been testing in the same space. When I started to create the actual individual levels I had multiplied the size.

I went back and redesigned the first three levels, first cropping them into a more square shape that would fit inside a 512 pixel heightmap rather than a long thin shape that spilled into a 1024 pixel one but didn't use up much of the available space. This saved on the amount of terrain that the engine had to render and precompile collision for, which in turn saved on the number of polygons that had to be drawn.

The original test level had later become the basis for the first level. This map has a traversable area of twelve percent. Originally I had started by doubling the size for progressive levels but this now obviously far too much. Going back, I redesigned the second and third levels with a formula to increase level size based on around 50%-70% of level 1 size. Thus level 2 now has a traversable area of >150% the size of level 1 at ~20% of the 512 pixel heightmap, and level 3 is >200% larger than level 1 with a traversable area of ~26%. By contrast level 3 has an area of  ~33% that the player can traverse.

Smaller heightmap sizes obviously reduce the amount of renderable terrain triangles and collision calls. For the first time I also used the "remove terrain tool", creating holes in the terrain in areas which the player would certainly never be able to see on-screen. This helped reduce the renderable area further.

Thick foliage.
Thinned foliage -50% polygons. Textures with less leaves show more transparency.

In the spirit of creating complex but also lean environments to reduce overhead I had another look at all my foliage. Whilst grass clearly needs all of it's polygons, I thought that I might be able to save a few on the bushes as the leaves near the undersides are not all going to be visible, obscured by those on top. I selected all the polygons that could be seen from directly above and deleted the rest. Depending on how thick the textures are with leaves, this thinned the viewable foliage somewhat, but for a saving of a whopping 50% polygons. Bushes are there to add movement in the wind and prevent the levels from looking barren, they're not there to hide the terrain beneath them so being more see-through is not a problem.

I tried the same idea with trees but the saving were so small - around 10% - that it didn't seem worth bothering with, so I left them as is.

And that, has been the month of May, 2019. Also the local internet exchange blew up and I was reduced to living a stoneage existence, devoid of memes, waifus, and all the important work related sites and indie game and engine development discord channel I rely on for day-to-day information about work.

In the meantime I rewrote various bits of code related to spawning the player in more open areas, reworked some effects and did manage to have a little play around with the (PBR) Physical Based Rendering package due for release with the next update of the engine.

PBR coming soon ... ish ...

Not entirely sure which bit of the development cycle I will tackle next. I might continue with level building as I am now 40% complete, or I might go back into 3D character modelling and finally replace that yellow placeholder cube with an actual player character.

In the meantime, have a look at some gameplay testing for level 4, The Steppe.



Tune in for next month's exciting instalment of the game development that never ends!