/// <summary> /// draw a line /// </summary> public static bool DrawLineTrunk(bool trunk, Vector3 p1, Vector3 p2, Color color, float size, out bool hasChanged) { hasChanged = false; Vector3 direction = (p1 - p2); Vector3 middle = ExtVector3.GetMeanOfXPoints(p1, p2); Quaternion rotation = ExtQuaternion.QuaternionFromLine(p1, p2, Vector3.up); Handles.color = color; float scaleCylinder = direction.magnitude; if (!trunk) { Matrix4x4 scaleMatrix = Matrix4x4.TRS(middle, rotation, new Vector3(size, size, scaleCylinder)); using (new Handles.DrawingScope(scaleMatrix)) { Handles.CylinderHandleCap(0, Vector3.zero, Quaternion.identity, 1, EventType.Repaint); } } if (!Event.current.alt && Event.current.button != 2 && Handles.Button( middle, rotation, scaleCylinder, scaleCylinder, ExtGravityOverrideEditor.LineHandleCap)) { trunk = !trunk; hasChanged = true; Use(); } return(trunk); }
/// 2 ------2------ 3 /// 1 | 3 | /// 1 ------4----- 4 | /// | | 3 | | /// | 4| | 2 | /// | 1 | /// | | /// public ExtQuad(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4) : this() { _position = ExtVector3.GetMeanOfXPoints(p1, p2, p3, p4); Vector3 x = p1 - p2; Vector3 y = p1 - p4; Vector3 up = Vector3.Cross(x, y); _rotation = ExtRotation.QuaternionFromVectorDirector(up, x.FastNormalized()); _rotation = ExtRotation.RotateQuaternion(_rotation, new Vector3(-90, 0, 0)); _localScale = new Vector3(y.magnitude, 1, x.magnitude); UpdateMatrix(); }
/// <summary> /// from a given point in space, order the face, from the closest to the farrest from the point /// /// cube /// 6 ------------ 7 /// / | 3 / | /// 5 ------------ 8 | /// | | | | /// | 5 | 6 | 2-|------------ face /// | | 1 | | /// | 2 ----------|-- 3 /// |/ 4 | / /// 1 ------------ 4 /// </summary> /// <returns></returns> public static FloatRange[] GetOrdersOfFaceFromPoint(ExtCube cube, Vector3 point) { FloatRange[] faceDistance = new FloatRange[6]; faceDistance[0] = new FloatRange(1, ExtVector3.DistanceSquared(ExtVector3.GetMeanOfXPoints(cube.P1, cube.P5, cube.P8, cube.P4), point)); faceDistance[1] = new FloatRange(2, ExtVector3.DistanceSquared(ExtVector3.GetMeanOfXPoints(cube.P4, cube.P8, cube.P7, cube.P3), point)); faceDistance[2] = new FloatRange(3, ExtVector3.DistanceSquared(ExtVector3.GetMeanOfXPoints(cube.P5, cube.P6, cube.P7, cube.P8), point)); faceDistance[3] = new FloatRange(4, ExtVector3.DistanceSquared(ExtVector3.GetMeanOfXPoints(cube.P1, cube.P2, cube.P3, cube.P4), point)); faceDistance[4] = new FloatRange(5, ExtVector3.DistanceSquared(ExtVector3.GetMeanOfXPoints(cube.P2, cube.P6, cube.P5, cube.P1), point)); faceDistance[5] = new FloatRange(6, ExtVector3.DistanceSquared(ExtVector3.GetMeanOfXPoints(cube.P3, cube.P7, cube.P6, cube.P2), point)); faceDistance = FloatRange.Sort(faceDistance); return(faceDistance); }
private static void GroupGravityFields() { GameObject[] selected = Selection.gameObjects; if (selected.Length == 0) { return; } List <GameObject> selectedWithAttractor = new List <GameObject>(selected.Length); for (int i = 0; i < selected.Length; i++) { Attractor action = selected[i].GetComponentInChildren <Attractor>(); if (action != null) { selectedWithAttractor.Add(selected[i]); } } //first, do not group anything if one of them is already grouped for (int i = 0; i < selectedWithAttractor.Count; i++) { AttractorGroup parent = selectedWithAttractor[i].GetComponentInParent <AttractorGroup>(); if (parent != null) { return; } } Selection.activeGameObject = null; Transform commonParent = ExtObjectEditor.FindCommonParent(selectedWithAttractor, selectedWithAttractor[0].transform.parent); EditorGUIUtility.PingObject(commonParent); GameObject newParent = new GameObject("AttractorGroup"); newParent.transform.position = ExtVector3.GetMeanOfXPoints(selectedWithAttractor.ToArray(), out Vector3 sizeBoundingBox, true); AttractorGroup newGroup = newParent.AddComponent <AttractorGroup>(); //UnityEditor.Editor splineEditorGeneric = UnityEditor.Editor.CreateEditor(newGroup, typeof(GravityFieldsGroupEditor)); //GravityFieldsGroupEditor groupEditor = (GravityFieldsGroupEditor)splineEditorGeneric; //groupEditor.FillGroupList(selectedWithGravityFieldsAction); SetupSiblingOfNewGroup(selectedWithAttractor, commonParent, newParent); ExtReflection.SetExpanded(newParent, true); ExtReflection.Rename(newParent); }
public ExtCylinder(Vector3 p1, Vector3 p2, float radius = 0.25f) : this() { _position = ExtVector3.GetMeanOfXPoints(p1, p2); _rotation = ExtQuaternion.QuaternionFromLine(p1, p2, Vector3.up); _rotation = ExtRotation.RotateQuaternion(_rotation, new Vector3(90, 0, 0)); _localScale = new Vector3(1, 1, 1); _cylinderMatrix = Matrix4x4.TRS(_position, _rotation, _localScale * 1); //why radius a 0.25, and lenght * 0.8 ?? I don't know, //it's there to match the first constructor(position, rotation, scale) _radius = radius; _lenght = ExtVector3.Distance(p2, p1) * 0.8f; _lenghtSquared = _lenght * _lenght; _radiusSquared = _radius * _radius; _realRadius = _radius * MaxXY(_localScale); _realSquaredRadius = _realRadius * _realRadius; UpdateMatrix(); }