Exemplo n.º 1
0
        public Vrm10Runtime(Vrm10Instance target)
        {
            m_target = target;
            var animator = target.GetComponent <Animator>();

            if (animator == null)
            {
                throw new Exception();
            }

            m_head       = animator.GetBoneTransform(HumanBodyBones.Head);
            m_lookat     = new Vrm10RuntimeLookAt(target.Vrm.LookAt, animator, m_head, target.LookAtTargetType, target.Gaze);
            m_expression = new Vrm10RuntimeExpression(target, m_lookat, m_lookat.EyeDirectionApplicable);

            if (m_constraints == null)
            {
                m_constraints = target.GetComponentsInChildren <IVrm10Constraint>();
            }

            if (!Application.isPlaying)
            {
                // for UnitTest
                return;
            }

            m_fastSpringBoneService = FastSpringBoneService.Instance;
            m_fastSpringBoneBuffer  = CreateFastSpringBoneBuffer(m_target.SpringBone);
            m_fastSpringBoneService.BufferCombiner.Register(m_fastSpringBoneBuffer);
        }
Exemplo n.º 2
0
        static void OnSceneGUILookAt(VRM10ObjectLookAt lookAt, Vrm10RuntimeLookAt runtime, Transform head, VRM10ObjectLookAt.LookAtTargetTypes lookAtTargetType, Transform gaze)
        {
            if (head == null)
            {
                return;
            }

            if (gaze != null)
            {
                {
                    EditorGUI.BeginChangeCheck();
                    var newTargetPosition = Handles.PositionHandle(gaze.position, Quaternion.identity);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(gaze, "Change Look At Target Position");
                        gaze.position = newTargetPosition;
                    }
                }

                Handles.color = new Color(1, 1, 1, 0.6f);
                Handles.DrawDottedLine(runtime.GetLookAtOrigin(head).position, gaze.position, 4.0f);
            }

            var(yaw, pitch) = runtime.GetLookAtYawPitch(head, lookAtTargetType, gaze);
            var lookAtOriginMatrix = runtime.GetLookAtOrigin(head).localToWorldMatrix;

            Handles.matrix = lookAtOriginMatrix;
            var p = lookAt.OffsetFromHead;

            Handles.Label(Vector3.zero,
                          $"FromHead: [{p.x:0.00}, {p.y:0.00}, {p.z:0.00}]\nYaw: {yaw:0.}degree\nPitch: {pitch:0.}degree");

            Handles.color = new Color(0, 1, 0, 0.2f);
            Handles.DrawSolidArc(Vector3.zero,
                                 Matrix4x4.identity.GetColumn(1),
                                 Matrix4x4.identity.GetColumn(2),
                                 yaw,
                                 RADIUS);


            var yawQ      = Quaternion.AngleAxis(yaw, Vector3.up);
            var yawMatrix = default(Matrix4x4);

            yawMatrix.SetTRS(Vector3.zero, yawQ, Vector3.one);

            Handles.matrix = lookAtOriginMatrix * yawMatrix;
            Handles.color  = new Color(1, 0, 0, 0.2f);
            Handles.DrawSolidArc(Vector3.zero,
                                 Matrix4x4.identity.GetColumn(0),
                                 Matrix4x4.identity.GetColumn(2),
                                 -pitch,
                                 RADIUS);
        }