コード例 #1
0
        public List <SkeletonBone> GetSkeletonBones()
        {
            List <SkeletonBone> skeletonBones = new List <SkeletonBone>();

            SkeletonBone rootBone = new SkeletonBone();

            rootBone.name     = _Root.name;
            rootBone.position = _Root.localPosition;
            rootBone.rotation = _Root.localRotation;
            rootBone.scale    = _Root.localScale;

            skeletonBones.Add(rootBone);

            foreach (var boneTransform in _Skeleton.Values)
            {
                SkeletonBone skeletonBone = new SkeletonBone();
                skeletonBone.name     = boneTransform.name;
                skeletonBone.position = boneTransform.localPosition;
                skeletonBone.rotation = boneTransform.localRotation;
                skeletonBone.scale    = boneTransform.localScale;

                skeletonBones.Add(skeletonBone);
            }

            return(skeletonBones);
        }
コード例 #2
0
        public virtual JObject SerializeAvatar(GameObject parentGO, Animator animator)
        {
            JObject serializedAvatar = new JObject();

            serializedAvatar["avatarName"]   = animator.avatar.name;
            serializedAvatar["sharedAvatar"] = false;
            serializedAvatar["rootBone"]     = parentGO.name;

            List <AvatarBoneTransform> boneTransforms = new List <AvatarBoneTransform>();

            Transform searchChain = FindTransformInHierarchy(this.filter, parentGO.transform);

            //Add main root parent
            boneTransforms.Add(new AvatarBoneTransform(searchChain.parent));

            GetTransformHierarchy(searchChain, boneTransforms);

            JArray serializedBoneMappings = new JArray();
            int    humanBones             = 0;
            int    skeletonBones          = 0;

            foreach (AvatarBoneTransform bone in boneTransforms)
            {
                string name = bone.GetName();

                if (this.mapping.ContainsKey(name))
                {
                    HumanBone humanBone = new HumanBone();
                    humanBone.boneName  = name;
                    humanBone.humanName = this.mapping[name];
                    humanBone.limit.useDefaultValues = true;

                    bone.SetHumanBone(humanBone);
                    humanBones++;
                }
                else
                {
                    Debug.Log("No human bone mapping for: " + name);
                }

                SkeletonBone skeletonBone = new SkeletonBone();
                skeletonBone.name     = name;
                skeletonBone.rotation = bone.GetRotation();
                skeletonBone.position = bone.GetPosition();
                skeletonBone.scale    = bone.GetScale();

                bone.SetSkeletonBone(skeletonBone);
                skeletonBones++;

                //Serialize each mapped avatar bone to JSON so we can recreate avatar at runtime.
                serializedBoneMappings.Add(bone.Serialize());
            }

            Debug.Log("Mapped: " + humanBones + " Human bones");
            Debug.Log("Indexed: " + skeletonBones + " Skeleton bones");

            serializedAvatar["mappedBones"] = serializedBoneMappings;

            return(serializedAvatar);
        }
コード例 #3
0
        protected override SkeletonLayer Deserialize(BinaryDataReader reader)
        {
            var bones = new List <SkeletonBone>();

            while (reader.HasRemaining)
            {
                var bone = new SkeletonBone();
                bone.Name     = reader.ReadCString();
                bone.Position = new float[3];
                for (int i = 0; i < 3; i++)
                {
                    bone.Position[i] = (float)reader.ReadFloat40();
                }
                bone.RotationAxis = new float[3];
                for (int i = 0; i < 3; i++)
                {
                    bone.RotationAxis[i] = (float)reader.ReadFloat40();
                }
                bone.RotationAngle = (float)reader.ReadFloat40();
                bone.Parent        = reader.ReadCString();
                bones.Add(bone);
            }
            return(new SkeletonLayer {
                Bones = bones.ToArray()
            });
        }
コード例 #4
0
    /// <summary>
    /// MMD用スケルトンボーン作成
    /// </summary>
    /// <returns>スケルトンボーン</returns>
    SkeletonBone[] CreateSkeletonBone()
    {
        IEnumerable <GameObject> bones_enumerator = bones_;

        //Hipsボーンの親ボーン迄SkeletonBoneに入れる必要が有るので、確認と追加
        string    hips_bone_name   = ((HasBone("腰"))? "腰": "センター");
        Transform hips_parent_bone = bones_.Where(x => x.name == hips_bone_name).Select(x => x.transform.parent).FirstOrDefault();

        if (null != hips_parent_bone)
        {
            //Hipsボーンの親ボーンが有るなら
            //Hipsボーンの親ボーンがbones_に含まれているか確認する
            if (!HasBone(hips_parent_bone.name))
            {
                //Hipsボーンの親ボーンがbones_に無いなら
                //追加(Hipsボーン依りも前に追加しないといけないので注意)
                bones_enumerator = Enumerable.Repeat(hips_parent_bone.gameObject, 1)
                                   .Concat(bones_enumerator);
            }
        }

        var result = bones_enumerator.Select(x => {
            SkeletonBone skeleton_bone = new SkeletonBone();
            skeleton_bone.name         = x.name;
            Transform transform        = x.transform;
            skeleton_bone.position     = transform.localPosition;
            skeleton_bone.rotation     = transform.localRotation;
            skeleton_bone.scale        = transform.localScale;
            return(skeleton_bone);
        });

        return(result.ToArray());
    }
コード例 #5
0
ファイル: UmaTPose.cs プロジェクト: hafewa/UMA-1
 private void Serialize(BinaryWriter bn, SkeletonBone bone)
 {
     bn.Write(bone.name);
     Serialize(bn, bone.position);
     Serialize(bn, bone.rotation);
     Serialize(bn, bone.scale);
     bn.Write(bone.transformModified);
 }
コード例 #6
0
    static int _CreateSkeletonBone(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 0);
        SkeletonBone obj = new SkeletonBone();

        LuaScriptMgr.PushValue(L, obj);
        return(1);
    }
コード例 #7
0
 private void Serialize(BinaryWriter bn, SkeletonBone bone)
 {
     bn.Write(bone.name);
     Serialize(bn, bone.position);
     Serialize(bn, bone.rotation);
     Serialize(bn, bone.scale);
     bn.Write((int)1);
 }
コード例 #8
0
ファイル: Core_File.cs プロジェクト: Liance/justbreathe
        private static Transform LookForHumanBone(Transform tf, string name, System.Action <Transform, HumanBone, SkeletonBone> next = null, bool forceNext = false)
        {
            Transform result = null;
            int       len    = tf.childCount;

            for (int i = 0; i < len; i++)
            {
                var t = tf.GetChild(i);
                if (t.name == name)
                {
                    result = t;
                    break;
                }
            }
            if (!result)
            {
                for (int i = 0; i < len; i++)
                {
                    var t   = tf.GetChild(i);
                    var res = LookForHumanBone(t, name);
                    if (res)
                    {
                        result = res;
                        break;
                    }
                }
            }
            if (next != null && (result || forceNext))
            {
                if (result)
                {
                    var hBone = new HumanBone()
                    {
                        humanName = name,
                        boneName  = name,
                        limit     = new HumanLimit()
                        {
                            useDefaultValues = true,
                        },
                    };
                    var kBone = new SkeletonBone()
                    {
                        name     = name,
                        position = result.localPosition,
                        rotation = result.localRotation,
                        scale    = result.localScale,
                    };
                    next(result, hBone, kBone);
                }
                else
                {
                    next(null, default(HumanBone), default(SkeletonBone));
                }
            }
            return(result);
        }
コード例 #9
0
        /// <summary>
        /// Builds a SkeletonBone.
        /// </summary>
        /// <returns>The built skeleton bone.</returns>
        /// <param name="boneTransform">The bone Transform to build the Skeleton from.</param>
        private static SkeletonBone CreateSkeletonBone(Transform boneTransform)
        {
            var skeletonBone = new SkeletonBone();

            skeletonBone.name     = boneTransform.name;
            skeletonBone.position = boneTransform.localPosition;
            skeletonBone.rotation = boneTransform.localRotation;
            skeletonBone.scale    = boneTransform.localScale;
            return(skeletonBone);
        }
        protected override void ReadFromImpl(object obj)
        {
            base.ReadFromImpl(obj);
            SkeletonBone uo = (SkeletonBone)obj;

            name     = uo.name;
            position = uo.position;
            rotation = uo.rotation;
            scale    = uo.scale;
        }
コード例 #11
0
    ////////////////////////////////////

    private void AddSkeletonBone(Transform t, List <SkeletonBone> skeletonBones)
    {
        SkeletonBone bone = new SkeletonBone();

        bone.name     = t.name;
        bone.position = t.localPosition;
        bone.rotation = t.localRotation;
        bone.scale    = t.localScale;
        skeletonBones.Add(bone);
    }
コード例 #12
0
        static SkeletonBone ToSkeletonBone(Transform t)
        {
            var sb = new SkeletonBone();

            sb.name     = t.name;
            sb.position = t.localPosition;
            sb.rotation = t.localRotation;
            sb.scale    = t.localScale;
            return(sb);
        }
コード例 #13
0
    private static HumanDescription ReadHumanDescription()
    {
        HumanDescription humanDescription = new HumanDescription();
        List <HumanBone> humanBones       = new List <HumanBone>();

        HumanTemplate template = Resources.Load(humanTemplateFile) as HumanTemplate;

        string[] boneNames = HumanTrait.BoneName;

        //List<string> mapping = new List<string>();
        foreach (string boneName in boneNames)
        {
            HumanBone newBone = new HumanBone();
            newBone.humanName = boneName;
            newBone.boneName  = template.Find(boneName);

            if (newBone.boneName != "")
            {
                HumanLimit limit = new HumanLimit();
                limit.useDefaultValues = true;
                newBone.limit          = limit;
                humanBones.Add(newBone);
            }
        }

        humanDescription.human             = humanBones.ToArray();
        humanDescription.upperArmTwist     = 0.5f;
        humanDescription.lowerArmTwist     = 0.5f;
        humanDescription.upperLegTwist     = 0.5f;
        humanDescription.lowerLegTwist     = 0.5f;
        humanDescription.armStretch        = 0.05f;
        humanDescription.legStretch        = 0.05f;
        humanDescription.feetSpacing       = 0.0f;
        humanDescription.hasTranslationDoF = true;

        //if (secondPass && _isAnimation)
        {
            //skeletonDescription = modelImporter.humanDescription.skeleton;
            List <SkeletonBone> skeletonBones = new List <SkeletonBone>();
            for (int i = 0; i < skeletonDescription.Length; i++)
            {
                SkeletonBone newSkeletonBone = new SkeletonBone();
                newSkeletonBone.name     = skeletonDescription[i].name;
                newSkeletonBone.position = skeletonDescription[i].position;
                newSkeletonBone.rotation = skeletonDescription[i].rotation;
                newSkeletonBone.scale    = skeletonDescription[i].scale;
                //newSkeletonBone.transformModified = skeletonDescription[i].transformModified;

                skeletonBones.Add(newSkeletonBone);
            }

            humanDescription.skeleton = skeletonBones.ToArray();
        }
        return(humanDescription);
    }
コード例 #14
0
        private SkeletonBone DeSerializeSkeletonBone(BinaryReader br)
        {
            var res = new SkeletonBone();

            res.name     = br.ReadString();
            res.position = DeserializeVector3(br);
            res.rotation = DeSerializeQuaternion(br);
            res.scale    = DeserializeVector3(br);
            br.ReadInt32();
            return(res);
        }
        protected override object WriteToImpl(object obj)
        {
            obj = base.WriteToImpl(obj);
            SkeletonBone uo = (SkeletonBone)obj;

            uo.name     = name;
            uo.position = position;
            uo.rotation = rotation;
            uo.scale    = scale;
            return(uo);
        }
コード例 #16
0
 /// <summary>
 /// MMD用スケルトンボーン作成
 /// </summary>
 /// <returns>スケルトンボーン</returns>
 SkeletonBone[] CreateSkeletonBone()
 {
     return(bones_.Select(x => {
         SkeletonBone skeleton_bone = new SkeletonBone();
         skeleton_bone.name = x.name;
         Transform transform = x.transform;
         skeleton_bone.position = transform.localPosition;
         skeleton_bone.rotation = transform.localRotation;
         skeleton_bone.scale = transform.localScale;
         return skeleton_bone;
     }).ToArray());
 }
コード例 #17
0
    //private void PrepareSkeletonDescription(ModelImporter modelImporter)
    //{
    //    skeletonDescription = modelImporter.humanDescription.skeleton;
    //    List<SkeletonBone> tempSkeletonBoneList = skeletonDescription.ToList();

    //    //string refereneAvatarId = _referenceAvatarName.Split('@')[0];
    //    //for (int i = 0; i < tempSkeletonBoneList.Count; i++)
    //    //{
    //    //    if (!tempSkeletonBoneList[i].name.Contains(refereneAvatarId))
    //    //    {
    //    //        tempSkeletonBoneList.RemoveAt(i);
    //    //    }
    //    //}
    //    skeletonDescription = tempSkeletonBoneList.ToArray();
    //    Debug.Log(skeletonDescription);
    //}

    private void AddSkeletonBone(Transform t, List <SkeletonBone> skeletonBones)
    {
        SkeletonBone bone = new SkeletonBone();

        bone.name     = t.name;
        bone.position = t.localPosition;
        bone.rotation = t.localRotation;
        bone.scale    = t.localScale;
        skeletonBones.Add(bone);

        //AnimationUtility.SetAdditiveReferencePose
    }
コード例 #18
0
    public static int constructor(IntPtr l)
    {
        int result;

        try
        {
            SkeletonBone skeletonBone = default(SkeletonBone);
            LuaObject.pushValue(l, true);
            LuaObject.pushValue(l, skeletonBone);
            result = 2;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
コード例 #19
0
ファイル: UMAGeneratorBase.cs プロジェクト: Kinyajuu/UMA
        private static void SkeletonModifier(UMAData umaData, ref SkeletonBone[] bones)
        {
            Dictionary <Transform, Transform> animatedBones = new Dictionary <Transform, Transform>();

            for (var i = 0; i < umaData.animatedBones.Length; i++)
            {
                animatedBones.Add(umaData.animatedBones[i], umaData.animatedBones[i]);
            }

            for (var i = 0; i < bones.Length; i++)
            {
                var skeletonbone = bones[i];
                UMAData.BoneData entry;
                if (umaData.boneHashList.TryGetValue(UMASkeleton.StringToHash(skeletonbone.name), out entry))
                {
                    //var entry = umaData.boneList[skeletonbone.name];
                    skeletonbone.position = entry.boneTransform.localPosition;
                    //skeletonbone.rotation = entry.boneTransform.localRotation;
                    skeletonbone.scale = entry.boneTransform.localScale;
                    bones[i]           = skeletonbone;
                    animatedBones.Remove(entry.boneTransform);
                }
            }
            if (animatedBones.Count > 0)
            {
                var newBones = new List <SkeletonBone>(bones);
                // iterate original list rather than dictionary to ensure that relative order is preserved
                for (var i = 0; i < umaData.animatedBones.Length; i++)
                {
                    var animatedBone = umaData.animatedBones[i];
                    if (animatedBones.ContainsKey(animatedBone))
                    {
                        var newBone = new SkeletonBone();
                        newBone.name     = animatedBone.name;
                        newBone.position = animatedBone.localPosition;
                        newBone.rotation = animatedBone.localRotation;
                        newBone.scale    = animatedBone.localScale;
                        newBones.Add(newBone);
                    }
                }
                bones = newBones.ToArray();
            }
        }
コード例 #20
0
        //Create a SkeletonBone array out of an Avatar GameObject
        //This assumes that the Avatar as supplied is in a T-Pose
        //The local positions of its bones/joints are used to define this T-Pose
        private static SkeletonBone[] CreateSkeleton(GameObject avatarRoot)
        {
            List <SkeletonBone> skeleton = new List <SkeletonBone>();

            Transform[] avatarTransforms = avatarRoot.GetComponentsInChildren <Transform>();
            foreach (Transform avatarTransform in avatarTransforms)
            {
                SkeletonBone bone = new SkeletonBone()
                {
                    name     = avatarTransform.name,
                    position = avatarTransform.localPosition,
                    rotation = avatarTransform.localRotation,
                    scale    = avatarTransform.localScale
                };

                skeleton.Add(bone);
            }
            return(skeleton.ToArray());
        }
コード例 #21
0
    public static Avatar Build(List <string> boneNames, List <Transform> matchingBones, GameObject topObject)
    {
        HumanBone[]      humanBones = new HumanBone[boneNames.Count];
        List <Transform> bones      = new List <Transform>();

        for (int i = 0; i < boneNames.Count; i++)
        {
            if (matchingBones[i] == null)
            {
                continue;
            }
            humanBones[i]           = new HumanBone();
            humanBones[i].boneName  = matchingBones[i].name;
            humanBones[i].humanName = boneNames[i];
            humanBones[i].limit.useDefaultValues = true;
            AddParentRecursive(bones, matchingBones[i], topObject.transform);
        }

        HumanDescription hd = new HumanDescription();

        hd.human = humanBones;
        SkinnedMeshRenderer smr = topObject.GetComponentInChildren <SkinnedMeshRenderer>();

        //Transform[] bones=new Transform[smr.bones.Length+1];
        //System.Array.Copy(smr.bones,bones,smr.bones.Length);
        //bones[smr.bones.Length]=smr.bones[0].parent;



        SkeletonBone[] skeleton = new SkeletonBone[bones.Count];
        for (int i = 0; i < bones.Count; i++)
        {
            skeleton[i]          = new SkeletonBone();
            skeleton[i].name     = bones[i].name;
            skeleton[i].position = bones[i].localPosition;
            skeleton[i].rotation = bones[i].localRotation;
            skeleton[i].scale    = bones[i].localScale;
        }
        hd.skeleton = skeleton;
        Avatar avatar = AvatarBuilder.BuildHumanAvatar(topObject, hd);

        return(avatar);
    }
コード例 #22
0
ファイル: Skeletor.cs プロジェクト: unbit/aiv-assets
    private void AddBone(string name, Transform t)
    {
        HumanBone bone = new HumanBone();

        bone.humanName = name;
        bone.boneName  = t.name;
        bone.limit     = new HumanLimit();
        bone.limit.useDefaultValues = true;

        bones.Add(bone);

        SkeletonBone sbone = new SkeletonBone();

        sbone.name = t.name;

        sbone.position = t.localPosition;
        sbone.rotation = t.localRotation;
        sbone.scale    = t.localScale;

        sbones.Add(sbone);
    }
コード例 #23
0
        private List <SkeletonBone> GetTransforms(Transform t)
        {
            SkeletonBone skeletonBone = new SkeletonBone()
            {
                name     = t.name,
                position = t.localPosition,
                rotation = t.localRotation,
                scale    = t.localScale
            };

            List <SkeletonBone> singleParentFamily = new List <SkeletonBone>()
            {
                skeletonBone
            };

            foreach (Transform childT in t)
            {
                singleParentFamily.AddRange(GetTransforms(childT));
            }

            return(singleParentFamily);
        }
コード例 #24
0
    static int get_rotation(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        if (o == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name rotation");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index rotation on a nil value");
            }
        }

        SkeletonBone obj = (SkeletonBone)o;

        LuaScriptMgr.PushValue(L, obj.rotation);
        return(1);
    }
コード例 #25
0
    static int get_transformModified(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        if (o == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name transformModified");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index transformModified on a nil value");
            }
        }

        SkeletonBone obj = (SkeletonBone)o;

        LuaScriptMgr.Push(L, obj.transformModified);
        return(1);
    }
コード例 #26
0
        public HumanDescription ToHumanDescription(Transform root)
        {
            var transforms    = root.GetComponentsInChildren <Transform>();
            var skeletonBones = new SkeletonBone[transforms.Length];
            var index         = 0;

            foreach (var t in transforms)
            {
                skeletonBones[index] = t.ToSkeletonBone();
                index++;
            }

            var humanBones = new HumanBone[human.Length];

            index = 0;
            foreach (var bonelimit in human)
            {
                humanBones[index] = bonelimit.ToHumanBone();
                index++;
            }


            return(new HumanDescription
            {
                skeleton = skeletonBones,
                human = humanBones,
                armStretch = armStretch,
                legStretch = legStretch,
                upperArmTwist = upperArmTwist,
                lowerArmTwist = lowerArmTwist,
                upperLegTwist = upperLegTwist,
                lowerLegTwist = lowerLegTwist,
                feetSpacing = feetSpacing,
                hasTranslationDoF = hasTranslationDoF,
            });
        }
コード例 #27
0
    static int set_scale(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        if (o == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name scale");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index scale on a nil value");
            }
        }

        SkeletonBone obj = (SkeletonBone)o;

        obj.scale = LuaScriptMgr.GetNetObject <Vector3>(L, 3);
        LuaScriptMgr.SetValueObject(L, 1, obj);
        return(0);
    }
コード例 #28
0
        SkeletonBone[] GetSkeletonBones()
        {
            var skeletonBones = new SkeletonBone[_bones.Count];
            var rotationMap   = GetTPoseRotationMap();

            for (var x = 0; x < _bones.Count; x++)
            {
                var go       = _bones[x];
                var boneType = Naming.BoneDictionary.ContainsKey(go.name)
                    ? Naming.BoneDictionary[go.name]
                    : Naming.BoneType.Generic;

                skeletonBones[x] = new SkeletonBone()
                {
                    name     = go.name,
                    position = go.transform.localPosition,
                    rotation = rotationMap.ContainsKey(boneType)
                        ? rotationMap[boneType]
                        : go.transform.localRotation,
                    scale = go.transform.localScale
                };
            }
            return(skeletonBones);
        }
コード例 #29
0
    // Attempts to remap a mecanim rig so that the upper chest bone
    // is blank, by moving the upper chest bone to chest and rebuilding
    // CURRENTLY DOES NOT WORK!
    void UpperChestFix(VRCSDK2.VRC_AvatarDescriptor ad, GameObject avObj, Animator anim)
    {
        // if upper chest was mapped we need to reconfigure rig
        // by moving upper chest to chest
        Transform pelvis     = anim.GetBoneTransform(HumanBodyBones.Hips);
        Transform upchest    = anim.GetBoneTransform(HumanBodyBones.UpperChest);
        Transform chest      = anim.GetBoneTransform(HumanBodyBones.Chest);
        Transform torso      = anim.GetBoneTransform(HumanBodyBones.Spine);
        Avatar    origAvatar = anim.avatar;

        if (upchest != null)
        {
            // get every child transform of the animator
            Transform[] allBones = anim.GetComponentsInChildren <Transform>();

            // get a list of the extra spine bones between spine and pelvis
            List <Transform> extras = FindBonesBetween(torso, pelvis);

            HumanDescription desc = new HumanDescription();
            desc.upperArmTwist = 0.5f;
            desc.lowerArmTwist = 0.5f;
            desc.upperLegTwist = 0.5f;
            desc.lowerLegTwist = 0.5f;
            desc.armStretch    = 0.05f;
            desc.legStretch    = 0.05f;
            desc.feetSpacing   = 0.0f;
            List <HumanBone>               hbList   = new List <HumanBone>();
            List <SkeletonBone>            sbList   = new List <SkeletonBone>();
            HumanBodyBones[]               hbbArray = (HumanBodyBones[])System.Enum.GetValues(typeof(HumanBodyBones));
            Dictionary <Transform, string> hbbDict  = new Dictionary <Transform, string>();

            for (int i = 0; i < hbbArray.Length; i++)
            {
                Transform t = anim.GetBoneTransform(hbbArray[i]);
                string    n = hbbArray[i].ToString();
                if (t != null && n != "LastBone")
                {
                    hbbDict[t] = n;
                    //Debug.LogError("Dictionary Added:"+hbbArray[i].ToString());
                }
            }

            foreach (Transform bt in allBones)
            {
                // map the human bones
                if (hbbDict.Keys.Contains(bt))
                {
                    string hbName = hbbDict[bt];
                    //Debug.LogError("Processing: "+hbName);
                    if (hbName != "Spine" && bt != null && !extras.Contains(bt))
                    {
                        if (bt == upchest)
                        {
                            hbName = "Chest";
                        }
                        else if (bt == chest)
                        {
                            hbName = "Spine";
                        }
                        HumanBone hb = new HumanBone();
                        hb.boneName  = bt.name;
                        hb.humanName = hbName;
                        //Debug.Log("Mapped human bone:" + hb.humanName + " to " + hb.boneName);
                        hbList.Add(hb);
                    }
                    else
                    {
                        //Debug.LogError("Skipped:" + hbbDict[bt]);
                    }
                }

                if (bt != null)
                {
                    // THESE POSITIONS/ROTATIONS MUST BE FOR TPOSE !!!
                    SkeletonBone sb = new SkeletonBone();
                    sb.name     = bt.name;
                    sb.position = bt.position;
                    sb.rotation = bt.rotation;
                    sb.scale    = bt.localScale;
                    sbList.Add(sb);
                }
            }

            // add any root bones above hip
            Transform root = pelvis.parent;
            while (root != null && root != anim.transform)
            {
                // THESE POSITIONS/ROTATIONS MUST BE FOR TPOSE !!!
                SkeletonBone sb = new SkeletonBone();
                sb.name     = root.name;
                sb.position = root.position;
                sb.rotation = root.rotation;
                sb.scale    = root.localScale;
                sbList.Add(sb);
                root = root.parent;
            }

            desc.human    = hbList.ToArray();
            desc.skeleton = sbList.ToArray();
            anim.avatar   = AvatarBuilder.BuildHumanAvatar(avObj, desc);
            if (anim.avatar.isValid && anim.avatar.isHuman)
            {
                anim.avatar.name = "{ADJUSTED}" + origAvatar.name;
                // shift all the bone mappings
                torso   = chest;
                chest   = upchest;
                upchest = null;
            }
            else
            {
                OnGUIError(ad, "Automatic rig adjustment on " + origAvatar.name + " failed. You will need to manually configure the humanoid rig. Make sure the UpperChest slot is empty.");
                anim.avatar = origAvatar;
                return;
            }
        }

        if (anim.avatar.name.StartsWith("{ADJUSTED}"))
        {
            OnGUIWarning(ad, "Your rig has the UPPERCHEST mapped in the Humanoid Rig, and was automatically corrected " +
                         "to use the CHEST instead. If you run into issues we recommend leaving the " +
                         "UPPERCHEST blank and mapping your top spine bone to the CHEST.");
        }
    }
コード例 #30
0
#pragma warning disable 618
        private void ModifySkeletonBone(ref SkeletonBone bone, Transform trans)
        {
            bone.position = trans.localPosition;
            bone.rotation = trans.localRotation;
            bone.scale    = trans.localScale;
        }