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 /
  • Help Room /
avatar image
0
Question by Orzgames · May 16, 2016 at 06:33 AM · skinned mesh renderer

Mesh.bindposes official sample not working

Hi, I just copy and paste Mesh.bindposes official sample into unity 5.30, adjust the camera position and run.

The quad is static and no any animation. Do you know what's wrong?

Document: http://docs.unity3d.com/ScriptReference/Mesh-bindposes.html

My code:

using UnityEngine; using System.Collections;

//[ExecuteInEditMode] public class Test : MonoBehaviour {

 // Use this for initialization
 void Start () {
     gameObject.AddComponent<Animation>();
     gameObject.AddComponent<SkinnedMeshRenderer>();
     SkinnedMeshRenderer rend = GetComponent<SkinnedMeshRenderer>();
     Animation anim = GetComponent<Animation>();

     // Build basic mesh
     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();
     rend.material = new Material(Shader.Find("Diffuse"));

     // assign bone weights to mesh
     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;

     // Create Bone Transforms and Bind poses
     // One bone at the bottom and one at the top

     Transform[] bones = new Transform[2];
     Matrix4x4[] bindPoses = new Matrix4x4[2];
     bones[0] = new GameObject("Lower").transform;
     bones[0].parent = transform;
     // Set the position relative to the parent
     bones[0].localRotation = Quaternion.identity;
     bones[0].localPosition = Vector3.zero;
     // The bind pose is bone's inverse transformation matrix
     // In this case the matrix we also make this matrix relative to the root
     // So that we can move the root game object around freely
     bindPoses[0] = bones[0].worldToLocalMatrix * transform.localToWorldMatrix;

     bones[1] = new GameObject("Upper").transform;
     bones[1].parent = transform;
     // Set the position relative to the parent
     bones[1].localRotation = Quaternion.identity;
     bones[1].localPosition = new Vector3(0, 5, 0);
     // The bind pose is bone's inverse transformation matrix
     // In this case the matrix we also make this matrix relative to the root
     // So that we can move the root game object around freely
     bindPoses[1] = bones[1].worldToLocalMatrix * transform.localToWorldMatrix;

     mesh.bindposes = bindPoses;

     // Assign bones and bind poses
     rend.bones = bones;
     rend.sharedMesh = mesh;

     // Assign a simple waving animation to the bottom bone
     AnimationCurve curve = new AnimationCurve();
     curve.keys = new Keyframe[] { new Keyframe(0, 0, 0, 0), new Keyframe(1, 10, 0, 0), new Keyframe(2, 0.0F, 0, 0) };

     // Create the clip with the curve
     AnimationClip clip = new AnimationClip();
     clip.SetCurve("Lower", typeof(Transform), "localPosition.z", curve);
     clip.legacy = true;

// float animationLenghtInSeconds = 2; // var rot = Quaternion.Euler(0, 0, 30); // var localRotXCurve = AnimationCurve.EaseInOut(0, transform.localRotation.x, animationLenghtInSeconds, rot.x); // var localRotYCurve = AnimationCurve.EaseInOut(0, transform.localRotation.y, animationLenghtInSeconds, rot.y); // var localRotZCurve = AnimationCurve.EaseInOut(0, transform.localRotation.z, animationLenghtInSeconds, rot.z); // var localRotWCurve = AnimationCurve.EaseInOut(0, transform.localRotation.w, animationLenghtInSeconds, rot.w);

// clip.SetCurve("Lower", typeof(Transform), "localRotation.x", localRotXCurve ); // clip.SetCurve("Lower", typeof(Transform), "localRotation.y", localRotYCurve ); // clip.SetCurve("Lower", typeof(Transform), "localRotation.z", localRotZCurve ); // clip.SetCurve("Lower", typeof(Transform), "localRotation.w", localRotWCurve );

     // Add and play the clip
     clip.wrapMode = WrapMode.Loop;
     anim.AddClip(clip, "test");
     anim.Play("test");
 }
 
 // Update is called once per frame
 void Update () {
 
 }

}

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

0 Replies

· Add your reply
  • Sort: 

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

53 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

Related Questions

Skinned Mesh mask for character clothing clip in 0 Answers

Animated Skinned Mesh Renderer.Enable 0 Answers

Is Shader Graph Vertex Position not working with Skinned Mesh Renderer? 0 Answers

Change material in runtime 2 Answers

Skinned Mesh Switch 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