public Geometry Output() { Geometry geo = new Geometry(_geometry.Vertices.Length); var triangles = new List<int>(); for (int i = 0; i < _geometry.Vertices.Length; i++) { geo.Vertices[i] = _geometry.Vertices[i]; if (i < _geometry.Normals.Length) geo.Normals[i] = _geometry.Normals[i]; if (i < _geometry.UV.Length) geo.UV[i] = _geometry.UV[i]; } for (int i = 0; i < _geometry.Triangles.Length; i+=3) { int t = i / 3; if ((!Invert && System.Array.IndexOf(Indexes, t) >= 0) || ( Invert && System.Array.IndexOf(Indexes, t) == -1)) { triangles.Add(_geometry.Triangles[i ]); triangles.Add(_geometry.Triangles[i+1]); triangles.Add(_geometry.Triangles[i+2]); } } geo.Triangles = triangles.ToArray(); if (RecalculateNormals) { geo.RecalculateNormals(); } return geo; }
public Geometry Output() { Geometry geo = new Geometry(); var vertices = new List<Vector3>(); var normals = new List<Vector3>(); var tangents = new List<Vector4>(); var uv = new List<Vector2>(); for (int i = 0; i < _geometry.Vertices.Length; i++) { if ((!Invert && System.Array.IndexOf(Indexes, i) >= 0) || ( Invert && System.Array.IndexOf(Indexes, i) == -1)) { vertices.Add(_geometry.Vertices[i]); if (i < _geometry.Normals.Length) normals.Add(_geometry.Normals[i]); if (i < _geometry.Tangents.Length) tangents.Add(_geometry.Tangents[i]); if (i < _geometry.UV.Length) uv.Add(_geometry.UV[i]); } } geo.Vertices = vertices.ToArray(); geo.Normals = normals.ToArray(); geo.Tangents = tangents.ToArray(); geo.UV = uv.ToArray(); geo.Triangles = new int[0]; geo.Polygons = new int[0]; return geo; }
public Geometry Output() { Geometry geo = new Geometry(); // Square cell = new Square(); return geo; }
public Geometry Output() { bool isOpen = Mathf.Abs(EndAngle - StartAngle) < 360; bool hasMidPoint = (Opening == OpeningType.Sector && isOpen) || (Opening == OpeningType.Sector && Surface); int vertexCount = Segments; if (isOpen) vertexCount++; if (hasMidPoint) vertexCount++; Geometry geo = new Geometry(vertexCount); int arcVertices = Segments + (isOpen || hasMidPoint ? 1 : 0); // Vertices, Normals for (int i = 0; i < arcVertices; i++) { int seg = Segments + (hasMidPoint ? 0 : 0); float angle = StartAngle + ((EndAngle-StartAngle) * i / seg); float h = Mathf.Cos(angle * Mathf.Deg2Rad) * Radius; float v = Mathf.Sin(angle * Mathf.Deg2Rad) * Radius; geo.Vertices[arcVertices - i - 1] = new Vector3(h, 0f, v); geo.Normals[arcVertices - i - 1] = Vector3.up; } if (hasMidPoint) { geo.Vertices[vertexCount-1] = Vector3.zero; geo.Normals[vertexCount-1] = Vector3.up; } if (Surface) { var triangulate = new Triangulate(geo); geo = triangulate.Output(); if (!isOpen && Opening == OpeningType.Sector) { System.Array.Resize<int>(ref geo.Triangles, geo.Triangles.Length + 3); geo.Triangles[geo.Triangles.Length-3] = 0; geo.Triangles[geo.Triangles.Length-2] = Segments; geo.Triangles[geo.Triangles.Length-1] = Segments-1; } } // Polygon if (hasMidPoint && !isOpen) { geo.Polygons = new int[] {0, vertexCount-1}; } else { geo.Polygons = new int[] {0, vertexCount}; } geo.ApplyOrientation(Orientation); geo.Offset(Center); return geo; }
public Geometry Output() { int totalVerts = 0, totalTris = 0, totalPolys = 0; foreach (var inputGeo in Input) { totalVerts += inputGeo.Vertices.Length; totalTris += inputGeo.Triangles.Length; totalPolys += inputGeo.Polygons.Length; } Geometry result = new Geometry(totalVerts, totalTris, totalPolys); int vCount = 0; int tCount = 0; int pCount = 0; foreach (Geometry geo in Input) { // Vertices, Normals and UV for (int v = 0; v < geo.Vertices.Length; v++) { result.Vertices[vCount + v] = geo.Vertices[v]; if (v < geo.Normals.Length) { result.Normals[vCount + v] = geo.Normals[v]; } if (v < geo.Tangents.Length) { result.Tangents[vCount + v] = geo.Tangents[v]; } if (v < geo.UV.Length) { result.UV[vCount + v] = geo.UV[v]; } } // Faces for (int f = 0; f < geo.Triangles.Length; f++) { result.Triangles[tCount + f] = geo.Triangles[f] + vCount; } // Polygons for (int p = 0; p < geo.Polygons.Length; p+=2) { result.Polygons[pCount+p] = geo.Polygons[p] + vCount; result.Polygons[pCount+p+1] = geo.Polygons[p+1]; } vCount += geo.Vertices.Length; tCount += geo.Triangles.Length; pCount += geo.Polygons.Length; } return result; }
public Geometry Output() { if (_geometry.Polygons.Length == 0) return Geometry.Empty; var polyIndices = _geometry.Polygons.Length; var polyCount = polyIndices / 2; var segments = _geometry.Polygons[1]; var vertexCount = segments * polyCount; var triCount = segments * (polyCount - 1) * 6; var geo = new Geometry(vertexCount, triCount, polyCount); int vCount = 0; int tCount = 0; for (var p = 0; p < polyIndices; p+=2) { var start = _geometry.Polygons[p]; if (_geometry.Polygons[p+1] != segments) { Debug.LogErrorFormat("Bridge error: input polygons have different numbers of vertices\nGot {0}, expected {1}", _geometry.Polygons[p+1], segments); return Geometry.Empty; } for (var v = start; v < start+segments; v++) { geo.Vertices[vCount] = _geometry.Vertices[v]; if (v < _geometry.Normals.Length) geo.Normals[vCount] = _geometry.Normals[v]; if (v < _geometry.Tangents.Length) geo.Tangents[vCount] = _geometry.Tangents[v]; if (v < _geometry.UV.Length) geo.UV[vCount] = _geometry.UV[v]; vCount++; if (p > 0) { geo.Triangles[tCount++] = v; geo.Triangles[tCount++] = v-segments; geo.Triangles[tCount++] = (v-segments+1 == start) ? start-segments : v-segments+1; geo.Triangles[tCount++] = (v-1 < start) ? start+segments-1 : v-1; geo.Triangles[tCount++] = v-segments; geo.Triangles[tCount++] = v; } } } geo.Polygons = _geometry.Polygons; if (RecalculateNormals) { geo.RecalculateNormals(); } return geo; }
public Geometry Output() { Geometry geo = new Geometry(); // Vertices and normals geo.Vertices = new Vector3 [] { new Vector3( Size.x / 2, 0, -Size.y / 2), // bottom right new Vector3(-Size.x / 2, 0, -Size.y / 2), // bottom left new Vector3(-Size.x / 2, 0, Size.y / 2), // top left new Vector3( Size.x / 2, 0, Size.y / 2) // top right }; Vector3 normal = new Vector3(0f, 1f, 0f); geo.Normals = new Vector3 [] {normal, normal, normal, normal}; Vector4 tangent = new Vector4(1f, 0f, 0f, -1f); geo.Tangents = new Vector4 [] {tangent, tangent, tangent, tangent}; geo.Polygons = new int[] {0, 4}; // UV geo.UV = new Vector2 [] { new Vector2(1f, 1f), new Vector2(0f, 0f), new Vector2(0f, 1f), new Vector2(1f, 1f) }; // Surface switch (Surface) { case Surface.None: geo.Triangles = new int[0]; break; case Surface.Triangulate: geo.Triangles = new int [] { 0, 1, 2, 2, 3, 0 }; break; case Surface.Converge: var conv = new Converge(geo); conv.Point = Center; conv.RecalculateNormals = false; geo = conv.Output(); break; } geo.ApplyOrientation(Orientation); geo.Offset(Center); // Orientation return geo; }
public Geometry Output() { if (Segments == 0) return Geometry.Empty; if (Segments == 1) return Point.At((Start + End) / 2); var geo = new Geometry(Segments); geo.Polygons = new int[] {0, Segments}; for (int i = 0; i < Segments; i++) { float f = (float)i / (Segments-1); geo.Vertices[i] = Vector3.Lerp(Start, End, f); } return geo; }
public Geometry Output() { var result = new Geometry(_totalVerts, _totalTris); int vCount = 0; foreach (Geometry geo in _geometries) { for (int v = 0; v < geo.Vertices.Length; v++) { result.Vertices[vCount+v] = geo.Vertices[v]; } vCount += geo.Vertices.Length; } result.Polygons = new int[] {0, vCount}; return result; }
public Geometry Output() { Geometry geo = new Geometry(3); // http://upload.wikimedia.org/wikipedia/commons/9/9a/Degree-Radian_Conversion.svg float radius = 2 * Height / 3; geo.Vertices = new Vector3[3]; for (int i = 0; i < 3; i++) { float degrees = 90 + 120 * i; float radians = Mathf.PI / 180 * degrees; float cos = Mathf.Cos(radians); float sin = Mathf.Sin(radians); geo.Vertices[2 - i] = new Vector3(cos * radius, 0f, sin * radius); } // Normals Vector3 normal = new Vector3(0f, 1f, 0f); geo.Normals = new Vector3 [] {normal, normal, normal}; // UV geo.UV = new Vector2 [] { new Vector2(1.0f, 0.0f), new Vector2(0.0f, 0.0f), new Vector2(0.5f, 1.0f) }; // Triangles if (Surface) { geo.Triangles = new int [] {0, 1, 2}; } else { geo.Triangles = new int[0]; } // Polygons geo.Polygons = new int[] {0, 3}; geo.ApplyOrientation(Orientation); geo.Offset(Center); // Orientation return geo; }
public Geometry Output() { int vertexCount = _geometry.Vertices.Length; Geometry geo = new Geometry(vertexCount+1); var triangles = new List<int>(); // Add the converge point geo.Vertices[vertexCount] = Point; geo.Normals[vertexCount] = Point; geo.UV[vertexCount] = new Vector2(.5f, .5f); for (int i = 0; i < vertexCount; i++) { geo.Vertices[i] = _geometry.Vertices[i]; if (!RecalculateNormals && i < _geometry.Normals.Length) { geo.Normals[i] = _geometry.Normals[i]; } geo.UV[i] = new Vector2((i % 2 == 0) ? 0f : 1f, 0f); int a = (i == _geometry.Vertices.Length-1) ? 0 : i+1, b = vertexCount, c = i; var dot = Vector3.Dot(_geometry.Vertices[a], _geometry.Vertices[c]); if (dot == 1f || dot == -1) { continue; } triangles.Add(a); triangles.Add(b); triangles.Add(c); } geo.Triangles = triangles.ToArray(); geo.Polygons = _geometry.Polygons; if (RecalculateNormals) { geo.RecalculateNormals(); } return geo; }
public Geometry Output() { Geometry geo = new Geometry(); Random.seed = Seed; // Vertices geo.Vertices = new Vector3 [Count]; geo.Normals = new Vector3 [Count]; geo.UV = new Vector2[0]; geo.Triangles = new int[0]; for (int i = 0; i < Count; i++) { float dist = Random.Range(0f, Radius); float angle = Random.Range(0f, Mathf.PI * 2); float cos = Mathf.Cos(angle); float sin = Mathf.Sin(angle); geo.Vertices[i] = new Vector3(cos * dist, 0, sin * dist); geo.Normals[i] = geo.Vertices[i].normalized; } return geo; }
public override void Create(int x, int y, Geometry geometry, Tile[] sides) { if (sides[0] != null && sides[0].filled) { geometry.CreateFace(x, 1, y + 1, Geometry.Direction.south, Textures.TEXTURES["hallway_wall_1"].uv); geometry.CreateFace(x, 2, y + 1, Geometry.Direction.south, Textures.TEXTURES["hallway_wall_2"].uv); } if (sides[1] != null && sides[1].filled) { geometry.CreateFace(x + 1, 1, y, Geometry.Direction.west, Textures.TEXTURES["hallway_wall_1"].uv); geometry.CreateFace(x + 1, 2, y, Geometry.Direction.west, Textures.TEXTURES["hallway_wall_2"].uv); } if (sides[2] != null && sides[2].filled) { geometry.CreateFace(x, 1, y - 1, Geometry.Direction.north, Textures.TEXTURES["hallway_wall_1"].uv); geometry.CreateFace(x, 2, y - 1, Geometry.Direction.north, Textures.TEXTURES["hallway_wall_2"].uv); } if (sides[3] != null && sides[3].filled) { geometry.CreateFace(x - 1, 1, y, Geometry.Direction.east, Textures.TEXTURES["hallway_wall_1"].uv); geometry.CreateFace(x - 1, 2, y, Geometry.Direction.east, Textures.TEXTURES["hallway_wall_2"].uv); } geometry.CreateFace(x, 0, y, Geometry.Direction.up, Textures.TEXTURES["hallway_1"].uv); }
public Geometry Process(Geometry geometry) { Converge converge = new Converge(); converge.Input(geometry); return converge.Output(); }
public Geometry Output() { if (Segments < 3) { Debug.LogError("Sphere error: Spheres must have at least 3 segments"); } Geometry geo = new Geometry( Segments*(Segments+1), (Segments*2) * (Segments-1) * 3 -Segments*6, // (Segments*2) = # triangles in a ring, (Segments-1) = # of rings in sphere Segments*2 ); float tau = Mathf.PI * 2; int triIndex = 0; // Longitudes (meridians) for (int i = 0; i < Segments; i++) { float lonAng = Mathf.PI/2 + (Mathf.PI * i / (Segments - 1)); float lonSin = Mathf.Sin(lonAng) * Radius; float lonCos = Mathf.Cos(lonAng) * Radius; // Latitudes (parallels) int offset = i * (Segments + 1); // We iterate one additional time to create an overlapping longitude // at the UV seam for (int l = 0; l < Segments + 1; l++) { float latAng = tau * l / Segments; float latCos = Mathf.Cos(latAng) * lonCos; float latSin = Mathf.Sin(latAng) * lonCos; // Vertices, Normals, UV geo.Vertices[offset + Segments - l] = new Vector3(latCos, lonSin, latSin); geo.Normals[offset + Segments - l] = new Vector3(latCos, lonSin, latSin); geo.UV[offset + Segments - l] = new Vector2(latAng / tau, (lonSin+Radius) / (Radius*2)); // Tangents geo.Tangents[offset + Segments - l] = new Vector4(-latSin, 0f, latCos, -1).normalized; } // Polygons var polyOrigin = geo.Polygons[i*2 ] = offset; var polyLength = geo.Polygons[i*2+1] = Segments+1; if (i > 0) { for (int t = 0; t < polyLength-1; t++) { // First Triangle if (i < Segments-1) { geo.Triangles[triIndex++] = polyOrigin + t; geo.Triangles[triIndex++] = polyOrigin + t + 1; geo.Triangles[triIndex++] = polyOrigin + t - polyLength + 1; } // Second Triangle if (i > 1) { geo.Triangles[triIndex++] = polyOrigin + t; geo.Triangles[triIndex++] = polyOrigin + t - polyLength + 1; geo.Triangles[triIndex++] = polyOrigin + t - polyLength; } } } } geo.Offset(Center); geo.ApplyOrientation(Orientation); return geo; }
public override void Create(int x, int y, Geometry geometry, Tile[] sides) { geometry.CreateFace(x, 2, y, Geometry.Direction.up, null, 1); }
public Fuse(Geometry geometry) { Input(geometry); }
public static Geometry Process(Geometry geometry) { Fuse fuse = new Fuse(); fuse.Input(geometry); return fuse.Output(); }
public void Input(Geometry geometry) { _totalVerts += geometry.Vertices.Length; _totalTris += geometry.Triangles.Length; _geometries.Add(geometry.Copy()); }
public Bridge(Geometry geometry) { Input(geometry); }
public Triangulate(Geometry geometry) { Input(geometry); }
public ExtractVertices(Geometry geometry) { Input(geometry); }
public static Geometry Process(Geometry geometry) { var triangulate = new Triangulate(geometry); return triangulate.Output(); }
public Converge(Geometry geometry) { Input(geometry); }
public ExtractFaces(Geometry geometry) { Input(geometry); }
public static Geometry Process(Geometry geometry) { var mirror = new Mirror(geometry); return mirror.Output(); }
public Manipulate(Geometry geometry) { Input(geometry); }
public void Input(Geometry geometry) { _geometry = geometry.Copy(); }
public Mirror(Geometry geometry) { Input = geometry; }