Last active
March 12, 2019 02:23
-
-
Save edwios/bf4c2eb046fb2a29a7e3ad1cdfab5026 to your computer and use it in GitHub Desktop.
VRM Size Fixer: to fix the size difference of those VRoid models in Unity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class VRMSizeFixer : MonoBehaviour { | |
public float minSize;//調整後の最小サイズ | |
public float maxSize;//調整後の最大サイズ | |
public GameObject VRMModel;//対象のモデル | |
private Transform transSelf; | |
private Animator anime; | |
private Transform transHead; | |
private Transform transFoot; | |
private float defaultHeight; | |
// Use this for initialization | |
void Start () { | |
anime = VRMModel.GetComponent<Animator>(); | |
transSelf = VRMModel.GetComponent<Transform>(); | |
transHead = anime.GetBoneTransform(HumanBodyBones.Head); | |
transFoot = anime.GetBoneTransform(HumanBodyBones.RightFoot); | |
defaultHeight = transHead.position.y - transFoot.position.y; | |
Debug.Log(defaultHeight); | |
if(defaultHeight < minSize) | |
{ | |
float multiply = minSize / defaultHeight; | |
transSelf.localScale = new Vector3(multiply, multiply, multiply); | |
}else if(defaultHeight > maxSize) | |
{ | |
float multiply = maxSize / defaultHeight; | |
transSelf.localScale = new Vector3(multiply, multiply, multiply); | |
} | |
} | |
// Update is called once per frame | |
void Update () { | |
} | |
} | |
// Source: https://qiita.com/Hirai0827/items/0ac58c024c125faeaaa5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment