public static Microsoft.Xna.Framework.Matrix Convert(StillDesign.PhysX.MathPrimitives.Matrix input) { Microsoft.Xna.Framework.Matrix output = new Microsoft.Xna.Framework.Matrix ( input.M11, input.M12, input.M13, input.M14, input.M21, input.M22, input.M23, input.M24, input.M31, input.M32, input.M33, input.M34, input.M41, input.M42, input.M43, input.M44 ); return output; }
/// <summary> /// Initializes a new instance of the <see cref="PhysxTriangleMesh"/> class. /// Cooks the Model on the fly /// </summary> /// <param name="PhysxPhysicWorld">The physx physic world.</param> /// <param name="model">The model.</param> /// <param name="worldTransformation">The world transformation.</param> /// <param name="scale">The scale.</param> /// <param name="density">The density.</param> /// <param name="material">The material.</param> public PhysxTriangleMesh(PhysxPhysicWorld PhysxPhysicWorld, IModelo model, Microsoft.Xna.Framework.Matrix worldTransformation, Microsoft.Xna.Framework.Vector3 scale, float density = 1,StillDesign.PhysX.Material material = null) { Microsoft.Xna.Framework.Vector3[] vertices = null; int[] indices = null; ExtractData(ref vertices, ref indices, model); TriangleMeshDescription meshDesc = new TriangleMeshDescription(); meshDesc.AllocateVertices<Microsoft.Xna.Framework.Vector3>(vertices.Count()); meshDesc.VerticesStream.SetData<Microsoft.Xna.Framework.Vector3>(vertices); meshDesc.AllocateTriangles<int>(indices.Count()); meshDesc.TriangleStream.SetData<int>(indices); meshDesc.Flags = 0; meshDesc.VertexCount = vertices.Count(); meshDesc.TriangleCount = indices.Count(); MemoryStream ms = new MemoryStream(); Cooking.InitializeCooking(); if (Cooking.CookTriangleMesh(meshDesc, ms) == false) { PloobsEngine.Engine.Logger.ActiveLogger.LogMessage("Cant Cook Model",Engine.Logger.LogLevel.FatalError); } Cooking.CloseCooking(); ms.Position = 0; TriangleMesh triangleMesh = PhysxPhysicWorld.Core.CreateTriangleMesh(ms); TriangleMeshShapeDescription bunnyShapeDesc = new TriangleMeshShapeDescription(); if (material != null) bunnyShapeDesc.Material = material; bunnyShapeDesc.TriangleMesh = triangleMesh; ActorDesc = new ActorDescription(); ActorDesc.Shapes.Add(bunnyShapeDesc); ActorDesc.BodyDescription= null; ActorDesc.GlobalPose = worldTransformation.AsPhysX(); this.Scale = scale; }
/// <summary> /// This method gets the debug geometry from the PhysX scene, and draws it to the screen. This is useful for /// making sure that models are being correctly placed within their PhysX bounding boxes, and for checking to /// see if things are physically working without actually drawing them. /// </summary> /// <param name="scene">The PhysX scene that we want to draw debug geometry for.</param> public void DrawPhysXDebug(StillDesign.PhysX.Scene scene) { Camera cam = (Camera)this.Game.Services.GetService(typeof(ICameraService)); _graphics.VertexDeclaration = new VertexDeclaration(_graphics, VertexPositionColor.VertexElements); BasicEffect debugEffect = new BasicEffect(_graphics, null); debugEffect.World = Matrix.Identity; debugEffect.View = cam.View; debugEffect.Projection = cam.Projection; DebugRenderable data = scene.GetDebugRenderable(); debugEffect.Begin(); foreach (EffectPass pass in debugEffect.CurrentTechnique.Passes) { pass.Begin(); if (data.PointCount > 0) { DebugPoint[] points = data.GetDebugPoints(); _graphics.DrawUserPrimitives<DebugPoint>(PrimitiveType.PointList, points, 0, points.Length); } if (data.LineCount > 0) { DebugLine[] lines = data.GetDebugLines(); VertexPositionColor[] vertices = new VertexPositionColor[data.LineCount * 2]; for (int x = 0; x < data.LineCount; x++) { DebugLine line = lines[x]; vertices[x * 2 + 0] = new VertexPositionColor(line.Point0, Int32ToColor(line.Color)); vertices[x * 2 + 1] = new VertexPositionColor(line.Point1, Int32ToColor(line.Color)); } _graphics.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, vertices, 0, lines.Length); } if (data.TriangleCount > 0) { DebugTriangle[] triangles = data.GetDebugTriangles(); VertexPositionColor[] vertices = new VertexPositionColor[data.TriangleCount * 3]; for (int x = 0; x < data.TriangleCount; x++) { DebugTriangle triangle = triangles[x]; vertices[x * 3 + 0] = new VertexPositionColor(triangle.Point0, Int32ToColor(triangle.Color)); vertices[x * 3 + 1] = new VertexPositionColor(triangle.Point1, Int32ToColor(triangle.Color)); vertices[x * 3 + 2] = new VertexPositionColor(triangle.Point2, Int32ToColor(triangle.Color)); } _graphics.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, vertices, 0, triangles.Length); } pass.End(); } debugEffect.End(); }
public StillDesign.PhysX.Material CreatePhysicMaterial(StillDesign.PhysX.MaterialDescription MaterialDescription, bool safeAndSlowUpdate = true) { this.safeAndSlowUpdate = safeAndSlowUpdate; return Scene.CreateMaterial(MaterialDescription); }