initial
This commit is contained in:
50
main.js
Normal file
50
main.js
Normal file
@@ -0,0 +1,50 @@
|
||||
import * as THREE from 'three';
|
||||
import Stats from 'three/addons/libs/stats.module.js';
|
||||
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
||||
|
||||
const container = document.getElementById('container');
|
||||
|
||||
const stats = new Stats();
|
||||
container.appendChild(stats.dom);
|
||||
|
||||
const renderer = new THREE.WebGLRenderer({ antialias: true });
|
||||
renderer.setPixelRatio(window.devicePixelRatio);
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
container.appendChild(renderer.domElement);
|
||||
|
||||
const camera = new THREE.PerspectiveCamera(40, window.innerWidth / window.innerHeight, 1, 100);
|
||||
const controls = new OrbitControls(camera, renderer.domElement);
|
||||
const scene = new THREE.Scene();
|
||||
|
||||
const geometry = new THREE.BoxGeometry(1, 1, 1);
|
||||
const material = new THREE.MeshPhysicalMaterial({ color: 0x00ff00 });
|
||||
const cube = new THREE.Mesh(geometry, material);
|
||||
scene.add(cube);
|
||||
|
||||
controls.target.set( 0, 0, 0 );
|
||||
controls.update();
|
||||
controls.enablePan = false;
|
||||
controls.enableDamping = true;
|
||||
|
||||
camera.position.z = 5;
|
||||
|
||||
window.onresize = function () {
|
||||
camera.aspect = window.innerWidth / window.innerHeight;
|
||||
camera.updateProjectionMatrix();
|
||||
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
|
||||
};
|
||||
|
||||
|
||||
function animate() {
|
||||
stats.update();
|
||||
|
||||
controls.update();
|
||||
|
||||
renderer.render(scene, camera);
|
||||
|
||||
cube.rotation.x += 0.01;
|
||||
cube.rotation.y += 0.01;
|
||||
}
|
||||
renderer.setAnimationLoop(animate);
|
Reference in New Issue
Block a user