Esempio n. 1
0
    public void Awake(Dictionary <Type, object> monobehaviours)
    {
        //container.Add<TicksManager>(monobehaviours[typeof(TicksManager)] as TicksManager);
        //container.Add<TranslationsManager>(new TranslationsManager());

        container.Add <PlayerState>(new PlayerState());
        container.Add <ShipState>(new ShipState());
    }
Esempio n. 2
0
        internal static bool TrySplitFace(this Kernel kernel, HalfEdge start, HalfEdge end, out (Face, Face) parts)
        {
            parts = (null, null);
            // TODO: Error checks

            // get edges for face of both halfedges
            var edges = new EdgeIterator(start).ToArray();

            // can't split triangles
            if (edges.Length <= 3)
            {
                return(false);
            }

            // get the index of the end edge inside the edges array
            var endIndex = Array.IndexOf(edges, end);

            // create the new ending halfedge for the start half
            var newEnd = new HalfEdge
            {
                Face     = start.Face,
                Next     = start,
                Previous = edges[endIndex - 1],
                Origin   = end.Origin
            };

            // create the new Face for the end half
            var newFace = new Face {
                Start = end
            };
            // create a new starting edge for the end half
            var newStart = new HalfEdge
            {
                Face     = newFace,
                Next     = end,
                Previous = edges.Last(),
                Origin   = start.Origin,
                Pair     = newEnd
            };

            // pair up the new end
            newEnd.Pair = newStart;

            // establish circular link for first face
            var firstFaceEdges = edges.Take(endIndex).ToList();

            firstFaceEdges.Add(newEnd);
            EdgeLinker.LinkOrderedEdgeCollection(firstFaceEdges);

            // hacky re-assignment
            newEnd.Face.Start = newEnd.Next;

            // establish circular link for second face
            var secondFaceEdges = edges.Skip(endIndex).ToList();

            secondFaceEdges.Insert(0, newStart);
            EdgeLinker.LinkOrderedEdgeCollection(secondFaceEdges);
            secondFaceEdges.ForEach(e => e.Face = newFace);

            // Add new edges to kernel
            kernel.Add(newEnd);
            kernel.Add(newStart);

            // add new face
            kernel.Insert(newFace);

            // prepare output
            parts = (start.Face, newFace);
            return(true);
        }
Esempio n. 3
0
        internal static void Kis(this Kernel kernel)
        {
            var initialFaceCount = kernel.FaceCount;

            for (int i = 0; i < initialFaceCount; i++)
            {
                var face = kernel.Faces[i];

                // get face center
                // TODO: We could move the center vertex by face normal direction to build a n - pyramid
                var center = face.GetFaceCenter();

                // get vertex for center
                var centerVertex = kernel.GetVertexForPosition(center);

                var newCenter = true;

                // iterate over face edges
                foreach (var edge in new EdgeIterator(face.Start))
                {
                    // new face that will be created
                    var newFace = new Face {
                        Start = edge
                    };

                    // link up current edge
                    edge.Face = newFace;

                    // create an edge from center to origin of current edge
                    if (!kernel.TryGetHalfEdgeBetweenVertices(centerVertex, edge.Origin, out var incoming))
                    {
                        incoming = new HalfEdge
                        {
                            Face   = newFace,
                            Origin = centerVertex
                        };
                    }

                    // create an edge from current edge target to center
                    if (!kernel.TryGetHalfEdgeBetweenVertices(edge.Target, centerVertex, out var outgoing))
                    {
                        outgoing = new HalfEdge
                        {
                            Face   = newFace,
                            Origin = edge.Target,
                        };
                    }

                    // link up center vertex on first iteration
                    if (newCenter)
                    {
                        centerVertex.Outgoing = incoming;
                        newCenter             = false;
                    }

                    // link up edges
                    EdgeLinker.LinkOrderedEdgeCollection(new[] { incoming, edge, outgoing });

                    // add new edges to kernel
                    kernel.Add(incoming);
                    kernel.Add(outgoing);

                    // insert new face into kernel
                    kernel.Insert(newFace);
                }

                // unlink face
                face.Start = null;
            }

            for (int i = initialFaceCount - 1; i >= 0; i--)
            {
                kernel.Remove(kernel.Faces[i]);
            }
        }