public void ReadBlueprintColor(ContourMeshBlueprint blueprint) { // Set colors: fetch color in blueprint if (blueprint != null) { int vertexCount = Vertices != null ? Vertices.Count : 0; int colorCount = Colors != null ? Colors.Count : 0; if (vertexCount == colorCount && vertexCount > 0) { Color color = blueprint.Color; for (int i = 0; i < colorCount; i++) { Colors[i] = color; } } else { throw new Exception("Blueprint and reader mismatch"); } } // Notify if there's a problem with the blueprint else { throw new Exception("Can't read blueprint"); } }
public void ReadBlueprintNormal(ContourMeshBlueprint blueprint) { // Set normals: fetch value in blueprint if (blueprint != null) { int vertexCount = Vertices != null ? Vertices.Count : 0; int normalCount = Normals != null ? Normals.Count : 0; if (vertexCount == normalCount && vertexCount > 0) { Vector3 normal = blueprint.Normal; for (int i = 0; i < normalCount; i++) { Normals[i] = normal; } } else { throw new Exception("Blueprint and reader mismatch"); } } // Notify if there's a problem with the blueprint else { throw new Exception("Can't read blueprint"); } }
protected override void OnChangeBlueprintParameters(int blueprintIndex) { ContourMeshBlueprint bp = blueprints[blueprintIndex] as ContourMeshBlueprint; ContourMeshReader rd = readers[blueprintIndex] as ContourMeshReader; string[] changedParameters = bp.changedParameters.Split(' '); foreach (string p in changedParameters) { switch (p) { case "normal": rd.ReadBlueprintNormal(bp); UpdateNormals(); break; case "color": rd.ReadBlueprintColor(bp); UpdateColors(); break; } } }
public override bool TryReadBlueprint(ContourBlueprint blueprint) { // Read if possible if (blueprint != null && blueprint is ContourMeshBlueprint && blueprint.material is ContourFaceMaterial) { ContourMeshBlueprint meshBlueprint = blueprint as ContourMeshBlueprint; // Get positions Vector2[] positions = blueprint.Positions; if (positions == null) { return(false); } // Get material ContourFaceMaterial contourMaterial = blueprint.material as ContourFaceMaterial; if (contourMaterial == null) { return(false); } MeshMaterial = contourMaterial.meshMaterial; // To build a face, there must be enough positions and contour must be a loop int positionCount = positions != null ? positions.Length : 0; if (positionCount < 3 || positions[0] != positions[positionCount - 1]) { Clear(); return(false); } // Set vertices: copy positions x,y and set z to value in contourMaterial (last position is ignored because of loop) int vertexCount = positionCount - 1; Vector3 zOffset = contourMaterial.zOffset * Vector3.forward; Vertices = new List <Vector3>(vertexCount); for (int i = 0; i < vertexCount; i++) { Vertices.Add((Vector3)positions[i] + zOffset); } // Set triangles: simple convex triangulation int triangleCount = Mathf.Max(vertexCount - 2, 0); Triangles = new List <int>(triangleCount * 3); for (int i = 0; i < triangleCount; i++) { Triangles.AddRange(new int[] { 0, i + 1, i + 2 }); } // Set uvs: since it's 2D, use vertex positions UVs = new List <Vector2>(vertexCount); for (int i = 0; i < vertexCount; i++) { UVs.Add(Vertices[i]); } // Set normals: fetch value in blueprint Normals = new List <Vector3>(vertexCount); Vector3 normal = meshBlueprint.Normal; for (int i = 0; i < vertexCount; i++) { Normals.Add(normal); } // Set colors: fetch color in blueprint Color color = meshBlueprint.Color; Colors = new List <Color>(vertexCount); for (int i = 0; i < vertexCount; i++) { Colors.Add(color); } return(true); } // If not, return false return(false); }
public override bool TryReadBlueprint(ContourBlueprint blueprint) { // Read if possible if (blueprint != null && blueprint is ContourMeshBlueprint && blueprint.material is ContourLineMaterial) { ContourMeshBlueprint meshBlueprint = blueprint as ContourMeshBlueprint; // Get positions Vector2[] positions = blueprint.Positions; if (positions == null) { return(false); } // Get material ContourLineMaterial contourMaterial = blueprint.material as ContourLineMaterial; if (contourMaterial == null) { return(false); } MeshMaterial = contourMaterial.meshMaterial; // Check if enough points to build at least one segment int positionCount = positions != null ? positions.Length : 0; if (positionCount < 2) { Clear(); return(false); } // Set vertices: two vertices per point int vertexCount = positionCount * 2; Vertices = new List <Vector3>(new Vector3[vertexCount]); GenerateVertices(positions, contourMaterial.zOffset, contourMaterial.width); // Set triangles: one quad per segment, two triangles per quad int quadCount = positionCount - 1; Triangles = new List <int>(quadCount * 6); for (int i = 0; i < quadCount; i++) { int q = i * 2; // First half of a quad Triangles.AddRange(new int[] { q, q + 1, q + 3 }); // Second half Triangles.AddRange(new int[] { q, q + 3, q + 2 }); } // Set normals: fetch value in blueprint Normals = new List <Vector3>(vertexCount); Vector3 normal = meshBlueprint.Normal; for (int i = 0; i < vertexCount; i++) { Normals.Add(normal); } // Set uvs: repeat texture along segments GenerateUVs(positions, contourMaterial.uvScale); // Set colors: fetch value in blueprint Color color = meshBlueprint.Color; Colors = new List <Color>(vertexCount); for (int i = 0; i < vertexCount; i++) { Colors.Add(color); } return(true); } // If not, return false return(false); }