private void AttachLimbMarker() { var chara = FkCharaMgr.FindSelectChara(); if (chara == null) { return; } chara.Limbs().Foreach(b => { var marker = BoneMarker.Create(b.Transform); _limbMarkers.Add(marker); marker.OnDrag = (m) => { var screenVec = m.MouseEndPos - m.MouseStartPos; var pos = Kit.MapScreenVecToWorld(screenVec, b.Transform.position); FkJointAssist.MoveEnd(b.GuideObject, pos); }; marker.OnMidClick = (m) => { // ClearLimbMarker(); DisableLimbMarker(); _follower = b; AttachSelectorMarker(); }; marker.OnRightClick = (m) => { ToggleLockBone(b, m); }; marker.OnLeftDown = (m) => { UndoRedoHelper.Record(); }; marker.OnLeftUp = (m) => { UndoRedoHelper.Finish(); }; }); }
public static void Record() { _lastRots.Clear(); _lastTargets.Clear(); var set = new HashSet <GuideObject>(); foreach (var selectObject in FkCharaMgr.FindSelectChara().DicGuideBones.Keys) { Record(selectObject); set.Add(selectObject); } Context.GuideObjectManager().selectObjects.Filter(go => !set.Contains(go)) .Foreach(go => Record(go)); }
public static void RecordAll(string mode) { _mode = mode; _oldPoss.Clear(); _oldRots.Clear(); _targets.Clear(); var boneSet = new HashSet <GuideObject>(); foreach (var selectObject in FkCharaMgr.FindSelectChara().DicGuideBones.Keys) { Record(selectObject); boneSet.Add(selectObject); } Context.GuideObjectManager().selectObjects.Filter(go => !boneSet.Contains(go)) .Foreach(go => Record(go)); }
private void AttachHangMarker() { DisableLimbMarker(); FkCharaMgr.FindSelectChara().Bones().Foreach(b => { var marker = BoneMarker.Create(b.Transform); marker.SetColor(_hangColor); _hangMarkers.Add(marker); marker.OnLeftClick = m => { var r = new HangRecord(); r.Bone = b; r.Pos = b.Transform.position; r.Rot = b.Transform.rotation; _hangRecords.Add(r); ClearHangMarker(); EnableLimbMarker(); }; }); }
private void InnerUpdate() { if (Input.GetKeyDown(KeyCode.T) && (Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt))) { var chara = FkCharaMgr.FindSelectChara(); if (chara != null) { chara.Limbs().Foreach(bone => { var r = new LockRecord(); r.Bone = bone; r.Pos = bone.Transform.position; r.Rot = bone.Transform.rotation; _lockRecord.Add(r); }); } } else if (Input.GetKeyDown(KeyCode.T) && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))) { var go = Context.GuideObjectManager().selectObject; if (go != null && go.IsLimb()) { var chara = FkCharaMgr.FindSelectChara(); var bone = chara.DicGuideBones[go]; var r = new LockRecord(); r.Bone = bone; r.Pos = bone.Transform.position; r.Rot = bone.Transform.rotation; _lockRecord.Add(r); } else if (go != null && (go.IsHead())) { var r = new LockRecord(); var bone = FkCharaMgr.BuildChara(go).Head; r.Bone = bone; r.Pos = bone.Transform.position; var cv = Context.MainCamera().transform.position - bone.Transform.position; if (Input.GetKey(KeyCode.LeftControl)) { r.Rot = Quaternion.FromToRotation(cv, bone.GuideObject.transformTarget.forward); } else { r.Rot = Quaternion.FromToRotation(cv, cv); } _headLocks.Add(r); } } else if (Input.GetKeyDown(KeyCode.T)) { _lockRecord.Clear(); _headLocks.Clear(); } _lockRecord.ForEach(r => { if (r.Pos != r.Bone.Transform.position) { r.Bone.MoveTo(r.Pos); } if (r.Rot != r.Bone.Transform.rotation) { r.Bone.TurnTo(r.Rot); } }); _headLocks.ForEach(r => { var bone = r.Bone; var target = Context.MainCamera().transform.position - bone.Transform.position; var from = new Vector3(0, 0, 1); var p1 = Quaternion.FromToRotation(from, target); var p2 = r.Rot; bone.TurnTo(p2 * p1); // var bone = r.Bone; // var go = new GameObject(); // var target = Context.MainCamera().transform.position - bone.Transform.position; // var v1 = go.transform.forward; // var v2 = new Vector3(target.x, 0, target.z); // var axis = Vector3.Cross(v1, v2); // var angel = Vector3.Angle(v1, v2); // go.transform.RotateAround(go.transform.position, axis, angel); // axis = Vector3.Cross(v2, target); // angel = Vector3.Angle(v2, target); // go.transform.RotateAround(go.transform.position, axis, angel); // bone.TurnTo(go.transform.rotation); // GameObject.Destroy(go); }); }