Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by UnityUser666 · Oct 01, 2014 at 05:21 AM · meshverticestube

How do I make a series of primitive planes and roll them into a tube?

So I want to create any number of primitive planes and roll them into a tube. Currently I get here from doing this:

 for(int i = 0; i < 10; i++)
         {
             GameObject symbol = GameObject.CreatePrimitive(PrimitiveType.Plane);
             symbol.name = "Symbol_" + i;
             symbol.transform.parent = reel.transform;
 
             Vector3 tran = new Vector3(PLANE_SIZE * i, 0.0f, 0.0f);
             Quaternion rot = Quaternion.Euler(0.0f, 0.0f, 0.0f);
             Vector3 scale = new Vector3(1.0f, 1.0f, 1.0f);
 
             Matrix4x4 mat = new Matrix4x4();
             mat.SetTRS(tran, rot, scale);
 
             List<Vector3> updatedVerts = new List<Vector3>();
             foreach(Vector3 vert in symbol.GetComponent<MeshFilter>().mesh.vertices)
             {
                 updatedVerts.Add(mat.MultiplyPoint3x4(vert));
             }
 
             symbol.GetComponent<MeshFilter>().mesh.vertices = updatedVerts.ToArray();
             symbol.GetComponent<MeshCollider>().sharedMesh = symbol.GetComponent<MeshFilter>().mesh;
         
             symbol.GetComponent<MeshFilter>().mesh.RecalculateBounds();
             symbol.GetComponent<MeshFilter>().mesh.RecalculateNormals();
         }

alt text

Things start to go wrong when I try and roll it up into a tube.

     int vertCount = 0;
     foreach(MeshFilter meshFilter in reel.GetComponentsInChildren<MeshFilter>())
     {
         List<Vector3> updatedVerts = new List<Vector3>();
         foreach(Vector3 vert in meshFilter.mesh.vertices)
         {
             int multiplier = vertCount / 11;
             float angle = 3.0f * multiplier;
             float xPos = Mathf.Cos(angle) * 5.0f;
             float yPos = Mathf.Sin(angle) * 5.0f;
             Vector3 tran = new Vector3(xPos, yPos, 0.0f);
             Quaternion rot = Quaternion.Euler(0.0f, 0.0f, 0.0f);
             Vector3 scale = new Vector3(1.0f, 1.0f, 1.0f);
             
             Matrix4x4 mat = new Matrix4x4();
             mat.SetTRS(tran, rot, scale);

             updatedVerts.Add(mat.MultiplyPoint3x4(vert));
             vertCount++;
         }

         meshFilter.mesh.vertices = updatedVerts.ToArray();
     }


alt text

I was thinking I could just run through each row and apply the cos and sin to the x and y respectively. I pass 3.0f as an angle into both just as a place holder. Eventually I'll calculate the length of the original strip(circumference) to figure out my theta for cos and sin. Please and thank you for any help.

screen shot 2014-09-30 at 10.08.58 pm.png (195.0 kB)
screen shot 2014-09-30 at 10.13.01 pm.png (209.0 kB)
Comment
Add comment · Show 2
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 robertbu · Oct 01, 2014 at 05:59 AM 0
Share

What is your goal here? Why are you modifying the vertices rather than simply rotating/positioning the Transform.

avatar image UnityUser666 · Oct 01, 2014 at 05:00 PM 0
Share

$$anonymous$$y goal is to have a smooth tube with x number of individual texture meshes. If I alter the transform and rotation of the the individual planes, I think the final product would look a little blocky. Hope that clears things up.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by UnityUser666 · Oct 01, 2014 at 07:49 PM

Figured it out. I'm sure this isn't optimized, but it works. Hopefully this helps someone.

         //This is where we make the cylinder
         MeshFilter[] totalSymbolMesh = reel.GetComponentsInChildren<MeshFilter>();
         List<Vector3> totalMeshVertList = new List<Vector3>();
         foreach (MeshFilter symbolMeshFilter in totalSymbolMesh)
         {
             foreach (Vector3 symbolMeshVert in symbolMeshFilter.mesh.vertices)
             {
                 totalMeshVertList.Add(symbolMeshVert);
             }
         }
 
         float reelCircumference = getStripLength(totalMeshVertList);
         float reelDiameter = reelCircumference / Mathf.PI;
         float reelRadius = reelDiameter / 2;
 
         int numOfStripHorizontalVerts = NumberOfSymbolsOnReel * NUM_VERTS_HEIGHT;
         float incrimentalAngle = 360.0f / (NumberOfSymbolsOnReel * DEFAULT_PLANE_HEIGHT_SEGMENTS);
 
         float angle = 0.0f;
         float angleStep = 0.0f;
         for (int meshCount = 0; meshCount < totalSymbolMesh.Length; meshCount++)
         {
             List<Vector3> updatedVerts = new List<Vector3>();
 
             for (int vertIndex = 0; vertIndex < DEFAULT_NUMBER_PLANE_VERTS; vertIndex++)
             {
                 angle = incrimentalAngle * (vertIndex / NUM_VERTS_HEIGHT);
                 angle = angle + angleStep;
 
                 float xPos = totalSymbolMesh[meshCount].mesh.vertices[vertIndex].x;
                 float yPos = reelRadius * Mathf.Sin(angle * Mathf.Deg2Rad);
                 float zPos = reelRadius * Mathf.Cos(angle * Mathf.Deg2Rad);
 
                 updatedVerts.Add(new Vector3(xPos, yPos, zPos));
             }
 
             angleStep = angle;
 
             totalSymbolMesh[meshCount].mesh.vertices = updatedVerts.ToArray();
             totalSymbolMesh[meshCount].mesh.RecalculateBounds();
             totalSymbolMesh[meshCount].mesh.RecalculateNormals();
         }


alt text


cylinder.png (28.6 kB)
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

2 People are following this question.

avatar image avatar image

Related Questions

Connecting flatshaded vertices 0 Answers

how to remove vertices of a certain colour range from a mesh? 0 Answers

Finding Viewport Coordinates of Vertices of Meshes that are in View 1 Answer

Modifying plane to fit view frustrum issue 0 Answers

Vertex Color index problem 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