コード例 #1
0
 void OnDestroy()
 {
     if (xr.DisabledInEditor())
     {
         return;
     }
     if (isCBInit)
     {
         cam.RemoveCommandBuffer(CameraEvent.BeforeForwardOpaque, buffer);
     }
 }
コード例 #2
0
    void Update()
    {
        if (xr.DisabledInEditor())
        {
            return;
        }

        if (!initialized)
        {
            Initialize();
        }

        if (displayImmediately && xr.GetCapabilities().IsSurfaceEstimationFixedSurfaces())
        {
            return;
        }

        if (groundOnly && displayImmediately)
        {
            UpdateForDisplayImmediatelyGroundOnly();
            return;
        }

        bool surfaceUpdated = UpdateSurface();

        if (!surfaceUpdated && surfaceFound)
        {
            transform.position = centerMap[surfaceId];
            if (deformToSurface)
            {
                DeformMesh(xr.GetSurface(surfaceId).mesh);
            }
        }
    }
コード例 #3
0
 void Start()
 {
     xr = GameObject.FindWithTag("XRController").GetComponent <XRController>();
     if (!xr.DisabledInEditor())
     {
         Initialize();
     }
 }
コード例 #4
0
 void OnEnable()
 {
     xr = GameObject.FindWithTag("XRController").GetComponent <XRController>();
     xr.UpdateCameraProjectionMatrix(
         GetComponent <Camera>(), transform.position, transform.rotation, scale);
     if (!xr.DisabledInEditor())
     {
         initialized = true;
     }
 }
コード例 #5
0
 void Update()
 {
     if (xr.DisabledInEditor())
     {
         return;
     }
     if (!initialized)
     {
         Initialize();
     }
     transform.position = xr.GetCameraPosition();
     transform.rotation = xr.GetCameraRotation();
 }
コード例 #6
0
    void Update()
    {
        if (xr_.DisabledInEditor())
        {
            return;
        }

        long surfaceId = xr_.GetActiveSurfaceId();
        var  surface   = xr_.GetSurface(surfaceId);

        if (surface != XRSurface.NO_SURFACE && !idToMesh_.ContainsKey(surfaceId))
        {
            MeshThing meshThing = new MeshThing();
            meshThing.holder = new GameObject();
            meshThing.holder.transform.parent = gameObject.transform;
            meshThing.filter              = meshThing.holder.AddComponent <MeshFilter>();
            meshThing.collider            = meshThing.holder.AddComponent <MeshCollider>();
            meshThing.renderer            = meshThing.holder.AddComponent <MeshRenderer>();
            meshThing.filter.mesh         = surface.mesh;
            meshThing.collider.sharedMesh = surface.mesh;
            if (surface.type == XRSurface.Type.VERTICAL_PLANE)
            {
                meshThing.renderer.material = verticalSurfaceMaterial_;
            }
            else
            {
                meshThing.renderer.material = horizontalSurfaceMaterial_;
            }
            idToMesh_[surfaceId] = meshThing;

            // Save all surfaces that we have seen
            idToSurface_[surfaceId] = surface;
        }

        // Update Status Text
        if (statusText_ != null)
        {
            int totalSurfaceCount    = idToSurface_.Count;
            int verticalSurfaceCount = 0;
            foreach (var s in idToSurface_.Values)
            {
                if (s.type == XRSurface.Type.VERTICAL_PLANE)
                {
                    verticalSurfaceCount++;
                }
            }
            statusText_.text = string.Format("Surface {0} Vertical /{1} Total",
                                             verticalSurfaceCount, totalSurfaceCount);
        }
    }
コード例 #7
0
    void Update()
    {
        if (xr.DisabledInEditor())
        {
            return;
        }
        // Update the light exposure.
        float exposure    = xr.GetLightExposure();
        float temperature = xr.GetLightTemperature();

        // Exposure ranges from -1 to 1 in XR, adjust to 0-2 for Unity.
        sceneLight.intensity            = exposure + 1.0f;
        sceneLight.colorTemperature     = temperature;
        RenderSettings.ambientIntensity = exposure + 1.0f;
        RenderSettings.ambientLight     = tempToColor(temperature);
    }
コード例 #8
0
    void Update()
    {
        if (xr.DisabledInEditor())
        {
            return;
        }

        if (!initialized)
        {
            Initialize();
        }

        if (!isCBInit)
        {
            buffer = new CommandBuffer();
            buffer.Blit(null, BuiltinRenderTextureType.CurrentActive, rMat);
            isCBInit = true;
        }

        float scaleFactor = texAspect / xr.GetRealityTextureAspectRatio();
        float rotation    = lastRotation;

        switch (xr.GetTextureRotation())
        {
        case XRTextureRotation.R270:
            rotation    = -90.0f;
            scaleFactor = texAspect * xr.GetRealityTextureAspectRatio();
            rMat.SetInt("_ScreenOrientation", (int)ScreenOrientation.LandscapeRight);
            break;

        case XRTextureRotation.R0:
            rotation = 0.0f;
            rMat.SetInt("_ScreenOrientation", (int)ScreenOrientation.Portrait);
            break;

        case XRTextureRotation.R90:
            rotation    = 90.0f;
            scaleFactor = texAspect * xr.GetRealityTextureAspectRatio();
            rMat.SetInt("_ScreenOrientation", (int)ScreenOrientation.LandscapeLeft);
            break;

        case XRTextureRotation.R180:
            rotation = 180.0f;
            rMat.SetInt("_ScreenOrientation", (int)ScreenOrientation.PortraitUpsideDown);
            break;

        default:
            break;
        }
        lastRotation = rotation;

        Matrix4x4 mWarp = Matrix4x4.identity;

        if (scaleFactor > 1 + 1e-2)
        {
            float invScaleFactor = 1.0f / scaleFactor;
            mWarp[1, 1] = invScaleFactor;
            mWarp[1, 3] = (1 - invScaleFactor) * .5f;
        }
        else if (scaleFactor < 1 - 1e-2)
        {
            mWarp[0, 0] = scaleFactor;
            mWarp[0, 3] = (1 - scaleFactor) * .5f;
        }

        Matrix4x4 m = Matrix4x4.TRS(
            Vector3.zero,
            Quaternion.Euler(0.0f, 0.0f, rotation),
            Vector3.one);

        Matrix4x4 nm = m * mWarp;

#if (UNITY_ANDROID && !UNITY_EDITOR)
        // ARCore shader rotates internally.
        if (xr.GetCapabilities().IsPositionTrackingRotationAndPosition())
        {
            nm = mWarp;
        }
#endif

        rMat.SetMatrix("_TextureWarp", nm);
    }
コード例 #9
0
    void Update()
    {
        if (xr.DisabledInEditor())
        {
            return;
        }

        if (!initialized)
        {
            Initialize();
        }

        if (!isCBInit)
        {
            buffer = new CommandBuffer();
            buffer.Blit(null, BuiltinRenderTextureType.CurrentActive, rMat);
            isCBInit = true;
        }

        if (xr.ShouldUseRealityRGBATexture())
        {
            var tex = xr.GetRealityRGBATexture();
            if (tex == null)
            {
                return;
            }
            rMat.mainTexture = tex;
            texAspect        = tex.width * 1.0f / tex.height;
        }
        else
        {
            var ytex = xr.GetRealityYTexture();
            rMat.SetTexture("_YTex", ytex);
            rMat.SetTexture("_UVTex", xr.GetRealityUVTexture());
            texAspect = ytex.width * 1.0f / ytex.height;
        }

        float scaleFactor = texAspect / xr.GetRealityTextureAspectRatio();
        float rotation    = lastRotation;

        switch (xr.GetTextureRotation())
        {
        case XRTextureRotation.R270:
            rotation    = -90.0f;
            scaleFactor = texAspect * xr.GetRealityTextureAspectRatio();
            break;

        case XRTextureRotation.R0:
            rotation = 0.0f;
            break;

        case XRTextureRotation.R90:
            rotation    = 90.0f;
            scaleFactor = texAspect * xr.GetRealityTextureAspectRatio();
            break;

        case XRTextureRotation.R180:
            rotation = 180.0f;
            break;

        default:
            break;
        }
        lastRotation = rotation;

        Matrix4x4 mWarp = Matrix4x4.identity;

        if (scaleFactor > 1 + 1e-2)
        {
            float invScaleFactor = 1.0f / scaleFactor;
            mWarp[1, 1] = invScaleFactor;
            mWarp[1, 3] = (1 - invScaleFactor) * .5f;
        }
        else if (scaleFactor < 1 - 1e-2)
        {
            mWarp[0, 0] = scaleFactor;
            mWarp[0, 3] = (1 - scaleFactor) * .5f;
        }

        Matrix4x4 rotate90 = Matrix4x4.zero;

        rotate90[0, 1] = -1;
        rotate90[0, 3] = 1;
        rotate90[1, 0] = 1;
        rotate90[2, 2] = 1;
        rotate90[3, 3] = 1;

        Matrix4x4 m = Matrix4x4.identity;

        while (rotation < 0)
        {
            rotation += 360;
        }
        while (rotation > 360)
        {
            rotation -= 360;
        }
        while (rotation > 0)
        {
            m         = m * rotate90;
            rotation -= 90;
        }

        Matrix4x4 nm = m * mWarp;

        rMat.SetMatrix("_TextureWarp", nm);
    }