Esempio n. 1
0
        protected void Awake()
        {
            if (!BuoyancyObject._water)
            {
                BuoyancyObject._water = FindObjectOfType <WaterWaves>();
            }
            _colliders       = new List <Collider>(GetComponents <Collider>());
            _rigidbody       = GetComponent <Rigidbody>();
            _initDrag        = _rigidbody.drag;
            _initAngularDrag = _rigidbody.angularDrag;

            if (calculateDensity)
            {
                density = _rigidbody.mass / MathfUtils.CalculateVolume_Mesh(GetComponent <MeshFilter>().mesh, transform);
            }
        }
Esempio n. 2
0
        protected void OnDrawGizmos()
        {
            if (!Application.isPlaying)
            {
                Gizmos.color  = Color.cyan - new Color(0f, 0f, 0f, 0.75f);
                Gizmos.matrix = transform.localToWorldMatrix;

                Gizmos.DrawCube(GetComponent <BoxCollider>().center - Vector3.up * 0.01f, GetComponent <BoxCollider>().size);

                Gizmos.color = Color.cyan - new Color(0f, 0f, 0f, 0.5f);
                Gizmos.DrawWireCube(GetComponent <BoxCollider>().center, GetComponent <BoxCollider>().size);

                Gizmos.matrix = Matrix4x4.identity;
            }
            else
            {
                // Debug sufrace normal
                if (debugNormal)
                {
                    int[] triangles = mesh.triangles;
                    if (useJobs)
                    {
                        NativeArray <Vector3> vertices = worldVerticesNative;
                        for (int i = 0; i < triangles.Length; i += 3)
                        {
                            Gizmos.color = Color.white;
                            Gizmos.DrawLine(vertices[triangles[i + 0]], vertices[triangles[i + 1]]);
                            Gizmos.DrawLine(vertices[triangles[i + 1]], vertices[triangles[i + 2]]);
                            Gizmos.DrawLine(vertices[triangles[i + 2]], vertices[triangles[i + 0]]);

                            Vector3 center = MathfUtils.GetAveratePoint(vertices[triangles[i + 0]], vertices[triangles[i + 1]], vertices[triangles[i + 2]]);
                            Vector3 normal = GetSurfaceNormal(center);

                            Gizmos.color = Color.green;
                            Gizmos.DrawLine(center, center + normal);
                        }
                    }
                    else
                    {
                        var vertices = worldVertices;
                        for (int i = 0; i < triangles.Length; i += 3)
                        {
                            Gizmos.color = Color.white;
                            Gizmos.DrawLine(vertices[triangles[i + 0]], vertices[triangles[i + 1]]);
                            Gizmos.DrawLine(vertices[triangles[i + 1]], vertices[triangles[i + 2]]);
                            Gizmos.DrawLine(vertices[triangles[i + 2]], vertices[triangles[i + 0]]);

                            Vector3 center = MathfUtils.GetAveratePoint(vertices[triangles[i + 0]], vertices[triangles[i + 1]], vertices[triangles[i + 2]]);
                            Vector3 normal = GetSurfaceNormal(center);

                            Gizmos.color = Color.green;
                            Gizmos.DrawLine(center, center + normal);
                        }
                    }
                }

                // Debug mesh vertices
                if (debugMesh)
                {
                    if (worldVertices != null)
                    {
                        for (int i = 0; i < worldVertices.Length; i++)
                        {
                            DebugUtils.DrawPoint(worldVertices[i], Color.red);
                        }
                    }
                    else if (worldVerticesNative != null)
                    {
                        for (int i = 0; i < worldVerticesNative.Length; i++)
                        {
                            DebugUtils.DrawPoint(worldVerticesNative[i], Color.red);
                        }
                    }
                }

                // Test GetSurroundingTrianglePolygon
                if (debugTriangleSearch)
                {
                    if (debugTransformForTrinagleSearch != null)
                    {
                        Gizmos.color = Color.blue;
                        Gizmos.DrawSphere(debugTransformForTrinagleSearch.position, 0.1f);
                        var point    = debugTransformForTrinagleSearch.position;
                        var triangle = GetSurroundingTrianglePolygon(point);
                        if (triangle != null)
                        {
                            Gizmos.color = Color.red;
                            Gizmos.DrawLine(triangle[0], triangle[1]);
                            Gizmos.DrawLine(triangle[1], triangle[2]);
                            Gizmos.DrawLine(triangle[2], triangle[0]);
                        }
                    }
                }
            }
        }