728x90
<!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>
<!-- Import maps polyfill -->
<!-- Remove this when import maps will be widely supported -->
<script async src="https://unpkg.com/es-module-shims@1.6.3/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "../build/three.module.js",
"three/addons/": "./jsm/"
}
}
</script>
<script type="module">
import * as THREE from 'three';
let camera, scene, renderer;
let meshS, meshE, meshM;
var r = 200;
var t = 0;
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 300;
scene = new THREE.Scene();
const textureS = new THREE.TextureLoader().load( 'textures/celeb/8k_sun.jpg' );
textureS.colorSpace = THREE.SRGBColorSpace;
const materialS = new THREE.MeshBasicMaterial( { map: textureS } );
const textureE = new THREE.TextureLoader().load( 'textures/celeb/earth2.jpg' );
textureE.colorSpace = THREE.SRGBColorSpace;
const materialE = new THREE.MeshBasicMaterial( { map: textureE } );
const textureM = new THREE.TextureLoader().load( 'textures/celeb/8k_moon.jpg' );
textureM.colorSpace = THREE.SRGBColorSpace;
const materialM = new THREE.MeshBasicMaterial( { map: textureM } );
const geometryS = new THREE.SphereGeometry( 15, 50, 30 );
const geometryE = new THREE.SphereGeometry( 10, 50, 30 );
const geometryM = new THREE.SphereGeometry( 7, 50, 30 );
meshS = new THREE.Mesh( geometryS, materialS );
meshE = new THREE.Mesh( geometryE, materialE );
meshM = new THREE.Mesh( geometryM, materialM );
scene.add( meshS );
scene.add( meshE );
scene.add( meshM );
meshE.position.x = 200;
meshM.position.x = 250;
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
//
window.addEventListener( 'resize', onWindowResize );
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
var r = 200;
var t = 0;
var rr =50;
var tt = 0;
function animate() {
requestAnimationFrame( animate );
meshS.rotation.z += 0.01;
meshS.rotation.y += 0.01;
meshE.position.x = r * Math.cos(t);
meshE.position.y = r * Math.sin(t);
meshM.position.x = meshE.position.x + rr*Math.cos(tt);
meshM.position.y = meshE.position.y + rr*Math.sin(tt);
camera.lookAt(meshE.position);
renderer.render( scene, camera );
t += 0.01;
tt +=0.1;
}
</script>
</body>
</html>
'Python > Three.JS' 카테고리의 다른 글
Three.js EX10 드론만들어보기 연습 (0) | 2023.07.15 |
---|---|
Three.js EX09 드론만들어보기 연습 (0) | 2023.07.15 |
Three.js EX07 우주만들어보기 (0) | 2023.07.15 |
Three.js EX05,EX06 SphereGeometry (0) | 2023.07.14 |
Three.js EX04 PlaneGeometry (0) | 2023.07.14 |