Texture to Polygons

Jan 27, 2011 at 7:48 PM

I'm trying to make a world space filled with polygons by using a texture.  This would be much faster than the standard way.  But, I keep getting stuck on debug.assert calls within ContactSolver, and I can't test my game.


Here's my code:

public override void LoadContent()
            // Grab the texture.
            uint[] data = new uint[this.back.texture.Width * this.back.texture.Height];

            // Turn the texture into vertices.
            Vertices verts = PolygonTools.CreatePolygon(data, this.back.texture.Width, this.back.texture.Height, true);
            Vector2 scale = new Vector2(0.07f, 0.07f);
            verts.Scale(ref scale);

            // Create a fixture from the texture.
            List<Vertices> list = BayazitDecomposer.ConvexPartition(verts);

            for (int i = 0; i < list.Count; i++)
                if (list[i].Count == 0)

            this.walls = FixtureFactory.CreateCompoundPolygon(this.physWorld, list, 1);
            this.walls[0].Body.BodyType = BodyType.Dynamic;





Also: If anyone else has a fast way of level creation, please do tell.   Thanks.

Jan 27, 2011 at 8:18 PM

There are a lot of asserts in the engine. Could you tell me what line the assert is at?

If you are using XNA, then you might want to flip the y-axis to get the terrain to work properly. Take a look at the samples for a good reference.

Jan 27, 2011 at 8:29 PM

The nested for loop inside of the InitializeVelocityConstraints method of the ContactSolver class.   Lines 196 and 175.  They seem to be going back and fourth.

Jan 27, 2011 at 11:34 PM

As you are importing a texture, I can't say for sure what is going on. Could you by any chance work up a testbed sample (use the testbed from the downloads section) and replicate this assert? You can create an issue and attach the test in there. Then I will take a look at it and see what is up.

Jan 28, 2011 at 12:39 AM

Okay, I didn't try the testbed yet.  I'm not exactly sure what that is.  But, I did notice that KNormal is NaN.  Which is why the debug assert is returning false.  KNormal is NaN because RnB is NaN, whatever that is.

Jan 28, 2011 at 1:02 AM
Edited Jan 28, 2011 at 2:18 AM

Okay, I don't know what's wrong, but this isn't working at all.  I just tried the TestBed.  It would not respond to the "J" key.  Maybe I'm doing this wrong.


Okay, I played with the stupid rope joint.  What now?

Jan 28, 2011 at 1:10 AM

Not sure what you need the J key for. Is it needed to replicate your problem in the testbed?

Jan 28, 2011 at 1:40 AM

Well, then what do I to?  Because I don't know how to use the tested and there are no instructions.

Jan 28, 2011 at 1:47 AM

The testbed is a bunch of tests written to test the different parts of the engine. It is also known to be working correctly and thus, if you paste in your code as a test in the testbed, I can then narrow down the problem you are having, to the code you are using, and not some other setting you have in your game.

Here is what you do:

1. Create a new file inside the folder with all the other tests. It might be easier to copy one of the already existing tests and remove all the test code from it.
2. Make sure it inherits from Test and have a static Create() method (like the other tests)
3. Put the test at the top of the TestEntries.cs file (copy one of the already existing entries and change it)
4. Now you create the code inside the test that is causing the problem you are having.

If you can't replicate the problem in the testbed, then it is a problem in your code and not the engine.

Jan 28, 2011 at 3:12 AM

Okay, I think this is an issue with the Texture I'm using to create my levels.


I see that the texture in the TestBed has a black outline around it, and it's white in the center.  I tried to duplicate that, and replace the texture.  But, I'm getting an error with my texture.


Is there some kind of format that you guys use or something, for creating textures?  I'm saving as a .png.

Jan 28, 2011 at 11:06 AM

The format you are using does not matter. After going through the content importer it is pretty much the same regardless of your input.

As long as you are not using Texture2D.FromStream() to create them manually... in that case you have to take care of things like pre-multiplied alpha and correct color formats yourself.

What do you mean by: "getting an error with my texture."?

Could you post the texture in question somewhere?