Defold Polygon Editor

Awesome that you are using the Def-Diags library, makes me happy! :slight_smile: I’ll look into the Linux support as soon as we have support for it in native extensions. I know the library I use has Linux support, so hopefully it shouldn’t be too hard.

4 Likes

@Oleg_The_Evangelist Haha. Hey, it’s only 7:30 AM here! It’ll get there.

@sven Having native dialogs makes me pretty happy too! It’s so awesome. Yeah, I saw that the library has Linux support, which is great. I decided to go ahead with it, figuring it would only be temporary breakage. Thanks for making the native extension!

1 Like

Hey @ross.grams, you should add this to the Asset Portal!

6 Likes

Oof, how the heck has it been 25 days?!

It’s up! https://www.defold.com/community/projects/58981/

9 Likes

You’re a god. Game ideas are pouring out my brain because of this. Thank you XD. Ill probably use this sometime in the future after getting comfortable with using Defold.

5 Likes

@ross.grams hey! thanks for your editor!
any idea how to add the polygon figure with internal angles? like this? split into 3 figures?
image

Yeah, that would have to be split up. All shapes must be convex like a ball “( )”. Any concave shapes, like the inside of a bowl " ) ( ", doesn’t work for collision.

4 Likes

Yep, what Mattias said. But if you want to create a dynamic collision object with that shape, as far as I know it is not possible. Polygons are treated differently from other collision shapes, and you can only use one per collision object. If you want a static, kinematic, or trigger body this shouldn’t be a big problem (you just add multiple collision object components), but with dynamic bodies each component will be a separate object, so you can’t have multiple polygons “welded” together. You can use one polygon and multiple “normal” collision shapes though.

2 Likes

@Mattias_Hedberg , @ross.grams okay, understand. thanks!

Finally used this in a project. I may have a pull request in the future with some new features…

I highly recommend people use this tool if they need shapes which they are tempted to make from combining multiple premade collision shapes together. Previously on a project I was using a box and a circle to make a pill like shape, and had some bugs for a while I didn’t know the cause. Turns out it was the box shape’s corners causing the bugs. Instead making a water tight custom shape with this tool fixed the issues.

5 Likes

Would this shape ever be possible, even if breaking it up into multiple collision shapes?

In Box2D a chain shape would work, because those don’t have the limitations of bodies made up of polygon shapes. Are chain shapes supported by Defold? I’m guessing not.

Maybe a Tile Map could be used instead?

You can make any shape you want if you break it up into pieces. This tool is really, really simple and doesn’t do that for you though. Depending on how precise you want it, you could probably do this with 4 shapes. Though if you want to use it for a dynamic body, as far as I know Defold doesn’t let you have multiple polygons on a single Collision Object, so you can’t really make dynamic bodies with multiple polygons.

Tile Maps only do convex collision as well, though if you split this up over multiple tiles, that -might- be easier than using polygons. I’m not sure how well that would work, but it’s worth a try.

3 Likes

For this project it looks like Tile Map is out:

17

The result is a bit too uneven and unpredictable. Maybe a different approach entirely is the way to go, by somehow calculating the y collision of the character. The mechanic is similar to Tiny Wings and those types of games.

2 Likes

Ah, yeah. For that kind of game I think a more mathematical approach would be better. Use a Bezier curve and do the math for a body on an inclined plane yourself.


[Edit] Actually, the physics part would only be a few lines of code. The trickier parts would be:

  1. Find a good Bezier curve Lua library and figure out how to use it, (or write one yourself…).
  2. Get the slope of the curve at the X-position of your character.
  3. Figure out how to draw the ground to match the curve. (put the Bezier math into a shader and stretch/skew a texture to fit?)
2 Likes

Would be cool if the editor could automatically divide and generate sets of ready to use collision shapes for concave bodies maybe even with a go with all of the shapes defined too. Anyone out there could add support for this…

Doesn’t have to be automatic, could add cut ability between points and then mark the remaining concave subshapes.

2 Likes

Alternatively, load a JSON file spat out by RUBE! It divides shapes into separate convex fixtures automatically.

1 Like

Can’t RUBE export custom formats?

Yeah, this solution sounds like a can of worms (to me). I was hoping to be able to stick to standard Defold objects, so I can visualise it in the amazing IDE. Trying the “many collisions shapes” idea now, praying it will be good enough. :slight_smile:

It can export to JSON or C code.

Ok lovely people, I’ve created a VERY rudimentary bridge between RUBE and Defold. Maybe this could be useful for reference when integrating a more robust polygon support in Defold, or maybe even offer RUBE support.

First, a video of the result:

This uses collision data from a RUBE JSON file:
test.json.zip (1.3 KB)

I wrote a small Lua script to extract the data and print it in the right format:

    local data = sys.load_resource("/json/test.json")
	local data_table = json.decode(data)
	local bodies = data_table.body

	for b=1, #bodies do
		
		local body = bodies[b]
		local fixtures = body.fixture

		for f=1, #fixtures do

			print( "shape_type: TYPE_HULL" )
			
			local fixture = fixtures[f]
			local polygon = fixture.polygon
			local vertices = polygon.vertices
			local xs = vertices.x
			local ys = vertices.y
			
			for v=1, #xs do

				local x = xs[v]
				local y = ys[v]
				print( "data: ", x )
				print( "data: ", y )
				print( "data: 0.0" )	
							
			end

			print()
			
		end

	end

Then I added the 15 (!) collision shapes to the game object, each file containing a convex polygon, making up the final concave polygon:

Now I need a coffee.

The test project zipped: PolygonTest.zip (75.6 KB)

13 Likes

Well-deserved, amazing work :raised_hands:

3 Likes