povdocs / webvr-starter-kit

Other
298 stars 59 forks source link

Loading an object #13

Open sirkitree opened 9 years ago

sirkitree commented 9 years ago

This library is really great, thank you so much!

I'm wondering if you have an example of loading an object (.obj) file and material with it. There doesn't seem to be any out of the box functionality to do that, so would you still need to use Three's OBJLoader?

It'd be really useful to be able to do something like:

VR.load({
  path: 'path-to-obj-file'
});
sirkitree commented 9 years ago

I wrote up some code to see how this might look. Here's a prototype:

/**
 * objLocation should be the http location of the file without the extension.
 * we will automatically assume that an obj file and an mtl file are present.
 * ex: https://raw.githubusercontent.com/bitgridio/models/gh-pages/lullabot/Body
 */
var loadObjMtl = function(objLocation) {
  var loader = new THREE.OBJMTLLoader(manager)
  loader.load(
    objLocation + '.obj',
    objLocation + '.mtl',
    function(obj) {
      console.log(obj)
      VR.scene.add(obj)
    },
    function(xhr) {
      console.log(xhr.loaded + ' bytes loaded')
    },
    function(xhr) {
      console.log('Error loading object')
    }
  )
}

loadObjMtl('https://raw.githubusercontent.com/bitgridio/models/gh-pages/lullabot/Body')
loadObjMtl('https://raw.githubusercontent.com/bitgridio/models/gh-pages/lullabot/Headd')

If you think something like this would be a good addition to this library, let me know and I'll look at your source and see what might be a good way to implement it as a VR.prototype or something.

brianchirls commented 9 years ago

This is a good idea. I'll see if I can whip something up. There are a couple things I need to think about though...

  1. Is there a good place for people to host obj files if they don't have their own servers? Need CORS headers.
  2. What's the best way to design the API to allow for multiple object formats?
  3. How many different object formats do we need to support? Each one comes at a cost of making the script file a bit larger.
sirkitree commented 9 years ago

Not sure about the first two, but for the third I'd suggests starting with .obj (these can have multiple textures though so not sure that my approach in assuming .mtl is going to pan out), .dae (collada), .fbx?

brianchirls commented 9 years ago

I think I will start with obj since it seems to be the most popular. Collada is also popular, but I think the files are quite large and slow to parse. So they're not great for deployment on the web.

I've put off building this because everything else about the library is meant to be as self-contained as possible, for people who may not have easy access to their own servers. jsbin is fine for hosting prototype code; imgur.com is good at hosting images. But I haven't found a good place to store video, audio or 3d models. So it's unlikely this feature will be used by some beginners. I would like to find a way to solve that problem. I'm open to suggestions...

brianchirls commented 9 years ago

...might be cool to build a github repo full of open source models, kind of like npm or homebrew. They could be served by github pages, or maybe someone will donate CDN space. Could be a fair bit of work to dig up the models and make sure they're in usable formats at consistent scales and with working materials/textures.

What do you think?

sirkitree commented 9 years ago

I help run http://vrsites.com/ where we do some hosting of models and rooms for http://janusvr.com/. The goal of that site is to help teach people to make JanusVR rooms and provide some basic hosting capabilities. Might be an option to point people to, but I do prefer putting things up on GitHub cuz they're so damned fast.

brianchirls commented 9 years ago

I'm kind of excited about this idea. I'm gonna run it by some folks at Mozilla Festival this weekend. What if I set up an empty repo with notes and some issues for discussion? Would you be interested in participating at least in some ideas of how to put it together, or possibly contributing code and/or models?

sirkitree commented 9 years ago

Yes, I certainly would.