コード例 #1
0
ファイル: PolyMesh.cs プロジェクト: jcnossen/upspring.net
		public void Optimize(IsEqualVertexDelegate cb)
		{
			OptimizeVertices(cb);

			// remove double linked vertices
			List<Poly> npl = new List<Poly>();
			foreach (Poly pl in poly) {
				bool finished;
				do {
					finished = true;
					for (int i = 0, j = (int)pl.Length - 1; i < pl.Length; j = i++)
						if (pl[i] == pl[j]) {
							var l = new List<int>(pl.verts);
							l.RemoveAt(i);
							pl.verts = l.ToArray();
							finished = false;
							break;
						}
				} while (!finished);

				if (pl.Length >= 3)
					npl.Add(pl);
			}
			poly = npl.ToArray();
		}
コード例 #2
0
ファイル: PolyMesh.cs プロジェクト: jcnossen/upspring.net
		public void OptimizeVertices(IsEqualVertexDelegate cb)
		{
			int[] old2new = new int[verts.Length];
			int[] usage = new int[verts.Length];
			List<Vertex> nv = new List<Vertex>();

			foreach (Poly pl in poly) {
				for (int b = 0; b < pl.Length; b++)
					usage[pl.verts[b]]++;
			}

			for (int a = 0; a < verts.Length; a++) {
				bool matched = false;

				if (usage[a] == 0)
					continue;

				for (int b = 0; b < nv.Count; b++) {
					if (cb(verts[a], nv[b])) {
						matched = true;
						old2new[a] = b;
						break;
					}
				}

				if (!matched) {
					old2new[a] = nv.Count;
					nv.Add(verts[a]);
				}
			}

			verts = nv.ToArray();

			// map the poly vertex-indices to the new set of vertices
			foreach (Poly pl in poly) {
				for (int b = 0; b < pl.Length; b++)
					pl.verts[b] = old2new[pl.verts[b]];
			}
		}