Start a new topic

Change texture or color

Change texture or color

Hello,

Unfortunately a change of textures or colors on the fly is not possible at the moment.
As a workaround you could create the same models with different materials and exchange the models when a button is clicked.

Regards,
Christian
Hi..

I'm new wikitude sdk. I want to know whether there's a way to change the textures or colors of the 3d models using a button click of something like that. For example if it is a ball, user must be able to change it's color while viewing the object.

Can it is possible?
Hi Christian,

How can I change the image on button click? Is there any example?
Hello,

just implement the onClick-function and set the enabled flag of the ARObject you would like to enable/disable.

Here an example (quick and dirty):

 

var image1 = new AR.ImageResource("assets/foo1.png");

var image2 = new AR.ImageResource("assets/foo2.png");

var drawable1 = new AR.ImageDrawable(image1, 5);

var drawable2 = new AR.ImageDrawable(image2, 5);

var loc = new AR.RelativeLocation(null, 30, 0, null);

drawable1.onClick = function() { 

drawable2.enable = true;

drawable1.enable = false; 

};

drawable2.onClick = function() { 

drawable1.enable = true; 

drawable2.enable = false; 

};

var go = new AR.GeoObject(loc, {

drawables: {

cam: 

}

});

 


 

Thanks for the quick reply. 
I am using this code and this is not working. Am i doing something wrong?

var image1 = new AR.ImageResource("img/yellow.jpg");
var image2 = new AR.ImageResource("img/red.jpg");
var drawable1 = new AR.ImageDrawable(image1, 1);
var drawable2 = new AR.ImageDrawable(image2, 1);
drawable1.onClick = function() { 
drawable2.enable = true;
drawable1.enable = false; 
};

drawable2.onClick = function() { 
drawable1.enable = true; 
drawable2.enable = false; 
};

var seven = new AR.Trackable2DObject(this.tracker, "1", {
drawables: {
cam:  
}
});
Difficult to say why it doesnt work without seeing the full picture. What exactly doesn't work? Do you get a JavaScript-error?
It could be that

...'this.tracker' is not defined
...your tracker name '1' is not correct
...the drawable variables are not global and you need a closure for the onClick function
...the images can't be found or loaded
There are no errors in the console. I am seeing first image but onclick there is no change although click function is working.

Hi guys, 
regarding: "... a change of textures or colors on the fly is not possible at the moment.
As a workaround you could create the same models with different materials and exchange the models when a button is clicked." Is this still the only available option in SDK Cordova version 8.0? 

Beside a more complex workflow, I'm worried that with a large number of model variants the size of my app grows excessively.

Thanks,
Matteo
Login or Signup to post a comment