Stop Object Rotation

Hello @wojtek and @jan ,

Is there a way to stop an object from rotating by a click interaction, or through some API ?

This can open up new possibilities and can be an interesting UI response to indicate that an interaction has happened.

Thanks.

This is not a part of the public API, but if you mark a node type as editable before the scene starts to load:

var viewer = WALK.getViewer();
viewer.setNodeTypeEditable('<NODE-TYPE>');

then, after the scene is ready to display you can turn rotation for all nodes of a given type on/off by:

var node = viewer.findNodesOfType('<NODE-TYPE>')[0];
node.config.rotate = true; // false
node.config.rotationSpeed = <SPEED>;
2 Likes
 viewer.onMaterialClicked("Floor", function () {
    viewer.setNodeTypeEditable("Armchair");
    var node = viewer.findNodesOfType("Armchair")[0];
    node.config.rotate = false;
    node.config.rotationSpeed = 0.1;
  });

It works when rotated, but not when not rotated.

Add viewer.requestFrame() at the end of the callback. It triggers the animation, if the scene animation is currently in idle state (because there are no rotating objects or animated materials).

 viewer.onMaterialClicked("Stove black", function () {
    viewer.setNodeTypeEditable("Armchair");
    var node = viewer.findNodesOfType("Armchair")[0];

    if ((node.config.rotate = true)) {
      node.config.rotate = false;
    } else {
      node.config.rotate = true;
    }

    viewer.requestFrame();
  });

Is this right?
it’s not working… :sob
Only the rotating material stops.

  1. setNodeTypeEditable must be called before the scene is loaded.
  2. The if condition use wrong operator. Instead of the if use: node.config.rotate = !node.config.rotate;
1 Like

thank you so much :+1: :+1: :+1: :+1: :+1: :sob:

1 Like

If I click while rotating, I want to slow down without breaking the scene.

I am sorry, I am not sure if I understand correctly what you’d like to achieve.

When an object is clicked, would you like to slow down the rotation (but keep the object rotating)?

 viewer.onMaterialClicked("2F BLUE", function () {
    viewer.setNodeTypeEditable("Cylinder.001");
    var node = viewer.findNodesOfType("Cylinder.001")[0];
    node.config.rotationSpeed = 0.3;
    viewer.requestFrame();
  });
  viewer.onMaterialClicked("2F PINK", function () {
    viewer.setNodeTypeEditable("Cylinder.001");
    var node = viewer.findNodesOfType("Cylinder.001")[0];
    node.config.rotationSpeed = 0.1;
    viewer.requestFrame();
  });

I want to slow down while keeping the rotation smooth.

I see. There is no built-in support for rotation speed animation. You’d need to write a code that gradually decreases the rotation speed, for example using setTimer or setInterval, but I am afraid that providing you with a complete solution for this issue is out of the scope of our support.

Slowing down with the button will restart the material where it was first located. Is it possible to slow down by pressing the button while moving?

Could you write in more detail what behavior you’d like to achieve? I am not sure if I understand it correctly.

 viewer.onMaterialClicked("2F PINK", function () {
    viewer.setNodeTypeEditable("Cylinder.001");
    var node = viewer.findNodesOfType("Cylinder.001")[0];
    node.config.rotationSpeed = 0.1;
    viewer.requestFrame();
  });

The object is rotating. Click the speed control button you created, and it will go back to the beginning and rotate at the speed you set