コード例 #1
0
 /// <inheritdoc/>
 public override void addDirtyUMA(UMAData umaToAdd)
 {
     if (umaToAdd)
     {
         umaDirtyList.Add(umaToAdd);
         umaToAdd.MoveToList(dirtyUmas);
     }
 }
コード例 #2
0
 // UMAs can have lots of renderers, but this should return the one that we should use when calculating umaData.characterHeight/Radius/Mass- will that always be umaData.GetRenderer(0)?
 private SkinnedMeshRenderer GetBaseRenderer(UMAData umaData, int rendererToGet = 0)
 {
     if (umaData.rendererCount == 0 || umaData.GetRenderer(rendererToGet) == null)
     {
         return(null);
     }
     return(umaData.GetRenderer(rendererToGet));
 }
コード例 #3
0
 public virtual void OnDirtyUpdate()
 {
     if (HandleDirtyUpdate(umaDirtyList[0]))
     {
         umaDirtyList.RemoveAt(0);
         umaData = null;
     }
 }
コード例 #4
0
 public void Prepare(UMAGeneratorBase _umaGenerator, UMAData _umaData, TextureProcessBaseCoroutine textureProcessCoroutine, bool updateMaterialList, int InitialScaleFactor)
 {
     umaGenerator = _umaGenerator;
     umaData      = _umaData;
     this.textureProcessCoroutine = textureProcessCoroutine;
     this.updateMaterialList      = updateMaterialList;
     scaleFactor = InitialScaleFactor;
 }
コード例 #5
0
        /// <summary>
        /// Creates a generic avatar for a UMA character.
        /// </summary>
        /// <returns>The generic avatar.</returns>
        /// <param name="umaData">UMA data.</param>
        public static Avatar CreateGenericAvatar(UMAData umaData)
        {
            Avatar res = AvatarBuilder.BuildGenericAvatar(umaData.gameObject, umaData.umaRecipe.GetRace().genericRootMotionTransformName);

            res.name = umaData.name;
            CreatedAvatars.Add(res.GetInstanceID());
            return(res);
        }
コード例 #6
0
        public void Initialize()
        {
            if (context == null)
            {
                context = UMAContextBase.Instance;
            }

            if (umaData == null)
            {
                umaData = GetComponent <UMAData>();
                if (umaData == null)
                {
                    umaData           = gameObject.AddComponent <UMAData>();
                    umaData.umaRecipe = new UMAData.UMARecipe();                     // TEST JRRM
                    if (umaGenerator != null && !umaGenerator.gameObject.activeInHierarchy)
                    {
                        if (Debug.isDebugBuild)
                        {
                            Debug.LogError("Invalid UMA Generator on Avatar.", gameObject);
                            Debug.LogError("UMA generators must be active scene objects!", umaGenerator.gameObject);
                        }
                        umaGenerator = null;
                    }
                }
            }
            if (umaGenerator != null)
            {
                umaData.umaGenerator = umaGenerator;
            }
            if (CharacterCreated != null)
            {
                umaData.CharacterCreated = CharacterCreated;
            }
            if (CharacterBegun != null)
            {
                umaData.CharacterBegun = CharacterBegun;
            }
            if (CharacterDestroyed != null)
            {
                umaData.CharacterDestroyed = CharacterDestroyed;
            }
            if (CharacterUpdated != null)
            {
                umaData.CharacterUpdated = CharacterUpdated;
            }
            if (CharacterDnaUpdated != null)
            {
                umaData.CharacterDnaUpdated = CharacterDnaUpdated;
            }
            if (AnimatorStateSaved != null)
            {
                umaData.AnimatorStateSaved = AnimatorStateSaved;
            }
            if (AnimatorStateRestored != null)
            {
                umaData.AnimatorStateRestored = AnimatorStateRestored;
            }
        }
コード例 #7
0
        public static Animator CreateAnimator(UMAData umaData, UmaTPose umaTPose, RuntimeAnimatorController controller, bool applyRootMotion, bool animatePhysics, AnimatorCullingMode cullingMode)
        {
            var animator = CreateAnimator(umaData, umaTPose, controller);

            animator.applyRootMotion = applyRootMotion;
            animator.animatePhysics  = animatePhysics;
            animator.cullingMode     = cullingMode;
            return(animator);
        }
コード例 #8
0
        /// <summary>
        /// Apply the DNA information about eye spacing to a skeleton.
        /// </summary>
        /// <param name="umaData">The character data.</param>
        /// <param name="skeleton">Skeleton.</param>
        public static void UpdateTutorialBones(UMAData umaData, UMASkeleton skeleton)
        {
            var umaDna = umaData.GetDna <UMADnaTutorial>();

            float spacing = (umaDna.eyeSpacing - 0.5f) * 0.01f;

            skeleton.SetPositionRelative(UMAUtils.StringToHash("LeftEye"), new Vector3(0f, -spacing, 0f));
            skeleton.SetPositionRelative(UMAUtils.StringToHash("RightEye"), new Vector3(0f, spacing, 0f));
        }
コード例 #9
0
        private UMA.UMAData umaData;                                     // UMAData of the owning UMA


        // Setup the anchor, bones and the pendulum
        public void OnCharacterUpdated(UMA.UMAData dta)
        {
            umaData = dta;
            // Find Anchor Bone
            AnchorBone = SetupAnchorBone(AnchorBoneName);

            // Setup Swing Bones
            SetupSwingBones(SwingBoneNames);
        }
コード例 #10
0
        public void OnDnaApplied(UMAData umaData)
        {
            var locomotion = umaData.GetComponent <Locomotion>();

            if (locomotion == null)
            {
                umaData.gameObject.AddComponent <Locomotion>();
            }
        }
コード例 #11
0
 /// <summary>
 /// Setup data for atlas building.
 /// </summary>
 /// <param name="_umaData">UMA data.</param>
 /// <param name="_umaGenerator">UMA generator.</param>
 public override void Prepare(UMAData _umaData, UMAGeneratorBase _umaGenerator)
 {
     umaData      = _umaData;
     umaGenerator = _umaGenerator;
     if (umaData.atlasResolutionScale <= 0)
     {
         umaData.atlasResolutionScale = 1f;
     }
 }
コード例 #12
0
ファイル: UMAGeneratorBase.cs プロジェクト: imerr/UMA-1
        /// <summary>
        /// Creates a human (biped) avatar for a UMA character.
        /// </summary>
        /// <returns>The human avatar.</returns>
        /// <param name="umaData">UMA data.</param>
        /// <param name="umaTPose">UMA TPose.</param>
        public static Avatar CreateAvatar(UMAData umaData, UmaTPose umaTPose)
        {
            umaTPose.DeSerialize();
            HumanDescription description = CreateHumanDescription(umaData, umaTPose);
            //DebugLogHumanAvatar(umaData.gameObject, description);
            Avatar res = AvatarBuilder.BuildHumanAvatar(umaData.gameObject, description);

            return(res);
        }
コード例 #13
0
        public override void UpdateUMAMesh(bool updatedAtlas, UMAData umaData, string[] textureNameList, int atlasResolution)
        {
            this.umaData         = umaData;
            this.textureNameList = textureNameList;
            this.atlasResolution = atlasResolution;

            combinedMeshList     = new List <SkinnedMeshCombiner.CombineInstance>();
            combinedMaterialList = new List <Material>();

            if (updatedAtlas)
            {
                CombineByShader();
            }
            else
            {
                CombineByMaterial();
            }

            if (umaData.firstBake)
            {
                umaData.myRenderer.sharedMesh = new Mesh();
            }
            else
            {
                umaData.cleanMesh(false);
            }

            var boneMap = new Dictionary <Transform, Transform>();

            SkinnedMeshCombiner.CombineMeshes(umaData.myRenderer, combinedMeshList.ToArray(), boneMap);

            if (updatedAtlas)
            {
                RecalculateUV();
            }

            umaData.umaRecipe.ClearDNAConverters();
            for (int i = 0; i < umaData.umaRecipe.slotDataList.Length; i++)
            {
                SlotData slotData = umaData.umaRecipe.slotDataList[i];
                if (slotData != null)
                {
                    umaData.EnsureBoneData(slotData.umaBoneData, slotData.animatedBones, boneMap);

                    umaData.umaRecipe.AddDNAUpdater(slotData.slotDNA);
                }
            }

            umaData.myRenderer.quality = SkinQuality.Bone4;
            //umaData.myRenderer.useLightProbes = true;
            umaData.myRenderer.sharedMaterials = combinedMaterialList.ToArray();
            //umaData.myRenderer.sharedMesh.RecalculateBounds();
            umaData.myRenderer.sharedMesh.name = "UMAMesh";

            umaData.firstBake = false;
        }
コード例 #14
0
        /// <summary>
        /// Update the avatar of a UMA character.
        /// </summary>
        /// <param name="umaData">UMA data.</param>
        public virtual void UpdateAvatar(UMAData umaData)
        {
            if (umaData)
            {
                if (umaData.animationController != null)
                {
                    var umaTransform = umaData.transform;
                    var oldParent    = umaTransform.parent;
                    var originalRot  = umaTransform.localRotation;
                    var originalPos  = umaTransform.localPosition;
                    var animator     = umaData.animator;

                    umaTransform.SetParent(null, false);
                    umaTransform.localRotation = Quaternion.identity;
                    umaTransform.localPosition = Vector3.zero;

                    if (animator == null)
                    {
                        animator = umaData.gameObject.GetComponent <Animator>();
                        if (animator == null)
                        {
                            animator = umaData.gameObject.AddComponent <Animator>();
                        }
                        SetAvatar(umaData, animator);
                        animator.runtimeAnimatorController = umaData.animationController;
                        umaData.animator = animator;
                    }
                    // the controller is the same so state can be saved and restored
                    else if (animator.runtimeAnimatorController == umaData.animationController)
                    {
                        AnimatorState snapshot = new AnimatorState();
                        snapshot.SaveAnimatorState(animator);
                        Object.Destroy(animator.avatar);
                        SetAvatar(umaData, animator);
                        if (animator.runtimeAnimatorController != null)
                        {
                            snapshot.RestoreAnimatorState(animator);
                        }
                    }
                    // controller is different and needs updating
                    else
                    {
                        SetAvatar(umaData, animator);
                        animator.runtimeAnimatorController = umaData.animationController;
                    }

                    umaTransform.SetParent(oldParent, false);
                    umaTransform.localRotation = originalRot;
                    umaTransform.localPosition = originalPos;
                }
                else
                {
                    Debug.LogWarning("No animation controller supplied.");
                }
            }
        }
コード例 #15
0
        /// <summary>
        /// Update the avatar of a UMA character.
        /// </summary>
        /// <param name="umaData">UMA data.</param>
        public virtual void UpdateAvatar(UMAData umaData)
        {
            if (umaData)
            {
                if (umaData.animationController != null)
                {
                    var umaTransform = umaData.transform;
                    var oldParent    = umaTransform.parent;
                    var originalRot  = umaTransform.localRotation;
                    var originalPos  = umaTransform.localPosition;
                    var animator     = umaData.animator;

                    umaTransform.SetParent(null, false);
                    umaTransform.localRotation = Quaternion.identity;
                    umaTransform.localPosition = Vector3.zero;

                    if (animator == null)
                    {
                        animator = umaData.gameObject.GetComponent <Animator>();
                        if (animator == null)
                        {
                            animator = umaData.gameObject.AddComponent <Animator>();
                        }
                        SetAvatar(umaData, animator);
                        animator.runtimeAnimatorController = umaData.animationController;
                        umaData.animator = animator;

                        umaTransform.SetParent(oldParent, false);
                        umaTransform.localRotation = originalRot;
                        umaTransform.localPosition = originalPos;
                    }
                    else
                    {
                        AnimatorState snapshot = new AnimatorState();
#if UNITY_EDITOR
                        snapshot.FreezeTime = FreezeTime;
#endif
                        snapshot.SaveAnimatorState(animator, umaData);
                        if (!umaData.KeepAvatar || animator.avatar == null)
                        {
                            UMAUtils.DestroyAvatar(animator.avatar);
                            SetAvatar(umaData, animator);
                        }

                        umaTransform.SetParent(oldParent, false);
                        umaTransform.localRotation = originalRot;
                        umaTransform.localPosition = originalPos;

                        if (animator.runtimeAnimatorController != null)
                        {
                            snapshot.RestoreAnimatorState(animator, umaData);
                        }
                    }
                }
            }
        }
コード例 #16
0
ファイル: UMAData.cs プロジェクト: Marwan0/KinectUMAPrototype
         #pragma warning disable 618
 /// <summary>
 /// Shallow copy from another UMAData.
 /// </summary>
 /// <param name="other">Source UMAData.</param>
 public void Assign(UMAData other)
 {
     animator   = other.animator;
     myRenderer = other.myRenderer;
     umaRoot    = other.umaRoot;
     if (animationController == null)
     {
         animationController = other.animationController;
     }
 }
コード例 #17
0
 public virtual void UpdateUMABody(UMAData umaData)
 {
     if (umaData)
     {
         umaData.GotoOriginalPose();
         umaData.skeleton = new UMASkeletonDefault(umaData.myRenderer.rootBone);
         umaData.ApplyDNA();
         UpdateAvatar(umaData);
     }
 }
コード例 #18
0
        /// <summary>
        /// Apply the blendshape modifications according to the given dna (determined by the dnaTypeHash)
        /// </summary>
        /// <param name="umaData"></param>
        /// <param name="skeleton"></param>
        /// <param name="dnaTypeHash"></param>
        public override void ApplyDNA(UMAData umaData, UMASkeleton skeleton, int dnaTypeHash)
        {
            var umaDna           = umaData.GetDna(dnaTypeHash);
            var masterWeightCalc = masterWeight.GetWeight(umaDna);

            for (int i = 0; i < _blendshapeDNAConverters.Count; i++)
            {
                _blendshapeDNAConverters[i].ApplyDNA(umaData, skeleton, umaDna, masterWeightCalc);
            }
        }
コード例 #19
0
 public virtual void UpdateUMABody(UMAData umaData)
 {
     if (umaData)
     {
         umaData.skeleton.ResetAll();
         umaData.ApplyDNA();
         umaData.FireDNAAppliedEvents();
         UpdateAvatar(umaData);
     }
 }
コード例 #20
0
 public override void addDirtyUMA(UMAData umaToAdd)
 {
     if (!gameObject.activeInHierarchy)
     {
         Debug.LogError("Adding Dirty UMA to a Generator that is not an active scene object, UMA generators must be active scene objects!", gameObject);
         Debug.LogError("UMA Data ", umaToAdd.gameObject);
         return;
     }
     base.addDirtyUMA(umaToAdd);
 }
コード例 #21
0
 /// <inheritdoc/>
 public override bool updateProcessing(UMAData umaToCheck)
 {
     if (umaDirtyList.Count > 0)
     {
         if (umaDirtyList[0] == umaToCheck)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #22
0
ファイル: TransposeDK2UMA.cs プロジェクト: aliasn456/Folio
    void myColliderUpdateMethod(UMA.UMAData umaData)
    {
        CapsuleCollider tempCollider = umaData.umaRoot.gameObject.GetComponent("CapsuleCollider") as CapsuleCollider;

        if (tempCollider)
        {
            UMA.UMADnaHumanoid umaDna = umaData.umaRecipe.GetDna <UMA.UMADnaHumanoid>();
            tempCollider.height = (umaDna.height + 0.5f) * 2 + 0.1f;
            tempCollider.center = new Vector3(0, tempCollider.height * 0.5f - 0.04f, 0);
        }
    }
コード例 #23
0
        private UMA.UMAData umaData;                                     // UMAData of the owning UMA


        // Setup the anchor, bones and the pendulum
        public void OnCharacterUpdated(UMA.UMAData dta)
        {
            CollisionMatrixFixer.FixLayers();

            umaData = dta;
            // Find Anchor Bone
            AnchorBone = SetupAnchorBone(AnchorBoneName);

            // Setup Swing Bones
            SetupSwingBones(SwingBoneNames);
        }
コード例 #24
0
        /// <inheritdoc/>
        public override bool updatePending(UMAData umaToCheck)
        {
            if (umaDirtyList.Count < 2)
            {
                return(false);
            }

            int val = umaDirtyList.IndexOf(umaToCheck, 1);

            return(val != -1);
        }
コード例 #25
0
        private void ApplyMorph(float dnaValue, UMAData data, UMASkeleton skeleton, MorphSetDnaAsset.DNAMorphSet morph)
        {
            if (dnaValue >= 0.5001f)
            {
                float morphWeight = (dnaValue - 0.5f) * 2f;
                if (morph.poseOne != null)
                {
                    morph.poseOne.ApplyPose(skeleton, morphWeight);
                }
                if (!String.IsNullOrEmpty(morph.blendShapeOne))
                {
                    data.SetBlendShape(morph.blendShapeOne, morphWeight);
                }

                if (!String.IsNullOrEmpty(morph.blendShapeZero))
                {
                    data.SetBlendShape(morph.blendShapeZero, 0f);
                }

                return;
            }

            if (dnaValue <= 0.4999f)
            {
                float morphWeight = (0.5f - dnaValue) * 2f;
                if (morph.poseZero != null)
                {
                    morph.poseZero.ApplyPose(skeleton, morphWeight);
                }
                if (!String.IsNullOrEmpty(morph.blendShapeZero))
                {
                    data.SetBlendShape(morph.blendShapeZero, morphWeight);
                }

                if (!String.IsNullOrEmpty(morph.blendShapeOne))
                {
                    data.SetBlendShape(morph.blendShapeOne, 0f);
                }

                return;
            }

            //if dnaValue == 0.5f
            if (!String.IsNullOrEmpty(morph.blendShapeOne))
            {
                data.SetBlendShape(morph.blendShapeOne, 0f);
            }

            if (!String.IsNullOrEmpty(morph.blendShapeZero))
            {
                data.SetBlendShape(morph.blendShapeZero, 0f);
            }
        }
コード例 #26
0
 /// <inheritdoc/>
 public override void addDirtyUMA(UMAData umaToAdd)
 {
     if (umaToAdd)
     {
         // guard against duplicates
         if (!updatePending(umaToAdd))
         {
             umaDirtyList.Add(umaToAdd);
             umaToAdd.MoveToList(dirtyUmas);
         }
     }
 }
コード例 #27
0
ファイル: UMAGeneratorBase.cs プロジェクト: Kinyajuu/UMA
        public virtual void UpdateAvatar(UMAData umaData)
        {
            if (umaData)
            {
                AnimationState[] snapshot = null;
                if (umaData.animationController)
                {
                    var animator = umaData.animator;

                    bool animating                  = false;
                    bool applyRootMotion            = false;
                    bool animatePhysics             = false;
                    AnimatorCullingMode cullingMode = AnimatorCullingMode.AlwaysAnimate;

                    if (animator)
                    {
                        animating       = animator.enabled;
                        applyRootMotion = animator.applyRootMotion;
                        animatePhysics  = animator.animatePhysics;
                        cullingMode     = animator.cullingMode;

                        if (umaData.animationController == animator.runtimeAnimatorController)
                        {
                            snapshot = new AnimationState[animator.layerCount];
                            for (int i = 0; i < animator.layerCount; i++)
                            {
                                var state = animator.GetCurrentAnimatorStateInfo(i);
                                snapshot[i].stateHash = state.nameHash;
                                snapshot[i].stateTime = Mathf.Max(0, state.normalizedTime - Time.deltaTime / state.length);
                            }
                        }

                        Object.DestroyImmediate(animator);
                    }
                    var oldParent = umaData.umaRoot.transform.parent;
                    umaData.umaRoot.transform.parent = null;
                    animator         = CreateAnimator(umaData, umaData.umaRecipe.raceData.TPose, umaData.animationController, applyRootMotion, animatePhysics, cullingMode);
                    umaData.animator = animator;
                    umaData.umaRoot.transform.parent = oldParent;
                    if (snapshot != null)
                    {
                        for (int i = 0; i < animator.layerCount; i++)
                        {
                            animator.Play(snapshot[i].stateHash, i, snapshot[i].stateTime);
                        }

                        animator.Update(0);
                        animator.enabled = animating;
                    }
                }
            }
        }
コード例 #28
0
        public void SetUpColorDropdowns()
        {
            UMA.UMAData umaData = Avatar.umaData;
            thisRace = Avatar.activeRace.name;
            var           currentColorDropdowns = colorDropdownPanel.transform.GetComponentsInChildren <CSColorChangerDD>(true);
            List <string> activeColorDropdowns  = new List <string>();

            //foreach (DynamicCharacterAvatar.ColorValue colorType in Avatar.characterColors.Colors)
            //using new colorvaluestuff
            foreach (OverlayColorData colorType in Avatar.characterColors.Colors)
            {
                activeColorDropdowns.Add(colorType.name);
                bool dropdownExists = false;
                foreach (CSColorChangerDD colorDropdown in currentColorDropdowns)
                {
                    if (colorDropdown.colorToChange == colorType.name)
                    {
                        dropdownExists = true;
                        colorDropdown.gameObject.SetActive(true);
                        SetUpColorDropdownValue(colorDropdown, colorType);
                        break;
                    }
                }
                if (!dropdownExists)
                {
                    GameObject thisColorDropdown = Instantiate(colorDropdownPrefab) as GameObject;
                    thisColorDropdown.transform.SetParent(colorDropdownPanel.transform, false);
                    thisColorDropdown.GetComponent <CSColorChangerDD>().customizerScript = this;
                    thisColorDropdown.GetComponent <CSColorChangerDD>().colorToChange    = colorType.name;
                    thisColorDropdown.name = colorType.name + "DropdownHolder";
                    thisColorDropdown.transform.Find("SlotLabel").GetComponent <Text>().text = colorType.name + " Color";
                    thisColorDropdown.GetComponent <DropdownWithColor>().onValueChanged.AddListener(thisColorDropdown.GetComponent <CSColorChangerDD>().ChangeColor);
                    SetUpColorDropdownValue(thisColorDropdown.GetComponent <CSColorChangerDD>(), colorType);
                }
            }
            foreach (CSColorChangerDD colorDropdown in colorDropdownPanel.transform.GetComponentsInChildren <CSColorChangerDD>())
            {
                bool keepOptionActive = false;
                foreach (UMA.OverlayColorData ucd in umaData.umaRecipe.sharedColors)
                {
                    if (colorDropdown.colorToChange == ucd.name)
                    {
                        keepOptionActive = true;
                        break;
                    }
                }
                if (!keepOptionActive)
                {
                    colorDropdown.gameObject.SetActive(false);
                }
            }
        }
コード例 #29
0
 /// <summary>
 /// Setup data for atlas building.
 /// </summary>
 /// <param name="_umaData">UMA data.</param>
 /// <param name="_umaGenerator">UMA generator.</param>
 public override void Prepare(UMAData _umaData, UMAGeneratorBase _umaGenerator)
 {
     umaData      = _umaData;
     umaGenerator = _umaGenerator;
     if (umaGenerator is UMAGenerator)
     {
         fastPath = (umaGenerator as UMAGenerator).fastGeneration;
     }
     if (umaData.atlasResolutionScale <= 0)
     {
         umaData.atlasResolutionScale = 1f;
     }
 }
コード例 #30
0
 public virtual void OnDirtyUpdate()
 {
     if (HandleDirtyUpdate(umaDirtyList[0]))
     {
         umaDirtyList.RemoveAt(0);
         umaData = null;
     }
     else if (fastGeneration && HandleDirtyUpdate(umaDirtyList[0]))
     {
         umaDirtyList.RemoveAt(0);
         umaData = null;
     }
 }