@@ -21,21 +21,20 @@ var mouse = {
2121 }
2222}
2323
24- function fitTo ( scene , targetSize = 1 ) {
24+ function fitTo ( group , targetSize = 1 ) {
2525 const box = new THREE . Box3 ( ) ;
26- scene . traverse ( object => {
26+ group . traverse ( object => {
2727 if ( object instanceof THREE . Mesh || object instanceof THREE . Group ) {
2828 box . expandByObject ( object ) ;
2929 }
3030 } ) ;
3131 const size = box . getSize ( new THREE . Vector3 ( ) ) ;
3232 const scale = targetSize / Math . max ( size . x , size . y , size . z ) ;
33- console . info ( 'Scaling scene by' , scale ) ;
34- scene . scale . set ( scale , scale , scale ) ;
33+ group . scale . set ( scale , scale , scale ) ;
34+ group . position . set ( 0 , 0 , - 0.1 ) ;
3535}
3636
3737async function init ( cb ) {
38-
3938 container . width = window . innerWidth ;
4039 container . height = window . innerHeight ;
4140
@@ -70,52 +69,6 @@ async function init(cb) {
7069 }
7170}
7271
73- function onWindowResize ( ) {
74- container . width = window . innerWidth ;
75- container . height = window . innerHeight ;
76- camera . aspect = container . width / container . height ;
77- camera . updateProjectionMatrix ( ) ;
78- renderer . setSize ( window . innerWidth , window . innerHeight ) ;
79- }
80-
81- function mousemove ( e ) {
82- mouse . x . current = e . clientX ;
83- mouse . y . current = e . clientY ;
84- mouse . x . calc = mouse . x . current - ( container . width / 2 ) ;
85- mouse . y . calc = mouse . y . current - ( container . height / 2 ) ;
86- }
87-
88-
89- function touchend ( e ) {
90- if ( isUp ) {
91- isUp = false ;
92- } else {
93- mousedown ( e ) ;
94- }
95- }
96-
97- function touchmove ( e ) {
98- if ( e . touches . length === 1 ) {
99- e . preventDefault ( ) ;
100- mouse . x . current = e . touches [ 0 ] . pageX ,
101- mouse . y . current = e . touches [ 0 ] . pageY ;
102- mouse . x . calc = mouse . x . current - ( container . width / 2 ) ;
103- mouse . y . calc = mouse . y . current - ( container . height / 2 ) ;
104- }
105- }
106-
107- function mouseup ( e ) {
108- isUp = false ;
109- console . log ( isUp )
110-
111- }
112-
113- function mousedown ( e ) {
114- isUp = true ;
115- console . log ( isUp )
116-
117- }
118-
11972function addLights ( ) {
12073 hemiLight = new THREE . HemisphereLight ( 0xffffff , 0xffffff , 0.6 ) ;
12174
@@ -138,11 +91,10 @@ function addLights() {
13891function createWalter ( ) {
13992 walter = new Walter ( ) ;
14093 scene . add ( walter . threegroup ) ;
94+ return walter . threegroup ;
14195}
14296
143-
14497function Walter ( ) {
145-
14698 this . threegroup = new THREE . Group ( ) ;
14799
148100 this . informalSmokingMat = "#ffc107" ;
@@ -285,25 +237,25 @@ function Walter() {
285237
286238 //body
287239
288- var body = new THREE . BoxGeometry ( 300 , 250 , 600 ) ;
240+ var body = new THREE . BoxGeometry ( 300 , 250 , 200 ) ;
289241 this . body = new THREE . Mesh ( body , this . smokingMat ) ;
290242 this . body . position . x = 0 ;
291- this . body . position . y = - 220 ;
292- this . body . position . z = 100 ;
243+ this . body . position . y = - 160 ;
244+ this . body . position . z = 400 ;
293245
294246 //arms
295247
296248 var arm = new THREE . BoxGeometry ( 50 , 250 , 100 ) ;
297249
298250 this . armLeft = new THREE . Mesh ( arm , this . smokingMat ) ;
299251 this . armLeft . position . x = - 170 ;
300- this . armLeft . position . y = 0 ;
301- this . armLeft . position . z = 200 ;
252+ this . armLeft . position . y = - 20 ;
253+ this . armLeft . position . z = 0 ;
302254
303255 this . armRight = new THREE . Mesh ( arm , this . smokingMat ) ;
304256 this . armRight . position . x = 170 ;
305- this . armRight . position . y = 0 ;
306- this . armRight . position . z = 200 ;
257+ this . armRight . position . y = - 20 ;
258+ this . armRight . position . z = 0 ;
307259
308260
309261 // hands
@@ -313,44 +265,44 @@ function Walter() {
313265 this . handLeft = new THREE . Mesh ( hand , this . skinMat ) ;
314266 this . handLeft . position . x = - 170 ;
315267 this . handLeft . position . y = - 150 ;
316- this . handLeft . position . z = 220 ;
268+ this . handLeft . position . z = 20 ;
317269
318270 this . handRight = new THREE . Mesh ( hand , this . skinMat ) ;
319271 this . handRight . position . x = 170 ;
320272 this . handRight . position . y = - 150 ;
321- this . handRight . position . z = 220 ;
273+ this . handRight . position . z = 20 ;
322274
323275 //zipper
324276
325277 var zipper = new THREE . BoxGeometry ( 80 , 250 , 10 ) ;
326278 this . zipper = new THREE . Mesh ( zipper , this . zipperMat ) ;
327279 this . zipper . position . x = 0 ;
328280 this . zipper . position . y = 0 ;
329- this . zipper . position . z = 300 ;
281+ this . zipper . position . z = 100 ;
330282
331283 //legs
332284
333- var legs = new THREE . BoxGeometry ( 200 , 300 , 300 ) ;
285+ var legs = new THREE . BoxGeometry ( 200 , 300 , 50 ) ;
334286 this . legs = new THREE . Mesh ( legs , this . smokingMat ) ;
335287 this . legs . position . x = 0 ;
336288 this . legs . position . y = - 200 ;
337- this . legs . position . z = 100 ;
289+ this . legs . position . z = 0 ;
338290
339291 //legsMiddle
340292
341293 var legsM = new THREE . BoxGeometry ( 10 , 130 , 5 ) ;
342294 this . legsM = new THREE . Mesh ( legsM , this . legsMMat ) ;
343295 this . legsM . position . x = 0 ;
344296 this . legsM . position . y = - 280 ;
345- this . legsM . position . z = 248 ;
297+ this . legsM . position . z = 25 ;
346298
347299 //shoes
348300
349- var shoes = new THREE . BoxGeometry ( 200 , 50 , 400 ) ;
301+ var shoes = new THREE . BoxGeometry ( 200 , 50 , 50 ) ;
350302 this . shoes = new THREE . Mesh ( shoes , this . shoesMat ) ;
351303 this . shoes . position . x = 0 ;
352304 this . shoes . position . y = - 400 ;
353- this . shoes . position . z = 100 ;
305+ this . shoes . position . z = 0 ;
354306
355307
356308 // group elements
@@ -463,17 +415,16 @@ function calc(v, vmin, vmax, tmin, tmax) {
463415
464416function loop ( ) {
465417 renderer . render ( scene , camera ) ;
466- walter . update ( ) ;
418+ // walter.update();
467419}
468420
469421try {
470422 init ( ( ) => {
471423 renderer . setAnimationLoop ( loop ) ;
472424 } ) ;
473425 addLights ( ) ;
474- createWalter ( ) ;
475426
476- fitTo ( scene , 0.3 ) ;
427+ fitTo ( createWalter ( ) , 0.3 ) ;
477428} catch ( err ) {
478429 console . error ( err ) ;
479430}
0 commit comments