Browse Source

Change dragpoint material shader and add colours

Used the shader from the box for COM3D2's world transform axis.

Added colours that match MM's colour scheme defined in code despite it
looking black in game (Shine a light on the cubes to see their colour).

Closes #13
habeebweeb 4 năm trước cách đây
mục cha
commit
fc88a1c446

+ 24 - 19
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/DragPoint/DragPoint.cs

@@ -6,6 +6,8 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
     using static CustomGizmo;
     internal abstract class DragPoint : MonoBehaviour
     {
+        public const float defaultAlpha = 0.75f;
+        private static GameObject dragPointParent = new GameObject("[MPS DragPoint Parent]");
         private const float doubleClickSensitivity = 0.3f;
         private Func<Vector3> position;
         private Func<Vector3> rotation;
@@ -13,9 +15,12 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private Renderer renderer;
         private bool reinitializeDrag;
         protected bool Transforming => CurrentDragType >= DragType.MoveXZ;
+        protected bool Special => CurrentDragType == DragType.Select || CurrentDragType == DragType.Delete;
         protected bool Moving => CurrentDragType == DragType.MoveXZ || CurrentDragType == DragType.MoveY;
         protected bool Rotating => CurrentDragType >= DragType.RotLocalXZ && CurrentDragType <= DragType.RotLocalY;
-        protected bool Special => CurrentDragType == DragType.Select || CurrentDragType == DragType.Delete;
+        protected bool Scaling => CurrentDragType == DragType.Scale;
+        protected bool Selecting => CurrentDragType == DragType.Select;
+        protected bool Deleting => CurrentDragType == DragType.Delete;
         private Vector3 startMousePosition;
         protected static Camera camera = GameMain.Instance.MainCamera.camera;
         public enum DragType
@@ -31,14 +36,8 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private Vector3 screenPoint;
         private Vector3 startOffset;
         private Vector3 newOffset;
-        public static Material LightBlue = new Material(Shader.Find("Transparent/Diffuse"))
-        {
-            color = new Color(0.4f, 0.4f, 1f, 0.3f)
-        };
-        public static Material Blue = new Material(Shader.Find("Transparent/Diffuse"))
-        {
-            color = new Color(0.5f, 0.5f, 1f, 0.8f)
-        };
+        public static Material dragPointMaterial = new Material(Shader.Find("CM3D2/Trans_AbsoluteFront"));
+        public static readonly Color defaultColour = new Color(0f, 0f, 0f, defaultAlpha);
         public Vector3 BaseScale { get; private set; }
         private float dragPointScale = 1f;
         public float DragPointScale
@@ -99,19 +98,18 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             ApplyDragType();
         }
 
-        private static GameObject DragPointParent() => GameObject.Find("[MPS DragPoint Parent]")
-            ?? new GameObject("[MPS DragPoint Parent]");
-
-        public static T Make<T>(PrimitiveType primitiveType, Vector3 scale, Material material) where T : DragPoint
+        public static T Make<T>(PrimitiveType primitiveType, Vector3 scale) where T : DragPoint
         {
-            GameObject dragPoint = GameObject.CreatePrimitive(primitiveType);
-            dragPoint.transform.localScale = scale;
-            dragPoint.GetComponent<Renderer>().material = material;
-            dragPoint.layer = 8;
+            GameObject dragPointGo = GameObject.CreatePrimitive(primitiveType);
+            dragPointGo.transform.SetParent(dragPointParent.transform, false);
+            dragPointGo.transform.localScale = scale;
+            dragPointGo.layer = 8;
 
-            dragPoint.transform.SetParent(DragPointParent().transform, true);
+            T dragPoint = dragPointGo.AddComponent<T>();
+            dragPoint.renderer.material = dragPointMaterial;
+            dragPoint.renderer.material.color = defaultColour;
 
-            return dragPoint.AddComponent<T>();
+            return dragPoint;
         }
 
         public virtual void Initialize(Func<Vector3> position, Func<Vector3> rotation)
@@ -143,6 +141,13 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             if (this.Gizmo != null) this.Gizmo.GizmoVisible = gizmo;
         }
 
+        protected void ApplyColour(Color colour) => this.renderer.material.color = colour;
+
+        protected void ApplyColour(float r, float g, float b, float a = defaultAlpha)
+        {
+            ApplyColour(new Color(r, g, b, a));
+        }
+
         protected Vector3 MouseDelta() => Input.mousePosition - startMousePosition;
 
         protected bool OtherDragType()

+ 15 - 0
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/DragPoint/DragPointGeneral.cs

@@ -13,6 +13,11 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private Quaternion currentRotation;
         public float ScaleFactor { get; set; } = 1f;
         public bool ConstantScale { get; set; }
+        public static readonly Color moveColour = new Color(0.2f, 0.5f, 0.95f, defaultAlpha);
+        public static readonly Color rotateColour = new Color(0.2f, 0.75f, 0.3f, defaultAlpha);
+        public static readonly Color scaleColour = new Color(0.8f, 0.7f, 0.3f, defaultAlpha);
+        public static readonly Color selectColour = new Color(0.9f, 0.5f, 1f, defaultAlpha);
+        public static readonly Color deleteColour = new Color(1f, 0.1f, 0.1f, defaultAlpha);
         public event EventHandler Move;
         public event EventHandler Rotate;
         public event EventHandler Scale;
@@ -29,6 +34,16 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             };
         }
 
+        protected virtual void ApplyColours()
+        {
+            Color colour = moveColour;
+            if (Rotating) colour = rotateColour;
+            else if (Scaling) colour = scaleColour;
+            else if (Selecting) colour = selectColour;
+            else if (Deleting) colour = deleteColour;
+            ApplyColour(colour);
+        }
+
         protected override void Update()
         {
             base.Update();

+ 7 - 23
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/DragPoint/DragPointLight.cs

@@ -194,29 +194,13 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         protected override void ApplyDragType()
         {
-            DragType current = CurrentDragType;
-            if (current == DragType.Select || current == DragType.MoveXZ || current == DragType.MoveY)
-            {
-                ApplyProperties(true, true, false);
-            }
-            else if (current == DragType.RotY || current == DragType.RotLocalXZ || current == DragType.RotLocalY)
-            {
-                bool canRotate = SelectedLightType != MPSLightType.Point;
-                ApplyProperties(canRotate, canRotate, false);
-            }
-            else if (current == DragType.Scale)
-            {
-                bool canScale = SelectedLightType != MPSLightType.Normal;
-                ApplyProperties(canScale, canScale, false);
-            }
-            else if (current == DragType.Delete)
-            {
-                ApplyProperties(!IsMain, !IsMain, false);
-            }
-            else
-            {
-                ApplyProperties(false, false, false);
-            }
+            if (Selecting || Moving) ApplyProperties(true, true, false);
+            else if (SelectedLightType != MPSLightType.Point && Rotating) ApplyProperties(true, true, false);
+            else if (SelectedLightType != MPSLightType.Normal && Scaling) ApplyProperties(true, true, false);
+            else if (!IsMain && Deleting) ApplyProperties(true, true, false);
+            else ApplyProperties(false, false, false);
+
+            ApplyColours();
         }
 
         public void SetLightType(MPSLightType type)

+ 12 - 5
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/DragPoint/DragPointOther.cs

@@ -1,3 +1,4 @@
+using System;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Rendering;
@@ -22,10 +23,11 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         }
         protected override void ApplyDragType()
         {
-            DragType current = CurrentDragType;
-            bool enabled = !IsIK && (Transforming || (current == DragType.Select));
-            bool select = IsIK && current == DragType.Select;
+            bool enabled = !IsIK && (Transforming || Selecting);
+            bool select = IsIK && Selecting;
             ApplyProperties(enabled || select, IsCube && enabled, false);
+
+            if (IsCube) ApplyColours();
         }
     }
 
@@ -34,6 +36,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         protected override void ApplyDragType()
         {
             ApplyProperties(Transforming, Transforming, Rotating);
+            ApplyColours();
         }
     }
 
@@ -68,9 +71,9 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         protected override void ApplyDragType()
         {
-            DragType current = CurrentDragType;
             bool active = (DragPointEnabled && Transforming) || Special;
             ApplyProperties(active, active, GizmoEnabled && Rotating);
+            ApplyColours();
         }
 
         protected override void OnDestroy()
@@ -82,6 +85,10 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
     internal class DragPointGravity : DragPointGeneral
     {
-        protected override void ApplyDragType() => ApplyProperties(Moving, Moving, false);
+        protected override void ApplyDragType()
+        {
+            ApplyProperties(Moving, Moving, false);
+            ApplyColours();
+        }
     }
 }

+ 1 - 3
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/EnvironmentManager.cs

@@ -122,9 +122,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             bgObject = GameObject.Find("__GameMain__/BG");
             bg = bgObject.transform;
 
-            bgDragPoint = DragPoint.Make<DragPointBG>(
-                PrimitiveType.Cube, Vector3.one * 0.12f, DragPoint.LightBlue
-            );
+            bgDragPoint = DragPoint.Make<DragPointBG>(PrimitiveType.Cube, Vector3.one * 0.12f);
             bgDragPoint.Initialize(() => bg.position, () => Vector3.zero);
             bgDragPoint.Set(bg);
             bgDragPoint.AddGizmo();

+ 1 - 3
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/LightManager.cs

@@ -98,9 +98,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         public void AddLight(GameObject lightGo = null, bool isMain = false)
         {
             GameObject go = lightGo ?? new GameObject("MPS Light");
-            DragPointLight light = DragPoint.Make<DragPointLight>(
-                PrimitiveType.Cube, Vector3.one * 0.12f, DragPoint.LightBlue
-            );
+            DragPointLight light = DragPoint.Make<DragPointLight>(PrimitiveType.Cube, Vector3.one * 0.12f);
             light.Initialize(() => go.transform.position, () => go.transform.eulerAngles);
             light.Set(go.transform);
             light.IsMain = isMain;

+ 1 - 3
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/PropManager.cs

@@ -407,9 +407,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             dogu.name = name;
             dogu.transform.position = position;
 
-            DragPointDogu dragDogu = DragPoint.Make<DragPointDogu>(
-                PrimitiveType.Cube, Vector3.one * 0.12f, DragPoint.LightBlue
-            );
+            DragPointDogu dragDogu = DragPoint.Make<DragPointDogu>(PrimitiveType.Cube, Vector3.one * 0.12f);
             dragDogu.Initialize(() => dogu.transform.position, () => Vector3.zero);
             dragDogu.Set(dogu.transform);
             dragDogu.AddGizmo(scale: 0.45f, mode: CustomGizmo.GizmoMode.World);

+ 5 - 12
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Meido/IK/DragPointFinger.cs

@@ -8,6 +8,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private Transform[] ikChain;
         private Quaternion[] jointRotation = new Quaternion[2];
         private bool baseFinger;
+        private static readonly Color dragpointColour = new Color(0.1f, 0.4f, 0.95f, defaultAlpha);
 
         public override void Set(Transform finger)
         {
@@ -30,18 +31,10 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         protected override void ApplyDragType()
         {
-            if (baseFinger && CurrentDragType == DragType.RotLocalY)
-            {
-                ApplyProperties(true, true, false);
-            }
-            else if (CurrentDragType == DragType.MoveXZ)
-            {
-                ApplyProperties(true, true, false);
-            }
-            else
-            {
-                ApplyProperties(false, false, false);
-            }
+            if (baseFinger && CurrentDragType == DragType.RotLocalY) ApplyProperties(true, true, false);
+            else if (CurrentDragType == DragType.MoveXZ) ApplyProperties(true, true, false);
+            else ApplyProperties(false, false, false);
+            ApplyColour(dragpointColour);
         }
 
         protected override void UpdateDragType()

+ 1 - 1
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Meido/Meido.cs

@@ -495,7 +495,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private DragPointGravity MakeGravityDragPoint(GravityTransformControl control)
         {
             DragPointGravity gravityDragpoint = DragPoint.Make<DragPointGravity>(
-                PrimitiveType.Cube, Vector3.one * 0.12f, DragPoint.LightBlue
+                PrimitiveType.Cube, Vector3.one * 0.12f
             );
             gravityDragpoint.Initialize(() => control.transform.position, () => Vector3.zero);
             gravityDragpoint.Set(control.transform);

+ 10 - 24
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Meido/MeidoDragPointManager.cs

@@ -345,9 +345,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         private void InitializeDragPoints()
         {
-            dragCube = DragPoint.Make<DragPointBody>(
-                PrimitiveType.Cube, Vector3.one * 0.12f, DragPoint.Blue
-            );
+            dragCube = DragPoint.Make<DragPointBody>(PrimitiveType.Cube, Vector3.one * 0.12f);
             dragCube.Initialize(() => meido.Maid.transform.position, () => Vector3.zero);
             dragCube.Set(meido.Maid.transform);
 
@@ -357,9 +355,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             dragCube.EndScale += OnSetDragPointScale;
             dragCube.gameObject.SetActive(CubeActive);
 
-            dragBody = DragPoint.Make<DragPointBody>(
-                PrimitiveType.Capsule, new Vector3(0.2f, 0.3f, 0.24f), DragPoint.LightBlue
-            );
+            dragBody = DragPoint.Make<DragPointBody>(PrimitiveType.Capsule, new Vector3(0.2f, 0.3f, 0.24f));
             dragBody.Initialize(
                 () => new Vector3(
                     (BoneTransform[Bone.Hip].position.x + BoneTransform[Bone.Spine0a].position.x) / 2f,
@@ -378,7 +374,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
             // Neck Dragpoint
             DragPointHead dragNeck = DragPoint.Make<DragPointHead>(
-                PrimitiveType.Sphere, new Vector3(0.2f, 0.24f, 0.2f), DragPoint.LightBlue
+                PrimitiveType.Sphere, new Vector3(0.2f, 0.24f, 0.2f)
             );
             dragNeck.Initialize(meido,
                 () => new Vector3(
@@ -398,9 +394,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             DragPoints[Bone.Head] = dragNeck;
 
             // Head Dragpoint
-            DragPointSpine dragHead = DragPoint.Make<DragPointSpine>(
-                PrimitiveType.Sphere, Vector3.one * 0.045f, DragPoint.LightBlue
-            );
+            DragPointSpine dragHead = DragPoint.Make<DragPointSpine>(PrimitiveType.Sphere, Vector3.one * 0.045f);
             dragHead.Initialize(meido, () => BoneTransform[Bone.Head].position, () => Vector3.zero);
             dragHead.Set(BoneTransform[Bone.Head]);
             dragHead.AddGizmo();
@@ -412,7 +406,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             Transform spineTrans2 = BoneTransform[Bone.Spine1a];
 
             DragPointTorso dragTorso = DragPoint.Make<DragPointTorso>(
-                PrimitiveType.Capsule, new Vector3(0.2f, 0.19f, 0.24f), DragPoint.LightBlue
+                PrimitiveType.Capsule, new Vector3(0.2f, 0.19f, 0.24f)
             );
             dragTorso.Initialize(meido,
                 () => new Vector3(
@@ -435,7 +429,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             Transform spineTrans = BoneTransform[Bone.Spine];
 
             DragPointPelvis dragPelvis = DragPoint.Make<DragPointPelvis>(
-                PrimitiveType.Capsule, new Vector3(0.2f, 0.15f, 0.24f), DragPoint.LightBlue
+                PrimitiveType.Capsule, new Vector3(0.2f, 0.15f, 0.24f)
             );
             dragPelvis.Initialize(meido,
 
@@ -487,9 +481,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         {
             Bone mune = left ? Bone.MuneL : Bone.MuneR;
             Bone sub = left ? Bone.MuneSubL : Bone.MuneSubR;
-            DragPointChain muneDragPoint = DragPoint.Make<DragPointChain>(
-                PrimitiveType.Sphere, Vector3.one * 0.12f, DragPoint.LightBlue
-            );
+            DragPointChain muneDragPoint = DragPoint.Make<DragPointChain>(PrimitiveType.Sphere, Vector3.one * 0.12f);
             muneDragPoint.Initialize(meido,
                 () => (BoneTransform[mune].position + BoneTransform[sub].position) / 2f,
                 () => Vector3.zero
@@ -507,9 +499,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             for (int i = dragPoints.Length - 1; i >= 0; i--)
             {
                 Transform joint = lower;
-                dragPoints[i] = DragPoint.Make<DragPointChain>(
-                    PrimitiveType.Sphere, limbDragPointSize, DragPoint.LightBlue
-                );
+                dragPoints[i] = DragPoint.Make<DragPointChain>(PrimitiveType.Sphere, limbDragPointSize);
                 dragPoints[i].Initialize(meido, () => joint.position, () => Vector3.zero);
                 dragPoints[i].Set(joint);
                 dragPoints[i].AddGizmo();
@@ -527,9 +517,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 for (int i = 1; i < joints; i++)
                 {
                     Transform trans = BoneTransform[bone + i];
-                    DragPointFinger chain = DragPoint.Make<DragPointFinger>(
-                        PrimitiveType.Sphere, fingerDragPointSize, DragPoint.Blue
-                    );
+                    DragPointFinger chain = DragPoint.Make<DragPointFinger>(PrimitiveType.Sphere, fingerDragPointSize);
                     chain.Initialize(meido, () => trans.position, () => Vector3.zero);
                     chain.Set(trans);
                     DragPoints[bone + i] = chain;
@@ -544,9 +532,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             {
                 Transform spine = BoneTransform[bone];
                 PrimitiveType primitive = bone == Bone.Hip ? PrimitiveType.Cube : PrimitiveType.Sphere;
-                DragPointSpine dragPoint = DragPoint.Make<DragPointSpine>(
-                    primitive, spineDragPointSize, DragPoint.LightBlue
-                );
+                DragPointSpine dragPoint = DragPoint.Make<DragPointSpine>(primitive, spineDragPointSize);
                 dragPoint.Initialize(meido,
                     () => spine.position,
                     () => Vector3.zero