private void Start()
        {
            minEyeBlend = eyes[0].GetBlendShapeWeight(TargetToBendShapeIndex("press"));
            var mouthAnimation = new BlendShapeAnimation(fishSkin, 3, 0, maxBlend, 1.7f, Ease.PingPong.Linear);

            mouthAnimation.Play(-1);
        }
        private void CreateAnimation(float toValue)
        {
            float fromValue = skin.GetBlendShapeWeight(BLEND_DILATE_IDX);

            if (currentAnimation != null)
            {
                currentAnimation.Abort();
            }
            currentAnimation = new BlendShapeAnimation(skin, BLEND_DILATE_IDX, fromValue, toValue, dilateDuration, Ease.Cubic.Out);
            currentAnimation.Play();
        }
        private void StartBlend(string target, bool revert = false)
        {
            int   index               = TargetToBendShapeIndex(target);
            float endValue            = revert ? 0f : maxBlend;
            BlendShapeAnimation tween = new BlendShapeAnimation(fishSkin, index, fishSkin.GetBlendShapeWeight(index), endValue, blendTransition);

            tweens["fish-" + index] = tween;
            tween.Play();

            index = TargetToBendShapeIndex("press");
            if (revert)
            {
                endValue = minEyeBlend;
            }
            for (var i = 0; i < eyes.Length; i++)
            {
                tween = new BlendShapeAnimation(eyes[i], index, fishSkin.GetBlendShapeWeight(index), endValue, blendTransition);
                tweens["eye-" + i + "-" + index] = tween;
                tween.Play();
            }
        }
Example #4
0
        protected override void InputClicked(GameObject obj, InputClickedEventData eventData)
        {
            if (Time.time < lastTimeTapped + coolDownTime)
            {
                return;
            }

            lastTimeTapped = Time.time;

            base.InputClicked(obj, eventData);

            switch (obj.name)
            {
            case "Remove":
                // Destroy the target object, Bounding Box, Bounding Box Rig and App Bar
                boundingBox.Target.GetComponent <BoundingBoxRig>().Deactivate();
                Destroy(boundingBox.Target.GetComponent <BoundingBoxRig>());
                Destroy(boundingBox.Target);
                Destroy(gameObject);
                break;

            case "Adjust":
                // Make the bounding box active so users can manipulate it
                State = AppBarStateEnum.Manipulation;
                // Activate BoundingBoxRig
                boundingBox.Target.GetComponent <BoundingBoxRig>().Activate();
                break;

            case "Hide":
                // Make the bounding box inactive and invisible
                State = AppBarStateEnum.Hidden;
                break;

            case "Show":
                State = AppBarStateEnum.Default;
                // Deactivate BoundingBoxRig
                boundingBox.Target.GetComponent <BoundingBoxRig>().Deactivate();
                break;

            case "Done":
                State = AppBarStateEnum.Default;
                // Deactivate BoundingBoxRig
                boundingBox.Target.GetComponent <BoundingBoxRig>().Deactivate();
                break;

            case "TogglePlay":
                State = AppBarStateEnum.Default;
                // Play / Pause Animation of model
                BlendShapeAnimation blendShapeAnimation = boundingBox.Target.GetComponent <BlendShapeAnimation>();
                blendShapeAnimation.TogglePlay();

                // Switch icon to Play <=> Pause
                AppBarButton   toggleButton = buttonParent.GetComponentsInChildren <AppBarButton>().Single(b => b.name == "TogglePlay");
                ButtonTemplate buttonTmpl   = buttons.Single(b => b.Name == "TogglePlay");
                buttonTmpl.Icon = blendShapeAnimation.Playing ? "PauseIcon" : "PlayIcon";
                toggleButton.Initialize(this, buttonTmpl, null);
                break;

            default:
                break;
            }
        }
Example #5
0
    private void LoadLayers()
    {
        layers = new List <ModelLayer>();
        bounds = null;
        int?newBlendShapesCount = null;

        foreach (string bundleObjectName in assetBundle.GetAllAssetNames())
        {
            if (!bundleObjectName.EndsWith(".prefab"))
            {
                continue;
            }                                                        // ignore other objects

            GameObject layerGameObject = assetBundle.LoadAsset <GameObject>(bundleObjectName);
            string     layerDebugName  = "Prefab '" + bundleObjectName + "' layer '" + layerGameObject.name + "'";

            SkinnedMeshRenderer skinnedMesh = layerGameObject.GetComponent <SkinnedMeshRenderer>();
            if (skinnedMesh != null &&
                skinnedMesh.sharedMesh != null &&
                skinnedMesh.sharedMesh.blendShapeCount != 0)
            {
                // Update bounds
                // Note that we use skinnedMesh.bounds, not skinnedMesh.localBounds, because we want to preserve local rotations
                BoundsAdd(ref bounds, skinnedMesh.bounds);

                // check and update newBlendShapesCount
                if (newBlendShapesCount.HasValue && newBlendShapesCount.Value != skinnedMesh.sharedMesh.blendShapeCount)
                {
                    Debug.LogWarning(layerDebugName + " have different number of blend shapes, " +
                                     newBlendShapesCount.Value.ToString() + " versus " +
                                     skinnedMesh.sharedMesh.blendShapeCount.ToString());
                }
                newBlendShapesCount = skinnedMesh.sharedMesh.blendShapeCount;

                // check BlendShapeAnimation
                BlendShapeAnimation animation = layerGameObject.GetComponent <BlendShapeAnimation>();
                if (animation == null)
                {
                    Debug.LogWarning(layerDebugName + " does not contain BlendShapeAnimation component, adding");
                    animation = layerGameObject.AddComponent <BlendShapeAnimation>();
                }

                // check Animator does not exist (we do not animate using Mecanim)
                Animator animator = layerGameObject.GetComponent <Animator>();
                if (animator != null)
                {
                    Debug.LogWarning(layerDebugName + " contains Animator component, removing");
                    UnityEngine.Object.Destroy(animator);
                }
            }
            else
            {
                // Model not animated using BlendShapeAnimation, search for meshes (skinned or not) inside
                var renderers = layerGameObject.GetComponentsInChildren <Renderer>();
                if (renderers.Length == 0)
                {
                    Debug.LogWarning(layerDebugName + " has nothing visible, ignoring");
                    continue;
                }
                foreach (Renderer renderer in renderers)
                {
                    BoundsAdd(ref bounds, renderer.bounds);
                }
            }

            // check ModelLayer existence
            ModelLayer layer = layerGameObject.GetComponent <ModelLayer>();
            if (layer == null)
            {
                layer            = layerGameObject.AddComponent <ModelLayer>();
                layer.Caption    = Path.GetFileNameWithoutExtension(bundleObjectName);
                layer.Simulation = bundleObjectName.Contains("dataflow") || bundleObjectName.Contains("simulation");
                if (layer.Simulation)
                {
                    int simulationsCount = layers.Count(c => c.Simulation);
                    layer.Caption = "Simulation " + (simulationsCount + 1).ToString();
                }
                Debug.LogWarning(layerDebugName + " does not contain ModelLayer component, guessing layer Caption (" +
                                 layer.Caption + ") and simulation (" +
                                 layer.Simulation.ToString() + ")");
            }

            layer.LayerIndex = layers.Count;

            // add to layers list
            layers.Add(layer);
        }

        if (!bounds.HasValue)
        {
            Debug.LogWarning("Empty model, no layers with something visible");
        }
        else
        {
            Debug.Log("Loaded model with bounds " + bounds.ToString());
        }

        if (!newBlendShapesCount.HasValue)
        {
            Debug.LogWarning("Not animated model, no layers with blend shapes");
            blendShapeCount = 0;
        }
        else
        {
            blendShapeCount = newBlendShapesCount.Value;
            Debug.Log("Loaded model with blend shapes " + blendShapeCount.ToString());
        }
    }