-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
97 lines (71 loc) · 2.52 KB
/
scripts.js
File metadata and controls
97 lines (71 loc) · 2.52 KB
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
import * as THREE from 'three';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
import * as dat from 'dat.gui';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
const monkeyUrl = new URL('../assets/monkey.glb', import.meta.url);
const renderer = new THREE.WebGL1Renderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
45,
window.innerWidth / window.innerHeight,
0.1,
1000
);
const orbit = new OrbitControls(camera, renderer.domElement);
const axesHelper = new THREE.AxesHelper(3);
scene.add(axesHelper);
camera.position.set(-10, 30, 30);
orbit.update();
const assetLoader = new GLTFLoader();
assetLoader.load(monkeyUrl.href, function (gltf) {
const model = gltf.scene;
// Scale up the model
model.scale.set(40, 40, 40); // Adjust the scale factor as needed
// Position the model at the axes
model.position.set(0, 5, 0); // Adjust the position as needed
scene.add(model);
}, undefined, function (error) {
console.error(error);
});
const gridHelper = new THREE.GridHelper(30);
scene.add(gridHelper);
const sphereGeometry = new THREE.SphereGeometry(4, 50, 50);
const sphereMaterial = new THREE.MeshStandardMaterial({
color: 'blue',
wireframe: false
});
const sphere = new THREE.Mesh(sphereGeometry, sphereMaterial);
scene.add(sphere);
sphere.position.set(-10, 14, 0);
const ambientLight = new THREE.AmbientLight(0x3333333333333333333333);
scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xFFFFFF, 5);
scene.add(directionalLight);
const gui = new dat.GUI();
const options = {
sphereColor: '#ffea00',
wireframe: false,
speed: 0.01
};
gui.addColor(options, 'sphereColor').onChange(function (e) {
sphere.material.color.set(e);
});
gui.add(options, 'wireframe').onChange(function (e) {
sphere.material.wireframe = e;
})
gui.add(options, 'speed', 0, 0.1);
let step = 0;
let speed = 0.01;
function animate(time) {
step += options.speed;
sphere.position.y = 10 * Math.abs(Math.sin(step));
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
window.addEventListener('resize', function () {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});