Skip to content

Commit

Permalink
Preprocessing changes and fixes in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
struffel committed Apr 10, 2023
1 parent b741b15 commit 3678648
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 44 deletions.
8 changes: 7 additions & 1 deletion src/js/common/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export function start(initializationFunction,preprocessingFunction,updateFunctio
window.addEventListener('hashchange', (e) =>{
var parsedHashString = MISC.parseHashString();
var oldAndNew = SCENE_CONFIGURATION.updateConfiguration(parsedHashString,CONSTANTS.updateMode.extendCurrent);

// Perform preprocessing
if(preprocessingFunction){
oldAndNew.new = preprocessingFunction(oldAndNew.new);
}

updateFunction(oldAndNew.old,oldAndNew.new);

GUI.updateGuiFromCurrentSceneConfiguration();
Expand All @@ -33,7 +39,7 @@ export function start(initializationFunction,preprocessingFunction,updateFunctio

// Perform the initial loading by simulating a change in the hashstring.
var initConfiguration = MISC.parseHashString();
var oldAndNew = SCENE_CONFIGURATION.updateConfiguration(initConfiguration,CONSTANTS.updateMode.startFromDefault);
var oldAndNew = SCENE_CONFIGURATION.updateConfiguration(initConfiguration,CONSTANTS.updateMode.startFromFoundation);

// Perform preprocessing
if(preprocessingFunction){
Expand Down
2 changes: 1 addition & 1 deletion src/js/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as THREE from '../threejs/three.module.js';
*/
export const updateMode = {
"extendCurrent":0, // Merges with the current configuration
"startFromDefault":1,
"startFromFoundation":1,
"resetSelected":2
}

Expand Down
26 changes: 13 additions & 13 deletions src/js/common/scene-configuration.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as CONSTANTS from "./constants.js";

var defaultConfiguration = {
var foundationalConfiguration = {
"watermark_enable":['2'],
"gui_enable":['1']
};
Expand All @@ -10,34 +10,34 @@ var currentConfiguration;

/**
*
* @param {*} newDefaultConfiguration
* @param {*} newFoundationalConfiguration
*/
export function initializeConfiguration(newDefaultConfiguration){
export function initializeConfiguration(newFoundationalConfiguration){
if(!defaultDefinied){
currentConfiguration = {};
console.debug("Initialize scene",newDefaultConfiguration);
console.debug("Initialize scene",newFoundationalConfiguration);

for(const key in newDefaultConfiguration){
defaultConfiguration[key] = [].concat(newDefaultConfiguration[key]);
for(const key in newFoundationalConfiguration){
foundationalConfiguration[key] = [].concat(newFoundationalConfiguration[key]);
}

console.debug("Default is now:", defaultConfiguration);
console.debug("Foundation is now:", foundationalConfiguration);
console.debug("Current is now:",currentConfiguration);
defaultDefinied = true;
}else{
throw "Can't redefine default configuration.";
throw "Can't redefine foundational configuration.";
}
}

export function resetConfigurationKey(key){
currentConfiguration[key] = defaultConfiguration[key];
currentConfiguration[key] = foundationalConfiguration[key];
return currentConfiguration[key];
}

/**
* Takes in changes to the scene configuration, processes them and returns the new current scene configuration.
* @param {*} configurationChanges
* @param {CONSTANTS.updateMode} startFromDefault
* @param {CONSTANTS.updateMode} startFromFoundation
* @param {Boolean} resetValues Reset the keys supplied on the 'configurationChanges' object to their default value.
* @returns
*/
Expand All @@ -57,11 +57,11 @@ export function updateConfiguration(configurationChanges,mode){
case CONSTANTS.updateMode.resetSelected:
var newConfiguration = structuredClone(currentConfiguration);
for(const key in configurationChanges){
newConfiguration[key] = [].concat(defaultConfiguration[key]);
newConfiguration[key] = [].concat(foundationalConfiguration[key]);
};
break;
case CONSTANTS.updateMode.startFromDefault:
var newConfiguration = structuredClone(defaultConfiguration);
case CONSTANTS.updateMode.startFromFoundation:
var newConfiguration = structuredClone(foundationalConfiguration);
for(const key in configurationChanges){
newConfiguration[key] = [].concat(configurationChanges[key]);
};
Expand Down
16 changes: 11 additions & 5 deletions src/js/views/hdri-exposure.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@ var scene, renderer, camera, previewPlane;

function preprocessSceneConfiguration(sceneConfiguration){

// No environment specified
if(sceneConfiguration.environment_url.length == 0){
sceneConfiguration.environment_url = ["./media/env-placeholder.exr"];
sceneConfiguration.environment_name = ["Placeholder"];
}

// More URLs than names
if(sceneConfiguration.environment_url.length > sceneConfiguration.environment_name.length && sceneConfiguration.environment_url.length > 1){
//MESSAGE.newWarning("Not all environments have a name.");
MESSAGE.newWarning("Not all environments have a name.");
sceneConfiguration.environment_name = MISC.padArray(sceneConfiguration.environment_name,sceneConfiguration.environment_url.length,"Unnamed HDRI");
}

// More names than URLs
else if(sceneConfiguration.environment_url.length < sceneConfiguration.environment_name.length){
//MESSAGE.newWarning("More env. names than URLs have been defined.")
MESSAGE.newWarning("More env. names than URLs have been defined.")
sceneConfiguration.environment_name = sceneConfiguration.environment_name.slice(0,sceneConfiguration.environment_url.length);
}

Expand Down Expand Up @@ -71,7 +77,7 @@ function updateScene(oldSceneConfiguration,newSceneConfiguration){

var envUrlChanged = !SCENE_CONFIGURATION.equalAtKey(oldSceneConfiguration,newSceneConfiguration,"environment_url");

if(envIndexChanged || envUrlChanged){
if( envIndexChanged || envUrlChanged ){
var envUrl = newSceneConfiguration["environment_url"][newSceneConfiguration.environment_index];
console.info("New environment will be loaded from URL",envUrl);

Expand Down Expand Up @@ -116,8 +122,8 @@ function initializeScene(){
SCENE_CONFIGURATION.initializeConfiguration({
"environment_tonemapping" : "linear",
"environment_exposure" : 0.0,
"environment_url" : ["./media/env-riverbed-lq.exr"],
"environment_name": ["Riverbed"],
"environment_url" : [],
"environment_name": [],
"environment_index":0
});

Expand Down
4 changes: 2 additions & 2 deletions src/js/views/hdri-shading.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ function preprocessSceneConfiguration(sceneConfiguration){

// More URLs than names
if(sceneConfiguration.environment_url.length > sceneConfiguration.environment_name.length && sceneConfiguration.environment_url.length > 1){
//MESSAGE.newWarning("Not all environments have a name.");
MESSAGE.newWarning("Not all environments have a name.");
sceneConfiguration.environment_name = MISC.padArray(sceneConfiguration.environment_name,sceneConfiguration.environment_url.length,"Unnamed HDRI");
}

// More names than URLs
else if(sceneConfiguration.environment_url.length < sceneConfiguration.environment_name.length){
//MESSAGE.newWarning("More env. names than URLs have been defined.")
MESSAGE.newWarning("More env. names than URLs have been defined.")
sceneConfiguration.environment_name = sceneConfiguration.environment_name.slice(0,sceneConfiguration.environment_url.length);
}

Expand Down
28 changes: 22 additions & 6 deletions src/js/views/material-shading.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,32 @@ import * as SCENE_CONFIGURATION from "../common/scene-configuration.js";
import * as CONSTANTS from "../common/constants.js";
import * as THREE_ACTIONS from "../common/three-actions.js";
import * as LOADINGNOTE from "../common/loading.js";
import * as MESSAGE from "../common/message.js";

var scene, camera, renderer, mesh, controls, textureLoader;

function preprocessSceneConfiguration(sceneConfiguration){

// No environment specified, use default
if(sceneConfiguration.environment_url.length == 0 && sceneConfiguration.environment_name.length == 0){
sceneConfiguration.environment_url = ["./media/env-studio-lq.exr","./media/env-dune-lq.exr","./media/env-forest-lq.exr","./media/env-field-lq.exr","./media/env-lab-lq.exr","./media/env-night-lq.exr"];
sceneConfiguration.environment_name = ["Studio","Dune","Forest","Field","Computer Lab","Night"];
}

// Environment Index too high
if(sceneConfiguration.environment_index >= sceneConfiguration.environment_url.length){
sceneConfiguration.environment_index = 0;
}

// More environment URLs than names
if(sceneConfiguration.environment_url.length > sceneConfiguration.environment_name.length && sceneConfiguration.environment_url.length > 1){
//MESSAGE.newWarning("Not all environments have a name.");
MESSAGE.newWarning("Not all environments have a name.");
sceneConfiguration.environment_name = MISC.padArray(sceneConfiguration.environment_name,sceneConfiguration.environment_url.length,"Unnamed HDRI");
}

// More environment names than URLs
else if(sceneConfiguration.environment_url.length < sceneConfiguration.environment_name.length){
//MESSAGE.newWarning("More env. names than URLs have been defined.");
MESSAGE.newWarning("More env. names than URLs have been defined.");
sceneConfiguration.environment_name = sceneConfiguration.environment_name.slice(0,sceneConfiguration.environment_url.length);
}

Expand All @@ -39,17 +51,21 @@ function preprocessSceneConfiguration(sceneConfiguration){
var numberOfMaterialNames = sceneConfiguration.material_name.length;

if(numberOfMaterials > numberOfMaterialNames && numberOfMaterials > 1){
//MESSAGE.newWarning("More env. names than URLs have been defined.");
MESSAGE.newWarning("More env. names than URLs have been defined.");
sceneConfiguration.material_name = MISC.padArray(sceneConfiguration.material_name,sceneConfiguration.material_url.length,"Unnamed Material");
}

// More names than materials

if(numberOfMaterials < numberOfMaterialNames){
//MESSAGE.newWarning("More env. names than URLs have been defined.");
MESSAGE.newWarning("More env. names than URLs have been defined.");
sceneConfiguration.material_name = sceneConfiguration.material_name.slice(0,numberOfMaterials);
}

if(sceneConfiguration.material_index >= numberOfMaterials){
sceneConfiguration.material_index = 0;
}

return sceneConfiguration;
}

Expand Down Expand Up @@ -241,9 +257,9 @@ function initializeScene(){
"opacity_url" : [],
"opacity_encoding" : "linear",

"environment_url" : ["./media/env-studio-lq.exr","./media/env-dune-lq.exr","./media/env-forest-lq.exr","./media/env-field-lq.exr","./media/env-lab-lq.exr","./media/env-night-lq.exr"],
"environment_url" : [],
"environment_index":0,
"environment_name":["Studio","Dune","Forest","Field","Computer Lab","Night"],
"environment_name":[],

"geometry_type" : "plane",
"geometry_subdivisions" : 500,
Expand Down
8 changes: 4 additions & 4 deletions src/js/views/texture-tiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as CONSTANTS from "../common/constants.js";
import * as BASE from "../common/base.js";
import * as SCENE_CONFIGURATION from "../common/scene-configuration.js";
import * as MISC from "../common/misc.js";

import * as MESSAGE from "../common/message.js";
var targetDomElement, mouseDown, backgroundPositionX, backgroundPositionY, backgroundSize, previousTouchX, previousTouchY;


Expand Down Expand Up @@ -43,13 +43,13 @@ function preprocessSceneConfiguration(sceneConfiguration){

// More texture URLs than names
if(sceneConfiguration.texture_url.length > sceneConfiguration.texture_name.length && sceneConfiguration.texture_url.length > 1){
//MESSAGE.newWarning("Not all environments have a name.");
MESSAGE.newWarning("Not all textures have a name.");
sceneConfiguration.texture_name = MISC.padArray(sceneConfiguration.texture_name,sceneConfiguration.texture_url.length,"Unnamed Texture");
}

// More texture names than URLs
else if(sceneConfiguration.texture_url.length < sceneConfiguration.texture_name.length){
//MESSAGE.newWarning("More env. names than URLs have been defined.");
MESSAGE.newWarning("More texture names than URLs have been defined.");
sceneConfiguration.texture_name = sceneConfiguration.texture_name.slice(0,sceneConfiguration.texture_url.length);
}

Expand All @@ -73,7 +73,7 @@ function initializeScene(){
"texture_size_min":32,
"texture_size_max":4096
});
SCENE_CONFIGURATION.updateConfiguration({},CONSTANTS.updateMode.startFromDefault);
SCENE_CONFIGURATION.updateConfiguration({},CONSTANTS.updateMode.startFromFoundation);

targetDomElement = document.querySelector('#renderer_target');
mouseDown = false;
Expand Down
12 changes: 4 additions & 8 deletions test/hdri-exposure-base.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ <h1><pre>hdri-exposure-base.html</pre></h1>
var base ="http://localhost:8080/hdri-exposure.html";
var configurations = {
"Plain (No parameters)": "",
"Load single | .EXR": "#"+JSON.stringify({
environment_url:"http://localhost:8081/test-media/env-lab-hq.exr"
}),
"Load single | .HDR": "#"+JSON.stringify({
environment_url:"http://localhost:8081/test-media/env-lab-hq.hdr"
}),
"Load single | Same domain as iframe (relative path)": "#environment_url=./media/env-full-forest-hq.exr",
"Load single | .EXR": "#environment_url=http://localhost:8081/test-media/env-lab-hq.exr",
"Load single | .HDR": "#environment_url=http://localhost:8081/test-media/env-lab-hq.hdr",
"Load single | Same domain as iframe (relative path)": "#environment_url=./media/env-forest-hq.exr",
"Load single | Different domain than iframe": "#environment_url=http://localhost:8081/test-media/env-lab-hq.exr",
"Load multiple | All working": "#environment_url=./media/env-full-forest-hq.exr,http://localhost:8081/test-media/env-lab-hq.exr&environment_name=Green Forest,University Lab",
"Load multiple | All working": "#environment_url=./media/env-forest-hq.exr,http://localhost:8081/test-media/env-lab-hq.exr&environment_name=Green Forest,University Lab",
"GUI | Hide on start": "#gui_enable=0",
"GUI | Hide completely": "#gui_enable=-1",
"Watermark | Large": "#watermark_enable=2",
Expand Down
8 changes: 4 additions & 4 deletions test/hdri-exposure-errors.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ <h1><pre>hdri-exposure-errors.html</pre></h1>
"Invalid URL | Poor syntax": "#environment_url=foo",
"Invalid URL | Invalid extension": "#environment_url=http://example.com/test.jpg",
"Invalid URL | File missing": "#environment_url=http://example.com/test.exr",
"Load multiple | First OK, second broken": "#environment_url=./media/env-full-forest-hq.exr;http://localhost:8081/test-media/XXXXXXXXXXXXXXX.exr,environment_name=Forest;Lab",
"Load multiple | First broken, second OK": "#environment_url=./media/XXXXXXXXXXXXXXXXXXXXX.exr;http://localhost:8081/test-media/env-lab-hq.exr,environment_name=Forest;Lab",
"Load multiple | Too many environment names": "#environment_url=./media/env-full-forest-hq.exr;http://localhost:8081/test-media/env-lab-hq.exr,environment_name=Forest;Lab;Foo;Bar",
"Load multiple | Not enough environment names": "#environment_url=./media/env-full-forest-hq.exr;http://localhost:8081/test-media/env-lab-hq.exr,environment_name=Forest"
"Load multiple | First OK, second broken": "#environment_url=./media/env-forest-hq.exr,http://localhost:8081/test-media/XXXXXXXXXXXXXXX.exr&environment_name=Forest,Lab",
"Load multiple | First broken, second OK": "#environment_url=./media/XXXXXXXXXXXXXXXXXXXXX.exr,http://localhost:8081/test-media/env-lab-hq.exr&environment_name=Forest,Lab",
"Load multiple | Too many environment names": "#environment_url=./media/env-forest-hq.exr,http://localhost:8081/test-media/env-lab-hq.exr&environment_name=Forest,Lab,Foo,Bar",
"Load multiple | Not enough environment names": "#environment_url=./media/env-forest-hq.exr,http://localhost:8081/test-media/env-lab-hq.exr&environment_name=Forest"
};
</script>
<script src="./iframes.js"></script>
Expand Down

0 comments on commit 3678648

Please sign in to comment.