GLGE API setRot/setRotX doesn't work

2019-05-29 01:25发布

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.

1条回答
来,给爷笑一个
2楼-- · 2019-05-29 02:04

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);
});
查看更多
登录 后发表回答