Giter Site home page Giter Site logo

Resource Management about webvs HOT 4 CLOSED

grandchild avatar grandchild commented on July 21, 2024
Resource Management

from webvs.

Comments (4)

azeem avatar azeem commented on July 21, 2024

Image resources are currently loaded with 'new Image()' object and setting the 'src'. This has multiple nice consequences

  1. Images can be loaded from any web resource asynchronously with URLs. Have to check out cross-origin policies on this, im guessing you can load files from anywhere, the same way we can embed img tags from any location.
  2. We can use base64 encoded data. instead of a url we can just provide the raw data directly in the css "mimetpye+base64" format. This means the image binary can be included in the preset json itself. This i think allows the preset-internal resources that you mention

As for global resources im including a Resources object (https://github.com/azeem/webvs/blob/1.1dev/src/Resources.js) that contains common resources. If the present json mentions a key in the Resources object instead of a URL or Base64 data then its loaded from the Resources object (check texer example https://github.com/azeem/webvs/blob/1.1dev/examples/PilloFight.html).

As for packs, i agree with you, it makes limited sense. But if anyone wants to package Webvs the library with preset packs then registering pack level resources is as simple as adding more data into Webvs.Resources object. This can even be done at runtime without touching the library code.

from webvs.

QOAL avatar QOAL commented on July 21, 2024

How about a media object in the root of the preset.
Taking the form of "media": {"fileName":"data/url"}
It would contain any embedded media and urls pointing to either standalone media or packs of media.
I think media packs would compliment WebVS packs (if we get to such a thing), its sympathetic to AVS installers.
They (media packs) would probably better suited to having base64 encoded entries only, to reduce http requests.
localstorage could be optionally used to cache fetched media.

The media could then be added to Webvs.Resources as azeem wrote about above.

The only downside of allowing external stuff is

  • This is the internet, things go down and disappear
  • Cross domain security policies (Not a problem with CORS)

So when converting presets, I guess it would be best to convert them a pack at a time, and generate a media pack for the pack (ignoring Tug's texer resource files)

Also I converted all (85) of Tug's texer resources to base64/pngs: https://github.com/QOAL/qios-webvseditor/blob/master/avsres.js

from webvs.

azeem avatar azeem commented on July 21, 2024

I like the "media": {"fileName":"data/url"} idea. if a file is being used multiple times (like texer image for example) then this can avoid repetition.

I agree with you on external files. Its not much of an advantage when you can just robustly embed the image as base64 data itself. Its just a nice addon that comes for free since loading of images work the same in either case. Going further, if there are other non-image types of binary resources that we might want to use then embedding seems to be the cleaner way to go.

from webvs.

azeem avatar azeem commented on July 21, 2024

I have added a ResourceManager system (https://github.com/azeem/webvs/blob/1.2dev/src/ResourceManager.js) that (hopefully) addresses some of the issues discussed in this thread and here: #13

So here is how it works right now.

  • ResourceManager maintains a map between filenames and URI (could be URL or data URI)
  • In the JSON, for individual effects, the resources will be specified only by filenames
  • When a resource is required by an effect, it asks the ResourceManager, which then looks up the URI and loads the resource.

Now, there are different ways to setup this filename to URI map in the resource manager

  1. From the preset JSON. a resources field in the root eg:

    "resources": { 
      "uris": {
        "abc.png": "http://example.com/abc.png",
        "def.bmp": "data:image/png;base64;..."
      }
    }
    
  2. Programatically. by calling registerUri on ResourceManager. UIs can use this. When preset JSON's are generated later with a getPreset call, the resources field is automatically added

  3. Builtin resource packs. This is just a bunch of default files that the Webvs library user is expected to put at a fixed location.

  4. And may be later from External resource packs.

from webvs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.