Is it possible to scale a mesh with the API?


(Pierre Savoie) #1

From this example, I can see that you can move a specific mesh around.
Sketchfab Game

Would it be possible to also scale up the mesh? After each gem taken, the sphere would grow in size.
If yes, could the transformation be fluid? A ease-in style instead of just snapping to the specific size.


Maybe you can scale with setMatrix ?

(Pierre Savoie) #3

Do you have any example that use the function setMatrix? I have yet to know how it work.
The Viewer Api documentation says :

We recommend the use of glmatrix for matrix operations.

How do I go about using this?


I have yet to use this. @shaderbytes have you done anything with setMatrix ?

(Shaderbytes) #5

no i have not tested scaling, i have tested using glmatrix but only for translation and rotation.

if you imported the glmatric class you can work with it creating you vectors and other matrix manipulation, you can pass this matrix into the setMatrix function of your api without hastle it is a flattened array in the same order as the api uses/.

(Shaderbytes) #6

also i doubt it would be smooth as each call to setMatrix requires some network action it is not local to the viewer instance.

(Pierre Savoie) #7

Hmm, thanks for the quick answer. I'll continue to look to see if I could figure a workaround.

(Madalin Berechet) #8

Example here: change scale on X, Y, and Z

  1. Use Model Inspector to see what node you'll scale.
    Paste your model urlid in the link above.
  2. Detect the MatrixTransform nodes and build an array indexed by name.
  3. Use mat4 to apply the scale
  4. Use api.setMatrix() for the node

The problem is that the node UV's won't be recalculated after the scaling process. The texture will appear deformed.
You need to build a multi UV channel geometry (node) and set the right channel for each scale.

Programatically change UV channel

The important lines on all that example, are:

materialToUpdate.channels.DiffusePBR.texture.texCoordUnit = channel;
            api.setMaterial(materialToUpdate, function () {

As the Map Channels are predefined for a loaded model - you can't create them "on the fly" - you won't be able to set a perfect mapped texture for each scale. But you can use intervals e.g. UV0 for scale between 0 and 1, UV1 for scale between 1 and 2 and so.

I'm interested in finding out if Boolean operations can be applied to the nodes (geometries) using glmatrix.


Cool, thanks for the samples!

The node IDs aren't necessarily permanent, so checking them in the Inspector might not be future proof. It's probably best to get the node programmatically by checking for its name.

(Madalin Berechet) #10

I believe it's important to see the structure (hierarchy). Groups may exist and we only want to scale a component. I'm interested in knowing if there are other approaches.