SVG library doesn't display files exported by flash and inkscape

Hello i have a problem with svg library, to be truthful it’s quite bad since object created in flash (not complicated only one layer) and edit in inkscape (when flash exports or read graphic data its adds many nodes (anchors) from 10 it become 25-30 so i just removed that additional and some minor editing) is not rendered by library (basically i add dump function that exist in library to see whats wrong with object and it shows only one path object with most of value as nan - to be precise trace command shows, and one thing it’s only for object modified in inkscape, the non modifed svg object from flash shows only groups without any contents(one group inside second).

So i tried the object created from scratch in inkscape so draw two “curves” and one line with pen tool saved and tried to load in openfl. For legacy mode the line isn’t drawn but i believe since it’s older version of library it might not support, but for next mode line is drawn, but two curves are closed (and in svg they weren’t) so basically i suspect that library by default try to close paths, and to be truthful i don’t see any documentation regarding svg so can’t say what version of svg library render properly (or which software create a properly rendered files).

To be truthful what i need is path since i thought about creating morphable 2d characters so basically i need to know parameters of path to modify them and create from them MovieClip which I swap with template. This way i can get animation for every kind of characters without needing to create different animation for different characters.

1 Like

If what you need is the path coordinates, you can try getting the data with an XML parser. Just remember to stick to simple files, or you’ll make this a lot harder than it already is.

var characterXml:Xml = Xml.parse(Assets.getText("Character.svg"));
var character:Fast = new Fast(characterXml.firstElement());
character = character.node.svg;

var pathParser:Ereg = ~/([MLHVCSQTAZ]) ?(\d+ ?)*/i;

for(element in character.elements) {
    trace(element.name);
    if(element.name == "line") {
         trace(element.att.x1);
         trace(element.att.y1);
         trace(element.att.x2);
         trace(element.att.y2);
    } else if(element.name == "path") {
        var path:String = element.att.d;
        while(pathParser.match(path)) {
            var command:String = pathParser.matched(1);
            var coordinateStrings:Array<String> = pathParser.matched(2).split(" ");
            var coordinates:Array<Float> = [for(c in coordinateStrings) Std.parseFloat(c)];
            
            if(command == "Q" || command == "q") {
                trace("Quadratic curve: " + coordinates);
                if(command == "q") trace("(Using relative coordinates)");
            } else if(command == "C" || command == "c") {
                trace("Cubic curve: " + coordinates);
                if(command == "c") trace("(Using relative coordinates)");
            }
        }
    }
}

For reference.

Hmm thanks for answer although to be truthful i make my own importer from flash path, so this idea isn’t alien to me (although to be truthful i like the method you use to fill coordinates i never knew that in haxe we can write something like that). It seems that i need to build my own path object and give them methods that export to path data (either for MC or SVG), i previously planned to have only a wrapper class over graphic object but since there is no other idea besides loading manually from svg so it’s better to use my own class and apply morphs inside.

Also one thing is inkscape available to save text files?? I basically to export files (or to be precise only paths) in xml file where i can add custom attributes to nodes??

See the page on array comprehension. Check out the other language features while you’re at it; there might be something else you missed.

Well, Inkscape saves SVG files, and those are text files. You can open them with any text editor.

thanks to be truthful i didn’t read documentation for haxe since the language is so similar to others (and to be truthful currently i have a time which i reserved to create morphs for flash animations (basically want to check if it will be really an easy task to change body parts without making character animations ugly or without too many calculation involved (and here why i export to svg since in flash it’s exports me data with additional nodes and without any display system i can’t say which nodes and how much i need to change, and it’s add additional data so i believe few longer paths are better than more shorter paths from render side (but to be truthful i don’t know yet how library implement drawing vector paths so i might be wrong).
As for svg yes i know it’s a basically xml file so i can read with text but i plan game to be highly moddable (my example is civ 5) so either i would export from inkscape in my own format then let people to modify it with notepad or create some visual tool that it will help with it (and since it require more work for something that i don’t know if i would be able use in game i would prefer first method and wait until i have something like alpha of game, where i can start think about adding content to game as easy as possible).

In Flash, you can use the subselection tool (A) to look at the nodes defining each curve, and you can use Optimize Shape (Modify -> Shape -> Optimize) to cut down on the extra nodes that Flash adds whenever you use the selection tool (V).

And just for the record, you’re right that a small number of long paths are better than a larger number of short paths, though there may not be a whole lot of difference.