-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmario3d.js
More file actions
87 lines (73 loc) · 2.38 KB
/
mario3d.js
File metadata and controls
87 lines (73 loc) · 2.38 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
// Ensure ThreeJS is in global scope for the 'examples/'
global.THREE = require("three");
require("three/examples/js/loaders/GLTFLoader");
// Include any additional ThreeJS examples below
require("three/examples/js/controls/OrbitControls");
const canvasSketch = require("canvas-sketch");
const settings = {
// Make the loop animated
animate: true,
alpha: true,
// Get a WebGL canvas rather than 2D
context: "webgl",
dimensions: [300, 300],
};
const sketch = ({ canvas, context }) => {
// Create a renderer
const renderer = new THREE.WebGLRenderer({
canvas: context.canvas,
});
// WebGL background color
renderer.setClearColor("#000", 0);
// Setup a camera
const camera = new THREE.PerspectiveCamera(50, 1, 0.01, 10000);
camera.position.set(0, 0, -4);
camera.lookAt(new THREE.Vector3());
// Setup camera controller
// const controls = new THREE.OrbitControls(camera, context.canvas);
// Setup your scene
const scene = new THREE.Scene();
scene.add(new THREE.AmbientLight(0xcccccc));
const light = new THREE.DirectionalLight(0xcccccc);
light.position.set(-100, 100, 100);
scene.add(light);
const loader = new THREE.GLTFLoader();
loader.load("./mario/scene.gltf", (gltf) => {
console.log(gltf);
scene.add(gltf.scene);
});
const mouse = new THREE.Vector2();
window.addEventListener("mousemove", (event) => {
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
console.log(mouse);
});
const img = new Image();
img.src = "./mario/metamask.png";
document.body.appendChild(img);
canvas.style.position = "fixed";
canvas.style.top = "20%";
// draw each frame
return {
// Handle resize events here
resize({ pixelRatio, viewportWidth, viewportHeight }) {
renderer.setPixelRatio(pixelRatio);
renderer.setSize(viewportWidth, viewportHeight, false);
camera.aspect = viewportWidth / viewportHeight;
camera.updateProjectionMatrix();
},
// Update & render your scene here
render({ time }) {
// controls.update();
camera.position.set(-mouse.x * 4, -mouse.y * 4, 12);
camera.lookAt(scene.position);
renderer.render(scene, camera);
},
// Dispose of events & renderer for cleaner hot-reloading
unload() {
// controls.dispose();
renderer.dispose();
},
};
};
canvasSketch(sketch, settings);