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
15 changes: 7 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"react": "^17.0.1",
"react-dom": "^17.0.1",
"simplebar-react": "^2.3.0",
"three": "^0.125.2"
"three": "^0.141.0"
}
}
2 changes: 1 addition & 1 deletion src/create-texture-atlas.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const createTextureAtlas = (function () {
context.globalCompositeOperation = image ? "multiply" : "source-over";

const colorClone = mesh.material.color.clone();
colorClone.convertLinearToGamma();
colorClone.convertLinearToSRGB();

context.fillStyle = `#${colorClone.getHexString()}`;
context.fillRect(min.x * ATLAS_SIZE_PX, min.y * ATLAS_SIZE_PX, tileSize, tileSize);
Expand Down
12 changes: 10 additions & 2 deletions src/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,16 @@ export function combineHubsComponents(a, b) {
export const exportGLTF = (function () {
const exporter = new GLTFExporter();
return function exportGLTF(object3D, { binary, animations }) {
return new Promise((resolve) => {
exporter.parse(object3D, (gltf) => resolve({ gltf }), { binary, animations });
return new Promise((resolve, reject) => {
exporter.parse(
object3D,
(gltf) => resolve({ gltf }),
(error) => {
console.error(error);
reject("Error exporting the avatar");
},
{ binary, animations }
);
});
};
})();
Expand Down
7 changes: 4 additions & 3 deletions src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ const state = {
};
window.gameState = state;

window.onresize = () => {
window.addEventListener("resize", () => {
state.shouldResize = true;
};
});
document.addEventListener(constants.reactIsLoaded, () => {
state.reactIsLoaded = true;
});
Expand Down Expand Up @@ -126,8 +126,9 @@ function init() {

// TODO: Square this with react
const renderer = new THREE.WebGLRenderer({ canvas: document.getElementById("scene"), antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.physicallyCorrectLights = true;
renderer.gammaOutput = true;
renderer.outputEncoding = THREE.sRGBEncoding;
state.renderer = renderer;

state.clock = new THREE.Clock();
Expand Down
6 changes: 3 additions & 3 deletions src/merge-geometry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as THREE from "three";
import { BufferGeometryUtils } from "three/examples/jsm/utils/BufferGeometryUtils";
import { mergeBufferAttributes } from "three/examples/jsm/utils/BufferGeometryUtils";
import constants from "./constants";
import { GLTFCubicSplineInterpolant } from "./gltf-cubic-spline-interpolant";

Expand Down Expand Up @@ -39,7 +39,7 @@ function mergeSourceAttributes({ sourceAttributes }) {

const destAttributes = {};
Array.from(propertyNames.keys()).map((name) => {
destAttributes[name] = BufferGeometryUtils.mergeBufferAttributes(
destAttributes[name] = mergeBufferAttributes(
allSourceAttributes.map((sourceAttributes) => sourceAttributes[name]).flat()
);
});
Expand Down Expand Up @@ -103,7 +103,7 @@ function mergeSourceMorphAttributes({
propertyNames.forEach((propName) => {
merged[propName] = [];
Object.entries(destMorphTargetDictionary).forEach(([morphName, destMorphIndex]) => {
merged[propName][destMorphIndex] = BufferGeometryUtils.mergeBufferAttributes(unmerged[propName][destMorphIndex]);
merged[propName][destMorphIndex] = mergeBufferAttributes(unmerged[propName][destMorphIndex]);
});
});

Expand Down
15 changes: 15 additions & 0 deletions src/mesh-combination.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ export async function combine({ avatar }) {
delete geometry.attributes[`morphTarget${i}`];
delete geometry.attributes[`morphNormal${i}`];
}
// Computing tangents that was done in GLTFLoader in threejs 0.125.2 was removed in threejs r126 (https://github.com/mrdoob/three.js/pull/21186)
// The mergeSourceAttributes function will crash because it can't find the tangent attribute on some geometry.
// So putting back here the code that was executed in GLTFLoader 0.125.2:
const material = mesh.material;
if (
material.isMeshStandardMaterial === true &&
material.side === THREE.DoubleSide &&
geometry.getIndex() !== null &&
geometry.hasAttribute("position") === true &&
geometry.hasAttribute("normal") === true &&
geometry.hasAttribute("uv") === true &&
geometry.hasAttribute("tangent") === false
) {
geometry.computeTangents();
}
});

const { source, dest } = mergeGeometry({ meshes });
Expand Down
9 changes: 6 additions & 3 deletions src/react-components/AvatarEditorContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ export function AvatarEditorContainer() {
});

// TODO: Save the wave to a static image, or actually do some interesting animation with it.
useEffect(async () => {
if (canvasUrl === null) {
setCanvasUrl(await generateWave());
useEffect(() => {
async function init() {
if (canvasUrl === null) {
setCanvasUrl(await generateWave());
}
}
init();
});

function updateAvatarConfig(newConfig) {
Expand Down
4 changes: 2 additions & 2 deletions src/react-components/ToolbarContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export function ToolbarContainer({ onGLBUploaded, randomizeConfig }) {
</button>
</div>
<div className="toolbarNotice">
<span>The 3D models used in this app are ©2020-2022 by individual <a href="https://www.mozilla.org" target="_blank" noreferrer>mozilla.org</a> contributors.
Content available under a <a href="https://www.mozilla.org/en-US/foundation/licensing/website-content/" target="_blank" noreferrer>Creative Commons license</a>.</span>
<span>The 3D models used in this app are ©2020-2022 by individual <a href="https://www.mozilla.org" target="_blank" rel="noreferrer">mozilla.org</a> contributors.
Content available under a <a href="https://www.mozilla.org/en-US/foundation/licensing/website-content/" target="_blank" rel="noreferrer">Creative Commons license</a>.</span>
</div>
</Toolbar>
);
Expand Down