forked from github/game-off-2013
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfactory.js
78 lines (67 loc) · 2.7 KB
/
factory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"use strict";
define(['colors','utility','three.min','tween.min'], function( colors, utility ) {
function HammerMesh( params ) {
var points = [];
var shape;
if( params.type === "corner" ) {
points.push( new THREE.Vector2 ( -params.width/2, -params.height/2) );
points.push( new THREE.Vector2 ( -params.width/2, params.height/2 ) );
points.push( new THREE.Vector2 ( params.width/2, -params.height/2 ) );
shape = new THREE.Shape( points );
}
else if( params.type === "edge" ) {
points.push( new THREE.Vector2 ( 0, -params.height/2) );
points.push( new THREE.Vector2 ( -params.width/2, params.height/2 ) );
points.push( new THREE.Vector2 ( params.width/2, params.height/2 ) );
shape = new THREE.Shape( points );
}
var extrusionSettings = {
amount: -params.depth/2,
curveSegments: 3,
bevelThickness: 4, bevelSize: 2, bevelEnabled: false,
material: 0, extrudeMaterial: 1
};
var geometry = new THREE.ExtrudeGeometry( shape, extrusionSettings );
var materialFront = new THREE.MeshBasicMaterial( { color: 0xffff00, side:THREE.DoubleSide } );
var materialSide = new THREE.MeshBasicMaterial( { color: 0xff8800, side:THREE.DoubleSide } );
var materialArray = [ materialFront, materialSide ];
var material = new THREE.MeshFaceMaterial( materialArray );
var mesh = new THREE.Mesh( geometry, material );
mesh.position.set( 0, 0, 0 );
mesh.rotation.z = params.rotation;
return mesh;
}
function Hammer( params ) {
var hammer = new HammerMesh( params );
hammer.position.z = 0;
var hammerTween;
function activate() {
if( hammerTween ) { hammerTween.stop(); }
hammerTween = new TWEEN.Tween( { z:hammer.position.z } )
.to( { z:-8 }, 500 )
.easing( TWEEN.Easing.Exponential.In )
.onUpdate( function () {
hammer.position.z = this.z;
})
.start();
}
function deactivate() {
if( hammerTween ) { hammerTween.stop(); }
hammerTween = new TWEEN.Tween( { z:hammer.position.z } )
.to( { z:-0.1 }, 500 )
.easing( TWEEN.Easing.Exponential.Out )
.onUpdate( function () {
hammer.position.z = this.z;
} )
.start();
}
return {
model:hammer,
activate:activate,
deactivate:deactivate
};
}
return {
Hammer: Hammer,
};
});