Example #1
0
    public void SetTransform(CustomHandle handle)
    {
        this.rotation = Quaternion.LookRotation(
            handle.matrix.GetColumn(2),
            handle.matrix.GetColumn(1)
            );
        this.position = handle.matrix.GetColumn(3);
        this.scale    = new Vector3(
            handle.matrix.GetColumn(0).magnitude,
            handle.matrix.GetColumn(1).magnitude,
            handle.matrix.GetColumn(2).magnitude
            );

        matrix = Matrix4x4.TRS(position, rotation, scale);
    }
Example #2
0
        protected void AddDraggableHandles()
        {
            PointCloudPoint[] points = _shape.Points;

            int index = 0;

            foreach (T point in points)
            {
                Vector3 worldPosition = _shape.transform.position + (Vector3)point.LocalPosition;

                CustomHandle.DragHandleResult dhResult;
                string label = index.ToString();
                if (index == _lastIndexInteractedWith)
                {
                    label += "[Last Interacted]";
                }
                Handles.Label(worldPosition + new Vector3(0.5f, 0, 0), label);
                Vector3 movedWorldPosition = CustomHandle.DragHandle(worldPosition, 0.3f, Handles.SphereCap, Color.red, out dhResult);
                Vector3 movedLocalPosition = movedWorldPosition - _shape.gameObject.transform.position;

                switch (dhResult)
                {
                case CustomHandle.DragHandleResult.LMBDrag: {
                    T copy = point;
                    movedLocalPosition = _autoSnapInstance.SnapToValues(movedLocalPosition);
                    copy.LocalPosition = movedLocalPosition;
                    Undo.RecordObject(_shape, "SetPoint");
                    _shape.SetPoint(index, copy);
                    break;
                }

                case CustomHandle.DragHandleResult.LMBRelease:
                case CustomHandle.DragHandleResult.LMBClick:
                    _lastIndexInteractedWith = index;
                    break;
                }

                if (GUI.changed)
                {
                    EditorUtility.SetDirty(_shape);
                }

                index++;
            }
        }