Skip to content

Commit

Permalink
Merge pull request #3 from frericp/hdEmscripten_cleanup
Browse files Browse the repository at this point in the history
cleanup and minor fixes
  • Loading branch information
kaischroeder authored and GitHub Enterprise committed Feb 2, 2022
2 parents 34250f5 + b06a194 commit 6d10683
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 205 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ set(CMAKE_CXX_FLAGS "${_PXR_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")

if(PXR_ENABLE_JS_SUPPORT)
# Add EMSCRIPTEN specific compiler flags (is this the right place)?
set(EMSCRIPTEN_COMPILE_FLAGS "-s ALLOW_MEMORY_GROWTH=1 -s MAXIMUM_MEMORY=4GB -s ASSERTIONS=1 -s DISABLE_EXCEPTION_CATCHING=0 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=2 -s MODULARIZE=1 -s EXPORT_NAME='getUsdModule' -s 'EXTRA_EXPORTED_RUNTIME_METHODS=[\"FS\"]' -s FORCE_FILESYSTEM=1 --pre-js ${CMAKE_SOURCE_DIR}/js/prejs.js")
set(EMSCRIPTEN_COMPILE_FLAGS "-s ALLOW_MEMORY_GROWTH=1 -s MAXIMUM_MEMORY=4GB -s ASSERTIONS=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=2 -s MODULARIZE=1 -s EXPORT_NAME='getUsdModule' -s 'EXTRA_EXPORTED_RUNTIME_METHODS=[\"FS\"]' -s FORCE_FILESYSTEM=1 --pre-js ${CMAKE_SOURCE_DIR}/js/prejs.js")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EMSCRIPTEN_COMPILE_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EMSCRIPTEN_COMPILE_FLAGS}")

Expand Down
24 changes: 10 additions & 14 deletions pxr/usdImaging/hdEmscripten/js/ThreeJsRenderDelegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TextureRegistry {
return;
}

let blob = new Blob([loadedFile.slice(0)], {type: filetype});
let blob = new Blob([loadedFile.slice()], {type: filetype});
let blobUrl = URL.createObjectURL(blob);

// Load the texture
Expand Down Expand Up @@ -77,14 +77,14 @@ class HydraMesh {

const material = new THREE.MeshPhysicalMaterial( {
side: THREE.DoubleSide,
color: new THREE.Color(0xa0a0a0) // a gray default color
color: new THREE.Color(0xa0a0a0) // a gray default color
});

this._mesh = new THREE.Mesh( this._geometry, material );
this._mesh.castShadow = true;
this._mesh.receiveShadow = true;

window.scene.add(this._mesh); // FIXME
window.scene.add(this._mesh);
}

updateOrder(attribute, attributeName, dimension = 3) {
Expand All @@ -105,7 +105,6 @@ class HydraMesh {
for (let i = 0; i< indices.length; i++) {
this._indices.push(indices[i]);
}
//this._geometry.setIndex( indicesArray );
this.updateOrder(this._points, 'position');
this.updateOrder(this._normals, 'normal');
if (this._colors) {
Expand All @@ -124,7 +123,7 @@ class HydraMesh {
}

updateNormals(normals) {
this._normals = normals.slice(0);
this._normals = normals.slice();
this.updateOrder(this._normals, 'normal');
}

Expand All @@ -151,10 +150,10 @@ class HydraMesh {
// Per-vertex buffer attribute
this._mesh.material.vertexColors = true;
if (wasDefaultMaterial) {
// Reset the pink debugging color
// Reset the debugging color
this._mesh.material.color = new THREE.Color(0xffffff);
}
this._colors = data.slice(0);
this._colors = data.slice();
this.updateOrder(this._colors, 'color');
} else {
console.warn(`Unsupported displayColor interpolation type '${interpolation}'.`);
Expand All @@ -167,10 +166,10 @@ class HydraMesh {

if (interpolation === 'facevarying') {
// The UV buffer has already been prepared on the C++ side, so we just set it
this._geometry.setAttribute('uv', new THREE.Float32BufferAttribute(data, dimension));
this._geometry.setAttribute('uv', new THREE.Float32BufferAttribute(data.slice(), dimension));
} else if (interpolation === 'vertex') {
// We have per-vertex UVs, so we need to sort them accordingly
this._uvs = data.slice(0);
this._uvs = data.slice();
this.updateOrder(this._uvs, 'uv', 2);
}
this._geometry.attributes.uv2 = this._geometry.attributes.uv;
Expand Down Expand Up @@ -202,7 +201,7 @@ class HydraMesh {
}

updatePoints(points) {
this._points = points.slice(0);
this._points = points.slice();
this.updateOrder(this._points, 'position');
}

Expand Down Expand Up @@ -407,10 +406,7 @@ export class RenderDelegateInterface {
}

createBPrim(typeId, id) {
console.log('Creating BPrim: ' + typeId + ' ' + id);
/*let mesh = new HydraMesh(id, this);
this.meshes[id] = mesh;
return mesh;*/
console.warn('BPrims are not supported!');
}

createSPrim(typeId, id) {
Expand Down
2 changes: 1 addition & 1 deletion pxr/usdImaging/hdEmscripten/testenv/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
req.responseType = "arraybuffer";

req.onload = function (oEvent) {
let arrayBuffer = req.response; // Note: not oReq.responseText
let arrayBuffer = req.response;
if (arrayBuffer) {
resolve(arrayBuffer);
} else {
Expand Down
Loading

0 comments on commit 6d10683

Please sign in to comment.