示例#1
0
        void OnUpdate()
        {
            if (haveValidContext)
            {
                if (activeBoneIndex != editBoneIndex)
                {
                    activeBoneIndex = BAD_INDEX;
                    mirrorBoneIndex = BAD_INDEX;
                    if (editBoneIndex != BAD_INDEX)
                    {
                        int boneHash = targetPose.poses[editBoneIndex].hash;
                        context.activeTransform = context.activeUMA.skeleton.GetBoneTransform(boneHash);
                        if (context.activeTransform != null)
                        {
                            activeBoneIndex = editBoneIndex;
                        }

                        if (context.mirrorTransform != null)
                        {
                            int mirrorHash = UMASkeleton.StringToHash(context.mirrorTransform.name);
                            for (int i = 0; i < targetPose.poses.Length; i++)
                            {
                                if (targetPose.poses[i].hash == mirrorHash)
                                {
                                    mirrorBoneIndex = i;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        context.activeTransform = null;
                    }
                }
                if (!dynamicDNAConverterMode)
                {
                    context.activeUMA.skeleton.ResetAll();
                    if (context.startingPose != null)
                    {
                        context.startingPose.ApplyPose(context.activeUMA.skeleton, context.startingPoseWeight);
                    }

                    foreach (IDNAConverter id in context.activeUMA.umaRecipe.raceData.dnaConverterList)
                    {
                        if (id is DynamicDNAConverterController)
                        {
                            DynamicDNAConverterController Dcc  = id as DynamicDNAConverterController;
                            List <DynamicDNAPlugin>       LBpp = Dcc.GetPlugins(typeof(BonePoseDNAConverterPlugin));
                            foreach (DynamicDNAPlugin ddp in LBpp)
                            {
                                BonePoseDNAConverterPlugin bc = ddp as BonePoseDNAConverterPlugin;
                                foreach (BonePoseDNAConverterPlugin.BonePoseDNAConverter converter in bc.poseDNAConverters)
                                {
                                    converter.poseToApply.ApplyPose(context.activeUMA.skeleton, converter.startingPoseWeight);
                                }
                            }
                            Dcc.overallModifiers.UpdateCharacter(context.activeUMA, context.activeUMA.skeleton, false);
                        }
                    }

                    if (haveEditTarget)
                    {
                        targetPose.ApplyPose(context.activeUMA.skeleton, 1f);
                    }
                    else
                    {
                        targetPose.ApplyPose(context.activeUMA.skeleton, previewWeight);
                    }
                }
                else
                {
                    //TODO
                    //how do we deal with poses that are not applied? The user will see the character in its current pose and bone positions for that
                    //which makes no sense
                    //also because this will be hooked up to dna, the dna itself might be causing other changes to happen ('overallScale' for example)
                    //So I think the editor for bonePoseConverters, needs to jump in here and ask the user if they want to apply the dna that makes the pose active?
                    //OR
                    //maybe we create a skeleton how it would be IF the pose was applied to it and the user edits those transforms?
                    //If the pose is applied they will see their character change, if its not it might be clearer that is the case
                }
            }
            if (!Application.isPlaying)
            {
                _livePopupEditor = null;
            }
        }
示例#2
0
        private void CreateBonePoseCallback(UMAData umaData)
        {
            UMA.PoseTools.UMABonePose bonePose = CreatePoseAsset("", bonePoseSaveName);
            //I dont think this should have ever overwritten the existing one

            /*if (selectedConverter.startingPose == null)
             * {
             *      bonePose = CreatePoseAsset("", bonePoseSaveName);
             * }
             * else
             * {
             *      bonePose = selectedConverter.startingPose;
             *      bonePose.poses = new UMABonePose.PoseBone[1];
             * }*/

            UMASkeleton skeletonPreDNA  = tempAvatarPreDNA.GetComponent <UMADynamicAvatar>().umaData.skeleton;
            UMASkeleton skeletonPostDNA = tempAvatarPostDNA.GetComponent <UMADynamicAvatar>().umaData.skeleton;

            Transform transformPreDNA;
            Transform transformPostDNA;
            bool      transformDirty;
            int       parentHash;

            foreach (int boneHash in skeletonPreDNA.BoneHashes)
            {
                skeletonPreDNA.TryGetBoneTransform(boneHash, out transformPreDNA, out transformDirty, out parentHash);
                skeletonPostDNA.TryGetBoneTransform(boneHash, out transformPostDNA, out transformDirty, out parentHash);

                if ((transformPreDNA == null) || (transformPostDNA == null))
                {
                    Debug.LogWarning("Bad bone hash in skeleton: " + boneHash);
                    continue;
                }

                if (!LocalTransformsMatch(transformPreDNA, transformPostDNA))
                {
                    bonePose.AddBone(transformPreDNA, transformPostDNA.localPosition, transformPostDNA.localRotation, transformPostDNA.localScale);
                }
            }

            UMAUtils.DestroySceneObject(tempAvatarPreDNA);
            UMAUtils.DestroySceneObject(tempAvatarPostDNA);


            // This can be very helpful for testing

            /*
             * bonePose.ApplyPose(skeletonPreDNA, 1.0f);
             */

            EditorUtility.SetDirty(bonePose);
            AssetDatabase.SaveAssets();

            if (_applyAndResetOnCreateBP)
            {
                DynamicDNAConverterController converterController = (selectedConverter is DynamicDNAConverterController) ? (selectedConverter as DynamicDNAConverterController) : null;
                DynamicDNAConverterBehaviour  converterBehaviour  = (selectedConverter is DynamicDNAConverterBehaviour) ? (selectedConverter as DynamicDNAConverterBehaviour) : null;
                //UMA2.8+ fixDNAPrefabs Removed the converterBehaviour.ConverterController field, it should be directly assigned to the Races/Slots now
                //if (converterBehaviour.ConverterController != null)
                //	converterController = converterBehaviour.ConverterController;
                if (converterController != null)
                {
                    //find the first BonePoseDNAConverterPlugin and add the pose to it
                    var existingBPCPs = converterController.GetPlugins(typeof(BonePoseDNAConverterPlugin));
                    BonePoseDNAConverterPlugin thisBPCP;
                    if (existingBPCPs.Count > 0)
                    {
                        thisBPCP = existingBPCPs[0] as BonePoseDNAConverterPlugin;
                        //Turn off any other starting poses?
                        for (int i = 0; i < existingBPCPs.Count; i++)
                        {
                            for (int bi = 0; bi < (existingBPCPs[i] as BonePoseDNAConverterPlugin).poseDNAConverters.Count; bi++)
                            {
                                (existingBPCPs[i] as BonePoseDNAConverterPlugin).poseDNAConverters[bi].startingPoseWeight = 0f;
                            }
                        }
                    }
                    else
                    {
                        //if there isn't one create it
                        thisBPCP = converterController.AddPlugin(typeof(BonePoseDNAConverterPlugin)) as BonePoseDNAConverterPlugin;
                    }
                    thisBPCP.poseDNAConverters.Add(new BonePoseDNAConverterPlugin.BonePoseDNAConverter(bonePose, 1f));
                    Debug.Log(bonePose.name + " added as a starting pose to " + thisBPCP.name);
                }
                else if (converterBehaviour != null)
                {
                    // Set this asset as the converters pose asset
                    converterBehaviour.startingPose = bonePose;
                    //make sure its fully applied
                    converterBehaviour.startingPoseWeight = 1f;
                }

                // Reset all the DNA values for target Avatar to default
                UMADnaBase[] targetDNA = activeUMA.umaData.GetAllDna();
                foreach (UMADnaBase dnaEntry in targetDNA)
                {
                    for (int i = 0; i < dnaEntry.Values.Length; i++)
                    {
                        dnaEntry.SetValue(i, 0.5f);
                    }
                }

                // Optionally clear the DNA from the base recipe,
                // since it's now included in the new starting pose
                UMARecipeBase baseRaceRecipe = activeUMA.umaData.umaRecipe.GetRace().baseRaceRecipe;
                if (baseRaceRecipe != null)
                {
                    if (EditorUtility.DisplayDialog("Base Recipe Cleanup", "Starting Pose created. Remove DNA from base recipe of active race? Choose 'RemoveDNA' if your intention is to replace modifications made by a recipes starting DNA values with the created pose.", "Remove DNA", "Keep DNA"))
                    {
                        UMAData.UMARecipe baseRecipeData = new UMAData.UMARecipe();
                        baseRaceRecipe.Load(baseRecipeData, activeUMA.context);
                        baseRecipeData.ClearDna();
                        baseRaceRecipe.Save(baseRecipeData, activeUMA.context);
                    }
                }
            }
        }