xeokit / xeokit-sdk

Open source JavaScript SDK for viewing high-detail, full-precision 3D BIM and AEC models in the Web browser.
https://xeokit.io
Other
728 stars 288 forks source link

Rotate an GLTF after loading it. #1067

Closed antoniohof closed 1 year ago

antoniohof commented 1 year ago

Hi, I'm trying to rotate an .gltf after loading it, but can't find the proper way to do it.

I can only load it using the GLTFLoaderPlugin, is there a way to get a Mesh when loading with GLTFLoaderPlugin?

When I try to load it using the parseGLTFIntoXKTModel, it gives out a texture error: "Basis Universal Supercompressed GPU Texture encoder Error"

Is this the right way?


`utils.loadArraybuffer(this.url, async (gltf) => {
        const xktModel = new XKTModel();

        parseGLTFIntoXKTModel({
          data: gltf,
          xktModel,
          log: (msg) => {
            console.log('log', msg);
          },
        }).then(
          () => {
            console.log('model loaded!', xktModel);
            xktModel.finalize();

            const buffer = writeXKTModelToArrayBuffer(xktModel);

            const xktLoader = new XKTLoaderPlugin(viewer);

            const modelNode = xktLoader.load({
              id: 'myModel',
              xkt: buffer,
            });
            modelNode.on('loaded', (loaded) => {
              console.log('xkt loaded', loaded);
              resolve(viewer.scene.models.myModel);
            });
          }
brunokunace commented 1 year ago

@xeolabs have any way to rotate this gltf loaded?

I can change the position with (not best way):


    model.entityList.forEach((entity) => {
      entity.offset = [curPosition.x, curPosition.y, curPosition.z];
    });
xeolabs commented 1 year ago

This feature is coming in the next release, but is now pre-released in the latest alpha release on npm.

We have some low-level examples here, where we update position and rotation properties on the SceneModel, which do what you need: