File size: 1,423 Bytes
0dc587b
8f75885
 
0dc587b
8f75885
 
 
0dc587b
 
 
 
 
 
8f75885
 
 
 
 
0dc587b
8f75885
 
0dc587b
 
 
 
8f75885
0dc587b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>


<div id="cube-container"></div>



#cube-container {
    width: 100%;
    height: 400px;
    position: relative;
    margin-top: 20px;
}





Java


// scripts.js
document.addEventListener('DOMContentLoaded', function() {
    // Set up the scene, camera, and renderer as global variables.
    var scene, camera, renderer, cube;

    init();

    function init() {
        // Add the scene.
        scene = new THREE.Scene();
        scene.background = new THREE.Color(0xf4f4f4);

        // Add the camera.
        camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
        camera.position.z = 5;

        // Add the renderer.
        renderer = new THREE.WebGLRenderer({ antialias: true });
        renderer.setSize(window.innerWidth, window.innerHeight);
        document.getElementById('cube-container').appendChild(renderer.domElement);

        // Add the cube.
        var geometry = new THREE.BoxGeometry(2, 2, 2);
        var material = new THREE.MeshBasicMaterial({ color: 0x007bff, wireframe: false });
        cube = new THREE.Mesh(geometry, material);
        scene.add(cube);

        // Render the scene/camera combination.
        render();
    }

    function render() {
        requestAnimationFrame(render);
        
        // Rotate the cube.
        cube.rotation.x +=