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 /
avatar image
1
Question by Tocaro · Apr 17, 2016 at 09:07 PM · morph

Attaching an object to a morphing mesh.

So I've got a plant-like eye stalk that swings back and forth via blendshapes/morphing and I want to attach an object to the eyeball portion. Essentially I want to have a single point on the 3d mesh that I can parent to that moves along with the morph.

My first guess was to use a single bone, but it didn't follow the blendshape morph at all. My other guess would be to somehow detect the vertices at the eyeball area and then somehow assign the object to follow those vertices (But I have no idea how to do that).

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Apr 18, 2016 at 03:59 AM

Well it's a bit tricky. One solution is what @Glurth explained in his answer but you can't use .sharedMesh nor .mesh as this will only return the original mesh. The actual skinning might even be done on the GPU. The temporary (skinned) mesh isn't available to the scripting side.

However Unity added (along with the blendshape support i guess) the method BakeMesh. This will calculate a static mesh of the current skinned position of the mesh. This mesh can be used to find the position of a certain vertex.

Everything would be easier if you would use a "normal" bone animation as each bone is an actual gameobject where you can attach things directly.

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
avatar image
2

Answer by Glurth · Apr 17, 2016 at 09:28 PM

My other guess would be to somehow detect the vertices at the eyeball area and then somehow assign the object to follow those vertices

This is how I would do it. Once you have figured out which vertex in the mesh you want to attach to, you can get the model-space value of the vertex like so:

 Vector3 pos=meshFilter.sharedMesh.vertices[vertexNumber];

You can then transform that into a world position with:

 pos=meshFilter.transform.TransformPoint(pos);

And there is your attachment point, in world space. You could assign it directly to your attached object's transform.position, when you want to update the objects position. But you probably want to add some offset to the pos, and perhaps even re-orient it based on the normal.

If you want the the normal of that vertex, you would use:

 Vector3 norm=meshFilter.sharedMesh.normal[vertexNumber];
 norm=meshFilter.transform.TransformDirection(pos);

To figure out which vertex you want, you can use the above code and, via trial and error (or on keypress), vary VertexNumber until you find the one you like. (Keep in mind, multiple vertices MAY have the same position, and different normals)

Comment
Add comment · Show 4 · 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 Tocaro · Apr 17, 2016 at 10:36 PM 0
Share

Thanks Glurth, just what I needed! I do have one follow up though.

You say trial and error in Unity to find the vertex, is there any way to find the vertexNumber directly through the 3d modeling program (3ds$$anonymous$$ax for me) or does unity assign the numbers on import? Either way I can do trial and error, I'm just curious. Thanks again.

avatar image Tocaro · Apr 17, 2016 at 10:52 PM 0
Share

Hm, just tested this out, the object doesn't seem to actually follow when the models blendshape is changed, it just sticks to where it would be on the unchanged model.

avatar image Glurth Tocaro · Apr 18, 2016 at 02:56 AM 0
Share

I'm not sure what the "blendshape" is, but I suspect that whatever function is doing the blending/morphing, is outputting a mesh of some kind. It SOUNDS like you are looking at the vertices of your original mesh, rather than the blended/morphed mesh. Hmm, maybe the generated mesh gets stored in meshFilter.mesh, rather than meshFilter.shared$$anonymous$$esh- that stuff always throws me off.

avatar image Glurth Glurth · Apr 18, 2016 at 02:59 AM 0
Share

odd, I see some code of yours in my email but not your comment. In that code I saw you are using a Skinned$$anonymous$$eshRenderer. I'm NOT familiar with those... so I could be way off base here!

avatar image
0

Answer by Redrag · Apr 20, 2021 at 12:39 PM

You can also try a cloth component. If you snap it on and off it will give you the exact position of all the vertices. Less expensive than baking the mesh from my experience.

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

43 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

Related Questions

Using the MorphTargets script with a SkinnedMeshRenderer? 2 Answers

Unity 5 webGl Export Error 0 Answers

Is this the best way to access the Megafiers Morph Channels Dynamically 1 Answer

Deformation Maps Possible? 0 Answers

Problem with skinned character morphing 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