Skip to content

Commit

Permalink
Add support for bypassing web worker for mesh decompression
Browse files Browse the repository at this point in the history
  • Loading branch information
kainino0x committed Aug 7, 2015
1 parent ada7c23 commit d54780b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 27 deletions.
54 changes: 40 additions & 14 deletions Source/Scene/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ define([
'../ThirdParty/gltfDefaults',
'../ThirdParty/Uri',
'../ThirdParty/when',
'./decompressOpen3DGC',
'./getModelAccessor',
'./ModelAnimationCache',
'./ModelAnimationCollection',
Expand Down Expand Up @@ -81,6 +82,7 @@ define([
gltfDefaults,
Uri,
when,
decompressOpen3DGC,
getModelAccessor,
ModelAnimationCache,
ModelAnimationCollection,
Expand Down Expand Up @@ -1301,34 +1303,58 @@ define([

///////////////////////////////////////////////////////////////////////////

var decompressTaskProcessor = new TaskProcessor('decompressMesh');
var open3dgcTaskProcessor = new TaskProcessor('decompressOpen3DGC');

function createDecompressedView(model) {
var loadResources = model._loadResources;
var decompressedViews = model.gltf.extensions.mesh_compression_open3dgc.decompressedViews;
function decompressOpen3dgcSync(buffer, decompressedView) {
var compressedBuffer = getSubarray(buffer, decompressedView.byteOffset, decompressedView.byteLength);

var name = loadResources.decompressedViewsToCreate.dequeue();
var decompressedView = decompressedViews[name];
var decompressedArrayBuffer = decompressOpen3DGC(decompressedView.decompressedByteLength, compressedBuffer);

var buffer = loadResources.buffers[decompressedView.buffer];
return when(decompressedArrayBuffer);
}

function decompressOpen3dgcAsync(buffer, decompressedView) {
var compressedBuffer = copySubarray(buffer, decompressedView.byteOffset, decompressedView.byteLength);

var decompressPromise = decompressTaskProcessor.scheduleTask({
return open3dgcTaskProcessor.scheduleTask({
decompressedByteLength : decompressedView.decompressedByteLength,
compressedBuffer : compressedBuffer
}, [compressedBuffer.buffer]);
}

if (!defined(decompressPromise)) {
loadResources.decompressedViewsToCreate.enqueue(name);
return;
function decompressOpen3dgc(model, name) {
var decompressedViews = model.gltf.extensions.mesh_compression_open3dgc.decompressedViews;

var loadResources = model._loadResources;
var decompressedView = decompressedViews[name];
var buffer = loadResources.buffers[decompressedView.buffer];

var forceSynchronous = false;

if (forceSynchronous) {
return decompressOpen3dgcSync(buffer, decompressedView);
}

var decompressPromise = decompressOpen3dgcAsync(buffer, decompressedView);
if (defined(decompressPromise)) {
return when(decompressPromise).then(function(result) {
return result.decompressedArrayBuffer;
});
} else {
return decompressOpen3dgcSync(buffer, decompressedView);
}
}

function createDecompressedView(model) {
var loadResources = model._loadResources;

loadResources.decompressionInFlight++;

when(decompressPromise).then(function(result) {
var decompressedArrayBuffer = result.decompressedArrayBuffer;
loadResources.decompressedViews[name] = new Uint8Array(decompressedArrayBuffer);
var name = loadResources.decompressedViewsToCreate.dequeue();

var decompressPromise = decompressOpen3dgc(model, name);
decompressPromise.then(function(decompressedArrayBuffer) {
loadResources.decompressedViews[name] = new Uint8Array(decompressedArrayBuffer);
loadResources.decompressionInFlight--;
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/*global define*/
define([
'../ThirdParty/o3dgc',
'./createTaskProcessorWorker'
'../ThirdParty/o3dgc'
], function(
o3dgc,
createTaskProcessorWorker ) {
o3dgc) {
"use strict";

function alignOffset(offset, alignment) {
Expand All @@ -13,12 +11,8 @@ define([
return (Math.ceil(offset / alignment) * alignment) | 0;
}

function decompressMesh(parameters, transferableObjects) {
var decompressedByteLength = parameters.decompressedByteLength;
var compressedBuffer = parameters.compressedBuffer;

function decompressOpen3DGC(decompressedByteLength, compressedBuffer) {
var decompressedArrayBuffer = new ArrayBuffer(decompressedByteLength);
transferableObjects.push(decompressedArrayBuffer);

// Mostly copied from https://github.com/amd/rest3d/blob/master/server/o3dgc/js/index.php

Expand Down Expand Up @@ -78,10 +72,8 @@ define([
//console.log("DecodePlayload: " + timer.GetElapsedTime());
//console.log(decoder.GetStats());

return {
decompressedArrayBuffer : decompressedArrayBuffer
};
return decompressedArrayBuffer;
}

return createTaskProcessorWorker(decompressMesh);
return decompressOpen3DGC;
});
23 changes: 23 additions & 0 deletions Source/Workers/decompressOpen3DGC.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*global define*/
define([
'../Scene/decompressOpen3DGC',
'./createTaskProcessorWorker'
], function(
decompressOpen3DGC,
createTaskProcessorWorker) {
"use strict";

function decompressOpen3DGCWorker(parameters, transferableObjects) {
var decompressedByteLength = parameters.decompressedByteLength;
var compressedBuffer = parameters.compressedBuffer;

var decompressedArrayBuffer = decompressOpen3DGC(decompressedByteLength, compressedBuffer);

transferableObjects.push(decompressedArrayBuffer);
return {
decompressedArrayBuffer : decompressedArrayBuffer
};
}

return createTaskProcessorWorker(decompressOpen3DGCWorker);
});

0 comments on commit d54780b

Please sign in to comment.