Big Trouble In Little Blender – 1.7 Initial Unity FBX Import & Animation Notes (Part2)

blender-socket

Notes made after creating a spring for a game element in my current Unity project.

I’d built a model and animated it in Blender using rotation, location and scale – no armatures required. I wanted to be able to import the model into Unity with the multi-mesh animation all ready to go. These notes are based on the mesh having only one animation

These notes probably won’t be useful for anyone other than myself. I’m planning on building models as required, rather than in one lump – Which means I’ll forget everything in the meantime & have to relearn every model I build – To avoid this as much as possible, I’m hoping to use these posts as a reference point.

Apologies for any obvious mistakes or omissions – These notes were made as I was learning, and not necessarily as I had learnt.

 


 

Exporting a mesh with a single animation created using rotation /scale and location – Using no armatures.

Important safety tip:
when creating animations this way –
if the ‘scale’ of a mesh is modified during the animation
the scale of all child meshes will also be affected
this will only be apparent after importing into unity
the animation will play as expected in blender.

1.1 Animation Without Armature

First step – change layout to ‘Animation‘ (top of the window, right of the help menu)

1.2. Goto animation layout

change the view in the top left frame from dope sheet to ‘Action Editor

1.3 view action editor

in the ‘Outlier‘ frame on the far right, select all the meshes with animations you want to merge

1.4 select all animated meshes

Back in the ‘Action View‘ frame (top left) – click ‘+ New‘ button to create a new ‘action’ – this will merge the animations of the selected meshes into one action

1.5 click to create merged animation
Blender will be give this the default name ‘Action

1.6 New animation called action

Click the F button – Positioned next to the Action section

1.7 Press F

Looking something like this;

1.8 looks something like this

Now the action has been created – it needs to be exported to Unity (in this example I’m exporting as an as an FBX)

Select File->Export->FBX

1.9 when exporting the fbx

This will display the ‘export FBX‘ options frame
In this section – Select ‘Animation‘ & untick everything except ‘Baked Animation

1.10 turn off everything except baked animation

Next – in the ‘Armatures‘ section – clear the ‘Add Leaf Bones‘ tickbox

1.11 no armature so untick leaf bones

in the ‘Main‘ section – make sure only mesh is selected (Empty, Camer, Lamp, Armat & Other should be deselected)

1.12 only the mesh needs to be exported

& Finally – Click the ‘Export FBX‘ to export and save the model into the Assets folder in your Unity project.

When the model is opened in Unity – it should only show one animation (called ‘Scene‘)

01c-FullScreen-&-large-base---2-ALT---2

 


 

Last post: 1.6 Animating a basic spring

Contents page.

 


Advertisements

Big Trouble In Little Blender – 1.6 Animating a basic spring

blender-socket

Notes made after creating a spring for a game element in my current Unity project. I needed to animate the spring – The notes below provide a method which keeps the scale intact.

These notes probably won’t be useful for anyone other than myself. I’m planning on building models as required, rather than in one lump – Which means I’ll forget everything in the meantime & have to relearn every model I build – To avoid this as much as possible, I’m hoping to use these posts as a reference point.

Apologies for any obvious mistakes or omissions – These notes were made as I was learning, and not necessarily as I had learnt.

 


 

In the add modifier section change the value of the ‘Screw‘ field to stretch the spring to the desired maximum height.

1.1 spring streched

next duplicate the spring using tools->duplicate – creating spring #2

1.2 duplicate button

Back in the add ‘Modifier Tools‘ section – change the ‘Screw‘ value of this duplicate so the spring #2 is at its minimum desired height – then click ‘Apply

1.3 duplicated minimum height

Select the original (fully expanded) spring #1 and click ‘Apply‘ in the ‘Add Modifier‘ box

1.4 Click apply

 


 

With the original (fully expanded) spring #1 – still selected

1.5 Select original spring

select ‘data object data‘ – the triangle icon next to the modifiers screwdriver icon

1.6 data object properties

in the ‘shape keys‘ section of ‘data object data

1.7a shape keys

click the + button/icon
this should add an element called ‘Basis
storing the settings the original (fully expanded) spring #1

1.7b shape keys

Select the second (fully contracted) spring #2
hold down shift and select the original (fully expanded) spring #1

1.8 both springs selected

in the ‘shape keys‘ section of ‘data object data
click on the black arrow/triangle (under the ‘add button‘)

1.9a black arrow down
this should display a pull down menu
from this menu select ‘join as shapes

1.9b join as shapes
which will add a second element to the ‘shape keys list‘ – this element will have the name of the second (fully contracted) spring #2 (in this case Vert.001)

1.9c second spring added

Since there no further need for the second (fully contracted) spring #2
this can be hidden (or deleted)

1.10 second spring hidden spring

 


 

In the ‘shape keys‘ section of ‘data object data
click on the name of the second (fully contracted) spring #2 (vert.001)

doing this should expand the ‘data object data‘ section
displaying more the shape keys parameters
(if this doesn’t occur try clicking on the white down arrow on the right hand side of the ‘data object data‘ section

1.11a second spring entry
sliding the ‘value‘ parameter up and down should expand and contract the spring.

1.11b spring value 0
Value 0 = Maximum
1.11c spring value 0.5
Value 0.5 = Mid
1.11d spring value 1
Value 1 = Minimum

 


 

To create an animation – Using the animation bar move the green marker to the first frame

1.12 Frame 1

in the ‘shape keys‘ section of ‘data object data
slide the ‘Value‘ parameter and set the spring to fully coiled

1.12b Frame Added
& with the mouse pointer OVER the ‘Value‘ parameter press the I key
this will add a frame to the animation bar & turn the ‘Value‘ field green

1.12b Frame Added

in the animation bar move the green marker to the last frame
& with the mouse pointer over the value parameter press the I key

1.13 last frame

In the animation bar move the green marker to the middle frame

in the ‘shape keys‘ section of ‘data object data
slide the ‘Value‘ parameter and set the spring to fully uncoiled
& with the mouse pointer over the value parameter press the I key

1.14 Mid Frame

Now pressing play – you should have a half decent bouncing spring animation

2017-05-13-1336-49---2-ALT

 


 

Next post: 1.7 Initial Unity FBX Import & Animation Notes (Part2)

Last post: 1.5 Creating a basic Spring

Contents page.

 


Big Trouble In Little Blender – 1.5 Creating a basic Spring

blender-socket

Notes made after creating a spring for a game element in my current Unity project. The process itself isn’t too complicated & the results are pretty nice.

These notes probably won’t be useful for anyone other than myself. I’m planning on building models as required, rather than in one lump – Which means I’ll forget everything in the meantime & have to relearn every model I build – To avoid this as much as possible, I’m hoping to use these posts as a reference point.

Apologies for any obvious mistakes or omissions – These notes were made as I was learning, and not necessarily as I had learnt.

 


 

First the ‘Add Mesh: Extra Objects‘ add-on needs to be enabled – This is used to add a single vertices later in the process.

To do this – goto File->User Preferences

1.1 User Preferences

This should open the ‘Blender User Preferences‘ window
From here click Add-On’s tab at the top of the window and search for ‘Extra Objects

1.3 Addons

Add a tick to ‘Add Mesh: Extra Objects
& everything is done.

 


 

Next add a circle – this circle will be used by blender to create the body of the spring;

2.1 Add circle

Once created – scale the circle to the desired thickness of the spring

2.2 Scale circle

since the spring will coil around the XY axis – the circle needs to be rotated by 90 degrees on the x axis

2.3 Rotate circle

In this example – the spring will be generated/coiled around the central point (position 0, 0, 0).

The radius of the spring will be determined by how far the circle is moved along the x axis

2.4 Position circle 2

 


 

Now to add a single vert – this is used to determine the centre of the spring

Make sure the circle is selected.
Press shift-A to open the add menu
From here select – Mesh->SingleVert->Add Single vert

3.1 Add Single Vert

this will add a single vertices at position 0, 0, 0

3.2 Single Vert Added


The mesh and circle need to be ‘joined‘ creating a single object;
Go to ‘object mode‘ (bottom half of the screen – right of the Object menu)
right click the circle
hold shift and right click the single vert
this will select both elements at the same time

4.1 Both Objects Selected

hold ctrl-J – this will join the two objects
it will also move the axis point to the middle of the world (position 0, 0, 0)

4.2 Both objects joined

 


 

Next the screw tool is used to generate and define the spring – but first it is needed to create a doughnut;

On the right hand side of the screen in the click the spanner icon
this will open the modifiers section

5.1 modifiers

click ‘Add modifier

5.2 Add modifier

and from the list select ‘Screw

5.2 Add screw

this should apply the ‘Screw Modifier‘ to the circle

5.2 screw added

 


 

Construct the spring from the doughnut;

In the ‘Add Modifier‘ ‘Screw‘ settings;

6.1 screw modifier settings

to set the scale of the coil – change the value in the ‘Screw‘ section
this will determine how much the coil rises each 360 degree rotation

6.2 set scale

set the number of coils – change the value in the ‘Iteration‘ parameter
this will termine the size of the spring – the number of coils used to make up the spring

6.3 set iterations

the steps parameter determines how many angles are used to build each coil
the default is 16 – since I generally work with low poly game elements I’m moving this down to 8

6.4 steps 8

make sure ‘click order‘ option is selected to make sure the spring is drawn nicely

6.5 calc order

 


 

That should create a simple spring.
if thats all you need – click ‘Apply‘ in the modifiers box to set the values chosen & move on (maybe close the ends of the spring?)

if you want to animate the spring – DON’T click ‘Apply‘ quite yet… go to the next post (link below) and continue from there…

7.1 apply settings

 


 

Next post: 1.6 Animating a basic spring

Last post: 1.4 Initial Unity FBX Import & Animation Notes (Part1)

Contents page.

 


Adventures in Unity – 2.7 Mesh Fade

Official_unity_logo

Fading a model out of the game can be a pretty useful technique.

When using the built-in shaders, fading a single mesh model in/out is a pretty straight forward process.

If you have model made up of multiple meshes – there is a couple of extra steps you may need to get the desired effect.

I’m going to try and cover both situations below;


For this example, I’m using Unity’s built-in ‘standard’ shader.

The standard shader provides two rendering modes that can be used to fade a mesh – Transparent & Fade.

The unity guide explains their intended usage;

TransparentSuitable for rendering realistic transparent materials such as clear plastic or glass. In this mode, the material itself will take on transparency values (based on the texture’s alpha channel and the alpha of the tint colour), however reflections and lighting highlights will remain visible at full clarity as is the case with real transparent materials.

FadeAllows the transparency values to entirely fade an object out, including any specular highlights or reflections it may have. This mode is useful if you want to animate an object fading in or out. It is not suitable for rendering realistic transparent materials such as clear plastic or glass because the reflections and highlights will also be faded out.

Though it’s generally best to try out both options and see which works best for your project.


To fade in/out a single mesh model;

Models use a material to manage their texture, each material has an assoiated colour.
To fade the mesh we change of the alpha value of this colour.

Alpha values are between 0 & 1;
0.0 = completely transparent
0.x = faded to some degree.
1.0 = fully opaque

To fade a mesh out by 50% (In a script attached to the model’s prefab);

Renderer renderer = GetComponent();
Color color = renderer.material.color;
color.a = 0.5f;
renderer.material.color = color;

to fade a specific colour in the material, use the SetColor function;

Renderer renderer = GetComponent();
Color color = renderer.material.color;
color.a = 0.5f;
renderer.material.SetColor("_Color", color);
001a-FadeBonusTile-x32
Single mesh model – Standard shader set to Fade
001b-TransparentBonusTile-x32
Single Mesh Model – Standard shader set to Transparent

To fade in/out a multi-mesh mesh model;

If the model has multiple meshes, we need to reference the material(s) for each mesh.

(It can be useful to create an instance of each material.
That way the alpha change will only effect that instance of the model & not every model that uses the material)

We may also need to manually set the models ZWrite value
The ZWrite value determines the order in which each mesh is drawn to screen.

002a-FadeMinesUnordered2
Multi-Mesh model – Standard Shader set to Fade – Default ZWrite order
002b-TransparentMinesUnordered2
Multi-Mesh model – Standard shader set to Transparent – Default ZWrite order

To put this in code (as a script attached to the models prefab);

First create a global variable to hold the renderer for each mesh;

Renderer[] rendererObjects;

Then in the init or start method, the renderer array is initialised & populated,
the ZWrite value (draw order) is defined (rather simply here)

 for (int counter = 0; counter < rendererObjects.Length; counter++)
 {
   Material material = rendererObjects[counter].material;
   material.SetInt("_ZWrite", counter);
 }

Once thats done & we are ready to fade – In the main code we can fade the model in or out (in this example I fade the model out – then destroy the instance once it is completely transparent);

for (int counter = 0; counter < rendererObjects.Length; counter++)
 {

   Color color = rendererObjects[counter].material.color;
   color.a -= (Time.deltaTime / 1f) % 1.0f;

   if (color.a <= 0)
      Destroy(gameObject);

   else
      rendererObjects[counter].material.SetColor("_Color", color);

}

The final result should look something like this;

003a-FadeMinesOrdered2
Multi-mesh model – Standard shader set to Fade – ZWrite manually defined.
003b-TransparentMinesOrdered2
Multi-Mesh model – Standard shader set to Transparent – ZWrite manually defined.

Next Post: 2.8 C64 Tileset

Last post: 2.6 Pause & Resume

Contents page.


 

Windows Big Adventure – 1.1 Command Prompt Shutdown

windows10

Command Prompt Shutdown -Allows you to shut down or restart a local or remote computer.
Used without parameters, shutdown will logoff the current user.

I find the timed shutdown command particularly useful. If I want to go to bed, but I know the computer will still need to churn away for another hour or two – I can set the computer to shutdown in 3 hours time (to give it a little leeway) – and push off for the night.

The shutdown command works with Windows 10, Windows 8, Windows 7, Windows Vista, and Windows XP.


Parameters:

[No args] Display help.
/? Display help.
/i Display the graphical user interface (GUI).
/l Log off.
/s Shutdown the computer.
/r Full shutdown and restart the computer.
/g Full shutdown and restart the computer. After the system is
rebooted, restart any registered applications.
/a Abort a system shutdown.
/p Turn off the local computer with no time-out or warning.
/h Hibernate the local computer.
/hybrid Performs a shutdown of the computer and prepares it for fast startup.
/fw Combine with a shutdown option to cause the next boot to go to the
firmware user interface.
/e Document the reason for an unexpected shutdown of a computer.
/o Go to the advanced boot options menu and restart the computer.
Must be used with /r option.
/m \\computer Specify the target computer.
/t xxx Set the time-out period before shutdown to xxx seconds.
The valid range is 0-315360000 (10 years), with a default of 30.
If the timeout period is greater than 0, the /f parameter is
implied.
/c “comment” Comment on the reason for the restart or shutdown.
Maximum of 512 characters allowed.
/f Force running applications to close without forewarning users.
The /f parameter is implied when a value greater than 0 is
specified for the /t parameter.
/d [p|u:]xx:yy Provide the reason for the restart or shutdown

So, for example;

To shutdown the computer and force any open programs to close;
shutdown /s /f

To shutdown and restart autoloading the advanced boot menu;
shutdown /r /o

Top open the remote shutdown GUI;
shutdown /i

remoteshutdowndialog


I use two commands regularly:

Timer shutdown…
shutdown /s /f /t 1800 – Shutdown after half an hour
shutdown /s /f /t 3600 – Shutdown after an hour
shutdown /s /f /t 7200 – Shutdown after Two Hours
shutdown /s /f /t 10800 – Shutdown after Three Hours

& abort [timer] shutdown (once I realise I’ve set the wrong time)…
shutdown /a – Abort the shutdown.

shutdowncmd


It can be a pain working out (Googling) the number of seconds in X hours; these batch files provide a time saving shortcut;

Shutdown after half an hour
Shutdown after One hour
Shutdown after Two Hours
Shutdown after Three Hours
Shutdown Abort