-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBergamota.js
executable file
·121 lines (101 loc) · 3.37 KB
/
Bergamota.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var textures = {
'map': {
url: 'bergamota-3.jpg',
val: undefined
},
'mapPeeled': {
url: 'bergamota--peeled.jpg',
val: undefined
},
'gordinho': {
url: 'bergamota-3.jpg',
val: undefined
},
'bumpMap': {
url: 'bergamota_bump.jpg',
val: undefined
}
};
var Bergamota = function (radius, segments) {
THREE.Object3D.call(this);
this.name = "Bergamota";
var that = this;
// instantiate a loader
var loader = new THREE.TextureLoader();
var texturePromises = [], path = './';
for (var key in textures) {
texturePromises.push(new Promise((resolve, reject) => {
var entry = textures[key]
var url = path + entry.url
loader.load(url,
texture => {
entry.val = texture;
if (entry.val instanceof THREE.Texture) resolve(entry);
},
xhr => {
console.log(url + ' ' + (xhr.loaded / xhr.total * 100) +
'% loaded');
},
xhr => {
reject(new Error(xhr +
'An error occurred loading while loading: ' +
entry.url));
}
);
}));
}
// load the geometry and the textures
Promise.all(texturePromises).then(loadedTextures => {
var geometry = new THREE.SphereGeometry(radius, segments, segments);
textures.map.val.wrapS = THREE.RepeatWrapping;
textures.map.val.wrapT = THREE.RepeatWrapping;
textures.map.val.repeat.set( 8, 8 );
textures.mapPeeled.val.wrapS = THREE.RepeatWrapping;
textures.mapPeeled.val.wrapT = THREE.RepeatWrapping;
textures.mapPeeled.val.repeat.set( 16, 16 );
var material = new THREE.MeshPhongMaterial({
map: textures.map.val,
bumpMap: textures.bumpMap.val,
bumpScale: 0.05
});
var bergamota = that.bergamota = new THREE.Mesh(geometry, material);
that.add(bergamota);
textures.gordinho.val.repeat.set( 0.4, 0.4 );
var gordinhoGeometry = new THREE.CylinderGeometry( 1.6, 3, 1.4, 32 );
var gordinhoMaterial = new THREE.MeshPhongMaterial({
map: textures.gordinho.val,
bumpMap: textures.bumpMap.val,
bumpScale: 0.05
});
var gordinho = new THREE.Mesh( gordinhoGeometry, gordinhoMaterial );
that.add( gordinho );
gordinho.position.set(0, 14, 0);
textures.gordinho.val.repeat.set( 0.4, 0.4 );
var gordinhoGeometry = new THREE.CylinderGeometry( 1.6, 3, 1.4, 32 );
var gordinhoMaterial = new THREE.MeshPhongMaterial({
map: textures.gordinho.val,
bumpMap: textures.bumpMap.val,
bumpScale: 0.05
});
var gordinho = new THREE.Mesh( gordinhoGeometry, gordinhoMaterial );
that.add( gordinho );
gordinho.position.set(0, 14, 0);
var cabinhoGeometry = new THREE.CylinderGeometry( 0.5, 0.5, 4, 32 );
var cabinhoMaterial = new THREE.MeshBasicMaterial( {color: 0x5f4123} );
var cabinhoP1 = new THREE.Mesh( cabinhoGeometry, cabinhoMaterial );
that.add( cabinhoP1 );
cabinhoP1.position.set(0, 15, 0);
cabinhoP1.rotateX(0.3);
cabinhoP1.rotateY(0.2);
var cabinhoP2 = new THREE.Mesh( cabinhoGeometry, cabinhoMaterial );
that.add( cabinhoP2 );
cabinhoP2.position.set(0, 16, -1);
cabinhoP2.rotateX(-0.2);
cabinhoP2.rotateY(0);
});
}
Bergamota.prototype = Object.create(THREE.Object3D.prototype);
Bergamota.prototype.constructor = Bergamota;
Bergamota.prototype.descasca = function() {
bergamota.children[0].material.map = textures.mapPeeled.val
}