コード例 #1
0
        internal void CreateVertices()
        {
            Heap <MqoVert> mh = new Heap <MqoVert>();

            foreach (TSOSubMesh sub_mesh in mesh.sub_meshes)
            {
                int     cnt = 0;
                ushort  a, b = 0, c = 0;
                MqoVert ma, mb = new MqoVert(), mc = new MqoVert();

                foreach (Vertex v in sub_mesh.vertices)
                {
                    MqoVert m = new MqoVert(v.position, v.normal, null);
                    ushort  i;
                    if (mh.map.TryGetValue(m, out i))
                    {
                        //集約先はidx=i
                        m = mh.ary[i];
                    }
                    else
                    {
                        m.skin_weights = new MqoSkinWeight[4];
                        for (int w = 0; w < 4; w++)
                        {
                            m.skin_weights[w] = new MqoSkinWeight(sub_mesh.GetBone(v.skin_weights[w].bone_index), v.skin_weights[w].weight);
                        }
                        //mはidx=iになる
                        i = (ushort)mh.Count;
                        mh.Add(m);
                    }
                    //集約する
                    m.rel.Add(new TSOPair(v, sub_mesh));

                    cnt++;
                    a  = b;
                    b  = c;
                    c  = i;
                    ma = mb;
                    mb = mc;
                    mc = m;

                    m.Index = i;
                    graph.AddNode(m);

                    if (cnt < 3)
                    {
                        continue;
                    }

                    if (a != b && b != c && c != a)
                    {
                        graph.AddEdge(new MqoEdge(a, b, GetCost(ma, mb)));
                        graph.AddEdge(new MqoEdge(b, c, GetCost(mb, mc)));
                        graph.AddEdge(new MqoEdge(c, a, GetCost(mc, ma)));
                    }
                }
            }
            vertices = mh.ary.ToArray();
        }
コード例 #2
0
ファイル: GraphHelper.cs プロジェクト: xvok16/TDCGExplorer
        //
        //  use to add he eight neighboring edges of a graph node that
        //  is positioned in a grid layout
        public static void AddAllNeighboursToGridNode(NavGraph graph, int row, int col, int numCellsX, int numCellsY)
        {
            for (int i = -1; i <= +1; ++i)
            {
                for (int j = -1; j <= +1; ++j)
                {
                    //skip if equal to this node
                    if (i == 0 && j == 0)
                    {
                        continue;
                    }

                    int nodeX = col + j;
                    int nodeY = row + i;

                    //check to see if this is a valid neighbour
                    if (ValidNeighbour(nodeX, nodeY, numCellsX, numCellsY))
                    {
                        //calculate the distance to this node
                        Vector2 posNode      = graph.GetNode(row * numCellsX + col).Position;
                        Vector2 posNeighbour = graph.GetNode(nodeY * numCellsX + nodeX).Position;

                        float dist = Vector2.Length(posNeighbour - posNode);

                        GraphEdge newEdge;

                        newEdge = new GraphEdge(row * numCellsX + col, nodeY * numCellsX + nodeX, dist);
                        graph.AddEdge(newEdge);

                        //if graph is not a diagraph then an edge needs to be added going
                        //in the other direction
                        if (!graph.IsDigraph())
                        {
                            newEdge = new GraphEdge(nodeY * numCellsX + nodeX, row * numCellsX + col, dist);
                            graph.AddEdge(newEdge);
                        }
                    }
                }
            }
        }