Tfe

Ongi etorri tfe-ren webgunera...

Old stuff/old_sites/threejs/13_fighting/js/key.js

(Deskargatu)
var Key = function(game, options)
{
    this.build =function()
    {
        var self=this;
        this.container = new THREE.Object3D();
        game.scene.add(this.container);

        var cube_material = new THREE.MeshBasicMaterial( { color: 0x0000ff, wireframe:true, transparent:true, opacity: game.opt.debug_level>1 ? 1 : 0  } );
        var cube_geo = new THREE.BoxGeometry(6 , 6, 6);
        this.container_mesh = new THREE.Mesh(cube_geo, cube_material);
        this.container_mesh.name='Key';
        this.container_mesh.position.y=0;
        this.container_mesh.rotation.x = Math.radians(90);
        this.container_mesh.rotation.z = Math.radians(45);
        this.container.add(this.container_mesh);

        this.container_mesh.callback_data = {
            current_maze: options.maze,
            callback_function: this.remove.bind(this, options.callback),
            mazeid: options.mazeid,
            cellid: options.cellid,
            type:'key'
        };

        this.container.position.x = options.x;
        this.container.position.y = 0;
        this.container.position.z = options.z;

        var materials = [];
        var mat1 = new THREE.MeshLambertMaterial({ color: 0xffff00} );
        mat1.skinning=true;
        mat1.morphTargets=true;

        var mat2 = new THREE.MeshLambertMaterial({ color: 0x00ff00} );
        mat2.skinning=true;
        mat2.morphTargets=true;

        var mat3 = new THREE.MeshLambertMaterial({ color: 0xff0000} );
        mat3.skinning=true;
        mat3.morphTargets=true;

        materials.push(mat1);
        materials.push(mat2);
        materials.push(mat3);
        materials.push(mat2);
        materials.push(mat1);


        //material.skinning = true;
        //material.morphTargets = true;


		var materials = game.assets.key_mat;
		for ( var i = 0; i < materials.length; i ++ ) {
			var m = materials[ i ];
			m.skinning = true;
			m.morphTargets = true;
		}
	
        this.mesh = new THREE.SkinnedMesh( game.assets.key_geo, new THREE.MultiMaterial(materials));
        this.mesh.scale.x=15;
        this.mesh.scale.y=15;
        this.mesh.scale.z=15;
        this.container.add(this.mesh);
        this.mesh.receiveShadow  = true;

        this.mesh.position.x = 0;
        this.mesh.position.y = 0;
        this.mesh.position.z = 0;

        this.mixer = new THREE.AnimationMixer( this.mesh );

        this.rotatingClip = game.assets.key_geo.animations[1];
        this.rotate_action = this.mixer.clipAction(this.rotatingClip, null ).setDuration(1);
        this.rotate_action.play();
        this.rotate_action.setEffectiveWeight(1);

    };

    this.remove= function(callback)
    {
        game.scene.remove(this.container);
        callback();
        game.updateCollisionsCache();
    }

    this.update = function(delta)
    {
        this.mixer.update(delta);
    };


    this.build();
};