Beispiel #1
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        EditorGUILayout.Space();
        EditorGUILayout.LabelField("DEVELOPMENT", EditorStyles.boldLabel);

        index = (MaterialIndex)EditorGUILayout.ObjectField("Material Index",
                                                           index,
                                                           typeof(MaterialIndex),
                                                           true);
        uvm = (UVMapper)EditorGUILayout.ObjectField("UV Mapper",
                                                    uvm,
                                                    typeof(UVMapper),
                                                    true);
        if (index == null || uvm == null)
        {
            return;
        }

        Entity       e    = target as Entity;
        Mesh         mesh = e.transform.GetComponent <MeshFilter>().sharedMesh;
        MaterialData md   = MaterialIndex.GetMaterialData(index, e.materialID);

        if (GUILayout.Button("Box Mapping"))
        {
            UVMapper.SetUV(md, mesh, UVMapper.GetMapFunction(uvm, UVMapFnID.PROJECTION));
        }

        if (GUILayout.Button("Bark Mapping"))
        {
            UVMapper.SetUV(md, mesh, UVMapper.GetMapFunction(uvm, UVMapFnID.BARK));
        }
    }
Beispiel #2
0
    private void UpdateMesh(List <Vector3> input, Mesh mesh, MaterialID matid, UVMapper uvMapper)
    {
        Vertex3[] inputVtx3 = new Vertex3[input.Count];
        CastToVertex3(input, inputVtx3);

        ConvexHull <Vertex3, Face3> hull = ConvexHull.Create <Vertex3, Face3>(inputVtx3, 0.0001);

//        List<Vertex3> hullVtx3 = new List<Vertex3>(hull.Points);
        List <Vertex3> hullVtx3 = new List <Vertex3>();
        List <Face3>   faces    = new List <Face3>(hull.Faces);

        int[] indices = new int[faces.Count * 3];

        int n = 0;

        for (int i = 0; i < faces.Count; ++i)
        {
            // Sometime in the future, I'd like each side of the log
            // to share vertices, and only separate them along the
            // cardinal edges.

            // This is how we do it when we want to separate each
            // triangle. We create a vertex for each point of each
            // triangle.
            hullVtx3.Add(faces[i].Vertices[0]);
            indices[n++] = hullVtx3.Count - 1;
            hullVtx3.Add(faces[i].Vertices[1]);
            indices[n++] = hullVtx3.Count - 1;
            hullVtx3.Add(faces[i].Vertices[2]);
            indices[n++] = hullVtx3.Count - 1;

            // This is the way to do it when you want to share
            // vertices between triangles. That's not going to
            // work with texture atlassing.
//            indices[n++] = hullVtx3.IndexOf(faces[i].Vertices[0]);
//            indices[n++] = hullVtx3.IndexOf(faces[i].Vertices[1]);
//            indices[n++] = hullVtx3.IndexOf(faces[i].Vertices[2]);
        }

        Vector3[] vertices = new Vector3[hullVtx3.Count];
        CastToVector3(hullVtx3, vertices);

        mesh.Clear();
        mesh.vertices = vertices;
        mesh.SetIndices(indices, MeshTopology.Triangles, 0);

        MaterialData md    = MaterialIndex.GetMaterialData(matIndex, matid);
        UVMapFn      mapFn = UVMapper.GetMapFunction(uvMapper, md.mapFnID);

        UVMapper.SetUV(md, mesh, mapFn);

        mesh.RecalculateNormals();
        mesh.RecalculateBounds();
    }