public CircleGeometry(float radius=1,int segments=8,float thetaStart = 0, float thetaLength = Mathf.Tau) { segments = Mathf.Max(3, segments); var uvs = new List<Vector2>(); vertices.Add(Vector3.Zero); uvs.Add(Vector2.Half); for(var i = 0f; i <= segments; i ++ ) { var segment = thetaStart + i / segments * thetaLength; var v = new Vector3(Mathf.Cos( segment ),radius * Mathf.Sin( segment ),0); v.Multiply(radius); vertices.Add(v); uvs.Add(new Vector2(( v.x / radius + 1 ) / 2, ( v.y / radius + 1 ) / 2 )); } var n = Vector3.UnitZ; for (var i = 1; i <= segments; i++) { faces.Add(new Face3(i, i + 1, 0, n)); var faceSet = new UVFaceSet(uvs[i], uvs[i + 1], Vector2.Half); faceVertexUvs[0].Add(faceSet); } ComputeNormals(); BoundingSphere = new Sphere(Vector3.Zero,radius ); }
private void HandleTriangle(int a, int b, int c, int ua, int ub, int uc, UVFaceSet uv, List <Vector3> tan1, List <Vector3> tan2) { Vector3 vA = vertices[a], vB = vertices[b], vC = vertices[c]; Vector2 uvA = uv[ua], uvB = uv[ub], uvC = uv[uc]; var x1 = vB.x - vA.x; var x2 = vC.x - vA.x; var y1 = vB.y - vA.y; var y2 = vC.y - vA.y; var z1 = vB.z - vA.z; var z2 = vC.z - vA.z; var s1 = uvB.x - uvA.x; var s2 = uvC.x - uvA.x; var t1 = uvB.y - uvA.y; var t2 = uvC.y - uvA.y; var r = 1 / (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); var tA1 = tan1[a]; tA1.Add(sdir); tan1[a] = tA1; var tB1 = tan1[b]; tB1.Add(sdir); tan1[b] = tB1; var tC1 = tan1[c]; tC1.Add(sdir); tan1[c] = tC1; var tA2 = tan2[a]; tA2.Add(tdir); tan2[a] = tA2; var tB2 = tan2[b]; tB2.Add(tdir); tan2[b] = tB2; var tC2 = tan2[c]; tC2.Add(tdir); tan2[c] = tC2; }
private void HandleTriangle(int a, int b, int c, int ua, int ub, int uc, UVFaceSet uv, List<Vector3> tan1, List<Vector3> tan2) { Vector3 vA = vertices[a], vB = vertices[b], vC = vertices[c]; Vector2 uvA = uv[ua], uvB = uv[ub], uvC = uv[uc]; var x1 = vB.x - vA.x; var x2 = vC.x - vA.x; var y1 = vB.y - vA.y; var y2 = vC.y - vA.y; var z1 = vB.z - vA.z; var z2 = vC.z - vA.z; var s1 = uvB.x - uvA.x; var s2 = uvC.x - uvA.x; var t1 = uvB.y - uvA.y; var t2 = uvC.y - uvA.y; var r = 1 / (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); var tA1 = tan1[a]; tA1.Add(sdir); tan1[a] = tA1; var tB1 = tan1[b]; tB1.Add(sdir); tan1[b] = tB1; var tC1 = tan1[c]; tC1.Add(sdir); tan1[c] = tC1; var tA2 = tan2[a]; tA2.Add(tdir); tan2[a] = tA2; var tB2 = tan2[b]; tB2.Add(tdir); tan2[b] = tB2; var tC2 = tan2[c]; tC2.Add(tdir); tan2[c] = tC2; }
// Approximate a curved face with recursively sub-divided triangles. private void Make(VertexInfo v1, VertexInfo v2, VertexInfo v3) { var face = new Face3(v1.Index, v2.Index, v3.Index, v1.Position, v2.Position, v3.Position); faces.Add(face); var centroid = v1.Position; centroid.Add(v2.Position); centroid.Add(v3.Position); centroid.Divide(3); var azi = Azimuth(centroid); var uvA = CorrectUV(v1.UV, v1.Position, azi); var uvB = CorrectUV(v2.UV, v2.Position, azi); var uvC = CorrectUV(v3.UV, v3.Position, azi); var faceSet = new UVFaceSet(uvA,uvB,uvC); var uvs = faceVertexUvs[0]; uvs.Add(faceSet); }