Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dist/main-50df94adac52a08a7035.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/main-50df94adac52a08a7035.js.map

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions dist/main-94aa61a7cab659448779.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/main-94aa61a7cab659448779.js.map

This file was deleted.

2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@

label {
display: block;
}</style></head><body><main><div id="root"></div><div id="sceneContainer"><canvas id="scene"></canvas></div></main><script src="dist/536-40e5fff7416b638c6529.js"></script><script src="dist/main-94aa61a7cab659448779.js"></script></body></html>
}</style></head><body><main><div id="root"></div><div id="sceneContainer"><canvas id="scene"></canvas></div></main><script src="dist/536-40e5fff7416b638c6529.js"></script><script src="dist/main-50df94adac52a08a7035.js"></script></body></html>
4 changes: 4 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ export default {
avatarConfigChanged: "avatarConfigChanged",
exportAvatar: "exportAvatar",
resetView: "resetView",
saveView: "saveView",
deleteView: "deleteView",
goNextView: "goNextView",
goPreviousView: "goPreviousView",
};
77 changes: 72 additions & 5 deletions src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { GLTFExporter } from "three/examples/jsm/exporters/GLTFExporter";
import constants from "./constants";
import { exportAvatar } from "./export";
import { loadGLTF, forEachMaterial, generateEnvironmentMap, createSky } from "./utils";
import { createSnapshot, snapTo } from "./orbit-controls-utils";
import initialSnapshots from "./snapshots";

// TODO: Don't do this
function urlFor(value) {
Expand All @@ -29,6 +31,11 @@ const state = {
shouldApplyNewAvatarConfig: false,
shouldExportAvatar: false,
shouldResetView: false,
shouldSaveView: false,
shouldGoNextView: false,
shouldGoPreviousView: false,
snapshots: initialSnapshots,
viewIndex: 0,
};
window.gameState = state;

Expand All @@ -48,6 +55,34 @@ document.addEventListener(constants.exportAvatar, () => {
document.addEventListener(constants.resetView, () => {
state.shouldResetView = true;
});
document.addEventListener(constants.saveView, () => {
state.shouldSaveView = true;
});
document.addEventListener(constants.deleteView, () => {
state.shouldDeleteView = true;
});
document.addEventListener(constants.goNextView, () => {
state.shouldGoNextView = true;
});
document.addEventListener(constants.goPreviousView, () => {
state.shouldGoPreviousView = true;
});
document.addEventListener("keydown", (e) => {
switch (e.key.toLowerCase()) {
case "s":
document.dispatchEvent(new CustomEvent(constants.saveView));
break;
case "d":
document.dispatchEvent(new CustomEvent(constants.deleteView));
break;
case "k":
document.dispatchEvent(new CustomEvent(constants.goPreviousView));
break;
case "j":
document.dispatchEvent(new CustomEvent(constants.goNextView));
break;
}
});

function resetView() {
state.controls.reset();
Expand Down Expand Up @@ -134,11 +169,6 @@ function tick(time) {
}
}

{
const { renderer, scene, camera } = state;
renderer.render(scene, camera);
}

{
if (state.shouldApplyNewAvatarConfig) {
state.shouldApplyNewAvatarConfig = false;
Expand Down Expand Up @@ -177,6 +207,43 @@ function tick(time) {
}
}

if (state.shouldSaveView) {
state.shouldSaveView = false;
const { snapshots, controls } = state;
snapshots.push(createSnapshot(controls));
state.viewIndex = snapshots.length - 1;
}
if (state.shouldDeleteView) {
state.shouldDeleteView = false;
const { snapshots, controls } = state;
if (snapshots.length && state.viewIndex < snapshots.length) {
snapshots.splice(state.viewIndex, 1);
state.shouldGoPreviousView = true;
}
}

if (state.shouldGoNextView) {
state.shouldGoNextView = false;
const { snapshots, controls } = state;
if (snapshots.length) {
state.viewIndex = (state.viewIndex + 1) % snapshots.length;
snapTo(controls, snapshots[state.viewIndex]);
}
}
if (state.shouldGoPreviousView) {
state.shouldGoPreviousView = false;
const { snapshots, controls } = state;
if (snapshots.length) {
state.viewIndex = (state.viewIndex + snapshots.length - 1) % snapshots.length;
snapTo(controls, snapshots[state.viewIndex]);
}
}

{
const { renderer, scene, camera } = state;
renderer.render(scene, camera);
}

{
window.requestAnimationFrame(tick);
}
Expand Down
44 changes: 44 additions & 0 deletions src/snapshots.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
export default [
{ target: { x: 0, y: 0.5, z: 0 }, position: { x: 0, y: 0.25, z: 1.5 }, zoom: 1 },
{
target: { x: 0.02307116018084527, y: 0.6334402516427525, z: 0.022240041940458772 },
position: { x: 0.02307116018084527, y: 0.5176174441028143, z: 0.7171768871800882 },
zoom: 1,
},
{
target: { x: 0.09387002157314916, y: 0.546635562471844, z: 0.08014199094868098 },
position: { x: -0.3879717518873724, y: 0.4947348350813956, z: 0.5914999491959408 },
zoom: 1,
},
{
target: { x: -0.09493661261301585, y: 0.5639529591055843, z: 0.1055502022610856 },
position: { x: -0.671104818392942, y: 1.0921215489830267, z: -0.6936061291504049 },
zoom: 1,
},
{
target: { x: -0.008422856623338703, y: 0.4941459483505538, z: 0.10198716075212154 },
position: { x: -0.011493544628165472, y: 0.5417760987144405, z: -0.9057404120118234 },
zoom: 1,
},
{
target: { x: -0.008422856623338703, y: 0.4941459483505538, z: 0.10198716075212154 },
position: { x: 0.9967533644672771, y: 0.5785843629152699, z: 0.1188347112272661 },
zoom: 1,
},
{
target: { x: 0.04413113687842558, y: 0.49809272819211714, z: 0.06414813223383779 },
position: { x: 0.42686384587556403, y: 0.5905893343933903, z: 0.6053669965717776 },
zoom: 1,
},
{
target: { x: 0.41859185291264084, y: 0.31485181426204567, z: -0.08600123811976045 },
position: { x: 0.6482708508647577, y: 0.4157154496534844, z: 0.22650580642214352 },
zoom: 1,
},
{
target: { x: 0.018173720594482693, y: 0.44480533951578716, z: -0.15500048584516604 },
position: { x: 0.001957996317477624, y: 0.8078606430954935, z: 0.7318399779720074 },
zoom: 1,
},
{ target: { x: 0, y: 0.5, z: 0 }, position: { x: 0, y: 0.35779997693088517, z: 0.8532001384146891 }, zoom: 1 },
];