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.

1 Like

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

This makes the rotation happens from the middle point of object as centre point, I’m trying to achieve the door rotation, so rotation should should happen from the right corner middle, as a centre point right?? How to achieve that, I even tried setting the object anchor point to right middle corner in the blender, still this config.rotate is happening from middle point, not right corner middle

There is currently no way to do this directly in Shapespark.

There is one workaround for this. You can place an object (something simple as a box) with its center exactly in a place where you want your pivot (this dummy object has to be fully covering the object you want to rotate, i.e. the object you want to rotate has to be fully inside the dummy object) and then link it as the parent object for the one that you actually want to rotate. Before baking, please make sure that you enable isolate shadows for the parent object and then turn off visibility in all the views or make it transparent. You can also set custom lightmap resolution for this object to 0, so it won’t waste lightmap’s space.

If you do this, then rotating of the dummy parent object will rotate also the object you want to rotate along the pivot of the dummy object.

You can see on the image below how I am forcing the rotation of the monkey face around a different point by using a bigger box (with red color and semi-transparent material to illustrate the situation better) and then both the box (that is the parent of the monkey face) and the monkey face will rotate around the center.