public override void ReadBlueprintPositions(ContourBlueprint blueprint) { // Read contour positions only (assumes only modification on contour is some point moved) if (blueprint != null && blueprint is ContourMeshBlueprint && blueprint.material is ContourLineMaterial) { // Get positions Vector2[] positions = blueprint.Positions; // Check if blueprint matches reader mesh's length int positionCount = positions != null ? positions.Length : 0; int vertexCount = Vertices.Count; if (vertexCount == positionCount * 2) { if (vertexCount > 0) { ContourLineMaterial contourMaterial = blueprint.material as ContourLineMaterial; GenerateVertices(positions, contourMaterial.zOffset, contourMaterial.width); GenerateUVs(positions, contourMaterial.uvScale); } } 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 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); }