imagination XD

realizing dream


80 Comments

[Tutorial] MMD 4 Unity

Flawless, I wish Bullet Physic comes to Unity 5. VMD Anim + FBX Anim demo.

So I found out how to Import PMD / PMX to Unity. My old trick uses Blender, PMD Importer, and FBX Exporter. It was like this below, (mine was old anyway…) *keep scrolling for a simpler way* Recipe

  1. One Teaspoon of Blender (I use 2.71)
  2. A cup of Sugiany Blender MMD Tools
  3. a PMD Model of course
  4. And 1Kg of Patients

Stereoarts’ MMD4Mecanim

And it was really long and hard and it doesn’t even have an automatic physics configuring! And then I found this good guy posts about MMD4Mecanim which only import PMD / PMX to Unity Assets folder and it’ll automatically do the magic and poof! You got PMD model on Unity.

MMD4U9

Any motions can be played with this

Why MMD4Unity ? Isn’t MMD just enough ?

  • Unity has Mecanim, it’s easier (for me) to animate especially a lazy person like me (too lazy to reanimate every locomotion for every model)
  • Unity 5 now has full access of epic post processing. Depth of Field! Bloom! Motion Blur! Edge Detection!
  • And many more…

What you’ll need for MMD4Mecanim,

  1. Unity
  2. Stereoarts’ MMD4Mecanim (download is on MMD4Mecanim_Beta_*.zip)
  3. A PMD / PMX Model.

NOTE FOR PMD Users : Since I see this only supports PMX, you have to convert your PMD to PMX first. Download PMX Editor, then open your PMD file and save it as PMX.

And here’s how to import your PMD / PMX Model to Unity

  1. Download and extract PMD / PMX Model, copy whole folder to Unity Assets folder
  2. MMD4U1
  3. Then you’ll found there’s a MMD4Mecanim assets file (It has Unity logo)
  4. MMD4U2
  5. Read the License agreement and then click process.
  6. If you have a VMD File (MMD’s Motion data), copy your VMD data to Unity Assets and put your VMD to Animation Clip field.
  7. MMD4U3
  8. Then press process
  9. MMD4U5
  10. Always remember to set Animation Type to Humanoid then press Apply. If you not, no animation can be played unless you import a VMD file.
  11. MMD4U6
  12. Remember to select your Animator controller and Check Apply Root Motion and turn on Bullet Physics
  13. Now add your processed FBX to your scene, it’s now compatible for all your Mecanim like ThirdPersonHumanoid. If you want to add VMD to your mecanim, just Create a New state then put your anim-ized VMD there, and play.
  14. MMD4U7
  15. MMD4U8
  16. Flawless isn’t it ?


Leave a comment

[Unity] Save Game with ArrayPrefs2

I already use this script since Catapult. This is the best saving script I ever use, but this is not really easy to use. I also developing my own format but it’s not really better than this. My own format will going to be use in Personified Fear or above game. Works with indie don’t worry.

You can see the script here.

It can save any types, but the most i liked is the Array function. It’s easier and much more safe.

For example, if you want to save sound volumes setting information (Javascript for example)

  1. In your Menu GUI Script, put var volumes = new float[5];
  2. Also set the awake / default value of volumes if Player haven’t set the volumes. like if(!PlayerPrefs.HasKey(“KeyName”)){ awakeVolumes[0] = Camera.main.audio.volume; awakeVolumes[1] = AudioListener.volume; volumes = awakeVolumes; PlayerPrefsX.SetFloatArray(“KeyName”, volumes);}
  3. Then set on start / awake function, if(PlayerPrefs.HasKey(“KeyName”)){ volumes = PlayerPrefsX.GetFloatArray(“KeyName”, awakeVolumes); }
  4. On your Scroll bar GUI of main volume (volumes[1]) or music volume (volumes[0]), the scrollbar value must be volumes[0] for music volume scrollbar. Whatever you set it, when player press Save, just put PlayerPrefsX.SetFloatArray(“KeyName”,volumes);
  5. To delete user data, just simply put PlayerPrefs.DeleteKey(“KeyName”)

Okay, this is the script example of Menu GUI

var volumes = new float[5]; // volumes has 5 array of float with 0 value...
private var awakeVolumes = new float[5]; //must be same array with volumes above

function Awake(){

awakeVolumes[0] = Camera.main.audio.volume; //music volume
awakeVolumes[1] = AudioListener.volume;

if(HasKey("Game Volumes")){
volumes = PlayerPrefsX.GetFloatArray("Game Volumes", awakeVolumes);
Camera.main.audio.volume = volumes[0];
AudioListener.volume = volumes[1];
}else{
PlayerPrefsX.SetFloatArray("Game Volumes", awakeVolumes);
volumes = awakeVolumes;
}

function OnGUI(){

// let's skip making window process
GUILayout.Label("Music Volume");
volumes[0] = GUILayout.HorizontalScrollbar(volumes[0],0.0,1.0);
GUILayout.Label(volumes[0].ToString());

GUILayout.Label("Main Volume");
volumes[1] = GUILayout.HorizontalScrollbar(volumes[1],0.0,1.0);
GUILayout.Label(volumes[1].ToString());

if(GUILayout.Button("Save")){
PlayerPrefsX.SetFloatArray("Game Volumes", volumes);
}
if(GUILayout.Button("Delete")){
PlayerPrefs.DeleteKey("Game Volumes");
}

}

}

My New 2013 saver use something like XML but i’ll make own format to keep player to change every value on XML.


2 Comments

[Unity Editor Tool] Set Tag Recursively

This tool will set all object children tag to parent’s tag. Without this, you would have to set every children tag one by one, with this, you’ll only need to drag one parent object to Object to change and every child object’s tag will be same with parent’s. But remember! The tag you want to change must add to Unity Tags (Unity > Edit > Project Settings > Layers and Tags).

Change Tags Recursively

This can be really useful you know since Unity wont let to change tags recursively.

Save it as javascript and put it on Editor folder… Ah yes, I put it on SKiPPER > Set Tag to launch this tool


class SetTagRecursively extends ScriptableWizard
{
	var objToChange : GameObject;
	var tag : String;
	
	function OnWizardUpdate () {
		//objToChange = Selection.gameObject;
	}
	
	function OnWizardCreate () {
		//for(x in objToChange){
			var x = objToChange.GetComponentsInChildren(Transform);
			for(var z in x) z.tag = tag;
		//}
	}
	
	@MenuItem("SKiPPER/Set Tag")
	static function TagRecursively () {
		ScriptableWizard.DisplayWizard("Change Tags Recursively", SetTagRecursively, "Touch to Henshin...");
	}
}


3 Comments

[Unity] Keyed Lipsync using Blendshape + Tagarela

edfedfe

I still research on how to make automated keyless lipsync. So, I found this plug in, it’s free, and it’s easy to use so I got that goin’ for me, which is nice.

Recipe (What you’ll need) :

  • PC with Unity 4.3 or above
  • Tagarela
  • Mesh that has blendshape (If you don’t know how to make blendshape, read this)
  • Blendshape that has at least A,I,U,E,O keys. (if you are too lazy to make E key, you can use I for every E)

Alright let’s start! I’ll use Kagamine Len by Animasa model as example.

  1. After finished download, open it in Unity.
  2. Select an object that has blendshape / skinned mesh renderer on it. Open Component > Tagarela. After that insert Audio Clip and then press Add.lt1
  3. Click Open Editor then press Create New Animation, choose Audio Sync, name it whatever you want, press save.lt2
  4. First, slide the tiny slider near audio’s start, then press + to add new keyframe, locate the new keyframe at the middle of audio, and adjust the blendshape below.
    lt3
  5. I use Unity chan’s konnichiwa (こんにちは私ユニティちゃん). 1 is all Zero, 2 is 100% 001 (O (I forgot to change name), 3 is also zero because it’s closing its mouth when saying kon’, and 4 is 100% i, when it says ni.
    lt4
  6. Set it till near perfection. Also remember to set keyframe to zero on all flat audio which is mute (does your mouth open when you say nothing ? unless you breathing with mouth, like me). For example, your voice was “Hello World”, 1 all zero keyframe was located before Hello, 2 keyframe was located in ‘He’ has 100% ‘E’, and 3 keyframe was located in the ‘llo” has 100% ‘O’ and 0% ‘E’, at the end of ‘Hello’ add 4 keyframe that is zero keyframe, and 5 keyframe was located at the beginning of ‘World’ which also zero. 6 keyframe repat like 2 keyframe but with different value.
    lt5
  7. After you done naturalising the lipsync, always remember to put zero keyframe at the start of audio not voice. and then save it. You may ask how to use it on gameplay, well, you’ll only need to put this GetComponent<Tagarela>().Play( <Your animation number (mine is 0 because it’s the first animation)> ); on a C# script. Also attach this script on the same place where your blendshape mesh.
    lt6
  8. Ta-da… Not bad I see. I also forgot to add some Mecanim animator, so it looks like stupid people says “Hello, I’m Unity-chan” but actually you are Len Kagamine.

Next, I’ll research much easier to use lipsync or Anime-like lipsync. Most anime I watch, they only use 1 key. Even they say “What the hell are you doing”, their mouth will be always open and close only, no wide or narrow. Also remember to make it jagged, so it’ll look like Anime. I also researching on how to combine cloth shader with Toon shader like cloth crumple shadow in usual anime.

Ah and Imagine-chan’s model has finished, and it’ll release probably this november. I think I’ll need to remodel, because her head looks ridiculous. However, morphless FBX and PMX download will be available. I’m kinda busy working. My supervisor wont let me to do this, so that’s why I wont upload this model soon.


1 Comment

[Unity] Taking In-Game Screenshot

Hello, everyone, Sorry I didn’t post something here in long time. I’m very busy, leveling up my CG skills. I also post some random unity things.

So, basically, taking screenshot in Unity is very easy. Copy this script below, and attach it in Main Camera

var folderName : String = "DCIM";
var captureSound : AudioClip;
var quality : float; //Set screenshot resolutions, default is 1. 1 equals your monitor size.
private var screenshotFader : GameObject;

function LateUpdate(){
 if(screenshotFader){ //Flashing effect
 screenshotFader.guiTexture.color.a -= Time.deltaTime;
 if(screenshotFader.guiTexture.color.a < 0){
 Destroy(screenshotFader);
 screenshotFader = null;
 }
 }
 
 if(Input.GetKeyDown("C") && !screenshotFader){
 if (!System.IO.Directory.Exists(folderName)) System.IO.Directory.CreateDirectory(folderName);
 
 screenshotFilename = folderName+"/DSC_"+System.DateTime.Now.Day.ToString()+"_"+System.DateTime.Now.Hour.ToString()+System.DateTime.Now.Minute.ToString()+System.DateTime.Now.Second.ToString()+".png";
 if(!System.IO.File.Exists(screenshotFilename)){
 Application.CaptureScreenshot(screenshotFilename,quality);
 AudioSource.PlayClipAtPoint(captureSound,transform.position);
 DrawWhiteItem();
 }
 }
}

function DrawWhiteItem(){
 yield new WaitForSeconds(0.5); //wait for a few frames so the application can capture before the white flash comes out.
 screenshotFader = DrawFader();
}

static function DrawFader() : GameObject{
 var fdt = new Texture2D(1,1);
 fdt.SetPixel(0,0,Color.white);
 fdt.Apply();
 
 var fadex = new GameObject("CSader");
 fadex.AddComponent(GUITexture);
 fadex.transform.position = Vector3(.5,.5,1000);
 fadex.guiTexture.texture = fdt;
 
 return fadex;
}

now it’ll save the screenshot on your game root folder / DCIM (you can change the folder name).


12 Comments

Joint-based Hair / Cloth Physics for Unity

I was doing the MMD4Unity research. I do this because, on Google, if you want a Hair Physics, you have to wrote a script, or key frame it naturally in your model. Ain’t nobody got time for that keyframing! So, this might be very useful for easy Joint-based hair / cloth physics, even wrote a script was useful too.

Okay, so it’ll be like this. It could be very awesomely epic if you are not lazy to set the character joint setting.

“It’s long and complicated, i better use keyframe method.” Yeah true, but what to do when the hair colliding object because of your keyframing method ?

Let’s get Neru Akita as example (Model from MMD, some motion from Unity-chan).

Unity 2014-07-27 14-07-06-60_2

1. Now Select cloth / hair bones and then add Capsule Collider like the picture below.
1(bones)

2. After that, adjust the size of the colliders and then add Character Joint.
2(bones)

3. If your character has a Character Controller on it / Playable, Open Tags & Layer, add 2 layers. Set ‘Player’ layer to object that has Character Controller on it. Else, set the object that you want to have a hair / cloth physics like Hair Bones1, Hair Bones2, and so on, or Hair/Cloth physics collider like MidSpine (That has Collider, so hair / cloth wont clip like hell). Basically, Just set Cloth Layer to Skinned Mesh Renderer, and set it to all children.
3b (Bones)

4. Go to your character controller script. Whatever script is OK as long as its located on Object that has Character Controller on it. Don’t make a new script. Just add this line to function Start() or void Start(). Works on both C# and JS. 8 is Cloth layer, 9 is Player layer. it’s all up to you on what layer you set the Cloth or Player layer. If you set cloth layer to 10, then write 10.

Physics.IgnoreLayerCollision(8,9);

3c (bones)
5. Alright now let’s add Rigidbody on cloth’s / hair’s root bone. For the root of the cloth (like this below), turn on isKinematic and turn off useGravity. Root doesn’t need a Character Joint, Collider is optional.

4 (bones)
6. Now set the Character Joint’s connected body. For instance, 1 (Cloth Root), 2 (1’s child), 3 (2’s child). 3’s connected body is 2, 2’s connected body is 1, and 1 doesn’t have a Character Joint. Like the picture below.
5 (bones)
7. Set bone’s swing limit, spring, high twist limit, low twist limit that suits to your model.
6 (bones)
8. Now add some collider to body that Hair or cloth will collide. Remember to set the body layer to CLOTH, so your character controller wont collide it. I add the colliders on Body, Hands, and Head.
7 (bones)

Because if you don’t add colliders, it’ll look like this:
Unity 2014-07-27 14-07-06-60

Now look! A cloths dynamic! It much better than the method I use on Wild West Showdown (Skinned Cloth). Look at her front hair and tie.
Unity 2014-07-27 14-07-06-60_1

 

As I said, I leave making games because I need to level up my CG level. I said I was give up right ? No, and never. I just need to learn to make a better CG Artwork. I’m currently making a mascot model for Imagination, named Imajine-chan. but, I don’t have an inspiration for her character design.

EDIT : “My Character raycast’s script is broken because of this.” Well, you could replace Cloth to IgnoreRaycast layer.


Leave a comment

[Shader] Reflective Transparent / Water-like Unity Indie

This is what I promised. Sorry for being late, I’m kinda busy recently. I made this shader by merging between Transparent>Diffuse and Reflective>Diffuse. But I haven’t done with Normal Mapped Specular. My Unity kinda hates me, everytime I add Normal Map to this shader Unity Yells “Too many texture interpolators would be used for ForwardBase pass!” or “_ReflectColor no Properties!”. Perhaps you can do it yourself.

NOTE : I didn’t copy this script from internet. I just merge Unity’s Transparent>Diffuse and Reflective>Diffuse. So, if you are saying that I copy your script like that movie script I was made in 2012 and you found in 2014, go f*** yourself… By the way, this script ALREADY Exist on Nitro Racer XD on Epic Living Room track. I just made a lot of modification from Nitro Racer XD.

Shader name in Unity is “Glass Reflective_N”, and this is the preview / how to use the shader.

Ref_BLWater Ref_Full Ref_BLRef Ref_MStUnity - Untitled - RT - PC, Mac & Linux Standalone_4

Want More Realistic ?

If you want more realistic, you could add UVMover (Moving main texture’s offset from script * Time.deltaTime), and Realtime Reflection INDIE. Adding some Caustic effects or Underwater effects or Normal Map or Specular Shininess. You can also use this shader for a glass…

Glass Reflective_N

Shader name is a little bit ironic isn’t it ? It says N for Normal Map support, but this shader couldn’t support Normal Map. Alright here’s the shader.

Shader "Glass Reflective_N" {
 Properties {
 _Color ("Main Color", Color) = (0.5,0.5,0.5,1)
 _ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
 //_Shininess ("Shininess", Range (0.01, 1)) = 0.078125
 _MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {}
 //_BumpMap ("Normalmap", 2D) = "bump" {}
 _Cube ("Reflection Cubemap", Cube) = "black" { TexGen CubeReflect }
 }
 SubShader {
 Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
 Blend SrcAlpha OneMinusSrcAlpha
 //Pass {
 // Color [_Color]
 // SetTexture [_MainTex] {
 // combine texture * primary
 // }
 // }
 LOD 300
 
 CGPROGRAM
 //#pragma surface surf BlinnPhong decal:add nolightmap
 #pragma surface surf BlinnPhong alpha
 //#pragma target 3.0
 sampler2D _MainTex;
 //sampler2D _BumpMap;
 samplerCUBE _Cube;
 //half _Shininess;
 
 fixed4 _ReflectColor;
 fixed4 _Color;
 
 struct Input {
 float3 worldRefl;
 float2 uv_MainTex;
 //float2 uv_BumpMap;
 INTERNAL_DATA
 };
 
 void surf (Input IN, inout SurfaceOutput o) {
 fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
 //o.Albedo = 1;
 //o.Gloss = 0;
 o.Albedo = tex.rgb * _Color.rgb;
 o.Gloss = tex.a;
 //o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
 
 //o.Specular = _Shininess;
 float3 worldRefl = WorldReflectionVector (IN, o.Normal);
 fixed4 reflcol = texCUBE (_Cube, IN.worldRefl);
 reflcol *= tex.a;
 o.Emission = reflcol.rgb * _ReflectColor.rgb;
 //o.Alpha = reflcol.a * _ReflectColor.a;
 o.Alpha = tex.a * _Color.a;
 
 }
 ENDCG
 }
 FallBack "Transparent/VertexLit"
}