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 /
avatar image
0
Question by msjunior091995 · Jan 14, 2019 at 12:40 PM · meshmesh verticesmesh manipulationmesh-deformation

make one mesh follow the deformations of the other,adjust mesh to follow deformations of another(cloth, hair)

Hi, I usually use daz studio models in my projects, the problem is that every time I download a new morph for the main model (Genesis 3), I have to reimport all others like hair and clothes. To facilitate this process I decided to write the script below, it searches for each vertex of the clothing, the vertex closest to the main mesh and based on the distance between the two turns this vertex into a parent (this process is very slow), causing the secondary mesh follows the deformations of the main mesh, but it is not behaving as it should, the mesh gets very strange. What can I do to improve the script?

I'm sorry for bad English.

 public class MorphConform : MonoBehaviour {
 
     public GameObject TargetMesh;
     Vector3[] TargetVertices;
 
     public GameObject SourceMesh;
     Vector3[] SourceVertices;
 
     int[] VertParent;
     Vector3[] LocalPos;
 
 
 
     void Update(){
 
         if (Input.GetKeyDown("a"))
         {
 
             GetOriginal ();
         }
 
         if (Input.GetKeyDown("b"))
         {
 
             Conform();
         }
 
     }
 
     void GetOriginal () {
 
         TargetVertices = TargetMesh.GetComponent<MeshFilter> ().mesh.vertices;
         Mesh provmesh = new Mesh ();
         SourceMesh.GetComponent<SkinnedMeshRenderer> ().BakeMesh (provmesh);
         SourceVertices = provmesh.vertices;
 
         VertParent = new int[TargetVertices.Length];
         LocalPos = new Vector3[TargetVertices.Length];
 
         for (int t = 0; t < TargetVertices.Length; t++) {
 
             bool FirtsTime = true;
             float AtDist = 0.0000000f;
             float MinDist = 0.0000000f;
 
             for (int s = 0; s < SourceVertices.Length; s++) {
 
                 Vector3 wt = TargetMesh.transform.TransformPoint (TargetVertices[t]);
                 Vector3 ws = SourceMesh.transform.TransformPoint (SourceVertices[s]);
 
                 AtDist = Vector3.Distance (ws, wt);
 
                 if(AtDist < MinDist || FirtsTime){
                     FirtsTime = false;
                     MinDist = AtDist;
                     VertParent[t] = s;
                     LocalPos[t] = wt - ws;
                 }
 
 
             }
         }
         
     }
     
     void Conform () {
 
         TargetVertices = TargetMesh.GetComponent<MeshFilter> ().mesh.vertices;
         Mesh provmesh = new Mesh ();
         SourceMesh.GetComponent<SkinnedMeshRenderer> ().BakeMesh (provmesh);
         SourceVertices = provmesh.vertices;
 
         for (int t = 0; t < TargetVertices.Length; t++) {
 
             Vector3 ws = SourceMesh.transform.TransformPoint (SourceVertices [VertParent [t]]);
             Vector3 lt = TargetMesh.transform.InverseTransformPoint (ws);
             TargetVertices [t] = lt + LocalPos [t];
 
         }
 
         TargetMesh.GetComponent<MeshFilter>().mesh.vertices = TargetVertices;
         TargetMesh.GetComponent<MeshFilter> ().mesh.RecalculateBounds ();
         TargetMesh.GetComponent<MeshFilter> ().mesh.RecalculateNormals ();
         TargetMesh.GetComponent<MeshFilter> ().mesh.RecalculateTangents ();
         
     }

alt textalt text

1.png (79.9 kB)
2.png (107.4 kB)
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

108 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

Related Questions

How to manipulate(flatten) the Mesh of an object 0 Answers

Problem with setting vertices positions and smoothing groups. 1 Answer

mesh deformation to a shape ,how do i found that my mesh is deformed to a specific shape 0 Answers

Splitting shared vertices in a plane 0 Answers

Flawed Mesh Manipulation Question! 1 Answer


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