Exemple #1
0
        public static void Rebuild()
        {
            pb_Object[] pbObjs = (pb_Object[])GameObject.FindObjectsOfType(typeof(pb_Object));
            foreach (pb_Object pb in pbObjs)
            {
                pb_IntArray[] val = pb.sharedIndices;

                List <int> empty = new List <int>();

                for (int i = 0; i < val.Length; i++)
                {
                    if (val[i].IsEmpty())
                    {
                        empty.Add(i);
                    }
                }

                pb_IntArray[] trimmed = new pb_IntArray[val.Length - empty.Count];

                int n = 0;
                for (int i = 0; i < trimmed.Length; i++)
                {
                    if (!empty.Contains(i))
                    {
                        trimmed[n++] = val[i];
                    }
                }

                pb.SetSharedIndices(trimmed);
            }
        }
Exemple #2
0
    /**
     *	\brief Call this to ensure that the mesh is unique.  Basically performs a DeepCopy and assigns back to self.
     */
    public void MakeUnique()
    {
        pb_Face[] q = new pb_Face[_faces.Length];

        for (int i = 0; i < q.Length; i++)
        {
            q[i] = new pb_Face(_faces[i]);
        }

        pb_IntArray[] sv = new pb_IntArray[_sharedIndices.Length];
        System.Array.Copy(_sharedIndices, sv, sv.Length);

        SetSharedIndices(sv);
        SetFaces(q);

        Vector3[] v = new Vector3[vertexCount];
        System.Array.Copy(_vertices, v, vertexCount);
        SetVertices(v);

        if (_uv != null && _uv.Length == vertexCount)
        {
            Vector2[] u = new Vector2[vertexCount];
            System.Array.Copy(_uv, u, vertexCount);
            SetUV(u);
        }

        msh = pbUtil.DeepCopyMesh(msh);

        ToMesh();
        Refresh();
    }
Exemple #3
0
    /**
     *	\brief Returns a copy of the sharedIndices array.
     */
    public pb_IntArray[] GetSharedIndices()
    {
        int sil = _sharedIndices.Length;

        pb_IntArray[] sharedIndicesCopy = new pb_IntArray[sil];
        for (int i = 0; i < sil; i++)
        {
            int[] arr = new int[_sharedIndices[i].Length];
            System.Array.Copy(_sharedIndices[i].array, arr, arr.Length);
            sharedIndicesCopy[i] = new pb_IntArray(arr);
        }

        return(sharedIndicesCopy);
    }
		public static void Rebuild()
		{
			pb_Object[] pbObjs = (pb_Object[])GameObject.FindObjectsOfType(typeof(pb_Object));
			foreach(pb_Object pb in pbObjs)
			{
				pb_IntArray[] val = pb.sharedIndices;
					
				List<int> empty = new List<int>();

				for(int i = 0; i < val.Length; i++)
					if(val[i].IsEmpty())
						empty.Add(i);
				
				pb_IntArray[] trimmed = new pb_IntArray[val.Length-empty.Count];
				
				int n = 0;
				for(int i = 0; i < trimmed.Length; i++)
					if(!empty.Contains(i))
						trimmed[n++] = val[i];
							
				pb.SetSharedIndices( trimmed );
			}
		}
Exemple #5
0
        /**
         *	Similar to Merge vertices, expect that this method only collapses vertices within
         *	a specified distance of one another (typically epsilon).  Returns true if any action
         *  was taken, false otherwise.  Outputs indices that have been welded in the @welds var.
         */
        public static bool WeldVertices(this pb_Object pb, int[] indices, float delta, out int[] welds)
        {
            List <int> universal = pb.sharedIndices.GetUniversalIndices(indices).ToList();

            Vector3[] v = pb.vertices;

            HashSet <int> used = new HashSet <int>();
            KDTree <int>  tree = new KDTree <int>(3, 48);               // dimensions (xyz), node size

            for (int i = 0; i < universal.Count; i++)
            {
                Vector3 vert = v[pb.sharedIndices[universal[i]][0]];
                tree.AddPoint(new double[] { vert.x, vert.y, vert.z }, universal[i]);
            }

            List <List <int> > groups = new List <List <int> >();

            double[] point = new double[3] {
                0, 0, 0
            };

            int[][] si = pb.sharedIndices.ToArray();
            for (int i = 0; i < universal.Count; i++)
            {
                if (used.Contains(universal[i]))
                {
                    continue;
                }

                int tri = si[universal[i]][0];

                point[0] = v[tri].x;
                point[1] = v[tri].y;
                point[2] = v[tri].z;

                NearestNeighbour <int> neighborIterator = tree.NearestNeighbors(point, 64, delta);

                List <int> neighbors = new List <int>();

                while (neighborIterator.MoveNext())
                {
                    if (used.Contains(neighborIterator.Current))
                    {
                        continue;
                    }

                    used.Add(neighborIterator.Current);
                    neighbors.Add(neighborIterator.Current);
                }

                used.Add(universal[i]);
                groups.Add(neighbors);
            }

            pb_IntArray[] rebuilt = new pb_IntArray[groups.Count];            // + remainingCount ];
            welds = new int[groups.Count];

            for (int i = 0; i < groups.Count; i++)
            {
                rebuilt[i] = new pb_IntArray(groups[i].SelectMany(x => pb.sharedIndices[x].array).ToArray());
                welds[i]   = rebuilt[i][0];
            }

            foreach (pb_IntArray arr in rebuilt)
            {
                Vector3 avg = pb_Math.Average(pbUtil.ValuesWithIndices(v, arr.array));
                foreach (int i in arr.array)
                {
                    v[i] = avg;
                }
            }

            pb.SetVertices(v);
            // profiler.EndSample();

            pb_IntArray[] remaining = pb.sharedIndices.Where((val, index) => !used.Contains(index)).ToArray();

            rebuilt = pbUtil.Concat(rebuilt, remaining);

            pb.SetSharedIndices(rebuilt);

            return(true);
        }