I am digging into Three.js and am experimenting with vrml, and now with collada files.
Importing a collada file works. It works with webGL AND canvas as a fallback : my 3D model rotates, shows the model… and in webGL i can even have that wonderful effects like shadows, bumps, etc.
I did achieve loading another texture file, assigning it to the webGL renderer… but in this particular case, the canvas renderer completely fails : frames drop from 60fps to 2fps, and the texture "slides" on the polygons.
I guess i miss something in order to "fix" the texture to the model, or when importing the texture maybe do i miss some parameters ? Once again it is working fine without changing the texture… but i really need to do so :p
Here is a working preview : http://dokmixer.com/three-tests/
And here is the part where the magic fails :
//model loading
loader = new THREE.ColladaLoader();
loader.load('models/collada/7cm.005.dae',function colladaReady( collada ){
player = collada.scene;
skin = collada.skins [ 0 ];
player.scale.x = player.scale.y = player.scale.z = 0.10;
if (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1) {
var newskinTexture = new THREE.ImageUtils.loadTexture( 'models/collada/dokMixer.png' );
themodel = collada.scene.children[0];
themodel.material = new THREE.MeshBasicMaterial( { map: newskinTexture, overdraw: true} );
}
else {
var newskinTexture = new THREE.ImageUtils.loadTexture( 'models/collada/dokMixer.png' );
var bumpTexture = new THREE.ImageUtils.loadTexture( 'models/collada/noise.png' );
bumpTexture.anisotropy = 2;
player_material = collada.scene.children[0].material;
themodel = collada.scene.children[0];
themodel.material = new THREE.MeshPhongMaterial( { map: newskinTexture, bumpMap: bumpTexture, bumpScale: 0.05} );
}
//utile pour avoir les ombres
daemesh = player.children[0];
daemesh.castShadow = true;
daemesh.receiveShadow = true;
scene.add( player );
});
The part to look into is the first if statement (as i am testing canvas with Safari, before expanding to other canvas enabled devices). When assigning a new material, the renderer completely fails. You can test the effect by going to the page with Safari.
Note : i am working on OSX if that can be of any relevant information.
Any help appreciated :)
EDIT : i guess i'm setting here a new material, instead of replacing only the source image file ?