示例#1
0
        private void UpdateClonersPanel()
        {
            for (var i = 0; i < scene.Cloners.Count; i++)
            {
                EditorGUILayout.Space();

                var cloner  = scene.Cloners[i];
                var matRect =
                    EditorGUILayout.BeginVertical(GetSelectableStyle(currentCloners.Contains(cloner), true));
                P3dHelper.BeginLabelWidth(60.0f);
                if (currentCloners.Contains(cloner) == true)
                {
                    EditorGUILayout.BeginHorizontal();
                    P3dHelper.BeginColor(scene.MatNameValid(cloner.Name) == false);
                    cloner.Name = EditorGUILayout.TextField(cloner.Name);
                    P3dHelper.EndColor();
                    if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.Width(20)) == true && EditorUtility.DisplayDialog("Are you sure?", "This will delete the current cloner from the paint scene.", "Delete") == true)
                    {
                        scene.Cloners.RemoveAt(i--); P3dHelper.ClearControl();
                    }
                    EditorGUILayout.EndHorizontal();
                    cloner.Position = EditorGUILayout.Vector3Field("Position", cloner.Position);
                    cloner.Euler    = EditorGUILayout.Vector3Field("Euler", cloner.Euler);
                    cloner.Flip     = EditorGUILayout.Toggle("Flip", cloner.Flip);
                }
                else
                {
                    EditorGUILayout.LabelField(cloner.Name);
                }
                P3dHelper.EndLabelWidth();
                EditorGUILayout.EndVertical();

                if (Event.current.type == EventType.MouseDown && matRect.Contains(Event.current.mousePosition) == true)
                {
                    if (currentCloners.Remove(cloner) == false)
                    {
                        currentCloners.Add(cloner);
                    }

                    P3dHelper.ClearControl();
                }
            }

            if (GUILayout.Button("Add Cloner") == true)
            {
                currentCloners.Add(scene.AddCloner("New Cloner", Vector3.zero, Vector3.zero)); P3dHelper.ClearControl();
            }
        }
        private void UpdateLayersPanel()
        {
            GUILayout.FlexibleSpace();

            for (var i = scene.Layers.Count - 1; i >= 0; i--)
            {
                if (i < scene.Layers.Count - 1)
                {
                    EditorGUILayout.Space();
                }

                var layer     = scene.Layers[i];
                var layerRect =
                    EditorGUILayout.BeginVertical(GetSelectableStyle(layer == currentLayer, true));
                P3dHelper.BeginLabelWidth(60.0f);
                GUILayout.BeginHorizontal();
                if (layer == currentLayer)
                {
                    EditorGUILayout.BeginHorizontal();
                    layer.Name = EditorGUILayout.TextField(layer.Name);
                    if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.Width(20)) == true && EditorUtility.DisplayDialog("Are you sure?", "This will delete the current layer from the paint window.", "Delete") == true)
                    {
                        scene.RemoveLayer(layer); P3dHelper.ClearControl();
                    }
                    EditorGUILayout.EndHorizontal();
                }
                else
                {
                    GUILayout.Label(layer.Name);
                }
                GUILayout.EndHorizontal();

                if (layer == currentLayer)
                {
                    EditorGUI.BeginChangeCheck();

                    layer.Opacity = EditorGUILayout.Slider("Opacity", layer.Opacity, 0.0f, 1.0f);

                    if (EditorGUI.EndChangeCheck() == true)
                    {
                        UpdatePaintedMats();
                    }

                    //foreach (var image in layer.Images)
                    //{
                    //	EditorGUILayout.ObjectField(image.Current, typeof(Texture), true);
                    //}
                }
                P3dHelper.EndLabelWidth();
                GUILayout.EndVertical();

                if (Event.current.type == EventType.MouseDown && layerRect.Contains(Event.current.mousePosition) == true)
                {
                    currentLayer = layer; P3dHelper.ClearControl();
                }
            }

            if (GUILayout.Button("Add Layer") == true)
            {
                currentLayer = scene.AddLayer(); P3dHelper.ClearControl();
            }
        }
示例#3
0
        private void UpdateObjectsPanel()
        {
            if (Selection.gameObjects.Length == 0 && scene.Objs.Count == 0)
            {
                EditorGUILayout.HelpBox("Select a GameObject with a MesFilter+MeshRenderer or SkinnedMeshRenderer.", MessageType.Info);
            }

            // Mark
            tempObjs.ForEach(t => t.Dirty = true);

            foreach (var go in Selection.gameObjects)
            {
                if (scene.ObjExists(go.transform) == false)
                {
                    var mf = go.GetComponent <MeshFilter>();
                    var mr = go.GetComponent <MeshRenderer>();

                    if (mf != null && mr != null && mf.sharedMesh != null)
                    {
                        GUILayout.BeginVertical(EditorStyles.helpBox);
                        EditorGUI.BeginDisabledGroup(true);
                        EditorGUILayout.ObjectField(go, typeof(GameObject), true);
                        EditorGUI.EndDisabledGroup();

                        var materials = mr.sharedMaterials;

                        tempTemplates.Clear();

                        for (var i = 0; i < materials.Length; i++)
                        {
                            var material  = materials[i];
                            var templates = P3dShaderTemplate.GetTemplates(material != null ? material.shader : null);
                            var slot      = GetTempObj(go, i);

                            if (templates.Contains(slot.Template) == false)
                            {
                                slot.Template = templates.Count > 0 ? templates[0] : null;
                            }

                            GUILayout.BeginVertical(EditorStyles.helpBox);
                            P3dHelper.BeginLabelWidth(60.0f);
                            EditorGUI.BeginDisabledGroup(true);
                            EditorGUILayout.ObjectField("Material", material, typeof(Material), true);
                            EditorGUI.EndDisabledGroup();
                            P3dHelper.BeginColor(slot.Template == null);
                            P3dShaderTemplate_Editor.DrawDropdown("Template", material, slot);
                            P3dHelper.EndColor();
                            P3dHelper.EndLabelWidth();
                            GUILayout.EndVertical();

                            tempTemplates.Add(slot.Template);
                        }

                        if (GUILayout.Button("Add") == true)
                        {
                            scene.AddObj(go.transform, mf.sharedMesh, go.transform.position, go.transform.rotation, go.transform.lossyScale, materials, tempTemplates.ToArray(), settings.DefaultTextureSize);
                        }
                        GUILayout.EndVertical();
                    }
                }
            }

            // Sweep
            tempObjs.RemoveAll(t => t.Dirty == true);

            EditorGUILayout.Separator();

            for (var i = 0; i < scene.Objs.Count; i++)
            {
                if (i > 0)
                {
                    EditorGUILayout.Space();
                }

                var obj     = scene.Objs[i];
                var objRect =
                    EditorGUILayout.BeginVertical(GetSelectableStyle(obj == currentObj, true));
                P3dHelper.BeginLabelWidth(60.0f);
                if (obj == currentObj)
                {
                    EditorGUILayout.BeginHorizontal();
                    obj.Name = EditorGUILayout.TextField(obj.Name);
                    if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.Width(20)) == true && EditorUtility.DisplayDialog("Are you sure?", "This will delete the current layer from the paint window.", "Delete") == true)
                    {
                        scene.RemoveObj(obj); i--; P3dHelper.ClearControl();
                    }
                    EditorGUILayout.EndHorizontal();

                    obj.Mesh      = (Mesh)EditorGUILayout.ObjectField("Mesh", obj.Mesh, typeof(Mesh), true);
                    obj.Paintable = EditorGUILayout.Toggle("Paintable", obj.Paintable);
                    obj.Coord     = (P3dCoord)EditorGUILayout.EnumPopup("Coord", obj.Coord);
                    obj.Transform = (Transform)EditorGUILayout.ObjectField("Transform", obj.Transform, typeof(Transform), true);

                    if (obj.Transform == null)
                    {
                        obj.Position = EditorGUILayout.Vector3Field("Position", obj.Position);

                        EditorGUI.BeginChangeCheck();
                        var newRot = EditorGUILayout.Vector3Field("Rotation", obj.Rotation.eulerAngles);
                        if (EditorGUI.EndChangeCheck() == true)
                        {
                            obj.Rotation = Quaternion.Euler(newRot);
                        }

                        obj.Scale = EditorGUILayout.Vector3Field("Scale", obj.Scale);
                    }

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Materials", EditorStyles.boldLabel);
                    if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.Width(20)) == true)
                    {
                        obj.MatIds.Add(-1);
                    }
                    EditorGUILayout.EndHorizontal();

                    for (var j = 0; j < obj.MatIds.Count; j++)
                    {
                        var matId = obj.MatIds[j];
                        var rect  = P3dHelper.Reserve(); rect.xMin += 10;
                        var mat   = scene.GetMat(matId);

                        if (GUI.Button(rect, mat != null ? mat.Name : "", EditorStyles.popup) == true)
                        {
                            var menu = new GenericMenu();

                            for (var k = 0; k < scene.Mats.Count; k++)
                            {
                                var setObj = obj;
                                var setIdx = j;
                                var setMat = scene.Mats[k];

                                menu.AddItem(new GUIContent(setMat.Name), setMat == mat, () => setObj.MatIds[setIdx] = setMat.Id);
                            }

                            var remObj = obj;
                            var remIdx = j;

                            menu.AddSeparator("");
                            menu.AddItem(new GUIContent("Remove"), false, () => remObj.MatIds.RemoveAt(remIdx));

                            menu.DropDown(rect);
                        }
                    }
                }
                else
                {
                    EditorGUILayout.LabelField(obj.Name);
                }
                P3dHelper.EndLabelWidth();
                EditorGUILayout.EndVertical();

                if (Event.current.type == EventType.MouseDown && objRect.Contains(Event.current.mousePosition) == true)
                {
                    currentObj = obj; P3dHelper.ClearControl();
                }
            }
        }
示例#4
0
        private void UpdateMaterialsPanel()
        {
            for (var i = 0; i < scene.Mats.Count; i++)
            {
                EditorGUILayout.Space();

                var mat     = scene.Mats[i];
                var matRect =
                    EditorGUILayout.BeginVertical(GetSelectableStyle(mat == currentMat, true));
                P3dHelper.BeginLabelWidth(60.0f);
                if (mat == currentMat)
                {
                    EditorGUILayout.BeginHorizontal();
                    P3dHelper.BeginColor(scene.MatNameValid(mat.Name) == false);
                    mat.Name = EditorGUILayout.TextField(mat.Name);
                    P3dHelper.EndColor();
                    if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.Width(20)) == true && EditorUtility.DisplayDialog("Are you sure?", "This will delete the current material from the paint window.", "Delete") == true)
                    {
                        scene.Mats.RemoveAt(i--); P3dHelper.ClearControl();
                    }
                    EditorGUILayout.EndHorizontal();
                    P3dHelper.BeginColor(mat.Material == null);
                    mat.Material = (Material)EditorGUILayout.ObjectField("Material", mat.Material, typeof(Material), true);
                    P3dHelper.EndColor();
                    P3dHelper.BeginColor(mat.Template == null);
                    P3dShaderTemplate_Editor.DrawDropdown("Template", mat.Material, mat);
                    P3dHelper.EndColor();
                    mat.Width  = EditorGUILayout.IntField("Width", mat.Width);
                    mat.Height = EditorGUILayout.IntField("Height", mat.Height);

                    /*
                     *              foreach (var slot in mat.Slots)
                     *              {
                     *                      EditorGUILayout.ObjectField(slot.Texture, typeof(Texture), false);
                     *              }
                     *
                     *              foreach (var layer in mat.MergedLayers.Values)
                     *              {
                     *                      if (layer.Layer != null)
                     *                      {
                     *                      EditorGUILayout.LabelField(layer.Layer.Name );
                     *                      }
                     *                      EditorGUILayout.ObjectField(layer.Under, typeof(Texture), false);
                     *                      EditorGUILayout.ObjectField(layer.Above, typeof(Texture), false);
                     *                      EditorGUILayout.ObjectField(layer.Final, typeof(Texture), false);
                     *              }
                     */
                    if (mat.SizesMatch == false && GUILayout.Button("Resize") == true)
                    {
                        mat.Resize();
                    }
                }
                else
                {
                    EditorGUILayout.LabelField(mat.Name);
                }
                P3dHelper.EndLabelWidth();
                EditorGUILayout.EndVertical();

                if (Event.current.type == EventType.MouseDown && matRect.Contains(Event.current.mousePosition) == true)
                {
                    currentMat = mat; P3dHelper.ClearControl();
                }
            }

            if (GUILayout.Button("Add Material") == true)
            {
                currentMat = scene.AddMat(null, null, settings.DefaultTextureSize); P3dHelper.ClearControl();
            }
        }
示例#5
0
        private void UpdateObjectsPanel()
        {
            if (Selection.gameObjects.Length == 0 && scene.Objs.Count == 0)
            {
                EditorGUILayout.HelpBox("Select a GameObject with a MesFilter+MeshRenderer or SkinnedMeshRenderer.", MessageType.Info);
            }

            // Mark
            tempObjs.ForEach(t => t.Dirty = true);

            roots.Clear();

            foreach (var transform in Selection.transforms)
            {
                RunRoots(transform);
            }

            foreach (var root in roots)
            {
                if (scene.ObjExists(root) == false)
                {
                    var mf  = root.GetComponent <MeshFilter>();
                    var mr  = root.GetComponent <MeshRenderer>();
                    var smr = root.GetComponent <SkinnedMeshRenderer>();

                    if (mf != null && mr != null && mf.sharedMesh != null)
                    {
                        if (DrawAddableObject(root.gameObject, mr.sharedMaterials) == true)
                        {
                            scene.AddObj(root, mf.sharedMesh, root.position, root.rotation, root.lossyScale, mr.sharedMaterials, tempTemplates.ToArray(), settings.DefaultTextureSize);
                        }
                    }
                    else if (smr != null && smr.sharedMesh != null)
                    {
                        if (DrawAddableObject(root.gameObject, smr.sharedMaterials) == true)
                        {
                            scene.AddObj(root, smr.sharedMesh, root.position, root.rotation, root.lossyScale, smr.sharedMaterials, tempTemplates.ToArray(), settings.DefaultTextureSize);
                        }
                    }
                }
            }

            // Sweep
            tempObjs.RemoveAll(t => t.Dirty == true);

            EditorGUILayout.Separator();

            for (var i = 0; i < scene.Objs.Count; i++)
            {
                if (i > 0)
                {
                    EditorGUILayout.Space();
                }

                var obj     = scene.Objs[i];
                var objRect =
                    EditorGUILayout.BeginVertical(GetSelectableStyle(obj == currentObj, true));
                P3dHelper.BeginLabelWidth(60.0f);
                if (obj == currentObj)
                {
                    EditorGUILayout.BeginHorizontal();
                    obj.Name = EditorGUILayout.TextField(obj.Name);
                    if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.Width(20)) == true && EditorUtility.DisplayDialog("Are you sure?", "This will delete the current layer from the paint window.", "Delete") == true)
                    {
                        scene.RemoveObj(obj); i--; P3dHelper.ClearControl();
                    }
                    EditorGUILayout.EndHorizontal();

                    obj.Mesh      = (Mesh)EditorGUILayout.ObjectField("Mesh", obj.Mesh, typeof(Mesh), true);
                    obj.Paintable = EditorGUILayout.Toggle("Paintable", obj.Paintable);
                    obj.Coord     = (P3dCoord)EditorGUILayout.EnumPopup("Coord", obj.Coord);
                    obj.Transform = (Transform)EditorGUILayout.ObjectField("Transform", obj.Transform, typeof(Transform), true);
                    obj.Preview   = (Transform)EditorGUILayout.ObjectField("Preview", obj.Preview, typeof(Transform), true);

                    if (obj.Transform == null)
                    {
                        obj.Position = EditorGUILayout.Vector3Field("Position", obj.Position);

                        EditorGUI.BeginChangeCheck();
                        var newRot = EditorGUILayout.Vector3Field("Rotation", obj.Rotation.eulerAngles);
                        if (EditorGUI.EndChangeCheck() == true)
                        {
                            obj.Rotation = Quaternion.Euler(newRot);
                        }

                        obj.Scale = EditorGUILayout.Vector3Field("Scale", obj.Scale);
                    }
                    else
                    {
                        var smr = obj.Transform.GetComponent <SkinnedMeshRenderer>();

                        if (smr != null && smr.sharedMesh != null)
                        {
                            if (obj.BakedMesh == null)
                            {
                                if (GUILayout.Button("Bake Pose") == true)
                                {
                                    BakeMesh(smr, ref obj.BakedMesh, false);
                                }

                                if (GUILayout.Button("Bake Pose + Scale") == true)
                                {
                                    BakeMesh(smr, ref obj.BakedMesh, true);
                                }
                            }
                            else
                            {
                                if (GUILayout.Button("Update Pose") == true)
                                {
                                    BakeMesh(smr, ref obj.BakedMesh, obj.BakedMesh.name == "SCALED");
                                }

                                if (GUILayout.Button("Reset Pose") == true)
                                {
                                    DestroyImmediate(obj.BakedMesh);

                                    obj.BakedMesh = null;
                                }
                            }
                        }
                    }

                    if (GUILayout.Button("Center Camera") == true)
                    {
                        cameraOrigin = obj.Position;
                    }

                    EditorGUILayout.Separator();

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Materials", EditorStyles.boldLabel);
                    if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.Width(20)) == true)
                    {
                        obj.MatIds.Add(-1);
                    }
                    EditorGUILayout.EndHorizontal();

                    for (var j = 0; j < obj.MatIds.Count; j++)
                    {
                        var matId = obj.MatIds[j];
                        var rect  = P3dHelper.Reserve(); rect.xMin += 10;
                        var mat   = scene.GetMat(matId);

                        if (GUI.Button(rect, mat != null ? mat.Name : "", EditorStyles.popup) == true)
                        {
                            var menu = new GenericMenu();

                            for (var k = 0; k < scene.Mats.Count; k++)
                            {
                                var setObj = obj;
                                var setIdx = j;
                                var setMat = scene.Mats[k];

                                menu.AddItem(new GUIContent(setMat.Name), setMat == mat, () => setObj.MatIds[setIdx] = setMat.Id);
                            }

                            var remObj = obj;
                            var remIdx = j;

                            menu.AddSeparator("");
                            menu.AddItem(new GUIContent("Remove"), false, () => remObj.MatIds.RemoveAt(remIdx));

                            menu.DropDown(rect);
                        }
                    }
                }
                else
                {
                    EditorGUILayout.LabelField(obj.Name);
                }
                P3dHelper.EndLabelWidth();
                EditorGUILayout.EndVertical();

                if (Event.current.type == EventType.MouseDown && objRect.Contains(Event.current.mousePosition) == true)
                {
                    currentObj = obj; P3dHelper.ClearControl();
                }
            }
        }