Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by LionWare · Nov 12, 2020 at 08:11 AM · shaderscoordinatesdimensionssphericalsector

Rendering a Spherical Sector

I want to create a spherical sector from a sphere game object whose dimensions (Area) can be modified in real time (runtime) using it's azimuth and elevation angles. I tried to create a shader that does so but cannot get any where, all I am doing is distorting the shape of the sphere to a ellipsoid. Any idea on how to achieve this? Thanks

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by LionWare · Nov 26, 2020 at 08:13 AM

Its done. Here is the code

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.Data;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEditor.UIElements;
 
 public class Please : MonoBehaviour
 {
     public int ThetaUpper = 30;
     public int ThetaLower = 40;
     public int PhiUpper = 30;
     public int PhiLower = 10;
     public bool edit = true;
     private int ThetaU;
     private int ThetaL;
     private int PhiU;
     private int PhiL;
     public float size = 0.001f;
     private readonly int res = 2;
     private Mesh mesh;
     private MeshFilter meshFilter;
     public float radius = 5.0f;
     private GameObject[] points;
     private Vector3[] vertices;
 
     // Start is called before the first frame update
     void Start()
     {
         this.gameObject.AddComponent<MeshFilter>();
         this.gameObject.AddComponent<MeshRenderer>();
         meshFilter = this.gameObject.GetComponent<MeshFilter>();
         meshFilter.sharedMesh = new Mesh();
         mesh = meshFilter.sharedMesh;
         Create();
         Assign();
     }
 
     // Update is called once per frame
     void Update()
     {
     }
 
     bool check()
     {
         if (ThetaLower == ThetaL && ThetaUpper == ThetaU && PhiLower == PhiL && PhiUpper == PhiU)
             return true;
         else return false;
     }
     void Assign()
     {
         ThetaU = ThetaUpper;
         ThetaL = ThetaLower;
         PhiL = PhiLower;
         PhiU = PhiUpper;
     }
 
     void Create()
     {
         int index1 = (ThetaLower - ThetaUpper) * 2;
         int index2 = (PhiUpper - PhiLower) * 2;
         vertices = new Vector3[index1 * index2];
         int[,] temp = new int[index1, index2];
         int no = 0;
         for (int i = 0; i < index1; i++)
         {
             float theta = ((0.5f * i) + ThetaUpper) * Mathf.Deg2Rad;
             for (int j = 0; j < index2; j++, no++)
             {               
                 float phi = ((0.5f * j) + PhiLower) * Mathf.Deg2Rad;
                 float x = radius * Mathf.Sin(theta) * Mathf.Cos(phi);
                 float z = radius * Mathf.Sin(theta) * Mathf.Sin(phi);
                 float y = radius * Mathf.Cos(theta);
                 vertices[no] = new Vector3(x, y, z);
                 temp[i, j] = no;
             }
         }
         int[] triangles = new int[(index1 - 1) * (index2 - 1) * 6];
         int triIndex = 0;
         for (int i = 0; i < index1-1; i++)
         {
             for (int j = 0; j < index2-1; j++)
             {
                 triangles[triIndex] = temp[i, j];
                 triangles[triIndex + 1] = temp[i + 1, j + 1];
                 triangles[triIndex + 2] = temp[i, j + 1];
 
                 triangles[triIndex + 3] = temp[i, j];
                 triangles[triIndex + 4] = temp[i + 1, j];
                 triangles[triIndex + 5] = temp[i + 1, j + 1];
 
                 triIndex += 6;
             }
         }
 
         mesh.Clear();
         mesh.vertices = vertices;
         mesh.triangles = triangles;
         mesh.RecalculateNormals();
     } 
 }
 

 

This Works

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

227 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Get the screen coordinates of the object in the projected FishEye image -1 Answers

Grayscale Green and Blue but not Red 1 Answer

Shaders on new projects dont seem to work. Work on old (Tutorial) Project just fine. 1 Answer

Surface shader, too many samplers workaround 1 Answer

Overlap 2d image than blend color with shader 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges