@@ -59,6 +59,7 @@ export class MainCSS3d {
59
59
private timestep : number = 1 / 60 ;
60
60
private bPhysicsOn : boolean = false ;
61
61
private cannonBalls : Array < Cannon . Body > = [ ] ;
62
+ private cannonBallsBodyPosOrigin : Array < Cannon . Vec3 > = [ ] ;
62
63
63
64
/**
64
65
* Creates an instance of MainCSS3d.
@@ -233,31 +234,32 @@ export class MainCSS3d {
233
234
for ( var i = 1 ; i < 8 ; i ++ ) {
234
235
for ( var j = 1 ; j < 3 ; j ++ ) {
235
236
let factor = Math . random ( ) * 30 + 5 ;
236
- console . log ( "factor: " + factor ) ;
237
+ // console.log("factor: " + factor);
237
238
238
239
let sign : number = ( factor > 20 ) ? + 1 : - 1 ; // positive or negative
239
- var sphereShape = new Cannon . Sphere ( factor ) ;
240
- var sphereBody = new Cannon . Body ( { mass : factor } ) ;
240
+ let sphereShape = new Cannon . Sphere ( factor ) ;
241
+ let sphereBody = new Cannon . Body ( { mass : factor } ) ;
241
242
sphereBody . addShape ( sphereShape ) ;
242
- sphereBody . position . set ( j * 50 , 100 * i , 20 * i * j - 150 ) ;
243
- sphereBody . angularVelocity . set ( 0 , factor / 100 * sign , 0 ) ;
243
+ sphereBody . position . set ( j * 50 , 100 * i , 20 * i * j - 150 ) ;
244
+ //cpyCanBallPosOrig.push(sphereBody.position);
245
+ this . cannonBallsBodyPosOrigin . push ( new Cannon . Vec3 ( sphereBody . position . x , sphereBody . position . y , sphereBody . position . z ) ) ;
246
+
247
+ sphereBody . angularVelocity . set ( 0 , factor / 100 * sign , 0 ) ;
244
248
sphereBody . quaternion . set ( 0.2 , 0.5 , 0 , 1 ) ;
245
249
this . cannonBalls . push ( sphereBody ) ;
246
250
this . cannonWorld . addBody ( sphereBody ) ;
247
251
248
252
// visual
249
253
var geom = new THREE . SphereGeometry ( factor , 32 , 32 ) ;
250
254
var mesh = new THREE . Mesh ( geom , this . getMeshPhongMaterialFromTexture ( Texture . GAS_GREEN ) ) ;
251
- mesh . position . set ( j * 50 , 100 * i , 20 * i * j - 150 ) ;
255
+ mesh . position . set ( j * 50 , 100 * i , 20 * i * j - 150 ) ;
252
256
mesh . castShadow = true ;
253
257
mesh . receiveShadow = true ;
254
258
this . sceneBalls . push ( mesh ) ;
255
259
this . scene . add ( mesh ) ;
256
260
257
261
}
258
262
}
259
-
260
-
261
263
}
262
264
263
265
private addHelpers ( ) {
@@ -427,34 +429,49 @@ export class MainCSS3d {
427
429
case "elem_5" : //reset physic objects
428
430
// everytime do the same sequential steps
429
431
document . getElementById ( this . id ) . className = "elementClick" ;
430
-
432
+
431
433
component . cannonWorld . gravity . set ( 0 , 0 , 0 ) ; // gravity off
432
434
433
435
document . getElementById ( "elem_1" ) . className = "element" ;
434
436
component . bPhysicsOn = false ;
435
437
436
- // tween objects upwards
437
- component . tweenPhysicObjects = new TWEEN . Tween ( { yPos : 0 } )
438
- . to ( { yPos : 250 } , 2000 )
439
- . onUpdate ( function ( ) {
440
- for ( let i = 0 ; i < component . cannonBalls . length ; i ++ ) {
441
- component . sceneBalls [ i ] . position . y = component . cannonBalls [ i ] . position . y = this . yPos ;
442
- }
438
+ // tween sphere objects to origin
439
+ for ( let i = 0 ; i < component . cannonBalls . length ; i ++ ) {
440
+ //console.log("i: " + i + ", component.cannonBallsBodyPosOrigin[i]: " + component.cannonBallsBodyPosOrigin[i]);
441
+
442
+ // stop translation velocity
443
+ //component.cannonBalls[i].quaternion.set(0,0,0,0);
444
+ component . cannonBalls [ i ] . velocity . set ( 0 , 0 , 0 ) ;
445
+ component . cannonBalls [ i ] . initVelocity . set ( 0 , 0 , 0 ) ;
446
+
447
+ // set tween
448
+ component . tweenPhysicObjects = new TWEEN . Tween ( {
449
+ xPos : component . cannonBalls [ i ] . position . x ,
450
+ yPos : component . cannonBalls [ i ] . position . y ,
451
+ zPos : component . cannonBalls [ i ] . position . z
452
+ } )
453
+ . to ( {
454
+ xPos : component . cannonBallsBodyPosOrigin [ i ] . x ,
455
+ yPos : component . cannonBallsBodyPosOrigin [ i ] . y ,
456
+ zPos : component . cannonBallsBodyPosOrigin [ i ] . z
457
+ } , 2000 )
458
+ . onUpdate ( function ( ) {
459
+ //console.log("this.yPos: " + this.yPos + ", component.cannonBalls[i].position.y: " + component.cannonBalls[i].position.y);
460
+ component . cannonBalls [ i ] . position = new Cannon . Vec3 ( this . xPos , this . yPos , this . zPos ) ;
461
+ } )
462
+ . start ( ) ;
463
+ }
464
+ // tween CSS 3d element
465
+ let targetPosZ = ( component . sceneCSS . getObjectByName ( "elem_5" ) . position . z === 0 ) ? 150 : 0 ;
466
+ component . tweenPhysicCSSElem = new TWEEN . Tween ( { zPos : component . sceneCSS . getObjectByName ( "elem_5" ) . position . z } )
467
+ . to ( { zPos : targetPosZ } , 1000 )
468
+ . onUpdate ( function ( ) {
469
+ component . sceneCSS . getObjectByName ( "elem_5" ) . position . z = this . zPos ;
443
470
} )
444
- . onComplete ( function ( ) {
471
+ . onComplete ( function ( ) {
445
472
document . getElementById ( "elem_5" ) . className = "element" ;
446
473
} )
447
474
. start ( ) ;
448
-
449
- // tween CSS 3d element
450
- let targetPosZ = ( component . sceneCSS . getObjectByName ( "elem_5" ) . position . z === 0 ) ? 150 : 0 ;
451
- component . tweenPhysicCSSElem = new TWEEN . Tween ( { zPos : component . sceneCSS . getObjectByName ( "elem_5" ) . position . z } )
452
- . to ( { zPos : targetPosZ } , 1000 )
453
- . onUpdate ( function ( ) {
454
- component . sceneCSS . getObjectByName ( "elem_5" ) . position . z = this . zPos ;
455
- } )
456
- . start ( ) ;
457
-
458
475
break ;
459
476
default :
460
477
console . log ( this . id + " not configured" ) ;
@@ -476,14 +493,14 @@ export class MainCSS3d {
476
493
477
494
var details = document . createElement ( 'div' ) ;
478
495
details . className = 'details' ;
479
- details . innerHTML = ( i == 5 ) ? liTxt [ i - 1 ] : "Toggle<br>" + liTxt [ i - 1 ] ;
496
+ details . innerHTML = ( i == 5 ) ? liTxt [ i - 1 ] : "Toggle<br>" + liTxt [ i - 1 ] ;
480
497
element . appendChild ( details ) ;
481
498
482
- let object :CSS3DRenderer . CSS3DObject = new CSS3DRenderer . CSS3DObject ( element ) ;
499
+ let object : CSS3DRenderer . CSS3DObject = new CSS3DRenderer . CSS3DObject ( element ) ;
483
500
object . position . x = menuPosX + ( - 100 * i ) ;
484
501
object . position . y = 200 ;
485
- object . name = "elem_" + i ;
486
- // object.userData = {id: "elem_"+i};
502
+ object . name = "elem_" + i ;
503
+ // object.userData = {id: "elem_"+i};
487
504
this . sceneCSS . add ( object ) ;
488
505
}
489
506
0 commit comments