Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
1
Question by sun_stealer · Jan 18, 2017 at 04:57 PM · animationmeshskinnedmeshrenderer

Generate skinned mesh in runtime

I want to create a script that loads character head from an external source.

I already have a character without a head, and it sits comfortably in the origin as shown here: character Everything works as I expect, including animations.

Then I load mesh data from external source and add it to scene using the following code:

         var character = GameObject.Find ("fuse_base_character");
 
         var headObject = new GameObject ("head");
         headObject.AddComponent<SkinnedMeshRenderer> ();
         headObject.transform.SetParent (character.transform);
 
         var headRenderer = headObject.GetComponent <SkinnedMeshRenderer> ();
         headRenderer.sharedMesh = mesh;
         var rig = GameObject.Find ("mixamorig:Hips");
         headRenderer.rootBone = rig.transform;

Head is in exactly the same coordinate frame as the body, I can confirm that by opening both models in a 3D editor. But when I execute this code, head appears far higher than it should:

head

Head has exactly the same "armature" as the body, so even animations work. But head flies 3 meters above the ground instead of being in it's proper place.

I found that this happens because head uses position of the root bone as it's origin, instead of world origin! Thus it appears shifted relative to the rest of the body, because body uses world origin.

I tried to headObject.transform.Translate and headRenderer.transform.Translate, but this does not change anything. How should I add this mesh to the scene so it uses correct coordinate system? Please excuse me if the question is dumb, I am very new to Unity!

character-head.png (198.4 kB)
character.png (170.2 kB)
Comment
Add comment · Show 1
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 sun_stealer · Jan 18, 2017 at 05:01 PM 0
Share

I can confirm that this is not the problem with Head model. To verify this I procedurally created a polygon whose bottom-right corner should be exactly in (0, 0, 0). When I add it to scene using the code above I end up with exactly the same situation:

poly

As you can see, polygon location precisely matches the location of "Hips" bone.

cube.png (228.2 kB)

1 Reply

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

Answer by sun_stealer · Jan 20, 2017 at 09:09 AM

Thanks to help on Unity IRC channel I managed to figure this out.

In order to add another mesh that is animated by the same skeleton you have to:

  1. Fill "bones" array of your new SkinnedMeshRenderer object. Bones at each index should match bones that are listed in "boneWeights" array of your mesh.

  2. Fill "bindposes" array of new mesh object. In my case I had to just copy it from body mesh to head mesh.

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 BradyIrv · Dec 04, 2019 at 11:52 PM 0
Share

how did you dynamically (from code) fill the bones array and bindposes?

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

167 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 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 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 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

Maya Vertex Animation import 1 Answer

Update bindposes of SkinnedMeshRenderer and re-target animations 0 Answers

Skinned mesh to mesh and vice-versa 0 Answers

I have a problem with skinned render mesh on Android. 0 Answers

How to Avoid splitting Normals on Geometry with blendshapes 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