|
<!DOCTYPE html> |
|
<html lang="en"> |
|
<head> |
|
<title>three.js webgl - geometry - cube</title> |
|
<meta charset="utf-8"> |
|
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"> |
|
<link type="text/css" rel="stylesheet" href="main.css"> |
|
</head> |
|
<body> |
|
<!-- <script type="importmap"> |
|
{ |
|
"imports": { |
|
"three": "https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js" |
|
} |
|
} |
|
</script> --> |
|
|
|
<script type="module"> |
|
|
|
// import * as THREE from 'three'; |
|
const THREE = await import("https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js"); |
|
|
|
|
|
console.log("THREE: ", THREE); |
|
|
|
let camera, scene, renderer; |
|
let mesh; |
|
|
|
|
|
function init() { |
|
console.log("init"); |
|
|
|
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 100 ); |
|
camera.position.z = 2; |
|
|
|
scene = new THREE.Scene(); |
|
|
|
const geometry = new THREE.BoxGeometry(); |
|
const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } ); |
|
mesh = new THREE.Mesh( geometry, material ); |
|
|
|
scene.add( mesh ); |
|
|
|
renderer = new THREE.WebGLRenderer( { antialias: true } ); |
|
renderer.setPixelRatio( window.devicePixelRatio ); |
|
renderer.setSize( window.innerWidth, window.innerHeight ); |
|
renderer.setAnimationLoop( animate ); |
|
document.body.appendChild( renderer.domElement ); |
|
|
|
window.addEventListener( 'resize', onWindowResize ); |
|
console.log("inited"); |
|
console.log("window: ", window); |
|
console.log("renderer: ", renderer); |
|
console.log(renderer.domElement); |
|
|
|
} |
|
|
|
function onWindowResize() { |
|
|
|
camera.aspect = window.innerWidth / window.innerHeight; |
|
camera.updateProjectionMatrix(); |
|
|
|
renderer.setSize( window.innerWidth, window.innerHeight ); |
|
|
|
} |
|
|
|
function animate() { |
|
|
|
mesh.rotation.x += 0.005; |
|
mesh.rotation.y += 0.01; |
|
|
|
renderer.render( scene, camera ); |
|
|
|
} |
|
|
|
init(); |
|
|
|
</script> |
|
|
|
</body> |
|
</html> |