Ejemplo n.º 1
0
    void GenerateHouse()
    {
        //ensures houses are created in a horizontal line
        float oldRandX = randX;

        randX = Random.Range(SizeRange.x, SizeRange.y);
        randY = Random.Range(SizeRange.x, SizeRange.y);
        randZ = Random.Range(SizeRange.x, SizeRange.y);

        if (Input.GetKeyDown(KeyCode.Space))
        {
            distX += (10.2f * randX) + (10.2f * oldRandX);
        }

        if (Input.GetKeyDown(KeyCode.RightShift) || Input.GetKeyDown(KeyCode.LeftShift))
        {
            distX  = posX;
            distZ += (27.5f * SizeRange.y);
        }

        //Creates a new house
        AXModel newModel = Instantiate(model, new Vector3(distX, model.transform.position.y, distZ), Quaternion.identity);

        GenerateDesign(newModel);

        //changes the width of the landscape
        newModel.getParameter("Full House_Scale_X").initiateRipple_setFloatValueFromGUIChange(randX);
        //newModel.GetComponentInChildren<TerrainGenerator>().scaleX = randX;
        //field.scaleX = randX;

        //changes the height of the landscape
        newModel.getParameter("Full House_Scale_Y").initiateRipple_setFloatValueFromGUIChange(randY);
        //newModel.GetComponentInChildren<TerrainGenerator>().scaleY = randY;
        //field.scaleY = randY;

        //changes the length of the landscape
        newModel.getParameter("Full House_Scale_Z").initiateRipple_setFloatValueFromGUIChange(randZ);
        //newModel.GetComponentInChildren<TerrainGenerator>().scaleZ = randZ;
        //field.scaleZ = randZ;

        GenerateBackyard(newModel);

        newModel.build();
    }
Ejemplo n.º 2
0
    public static void makePrefab(AXModel model, string prefabPath, AXNodeGraphEditorWindow _editor)
    {
        //if (model == null)
        //	return null;

        if (model.generatedGameObjects != null)
        {
            // extrat folder path from path

            //string filename = System.IO.Path.GetFileName (filepath);
            string prefabName = System.IO.Path.GetFileNameWithoutExtension(prefabPath);

            string relativePrefabPath = ArchimatixUtils.getRelativeFilePath(prefabPath);

            string folderPath         = System.IO.Path.GetDirectoryName(prefabPath);
            string relativeFolderPath = ArchimatixUtils.getRelativeFilePath(folderPath);

            // if no directory selected in dialog, then relativeFolderPath is empty
            if (String.IsNullOrEmpty(relativeFolderPath))
            {
                relativeFolderPath = "Assets";
            }

            Debug.Log(folderPath + " :: " + relativeFolderPath + " :: " + prefabName);

            model.build();

            GameObject stampedGO = model.stamp();

            // Only save unique, sharedMeshes to the AssetsDatabase
            List <Mesh> meshesToSave = new List <Mesh> ();
            int         meshCount    = 0;

            Transform[] transforms = stampedGO.GetComponentsInChildren <Transform> ();
            foreach (Transform transform in transforms)
            {
                MeshFilter meshFilter = transform.gameObject.GetComponent <MeshFilter> ();

                if (meshFilter != null)
                {
                    Mesh mesh = meshFilter.sharedMesh;
                    if (mesh != null && !meshesToSave.Contains(mesh))
                    {
                        ;
                        meshesToSave.Add(mesh);

                        meshCount++;
                    }
                    GameObjectUtility.SetStaticEditorFlags(transform.gameObject, StaticEditorFlags.LightmapStatic);
                }
            }

            AssetDatabase.DeleteAsset(relativePrefabPath);


            // [not sure why this is needed here to correct the filepath, but not in the Library Save dalog...]
            relativePrefabPath = relativePrefabPath.Replace('\\', '/');



            var prefab = PrefabUtility.CreateEmptyPrefab(relativePrefabPath);

            int i = 0;
            foreach (Mesh mesh in meshesToSave)

            /*
             * {
             *      if (string.IsNullOrEmpty(mesh.name))
             *              mesh.name = prefabName+"_"+(i++);
             *      AssetDatabase.DeleteAsset (relativePrefabPath+"/"+mesh.name);
             *      AssetDatabase.AddObjectToAsset(mesh, relativePrefabPath);
             * }
             */
            {             // Compliments of Enoch
                if (string.IsNullOrEmpty(mesh.name))
                {
                    mesh.name = prefabName + "_" + (i++);
                }
                var path = AssetDatabase.GetAssetPath(mesh);

                if (string.IsNullOrEmpty(path))
                {
                    AssetDatabase.AddObjectToAsset(mesh, relativePrefabPath);
                }
            }



            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            PrefabUtility.ReplacePrefab(stampedGO, prefab, ReplacePrefabOptions.ConnectToPrefab);

            stampedGO.name = prefabName;
            //Selection.activeGameObject = stampedGO;

            //buildStatus = BuildStatus.Generated;



            //Close();
        }
    }
        // return the height of this gui area
        public static void OnGUI(Rect headerRect, AXNodeGraphEditorWindow editor)
        {
            Event e = Event.current;

            AXModel model = editor.model;

            // DO HEADER MENU BAR -- MODEL MENU


            GUILayout.BeginArea(headerRect);
            GUILayout.BeginHorizontal();

            GUIStyle labelstyle = new GUIStyle(GUI.skin.label);

            labelstyle.alignment = TextAnchor.LowerLeft;

            labelstyle.fixedWidth = 150;


            GUILayout.Space(5);


            if (GUILayout.Button("2D"))
            {
                ArchimatixEngine.openLibrary2D();
            }
            if (GUILayout.Button("3D"))
            {
                ArchimatixEngine.openLibrary3D();
            }



            // NEW MODEL
            GUILayout.Space(10);



            if (GUILayout.Button("▼"))
            {
                AXModel[] allModels = ArchimatixUtils.getAllModels();


                GenericMenu menu = new GenericMenu();

                //menu.AddSeparator("Library ...");


                if (allModels != null && allModels.Length > 0)
                {
                    for (int i = 0; i < allModels.Length; i++)
                    {
                        AXModel m = allModels [i];
                        menu.AddItem(new GUIContent(m.gameObject.name), false, () => {
                            Selection.activeGameObject    = m.gameObject;
                            ArchimatixEngine.currentModel = m;
                        });
                    }
                }


                menu.AddSeparator("");

                menu.AddItem(new GUIContent("New Model"), false, () => {
                    AXEditorUtilities.createNewModel();
                });

                menu.ShowAsContext();
            }



            Color bgc = GUI.backgroundColor;

            GUI.backgroundColor = Color.clear;



            if (model != null)
            {
                // SELECTED MODEL
                if (GUILayout.Button(model.name))
                {
                    model.currentWorkingGroupPO = null;

                    model.selectAllVisibleInGroup(null);

                    float framePadding = 50;

                    Rect allRect = AXUtilities.getBoundaryRectFromPOs(model.selectedPOs);
                    allRect.x      -= framePadding;
                    allRect.y      -= framePadding;
                    allRect.width  += framePadding * 2;
                    allRect.height += framePadding * 2;



                    AXNodeGraphEditorWindow.zoomToRectIfOpen(allRect);
                }



                if (model.currentWorkingGroupPO != null)
                {
                    if (model.currentWorkingGroupPO.grouper != null)
                    {
                        // Make breadcrumb trail
                        List <AXParametricObject> crumbs = new List <AXParametricObject>();
                        AXParametricObject        cursor = model.currentWorkingGroupPO;


                        while (cursor.grouper != null)
                        {
                            crumbs.Add(cursor.grouper);
                            cursor = cursor.grouper;
                        }
                        crumbs.Reverse();

                        // model button frames



                        for (int i = 0; i < crumbs.Count; i++)
                        {
                            if (GUILayout.Button("> " + crumbs[i].Name))
                            {
                                model.currentWorkingGroupPO = crumbs[i];
                                Rect grouperCanvasRect = model.currentWorkingGroupPO.getBoundsRect();
                                editor.zoomToRect(grouperCanvasRect);
                            }
                        }
                    }
                    GUILayout.Button("> " + model.currentWorkingGroupPO.Name);
                }
            }
            GUILayout.FlexibleSpace();



            if (model != null)
            {
                Color  buildBG    = Color.Lerp(Color.cyan, Color.white, .8f);
                string buildLabel = "Rebuild";



                if (model.buildStatus == AXModel.BuildStatus.Generated)
                {
                    buildBG    = Color.red;
                    buildLabel = "Build";
                }



                GUI.backgroundColor = buildBG;
                if (GUILayout.Button(buildLabel))
                {
                    model.build();
                }

                GUI.backgroundColor = Color.cyan;


                if (model.generatedGameObjects != null && model.generatedGameObjects.transform.childCount == 0)
                {
                    GUI.enabled = false;
                }

                if (GUILayout.Button("Stamp"))
                {
                    model.stamp();
                }

                if (GUILayout.Button("Prefab"))
                {
                    string startDir = Application.dataPath;

                    string path = EditorUtility.SaveFilePanel(
                        "Save Prefab",
                        startDir,
                        ("" + model.name),
                        "prefab");

                    if (!string.IsNullOrEmpty(path))
                    {
                        AXPrefabWindow.makePrefab(model, path, editor);
                    }
                }
                GUI.enabled = true;

                GUILayout.Space(4);
            }


            GUILayout.EndHorizontal();
            GUILayout.EndArea();

            GUI.backgroundColor = bgc;
        }
Ejemplo n.º 4
0
        public static AXParametricObject instantiateParametricObject(string readIntoLibraryFromRelativeAXOBJPath)
        {
            AXModel model = null;

            // 1. First choice is to use a selected model....
            if (ArchimatixEngine.currentModel != null)
            {
                model = ArchimatixEngine.currentModel;
            }

            bool doInstantiation = true;

            if (model == null)
            {
                // ok, are there other models in the scene that the user doesn't realize arene't selected?
                AXModel[] axModels = GameObject.FindObjectsOfType(typeof(AXModel)) as AXModel[];

                if (axModels != null)
                {
                    if (axModels.Length == 1)
                    {
                        // Offer this model as a button,  but also give opportunity to create a new one...
                        int option = EditorUtility.DisplayDialogComplex("Instantiating Library Item", "There is no AX model currently selected", "Cancel", "Add to " + axModels[0], "Create a new Model");


                        switch (option)
                        {
                        // Save Scene
                        case 0:
                            doInstantiation = false;
                            break;

                        // Save and Quit.
                        case 1:
                            model = axModels[0];
                            break;

                        case 2:
                            GameObject axgo = AXEditorUtilities.createNewModel();
                            model           = axgo.GetComponent <AXModel>();
                            doInstantiation = false;
                            break;

                        default:
                            doInstantiation = false;
                            break;
                        }
                    }

                    else if (axModels.Length > 1)
                    {
                        // Throw up a dialog to see if use wants to go select one of the existing models or create a new one.

                        if (EditorUtility.DisplayDialog("Instantiating Library Item", "There is no AX model currently selected", "Select and Existing Model", "Create a new Model"))
                        {
                            return(null);
                        }
                    }
                }
            }


            if (!doInstantiation)
            {
                return(null);
            }



            if (model == null)
            {                   // Well, then, we tried everything....
                GameObject axgo = AXEditorUtilities.createNewModel();
                model = axgo.GetComponent <AXModel>();
            }



            //Library.lastInstantiation = po;

            // This file path is where the metadata
            // for this head_po was found. Go back to this file
            // and get the rest of the data...
            string filepath = ArchimatixUtils.getAbsoluteLibraryPath(readIntoLibraryFromRelativeAXOBJPath);


            List <AXParametricObject> poList       = new List <AXParametricObject>();
            List <AXRelation>         relationList = new List <AXRelation>();

            AX.SimpleJSON.JSONNode json = AX.SimpleJSON.JSON.Parse(File.ReadAllText(filepath));

            foreach (AX.SimpleJSON.JSONNode poNode in json["parametric_objects"].AsArray)
            {
                poList.Add(JSONSerializersAX.ParametricObjectFromJSON(poNode));
            }

            foreach (AX.SimpleJSON.JSONNode rNode in json["relations"].AsArray)
            {
                relationList.Add(AXRelation.fromJSON(rNode));
            }

            //Debug.Log (rNode);



            // make sure there is a game object ready to instantiate this on



            if (model == null)
            {
                // check if the user really wants to create a new model...

                GameObject axgo = AXEditorUtilities.createNewModel();
                model = axgo.GetComponent <AXModel>();
            }

            Undo.RegisterCompleteObjectUndo(model, "Add Library Object");



            // ADD AND RIGUP
            // !!! Actually add the library item (as a list of PO's and Relations) to the model
            model.addAndRigUp(poList, relationList);



            AXParametricObject head_po = poList[0];

            head_po.startStowInputs();
            //if (poList[0].is2D() && ArchimatixEngine.workingAxis != (int) Axis.NONE)
            //	poList[0].intValue ("Axis", ArchimatixEngine.workingAxis);


            model.setRenderMode(AXModel.RenderMode.GameObjects);
            model.generate();

            ArchimatixEngine.currentModel = model;
            Selection.activeGameObject    = model.gameObject;


            model.deselectAll();
            model.selectOnlyPO(head_po);
            head_po.focusMe = true;


            //AXParametricObject mostRecentPO = model.recentlySelectedPO;
            AXParametricObject mostRecentPO = model.recentlySelectedPO;            //getPOSelectedBefore(head_po);



            //Debug.Log ("model.focusPointInGraphEditor="+model.focusPointInGraphEditor);

            float pos_x = (model.focusPointInGraphEditor.x) + 100;          // + UnityEngine.Random.Range(-100, 300);
            float pos_y = (model.focusPointInGraphEditor.y - 250) + UnityEngine.Random.Range(-10, 0);

            if (mostRecentPO != null)
            {
                //pos_x =  mostRecentPO.rect.x + 200;
                //pos_y =  mostRecentPO.rect.y;
            }

            //Debug.Log (new Rect(pos_x, pos_y, 150, 100));
            head_po.rect = new Rect(pos_x, pos_y, 150, 500);


            //Debug.Log ("OK "+po.Name+".focusMe = " + po.focusMe);
            // make sure it is in view in the editor window....

            //model.startPanningToRect(head_po.rect);


            //model.cleanGraph();
            model.remapMaterialTools();
            model.autobuild();
            head_po.generator.adjustWorldMatrices();
            model.build();

            model.selectOnlyPO(head_po);

            //model.beginPanningToRect(head_po.rect);
            //AXNodeGraphEditorWindow.zoomToRectIfOpen(head_po.rect);

            //Debug.Log(" 1 model.selectedPOs.Count="+model.selectedPOs.Count + " " + model.selectedPOs[0].Name );
            // EDITOR WINDOW
            ArchimatixEngine.repaintGraphEditorIfExistsAndOpen();



            // SCENEVIEW
            if (SceneView.lastActiveSceneView != null)
            {
                //Debug.Log("REPAINT");
                SceneView.lastActiveSceneView.Repaint();
            }

            //Debug.Log("--> ArchimatixEngine.currentModel=" + ArchimatixEngine.currentModel);


            return(head_po);
        }