Skip to content

Commit

Permalink
Merge pull request #581 from KhronosGroup/feature/IBLcredits
Browse files Browse the repository at this point in the history
Feature/ibl credits
  • Loading branch information
UX3D-labode authored Oct 28, 2024
2 parents 4fe509d + ead6619 commit 686b6fa
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ <h2 class="title is-spaced">Animation</h2>
<h2 class="title">Model Credits</h2>
<div class="modelCredit"><i>Copyright:</i><br/>{{ assetCopyright }}</div>
<div class="modelCredit"><i>Generated by:</i><br/>{{ assetGenerator }}</div>
<h2 class="title">Environment Credits</h2>
<div class="modelCredit"><i>Copyright:</i><br/><p v-html="environmentLicense"></p></div>
<h3 class="title">{{ xmp ? "XMP" : "" }}</h3>
<json-to-ui-template v-bind:data="xmp" v-bind:isinner="false"></json-to-ui-template>
</div>
Expand Down
37 changes: 33 additions & 4 deletions src/logic/uimodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class UIModel
this.environmentRotation = app.environmentRotationChanged.pipe();
this.app.environments = environments;
const selectedEnvironment = app.selectedEnvironmentChanged.pipe(
map(environmentName => this.app.environments[environmentName].hdr_path)
map(environmentName => this.app.environments[environmentName])
);
const initialEnvironment = "Cannon_Exterior";
this.app.selectedEnvironment = initialEnvironment;
Expand Down Expand Up @@ -111,12 +111,40 @@ class UIModel
);

this.model = merge(dropdownGltfChanged, dropdownFlavourChanged, inputObservables.droppedGltf);

this.hdr = merge(selectedEnvironment, this.addEnvironment, inputObservables.droppedHdr).pipe(
startWith(environments[initialEnvironment].hdr_path)
startWith(environments[initialEnvironment])
);

this.hdr.subscribe(async hdr => {
if (hdr.license_path !== undefined) {
try {
const response = await fetch(hdr.license_path);
if (!response.ok) {
throw new Error("License file not found");
}
let text = await response.text();
const license = text.split("SPDX-License-Identifier: ")[1];
console.log(license);
text = text.replace("SPDX-FileCopyrightText: ", "");
text = text.replace(/SPDX-License-Identifier:(.)*/g, `, <a href="${hdr.hdr_path}">Source</a>, License: `);
text += `<a href="${hdr.base_path}/LICENSES/${license}.txt">${license}</a>`;
text = "(c) " + text;
text = text.replaceAll("\n","");
text = text.replaceAll(" ,", ",");
this.app.environmentLicense = text;
} catch (error) {
this.app.environmentLicense = "N/A";
}

} else {
this.app.environmentLicense = "N/A";
}
});

merge(this.addEnvironment, inputObservables.droppedHdr)
.subscribe(hdrPath => {
.subscribe(hdr => {
const hdrPath = hdr.hdr_path;
this.app.environments[hdrPath.name] = {
title: hdrPath.name,
hdr_path: hdrPath,
Expand Down Expand Up @@ -285,7 +313,8 @@ const getInputObservables = (inputElement, app) => {
observables.droppedHdr = droppedFiles.pipe(
map(files => files.find(([path]) => path.endsWith(".hdr"))),
filter(file => file !== undefined),
pluck("1")
pluck("1"),
map(file => ({hdr_path: file}))
);

const mouseMove = fromEvent(document, 'mousemove');
Expand Down
4 changes: 2 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ export default async () => {
);
listenForRedraw(uiModel.activeAnimations);

uiModel.hdr.subscribe((hdrFile) => {
resourceLoader.loadEnvironment(hdrFile).then((environment) => {
uiModel.hdr.subscribe((hdr) => {
resourceLoader.loadEnvironment(hdr.hdr_path).then((environment) => {
state.environment = environment;
// We need to wait until the environment is loaded to redraw
redraw = true;
Expand Down
4 changes: 3 additions & 1 deletion src/model_path_provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ export function fillEnvironmentWithPaths(environmentNames, environmentsBasePath)
index: index,
title: title,
hdr_path: environmentsBasePath + name + ".hdr",
jpg_path: environmentsBasePath + name + ".jpg"
jpg_path: environmentsBasePath + name + ".jpg",
license_path: environmentsBasePath + name + ".hdr.license",
base_path: environmentsBasePath
};
});
return environmentNames;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ const appCreated = createApp({
},
onFileChange(e) {
const file = e.target.files[0];
this.addEnvironmentChanged.next(file);
this.addEnvironmentChanged.next({hdr_path: file});
},

toggleUI() {
Expand Down

0 comments on commit 686b6fa

Please sign in to comment.