Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 alexander11 · Aug 25, 2016 at 03:06 AM · unity 5mesh3dvector3duplicate

How do i calculate the outer bounds???

Hello so i have a script on duplicating Vector3[](newVerts) but i would like to know how can i only duplicate the outer bounds vertices(newVerts) of the object, like this in the picture below?

Would anyone know how to do this, i'll be very pleased if some could help me out with this?

alt text

Here is my duplication code.

 public class Extruder : MonoBehaviour
 {
     public float rotAngle;
     public int stretch = 5;
 
     public MeshFilter mf;
     private Vector3[] origVerts;
     private Vector3[] newVerts;
     float xStretchDistance = 0f;
     float zStretchDistance = 1f;
     float yStretchDistance = 0f;
 
     void Start()
     {
         mf = GetComponent<MeshFilter>();
 
         Generate();
     }
 
     void Generate()
     {
         origVerts = mf.mesh.vertices;
         newVerts = new Vector3[origVerts.Length * stretch];
 
         for (int i = 0; i < origVerts.Length; i++)
         {
             for (int j = 0; j < stretch; j++)
             {
                 float newX = origVerts[i].x + xStretchDistance * j;
                 float newY = origVerts[i].y + yStretchDistance * j;
                 float newZ = origVerts[i].z + zStretchDistance * j;
                 Vector3 pos = new Vector3(this.transform.position.x + newX, this.transform.position.y + newY, this.transform.position.z + newZ);
                 newVerts[j + i * stretch] = pos;
             }
         }
 
         Mesh newMesh = new Mesh();
         newMesh.vertices = newVerts;
         mf.mesh = newMesh;
     }
     void OnDrawGizmos()
     {
         Gizmos.color = Color.white;
         for (int i = 0; i < newVerts.Length; i++)
         {
             Gizmos.DrawSphere(newVerts[i], 0.1f);
         }
         Gizmos.color = Color.green;
         for (int i = 0; i < origVerts.Length; i++)
         {
             Gizmos.DrawSphere(origVerts[i], 0.2f);
         }
     }
 }
capture35.png (43.7 kB)
Comment
Add comment · Show 4
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
avatar image b1gry4n · Aug 25, 2016 at 08:11 AM 0
Share

I havent generated meshes with vertices in a while so I am having trouble remembering the order the verts are generated, however....

you could get the border verts inside your forloops I believe.

         if (i == origVerts.Length - 1) {
         //Border vert
         }
     
         if (i == 0) {
         //Border vert
         }

That would give you at least 2 sides of your mesh. you would need the other forloop (for you the "stretch" length) to generate the other 2 sides. I will try to explain my thought process...

If you have a 5x5 square made up of 25 vertices, with x being horizontal and y being vertical [x,y] , the borders would be:

 bottom: [0,0] [0,1] [0,2] [0,3] [0,4] 
 left: [0,0] [1,0] [2,0] [3,0] [4,0]
 top: [0,4] [1,4] [2,4] [3,4] [4,4]
 right: [4,0] [4,1] [4,2] [4,3] [4,4]
avatar image alexander11 b1gry4n · Aug 25, 2016 at 08:15 AM 0
Share

Thanks but i have already done that, iv'e been looking for a way that works with any mesh.

avatar image b1gry4n · Aug 25, 2016 at 08:27 AM 0
Share

There are a few answers out there that relate to triangles sharing vertices. They are explained more in depth in these answers.

http://answers.unity3d.com/questions/1019436/get-outeredge-vertices-c.html

http://answers.unity3d.com/questions/443633/finding-the-vertices-of-each-edge-on-mesh.html

http://answers.unity3d.com/questions/566779/how-to-find-the-vertices-of-each-edge-on-mesh.html

avatar image alexander11 b1gry4n · Aug 25, 2016 at 08:33 AM 0
Share

Thanks, i will now "LEARN!" about the mysterious mesh.

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

97 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

Related Questions

How to add manual generated color ? 0 Answers

Hiding part of mesh 0 Answers

How do i use lines to calculate triangles on mesh?? 0 Answers

Can someone please help me with mesh extrusion 0 Answers

How do i calculate mesh on a spline?? 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