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 /
This question was closed Sep 24, 2016 at 01:20 AM by amiel_ace for the following reason:

Needed a new feature of unity: Expose blend shape vertex datam, already on vote

avatar image
0
Question by amiel_ace · Sep 23, 2016 at 12:14 AM · meshscript.functions

What this does? Mesh.GetBlendShapeFrameVertices

So I'm combining skinned meshes at runtime, now everything is working, except for the blend shapes from the head mesh not being saved(or get lost), So now I'm finding a way to somehow save blendshapes from mesh parts first BEFORE combining them, so I can then save it to the new combined mesh. I saw this function Mesh.GetBlendShapeFrameVertices looks like can help me do the job, but this function doesn't return a value or something? I don't know what this does? There's also this function Mesh.AddBlendShapeFrame

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

1 Reply

  • Sort: 
avatar image
1

Answer by Bunny83 · Sep 23, 2016 at 04:13 AM

Isn't the documentation quite clear what the method does?

Mesh.GetBlendShapeFrameVertices

 shapeIndex      The shape index of the frame.
 frameIndex      The frame index to get the weight from.
 deltaVertices   Delta vertices output array for the frame being retreived.
 deltaNormals    Delta normals output array for the frame being retreived.
 deltaTangents   Delta tangents output array for the frame being retreived.

Furthermore:

 Retreives deltaVertices, deltaNormals and deltaTangents of a blend shape frame.
 
 deltaVetrices, deltaNormals and deltaTangents arrays must be of size = Mesh.vertexCount.
 Add Mesh vertices, normals or tangents to convert from frame deltas to full vectors.
 deltaNormals or deltaTangents may be set to null if there is no normals or tangents to be
 retreived for a frame.

So you simply have to pass the blendshape index and the frame index of the frame you want to retrieve. Furthermore you need to pass 3 arrays which will be filled with the data you're interested in. The arrays have to be initialized with the vertexCount of the mesh, so each array has "vertexCount" elements.

Mesh.AddBlendShapeFrame basically does exacly the opposite. You have to pass the blendshape name and the blend weight along with the 3 arrays. This will add a new frame to a specific blendshape.

Of course when you combine two skinned meshes, you would need to merge the arrays from both meshes according to their vertices.

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 amiel_ace · Sep 23, 2016 at 06:39 AM 0
Share

Yow, thank you for explaining it to me, so now all I have to do is something like:

 old$$anonymous$$esh.GetBlendShapeFrameVertices( old$$anonymous$$esh.arguments.... );
 
 combine$$anonymous$$esh.AddBlendShapeFrame( old$$anonymous$$esh.arguments....);

Thank you, I hope this will make the blend shapes working on the new combine mesh

avatar image amiel_ace amiel_ace · Sep 23, 2016 at 08:10 AM 0
Share

Although, now my problem is merging the arrays together.hmmm...

avatar image amiel_ace · Sep 23, 2016 at 09:19 AM 0
Share

So I modified my script, new blend shape was added, but it doesn't seem to work, when I set it's weight to 100 manually in the editor, nothing happens? This is how I do it

    Vector3[] blendVertices = new Vector3[smr.shared$$anonymous$$esh.vertexCount];
    Vector3[] blendNormals = new Vector3[smr.shared$$anonymous$$esh.vertexCount];
    Vector3[] blendTangents = new Vector3[smr.shared$$anonymous$$esh.vertexCount];
    Debug.Log("Getting Blendshape");
                     
    smr.shared$$anonymous$$esh.GetBlendShapeFrameVertices(0, 0, blendVertices, blendNormals, blendTangents);
 

And then after combining the mesh:

 Vector3[] temp = new Vector3[combined.shared$$anonymous$$esh.vertexCount];
 Vector3[] temp2 = new Vector3[combined.shared$$anonymous$$esh.vertexCount];
 Vector3[] temp3 = new Vector3[combined.shared$$anonymous$$esh.vertexCount];

     //This seems to be the part that's not working right, I assume this will merge them?
     for(int i = 0; i < blendVertices.Length; i++)
     {
         temp[i] = blendVertices[i];
         temp2[i] = blendNormals[i];
         temp3[i] = blendTangents[i];
     }
             
     combined.shared$$anonymous$$esh.AddBlendShapeFrame("blink", 0, temp, temp2, temp3);

avatar image siepiau amiel_ace · Feb 24, 2017 at 11:11 AM 0
Share

Hi! This is how I copy blend shapes to a new mesh:

 // Copy blend shape data from my$$anonymous$$esh to tmp$$anonymous$$esh
 
 Vector3[] dVertices = new Vector3[my$$anonymous$$esh.vertexCount];
 Vector3[] dNormals = new Vector3[my$$anonymous$$esh.vertexCount];
 Vector3[] dTangents= new Vector3[my$$anonymous$$esh.vertexCount];
 for (int shape = 0; shape < my$$anonymous$$esh.blendShapeCount; shape++) {
     for (int frame = 0; frame < my$$anonymous$$esh.GetBlendShapeFrameCount(shape); frame++) {
         string shapeName = my$$anonymous$$esh.GetBlendShapeName(shape);
         float frameWeight = my$$anonymous$$esh.GetBlendShapeFrameWeight(shape, frame);
 
         my$$anonymous$$esh.GetBlendShapeFrameVertices(shape, frame, dVertices, dNormals, dTangents);
         tmp$$anonymous$$esh.AddBlendShapeFrame(shapeName, frameWeight, dVertices, dNormals, dTangents);
     }
 }

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How do i activate a function attached to a listed GameObject from the perspective of itself? 1 Answer

how to create moser spindle graph ? 0 Answers

Get other GameObject's script name 2 Answers

Assign a Mesh to Mesh Collider Automatically 1 Answer

C# Recreating Blender's Skin Modifier in Unity 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