-
Notifications
You must be signed in to change notification settings - Fork 0
/
cube.js
49 lines (41 loc) · 1.29 KB
/
cube.js
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
import * as THREE from "three";
// Create scene, camera, and renderer
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
0.1,
1000,
);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Load grain texture
const textureLoader = new THREE.TextureLoader();
const grainTexture = textureLoader.load("textures/grain.jpg");
// Create a cube geometry
const geometry = new THREE.BoxGeometry();
// Create material with grain texture and tint color
const material = new THREE.MeshStandardMaterial({
map: grainTexture,
color: 0x008080, // Tint color (you can change this to any color)
});
// Create the cube
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);
// Position camera
camera.position.z = 5;
// Lighting (optional for better material shading)
const ambientLight = new THREE.AmbientLight(0xffffff, 1000);
scene.add(ambientLight);
const pointLight = new THREE.PointLight(0xffffff, 1);
pointLight.position.set(10, 10, 10);
scene.add(pointLight);
// Animation loop
function animate() {
requestAnimationFrame(animate);
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
renderer.render(scene, camera);
}
animate();