void Update() { if (Input.GetKeyDown(KeyCode.Space)) { Mesh mesh = cube.GetComponent <MeshFilter>().mesh; MeshLib.BoxProjection b = new MeshLib.BoxProjection(); b.BoxUvProjection(mesh); } }
/// <summary> /// Create the mesh from specified points, thickness, name and axis /// </summary> public Meshes Create(List <Vector3> points, float thickness, string name, AXIS axis = AXIS.Y) { GameObject meshObject = new GameObject(name); meshObject.name = name; meshObject.transform.position = GetMidPt(points); //get the vertices for building mesh Vector3[] verts = GetVertices(meshObject.transform, points, thickness, axis); Vector2[] pointsToTriangulate = ConvertPointsTo2DArray(meshObject.transform, verts, axis); //get necessary triangles to build mesh int[] triangles = GetTriangles(pointsToTriangulate, points.Count); //If the thickness is less than 0 then the triangles needs to be reversed //so that normals will be proper if (thickness < 0) { triangles = ReverseTriangles(triangles, points.Count); } //generate mesh using the vertices and triangles Mesh mesh = CreateMesh(verts, triangles); //UV projection for generated mesh BoxProjection b = new BoxProjection(); b.BoxUvProjection(mesh, axis); //add mesh filter MeshFilter meshFilter = meshObject.AddComponent(typeof(MeshFilter)) as MeshFilter; meshFilter.mesh = mesh; //add meshrenderer Renderer renderer = meshObject.AddComponent(typeof(MeshRenderer)) as Renderer; renderer.material = new Material(Shader.Find("Standard")); //create object for floor/ceiling Meshes meshObj = new Meshes(name, mesh, renderer, thickness); return(meshObj); }