2

I'm trying to make a little scene for viewing 3D models.

I modified the GLGE Collada example to add a .dae model from code.

http://goleztrol.nl/SO/GLGE/01/

What I've got
So far it works. The camera is rotated using an animation.

Using the buttons 'Add' and 'Remove' the model is added and removed from the scene, using the following code (Don't mind 'duck'. It was a duck in the original example.)

var duck = null;
function addDuck()
{
    if (duck) return;
    duck = new GLGE.Collada();

    doc.getElement("mainscene").addCollada(duck);

    duck.setId("duck");
    duck.setDocument("amyrose.dae");
    duck.setLocY(-15);
    duck.setRotX(1);
    duck.setScale(2);
}

function removeDuck()
{
    if (!duck) return;
    doc.getElement("mainscene").removeChild(duck);
    duck = null;
}

Problem
Now the model is lying down, while it should stand up. The various methods of the element seem to work. The location is set, and the scale is set, but the call to setRotX seems to be ignored. I tried various others methods from the api, but setRotY, setRot, setQuatX and setDRotX all seem to fail. I don't get any errors (well not about this method). I tried values of 1.57 (which should be about 90 degrees), but other values as well, ranging from 1 to 180.

I can't find out what I'm doing wrong. Of course I could rotate the model itself in Blender, but I'd like to do it using the GLGE API.

Update
When I load the demo-model, seymourplane_triangulate.dae, the rotation works. Apparently my model differs in that it cannot be rotated. I just don't understand why. I figured it may be because the model is built of various separate meshes, but I don't understand why scaling and moving does work.

Does anyone know what's wrong with this model, and what I could do to fix it (maybe using Blender)?

Setting an initial rotation in the XML file that contains the scene does work. Setting rotation on another element (like the whole scene) works as well.

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
  • Update: Tried various things, amongst which loading the `Seymour Plane` model. It does get rotated, but it doesn't load its skin when I load it like this. Apparently there's quite a difference between AmyRose and Seymour Plane. Anyone knows how to fix it using Blender? – GolezTrol Oct 17 '11 at 22:07

1 Answers1

2

You need to rotate it after it has been loaded.

You can do this in the callback to setDocument

duck.setDocument("amyrose.dae", null, function() {
    duck.setLocY(-15);
    duck.setScale(2);
    duck.setRotX(0);
    duck.setRotY(0);
    duck.setRotZ(3);
});
Petah
  • 45,477
  • 28
  • 157
  • 213
  • Brilliant! :'D It works. I didn't ever see that setDocument had a callback. Thanks! – GolezTrol Oct 17 '11 at 22:51
  • I only noticed the callback by looking at the source code. If you have code completion in your IDE, try using the non-minified version of GLGE – Petah Oct 17 '11 at 22:56
  • Yes, I've used that and I've done some digging in the code too, but somehow I overlooked this callback. I guess I put it aside as not the problem, because I could move and size the model, and I could rotate the other model I tried as well. I feel kinda stupid now. :-/ Well, it's a lesson learnt. :) – GolezTrol Oct 17 '11 at 23:00