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 daterre · Nov 12, 2012 at 05:01 PM · unity4skinnedmeshrenderer

Transform problem with vertex positions from SkinnedMeshRenderer.BakeMesh

I'm trying to retrieve a mesh triangle's vertex coordinates from the current animation using the new Unity 4 method SkinnedMeshRenderer.BakeMesh. I'm having a weird problem where the coordinates returned are exponentially larger than the actual mesh. When the animated object's scale is 1, the returned data is the same size, but for scale 2, the vertex data is scaled up by roughly 3, for scale 5 scaled by about 20, etc. At first I thought this was a simple transformation bug on my part, but when I swap the BakeMesh output for the SkinnedMeshRenderer.sharedMesh, I get correct data. Is this a Unity 4 bug or am I missing something?

Thanks for any help.

 public Vector3[] GetTriangleVertices (int triangle)
 {
     SkinnedMeshRenderer skin = this.GetComponent<SkinnedMeshRenderer> ();
         
     Mesh baked = new Mesh();
     skin.BakeMesh(baked);
     
     var normals = new Vector3[baked.normals.Length]; baked.normals.CopyTo(normals, 0);
     var triangles = new int[baked.triangles.Length]; baked.triangles.CopyTo(triangles, 0);
     var vertices = new Vector3[baked.vertices.Length]; baked.vertices.CopyTo(vertices, 0);
         
     int i = triangle * 3;
 
     Vector3[] verts = new Vector3[3];
     verts[0] = vertices [triangles [i]];
     verts[1] = vertices [triangles [i + 1]];
     verts[2] = vertices [triangles [i + 2]];
 
     if (this.transform != null)
         for (int v = 0; v <3; v++)
             verts [v] = this.transform.TransformPoint (verts [v]);
     
     return vertices;
 }
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

2 Replies

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

Answer by daterre · Jan 08, 2013 at 10:24 AM

Turns out the vertex coords I was getting were using the scale of the model from the model import settings without the transform applied. To get the right coords I left the GameObject's transform scale at 1 and changed only the scaling in the model import settings.

Far from ideal, probably a bug, FYI.

Comment
Add comment · Show 1 · 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 MarkD · Dec 25, 2013 at 10:10 PM 0
Share

I had the same problem, simply add a multiply to the vector.

 var pos:Vector3= Vector3(Parent.transform.position.x-vertices[i].x*$$anonymous$$eshScale,Parent.transform.position.y-vertices[i].y*$$anonymous$$eshScale,Parent.transform.position.z-vertices[i].z*$$anonymous$$eshScale);
 

Same goes for normals, sorry I only know this in javascript.

avatar image
0

Answer by ZFarago · Jun 19, 2013 at 02:09 PM

Just before call the bakemesh function, make sure the skinned mesh object has localScale of (1,1,1). This should not affect the skinned mesh renderer's appearance.

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

11 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

Related Questions

Skinned Mesh Renderer Importing as Mesh Renderer 2 Answers

3D Platformer Tutorial getting Lerpz's SkinnedMeshRenderer using c# 0 Answers

Best way to send real-time blendshape data over a networkView? 0 Answers

Why does adding cloth component to skinned meshrenderer move the bounds away from the mesh? 2 Answers

Help! Skinned mesh render not visible!! 3 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