示例#1
0
    public bool Apply()
    {
        context.diagnostics.TakeSnapshot($"{nameof(ExperimentalRecordViveTrackersStep)}.{nameof(Apply)}.Before");
        var autoSetup = new TrackerAutoSetup(context);
        var hashSet   = new HashSet <string>();

        foreach (var mc in context.trackers.viveTrackers)
        {
            if (mc.mappedControllerName != null)
            {
                continue;
            }
            if (!mc.SyncMotionControl())
            {
                continue;
            }
            autoSetup.AttachToClosestNode(mc);
            if (!hashSet.Add(mc.mappedControllerName))
            {
                lastError = $"The same controller was bound more than once: {mc.mappedControllerName}";
                context.diagnostics.Log(lastError);
                mc.mappedControllerName = null;
                foreach (var mc2 in context.trackers.viveTrackers)
                {
                    if (mc2.mappedControllerName == null || mc2.mappedControllerName.EndsWith("FootControl"))
                    {
                        continue;
                    }
                    mc2.ResetToDefault();
                }
                return(false);
            }
        }
        context.Refresh();
        context.diagnostics.TakeSnapshot($"{nameof(ExperimentalRecordViveTrackersStep)}.{nameof(Apply)}.After");

        return(true);
    }
示例#2
0
    public bool Apply()
    {
        context.diagnostics.TakeSnapshot($"{nameof(ExperimentalRecordViveTrackersFeetStep)}.{nameof(Apply)}.Before");
        var feet              = context.containingAtom.freeControllers.Where(fc => fc.name.EndsWith("FootControl")).ToList();
        var eyes              = context.head.position.y;
        var floor             = context.worldScale.worldScaleMethodJSON.val == WorldScaleModule.PlayerHeightMethod ? eyes - (context.worldScale.playerHeightJSON.val * SuperController.singleton.worldScale) : 0f;
        var maxY              = floor + (eyes - floor) * 0.25f;
        var trackersNearFloor = context.trackers.viveTrackers
                                .Where(t => t.SyncMotionControl())
                                .Where(t => t.currentMotionControl.position.y < maxY)
                                .ToList();

        if (trackersNearFloor.Count != 2)
        {
            lastError = $"Expected to find 2 trackers near floor level, but {trackersNearFloor.Count} were found.\n\nFoot trackers were not assigned.\n\nTry again, or skip this step.";
            return(false);
        }

        var autoSetup = new TrackerAutoSetup(context);

        foreach (var mc in trackersNearFloor)
        {
            autoSetup.AttachToClosestNode(mc, feet);
        }

        if (trackersNearFloor[0].mappedControllerName == trackersNearFloor[1].mappedControllerName)
        {
            lastError = $"Embody: Both vive trackers were mapped to the same foot.\n\nMake sure your feet are each placed close to the model's feet.\n\nTry again, or skip this step.";
            trackersNearFloor[0].mappedControllerName = null;
            trackersNearFloor[1].mappedControllerName = null;
            return(false);
        }

        context.Refresh();
        context.diagnostics.TakeSnapshot($"{nameof(ExperimentalRecordViveTrackersFeetStep)}.{nameof(Apply)}.After");
        return(true);
    }
示例#3
0
    private void ShowMotionControl(MotionControllerWithCustomPossessPoint motionControl)
    {
        if (_section == null)
        {
            _section = CreateSection();
        }
        _section.RemoveAll();

        if (_currentMotionControl != null)
        {
            _currentMotionControl.highlighted = false;
        }

        if (motionControl == null)
        {
            return;
        }

        _currentMotionControl             = motionControl;
        _currentMotionControl.highlighted = true;

        if (MotionControlNames.IsViveTracker(motionControl.name))
        {
            _section.CreateButton("Map to Closest Control", true).button.onClick.AddListener(() =>
            {
                _trackerAutoSetup.AttachToClosestNode(motionControl);
                ShowMotionControl(motionControl);
                context.Refresh();
            });

            _section.CreateButton("Align to Mapped Control", true).button.onClick.AddListener(() =>
            {
                var controller = context.containingAtom.freeControllers.FirstOrDefault(fc => fc.name == motionControl.mappedControllerName);
                if (controller != null)
                {
                    _trackerAutoSetup.AlignToNode(motionControl, controller);
                    ShowMotionControl(motionControl);
                    context.Refresh();
                }
            });
        }

        _section.CreateToggle(new JSONStorableBool(
                                  $"{motionControl.name} Enabled",
                                  motionControl.enabled,
                                  val =>
        {
            motionControl.enabled = val;
            if (MotionControlNames.IsHands(motionControl.name))
            {
                _handsToggleJSON.valNoCallback = _trackers.leftHandMotionControl.enabled || _trackers.rightHandMotionControl.enabled;
            }
            context.Refresh();
        }
                                  ));

        if (!MotionControlNames.IsHeadOrHands(motionControl.name))
        {
            _section.CreateFilterablePopup(new JSONStorableStringChooser(
                                               "",
                                               new[] { _none }.Concat(_trackers.controllers.Select(mc => mc.controller.name)).ToList(),
                                               motionControl.mappedControllerName,
                                               "Map to control*",
                                               val =>
            {
                motionControl.mappedControllerName = val == _none ? null : val;
                context.Refresh();
            }), false);

            _section.CreateToggle(new JSONStorableBool(
                                      $"{motionControl.name} Controls Position*",
                                      motionControl.controlPosition,
                                      val => motionControl.controlPosition = val
                                      ), false);

            _section.CreateToggle(new JSONStorableBool(
                                      $"{motionControl.name} Controls Rotation*",
                                      motionControl.controlRotation,
                                      val => motionControl.controlRotation = val
                                      ), false);
        }

        if (MotionControlNames.IsHands(motionControl.name))
        {
            _section.CreateToggle(new JSONStorableBool(
                                      $"Fingers Tracking*",
                                      motionControl.fingersTracking,
                                      val => motionControl.fingersTracking = val
                                      ), false);

            _section.CreateToggle(new JSONStorableBool(
                                      $"Position Tracking*",
                                      motionControl.controlPosition,
                                      val => motionControl.controlPosition = motionControl.controlRotation = val
                                      ), false);

            _section.CreateToggle(new JSONStorableBool(
                                      $"Use Leap Motion Position*",
                                      motionControl.useLeapPositioning,
                                      val => motionControl.useLeapPositioning = val
                                      ), false);
        }

        _section.CreateSlider(new JSONStorableFloat(
                                  $"Offset X*",
                                  motionControl.offsetControllerCustom.x,
                                  val => motionControl.offsetControllerCustom = new Vector3(val, motionControl.offsetControllerCustom.y, motionControl.offsetControllerCustom.z),
                                  -0.5f,
                                  0.5f,
                                  false), false);

        _section.CreateSlider(new JSONStorableFloat(
                                  $"Offset Y*",
                                  motionControl.offsetControllerCustom.y,
                                  val => motionControl.offsetControllerCustom = new Vector3(motionControl.offsetControllerCustom.x, val, motionControl.offsetControllerCustom.z),
                                  -0.5f,
                                  0.5f,
                                  false), false);

        _section.CreateSlider(new JSONStorableFloat(
                                  $"Offset Z*",
                                  motionControl.offsetControllerCustom.z,
                                  val => motionControl.offsetControllerCustom = new Vector3(motionControl.offsetControllerCustom.x, motionControl.offsetControllerCustom.y, val),
                                  -0.5f,
                                  0.5f,
                                  false), false);

        _section.CreateSlider(new JSONStorableFloat(
                                  $"Rotate Controller X*",
                                  motionControl.rotateControllerCustom.x,
                                  val => motionControl.rotateControllerCustom = new Vector3(val, motionControl.rotateControllerCustom.y, motionControl.rotateControllerCustom.z),
                                  -180,
                                  180,
                                  false), false);

        _section.CreateSlider(new JSONStorableFloat(
                                  $"Rotate Controller Y*",
                                  motionControl.rotateControllerCustom.y,
                                  val => motionControl.rotateControllerCustom = new Vector3(motionControl.rotateControllerCustom.x, val, motionControl.rotateControllerCustom.z),
                                  -180,
                                  180,
                                  false), false);

        _section.CreateSlider(new JSONStorableFloat(
                                  $"Rotate Controller Z*",
                                  motionControl.rotateControllerCustom.z,
                                  val => motionControl.rotateControllerCustom = new Vector3(motionControl.rotateControllerCustom.x, motionControl.rotateControllerCustom.y, val),
                                  -180,
                                  180,
                                  false), false);

        _section.CreateSlider(new JSONStorableFloat(
                                  $"Rotate Around Tracker X*",
                                  motionControl.rotateAroundTrackerCustom.x,
                                  val => motionControl.rotateAroundTrackerCustom = new Vector3(val, motionControl.rotateAroundTrackerCustom.y, motionControl.rotateAroundTrackerCustom.z),
                                  -180,
                                  180,
                                  false), false);

        _section.CreateSlider(new JSONStorableFloat(
                                  $"Rotate Around Tracker Y*",
                                  motionControl.rotateAroundTrackerCustom.y,
                                  val => motionControl.rotateAroundTrackerCustom = new Vector3(motionControl.rotateAroundTrackerCustom.x, val, motionControl.rotateAroundTrackerCustom.z),
                                  -180,
                                  180,
                                  false), false);

        _section.CreateSlider(new JSONStorableFloat(
                                  $"Rotate Around Tracker Z*",
                                  motionControl.rotateAroundTrackerCustom.z,
                                  val => motionControl.rotateAroundTrackerCustom = new Vector3(motionControl.rotateAroundTrackerCustom.x, motionControl.rotateAroundTrackerCustom.y, val),
                                  -180,
                                  180,
                                  false), false);

        _section.CreateToggle(new JSONStorableBool(
                                  "Keep current physics hold strength*",
                                  motionControl.keepCurrentPhysicsHoldStrength,
                                  val => motionControl.keepCurrentPhysicsHoldStrength = val), false);

        if (MotionControlNames.IsHands(motionControl.name))
        {
            _section.CreateButton("Sync to other hand").button.onClick.AddListener(() =>
            {
                var otherHand = motionControl.name == MotionControlNames.LeftHand ? _trackers.rightHandMotionControl : _trackers.leftHandMotionControl;

                otherHand.offsetControllerCustom    = new Vector3(-motionControl.offsetControllerCustom.x, motionControl.offsetControllerCustom.y, motionControl.offsetControllerCustom.z);
                otherHand.rotateControllerCustom    = new Vector3(motionControl.rotateControllerCustom.x, -motionControl.rotateControllerCustom.y, -motionControl.rotateControllerCustom.z);
                otherHand.rotateAroundTrackerCustom = new Vector3(motionControl.rotateAroundTrackerCustom.x, -motionControl.rotateAroundTrackerCustom.y, -motionControl.rotateAroundTrackerCustom.z);
            });
        }
    }