วันพุธที่ 19 กุมภาพันธ์ พ.ศ. 2568

  <!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Simple 3D Scene</title>

    <style>

        body { margin: 0; }

        canvas { width: 100%; height: 100vh; display: block; }

    </style>

</head>

<body>

    <script type="module">

        import * as THREE from 'https://cdn.jsdelivr.net/npm/three@0.141.0/build/three.module.js';


        // Scene

        const scene = new THREE.Scene();


        // Camera

        const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);

        camera.position.z = 5;


        // Renderer

        const renderer = new THREE.WebGLRenderer();

        renderer.setSize(window.innerWidth, window.innerHeight);

        document.body.appendChild(renderer.domElement);


        // Geometry and Material

        const geometry = new THREE.BoxGeometry();

        const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });

        const cube = new THREE.Mesh(geometry, material);

        scene.add(cube);


        // Animation loop

        function animate() {

            requestAnimationFrame(animate);


            // Rotate the cube

            cube.rotation.x += 0.01;

            cube.rotation.y += 0.01;


            renderer.render(scene, camera);

        }


        animate();

    </script>

</body>

</html>

ไม่มีความคิดเห็น:

แสดงความคิดเห็น