Vector Graphics

No idea, I know nothing about all this.

JSON would give me a head start simply because Corona already has a JSON importer.

What I’d probably do is start with the JSON just to check I can do what is needed, then expand it to use SVG if possible, as I have the feeling you are almost certainly right about SVG being a better format.

OK I made a start on this, and I’ve got stuff showing, but…

What the heck is happening with the polygon placement? If I create a polygon with values all around 7000, I do not expect to see it sitting at the origin :s

I understand they go through the painful (to me) process of normalising the polygon so it has the anchor at the middle (another reason I am really beginning to hate anchors), but they should at least then offset the X and Y by the amount so, you know, it appears where the points were set, at least :s

Anyway I expect this to only be a small delay, but it is a frustrating thing. I know I read this elsewhere on the forums, so I’m not the only one finding this behaviour unhelpful, to say the least.

Righto got some placement working right, and I’m going to store all the bounding areas of each shape I create so you can see roughly where it all ended up, in case you create it but you can’t see it.

The face demo I’ve got importing ok, and should look a lot better when I have in bezier subdivision.

The icecream one for now produces a long list of errors saying it can’t create the polygons due to holes or self-intersection, then produces a segment fault and crashes the simulator. I seem to be rather good at doing that lately :slight_smile:

I do have some ideas on what might be the problem in that respect, but it’d be useful to know if the icecream does indeed have any holes in it, as that seems to be a (reasonable) limitation of newPolygon(). I think not, from the image, but can’t hurt to double check.

I had a look at the Ice-Cream vector graphic in CS6, and there are some open paths with a stroke+fill.

The Cherry has two open paths, and one part of the cone are some that I could find.

Would that be the problem?

Not sure but likely. I could close them up if I find them, but we’ll have to see.

I’ve got the face drawing correctly, at least. Subdivision for the bezier is hard-coded, but you’d likely want this to be based on length of the line segments etc, but that’ll be for another day.

Time to see what happens with the icecream now I know the code roughly works :slight_smile:

Yup ice cream crashes. I imagine the open ends don’t help.

I’ll try removing bits to see what, if anything, I can get to draw to find the culprits by a process of elimination.

OK I’ve got ice cream not crashing.

It was down to the fact that some of the shapes are only a single line, and newPolygon won’t accept only 2 points.

So I’ve caught this and it creates a newLine() instead.

Some bits are still wrong, and I think it may not be possible to sort absolutely everything, but I’ll play a bit more and then post the code so others can see what they make of it.

:smiley:

It seems to me there are a few types of errors:

1 - Open ended shapes or shapes with holes - these simply fail

2 - Certain types of curving polygons. I’ve not been able to locate these exactly, but on the ice cream, the criss-cross patterns go wrong. I’m also seeing a weird error in the outline of the cone.

3 - The higher I set the bezier subdivision the more likely there are to be errors.

Images:

Face:

http://i.imgur.com/xkcOaVB.png

This is fine now.

Ice cream:

http://i.imgur.com/RZNur7V.png

http://i.imgur.com/13ZF0rr.png

http://i.imgur.com/DV1yTly.png

As you can see, I can generate various types of different errors by tweaking my code, and most things look ok in at least one pic, but I haven’t found a way of making them all work.

At this point I think it is a combination of the open objects, but also how I start an object’s path - the 3 pics show differences when I do or do not include these first points, either for lines or for curves.

And here is the source:

https://github.com/Rakoonic/Vector-Importer

It displays both the face and the icecream. I left the settings as they are to work best with the face image, as I think it gives us the best starting place for the icecream weirdness.

What I think I need to do is determine if a shape is open or closed.

There should be a way to do it from the data given (likely some sort of combination of do first / last points match, or how many entries there are in the shape - if just one then is open, dunno).

However, I should have been in bed 5 hours ago, so it’ll have to wait!

One question I have is what the code would look like in Corona to convert an imported json file into a shape. Is this something that can be done with Starter or do I need to have Pro?

I won’t, unfortunately, be able to justify upgrading to Pro until I’ve seen some sales from my apps… Too bad there isn’t a way to use Pro for free until you’ve had a certain number of sales (1000 or something like that). Perhaps that’s too complicated but it would encourage more developers to experiment with the added features.

You can see exactly what the code looks like as I posted it above on github.

I don’t believe Graphics 2.0 will be Pro or Enterprise only as it aims to be the backbone of all graphics-based operations in the future - eventually leading G1 to be retired.

It seems there is a basic incompatibility in abilities between illustrator and graphics 2.0.

It isn’t a crashing thing, but does mean you get undesired drawing.

It seems that if you supply an open polygon with a fill and border, then this wiil be drawn wrong.

In Illustrator what would happen is that it would draw the fill as if the shape was closed (adds an extra line from the start to the end point of shape), but draws borders only around the supplied edges (so the open area won’t have a line).

In graphics 2.0, a polygon must be closed. In fact this happens automatically in the above example because in G2 you don’t add in an additional end point that matches the start point to mark it as closed. So the *fill* is fine, but in G2 the border is applied to every single edge, and this means you will get unwanted extras.

You have a choice really then on how to render open bordered polygons:

  1. You draw them filled and with the border on every side, or

  2. You draw them unfilled and with the borders correct

Ideally of course, you’d not use this sort of shape.

The problem with icecream? It contains both :slight_smile:

I should also point out I’m getting a much different set of strokewidths from the icecream image - values seem to be much lower than the exported image would imply, so I’m adding in a scalar to see what ‘feels’ right.

Rakoonic - first of all - Wow you did it! I’m sitting here amazed at the possibilities of what could be achieved with vector graphics in Corona. If you think about it, apps could be made with no bitmaps so they would be extremely small files. I guess they would also use very little texture memory? I s’pose the overhead is in the actual memory given what it would take to render a relatively detailed image in code?

I have to confess to having limited coding skills so looking at your work I feel a bit like a jawa trying to use a light saber… better left to the jedis like yourself :)  But… if I make changes to face.json - will your code draw those too?

btw - just got Runtime error - attempt to call ‘newPolygon’ (a nil value’) - polygons.lua123: in function ‘loadJSON’ using latest build on a PC… First time I’ve run code with Graphics 2.0 so I may have something else still turned off…?

I should also point out that using JSON, gradients don’t get exported.

@kilopop - I’ve not tried on the PC - what daily version are you using (I’m running 2013 here).

Also, I’m about to upload a new version anyway once I get a few more tweaks sorted.

Note there’s very little error checking, so it is likely easy to create an invalid shape or make the JSON file invalid (although in this case it should simply not do anything).

One thing I’ve done through laziness is the inheritence. It does mean that I can’t use a display group as the actual object (as the metatable stuff screws up). I’ll rewrite it to do a different method so that the returned new ‘object’ is actually a display group containing the new vector image.