@@ -6,39 +6,51 @@ define('three-scene', () => {
66 init ( ) ;
77
88 function init ( ) {
9- scene = new THREE . Scene ( ) ;
10- camera = new THREE . PerspectiveCamera ( 100 , 1 , 0.1 , 1000 ) ;
119 container = document . createElement ( 'div' ) ;
1210 document . getElementById ( 'perspective' ) . appendChild ( container ) ;
1311
14- gemoetry = new THREE . BoxGeometry ( 50 , 50 , 50 ) ;
15- material = new THREE . MeshBasicMaterial ( { color : 0xff0000 } ) ;
16- cube = new THREE . Mesh ( gemoetry , material ) ;
12+ scene = new THREE . Scene ( ) ;
13+ camera = new THREE . PerspectiveCamera ( 50 , 1 , 1 , 1000 ) ;
14+ camera . position . z = 500 ;
15+ scene . add ( camera ) ;
16+
17+ geometry = new THREE . CubeGeometry ( 50 , 50 , 50 ) ;
18+ material = new THREE . MeshNormalMaterial ( { color : 0xff0000 } ) ;
19+
20+ cube = new THREE . Mesh ( geometry , material ) ;
1721 scene . add ( cube ) ;
22+
1823 renderer = new THREE . CanvasRenderer ( ) ;
1924 console . log ( renderer ) ;
2025 renderer . setSize ( w , h ) ;
21- camera . position . x = 50 ;
22- camera . position . y = 50 ;
23- camera . position . z = 300 ;
2426
2527 container . appendChild ( renderer . domElement ) ;
2628
27- renderer . render ( scene , camera ) ;
29+ // renderer.render(scene, camera);
2830
2931 }
3032
3133 let currentFrame = 0 ;
3234 let animate ;
33- let rotationSpeed = ( rotation = { speed :{ x :0 , y :0 } } ) => {
35+
36+ let rotationSpeed = ( rotation = { speed :{ x :0 , y :0 } } ) => {
3437 cube . rotation . x += rotation . speed . x ;
3538 cube . rotation . y += rotation . speed . y ;
3639 }
40+
41+ let positionSpeed = ( position = { x :0 , y :0 } ) => {
42+ cube . position . x += position . x * 0.01 ;
43+ cube . position . z += position . y * 0.01 ;
44+ }
45+
3746 animate = ( params ) => {
3847 requestAnimationFrame ( ( ) => animate ( params ) ) ;
3948 if ( params . rotation ) rotationSpeed ( params . rotation )
40- //console.info(cube.rotation.y, scene, camera, cube);
41- scene . add ( cube ) ;
49+ if ( params . position ) positionSpeed ( params . position )
50+ //cube.position.x += 2.0; // auto move right
51+ cube . position . y = 30 ; // make it visible, do not change ...
52+ //cube.position.z += params.position.z * 0.1;
53+ //log(cube.position.z);
4254 renderer . render ( scene , camera ) ;
4355 document . querySelector ( '#perspective_stats' ) . innerHTML = cube . rotation . x ;
4456 }
0 commit comments