Exemplo n.º 1
0
        public override void OnDrawGizmosSelected()
        {
            if (!drawGizmo)
            {
                return;
            }
            Vector3    position = transform.position;
            Quaternion rotation = transform.rotation;
            Vector3    scale    = m_localScaling;

            Gizmos.color = Color.yellow;
            BoxShape shape = GetCollisionShape() as BoxShape;

            Gizmos.matrix = this.transform.localToWorldMatrix * Matrix4x4.Scale(transform.lossyScale).inverse;
            for (int i = 0; i < shape.NumEdges; i++)
            {
                BulletSharp.Math.Vector3 vertex1;
                BulletSharp.Math.Vector3 vertex2;
                shape.GetEdge(i, out vertex1, out vertex2);
                Vector3 vertexUnity1 = BSExtensionMethods2.ToUnity(vertex1);
                Vector3 vertexUnity2 = BSExtensionMethods2.ToUnity(vertex2);
                Gizmos.DrawLine(vertexUnity1, vertexUnity2);
            }
            //BUtility.DebugDrawBox(position, rotation, scale, extents, Color.yellow);
        }
        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);
            }
        }
            public override void InternalProcessTriangleIndex(ref BulletSharp.Math.Vector3 point0, ref BulletSharp.Math.Vector3 point1, ref BulletSharp.Math.Vector3 point2, int partId, int triangleIndex)
            {
                Vector3 point0Unity = BSExtensionMethods2.ToUnity(point0);
                Vector3 point1Unity = BSExtensionMethods2.ToUnity(point1);
                Vector3 point2Unity = BSExtensionMethods2.ToUnity(point2);

                Gizmos.DrawLine(point0Unity, point1Unity);
                Gizmos.DrawLine(point1Unity, point2Unity);
                Gizmos.DrawLine(point2Unity, point0Unity);
            }
        //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);
        }
Exemplo n.º 5
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);
                     * }*/
                }
            }
        }