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 jnc1 · Feb 28, 2014 at 03:48 PM · meshcreatecircle

Problem creating a circle mesh

Hello,

I'm trying to create a circle mesh, however I get a warning error : Shader wants tangents, but the mesh doesn't have them.

What are theses tangents ? How can I fix this ?

My circle in editor should look like this : alt text

And edges should be at each degrees (I simplified the image), here is my actual code :

 var l : int = 50;
 var x : float;
 var y : float;
 
 function Start() {
     var verts: Vector3[] = new Vector3[361];
     var normals: Vector3[] = new Vector3[361];
     var uv: Vector2[] = new Vector2[361];
     var tri: int[] = new int[1080];
  
     var mf: MeshFilter = GetComponent(MeshFilter);
     
     verts[0] = new Vector3(0, 0, 0);
     uv[0] = new Vector3(0, 0);
     for (var i : int = 1;i<361;i++) { // For each degrees
         x = Mathf.Cos(i) * l; // I calc the position
         y = Mathf.Sin(i) * l;
         verts[i] = new Vector3(x, 0, y); // and assign vertices, uv, normals, etc..
         uv[i] = new Vector3(x, y);
         tri[(i-1)*3] = 0; //     I don't know if triangles should work like this,
         tri[(i-1)*3+1] = i; // here I think that triangle is the index of a vertice
         if ((i+1 > 360)) {
             tri[(i-1)*3 + 2] = 1;
         } else {
             tri[(i-1)*3 + 2] = i+1;
         }
     }
 
     for (i = 0; i < normals.Length; i++) {
         normals[i] = Vector3.up;
     }
 
     var mesh: Mesh = new Mesh();
     mesh.vertices = verts;
     mesh.triangles = tri;
     mesh.uv = uv;
     mesh.normals = normals;
 
     mf.mesh = mesh;
 }

Thanks you for your help and sorry for the lack of informations.

edit : I'm also sorry for the big image :/

sans titre.png (27.1 kB)
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 AlucardJay · Feb 28, 2014 at 03:54 PM 1
Share

http://answers.unity3d.com/questions/597849/shader-wants-tangents-but-the-mesh-doesnt-have-the-1.html#answer-597899

avatar image jnc1 · Mar 01, 2014 at 03:02 AM 0
Share

@alucardj : I have already seen this link, but it didn't worked :(

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by AlucardJay · Mar 01, 2014 at 04:21 PM

from the comments : http://answers.unity3d.com/questions/597849/shader-wants-tangents-but-the-mesh-doesnt-have-the-1.html#answer-597899

  • have already seen this link, but it didn't worked :(*

Possibly because you are coding in uJS and the script is in C#. If you havn't put the TangentSolver in a special folder as per compilation order to be recognized.

Here is your script with a line added to use the class (tested and working) :

 #pragma strict
 
 var l : int = 50;
 var x : float;
 var y : float;
 
 function Start() 
 {
     var verts: Vector3[] = new Vector3[361];
     var normals: Vector3[] = new Vector3[361];
     var uv: Vector2[] = new Vector2[361];
     var tri: int[] = new int[1080];
 
     var mf: MeshFilter = GetComponent(MeshFilter);
 
     verts[0] = new Vector3(0, 0, 0);
     uv[0] = new Vector3(0, 0);
     for (var i : int = 1;i<361;i++) { // For each degrees
         x = Mathf.Cos(i) * l; // I calc the position
         y = Mathf.Sin(i) * l;
         verts[i] = new Vector3(x, 0, y); // and assign vertices, uv, normals, etc..
         uv[i] = new Vector3(x, y);
         tri[(i-1)*3] = 0; // I don't know if triangles should work like this,
         tri[(i-1)*3+1] = i; // here I think that triangle is the index of a vertice
         if ((i+1 > 360)) {
             tri[(i-1)*3 + 2] = 1;
         } else {
             tri[(i-1)*3 + 2] = i+1;
         }
     }
 
     for (i = 0; i < normals.Length; i++) {
         normals[i] = Vector3.up;
     }
 
     var mesh: Mesh = new Mesh();
     mesh.vertices = verts;
     mesh.triangles = tri;
     mesh.uv = uv;
     mesh.normals = normals;
     
     // Calculate Tangents
     TangentSolver(mesh);
 
     mf.mesh = mesh;
 }

There is something not right about the way you are calculating the triangles. You can have a look at my answer here for another way to create a circle/ring mesh : http://answers.unity3d.com/questions/375604/expanding-ring-velocity-ellipsoid-particle-emitter.html

As you are working in uJS, to avoid compilation problems, here is my uJS version of the TangentSolver :

 /*
 Derived from
 Lengyel, Eric. “Computing Tangent Space Basis Vectors for an Arbitrary Mesh”. Terathon Software 3D Graphics Library, 2001.
 [url]http://www.terathon.com/code/tangent.html[/url]
 */
 
 class TangentSolver
 {
     function TangentSolver(theMesh : Mesh)
     {
         var vertexCount = theMesh.vertexCount;
         var vertices = theMesh.vertices;
         var normals = theMesh.normals;
         var texcoords = theMesh.uv;
         var triangles = theMesh.triangles;
         var triangleCount = triangles.length/3;
         var tangents = new Vector4[vertexCount];
         var tan1 = new Vector3[vertexCount];
         var tan2 = new Vector3[vertexCount];
         var tri = 0;
 
         for (var  i:int = 0; i < (triangleCount); i++)
         {
             var i1 = triangles[tri];
             var i2 = triangles[tri+1];
             var i3 = triangles[tri+2];
 
             var v1 = vertices[i1];
             var v2 = vertices[i2];
             var v3 = vertices[i3];
 
             var w1 = texcoords[i1];
             var w2 = texcoords[i2];
             var w3 = texcoords[i3];
 
             var x1 = v2.x - v1.x;
             var x2 = v3.x - v1.x;
             var y1 = v2.y - v1.y;
             var y2 = v3.y - v1.y;
             var z1 = v2.z - v1.z;
             var z2 = v3.z - v1.z;
 
             var s1 = w2.x - w1.x;
             var s2 = w3.x - w1.x;
             var t1 = w2.y - w1.y;
             var t2 = w3.y - w1.y;
 
             var r = 1.0 / (s1 * t2 - s2 * t1);
             var sdir = new Vector3((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, (t2 * z1 - t1 * z2) * r);
             var tdir = new Vector3((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, (s1 * z2 - s2 * z1) * r);
 
             tan1[i1] += sdir;
             tan1[i2] += sdir;
             tan1[i3] += sdir;
 
             tan2[i1] += tdir;
             tan2[i2] += tdir;
             tan2[i3] += tdir;
 
             tri += 3;
         }
 
         for (i = 0; i < (vertexCount); i++)
         {
             var n = normals[i];
             var t = tan1[i];
 
             // Gram-Schmidt orthogonalize
             Vector3.OrthoNormalize( n, t );
 
             tangents[i].x  = t.x;
             tangents[i].y  = t.y;
             tangents[i].z  = t.z;
 
             // Calculate handedness
             tangents[i].w = ( Vector3.Dot(Vector3.Cross(n, t), tan2[i]) < 0.0 ) ? -1.0 : 1.0;
         }     
         
         theMesh.tangents = tangents;
     }
 }


Comment
Add comment · Show 1 · 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 AlucardJay · Mar 12, 2014 at 03:59 PM 0
Share

If this helped, please mark as answered.

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

22 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

Related Questions

How do I create a specific object in Unity? I need a planet with huge mountains and oceans. 1 Answer

Creating a smooth flat circle? 3 Answers

Any tips for creating grass on mesh(creating gardens) ? 0 Answers

Generating a cube mesh with two given points 1 Answer

How to connect walls corners 3 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