Browse Source

Added different axis models for the rotation & scaling modes.

Lasse Öörni 14 years ago
parent
commit
00dbad68cb

BIN
Bin/CoreData/Models/Axes.mdl


BIN
Bin/CoreData/Models/RotateAxes.mdl


BIN
Bin/CoreData/Models/ScaleAxes.mdl


+ 48 - 7
Bin/Data/Scripts/Editor/EditorGizmo.as

@@ -7,10 +7,13 @@ const float axisMaxD = 0.1;
 const float axisMaxT = 1.0;
 const float axisMaxT = 1.0;
 const float rotSensitivity = 50.0;
 const float rotSensitivity = 50.0;
 
 
+EditMode lastGizmoMode;
+
 class GizmoAxis
 class GizmoAxis
 {
 {
     Ray axisRay;
     Ray axisRay;
     bool selected;
     bool selected;
+    bool lastSelected;
     float t;
     float t;
     float d;
     float d;
     float lastT;
     float lastT;
@@ -19,6 +22,7 @@ class GizmoAxis
     GizmoAxis()
     GizmoAxis()
     {
     {
         selected = false;
         selected = false;
+        lastSelected = false;
         t = 0.0;
         t = 0.0;
         d = 0.0;
         d = 0.0;
         lastT = 0.0;
         lastT = 0.0;
@@ -66,6 +70,11 @@ void CreateGizmo()
     gizmo.materials[1] = cache.GetResource("Material", "Materials/GreenUnlit.xml");
     gizmo.materials[1] = cache.GetResource("Material", "Materials/GreenUnlit.xml");
     gizmo.materials[2] = cache.GetResource("Material", "Materials/BlueUnlit.xml");
     gizmo.materials[2] = cache.GetResource("Material", "Materials/BlueUnlit.xml");
     gizmo.visible = false;
     gizmo.visible = false;
+    
+    gizmoAxisX.lastSelected = false;
+    gizmoAxisY.lastSelected = false;
+    gizmoAxisZ.lastSelected = false;
+    lastGizmoMode = EDIT_MOVE;
 
 
     // Add to the octree without culling. This also makes the gizmo invisible to raycasts
     // Add to the octree without culling. This also makes the gizmo invisible to raycasts
     if (editorScene.octree !is null)
     if (editorScene.octree !is null)
@@ -109,6 +118,26 @@ void PositionGizmo()
     else
     else
         gizmoNode.rotation = editNodes[0].worldRotation;
         gizmoNode.rotation = editNodes[0].worldRotation;
 
 
+    if (editMode != lastGizmoMode)
+    {
+        switch (editMode)
+        {
+        case EDIT_MOVE:
+            gizmo.model = cache.GetResource("Model", "Models/Axes.mdl");
+            break;
+        
+        case EDIT_ROTATE:
+            gizmo.model = cache.GetResource("Model", "Models/RotateAxes.mdl");
+            break;
+            
+        case EDIT_SCALE:
+            gizmo.model = cache.GetResource("Model", "Models/ScaleAxes.mdl");
+            break;
+        }
+          
+        lastGizmoMode = editMode;
+    }
+    
     gizmo.visible = true;
     gizmo.visible = true;
 }
 }
 
 
@@ -163,15 +192,27 @@ void UseGizmo()
     gizmoAxisY.Update(cameraRay, scale, drag);
     gizmoAxisY.Update(cameraRay, scale, drag);
     gizmoAxisZ.Update(cameraRay, scale, drag);
     gizmoAxisZ.Update(cameraRay, scale, drag);
 
 
-    gizmo.materials[0] = cache.GetResource("Material", gizmoAxisX.selected ? "Materials/BrightRedUnlit.xml" : "Materials/RedUnlit.xml");
-    gizmo.materials[1] = cache.GetResource("Material", gizmoAxisY.selected ? "Materials/BrightGreenUnlit.xml" : "Materials/GreenUnlit.xml");
-    gizmo.materials[2] = cache.GetResource("Material", gizmoAxisZ.selected ? "Materials/BrightBlueUnlit.xml" : "Materials/BlueUnlit.xml");
+    if (gizmoAxisX.selected != gizmoAxisX.lastSelected)
+    {
+        gizmo.materials[0] = cache.GetResource("Material", gizmoAxisX.selected ? "Materials/BrightRedUnlit.xml" : "Materials/RedUnlit.xml");
+        gizmoAxisX.lastSelected = gizmoAxisX.selected;
+    }
+    if (gizmoAxisY.selected != gizmoAxisY.lastSelected)
+    {
+        gizmo.materials[1] = cache.GetResource("Material", gizmoAxisY.selected ? "Materials/BrightGreenUnlit.xml" : "Materials/GreenUnlit.xml");
+        gizmoAxisY.lastSelected = gizmoAxisY.selected;
+    }
+    if (gizmoAxisZ.selected != gizmoAxisZ.lastSelected)
+    {
+        gizmo.materials[2] = cache.GetResource("Material", gizmoAxisZ.selected ? "Materials/BrightBlueUnlit.xml" : "Materials/BlueUnlit.xml");
+        gizmoAxisZ.lastSelected = gizmoAxisZ.selected;
+    };
 
 
     if (drag)
     if (drag)
     {
     {
         bool moved = false;
         bool moved = false;
 
 
-        if (moveMode == OBJ_MOVE)
+        if (editMode == EDIT_MOVE)
         {
         {
             Vector3 adjust(0, 0, 0);
             Vector3 adjust(0, 0, 0);
             if (gizmoAxisX.selected)
             if (gizmoAxisX.selected)
@@ -183,7 +224,7 @@ void UseGizmo()
 
 
             moved = MoveNodes(adjust);
             moved = MoveNodes(adjust);
         }
         }
-        else if (moveMode == OBJ_ROTATE)
+        else if (editMode == EDIT_ROTATE)
         {
         {
             Vector3 adjust(0, 0, 0);
             Vector3 adjust(0, 0, 0);
             if (gizmoAxisX.selected)
             if (gizmoAxisX.selected)
@@ -195,7 +236,7 @@ void UseGizmo()
 
 
             moved = RotateNodes(adjust);
             moved = RotateNodes(adjust);
         }
         }
-        else if (moveMode == OBJ_SCALE)
+        else if (editMode == EDIT_SCALE)
         {
         {
             Vector3 adjust(0, 0, 0);
             Vector3 adjust(0, 0, 0);
             if (gizmoAxisX.selected)
             if (gizmoAxisX.selected)
@@ -206,7 +247,7 @@ void UseGizmo()
                 adjust += Vector3(0, 0, 1) * (gizmoAxisZ.t - gizmoAxisZ.lastT);
                 adjust += Vector3(0, 0, 1) * (gizmoAxisZ.t - gizmoAxisZ.lastT);
 
 
             // Special handling for uniform scale: use the unmodified X-axis movement only
             // Special handling for uniform scale: use the unmodified X-axis movement only
-            if (moveMode == OBJ_SCALE && gizmoAxisX.selected && gizmoAxisY.selected && gizmoAxisZ.selected)
+            if (editMode == EDIT_SCALE && gizmoAxisX.selected && gizmoAxisY.selected && gizmoAxisZ.selected)
             {
             {
                 float x = gizmoAxisX.t - gizmoAxisX.lastT;
                 float x = gizmoAxisX.t - gizmoAxisX.lastT;
                 adjust = Vector3(x, x, x);
                 adjust = Vector3(x, x, x);

+ 3 - 3
Bin/Data/Scripts/Editor/EditorUI.as

@@ -414,11 +414,11 @@ void HandleKeyDown(StringHash eventType, VariantMap& eventData)
     if (eventData["Qualifiers"].GetInt() == QUAL_CTRL)
     if (eventData["Qualifiers"].GetInt() == QUAL_CTRL)
     {
     {
         if (key == '1')
         if (key == '1')
-            moveMode = OBJ_MOVE;
+            editMode = EDIT_MOVE;
         else if (key == '2')
         else if (key == '2')
-            moveMode = OBJ_ROTATE;
+            editMode = EDIT_ROTATE;
         else if (key == '3')
         else if (key == '3')
-            moveMode = OBJ_SCALE;
+            editMode = EDIT_SCALE;
         else if (key == '4')
         else if (key == '4')
             axisMode = AxisMode(axisMode ^ AXIS_LOCAL);
             axisMode = AxisMode(axisMode ^ AXIS_LOCAL);
         else if (key == '5')
         else if (key == '5')

+ 20 - 20
Bin/Data/Scripts/Editor/EditorView.as

@@ -4,11 +4,11 @@ Node@ cameraNode;
 Camera@ camera;
 Camera@ camera;
 Window@ settingsDialog;
 Window@ settingsDialog;
 
 
-enum ObjectMoveMode
+enum EditMode
 {
 {
-    OBJ_MOVE = 0,
-    OBJ_ROTATE,
-    OBJ_SCALE
+    EDIT_MOVE = 0,
+    EDIT_ROTATE,
+    EDIT_SCALE
 }
 }
 
 
 enum AxisMode
 enum AxisMode
@@ -21,7 +21,7 @@ Text@ editorModeText;
 Text@ renderStatsText;
 Text@ renderStatsText;
 Text@ cameraPosText;
 Text@ cameraPosText;
 
 
-ObjectMoveMode moveMode = OBJ_MOVE;
+EditMode editMode = EDIT_MOVE;
 AxisMode axisMode = AXIS_WORLD;
 AxisMode axisMode = AXIS_WORLD;
 
 
 float cameraBaseSpeed = 10;
 float cameraBaseSpeed = 10;
@@ -47,7 +47,7 @@ Array<int> pickModeDrawableFlags = {
     DRAWABLE_ZONE
     DRAWABLE_ZONE
 };
 };
 
 
-Array<String> moveModeText = {
+Array<String> editModeText = {
     "Move",
     "Move",
     "Rotate",
     "Rotate",
     "Scale"
     "Scale"
@@ -122,7 +122,7 @@ void SetupStatsBarText(Text@ text, Font@ font, int x, int y, HorizontalAlignment
 void UpdateStats(float timeStep)
 void UpdateStats(float timeStep)
 {
 {
     editorModeText.text = String(
     editorModeText.text = String(
-        "Mode: " + moveModeText[moveMode] +
+        "Mode: " + editModeText[editMode] +
         "  Axis: " + axisModeText[axisMode] +
         "  Axis: " + axisModeText[axisMode] +
         "  Pick: " + pickModeText[pickMode] +
         "  Pick: " + pickModeText[pickMode] +
         "  Updates: " + (runUpdate ? "Running" : "Paused"));
         "  Updates: " + (runUpdate ? "Running" : "Paused"));
@@ -202,7 +202,7 @@ void MoveCamera(float timeStep)
             adjust.y = 1;
             adjust.y = 1;
         if (input.keyDown[KEY_PAGEDOWN])
         if (input.keyDown[KEY_PAGEDOWN])
             adjust.y = -1;
             adjust.y = -1;
-        if (moveMode == OBJ_SCALE)
+        if (editMode == EDIT_SCALE)
         {
         {
             if (input.keyDown[KEY_ADD])
             if (input.keyDown[KEY_ADD])
                 adjust = Vector3(1, 1, 1);
                 adjust = Vector3(1, 1, 1);
@@ -216,14 +216,14 @@ void MoveCamera(float timeStep)
         bool moved = false;
         bool moved = false;
         adjust *= timeStep * 10;
         adjust *= timeStep * 10;
 
 
-        switch (moveMode)
+        switch (editMode)
         {
         {
-        case OBJ_MOVE:
+        case EDIT_MOVE:
             if (!moveSnap)
             if (!moveSnap)
                 moved = MoveNodes(adjust * moveStep);
                 moved = MoveNodes(adjust * moveStep);
             break;
             break;
             
             
-        case OBJ_ROTATE:
+        case EDIT_ROTATE:
             if (!rotateSnap)
             if (!rotateSnap)
             {
             {
                 Vector3 rotAdjust;
                 Vector3 rotAdjust;
@@ -234,7 +234,7 @@ void MoveCamera(float timeStep)
             }
             }
             break;
             break;
 
 
-        case OBJ_SCALE:
+        case EDIT_SCALE:
             if (!scaleSnap)
             if (!scaleSnap)
                 moved = ScaleNodes(adjust * scaleStep);
                 moved = ScaleNodes(adjust * scaleStep);
             break;
             break;
@@ -251,11 +251,11 @@ void SteppedObjectManipulation(int key)
         return;
         return;
 
 
     // Do not react in non-snapped mode, because that is handled in frame update
     // Do not react in non-snapped mode, because that is handled in frame update
-    if (moveMode == OBJ_MOVE && !moveSnap)
+    if (editMode == EDIT_MOVE && !moveSnap)
         return;
         return;
-    if (moveMode == OBJ_ROTATE && !rotateSnap)
+    if (editMode == EDIT_ROTATE && !rotateSnap)
         return;
         return;
-    if (moveMode == OBJ_SCALE && !scaleSnap)
+    if (editMode == EDIT_SCALE && !scaleSnap)
         return;
         return;
 
 
     Vector3 adjust(0, 0, 0);
     Vector3 adjust(0, 0, 0);
@@ -271,7 +271,7 @@ void SteppedObjectManipulation(int key)
         adjust.y = 1;
         adjust.y = 1;
     if (key == KEY_PAGEDOWN)
     if (key == KEY_PAGEDOWN)
         adjust.y = -1;
         adjust.y = -1;
-    if (moveMode == OBJ_SCALE)
+    if (editMode == EDIT_SCALE)
     {
     {
         if (key == KEY_ADD)
         if (key == KEY_ADD)
             adjust = Vector3(1, 1, 1);
             adjust = Vector3(1, 1, 1);
@@ -284,13 +284,13 @@ void SteppedObjectManipulation(int key)
 
 
     bool moved = false;
     bool moved = false;
 
 
-    switch (moveMode)
+    switch (editMode)
     {
     {
-    case OBJ_MOVE:
+    case EDIT_MOVE:
         moved = MoveNodes(adjust);
         moved = MoveNodes(adjust);
         break;
         break;
 
 
-    case OBJ_ROTATE:
+    case EDIT_ROTATE:
         {
         {
             Vector3 rotAdjust;
             Vector3 rotAdjust;
             rotAdjust.x = adjust.z * rotateStep;
             rotAdjust.x = adjust.z * rotateStep;
@@ -300,7 +300,7 @@ void SteppedObjectManipulation(int key)
         }
         }
         break;
         break;
 
 
-    case OBJ_SCALE:
+    case EDIT_SCALE:
         moved = ScaleNodes(adjust * scaleStep);
         moved = ScaleNodes(adjust * scaleStep);
         break;
         break;
     }
     }

BIN
SourceAssets/Models/Axes.blend


BIN
SourceAssets/Models/RotateAxes.blend


BIN
SourceAssets/Models/ScaleAxes.blend