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
0
Question by detroit91 · Nov 13, 2014 at 07:01 PM · meshverticesmesh-deformationcylinderbend

How do you bend a cylindrical gameobject?

I'm trying to simply bend a cylinder in C#. The only way I can see to do this is to use mesh vertices.

     void Update () {
         Mesh cyl = GetComponent<MeshFilter> ().mesh;
         Vector3[] vertices = cyl.vertices;
         int i = 0;
         Debug.Log (vertices.Length);
         while(i < vertices.Length){
             vertices[i] += Vector3.up * Time.deltaTime;
             i++;
         }
         cyl.vertices = vertices;
         cyl.RecalculateBounds ();
     }

Obviously this code moves the cylinder up. I want to bend, but I'm not sure how to select certain vertices and then move them appropriately. Is it even possible to deform the cylinder with this method? If not how can it be done?

Comment
Add comment · Show 6
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 detroit91 · Nov 13, 2014 at 11:41 PM 0
Share

Thanks for your response, I'm using the built in cylinder. It says that it has a 88 vertices though. At least where I print the length of the vertices.

 Debug.Log(vertices.Length);

After that though, how would I select certain vertices? like say the top half?

edit-- I'm going to try to import a cylinder from $$anonymous$$aya

avatar image MrSoad · Nov 13, 2014 at 11:49 PM 0
Share

You select verts by their position in relation to the anchor/origin(all the same thing just different names) point. All verts coordinates are in local space and calculated in relation to this anchor point which is always position (0, 0, 0) of your model. So if you wanted all the top half verts you would select all the verts that have a greater y value than 0(assu$$anonymous$$g that you don't get any axis mix ups which may happen, in which case it will be either x or z rather than y).

avatar image robertbu · Nov 14, 2014 at 12:18 AM 1
Share

I believe the built-in cylinder has verts at just the top and the bottom. There's no ring of verts in the middle. You will need rings of verts as bend points.

avatar image Bunny83 · Nov 14, 2014 at 02:00 AM 0
Share

@robertbu: I know it only has vertices at the top and bottom, so you're right, there's no way around using a custom mesh or a procedurally generated mesh.

edit
I've edited my comment as i don't like posts with 20+ comments...

@detroit91:
Can you be a bit more specific about your "bending"? There are like ten million ways how to bend an object. Bending usually happens either by having a "fix end" and a moving & bending end and a bending direction which goes from the fixed to the moving end. This line is bend in one or two directions.

The second way is to kind or "warp" an object around an arbitrary axis. The first case is the more common one.

avatar image Dragonsnare0 · Nov 14, 2014 at 04:17 AM 0
Share

robertbu is right you can see the wireframe of the cylinder when you create it in unity. top and bottom only.

You'll need to create it yourself in a 3d modeler. A good free one is blender.

If it needs to be dynamic then create one in let's say blender with multiple "ribs" and alter it's shape with code as needed.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by robertbu · Nov 13, 2014 at 07:22 PM

Is the 'cly' object Unity's build-in cyclinder, or a cylinder you created? I don't believe the built-in cylinder has any vertices on the sides...just top and bottom. You are going to need vertices at each bend point. You can author your tube in a 3D modeling program, or you could create one from script. The Tube object at the following link will give you a starting point, though you will need to expand it:

http://wiki.unity3d.com/index.php/ProceduralPrimitives

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Mesh deformation simulating a fire 0 Answers

Mesh Deformation 2 Answers

Expanding mesh animation 0 Answers

Adding vertices to procedural mesh generator 2 Answers

Handles does not modify mesh... 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