Exemplo n.º 1
0
        /// <summary>
        /// Creates a new dynamic MobileMesh.
        /// </summary>
        /// <param name="vertices">Vertices in the mesh.</param>
        /// <param name="indices">Indices of the mesh.</param>
        /// <param name="localTransform">Affine transform to apply to the vertices.</param>
        /// <param name="solidity">Solidity/sidedness of the mesh.  "Solid" is only permitted if the mesh is closed.</param>
        /// <param name="mass">Mass of the mesh.</param>
        public MobileMesh(Vector3[] vertices, int[] indices, AffineTransform localTransform,
                          MobileMeshSolidity solidity, float mass)
        {
            Vector3         center;
            MobileMeshShape shape = new MobileMeshShape(vertices, indices, localTransform, solidity, out center);

            Initialize(new MobileMeshCollidable(shape), mass);
            Position = center;
        }
Exemplo n.º 2
0
        ///<summary>
        /// Constructs a new mobile mesh shape from cached data.
        ///</summary>
        ///<param name="meshData">Mesh data reprsenting the shape. Should already be properly centered.</param>
        /// <param name="hullVertices">Outer hull vertices of the mobile mesh shape used to quickly compute the bounding box.</param>
        ///<param name="solidity">Solidity state of the shape.</param>
        /// <param name="sidednessWhenSolid">Triangle sidedness to use when the shape is solid.</param>
        /// <param name="collisionMargin">Collision margin used to expand the mesh triangles.</param>
        /// <param name="volumeDescription">Description of the volume and its distribution in the shape. Assumed to be correct; no processing or validation is performed.</param>
        public MobileMeshShape(TransformableMeshData meshData, IList <Vector3> hullVertices, MobileMeshSolidity solidity, TriangleSidedness sidednessWhenSolid, Fix64 collisionMargin, EntityShapeVolumeDescription volumeDescription)
        {
            triangleMesh        = new TriangleMesh(meshData);
            this.hullVertices   = new RawList <Vector3>(hullVertices);
            meshCollisionMargin = collisionMargin;
            this.solidity       = solidity;
            SidednessWhenSolid  = sidednessWhenSolid;

            UpdateEntityShapeVolume(volumeDescription);
        }
Exemplo n.º 3
0
        ///<summary>
        /// Constructs a new mobile mesh shape.
        ///</summary>
        ///<param name="vertices">Vertices of the mesh.</param>
        ///<param name="indices">Indices of the mesh.</param>
        ///<param name="localTransform">Local transform to apply to the shape.</param>
        ///<param name="solidity">Solidity state of the shape.</param>
        public MobileMeshShape(System.Numerics.Vector3[] vertices, int[] indices, AffineTransform localTransform, MobileMeshSolidity solidity)
        {
            this.solidity = solidity;
            var data = new TransformableMeshData(vertices, indices, localTransform);
            var shapeDistributionInformation = ComputeVolumeDistribution(data);
            data.worldTransform.Translation -= shapeDistributionInformation.Center;

            triangleMesh = new TriangleMesh(data);

            UpdateEntityShapeVolume(new EntityShapeVolumeDescription { Volume = shapeDistributionInformation.Volume, VolumeDistribution = shapeDistributionInformation.VolumeDistribution });

            ComputeSolidSidedness();

            UpdateSurfaceVertices();
        }
Exemplo n.º 4
0
        ///<summary>
        /// Constructs a new mobile mesh shape.
        ///</summary>
        ///<param name="vertices">Vertices of the mesh.</param>
        ///<param name="indices">Indices of the mesh.</param>
        ///<param name="localTransform">Local transform to apply to the shape.</param>
        ///<param name="solidity">Solidity state of the shape.</param>
        public MobileMeshShape(Vector3[] vertices, int[] indices, AffineTransform localTransform, MobileMeshSolidity solidity)
        {
            this.solidity = solidity;
            var data = new TransformableMeshData(vertices, indices, localTransform);
            ShapeDistributionInformation distributionInfo;
            ComputeShapeInformation(data, out distributionInfo);

            for (int i = 0; i < surfaceVertices.Count; i++)
            {
                Vector3.Subtract(ref surfaceVertices.Elements[i], ref distributionInfo.Center, out surfaceVertices.Elements[i]);
            }
            triangleMesh = new TriangleMesh(data);

            ComputeSolidSidedness();
        }
Exemplo n.º 5
0
        ///<summary>
        /// Constructs a new mobile mesh shape.
        ///</summary>
        ///<param name="vertices">Vertices of the mesh.</param>
        ///<param name="indices">Indices of the mesh.</param>
        ///<param name="localTransform">Local transform to apply to the shape.</param>
        ///<param name="solidity">Solidity state of the shape.</param>
        ///<param name="distributionInfo">Information computed about the shape during construction.</param>
        public MobileMeshShape(Vector3[] vertices, int[] indices, AffineTransform localTransform, MobileMeshSolidity solidity, out ShapeDistributionInformation distributionInfo)
        {
            this.solidity = solidity;
            var data = new TransformableMeshData(vertices, indices, localTransform);

            ComputeShapeInformation(data, out distributionInfo);

            for (int i = 0; i < surfaceVertices.count; i++)
            {
                Vector3.Subtract(ref surfaceVertices.Elements[i], ref distributionInfo.Center, out surfaceVertices.Elements[i]);
            }
            triangleMesh = new TriangleMesh(data);

            ComputeSolidSidedness();
            //ComputeBoundingHull();
        }
Exemplo n.º 6
0
        ///<summary>
        /// Constructs a new mobile mesh shape.
        ///</summary>
        ///<param name="vertices">Vertices of the mesh.</param>
        ///<param name="indices">Indices of the mesh.</param>
        ///<param name="localTransform">Local transform to apply to the shape.</param>
        ///<param name="solidity">Solidity state of the shape.</param>
        public MobileMeshShape(Vector3[] vertices, int[] indices, AffineTransform localTransform, MobileMeshSolidity solidity)
        {
            this.solidity = solidity;
            var data = new TransformableMeshData(vertices, indices, localTransform);
            var shapeDistributionInformation = ComputeVolumeDistribution(data);

            data.worldTransform.Translation -= shapeDistributionInformation.Center;

            triangleMesh = new TriangleMesh(data);

            UpdateEntityShapeVolume(new EntityShapeVolumeDescription {
                Volume = shapeDistributionInformation.Volume, VolumeDistribution = shapeDistributionInformation.VolumeDistribution
            });

            ComputeSolidSidedness();

            UpdateSurfaceVertices();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MobileMeshObject "/> class.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="pos">The pos.</param>
        /// <param name="rotation">The rotation.</param>
        /// <param name="scale">The scale.</param>
        /// <param name="materialDescription">The material description.</param>
        /// <param name="MobileMeshSolidity">The mobile mesh solidity.</param>
        /// <param name="mass">The mass.</param>
        public MobileMeshObject(IModelo model, Vector3 pos, Matrix? rotation = null, Vector3? scale = null, MaterialDescription materialDescription = null,MobileMeshSolidity MobileMeshSolidity = MobileMeshSolidity.Solid,float mass = 10)
        {
            if (materialDescription == null)
                materialDescription = MaterialDescription.DefaultBepuMaterial();

            if (!rotation.HasValue)
                rotation = Matrix.Identity;

            if (!scale.HasValue)
                scale = Vector3.One;


            System.Diagnostics.Debug.Assert(scale != Vector3.Zero);
            System.Diagnostics.Debug.Assert(model != null);
            
            this.scale = scale.Value;            
            Vector3[] vertices = null;
            int[] indices = null;
            ExtractData(ref vertices, ref indices, model);
            triangleGroup = new MobileMesh(vertices, indices, new AffineTransform(scale.Value, Quaternion.CreateFromRotationMatrix(rotation.Value), pos), MobileMeshSolidity,mass);        
            triangleGroup.Material = new BEPUphysics.Materials.Material(materialDescription.StaticFriction, materialDescription.DynamicFriction, materialDescription.Bounciness);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MobileMeshObject "/> class.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="pos">The pos.</param>
        /// <param name="rotation">The rotation.</param>
        /// <param name="scale">The scale.</param>
        /// <param name="materialDescription">The material description.</param>
        /// <param name="MobileMeshSolidity">The mobile mesh solidity.</param>
        /// <param name="mass">The mass.</param>
        public MobileMeshObject(IModelo model, Vector3 pos, Matrix?rotation = null, Vector3?scale = null, MaterialDescription materialDescription = null, MobileMeshSolidity MobileMeshSolidity = MobileMeshSolidity.Solid, float mass = 10)
        {
            if (materialDescription == null)
            {
                materialDescription = MaterialDescription.DefaultBepuMaterial();
            }

            if (!rotation.HasValue)
            {
                rotation = Matrix.Identity;
            }

            if (!scale.HasValue)
            {
                scale = Vector3.One;
            }


            System.Diagnostics.Debug.Assert(scale != Vector3.Zero);
            System.Diagnostics.Debug.Assert(model != null);

            this.scale = scale.Value;
            Vector3[] vertices = null;
            int[]     indices  = null;
            ExtractData(ref vertices, ref indices, model);
            triangleGroup          = new MobileMesh(vertices, indices, new AffineTransform(scale.Value, Quaternion.CreateFromRotationMatrix(rotation.Value), pos), MobileMeshSolidity, mass);
            triangleGroup.Material = new BEPUphysics.Materials.Material(materialDescription.StaticFriction, materialDescription.DynamicFriction, materialDescription.Bounciness);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates a new dynamic MobileMesh.
        /// </summary>
        /// <param name="vertices">Vertices in the mesh.</param>
        /// <param name="indices">Indices of the mesh.</param>
        /// <param name="localTransform">Affine transform to apply to the vertices.</param>
        /// <param name="solidity">Solidity/sidedness of the mesh.  "Solid" is only permitted if the mesh is closed.</param>
        /// <param name="mass">Mass of the mesh.</param>
        public MobileMesh(Vector3[] vertices, int[] indices, AffineTransform localTransform, MobileMeshSolidity solidity, float mass)
        {
            ShapeDistributionInformation info;
            var       shape = new MobileMeshShape(vertices, indices, localTransform, solidity, out info);
            Matrix3X3 inertia;

            Matrix3X3.Multiply(ref info.VolumeDistribution, mass * InertiaHelper.InertiaTensorScale, out inertia);
            Initialize(new MobileMeshCollidable(shape), mass, inertia, info.Volume);
            Position = info.Center;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Creates a new kinematic MobileMesh.
        /// </summary>
        /// <param name="vertices">Vertices in the mesh.</param>
        /// <param name="indices">Indices of the mesh.</param>
        /// <param name="localTransform">Affine transform to apply to the vertices.</param>
        /// <param name="solidity">Solidity/sidedness of the mesh.  "Solid" is only permitted if the mesh is closed.</param>
        public MobileMesh(Vector3[] vertices, int[] indices, AffineTransform localTransform, MobileMeshSolidity solidity)
        {
            ShapeDistributionInformation info;
            var shape = new MobileMeshShape(vertices, indices, localTransform, solidity, out info);

            Initialize(new MobileMeshCollidable(shape));
            Position = info.Center;
        }
Exemplo n.º 11
0
        ///<summary>
        /// Constructs a new mobile mesh shape from cached data.
        ///</summary>
        ///<param name="meshData">Mesh data reprsenting the shape. Should already be properly centered.</param>
        /// <param name="hullVertices">Outer hull vertices of the mobile mesh shape used to quickly compute the bounding box.</param>
        ///<param name="solidity">Solidity state of the shape.</param>
        /// <param name="sidednessWhenSolid">Triangle sidedness to use when the shape is solid.</param>
        /// <param name="collisionMargin">Collision margin used to expand the mesh triangles.</param>
        /// <param name="volumeDescription">Description of the volume and its distribution in the shape. Assumed to be correct; no processing or validation is performed.</param>
        public MobileMeshShape(TransformableMeshData meshData, IList<Vector3> hullVertices, MobileMeshSolidity solidity, TriangleSidedness sidednessWhenSolid, float collisionMargin, EntityShapeVolumeDescription volumeDescription)
        {
            triangleMesh = new TriangleMesh(meshData);
            this.hullVertices = new RawList<Vector3>(hullVertices);
            meshCollisionMargin = collisionMargin;
            this.solidity = solidity;
            SidednessWhenSolid = sidednessWhenSolid;

            UpdateEntityShapeVolume(volumeDescription);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Creates a new kinematic MobileMesh.
        /// </summary>
        /// <param name="vertices">Vertices in the mesh.</param>
        /// <param name="indices">Indices of the mesh.</param>
        /// <param name="localTransform">Affine transform to apply to the vertices.</param>
        /// <param name="solidity">Solidity/sidedness of the mesh.  "Solid" is only permitted if the mesh is closed.</param>
        public MobileMesh(System.Numerics.Vector3[] vertices, int[] indices, AffineTransform localTransform, MobileMeshSolidity solidity)
        {
            System.Numerics.Vector3 center;
            var shape = new MobileMeshShape(vertices, indices, localTransform, solidity, out center);

            Initialize(new MobileMeshCollidable(shape));
            Position = center;
        }