1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using System;
- using UnityEngine;
- namespace COM3D2.MeidoPhotoStudio.Plugin
- {
- public class DragJointForearm : BaseDrag
- {
- private readonly TBody.IKCMO IK = new TBody.IKCMO();
- private readonly GameObject[] otherIK = new GameObject[3];
- private Transform[] ikChain;
- private Vector3[] jointRotation = new Vector3[2];
- private Vector3 off;
- private Vector3 off2;
- private bool knee = false;
- public void Initialize(Transform[] ikChain, bool knee, Maid maid, Func<Vector3> position, Func<Vector3> rotation)
- {
- base.Initialize(maid, position, rotation);
- this.ikChain = ikChain;
- this.knee = knee;
- for (int i = 0; i < otherIK.Length; i++)
- {
- otherIK[i] = new GameObject();
- otherIK[i].transform.position = this.ikChain[i].position;
- otherIK[i].transform.localRotation = this.ikChain[i].localRotation;
- }
- InitializeIK();
- InitializeGizmo(this.ikChain[hand]);
- }
- public void InitializeIK()
- {
- IK.Init(ikChain[upperArm], ikChain[foreArm], ikChain[hand], maid.body0);
- }
- protected override void GetDragType()
- {
- if (knee && Utility.GetModKey(Utility.ModKey.Shift) && Utility.GetModKey(Utility.ModKey.Alt))
- {
- dragType = DragType.RotLocalY;
- }
- else
- {
- dragType = DragType.None;
- }
- }
- protected override void InitializeDrag()
- {
- base.InitializeDrag();
- off = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z));
- off2 = new Vector3(
- transform.position.x - ikChain[hand].position.x,
- transform.position.y - ikChain[hand].position.y,
- transform.position.z - ikChain[hand].position.z);
- jointRotation[upperArmRot] = ikChain[upperArm].localEulerAngles;
- jointRotation[handRot] = ikChain[hand].localEulerAngles;
- InitializeIK();
- }
- protected override void Drag()
- {
- if (isPlaying)
- {
- maid.GetAnimation().Stop();
- }
- IKCtrlData ikData = maid.body0.IKCtrl.GetIKData("左手");
- Vector3 pos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z)) + off - off2;
- if (dragType == DragType.None)
- {
- IK.Porc(ikChain[upperArm], ikChain[foreArm], ikChain[hand], pos, Vector3.zero, ikData);
- jointRotation[handRot] = ikChain[hand].localEulerAngles;
- jointRotation[upperArmRot] = ikChain[upperArm].localEulerAngles;
- ikChain[upperArm].localEulerAngles = jointRotation[upperArm];
- ikChain[hand].localEulerAngles = jointRotation[handRot];
- }
- else
- {
- Vector3 vec31 = Input.mousePosition - mousePos;
- if (dragType == DragType.RotLocalY)
- {
- ikChain[upperArm].localEulerAngles = jointRotation[upperArmRot];
- ikChain[upperArm].localRotation = Quaternion.Euler(ikChain[upperArm].localEulerAngles)
- * Quaternion.AngleAxis((-vec31.x / 1.5f), Vector3.right);
- }
- }
- }
- }
- }
|