tech/metaverse

21/09/10 Virtual Tour Using Sphere with unity

tech-lover 2021. 9. 10. 10:23

https://youtu.be/1Fupk75GhHg

 

Virtual Tour Using Sphere with unity

how to make virtual tour using unity , build 360 degree experience here is the link to script of vrcamera : https://github.com/safeee/VRtour/blob/master/VRCamera.cs i get the 360 degree image from this link : http://www.andrewphotography.com.au/wordpress

youtu.be

- VRcamera Script

 

```

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using System;

public class VRcamera : MonoBehaviour

// flag to keep track whether we are dragging or not

    public  bool isDragging = false;

 

    // starting point of a camera movement

    float startMouseX;

    float startMouseY;

 

    // Camera component

    public  Camera cam;

    // Start is called before the first frame update

    void Start()

    {

        // Get our camera component

        cam = this.gameObject.GetComponent<Camera>();

    }

 

    // Update is called once per frame

    void Update () {

            

        // if we press the left button and we haven't started dragging

        if(Input.GetMouseButtonDown(0) && !isDragging )

        {                

            // set the flag to true

            isDragging = true;

 

            // save the mouse starting position

            startMouseX = Input.mousePosition.x;

            startMouseY = Input.mousePosition.y;

        }

        // if we are not pressing the left btn, and we were dragging

        else if(Input.GetMouseButtonUp(0) && isDragging)

        {                

            // set the flag to false

            isDragging = false;

        }

    }

 

    void LateUpdate()

    {

        // Check if we are dragging

         if(isDragging)

        {

            //Calculate current mouse position

            float endMouseX = Input.mousePosition.x;

            float endMouseY = Input.mousePosition.y;

 

            //Difference (in screen coordinates)

            float diffX = endMouseX - startMouseX;

            float diffY = endMouseY - startMouseY;

 

            //New center of the screen

            float newCenterX = Screen.width / 2 + diffX;

            float newCenterY = Screen.height / 2 + diffY;

 

            //Get the world coordinate , this is where we want to look at

            Vector3 LookHerePoint = cam.ScreenToWorldPoint(new Vector3(newCenterXnewCenterYcam.nearClipPlane));

 

            //Make our camera look at the "LookHerePoint"

            transform.LookAt(LookHerePoint);

 

            //starting position for the next call

            startMouseX = endMouseX;

            startMouseY = endMouseY;

        }

    }

}

```

 

- 360 degree image

 

 

- Unity project

* import image and then change texture shape to cube

 

 

 

현재 Mapping : Auto (default)로 해도 정상 동작함.

 

아래 내용은 참고.

동영상에 없는 내용 - 버전 차이요인으로 인해 Single Channel선택해서 Mapping이 가능하게 해주어

아래 그림처럼 material을 변경 가능

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

- References

https://youtu.be/OQUtvyGrusk

 

Skybox from 360 Panorama Image in Unity3d

In this video we will see how we can use a 360 or Panorama image as a skybox in unity 3d.

youtu.be