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 declination · Aug 08, 2011 at 06:52 PM · lightingprocedural meshblendshapes

Procedural Mesh Deformation causes UV Seams to Appear

Hello, I am using Unity 3.3 to develop a web-based medical simulation. As part of our design needs, I am doing procedural mesh deformations in order to simulation biological processes like breathing (a la blend shapes or morph targets). I have scripts that do this, and they appear to work correctly, save for the appearance of light seams on the patient which do not exist when the scripts are not running. Additionally, these light seams appear if the scripts are active, but no vertices are being deformed (i.e. the blend shape is the same as the bash mesh). As an example, consider the following 2 screen grabs.

Base Mesh alt text

Base Mesh + Blend Shape alt text

What we do know is that seams on the forehead and arm correspond to seams in the UV texture. The scripts that do the deformation follow. As a brief overview, The BlendshapeController asks each attached BlendshapePackage to deform the vertices of the mesh every frame to the correct weight. I would appreciate any insight into how to remove these artifacts. Thanks in advance!

 public class BlendshapeController : MonoBehaviour {
 
 private bool usingSkin;
 private Vector3[] baseVertices;
 private Vector3[] deformVertices;
 
 void Awake() {
     Mesh mesh = FetchMesh();
     baseVertices = new Vector3[mesh.vertexCount];
     Array.Copy(mesh.vertices, baseVertices, mesh.vertexCount);        
     deformVertices = new Vector3[mesh.vertexCount];
 }
 
 void Start () {
     BlendshapePackage[] blendPacks = GetComponentsInChildren<BlendshapePackage>(true);
     foreach (BlendshapePackage pack in blendPacks) {
         pack.Init(baseVertices);
     }
 }
 
 void Update () {
     Array.Copy(baseVertices, deformVertices, baseVertices.Length);
     BlendshapePackage[] blendPacks = GetComponentsInChildren<BlendshapePackage>(false);
     foreach (BlendshapePackage pack in blendPacks) {
         if (pack.blendWeight > 0) {
             pack.Deform(deformVertices);
         }
     }
     ApplyDeformation();
 }
 
 private Mesh FetchMesh() {
     MeshFilter filter = GetComponent<MeshFilter>();
     SkinnedMeshRenderer skinMeshRenderer = GetComponent<SkinnedMeshRenderer>();
     if (filter != null) {
         usingSkin = false;
         return filter.mesh;    
     } else if (skinMeshRenderer != null) {
         usingSkin = true;
         return skinMeshRenderer.sharedMesh;
     } else {
         Debug.LogError("BlendshapeController is not attached to a mesh-bearing GameObject");
         return null;
     }
 }
 
 private void ApplyDeformation() {
     MeshFilter filter = GetComponent<MeshFilter>();
     SkinnedMeshRenderer skinMeshRenderer = GetComponent<SkinnedMeshRenderer>();
     if (filter != null) {
         filter.mesh.vertices = deformVertices;
         filter.mesh.RecalculateNormals();
         filter.mesh.RecalculateBounds();
     } else if (skinMeshRenderer != null) {
         skinMeshRenderer.sharedMesh.vertices = deformVertices;
         skinMeshRenderer.sharedMesh.RecalculateNormals();
         skinMeshRenderer.sharedMesh.RecalculateBounds();
     } else {
         Debug.LogError("BlendshapeController is not attached to a mesh-bearing GameObject");
     }
 }
 }
 



 public class BlendshapePackage : MonoBehaviour
 {
 public float blendWeight;
 public List<Mesh> blendTargets;
 
 private List<Vector3[]> blendDeltas;
 private bool inconsistent;
 
 void Awake() {
     inconsistent = false;
     blendDeltas = new List<Vector3[]>(blendTargets.Count);    
 }
 
 // Use this for initialization
 void Start ()
 {
     
 }

 // Update is called once per frame
 void Update ()
 {

 }
 
 public void Init(Vector3[] baseVert) {
     for (int i = 0; i < blendTargets.Count; i++) {
         Vector3[] blendVert = blendTargets[i].vertices;
         if (blendVert.Length != baseVert.Length) {
             Debug.LogError("Inconsistent vertex lengths between base mesh and blendshapes");
             inconsistent = true;
             return;
         }
         Vector3[] blendDelta = new Vector3[blendVert.Length];
         for (int j = 0; j < blendDelta.Length; j++) {
             blendDelta[j] = blendVert[j] - baseVert[j];    
         }
         blendDeltas.Add(blendDelta);
     }
 }
 
 public void Deform(Vector3[] vectors) { // Apply deformations
     if (!inconsistent) {
         for (int i = 0; i < blendDeltas.Count; i++) { 
             Vector3[] blendDelta = blendDeltas[i];
             for (int j = 0; j < vectors.Length; j++) {
                 vectors[j] += blendWeight * blendDelta[j];
             }
         }
     } else {
         Debug.LogWarning("Skipping deformation step due to inconsistency");
     }
 }
 }

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

· Add your reply
  • Sort: 
avatar image
0

Answer by SpookyCat · Jun 21, 2012 at 01:14 PM

You will need to calculate the smoothing groups from the original mesh which is not trivial. Or you can use one of the systems on the Asset Store that will do the morphing for you but beware as far as I know there is only one that deals with smoothing and uv seams etc correctly.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

HDRP - The closer I get to a procedurally generated object the brigther everything in the scene becomes 0 Answers

Passing custom vertex attributes to cg shader 0 Answers

Procedural-mesh normals reversed, but only when lit from the left 1 Answer

How to apply PBR material to Procedurally generated Mesh? 1 Answer

Lighting Banding Artifact 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