Inheritance: MonoBehaviour
 void OnDestroy()
 {
     if (_instance == this)
     {
         _instance = null;
     }
 }
    public override void OnInspectorGUI()
    {
        SerializedProperty properties = serializedObject.GetIterator();

        bool useEnterChildren = true;

        while (properties.NextVisible(useEnterChildren) == true)
        {
            useEnterChildren = false;
            if (AdvancedMode._advancedModeEnabled || BasicModePropertyNames.Contains(properties.name))
            {
                EditorGUILayout.PropertyField(properties, true);
            }
        }

        SerializedProperty eyeProperty = serializedObject.FindProperty("retrievedEye");

        if (eyeProperty.enumValueIndex == -1)
        {
            LeapImageRetriever retrieverScript = target as LeapImageRetriever;
            bool containsLeft = retrieverScript.gameObject.name.ToLower().Contains("left");
            eyeProperty.enumValueIndex = containsLeft ? (int)LeapImageRetriever.EYE.LEFT : (int)LeapImageRetriever.EYE.RIGHT;
        }

        serializedObject.ApplyModifiedProperties();
    }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        SerializedProperty properties = serializedObject.GetIterator();

        bool useEnterChildren = true;

        while (properties.NextVisible(useEnterChildren) == true)
        {
            useEnterChildren = false;
            if (AdvancedMode._advancedModeEnabled || BasicModePropertyNames.Contains(properties.name))
            {
                EditorGUILayout.PropertyField(properties, true);
            }
        }

        if (Application.isPlaying)
        {
            LeapImageRetriever retriever = target as LeapImageRetriever;
            var data     = retriever.TextureData;
            var dataType = typeof(Object);

            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.ObjectField(_brightTextureGUIContent, data.BrightTexture.CombinedTexture, dataType, true);
            EditorGUILayout.ObjectField(_rawTextureGUIContent, data.RawTexture.CombinedTexture, dataType, true);
            EditorGUILayout.ObjectField(_distortionTextureGUIContent, data.Distortion.CombinedTexture, dataType, true);
            EditorGUI.EndDisabledGroup();
        }

        serializedObject.ApplyModifiedProperties();
    }
Exemple #4
0
 void OnDisable ()
 {
   LeapImageRetriever.unregisterImageBasedMaterial (this);
   if (cameraAlignment != null) {
     cameraAlignment.warpedImages.Remove(this);
   }
 }
    void OnDisable()
    {
        provider.GetLeapController().DistortionChange -= onDistortionChange;

        if (_instance == this)
        {
            _instance = null;
        }
    }
    void Awake()
    {
        if (_instance != null && _instance != this)
        {
            Debug.LogError("Can only have one instance of LeapImageRetriever in the scene!  This one has been destroyed!");
            DestroyImmediate(this);
            return;
        }

        _instance = this;
    }
    private void setLeftAndRightImageRetrieversEnabled(bool enabled)
    {
        LeapImageRetriever left  = getImageRetreiverForEye(UnityEngine.VR.VRNode.LeftEye);
        LeapImageRetriever right = getImageRetreiverForEye(UnityEngine.VR.VRNode.RightEye);

        left.enabled  = enabled;
        right.enabled = enabled;

        EditorUtility.SetDirty(left);
        EditorUtility.SetDirty(right);
    }
 void Start()
 {
     if (imageRetriever == null)
     {
         imageRetriever = FindObjectOfType <LeapImageRetriever>();
     }
     if (meshRenderer == null)
     {
         meshRenderer = GetComponent <MeshRenderer>();
     }
 }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        SerializedProperty eyeProperty = serializedObject.FindProperty("eye");

        if (eyeProperty.enumValueIndex == -1)
        {
            LeapImageRetriever retrieverScript = target as LeapImageRetriever;
            bool containsLeft = retrieverScript.gameObject.name.ToLower().Contains("left");
            eyeProperty.enumValueIndex = containsLeft ? (int)LeapImageRetriever.EYE.LEFT : (int)LeapImageRetriever.EYE.RIGHT;
            serializedObject.ApplyModifiedProperties();
        }
    }
Exemple #10
0
    void OnEnable()
    {
        LeapImageRetriever.registerImageBasedMaterial(this);
        // Make shader consistent with settings

        if (QualitySettings.activeColorSpace == ColorSpace.Linear)
        {
            GetComponent <Renderer> ().material.SetFloat("_ColorSpaceGamma", 1.0f);
        }
        else
        {
            float gamma = -Mathf.Log10(Mathf.GammaToLinearSpace(0.1f));
            GetComponent <Renderer> ().material.SetFloat("_ColorSpaceGamma", gamma);
            //Debug.Log ("Derived gamma = " + gamma);
        }
    }
Exemple #11
0
    void CreateRetriever()
    {
        _retrival = GameObject.FindObjectOfType <LeapImageRetriever> ();
        if (_retrival != null)
        {
            return;
        }

        var c   = GameObject.FindObjectOfType <LeapServiceProvider>();
        var cam = Camera.main;


        _retrival                  = cam.gameObject.AddComponent <LeapImageRetriever>();
        _retrival._provider        = c;
        _retrival._gammaCorrection = 1.0f;
    }
Exemple #12
0
 void OnEnable ()
 {
   Material imageBasedMaterial = GetComponent<Renderer> ().material;
       
   //Initialize gamma correction
   float gamma = 1f;
   if (QualitySettings.activeColorSpace != ColorSpace.Linear) {
     gamma = -Mathf.Log10 (Mathf.GammaToLinearSpace (0.1f));
     //Debug.Log ("Derived gamma = " + gamma);
   }
   imageBasedMaterial.SetFloat ("_ColorSpaceGamma", gamma);
   
   //Initialize the Time-Warp to be the identity
   imageBasedMaterial.SetMatrix ("_ViewerImageToNow", Matrix4x4.identity);
   LeapImageRetriever.registerImageBasedMaterial(this);
 }
    private LeapImageRetriever getImageRetreiverForEye(UnityEngine.VR.VRNode eyeNode)
    {
        Camera             cameraForEye         = getCameraObjectForEye(eyeNode);
        LeapImageRetriever imageRetrieverForEye = cameraForEye.gameObject.GetComponent <LeapImageRetriever>();

        if (cameraForEye == null)
        {
            throw new System.NullReferenceException("Could not resolve the camera for the given eye: " + eyeNode.ToString());
        }

        if (imageRetrieverForEye == null)
        {
            throw new UnityEngine.MissingComponentException("Could not find LeapImageRetriever component adjacent to camera on " + cameraForEye.gameObject.name + " for the given eye: " + eyeNode.ToString());
        }

        return(imageRetrieverForEye);
    }
Exemple #14
0
    // Use this for initialization
    void Start()
    {
        OVRCameraRig OculusCamera = gameObject.GetComponent <OVRCameraRig>();

        _handController = gameObject.AddComponent <HandController> ();
        _handController.isHeadMounted = true;
        _handController.destroyHands  = true;


        LeapImageRetriever.EYE[] eyes = new LeapImageRetriever.EYE[] { LeapImageRetriever.EYE.RIGHT, IsStereo? LeapImageRetriever.EYE.LEFT:LeapImageRetriever.EYE.RIGHT };
        if (OculusCamera != null)
        {
            Camera[] cams = new Camera[] { OculusCamera.rightEyeCamera, OculusCamera.leftEyeCamera };

            for (int i = 0; i < cams.Length; ++i)
            {
                LeapImageRetriever lret = cams[i].gameObject.AddComponent <LeapImageRetriever>();
                lret.eye             = eyes[i];
                lret.syncMode        = LeapImageRetriever.SYNC_MODE.LOW_LATENCY;
                lret.gammaCorrection = 1.0f;

                _retrivals[i] = lret;

                cams[i].gameObject.AddComponent <EnableDepthBuffer>();
            }

            //OculusCamera.centerEyeAnchor.gameObject;

            GameObject HandsRenderer = GameObject.CreatePrimitive(PrimitiveType.Quad);
            HandsRenderer.name                    = "LeapMotionHandsRenderer";
            HandsRenderer.transform.parent        = OculusCamera.centerEyeAnchor.transform;
            HandsRenderer.transform.localPosition = new Vector3(0, 0, 0.137f);
            HandsRenderer.transform.localRotation = Quaternion.identity;
            LeapImageBasedMaterial lmat = HandsRenderer.AddComponent <LeapImageBasedMaterial>();
            lmat.imageMode = IsStereo?LeapImageBasedMaterial.ImageMode.STEREO:LeapImageBasedMaterial.ImageMode.RIGHT_ONLY;
            HandsRenderer.GetComponent <MeshRenderer>().material = HandsMaterial;
            _Hands = HandsRenderer;
            _Hands.GetComponent <MeshRenderer>().enabled = IsActive;
        }
    }
    void Update()
    {
        LeapImageRetriever images = GetComponent <LeapImageRetriever>();

        if (Input.GetKeyDown("1"))
        {
            images.imageColor         = Color.white;
            images.blackIsTransparent = false;
            images.undistortImage     = false;
        }
        if (Input.GetKeyDown("2"))
        {
            images.imageColor         = Color.white;
            images.blackIsTransparent = false;
            images.undistortImage     = true;
        }
        if (Input.GetKeyDown("3"))
        {
            images.imageColor         = Color.black;
            images.blackIsTransparent = true;
            images.undistortImage     = true;
        }
    }
 // Use this for initialization
 void Start()
 {
     mr = GetComponent <MeshRenderer>();
     lr = GetComponent <LeapImageRetriever>();
 }
    void OnDisable()
    {
        provider.GetLeapController().DistortionChange -= onDistortionChange;

        if (_instance == this) {
          _instance = null;
        }
    }
 void OnDestroy()
 {
     if (_instance == this) {
       _instance = null;
     }
 }
    void Awake()
    {
        if (_instance != null && _instance != this) {
          Debug.LogError("Can only have one instance of LeapImageRetriever in the scene!  This one has been destroyed!");
          DestroyImmediate(this);
          return;
        }

        _instance = this;
    }
Exemple #20
0
 void OnDisable()
 {
     LeapImageRetriever.unregisterImageBasedMaterial(this);
 }
Exemple #21
0
    void Start()
    {
        HandController[] allControllers = FindObjectsOfType <HandController> ();
        foreach (HandController controller in allControllers)
        {
            if (controller.isActiveAndEnabled)
            {
                handController = controller;
            }
        }
        if (handController == null)
        {
            //Debug.LogWarning ("Camera alignment requires an active HandController in the scene -> enabled = false");
            enabled = false;
            return;
        }

        LeapImageRetriever[] allRetrievers = FindObjectsOfType <LeapImageRetriever> ();
        foreach (LeapImageRetriever retriever in allRetrievers)
        {
            if (retriever.isActiveAndEnabled)
            {
                imageRetriever = retriever;
            }
        }

        /*if (imageRetriever == null) {
         * //Debug.LogWarning ("Camera alignment requires an active LeapImageRetriever in the scene -> enabled = false");
         * enabled = false;
         * return;
         * }*/

        hasCameras = VRCameras.NONE;
        if (centerCamera != null)
        {
            Camera center = centerCamera.GetComponent <Camera>();
            if (center != null && center.isActiveAndEnabled)
            {
                hasCameras = VRCameras.CENTER;
            }
        }
        if (hasCameras == VRCameras.NONE)
        {
            Camera left  = leftCamera.GetComponent <Camera>();
            Camera right = rightCamera.GetComponent <Camera>();
            if (left != null && left.isActiveAndEnabled &&
                right != null && right.isActiveAndEnabled)
            {
                hasCameras = VRCameras.LEFT_RIGHT;
            }
        }
        if (hasCameras == VRCameras.NONE)
        {
            //Debug.LogWarning ("Either a central Camera for both eyes, or a Left and Right cameras must be referenced -> enabled = false");
            enabled = false;
            return;
        }

        if (transform.parent == null)
        {
            //Debug.LogWarning ("Alignment requires a parent object to define the location of the player in the world. enabled -> false");
            enabled = false;
            return;
        }

        if (transform != leftCamera.parent ||
            transform != centerCamera.parent ||
            transform != rightCamera.parent)
        {
            //Debug.LogWarning ("LeapCameraAlignment must be a component of the parent of the camera tranasforms -> enabled = false");
            enabled = false;
            return;
        }

        deviceInfo = (overrideDeviceType) ? new LeapDeviceInfo(overrideDeviceTypeWith) : handController.GetDeviceInfo();
        if (deviceInfo.type == LeapDeviceType.Invalid)
        {
            //Debug.LogWarning ("Invalid Leap Device -> enabled = false");
            enabled = false;
            return;
        }

        if (VRDevice.isPresent &&
            VRSettings.loadedDevice == VRDeviceType.Oculus)
        {
            eyeAlignment = new UserEyeAlignment()
            {
                use       = true,
                ipd       = OVRPlugin.ipd,
                eyeDepth  = OVRPlugin.eyeDepth,
                eyeHeight = OVRPlugin.eyeHeight
            };
            //Debug.Log ("Unity VR Support with Oculus");
        }
        else
        {
            eyeAlignment = new UserEyeAlignment()
            {
                use       = false,
                ipd       = 0f,
                eyeDepth  = 0f,
                eyeHeight = 0f
            };
            //Debug.Log ("Two-camera stereoscopic alignment");
        }
    }
Exemple #22
0
    void Start()
    {
        HandController[] allControllers = FindObjectsOfType<HandController> ();
        foreach (HandController controller in allControllers) {
          if (controller.isActiveAndEnabled) {
        handController = controller;
          }
        }
        if (handController == null) {
          Debug.LogWarning ("Camera alignment requires an active HandController in the scene -> enabled = false");
          enabled = false;
          return;
        }

        LeapImageRetriever[] allRetrievers = FindObjectsOfType<LeapImageRetriever> ();
        foreach (LeapImageRetriever retriever in allRetrievers) {
          if (retriever.isActiveAndEnabled) {
        imageRetriever = retriever;
          }
        }
        /*if (imageRetriever == null) {
          Debug.LogWarning ("Camera alignment requires an active LeapImageRetriever in the scene -> enabled = false");
          enabled = false;
          return;
        }*/

        hasCameras = VRCameras.NONE;
        if (centerCamera != null) {
          Camera center = centerCamera.GetComponent<Camera>();
          if (center != null && center.isActiveAndEnabled) {
        hasCameras = VRCameras.CENTER;
          }
        }
        if (hasCameras == VRCameras.NONE) {
          Camera left = leftCamera.GetComponent<Camera>();
          Camera right = rightCamera.GetComponent<Camera>();
          if (left != null && left.isActiveAndEnabled &&
          right != null && right.isActiveAndEnabled) {
        hasCameras = VRCameras.LEFT_RIGHT;
          }
        }
        if (hasCameras == VRCameras.NONE) {
          Debug.LogWarning ("Either a central Camera for both eyes, or a Left and Right cameras must be referenced -> enabled = false");
          enabled = false;
          return;
        }

        if (transform.parent == null) {
          Debug.LogWarning ("Alignment requires a parent object to define the location of the player in the world. enabled -> false");
          enabled = false;
          return;
        }

        if (transform != leftCamera.parent ||
        transform != centerCamera.parent ||
        transform != rightCamera.parent) {
          Debug.LogWarning ("LeapCameraAlignment must be a component of the parent of the camera tranasforms -> enabled = false");
          enabled = false;
          return;
        }

        deviceInfo = (overrideDeviceType) ? new LeapDeviceInfo(overrideDeviceTypeWith) : handController.GetDeviceInfo ();
        if (deviceInfo.type == LeapDeviceType.Invalid) {
          Debug.LogWarning ("Invalid Leap Device -> enabled = false");
          enabled = false;
          return;
        }

        if (VRDevice.isPresent &&
        VRSettings.loadedDevice == VRDeviceType.Oculus) {
          eyeAlignment = new UserEyeAlignment() {
        use = true,
        ipd = OVRPlugin.ipd,
        eyeDepth = OVRPlugin.eyeDepth,
        eyeHeight = OVRPlugin.eyeHeight
          };
          Debug.Log ("Unity VR Support with Oculus");
        } else {
          eyeAlignment = new UserEyeAlignment() {
        use = false,
        ipd = 0f,
        eyeDepth = 0f,
        eyeHeight = 0f
          };
          Debug.Log ("Two-camera stereoscopic alignment");
        }
    }