コード例 #1
0
    /// <summary>
    /// アバダーを設定する
    /// </summary>
    /// <returns>アニメーター</returns>
    /// <param name='root_game_object'>ルートゲームオブジェクト</param>
    /// <param name='bones'>ボーンのゲームオブジェクト</param>
    /// <remarks>
    /// モデルに依ってボーン構成に差が有るが、MMD標準モデルとの一致を優先する
    /// </remarks>
    public Animator SettingAvatar()
    {
        //生成済みのボーンをUnity推奨ポーズに設定
        SetRequirePose();

        //アバタールートトランスフォームの取得
        Transform avatar_root_transform = root_game_object_.transform.FindChild("Model");
        if (null == avatar_root_transform) {
            //ルートゲームオブジェクト直下にモデルルートオブジェクトが無い(PMDConverter)なら
            //ルートゲームオブジェクトをアバタールートオブジェクトとする
            avatar_root_transform = root_game_object_.transform;
        }

        //ヒューマノイドアバター作成
        HumanDescription description = new HumanDescription();
        description.human = CreateHumanBone();
        description.skeleton = CreateSkeletonBone();
        description.lowerArmTwist = 0.0f;
        description.upperArmTwist = 0.0f;
        description.upperLegTwist = 0.0f;
        description.lowerLegTwist = 0.0f;
        description.armStretch = 0.0f;
        description.legStretch = 0.0f;
        description.feetSpacing = 0.0f;
        avatar_ = AvatarBuilder.BuildHumanAvatar(avatar_root_transform.gameObject, description);

        //アバターをアニメーターに設定
        animator_ = root_game_object_.AddComponent<Animator>();
        animator_.avatar = avatar_;

        //IKの無効化
        DisableIk();

        return animator_;
    }
コード例 #2
0
 static void HumanDescription_skeleton(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.HumanDescription _this = (UnityEngine.HumanDescription)vc.csObj;
         var result = _this.skeleton;
         var arrRet = result;
         for (int i = 0; arrRet != null && i < arrRet.Length; i++)
         {
             JSMgr.datax.setObject((int)JSApi.SetType.SaveAndTempTrace, arrRet[i]);
             JSApi.moveSaveID2Arr(i);
         }
         JSApi.setArrayS((int)JSApi.SetType.Rval, (arrRet != null ? arrRet.Length : 0), true);
     }
     else
     {
         UnityEngine.SkeletonBone[] arg0 = JSDataExchangeMgr.GetJSArg <UnityEngine.SkeletonBone[]>(() =>
         {
             int jsObjID = JSApi.getObject((int)JSApi.GetType.Arg);
             int length  = JSApi.getArrayLength(jsObjID);
             var ret     = new UnityEngine.SkeletonBone[length];
             for (var i = 0; i < length; i++)
             {
                 JSApi.getElement(jsObjID, i);
                 ret[i] = (UnityEngine.SkeletonBone)JSMgr.datax.getObject((int)JSApi.GetType.SaveAndRemove);
             }
             return(ret);
         });
         UnityEngine.HumanDescription _this = (UnityEngine.HumanDescription)vc.csObj;
         _this.skeleton = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
コード例 #3
0
    public static void CreateAvatar()
    {
        GameObject go = Selection.activeGameObject;

        if (go != null && go.GetComponent("Animator") != null)
        {
            HumanDescription hd = new HumanDescription();

            Dictionary<string,string> boneName = new System.Collections.Generic.Dictionary<string, string>();
            boneName["Chest"] = "spine";
            boneName["Head"] = "head";
            boneName["Hips"] = "hip";
            boneName["LeftFoot"] = "footL";
            boneName["LeftHand"] = "handL";
            boneName["LeftLowerArm"] = "elbowL";
            boneName["LeftLowerLeg"] = "kneeL";
            boneName["LeftShoulder"] = "clavL";
            boneName["LeftUpperArm"] = "armL";
            boneName["LeftUpperLeg"] = "legL";
            boneName["RightFoot"] = "footR";
            boneName["RightHand"] = "handR";
            boneName["RightLowerArm"] = "elbowR";
            boneName["RightLowerLeg"] = "kneeR";
            boneName["RightShoulder"] = "clavR";
            boneName["RightUpperArm"] = "armR";
            boneName["RightUpperLeg"] = "legR";
            boneName["Spine"] = "spine2";
            string[] humanName = HumanTrait.BoneName;
            HumanBone[] humanBones = new HumanBone[boneName.Count];
            int j = 0;
            int i = 0;
            while (i < humanName.Length) {
                if (boneName.ContainsKey(humanName[i])) {
                    HumanBone humanBone = new HumanBone();
                    humanBone.humanName = humanName[i];
                    humanBone.boneName = boneName[humanName[i]];
                    humanBone.limit.useDefaultValues = true;
                    humanBones[j++] = humanBone;
                }
                i++;
            }

            hd.human = humanBones;

            //hd.skeleton = new SkeletonBone[18];
            //hd.skeleton[0].name = ("Hips") ;
            Avatar avatar = AvatarBuilder.BuildHumanAvatar(go, hd);

            avatar.name = (go.name + "_Avatar");
            Debug.Log(avatar.isHuman ? "is human" : "is generic");

            Animator animator = go.GetComponent("Animator") as Animator;
            animator.avatar = avatar;

            string path = AssetDatabase.GenerateUniqueAssetPath(Puppet2D_Editor._puppet2DPath+"/Animation/"+avatar.name+".asset");
            AssetDatabase.CreateAsset(avatar, path);

        }
    }
コード例 #4
0
 public static Avatar BuildHumanAvatar(GameObject go, HumanDescription humanDescription)
 {
     if (go == null)
     {
         throw new NullReferenceException();
     }
     return(BuildHumanAvatarInternal(go, humanDescription));
 }
コード例 #5
0
 /// <summary>
 /// <para>Create a humanoid avatar.</para>
 /// </summary>
 /// <param name="go">Root object of your transform hierachy. It must be the top most gameobject when you create the avatar.</param>
 /// <param name="humanDescription">Humanoid description of the avatar.</param>
 /// <returns>
 /// <para>Returns the Avatar, you must always always check the avatar is valid before using it with Avatar.isValid.</para>
 /// </returns>
 public static Avatar BuildHumanAvatar(GameObject go, HumanDescription humanDescription)
 {
     if (go == null)
     {
         throw new NullReferenceException();
     }
     return BuildHumanAvatarMono(go, humanDescription);
 }
コード例 #6
0
 public static Avatar BuildHumanAvatar(GameObject go, HumanDescription monoHumanDescription)
 {
     if (go == null)
     {
         throw new NullReferenceException();
     }
     return(BuildHumanAvatarMono(go, monoHumanDescription));
 }
コード例 #7
0
 static public int set_skeleton(IntPtr l)
 {
     UnityEngine.HumanDescription o = (UnityEngine.HumanDescription)checkSelf(l);
     UnityEngine.SkeletonBone[]   v;
     checkType(l, 2, out v);
     o.skeleton = v;
     setBack(l, o);
     return(0);
 }
コード例 #8
0
    static public int set_armStretch(IntPtr l)
    {
        UnityEngine.HumanDescription o = (UnityEngine.HumanDescription)checkSelf(l);
        float v;

        checkType(l, 2, out v);
        o.armStretch = v;
        setBack(l, o);
        return(0);
    }
コード例 #9
0
    static public int set_feetSpacing(IntPtr l)
    {
        UnityEngine.HumanDescription o = (UnityEngine.HumanDescription)checkSelf(l);
        float v;

        checkType(l, 2, out v);
        o.feetSpacing = v;
        setBack(l, o);
        return(0);
    }
コード例 #10
0
    static public int set_lowerArmTwist(IntPtr l)
    {
        UnityEngine.HumanDescription o = (UnityEngine.HumanDescription)checkSelf(l);
        float v;

        checkType(l, 2, out v);
        o.lowerArmTwist = v;
        setBack(l, o);
        return(0);
    }
コード例 #11
0
        public static Avatar BuildHumanAvatar(GameObject go, HumanDescription humanDescription)
        {
            bool flag = go == null;

            if (flag)
            {
                throw new NullReferenceException();
            }
            return(AvatarBuilder.BuildHumanAvatarInternal(go, humanDescription));
        }
コード例 #12
0
	static public int constructor(IntPtr l) {
		try {
			UnityEngine.HumanDescription o;
			o=new UnityEngine.HumanDescription();
			pushValue(l,true);
			pushValue(l,o);
			return 2;
		}
		catch(Exception e) {
			return error(l,e);
		}
	}
コード例 #13
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.HumanDescription o;
         o = new UnityEngine.HumanDescription();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
コード例 #14
0
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.HumanDescription o;
         o=new UnityEngine.HumanDescription();
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
コード例 #15
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.HumanDescription o;
         o = new UnityEngine.HumanDescription();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
コード例 #16
0
    static bool AvatarBuilder_BuildHumanAvatar__GameObject__HumanDescription(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 2)
        {
            UnityEngine.GameObject       arg0 = (UnityEngine.GameObject)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
            UnityEngine.HumanDescription arg1 = (UnityEngine.HumanDescription)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
            JSMgr.datax.setObject((int)JSApi.SetType.Rval, UnityEngine.AvatarBuilder.BuildHumanAvatar(arg0, arg1));
        }

        return(true);
    }
コード例 #17
0
 static void HumanDescription_hasTranslationDoF(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.HumanDescription _this = (UnityEngine.HumanDescription)vc.csObj;
         var result = _this.hasTranslationDoF;
         JSApi.setBooleanS((int)JSApi.SetType.Rval, (System.Boolean)(result));
     }
     else
     {
         System.Boolean arg0 = (System.Boolean)JSApi.getBooleanS((int)JSApi.GetType.Arg);
         UnityEngine.HumanDescription _this = (UnityEngine.HumanDescription)vc.csObj;
         _this.hasTranslationDoF = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
コード例 #18
0
 static void HumanDescription_feetSpacing(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.HumanDescription _this = (UnityEngine.HumanDescription)vc.csObj;
         var result = _this.feetSpacing;
         JSApi.setSingle((int)JSApi.SetType.Rval, (System.Single)(result));
     }
     else
     {
         System.Single arg0 = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg);
         UnityEngine.HumanDescription _this = (UnityEngine.HumanDescription)vc.csObj;
         _this.feetSpacing = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
コード例 #19
0
ファイル: UMAGeneratorBase.cs プロジェクト: jlu3389/UMA
        public static HumanDescription CreateHumanDescription(UMAData umaData, UmaTPose umaTPose)
        {
            var res = new HumanDescription();
            res.armStretch = 0;
            res.feetSpacing = 0;
            res.legStretch = 0;
            res.lowerArmTwist = 0.2f;
            res.lowerLegTwist = 1f;
            res.upperArmTwist = 0.5f;
            res.upperLegTwist = 0.1f;

            res.human = umaTPose.humanInfo;
            res.skeleton = umaTPose.boneInfo;
            res.skeleton[0].name = umaData.umaRoot.name;
            SkeletonModifier(umaData, ref res.skeleton);
            return res;
        }
コード例 #20
0
 extern private static Avatar BuildHumanAvatarInternal(GameObject go, HumanDescription humanDescription);
コード例 #21
0
 private static Avatar BuildHumanAvatarMono(GameObject go, HumanDescription monoHumanDescription)
 {
     return INTERNAL_CALL_BuildHumanAvatarMono(go, ref monoHumanDescription);
 }
コード例 #22
0
 static public int get_upperLegTwist(IntPtr l)
 {
     UnityEngine.HumanDescription o = (UnityEngine.HumanDescription)checkSelf(l);
     pushValue(l, o.upperLegTwist);
     return(1);
 }
コード例 #23
0
 private static Avatar INTERNAL_CALL_BuildHumanAvatarMono(GameObject go, ref HumanDescription monoHumanDescription)
 {
     throw new NotImplementedException("なにこれ");
 }
コード例 #24
0
 private extern void get_humanDescription_Injected(out HumanDescription ret);
コード例 #25
0
 private static extern Avatar INTERNAL_CALL_BuildHumanAvatarMono(GameObject go, ref HumanDescription monoHumanDescription);
コード例 #26
0
 static public int get_feetSpacing(IntPtr l)
 {
     UnityEngine.HumanDescription o = (UnityEngine.HumanDescription)checkSelf(l);
     pushValue(l, o.feetSpacing);
     return(1);
 }
コード例 #27
0
 static public int get_legStretch(IntPtr l)
 {
     UnityEngine.HumanDescription o = (UnityEngine.HumanDescription)checkSelf(l);
     pushValue(l, o.legStretch);
     return(1);
 }
コード例 #28
0
 private static extern Avatar BuildHumanAvatarInternal_Injected(GameObject go, ref HumanDescription humanDescription);
コード例 #29
0
		public static Avatar BuildHumanAvatar(GameObject go, HumanDescription monoHumanDescription)
		{
			return AvatarBuilder.INTERNAL_CALL_BuildHumanAvatar(go, ref monoHumanDescription);
		}
コード例 #30
0
 private extern void INTERNAL_get_humanDescription(out HumanDescription value);
コード例 #31
0
ファイル: UmaTPose.cs プロジェクト: NotYours180/UMA
		/// <summary>
		/// Reads from Mecanim human description.
		/// </summary>
		/// <param name="description">Human description.</param>
		public void ReadFromHumanDescription(HumanDescription description)
		{
			humanInfo = description.human;
			boneInfo = description.skeleton;
			armStretch = description.armStretch;
			feetSpacing = description.feetSpacing;
			legStretch = description.legStretch;
			lowerArmTwist = description.lowerArmTwist;
			lowerLegTwist = description.lowerLegTwist;
			upperArmTwist = description.upperArmTwist;
			upperLegTwist = description.upperLegTwist;
			extendedInfo = true;

			Serialize();
			boneInfo = null;
			humanInfo = null;
		}
コード例 #32
0
 private static Avatar BuildHumanAvatarInternal(GameObject go, HumanDescription humanDescription)
 {
     return(AvatarBuilder.BuildHumanAvatarInternal_Injected(go, ref humanDescription));
 }
コード例 #33
0
 /// <summary>
 ///   <para>Create a humanoid avatar.</para>
 /// </summary>
 /// <param name="go">Root object of your transform hierachy.</param>
 /// <param name="monoHumanDescription">Description of the avatar.</param>
 public static Avatar BuildHumanAvatar(GameObject go, HumanDescription monoHumanDescription)
 {
   if ((Object) go == (Object) null)
     throw new NullReferenceException();
   return AvatarBuilder.BuildHumanAvatarMono(go, monoHumanDescription);
 }
コード例 #34
0
 static public int get_skeleton(IntPtr l)
 {
     UnityEngine.HumanDescription o = (UnityEngine.HumanDescription)checkSelf(l);
     pushValue(l, o.skeleton);
     return(1);
 }
コード例 #35
0
 public static Avatar BuildHumanAvatar(GameObject go, HumanDescription monoHumanDescription)
 {
     return(AvatarBuilder.INTERNAL_CALL_BuildHumanAvatar(go, ref monoHumanDescription));
 }
コード例 #36
0
ファイル: UMAGeneratorBase.cs プロジェクト: NotYours180/UMA
		/// <summary>
		/// Creates a Mecanim human description for a UMA character.
		/// </summary>
		/// <returns>The human description.</returns>
		/// <param name="umaData">UMA data.</param>
		/// <param name="umaTPose">UMA TPose.</param>
		public static HumanDescription CreateHumanDescription(UMAData umaData, UmaTPose umaTPose)
		{
			var res = new HumanDescription();
			res.armStretch = 0;
			res.feetSpacing = 0;
			res.legStretch = 0;
			res.lowerArmTwist = 0.2f;
			res.lowerLegTwist = 1f;
			res.upperArmTwist = 0.5f;
			res.upperLegTwist = 0.1f;

			//var animatedBones = umaData.GetAnimatedBones();
			//if (animatedBones.Length > 0)
			//{
			//	List<SkeletonBone> animatedSkeleton = new List<SkeletonBone>(umaTPose.boneInfo);

			//	foreach (var animatedBoneHash in animatedBones)
			//	{
			//		var animatedBone = umaData.GetBoneGameObject(animatedBoneHash).transform;

			//		var sb = new SkeletonBone();
			//		sb.name = animatedBone.name;
			//		sb.position = animatedBone.localPosition;
			//		sb.rotation = animatedBone.localRotation;
			//		sb.scale = animatedBone.localScale;
			//		animatedSkeleton.Add(sb);
			//	}
			//	res.skeleton = animatedSkeleton.ToArray();
			//} else
			//{
			res.skeleton = umaTPose.boneInfo;
			//}

			res.human = umaTPose.humanInfo;

			SkeletonModifier(umaData, ref res.skeleton, res.human);
			return res;
		}
コード例 #37
0
 private static Avatar BuildHumanAvatarMono(GameObject go, HumanDescription monoHumanDescription)
 {
     return(INTERNAL_CALL_BuildHumanAvatarMono(go, ref monoHumanDescription));
 }
コード例 #38
0
 private static extern Avatar INTERNAL_CALL_BuildHumanAvatarMono(GameObject go, ref HumanDescription monoHumanDescription);
コード例 #39
0
ファイル: UMAGeneratorBase.cs プロジェクト: RapsFan/UMA
 public static void DebugLogHumanAvatar(GameObject root, HumanDescription description)
 {
     Debug.Log("***", root);
     Dictionary<String, String> bones = new Dictionary<String, String>();
     foreach (var sb in description.skeleton)
     {
         Debug.Log(sb.name);
         bones[sb.name] = sb.name;
     }
     Debug.Log("----");
     foreach (var hb in description.human)
     {
         string boneName;
         if (bones.TryGetValue(hb.boneName, out boneName))
         {
             Debug.Log(hb.humanName + " -> " + boneName);
         }
         else
         {
             Debug.LogWarning(hb.humanName + " !-> " + hb.boneName);
         }
     }
     Debug.Log("++++");
 }
コード例 #40
0
 static int _CreateHumanDescription(IntPtr L)
 {
     LuaScriptMgr.CheckArgsCount(L, 0);
     HumanDescription obj = new HumanDescription();
     LuaScriptMgr.PushValue(L, obj);
     return 1;
 }
コード例 #41
0
 private extern void INTERNAL_set_humanDescription(ref HumanDescription value);
コード例 #42
0
ファイル: UMAGeneratorBase.cs プロジェクト: RapsFan/UMA
        public static HumanDescription CreateHumanDescription(UMAData umaData, UmaTPose umaTPose)
        {
            var res = new HumanDescription();
            res.armStretch = 0;
            res.feetSpacing = 0;
            res.legStretch = 0;
            res.lowerArmTwist = 0.2f;
            res.lowerLegTwist = 1f;
            res.upperArmTwist = 0.5f;
            res.upperLegTwist = 0.1f;

            var animatedBones = umaData.GetAnimatedBones();
            if (animatedBones.Length > 0)
            {
                List<SkeletonBone> animatedSkeleton = new List<SkeletonBone>(umaTPose.boneInfo);

                foreach (var animatedBoneHash in animatedBones)
                {
                    var animatedBone = umaData.GetBoneGameObject(animatedBoneHash).transform;

                    var sb = new SkeletonBone();
                    sb.name = animatedBone.name;
                    sb.position = animatedBone.localPosition;
                    sb.rotation = animatedBone.localRotation;
                    sb.scale = animatedBone.localScale;
                    animatedSkeleton.Add(sb);
                }
                res.skeleton = animatedSkeleton.ToArray();
            }
            else
            {
                res.skeleton = umaTPose.boneInfo;
            }

            //			List<HumanBone> animatedHuman = new List<HumanBone>();
            //			foreach (HumanBone bone in umaTPose.humanInfo) {
            //				int animIndex = System.Array.IndexOf(umaData.animatedBones, bone.boneName);
            //				if (animIndex > -1) {
            //					animatedHuman.Add(bone);
            //				}
            //				else {
            //					int traitIndex = System.Array.IndexOf(HumanTrait.BoneName, bone.humanName);
            //					if (HumanTrait.RequiredBone(traitIndex)) {
            //						animatedHuman.Add(bone);
            //					}
            //				}
            //			}
            //			List<SkeletonBone> animatedSkeleton = new List<SkeletonBone>();
            //			foreach (SkeletonBone bone in umaTPose.boneInfo) {
            //				int animIndex = System.Array.IndexOf(umaData.animatedBones, bone.name);
            //				if (animIndex > -1) {
            //					animatedSkeleton.Add(bone);
            //				}
            //			}
            //			res.human = animatedHuman.ToArray();
            //			res.skeleton = animatedSkeleton.ToArray();
            res.human = umaTPose.humanInfo;

            res.skeleton[0].name = umaData.umaRoot.name;
            SkeletonModifier(umaData, ref res.skeleton);
            return res;
        }