コード例 #1
0
        private CommonGeometry[] GetShapeGeometry(IConvexHullEngine convexHullEngine)
        {
            AABB region = AABB.GetGeometryAABB(Geometry.VerticesPosition, this);

            Vertex3Index[] verticesIndex = new Vertex3Index[Geometry.VerticesPosition.Length];

            for (int i = 0; i < Geometry.VerticesPosition.Length; i++)
            {
                verticesIndex[i] = new Vertex3Index(Geometry.VerticesPosition[i], Geometry.VerticesIdx[i].GetGlobalAdjacencyList(), i);
            }

            ConvexDecompositionEngine convexDecomposition = new ConvexDecompositionEngine(region, verticesIndex, 0.2);
            var convexShapes         = convexDecomposition.Execute().GetConvexShapeList(true);
            var ConvexShapesGeometry = new CommonGeometry[convexShapes.Count];

            for (int i = 0; i < convexShapes.Count; i++)
            {
                ConvexHullData convexHullData = convexHullEngine.GetConvexHull(convexShapes[i].Vertex3Idx.ToArray());

                var verticesIdx = Array.ConvertAll(convexHullData.Vertices, x => x.ID);
                ConvexShapesGeometry[i] = new CommonGeometry(null, convexHullData.TriangleMeshes, verticesIdx);
            }

            return(ConvexShapesGeometry);
        }
コード例 #2
0
        private List <CollisionPointStructure> SoftBodyCollisionStep(
            ISoftShape softShapeA,
            ISoftShape softShapeB)
        {
            var result = new List <CollisionPointStructure>();

            var shapeA = (IShape)softShapeA;
            var shapeB = (IShape)softShapeB;

            var convexDecompositionA = new ConvexDecompositionEngine(
                shapeA.AABBox,
                Array.ConvertAll(softShapeA.ShapePoints, item => new Vertex3Index(item.Position, item.TriangleIndex, item.ID)),
                softShapeA.DecompositionParameter);

            var convexDecompositionB = new ConvexDecompositionEngine(
                shapeB.AABBox,
                Array.ConvertAll(softShapeB.ShapePoints, item => new Vertex3Index(item.Position, item.TriangleIndex, item.ID)),
                softShapeB.DecompositionParameter);

            List <ShapeDecompositionOutput> decompConvexShapeA = convexDecompositionA.Execute().GetConvexShapeList(true);

            List <ShapeDecompositionOutput> decompConvexShapeB = convexDecompositionB.Execute().GetConvexShapeList(true);

            AABB[][] boxCollision = new AABB[2][];

            boxCollision[0] = Array.ConvertAll(decompConvexShapeA.ToArray(), x => x.Region);
            boxCollision[1] = Array.ConvertAll(decompConvexShapeB.ToArray(), x => x.Region);

            List <CollisionPair> collisionPair = broadPhaseCollisionEngine.Execute(
                boxCollision[0],
                boxCollision[1],
                parameters.CollisionDistance);

            var lockMe = new object();

            Parallel.ForEach(
                collisionPair,
                new ParallelOptions {
                MaxDegreeOfParallelism = parameters.MaxThreadNumber
            },
                pair =>
            {
                CollisionPointStructure collisionPointStruct = SoftBodyNarrowPhase(
                    decompConvexShapeA[pair.objectIndexA],
                    decompConvexShapeB[pair.objectIndexB],
                    shapeA.ID,
                    shapeB.ID);

                if (collisionPointStruct != null)
                {
                    lock (lockMe)
                    {
                        result.Add(collisionPointStruct);
                    }
                }
            });

            return(result);
        }
コード例 #3
0
        private void GenerateConvexShapes(IConvexHullEngine convexHullEngine)
        {
            AABB box = AABB.GetGeometryAABB(positions, this);

            var vertex3Idx = SetVertexAdjacency(positions, triangleMeshes);
            ConvexDecompositionEngine convexDecomposition = new ConvexDecompositionEngine(box, vertex3Idx, 0.7);

            convexShapes = convexDecomposition.Execute().GetConvexShapeList(true);
        }
コード例 #4
0
        //Manca gestione compuondShape
        private List <CollisionPointStructure> Rigid_SoftBodyCollisionDetection(
            IShape rigidShape,
            ISoftShape softShape)
        {
            var shapeSoft = (IShape)softShape;

            List <CollisionPointStructure> collisionPointStructure = new List <CollisionPointStructure>();

            ConvexDecompositionEngine convexDecomposition = new ConvexDecompositionEngine(
                shapeSoft.AABBox,
                Array.ConvertAll(softShape.ShapePoints, item => new Vertex3Index(item.Position, item.TriangleIndex, item.ID)),
                softShape.DecompositionParameter);

            List <ShapeDecompositionOutput> shapeOutput = convexDecomposition.Execute().GetIntersectedShape(
                rigidShape.AABBox,
                parameters.CollisionDistance,
                true);

            if (shapeOutput != null)
            {
                IGeometry[] convexShapeGeometry = ShapeDefinition.Helper.GetGeometry(rigidShape);

                foreach (var convexGeometry in convexShapeGeometry)
                {
                    VertexProperties[] convexVertexObj = Helper.SetVertexPosition(convexGeometry);

                    foreach (var softConvexShape in shapeOutput)
                    {
                        VertexProperties[] vertexObjSoftShape = Array.ConvertAll(softConvexShape.Vertex3Idx.ToArray(), x => new VertexProperties(x.Vector3, x.ID));

                        var cps = convexBodyNarrowPhase.Execute(convexVertexObj, vertexObjSoftShape, rigidShape.ID, shapeSoft.ID, parameters.CollisionDistance);

                        if (cps != null)
                        {
                            collisionPointStructure.Add(cps);
                        }
                    }
                }
            }

            return(collisionPointStructure);
        }