예제 #1
0
            internal void RefreshHull(MeshCollider collider)
            {
                _boundingMode = _parent.boundingMode;
                var unique = new HashSet <Vector3>();

                var vertices = collider.sharedMesh.vertices;

                for (int i = 0; i < vertices.Length; i++)
                {
                    if (!unique.Contains(vertices[i]))
                    {
                        unique.Add(vertices[i]);
                    }
                }

                bool velocityEnabled = _parent.isVelocityEnabled;

                if (_boundingMode == Bounding.FixedHull)
                {
                    velocityEnabled = false;

                    //Create the temporary hull to get the hull vertices
                    var tmpHull = new ConvexHull(unique.Count, false);

                    int idx = 0;
                    foreach (var v in unique)
                    {
                        tmpHull[idx++] = v;
                    }

                    tmpHull.CalculateHull();

                    //Filter away vertices very close to each other
                    unique = new HashSet <Vector3>(new Vector3EqualityComparer(_verticeClosenessThreshold));
                    for (int i = 0; i < tmpHull.hullPointsCount; i++)
                    {
                        if (!unique.Contains(tmpHull[i]))
                        {
                            unique.Add(tmpHull[i]);
                        }
                    }
                }

                //Create the actual hulls etc.
                _vertices = new Vector3[unique.Count];
                unique.CopyTo(_vertices);

                EnsurePaddingBuffer();

                _actualBounds = new ConvexHull(_vertices.Length, velocityEnabled);
                _oldBounds    = new ConvexHull(_vertices.Length, velocityEnabled);

                if (_boundingMode == Bounding.FixedHull)
                {
                    _actualBounds.hullPointsCount = _vertices.Length;
                }
            }