This project has moved. For the latest updates, please go here.

Split fixture into 2 shapes

Topics: Developer Forum
Jan 5, 2013 at 10:20 PM

I'm using a texture to generate the ground for a game I'm working on.  the ground is generated fine but the issue is I'm using AssetCreator.TextureFromShape method to create a texture for my shapes. the problem is some of the shapes are bigger than 2048.  Is there a way to break large shapes to make them smaller?  code below.



 groundTexture = contentManager.Load("Levels/T1");
            uint[] data = new uint[groundTexture.Width * groundTexture.Height];
            Vertices textureVertices = PolygonTools.CreatePolygon(data, groundTexture.Width, true);
            Vector2 centroid = -textureVertices.GetCentroid();
            textureVertices.Translate(ref centroid);
            _origin = -centroid;
            textureVertices = SimplifyTools.ReduceByDistance(textureVertices, 1f);
            List list = new List();
            list = BayazitDecomposer.ConvexPartition(textureVertices);
            float scale = groundscale;
            Vector2 vertScale = new Vector2(ConvertUnits.ToSimUnits(1)) * scale;

            foreach (Vertices vertices in list)
                vertices.Scale(ref vertScale);

            _ground = BodyFactory.CreateCompoundPolygon(World, list, 1f, _origin);
            _ground.BodyType = BodyType.Static;
            _ground.Position = ConvertUnits.ToSimUnits(groundpos);
            _ground.Friction = 0.3f;
            _ground.IsStatic = true;
            _ground.Mass = 1;

            _ground.GetTransform(out xform);

            foreach (Fixture fixture in _ground.FixtureList)
                PolygonShape poly = fixture.Shape as PolygonShape;
\\this is where I need to break the shape

                Vector2 lBound = new Vector2(float.MaxValue);
                AABB bounds;
                poly.ComputeAABB(out bounds, ref xform, 0);
                Vector2.Min(ref lBound, ref bounds.LowerBound, out lBound);
                groundsprites.Add(new Sprite(assets.TextureFromShape(poly, MaterialType.Pavement, Color.White, 1f), ConvertUnits.ToDisplayUnits(_ground.Position - lBound) + new Vector2(1f)));