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 Mish · Sep 09, 2013 at 07:24 PM · treeverticesvertexwindcreator

Tree vertices never change position in wind

I am trying to access the vertices of a tree created with the unity tree creator. The tree is placed in a wind zone and moves correctly according to the wind. However, I want to use the vertices of the mesh for attaching an object their position so that is follows the movement of the tree.

But the vertices never change value in the array list, even though they move visually. How can this be?

 void Awake () {
     
         tree = GameObject.FindGameObjectWithTag("Tree");
         treeMesh = tree.GetComponent<MeshFilter>().mesh;
         float closestDistance = 99999;
         for(int i = 0; i < treeMesh.vertices.Length; i++){
             float tempDistance = Vector3.Distance(transform.position, treeMesh.vertices[i]);
             if(tempDistance < closestDistance) {
                 closestDistance = tempDistance;
                 closestIndex = i;
             }
         }
         
     }
 
 
 void Update () {
         
     
         transform.position = tree.transform.TransformPoint(treeMesh.vertices[closestIndex]);
 
 }
     
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 getyour411 · Sep 10, 2013 at 04:55 AM 0
Share

Try doing this in Start() ins$$anonymous$$d of Awake() in case the WindZone stuff hasn't kicked in, just a shot in the dark.

avatar image Mish · Sep 10, 2013 at 08:21 AM 0
Share

I tried both in Awake and Start but its the same result..

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by cod · Sep 10, 2013 at 08:34 AM

I think this is because the tree animation is done via shader, so the vertices are modified not in the cpu loop, but on the GPU, as it is done by the shader as i said before. The only way to achieve this effect is to write a new shader with the same vertex animation as in the tree shader

PS u can easily find the tree shader in the builtin shader resource on the unity site

Comment
Add comment · Show 6 · 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 Mish · Sep 10, 2013 at 04:27 PM 0
Share

Ah thanks for the answer didn't think about that option. However, as I am new to shader program$$anonymous$$g I am not sure where to find the piece of code that animates the vertices, any hints?

avatar image cod · Sep 11, 2013 at 09:17 AM 1
Share

Here's the vertex function

 void TreeVertBark (inout appdata_full v)
 {
 v.vertex.xyz *= _Scale.xyz;
     v.vertex = AnimateVertex(v.vertex, v.normal,    float4(v.color.xy, v.texcoord1.xy));
     
     v.vertex = Squash(v.vertex);
     
     v.color = float4 (1, 1, 1, v.color.a);
     v.normal = normalize(v.normal);
     v.tangent.xyz = normalize(v.tangent.xyz); 
     }

and here're the docs link text

try to have a look at them and tell me if u have any problem :)

EDIT: fixed the wrong format

avatar image Mish · Sep 11, 2013 at 06:12 PM 0
Share

Thanks! Which shader script is this included in? I cant seem to find it.

avatar image cod · Sep 11, 2013 at 08:19 PM 0
Share

it should be in

 YourUnityFolder\Editor\Data\CGIncludes\TerrainEngine.cginc

or simply link text

avatar image Mish · Sep 12, 2013 at 09:59 AM 0
Share

Ok I got to a point where I can edit the code and see it affect the tree animation while running the game. However, I am unsure where to go from here. How do I give the positions of the vertices to my object?

I thought maybe its possible to use the same shader for my custom object as for the leaves in order to make it move, but it doesnt seem to do anything when put on something other than the unity tree.

Show more comments

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

17 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

Related Questions

WindZone and Tree direction 0 Answers

Is there an easy way to find connected vertices in Mesh.vertices? 2 Answers

Precise vertex positions 1 Answer

Why vertex positions appear (0.0, 0.0, 0.0) ? 1 Answer

tree bend factor wont work 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