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 Deshun · Dec 12, 2011 at 02:44 PM · meshprocedural

Procedurally modified mesh is displayed wrong

Hello,

i tryed to make me familary with procedural mesh generation. After modifing the "CrumpleMesh" example from the Unity-Page, i got the following problem:

I just wanted to move every plane-vertice for testing purpose 2 up. But the result ended up to be that the mesh is in place where it was at the beginning and a "clone" of the plane spawned two above the original. In the "CrumpleMesh"-example the origin-mesh is modified. Here is the code:

 private Vector3[] baseVertices;
 
 void Start()
 {
     renderer.material.color = Color.white;
     Mesh mesh = GetComponent<MeshFilter>().mesh;
     baseVertices = mesh.vertices;

     Vector3[] vertices = new Vector3[baseVertices.Length];

     for (int y = 0; y < mesh.vertices.Length; y++)
     {
         Vector3 vertex = baseVertices[y];
         vertex.y += 2;
         vertices[y] = vertex;
     }

     mesh.vertices = vertices;

     mesh.RecalculateNormals();
     mesh.RecalculateBounds();
 }

The Code is attached to the plane. What is wrong? I hope the problem is understandable.

Thank you for your help.

alt text

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
2
Best Answer

Answer by Tasarran · Dec 12, 2011 at 08:39 PM

Add this line right after you RecalculateNormals

 gameObject.GetComponent(MeshCollider).sharedMesh = gameObject.GetComponent(MeshFilter).mesh;
Comment
Add comment · Show 3 · 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
avatar image Deshun · Dec 12, 2011 at 11:51 PM 0
Share

thank you. your solution worked perfectly.

avatar image Tasarran · Dec 13, 2011 at 12:30 AM 0
Share

I just learned that yesterday; glad it was useful two days in a row :)

avatar image MountDoomTeam · Nov 02, 2012 at 06:16 PM 0
Share

I just had a similar problem, the collider was fine, but I was not recalculating the bounds so the camera was not seeing new bounds and objects were disappearing. these are the lines I use,I can't tell what the differences compared to the above line, I think it's the same thing.

mesh.vertices = vertices;

mesh.RecalculateNormals();

mesh.RecalculateBounds();

DestroyImmediate(collider);

    gameObject.AddComponent("$$anonymous$$eshCollider");

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Determine whether or not model is "inside out" 2 Answers

Combining meshes (different materials) together for rotation/translation 1 Answer

Custom Mesh UV Problem 1 Answer

Mesh return vs out Mesh 2 Answers

Strange shading on procedural mesh 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