Пример #1
0
 public BepuColliderShape CreateShape(BepuUtilities.Memory.BufferPool bufferPool)
 {
     return(new BepuBoxColliderShape(Size)
     {
         LocalOffset = LocalOffset, LocalRotation = LocalRotation
     });
 }
Пример #2
0
 public BepuColliderShape CreateShape(BepuUtilities.Memory.BufferPool bufferPool)
 {
     return(new BepuCylinderColliderShape(Height, Radius)
     {
         LocalOffset = LocalOffset, LocalRotation = LocalRotation
     });
 }
Пример #3
0
        internal void SetCharacterInput(BepuUtilities.Memory.BufferPool bufferpool, int bodyHandle, Simulation simulation)
        {
            characterControllers = new Demos.Demos.Characters.CharacterControllers(bufferpool);
            collider.bodyHandle  = bodyHandle;

            characterInput = new CharacterInput(characterControllers, bodyHandle, simulation, this.Position, new Capsule(0.5f, 1), 0.1f, 1, 20, 100, 6, 4, MathF.PI * 0.4f);
        }
Пример #4
0
 public BepuColliderShape CreateShape(BepuUtilities.Memory.BufferPool bufferPool)
 {
     return(new BepuSphereColliderShape(Radius)
     {
         LocalOffset = LocalOffset
     });
 }
Пример #5
0
 public BepuColliderShape CreateShape(BepuUtilities.Memory.BufferPool bufferPool)
 {
     return(new BepuCapsuleColliderShape(Radius, Length)
     {
         LocalOffset = LocalOffset, LocalRotation = LocalRotation
     });
 }
Пример #6
0
        public SceneGraph(BaseScene sceneOwner)
        {
            SceneOwner = sceneOwner;
            Actors     = new List <BaseActor>();

            bufferPool        = new BepuUtilities.Memory.BufferPool();
            physicsSimulation = BepuPhysics.Simulation.Create(bufferPool, new SceneCallbacks());
        }
Пример #7
0
        public BepuColliderShape CreateShape(BepuUtilities.Memory.BufferPool bufferPool)
        {
            if (Shape == null)
            {
                return(null);
            }

            if (Shape.Shape == null)
            {
                Shape.Shape = BepuPhysicsColliderShape.Compose(Shape.Descriptions, bufferPool);
            }

            return(Shape.Shape);
        }
Пример #8
0
        internal static BepuColliderShape CreateShape(IBepuColliderShapeDesc desc, BepuUtilities.Memory.BufferPool bufferPool)
        {
            if (desc == null)
            {
                return(null);
            }

            BepuColliderShape shape = desc.CreateShape(bufferPool);

            if (shape == null)
            {
                return(null);
            }

            //shape.UpdateLocalTransformations();
            shape.Description = desc;

            return(shape);
        }
Пример #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BepuStaticPlaneColliderShape"/> class.
        /// A static plane that is solid to infinity on one side.
        /// Several of these can be used to confine a convex space in a manner that completely prevents tunneling to the outside.
        /// The plane itself is specified with a normal and distance as is standard in mathematics.
        /// </summary>
        /// <param name="normal">The normal.</param>
        /// <param name="offset">The offset.</param>
        public BepuStaticPlaneColliderShape(Vector3 normal, float offset, BepuUtilities.Memory.BufferPool bufferPool)
        {
            this.bufferPool = bufferPool;

            Type   = ColliderShapeTypes.StaticPlane;
            Normal = normal;
            Offset = offset;

            cachedScaling = Vector3.One;

            Matrix rotationMatrix;
            var    oY = Vector3.Normalize(Normal);
            var    oZ = Vector3.Cross(Vector3.UnitX, oY);

            if (oZ.Length() > MathUtil.ZeroTolerance)
            {
                oZ.Normalize();
                var oX = Vector3.Cross(oY, oZ);
                rotationMatrix = new Matrix(
                    oX.X, oX.Y, oX.Z, 0,
                    oY.X, oY.Y, oY.Z, 0,
                    oZ.X, oZ.Y, oZ.Z, 0,
                    0, 0, 0, 1);
            }
            else
            {
                var s = Math.Sign(oY.X);
                rotationMatrix = new Matrix(
                    0, s, 0, 0,
                    s, 0, 0, 0,
                    0, 0, 1, 0,
                    0, 0, 0, 1);
            }

            var transformMatrix = Matrix.Translation(Offset * Vector3.UnitY) * rotationMatrix;

            // Infinite plane doesn't exist in Bepu!
            CreatePlane(cachedScaling, transformMatrix, bufferPool, out var planeMesh);

            InternalShape = planeMesh;

            DebugPrimitiveMatrix = transformMatrix;
        }
Пример #10
0
        public BepuConvexHullColliderShape(
            IReadOnlyList <Vector3> points, IReadOnlyList <uint> indices, Vector3 scaling, BepuUtilities.Memory.BufferPool bufferPool)
        {
            Type = ColliderShapeTypes.ConvexHull;
            //Is2D = false;

            cachedScaling = scaling;

            pointsList  = points;
            indicesList = indices;

            this.bufferPool = bufferPool;
            bufferPool.Take <System.Numerics.Vector3>(points.Count, out var vertexBuffer);
            for (int i = 0; i < vertexBuffer.Length; i++)
            {
                vertexBuffer[i] = points[i].ToNumericsVector3();
            }
            InternalShape = new ConvexHull(vertexBuffer, bufferPool, out var hullCenter);
            HullCenter    = hullCenter.ToXenkoVector3();

            DebugPrimitiveMatrix = Matrix.Scaling(Vector3.One * DebugScaling);
        }
Пример #11
0
        internal static BepuColliderShape Compose(IReadOnlyList <IBepuAssetColliderShapeDesc> descs, BepuUtilities.Memory.BufferPool bufferPool)
        {
            if (descs == null)
            {
                return(null);
            }

            BepuColliderShape res = null;

            if (descs.Count == 1) // Single shape case
            {
                res = CreateShape(descs[0], bufferPool);
                if (res == null)
                {
                    return(null);
                }
                res.IsPartOfAsset = true;
            }
            else if (descs.Count > 1) // Need a compound shape in this case
            {
                var compound = new BepuCompoundColliderShape();
                foreach (var desc in descs)
                {
                    var subShape = CreateShape(desc, bufferPool);
                    if (subShape == null)
                    {
                        continue;
                    }
                    compound.AddChildShape(subShape);
                }
                res = compound;
                res.IsPartOfAsset = true;
            }

            return(res);
        }
Пример #12
0
        public BepuColliderShape CreateShape(BepuUtilities.Memory.BufferPool bufferPool)
        {
            if (ConvexHulls == null)
            {
                return(null);
            }
            BepuColliderShape shape;

            // Optimize performance and focus on less shapes creation since this shape could be nested

            if (ConvexHulls.Count == 1)
            {
                var curMeshConvexHulls        = ConvexHulls[0];
                var curMeshConvexHullsIndices = ConvexHullsIndices[0];
                if (curMeshConvexHulls.Count == 1 && curMeshConvexHullsIndices[0].Count > 0)
                {
                    shape = new BepuConvexHullColliderShape(curMeshConvexHulls[0], curMeshConvexHullsIndices[0], Scaling, bufferPool)
                    {
                        NeedsCustomCollisionCallback = true,
                    };

                    //shape.UpdateLocalTransformations();
                    shape.Description = this;

                    return(shape);
                }

                if (curMeshConvexHulls.Count <= 1)
                {
                    return(null);
                }

                var subCompound = new BepuCompoundColliderShape
                {
                    NeedsCustomCollisionCallback = true,
                };

                for (int i = 0; i < curMeshConvexHulls.Count; i++)
                {
                    var verts   = curMeshConvexHulls[i];
                    var indices = curMeshConvexHullsIndices[i];

                    if (indices.Count == 0)
                    {
                        continue;
                    }

                    var subHull = new BepuConvexHullColliderShape(verts, indices, Scaling, bufferPool);
                    //subHull.UpdateLocalTransformations();
                    subCompound.AddChildShape(subHull);
                }

                //subCompound.UpdateLocalTransformations();
                subCompound.Description = this;

                return(subCompound);
            }

            if (ConvexHulls.Count <= 1)
            {
                return(null);
            }

            var compound = new BepuCompoundColliderShape
            {
                NeedsCustomCollisionCallback = true,
            };

            for (int i = 0; i < ConvexHulls.Count; i++)
            {
                var curMeshConvexHulls        = ConvexHulls[i];
                var curMeshConvexHullsIndices = ConvexHullsIndices[i];

                if (curMeshConvexHulls.Count == 1)
                {
                    if (curMeshConvexHullsIndices[0].Count == 0)
                    {
                        continue;
                    }

                    var subHull = new BepuConvexHullColliderShape(curMeshConvexHulls[0], curMeshConvexHullsIndices[0], Scaling, bufferPool);
                    //subHull.UpdateLocalTransformations();
                    compound.AddChildShape(subHull);
                }
                else if (curMeshConvexHulls.Count > 1)
                {
                    var subCompound = new BepuCompoundColliderShape();

                    // Loop through each hulls
                    for (int b = 0; b < curMeshConvexHulls.Count; b++)
                    {
                        var verts   = curMeshConvexHulls[b];
                        var indices = curMeshConvexHullsIndices[b];

                        if (indices.Count == 0)
                        {
                            continue;
                        }

                        var subHull = new BepuConvexHullColliderShape(verts, indices, Scaling, bufferPool);
                        //subHull.UpdateLocalTransformations();
                        subCompound.AddChildShape(subHull);
                    }

                    //subCompound.UpdateLocalTransformations();

                    compound.AddChildShape(subCompound);
                }
            }

            //compound.UpdateLocalTransformations();
            compound.Description = this;

            return(compound);
        }
Пример #13
0
 public BepuColliderShape CreateShape(BepuUtilities.Memory.BufferPool bufferPool)
 {
     return(new BepuStaticPlaneColliderShape(Normal, Offset, bufferPool));
 }