no8fear / jsc3d

Automatically exported from code.google.com/p/jsc3d
0 stars 0 forks source link

Update rotation #89

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Example:
viewer.setParameter('SceneUrl', 'ex1.obj');
viewer.setParameter('InitRotationX', 45);
viewer.setParameter('InitRotationY', 45);
viewer.setParameter('InitRotationZ', 45);

then
viewer.replaceSceneFromUrl('ex2.obj');
viewer.update(true);

How to set new rotation x,y,z of ex2.obj?

Original issue reported on code.google.com by fabien...@gmail.com on 31 Jul 2014 at 9:48

GoogleCodeExporter commented 9 years ago
oh, I setParameter again then init & update. It's work

Original comment by fabien...@gmail.com on 31 Jul 2014 at 10:11

GoogleCodeExporter commented 9 years ago
Don't do that. A viewer instance should not be initialized a second time. The 
viewer.rotate() method 
http://jsc3d.googlecode.com/svn/trunk/jsc3d/docs/symbols/JSC3D.Viewer.html#rotat
e is provided for this purpose. Call viewer.rotate(), passing in the rotation 
angles and it will be ok.

Original comment by Humu2...@gmail.com on 31 Jul 2014 at 11:05

GoogleCodeExporter commented 9 years ago
I tried rotate but it not work 

var canvas = document.getElementById('cv');
var viewer = new JSC3D.Viewer(canvas);
viewer.setParameter('SceneUrl', 'bank/Western_Bank.obj');
viewer.setParameter('InitRotationX', 0);
viewer.setParameter('InitRotationY', 0);
viewer.setParameter('InitRotationZ', 0);
viewer.setParameter('ModelColor', '#CAA618');
viewer.setParameter('BackgroundColor1', '#E5D7BA');
viewer.setParameter('BackgroundColor2', '#383840');
viewer.setParameter('RenderMode', 'textureflat');
viewer.setParameter('MipMapping', 'on');
viewer.setParameter('Renderer', 'webgl');
viewer.init();
viewer.update();
$('#change-obj').click(function(){
    viewer.replaceSceneFromUrl('bank/Western_Bank_2.obj');
    viewer.rotate(45,45,45);
    viewer.update();
})

if no replaceSceneFromUrl => it work & each click obj model rotate 45 45 45.
I want new obj model (replaceSceneFromUrl) has rotate only 45 45 45. I try 
setParameter again then init & update. It's work

Original comment by fabien...@gmail.com on 1 Aug 2014 at 1:25

GoogleCodeExporter commented 9 years ago
viewer.rotate() makes incremental rotations. I guess you should save the 
current rotation angles before call of viewer.replaceSceneFromUrl() and then 
restore them using viewer.rotate().

Original comment by Humu2...@gmail.com on 1 Aug 2014 at 2:05

GoogleCodeExporter commented 9 years ago
I set:
viewer.setParameter('SceneUrl', 'bank/Western_Bank.obj');
viewer.setParameter('InitRotationX', 0);
viewer.setParameter('InitRotationY', 0);
viewer.setParameter('InitRotationZ', 0);
$('#change-obj').click(function(){
        var rotationAngles = viewer.getRotationAngles();

    viewer.replaceSceneFromUrl('bank/Western_Bank_2.obj');
    viewer.rotate(rotationAngles[0],rotationAngles[1],rotationAngles[2]);
    viewer.update();
})

but not work. Rotation is 0 0 0 although I rotation objModel to new rotation
I set:

$('#change-obj').click(function(){
        var rotationAngles = viewer.getRotationAngles();

    viewer.replaceSceneFromUrl('bank/Western_Bank_2.obj');
    viewer.setParameter('InitRotationX', rotationAngles[0]);
        viewer.setParameter('InitRotationY', rotationAngles[1]);
        viewer.setParameter('InitRotationZ', rotationAngles[2]);
        viewer.init();
        viewer.update(false);
})

It't work

Original comment by fabien...@gmail.com on 1 Aug 2014 at 2:15

GoogleCodeExporter commented 9 years ago
I'm afraid you forget the loading is asynchronous. When you call 
viewer.replaceSceneFromUrl(), it won't be done immediately. The correct method 
is to utilize the callback mechanism, overriding viewer.onloadingcomplete 
(http://jsc3d.googlecode.com/svn/trunk/jsc3d/docs/symbols/JSC3D.Viewer.html#onlo
adingcomplete) to defer the rotation until the new model is loaded suceessfully:

  viewer.replaceSceneFromUrl(...);
  viewer.onloadingcomplete = function() {
    viewer.rotate(...);
    viewer.update();
  };

That's it.

Original comment by Humu2...@gmail.com on 1 Aug 2014 at 3:19

GoogleCodeExporter commented 9 years ago
Yes. Thank you. Rotation it work. But each click, it makes INCREMENTAL 
rotations. 
How to reset this to 0 0 0 then resume rotate with rotation current?

Original comment by fabien...@gmail.com on 1 Aug 2014 at 3:28

GoogleCodeExporter commented 9 years ago
Because I set
viewer.setParameter('InitRotationX', 45);
viewer.setParameter('InitRotationY', 45);
viewer.setParameter('InitRotationZ', 30);
not 0 0 0 => each click, objModel will INCREMENTAL rotation, not resume

Original comment by fabien...@gmail.com on 1 Aug 2014 at 3:34

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I see. Try to add this new function to jsc3d.js and use it instead of rotate() 
then:

  JSC3D.Viewer.prototype.setRotations = function(rotX, rotY, rotZ) {
    this.rotMatrix.identity();
    this.rotMatrix.rotateAboutXAxis(rotX);
    this.rotMatrix.rotateAboutYAxis(rotY);
    this.rotMatrix.rotateAboutZAxis(rotZ);
  };

It resets the rotation matrix and apply the given rotations on an identity one.

Original comment by Humu2...@gmail.com on 1 Aug 2014 at 9:55

GoogleCodeExporter commented 9 years ago
Thank you so much. It's work very well

Original comment by fabien...@gmail.com on 2 Aug 2014 at 4:55

GoogleCodeExporter commented 9 years ago
Hello,
I am new at jsc3d, can you show me how to set to the fixed position on click 
event, when the object is at any axis.
I mean to say, when click event is trigger it should bring to (0,0,0) with 
slight animated motion.

Please with some detailed example as I am in learning phase.

Thanks in advance

Original comment by ruchir.k...@gmail.com on 19 Feb 2015 at 7:20