コード例 #1
0
        public void Init()
        {
            if (SpineBones.Count == 0)
            {
                if (SpineTransforms.Count > 2)
                {
                    CreateSpineChain(SpineTransforms[0], SpineTransforms[SpineTransforms.Count - 1]);
                    Debug.Log("[SPINE ANIMATOR] Auto Bone Conversion from old version of Spine Animator! Please select your objects with Spine Animator to pre-convert it instead of automatically doing it when game Starts! (" + name + ")");
                }
                else
                {
                    Debug.Log("[SPINE ANIMATOR] could not initialize Spine Animator inside '" + name + "' because there are no bones to animate!");
                    return;
                }
            }

            if (initialized)
            {
                Debug.Log("[Spine Animator] " + name + " is already initialized!"); return;
            }

            if (BaseTransform == null)
            {
                BaseTransform = FindBaseTransform();
            }

            referenceDistance = 0f;
            // Preparing bones
            for (int i = 0; i < SpineBones.Count; i++)
            {
                SpineBones[i].PrepareBone(BaseTransform, SpineBones, i);
                referenceDistance += SpineBones[i].BoneLength;
            }

            referenceDistance /= (float)(SpineBones.Count);

            frontHead = new HeadBone(SpineBones[0].transform);
            frontHead.PrepareBone(BaseTransform, SpineBones, 0);
            backHead = new HeadBone(SpineBones[SpineBones.Count - 1].transform);
            backHead.PrepareBone(BaseTransform, SpineBones, SpineBones.Count - 1);

            // Collision calculations helper list
            CollidersDataToCheck = new List <FImp_ColliderData_Base>();

            // Straightening spine pose to desired positions and rotations on init
            chainReverseFlag = !LastBoneLeading;
            UpdateChainIndexHelperVariables();
            ReposeSpine();
            //SpineMotion();

            initialized = true;
        }
コード例 #2
0
 protected override Validation <string, PairedEyeSight> CreateService(ILoggerFactory loggerFactory)
 {
     return(from skeleton in Skeleton
            .ToValidation("Failed to find the skeleton.")
            from animationManager in AnimationManager
            .ToValidation("Failed to find the animation manager.")
            from horizontalEyesControl in HorizontalEyesControl.TrimToOption()
            .Bind(animationManager.FindSeekableAnimator)
            .ToValidation("Failed to find an animation control for horizontal eyes movement.")
            from verticalEyesControl in VerticalEyesControl.TrimToOption()
            .Bind(animationManager.FindSeekableAnimator)
            .ToValidation("Failed to find an animation control for vertical eyes movement.")
            from rightEye in Markers.Find(m => RightEyeMarker.TrimToOption().Contains(m.Key))
            .ToValidation("Failed to find the right eye marker.")
            from leftEye in Markers.Find(m => LeftEyeMarker.TrimToOption().Contains(m.Key))
            .ToValidation("Failed to find the left eye marker.")
            from headBone in HeadBone.TrimToOption()
            .Map(skeleton.FindBone).Filter(i => i > -1)
            .ToValidation("Failed to find the head bone.")
            from neckBone in NeckBone.TrimToOption()
            .Map(skeleton.FindBone).Filter(i => i > -1)
            .ToValidation("Failed to find the neck bone.")
            from chestBone in ChestBone.TrimToOption()
            .Map(skeleton.FindBone).Filter(i => i > -1)
            .ToValidation("Failed to find the chest bone.")
            select new PairedEyeSight(
                skeleton,
                animationManager,
                horizontalEyesControl,
                verticalEyesControl,
                rightEye,
                leftEye,
                headBone,
                neckBone,
                chestBone,
                new Range <float>(Deg2Rad(MinEyesYaw), Deg2Rad(MaxEyesYaw), TFloat.Inst),
                new Range <float>(Deg2Rad(MinEyesPitch), Deg2Rad(MaxEyesPitch), TFloat.Inst),
                new Range <float>(Deg2Rad(MinHeadYaw), Deg2Rad(MaxHeadYaw), TFloat.Inst),
                new Range <float>(Deg2Rad(MinHeadPitch), Deg2Rad(MaxHeadPitch), TFloat.Inst),
                new Range <float>(Deg2Rad(MinNeckYaw), Deg2Rad(MaxNeckYaw), TFloat.Inst),
                new Range <float>(Deg2Rad(MinNeckPitch), Deg2Rad(MaxNeckPitch), TFloat.Inst),
                this,
                Active,
                loggerFactory));
 }
コード例 #3
0
    //Setup hinges and springs
    void Start()
    {
        leftLegHinge      = LeftLegBone.GetComponent <HingeJoint>();
        leftLegBoneSpring = leftLegHinge.spring;

        rightLegHinge      = RightLegBone.GetComponent <HingeJoint>();
        rightLegBoneSpring = rightLegHinge.spring;

        rightElbowHinge      = RightElbowBone.GetComponent <HingeJoint>();
        rightElbowBoneSpring = rightElbowHinge.spring;

        leftElbowHinge      = LeftElbowBone.GetComponent <HingeJoint>();
        leftElbowBoneSpring = leftElbowHinge.spring;

        chestBoneHinge  = ChestBone.GetComponent <HingeJoint>();
        chestBoneSpring = chestBoneHinge.spring;

        headBoneHinge  = HeadBone.GetComponent <HingeJoint>();
        headBoneSpring = headBoneHinge.spring;
    }
コード例 #4
0
    //rendertexture (photo) is saved. this is also where some grading happens
    void TakePicture()
    {
        if (picIndex >= allPics.Length)
        {
            this.GetComponent <GameManager>().EndPrompt(Constants.OutOfFilmPrompt);
            return;
        }

        //take the photo
        //https://answers.unity.com/questions/22954/how-to-save-a-picture-take-screenshot-from-a-camer.html
        RenderTexture rt = new RenderTexture(cryptoCam.pixelWidth, cryptoCam.pixelHeight, 24);

        cryptoCam.targetTexture = rt;
        Texture2D screenshot = new Texture2D(cryptoCam.pixelWidth, cryptoCam.pixelHeight, TextureFormat.RGB24, true);

        cryptoCam.Render();
        RenderTexture.active = rt;
        screenshot.ReadPixels(new Rect(0, 0, cryptoCam.pixelWidth, cryptoCam.pixelHeight), 0, 0);
        screenshot.Apply();
        cryptoCam.targetTexture = null;
        RenderTexture.active    = null;
        Destroy(rt);

        //create the photo
        Photograph pic = new Photograph();

        pic.pic = screenshot;

        //Display(screenshot);

        //determine who's in the photo
        List <GameObject> subjects = new List <GameObject>();
        GameObject        mainSubject;

        foreach (GameObject cryptid in allCryptids)
        {
            //https://answers.unity.com/questions/8003/how-can-i-know-if-a-gameobject-is-seen-by-a-partic.html
            Renderer renderer = cryptid.GetComponent <Cryptid>().renderer;
            //check if cyrptid position is visible by camera
            if (renderer != null && renderer.isVisible)
            {
                Vector3 viewPos = cryptoCam.WorldToViewportPoint(cryptid.transform.position);
                if ((viewPos.x >= 0) && (viewPos.x <= 1) && (viewPos.y >= 0) && (viewPos.y <= 1) && (viewPos.z > 0))
                {
                    //if x and y are between 1 and 0 ((0,0) is bottom left corner and (1,1) is top riht) and z (distance from camera) is positive then cryptid is in the shot
                    //dont add cryptids that are in frame but not visible
                    if (checkVisibility(cryptid) != 0)
                    {
                        subjects.Add(cryptid);
                    }
                }
            }
        }
        pic.subjectCount = subjects.Count;

        //automatic 0 if no one is in the photo
        if (subjects.Count == 0)
        {
            pic.baseScore   = 0;
            pic.subjectName = "No one";
            //store the pic
            allPics[picIndex] = pic;

            //Display(pic.pic);
            //DisplayScore(0);

            //move up index
            picIndex++;

            if (picIndex >= allPics.Length)
            {
                this.GetComponent <GameManager>().EndPrompt(Constants.OutOfFilmPrompt);
            }

            return;
        }

        //else if(subjects.Count == 1)
        //treatin this as default case to avoid issue of mainsubject being unnasigned
        //{

        //allScores[picIndex] = ScoreSubject(subjects[0]);
        mainSubject     = subjects[0];
        pic.baseScore   = mainSubject.GetComponent <Cryptid>().baseScore;
        pic.subjectName = mainSubject.GetComponent <Cryptid>().cryptidType;

        //}
        //if more than one cryptid is in the photo determine whos the subject
        //factors to consider: closer to camera (viewpos.z), closer to center of frame, more visible
        if (subjects.Count > 1)
        {
            float subjectScore = 1000000f;
            foreach (GameObject cryptid in subjects)
            {
                //viewpos.z represents distance from camera (z=0 is on top of camera)
                //(.5,.5) is the center of the screen: |(x,y)-(.5,.5)| represents distance from center
                Vector3 viewPos = cryptoCam.WorldToViewportPoint(cryptid.transform.position);

                //calculate a "score" for each cryptid based on placement and visibility
                //distance from center should have more "weight" in score than distance from camera which is why its bein multipied
                Vector2 distanceFromCenter = new Vector2(.5f, .5f) - new Vector2(viewPos.x, viewPos.y);
                float   currentScore       = viewPos.z + (100 * distanceFromCenter.magnitude);

                //lowest scorin cryptid becomes the main subject: lower score means less distance from ideal placement
                if (currentScore < subjectScore)
                {
                    mainSubject  = cryptid;
                    subjectScore = currentScore;
                }
            }

            pic.baseScore   = mainSubject.GetComponent <Cryptid>().baseScore;
            pic.subjectName = mainSubject.GetComponent <Cryptid>().cryptidType;
        }

        //once main subject is determined check other score criteria

        //check if facing forward
        Vector3 cryptidForward = mainSubject.transform.forward;

        //if cryptid has a "head bone" (object that represents the head and face) then use the forward of that for a more accurate estimate of which way its facing
        HeadBone cryptidHead = mainSubject.GetComponentInChildren <HeadBone>();

        if (cryptidHead != null)
        {
            cryptidForward = cryptidHead.GetForward();
        }

        //if the cos of the angle between the cameras forward vector and the cryptids forward vector is less than 0,
        //then the vectors are in opposite directions and the cryptid is facing the camera
        if (Vector3.Dot(cryptoCam.transform.forward, cryptidForward) < 0)
        {
            pic.facinForward = true;
        }

        //todo: check for cool animation
        pic.coolPose = mainSubject.GetComponent <Cryptid>().SpecialPose();

        //store distance from center and distance from camera
        Vector3 cameraPos = cryptoCam.WorldToViewportPoint(mainSubject.transform.position);

        //if cryptid has a head bone use that as the center instead
        if (cryptidHead != null)
        {
            cameraPos = cryptoCam.WorldToViewportPoint(cryptidHead.transform.position);
        }

        pic.distanceFromCamera = cameraPos.z;
        Vector2 dfc = new Vector2(.5f, .5f) - new Vector2(cameraPos.x, cameraPos.y);

        pic.distanceFromCenter = dfc.magnitude;

        //store visibility
        pic.visibility = checkVisibility(mainSubject);

        //score the pic
        pic.finalScore = ScorePhoto(pic);

        //store the pic
        allPics[picIndex] = pic;

        //display (debu)
        //Display(pic.pic);
        //ScorePhoto(pic);
        //DisplayScore(ScorePhoto(pic));


        //displaying all elements of score
        //testtxt.text = "Score: " + ScorePhoto(pic);
        //testtxt.text += '\n' + "Cryptids in Pic: " + pic.subjectCount;
        //testtxt.text += '\n' + "Subject: " + pic.subjectName;
        //testtxt.text += '\n' + "Facin forward: " + pic.facinForward;
        //testtxt.text += '\n' + "Visibility: " + pic.visibility;

        //move up index
        picIndex++;

        //check if we're allowed to take any more photos
        if (picIndex >= allPics.Length)
        {
            this.GetComponent <GameManager>().EndPrompt(Constants.OutOfFilmPrompt);
            return;
        }
    }
コード例 #5
0
        //Vector3 firstBoneOff = Vector3.zero;

        public void Init()
        {
            if (SpineBones.Count == 0)
            {
                if (SpineTransforms.Count > 2)
                {
                    CreateSpineChain(SpineTransforms[0], SpineTransforms[SpineTransforms.Count - 1]);
                    Debug.Log("[SPINE ANIMATOR] Auto Bone Conversion from old version of Spine Animator! Please select your objects with Spine Animator to pre-convert it instead of automatically doing it when game Starts! (" + name + ")");
                }
                else
                {
                    Debug.Log("[SPINE ANIMATOR] could not initialize Spine Animator inside '" + name + "' because there are no bones to animate!");
                    return;
                }
            }

            if (initialized)
            {
                Debug.Log("[Spine Animator] " + name + " is already initialized!"); return;
            }

            if (BaseTransform == null)
            {
                BaseTransform = FindBaseTransform();
            }

            // Checking bones for zero-distance ones
            for (int i = 0; i < SpineBones.Count; i++)
            {
                Vector3 childPos;
                if (i == SpineBones.Count - 1)
                {
                    childPos = SpineBones[i - 1].transform.position + (SpineBones[i - 1].transform.position - SpineBones[i].transform.position);
                }
                else
                {
                    childPos = SpineBones[i + 1].transform.position;
                }

                float dist = Vector3.Distance(SpineBones[i].transform.position, childPos);
                if (dist < 0.01f)
                {
                    float refDistance = (SpineBones[SpineBones.Count - 1].transform.position - SpineBones[SpineBones.Count - 2].transform.parent.position).magnitude;

                    Vector3 forw = SpineBones[i].transform.position - BaseTransform.position;
                    Vector3 loc  = BaseTransform.InverseTransformDirection(forw);
                    loc.y = 0f; loc.Normalize();

                    SpineBones[i + 1].DefaultForward = loc;

                    // firstBoneOff
                    SpineBones[i + 1].transform.position = SpineBones[i + 1].transform.position + BaseTransform.TransformDirection(loc) * refDistance * -0.125f;
                }
            }

            referenceDistance = 0f;
            // Preparing bones
            for (int i = 0; i < SpineBones.Count; i++)
            {
                SpineBones[i].PrepareBone(BaseTransform, SpineBones, i);
                referenceDistance += SpineBones[i].BoneLength;
            }

            referenceDistance /= (float)(SpineBones.Count);

            frontHead = new HeadBone(SpineBones[0].transform);
            frontHead.PrepareBone(BaseTransform, SpineBones, 0);
            backHead = new HeadBone(SpineBones[SpineBones.Count - 1].transform);
            backHead.PrepareBone(BaseTransform, SpineBones, SpineBones.Count - 1);

            // Collision calculations helper list
            CollidersDataToCheck = new List <FImp_ColliderData_Base>();

            // Straightening spine pose to desired positions and rotations on init
            chainReverseFlag = !LastBoneLeading;
            UpdateChainIndexHelperVariables();
            ReposeSpine();
            //SpineMotion();

            initialized = true;
        }
コード例 #6
0
    public void SetImportDefault()
    {
        transform.localPosition = Vector3.zero;
        transform.localRotation = Quaternion.identity;
        transform.localScale    = Vector3.one;

        Animation model = Animation;

        if (model.GetComponentsInChildren <SkinnedMeshRenderer>().Length > 1)
        {
            Debug.LogError("SkinnedMesh count error");
        }

        m_AnimationStates = null;
        CheckBones();

        model.transform.localRotation         = rotationCharacter;
        model.GetComponent <Animation>().clip = null;
        model.GetComponent <Animation>().playAutomatically = false;
        model.GetComponent <Animation>().cullingType       = AnimationCullingType.AlwaysAnimate;
        m_DefaultStateName = "battleidle";

        Transform bip_node = FindTransform(model.transform, "Bip");

        AnimationState idle_state = Animation["idle"];

        if (idle_state != null && HeadBone != null)
        {
            idle_state.enabled = true;
            idle_state.time    = 0f;
            idle_state.weight  = 1f;
            Animation.Sample();
            idle_state.enabled = false;

            IdleRotation = 90f - GetRotation(HeadBone.transform, transform).eulerAngles.y;
        }

        AnimationState default_state = Animation[m_DefaultStateName];

        if (default_state != null)
        {
            default_state.enabled = true;
            default_state.time    = 0f;
            default_state.weight  = 1f;
            Animation.Sample();

            default_state.enabled = false;
        }

        {
            BoxCollider temp_col = GetComponent <BoxCollider>();
            if (temp_col != null)
            {
                DestroyImmediate(temp_col, true);
            }

            CapsuleCollider collider = GetComponent <CapsuleCollider>();
            if (collider == null)
            {
                collider        = gameObject.AddComponent <CapsuleCollider>();
                collider.center = new Vector3(0f, 4f, 0f);
                collider.radius = 3f;
                collider.height = 10f;
            }
        }

        if (bip_node != null)
        {
            BoxCollider temp_col = bip_node.GetComponent <BoxCollider>();
            if (temp_col != null)
            {
                DestroyImmediate(temp_col, true);
            }

            SphereCollider collider = bip_node.GetComponent <SphereCollider>();
            if (collider != null)
            {
                DestroyImmediate(collider, true);
            }
        }

        if (HeadBone != null)
        {
            SphereCollider collider = HeadBone.GetComponent <SphereCollider>();
            if (collider == null)
            {
                collider = HeadBone.gameObject.AddComponent <SphereCollider>();
            }
            collider.center = new Vector3(-1.5f, 0f, 0f);
            collider.radius = 3;
        }

        //RootBone.localRotation = Quaternion.Euler(-90f, 180f, 0f);

        CoreUtility.SetRecursiveLayer(gameObject, "Character");

        RefreshMove(true);
        RefreshFx(true);

        string             prefab_path = "Assets/Character/" + gameObject.name + ".prefab";
        CharacterAnimation prefab      = AssetDatabase.LoadAssetAtPath(prefab_path, typeof(CharacterAnimation)) as CharacterAnimation;

        if (prefab == null)
        {
            PrefabUtility.CreatePrefab(prefab_path, gameObject, ReplacePrefabOptions.ConnectToPrefab);
        }
        else
        {
            PrefabUtility.ReplacePrefab(gameObject, prefab, ReplacePrefabOptions.ConnectToPrefab);
        }
    }
コード例 #7
0
        private void ViewBodyMenu(HumanMuscle script)
        {
            GUILayout.BeginHorizontal();
            EditorGUILayout.Space();
            BoneNameButton(HeadBone.GetInstance(), 100);
            EditorGUILayout.Space();
            GUILayout.EndHorizontal();


            GUILayout.BeginHorizontal();
            EditorGUILayout.Space();
            BoneNameButton(ShoulderLeftBone.GetInstance());
            BoneNameButton(NeckBone.GetInstance(), 80);
            BoneNameButton(ShoulderRightBone.GetInstance());
            EditorGUILayout.Space();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            BoneNameButton(UpperArmLeftBone.GetInstance());
            EditorGUILayout.Space();
            BoneNameButton(UpperChestBone.GetInstance(), 100);
            EditorGUILayout.Space();
            BoneNameButton(UpperArmRightBone.GetInstance());
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            BoneNameButton(LowerArmLeftBone.GetInstance());
            EditorGUILayout.Space();
            BoneNameButton(ChestBone.GetInstance(), 100);
            EditorGUILayout.Space();
            BoneNameButton(LowerArmRightBone.GetInstance());
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            BoneNameButton(HandLeftBone.GetInstance(), 100);
            EditorGUILayout.Space();
            BoneNameButton(SpineBone.GetInstance(), 100);
            EditorGUILayout.Space();
            BoneNameButton(HandRightBone.GetInstance(), 100);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            EditorGUILayout.Space();
            BoneNameButton(RootBone.GetInstance(), 100);
            EditorGUILayout.Space();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            EditorGUILayout.Space();
            BoneNameButton(UpperLegLeftBone.GetInstance(), 150);
            BoneNameButton(UpperLegRightBone.GetInstance(), 150);
            EditorGUILayout.Space();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            EditorGUILayout.Space();
            BoneNameButton(LowerLegLeftBone.GetInstance(), 150);
            EditorGUILayout.Space();
            BoneNameButton(LowerLegRightBone.GetInstance(), 150);
            EditorGUILayout.Space();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            BoneNameButton(FootLeftBone.GetInstance(), 150);
            EditorGUILayout.Space();
            BoneNameButton(FootRightBone.GetInstance(), 150);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            BoneNameButton(ToesLeftBone.GetInstance(), 150);
            EditorGUILayout.Space();
            BoneNameButton(ToesRightBone.GetInstance(), 150);
            GUILayout.EndHorizontal();
        }
コード例 #8
0
 void Start()
 {
     headBoneRigidbody = HeadBone.GetComponent <Rigidbody>();
 }