API V3 - Help to Clone node


For a new project, I need to clone several times the same object. Instead of adding several sessions in my viewer, I prefer to clone it for better repsonse time.

I found this codepen : cloning and transforming - session update - CodeSandbox

In the codepen, you use mat4 and vec3 from gl-matrix
How to reproduce this in JS code ?

Do I have to load a specific script to use GL Matrix ?

I tried to load this script :

but then mat4 is not working.
How to declare mat4 and vec3 variables?

Many Thanks

mat4 is simply an array of 16 numbers (column-major matrix representation), vec3 is an array of 3 numbers.

If you do not want to use the gl-matrix package, you can also use Matrix4 of three.js.
The Matrix4.toArray function gives a column-major matrix representation like mat4.

Thanks !
I’ll try and let you know


1 Like

Here is hte solution to use the GL Matrix script if someone want to

  1. Register the script

  2. On top of your JS, declare the variables

const { mat4, quat, vec3 } = glMatrix
  1. Use them in your code
    id: "transformation",
    matrix: mat4.fromRotationTranslation(
      quat.fromValues(0, 0, 0.7071068, 0.7071068),
      vec3.fromValues(0, 50, 0)