Old stuff/old_sites/threejs/7_bones/js/perso.js
(Deskargatu)
var Perso = function(scene)
{
var self=this;
self.scene = scene;
this.load= function()
{
var self=this;
console.log('load!');
return new Promise(function(ok, reject)
{
var loader = new THREE.JSONLoader();
console.log('loading js/bar.json');
loader.load( "blender/bar.json", function(geometry, mat)
{
console.log('received ',geometry, mat);
self.bar_geo = geometry;
self.bar_mat = mat;
ok();
});
});
};
this.build = function()
{
var self=this;
this.load().then(function()
{
self.create({ x:0, y:0});
});
};
this.create =function(options)
{
console.log('creating material');
material = new THREE.MeshLambertMaterial( { color: 0xffffff } );
material.skinning = true;
material.morphTargets = true;
this.mesh = new THREE.SkinnedMesh( self.bar_geo, material);
this.scene.add(this.mesh);
this.mesh.castShadow=true;
this.mesh.receiveShadow=true;
this.mesh.position.x = options.x;
this.mesh.position.y = options.y;
console.log('perso ',this.mesh);
this.mixer = new THREE.AnimationMixer( this.mesh );
this.bounceClip = self.bar_geo.animations[0];
this.action = this.mixer.clipAction(this.bounceClip, null ).setDuration(0.7);
this.action.play();
console.log('actio ',this.action, 'mixer = ',this.mixer);
};
this.play = function()
{
var action = this.mixer.clipAction(this.bounceClip, null);
action.repetitions += Infinity;
console.log('playing ',action);
action.play();
};
};