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 montblack · Apr 17, 2011 at 10:00 PM · rotatebone

rotate bones before bindposes

please a need help with this.

I have used this code http://unity3d.com/support/documentation/ScriptReference/Mesh-bindposes.html, modify but I noticed that the bones did not rotate. I've tried in this way to see the bones:

void Update(){

 try{
     for ( int i = 0; i < bones.Length; i++ ){
         Debug.DrawLine (bones[i].transform.position,bones[i].parent.transform.position, Color.green);
     }

 }catch(Exception e){}

}

and this way to rorate:

bones[1] = new GameObject("Upper").transform;
    bones[1].parent = transform;
    bones[1].localRotation = Quaternion.Euler(0,  180, 0);
    bones[1].localPosition = new Vector3(0, 5, 0);

and does not work, the bones are not rotating.

What am I doing wrong?

spanish to english(spanish to english)

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
0

Answer by Paulius-Liekis · Apr 18, 2011 at 06:10 AM

Do you do this as well (taken from your link):

bindPoses[1] = bones[1].worldToLocalMatrix * transform.localToWorldMatrix;

This kind of "compensates" for the rotation that you just set. You need to change position/rotation of bone after that (better in runtime to see the results).

Do you really need to create meshes from code?

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
0

Answer by montblack · Apr 18, 2011 at 02:57 PM

yes i do that the complete code is:

using UnityEngine; using System.Collections; using System; public class example : MonoBehaviour { Transform[] bones; void Start() { gameObject.AddComponent<Animation>(); gameObject.AddComponent<SkinnedMeshRenderer>(); SkinnedMeshRenderer renderer = GetComponent<SkinnedMeshRenderer>(); Mesh mesh = new Mesh(); mesh.vertices = new Vector3[] {new Vector3(-1, 0, 0), new Vector3(1, 0, 0), new Vector3(-1, 5, 0), new Vector3(1, 5, 0)}; mesh.uv = new Vector2[] {new Vector2(0, 0), new Vector2(1, 0), new Vector2(0, 1), new Vector2(1, 1)}; mesh.triangles = new int[] {0, 1, 2, 1, 3, 2}; mesh.RecalculateNormals(); renderer.material = new Material(Shader.Find(" Diffuse")); BoneWeight[] weights = new BoneWeight[4]; weights[0].boneIndex0 = 0; weights[0].weight0 = 1; weights[1].boneIndex0 = 0; weights[1].weight0 = 1; weights[2].boneIndex0 = 1; weights[2].weight0 = 1; weights[3].boneIndex0 = 1; weights[3].weight0 = 1; mesh.boneWeights = weights; bones = new Transform[2]; Matrix4x4[] bindPoses = new Matrix4x4[2]; bones[0] = new GameObject("Lower").transform; bones[0].parent = transform; bones[0].localRotation = Quaternion.identity; bones[0].localPosition = Vector3.zero; bindPoses[0] = bones[0].worldToLocalMatrix * transform.localToWorldMatrix; bones[1] = new GameObject("Upper").transform; bones[1].parent = transform; bones[1].localRotation = Quaternion.Euler(0, 180, 0); bones[1].localPosition = new Vector3(0, 5, 0); bindPoses[1] = bones[1].worldToLocalMatrix * transform.localToWorldMatrix; mesh.bindposes = bindPoses; renderer.bones = bones; renderer.sharedMesh = mesh; AnimationCurve curve = new AnimationCurve(); curve.keys = new Keyframe[] {new Keyframe(0, 0, 0, 0), new Keyframe(1, 3, 0, 0), new Keyframe(2, 0.0F, 0, 0)}; AnimationClip clip = new AnimationClip(); clip.SetCurve("Lower", typeof(Transform), "m_LocalPosition.z", curve); animation.AddClip(clip, "test"); animation.Play("test"); }

 void Update(){ 

 try{
     for ( int i = 0; i &lt; bones.Length; i++ ){
     Debug.DrawLine (bones[i].transform.position,bones[i].parent.transform.position, Color.green);
 }

     }catch(Exception e){}
 }

}

I see the inspector that applies a rotation, but graphically the object is in the same position and without rotating, try using that code and rotate in different angles, and you will see that they will always get the same result. And yes, i need to create the mesh with code, becouse i'm allready reading a xml format, and greatly reducing the number of vertices when importing.

i need a rotation like this:

alt text

please help me i really need this.

Greetings from Colombia!

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

No one has followed this question yet.

Related Questions

I need a point midway between two bones' rest positions 1 Answer

How to make a bone rotate facing towards a given Transform? 0 Answers

Bone doesn't rotate through script 1 Answer

How can I rotate a bone from script? Applications: Move crane arm, point gun... 2 Answers

Why does rotating a bone on one axis affect others and translation 2 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