Skip to content

Commit

Permalink
JavaScript viewer update (#895)
Browse files Browse the repository at this point in the history
- Add USD and glTF as loadable materials.
- Add in geometry switcher to select glTF files to load.
- Fix texture flipping.
- Fix when default url options not set.
- Update camera to more closely match desktop viewer.
- For boombox example add in images and image path mapping. Search pathing has not been added to viewer so adding to manual mapping.
- Fixed up geometric stream loading so there is fallback geometry if the load fails, and if there are no uvs or normals they are generated. This prevents tangent generation from failing if either of those does not exist and hence failing on a series of GL errors.
- Add some very basic parameter control.
  • Loading branch information
kwokcb authored Apr 4, 2022
1 parent 41c5834 commit 569c9b4
Show file tree
Hide file tree
Showing 7 changed files with 421 additions and 106 deletions.
29 changes: 23 additions & 6 deletions javascript/MaterialXView/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,38 @@
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<title>MaterialX Web Viewer</title>
<link rel="icon" type="image/x-icon" href="public/favicon.ico" />
<style>
body {
margin: 0;
font-family: Arial
}
</style>
</head>
<body style="margin: 0px; overflow: hidden;">
<div id="container">
<div style="position: absolute;margin: 10px;">
<label for="materials" style="color: white;">Choose a material:</label>
<div style="color:white; position: absolute; top: 0em; margin: 1em">
<label for="materials">Material:</label>
<select name="materials" id="materials">
<% materials.forEach(function(m){ %>
<option value="<%-m.value%>"><%-m.name%></option>
<% }); %>
<option value="<%-m.value%>">
<%-m.name%>
</option>
<% }); %>
</select>
</div>
<div style="color:white; position: absolute; top: 1.5em; margin: 1em">
<label for="geometry">Geometry:</label>
<select name="geometry" id="geometry">
<% geometry.forEach(function(m){ %>
<option value="<%-m.value%>">
<%-m.name%>
</option>
<% }); %>
</select>
</div>

<canvas id="webglcanvas"></canvas>
</div>
<script src="JsMaterialXGenShader.js"></script>
Expand Down
1 change: 1 addition & 0 deletions javascript/MaterialXView/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"dat.gui": "^0.7.9",
"three": "^0.128.0",
"webpack": "^5.37.1"
},
Expand Down
5 changes: 4 additions & 1 deletion javascript/MaterialXView/source/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ function toThreeUniform(type, value, name, uniforms, textureLoader)
case 'filename':
if (value)
{
const mappedValue = value.replace(FILE_PREFIX, TARGET_FILE_PREFIX)
let mappedValue = value.replace(FILE_PREFIX, TARGET_FILE_PREFIX);
mappedValue = mappedValue.replace('boombox', TARGET_FILE_PREFIX);
const texture = textureLoader.load(mappedValue);
// Set address & filtering mode
setTextureParameters(texture, name, uniforms);
Expand Down Expand Up @@ -239,6 +240,8 @@ function setTextureParameters(texture, name, uniforms, generateMipmaps = true)
const filterType = uniforms.get(base + FILTER_TYPE_SUFFIX) ? uniforms.get(base + FILTER_TYPE_SUFFIX).value : -1;
texture.magFilter = THREE.LinearFilter;
texture.minFilter = getMinFilter(filterType, generateMipmaps);

texture.flipY = false;
}

/**
Expand Down
Loading

0 comments on commit 569c9b4

Please sign in to comment.