Esempio n. 1
0
        public override void OnInspectorGUI()
        {
            ClayContainer clayxel = (ClayContainer)this.target;

            EditorGUILayout.LabelField("Clayxels, V0.51 beta");
            EditorGUILayout.LabelField("clayObjects: " + clayxel.getNumClayObjects());

                        #if !CLAYXELS_FULL
            EditorGUILayout.LabelField("free version limit is 64");
                        #else
            EditorGUILayout.LabelField("limit is " + clayxel.getMaxSolids());
                        #endif

            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();
            int        gridResolution = EditorGUILayout.IntField("resolution", clayxel.gridResolution);
            Vector3Int gridSize       = EditorGUILayout.Vector3IntField("containerSize", new Vector3Int(clayxel.gridSizeX, clayxel.gridSizeY, clayxel.gridSizeZ));

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(this.target, "changed clayxel grid");

                clayxel.gridResolution = gridResolution;
                clayxel.gridSizeX      = gridSize.x;
                clayxel.gridSizeY      = gridSize.y;
                clayxel.gridSizeZ      = gridSize.z;

                clayxel.init();
                clayxel.needsUpdate = true;
                UnityEditor.EditorApplication.QueuePlayerLoopUpdate();
                ClayContainer.getSceneView().Repaint();

                return;
            }

            EditorGUI.BeginChangeCheck();

            EditorGUILayout.Space();

            Material customMaterial = (Material)EditorGUILayout.ObjectField("customMaterial", clayxel.customMaterial, typeof(Material), false);

            float     materialSmoothness        = 0.0f;
            float     materialMetallic          = 0.0f;
            Color     materialEmission          = new Color();
            float     materialEmissionIntensity = 0.0f;
            float     splatSizeMultiplier       = 1.0f;
            float     normalOrientedSplat       = 1.0f;
            Texture2D splatTexture = null;

            if (customMaterial == null)
            {
                materialSmoothness        = EditorGUILayout.FloatField("smoothness", clayxel.materialSmoothness);
                materialMetallic          = EditorGUILayout.FloatField("metallic", clayxel.materialMetallic);
                materialEmission          = EditorGUILayout.ColorField("emission", clayxel.materialEmission);
                materialEmissionIntensity = EditorGUILayout.FloatField("emissionIntensity", clayxel.materialEmissionIntensity);
                splatSizeMultiplier       = EditorGUILayout.FloatField("clayxelsSize", clayxel.splatSizeMultiplier);
                normalOrientedSplat       = EditorGUILayout.FloatField("normal oritented", clayxel.normalOrientedSplat);
                splatTexture = (Texture2D)EditorGUILayout.ObjectField("texture", clayxel.splatTexture, typeof(Texture2D), false);
            }

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(this.target, "changed clayxel container");

                if (customMaterial == null)
                {
                    clayxel.materialSmoothness        = materialSmoothness;
                    clayxel.materialMetallic          = materialMetallic;
                    clayxel.materialEmission          = materialEmission;
                    clayxel.materialEmissionIntensity = materialEmissionIntensity;
                    clayxel.splatSizeMultiplier       = splatSizeMultiplier;
                    clayxel.normalOrientedSplat       = normalOrientedSplat;
                    clayxel.splatTexture = splatTexture;
                }

                if (clayxel.normalOrientedSplat < 0.0f)
                {
                    clayxel.normalOrientedSplat = 0.0f;
                }
                else if (clayxel.normalOrientedSplat > 1.0f)
                {
                    clayxel.normalOrientedSplat = 1.0f;
                }

                clayxel.updateSplatLook();

                if (customMaterial != clayxel.customMaterial)
                {
                    clayxel.customMaterial = customMaterial;
                    clayxel.init();
                }

                clayxel.needsUpdate = true;
                clayxel.forceUpdateAllChunks();
                UnityEditor.EditorApplication.QueuePlayerLoopUpdate();
                ClayContainer.getSceneView().Repaint();

                return;
            }

            EditorGUILayout.Space();

            if (GUILayout.Button("reload all"))
            {
                ClayContainer.reloadAll();
            }

            if (GUILayout.Button("pick solid (p)"))
            {
                ClayContainer.startPicking();
            }

            if (GUILayout.Button("add solid"))
            {
                ClayObject clayObj = ((ClayContainer)this.target).addSolid();

                Undo.RegisterCreatedObjectUndo(clayObj.gameObject, "added clayxel solid");
                UnityEditor.Selection.objects = new GameObject[] { clayObj.gameObject };

                clayxel.needsUpdate = true;
                UnityEditor.EditorApplication.QueuePlayerLoopUpdate();
                ClayContainer.getSceneView().Repaint();

                return;
            }

            EditorGUILayout.Space();

                        #if CLAYXELS_FULL
            clayxel.exportRetopoFBX = EditorGUILayout.Toggle("retopology", clayxel.exportRetopoFBX);
            if (clayxel.exportRetopoFBX)
            {
                clayxel.retopoMaxVerts = EditorGUILayout.IntField("max verts", clayxel.retopoMaxVerts);

                clayxel.retopoFbxFile = EditorGUILayout.TextField("export fbx", clayxel.retopoFbxFile);
            }
                        #endif

            if (!clayxel.hasCachedMesh())
            {
                if (GUILayout.Button("freeze to mesh"))
                {
                    if (clayxel.exportRetopoFBX)
                    {
                        clayxel.retopoMesh();
                    }
                    else
                    {
                        clayxel.generateMesh();
                    }
                }
            }
            else
            {
                if (GUILayout.Button("defrost clayxels"))
                {
                    clayxel.disableMesh();
                    UnityEditor.EditorApplication.QueuePlayerLoopUpdate();
                    ClayContainer.getSceneView().Repaint();
                }
            }
        }