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 :
[22872-sans+titre.png*_|22872]

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 *= new Vector3(x, 0, y); // and assign vertices, uv, normals, etc..*

_ uv = 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 = 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 :confused:
_*

from the comments : Shader wants tangents, but the mesh doesn't have them - Unity Answers

I have already seen this link, but it didn’t worked :frowning:

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][1] 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 *= new Vector3(x, 0, y); // and assign vertices, uv, normals, etc..*

_ uv = 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 = 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.
http://www.terathon.com/code/tangent.html*_
_/_

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*;*
var t = tan1*;*

// Gram-Schmidt orthogonalize
Vector3.OrthoNormalize( n, t );

tangents*.x = t.x;*
tangents*.y = t.y;*
tangents*.z = t.z;*

// Calculate handedness
tangents_.w = ( Vector3.Dot(Vector3.Cross(n, t), tan2*) < 0.0 ) ? -1.0 : 1.0;
}*_

theMesh.tangents = tangents;
}
}
_*[1]: http://docs.unity3d.com/Documentation/Manual/ScriptCompileOrderFolders.html*_