// // creates a graph based on a grid layout. This function requires the // dimensions of the environment and the number of cells required horizontally // and vertically public static void CreateGrid(NavGraph graph, int cySize, int cxSize, int numCellsY, int numCellsX) { //need some temporaries to help calculate each node center float cellWidth = (float)cxSize / (float)numCellsX; float cellHeight = (float)cySize / (float)numCellsY; float midX = cellWidth / 2.0f; float midY = cellHeight / 2.0f; //first create all the nodes for (int row = 0; row < numCellsY; ++row) { for (int col = 0; col < numCellsX; ++col) { graph.AddNode(new NavGraphNode(graph.GetNextFreeNodeIndex(), new Vector2(midX + col * cellWidth, midY + row * cellHeight))); } } //now to calculate the edges. (A position in a 2d array [x][y] is the //same as [y*numCellsX + x] in a 1d array). Each cell has up to eight //neighbours. for (int row = 0; row < numCellsY; ++row) { for (int col = 0; col < numCellsX; ++col) { AddAllNeighboursToGridNode(graph, row, col, numCellsX, numCellsY); } } }
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(); }