public PhysxTriangleMesh(PhysxPhysicWorld PhysxPhysicWorld, IModelo model,Microsoft.Xna.Framework.Matrix localTransformation, Microsoft.Xna.Framework.Matrix worldTransformation, Microsoft.Xna.Framework.Vector3 scale, MaterialDescription MaterialDescription) { Microsoft.Xna.Framework.Vector3[] vertices = null; int[] indices = null; ExtractData(ref vertices, ref indices, model); TriangleMeshDesc meshDesc = new TriangleMeshDesc(); Vector3[] points = new Vector3[vertices.Count()]; for (int i = 0; i < vertices.Count(); i++) { points[i] = vertices[i].AsPhysX(); } meshDesc.Points = points; meshDesc.SetTriangles<int>(indices); //meshDesc.Triangles = indices; MemoryStream ms = new MemoryStream(); if(PhysxPhysicWorld.Cooking.CookTriangleMesh(meshDesc,ms)==false) { PloobsEngine.Engine.Logger.ActiveLogger.LogMessage("Cant Cook Model",Engine.Logger.LogLevel.FatalError); } ms.Position = 0; TriangleMesh triangleMesh = PhysxPhysicWorld.Physix.CreateTriangleMesh(ms); staticActor = PhysxPhysicWorld.Physix.CreateRigidStatic(worldTransformation.AsPhysX()); TriangleMeshGeometry TriangleMeshGeometry = new TriangleMeshGeometry(triangleMesh,new MeshScale(scale.AsPhysX(),Quaternion.Identity)); material = PhysxPhysicWorld.Physix.CreateMaterial(MaterialDescription.StaticFriction, MaterialDescription.DynamicFriction, MaterialDescription.Bounciness); aTriMeshShape = staticActor.CreateShape(TriangleMeshGeometry, material, localTransformation.AsPhysX()); this.Scale = scale; }
public PhysxPhysicObject(Scene scene, Geometry geometry, float mass, Matrix localTransformation, Matrix worldTransformation, Vector3 scale, MaterialDescription MaterialDescription) { Scale = scale; rigidActor = scene.Physics.CreateRigidDynamic(worldTransformation.AsPhysX()); material = scene.Physics.CreateMaterial(MaterialDescription.StaticFriction, MaterialDescription.DynamicFriction, MaterialDescription.Bounciness); var boxShape = rigidActor.CreateShape(geometry, material, localTransformation.AsPhysX()); rigidActor.SetMassAndUpdateInertia(mass); }
public static void WriteTrianglemesh(this NetOutgoingMessage mes, String objectName, Vector3 pos, Matrix oro, Vector3 scale, MaterialDescription MaterialDescription) { mes.Write(objectName); mes.Write(pos); mes.WriteRotation(Quaternion.CreateFromRotationMatrix(oro)); mes.Write(scale); mes.Write(MaterialDescription.Bounciness); mes.Write(MaterialDescription.DynamicFriction); mes.Write(MaterialDescription.StaticFriction); }
public static void WriteSphere(this NetOutgoingMessage message, Vector3 pos, float radius, float mass, float scale, MaterialDescription MaterialDescription) { message.Write(pos); message.Write(radius); message.Write(mass); message.Write(scale); message.Write(MaterialDescription.Bounciness); message.Write(MaterialDescription.DynamicFriction); message.Write(MaterialDescription.StaticFriction); }
public PhysxTriangleMesh(PhysxPhysicWorld PhysxPhysicWorld, FileStream FileStream, Microsoft.Xna.Framework.Matrix localTransformation, Microsoft.Xna.Framework.Matrix worldTransformation, Microsoft.Xna.Framework.Vector3 scale, MaterialDescription MaterialDescription) { TriangleMesh triangleMesh = PhysxPhysicWorld.Physix.CreateTriangleMesh(FileStream); staticActor = PhysxPhysicWorld.Physix.CreateRigidStatic(worldTransformation.AsPhysX()); TriangleMeshGeometry TriangleMeshGeometry = new TriangleMeshGeometry(triangleMesh, new MeshScale(scale.AsPhysX(), Quaternion.Identity)); material = PhysxPhysicWorld.Physix.CreateMaterial(MaterialDescription.StaticFriction, MaterialDescription.DynamicFriction, MaterialDescription.Bounciness); aTriMeshShape = staticActor.CreateShape(TriangleMeshGeometry, material, localTransformation.AsPhysX()); this.Scale = scale; }
public PhysxStaticActor(PhysxPhysicWorld PhysxPhysicWorld ,Geometry geometry, Microsoft.Xna.Framework.Matrix localTransformation, Microsoft.Xna.Framework.Matrix worldTransformation, Microsoft.Xna.Framework.Vector3 scale, MaterialDescription MaterialDescription) { staticActor = PhysxPhysicWorld.Physix.CreateRigidStatic(worldTransformation.AsPhysX()); material = PhysxPhysicWorld.Physix.CreateMaterial(MaterialDescription.StaticFriction, MaterialDescription.DynamicFriction, MaterialDescription.Bounciness); Shape aTriMeshShape = staticActor.CreateShape(geometry, material, localTransformation.AsPhysX()); }
/// <summary> /// Initializes a new instance of the <see cref="PhysxTriangleMesh"/> class. /// For cooked Models /// </summary> /// <param name="PhysxPhysicWorld">The physx physic world.</param> /// <param name="FileStream">The file stream.</param> /// <param name="localTransformation">The local transformation.</param> /// <param name="worldTransformation">The world transformation.</param> /// <param name="scale">The scale.</param> /// <param name="MaterialDescription">The material description.</param> public PhysxTriangleMesh(PhysxPhysicWorld PhysxPhysicWorld, FileStream FileStream, Microsoft.Xna.Framework.Matrix localTransformation, Microsoft.Xna.Framework.Matrix worldTransformation, Microsoft.Xna.Framework.Vector3 scale, MaterialDescription MaterialDescription) { TriangleMesh triangleMesh = PhysxPhysicWorld.Core.CreateTriangleMesh(FileStream); TriangleMeshShapeDescription bunnyShapeDesc = new TriangleMeshShapeDescription(); bunnyShapeDesc.TriangleMesh = triangleMesh; BodyDescription bodyDesc = new BodyDescription(); ActorDesc.Shapes.Add(bunnyShapeDesc); ActorDesc.BodyDescription = bodyDesc; this.Scale = scale; }
/// <summary> /// Sets the material description. /// </summary> /// <param name="materialDescription">The material description.</param> public void SetMaterialDescription(MaterialDescription materialDescription) { this.materialDecription = materialDescription; terrain.Material = new BEPUphysics.Materials.Material(materialDescription.StaticFriction, materialDescription.DynamicFriction, materialDescription.Bounciness); }
public TerrainObject(GraphicFactory gfactory, Vector3 translation, Matrix rotation, float[,] heights, MaterialDescription materialDesc,BEPUphysics.CollisionShapes.QuadTriangleOrganization triangleorientation = BEPUphysics.CollisionShapes.QuadTriangleOrganization.BottomLeftUpperRight ) { terrainWidth = heights.GetLength(0); terrainHeight = heights.GetLength(1); //Create the terrain. BEPUphysics.CollisionShapes.TerrainShape shape = new BEPUphysics.CollisionShapes.TerrainShape(heights, triangleorientation); terrain = new Terrain(shape, new BEPUphysics.MathExtensions.AffineTransform(Vector3.One, Quaternion.CreateFromRotationMatrix(rotation), translation)); terrain.ImproveBoundaryBehavior = true; SetMaterialDescription(materialDesc); }
/// <summary> /// Create a Terrain Physic Object /// </summary> /// <param name="gfactory">The gfactory.</param> /// <param name="heighmapName">Name of the heighmap texture</param> /// <param name="translation">The translation.</param> /// <param name="rotation">The rotation.</param> /// <param name="materialDesc">The material desc.</param> /// <param name="XSpacing">The X spacing.</param> /// <param name="ZSpacing">The Z spacing.</param> /// <param name="heightMultipler">Default 10 - controla a altura, menor mais alto</param> public TerrainObject(GraphicFactory gfactory, String heighmapName, Vector3 translation, Matrix? rotation = null, MaterialDescription materialDesc = null, float XSpacing = 1, float ZSpacing = 1, float heightMultipler = 10) { if (!rotation.HasValue) rotation = Matrix.Identity; if (materialDecription == null) materialDecription = MaterialDescription.DefaultBepuMaterial(); //Used to calculate ther proportion of the xNormalized in the getHeightFast method xScale = XSpacing; zScale = ZSpacing; this.heightMultipler = heightMultipler; this.image = heighmapName; sourceImage = gfactory.GetTexture2D(image); int xLength = sourceImage.Width; int yLength = sourceImage.Height; terrainWidth = xLength; terrainHeight = yLength; this.rotation = rotation.Value; //this.scale = scale; Color[] colorData = new Color[xLength * yLength]; sourceImage.GetData<Color>(colorData); var heightStore = new float[xLength, yLength]; for (int i = 0; i < xLength; i++) { for (int j = 0; j < yLength; j++) { Color color = colorData[j * xLength + i]; heightStore[i, j] = (color.R) / heightMultipler; if (heightStore[i, j] > maxHeight) { maxHeight = heightStore[i, j]; } if (heightStore[i, j] < minHeight) { minHeight = heightStore[i, j]; } } } //Create the terrain. BEPUphysics.CollisionShapes.TerrainShape shape = new BEPUphysics.CollisionShapes.TerrainShape(heightStore, BEPUphysics.CollisionShapes.QuadTriangleOrganization.BottomLeftUpperRight); terrain = new Terrain(shape, new BEPUphysics.MathExtensions.AffineTransform(new Vector3(XSpacing, 1, ZSpacing), Quaternion.CreateFromRotationMatrix(rotation.Value), new Vector3(-xLength * XSpacing / 2, 0, -yLength * ZSpacing / 2) + translation)); terrain.ImproveBoundaryBehavior = true; SetMaterialDescription(materialDesc); }
public static IObject[] CreateOBJ(IWorld world, GraphicFactory factory, GraphicInfo ginfo, ObjectInformation[] mi) { IModelo model = new CustomModel(factory, mi); MaterialDescription material; if (mi[0].staticfriction == -1 || mi[0].dinamicfriction == -1 || mi[0].ellasticity == -1) { material = MaterialDescription.DefaultBepuMaterial(); } else { material = new MaterialDescription(mi[0].staticfriction, mi[0].dinamicfriction, mi[0].ellasticity); } IPhysicObject po; bool massflag = false; if (mi[0].mass == 0) { massflag = true; mi[0].mass = 0.5f; } BatchInformation binf = model.GetBatchInformation(0)[0]; BoundingBox bb; switch (mi[0].collisionType) { case "Ghost": po = new GhostObject(mi[0].position,Matrix.CreateFromQuaternion(mi[0].rotation), mi[0].scale); break; case "Cylinder": binf.ModelLocalTransformation = Matrix.Identity; bb = ModelBuilderHelper.CreateBoundingBoxFromModel(binf); Vector3 len = bb.Max - bb.Min; po = new CylinderObject(mi[0].position, len.Y, len.X / 2,Vector3.Up ,mi[0].mass, Matrix.CreateFromQuaternion(mi[0].rotation), material); break; case "Sphere": binf.ModelLocalTransformation = Matrix.Identity; po = new SphereObject(mi[0].position, model.GetModelRadius(), mi[0].mass, mi[0].scale.X, material); po.Rotation = Matrix.CreateFromQuaternion(mi[0].rotation); break; case "Box": bb = ModelBuilderHelper.CreateBoundingBoxFromModel(binf); len = bb.Max - bb.Min; po = new BoxObject(mi[0].position, len.X, len.Y, len.Z, mi[0].mass, mi[0].scale, Matrix.CreateFromQuaternion(mi[0].rotation), material); break; case "Water": po = new GhostObject(mi[0].position, Matrix.CreateFromQuaternion(mi[0].rotation), mi[0].scale); break; case "TriangleMesh": default: po = new TriangleMeshObject(model, Vector3.Zero, Matrix.Identity, new Vector3(1), material); break; } po.isMotionLess = massflag; IShader shader = null; #if !REACH && !WINDOWS_PHONE if (mi[0].HasTexture(TextureType.ENVIRONMENT)) { shader = new DeferredEMReflectiveShader(); (shader as DeferredEMReflectiveShader).TextureCube = mi[0].textureInformation.getCubeTexture(TextureType.ENVIRONMENT); } else if (mi[0].collisionType != null && mi[0].collisionType.Contains("Water")) { Vector3 position = (Vector3)(mi[0].extra["position"]); var width = (mi[0].extra["width"]); var height = (mi[0].extra["length"]); shader = new DeferredWaterCompleteShader((int)width,(int)height, new Plane(position.X, position.Y, position.Z, 1),10.0f); } else { shader = new DeferredCustomShader(mi[0].HasTexture(TextureType.GLOW), mi[0].HasTexture(TextureType.BUMP), mi[0].HasTexture(TextureType.SPECULAR), mi[0].HasTexture(TextureType.PARALAX)); } DeferredMaterial dm = new DeferredMaterial(shader); #else shader = new ForwardXNABasicShader(); ForwardMaterial dm = new ForwardMaterial(shader); #endif IObject ob = new IObject(dm, model, po); ob.Name = mi[0].modelName; return new IObject[] { ob }; }
public static MaterialDescription DefaultPhysxMaterial() { MaterialDescription md = new MaterialDescription(0.7f,0.7f,0.1f); return md; }
/// <summary> /// Defaults the bepu material. /// </summary> /// <returns></returns> public static MaterialDescription DefaultBepuMaterial() { MaterialDescription md = new MaterialDescription(BEPUphysics.Materials.MaterialManager.DefaultStaticFriction, BEPUphysics.Materials.MaterialManager.DefaultKineticFriction, BEPUphysics.Materials.MaterialManager.DefaultBounciness); return md; }