public Vector3 GetLocalAxis(CoordinateSystemAxis axis) { if (IsValid) { return(_surfaceQuad.GetLocalAxis(axis)); } return(Vector3.zero); }
private void RenderAlignmentAxisSelectionPopup() { CoordinateSystemAxis newCoordSystemAxis = (CoordinateSystemAxis)EditorGUILayout.EnumPopup(GetContentForAxisAlignmentSelectionPopup(), _settings.AlignmentAxis); if (newCoordSystemAxis != _settings.AlignmentAxis) { UndoEx.RecordForToolAction(_settings); _settings.AlignmentAxis = newCoordSystemAxis; } }
private void RenderCoordinateSystemAxis(CoordinateSystemAxis axis, CoordinateSystemRenderSettings coordinateSystemRenderSettings) { if (coordinateSystemRenderSettings.IsAxisVisible(axis)) { GizmosColor.Push(coordinateSystemRenderSettings.GetAxisColor(axis)); Vector3 axisVector = CoordinateSystemAxes.GetGlobalVector(axis); Gizmos.DrawLine(Vector3.zero, axisVector * coordinateSystemRenderSettings.GetAxisSize(axis)); GizmosColor.Pop(); } }
private void RenderAlignmentAxisSelectionPopup() { CoordinateSystemAxis newAxis = (CoordinateSystemAxis)EditorGUILayout.EnumPopup(GetContentForAlignmentAxisSelectionPopup(), _brushElement.AlignmentAxis); if (newAxis != _brushElement.AlignmentAxis) { UndoEx.RecordForToolAction(_brushElement); _brushElement.AlignmentAxis = newAxis; } }
public static Vector3 GetVector(CoordinateSystemAxis axis, TransformSpace transformSpace, Transform transform) { if (transformSpace == TransformSpace.Local) { return(GetLocalVector(axis, transform)); } else { return(GetGlobalVector(axis)); } }
public void InvertAxisScale(CoordinateSystemAxis axis) { if (axis == CoordinateSystemAxis.PositiveRight || axis == CoordinateSystemAxis.NegativeRight) { XScale = -XScale; } else if (axis == CoordinateSystemAxis.PositiveUp || axis == CoordinateSystemAxis.NegativeUp) { YScale = -YScale; } else { ZScale = -ZScale; } }
public static Vector3 GetLocalVector(CoordinateSystemAxis axis, Transform transform) { if (axis == CoordinateSystemAxis.PositiveRight) { return(transform.right); } if (axis == CoordinateSystemAxis.NegativeRight) { return(-transform.right); } if (axis == CoordinateSystemAxis.PositiveUp) { return(transform.up); } if (axis == CoordinateSystemAxis.NegativeUp) { return(-transform.up); } if (axis == CoordinateSystemAxis.PositiveLook) { return(transform.forward); } return(-transform.forward); }
public static Vector3 GetLocalVector(CoordinateSystemAxis axis, TransformMatrix transformMatrix) { if (axis == CoordinateSystemAxis.PositiveRight) { return(transformMatrix.GetNormalizedRightAxis()); } if (axis == CoordinateSystemAxis.NegativeRight) { return(-transformMatrix.GetNormalizedRightAxis()); } if (axis == CoordinateSystemAxis.PositiveUp) { return(transformMatrix.GetNormalizedUpAxis()); } if (axis == CoordinateSystemAxis.NegativeUp) { return(-transformMatrix.GetNormalizedUpAxis()); } if (axis == CoordinateSystemAxis.PositiveLook) { return(transformMatrix.GetNormalizedLookAxis()); } return(-transformMatrix.GetNormalizedLookAxis()); }
public Color GetAxisColor(CoordinateSystemAxis axis) { return(_axesRenderSettings[(int)axis].Color); }
public void SetAxisColor(CoordinateSystemAxis axis, Color color) { _axesRenderSettings[(int)axis].Color = color; }
public static CoordinateSystemAxis GetNext(CoordinateSystemAxis axis) { return((CoordinateSystemAxis)(((int)axis + 1) % Count)); }
public Vector3 GetAxisVector(CoordinateSystemAxis axis) { return(_localAxes[(int)axis]); }
public void RenderGUI(UnityEngine.Object undoRecordObject) { bool newBool; ObjectBlockProjectionDir newProjectionDir; CoordinateSystemAxis newAlignmentAxis; EditorGUI.indentLevel += 1; EditorGUILayout.Foldout(true, "Block projection settings"); EditorGUI.indentLevel -= 1; if (true) { EditorGUILayoutEx.BeginVerticalBox(); var content = new GUIContent(); content.text = "Project on surface"; content.tooltip = "If this is checked, the objects in the block will be projected on a surface. The projection surface " + "is selected by casting a projection ray along the chosen projection direction."; newBool = EditorGUILayout.ToggleLeft(content, ProjectOnSurface); if (newBool != ProjectOnSurface) { UndoEx.RecordForToolAction(undoRecordObject); ProjectOnSurface = newBool; } if (ProjectOnSurface) { content.text = "Reject non-projectables"; content.tooltip = "If this is checked, the plugin will not spawn objects which can not be projected on a surface."; newBool = EditorGUILayout.ToggleLeft(content, RejectNonProjectables); if (newBool != RejectNonProjectables) { UndoEx.RecordForToolAction(undoRecordObject); RejectNonProjectables = newBool; } content.text = "Projection direction"; content.tooltip = "Allows you to specify the direction of projection."; newProjectionDir = (ObjectBlockProjectionDir)EditorGUILayout.EnumPopup(content, ProjectionDirection); if (newProjectionDir != ProjectionDirection) { UndoEx.RecordForToolAction(undoRecordObject); ProjectionDirection = newProjectionDir; } content.text = "Can project on terrain"; content.tooltip = "If this is checked, objects can be projected onto terrain surfaces. Otherwise, terrain surfaces will be ignored."; newBool = EditorGUILayout.ToggleLeft(content, CanProjectOnTerrain); if (newBool != CanProjectOnTerrain) { UndoEx.RecordForToolAction(undoRecordObject); CanProjectOnTerrain = newBool; } content.text = "Can project on mesh"; content.tooltip = "If this is checked, objects can be projected onto mesh surfaces. Otherwise, mesh surfaces will be ignored."; newBool = EditorGUILayout.ToggleLeft(content, CanProjectOnMesh); if (newBool != CanProjectOnMesh) { UndoEx.RecordForToolAction(undoRecordObject); CanProjectOnMesh = newBool; } content.text = "Align to normal"; content.tooltip = "If this is checked, the objects will have one of their axes aligned with the projection surface."; newBool = EditorGUILayout.ToggleLeft(content, AlignToSurfaceNormal); if (newBool != AlignToSurfaceNormal) { UndoEx.RecordForToolAction(undoRecordObject); AlignToSurfaceNormal = newBool; } content.text = "Alignment axis"; content.tooltip = "If surface alignment is turned on, this is the axis that will be used to align objects to the projection surface normal."; newAlignmentAxis = (CoordinateSystemAxis)EditorGUILayout.EnumPopup(content, AlignmentAxis); if (newAlignmentAxis != AlignmentAxis) { UndoEx.RecordForToolAction(undoRecordObject); AlignmentAxis = newAlignmentAxis; } } EditorGUILayoutEx.EndVerticalBox(); } }
public static void AlignObjectAxis(GameObject gameObject, CoordinateSystemAxis alignmentAxis, Vector3 destinationAxis) { Transform objectTransform = gameObject.transform; objectTransform.rotation = CalculateRotationQuaternionForAxisAlignment(objectTransform.rotation, alignmentAxis, destinationAxis); }
public static Vector3 GetGlobalVector(CoordinateSystemAxis axis) { return(_globalVectors[(int)axis]); }
public void SetAxisFiniteSize(CoordinateSystemAxis axis, float size) { _axesRenderSettings[(int)axis].FiniteSize = size; }
public void SetAxisRenderInfinite(CoordinateSystemAxis axis, bool renderInfinite) { _axesRenderSettings[(int)axis].IsInfinite = renderInfinite; }
public bool IsAxisRenderedInfinite(CoordinateSystemAxis axis) { return(_axesRenderSettings[(int)axis].IsInfinite); }
public Vector3 GetLocalAxis(CoordinateSystemAxis axis) { return(_circleShape.GetLocalAxis(axis)); }
/// <summary> /// Returns the size of the specified axis. This is a convenience method which /// returns the correct size of the axis based on whether or not the axis is /// rendered infinite. If the axis is not rendered infinite, this is the same /// as calling 'GeteAxisFinitSize'. /// </summary> public float GetAxisSize(CoordinateSystemAxis axis) { return(_axesRenderSettings[(int)axis].GetSize()); }
public Vector3 GetLocalAxis(CoordinateSystemAxis axis) { return(_ellipse.GetLocalAxis(axis)); }
public static Quaternion CalculateRotationQuaternionForAxisAlignment(Quaternion currentRotation, CoordinateSystemAxis alignmentAxis, Vector3 destinationAxis) { TransformMatrix rotationMatrix = TransformMatrix.GetIdentity(); rotationMatrix.Rotation = currentRotation; Vector3 axisToAlign = CoordinateSystemAxes.GetLocalVector(alignmentAxis, rotationMatrix); bool isAlignmentAxisNegative = CoordinateSystemAxes.IsNegativeAxis(alignmentAxis); // Already aligned? bool pointsInSameDirection; bool isAlignedWithDestinationAxis = destinationAxis.IsAlignedWith(axisToAlign, out pointsInSameDirection); if (isAlignedWithDestinationAxis && pointsInSameDirection) { return(currentRotation); } if (!isAlignedWithDestinationAxis) { Vector3 rotationAxis = Vector3.Cross(axisToAlign, destinationAxis); rotationAxis.Normalize(); return(Quaternion.AngleAxis(axisToAlign.AngleWith(destinationAxis), rotationAxis) * currentRotation); } else { // If this point is reached, it means the axis is aligned with the destination axis but points in the opposite // direction. In this case we can not use the cross product, so we will have to regenerate the axes. Vector3 newRightAxis, newUpAxis, newLookAxis; if (alignmentAxis == CoordinateSystemAxis.PositiveRight || alignmentAxis == CoordinateSystemAxis.NegativeRight) { newRightAxis = destinationAxis; if (isAlignmentAxisNegative) { newRightAxis *= -1.0f; } bool worldUpPointsSameDirAsRightAxis; if (newRightAxis.IsAlignedWith(Vector3.up, out worldUpPointsSameDirAsRightAxis)) { newLookAxis = worldUpPointsSameDirAsRightAxis ? Vector3.forward : Vector3.back; } else { newLookAxis = Vector3.Cross(newRightAxis, Vector3.up); } if (isAlignmentAxisNegative) { newLookAxis *= -1.0f; } newUpAxis = Vector3.Cross(newLookAxis, newRightAxis); } if (alignmentAxis == CoordinateSystemAxis.PositiveUp || alignmentAxis == CoordinateSystemAxis.NegativeUp) { newUpAxis = destinationAxis; if (isAlignmentAxisNegative) { newUpAxis *= -1.0f; } bool worldUpPointsSameDirAsUpAxis; if (newUpAxis.IsAlignedWith(Vector3.up, out worldUpPointsSameDirAsUpAxis)) { newLookAxis = worldUpPointsSameDirAsUpAxis ? Vector3.forward : Vector3.back; } else { newLookAxis = Vector3.Cross(newUpAxis, Vector3.up); } if (isAlignmentAxisNegative) { newLookAxis *= -1.0f; } } else { newLookAxis = destinationAxis; if (isAlignmentAxisNegative) { newLookAxis *= -1.0f; } bool worldUpPointsSameDirAsLookAxis; if (newLookAxis.IsAlignedWith(Vector3.up, out worldUpPointsSameDirAsLookAxis)) { newUpAxis = worldUpPointsSameDirAsLookAxis ? Vector3.forward : Vector3.back; } else { newUpAxis = Vector3.Cross(newLookAxis, Vector3.up); } if (isAlignmentAxisNegative) { newUpAxis *= -1.0f; } } // Normalize the axes which were calculated newUpAxis.Normalize(); newLookAxis.Normalize(); // Now use the axes to calculate the rotation quaternion return(Quaternion.LookRotation(newLookAxis, newUpAxis)); } }
public CoordinateSystemAxisRenderSettings GetAxisRenderSettings(CoordinateSystemAxis axis) { return(_axesRenderSettings[(int)axis]); }
public void RenderView() { bool newBool; float newFloat; var content = new GUIContent(); content.text = "Align axis"; content.tooltip = "If this is checked, the obejcts' axes will be aligned with the hovered surface. Use the \'Alignment axis\' property to " + "specify the alignment axis."; newBool = EditorGUILayout.ToggleLeft(content, AlignAxis); if (newBool != AlignAxis) { UndoEx.RecordForToolAction(this); AlignAxis = newBool; } if (_alignAxis) { content.text = "Alignment axis"; content.tooltip = "Allows you to specify the alignment axis for the grabbed objects."; CoordinateSystemAxis newAxis = (CoordinateSystemAxis)EditorGUILayout.EnumPopup(content, AlignmentAxis); if (newAxis != AlignmentAxis) { UndoEx.RecordForToolAction(this); AlignmentAxis = newAxis; } } content.text = "Rotation sensitivity"; content.tooltip = "Allows you to control how sensitive the rotation is to mouse movements. Only horizontal movements count."; newFloat = EditorGUILayout.Slider(content, RotationSensitivity, _minSensitivity, 1.0f); if (newFloat != RotationSensitivity) { UndoEx.RecordForToolAction(this); RotationSensitivity = newFloat; } content.text = "Scale sensitivity"; content.tooltip = "Allows you to control how sensitive the scale is to mouse movements. Only horizontal movements count."; newFloat = EditorGUILayout.Slider(content, ScaleSensitivity, _minSensitivity, 1.0f); if (newFloat != ScaleSensitivity) { UndoEx.RecordForToolAction(this); ScaleSensitivity = newFloat; } Octave3DWorldBuilder.ActiveInstance.ShowGUIHint("Offset from surface only works when axis alignment is on OR when embedding is off."); content.text = "Offset from surface"; content.tooltip = "Allows you to control how much objects are offset from the surface on which they're sitting."; newFloat = EditorGUILayout.FloatField(content, OffsetFromSurface); if (newFloat != OffsetFromSurface) { UndoEx.RecordForToolAction(this); OffsetFromSurface = newFloat; } content.text = "Embed in surface (no align)"; content.tooltip = "If this is checked, the objects will be embedded inside the surface on which they reside by a specified percentage of their size. " + "This is useful for example when grabbing tress along a terrain surface with bumps/hills when axis alignment is turned off. In this case " + "embedding the tree will ensure the trunk of the tree will not float above the terrain."; newBool = EditorGUILayout.ToggleLeft(content, EmbedInSurfaceWhenNoAlign); if (newBool != EmbedInSurfaceWhenNoAlign) { UndoEx.RecordForToolAction(this); EmbedInSurfaceWhenNoAlign = newBool; } EditorGUILayout.Separator(); content.text = "Show grab lines"; content.tooltip = "Should the grab lines be drawn during a grab sesson. These are the lines that go from the objects' centers to the grab pivot."; newBool = EditorGUILayout.ToggleLeft(content, ShowGrabLines); if (newBool != ShowGrabLines) { UndoEx.RecordForToolAction(this); ShowGrabLines = newBool; } content.text = "Grab line color"; content.tooltip = "During a grab session, a line will be drawn from each object's center to the grab pivot point. This field allows you to control the color of those lines."; Color newColor = EditorGUILayout.ColorField(content, GrabLineColor); if (newColor != GrabLineColor) { UndoEx.RecordForToolAction(this); GrabLineColor = newColor; SceneView.RepaintAll(); } }
public bool IsAxisVisible(CoordinateSystemAxis axis) { return(_axesRenderSettings[(int)axis].IsVisible); }
public void InvertAxisScale(CoordinateSystemAxis axis) { _transformMatrix.InvertAxisScale(axis); RecalculateLocalAxes(); }
public void SetAxisVisible(CoordinateSystemAxis axis, bool visible) { _axesRenderSettings[(int)axis].IsVisible = visible; }
public Vector3 GetLocalAxis(CoordinateSystemAxis axis) { return(_coordinateSystem.GetAxisVector(axis)); }
public static bool IsNegativeAxis(CoordinateSystemAxis axis) { return(axis == CoordinateSystemAxis.NegativeRight || axis == CoordinateSystemAxis.NegativeUp || axis == CoordinateSystemAxis.NegativeLook); }