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 inkspots · Dec 18, 2011 at 03:13 AM · instantiatemeshskinnedmeshrenderer

mismatching numbers of verticles ?

Hello everyonem i have been struggling with this script now quite a bit since i realy wanted to solve it myself but it puzzles me, i have been altering a morph target script so it would work with skinnedmeshrenderer instead of mesh, i imported all meshes with an equal amount of verticles and it worked on the original script, but in the altered version of the script it seem to have an unmatching amount of verticles, i suspect that the instantiate is returning 0 and there for debug logs 'Mesh 0 doesn't have the same number of vertices as the first mesh' could someone please help me getting the right setup for instantiating the skinnedmeshrenderer in this script? i might made some wrong changes in the script, but it's hard to find reference information for it thanks in advance !!

class BlendShapeVertex { var originalIndex : int; var position : Vector3; var normal : Vector3; }

class BlendShape { //var vertices : BlendShapeVertex[]; var vertices = new Array(); }

var attributes : String[]; //Names for the attributes to be morphed var sourceMesh : SkinnedMeshRenderer; //The original mesh var attributeMeshes : Mesh[]; //The destination meshes for each attribute. var attributeProgress : float[]; //Current weight for each attribute.

private var blendShapes : BlendShape[]; //Array of BlendShape objects. This will be populated in Awake(). private var workingMesh : Mesh; //Stores mesh data for the working copy of the mesh (so the original mesh doesn't get changed).

function Awake () { //First, make sure all attributes are assigned. for (i=0; i < attributeMeshes.length; i++) { if (attributeMeshes[i] == null) {
Debug.Log("Attribute " + i + " has not been assigned."); return;
}
}

 //Populate the working mesh
 sourceMesh =  GetComponent(SkinnedMeshRenderer); 
 skin = GetComponent(SkinnedMeshRenderer);

 workingMesh = Instantiate(skin.sharedMesh);
 
 

 //Check attribute meshes to be sure vertex count is the same.
 var vertexCount = sourceMesh.vertexCount; 
 for (i=0; i < attributeMeshes.Length; i++) { 
     if (attributeMeshes[i].vertexCount != vertexCount) {    
         Debug.Log("Mesh " + i + " doesn't have the same number of vertices as the first mesh"); 
         return; 
           }
        } 
     }
  
 
 //Build blend shapes
 BuildBlendShapes();


//This function populates the various arrays that are used by the script later on. function BuildBlendShapes () {

 blendShapes = new BlendShape[attributes.length];
 
 //For each attribute figure out which vertices are affected, then store their info in the blend shape object.
 for (var i=0; i < attributes.length; i++) {
     //Populate blendShapes array with new blend shapes
     blendShapes[i] = new BlendShape();
     
     for (var j=0; j < workingMesh.vertexCount; j++) {
         //If the vertex is affected, populate a blend shape vertex with that info
         if (workingMesh.vertices[j] != attributeMeshes[i].vertices[j]) {
             //Create a blend shape vertex and populate its data.
             var blendShapeVertex = new BlendShapeVertex();
             blendShapeVertex.originalIndex = j;
             blendShapeVertex.position = attributeMeshes[i].vertices[j] - workingMesh.vertices[j];
             blendShapeVertex.normal = attributeMeshes[i].normals[j] - workingMesh.normals[j];
                             
             //Add new blend shape vertex to blendShape object.
             blendShapes[i].vertices.Push(blendShapeVertex);
         }
     }
     
     //Convert blendShapes.vertices to builtin array
     blendShapes[i].vertices = blendShapes[i].vertices.ToBuiltin(BlendShapeVertex);
 }

}

//This is the primary function that controls morphs. It is called from the GUI script every time one of the sliders is updated. function SetMorph () {

 //Set up working data to store mesh offset information.
 var morphedVertices : Vector3[] = sourceMesh.vertices;
 var morphedNormals : Vector3[] = sourceMesh.normals;
 
 //For each attribute...
 for (var j=0; j < attributes.length; j++) {
     //If the weight of this attribute isn't 0    
     if (!Mathf.Approximately(attributeProgress[j], 0)) {
         //For each vertex in this attribute's blend shape...
         for (var i=0; i < blendShapes[j].vertices.length; i++) {        
             //...adjust the mesh according to the offset value and weight
             morphedVertices[blendShapes[j].vertices[i].originalIndex] += blendShapes[j].vertices[i].position * attributeProgress[j];
             //Adjust normals as well
             morphedNormals[blendShapes[j].vertices[i].originalIndex] += blendShapes[j].vertices[i].normal * attributeProgress[j];
         }    
     }    
 }
 
 //Update the actual mesh with new vertex and normal information, then recalculate the mesh bounds.        
 workingMesh.vertices = morphedVertices;
 workingMesh.normals = morphedNormals;
 workingMesh.RecalculateBounds();

}

//Require that we have a mesh filter component and a mesh renderer component when assigning this script to an object. @script RequireComponent (MeshFilter) @script RequireComponent (SkinnedMeshRenderer)

Comment
Add comment · Show 2
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 Tasarran · Dec 18, 2011 at 04:02 AM 0
Share

Is it possible for you to post a picture of what the mesh looks like?

avatar image inkspots · Dec 18, 2011 at 10:20 AM 0
Share

sure, i'm linking to a picture of the model which shows a wireframed version and a textured version of the same model.

www.argusinsl.com/meshexample.jpg

since i managed to manipulate the skinnedmesh already i'm almost certain the problem is script based. Within the script under '//Populate the working mesh' you see how i tried to Instantiate, this and the 'var source$$anonymous$$esh : Skinned$$anonymous$$eshRenderer;' are the only things i changed on a working morph target script for meshes.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Is it possible to make vertices defined by a mesh and mesh filters animating? 0 Answers

how can I instantiate an object specifically at the intersection of a collider and a mesh 1 Answer

SkinnedMeshRenderer: Change Bones at start without changing mesh or blendshape results. 0 Answers

Skinned Mesh Renderer Combining submesh issue 1 Answer

Moving bones without moving mesh 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