-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscene2.js
106 lines (94 loc) · 3.34 KB
/
scene2.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import * as THREE from "three";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
let orb;
const clock = new THREE.Clock();
export const scene2 = async (scene, posZ) => {
let sceneEmpty = new THREE.Group();
sceneEmpty.position.set(0, 0, -posZ - 25);
scene.add(sceneEmpty);
const GLTLoader = new GLTFLoader();
GLTLoader.load(
`${import.meta.env.BASE_URL}assets/Mountains.glb`,
(gltf) => {
const mountain = gltf.scene;
mountain.position.set(0, -200, 0);
sceneEmpty.add(mountain);
// Create a 3x3 grid of instances
const distance = 900;
for (let i = -1; i <= 1; i++) {
for (let j = -1; j <= 1; j++) {
if (i === 0 && j === 0) continue; // Skip the original mountain
const mountainClone = mountain.clone();
mountainClone.position.set(
i * distance,
-200,
j * distance,
);
sceneEmpty.add(mountainClone);
}
}
},
);
const orbGeometry = new THREE.SphereGeometry(4, 64, 32);
const orbMaterial = new THREE.MeshPhysicalMaterial({
color: 0x888888,
roughness: 0.4,
reflectivity: 1,
clearcoat: 1,
clearcoatRoughness: 0.1,
sheen: 1,
sheenRoughness: 0.4,
sheenColor: 0xffffff,
emissive: 0xe6fff2,
emissiveIntensity: 0.1,
});
orb = new THREE.Mesh(orbGeometry, orbMaterial);
orb.position.set(0, 7, 0);
orb.castShadow = true;
sceneEmpty.add(orb);
const light = new THREE.PointLight(0xe6fff2, 100, 0, 3);
const lightHelper = new THREE.PointLightHelper(light);
light.position.set(0, 2, -5);
orb.add(light);
const groundGeometry = new THREE.BoxGeometry(0.3, 50, 0.2);
const groundMaterial = new THREE.MeshStandardMaterial({
emissive: 0xe6fff2,
emissiveIntensity: 0.05,
});
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
ground.rotateX(-Math.PI / 2);
ground.position.set(0, -0.1, 0);
ground.receiveShadow = true;
sceneEmpty.add(ground);
const doorGeometry = new THREE.PlaneGeometry(1.25, 2);
const doorMaterial = new THREE.MeshStandardMaterial({
color: 0x000000,
roughness: 0.2,
depthWrite: false,
});
const door = new THREE.Mesh(doorGeometry, doorMaterial);
door.position.set(0, 1, -25);
door.receiveShadow = true;
door.castShadow = true;
sceneEmpty.add(door);
let chair;
GLTLoader.load(`${import.meta.env.BASE_URL}assets/Chair.glb`, (gltf) => {
chair = gltf.scene;
chair.traverse((child) => {
if (child.isMesh) {
child.material.normalMap = null;
child.material.color = new THREE.Color(0xffffff);
}
});
chair.position.set(0, 0, -32);
chair.rotateY((Math.PI / 4) * 4.5);
sceneEmpty.add(chair);
const chairLight = new THREE.PointLight(0xffffff, 5, 0, 3);
const chairLightHelper = new THREE.PointLightHelper(chairLight);
chairLight.position.set(0, 1, 0.5);
chair.add(chairLight);
});
};
export const animateScene2 = () => {
orb.position.y = Math.sin(clock.getElapsedTime() / 2) + 7;
};