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 /
avatar image
0
Question by quexeky · Apr 29, 2021 at 10:48 AM · mesh3dplanet

How to find and use mesh positions in a variable for positions of other objects and generate them

I would like to know what the position of vertices in a mesh (but quadrants are more specific, and would be more helpful). Basically, what I want to do is have a sort of sphere, as created in Sebastian Lague's procedural planets, and find the positions of all quadrants to put a plane of noise onto it. This is his code that I used: using System.Collections; using System.Collections.Generic; using UnityEngine;

public class TerrainFace {

 Mesh mesh; //The mesh itself
 int resolution; //The resolution of the planet
 Vector3 localUp;
 Vector3 axisA; //Top and bottom of the mesh
 Vector3 axisB; // Sizes of the mesh

 public TerrainFace(Mesh mesh, int resolution, Vector3 localUp) //Generating the Terrain Faces, Uses variables Mesh, Resolution, Localup
 {
     this.mesh = mesh; //Sets the meshes globaly
     this.resolution = resolution; //
     this.localUp = localUp;//

     axisA = new Vector3(localUp.y, localUp.z, localUp.x); //Position of the Sphere/Cube's faces 

     axisB = Vector3.Cross(localUp, axisA); //Makes them Join
 }

 public void ConstructMesh() //Constructing the mesh
 {
     Vector3[] vertices = new Vector3[resolution * resolution];//Tells us how many verticies there are
     int[] triangles = new int[(resolution - 1) * (resolution - 1) * 6];//Tells us how many triangles there are
     int triIndex = 0; //Creates variable triIndex

     for (int y = 0; y < resolution; y++) //Tells us how big the y axis is
     {
         for (int x = 0; x < resolution; x++) //Tells the loop how big the x axis is
         {
             int i = x + y * resolution;
             Vector2 percent = new Vector2(x, y) / (resolution - 1);
             Vector3 pointOnUnitCube = localUp + (percent.x - .5f) * 2 * axisA + (percent.y - .5f) * 2 * axisB; //Defines the points where the angles generate
             Vector3 pointOnUnitSphere = pointOnUnitCube.normalized; //Makes the cube become a sphere
             vertices[i] = pointOnUnitSphere; //Part of making the cube a sphere

             if (x != resolution - 1 && y != resolution - 1) //Defines the triangles on the cube/sphere
             {
                 triangles[triIndex] = i;//Point one of the triangle
                 triangles[triIndex + 1] = i + resolution + 1; //Point 2 of the triangle
                 triangles[triIndex + 2] = i + resolution; //Point 3 of the triangle

                 triangles[triIndex + 3] = i;// Point one of the opposite triangle on the square of mesh
                 triangles[triIndex + 4] = i + 1;//repeated from above
                 triangles[triIndex + 5] = i + resolution + 1;
                 triIndex += 6;
             }
         }
     }
     mesh.Clear(); //Makes sure the existing mesh is cleared to reduce troubleshooting needed
     mesh.vertices = vertices; //Puts the verticies on the mesh
     mesh.triangles = triangles; //Puts the triangles into the mesh
     mesh.RecalculateNormals(); //smooths out lighting
 }

} How do I take the mesh out and apply those coordinates, angle, and rotation to a plane? I want to have a plane at each of the quads: https://imgur.com/a/r60FS78.

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

0 Replies

· Add your reply
  • Sort: 

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

158 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

Related Questions

How to snap a Prefab to the normal of an irregular mesh 1 Answer

Performance Optimization for Mobile 3D, No Static 2 Answers

Using the right terminology 1 Answer

Player model physics doesn't seem to work properly. Gravity issues maybe? 0 Answers

Viewing a 3d mesh in VR 0 Answers


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