Guest User

Untitled

a guest
Apr 30th, 2025
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function CubeRender(Container) {
  2.  
  3.                 // Get the container div
  4.                 var container = document.getElementById(Container.__id);
  5.  
  6.                 // Check if container exists
  7.                 if (!container) {
  8.                     console.error('Container element not found');
  9.                     return; // Stop the initialization if the container is not found
  10.                 }
  11.  
  12.                 // Create a scene
  13.                 var scene = new THREE.Scene();
  14.  
  15.                 // Create a camera
  16.                 var camera = new THREE.PerspectiveCamera(75, container.offsetWidth / container.offsetHeight, 0.1, 1000);
  17.                 camera.position.z = 2;
  18.                
  19.  
  20.                 // Create a renderer
  21.                 var renderer = new THREE.WebGLRenderer({ alpha: true });
  22.                 renderer.setSize(container.offsetWidth, container.offsetHeight);
  23.                 renderer.setClearColor(0x000000, 0);
  24.                 container.appendChild(renderer.domElement);
  25.  
  26.                 // Create a cube geometry
  27.                 var geometry = new THREE.BoxGeometry();
  28.  
  29.                 // Create a material
  30.                 var material = new THREE.MeshBasicMaterial({ color: 0xFF202020 });
  31.  
  32.                 // Create a mesh (cube) with geometry and material
  33.                 var cube = new THREE.Mesh(geometry, material);
  34.                 scene.add(cube);
  35.  
  36.                 // Render the scene
  37.                 function render() {
  38.                     requestAnimationFrame(render);
  39.                     cube.rotation.x += 0.01;
  40.                     cube.rotation.y += 0.01;
  41.                     renderer.render(scene, camera);
  42.                 }
  43.                 render();
  44.  
  45.             }
Advertisement
Add Comment
Please, Sign In to add comment