Is it possible to repeat image until body is fully covered?

General discussion about the R.U.B.E editor
Post Reply
Androidacct
Posts: 4
Joined: Mon Feb 03, 2014 10:23 am

Is it possible to repeat image until body is fully covered?

Post by Androidacct »

I'd like to attach images to some of your example scenes, but some of the grounds are fairly complicated. Is there an option to repeat image until body is fully covered? At the moment, the only way I can think of doing it is by creating an image of the ground before hand, importing it and then creating my own custom shape to fit image. Or I could just copy and paste the same image myself to fit body, but this would take forever on complicated shapes. Thanks.

EDIT: I believe I can create a textured mesh by querying the fixture's vertices. So far I have

Code: Select all

PolygonShape cs = (PolygonShape) rubeDef.getFixtureByName("fixture0").getShape();
	Vector2[] testVertex = new Vector2[cs.getVertexCount()];
but I don't know how to get each individual vertex. There is a method called getVertex which takes index and vertex as parameters, but it doesn't return any (void). Any ideas?
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Is it possible to repeat image until body is fully cover

Post by iforce2d »

This way:
... creating an image of the ground before hand, importing it and then creating my own custom shape to fit image
... would be the best if the image is a single unique one across the whole shape.

If the image is not a single unique one, then I guess you are meaning that it should be tiled. In that case, you could only make it fit shapes which are also built from rectangular areas that the image can match. This script might be helpful if you want to blanket a large area with tiled images: viewtopic.php?f=9&t=268 You could then position and scale the images and delete those that fall outside the shape.

If you are trying to fill a shape that is not built from rectangular areas, eg. it has diagonal edges etc. then simple tiled images will not fit the edges of that shape. You would need a much more sophisticated approach to triangulate the area of the shape and calculate the texture coordinates for each vertex. How exactly that would be done depends entirely on the rendering framework you are using and must be done in your app after loading the scene. Polygon triangulation is a pretty involved topic that you would most likely want to use an existing library for instead of coding yourself. (C++ users might find these links helpful: http://www.cs.cmu.edu/~quake/triangle.html http://code.google.com/p/poly2tri/ ) Once the triangulation has been done, the texture coordinates for each vertex can be generated by using their position in the world as s,t coordinates, scaled by some suitable value to stretch the texture to the size you want.

hm... the above paragraph assumes you would export the overall shape as a 'loop' type. If you exported it as 'polygon' type, and you select 'poly2tri' in the 'Geometry' tab of the options dialog, then the triangulation would already be done by RUBE.
Androidacct
Posts: 4
Joined: Mon Feb 03, 2014 10:23 am

Re: Is it possible to repeat image until body is fully cover

Post by Androidacct »

Hi there, thank you for such an in depth reply. I also saw your reply to my SO question and I have now managed to attach a tiled image to the ground in one of your example scenes:D
Post Reply