Beispiel #1
0
 public virtual void Init(SplineComputer comp)
 {
     computer   = comp;
     lastClosed = comp.isClosed;
     lastType   = comp.type;
     lastPoints = comp.GetPoints(SplineComputer.Space.Local);
 }
Beispiel #2
0
 internal SplineDefinition(string n, Spline spline)
 {
     name   = n;
     type   = spline.type;
     closed = spline.isClosed;
     points = new List <SplinePoint>(spline.points);
 }
 public static void LoadPrefs()
 {
     defaultAlwaysDraw     = EditorPrefs.GetBool("Dreamteck.Splines.defaultAlwaysDraw", false);
     defaultShowThickness  = EditorPrefs.GetBool("Dreamteck.Splines.defaultShowThickness", false);
     default2D             = EditorPrefs.GetBool("Dreamteck.Splines.default2D", false);
     showPointNumbers      = EditorPrefs.GetBool("Dreamteck.Splines.showPointNumbers", false);
     defaultColor          = LoadColor("Dreamteck.Splines.defaultColor", Color.white);
     highlightColor        = LoadColor("Dreamteck.Splines.highlightColor", new Color(0f, 0.564f, 1f, 1f));
     highlightContentColor = LoadColor("Dreamteck.Splines.highlightContentColor", new Color(1f, 1f, 1f, 0.95f));
     defaultComputerSpace  = (SplineComputer.Space)EditorPrefs.GetInt("Dreamteck.Splines.defaultComputerSpace", 0);
     defaultType           = (Spline.Type)EditorPrefs.GetInt("Dreamteck.Splines.defaultType", 0);
     loaded = true;
 }
Beispiel #4
0
 public override void Select()
 {
     base.Select();
     lastClosed = editor.isClosed;
     lastType   = editor.splineType;
     Apply();
     if (mode == 0)
     {
         LoadPrimitives();
     }
     else if (!createPresetMode)
     {
         LoadPresets();
     }
 }
Beispiel #5
0
        public static void OnGUI()
        {
            if (!loaded)
            {
                LoadPrefs();
            }
            EditorGUILayout.LabelField("Newly created splines:", EditorStyles.boldLabel);
            startInCreationMode  = EditorGUILayout.Toggle("Start in Creation Mode", startInCreationMode);
            defaultComputerSpace = (SplineComputer.Space)EditorGUILayout.EnumPopup("Space", defaultComputerSpace);
            defaultType          = (Spline.Type)EditorGUILayout.EnumPopup("Type", defaultType);
            defaultAlwaysDraw    = EditorGUILayout.Toggle("Always draw", defaultAlwaysDraw);
            defaultShowThickness = EditorGUILayout.Toggle("Show thickness", defaultShowThickness);
            default2D            = EditorGUILayout.Toggle("2D Mode", default2D);
            defaultColor         = EditorGUILayout.ColorField("Spline color", defaultColor);
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Newly created points:", EditorStyles.boldLabel);
            createPointSize  = EditorGUILayout.FloatField("Default Size", createPointSize);
            createPointColor = EditorGUILayout.ColorField("Default Color", createPointColor);
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Editor", EditorStyles.boldLabel);
            highlightColor        = EditorGUILayout.ColorField("Highlight color", highlightColor);
            highlightContentColor = EditorGUILayout.ColorField("Highlight content color", highlightContentColor);
            duplicationDirection  = (DuplicationDirection)EditorGUILayout.EnumPopup("Duplicate Direction", duplicationDirection);
            showPointNumbers      = EditorGUILayout.Toggle("Show point numbers", showPointNumbers);

            if (GUILayout.Button("Use Defaults", GUILayout.Width(120)))
            {
                duplicationDirection  = DuplicationDirection.Forward;
                defaultAlwaysDraw     = false;
                defaultShowThickness  = false;
                default2D             = false;
                startInCreationMode   = true;
                defaultColor          = Color.white;
                highlightColor        = new Color(0f, 0.564f, 1f, 1f);
                highlightContentColor = new Color(1f, 1f, 1f, 0.95f);
                showPointNumbers      = false;
                defaultComputerSpace  = SplineComputer.Space.Local;
                defaultType           = Spline.Type.Hermite;
                createPointSize       = 1f;
                createPointColor      = Color.white;
                SavePrefs();
            }
            if (GUI.changed)
            {
                SavePrefs();
            }
        }
Beispiel #6
0
 public static void LoadPrefs()
 {
     defaultAlwaysDraw     = EditorPrefs.GetBool("Dreamteck.Splines.defaultAlwaysDraw", false);
     defaultShowThickness  = EditorPrefs.GetBool("Dreamteck.Splines.defaultShowThickness", false);
     default2D             = EditorPrefs.GetBool("Dreamteck.Splines.default2D", false);
     startInCreationMode   = EditorPrefs.GetBool("Dreamteck.Splines.startInCreationMode", true);
     showPointNumbers      = EditorPrefs.GetBool("Dreamteck.Splines.showPointNumbers", false);
     pointEditSpace        = (SplineComputer.Space)EditorPrefs.GetInt("Dreamteck.Splines.pointEditSpace", 1);
     defaultColor          = LoadColor("Dreamteck.Splines.defaultColor", Color.white);
     highlightColor        = LoadColor("Dreamteck.Splines.highlightColor", new Color(0f, 0.564f, 1f, 1f));
     highlightContentColor = LoadColor("Dreamteck.Splines.highlightContentColor", new Color(1f, 1f, 1f, 0.95f));
     defaultComputerSpace  = (SplineComputer.Space)EditorPrefs.GetInt("Dreamteck.Splines.defaultComputerSpace", 0);
     defaultType           = (Spline.Type)EditorPrefs.GetInt("Dreamteck.Splines.defaultType", 0);
     duplicationDirection  = (DuplicationDirection)EditorPrefs.GetInt("Dreamteck.Splines.duplicationDirection", 0);
     createPointSize       = EditorPrefs.GetFloat("Dreamteck.Splines.createPointSize", 1f);
     createPointColor      = LoadColor("Dreamteck.Splines.createPointColor", Color.white);
     loaded = true;
 }
Beispiel #7
0
 public SplinePreset(SplinePoint[] p, bool closed, Spline.Type t)
 {
     points_position = new S_Vector3[p.Length];
     points_tanget   = new S_Vector3[p.Length];
     points_tangent2 = new S_Vector3[p.Length];
     points_normal   = new S_Vector3[p.Length];
     points_color    = new S_Color[p.Length];
     points_size     = new float[p.Length];
     points_type     = new SplinePoint.Type[p.Length];
     for (int i = 0; i < p.Length; i++)
     {
         points_position[i] = new S_Vector3(p[i].position);
         points_tanget[i]   = new S_Vector3(p[i].tangent);
         points_tangent2[i] = new S_Vector3(p[i].tangent2);
         points_normal[i]   = new S_Vector3(p[i].normal);
         points_color[i]    = new S_Color(p[i].color);
         points_size[i]     = p[i].size;
         points_type[i]     = p[i].type;
     }
     isClosed = closed;
     type     = t;
     path     = ResourceUtility.FindFolder(Application.dataPath, "Dreamteck/Splines/Presets");
 }
Beispiel #8
0
        public override void DrawInspector()
        {
            base.DrawInspector();
            if (spline == null)
            {
                return;
            }
            SplineEditorGUI.SetHighlightColors(SplinePrefs.highlightColor, SplinePrefs.highlightContentColor);
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            EditorGUI.BeginChangeCheck();
            operationsToolbar.SetContent(0, new GUIContent(spline.isClosed ? "Break" : "Close"));
            operationsToolbar.SetContent(1, new GUIContent("Reverse"));
            operationsToolbar.SetContent(2, new GUIContent(spline.is2D ? "3D Mode" : "2D Mode"));
            operationsToolbar.Draw(ref operation);
            //operation = GUILayout.Toolbar(operation, new string[] { , "Reverse", text2D }, GUILayout.Width(220f));
            if (EditorGUI.EndChangeCheck())
            {
                PerformOperation();
            }
            EditorGUI.BeginChangeCheck();
            if (splines.Length == 1)
            {
                int mod = module;
                utilityToolbar.Draw(ref mod);
                if (EditorGUI.EndChangeCheck())
                {
                    ToggleModule(mod);
                }
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            if (module >= 0 && module < modules.Length)
            {
                modules[module].DrawInspector();
            }
            EditorGUILayout.Space();
            DreamteckEditorGUI.DrawSeparator();

            EditorGUILayout.Space();

            serializedObject.Update();
            SerializedProperty splineProperty            = serializedObject.FindProperty("spline");
            SerializedProperty sampleRate                = serializedObject.FindProperty("spline").FindPropertyRelative("sampleRate");
            SerializedProperty type                      = serializedObject.FindProperty("spline").FindPropertyRelative("type");
            SerializedProperty linearAverageDirection    = splineProperty.FindPropertyRelative("linearAverageDirection");
            SerializedProperty space                     = serializedObject.FindProperty("_space");
            SerializedProperty sampleMode                = serializedObject.FindProperty("_sampleMode");
            SerializedProperty optimizeAngleThreshold    = serializedObject.FindProperty("_optimizeAngleThreshold");
            SerializedProperty updateMode                = serializedObject.FindProperty("updateMode");
            SerializedProperty rebuildOnAwake            = serializedObject.FindProperty("rebuildOnAwake");
            SerializedProperty multithreaded             = serializedObject.FindProperty("multithreaded");
            SerializedProperty customNormalInterpolation = splineProperty.FindPropertyRelative("customNormalInterpolation");
            SerializedProperty customValueInterpolation  = splineProperty.FindPropertyRelative("customValueInterpolation");

            EditorGUI.BeginChangeCheck();
            Spline.Type lastType = (Spline.Type)type.intValue;
            EditorGUILayout.PropertyField(type);
            if (lastType == Spline.Type.CatmullRom && type.intValue == (int)Spline.Type.Bezier)
            {
                if (EditorUtility.DisplayDialog("Hermite to Bezier", "Would you like to retain the Catmull Rom shape in Bezier mode?", "Yes", "No"))
                {
                    for (int i = 0; i < splines.Length; i++)
                    {
                        splines[i].CatToBezierTangents();
                    }

                    serializedObject.Update();
                    pathEditor.Refresh();
                }
            }
            if (spline.type == Spline.Type.Linear)
            {
                EditorGUILayout.PropertyField(linearAverageDirection);
            }
            int lastSpace = space.intValue;

            EditorGUILayout.PropertyField(space, new GUIContent("Space"));
            EditorGUILayout.PropertyField(sampleMode, new GUIContent("Sample Mode"));
            if (sampleMode.intValue == (int)SplineComputer.SampleMode.Optimized)
            {
                EditorGUILayout.PropertyField(optimizeAngleThreshold);
            }
            EditorGUILayout.PropertyField(updateMode);
            if (updateMode.intValue == (int)SplineComputer.UpdateMode.None && Application.isPlaying)
            {
                if (GUILayout.Button("Rebuild"))
                {
                    for (int i = 0; i < splines.Length; i++)
                    {
                        splines[i].RebuildImmediate(true, true);
                    }
                }
            }
            if (spline.type != Spline.Type.Linear)
            {
                EditorGUILayout.PropertyField(sampleRate, new GUIContent("Sample Rate"));
            }
            EditorGUILayout.PropertyField(rebuildOnAwake);
            EditorGUILayout.PropertyField(multithreaded);

            EditorGUI.indentLevel++;
            bool curveUpdate = false;

            interpolationFoldout = EditorGUILayout.Foldout(interpolationFoldout, "Point Value Interpolation");
            if (interpolationFoldout)
            {
                if (customValueInterpolation.animationCurveValue == null || customValueInterpolation.animationCurveValue.keys.Length == 0)
                {
                    if (GUILayout.Button("Size & Color Interpolation"))
                    {
                        AnimationCurve curve = new AnimationCurve();
                        curve.AddKey(new Keyframe(0, 0, 0, 0));
                        curve.AddKey(new Keyframe(1, 1, 0, 0));
                        for (int i = 0; i < splines.Length; i++)
                        {
                            splines[i].customValueInterpolation = curve;
                        }
                        serializedObject.Update();
                        curveUpdate = true;
                    }
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PropertyField(customValueInterpolation, new GUIContent("Size & Color Interpolation"));
                    if (GUILayout.Button("x", GUILayout.MaxWidth(25)))
                    {
                        customValueInterpolation.animationCurveValue = null;
                        for (int i = 0; i < splines.Length; i++)
                        {
                            splines[i].customValueInterpolation = null;
                        }
                        serializedObject.Update();
                        curveUpdate = true;
                    }
                    EditorGUILayout.EndHorizontal();
                }
                if (customNormalInterpolation.animationCurveValue == null || customNormalInterpolation.animationCurveValue.keys.Length == 0)
                {
                    if (GUILayout.Button("Normal Interpolation"))
                    {
                        AnimationCurve curve = new AnimationCurve();
                        curve.AddKey(new Keyframe(0, 0));
                        curve.AddKey(new Keyframe(1, 1));
                        for (int i = 0; i < splines.Length; i++)
                        {
                            splines[i].customNormalInterpolation = curve;
                        }
                        serializedObject.Update();
                        curveUpdate = true;
                    }
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PropertyField(customNormalInterpolation, new GUIContent("Normal Interpolation"));
                    if (GUILayout.Button("x", GUILayout.MaxWidth(25)))
                    {
                        customNormalInterpolation.animationCurveValue = null;
                        for (int i = 0; i < splines.Length; i++)
                        {
                            splines[i].customNormalInterpolation = null;
                        }
                        serializedObject.Update();
                        curveUpdate = true;
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }

            EditorGUI.indentLevel--;

            if (EditorGUI.EndChangeCheck() || curveUpdate)
            {
                if (sampleRate.intValue < 2)
                {
                    sampleRate.intValue = 2;
                }
                if (lastSpace != space.intValue)
                {
                    for (int i = 0; i < splines.Length; i++)
                    {
                        splines[i].space = (SplineComputer.Space)space.intValue;
                    }
                    serializedObject.Update();
                    if (splines.Length == 1)
                    {
                        pathEditor.Refresh();
                    }
                }
                serializedObject.ApplyModifiedProperties();
                for (int i = 0; i < splines.Length; i++)
                {
                    splines[i].Rebuild(true);
                }
            }


            if (pathEditor.currentModule != null)
            {
                transformTool = 0;
            }
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Edit Transform");
            GUILayout.FlexibleSpace();
            int lastTool = transformTool;

            transformToolbar.Draw(ref transformTool);
            if (lastTool != transformTool && transformTool > 0)
            {
                pathEditor.UntoggleCurrentModule();
            }
            EditorGUILayout.EndHorizontal();
        }
Beispiel #9
0
 internal SplineDefinition(string n, Spline.Type t)
 {
     name = n;
     type = t;
 }