public CanvasPositionHandle(DesignItem adornedControlItem, AdornerPanel adornerPanel, HandleOrientation orientation) { Debug.Assert(adornedControlItem != null); this.adornedControlItem = adornedControlItem; this.adornerPanel = adornerPanel; this.orientation = orientation; Angle = (double) orientation; canvas = (Canvas) adornedControlItem.Parent.Component; adornedControl = (FrameworkElement) adornedControlItem.Component; Stub = new MarginStub(this); ShouldBeVisible = true; leftDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.LeftProperty, adornedControlItem.Component.GetType()); leftDescriptor.AddValueChanged(adornedControl, OnPropertyChanged); rightDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.RightProperty, adornedControlItem.Component.GetType()); rightDescriptor.AddValueChanged(adornedControl, OnPropertyChanged); topDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.TopProperty, adornedControlItem.Component.GetType()); topDescriptor.AddValueChanged(adornedControl, OnPropertyChanged); bottomDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.BottomProperty, adornedControlItem.Component.GetType()); bottomDescriptor.AddValueChanged(adornedControl, OnPropertyChanged); widthDescriptor = DependencyPropertyDescriptor.FromProperty(Control.WidthProperty, adornedControlItem.Component.GetType()); widthDescriptor.AddValueChanged(adornedControl, OnPropertyChanged); heightDescriptor = DependencyPropertyDescriptor.FromProperty(Control.WidthProperty, adornedControlItem.Component.GetType()); heightDescriptor.AddValueChanged(adornedControl, OnPropertyChanged); BindAndPlaceHandle(); }
/// <summary> /// A node handle to which connections attach /// </summary> public NodeHandle(BaseNode attachedTo, HandleOrientation startingOrientation) { handleTex = AssetDatabase.LoadAssetAtPath("Assets/NodeEditor/Editor/Images/Handle.png", typeof(Texture)) as Texture; this.attachedTo = attachedTo; this.orientation = startingOrientation; CalculatePosition(); }
public MarginHandle(DesignItem adornedControlItem, AdornerPanel adornerPanel, HandleOrientation orientation) { Debug.Assert(adornedControlItem != null); this.adornedControlItem = adornedControlItem; this.adornerPanel = adornerPanel; this.orientation = orientation; Angle = (double)orientation; grid = (Grid)adornedControlItem.Parent.Component; adornedControl = (FrameworkElement)adornedControlItem.Component; Stub = new MarginStub(this); ShouldBeVisible = true; BindAndPlaceHandle(); adornedControlItem.PropertyChanged += OnPropertyChanged; OnPropertyChanged(this.adornedControlItem, new PropertyChangedEventArgs("HorizontalAlignment")); OnPropertyChanged(this.adornedControlItem, new PropertyChangedEventArgs("VerticalAlignment")); }
/// <summary> /// Get a rotation suitable for orienting a handle or gizmo relative to the element selection. /// </summary> /// <param name="mesh">The target mesh.</param> /// <param name="orientation">The type of <see cref="HandleOrientation"/> to calculate.</param> /// <param name="edges">Edges to consider in the rotation calculations. Only used when /// <see cref="HandleOrientation"/> is <see cref="HandleOrientation.ActiveElement"/>.</param> /// <returns>A rotation appropriate to the orientation and element selection.</returns> public static Quaternion GetEdgeRotation(ProBuilderMesh mesh, HandleOrientation orientation, IEnumerable <Edge> edges) { if (mesh == null) { return(Quaternion.identity); } switch (orientation) { case HandleOrientation.ActiveElement: if (mesh.selectedEdgeCount < 1) { goto case HandleOrientation.ActiveObject; } // Getting an average of the edge normals isn't very helpful in real world uses, so we just use the // first selected edge for orientation. // This function accepts an enumerable because in the future we may want to do something more // sophisticated, and it's convenient because selections are stored as collections. var face = EdgeUtility.GetFace(mesh, edges.First()); if (face == null) { goto case HandleOrientation.ActiveObject; } Normal nrm = Math.NormalTangentBitangent(mesh, face); if (nrm.normal == Vector3.zero || nrm.bitangent == Vector3.zero) { goto case HandleOrientation.ActiveObject; } return(mesh.transform.rotation * Quaternion.LookRotation(nrm.normal, nrm.bitangent)); case HandleOrientation.ActiveObject: return(mesh.transform.rotation); default: return(Quaternion.identity); } }
/// <summary> /// Returns a rotation suitable for orienting a handle or gizmo relative to the Face selection. /// </summary> /// <param name="mesh">The target mesh.</param> /// <param name="orientation">The type of <see cref="HandleOrientation"/> to calculate.</param> /// <param name="faces">Which faces to consider in the rotation calculations. This is only used when the /// <see cref="HandleOrientation"/> is set to <see cref="HandleOrientation.ActiveElement"/>.</param> /// <returns>A rotation appropriate to the orientation and element selection.</returns> public static Quaternion GetFaceRotation(ProBuilderMesh mesh, HandleOrientation orientation, IEnumerable <Face> faces) { if (mesh == null) { return(Quaternion.identity); } switch (orientation) { case HandleOrientation.ActiveElement: // Intentionally not using coincident vertices here. We want the normal of just the face, not an // average of it's neighbors. return(GetFaceRotation(mesh, faces.Last())); case HandleOrientation.ActiveObject: return(mesh.transform.rotation); default: return(Quaternion.identity); } }
/// <summary> /// Change where the handle is drawn /// </summary> public void Move(Vector2 mousePos) { Vector2 spacing = mousePos - attachedTo.rect.center; Vector2 scaledSpacing = new Vector2(spacing.x / attachedTo.rect.width, spacing.y / attachedTo.rect.height); if(Mathf.Abs(scaledSpacing.x) > Mathf.Abs(scaledSpacing.y)) { if (spacing.x < 0) { orientation = HandleOrientation.LEFT; } else { orientation = HandleOrientation.RIGHT; } offset = spacing.y; } else { if(spacing.y < 0) { orientation = HandleOrientation.TOP; } else { orientation = HandleOrientation.BOTTOM; } offset = spacing.x; } CalculatePosition(); }
/// <summary> /// Returns a rotation suitable for orienting a handle or gizmo relative to the Vertex selection. /// </summary> /// <param name="mesh">The target mesh.</param> /// <param name="orientation">The type of <see cref="HandleOrientation"/> to calculate.</param> /// <param name="vertices">Array of <see cref="Vertex"/> indices pointing to the vertices to consider in the rotation calculations. This is only used when the /// <see cref="HandleOrientation"/> is set to <see cref="HandleOrientation.ActiveElement"/>.</param> /// <returns>A rotation appropriate to the orientation and element selection.</returns> public static Quaternion GetVertexRotation(ProBuilderMesh mesh, HandleOrientation orientation, IEnumerable <int> vertices) { if (mesh == null) { return(Quaternion.identity); } switch (orientation) { case HandleOrientation.ActiveElement: if (mesh.selectedVertexCount < 1) { goto case HandleOrientation.ActiveObject; } return(GetRotation(mesh, vertices)); case HandleOrientation.ActiveObject: return(mesh.transform.rotation); default: return(Quaternion.identity); } }
/// <summary> /// Returns a rotation suitable for orienting a handle or gizmo relative to the Edge selection. /// </summary> /// <param name="mesh">The target mesh.</param> /// <param name="orientation">The type of <see cref="HandleOrientation"/> to calculate.</param> /// <param name="edges">Which edges to consider in the rotation calculations. This is only used when the /// <see cref="HandleOrientation"/> is set to <see cref="HandleOrientation.ActiveElement"/>.</param> /// <returns>A rotation appropriate to the orientation and element selection.</returns> public static Quaternion GetEdgeRotation(ProBuilderMesh mesh, HandleOrientation orientation, IEnumerable <Edge> edges) { if (mesh == null) { return(Quaternion.identity); } switch (orientation) { case HandleOrientation.ActiveElement: // Getting an average of the edge normals isn't very helpful in real world uses, so we just use the // first selected edge for orientation. // This function accepts an enumerable because in the future we may want to do something more // sophisticated, and it's convenient because selections are stored as collections. return(GetEdgeRotation(mesh, edges.Last())); case HandleOrientation.ActiveObject: return(mesh.transform.rotation); default: return(Quaternion.identity); } }
private static void Postfix(HandleRagdoll __instance, RagdollHand ragdollHand, float axisPosition, HandleOrientation orientation, bool teleportToHand = false) { if (__instance.ragdollPart.ragdoll.creature.FreezeData().IsCreatureFrozen) { Instance.UnFreezeCreature(__instance.ragdollPart.ragdoll.creature); } }
public MarginHandle(DesignItem adornedControlItem, AdornerPanel adornerPanel, HandleOrientation orientation) { Debug.Assert(adornedControlItem!=null); this.adornedControlItem = adornedControlItem; this.adornerPanel = adornerPanel; this.orientation = orientation; Angle = (double)orientation; grid=(Grid)adornedControlItem.Parent.Component; adornedControl=(FrameworkElement)adornedControlItem.Component; Stub = new MarginStub(this); ShouldBeVisible=true; BindAndPlaceHandle(); adornedControlItem.PropertyChanged += OnPropertyChanged; OnPropertyChanged(this.adornedControlItem, new PropertyChangedEventArgs("HorizontalAlignment")); OnPropertyChanged(this.adornedControlItem, new PropertyChangedEventArgs("VerticalAlignment")); }
public CanvasPositionHandle(DesignItem adornedControlItem, AdornerPanel adornerPanel, HandleOrientation orientation) { Debug.Assert(adornedControlItem != null); this.adornedControlItem = adornedControlItem; this.adornerPanel = adornerPanel; this.orientation = orientation; Angle = (double)orientation; canvas = (Canvas)adornedControlItem.Parent.Component; adornedControl = (FrameworkElement)adornedControlItem.Component; Stub = new MarginStub(this); ShouldBeVisible = true; leftDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.LeftProperty, adornedControlItem.Component.GetType()); leftDescriptor.AddValueChanged(adornedControl, OnPropertyChanged); rightDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.RightProperty, adornedControlItem.Component.GetType()); rightDescriptor.AddValueChanged(adornedControl, OnPropertyChanged); topDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.TopProperty, adornedControlItem.Component.GetType()); topDescriptor.AddValueChanged(adornedControl, OnPropertyChanged); bottomDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.BottomProperty, adornedControlItem.Component.GetType()); bottomDescriptor.AddValueChanged(adornedControl, OnPropertyChanged); widthDescriptor = DependencyPropertyDescriptor.FromProperty(Control.WidthProperty, adornedControlItem.Component.GetType()); widthDescriptor.AddValueChanged(adornedControl, OnPropertyChanged); heightDescriptor = DependencyPropertyDescriptor.FromProperty(Control.WidthProperty, adornedControlItem.Component.GetType()); heightDescriptor.AddValueChanged(adornedControl, OnPropertyChanged); BindAndPlaceHandle(); }
internal override MeshAndElementSelection GetElementSelection(ProBuilderMesh mesh, PivotPoint pivot, HandleOrientation orientation) { return(new MeshAndPositions(mesh, pivot, orientation)); }
public static Vector3 GetSnapPoint(Vector3 position, Quaternion rotation, Vector3 snapVector, Vector3 dragDirection, HandleOrientation handlesOrientation) { var selectedControl = HandleControlsUtility.handleControls.GetCurrentSelectedControl(); Vector3 result = Vector3.zero; if (handlesOrientation == HandleOrientation.globalAligned) { rotation = Quaternion.identity; } if (selectedControl == HandleControlsUtility.HandleControls.xAxisMoveHandle) { result = GetXSnappedPos(position, rotation, dragDirection, snapVector, selectedControl); } else if (selectedControl == HandleControlsUtility.HandleControls.yAxisMoveHandle) { result = GetYSnappedPos(position, rotation, dragDirection, snapVector, selectedControl); } else if (selectedControl == HandleControlsUtility.HandleControls.zAxisMoveHandle) { result = GetZSnappedPos(position, rotation, dragDirection, snapVector, selectedControl); } else if (selectedControl == HandleControlsUtility.HandleControls.xyAxisMoveHandle) { //Vector3 localAxisDir = GetXaxisinWorld(rotation); selectedControl = HandleControlsUtility.HandleControls.xAxisMoveHandle; result = GetXSnappedPos(position, rotation, dragDirection, snapVector, selectedControl); //localAxisDir = GetYaxisinWorld(rotation); selectedControl = HandleControlsUtility.HandleControls.yAxisMoveHandle; result = GetYSnappedPos(result, rotation, dragDirection, snapVector, selectedControl); } else if (selectedControl == HandleControlsUtility.HandleControls.yzAxisMoveHandle) { //Vector3 localAxisDir = GetYaxisinWorld(rotation); selectedControl = HandleControlsUtility.HandleControls.yAxisMoveHandle; result = GetYSnappedPos(position, rotation, dragDirection, snapVector, selectedControl); //localAxisDir = GetZaxisinWorld(rotation); selectedControl = HandleControlsUtility.HandleControls.zAxisMoveHandle; result = GetZSnappedPos(result, rotation, dragDirection, snapVector, selectedControl); } else if (selectedControl == HandleControlsUtility.HandleControls.xzAxisMoveHandle) { //Vector3 localAxisDir = GetXaxisinWorld(rotation); selectedControl = HandleControlsUtility.HandleControls.xAxisMoveHandle; result = GetXSnappedPos(position, rotation, dragDirection, snapVector, selectedControl); //localAxisDir = GetZaxisinWorld(rotation); selectedControl = HandleControlsUtility.HandleControls.zAxisMoveHandle; result = GetZSnappedPos(result, rotation, dragDirection, snapVector, selectedControl); } else if (selectedControl == HandleControlsUtility.HandleControls.allAxisMoveHandle) { //Vector3 localAxisDir = GetXaxisinWorld(rotation); selectedControl = HandleControlsUtility.HandleControls.xAxisMoveHandle; result = GetXSnappedPos(position, rotation, dragDirection, snapVector, selectedControl); //localAxisDir = GetYaxisinWorld(rotation); selectedControl = HandleControlsUtility.HandleControls.yAxisMoveHandle; result = GetXSnappedPos(result, rotation, dragDirection, snapVector, selectedControl); //localAxisDir = GetZaxisinWorld(rotation); selectedControl = HandleControlsUtility.HandleControls.zAxisMoveHandle; result = GetXSnappedPos(result, rotation, dragDirection, snapVector, selectedControl); } return(result); }
internal override MeshAndElementSelection GetElementSelection(ProBuilderMesh mesh, PivotPoint pivot, HandleOrientation orientation) { return(new TranslateTextureSelection(mesh, pivot, orientation)); }
public MeshAndElementSelection(ProBuilderMesh mesh, PivotPoint pivot, HandleOrientation orientation, bool collectCoincidentIndices) { m_Mesh = mesh; m_ElementGroups = ElementGroup.GetElementGroups(mesh, pivot, orientation, collectCoincidentIndices); }
public static List <ElementGroup> GetElementGroups(ProBuilderMesh mesh, PivotPoint pivot, HandleOrientation orientation, bool collectCoincident) { var groups = new List <ElementGroup>(); var trs = mesh.transform.localToWorldMatrix; var selectMode = ProBuilderEditor.selectMode; switch (pivot) { case PivotPoint.IndividualOrigins: { if (selectMode.ContainsFlag(SelectMode.Vertex | SelectMode.TextureVertex)) { foreach (var list in GetVertexSelectionGroups(mesh, collectCoincident)) { var bounds = Math.GetBounds(mesh.positionsInternal, list); var rot = UnityEngine.ProBuilder.HandleUtility.GetVertexRotation(mesh, orientation, list); groups.Add(new ElementGroup(list, trs.MultiplyPoint3x4(bounds.center), rot)); } } else if (selectMode.ContainsFlag(SelectMode.Edge | SelectMode.TextureEdge)) { foreach (var list in GetEdgeSelectionGroups(mesh)) { var bounds = Math.GetBounds(mesh.positionsInternal, list); var rot = UnityEngine.ProBuilder.HandleUtility.GetEdgeRotation(mesh, orientation, list); List <int> indices; if (collectCoincident) { indices = new List <int>(); mesh.GetCoincidentVertices(list, indices); } else { indices = list.SelectMany(x => new int[] { x.a, x.b }).ToList(); } groups.Add(new ElementGroup(indices, trs.MultiplyPoint3x4(bounds.center), rot)); } } else if (selectMode.ContainsFlag(SelectMode.Face | SelectMode.TextureFace)) { foreach (var list in GetFaceSelectionGroups(mesh)) { var bounds = Math.GetBounds(mesh.positionsInternal, list); var rot = UnityEngine.ProBuilder.HandleUtility.GetFaceRotation(mesh, orientation, list); List <int> indices; if (collectCoincident) { indices = new List <int>(); mesh.GetCoincidentVertices(list, indices); } else { indices = list.SelectMany(x => x.distinctIndexesInternal).ToList(); } groups.Add(new ElementGroup(indices, trs.MultiplyPoint3x4(bounds.center), rot)); } } break; } case PivotPoint.ActiveElement: { var indices = GetSelectedIndicesForSelectMode(mesh, selectMode, collectCoincident); var position = mesh.transform.position; var rotation = mesh.transform.rotation; if (selectMode.ContainsFlag(SelectMode.Face | SelectMode.TextureFace)) { var face = mesh.GetActiveFace(); if (face != null) { position = trs.MultiplyPoint3x4(Math.GetBounds(mesh.positionsInternal, face.distinctIndexesInternal).center); rotation = UnityEngine.ProBuilder.HandleUtility.GetFaceRotation(mesh, orientation, new Face[] { face }); } } else if (selectMode.ContainsFlag(SelectMode.Edge | SelectMode.TextureEdge)) { var edge = mesh.GetActiveEdge(); if (edge != Edge.Empty) { position = trs.MultiplyPoint3x4(Math.GetBounds(mesh.positionsInternal, new int [] { edge.a, edge.b }).center); rotation = UnityEngine.ProBuilder.HandleUtility.GetEdgeRotation(mesh, orientation, new Edge[] { edge }); } } else if (selectMode.ContainsFlag(SelectMode.Vertex | SelectMode.TextureVertex)) { var vertex = mesh.GetActiveVertex(); if (vertex > -1) { position = trs.MultiplyPoint3x4(mesh.positionsInternal[vertex]); rotation = UnityEngine.ProBuilder.HandleUtility.GetVertexRotation(mesh, orientation, new int[] { vertex }); } } groups.Add(new ElementGroup(indices, position, rotation)); break; } default: { var indices = GetSelectedIndicesForSelectMode(mesh, selectMode, collectCoincident); var position = MeshSelection.bounds.center; var rotation = Quaternion.identity; if (selectMode.ContainsFlag(SelectMode.Face | SelectMode.TextureFace)) { var face = mesh.GetActiveFace(); if (face != null) { rotation = UnityEngine.ProBuilder.HandleUtility.GetFaceRotation(mesh, orientation, new Face[] { face }); } } else if (selectMode.ContainsFlag(SelectMode.Edge | SelectMode.TextureEdge)) { var edge = mesh.GetActiveEdge(); if (edge != Edge.Empty) { rotation = UnityEngine.ProBuilder.HandleUtility.GetEdgeRotation(mesh, orientation, new Edge[] { edge }); } } else if (selectMode.ContainsFlag(SelectMode.Vertex | SelectMode.TextureVertex)) { var vertex = mesh.GetActiveVertex(); if (vertex > -1) { rotation = UnityEngine.ProBuilder.HandleUtility.GetVertexRotation(mesh, orientation, new int[] { vertex }); } } groups.Add(new ElementGroup(indices, position, rotation)); break; } } return(groups); }
internal abstract MeshAndElementSelection GetElementSelection(ProBuilderMesh mesh, PivotPoint pivot, HandleOrientation orientation);