↩︎ ホームへ
インデント:
2
4
8
Tab
▶ 実行
🗑 クリア
📋 コピー
💾 保存
📂 呼び出し
import * as THREE from "three"; // ここにthree.jsのコードを書いてください // シーン作成 const scene = new THREE.Scene(); scene.background = new THREE.Color(0x202020); // カメラ作成 const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 100); camera.position.set(0, 3, 10); camera.lookAt(0, 0, 0); // レンダラー作成 const renderer = new THREE.WebGLRenderer({ antialias: true }); renderer.setSize(window.innerWidth, window.innerHeight); document.body.appendChild(renderer.domElement); // 光源 const ambientLight = new THREE.AmbientLight(0xffffff, 0.4); scene.add(ambientLight); const directionalLight = new THREE.DirectionalLight(0xffffff, 1); directionalLight.position.set(5, 10, 7.5); scene.add(directionalLight); // Box作成 const geometry = new THREE.BoxGeometry(1, 1, 1); const material = new THREE.MeshStandardMaterial({ color: 0x00ff00, roughness: 0.4, metalness: 0.1 }); const box = new THREE.Mesh(geometry, material); scene.add(box); // アニメーション function animate() { requestAnimationFrame(animate); box.rotation.x += 0.01; box.rotation.y += 0.01; renderer.render(scene, camera); } animate(); // ウィンドウリサイズ対応 window.addEventListener('resize', () => { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize(window.innerWidth, window.innerHeight); });
折りたたむ
全画面表示
展開