示例#1
0
        protected virtual void OnEnable()
        {
            if (Current != null && Current != this)
            {
                if (!Current.EditMode)
                {
                    DestroyImmediate(Current.Anchor.gameObject);
                }
                else
                {
                    Current.gameObject.SetActive(false);
                }
            }

            Current = this;

            foreach (var element in Elements)
            {
                element.gameObject.SetActive(true);
                element.enabled = true;
            }

            if (Anchor != null)
            {
                Anchor.gameObject.hideFlags = HideFlags.None;
                Anchor.gameObject.transform.SetAsLastSibling();
            }
        }
示例#2
0
        public static Face4 Create(GeometryEditor geometryEditor, Triangle triangle1, Triangle triangle2)
        {
            var uniqueVertices = new List <Vertex>();

            foreach (var vertex in triangle1.Vertices)
            {
                if (!uniqueVertices.Contains(vertex))
                {
                    uniqueVertices.Add(vertex);
                }
            }

            foreach (var vertex in triangle2.Vertices)
            {
                if (!uniqueVertices.Contains(vertex))
                {
                    uniqueVertices.Add(vertex);
                }
            }

            var b = CreateBaseFace <Face4>(geometryEditor, uniqueVertices.ToArray());

            b.Triangle1 = triangle1;
            b.Triangle2 = triangle2;

            return(b);
        }
示例#3
0
        public static Face3 Create(GeometryEditor geometryEditor, Triangle triangle)
        {
            var b = CreateBaseFace <Face3>(geometryEditor, triangle.Vertices[0], triangle.Vertices[1], triangle.Vertices[2]);

            b.Triangle = triangle;

            return(b);
        }
示例#4
0
        /// <summary>
        /// Creates a new geometry component on the specified game object,
        /// using data from the specified editor.
        /// </summary>
        /// <param name="geometryGameObject">The game object to attach
        /// the component to.</param>
        /// <param name="editor">The editor to get the data from.</param>
        /// <returns>The newly created geometry component.</returns>
        public static Geometry Create(GameObject geometryGameObject, GeometryEditor editor)
        {
            var builtGeometry = geometryGameObject.AddComponent <Geometry>();

            builtGeometry.GeometryEditor = editor;

            return(builtGeometry);
        }
示例#5
0
        public static MeshPreview Create(GeometryEditor geometryEditor)
        {
            var meshPreview = new GameObject("Mesh Preview", typeof(MeshPreview)).GetComponent <MeshPreview>();

            meshPreview.GeometryEditor = geometryEditor;
            meshPreview.transform.SetParent(geometryEditor.transform);

            return(meshPreview);
        }
示例#6
0
        /// <summary>
        /// Base method for creating a new geometry editor element.
        /// </summary>
        /// <typeparam name="T">The type of the element being created.</typeparam>
        /// <param name="mainGeometryEditor">The geometry editor to
        /// assign the element to.</param>
        /// <returns>The newly created editor.</returns>
        protected static T CreateBase <T>(GeometryEditor mainGeometryEditor) where T : GeometryEditorElement
        {
            var element = new GameObject(typeof(T).Name, typeof(T)).GetComponent <T>();

            element.GeometryEditor = mainGeometryEditor;
            element.transform.SetParent(mainGeometryEditor.transform, true);
            element.GeometryEditor.Elements.Add(element);

            return(element);
        }
示例#7
0
        public static Vertex Create(GeometryEditor geometryEditor, Vector3 position)
        {
            var vertex = CreateBase <Vertex>(geometryEditor);

            vertex.transform.position = position;
            geometryEditor.Vertices.Add(vertex);
            vertex.name += $" {geometryEditor.Vertices.IndexOf(vertex)}";

            vertex.PositionLastFrame = vertex.transform.position;

            return(vertex);
        }
示例#8
0
        protected static T CreateBaseFace <T>(GeometryEditor geometryEditor, params Vertex[] vertices) where T : Face
        {
            var face = CreateBase <T>(geometryEditor);

            face.Vertices = vertices;

            face.transform.position = face.Center;

            geometryEditor.Faces.Add(face);
            face.name += $" {geometryEditor.Faces.IndexOf(face)}";

            return(face);
        }
示例#9
0
        /// <summary>
        /// Creates a new anchor associated with the specified geometry editor.
        /// </summary>
        /// <param name="geometryEditor">The editor to associate the anchor with.</param>
        /// <returns>The newly created anchor.</returns>
        public static Anchor Create(GeometryEditor geometryEditor)
        {
            var anchor = new GameObject("Geometry Editor", typeof(Anchor)).GetComponent <Anchor>();

            anchor.GeometryEditor = geometryEditor;

            anchor.GeometryEditor.Elements.Add(anchor);

            anchor.transform.position = anchor.Center;

            anchor.SnapToGrid();

            anchor.PositionLastFrame = anchor.transform.position;

            return(anchor);
        }
示例#10
0
        public static Vertex2D Create(GeometryEditor editor, Vertex2D vertex1, Vertex2D vertex2, ViewSide viewSide)
        {
            var vertex2D = CreateBase <Vertex2D>(editor);

            vertex2D.Vertex1  = vertex1;
            vertex2D.Vertex2  = vertex2;
            vertex2D.ViewSide = viewSide;

            vertex2D.transform.position = vertex2D.GetPosition();
            vertex2D.PositionLastFrame  = vertex2D.GetPosition();

            editor.Vertices2D.Add(vertex2D);
            vertex2D.name += $" {editor.Vertices2D.IndexOf(vertex2D)}";

            return(vertex2D);
        }
示例#11
0
        public static Vertex2D Create(GeometryEditor editor, Face face, ViewSide viewSide, Vector3 offset)
        {
            var vertex2D = CreateBase <Vertex2D>(editor);

            vertex2D.Offset   = offset;
            vertex2D.Face     = face;
            vertex2D.ViewSide = viewSide;

            vertex2D.transform.position = vertex2D.GetPosition();
            vertex2D.PositionLastFrame  = vertex2D.GetPosition();

            editor.Vertices2D.Add(vertex2D);
            vertex2D.name += $" {editor.Vertices2D.IndexOf(vertex2D)}";

            return(vertex2D);
        }
示例#12
0
        public static Edge Create(GeometryEditor geometryEditor, Vertex vertex1, Vertex vertex2)
        {
            var edge = CreateBase <Edge>(geometryEditor);

            edge.Vertex1 = vertex1;
            edge.Vertex2 = vertex2;

            edge.Vertex1.Edges.Add(edge);
            edge.Vertex2.Edges.Add(edge);

            geometryEditor.Edges.Add(edge);
            edge.name += $" {geometryEditor.Edges.IndexOf(edge)}";

            edge.transform.position = edge.Midpoint;
            edge.PositionLastFrame  = edge.Midpoint;

            return(edge);
        }
示例#13
0
        /// <summary>
        /// Creates a new geometry data using the specified geometry editor to
        /// get the data from.
        /// </summary>
        /// <param name="editor">The editor to get the data from.</param>
        public GeometryData(GeometryEditor editor)
        {
            AnchorPosition = editor.Anchor.transform.position;

            Vertices = new Vector3[editor.Vertices.Count];
            for (var i = 0; i < Vertices.Length; i++)
            {
                Vertices[i] = editor.Vertices[i].transform.position;
            }

            Edges = new EdgeData[editor.Edges.Count];
            for (var i = 0; i < Edges.Length; i++)
            {
                Edges[i] = new EdgeData(editor.Edges[i].Vertex1.transform.position, editor.Edges[i].Vertex2.transform.position);
            }

            Faces = new FaceData[editor.Faces.Count];
            for (var i = 0; i < Faces.Length; i++)
            {
                var face = editor.Faces[i];

                var vertices = new Vector3[face.Vertices.Length];
                for (var j = 0; j < vertices.Length; j++)
                {
                    vertices[j] = face.Vertices[j].transform.position;
                }

                var triangles = new TriangleData[0];
                if (face is Face3 f3)
                {
                    triangles = new[] { new TriangleData(new []
                        {
                            f3.Triangle.Vertices[0].transform.position,
                            f3.Triangle.Vertices[1].transform.position,
                            f3.Triangle.Vertices[2].transform.position,
                        }) };
                }
                else if (face is Face4 f4)
                {
                    triangles = new[] { new TriangleData(new []
                        {
                            f4.Triangle1.Vertices[0].transform.position,
                            f4.Triangle1.Vertices[1].transform.position,
                            f4.Triangle1.Vertices[2].transform.position
                        }), new TriangleData(new []
                        {
                            f4.Triangle2.Vertices[0].transform.position,
                            f4.Triangle2.Vertices[1].transform.position,
                            f4.Triangle2.Vertices[2].transform.position
                        }) };
                }

                Faces[i] = new FaceData(face is Face4, vertices, triangles);
            }

            Vertices2D = new Vector3[editor.Vertices2D.Count];
            for (var i = 0; i < Vertices2D.Length; i++)
            {
                Vertices2D[i] = editor.Vertices2D[i].transform.position;
            }
        }