Start a new topic

Changing 3D model

Changing 3D model

1 person has this problem


Changing 3D model or file .wt3

 

I want to scan an image and that image show me a 3D model.

When I press the button of Snap for move the model, I put two buttons more for change the model for another 3D model. But I don't find the way to apply that.

This is my try and my code: 

 

 

 

    this.modelCar = new AR.Model("model.wt3", {

      onLoaded: this.loadingStep,

      scale: {

        x: 0.0,

        y: 0.0,

        z: 0.0

      },

      translate: {

        x: 0.0,

        y: 0.05,

        z: 0.0

      },

      rotate: {

        roll: -25

      }

    });

    

    

 

 

      this.appearingAnimation = this.createAppearingAnimation(this.modelCar, 0.045);

 

      this.rotationAnimation = new AR.PropertyAnimation(this.modelCar, "rotate.roll", -25, 335, 10000);

 

      var imgRotate = new AR.ImageResource("rotateButton.png");

    this.buttonRotate = new AR.ImageDrawable(imgRotate, 0.2, {

      offsetX: 0.35,

      offsetY: 0.45,

      onClick: this.toggleAnimateModel

    });

 

      var imgSnap = new AR.ImageResource("assetsApp/snapButton.png");

    this.buttonSnap = new AR.ImageDrawable(imgSnap, 0.2, {

      offsetX: -0.35,

      offsetY: -0.45,

      onClick: this.toggleSnapping

    });

 

      var imgBtnLeft = new AR.ImageResource("btnLeft.png");

      this.buttonLeft = new AR.ImageDrawable(imgBtnLeft, 0.2, {

      offsetX: -0.60,

      offsetY: 0.0,

      onClick: this.otroObjtI

    });

 

 

      var imgBtnRight = new AR.ImageResource("btnRigth.png");

      this.buttonRight = new AR.ImageDrawable(imgBtnRigth, 0.2, {

      offsetX: 0.60,

      offsetY: 0.0,

      onClick: this.otroObjtD

    });

 

 

 

       this.img3D = new AR.Trackable2DObject(this.tracker, "auntekmin", {

      drawables: {

        cam:

      },

       snapToScreen: {

        snapContainer: document.getElementById('snapContainer')

      },

      onEnterFieldOfVision: this.appear

    });

 

 

 

This my function to each button:

 

 

  otroObjtI: function otroObjtIFn() {

 

 

 

    this.modelCar = new AR.Model("model2.wt3", {

      scale: {

        x: 0.0,

        y: 0.0,

        z: 0.0

      },

      translate: {

        x: 0.0,

        y: 0.05,

        z: 0.0

      },

      rotate: {

        roll: -25

      }

    });

 

   

  }

 

 

Can Help me?

Hi Sergio,
Assigning a new object to your member: "this.modelCar = new AR.Model("model2.wt3", {" will not work because the Wikitude SDK never knows that there is a new 3D model. You're only loosing the reference to the orginal model and can't destroy it properly anymore. 
 

What you should do is the following:
Create a new AR.Model in your 'otroObjtl' function and use the following Trackable2DObject JS API to replace the 3d model:

drawables.removeCamDrawable(this.modelCar)

drawables.addCamDrawable(myNew3dModel)

You can find more information about the JS API in our JS API reference which is available on our website and in the SDK package that you've downloaded.

Best regards

Andreas

 

Hello Andreas, I follow your example and read the Documentation and my code is:

 

 otroObjtI: function otherModel(){

 

      this.modelCar2 = new AR.Model("assetsApp/prueba.wt3", {

      scale: {

        x: 0.0,

        y: 0.0,

        z: 0.0

      },

      translate: {

        x: 0.0,

        y: 0.05,

        z: 0.0

      },

      rotate: {

        roll: -25

      }

    });

 

        World.img3D.drawables.removeCamDrawable(this.modelCar, 4);

 

 

       World.img3D.drawables.addCamDrawable(this.modelCar2);

 

 

  },

 

When I try to do this  an error who says: "Uncagth TypeError: Cannot read property 'length' of undefined", source: architect://architect.js(1).

 

I tried to do this too:

 World.img3D.drawables.removeCamDrawable(this.modelCar, 4);

 World.img3D.drawables.addCamDrawable(this.modelCar2, 4);

and:

 World.img3D.drawables.removeCamDrawable(this.modelCar);

 World.img3D.drawables.addCamDrawable(this.modelCar2);

but it doesn't work.

 

 

Really I don't understand

 

How can you help me? 

 

 

Thanks, I hope you can understand me.

Thanks now is running perfect.

Hi Sergio,

I met the same problem as you.( "Uncagth TypeError: Cannot read property 'length' of undefined", source: architect://architect.js(1).)

could you share your solution or your code ?

thanks!



Hi xinfei I dont remember well what I did because was a long time ago, but here is part of my code. I hope you can understand and will it is Helpful  for you.

You can find the file attach in this message.

 
Login or Signup to post a comment