コード例 #1
0
        private void PrecomputeImprovedDrag()
        {
            MeshCollider meshCollider = (MeshCollider)this._LocalCollider;
            Mesh         sharedMesh   = meshCollider.sharedMesh;

            Vector3[] vertices = sharedMesh.vertices;
            Vector3[] normals  = sharedMesh.normals;
            int[]     indices  = sharedMesh.GetIndices(0);
            int       num      = indices.Length / 3;

            this._DragNormals    = new Vector3[num];
            this._DragVertices   = new Vector3[num * 3];
            this._DragCenters    = new Vector3[num];
            this._DragAreas      = new float[num];
            this._PolygonVolumes = new float[num];
            Vector3 b    = this._LocalCollider.transform.InverseTransformPoint(this._LocalCollider.bounds.center);
            int     num2 = 0;
            int     i    = 0;

            while (i < indices.Length)
            {
                Vector3 vector  = vertices[indices[i]];
                Vector3 vector2 = vertices[indices[i + 1]];
                Vector3 vector3 = vertices[indices[i + 2]];
                this._DragVertices[i]     = vector;
                this._DragVertices[i + 1] = vector2;
                this._DragVertices[i + 2] = vector3;
                this._DragAreas[num2]     = Vector3.Cross(vector2 - vector, vector3 - vector).magnitude * 0.5f;
                this._DragCenters[num2]   = (vector + vector2 + vector3) * 0.333333343f;
                Vector3 a  = normals[indices[i++]];
                Vector3 b2 = normals[indices[i++]];
                Vector3 b3 = normals[indices[i++]];
                this._DragNormals[num2] = (a + b2 + b3) * 0.333333343f;
                Vector3 p  = vector - b;
                Vector3 p2 = vector2 - b;
                Vector3 p3 = vector3 - b;
                this._PolygonVolumes[num2++] = Mathf.Abs(ColliderExtensions.SignedVolumeOfTriangle(p, p2, p3));
            }
            this._ImprovedDragSamples = new WaterSample[num];
        }
コード例 #2
0
        public static float ComputeVolume(this MeshCollider that)
        {
            float num        = 0f;
            Mesh  sharedMesh = that.sharedMesh;

            Vector3[] vertices  = sharedMesh.vertices;
            int[]     triangles = sharedMesh.triangles;
            int       num2      = triangles.Length;
            Vector3   b         = that.transform.InverseTransformPoint(that.bounds.center);
            int       i         = 0;

            while (i < num2)
            {
                Vector3 p  = vertices[triangles[i++]] - b;
                Vector3 p2 = vertices[triangles[i++]] - b;
                Vector3 p3 = vertices[triangles[i++]] - b;
                num += ColliderExtensions.SignedVolumeOfTriangle(p, p2, p3);
            }
            Vector3 lossyScale = that.transform.lossyScale;

            return(Mathf.Abs(num) * lossyScale.x * lossyScale.y * lossyScale.z);
        }