Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Model View for Architectural Visualizzation

Discussion in 'Scripting' started by Tdonk, Jan 29, 2015.

  1. Tdonk

    Tdonk

    Joined:
    Jan 29, 2015
    Posts:
    7
    Hi,
    I would like to make the final project (architectural project) for my degree with Unity 3D. My idea is put the 3d model in Unity3d just for show the project. Also i need a simple interface for change different scheme/project.
    I'm beginner with Unity3d but i want to try. I studied some tutorial for understanding unity interface and c#
    My first question is:
    I need to create an script for the camera. I would like to make a "project model view" like Google Maps 3D, something that i can control rotate, pan, zoom, tilt with my mouse. Maybe this script is very easy but i'm a little bit confused =).
    Thank you for your time.
     
  2. fire7side

    fire7side

    Joined:
    Oct 15, 2012
    Posts:
    1,819
    Google Unity model viewer. You can either find one already written, or use it to understand what needs to be done.
     
  3. Tdonk

    Tdonk

    Joined:
    Jan 29, 2015
    Posts:
    7
  4. fire7side

    fire7side

    Joined:
    Oct 15, 2012
    Posts:
    1,819
  5. Tdonk

    Tdonk

    Joined:
    Jan 29, 2015
    Posts:
    7
    I tried a lot of script. This is the perfect one but is made for perspective camera. I need to use orthographic camera.
    The problem is the zoom. i need something for change the size (no the distance) of the camera
    Can you help me for modify this script?


    Code (CSharp):
    1.  using UnityEngine;
    2. using System.Collections;
    3. [AddComponentMenu("Camera-Control/Mouse drag Orbit with zoom")]
    4. public class DragMouseOrbit : MonoBehaviour
    5. {
    6.      public Transform target;
    7.      public float distance = 5.0f;
    8.      public float xSpeed = 120.0f;
    9.      public float ySpeed = 120.0f;
    10.      public float yMinLimit = -20f;
    11.      public float yMaxLimit = 80f;
    12.      public float distanceMin = .5f;
    13.      public float distanceMax = 15f;
    14.      public float smoothTime = 2f;
    15.      float rotationYAxis = 0.0f;
    16.      float rotationXAxis = 0.0f;
    17.      float velocityX = 0.0f;
    18.      float velocityY = 0.0f;
    19.      // Use this for initialization
    20.      void Start()
    21.      {
    22.          Vector3 angles = transform.eulerAngles;
    23.          rotationYAxis = angles.y;
    24.          rotationXAxis = angles.x;
    25.          // Make the rigid body not change rotation
    26.          if (rigidbody)
    27.          {
    28.              rigidbody.freezeRotation = true;
    29.          }
    30.      }
    31.      void LateUpdate()
    32.      {
    33.          if (target)
    34.          {
    35.              if (Input.GetMouseButton(0))
    36.              {
    37.                  velocityX += xSpeed * Input.GetAxis("Mouse X") * distance * 0.02f;
    38.                  velocityY += ySpeed * Input.GetAxis("Mouse Y") * 0.02f;
    39.              }
    40.              rotationYAxis += velocityX;
    41.              rotationXAxis -= velocityY;
    42.              rotationXAxis = ClampAngle(rotationXAxis, yMinLimit, yMaxLimit);
    43.              Quaternion fromRotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, 0);
    44.              Quaternion toRotation = Quaternion.Euler(rotationXAxis, rotationYAxis, 0);
    45.              Quaternion rotation = toRotation;
    46.          
    47.              distance = Mathf.Clamp(distance - Input.GetAxis("Mouse ScrollWheel") * 5, distanceMin, distanceMax);
    48.              RaycastHit hit;
    49.              if (Physics.Linecast(target.position, transform.position, out hit))
    50.              {
    51.                  distance -= hit.distance;
    52.              }
    53.              Vector3 negDistance = new Vector3(0.0f, 0.0f, -distance);
    54.              Vector3 position = rotation * negDistance + target.position;
    55.          
    56.              transform.rotation = rotation;
    57.              transform.position = position;
    58.              velocityX = Mathf.Lerp(velocityX, 0, Time.deltaTime * smoothTime);
    59.              velocityY = Mathf.Lerp(velocityY, 0, Time.deltaTime * smoothTime);
    60.          }
    61.      }
    62.      public static float ClampAngle(float angle, float min, float max)
    63.      {
    64.          if (angle < -360F)
    65.              angle += 360F;
    66.          if (angle > 360F)
    67.              angle -= 360F;
    68.          return Mathf.Clamp(angle, min, max);
    69.      }
    70. }
     
    Last edited: Feb 1, 2015