void ControlButtons()
    {
        Color defaultColor = GUI.backgroundColor;

        GUI.backgroundColor      = Color.green;
        generateButton.fontStyle = FontStyle.Bold;

        generateButton = "button";
        if (GUILayout.Button("Generate Building", generateButton, GUILayout.Width(130), GUILayout.Height(40)))
        {
            generatorController.Generate();
        }

        GUI.backgroundColor = defaultColor;
        generateButton      = "button";
        GUILayout.Space(5);

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Export", GUILayout.Width(130), GUILayout.Height(30)))
        {
            if (!String.IsNullOrEmpty(generatorController.path))
            {
                ObjExporter.DoExport(false, generatorController.parentObj, generatorController.path);
            }
        }
        if (GUILayout.Button("Merge Mesh", GUILayout.Width(130), GUILayout.Height(30)))
        {
            generatorController.Merge();
        }

        GUILayout.EndHorizontal();
    }
Exemplo n.º 2
0
    public static bool Export(GameObject go, string path, Settings settings)
    {
        if (path == null || path.Length == 0 || go == null)
        {
            return(false);
        }

        var inst = new ObjExporter();

        inst.DoExport(go, path, settings);
        return(true);
    }
Exemplo n.º 3
0
        private static void UniStorm()
        {
            UniStormWeatherSystem uniStormWeatherSystem = GameManager.GetUniStorm();
            GameObject            starSphere            = uniStormWeatherSystem.m_StarSphere;

            Debug.Log(DumpUtils.FormatGameObject("starSphere", starSphere));

            ObjExporter.DoExport(starSphere, true);

            Renderer starSphereRenderer = starSphere.GetComponent <Renderer>();
            Material material           = starSphereRenderer.material;

            Debug.Log(DumpUtils.FormatValue("material", material));
            Debug.Log(DumpUtils.FormatValue("mainTexture", material.mainTexture));
        }
    public override void OnInspectorGUI()
    {
        meshGeneratorControler = (MeshGeneratorControler)target;
        base.OnInspectorGUI();

        if (GUILayout.Button("Export", GUILayout.Width(100)))
        {
            if (!String.IsNullOrEmpty(meshGeneratorControler.path))
            {
                ObjExporter.DoExport(false, meshGeneratorControler.GetExportObj(), meshGeneratorControler.path);
            }
        }
        if (GUILayout.Button("Generate Mesh", GUILayout.Width(100)))
        {
            meshGeneratorControler.GenerateMesh();
        }
    }
Exemplo n.º 5
0
        private static void ExportObj()
        {
            if (!HasSelection())
            {
                Debug.Log("  Current selection is empty.");
                return;
            }

            GameObject gameObject = CurrentGameObject();

            if (gameObject == null)
            {
                Debug.Log("   Cannot export obj if the current selection is not a GameObject.");
                return;
            }

            ObjExporter.DoExport(gameObject, true);
        }
Exemplo n.º 6
0
    private void OnWizardCreate()
    {
        // Return if no objects are selected
        if (Selection.gameObjects.Length <= 0)
        {
            return;
        }
        if (Selection.activeTransform == null)
        {
            return;
        }

        // Create 2 new objects. One object that will have our new mesh
        // and one that will be a parent to all merged meshes.
        GameObject combinedMeshObject = new GameObject(combinedMeshName);
        GameObject oldMeshesObject    = new GameObject(combinedMeshName + " old meshes");

        // Add a meshcombiner script to the new mesh object.
        MeshCombiner combiner = combinedMeshObject.AddComponent <MeshCombiner>();

        // Make all objects as a child to the oldMeshesObject
        for (int i = 0; i < Selection.gameObjects.Length; i++)
        {
            Selection.gameObjects[i].transform.parent = oldMeshesObject.transform;
        }

        // Add a new list of materials and renderers to the combiner and
        // exectue the Combine function
        combiner.meshes    = oldMeshesObject.GetComponentsInChildren <MeshFilter>();
        combiner.materials = new List <Material>();
        combiner.renderers = oldMeshesObject.GetComponentsInChildren <MeshRenderer>();
        combiner.CombineMeshes();

        // Optimize the new mesh.
        if (optimizeMesh)
        {
            MeshUtility.Optimize(combiner.ObjectMesh);
        }

        // Let the user choose a path and name for the new mesh.
        string path = EditorUtility.SaveFilePanel("Save mesh asset", "Assets/", combinedMeshName, "asset");

        path = FileUtil.GetProjectRelativePath(path);

        AssetDatabase.CreateAsset(combiner.ObjectMesh, path);
        AssetDatabase.SaveAssets();

        // Deactivate the object that hold all old meshes.
        oldMeshesObject.SetActive(false);

        // Selection.objects needs to take in an array of
        // objects so we just make an temporary array and
        // give it the newly created mesh object.
        GameObject[] selectedObjects = { combinedMeshObject };

        Selection.objects = selectedObjects;

        if (savePrefab)
        {
            SaveObjectPrefab(combinedMeshObject, path);
        }

        if (exportObj)
        {
            ObjExporter.DoExport(true);
        }
    }
Exemplo n.º 7
0
    private void CreateMeshes(float depth, GameObject prefab, Transform parent)
    {
        IComparer <Vector2Radial> comparer = new Vector2RadialComparer();
        List <Vector2>            frontVertices = new List <Vector2>();
        List <Vector2Radial>      radialVertices = new List <Vector2Radial>();
        float offsetZ = depth / 2; int index = 0, pos;

        if (!AssetDatabase.IsValidFolder("Assets\\Temp"))
        {
            AssetDatabase.CreateFolder("Assets", "Temp");
        }
        GameObject[] selections = new GameObject[cells.Count];
        foreach (VoronoiCell cell in cells)
        {
            Mesh mesh = new Mesh();
            frontVertices.Clear();
            foreach (VoronoiEdge edge in cell.edges)
            {
                if (!frontVertices.Contains(edge.point1))
                {
                    frontVertices.Add(edge.point1);
                }
                if (!frontVertices.Contains(edge.point2))
                {
                    frontVertices.Add(edge.point2);
                }
            }
            radialVertices.Clear();
            foreach (Vector2 vert in frontVertices)
            {
                radialVertices.Add(new Vector2Radial(vert, cell.center));
            }
            radialVertices.Sort(comparer);

            int m = radialVertices.Count, n = m + 1, m3 = 3 * m, m6 = 6 * m;

            Vector3[] vertices = new Vector3[2 * n + 4 * m];
            Vector3[] normals  = new Vector3[2 * n + 4 * m];

            vertices[m].x = cell.center.x;
            vertices[m].y = cell.center.y;
            vertices[m].z = offsetZ;

            normals[m].x = 0;
            normals[m].y = 0;
            normals[m].z = vertices[m].z + 1;

            vertices[n + m].x = cell.center.x;
            vertices[n + m].y = cell.center.y;
            vertices[n + m].z = -offsetZ;

            normals[n + m].x = 0;
            normals[n + m].y = 0;
            normals[n + m].z = vertices[n + m].z - 1;

            for (int i = 0; i < m; ++i)
            {
                vertices[i].x = radialVertices[i].point.x;
                vertices[i].y = radialVertices[i].point.y;
                vertices[i].z = offsetZ;

                normals[i].x = 0;
                normals[i].y = 0;
                normals[i].z = vertices[i].z + 1;

                vertices[n + i].x = radialVertices[i].point.x;
                vertices[n + i].y = radialVertices[i].point.y;
                vertices[n + i].z = -offsetZ;

                normals[n + i].x = 0;
                normals[n + i].y = 0;
                normals[n + i].z = vertices[n + i].z - 1;
            }

            int[] triangles = new int[12 * m];

            for (int i = 0; i < m - 1; ++i)
            {
                triangles[3 * i]     = i;
                triangles[3 * i + 1] = i + 1;
                triangles[3 * i + 2] = m;

                triangles[m3 + 3 * i]     = n + i;
                triangles[m3 + 3 * i + 1] = n + m;
                triangles[m3 + 3 * i + 2] = n + i + 1;

                pos               = 2 * n + 4 * i;
                vertices[pos]     = vertices[i];
                vertices[pos + 1] = vertices[i + 1];
                vertices[pos + 2] = vertices[n + i];
                vertices[pos + 3] = vertices[n + i + 1];

                normals[pos]     = LineNormal(vertices[pos], vertices[pos + 1], vertices[m]);
                normals[pos + 1] = normals[pos];
                normals[pos + 2] = normals[pos];
                normals[pos + 3] = normals[pos];

                triangles[m6 + 6 * i]     = pos;
                triangles[m6 + 6 * i + 1] = pos + 2;
                triangles[m6 + 6 * i + 2] = pos + 1;
                triangles[m6 + 6 * i + 3] = pos + 2;
                triangles[m6 + 6 * i + 4] = pos + 3;
                triangles[m6 + 6 * i + 5] = pos + 1;
            }
            triangles[m3 - 3] = m - 1;
            triangles[m3 - 2] = 0;
            triangles[m3 - 1] = m;

            triangles[m6 - 3] = m + m;
            triangles[m6 - 2] = n + m;
            triangles[m6 - 1] = n;

            pos               = 2 * n + 4 * m - 4;
            vertices[pos]     = vertices[m - 1];
            vertices[pos + 1] = vertices[0];
            vertices[pos + 2] = vertices[m + m];
            vertices[pos + 3] = vertices[n];

            normals[pos]     = LineNormal(vertices[pos], vertices[pos + 1], vertices[m]);
            normals[pos + 1] = normals[pos];
            normals[pos + 2] = normals[pos];
            normals[pos + 3] = normals[pos];

            triangles[2 * m6 - 6] = pos;
            triangles[2 * m6 - 5] = pos + 2;
            triangles[2 * m6 - 4] = pos + 1;
            triangles[2 * m6 - 3] = pos + 2;
            triangles[2 * m6 - 2] = pos + 3;
            triangles[2 * m6 - 1] = pos + 1;

            mesh.vertices  = vertices;
            mesh.normals   = normals;
            mesh.triangles = triangles;

            AssetDatabase.CreateAsset(mesh, "Assets\\Temp\\mesh" + index + ".asset");
            GameObject part = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
            part.name                             = part.name + ' ' + index;
            part.transform.parent                 = parent;
            part.transform.localPosition          = Vector3.zero;
            part.GetComponent <MeshFilter>().mesh = mesh;

            selections[index] = part;

            index++;
        }

        ObjExporter.DoExport(selections);
    }
Exemplo n.º 8
0
 void model_export()
 {
     Debug.Log("The upper left corner is " + ulc.ToString());
     Debug.Log("The lower right corner is " + lrc.ToString());
     ObjExporter.DoExport(ulc, lrc);
 }