-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
172 lines (123 loc) · 4.22 KB
/
main.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import * as THREE from 'three'
import { WebGL } from 'three/examples/jsm/Addons.js'
// import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'
import { GLTFLoader} from 'three/examples/jsm/loaders/GLTFLoader.js'
// import { element } from 'three/examples/jsm/nodes/Nodes.js'
// Scene
const scene = new THREE.Scene()
const gltfLoader = new GLTFLoader()
const canvas = document.querySelector('.webgl')
const left = document.querySelector('.left')
const hero = document.querySelector('.hero')
// Camera
const sizes = {
width: canvas.clientWidth,
height: canvas.clientHeight
}
// window.addEventListener('resize', () =>
// {
// // Update sizes
// sizes.width = window.innerWidth
// sizes.height = window.innerHeight
// // Update camera
// camera.aspect = sizes.width / sizes.height
// camera.updateProjectionMatrix()
// // Update renderer
// renderer.setSize(sizes.width, sizes.height)
// renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
// })
const camera = new THREE.PerspectiveCamera(75, sizes.width / sizes.height)
camera.position.x = 0
camera.position.y = 1.2
camera.position.z = 1
// camera.lookAt(gltfLoader) // This line seems incorrect, should be a target
scene.add(camera)
// const controls = new OrbitControls(camera, canvas)
// controls.enableDamping = false
/**
* Lights
*/
const ambientLight = new THREE.AmbientLight(0xffffff, 0.8)
scene.add(ambientLight)
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.6)
// directionalLight.castShadow = true
// directionalLight.shadow.mapSize.set(1024, 1024)
// directionalLight.shadow.camera.far = 15
// directionalLight.shadow.camera.left = - 7
// directionalLight.shadow.camera.top = 7
// directionalLight.shadow.camera.right = 7
// directionalLight.shadow.camera.bottom = - 7
// directionalLight.position.set(- 5, 5, 0)
scene.add(directionalLight)
//Load GLTF
let mixer = null
gltfLoader.load(
'/static/3d/pastry chef animated.glb',
(gltf) =>
{
//const children = [...gltf.scene.children]
//for (const child of children)
//{
// scene.add(child)
//}
mixer = new THREE.AnimationMixer(gltf.scene)
const action = mixer.clipAction(gltf.animations[0])
action.play()
gltf.scene.scale.set(1.5, 1.5, 1.5)
scene.add(gltf.scene)
// // Calculate the center of the model's bounding box
// const box = new THREE.Box3().setFromObject(gltf.scene)
// const center = box.getCenter(new THREE.Vector3())
// // Position the camera to look at the center of the model
// camera.position.set(center.x, center.y, center.z + 3) // Adjust the distance as needed
// camera.lookAt(center)
}
)
// Renderer
const renderer = new THREE.WebGLRenderer({
canvas: canvas
})
renderer.setSize(sizes.width, sizes.height)
renderer.setClearColor(0x000000, 0); // Set the clear color and alpha to 0
renderer.premultiplyAlpha = false;
// Animate
const clock = new THREE.Clock()
let previousTime = 0
const tick = () =>
{
const elapsedTime = clock.getElapsedTime()
const deltaTime = elapsedTime - previousTime
previousTime = elapsedTime
// Update objects
//mesh.rotation.y = elapsedTime;
//update camera
//camera.position.x = cursor.x * 10
//camera.position.y = cursor.y * 10
//camera.lookAt(mesh.position)
//Update mixer
if(mixer !== null){
mixer.update(deltaTime)
}
// controls.update()
// Render
renderer.render(scene, camera)
// Call tick again on the next frame
window.requestAnimationFrame(tick)
}
tick()
const scrollers = document.querySelectorAll(".diplomas");
if(!window.matchMedia("(prefers-reduced-motion: reduce)").matches){
addAnimation();
}
function addAnimation(){
scrollers.forEach((diplomas) => {
diplomas.setAttribute('data-animated', true);
const dipin = diplomas.querySelector('.dipin');
const scrollerContent = Array.from(dipin.children);
scrollerContent.forEach((item) => {
const duplicatedItem = item.cloneNode(true);
duplicatedItem.setAttribute('aria-hidden', true);
dipin.appendChild(duplicatedItem);
})
})
}