Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Student Project, SVG, advice appreciated

Discussion in 'General Discussion' started by InsanityStricken, Nov 21, 2014.

  1. InsanityStricken

    InsanityStricken

    Joined:
    Oct 30, 2012
    Posts:
    2
    Details aside for the moment, we're a team of six students and we have to build SVG vector support for Unity for a GUI. And the GUI has to be built from scratch.
    One or two of our team members (total team size of six) will be busy with another set of features we have to implement.
    And, it all has to be supported across all platforms minus Linux, including Windows Phones.

    We have until May for this to be completed, and will obviously be occupied with a number of other units as well. If anyone could offer their thoughts on the feasibility of this it'd be appreciated, especially in relation the the SVG support.

    And some tips on where to start with building SVG support would be handy. Like what sort of things we'd need to know/look into, whether there are any libraries that we can use, etc. If there were a fully open-source existing solution that'd be fine too but as far as we're aware there isn't?
     
  2. goat

    goat

    Joined:
    Aug 24, 2009
    Posts:
    5,182
    You should start with the portions of Unity UI 4.6 that have been made open source and learn it.
     
  3. R-Lindsay

    R-Lindsay

    Joined:
    Aug 9, 2014
    Posts:
    287
    If your assignment is to build SVG vector support why would an open source solution matter?

    That said, here are some thoughts:
    It's doable, but some SVG functionality will be very hard to implement with Unity free and should be skipped, like full support of layer blending, filters, probably fonts, and so on. Or at least do them after you do the easier stuff - if you still have time left over.

    So focus on the basics, which is the SVG path spec. You can refer to non SVG specific libraries for guidance in this matter (e.g. Cairo and Antigrain), but essentially everything boils down to lines, bezier curves (quadratic and cubic) and ellipses, expressed as bezier curves. All curves are flattened down to lines for rendering.
    Once the foundations are down you can start adding in support like svg shapes and a DisplayList type structure.
    You then need to stroke and fill your paths. This will require investigation into triangulation algorithms.
    From here you can add in support for gradients and other effects, possibly via shaders.

    So, initial steps (for the programmers in your team) might be something like this:
    Start by becoming familiar with The SVG path spec.
    Next, get beziers implemented with a flattening algorithm. There are two approaches here, 'fixed' algorithms, such as forward differencing, and more intelligent 'adaptive' algorithms, which are a lot more involved. For a student project, just refer to this.
    Then do ellipses (including arcs and circles). A handy reference if you plan to have such support.
    On top of this adding in shapes should be trivial.

    Now you can represent virtually any shape. Triangulate/Stroke to render them in unity. You should be able to work out the rest from there.

    Good luck

    -------

    Edit: I am assuming this is University level work. You will really struggle if this is a high school assignment.
    Also: if you are allowed to use another low level vector graphics library... well I would research the sh*t out of that method first since it will make this project far more feasible.
     
    Last edited: Nov 21, 2014
    InsanityStricken likes this.
  4. InsanityStricken

    InsanityStricken

    Joined:
    Oct 30, 2012
    Posts:
    2
    Thank you, that was a really helpful post!

    It needed to be open source in the sense that if we were to use any existing solutions, they'd have to be fully in the public domain (not quite the same I know), otherwise we wouldn't be allowed to use them due to restraints with the project.
    In answer to your question at the end, you're correct to assume it's university work. We're computer science students and one of our units involves working with a client to implement a requested specification. Unfortunately it's actually only 1/6th of the course, 20/120 credits, so the chances are that if we have to implement all of this ourselves (specification to implement a fully cross-platform, SVG graphical user interface from scratch as well as a number of other features) that we wouldn't be able to complete the project in time.
    We're looking into reducing our workload - both the unit director and our project mentor think the amount of work we're expected to do is a bit ambitious.

    There's a chance we'll lose the project if we're not able to implement all the features as requested, or that SVG support might be cut from our brief (the client is pretty keen on SVG support so I can't really see the latter happening), so I want to apologize for wasting your time if that happens - I'm nevertheless really grateful that you took the time to make such a detailed reply.

    Edit - Should say that, with any luck we'll be able to continue the project with maybe just limited support for SVG files, such as only up to the level of shapes, and some of the other features removed, in which case the advice will definitely come in handy still.
     
    Last edited: Nov 23, 2014
  5. R-Lindsay

    R-Lindsay

    Joined:
    Aug 9, 2014
    Posts:
    287
    I agree. I wouldn't assign this project to you myself. The workload is far too high for this amount of credit. If they are raising concerns now - listen to them - and make changes.

    Np, and don't worry you are not wasting my time. If you feel like it's getting too much, speak out early. Don't let the client intimidate you into promising more than your team can deliver!

    Good luck your your degrees, and your project :)
     
  6. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I think if you really want to go for good performance then you need to be looking into simply procedurally generating geometry to represent the shapes, letting the hardware deal with the shading/rendering. If you try to do a software renderer, you are severely handicapped in terms of performance and animation etc. Take a look at RageSpline as an example... somewhat vector-object-y...
     
  7. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Hmm. A full SVG solution does sound ambition. If instead you made some SVG files that represented the sort of thing you wanted your GUI to display, and then write the SVG-InsanityStricken-lite renderer for those, you'd be a long way forward quite quickly. SVG has a lot of decoration you might not need. Look at the triangle01 example near the top of the page @R.Lindsay linked - the text above it has plenty of nonsense, where you only really need the path tag data. Concentrate on the real stuff you need. (I know this is not very SVG purist.)
     
  8. Ska0s

    Ska0s

    Joined:
    Feb 4, 2014
    Posts:
    32
    As a developer of SVGAssets I can confirm you that SVG is a huge beast to deal with. To give you an idea, at Mazatech we have developed a full OpenVG 1.1 implementation (AmanithVG is the engine behind our SVG solution) in 4 year of full 8h/day x 2developers.