@playcanvas/supersplat-viewer 1.40.0 → 1.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/THIRD_PARTY_NOTICES.md +436 -0
- package/dist/gsaf-decoder.d.ts +4 -0
- package/dist/gsaf-decoder.js +10 -0
- package/dist/gsaf-decoder.wasm +0 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +2 -2
- package/dist/viewer.d.ts +17 -2
- package/dist/viewer.js +587 -26
- package/dist/viewer.js.map +1 -1
- package/docs/api.md +18 -2
- package/package.json +7 -1
- package/public/gsaf-decoder.wasm +0 -0
- package/public/index.html +3 -0
- package/public/index.js +636 -25
- package/public/index.js.map +1 -1
package/public/index.js
CHANGED
|
@@ -37158,6 +37158,56 @@ class GSplatResourceBase {
|
|
|
37158
37158
|
}
|
|
37159
37159
|
}
|
|
37160
37160
|
|
|
37161
|
+
class GSplatContainer extends GSplatResourceBase {
|
|
37162
|
+
_maxSplats = 0;
|
|
37163
|
+
_numSplats = 0;
|
|
37164
|
+
constructor(device, maxSplats, format) {
|
|
37165
|
+
const aabb = new BoundingBox();
|
|
37166
|
+
const gsplatData = {
|
|
37167
|
+
numSplats: maxSplats,
|
|
37168
|
+
getCenters: () => null,
|
|
37169
|
+
calcAabb: (box) => box.copy(aabb)
|
|
37170
|
+
};
|
|
37171
|
+
super(device, gsplatData, { prepareCenters: false });
|
|
37172
|
+
this._format = format;
|
|
37173
|
+
this._maxSplats = maxSplats;
|
|
37174
|
+
this._numSplats = maxSplats;
|
|
37175
|
+
this.streams.init(this._format, maxSplats);
|
|
37176
|
+
}
|
|
37177
|
+
set centers(value) {
|
|
37178
|
+
this._centers = value;
|
|
37179
|
+
}
|
|
37180
|
+
get centers() {
|
|
37181
|
+
if (this._centers === null) {
|
|
37182
|
+
this._centers = new Float32Array(this._maxSplats * 3);
|
|
37183
|
+
this.centersVersion++;
|
|
37184
|
+
}
|
|
37185
|
+
return this._centers;
|
|
37186
|
+
}
|
|
37187
|
+
get maxSplats() {
|
|
37188
|
+
return this._maxSplats;
|
|
37189
|
+
}
|
|
37190
|
+
get numSplats() {
|
|
37191
|
+
return this._numSplats;
|
|
37192
|
+
}
|
|
37193
|
+
update(numSplats = this._numSplats, centersUpdated = true) {
|
|
37194
|
+
this._numSplats = math.clamp(numSplats, 0, this._maxSplats);
|
|
37195
|
+
if (centersUpdated) {
|
|
37196
|
+
this.centersVersion++;
|
|
37197
|
+
}
|
|
37198
|
+
}
|
|
37199
|
+
configureMaterialDefines(defines) {
|
|
37200
|
+
defines.set("SH_BANDS", "0");
|
|
37201
|
+
}
|
|
37202
|
+
configureMaterial(material, workBufferModifier = null, formatDeclarations) {
|
|
37203
|
+
super.configureMaterial(material, workBufferModifier, formatDeclarations);
|
|
37204
|
+
const chunks = this.device.isWebGPU ? material.shaderChunks.wgsl : material.shaderChunks.glsl;
|
|
37205
|
+
chunks.set("gsplatContainerDeclarationsVS", this.format.getInputDeclarations());
|
|
37206
|
+
chunks.set("gsplatDeclarationsVS", '#include "gsplatContainerDeclVS"');
|
|
37207
|
+
chunks.set("gsplatReadVS", this.format.getReadCode());
|
|
37208
|
+
}
|
|
37209
|
+
}
|
|
37210
|
+
|
|
37161
37211
|
const mat4 = new Mat4();
|
|
37162
37212
|
const quat$1 = new Quat();
|
|
37163
37213
|
const aabb = new BoundingBox();
|
|
@@ -85777,6 +85827,473 @@ const observe = (events, target) => {
|
|
|
85777
85827
|
});
|
|
85778
85828
|
};
|
|
85779
85829
|
|
|
85830
|
+
var decoderSource = "async function createGsafModule(moduleArg={}){var Module=moduleArg;var ENVIRONMENT_IS_WEB=false;var ENVIRONMENT_IS_WORKER=true;var programArgs=[];var thisProgram=\"./this.program\";var _scriptName;if(ENVIRONMENT_IS_WORKER){_scriptName=self.location.href}var scriptDirectory=\"\";function locateFile(path){if(Module[\"locateFile\"]){return Module[\"locateFile\"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){try{scriptDirectory=new URL(\".\",_scriptName).href}catch{}{if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open(\"GET\",url,false);xhr.responseType=\"arraybuffer\";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=async url=>{var response=await fetch(url,{credentials:\"same-origin\"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+\" : \"+response.url)}}}else{}var out=console.log.bind(console);var err=console.error.bind(console);var wasmBinary;var ABORT=false;class EmscriptenEH{}class EmscriptenSjLj extends EmscriptenEH{}var runtimeInitialized=false;function updateMemoryViews(){var b=wasmMemory.buffer;HEAP8=new Int8Array(b);HEAP16=new Int16Array(b);Module[\"HEAPU8\"]=HEAPU8=new Uint8Array(b);HEAPU16=new Uint16Array(b);HEAP32=new Int32Array(b);HEAPU32=new Uint32Array(b);Module[\"HEAPF32\"]=HEAPF32=new Float32Array(b);HEAPF64=new Float64Array(b);HEAP64=new BigInt64Array(b);HEAPU64=new BigUint64Array(b)}function preRun(){if(Module[\"preRun\"]){if(typeof Module[\"preRun\"]==\"function\")Module[\"preRun\"]=[Module[\"preRun\"]];while(Module[\"preRun\"].length){addOnPreRun(Module[\"preRun\"].shift())}}callRuntimeCallbacks(onPreRuns)}function initRuntime(){runtimeInitialized=true;wasmExports[\"F\"]()}function postRun(){if(Module[\"postRun\"]){if(typeof Module[\"postRun\"]==\"function\")Module[\"postRun\"]=[Module[\"postRun\"]];while(Module[\"postRun\"].length){addOnPostRun(Module[\"postRun\"].shift())}}callRuntimeCallbacks(onPostRuns)}function abort(what){Module[\"onAbort\"]?.(what);what=`Aborted(${what})`;err(what);ABORT=true;what+=\". Build with -sASSERTIONS for more info.\";var e=new WebAssembly.RuntimeError(what);throw e}var wasmBinaryFile;function findWasmBinary(){return locateFile(\"gsaf-decoder.wasm\")}function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw\"both async and sync fetching of the wasm failed\"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary){try{var response=fetch(binaryFile,{credentials:\"same-origin\"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err(\"falling back to ArrayBuffer instantiation\")}}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){var imports={a:wasmImports};return imports}async function createWasm(){function receiveInstance(instance,module){wasmExports=instance.exports;assignWasmExports(wasmExports);updateMemoryViews();return wasmExports}function receiveInstantiationResult(result){return receiveInstance(result[\"instance\"])}var info=getWasmImports();if(Module[\"instantiateWasm\"]){return new Promise((resolve,reject)=>{Module[\"instantiateWasm\"](info,(inst,mod)=>{resolve(receiveInstance(inst,mod))})})}wasmBinaryFile??=findWasmBinary();var result=await instantiateAsync(wasmBinary,wasmBinaryFile,info);var exports=receiveInstantiationResult(result);return exports}class ExitStatus{name=\"ExitStatus\";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var HEAP16;var HEAP32;var HEAP64;var HEAP8;var HEAPF32;var HEAPF64;var HEAPU16;var HEAPU32;var HEAPU64;var HEAPU8;var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var onPostRuns=[];var addOnPostRun=cb=>onPostRuns.push(cb);var onPreRuns=[];var addOnPreRun=cb=>onPreRuns.push(cb);var noExitRuntime=true;var stackRestore=val=>__emscripten_stack_restore(val);var stackSave=()=>_emscripten_stack_get_current();class ExceptionInfo{constructor(excPtr){this.excPtr=excPtr;this.ptr=excPtr-24}set_type(type){HEAPU32[this.ptr+4>>2]=type}get_type(){return HEAPU32[this.ptr+4>>2]}set_destructor(destructor){HEAPU32[this.ptr+8>>2]=destructor}get_destructor(){return HEAPU32[this.ptr+8>>2]}set_caught(caught){caught=caught?1:0;HEAP8[this.ptr+12]=caught}get_caught(){return HEAP8[this.ptr+12]!=0}set_rethrown(rethrown){rethrown=rethrown?1:0;HEAP8[this.ptr+13]=rethrown}get_rethrown(){return HEAP8[this.ptr+13]!=0}init(type,destructor){this.set_adjusted_ptr(0);this.set_type(type);this.set_destructor(destructor)}set_adjusted_ptr(adjustedPtr){HEAPU32[this.ptr+16>>2]=adjustedPtr}get_adjusted_ptr(){return HEAPU32[this.ptr+16>>2]}}var uncaughtExceptionCount=0;var ___cxa_throw=(ptr,type,destructor)=>{var info=new ExceptionInfo(ptr);info.init(type,destructor);uncaughtExceptionCount++;abort()};var __abort_js=()=>abort(\"\");var AsciiToString=ptr=>{var str=\"\";while(1){var ch=HEAPU8[ptr++];if(!ch)return str;str+=String.fromCharCode(ch)}};var awaitingDependencies={};var registeredTypes={};var typeDependencies={};var BindingError=class BindingError extends Error{constructor(message){super(message);this.name=\"BindingError\"}};var throwBindingError=message=>{throw new BindingError(message)};function sharedRegisterType(rawType,registeredInstance,options={}){var name=registeredInstance.name;if(!rawType){throwBindingError(`type \"${name}\" must have a positive integer typeid pointer`)}if(registeredTypes.hasOwnProperty(rawType)){if(options.ignoreDuplicateRegistrations){return}else{throwBindingError(`Cannot register type '${name}' twice`)}}registeredTypes[rawType]=registeredInstance;delete typeDependencies[rawType];if(awaitingDependencies.hasOwnProperty(rawType)){var callbacks=awaitingDependencies[rawType];delete awaitingDependencies[rawType];callbacks.forEach(cb=>cb())}}function registerType(rawType,registeredInstance,options={}){return sharedRegisterType(rawType,registeredInstance,options)}var integerReadValueFromPointer=(name,width,signed)=>{switch(width){case 1:return signed?pointer=>HEAP8[pointer]:pointer=>HEAPU8[pointer];case 2:return signed?pointer=>HEAP16[pointer>>1]:pointer=>HEAPU16[pointer>>1];case 4:return signed?pointer=>HEAP32[pointer>>2]:pointer=>HEAPU32[pointer>>2];case 8:return signed?pointer=>HEAP64[pointer>>3]:pointer=>HEAPU64[pointer>>3];default:throw new TypeError(`invalid integer width (${width}): ${name}`)}};var __embind_register_bigint=(primitiveType,name,size,minRange,maxRange)=>{name=AsciiToString(name);const isUnsignedType=minRange===0n;let fromWireType=value=>value;if(isUnsignedType){const bitSize=size*8;fromWireType=value=>BigInt.asUintN(bitSize,value);maxRange=fromWireType(maxRange)}registerType(primitiveType,{name,fromWireType,toWireType:(destructors,value)=>{if(typeof value==\"number\"){value=BigInt(value)}return value},readValueFromPointer:integerReadValueFromPointer(name,size,!isUnsignedType),destructorFunction:null})};var __embind_register_bool=(rawType,name,trueValue,falseValue)=>{name=AsciiToString(name);registerType(rawType,{name,fromWireType:function(wt){return!!wt},toWireType:function(destructors,o){return o?trueValue:falseValue},readValueFromPointer:function(pointer){return this.fromWireType(HEAPU8[pointer])},destructorFunction:null})};var shallowCopyInternalPointer=o=>({count:o.count,deleteScheduled:o.deleteScheduled,preservePointerOnDelete:o.preservePointerOnDelete,ptr:o.ptr,ptrType:o.ptrType,smartPtr:o.smartPtr,smartPtrType:o.smartPtrType});var throwInstanceAlreadyDeleted=obj=>{function getInstanceTypeName(handle){return handle.$$.ptrType.registeredClass.name}throwBindingError(getInstanceTypeName(obj)+\" instance already deleted\")};var finalizationRegistry=false;var detachFinalizer=handle=>{};var runDestructor=$$=>{if($$.smartPtr){$$.smartPtrType.rawDestructor($$.smartPtr)}else{$$.ptrType.registeredClass.rawDestructor($$.ptr)}};var releaseClassHandle=$$=>{$$.count.value-=1;var toDelete=0===$$.count.value;if(toDelete){runDestructor($$)}};var attachFinalizer=handle=>{if(!globalThis.FinalizationRegistry){attachFinalizer=handle=>handle;return handle}finalizationRegistry=new FinalizationRegistry(info=>{releaseClassHandle(info.$$)});attachFinalizer=handle=>{var $$=handle.$$;var hasSmartPtr=!!$$.smartPtr;if(hasSmartPtr){var info={$$};finalizationRegistry.register(handle,info,handle)}return handle};detachFinalizer=handle=>finalizationRegistry.unregister(handle);return attachFinalizer(handle)};var deletionQueue=[];var flushPendingDeletes=()=>{while(deletionQueue.length){var obj=deletionQueue.pop();obj.$$.deleteScheduled=false;obj[\"delete\"]()}};var delayFunction;var init_ClassHandle=()=>{let proto=ClassHandle.prototype;Object.assign(proto,{isAliasOf(other){if(!(this instanceof ClassHandle)){return false}if(!(other instanceof ClassHandle)){return false}var leftClass=this.$$.ptrType.registeredClass;var left=this.$$.ptr;other.$$=other.$$;var rightClass=other.$$.ptrType.registeredClass;var right=other.$$.ptr;while(leftClass.baseClass){left=leftClass.upcast(left);leftClass=leftClass.baseClass}while(rightClass.baseClass){right=rightClass.upcast(right);rightClass=rightClass.baseClass}return leftClass===rightClass&&left===right},clone(){if(!this.$$.ptr){throwInstanceAlreadyDeleted(this)}if(this.$$.preservePointerOnDelete){this.$$.count.value+=1;return this}else{var clone=attachFinalizer(Object.create(Object.getPrototypeOf(this),{$$:{value:shallowCopyInternalPointer(this.$$)}}));clone.$$.count.value+=1;clone.$$.deleteScheduled=false;return clone}},delete(){if(!this.$$.ptr){throwInstanceAlreadyDeleted(this)}if(this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete){throwBindingError(\"Object already scheduled for deletion\")}detachFinalizer(this);releaseClassHandle(this.$$);if(!this.$$.preservePointerOnDelete){this.$$.smartPtr=undefined;this.$$.ptr=undefined}},isDeleted(){return!this.$$.ptr},deleteLater(){if(!this.$$.ptr){throwInstanceAlreadyDeleted(this)}if(this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete){throwBindingError(\"Object already scheduled for deletion\")}deletionQueue.push(this);if(deletionQueue.length===1&&delayFunction){delayFunction(flushPendingDeletes)}this.$$.deleteScheduled=true;return this}});const symbolDispose=Symbol.dispose;if(symbolDispose){proto[symbolDispose]=proto[\"delete\"]}};function ClassHandle(){}var createNamedFunction=(name,func)=>Object.defineProperty(func,\"name\",{value:name});var registeredPointers={};var ensureOverloadTable=(proto,methodName,humanName)=>{if(undefined===proto[methodName].overloadTable){var prevFunc=proto[methodName];proto[methodName]=function(...args){if(!proto[methodName].overloadTable.hasOwnProperty(args.length)){throwBindingError(`Function '${humanName}' called with an invalid number of arguments (${args.length}) - expects one of (${proto[methodName].overloadTable})!`)}return proto[methodName].overloadTable[args.length].apply(this,args)};proto[methodName].overloadTable=[];proto[methodName].overloadTable[prevFunc.argCount]=prevFunc}};var exposePublicSymbol=(name,value,numArguments)=>{if(Module.hasOwnProperty(name)){if(undefined===numArguments||undefined!==Module[name].overloadTable&&undefined!==Module[name].overloadTable[numArguments]){throwBindingError(`Cannot register public name '${name}' twice`)}ensureOverloadTable(Module,name,name);if(Module[name].overloadTable.hasOwnProperty(numArguments)){throwBindingError(`Cannot register multiple overloads of a function with the same number of arguments (${numArguments})!`)}Module[name].overloadTable[numArguments]=value}else{Module[name]=value;Module[name].argCount=numArguments}};var char_0=48;var char_9=57;var makeLegalFunctionName=name=>{name=name.replace(/[^a-zA-Z0-9_]/g,\"$\");var f=name.charCodeAt(0);if(f>=char_0&&f<=char_9){return`_${name}`}return name};function RegisteredClass(name,constructor,instancePrototype,rawDestructor,baseClass,getActualType,upcast,downcast){this.name=name;this.constructor=constructor;this.instancePrototype=instancePrototype;this.rawDestructor=rawDestructor;this.baseClass=baseClass;this.getActualType=getActualType;this.upcast=upcast;this.downcast=downcast;this.pureVirtualFunctions=[]}var upcastPointer=(ptr,ptrClass,desiredClass)=>{while(ptrClass!==desiredClass){if(!ptrClass.upcast){throwBindingError(`Expected null or instance of ${desiredClass.name}, got an instance of ${ptrClass.name}`)}ptr=ptrClass.upcast(ptr);ptrClass=ptrClass.baseClass}return ptr};var embindRepr=v=>{if(v===null){return\"null\"}var t=typeof v;if(t===\"object\"||t===\"array\"||t===\"function\"){return v.toString()}else{return\"\"+v}};function constNoSmartPtrRawPointerToWireType(destructors,handle){if(handle===null){if(this.isReference){throwBindingError(`null is not a valid ${this.name}`)}return 0}if(!handle.$$){throwBindingError(`Cannot pass \"${embindRepr(handle)}\" as a ${this.name}`)}if(!handle.$$.ptr){throwBindingError(`Cannot pass deleted object as a pointer of type ${this.name}`)}var handleClass=handle.$$.ptrType.registeredClass;var ptr=upcastPointer(handle.$$.ptr,handleClass,this.registeredClass);return ptr}function genericPointerToWireType(destructors,handle){var ptr;if(handle===null){if(this.isReference){throwBindingError(`null is not a valid ${this.name}`)}if(this.isSmartPointer){ptr=this.rawConstructor();if(destructors!==null){destructors.push(this.rawDestructor,ptr)}return ptr}else{return 0}}if(!handle||!handle.$$){throwBindingError(`Cannot pass \"${embindRepr(handle)}\" as a ${this.name}`)}if(!handle.$$.ptr){throwBindingError(`Cannot pass deleted object as a pointer of type ${this.name}`)}if(!this.isConst&&handle.$$.ptrType.isConst){throwBindingError(`Cannot convert argument of type ${handle.$$.smartPtrType?handle.$$.smartPtrType.name:handle.$$.ptrType.name} to parameter type ${this.name}`)}var handleClass=handle.$$.ptrType.registeredClass;ptr=upcastPointer(handle.$$.ptr,handleClass,this.registeredClass);if(this.isSmartPointer){if(undefined===handle.$$.smartPtr){throwBindingError(\"Passing raw pointer to smart pointer is illegal\")}switch(this.sharingPolicy){case 0:if(handle.$$.smartPtrType===this){ptr=handle.$$.smartPtr}else{throwBindingError(`Cannot convert argument of type ${handle.$$.smartPtrType?handle.$$.smartPtrType.name:handle.$$.ptrType.name} to parameter type ${this.name}`)}break;case 1:ptr=handle.$$.smartPtr;break;case 2:if(handle.$$.smartPtrType===this){ptr=handle.$$.smartPtr}else{var clonedHandle=handle[\"clone\"]();ptr=this.rawShare(ptr,Emval.toHandle(()=>clonedHandle[\"delete\"]()));if(destructors!==null){destructors.push(this.rawDestructor,ptr)}}break;default:throwBindingError(\"Unsupported sharing policy\")}}return ptr}function nonConstNoSmartPtrRawPointerToWireType(destructors,handle){if(handle===null){if(this.isReference){throwBindingError(`null is not a valid ${this.name}`)}return 0}if(!handle.$$){throwBindingError(`Cannot pass \"${embindRepr(handle)}\" as a ${this.name}`)}if(!handle.$$.ptr){throwBindingError(`Cannot pass deleted object as a pointer of type ${this.name}`)}if(handle.$$.ptrType.isConst){throwBindingError(`Cannot convert argument of type ${handle.$$.ptrType.name} to parameter type ${this.name}`)}var handleClass=handle.$$.ptrType.registeredClass;var ptr=upcastPointer(handle.$$.ptr,handleClass,this.registeredClass);return ptr}function readPointer(pointer){return this.fromWireType(HEAPU32[pointer>>2])}var downcastPointer=(ptr,ptrClass,desiredClass)=>{if(ptrClass===desiredClass){return ptr}if(undefined===desiredClass.baseClass){return null}var rv=downcastPointer(ptr,ptrClass,desiredClass.baseClass);if(rv===null){return null}return desiredClass.downcast(rv)};var registeredInstances={};var getBasestPointer=(class_,ptr)=>{if(ptr===undefined){throwBindingError(\"ptr should not be undefined\")}while(class_.baseClass){ptr=class_.upcast(ptr);class_=class_.baseClass}return ptr};var getInheritedInstance=(class_,ptr)=>{ptr=getBasestPointer(class_,ptr);return registeredInstances[ptr]};var InternalError=class InternalError extends Error{constructor(message){super(message);this.name=\"InternalError\"}};var throwInternalError=message=>{throw new InternalError(message)};var makeClassHandle=(prototype,record)=>{if(!record.ptrType||!record.ptr){throwInternalError(\"makeClassHandle requires ptr and ptrType\")}var hasSmartPtrType=!!record.smartPtrType;var hasSmartPtr=!!record.smartPtr;if(hasSmartPtrType!==hasSmartPtr){throwInternalError(\"Both smartPtrType and smartPtr must be specified\")}record.count={value:1};return attachFinalizer(Object.create(prototype,{$$:{value:record,writable:true}}))};function RegisteredPointer_fromWireType(ptr){var rawPointer=this.getPointee(ptr);if(!rawPointer){this.destructor(ptr);return null}var registeredInstance=getInheritedInstance(this.registeredClass,rawPointer);if(undefined!==registeredInstance){if(0===registeredInstance.$$.count.value){registeredInstance.$$.ptr=rawPointer;registeredInstance.$$.smartPtr=ptr;return registeredInstance[\"clone\"]()}else{var rv=registeredInstance[\"clone\"]();this.destructor(ptr);return rv}}function makeDefaultHandle(){if(this.isSmartPointer){return makeClassHandle(this.registeredClass.instancePrototype,{ptrType:this.pointeeType,ptr:rawPointer,smartPtrType:this,smartPtr:ptr})}else{return makeClassHandle(this.registeredClass.instancePrototype,{ptrType:this,ptr})}}var actualType=this.registeredClass.getActualType(rawPointer);var registeredPointerRecord=registeredPointers[actualType];if(!registeredPointerRecord){return makeDefaultHandle.call(this)}var toType;if(this.isConst){toType=registeredPointerRecord.constPointerType}else{toType=registeredPointerRecord.pointerType}var dp=downcastPointer(rawPointer,this.registeredClass,toType.registeredClass);if(dp===null){return makeDefaultHandle.call(this)}if(this.isSmartPointer){return makeClassHandle(toType.registeredClass.instancePrototype,{ptrType:toType,ptr:dp,smartPtrType:this,smartPtr:ptr})}else{return makeClassHandle(toType.registeredClass.instancePrototype,{ptrType:toType,ptr:dp})}}var init_RegisteredPointer=()=>{Object.assign(RegisteredPointer.prototype,{getPointee(ptr){if(this.rawGetPointee){ptr=this.rawGetPointee(ptr)}return ptr},destructor(ptr){this.rawDestructor?.(ptr)},readValueFromPointer:readPointer,fromWireType:RegisteredPointer_fromWireType})};function RegisteredPointer(name,registeredClass,isReference,isConst,isSmartPointer,pointeeType,sharingPolicy,rawGetPointee,rawConstructor,rawShare,rawDestructor){this.name=name;this.registeredClass=registeredClass;this.isReference=isReference;this.isConst=isConst;this.isSmartPointer=isSmartPointer;this.pointeeType=pointeeType;this.sharingPolicy=sharingPolicy;this.rawGetPointee=rawGetPointee;this.rawConstructor=rawConstructor;this.rawShare=rawShare;this.rawDestructor=rawDestructor;if(!isSmartPointer&®isteredClass.baseClass===undefined){if(isConst){this.toWireType=constNoSmartPtrRawPointerToWireType;this.destructorFunction=null}else{this.toWireType=nonConstNoSmartPtrRawPointerToWireType;this.destructorFunction=null}}else{this.toWireType=genericPointerToWireType}}var replacePublicSymbol=(name,value,numArguments)=>{if(!Module.hasOwnProperty(name)){throwInternalError(\"Replacing nonexistent public symbol\")}if(undefined!==Module[name].overloadTable&&undefined!==numArguments){Module[name].overloadTable[numArguments]=value}else{Module[name]=value;Module[name].argCount=numArguments}};var wasmTableMirror=[];var getWasmTableEntry=funcPtr=>{var func=wasmTableMirror[funcPtr];if(!func){wasmTableMirror[funcPtr]=func=wasmTable.get(funcPtr)}return func};var embind__requireFunction=(signature,rawFunction,isAsync=false)=>{signature=AsciiToString(signature);function makeDynCaller(){var rtn=getWasmTableEntry(rawFunction);return rtn}var fp=makeDynCaller();if(typeof fp!=\"function\"){throwBindingError(`unknown function pointer with signature ${signature}: ${rawFunction}`)}return fp};class UnboundTypeError extends Error{}var getTypeName=type=>{var ptr=___getTypeName(type);var rv=AsciiToString(ptr);_free(ptr);return rv};var throwUnboundTypeError=(message,types)=>{var unboundTypes=[];var seen={};function visit(type){if(seen[type]){return}if(registeredTypes[type]){return}if(typeDependencies[type]){typeDependencies[type].forEach(visit);return}unboundTypes.push(type);seen[type]=true}types.forEach(visit);throw new UnboundTypeError(`${message}: `+unboundTypes.map(getTypeName).join([\", \"]))};var whenDependentTypesAreResolved=(myTypes,dependentTypes,getTypeConverters)=>{myTypes.forEach(type=>typeDependencies[type]=dependentTypes);function onComplete(typeConverters){var myTypeConverters=getTypeConverters(typeConverters);if(myTypeConverters.length!==myTypes.length){throwInternalError(\"Mismatched type converter count\")}for(var i=0;i<myTypes.length;++i){registerType(myTypes[i],myTypeConverters[i])}}var typeConverters=new Array(dependentTypes.length);var unregisteredTypes=[];var registered=0;for(let[i,dt]of dependentTypes.entries()){if(registeredTypes.hasOwnProperty(dt)){typeConverters[i]=registeredTypes[dt]}else{unregisteredTypes.push(dt);if(!awaitingDependencies.hasOwnProperty(dt)){awaitingDependencies[dt]=[]}awaitingDependencies[dt].push(()=>{typeConverters[i]=registeredTypes[dt];++registered;if(registered===unregisteredTypes.length){onComplete(typeConverters)}})}}if(0===unregisteredTypes.length){onComplete(typeConverters)}};var __embind_register_class=(rawType,rawPointerType,rawConstPointerType,baseClassRawType,getActualTypeSignature,getActualType,upcastSignature,upcast,downcastSignature,downcast,name,destructorSignature,rawDestructor)=>{name=AsciiToString(name);getActualType=embind__requireFunction(getActualTypeSignature,getActualType);upcast&&=embind__requireFunction(upcastSignature,upcast);downcast&&=embind__requireFunction(downcastSignature,downcast);rawDestructor=embind__requireFunction(destructorSignature,rawDestructor);var legalFunctionName=makeLegalFunctionName(name);exposePublicSymbol(legalFunctionName,function(){throwUnboundTypeError(`Cannot construct ${name} due to unbound types`,[baseClassRawType])});whenDependentTypesAreResolved([rawType,rawPointerType,rawConstPointerType],baseClassRawType?[baseClassRawType]:[],base=>{base=base[0];var baseClass;var basePrototype;if(baseClassRawType){baseClass=base.registeredClass;basePrototype=baseClass.instancePrototype}else{basePrototype=ClassHandle.prototype}var constructor=createNamedFunction(name,function(...args){if(Object.getPrototypeOf(this)!==instancePrototype){throw new BindingError(`Use 'new' to construct ${name}`)}if(undefined===registeredClass.constructor_body){throw new BindingError(`${name} has no accessible constructor`)}var body=registeredClass.constructor_body[args.length];if(undefined===body){throw new BindingError(`Tried to invoke ctor of ${name} with invalid number of parameters (${args.length}) - expected (${Object.keys(registeredClass.constructor_body).toString()}) parameters instead!`)}return body.apply(this,args)});var instancePrototype=Object.create(basePrototype,{constructor:{value:constructor}});constructor.prototype=instancePrototype;var registeredClass=new RegisteredClass(name,constructor,instancePrototype,rawDestructor,baseClass,getActualType,upcast,downcast);if(registeredClass.baseClass){registeredClass.baseClass.__derivedClasses??=[];registeredClass.baseClass.__derivedClasses.push(registeredClass)}var referenceConverter=new RegisteredPointer(name,registeredClass,true,false,false);var pointerConverter=new RegisteredPointer(name+\"*\",registeredClass,false,false,false);var constPointerConverter=new RegisteredPointer(name+\" const*\",registeredClass,false,true,false);registeredPointers[rawType]={pointerType:pointerConverter,constPointerType:constPointerConverter};replacePublicSymbol(legalFunctionName,constructor);return[referenceConverter,pointerConverter,constPointerConverter]})};var runDestructors=destructors=>{while(destructors.length){var ptr=destructors.pop();var del=destructors.pop();del(ptr)}};function usesDestructorStack(argTypes){for(var i=1;i<argTypes.length;++i){if(argTypes[i]!==null&&argTypes[i].destructorFunction===undefined){return true}}return false}function craftInvokerFunction(humanName,argTypes,classType,cppInvokerFunc,cppTargetFunc,isAsync){var argCount=argTypes.length;if(argCount<2){throwBindingError(\"argTypes array size mismatch! Must at least get return value and 'this' types!\")}var isClassMethodFunc=argTypes[1]!==null&&classType!==null;var needsDestructorStack=usesDestructorStack(argTypes);var returns=!argTypes[0].isVoid;var expectedArgCount=argCount-2;var argsWired=new Array(expectedArgCount);var invokerFuncArgs=[];var destructors=[];var invokerFn=function(...args){destructors.length=0;var thisWired;invokerFuncArgs.length=isClassMethodFunc?2:1;invokerFuncArgs[0]=cppTargetFunc;if(isClassMethodFunc){thisWired=argTypes[1].toWireType(destructors,this);invokerFuncArgs[1]=thisWired}for(var i=0;i<expectedArgCount;++i){argsWired[i]=argTypes[i+2].toWireType(destructors,args[i]);invokerFuncArgs.push(argsWired[i])}var rv=cppInvokerFunc(...invokerFuncArgs);function onDone(rv){if(needsDestructorStack){runDestructors(destructors)}else{for(var i=isClassMethodFunc?1:2;i<argTypes.length;i++){var param=i===1?thisWired:argsWired[i-2];if(argTypes[i].destructorFunction!==null){argTypes[i].destructorFunction(param)}}}if(returns){return argTypes[0].fromWireType(rv)}}return onDone(rv)};return createNamedFunction(humanName,invokerFn)}var heap32VectorToArray=(count,firstElement)=>{var array=[];for(var i=0;i<count;i++){array.push(HEAPU32[firstElement+i*4>>2])}return array};var getFunctionName=signature=>{signature=signature.trim();const argsIndex=signature.indexOf(\"(\");if(argsIndex===-1)return signature;return signature.slice(0,argsIndex)};var __embind_register_class_class_function=(rawClassType,methodName,argCount,rawArgTypesAddr,invokerSignature,rawInvoker,fn,isAsync,isNonnullReturn)=>{var rawArgTypes=heap32VectorToArray(argCount,rawArgTypesAddr);methodName=AsciiToString(methodName);methodName=getFunctionName(methodName);rawInvoker=embind__requireFunction(invokerSignature,rawInvoker,isAsync);whenDependentTypesAreResolved([],[rawClassType],classType=>{classType=classType[0];var humanName=`${classType.name}.${methodName}`;function unboundTypesHandler(){throwUnboundTypeError(`Cannot call ${humanName} due to unbound types`,rawArgTypes)}if(methodName.startsWith(\"@@\")){methodName=Symbol[methodName.substring(2)]}var proto=classType.registeredClass.constructor;if(undefined===proto[methodName]){unboundTypesHandler.argCount=argCount-1;proto[methodName]=unboundTypesHandler}else{ensureOverloadTable(proto,methodName,humanName);proto[methodName].overloadTable[argCount-1]=unboundTypesHandler}whenDependentTypesAreResolved([],rawArgTypes,argTypes=>{var invokerArgsArray=[argTypes[0],null].concat(argTypes.slice(1));var func=craftInvokerFunction(humanName,invokerArgsArray,null,rawInvoker,fn,isAsync);if(undefined===proto[methodName].overloadTable){func.argCount=argCount-1;proto[methodName]=func}else{proto[methodName].overloadTable[argCount-1]=func}if(classType.registeredClass.__derivedClasses){for(const derivedClass of classType.registeredClass.__derivedClasses){if(!derivedClass.constructor.hasOwnProperty(methodName)){derivedClass.constructor[methodName]=func}}}return[]});return[]})};var __embind_register_class_constructor=(rawClassType,argCount,rawArgTypesAddr,invokerSignature,invoker,rawConstructor)=>{var rawArgTypes=heap32VectorToArray(argCount,rawArgTypesAddr);invoker=embind__requireFunction(invokerSignature,invoker);whenDependentTypesAreResolved([],[rawClassType],classType=>{classType=classType[0];var humanName=`constructor ${classType.name}`;if(undefined===classType.registeredClass.constructor_body){classType.registeredClass.constructor_body=[]}if(undefined!==classType.registeredClass.constructor_body[argCount-1]){throw new BindingError(`Cannot register multiple constructors with identical number of parameters (${argCount-1}) for class '${classType.name}'! Overload resolution is currently only performed using the parameter count, not actual type info!`)}classType.registeredClass.constructor_body[argCount-1]=()=>{throwUnboundTypeError(`Cannot construct ${classType.name} due to unbound types`,rawArgTypes)};whenDependentTypesAreResolved([],rawArgTypes,argTypes=>{argTypes.splice(1,0,null);classType.registeredClass.constructor_body[argCount-1]=craftInvokerFunction(humanName,argTypes,null,invoker,rawConstructor);return[]});return[]})};var __embind_register_class_function=(rawClassType,methodName,argCount,rawArgTypesAddr,invokerSignature,rawInvoker,context,isPureVirtual,isAsync,isNonnullReturn)=>{var rawArgTypes=heap32VectorToArray(argCount,rawArgTypesAddr);methodName=AsciiToString(methodName);methodName=getFunctionName(methodName);rawInvoker=embind__requireFunction(invokerSignature,rawInvoker,isAsync);whenDependentTypesAreResolved([],[rawClassType],classType=>{classType=classType[0];var humanName=`${classType.name}.${methodName}`;if(methodName.startsWith(\"@@\")){methodName=Symbol[methodName.substring(2)]}if(isPureVirtual){classType.registeredClass.pureVirtualFunctions.push(methodName)}function unboundTypesHandler(){throwUnboundTypeError(`Cannot call ${humanName} due to unbound types`,rawArgTypes)}var proto=classType.registeredClass.instancePrototype;var method=proto[methodName];if(undefined===method||undefined===method.overloadTable&&method.className!==classType.name&&method.argCount===argCount-2){unboundTypesHandler.argCount=argCount-2;unboundTypesHandler.className=classType.name;proto[methodName]=unboundTypesHandler}else{ensureOverloadTable(proto,methodName,humanName);proto[methodName].overloadTable[argCount-2]=unboundTypesHandler}whenDependentTypesAreResolved([],rawArgTypes,argTypes=>{var memberFunction=craftInvokerFunction(humanName,argTypes,classType,rawInvoker,context,isAsync);if(undefined===proto[methodName].overloadTable){memberFunction.argCount=argCount-2;proto[methodName]=memberFunction}else{proto[methodName].overloadTable[argCount-2]=memberFunction}return[]});return[]})};var validateThis=(this_,classType,humanName)=>{if(!(this_ instanceof Object)){throwBindingError(`${humanName} with invalid \"this\": ${this_}`)}if(!(this_ instanceof classType.registeredClass.constructor)){throwBindingError(`${humanName} incompatible with \"this\" of type ${this_.constructor.name}`)}if(!this_.$$.ptr){throwBindingError(`cannot call emscripten binding method ${humanName} on deleted object`)}return upcastPointer(this_.$$.ptr,this_.$$.ptrType.registeredClass,classType.registeredClass)};var __embind_register_class_property=(classType,fieldName,getterReturnType,getterSignature,getter,getterContext,setterArgumentType,setterSignature,setter,setterContext)=>{fieldName=AsciiToString(fieldName);getter=embind__requireFunction(getterSignature,getter);whenDependentTypesAreResolved([],[classType],classType=>{classType=classType[0];var humanName=`${classType.name}.${fieldName}`;var desc={get(){throwUnboundTypeError(`Cannot access ${humanName} due to unbound types`,[getterReturnType,setterArgumentType])},enumerable:true,configurable:true};if(setter){desc.set=()=>throwUnboundTypeError(`Cannot access ${humanName} due to unbound types`,[getterReturnType,setterArgumentType])}else{desc.set=v=>throwBindingError(humanName+\" is a read-only property\")}Object.defineProperty(classType.registeredClass.instancePrototype,fieldName,desc);whenDependentTypesAreResolved([],setter?[getterReturnType,setterArgumentType]:[getterReturnType],types=>{var getterReturnType=types[0];var desc={get(){var ptr=validateThis(this,classType,humanName+\" getter\");return getterReturnType.fromWireType(getter(getterContext,ptr))},enumerable:true};if(setter){setter=embind__requireFunction(setterSignature,setter);var setterArgumentType=types[1];desc.set=function(v){var ptr=validateThis(this,classType,humanName+\" setter\");var destructors=[];setter(setterContext,ptr,setterArgumentType.toWireType(destructors,v));runDestructors(destructors)}}Object.defineProperty(classType.registeredClass.instancePrototype,fieldName,desc);return[]});return[]})};var emval_freelist=[];var emval_handles=[0,1,,1,null,1,true,1,false,1];var __emval_decref=handle=>{if(handle>9&&0===--emval_handles[handle+1]){var value=emval_handles[handle];emval_handles[handle]=undefined;emval_freelist.push(handle)}};var Emval={toValue:handle=>{if(!handle){throwBindingError(`Cannot use deleted val. handle = ${handle}`)}return emval_handles[handle]},toHandle:value=>{switch(value){case undefined:return 2;case null:return 4;case true:return 6;case false:return 8;default:{const handle=emval_freelist.pop()||emval_handles.length;emval_handles[handle]=value;emval_handles[handle+1]=1;return handle}}}};var EmValType={name:\"emscripten::val\",fromWireType:handle=>{var rv=Emval.toValue(handle);__emval_decref(handle);return rv},toWireType:(destructors,value)=>Emval.toHandle(value),readValueFromPointer:readPointer,destructorFunction:null};var __embind_register_emval=rawType=>registerType(rawType,EmValType);var floatReadValueFromPointer=(name,width)=>{switch(width){case 4:return function(pointer){return this.fromWireType(HEAPF32[pointer>>2])};case 8:return function(pointer){return this.fromWireType(HEAPF64[pointer>>3])};default:throw new TypeError(`invalid float width (${width}): ${name}`)}};var __embind_register_float=(rawType,name,size)=>{name=AsciiToString(name);registerType(rawType,{name,fromWireType:value=>value,toWireType:(destructors,value)=>value,readValueFromPointer:floatReadValueFromPointer(name,size),destructorFunction:null})};var __embind_register_function=(name,argCount,rawArgTypesAddr,signature,rawInvoker,fn,isAsync,isNonnullReturn)=>{var argTypes=heap32VectorToArray(argCount,rawArgTypesAddr);name=AsciiToString(name);name=getFunctionName(name);rawInvoker=embind__requireFunction(signature,rawInvoker,isAsync);exposePublicSymbol(name,function(){throwUnboundTypeError(`Cannot call ${name} due to unbound types`,argTypes)},argCount-1);whenDependentTypesAreResolved([],argTypes,argTypes=>{var invokerArgsArray=[argTypes[0],null].concat(argTypes.slice(1));replacePublicSymbol(name,craftInvokerFunction(name,invokerArgsArray,null,rawInvoker,fn,isAsync),argCount-1);return[]})};var __embind_register_integer=(primitiveType,name,size,minRange,maxRange)=>{name=AsciiToString(name);const isUnsignedType=minRange===0;let fromWireType=value=>value;if(isUnsignedType){var bitshift=32-8*size;fromWireType=value=>value<<bitshift>>>bitshift;maxRange=fromWireType(maxRange)}registerType(primitiveType,{name,fromWireType,toWireType:(destructors,value)=>value,readValueFromPointer:integerReadValueFromPointer(name,size,minRange!==0),destructorFunction:null})};var __embind_register_memory_view=(rawType,dataTypeIndex,name)=>{var typeMapping=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,BigInt64Array,BigUint64Array];var TA=typeMapping[dataTypeIndex];function decodeMemoryView(handle){var size=HEAPU32[handle>>2];var data=HEAPU32[handle+4>>2];return new TA(HEAP8.buffer,data,size)}name=AsciiToString(name);registerType(rawType,{name,fromWireType:decodeMemoryView,readValueFromPointer:decodeMemoryView},{ignoreDuplicateRegistrations:true})};var stringToUTF8Array=(str,heap,outIdx,maxBytesToWrite)=>{if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i<str.length;++i){var u=str.codePointAt(i);if(u<=127){if(outIdx>=endIdx)break;heap[outIdx++]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;heap[outIdx++]=192|u>>6;heap[outIdx++]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;heap[outIdx++]=224|u>>12;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}else{if(outIdx+3>=endIdx)break;heap[outIdx++]=240|u>>18;heap[outIdx++]=128|u>>12&63;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63;i++}}heap[outIdx]=0;return outIdx-startIdx};var stringToUTF8=(str,outPtr,maxBytesToWrite)=>stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite);var lengthBytesUTF8=str=>{var len=0;for(var i=0;i<str.length;++i){var c=str.charCodeAt(i);if(c<=127){len++}else if(c<=2047){len+=2}else if(c>=55296&&c<=57343){len+=4;++i}else{len+=3}}return len};var UTF8Decoder=globalThis.TextDecoder&&new TextDecoder;var findStringEnd=(heapOrArray,idx,maxBytesToRead,ignoreNul)=>{var maxIdx=idx+maxBytesToRead;if(ignoreNul)return maxIdx;while(heapOrArray[idx]&&!(idx>=maxIdx))++idx;return idx};var UTF8ArrayToString=(heapOrArray,idx=0,maxBytesToRead,ignoreNul)=>{var endPtr=findStringEnd(heapOrArray,idx,maxBytesToRead,ignoreNul);if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}var str=\"\";while(idx<endPtr){var u0=heapOrArray[idx++];if(!(u0&128)){str+=String.fromCharCode(u0);continue}var u1=heapOrArray[idx++]&63;if((u0&224)==192){str+=String.fromCharCode((u0&31)<<6|u1);continue}var u2=heapOrArray[idx++]&63;if((u0&240)==224){u0=(u0&15)<<12|u1<<6|u2}else{u0=(u0&7)<<18|u1<<12|u2<<6|heapOrArray[idx++]&63}if(u0<65536){str+=String.fromCharCode(u0)}else{var ch=u0-65536;str+=String.fromCharCode(55296|ch>>10,56320|ch&1023)}}return str};var UTF8ToString=(ptr,maxBytesToRead,ignoreNul)=>ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead,ignoreNul):\"\";var __embind_register_std_string=(rawType,name)=>{name=AsciiToString(name);var stdStringIsUTF8=true;registerType(rawType,{name,fromWireType(value){var length=HEAPU32[value>>2];var payload=value+4;var str;if(stdStringIsUTF8){str=UTF8ToString(payload,length,true)}else{str=\"\";for(var i=0;i<length;++i){str+=String.fromCharCode(HEAPU8[payload+i])}}_free(value);return str},toWireType(destructors,value){if(value instanceof ArrayBuffer){value=new Uint8Array(value)}var length;var valueIsOfTypeString=typeof value==\"string\";if(!(valueIsOfTypeString||ArrayBuffer.isView(value)&&value.BYTES_PER_ELEMENT==1)){throwBindingError(\"Cannot pass non-string to std::string\")}if(stdStringIsUTF8&&valueIsOfTypeString){length=lengthBytesUTF8(value)}else{length=value.length}var base=_malloc(4+length+1);var ptr=base+4;HEAPU32[base>>2]=length;if(valueIsOfTypeString){if(stdStringIsUTF8){stringToUTF8(value,ptr,length+1)}else{for(var i=0;i<length;++i){var charCode=value.charCodeAt(i);if(charCode>255){_free(base);throwBindingError(\"String has UTF-16 code units that do not fit in 8 bits\")}HEAPU8[ptr+i]=charCode}}}else{HEAPU8.set(value,ptr)}if(destructors!==null){destructors.push(_free,base)}return base},readValueFromPointer:readPointer,destructorFunction(ptr){_free(ptr)}})};var UTF16Decoder=globalThis.TextDecoder?new TextDecoder(\"utf-16le\"):undefined;var UTF16ToString=(ptr,maxBytesToRead,ignoreNul)=>{var idx=ptr>>1;var endIdx=findStringEnd(HEAPU16,idx,maxBytesToRead/2,ignoreNul);if(endIdx-idx>16&&UTF16Decoder)return UTF16Decoder.decode(HEAPU16.subarray(idx,endIdx));var str=\"\";for(var i=idx;i<endIdx;++i){var codeUnit=HEAPU16[i];str+=String.fromCharCode(codeUnit)}return str};var stringToUTF16=(str,outPtr,maxBytesToWrite)=>{maxBytesToWrite??=2147483647;if(maxBytesToWrite<2)return 0;maxBytesToWrite-=2;var startPtr=outPtr;var numCharsToWrite=maxBytesToWrite<str.length*2?maxBytesToWrite/2:str.length;for(var i=0;i<numCharsToWrite;++i){var codeUnit=str.charCodeAt(i);HEAP16[outPtr>>1]=codeUnit;outPtr+=2}HEAP16[outPtr>>1]=0;return outPtr-startPtr};var lengthBytesUTF16=str=>str.length*2;var UTF32ToString=(ptr,maxBytesToRead,ignoreNul)=>{var str=\"\";var startIdx=ptr>>2;for(var i=0;!(i>=maxBytesToRead/4);i++){var utf32=HEAPU32[startIdx+i];if(!utf32&&!ignoreNul)break;str+=String.fromCodePoint(utf32)}return str};var stringToUTF32=(str,outPtr,maxBytesToWrite)=>{maxBytesToWrite??=2147483647;if(maxBytesToWrite<4)return 0;var startPtr=outPtr;var endPtr=startPtr+maxBytesToWrite-4;for(var i=0;i<str.length;++i){var codePoint=str.codePointAt(i);if(codePoint>65535){i++}HEAP32[outPtr>>2]=codePoint;outPtr+=4;if(outPtr+4>endPtr)break}HEAP32[outPtr>>2]=0;return outPtr-startPtr};var lengthBytesUTF32=str=>{var len=0;for(var i=0;i<str.length;++i){var codePoint=str.codePointAt(i);if(codePoint>65535){i++}len+=4}return len};var __embind_register_std_wstring=(rawType,charSize,name)=>{name=AsciiToString(name);var decodeString,encodeString,lengthBytesUTF;if(charSize===2){decodeString=UTF16ToString;encodeString=stringToUTF16;lengthBytesUTF=lengthBytesUTF16}else{decodeString=UTF32ToString;encodeString=stringToUTF32;lengthBytesUTF=lengthBytesUTF32}registerType(rawType,{name,fromWireType:value=>{var length=HEAPU32[value>>2];var str=decodeString(value+4,length*charSize,true);_free(value);return str},toWireType:(destructors,value)=>{if(!(typeof value==\"string\")){throwBindingError(`Cannot pass non-string to C++ string type ${name}`)}var length=lengthBytesUTF(value);var ptr=_malloc(4+length+charSize);HEAPU32[ptr>>2]=length/charSize;encodeString(value,ptr+4,length+charSize);if(destructors!==null){destructors.push(_free,ptr)}return ptr},readValueFromPointer:readPointer,destructorFunction(ptr){_free(ptr)}})};var __embind_register_void=(rawType,name)=>{name=AsciiToString(name);registerType(rawType,{isVoid:true,name,fromWireType:()=>undefined,toWireType:(destructors,o)=>undefined})};var __emval_array_to_memory_view=(dst,src)=>{dst=Emval.toValue(dst);src=Emval.toValue(src);dst.set(src)};var emval_methodCallers=[];var emval_addMethodCaller=caller=>{var id=emval_methodCallers.length;emval_methodCallers.push(caller);return id};var requireRegisteredType=(rawType,humanName)=>{var impl=registeredTypes[rawType];if(undefined===impl){throwBindingError(`${humanName} has unknown type ${getTypeName(rawType)}`)}return impl};var emval_lookupTypes=(argCount,argTypes)=>{var a=new Array(argCount);for(var i=0;i<argCount;++i){a[i]=requireRegisteredType(HEAPU32[argTypes+i*4>>2],`parameter ${i}`)}return a};var emval_returnValue=(toReturnWire,destructorsRef,handle)=>{var destructors=[];var result=toReturnWire(destructors,handle);if(destructors.length){HEAPU32[destructorsRef>>2]=Emval.toHandle(destructors)}return result};var emval_symbols={};var getStringOrSymbol=address=>{var symbol=emval_symbols[address];if(symbol===undefined){return AsciiToString(address)}return symbol};var __emval_create_invoker=(argCount,argTypesPtr,kind)=>{var GenericWireTypeSize=8;var[retType,...argTypes]=emval_lookupTypes(argCount,argTypesPtr);var toReturnWire=retType.toWireType.bind(retType);var argFromPtr=argTypes.map(type=>type.readValueFromPointer.bind(type));argCount--;var argN=new Array(argCount);var invokerFunction=(handle,methodName,destructorsRef,args)=>{var offset=0;for(var i=0;i<argCount;++i){argN[i]=argFromPtr[i](args+offset);offset+=GenericWireTypeSize}var rv;switch(kind){case 0:rv=Emval.toValue(handle).apply(null,argN);break;case 2:rv=Reflect.construct(Emval.toValue(handle),argN);break;case 3:rv=argN[0];break;case 1:rv=Emval.toValue(handle)[getStringOrSymbol(methodName)](...argN);break}return emval_returnValue(toReturnWire,destructorsRef,rv)};var functionName=`methodCaller<(${argTypes.map(t=>t.name)}) => ${retType.name}>`;return emval_addMethodCaller(createNamedFunction(functionName,invokerFunction))};var __emval_get_global=name=>{if(!name){return Emval.toHandle(globalThis)}name=getStringOrSymbol(name);return Emval.toHandle(globalThis[name])};var __emval_get_property=(handle,key)=>{handle=Emval.toValue(handle);key=Emval.toValue(key);return Emval.toHandle(handle[key])};var __emval_incref=handle=>{if(handle>9){emval_handles[handle+1]+=1}};var __emval_invoke=(caller,handle,methodName,destructorsRef,args)=>emval_methodCallers[caller](handle,methodName,destructorsRef,args);var __emval_new_array=()=>Emval.toHandle([]);var __emval_new_cstring=v=>Emval.toHandle(getStringOrSymbol(v));var __emval_new_object=()=>Emval.toHandle({});var __emval_run_destructors=handle=>{var destructors=Emval.toValue(handle);runDestructors(destructors);__emval_decref(handle)};var __emval_set_property=(handle,key,value)=>{handle=Emval.toValue(handle);key=Emval.toValue(key);value=Emval.toValue(value);handle[key]=value};var getHeapMax=()=>2147483648;var alignMemory=(size,alignment)=>Math.ceil(size/alignment)*alignment;var growMemory=size=>{var oldHeapSize=wasmMemory.buffer.byteLength;var pages=(size-oldHeapSize+65535)/65536|0;try{wasmMemory.grow(pages);updateMemoryViews();return 1}catch(e){}};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignMemory(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=growMemory(newSize);if(replacement){return true}}return false};var getCFunc=ident=>{var func=Module[\"_\"+ident];return func};var writeArrayToMemory=(array,buffer)=>{HEAP8.set(array,buffer)};var stackAlloc=sz=>__emscripten_stack_alloc(sz);var stringToUTF8OnStack=str=>{var size=lengthBytesUTF8(str)+1;var ret=stackAlloc(size);stringToUTF8(str,ret,size);return ret};var ccall=(ident,returnType,argTypes,args,opts)=>{var toC={string:str=>{var ret=0;if(str!==null&&str!==undefined&&str!==0){ret=stringToUTF8OnStack(str)}return ret},array:arr=>{var ret=stackAlloc(arr.length);writeArrayToMemory(arr,ret);return ret}};function convertReturnValue(ret){if(returnType===\"string\"){return UTF8ToString(ret)}if(returnType===\"boolean\")return Boolean(ret);return ret}var func=getCFunc(ident);var cArgs=[];var stack=0;if(args){for(var i=0;i<args.length;i++){var converter=toC[argTypes[i]];if(converter){if(stack===0)stack=stackSave();cArgs[i]=converter(args[i])}else{cArgs[i]=args[i]}}}var ret=func(...cArgs);function onDone(ret){if(stack!==0)stackRestore(stack);return convertReturnValue(ret)}ret=onDone(ret);return ret};var cwrap=(ident,returnType,argTypes,opts)=>{var numericArgs=!argTypes||argTypes.every(type=>type===\"number\"||type===\"boolean\");var numericRet=returnType!==\"string\";if(numericRet&&numericArgs&&!opts){return getCFunc(ident)}return(...args)=>ccall(ident,returnType,argTypes,args,opts)};init_ClassHandle();init_RegisteredPointer();{if(Module[\"noExitRuntime\"])noExitRuntime=Module[\"noExitRuntime\"];if(Module[\"print\"])out=Module[\"print\"];if(Module[\"printErr\"])err=Module[\"printErr\"];if(Module[\"wasmBinary\"])wasmBinary=Module[\"wasmBinary\"];if(Module[\"arguments\"])programArgs=Module[\"arguments\"];if(Module[\"thisProgram\"])thisProgram=Module[\"thisProgram\"];if(Module[\"preInit\"]){if(typeof Module[\"preInit\"]==\"function\")Module[\"preInit\"]=[Module[\"preInit\"]];while(Module[\"preInit\"].length>0){Module[\"preInit\"].shift()()}}}Module[\"ccall\"]=ccall;Module[\"cwrap\"]=cwrap;var ___getTypeName,_malloc,_free,__emscripten_stack_restore,__emscripten_stack_alloc,_emscripten_stack_get_current,memory,__indirect_function_table,wasmMemory,wasmTable;function assignWasmExports(wasmExports){___getTypeName=wasmExports[\"G\"];_malloc=Module[\"_malloc\"]=wasmExports[\"I\"];_free=Module[\"_free\"]=wasmExports[\"J\"];__emscripten_stack_restore=wasmExports[\"K\"];__emscripten_stack_alloc=wasmExports[\"L\"];_emscripten_stack_get_current=wasmExports[\"M\"];memory=wasmMemory=wasmExports[\"E\"];__indirect_function_table=wasmTable=wasmExports[\"H\"]}var wasmImports={k:___cxa_throw,w:__abort_js,s:__embind_register_bigint,z:__embind_register_bool,p:__embind_register_class,q:__embind_register_class_class_function,u:__embind_register_class_constructor,d:__embind_register_class_function,A:__embind_register_class_property,x:__embind_register_emval,r:__embind_register_float,m:__embind_register_function,j:__embind_register_integer,h:__embind_register_memory_view,y:__embind_register_std_string,n:__embind_register_std_wstring,B:__embind_register_void,C:__emval_array_to_memory_view,g:__emval_create_invoker,a:__emval_decref,t:__emval_get_global,D:__emval_get_property,o:__emval_incref,f:__emval_invoke,l:__emval_new_array,c:__emval_new_cstring,i:__emval_new_object,e:__emval_run_destructors,b:__emval_set_property,v:_emscripten_resize_heap};async function run(){preRun();var setStatus=Module[\"setStatus\"];if(setStatus){setStatus(\"Running...\");await new Promise(resolve=>setTimeout(resolve,1));setTimeout(setStatus,1,\"\")}if(ABORT)return;initRuntime();Module[\"onRuntimeInitialized\"]?.();postRun()}var wasmExports;wasmExports=await createWasm();await run();\n;return Module}if(typeof exports===\"object\"&&typeof module===\"object\"){module.exports=createGsafModule;module.exports.default=createGsafModule}else if(typeof define===\"function\"&&define[\"amd\"])define([],()=>createGsafModule);\n";
|
|
85831
|
+
|
|
85832
|
+
// The worker's code. It runs in the worker after the decoder glue, which defines
|
|
85833
|
+
// `createGsafModule`, so it is stringified and must not reference anything outside itself.
|
|
85834
|
+
function gsafWorker() {
|
|
85835
|
+
const scope = self;
|
|
85836
|
+
let module = null;
|
|
85837
|
+
let reader = null;
|
|
85838
|
+
// float to half, rounding to nearest
|
|
85839
|
+
const f32 = new Float32Array(1);
|
|
85840
|
+
const u32 = new Uint32Array(f32.buffer);
|
|
85841
|
+
const toHalf = (value) => {
|
|
85842
|
+
f32[0] = value;
|
|
85843
|
+
const x = u32[0];
|
|
85844
|
+
const sign = (x >>> 16) & 0x8000;
|
|
85845
|
+
const exponent = ((x >>> 23) & 0xff) - 112;
|
|
85846
|
+
const mantissa = x & 0x7fffff;
|
|
85847
|
+
if (exponent <= 0) {
|
|
85848
|
+
if (exponent < -10)
|
|
85849
|
+
return sign;
|
|
85850
|
+
return sign | ((((mantissa | 0x800000) >> (1 - exponent)) + 0x1000) >> 13);
|
|
85851
|
+
}
|
|
85852
|
+
if (exponent >= 31)
|
|
85853
|
+
return sign | 0x7c00;
|
|
85854
|
+
return sign | ((exponent << 10) + ((mantissa + 0x1000) >> 13));
|
|
85855
|
+
};
|
|
85856
|
+
// the decoder arrives compiled, so the glue instantiates it rather than fetching it
|
|
85857
|
+
const open = async (bytes, wasm) => {
|
|
85858
|
+
module = await scope.createGsafModule({
|
|
85859
|
+
instantiateWasm: (imports, done) => {
|
|
85860
|
+
WebAssembly.instantiate(wasm, imports).then((instance) => done(instance, wasm));
|
|
85861
|
+
return {};
|
|
85862
|
+
}
|
|
85863
|
+
});
|
|
85864
|
+
reader = module.WasmReader.openFromBytes(new Uint8Array(bytes));
|
|
85865
|
+
if (!reader)
|
|
85866
|
+
throw new Error(`gsaf: ${module.gsafLastError()}`);
|
|
85867
|
+
const h = reader.header();
|
|
85868
|
+
let maxSplats = 0;
|
|
85869
|
+
for (let i = 0; i < h.frameCount; i++) {
|
|
85870
|
+
maxSplats = Math.max(maxSplats, reader.frameInfo(i).splatCount);
|
|
85871
|
+
}
|
|
85872
|
+
return {
|
|
85873
|
+
frameCount: h.frameCount,
|
|
85874
|
+
maxSplats,
|
|
85875
|
+
fps: h.metadata?.fps,
|
|
85876
|
+
boundsMin: Array.from(h.assetBounds.min),
|
|
85877
|
+
boundsMax: Array.from(h.assetBounds.max),
|
|
85878
|
+
canonicalRotation: h.metadata?.canonicalRotation && Array.from(h.metadata.canonicalRotation),
|
|
85879
|
+
canonicalTranslation: h.metadata?.canonicalTranslation && Array.from(h.metadata.canonicalTranslation)
|
|
85880
|
+
};
|
|
85881
|
+
};
|
|
85882
|
+
const decode = (index, frame) => {
|
|
85883
|
+
reader.decodeFrameInto(index, 0);
|
|
85884
|
+
const slot = reader.frameSlot(0);
|
|
85885
|
+
const n = slot.splatCount;
|
|
85886
|
+
// read after the decode: a heap growth inside it replaces the buffer
|
|
85887
|
+
const heap = module.HEAPF32;
|
|
85888
|
+
const positions = heap.subarray(slot.positionsPtr() >> 2, (slot.positionsPtr() >> 2) + n * 3);
|
|
85889
|
+
const rotations = heap.subarray(slot.rotationsPtr() >> 2, (slot.rotationsPtr() >> 2) + n * 4);
|
|
85890
|
+
const scales = heap.subarray(slot.scalesPtr() >> 2, (slot.scalesPtr() >> 2) + n * 3);
|
|
85891
|
+
const colors = heap.subarray(slot.colorsPtr() >> 2, (slot.colorsPtr() >> 2) + n * 4);
|
|
85892
|
+
const { center, color, scale, rotation, centers } = frame;
|
|
85893
|
+
for (let i = 0; i < n; i++) {
|
|
85894
|
+
const i3 = i * 3;
|
|
85895
|
+
const i4 = i * 4;
|
|
85896
|
+
center[i4] = centers[i3] = positions[i3];
|
|
85897
|
+
center[i4 + 1] = centers[i3 + 1] = positions[i3 + 1];
|
|
85898
|
+
center[i4 + 2] = centers[i3 + 2] = positions[i3 + 2];
|
|
85899
|
+
scale[i4] = toHalf(scales[i3]);
|
|
85900
|
+
scale[i4 + 1] = toHalf(scales[i3 + 1]);
|
|
85901
|
+
scale[i4 + 2] = toHalf(scales[i3 + 2]);
|
|
85902
|
+
// both are w, x, y, z / r, g, b, a, as the default format reads them
|
|
85903
|
+
for (let c = 0; c < 4; c++) {
|
|
85904
|
+
rotation[i4 + c] = toHalf(rotations[i4 + c]);
|
|
85905
|
+
color[i4 + c] = toHalf(colors[i4 + c]);
|
|
85906
|
+
}
|
|
85907
|
+
}
|
|
85908
|
+
frame.index = index;
|
|
85909
|
+
frame.count = n;
|
|
85910
|
+
return frame;
|
|
85911
|
+
};
|
|
85912
|
+
scope.onmessage = async (event) => {
|
|
85913
|
+
const { type } = event.data;
|
|
85914
|
+
try {
|
|
85915
|
+
if (type === 'open') {
|
|
85916
|
+
scope.postMessage({ type, header: await open(event.data.bytes, event.data.wasm) });
|
|
85917
|
+
}
|
|
85918
|
+
else if (type === 'decode') {
|
|
85919
|
+
const frame = decode(event.data.index, event.data.frame);
|
|
85920
|
+
const { center, color, scale, rotation, centers } = frame;
|
|
85921
|
+
scope.postMessage({ type, frame }, [
|
|
85922
|
+
center.buffer,
|
|
85923
|
+
color.buffer,
|
|
85924
|
+
scale.buffer,
|
|
85925
|
+
rotation.buffer,
|
|
85926
|
+
centers.buffer
|
|
85927
|
+
]);
|
|
85928
|
+
}
|
|
85929
|
+
}
|
|
85930
|
+
catch (err) {
|
|
85931
|
+
scope.postMessage({ type: 'error', message: err?.message ?? String(err) });
|
|
85932
|
+
}
|
|
85933
|
+
};
|
|
85934
|
+
}
|
|
85935
|
+
// The decoder's wasm, fetched and compiled once per url for the page, so a second viewer or a
|
|
85936
|
+
// remount reuses it. A failed compile is forgotten, so the next load tries again.
|
|
85937
|
+
const compiled = new Map();
|
|
85938
|
+
/**
|
|
85939
|
+
* Fetches and compiles the decoder's wasm, streaming where the response is served as
|
|
85940
|
+
* `application/wasm`.
|
|
85941
|
+
*
|
|
85942
|
+
* @param url - The wasm's url; by default the file shipped beside the bundle.
|
|
85943
|
+
* @returns The compiled module.
|
|
85944
|
+
*/
|
|
85945
|
+
const compileGsafDecoder = (url) => {
|
|
85946
|
+
// a literal `new URL(..., import.meta.url)`, so a host's bundler emits the file with its own
|
|
85947
|
+
const href = url ?? new URL('./gsaf-decoder.wasm', import.meta.url).href;
|
|
85948
|
+
let module = compiled.get(href);
|
|
85949
|
+
if (!module) {
|
|
85950
|
+
module = (async () => {
|
|
85951
|
+
const response = await fetch(href);
|
|
85952
|
+
if (!response.ok) {
|
|
85953
|
+
throw new Error(`gsaf: ${response.status} ${response.statusText} fetching the decoder ${href}`);
|
|
85954
|
+
}
|
|
85955
|
+
try {
|
|
85956
|
+
return await WebAssembly.compileStreaming(response.clone());
|
|
85957
|
+
}
|
|
85958
|
+
catch {
|
|
85959
|
+
// a server that does not send application/wasm
|
|
85960
|
+
return WebAssembly.compile(await response.arrayBuffer());
|
|
85961
|
+
}
|
|
85962
|
+
})();
|
|
85963
|
+
compiled.set(href, module);
|
|
85964
|
+
module.catch(() => compiled.delete(href));
|
|
85965
|
+
}
|
|
85966
|
+
return module;
|
|
85967
|
+
};
|
|
85968
|
+
/**
|
|
85969
|
+
* The gsaf decoder in a worker, so decoding never stalls the main thread. One request is in
|
|
85970
|
+
* flight at a time.
|
|
85971
|
+
*/
|
|
85972
|
+
class GsafDecoder {
|
|
85973
|
+
worker;
|
|
85974
|
+
pending = null;
|
|
85975
|
+
constructor() {
|
|
85976
|
+
const source = `${decoderSource}\n(${gsafWorker.toString()})();\n`;
|
|
85977
|
+
const url = URL.createObjectURL(new Blob([source], { type: 'application/javascript' }));
|
|
85978
|
+
this.worker = new Worker(url);
|
|
85979
|
+
URL.revokeObjectURL(url);
|
|
85980
|
+
this.worker.onmessage = (event) => {
|
|
85981
|
+
const pending = this.pending;
|
|
85982
|
+
this.pending = null;
|
|
85983
|
+
if (event.data.type === 'error') {
|
|
85984
|
+
pending?.reject(new Error(event.data.message));
|
|
85985
|
+
}
|
|
85986
|
+
else {
|
|
85987
|
+
pending?.resolve(event.data);
|
|
85988
|
+
}
|
|
85989
|
+
};
|
|
85990
|
+
this.worker.onerror = (event) => {
|
|
85991
|
+
const pending = this.pending;
|
|
85992
|
+
this.pending = null;
|
|
85993
|
+
pending?.reject(new Error(event.message || 'gsaf: the decoder worker failed'));
|
|
85994
|
+
};
|
|
85995
|
+
}
|
|
85996
|
+
stopped = false;
|
|
85997
|
+
request(type, message, transfer) {
|
|
85998
|
+
if (this.stopped)
|
|
85999
|
+
return Promise.reject(new Error('gsaf: the decoder was stopped'));
|
|
86000
|
+
return new Promise((resolve, reject) => {
|
|
86001
|
+
this.pending = { resolve: resolve, reject };
|
|
86002
|
+
this.worker.postMessage({ type, ...message }, transfer);
|
|
86003
|
+
});
|
|
86004
|
+
}
|
|
86005
|
+
/**
|
|
86006
|
+
* Opens the file; the bytes are transferred to the worker.
|
|
86007
|
+
*
|
|
86008
|
+
* @param bytes - The file.
|
|
86009
|
+
* @param wasm - The decoder, from {@link compileGsafDecoder}.
|
|
86010
|
+
* @returns The file's header.
|
|
86011
|
+
*/
|
|
86012
|
+
async open(bytes, wasm) {
|
|
86013
|
+
const { header } = await this.request('open', { bytes, wasm }, [bytes]);
|
|
86014
|
+
return header;
|
|
86015
|
+
}
|
|
86016
|
+
/** Decodes a frame into the given buffers, which come back with it. */
|
|
86017
|
+
async decode(index, buffers) {
|
|
86018
|
+
const { center, color, scale, rotation, centers } = buffers;
|
|
86019
|
+
const { frame } = await this.request('decode', { index, frame: { ...buffers, index, count: 0 } }, [center.buffer, color.buffer, scale.buffer, rotation.buffer, centers.buffer]);
|
|
86020
|
+
return frame;
|
|
86021
|
+
}
|
|
86022
|
+
/** Stops the worker. A request in flight, and any made after, rejects. Idempotent. */
|
|
86023
|
+
destroy() {
|
|
86024
|
+
if (this.stopped)
|
|
86025
|
+
return;
|
|
86026
|
+
this.stopped = true;
|
|
86027
|
+
this.worker.terminate();
|
|
86028
|
+
const pending = this.pending;
|
|
86029
|
+
this.pending = null;
|
|
86030
|
+
pending?.reject(new Error('gsaf: the decoder was stopped'));
|
|
86031
|
+
}
|
|
86032
|
+
}
|
|
86033
|
+
|
|
86034
|
+
// the playback rate when the file carries no fps hint
|
|
86035
|
+
const DEFAULT_FPS = 30;
|
|
86036
|
+
const STREAMS = [
|
|
86037
|
+
['dataCenter', 'center'],
|
|
86038
|
+
['dataColor', 'color'],
|
|
86039
|
+
['dataScale', 'scale'],
|
|
86040
|
+
['dataRotation', 'rotation']
|
|
86041
|
+
];
|
|
86042
|
+
// Reads the response whole, reporting progress. Chunks are gathered rather than written into a
|
|
86043
|
+
// buffer of the declared length, which is the compressed length when the server encodes it.
|
|
86044
|
+
const readBytes = async (response, progressCallback) => {
|
|
86045
|
+
if (!response.ok) {
|
|
86046
|
+
throw new Error(`gsaf: ${response.status} ${response.statusText} fetching ${response.url}`);
|
|
86047
|
+
}
|
|
86048
|
+
const length = Number(response.headers.get('content-length')) || 0;
|
|
86049
|
+
if (!response.body || !length) {
|
|
86050
|
+
return response.arrayBuffer();
|
|
86051
|
+
}
|
|
86052
|
+
const chunks = [];
|
|
86053
|
+
let received = 0;
|
|
86054
|
+
const reader = response.body.getReader();
|
|
86055
|
+
for (;;) {
|
|
86056
|
+
const { done, value } = await reader.read();
|
|
86057
|
+
if (done)
|
|
86058
|
+
break;
|
|
86059
|
+
chunks.push(value);
|
|
86060
|
+
received += value.length;
|
|
86061
|
+
progressCallback(Math.trunc(Math.min(1, received / length) * 100));
|
|
86062
|
+
}
|
|
86063
|
+
const bytes = new Uint8Array(received);
|
|
86064
|
+
let offset = 0;
|
|
86065
|
+
for (const chunk of chunks) {
|
|
86066
|
+
bytes.set(chunk, offset);
|
|
86067
|
+
offset += chunk.length;
|
|
86068
|
+
}
|
|
86069
|
+
return bytes.buffer;
|
|
86070
|
+
};
|
|
86071
|
+
/**
|
|
86072
|
+
* An animated splat sequence playing through a container. The viewer's timeline drives it:
|
|
86073
|
+
* {@link paused} stops its clock, {@link seek} moves it and {@link time} is where it is. Each
|
|
86074
|
+
* update decodes the frame due at that time, in a worker, so a slow decode skips frames rather
|
|
86075
|
+
* than slowing playback; the decoder continues forward from the frame it holds and replays from
|
|
86076
|
+
* the last keyframe to go back. Destroying {@link entity} stops it and releases the worker and
|
|
86077
|
+
* the container.
|
|
86078
|
+
*/
|
|
86079
|
+
class GsafPlayer {
|
|
86080
|
+
/** The gsplat entity, showing the frame at {@link time}. */
|
|
86081
|
+
entity;
|
|
86082
|
+
/**
|
|
86083
|
+
* Whether the sequence plays: more than one frame, on WebGPU. WebGL shows the first frame
|
|
86084
|
+
* only, since its sorter is asynchronous and lands a frame or more behind the data, and gsaf
|
|
86085
|
+
* reorders splats from frame to frame (survivors in their previous order, births appended),
|
|
86086
|
+
* so an order computed for one frame is wrong for the next.
|
|
86087
|
+
*/
|
|
86088
|
+
animated;
|
|
86089
|
+
/** Length of the sequence in seconds. */
|
|
86090
|
+
duration;
|
|
86091
|
+
/** Stops the clock; paused until the viewer starts it. */
|
|
86092
|
+
paused = true;
|
|
86093
|
+
app;
|
|
86094
|
+
decoder;
|
|
86095
|
+
fps;
|
|
86096
|
+
frameCount;
|
|
86097
|
+
_time = 0;
|
|
86098
|
+
// the frame on screen, and the buffers it came in, null while a decode has them
|
|
86099
|
+
shown = 0;
|
|
86100
|
+
buffers;
|
|
86101
|
+
// seeks waiting for their frame
|
|
86102
|
+
waiters = [];
|
|
86103
|
+
// a decode that failed, after which the player shows its last frame and every seek fails
|
|
86104
|
+
failure = null;
|
|
86105
|
+
destroyed = false;
|
|
86106
|
+
constructor(app, entity, decoder, frameCount, fps, first, animated) {
|
|
86107
|
+
this.app = app;
|
|
86108
|
+
this.entity = entity;
|
|
86109
|
+
this.decoder = decoder;
|
|
86110
|
+
this.frameCount = frameCount;
|
|
86111
|
+
this.fps = fps;
|
|
86112
|
+
this.duration = frameCount / fps;
|
|
86113
|
+
this.buffers = first;
|
|
86114
|
+
this.animated = animated;
|
|
86115
|
+
const onUpdate = (dt) => {
|
|
86116
|
+
if (!this.paused)
|
|
86117
|
+
this._time = (this._time + dt) % this.duration;
|
|
86118
|
+
this.pump();
|
|
86119
|
+
};
|
|
86120
|
+
if (animated)
|
|
86121
|
+
app.on('update', onUpdate);
|
|
86122
|
+
entity.once('destroy', () => {
|
|
86123
|
+
this.destroyed = true;
|
|
86124
|
+
app.off('update', onUpdate);
|
|
86125
|
+
this.settle();
|
|
86126
|
+
});
|
|
86127
|
+
}
|
|
86128
|
+
/** The playhead, in seconds from the start of the sequence. */
|
|
86129
|
+
get time() {
|
|
86130
|
+
return this._time;
|
|
86131
|
+
}
|
|
86132
|
+
/**
|
|
86133
|
+
* Moves the playhead, wrapping it into the sequence.
|
|
86134
|
+
*
|
|
86135
|
+
* @param time - The time in seconds.
|
|
86136
|
+
* @returns Resolves once the frame at that time is on screen, or the player is destroyed;
|
|
86137
|
+
* rejects once a decode has failed.
|
|
86138
|
+
*/
|
|
86139
|
+
seek(time) {
|
|
86140
|
+
if (this.failure)
|
|
86141
|
+
return Promise.reject(this.failure);
|
|
86142
|
+
if (!this.animated)
|
|
86143
|
+
return Promise.resolve();
|
|
86144
|
+
// a time already in range is kept exactly, so it lands on the frame it names
|
|
86145
|
+
const wrapped = time % this.duration;
|
|
86146
|
+
this._time = wrapped < 0 ? wrapped + this.duration : wrapped;
|
|
86147
|
+
const landed = new Promise((resolve, reject) => this.waiters.push({ resolve, reject }));
|
|
86148
|
+
this.pump();
|
|
86149
|
+
return landed;
|
|
86150
|
+
}
|
|
86151
|
+
settle(err) {
|
|
86152
|
+
const { waiters } = this;
|
|
86153
|
+
this.waiters = [];
|
|
86154
|
+
for (const waiter of waiters) {
|
|
86155
|
+
if (err)
|
|
86156
|
+
waiter.reject(err);
|
|
86157
|
+
else
|
|
86158
|
+
waiter.resolve();
|
|
86159
|
+
}
|
|
86160
|
+
}
|
|
86161
|
+
// decode the frame due now, unless it is on screen or a decode is already in flight
|
|
86162
|
+
pump() {
|
|
86163
|
+
if (this.destroyed || this.failure || !this.buffers)
|
|
86164
|
+
return;
|
|
86165
|
+
// a frame's own start time can land a rounding error short of it
|
|
86166
|
+
const due = Math.min(this.frameCount - 1, Math.floor(this._time * this.fps + 1e-6));
|
|
86167
|
+
if (due === this.shown) {
|
|
86168
|
+
this.settle();
|
|
86169
|
+
return;
|
|
86170
|
+
}
|
|
86171
|
+
const buffers = this.buffers;
|
|
86172
|
+
this.buffers = null;
|
|
86173
|
+
this.decoder.decode(due, buffers).then((frame) => {
|
|
86174
|
+
// the worker is terminated with the entity, so this only runs while alive
|
|
86175
|
+
uploadFrame(this.app, this.entity.gsplat.resource, frame);
|
|
86176
|
+
// the engine re-copies a resource into its work buffer only when its allocation
|
|
86177
|
+
// changes, and a frame keeps the container's, so ask for the copy
|
|
86178
|
+
this.entity.gsplat.workBufferUpdate = WORKBUFFER_UPDATE_ONCE;
|
|
86179
|
+
this.shown = frame.index;
|
|
86180
|
+
this.buffers = frame;
|
|
86181
|
+
this.pump();
|
|
86182
|
+
}, (err) => {
|
|
86183
|
+
// the worker was terminated with the entity
|
|
86184
|
+
if (this.destroyed)
|
|
86185
|
+
return;
|
|
86186
|
+
console.error(err);
|
|
86187
|
+
this.failure = err;
|
|
86188
|
+
this.settle(err);
|
|
86189
|
+
});
|
|
86190
|
+
}
|
|
86191
|
+
}
|
|
86192
|
+
const uploadFrame = (app, container, frame) => {
|
|
86193
|
+
for (const [name, key] of STREAMS) {
|
|
86194
|
+
const texture = container.getTexture(name);
|
|
86195
|
+
texture.lock().set(frame[key]);
|
|
86196
|
+
texture.unlock();
|
|
86197
|
+
}
|
|
86198
|
+
container.centers.set(frame.centers.subarray(0, frame.count * 3));
|
|
86199
|
+
container.update(frame.count);
|
|
86200
|
+
app.renderNextFrame = true;
|
|
86201
|
+
};
|
|
86202
|
+
/**
|
|
86203
|
+
* Loads a gsaf file (an animated, compressed splat sequence) into a {@link GsafPlayer}. Frames
|
|
86204
|
+
* are decoded in a worker and written into a {@link GSplatContainer} in the engine's default
|
|
86205
|
+
* float format, which takes gsaf's render-ready values (linear scales, `w, x, y, z` rotations,
|
|
86206
|
+
* activated colors) as they are.
|
|
86207
|
+
*
|
|
86208
|
+
* @param app - The application.
|
|
86209
|
+
* @param response - The file's response.
|
|
86210
|
+
* @param decoderUrl - The decoder's wasm, if not the file beside the bundle.
|
|
86211
|
+
* @param progressCallback - Receives the download progress, 0 to 100.
|
|
86212
|
+
* @param signal - Aborted when the viewer is destroyed. Its handlers run before the app's own
|
|
86213
|
+
* destroy, so a load in flight releases its worker and container while the device is alive.
|
|
86214
|
+
* @returns The player, paused on the first frame.
|
|
86215
|
+
*/
|
|
86216
|
+
const loadGsaf = async (app, response, decoderUrl, progressCallback, signal) => {
|
|
86217
|
+
const fail = () => new Error('loadGsaf: the viewer was destroyed while loading');
|
|
86218
|
+
// the decoder compiles while the file downloads
|
|
86219
|
+
const wasm = compileGsafDecoder(decoderUrl);
|
|
86220
|
+
wasm.catch(() => {
|
|
86221
|
+
// reported by the await below, once the download is done
|
|
86222
|
+
});
|
|
86223
|
+
const bytes = await readBytes(await response, progressCallback);
|
|
86224
|
+
if (signal.aborted)
|
|
86225
|
+
throw fail();
|
|
86226
|
+
const compiledWasm = await wasm;
|
|
86227
|
+
if (signal.aborted)
|
|
86228
|
+
throw fail();
|
|
86229
|
+
const decoder = new GsafDecoder();
|
|
86230
|
+
let container = null;
|
|
86231
|
+
// until the entity owns them, a destroy stops the worker at once, which rejects the request
|
|
86232
|
+
// it was serving, and frees the container
|
|
86233
|
+
const onAbort = () => {
|
|
86234
|
+
decoder.destroy();
|
|
86235
|
+
container?.destroy();
|
|
86236
|
+
container = null;
|
|
86237
|
+
};
|
|
86238
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
86239
|
+
try {
|
|
86240
|
+
const header = await decoder.open(bytes, compiledWasm);
|
|
86241
|
+
if (signal.aborted)
|
|
86242
|
+
throw fail();
|
|
86243
|
+
const device = app.graphicsDevice;
|
|
86244
|
+
container = new GSplatContainer(device, header.maxSplats, GSplatFormat.createDefaultFormat(device));
|
|
86245
|
+
container.aabb.setMinMax(new Vec3(header.boundsMin), new Vec3(header.boundsMax));
|
|
86246
|
+
const texture = container.getTexture('dataCenter');
|
|
86247
|
+
const capacity = texture.width * texture.height * 4;
|
|
86248
|
+
const first = await decoder.decode(0, {
|
|
86249
|
+
center: new Float32Array(capacity),
|
|
86250
|
+
color: new Uint16Array(capacity),
|
|
86251
|
+
scale: new Uint16Array(capacity),
|
|
86252
|
+
rotation: new Uint16Array(capacity),
|
|
86253
|
+
centers: new Float32Array(header.maxSplats * 3)
|
|
86254
|
+
});
|
|
86255
|
+
if (signal.aborted)
|
|
86256
|
+
throw fail();
|
|
86257
|
+
signal.removeEventListener('abort', onAbort);
|
|
86258
|
+
uploadFrame(app, container, first);
|
|
86259
|
+
// always name the app: the engine's default is the most recently created one, which is
|
|
86260
|
+
// another viewer's when two share a page
|
|
86261
|
+
const entity = new Entity('gsplat', app);
|
|
86262
|
+
if (header.canonicalRotation) {
|
|
86263
|
+
// the canonical frame is y up and -z forward, the engine's own
|
|
86264
|
+
const [w, x, y, z] = header.canonicalRotation;
|
|
86265
|
+
entity.setLocalRotation(new Quat(x, y, z, w));
|
|
86266
|
+
if (header.canonicalTranslation) {
|
|
86267
|
+
entity.setLocalPosition(new Vec3(header.canonicalTranslation));
|
|
86268
|
+
}
|
|
86269
|
+
}
|
|
86270
|
+
else {
|
|
86271
|
+
entity.setLocalEulerAngles(0, 0, 180);
|
|
86272
|
+
}
|
|
86273
|
+
entity.addComponent('gsplat', {
|
|
86274
|
+
unified: true,
|
|
86275
|
+
resource: container
|
|
86276
|
+
});
|
|
86277
|
+
app.root.addChild(entity);
|
|
86278
|
+
const animated = header.frameCount > 1 && device.isWebGPU;
|
|
86279
|
+
if (!animated)
|
|
86280
|
+
decoder.destroy();
|
|
86281
|
+
const owned = container;
|
|
86282
|
+
entity.once('destroy', () => {
|
|
86283
|
+
decoder.destroy();
|
|
86284
|
+
owned.destroy();
|
|
86285
|
+
});
|
|
86286
|
+
const fps = header.fps > 0 ? header.fps : DEFAULT_FPS;
|
|
86287
|
+
return new GsafPlayer(app, entity, decoder, header.frameCount, fps, first, animated);
|
|
86288
|
+
}
|
|
86289
|
+
catch (err) {
|
|
86290
|
+
signal.removeEventListener('abort', onAbort);
|
|
86291
|
+
decoder.destroy();
|
|
86292
|
+
container?.destroy();
|
|
86293
|
+
throw signal.aborted ? fail() : err;
|
|
86294
|
+
}
|
|
86295
|
+
};
|
|
86296
|
+
|
|
85780
86297
|
var deJson = {
|
|
85781
86298
|
"settings.performance-mode": "Leistungsmodus",
|
|
85782
86299
|
"settings.gaming-controls": "Gaming-Steuerung",
|
|
@@ -93615,7 +94132,7 @@ const resolveTouchInsetBottom = (insetBottom) => {
|
|
|
93615
94132
|
return Number.isFinite(value) ? Math.min(TOUCH_INSET_BOTTOM_MAX, Math.max(0, value)) : 0;
|
|
93616
94133
|
};
|
|
93617
94134
|
|
|
93618
|
-
var version = "1.
|
|
94135
|
+
var version = "1.41.0";
|
|
93619
94136
|
|
|
93620
94137
|
class Tooltip {
|
|
93621
94138
|
register;
|
|
@@ -94819,11 +95336,13 @@ const initPlayback = (viewer, root, showUI) => {
|
|
|
94819
95336
|
const handle = root.querySelector('.sse-handle');
|
|
94820
95337
|
const time = root.querySelector('.sse-time');
|
|
94821
95338
|
const available = () => state.loaded && state.hasAnimation;
|
|
95339
|
+
// a sequence plays in every camera mode; the camera's animation only in its own
|
|
95340
|
+
const animating = () => state.hasSequence || state.cameraMode === 'anim';
|
|
94822
95341
|
const updateControls = () => {
|
|
94823
|
-
const playing =
|
|
95342
|
+
const playing = animating() && !state.animationPaused;
|
|
94824
95343
|
play.classList.toggle('sse-hidden', !available() || playing);
|
|
94825
95344
|
pause.classList.toggle('sse-hidden', !available() || !playing);
|
|
94826
|
-
timeline.classList.toggle('sse-hidden', !available() ||
|
|
95345
|
+
timeline.classList.toggle('sse-hidden', !available() || !animating());
|
|
94827
95346
|
};
|
|
94828
95347
|
const updateSlider = () => {
|
|
94829
95348
|
const position = state.animationDuration > 0 ? (state.animationTime / state.animationDuration) * 100 : 0;
|
|
@@ -94834,13 +95353,15 @@ const initPlayback = (viewer, root, showUI) => {
|
|
|
94834
95353
|
const onPlay = () => {
|
|
94835
95354
|
if (!available())
|
|
94836
95355
|
return;
|
|
94837
|
-
state.
|
|
95356
|
+
if (!state.hasSequence)
|
|
95357
|
+
state.cameraMode = 'anim';
|
|
94838
95358
|
state.animationPaused = false;
|
|
94839
95359
|
};
|
|
94840
95360
|
const onPause = () => {
|
|
94841
95361
|
if (!available())
|
|
94842
95362
|
return;
|
|
94843
|
-
state.
|
|
95363
|
+
if (!state.hasSequence)
|
|
95364
|
+
state.cameraMode = 'anim';
|
|
94844
95365
|
state.animationPaused = true;
|
|
94845
95366
|
};
|
|
94846
95367
|
const scrub = (event) => {
|
|
@@ -94885,6 +95406,7 @@ const initPlayback = (viewer, root, showUI) => {
|
|
|
94885
95406
|
const subscriptions = [
|
|
94886
95407
|
events.on('loaded:changed', updateControls),
|
|
94887
95408
|
events.on('hasAnimation:changed', updateControls),
|
|
95409
|
+
events.on('hasSequence:changed', updateControls),
|
|
94888
95410
|
events.on('cameraMode:changed', updateControls),
|
|
94889
95411
|
events.on('animationPaused:changed', updateControls),
|
|
94890
95412
|
events.on('animationTime:changed', updateSlider),
|
|
@@ -100285,6 +100807,14 @@ const initXr = (global) => {
|
|
|
100285
100807
|
// The menu held in the hand, which takes the selects that start on it before the navigation aims
|
|
100286
100808
|
// with them
|
|
100287
100809
|
const menu = new XrPalmMenu(app, camera, [
|
|
100810
|
+
{
|
|
100811
|
+
// an animated splat sequence's transport; the page's timeline is out of sight here
|
|
100812
|
+
label: () => localize(state.animationPaused ? 'tooltip.play' : 'tooltip.pause'),
|
|
100813
|
+
visible: () => state.hasSequence,
|
|
100814
|
+
action: () => {
|
|
100815
|
+
state.animationPaused = !state.animationPaused;
|
|
100816
|
+
}
|
|
100817
|
+
},
|
|
100288
100818
|
{ label: () => localize('tooltip.reset-camera'), action: placeAtStart },
|
|
100289
100819
|
{
|
|
100290
100820
|
label: () => `${localize('settings.quality')}: ${localize(`settings.quality-${quality.level}`)}`,
|
|
@@ -102832,7 +103362,14 @@ class CameraManager {
|
|
|
102832
103362
|
setCollision;
|
|
102833
103363
|
// holds the camera state
|
|
102834
103364
|
camera = new Camera();
|
|
102835
|
-
|
|
103365
|
+
/**
|
|
103366
|
+
* @param global - The viewer's globals.
|
|
103367
|
+
* @param bbox - The scene bounds.
|
|
103368
|
+
* @param collision - Collision data, if it has already loaded.
|
|
103369
|
+
* @param cameraAnimation - Whether the camera has an animation. Off for an animated splat
|
|
103370
|
+
* sequence, whose frames the timeline plays instead; the timeline state is then the viewer's.
|
|
103371
|
+
*/
|
|
103372
|
+
constructor(global, bbox, collision = null, cameraAnimation = true) {
|
|
102836
103373
|
const { events, settings, state } = global;
|
|
102837
103374
|
let walkAllowed = isWalkAllowed(bbox, collision);
|
|
102838
103375
|
const camera0 = settings.cameras[0]?.initial;
|
|
@@ -102859,7 +103396,7 @@ class CameraManager {
|
|
|
102859
103396
|
};
|
|
102860
103397
|
// object experience starts outside the bounding box
|
|
102861
103398
|
const isObjectExperience = !bbox.containsPoint(resetCamera.position);
|
|
102862
|
-
const animTrack = getAnimTrack(resetCamera, isObjectExperience);
|
|
103399
|
+
const animTrack = cameraAnimation ? getAnimTrack(resetCamera, isObjectExperience) : null;
|
|
102863
103400
|
const controllers = {
|
|
102864
103401
|
orbit: new OrbitController(),
|
|
102865
103402
|
fly: new FlyController(),
|
|
@@ -102883,10 +103420,12 @@ class CameraManager {
|
|
|
102883
103420
|
return controllers[cameraMode];
|
|
102884
103421
|
};
|
|
102885
103422
|
// set the global animation flag
|
|
102886
|
-
|
|
102887
|
-
|
|
103423
|
+
if (cameraAnimation) {
|
|
103424
|
+
state.hasAnimation = !!controllers.anim;
|
|
103425
|
+
state.animationDuration = controllers.anim ? controllers.anim.animState.cursor.duration : 0;
|
|
103426
|
+
}
|
|
102888
103427
|
// initialize camera mode and initial camera position
|
|
102889
|
-
state.cameraMode =
|
|
103428
|
+
state.cameraMode = controllers.anim ? 'anim' : isObjectExperience ? 'orbit' : walkAllowed ? 'walk' : 'fly';
|
|
102890
103429
|
this.camera.copy(resetCamera);
|
|
102891
103430
|
const target = new Camera(this.camera); // the active controller updates this
|
|
102892
103431
|
const from = new Camera(this.camera); // stores the previous camera state during transition
|
|
@@ -102999,7 +103538,12 @@ class CameraManager {
|
|
|
102999
103538
|
}
|
|
103000
103539
|
break;
|
|
103001
103540
|
case 'playPause':
|
|
103002
|
-
if (
|
|
103541
|
+
if (!controllers.anim) {
|
|
103542
|
+
// a sequence plays in every camera mode
|
|
103543
|
+
if (state.hasAnimation)
|
|
103544
|
+
state.animationPaused = !state.animationPaused;
|
|
103545
|
+
}
|
|
103546
|
+
else if (state.hasAnimation) {
|
|
103003
103547
|
if (state.cameraMode === 'anim') {
|
|
103004
103548
|
state.animationPaused = !state.animationPaused;
|
|
103005
103549
|
}
|
|
@@ -103043,6 +103587,13 @@ class CameraManager {
|
|
|
103043
103587
|
});
|
|
103044
103588
|
// handle camera mode switching
|
|
103045
103589
|
events.on('cameraMode:changed', (value, prev) => {
|
|
103590
|
+
// no animation to enter: a host's write is undone, and the undo has nothing to exit
|
|
103591
|
+
if (!getController(value)) {
|
|
103592
|
+
state.cameraMode = prev;
|
|
103593
|
+
return;
|
|
103594
|
+
}
|
|
103595
|
+
if (!getController(prev))
|
|
103596
|
+
return;
|
|
103046
103597
|
// Host state writes and the walk toggle must remember the same return mode.
|
|
103047
103598
|
if (value === 'walk') {
|
|
103048
103599
|
preWalkMode = prev;
|
|
@@ -103071,6 +103622,8 @@ class CameraManager {
|
|
|
103071
103622
|
}
|
|
103072
103623
|
});
|
|
103073
103624
|
this.seek = (time) => {
|
|
103625
|
+
if (!controllers.anim)
|
|
103626
|
+
return;
|
|
103074
103627
|
// switch to animation camera if we're not already there
|
|
103075
103628
|
state.cameraMode = 'anim';
|
|
103076
103629
|
// set time
|
|
@@ -103326,7 +103879,7 @@ class Capture {
|
|
|
103326
103879
|
camera.horizontalFov = srcW >= srcH;
|
|
103327
103880
|
this.setCameraTarget(srcRT);
|
|
103328
103881
|
if (time !== undefined && scrub) {
|
|
103329
|
-
scrub(time);
|
|
103882
|
+
await scrub(time);
|
|
103330
103883
|
}
|
|
103331
103884
|
this.app.renderNextFrame = true;
|
|
103332
103885
|
await new Promise((resolve) => {
|
|
@@ -107505,6 +108058,8 @@ class Viewer {
|
|
|
107505
108058
|
miniStats = null;
|
|
107506
108059
|
/** Set once {@link destroy} has run. Load continuations check it and bail. */
|
|
107507
108060
|
destroyed = false;
|
|
108061
|
+
/** An animated splat sequence the timeline plays, once loaded; null for other content. */
|
|
108062
|
+
sequence = null;
|
|
107508
108063
|
disposers = [];
|
|
107509
108064
|
fullscreen;
|
|
107510
108065
|
xr;
|
|
@@ -107524,7 +108079,7 @@ class Viewer {
|
|
|
107524
108079
|
// with it the captured image, reachable until the viewer went away.
|
|
107525
108080
|
abortHandlers = new Set();
|
|
107526
108081
|
origChunks;
|
|
107527
|
-
constructor(global, gsplatLoad, skyboxLoad, collisionLoad) {
|
|
108082
|
+
constructor(global, gsplatLoad, skyboxLoad, collisionLoad, sequenceLoad = null) {
|
|
107528
108083
|
this.global = global;
|
|
107529
108084
|
const { app, settings, config, events, state, camera, renderer } = global;
|
|
107530
108085
|
const { graphicsDevice } = app;
|
|
@@ -107663,8 +108218,9 @@ class Viewer {
|
|
|
107663
108218
|
if (!config.exposeGlobals)
|
|
107664
108219
|
return;
|
|
107665
108220
|
window.scrubTo = async (time) => {
|
|
107666
|
-
this.
|
|
108221
|
+
const landed = this.seekTo(time);
|
|
107667
108222
|
state.animationPaused = true;
|
|
108223
|
+
await this.untilDestroyed(landed);
|
|
107668
108224
|
let onFrame;
|
|
107669
108225
|
const rendered = new Promise((resolve) => {
|
|
107670
108226
|
onFrame = resolve;
|
|
@@ -107777,10 +108333,26 @@ class Viewer {
|
|
|
107777
108333
|
attachCollision?.(collision);
|
|
107778
108334
|
}, ignoreLoadFailure);
|
|
107779
108335
|
// wait for the model to load
|
|
107780
|
-
Promise.all([gsplatLoad, skyboxLoad]).then((results) => {
|
|
108336
|
+
Promise.all([gsplatLoad, skyboxLoad, sequenceLoad]).then((results) => {
|
|
107781
108337
|
// destroyed while loading: the app is gone, so there is nothing to wire up
|
|
107782
108338
|
if (this.destroyed)
|
|
107783
108339
|
return;
|
|
108340
|
+
// A sequence's frames are the timeline, in every camera mode, and the camera has no
|
|
108341
|
+
// animation of its own. The firstFrame handler starts it, as it would the camera's
|
|
108342
|
+
const sequence = results[2];
|
|
108343
|
+
if (sequence?.animated) {
|
|
108344
|
+
this.sequence = sequence;
|
|
108345
|
+
state.hasSequence = true;
|
|
108346
|
+
state.hasAnimation = true;
|
|
108347
|
+
state.animationDuration = sequence.duration;
|
|
108348
|
+
sequence.paused = state.animationPaused;
|
|
108349
|
+
events.on('animationPaused:changed', (paused) => {
|
|
108350
|
+
sequence.paused = paused;
|
|
108351
|
+
});
|
|
108352
|
+
app.on('update', () => {
|
|
108353
|
+
state.animationTime = sequence.time;
|
|
108354
|
+
});
|
|
108355
|
+
}
|
|
107784
108356
|
const gsplatComponent = results[0].gsplat;
|
|
107785
108357
|
// get scene bounding box
|
|
107786
108358
|
const gsplatBbox = gsplatComponent.customAabb;
|
|
@@ -107814,7 +108386,7 @@ class Viewer {
|
|
|
107814
108386
|
// for development pages (the bench measures pick noise), as splatRenderer:ready
|
|
107815
108387
|
events.fire('picker:ready', this.picker);
|
|
107816
108388
|
this.inputController = new InputController(global, this.picker);
|
|
107817
|
-
this.cameraManager = new CameraManager(global, sceneBound);
|
|
108389
|
+
this.cameraManager = new CameraManager(global, sceneBound, null, !sequence);
|
|
107818
108390
|
applyCamera(this.cameraManager.camera);
|
|
107819
108391
|
// the vr flag's prompt (ui/vr-prompt.ts) can start a session from here on, where
|
|
107820
108392
|
// startXR waits for the scene to finish loading: the camera is where the session
|
|
@@ -108061,6 +108633,13 @@ class Viewer {
|
|
|
108061
108633
|
return this.xr.end();
|
|
108062
108634
|
}
|
|
108063
108635
|
seek(time) {
|
|
108636
|
+
this.seekTo(time).catch(() => {
|
|
108637
|
+
// a sequence's failed decode, which the player has already reported
|
|
108638
|
+
});
|
|
108639
|
+
}
|
|
108640
|
+
// seek(), resolving once the frame at `time` is ready to render: at once for the camera's
|
|
108641
|
+
// animation, once decoded for a sequence's
|
|
108642
|
+
seekTo(time) {
|
|
108064
108643
|
this.requireLoaded('seek');
|
|
108065
108644
|
const { state, app } = this.global;
|
|
108066
108645
|
if (!state.hasAnimation) {
|
|
@@ -108069,8 +108648,14 @@ class Viewer {
|
|
|
108069
108648
|
if (!Number.isFinite(time)) {
|
|
108070
108649
|
throw new Error('seek: time must be finite');
|
|
108071
108650
|
}
|
|
108072
|
-
this.cameraManager.seek(time);
|
|
108073
108651
|
app.renderNextFrame = true;
|
|
108652
|
+
if (this.sequence) {
|
|
108653
|
+
const landed = this.sequence.seek(time);
|
|
108654
|
+
state.animationTime = this.sequence.time;
|
|
108655
|
+
return landed;
|
|
108656
|
+
}
|
|
108657
|
+
this.cameraManager.seek(time);
|
|
108658
|
+
return Promise.resolve();
|
|
108074
108659
|
}
|
|
108075
108660
|
/**
|
|
108076
108661
|
* Render the scene, with post effects, into an offscreen supersampled target, GPU
|
|
@@ -108093,10 +108678,10 @@ class Viewer {
|
|
|
108093
108678
|
width,
|
|
108094
108679
|
height,
|
|
108095
108680
|
supersample,
|
|
108096
|
-
scrub: (t) => {
|
|
108681
|
+
scrub: async (t) => {
|
|
108097
108682
|
if (state.hasAnimation) {
|
|
108098
108683
|
state.animationPaused = true;
|
|
108099
|
-
this.
|
|
108684
|
+
await this.seekTo(t);
|
|
108100
108685
|
}
|
|
108101
108686
|
}
|
|
108102
108687
|
});
|
|
@@ -108318,6 +108903,9 @@ const contentName = (contentUrl, contentFilename) => contentFilename || new URL(
|
|
|
108318
108903
|
// it starts its own prefetch, and docs/streaming-progress.md covers the engine fix that would
|
|
108319
108904
|
// let the octree path reuse the response instead of opting out of it.
|
|
108320
108905
|
const isPrefetchable = (contentUrl, contentFilename) => contentName(contentUrl, contentFilename)?.toLowerCase() !== 'lod-meta.json';
|
|
108906
|
+
// gsaf is an animated splat sequence, which the viewer decodes and plays itself rather than
|
|
108907
|
+
// through an engine parser
|
|
108908
|
+
const isGsaf = (contentUrl, contentFilename) => contentName(contentUrl, contentFilename)?.toLowerCase().endsWith('.gsaf');
|
|
108321
108909
|
const loadGsplat = async (app, config, progressCallback, cancelled) => {
|
|
108322
108910
|
const { contents, contentUrl, contentFilename } = config;
|
|
108323
108911
|
const c = contents;
|
|
@@ -108502,6 +109090,7 @@ const resolveConfig = (options) => ({
|
|
|
108502
109090
|
posterUrl: options.posterUrl,
|
|
108503
109091
|
skyboxUrl: options.skyboxUrl,
|
|
108504
109092
|
collisionUrl: options.collisionUrl,
|
|
109093
|
+
gsafDecoderUrl: options.gsafDecoderUrl,
|
|
108505
109094
|
poster: options.poster ?? (options.posterUrl ? createImage(options.posterUrl) : undefined),
|
|
108506
109095
|
contents: options.contents ??
|
|
108507
109096
|
(isPrefetchable(options.contentUrl, options.contentFilename) ? fetch(options.contentUrl) : undefined),
|
|
@@ -108518,8 +109107,16 @@ const resolveConfig = (options) => ({
|
|
|
108518
109107
|
vr: options.vr ?? false,
|
|
108519
109108
|
aa: options.aa ?? false,
|
|
108520
109109
|
stochastic: options.stochastic ?? false,
|
|
108521
|
-
|
|
108522
|
-
|
|
109110
|
+
// the direct source reads the engine's own splat files, not the container a gsaf sequence
|
|
109111
|
+
// plays through; the work buffer source reads whatever the engine copied
|
|
109112
|
+
splatSource: isGsaf(options.contentUrl, options.contentFilename) ? 'workbuffer' : (options.splatSource ?? 'direct'),
|
|
109113
|
+
// The stochastic renderer's temporal passes assume splats move only with the camera: an
|
|
109114
|
+
// animated sequence would ghost in the accumulation, and the occlusion cull, which forgets the
|
|
109115
|
+
// previous frame's depth only when a node goes away, would test a frame against the one before
|
|
109116
|
+
// it, which keeps its allocation. An explicit variant still overrides both
|
|
109117
|
+
variant: isGsaf(options.contentUrl, options.contentFilename)
|
|
109118
|
+
? `taa:off,cull:off,${options.variant ?? ''}`
|
|
109119
|
+
: (options.variant ?? ''),
|
|
108523
109120
|
budget: options.budget,
|
|
108524
109121
|
framesInFlight: options.framesInFlight ?? 2,
|
|
108525
109122
|
heatmap: options.heatmap ?? false,
|
|
@@ -108574,6 +109171,7 @@ const createViewer = async (options) => {
|
|
|
108574
109171
|
inputMode: platform.mobile ? 'touch' : 'desktop',
|
|
108575
109172
|
cameraMode: 'orbit',
|
|
108576
109173
|
hasAnimation: false,
|
|
109174
|
+
hasSequence: false,
|
|
108577
109175
|
animationDuration: 0,
|
|
108578
109176
|
animationTime: 0,
|
|
108579
109177
|
animationPaused: true,
|
|
@@ -108613,10 +109211,22 @@ const createViewer = async (options) => {
|
|
|
108613
109211
|
// a load continuation can outlive a destroy, so anything that resumes after an await checks
|
|
108614
109212
|
// this before touching the app
|
|
108615
109213
|
let destroyed = false;
|
|
108616
|
-
// Load model
|
|
108617
|
-
const
|
|
109214
|
+
// Load model: a gsaf sequence plays through its own player, which the viewer's timeline drives
|
|
109215
|
+
const onProgress = (progress) => {
|
|
108618
109216
|
state.progress = progress;
|
|
108619
|
-
}
|
|
109217
|
+
};
|
|
109218
|
+
// aborted by the viewer's destroy, which lets a gsaf load release its worker mid-wait
|
|
109219
|
+
const loading = new AbortController();
|
|
109220
|
+
const sequenceLoad = isGsaf(config.contentUrl, config.contentFilename)
|
|
109221
|
+
? loadGsaf(app, config.contents ?? fetch(config.contentUrl), config.gsafDecoderUrl, onProgress, loading.signal).catch((err) => {
|
|
109222
|
+
if (!destroyed)
|
|
109223
|
+
console.log(err);
|
|
109224
|
+
throw err;
|
|
109225
|
+
})
|
|
109226
|
+
: null;
|
|
109227
|
+
const gsplatLoad = sequenceLoad
|
|
109228
|
+
? sequenceLoad.then((player) => player.entity)
|
|
109229
|
+
: loadGsplat(app, config, onProgress, () => destroyed);
|
|
108620
109230
|
// Load skybox (continue without if it fails — e.g. CORS, 404)
|
|
108621
109231
|
const skyboxLoad = config.skyboxUrl &&
|
|
108622
109232
|
loadSkybox(app, config.skyboxUrl)
|
|
@@ -108663,7 +109273,7 @@ const createViewer = async (options) => {
|
|
|
108663
109273
|
};
|
|
108664
109274
|
}
|
|
108665
109275
|
// Create the viewer
|
|
108666
|
-
const viewer = new Viewer(global, gsplatLoad, skyboxLoad, collisionLoad);
|
|
109276
|
+
const viewer = new Viewer(global, gsplatLoad, skyboxLoad, collisionLoad, sequenceLoad);
|
|
108667
109277
|
viewer.onDestroy(persistPreferences(events));
|
|
108668
109278
|
viewer.onDestroy(() => quality.destroy());
|
|
108669
109279
|
const handle = {
|
|
@@ -108690,6 +109300,7 @@ const createViewer = async (options) => {
|
|
|
108690
109300
|
: null;
|
|
108691
109301
|
viewer.onDestroy(() => {
|
|
108692
109302
|
destroyed = true;
|
|
109303
|
+
loading.abort();
|
|
108693
109304
|
});
|
|
108694
109305
|
viewer.onDestroy(disposeCanvas);
|
|
108695
109306
|
if (disposeUI) {
|