how to create various shape object? polygonal is not enough

Hi, let’s say I have gif, similar to this one. On gif 3 objects, 3 colors (without white near the borders, imagine there’s no white on the image :wink: )

Now I’d like to make them static objects, so dynamic could interact with them (I want to throw sand at them)

Obviously polygonal shape will not work here. 

I could read pixel color under X,Y parameters, but I’m afraid it will get really slow reading pixels for dynamically falling sand.

Do you have any idea for some other approach here?

  3objects.png?dl=1

for now the best way I found is I think https://www.codeandweb.com/physicseditor

  1. Even if they work in the simulator, you can’t use GIF files for display object fills in Corona.  Just PNG or JPG.

  2. I’m not clear what this post is about:

A. Are you asking how to draw objects with arbitrary shapes?  If so your options are:

B. Are you asking how to add arbitrary physics shapes to bodies?  If so, your best bet is probably an edge-chain, but there are many many options:

  1. Oh, yes, yes, of course

  2. I have 30 images (for example) with various color and shape objects there. How can I convert it easiest/most optimal way to some corona objects?

in physics editor I don’t see option to select separate color object (like in my attached image) only whole object. So If I have image with 20 “objects”, then I’d have to cut all of them and separately import to physics editor - sounds time consuming. 

For example: I want to import some animated charater - very simply drawn - and make sand bounce from his nose, and stick to his body (under head). 

Images

I don’t know what you mean by a Corona object.

There are display objects (https://docs.coronalabs.com/api/library/display/index.html) and physics [bodies] (https://docs.coronalabs.com/api/library/physics/index.html)

To extract images from a sheet of images, you can use shoebox’s extract sprites feature: http://renderhjs.net/shoebox/

If you want to use those images as discrete display objects, time consuming or not, you’ve got to do it. 

That is of course, unless it is a proper image sheet (https://docs.coronalabs.com/api/library/graphics/newImageSheet.html) already, but your description tells/shows me it is not.

Animations

This is a different topic,l but what you describe sounds quite challenging.

Tip

I think you might want to find someone near you to work with and get up to speed.  You’re using terms a little loosely and talking about some high-level stuff.  So, it is hard to give proper help remotely via the forums.

@pajter  I admit I’m also a bit puzzled about how this will all work, especially if it’s animated. What’s the motivation for having the solid colors in the images? My best guess would be that the images double as the background, but that only makes sense if static.

Anyhow, that aside, I’ve been working on an msquares binding and this sounds like it would fit a “get color -> extract boundary -> make edge chain” approach. I was planning to make a fancy sample before submitting the plugin in maybe a week or two, but if it sounds promising I could do so in a few days with something more provisional and then spruce it up later. (Your image above actually is giving me an idea for a sample.)

If you want to get mechanics of similar to the typical “falling sand” games that simulate all kinds of pixelsized elements (fire, water, sand etc.) there’s no way to get anywhere but to do it in a per pixel level, that’s how these games are usually implemented.

Google for stuff like falling sand simulation or cellular automaton - it is actually no that hard, at least to get something nice going, but the challenge here is performance using an interpreted language and no easy way for direct bitmap access.

If your goal is something different, we really need some additional information.

I mean physics body. I was using terms loosely because I thought it’s not that important if I talk about display object or physics body - since both of them can be rectangle, circle or Polygonal body.

To be more precise: I want to simulate effect of sand falling into glue and sticking to it.

  1. One object (one color shape) in image should act like it has glue on it. I think it would be physics static body 

  2. Sand would be physics body dynamic type, falling from top

here I’m not sure if I can do that: Sand object is falling from top. First sand seed when fallen onto defined static body(1) would stop at first pixel of this body (glue). Second one would slide over previous one.

so when sand is falling every move or on collision I need to check:

a ) if sand is within static body it’s allowed to glue into

and

b ) if sand is over previously “glued” sand, if yes - let it fall down further down, if not - stick it

I’m not sure if collision detection would be enough here, but I wanted to solve first problem before moving onto how to glue sand into object.

Am I more clear now? :slight_smile:

As for http://renderhjs.net/shoebox/ goes - can’t open it on osx. Installed Adobe Air (but can’t it within /Applications/Utilities/Adobe), .air is not recognized. But it looks like not the answer, since it exports images from sprites (rectangular).

look at the image at homepage of physicseditor: https://www.codeandweb.com/physicseditor - there’s a girl running. Girl is traced - whole girl. And I’d like to traces separately hair, eyes, face, body, shoes. 

Well, actually I don’t need colors. I have them right now and I want somehow import/convert them into set of parameters for individual bodies.

After that I want to display those bodies with border around them, but that can be done in a background, sure.

wow! msquares looks very nice. I’d very much like to see what par_msquares_color_multi would return when run on one of my images. And what’s the format of your triangle meshes. Because that’s my only question if output format of triangle mesh I could import into physic bodies (and how many of them).

Week I can gladly wait, two… well, if I have to then I can too. :wink:

But if you could post some simpler example and submit plugin - that would be great. :slight_smile:

let’s consider hourglass app. Something like that is simple: https://www.youtube.com/watch?v=zsfm4xlm6cA

but this app: https://play.google.com/store/apps/details?id=com.keuwl.sandtimer has more complex curve - it’s not just 2 circle objects colliding with sand.

How can you do more complex curved lines/physic objects? Is it just not possible in corona and/or box2d?

@pajter Okay, I’ll aim for the simpler / quicker publishing schedule then.

The meshes are fairly compatible with Corona’s own, e.g. I have roughly this in the tests:

local mlist = msquares.grayscale(pixels, IMGWIDTH, IMGHEIGHT, CELLSIZE, THRESHOLD, "INVERT") local cx, cy = display.contentCenterX, display.contentCenterY for i = 1, #mlist do local mesh = mlist:GetMesh(i) local points, verts = mesh:GetPoints(), {} for i = 1, #points, mesh:GetDim() do local x, y = points[i], points[i + 1] verts[#verts + 1] = cx \* (x - .5) verts[#verts + 1] = cy \* (.5 - y) end display.newMesh(cx, cy, { indices = mesh:GetTriangles(), vertices = verts, mode = "indexed", zeroBasedIndices = true }) end

The idea your image gave me earlier would be to have a little drawing program with a small palette of colors. Then you extract each mesh, putting it into a Corona mesh with the appropriate color, then finally wipe the background. If all goes well you won’t notice, until the objects start moving…

However, the boundary seems more relevant for purposes of collision, thus the “get color -> extract boundary -> make edge chain” comment in my previous post. Adapting the example in the physics docs (untested):

local body = display.newRect( x, y, 40, 40 ) -- just some object to receive the body... body.alpha = .05 -- ...but we probably don't actually want to see it -- if you DO, say as in my idea for a sample, make a mesh in the previous step physics.addBody( body, "static", { chain = boundary[1], connectFirstAndLastChainVertex = true -- with simple shapes, just one element })

Hi.

The day of reckoning came for me last week on a plumbing problem and I didn’t get a whole lot done. Difficult to accomplish much when hammers are pounding not far away; struggling with some updated VPN settings too, so wasn’t able to do remote builds on my office Mac either.

That said, in the last couple days I did make a little headway. I’ve attached a GIF of the idea I had earlier, now a passable sample.

You can paint various color-coded “objects” and then bake them into meshes that then fly around. I also bake a mask and apply it to the canvas, though maybe I should add some underlying effect to better demonstrate this. The interface is a bit clumsy at the moment. Maybe I’ll switch the buttons around to a palette and some text or something.

Code so far here. Never mind the rest of the scenes; I copied over the structure from the last plugin I submitted.  :slight_smile:

Update: the msquares plugin is now out. I’ve revised the sample shown above and also added another one with physics. Probably further examples to follow down the road.

for now the best way I found is I think https://www.codeandweb.com/physicseditor

  1. Even if they work in the simulator, you can’t use GIF files for display object fills in Corona.  Just PNG or JPG.

  2. I’m not clear what this post is about:

A. Are you asking how to draw objects with arbitrary shapes?  If so your options are:

B. Are you asking how to add arbitrary physics shapes to bodies?  If so, your best bet is probably an edge-chain, but there are many many options:

  1. Oh, yes, yes, of course

  2. I have 30 images (for example) with various color and shape objects there. How can I convert it easiest/most optimal way to some corona objects?

in physics editor I don’t see option to select separate color object (like in my attached image) only whole object. So If I have image with 20 “objects”, then I’d have to cut all of them and separately import to physics editor - sounds time consuming. 

For example: I want to import some animated charater - very simply drawn - and make sand bounce from his nose, and stick to his body (under head). 

Images

I don’t know what you mean by a Corona object.

There are display objects (https://docs.coronalabs.com/api/library/display/index.html) and physics [bodies] (https://docs.coronalabs.com/api/library/physics/index.html)

To extract images from a sheet of images, you can use shoebox’s extract sprites feature: http://renderhjs.net/shoebox/

If you want to use those images as discrete display objects, time consuming or not, you’ve got to do it. 

That is of course, unless it is a proper image sheet (https://docs.coronalabs.com/api/library/graphics/newImageSheet.html) already, but your description tells/shows me it is not.

Animations

This is a different topic,l but what you describe sounds quite challenging.

Tip

I think you might want to find someone near you to work with and get up to speed.  You’re using terms a little loosely and talking about some high-level stuff.  So, it is hard to give proper help remotely via the forums.

@pajter  I admit I’m also a bit puzzled about how this will all work, especially if it’s animated. What’s the motivation for having the solid colors in the images? My best guess would be that the images double as the background, but that only makes sense if static.

Anyhow, that aside, I’ve been working on an msquares binding and this sounds like it would fit a “get color -> extract boundary -> make edge chain” approach. I was planning to make a fancy sample before submitting the plugin in maybe a week or two, but if it sounds promising I could do so in a few days with something more provisional and then spruce it up later. (Your image above actually is giving me an idea for a sample.)

If you want to get mechanics of similar to the typical “falling sand” games that simulate all kinds of pixelsized elements (fire, water, sand etc.) there’s no way to get anywhere but to do it in a per pixel level, that’s how these games are usually implemented.

Google for stuff like falling sand simulation or cellular automaton - it is actually no that hard, at least to get something nice going, but the challenge here is performance using an interpreted language and no easy way for direct bitmap access.

If your goal is something different, we really need some additional information.

I mean physics body. I was using terms loosely because I thought it’s not that important if I talk about display object or physics body - since both of them can be rectangle, circle or Polygonal body.

To be more precise: I want to simulate effect of sand falling into glue and sticking to it.

  1. One object (one color shape) in image should act like it has glue on it. I think it would be physics static body 

  2. Sand would be physics body dynamic type, falling from top

here I’m not sure if I can do that: Sand object is falling from top. First sand seed when fallen onto defined static body(1) would stop at first pixel of this body (glue). Second one would slide over previous one.

so when sand is falling every move or on collision I need to check:

a ) if sand is within static body it’s allowed to glue into

and

b ) if sand is over previously “glued” sand, if yes - let it fall down further down, if not - stick it

I’m not sure if collision detection would be enough here, but I wanted to solve first problem before moving onto how to glue sand into object.

Am I more clear now? :slight_smile:

As for http://renderhjs.net/shoebox/ goes - can’t open it on osx. Installed Adobe Air (but can’t it within /Applications/Utilities/Adobe), .air is not recognized. But it looks like not the answer, since it exports images from sprites (rectangular).

look at the image at homepage of physicseditor: https://www.codeandweb.com/physicseditor - there’s a girl running. Girl is traced - whole girl. And I’d like to traces separately hair, eyes, face, body, shoes. 

Well, actually I don’t need colors. I have them right now and I want somehow import/convert them into set of parameters for individual bodies.

After that I want to display those bodies with border around them, but that can be done in a background, sure.

wow! msquares looks very nice. I’d very much like to see what par_msquares_color_multi would return when run on one of my images. And what’s the format of your triangle meshes. Because that’s my only question if output format of triangle mesh I could import into physic bodies (and how many of them).

Week I can gladly wait, two… well, if I have to then I can too. :wink:

But if you could post some simpler example and submit plugin - that would be great. :slight_smile:

let’s consider hourglass app. Something like that is simple: https://www.youtube.com/watch?v=zsfm4xlm6cA

but this app: https://play.google.com/store/apps/details?id=com.keuwl.sandtimer has more complex curve - it’s not just 2 circle objects colliding with sand.

How can you do more complex curved lines/physic objects? Is it just not possible in corona and/or box2d?