BIN
static/secrets/finger.png
Normal file
BIN
static/secrets/finger.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.4 MiB |
BIN
static/secrets/paw.png
Normal file
BIN
static/secrets/paw.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 MiB |
@@ -9,9 +9,14 @@ const light = new THREE.HemisphereLight(0xeeeeff, 0x777788, 2.5);
|
|||||||
const controls = new PointerLockControls(camera, renderer.domElement);
|
const controls = new PointerLockControls(camera, renderer.domElement);
|
||||||
const scene = new THREE.Scene();
|
const scene = new THREE.Scene();
|
||||||
const clock = new THREE.Clock();
|
const clock = new THREE.Clock();
|
||||||
const loader = new GLTFLoader();
|
|
||||||
const keyMap = {}
|
const keyMap = {}
|
||||||
|
|
||||||
|
// 3D Loaders.
|
||||||
|
const room = new GLTFLoader();
|
||||||
|
const image = new THREE.TextureLoader();
|
||||||
|
|
||||||
|
let pawTexture, fingerTexture, currentSprite;
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
//Initialisation
|
//Initialisation
|
||||||
@@ -40,12 +45,12 @@ function init() {
|
|||||||
document.addEventListener('keydown', onDocumentKey, false);
|
document.addEventListener('keydown', onDocumentKey, false);
|
||||||
document.addEventListener('keyup', onDocumentKey, false);
|
document.addEventListener('keyup', onDocumentKey, false);
|
||||||
|
|
||||||
// GLFT Loader
|
room.load(
|
||||||
loader.load(
|
|
||||||
// url of file
|
// url of file
|
||||||
'../test.gltf',
|
'../test.gltf',
|
||||||
// when resource is loaded
|
// when resource is loaded
|
||||||
function(gltf) {
|
function(gltf) {
|
||||||
|
gltf.scene.position.y = -1;
|
||||||
scene.add(gltf.scene);
|
scene.add(gltf.scene);
|
||||||
|
|
||||||
gltf.animations;
|
gltf.animations;
|
||||||
@@ -63,18 +68,50 @@ function init() {
|
|||||||
console.log('a fucking error lmao: ', error);
|
console.log('a fucking error lmao: ', error);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
image.load('../paw.png', (texture) => {
|
||||||
|
pawTexture = texture;
|
||||||
|
image.load('../finger.png', (texture) => {
|
||||||
|
fingerTexture = texture;
|
||||||
|
const material = new THREE.SpriteMaterial({ map: texture });
|
||||||
|
currentSprite = new THREE.Sprite(material);
|
||||||
|
currentSprite.position.set(1, -0.7, -1.5);
|
||||||
|
camera.add(currentSprite);
|
||||||
|
scene.add(camera);
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function animate() {
|
function animate() {
|
||||||
const delta = clock.getDelta();
|
const delta = clock.getDelta();
|
||||||
|
|
||||||
if (controls.isLocked) {
|
if (controls.isLocked) {
|
||||||
if (keyMap['KeyW']) controls.moveForward(delta * 5);
|
if (keyMap['KeyW']) {
|
||||||
if (keyMap['KeyS']) controls.moveForward(-delta * 5);
|
controls.moveForward(delta * 5);
|
||||||
if (keyMap['KeyA']) controls.moveRight(-delta * 5);
|
}
|
||||||
if (keyMap['KeyD']) controls.moveRight(delta * 5);
|
if (keyMap['KeyS']) {
|
||||||
|
controls.moveForward(-delta * 5);
|
||||||
|
}
|
||||||
|
if (keyMap['KeyA']) {
|
||||||
|
controls.moveRight(-delta * 5);
|
||||||
|
}
|
||||||
|
if (keyMap['KeyD']) {
|
||||||
|
controls.moveRight(delta * 5);
|
||||||
|
}
|
||||||
|
if (keyMap['ShiftLeft']) {
|
||||||
|
if (currentSprite && fingerTexture && currentSprite.material.map !== fingerTexture) {
|
||||||
|
currentSprite.material.map = fingerTexture;
|
||||||
|
console.log("finger up");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (currentSprite && pawTexture && currentSprite.material.map !== pawTexture) {
|
||||||
|
currentSprite.material.map = pawTexture;
|
||||||
|
console.log("finger down");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.render(scene, camera);
|
renderer.render(scene, camera);
|
||||||
}
|
}
|
||||||
renderer.setAnimationLoop(animate);
|
renderer.setAnimationLoop(animate);
|
||||||
|
|||||||
Reference in New Issue
Block a user