Using Magicavoxel Marching Cube Models in Your Unity Game

 

The new version of Magicavoxel came out today (0.97.1) with the much-awaited marching cube export. Marching Cubes is an algorithm that takes your voxel model and kind of takes the hard edges off so you get something which has a lot of 45 degree angles in it compared to before. It’s been in magicavoxel for a while but only as a render option; now you can actually export the models in this form for your games!

 

All good so far, but unfortunately the export is in .ply format. Ply is a format which was invented to store data from 3d scanners. It’s not a bad format and it easily allows you to store rgb colour data in all your vertices. Unfortunately you really find out who your friends among your software applications when you have a .ply file! Modo, Maya and many others simply won’t let you import this format. More importanly, engines like Unreal Engine and Unity won’t let you import it either.

 

One 3d modeler that does let you import .ply format is Blender so if you haven’t got that go and get it now from blender.org, or get it through Steam which will keep it nice and updated for you. It’s totally free and if you work with 3d models you simply have to have it installed, even if you model in something else.

 

Start up Blender and you’ll see the default scene. I normally delete the default cube so it doesn’t get in the way of my model. Do this by right clicking on the cube then pressing the delete key or x then clicking ok or pressing return. Import the ply into Blender with File->Import->Stanford (.ply). Looking good. Now right click on your object to select it. Then go to File->Export->FBX. Look on the left at the options under “Export FBX”. If you aren’t on the “main” tab, click that. Now make sure you check (tick) “Selected objects”. This ensures that you only export the object you made and not the light and camera (and cube if you didn’t delete that) that come in the default blender scene.

 

Now in Unity you can drag this fbx into the assets pane. Shock horror it’s all in white without your magnificent colourizations! This is fine and is due to the fact that there is no texture for your object: the colour is stored in vertex data which you can’t see in the default unity shader.

 

Now we need to get a vertex colour shader for unity 5. Get it from http://forum.unity3d.com/attachments/unityvc-unitypackage.144627/ The page talking about it is at http://forum.unity3d.com/threads/standard-shader-with-vertex-colors.316529/

 

Now if you know what you’re doing with unity you know what to do next: open up the asset that represents your 3d model, navigate to the shader part and select one of either Standard Specular (vertex color) or Standard (vertex color). Tada.wav colourized model, ready for some spoopy gaming action!

Synthesizer Full Instructions (WIP)

The Synthesizer:


In the top half of the screen you have the synthesizer settings. There are four sections: OSC1, FIL1, OSC2 and FIL2. OSC1 is the player’s oscillator. It is modified by FIL1. OSC2 is the oscillator used by your enemies. It is modified by FIL2.

The first thing you can see in the OSC section is a little 9×9 LCD display. It shows a wave, undulating up and down. At the side you can see the scale: -4 to +4. Time goes across from left to right: the important part of the wave is the leftmost column: it shows what your next attack will be like (in osc1) or the enemies next attack (in osc2). Positive values translate into damage to the enemy; negative values into damage to yourself.

Therefore if the value at the leftmost position of the wave display in osc1 is +3 and you press the key to bump into a monster, they will take 3 damage (although effects can change that but more on those later). If the leftmost value is 0, nothing will happen, while if the leftmost value is say -2, you will take 2 points of damage yourself, again, subject to any effects that may apply.

As time moves on the wave will scroll from the right to the left, so you can see to a certain extent what your attacks will be like in the future and plan accordingly.

Now that you hopefully understand the wave display a little better let us turn to the various knobs that control the settings of the synthesizer. You can’t control these knobs manually by clicking on them: they are changed when you or an enemy walks over a patch. The patches are blue in colour and say things like “FIL LP” or “PW +”. If you mouse over them they will display a brief description of what they do. When these knobs change their positions they will immediately update the wave display. You won’t always notice a change because of how things work.

Wave knob: values: triangle, sawtooth, pulse wave, noise.
This selects the type of the wave. You can google the types of wave if you are new to waveforms.

Amplitude knob: ranges from 0 to 4.
This changes the height of the wave. It also changes the period of the triangle and sawtooth waves (horizontal width of the repeating part of the waveform). With more amplitude you will have higher highs but lower lows and it will affect the timing of the sawtooth and triangle waves. Experiment and have fun!

Pulse width knob: ranges from 1 to 5.
This controls the width of the waveform when it is set to pulse width.

Filter type: settings: off, LP (low pass), HP (high pass)
The filter filters the wave, removing parts of it. The high pass filter removes low parts (letting the -high pass-) and the low pass filter removes the high parts, (letting the -low pass-)

Filter cutoff: ranges from 0 to 4
The cutoff knob tunes the filter, i.e. selects exactly how much of the low or high to filter. At setting 4 the filter basically does nothing as it allows everything through, so it’s the same as if the filter type was set to off. At setting 0 on the other hand the filter filters a lot! If set to to high pass, cutoff 0 will remove all values below 0, so it’s hard to hurt yourself! If set to low pass, cutoff 0 will remove all value ABOVE 0, wiping out your ability to damage the enemy!

Bottom half of the screen:
At the bottom left of the screen we have the playfield: 8×8, non-scrolling map. No FOV, no lighting.

Elements on the playfield:

Effects:
There are various “effects” which show as coloured squares on the floor. These move around. You can see their direction of travel indicated by a little arrow. If you mouse over the effect you can see a brief description of what it does. You or the mob needs to be standing on the effect at the time when you attack forit to take effect.

Glitches:
There are six types of glitch (mobs basically). If you mouse over them in the play area you will see their name and their amount of HP left. Also if you mouse over a glitch or effect you will see a line highlight on the timegrid to the right.

Patches:
The blue things that say things like “PW+” are patches that will affect the synthesizer settings. You can mouse over them for a brief description.

Wall:
Orange hatched square is wall. Indestructible.

Pat->:
This changes the current pattern (level) so it’s kind of like an exit! Mobs can wipe out the exit. Hahahah. You are doomed. Not really. You can generate another one by killing all the mobs. And let’s face it you were going to do that anyway, weren’t you?

Some types of glitch may be able to bring additional gameplay elements into play. I’m sure you’ll figure them out.

To the right of the playfield is a readout showing which pattern you are on (basically level). Every four patterns the synth settings will reset to default. This is basically to combat boring situations in which you have the perfect setting set up. There is no actual end to the game by the way: the aim is to get as far as you can. The number of mobs will increase with level up to a maximum amount.

Master volume is the player’s hp. What a crazy conceit, no!? It’s a synth so the master volume is your hp! Craaaaazy.
Yeah, well, nevermind.

Timegrid:
The timegrid is like a step sequencer for the game. Going down from the top we have a row for the player, then four rows relating to the effects then up to twenty rows dedicated to glitches. In each row time proceeds from now to the future, from left to right. Each little square is one beat, or micro turn. If an entity has a full square in that beat column they will have a chance to act. A little filled box in the leftmost column means the entity can act this beat.

So one beat is a micro turn, and all activity within one beat is considered to happen simultaneously. The game actually looks from top to bottow, so it says, can the player act this beat? if so wait for him to act; next see if each effect can act and do it, then see if any of the glitches (mobs) can act, and do them in order from top to bottom.

It is only at the end of the beat that the game looks to see who is alive and who is dead, so it’s perfectly possible to be taken below 0 HP during a turn and not die.

Also shown on the timegrid, to the right is the hp for player and mobs. For effects it shows instead a small indicator to show what effect it is.

More notes on time:

The player typically acts once every four beats, but in order to be able to attack when conditions are favourable (e.g. when you are standing on a good effect or when your taveform is at its height) the ‘skip beat’ key is your friend. The default binding is numberpad 5.

Note that unlike a wait command in normal roguelikes, the skip button will only skip one beat, rescheduling your future beats to be in sync. For example, say the turns looked like: player yes no no no yes no no no… and then you hit skip it will still say yes no no no yes no no no, but you will be shifted one beat to the right.

Glitches (mobs) all have set beat intervals, e.g. fast small fighters act every 2 beats and slow ones take longer than the player’s 4. When a glitch spawns normally its sync is set randomly within its beat period, so for example a 1 in 4 acting enemy could, from the start of the game go act no no no or it could go no act no no no act … etc.

The current beat number is show just above the timegrid. It’s not that much use except to remind you how long you have been on the current pattern (level).

The Event log to the right is often useful to see what just happened.

The final interface element, situated to the right of the playfield is moop.

moop is bear.
moop carry crate for you, yes?

Keys:
If playing standalone version of the game you can redefine the keys from the unity launcher.
The default keys are:
numpad 2 4 6 8 to move up, down, left and right.
Numpad 5 skips a beat.
Space starts the game from title screen or goes back to title screen from game over. You can also click left mouse.

If you are playing the web player version then unfortunately you can’t change the keys from the default. Sorry about that and I will change it if I can “legally” do so to the 7drl version. If not then you have to buy New Key DLC.

Resolution will always be 1280×720, sorry. I got flustered trying to change that at the last minute. The engine runs at 640×360 and 1920×1080 too but I couldn’t get the smaller res into the unity resolution list, and I couldn’t pick up the res the player selects from the launcher.

What does work in the standalone version is selecting fullscreen or windowed from the launcher. The game will respect that.

Synthesizer: MACOS, Linux, Windows, offline webplayer

Instructional Video

Instructional Web Page:

https://pangoempire.wordpress.com/2015/03/15/synthesizer-full-instructions-wip/

Let’s Play by Author (slightly spoilery if you like to work everything out yourself):

Play in a web page

http://thebroominstitute.itch.io/synthesizer-7drl-2015

Webplayer for offline – only 700k!

http://7drl.org/wp-content/uploads/2015/03/synthesizer-2015-7DRL-web-player-deadline-build.zip

MACOS

http://7drl.org/wp-content/uploads/2015/03/synthesizer.2015-7DRL-deadline-build-MACOS-X86.zip

LINUX

http://7drl.org/wp-content/uploads/2015/03/synthesizer-2015-7drl-deadline-build-linux.zip

ORIGINAL WINDOWS

http://7drl.org/wp-content/uploads/2015/03/synthesizer-2015-7DRL-by-graspee-7DRL-deadline-build.rar

Synthesizer End of Day 7: Success!

Download here: Windows x86 only for now. More builds coming soon.

http://7drl.org/wp-content/uploads/2015/03/synthesizer-2015-7DRL-by-graspee-7DRL-deadline-build.rar
Added flashing squares for damage. It makes what’s going on a lot easier to see, especially the AOE.
Finished off mob special moves.
Added tool tips.

Flustered around near the deadline trying to fix a weird alpha blending bug and trying to add music to the title screen (with no success).

Synthesizer End of Day 6

No new screenshot today because the content I’ve been adding doesn’t change any graphics, only gameplay.

I did effects and mob special attacks.

I still have an animation for one mob special to do and the most complex mob to implement specials for, but that’s all I have to do tomorrow to be finished. Hopefully there will be time to implement some polishing touches I have planned.

Synthesizer End of day 5

<img src=”http://i.imgur.com/Er33mmP.png&#8221; alt=”Moop tired of war.” />

Today I coded combat and mob movement. Bugs in my shitty A* hilariously held me up for far too long and I probably spent too long messing about with sounds. The game is playable and losable now and fairly challenging/fun. I’ve been working on it too long to be a good judge of what is fun though.

Synthesizer End of Day 4

<img src=”http://i.imgur.com/NxlxM3g.png&#8221; alt=”Moop approaches!” />

Pleased with the work done today. A _lot_ of bugs and coding done, starting off with making the “effect” class and collection then a mob class and collection, then drawing the timegrid, showing which effects are in play, the hp of player and monsters, and most importantly showing the beats of who gets to act when in a step sequencer kind of a way.

The main thing done today was the actual Time Engine, which sounds very H.G.Wells. Basically it just handles letting every actor act when they are supposed to. Yesterday the mobs were just statically drawn on the map, as were effects and all you could do is walk around and pick up patches (powerupus) (and it used makeshift old style rl turns). Today the effects move about it as you move and everything is precisely controlled by the beat, and the mobs are real entities that can easily be made to move tomorrow.

The way the turns work is like this. In the timegrid you can see going across are 16 beats. The leftmost one represents the current turn and each one to the right after that is one turn in the future. Going down we have different actors: first the player, then up to 4 effects (coloured squares that provide an effect if standing on them), then mobs. On the current turn we first see if the player can move, and if he can we wait for him, then we see if the effects can move, then the mobs.

The player is set to move once every 4 turns; effects are random from 1 (every turn they move) to 8; mobs are set by their type so skeleton type things are fast fighters and move more often than big heavy things. Mobs and effects are offset by a random amount to make it more interesting but the player always starts with his act on the first beat: act no no no act no no no etc.

If the player using wait advanced him to his next beat it would be a bit dull and his attacks would not vary much, as the wave you can see at the top controls your damage. You would always be going forward 4 steps each time. So what happens is that wait moves you forward 1 beat only and then you can take your turn again, i.e. your turns look like “act no no no act no no no”- you hit wait and then instead of sitting out for this turn and the next three and then getting to act again, it moves the beat forward by one and it’s “act no no no act no no no” again.

I’m quite sanguine about this game getting finished, where I was doubtful earlier in the week.