Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No easy way to clone COLLADA models #59

Open
statico opened this issue Jan 16, 2012 · 2 comments
Open

No easy way to clone COLLADA models #59

statico opened this issue Jan 16, 2012 · 2 comments

Comments

@statico
Copy link
Contributor

statico commented Jan 16, 2012

If I include a COLLADA model in my XML, say the rubber duckie sample:

<collada document="duck.dae" /> 

There doesn't seem to be a way of adding an arbitrary number of ducks to the scene graph.

I've tried creating a new GLGE.Object and setting its mesh and materials, but calling doc.getElement on the document's onLoad handler results in a GLGE.Collada object that is uninitialized -- it's missing the xml property and its children array is empty.

@statico
Copy link
Contributor Author

statico commented Jan 16, 2012

I found that GLGE.Collada supports callbacks when finished. This might work:

  var assetFinished = (function() {
    var NUM_ASSETS = 2;
    var count = 0;
    return function() {
      if (++count == NUM_ASSETS) init();
    };
  })();

  var duck = new GLGE.Collada();
  duck.setDocument('assets/duck.dae', null, assetFinished);

  doc = new GLGE.Document();
  doc.onLoad = assetFinished;
  doc.parseScript('scene-xml');

  function init() {
    var renderer = new GLGE.Renderer($('canvas')[0]);
    ...
  }

@statico
Copy link
Contributor Author

statico commented Jan 16, 2012

Yep, my custom asset loader works. I also have this function:

    function createDuckie() {
      if (!duck.xml) throw new Error("Collada model not loaded");
      var source = duck.getObjects()[0]; // Ew.
      var dest = new GLGE.Object();
      dest.setScale(0.01);
      dest.setRotX(Math.PI / 2);
      dest.setRotY(Math.random() * 2 * Math.PI);
      dest.setMesh(source.getMesh());
      dest.setMaterial(source.getMaterial());
      return dest;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant