public override void OnDrawGizmosSelected()
        {
            if (!drawGizmo)
            {
                return;
            }
            Gizmos.color = Color.yellow;
            CollisionShape  shape       = GetCollisionShape();
            ConvexHullShape convexShape = shape as ConvexHullShape;

            Gizmos.matrix = transform.localToWorldMatrix * Matrix4x4.Scale(transform.lossyScale).inverse;
            if (convexShape != null)
            {
                //BulletSharp.Math.Matrix childShapeTransform = this.transform;
                //childShapeTransform.Invert();
                //BulletSharp.Math.Matrix shapeTransform = childShapeTransform * this.transform.localToWorldMatrix.ToBullet();
                int nbEdges = convexShape.NumEdges;
                for (int j = 0; j < nbEdges; j++)
                {
                    BulletSharp.Math.Vector3 vertex1;
                    BulletSharp.Math.Vector3 vertex2;
                    convexShape.GetEdge(j, out vertex1, out vertex2);
                    Vector3 vertexUnity1 = BSExtensionMethods2.ToUnity(vertex1);
                    Vector3 vertexUnity2 = BSExtensionMethods2.ToUnity(vertex2);
                    Gizmos.DrawLine(vertexUnity1, vertexUnity2);
                }
            }
            BvhTriangleMeshShape triangleShape = shape as BvhTriangleMeshShape;

            if (triangleShape != null)
            {
                DisplayTriangleCallback cb = new DisplayTriangleCallback();
                triangleShape.MeshInterface.InternalProcessAllTriangles(cb, triangleShape.LocalAabbMin, triangleShape.LocalAabbMax);
            }
        }
        //todo draw the hull when not in the world
        public override void OnDrawGizmosSelected()
        {
            Gizmos.color = Color.yellow;
            //            Gizmos.matrix =
            ConvexHullShape cs     = GetCollisionShape() as ConvexHullShape;
            Matrix4x4       matrix = Matrix4x4.TRS(transform.position, transform.rotation, transform.lossyScale);

            Gizmos.matrix = matrix;
            int nbEdges = cs.NumEdges;

            for (int i = 0; i < nbEdges; i++)
            {
                BulletSharp.Math.Vector3 vertex1;
                BulletSharp.Math.Vector3 vertex2;
                cs.GetEdge(i, out vertex1, out vertex2);
                Vector3 vertexUnity1 = BSExtensionMethods2.ToUnity(vertex1);
                Vector3 vertexUnity2 = BSExtensionMethods2.ToUnity(vertex2);
                Gizmos.DrawLine(vertexUnity1, vertexUnity2);
            }
            //Gizmos.DrawWireMesh(hullMesh, transform.position, transform.rotation, transform.lossyScale);
        }
示例#3
0
        public override void OnDrawGizmosSelected()
        {
            if (!drawGizmo)
            {
                return;
            }
            Gizmos.color = Color.yellow;
            CompoundShape compoundShape = GetCollisionShape() as CompoundShape;

            for (int i = 0; i < compoundShape.NumChildShapes; i++)
            {
                CollisionShape  collisionShape = compoundShape.GetChildShape(i);
                ConvexHullShape convexShape    = collisionShape as ConvexHullShape;
                if (convexShape != null)
                {
                    BulletSharp.Math.Matrix childShapeTransform = compoundShape.GetChildTransform(i);
                    //childShapeTransform.Invert();
                    BulletSharp.Math.Matrix shapeTransform = childShapeTransform * this.transform.localToWorldMatrix.ToBullet();
                    Gizmos.matrix = shapeTransform.ToUnity();
                    int nbEdges = convexShape.NumEdges;
                    for (int j = 0; j < nbEdges; j++)
                    {
                        BulletSharp.Math.Vector3 vertex1;
                        BulletSharp.Math.Vector3 vertex2;
                        convexShape.GetEdge(j, out vertex1, out vertex2);
                        Vector3 vertexUnity1 = BSExtensionMethods2.ToUnity(vertex1);
                        Vector3 vertexUnity2 = BSExtensionMethods2.ToUnity(vertex2);
                        Gizmos.DrawLine(vertexUnity1, vertexUnity2);
                    }

                    /*Mesh collisionMesh = new Mesh();
                    *  Vector3[] newVertices = new Vector3[convexShape.NumVertices];
                    *  int[] triangles = new int[convexShape.NumVertices * 3];
                    *  for (int j = 0; j < convexShape.NumVertices; j++)
                    *  {
                    *   BulletSharp.Math.Vector3 vertex1;
                    *   convexShape.GetVertex(j, out vertex1);
                    *   newVertices[j] = vertex1.ToUnity();
                    *   triangles[j] = j;
                    *  }
                    *  collisionMesh.vertices = newVertices;
                    *  collisionMesh.triangles = triangles;
                    *  collisionMesh.RecalculateNormals();
                    *  Gizmos.color = Color.blue;
                    *  Gizmos.DrawMesh(collisionMesh); */
                }
                BvhTriangleMeshShape triangleShape = collisionShape as BvhTriangleMeshShape;
                if (triangleShape != null)
                {
                    BulletSharp.Math.Matrix shapeTransform = this.transform.localToWorldMatrix.ToBullet() * compoundShape.GetChildTransform(i);
                    Gizmos.matrix = BSExtensionMethods2.ToUnity(shapeTransform);

                    /*int nbEdges = triangleShape.;
                     * for (int j = 0; j < nbEdges; j++)
                     * {
                     *   BulletSharp.Math.Vector3 vertex1;
                     *   BulletSharp.Math.Vector3 vertex2;
                     *   triangleShape.GetEdge(j, out vertex1, out vertex2);
                     *   Vector3 vertexUnity1 = BSExtensionMethods2.ToUnity(vertex1);
                     *   Vector3 vertexUnity2 = BSExtensionMethods2.ToUnity(vertex2);
                     *   Gizmos.DrawLine(vertexUnity1, vertexUnity2);
                     * }*/
                }
            }
        }