Added a rotating scene
To try
This commit is contained in:
10
src/main.js
10
src/main.js
@@ -1,7 +1,11 @@
|
|||||||
import * as THREE from 'three';
|
import * as THREE from 'three';
|
||||||
|
import {createGround} from './objects/ground.js';
|
||||||
|
console.log("OK")
|
||||||
|
|
||||||
const scene = new THREE.Scene();
|
const scene = new THREE.Scene();
|
||||||
|
scene.background = new THREE.Color(0x0EB1D2);
|
||||||
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
|
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
|
||||||
|
//const camera = new THREE.OrthographicCamera( width / - 2, width / 2, height / 2, height / - 2, 1, 1000 );
|
||||||
|
|
||||||
const renderer = new THREE.WebGLRenderer();
|
const renderer = new THREE.WebGLRenderer();
|
||||||
renderer.setSize( window.innerWidth, window.innerHeight );
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
||||||
@@ -9,16 +13,20 @@ document.body.appendChild( renderer.domElement );
|
|||||||
|
|
||||||
|
|
||||||
const geometry = new THREE.BoxGeometry( 1, 1, 1 );
|
const geometry = new THREE.BoxGeometry( 1, 1, 1 );
|
||||||
const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
|
const material = new THREE.MeshBasicMaterial( { color: 0xaabbff } );
|
||||||
const cube = new THREE.Mesh( geometry, material );
|
const cube = new THREE.Mesh( geometry, material );
|
||||||
scene.add( cube );
|
scene.add( cube );
|
||||||
|
scene.add(createGround());
|
||||||
|
|
||||||
|
camera.position.x = 0;
|
||||||
|
camera.position.y = 0;
|
||||||
camera.position.z = 5;
|
camera.position.z = 5;
|
||||||
|
|
||||||
function animate() {
|
function animate() {
|
||||||
requestAnimationFrame( animate );
|
requestAnimationFrame( animate );
|
||||||
cube.rotation.x += 0.01;
|
cube.rotation.x += 0.01;
|
||||||
cube.rotation.y += 0.01;
|
cube.rotation.y += 0.01;
|
||||||
|
camera.rotation.x += 0.01;
|
||||||
renderer.render( scene, camera );
|
renderer.render( scene, camera );
|
||||||
}
|
}
|
||||||
animate();
|
animate();
|
||||||
|
|||||||
10
src/objects/ground.js
Normal file
10
src/objects/ground.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
//ground
|
||||||
|
import * as THREE from 'three';
|
||||||
|
|
||||||
|
export function createGround() {
|
||||||
|
const geometry = new THREE.PlaneGeometry(10, 10);
|
||||||
|
const material = new THREE.MeshBasicMaterial({ color: 0xa3c973 });
|
||||||
|
const plane = new THREE.Mesh(geometry, material);
|
||||||
|
|
||||||
|
return plane;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user