-
Notifications
You must be signed in to change notification settings - Fork 2
/
Body.js
executable file
·53 lines (47 loc) · 1.05 KB
/
Body.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
import { Color } from '../Color';
const THREE = require('three');
/**
* body of protagonist
*/
export class Body{
/**
* generates mesh for body
*/
constructor(){
this.material = new THREE.MeshLambertMaterial({
color: 0xffffff,
transparent: false,
opacity: 0.8
});
this.mesh = new THREE.Mesh(Body.geometry, this.material);
}
/**
* positions the body according to given coordinates
* @param {number} x
* @param {number} y
* @param {number} z
*/
position(x,y,z){
this.mesh.position.set(x, y, z);
}
/**
* adds the body to a group
* @param {THREE.Group} group
*/
addToGroup(group) {
group.add(this.mesh);
}
/**
* loads the body from json file (blender)
* @param {Promise} promise
*/
static init(cb){
let loader = new THREE.JSONLoader();
return new Promise((resolve, reject)=>{
loader.load('/blender/body.json', function(geometry, materials) {
Body.geometry = geometry;
resolve();
});
});
}
}