@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/dist/viewer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AppBase, AppOptions, CameraComponentSystem, LightComponentSystem, RenderComponentSystem, GSplatComponentSystem, ScriptComponentSystem, ContainerHandler, TextureHandler, GSplatHandler, BinaryHandler, XrManager, Asset, SEMANTIC_POSITION, INDEXFORMAT_UINT32, Vec4, Mat4, Color,
|
|
1
|
+
import { AppBase, AppOptions, CameraComponentSystem, LightComponentSystem, RenderComponentSystem, GSplatComponentSystem, ScriptComponentSystem, ContainerHandler, TextureHandler, GSplatHandler, BinaryHandler, XrManager, Asset, SEMANTIC_POSITION, INDEXFORMAT_UINT32, GSplatContainer, GSplatFormat, Vec3, Entity, Quat, WORKBUFFER_UPDATE_ONCE, Vec4, Mat4, Color, PROJECTION_ORTHOGRAPHIC, ShaderChunks, Texture, ADDRESS_CLAMP_TO_EDGE, FILTER_NEAREST, PIXELFORMAT_RGBA16F, RenderTarget, RenderPassPicker, BlendState, BLENDEQUATION_MIN, BLENDMODE_ONE, PIXELFORMAT_R32U, Shader, BindGroupFormat, UniformBufferFormat, SHADERLANGUAGE_WGSL, BindUniformBufferFormat, BindTextureFormat, BindStorageTextureFormat, SHADERSTAGE_COMPUTE, SAMPLETYPE_FLOAT, SAMPLETYPE_UNFILTERABLE_FLOAT, TEXTUREDIMENSION_2D, UniformFormat, UNIFORMTYPE_VEC4, Compute, PIXELFORMAT_RGBA32U, PIXELFORMAT_R8U, SAMPLETYPE_UINT, PIXELFORMAT_RGBA8, StorageBuffer, BUFFERUSAGE_COPY_DST, PIXELFORMAT_RGBA32F, Vec2, Frustum, BoundingSphere, Camera as Camera$1, BindStorageBufferFormat, UNIFORMTYPE_UINT, SAMPLETYPE_DEPTH, ShaderMaterial, BLEND_NONE, CULLFACE_NONE, MeshInstance, GraphNode, FUNC_LESS, BLEND_PREMULTIPLIED, BUFFERUSAGE_COPY_SRC, UNIFORMTYPE_MAT4, UNIFORMTYPE_VEC2, UNIFORMTYPE_FLOAT, FUNC_ALWAYS, PIXELFORMAT_RGBA16U, FILTER_LINEAR, Mesh, PRIMITIVE_TRIANGLES, RenderPass, SHADER_FORWARD, FramePass, PIXELFORMAT_DEPTH, platform, PROJECTION_PERSPECTIVE, math, Script, SEMANTIC_TEXCOORD0, BLEND_NORMAL, CULLFACE_BACK, StandardMaterial, SHADERLANGUAGE_GLSL, PIXELFORMAT_SRGBA8, DEVICETYPE_WEBGL2, version as version$1, Pose, OrbitController as OrbitController$1, ShaderUtils, ASPECT_AUTO, drawQuadWithShader, PRIMITIVE_TRISTRIP, PIXELFORMAT_R32F, PIXELFORMAT_R16F, GamepadSource, KeyboardMouseSource, MultiTouchSource, InputFrame, Layer, SORTMODE_MANUAL, FUNC_EQUAL, FUNC_LESSEQUAL, RENDERSTYLE_WIREFRAME, BoundingBox, GSPLAT_DEBUG_LOD, GSPLAT_DEBUG_NONE, MiniStats, CameraFrame, TONEMAP_NEUTRAL, TONEMAP_ACES2, TONEMAP_ACES, TONEMAP_HEJL, TONEMAP_FILMIC, TONEMAP_LINEAR, TONEMAP_NONE, LAYERID_SKYBOX, GSPLAT_RENDERER_RASTER_GPU_SORT, GSPLAT_RENDERER_RASTER_CPU_SORT, revision, EventHandler, createGraphicsDevice, Keyboard, TouchDevice as TouchDevice$1, Mouse } from 'playcanvas';
|
|
2
2
|
import { XrControllers } from 'playcanvas/scripts/esm/xr/xr-controllers.mjs';
|
|
3
3
|
import { XrManipulation } from 'playcanvas/scripts/esm/xr/xr-manipulation.mjs';
|
|
4
4
|
import { XrNavigation } from 'playcanvas/scripts/esm/xr/xr-navigation.mjs';
|
|
@@ -1675,6 +1675,473 @@ const observe = (events, target) => {
|
|
|
1675
1675
|
});
|
|
1676
1676
|
};
|
|
1677
1677
|
|
|
1678
|
+
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";
|
|
1679
|
+
|
|
1680
|
+
// The worker's code. It runs in the worker after the decoder glue, which defines
|
|
1681
|
+
// `createGsafModule`, so it is stringified and must not reference anything outside itself.
|
|
1682
|
+
function gsafWorker() {
|
|
1683
|
+
const scope = self;
|
|
1684
|
+
let module = null;
|
|
1685
|
+
let reader = null;
|
|
1686
|
+
// float to half, rounding to nearest
|
|
1687
|
+
const f32 = new Float32Array(1);
|
|
1688
|
+
const u32 = new Uint32Array(f32.buffer);
|
|
1689
|
+
const toHalf = (value) => {
|
|
1690
|
+
f32[0] = value;
|
|
1691
|
+
const x = u32[0];
|
|
1692
|
+
const sign = (x >>> 16) & 0x8000;
|
|
1693
|
+
const exponent = ((x >>> 23) & 0xff) - 112;
|
|
1694
|
+
const mantissa = x & 0x7fffff;
|
|
1695
|
+
if (exponent <= 0) {
|
|
1696
|
+
if (exponent < -10)
|
|
1697
|
+
return sign;
|
|
1698
|
+
return sign | ((((mantissa | 0x800000) >> (1 - exponent)) + 0x1000) >> 13);
|
|
1699
|
+
}
|
|
1700
|
+
if (exponent >= 31)
|
|
1701
|
+
return sign | 0x7c00;
|
|
1702
|
+
return sign | ((exponent << 10) + ((mantissa + 0x1000) >> 13));
|
|
1703
|
+
};
|
|
1704
|
+
// the decoder arrives compiled, so the glue instantiates it rather than fetching it
|
|
1705
|
+
const open = async (bytes, wasm) => {
|
|
1706
|
+
module = await scope.createGsafModule({
|
|
1707
|
+
instantiateWasm: (imports, done) => {
|
|
1708
|
+
WebAssembly.instantiate(wasm, imports).then((instance) => done(instance, wasm));
|
|
1709
|
+
return {};
|
|
1710
|
+
}
|
|
1711
|
+
});
|
|
1712
|
+
reader = module.WasmReader.openFromBytes(new Uint8Array(bytes));
|
|
1713
|
+
if (!reader)
|
|
1714
|
+
throw new Error(`gsaf: ${module.gsafLastError()}`);
|
|
1715
|
+
const h = reader.header();
|
|
1716
|
+
let maxSplats = 0;
|
|
1717
|
+
for (let i = 0; i < h.frameCount; i++) {
|
|
1718
|
+
maxSplats = Math.max(maxSplats, reader.frameInfo(i).splatCount);
|
|
1719
|
+
}
|
|
1720
|
+
return {
|
|
1721
|
+
frameCount: h.frameCount,
|
|
1722
|
+
maxSplats,
|
|
1723
|
+
fps: h.metadata?.fps,
|
|
1724
|
+
boundsMin: Array.from(h.assetBounds.min),
|
|
1725
|
+
boundsMax: Array.from(h.assetBounds.max),
|
|
1726
|
+
canonicalRotation: h.metadata?.canonicalRotation && Array.from(h.metadata.canonicalRotation),
|
|
1727
|
+
canonicalTranslation: h.metadata?.canonicalTranslation && Array.from(h.metadata.canonicalTranslation)
|
|
1728
|
+
};
|
|
1729
|
+
};
|
|
1730
|
+
const decode = (index, frame) => {
|
|
1731
|
+
reader.decodeFrameInto(index, 0);
|
|
1732
|
+
const slot = reader.frameSlot(0);
|
|
1733
|
+
const n = slot.splatCount;
|
|
1734
|
+
// read after the decode: a heap growth inside it replaces the buffer
|
|
1735
|
+
const heap = module.HEAPF32;
|
|
1736
|
+
const positions = heap.subarray(slot.positionsPtr() >> 2, (slot.positionsPtr() >> 2) + n * 3);
|
|
1737
|
+
const rotations = heap.subarray(slot.rotationsPtr() >> 2, (slot.rotationsPtr() >> 2) + n * 4);
|
|
1738
|
+
const scales = heap.subarray(slot.scalesPtr() >> 2, (slot.scalesPtr() >> 2) + n * 3);
|
|
1739
|
+
const colors = heap.subarray(slot.colorsPtr() >> 2, (slot.colorsPtr() >> 2) + n * 4);
|
|
1740
|
+
const { center, color, scale, rotation, centers } = frame;
|
|
1741
|
+
for (let i = 0; i < n; i++) {
|
|
1742
|
+
const i3 = i * 3;
|
|
1743
|
+
const i4 = i * 4;
|
|
1744
|
+
center[i4] = centers[i3] = positions[i3];
|
|
1745
|
+
center[i4 + 1] = centers[i3 + 1] = positions[i3 + 1];
|
|
1746
|
+
center[i4 + 2] = centers[i3 + 2] = positions[i3 + 2];
|
|
1747
|
+
scale[i4] = toHalf(scales[i3]);
|
|
1748
|
+
scale[i4 + 1] = toHalf(scales[i3 + 1]);
|
|
1749
|
+
scale[i4 + 2] = toHalf(scales[i3 + 2]);
|
|
1750
|
+
// both are w, x, y, z / r, g, b, a, as the default format reads them
|
|
1751
|
+
for (let c = 0; c < 4; c++) {
|
|
1752
|
+
rotation[i4 + c] = toHalf(rotations[i4 + c]);
|
|
1753
|
+
color[i4 + c] = toHalf(colors[i4 + c]);
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
frame.index = index;
|
|
1757
|
+
frame.count = n;
|
|
1758
|
+
return frame;
|
|
1759
|
+
};
|
|
1760
|
+
scope.onmessage = async (event) => {
|
|
1761
|
+
const { type } = event.data;
|
|
1762
|
+
try {
|
|
1763
|
+
if (type === 'open') {
|
|
1764
|
+
scope.postMessage({ type, header: await open(event.data.bytes, event.data.wasm) });
|
|
1765
|
+
}
|
|
1766
|
+
else if (type === 'decode') {
|
|
1767
|
+
const frame = decode(event.data.index, event.data.frame);
|
|
1768
|
+
const { center, color, scale, rotation, centers } = frame;
|
|
1769
|
+
scope.postMessage({ type, frame }, [
|
|
1770
|
+
center.buffer,
|
|
1771
|
+
color.buffer,
|
|
1772
|
+
scale.buffer,
|
|
1773
|
+
rotation.buffer,
|
|
1774
|
+
centers.buffer
|
|
1775
|
+
]);
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
catch (err) {
|
|
1779
|
+
scope.postMessage({ type: 'error', message: err?.message ?? String(err) });
|
|
1780
|
+
}
|
|
1781
|
+
};
|
|
1782
|
+
}
|
|
1783
|
+
// The decoder's wasm, fetched and compiled once per url for the page, so a second viewer or a
|
|
1784
|
+
// remount reuses it. A failed compile is forgotten, so the next load tries again.
|
|
1785
|
+
const compiled = new Map();
|
|
1786
|
+
/**
|
|
1787
|
+
* Fetches and compiles the decoder's wasm, streaming where the response is served as
|
|
1788
|
+
* `application/wasm`.
|
|
1789
|
+
*
|
|
1790
|
+
* @param url - The wasm's url; by default the file shipped beside the bundle.
|
|
1791
|
+
* @returns The compiled module.
|
|
1792
|
+
*/
|
|
1793
|
+
const compileGsafDecoder = (url) => {
|
|
1794
|
+
// a literal `new URL(..., import.meta.url)`, so a host's bundler emits the file with its own
|
|
1795
|
+
const href = url ?? new URL('./gsaf-decoder.wasm', import.meta.url).href;
|
|
1796
|
+
let module = compiled.get(href);
|
|
1797
|
+
if (!module) {
|
|
1798
|
+
module = (async () => {
|
|
1799
|
+
const response = await fetch(href);
|
|
1800
|
+
if (!response.ok) {
|
|
1801
|
+
throw new Error(`gsaf: ${response.status} ${response.statusText} fetching the decoder ${href}`);
|
|
1802
|
+
}
|
|
1803
|
+
try {
|
|
1804
|
+
return await WebAssembly.compileStreaming(response.clone());
|
|
1805
|
+
}
|
|
1806
|
+
catch {
|
|
1807
|
+
// a server that does not send application/wasm
|
|
1808
|
+
return WebAssembly.compile(await response.arrayBuffer());
|
|
1809
|
+
}
|
|
1810
|
+
})();
|
|
1811
|
+
compiled.set(href, module);
|
|
1812
|
+
module.catch(() => compiled.delete(href));
|
|
1813
|
+
}
|
|
1814
|
+
return module;
|
|
1815
|
+
};
|
|
1816
|
+
/**
|
|
1817
|
+
* The gsaf decoder in a worker, so decoding never stalls the main thread. One request is in
|
|
1818
|
+
* flight at a time.
|
|
1819
|
+
*/
|
|
1820
|
+
class GsafDecoder {
|
|
1821
|
+
worker;
|
|
1822
|
+
pending = null;
|
|
1823
|
+
constructor() {
|
|
1824
|
+
const source = `${decoderSource}\n(${gsafWorker.toString()})();\n`;
|
|
1825
|
+
const url = URL.createObjectURL(new Blob([source], { type: 'application/javascript' }));
|
|
1826
|
+
this.worker = new Worker(url);
|
|
1827
|
+
URL.revokeObjectURL(url);
|
|
1828
|
+
this.worker.onmessage = (event) => {
|
|
1829
|
+
const pending = this.pending;
|
|
1830
|
+
this.pending = null;
|
|
1831
|
+
if (event.data.type === 'error') {
|
|
1832
|
+
pending?.reject(new Error(event.data.message));
|
|
1833
|
+
}
|
|
1834
|
+
else {
|
|
1835
|
+
pending?.resolve(event.data);
|
|
1836
|
+
}
|
|
1837
|
+
};
|
|
1838
|
+
this.worker.onerror = (event) => {
|
|
1839
|
+
const pending = this.pending;
|
|
1840
|
+
this.pending = null;
|
|
1841
|
+
pending?.reject(new Error(event.message || 'gsaf: the decoder worker failed'));
|
|
1842
|
+
};
|
|
1843
|
+
}
|
|
1844
|
+
stopped = false;
|
|
1845
|
+
request(type, message, transfer) {
|
|
1846
|
+
if (this.stopped)
|
|
1847
|
+
return Promise.reject(new Error('gsaf: the decoder was stopped'));
|
|
1848
|
+
return new Promise((resolve, reject) => {
|
|
1849
|
+
this.pending = { resolve: resolve, reject };
|
|
1850
|
+
this.worker.postMessage({ type, ...message }, transfer);
|
|
1851
|
+
});
|
|
1852
|
+
}
|
|
1853
|
+
/**
|
|
1854
|
+
* Opens the file; the bytes are transferred to the worker.
|
|
1855
|
+
*
|
|
1856
|
+
* @param bytes - The file.
|
|
1857
|
+
* @param wasm - The decoder, from {@link compileGsafDecoder}.
|
|
1858
|
+
* @returns The file's header.
|
|
1859
|
+
*/
|
|
1860
|
+
async open(bytes, wasm) {
|
|
1861
|
+
const { header } = await this.request('open', { bytes, wasm }, [bytes]);
|
|
1862
|
+
return header;
|
|
1863
|
+
}
|
|
1864
|
+
/** Decodes a frame into the given buffers, which come back with it. */
|
|
1865
|
+
async decode(index, buffers) {
|
|
1866
|
+
const { center, color, scale, rotation, centers } = buffers;
|
|
1867
|
+
const { frame } = await this.request('decode', { index, frame: { ...buffers, index, count: 0 } }, [center.buffer, color.buffer, scale.buffer, rotation.buffer, centers.buffer]);
|
|
1868
|
+
return frame;
|
|
1869
|
+
}
|
|
1870
|
+
/** Stops the worker. A request in flight, and any made after, rejects. Idempotent. */
|
|
1871
|
+
destroy() {
|
|
1872
|
+
if (this.stopped)
|
|
1873
|
+
return;
|
|
1874
|
+
this.stopped = true;
|
|
1875
|
+
this.worker.terminate();
|
|
1876
|
+
const pending = this.pending;
|
|
1877
|
+
this.pending = null;
|
|
1878
|
+
pending?.reject(new Error('gsaf: the decoder was stopped'));
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
|
|
1882
|
+
// the playback rate when the file carries no fps hint
|
|
1883
|
+
const DEFAULT_FPS = 30;
|
|
1884
|
+
const STREAMS = [
|
|
1885
|
+
['dataCenter', 'center'],
|
|
1886
|
+
['dataColor', 'color'],
|
|
1887
|
+
['dataScale', 'scale'],
|
|
1888
|
+
['dataRotation', 'rotation']
|
|
1889
|
+
];
|
|
1890
|
+
// Reads the response whole, reporting progress. Chunks are gathered rather than written into a
|
|
1891
|
+
// buffer of the declared length, which is the compressed length when the server encodes it.
|
|
1892
|
+
const readBytes = async (response, progressCallback) => {
|
|
1893
|
+
if (!response.ok) {
|
|
1894
|
+
throw new Error(`gsaf: ${response.status} ${response.statusText} fetching ${response.url}`);
|
|
1895
|
+
}
|
|
1896
|
+
const length = Number(response.headers.get('content-length')) || 0;
|
|
1897
|
+
if (!response.body || !length) {
|
|
1898
|
+
return response.arrayBuffer();
|
|
1899
|
+
}
|
|
1900
|
+
const chunks = [];
|
|
1901
|
+
let received = 0;
|
|
1902
|
+
const reader = response.body.getReader();
|
|
1903
|
+
for (;;) {
|
|
1904
|
+
const { done, value } = await reader.read();
|
|
1905
|
+
if (done)
|
|
1906
|
+
break;
|
|
1907
|
+
chunks.push(value);
|
|
1908
|
+
received += value.length;
|
|
1909
|
+
progressCallback(Math.trunc(Math.min(1, received / length) * 100));
|
|
1910
|
+
}
|
|
1911
|
+
const bytes = new Uint8Array(received);
|
|
1912
|
+
let offset = 0;
|
|
1913
|
+
for (const chunk of chunks) {
|
|
1914
|
+
bytes.set(chunk, offset);
|
|
1915
|
+
offset += chunk.length;
|
|
1916
|
+
}
|
|
1917
|
+
return bytes.buffer;
|
|
1918
|
+
};
|
|
1919
|
+
/**
|
|
1920
|
+
* An animated splat sequence playing through a container. The viewer's timeline drives it:
|
|
1921
|
+
* {@link paused} stops its clock, {@link seek} moves it and {@link time} is where it is. Each
|
|
1922
|
+
* update decodes the frame due at that time, in a worker, so a slow decode skips frames rather
|
|
1923
|
+
* than slowing playback; the decoder continues forward from the frame it holds and replays from
|
|
1924
|
+
* the last keyframe to go back. Destroying {@link entity} stops it and releases the worker and
|
|
1925
|
+
* the container.
|
|
1926
|
+
*/
|
|
1927
|
+
class GsafPlayer {
|
|
1928
|
+
/** The gsplat entity, showing the frame at {@link time}. */
|
|
1929
|
+
entity;
|
|
1930
|
+
/**
|
|
1931
|
+
* Whether the sequence plays: more than one frame, on WebGPU. WebGL shows the first frame
|
|
1932
|
+
* only, since its sorter is asynchronous and lands a frame or more behind the data, and gsaf
|
|
1933
|
+
* reorders splats from frame to frame (survivors in their previous order, births appended),
|
|
1934
|
+
* so an order computed for one frame is wrong for the next.
|
|
1935
|
+
*/
|
|
1936
|
+
animated;
|
|
1937
|
+
/** Length of the sequence in seconds. */
|
|
1938
|
+
duration;
|
|
1939
|
+
/** Stops the clock; paused until the viewer starts it. */
|
|
1940
|
+
paused = true;
|
|
1941
|
+
app;
|
|
1942
|
+
decoder;
|
|
1943
|
+
fps;
|
|
1944
|
+
frameCount;
|
|
1945
|
+
_time = 0;
|
|
1946
|
+
// the frame on screen, and the buffers it came in, null while a decode has them
|
|
1947
|
+
shown = 0;
|
|
1948
|
+
buffers;
|
|
1949
|
+
// seeks waiting for their frame
|
|
1950
|
+
waiters = [];
|
|
1951
|
+
// a decode that failed, after which the player shows its last frame and every seek fails
|
|
1952
|
+
failure = null;
|
|
1953
|
+
destroyed = false;
|
|
1954
|
+
constructor(app, entity, decoder, frameCount, fps, first, animated) {
|
|
1955
|
+
this.app = app;
|
|
1956
|
+
this.entity = entity;
|
|
1957
|
+
this.decoder = decoder;
|
|
1958
|
+
this.frameCount = frameCount;
|
|
1959
|
+
this.fps = fps;
|
|
1960
|
+
this.duration = frameCount / fps;
|
|
1961
|
+
this.buffers = first;
|
|
1962
|
+
this.animated = animated;
|
|
1963
|
+
const onUpdate = (dt) => {
|
|
1964
|
+
if (!this.paused)
|
|
1965
|
+
this._time = (this._time + dt) % this.duration;
|
|
1966
|
+
this.pump();
|
|
1967
|
+
};
|
|
1968
|
+
if (animated)
|
|
1969
|
+
app.on('update', onUpdate);
|
|
1970
|
+
entity.once('destroy', () => {
|
|
1971
|
+
this.destroyed = true;
|
|
1972
|
+
app.off('update', onUpdate);
|
|
1973
|
+
this.settle();
|
|
1974
|
+
});
|
|
1975
|
+
}
|
|
1976
|
+
/** The playhead, in seconds from the start of the sequence. */
|
|
1977
|
+
get time() {
|
|
1978
|
+
return this._time;
|
|
1979
|
+
}
|
|
1980
|
+
/**
|
|
1981
|
+
* Moves the playhead, wrapping it into the sequence.
|
|
1982
|
+
*
|
|
1983
|
+
* @param time - The time in seconds.
|
|
1984
|
+
* @returns Resolves once the frame at that time is on screen, or the player is destroyed;
|
|
1985
|
+
* rejects once a decode has failed.
|
|
1986
|
+
*/
|
|
1987
|
+
seek(time) {
|
|
1988
|
+
if (this.failure)
|
|
1989
|
+
return Promise.reject(this.failure);
|
|
1990
|
+
if (!this.animated)
|
|
1991
|
+
return Promise.resolve();
|
|
1992
|
+
// a time already in range is kept exactly, so it lands on the frame it names
|
|
1993
|
+
const wrapped = time % this.duration;
|
|
1994
|
+
this._time = wrapped < 0 ? wrapped + this.duration : wrapped;
|
|
1995
|
+
const landed = new Promise((resolve, reject) => this.waiters.push({ resolve, reject }));
|
|
1996
|
+
this.pump();
|
|
1997
|
+
return landed;
|
|
1998
|
+
}
|
|
1999
|
+
settle(err) {
|
|
2000
|
+
const { waiters } = this;
|
|
2001
|
+
this.waiters = [];
|
|
2002
|
+
for (const waiter of waiters) {
|
|
2003
|
+
if (err)
|
|
2004
|
+
waiter.reject(err);
|
|
2005
|
+
else
|
|
2006
|
+
waiter.resolve();
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
// decode the frame due now, unless it is on screen or a decode is already in flight
|
|
2010
|
+
pump() {
|
|
2011
|
+
if (this.destroyed || this.failure || !this.buffers)
|
|
2012
|
+
return;
|
|
2013
|
+
// a frame's own start time can land a rounding error short of it
|
|
2014
|
+
const due = Math.min(this.frameCount - 1, Math.floor(this._time * this.fps + 1e-6));
|
|
2015
|
+
if (due === this.shown) {
|
|
2016
|
+
this.settle();
|
|
2017
|
+
return;
|
|
2018
|
+
}
|
|
2019
|
+
const buffers = this.buffers;
|
|
2020
|
+
this.buffers = null;
|
|
2021
|
+
this.decoder.decode(due, buffers).then((frame) => {
|
|
2022
|
+
// the worker is terminated with the entity, so this only runs while alive
|
|
2023
|
+
uploadFrame(this.app, this.entity.gsplat.resource, frame);
|
|
2024
|
+
// the engine re-copies a resource into its work buffer only when its allocation
|
|
2025
|
+
// changes, and a frame keeps the container's, so ask for the copy
|
|
2026
|
+
this.entity.gsplat.workBufferUpdate = WORKBUFFER_UPDATE_ONCE;
|
|
2027
|
+
this.shown = frame.index;
|
|
2028
|
+
this.buffers = frame;
|
|
2029
|
+
this.pump();
|
|
2030
|
+
}, (err) => {
|
|
2031
|
+
// the worker was terminated with the entity
|
|
2032
|
+
if (this.destroyed)
|
|
2033
|
+
return;
|
|
2034
|
+
console.error(err);
|
|
2035
|
+
this.failure = err;
|
|
2036
|
+
this.settle(err);
|
|
2037
|
+
});
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
const uploadFrame = (app, container, frame) => {
|
|
2041
|
+
for (const [name, key] of STREAMS) {
|
|
2042
|
+
const texture = container.getTexture(name);
|
|
2043
|
+
texture.lock().set(frame[key]);
|
|
2044
|
+
texture.unlock();
|
|
2045
|
+
}
|
|
2046
|
+
container.centers.set(frame.centers.subarray(0, frame.count * 3));
|
|
2047
|
+
container.update(frame.count);
|
|
2048
|
+
app.renderNextFrame = true;
|
|
2049
|
+
};
|
|
2050
|
+
/**
|
|
2051
|
+
* Loads a gsaf file (an animated, compressed splat sequence) into a {@link GsafPlayer}. Frames
|
|
2052
|
+
* are decoded in a worker and written into a {@link GSplatContainer} in the engine's default
|
|
2053
|
+
* float format, which takes gsaf's render-ready values (linear scales, `w, x, y, z` rotations,
|
|
2054
|
+
* activated colors) as they are.
|
|
2055
|
+
*
|
|
2056
|
+
* @param app - The application.
|
|
2057
|
+
* @param response - The file's response.
|
|
2058
|
+
* @param decoderUrl - The decoder's wasm, if not the file beside the bundle.
|
|
2059
|
+
* @param progressCallback - Receives the download progress, 0 to 100.
|
|
2060
|
+
* @param signal - Aborted when the viewer is destroyed. Its handlers run before the app's own
|
|
2061
|
+
* destroy, so a load in flight releases its worker and container while the device is alive.
|
|
2062
|
+
* @returns The player, paused on the first frame.
|
|
2063
|
+
*/
|
|
2064
|
+
const loadGsaf = async (app, response, decoderUrl, progressCallback, signal) => {
|
|
2065
|
+
const fail = () => new Error('loadGsaf: the viewer was destroyed while loading');
|
|
2066
|
+
// the decoder compiles while the file downloads
|
|
2067
|
+
const wasm = compileGsafDecoder(decoderUrl);
|
|
2068
|
+
wasm.catch(() => {
|
|
2069
|
+
// reported by the await below, once the download is done
|
|
2070
|
+
});
|
|
2071
|
+
const bytes = await readBytes(await response, progressCallback);
|
|
2072
|
+
if (signal.aborted)
|
|
2073
|
+
throw fail();
|
|
2074
|
+
const compiledWasm = await wasm;
|
|
2075
|
+
if (signal.aborted)
|
|
2076
|
+
throw fail();
|
|
2077
|
+
const decoder = new GsafDecoder();
|
|
2078
|
+
let container = null;
|
|
2079
|
+
// until the entity owns them, a destroy stops the worker at once, which rejects the request
|
|
2080
|
+
// it was serving, and frees the container
|
|
2081
|
+
const onAbort = () => {
|
|
2082
|
+
decoder.destroy();
|
|
2083
|
+
container?.destroy();
|
|
2084
|
+
container = null;
|
|
2085
|
+
};
|
|
2086
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
2087
|
+
try {
|
|
2088
|
+
const header = await decoder.open(bytes, compiledWasm);
|
|
2089
|
+
if (signal.aborted)
|
|
2090
|
+
throw fail();
|
|
2091
|
+
const device = app.graphicsDevice;
|
|
2092
|
+
container = new GSplatContainer(device, header.maxSplats, GSplatFormat.createDefaultFormat(device));
|
|
2093
|
+
container.aabb.setMinMax(new Vec3(header.boundsMin), new Vec3(header.boundsMax));
|
|
2094
|
+
const texture = container.getTexture('dataCenter');
|
|
2095
|
+
const capacity = texture.width * texture.height * 4;
|
|
2096
|
+
const first = await decoder.decode(0, {
|
|
2097
|
+
center: new Float32Array(capacity),
|
|
2098
|
+
color: new Uint16Array(capacity),
|
|
2099
|
+
scale: new Uint16Array(capacity),
|
|
2100
|
+
rotation: new Uint16Array(capacity),
|
|
2101
|
+
centers: new Float32Array(header.maxSplats * 3)
|
|
2102
|
+
});
|
|
2103
|
+
if (signal.aborted)
|
|
2104
|
+
throw fail();
|
|
2105
|
+
signal.removeEventListener('abort', onAbort);
|
|
2106
|
+
uploadFrame(app, container, first);
|
|
2107
|
+
// always name the app: the engine's default is the most recently created one, which is
|
|
2108
|
+
// another viewer's when two share a page
|
|
2109
|
+
const entity = new Entity('gsplat', app);
|
|
2110
|
+
if (header.canonicalRotation) {
|
|
2111
|
+
// the canonical frame is y up and -z forward, the engine's own
|
|
2112
|
+
const [w, x, y, z] = header.canonicalRotation;
|
|
2113
|
+
entity.setLocalRotation(new Quat(x, y, z, w));
|
|
2114
|
+
if (header.canonicalTranslation) {
|
|
2115
|
+
entity.setLocalPosition(new Vec3(header.canonicalTranslation));
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
else {
|
|
2119
|
+
entity.setLocalEulerAngles(0, 0, 180);
|
|
2120
|
+
}
|
|
2121
|
+
entity.addComponent('gsplat', {
|
|
2122
|
+
unified: true,
|
|
2123
|
+
resource: container
|
|
2124
|
+
});
|
|
2125
|
+
app.root.addChild(entity);
|
|
2126
|
+
const animated = header.frameCount > 1 && device.isWebGPU;
|
|
2127
|
+
if (!animated)
|
|
2128
|
+
decoder.destroy();
|
|
2129
|
+
const owned = container;
|
|
2130
|
+
entity.once('destroy', () => {
|
|
2131
|
+
decoder.destroy();
|
|
2132
|
+
owned.destroy();
|
|
2133
|
+
});
|
|
2134
|
+
const fps = header.fps > 0 ? header.fps : DEFAULT_FPS;
|
|
2135
|
+
return new GsafPlayer(app, entity, decoder, header.frameCount, fps, first, animated);
|
|
2136
|
+
}
|
|
2137
|
+
catch (err) {
|
|
2138
|
+
signal.removeEventListener('abort', onAbort);
|
|
2139
|
+
decoder.destroy();
|
|
2140
|
+
container?.destroy();
|
|
2141
|
+
throw signal.aborted ? fail() : err;
|
|
2142
|
+
}
|
|
2143
|
+
};
|
|
2144
|
+
|
|
1678
2145
|
var deJson = {
|
|
1679
2146
|
"settings.performance-mode": "Leistungsmodus",
|
|
1680
2147
|
"settings.gaming-controls": "Gaming-Steuerung",
|
|
@@ -9513,7 +9980,7 @@ const resolveTouchInsetBottom = (insetBottom) => {
|
|
|
9513
9980
|
return Number.isFinite(value) ? Math.min(TOUCH_INSET_BOTTOM_MAX, Math.max(0, value)) : 0;
|
|
9514
9981
|
};
|
|
9515
9982
|
|
|
9516
|
-
var version = "1.
|
|
9983
|
+
var version = "1.41.0";
|
|
9517
9984
|
|
|
9518
9985
|
class Tooltip {
|
|
9519
9986
|
register;
|
|
@@ -10717,11 +11184,13 @@ const initPlayback = (viewer, root, showUI) => {
|
|
|
10717
11184
|
const handle = root.querySelector('.sse-handle');
|
|
10718
11185
|
const time = root.querySelector('.sse-time');
|
|
10719
11186
|
const available = () => state.loaded && state.hasAnimation;
|
|
11187
|
+
// a sequence plays in every camera mode; the camera's animation only in its own
|
|
11188
|
+
const animating = () => state.hasSequence || state.cameraMode === 'anim';
|
|
10720
11189
|
const updateControls = () => {
|
|
10721
|
-
const playing =
|
|
11190
|
+
const playing = animating() && !state.animationPaused;
|
|
10722
11191
|
play.classList.toggle('sse-hidden', !available() || playing);
|
|
10723
11192
|
pause.classList.toggle('sse-hidden', !available() || !playing);
|
|
10724
|
-
timeline.classList.toggle('sse-hidden', !available() ||
|
|
11193
|
+
timeline.classList.toggle('sse-hidden', !available() || !animating());
|
|
10725
11194
|
};
|
|
10726
11195
|
const updateSlider = () => {
|
|
10727
11196
|
const position = state.animationDuration > 0 ? (state.animationTime / state.animationDuration) * 100 : 0;
|
|
@@ -10732,13 +11201,15 @@ const initPlayback = (viewer, root, showUI) => {
|
|
|
10732
11201
|
const onPlay = () => {
|
|
10733
11202
|
if (!available())
|
|
10734
11203
|
return;
|
|
10735
|
-
state.
|
|
11204
|
+
if (!state.hasSequence)
|
|
11205
|
+
state.cameraMode = 'anim';
|
|
10736
11206
|
state.animationPaused = false;
|
|
10737
11207
|
};
|
|
10738
11208
|
const onPause = () => {
|
|
10739
11209
|
if (!available())
|
|
10740
11210
|
return;
|
|
10741
|
-
state.
|
|
11211
|
+
if (!state.hasSequence)
|
|
11212
|
+
state.cameraMode = 'anim';
|
|
10742
11213
|
state.animationPaused = true;
|
|
10743
11214
|
};
|
|
10744
11215
|
const scrub = (event) => {
|
|
@@ -10783,6 +11254,7 @@ const initPlayback = (viewer, root, showUI) => {
|
|
|
10783
11254
|
const subscriptions = [
|
|
10784
11255
|
events.on('loaded:changed', updateControls),
|
|
10785
11256
|
events.on('hasAnimation:changed', updateControls),
|
|
11257
|
+
events.on('hasSequence:changed', updateControls),
|
|
10786
11258
|
events.on('cameraMode:changed', updateControls),
|
|
10787
11259
|
events.on('animationPaused:changed', updateControls),
|
|
10788
11260
|
events.on('animationTime:changed', updateSlider),
|
|
@@ -13912,6 +14384,14 @@ const initXr = (global) => {
|
|
|
13912
14384
|
// The menu held in the hand, which takes the selects that start on it before the navigation aims
|
|
13913
14385
|
// with them
|
|
13914
14386
|
const menu = new XrPalmMenu(app, camera, [
|
|
14387
|
+
{
|
|
14388
|
+
// an animated splat sequence's transport; the page's timeline is out of sight here
|
|
14389
|
+
label: () => localize(state.animationPaused ? 'tooltip.play' : 'tooltip.pause'),
|
|
14390
|
+
visible: () => state.hasSequence,
|
|
14391
|
+
action: () => {
|
|
14392
|
+
state.animationPaused = !state.animationPaused;
|
|
14393
|
+
}
|
|
14394
|
+
},
|
|
13915
14395
|
{ label: () => localize('tooltip.reset-camera'), action: placeAtStart },
|
|
13916
14396
|
{
|
|
13917
14397
|
label: () => `${localize('settings.quality')}: ${localize(`settings.quality-${quality.level}`)}`,
|
|
@@ -16459,7 +16939,14 @@ class CameraManager {
|
|
|
16459
16939
|
setCollision;
|
|
16460
16940
|
// holds the camera state
|
|
16461
16941
|
camera = new Camera();
|
|
16462
|
-
|
|
16942
|
+
/**
|
|
16943
|
+
* @param global - The viewer's globals.
|
|
16944
|
+
* @param bbox - The scene bounds.
|
|
16945
|
+
* @param collision - Collision data, if it has already loaded.
|
|
16946
|
+
* @param cameraAnimation - Whether the camera has an animation. Off for an animated splat
|
|
16947
|
+
* sequence, whose frames the timeline plays instead; the timeline state is then the viewer's.
|
|
16948
|
+
*/
|
|
16949
|
+
constructor(global, bbox, collision = null, cameraAnimation = true) {
|
|
16463
16950
|
const { events, settings, state } = global;
|
|
16464
16951
|
let walkAllowed = isWalkAllowed(bbox, collision);
|
|
16465
16952
|
const camera0 = settings.cameras[0]?.initial;
|
|
@@ -16486,7 +16973,7 @@ class CameraManager {
|
|
|
16486
16973
|
};
|
|
16487
16974
|
// object experience starts outside the bounding box
|
|
16488
16975
|
const isObjectExperience = !bbox.containsPoint(resetCamera.position);
|
|
16489
|
-
const animTrack = getAnimTrack(resetCamera, isObjectExperience);
|
|
16976
|
+
const animTrack = cameraAnimation ? getAnimTrack(resetCamera, isObjectExperience) : null;
|
|
16490
16977
|
const controllers = {
|
|
16491
16978
|
orbit: new OrbitController(),
|
|
16492
16979
|
fly: new FlyController(),
|
|
@@ -16510,10 +16997,12 @@ class CameraManager {
|
|
|
16510
16997
|
return controllers[cameraMode];
|
|
16511
16998
|
};
|
|
16512
16999
|
// set the global animation flag
|
|
16513
|
-
|
|
16514
|
-
|
|
17000
|
+
if (cameraAnimation) {
|
|
17001
|
+
state.hasAnimation = !!controllers.anim;
|
|
17002
|
+
state.animationDuration = controllers.anim ? controllers.anim.animState.cursor.duration : 0;
|
|
17003
|
+
}
|
|
16515
17004
|
// initialize camera mode and initial camera position
|
|
16516
|
-
state.cameraMode =
|
|
17005
|
+
state.cameraMode = controllers.anim ? 'anim' : isObjectExperience ? 'orbit' : walkAllowed ? 'walk' : 'fly';
|
|
16517
17006
|
this.camera.copy(resetCamera);
|
|
16518
17007
|
const target = new Camera(this.camera); // the active controller updates this
|
|
16519
17008
|
const from = new Camera(this.camera); // stores the previous camera state during transition
|
|
@@ -16626,7 +17115,12 @@ class CameraManager {
|
|
|
16626
17115
|
}
|
|
16627
17116
|
break;
|
|
16628
17117
|
case 'playPause':
|
|
16629
|
-
if (
|
|
17118
|
+
if (!controllers.anim) {
|
|
17119
|
+
// a sequence plays in every camera mode
|
|
17120
|
+
if (state.hasAnimation)
|
|
17121
|
+
state.animationPaused = !state.animationPaused;
|
|
17122
|
+
}
|
|
17123
|
+
else if (state.hasAnimation) {
|
|
16630
17124
|
if (state.cameraMode === 'anim') {
|
|
16631
17125
|
state.animationPaused = !state.animationPaused;
|
|
16632
17126
|
}
|
|
@@ -16670,6 +17164,13 @@ class CameraManager {
|
|
|
16670
17164
|
});
|
|
16671
17165
|
// handle camera mode switching
|
|
16672
17166
|
events.on('cameraMode:changed', (value, prev) => {
|
|
17167
|
+
// no animation to enter: a host's write is undone, and the undo has nothing to exit
|
|
17168
|
+
if (!getController(value)) {
|
|
17169
|
+
state.cameraMode = prev;
|
|
17170
|
+
return;
|
|
17171
|
+
}
|
|
17172
|
+
if (!getController(prev))
|
|
17173
|
+
return;
|
|
16673
17174
|
// Host state writes and the walk toggle must remember the same return mode.
|
|
16674
17175
|
if (value === 'walk') {
|
|
16675
17176
|
preWalkMode = prev;
|
|
@@ -16698,6 +17199,8 @@ class CameraManager {
|
|
|
16698
17199
|
}
|
|
16699
17200
|
});
|
|
16700
17201
|
this.seek = (time) => {
|
|
17202
|
+
if (!controllers.anim)
|
|
17203
|
+
return;
|
|
16701
17204
|
// switch to animation camera if we're not already there
|
|
16702
17205
|
state.cameraMode = 'anim';
|
|
16703
17206
|
// set time
|
|
@@ -16953,7 +17456,7 @@ class Capture {
|
|
|
16953
17456
|
camera.horizontalFov = srcW >= srcH;
|
|
16954
17457
|
this.setCameraTarget(srcRT);
|
|
16955
17458
|
if (time !== undefined && scrub) {
|
|
16956
|
-
scrub(time);
|
|
17459
|
+
await scrub(time);
|
|
16957
17460
|
}
|
|
16958
17461
|
this.app.renderNextFrame = true;
|
|
16959
17462
|
await new Promise((resolve) => {
|
|
@@ -21132,6 +21635,8 @@ class Viewer {
|
|
|
21132
21635
|
miniStats = null;
|
|
21133
21636
|
/** Set once {@link destroy} has run. Load continuations check it and bail. */
|
|
21134
21637
|
destroyed = false;
|
|
21638
|
+
/** An animated splat sequence the timeline plays, once loaded; null for other content. */
|
|
21639
|
+
sequence = null;
|
|
21135
21640
|
disposers = [];
|
|
21136
21641
|
fullscreen;
|
|
21137
21642
|
xr;
|
|
@@ -21151,7 +21656,7 @@ class Viewer {
|
|
|
21151
21656
|
// with it the captured image, reachable until the viewer went away.
|
|
21152
21657
|
abortHandlers = new Set();
|
|
21153
21658
|
origChunks;
|
|
21154
|
-
constructor(global, gsplatLoad, skyboxLoad, collisionLoad) {
|
|
21659
|
+
constructor(global, gsplatLoad, skyboxLoad, collisionLoad, sequenceLoad = null) {
|
|
21155
21660
|
this.global = global;
|
|
21156
21661
|
const { app, settings, config, events, state, camera, renderer } = global;
|
|
21157
21662
|
const { graphicsDevice } = app;
|
|
@@ -21290,8 +21795,9 @@ class Viewer {
|
|
|
21290
21795
|
if (!config.exposeGlobals)
|
|
21291
21796
|
return;
|
|
21292
21797
|
window.scrubTo = async (time) => {
|
|
21293
|
-
this.
|
|
21798
|
+
const landed = this.seekTo(time);
|
|
21294
21799
|
state.animationPaused = true;
|
|
21800
|
+
await this.untilDestroyed(landed);
|
|
21295
21801
|
let onFrame;
|
|
21296
21802
|
const rendered = new Promise((resolve) => {
|
|
21297
21803
|
onFrame = resolve;
|
|
@@ -21404,10 +21910,26 @@ class Viewer {
|
|
|
21404
21910
|
attachCollision?.(collision);
|
|
21405
21911
|
}, ignoreLoadFailure);
|
|
21406
21912
|
// wait for the model to load
|
|
21407
|
-
Promise.all([gsplatLoad, skyboxLoad]).then((results) => {
|
|
21913
|
+
Promise.all([gsplatLoad, skyboxLoad, sequenceLoad]).then((results) => {
|
|
21408
21914
|
// destroyed while loading: the app is gone, so there is nothing to wire up
|
|
21409
21915
|
if (this.destroyed)
|
|
21410
21916
|
return;
|
|
21917
|
+
// A sequence's frames are the timeline, in every camera mode, and the camera has no
|
|
21918
|
+
// animation of its own. The firstFrame handler starts it, as it would the camera's
|
|
21919
|
+
const sequence = results[2];
|
|
21920
|
+
if (sequence?.animated) {
|
|
21921
|
+
this.sequence = sequence;
|
|
21922
|
+
state.hasSequence = true;
|
|
21923
|
+
state.hasAnimation = true;
|
|
21924
|
+
state.animationDuration = sequence.duration;
|
|
21925
|
+
sequence.paused = state.animationPaused;
|
|
21926
|
+
events.on('animationPaused:changed', (paused) => {
|
|
21927
|
+
sequence.paused = paused;
|
|
21928
|
+
});
|
|
21929
|
+
app.on('update', () => {
|
|
21930
|
+
state.animationTime = sequence.time;
|
|
21931
|
+
});
|
|
21932
|
+
}
|
|
21411
21933
|
const gsplatComponent = results[0].gsplat;
|
|
21412
21934
|
// get scene bounding box
|
|
21413
21935
|
const gsplatBbox = gsplatComponent.customAabb;
|
|
@@ -21441,7 +21963,7 @@ class Viewer {
|
|
|
21441
21963
|
// for development pages (the bench measures pick noise), as splatRenderer:ready
|
|
21442
21964
|
events.fire('picker:ready', this.picker);
|
|
21443
21965
|
this.inputController = new InputController(global, this.picker);
|
|
21444
|
-
this.cameraManager = new CameraManager(global, sceneBound);
|
|
21966
|
+
this.cameraManager = new CameraManager(global, sceneBound, null, !sequence);
|
|
21445
21967
|
applyCamera(this.cameraManager.camera);
|
|
21446
21968
|
// the vr flag's prompt (ui/vr-prompt.ts) can start a session from here on, where
|
|
21447
21969
|
// startXR waits for the scene to finish loading: the camera is where the session
|
|
@@ -21688,6 +22210,13 @@ class Viewer {
|
|
|
21688
22210
|
return this.xr.end();
|
|
21689
22211
|
}
|
|
21690
22212
|
seek(time) {
|
|
22213
|
+
this.seekTo(time).catch(() => {
|
|
22214
|
+
// a sequence's failed decode, which the player has already reported
|
|
22215
|
+
});
|
|
22216
|
+
}
|
|
22217
|
+
// seek(), resolving once the frame at `time` is ready to render: at once for the camera's
|
|
22218
|
+
// animation, once decoded for a sequence's
|
|
22219
|
+
seekTo(time) {
|
|
21691
22220
|
this.requireLoaded('seek');
|
|
21692
22221
|
const { state, app } = this.global;
|
|
21693
22222
|
if (!state.hasAnimation) {
|
|
@@ -21696,8 +22225,14 @@ class Viewer {
|
|
|
21696
22225
|
if (!Number.isFinite(time)) {
|
|
21697
22226
|
throw new Error('seek: time must be finite');
|
|
21698
22227
|
}
|
|
21699
|
-
this.cameraManager.seek(time);
|
|
21700
22228
|
app.renderNextFrame = true;
|
|
22229
|
+
if (this.sequence) {
|
|
22230
|
+
const landed = this.sequence.seek(time);
|
|
22231
|
+
state.animationTime = this.sequence.time;
|
|
22232
|
+
return landed;
|
|
22233
|
+
}
|
|
22234
|
+
this.cameraManager.seek(time);
|
|
22235
|
+
return Promise.resolve();
|
|
21701
22236
|
}
|
|
21702
22237
|
/**
|
|
21703
22238
|
* Render the scene, with post effects, into an offscreen supersampled target, GPU
|
|
@@ -21720,10 +22255,10 @@ class Viewer {
|
|
|
21720
22255
|
width,
|
|
21721
22256
|
height,
|
|
21722
22257
|
supersample,
|
|
21723
|
-
scrub: (t) => {
|
|
22258
|
+
scrub: async (t) => {
|
|
21724
22259
|
if (state.hasAnimation) {
|
|
21725
22260
|
state.animationPaused = true;
|
|
21726
|
-
this.
|
|
22261
|
+
await this.seekTo(t);
|
|
21727
22262
|
}
|
|
21728
22263
|
}
|
|
21729
22264
|
});
|
|
@@ -21945,6 +22480,9 @@ const contentName = (contentUrl, contentFilename) => contentFilename || new URL(
|
|
|
21945
22480
|
// it starts its own prefetch, and docs/streaming-progress.md covers the engine fix that would
|
|
21946
22481
|
// let the octree path reuse the response instead of opting out of it.
|
|
21947
22482
|
const isPrefetchable = (contentUrl, contentFilename) => contentName(contentUrl, contentFilename)?.toLowerCase() !== 'lod-meta.json';
|
|
22483
|
+
// gsaf is an animated splat sequence, which the viewer decodes and plays itself rather than
|
|
22484
|
+
// through an engine parser
|
|
22485
|
+
const isGsaf = (contentUrl, contentFilename) => contentName(contentUrl, contentFilename)?.toLowerCase().endsWith('.gsaf');
|
|
21948
22486
|
const loadGsplat = async (app, config, progressCallback, cancelled) => {
|
|
21949
22487
|
const { contents, contentUrl, contentFilename } = config;
|
|
21950
22488
|
const c = contents;
|
|
@@ -22129,6 +22667,7 @@ const resolveConfig = (options) => ({
|
|
|
22129
22667
|
posterUrl: options.posterUrl,
|
|
22130
22668
|
skyboxUrl: options.skyboxUrl,
|
|
22131
22669
|
collisionUrl: options.collisionUrl,
|
|
22670
|
+
gsafDecoderUrl: options.gsafDecoderUrl,
|
|
22132
22671
|
poster: options.poster ?? (options.posterUrl ? createImage(options.posterUrl) : undefined),
|
|
22133
22672
|
contents: options.contents ??
|
|
22134
22673
|
(isPrefetchable(options.contentUrl, options.contentFilename) ? fetch(options.contentUrl) : undefined),
|
|
@@ -22145,8 +22684,16 @@ const resolveConfig = (options) => ({
|
|
|
22145
22684
|
vr: options.vr ?? false,
|
|
22146
22685
|
aa: options.aa ?? false,
|
|
22147
22686
|
stochastic: options.stochastic ?? false,
|
|
22148
|
-
|
|
22149
|
-
|
|
22687
|
+
// the direct source reads the engine's own splat files, not the container a gsaf sequence
|
|
22688
|
+
// plays through; the work buffer source reads whatever the engine copied
|
|
22689
|
+
splatSource: isGsaf(options.contentUrl, options.contentFilename) ? 'workbuffer' : (options.splatSource ?? 'direct'),
|
|
22690
|
+
// The stochastic renderer's temporal passes assume splats move only with the camera: an
|
|
22691
|
+
// animated sequence would ghost in the accumulation, and the occlusion cull, which forgets the
|
|
22692
|
+
// previous frame's depth only when a node goes away, would test a frame against the one before
|
|
22693
|
+
// it, which keeps its allocation. An explicit variant still overrides both
|
|
22694
|
+
variant: isGsaf(options.contentUrl, options.contentFilename)
|
|
22695
|
+
? `taa:off,cull:off,${options.variant ?? ''}`
|
|
22696
|
+
: (options.variant ?? ''),
|
|
22150
22697
|
budget: options.budget,
|
|
22151
22698
|
framesInFlight: options.framesInFlight ?? 2,
|
|
22152
22699
|
heatmap: options.heatmap ?? false,
|
|
@@ -22201,6 +22748,7 @@ const createViewer = async (options) => {
|
|
|
22201
22748
|
inputMode: platform.mobile ? 'touch' : 'desktop',
|
|
22202
22749
|
cameraMode: 'orbit',
|
|
22203
22750
|
hasAnimation: false,
|
|
22751
|
+
hasSequence: false,
|
|
22204
22752
|
animationDuration: 0,
|
|
22205
22753
|
animationTime: 0,
|
|
22206
22754
|
animationPaused: true,
|
|
@@ -22240,10 +22788,22 @@ const createViewer = async (options) => {
|
|
|
22240
22788
|
// a load continuation can outlive a destroy, so anything that resumes after an await checks
|
|
22241
22789
|
// this before touching the app
|
|
22242
22790
|
let destroyed = false;
|
|
22243
|
-
// Load model
|
|
22244
|
-
const
|
|
22791
|
+
// Load model: a gsaf sequence plays through its own player, which the viewer's timeline drives
|
|
22792
|
+
const onProgress = (progress) => {
|
|
22245
22793
|
state.progress = progress;
|
|
22246
|
-
}
|
|
22794
|
+
};
|
|
22795
|
+
// aborted by the viewer's destroy, which lets a gsaf load release its worker mid-wait
|
|
22796
|
+
const loading = new AbortController();
|
|
22797
|
+
const sequenceLoad = isGsaf(config.contentUrl, config.contentFilename)
|
|
22798
|
+
? loadGsaf(app, config.contents ?? fetch(config.contentUrl), config.gsafDecoderUrl, onProgress, loading.signal).catch((err) => {
|
|
22799
|
+
if (!destroyed)
|
|
22800
|
+
console.log(err);
|
|
22801
|
+
throw err;
|
|
22802
|
+
})
|
|
22803
|
+
: null;
|
|
22804
|
+
const gsplatLoad = sequenceLoad
|
|
22805
|
+
? sequenceLoad.then((player) => player.entity)
|
|
22806
|
+
: loadGsplat(app, config, onProgress, () => destroyed);
|
|
22247
22807
|
// Load skybox (continue without if it fails — e.g. CORS, 404)
|
|
22248
22808
|
const skyboxLoad = config.skyboxUrl &&
|
|
22249
22809
|
loadSkybox(app, config.skyboxUrl)
|
|
@@ -22290,7 +22850,7 @@ const createViewer = async (options) => {
|
|
|
22290
22850
|
};
|
|
22291
22851
|
}
|
|
22292
22852
|
// Create the viewer
|
|
22293
|
-
const viewer = new Viewer(global, gsplatLoad, skyboxLoad, collisionLoad);
|
|
22853
|
+
const viewer = new Viewer(global, gsplatLoad, skyboxLoad, collisionLoad, sequenceLoad);
|
|
22294
22854
|
viewer.onDestroy(persistPreferences(events));
|
|
22295
22855
|
viewer.onDestroy(() => quality.destroy());
|
|
22296
22856
|
const handle = {
|
|
@@ -22317,6 +22877,7 @@ const createViewer = async (options) => {
|
|
|
22317
22877
|
: null;
|
|
22318
22878
|
viewer.onDestroy(() => {
|
|
22319
22879
|
destroyed = true;
|
|
22880
|
+
loading.abort();
|
|
22320
22881
|
});
|
|
22321
22882
|
viewer.onDestroy(disposeCanvas);
|
|
22322
22883
|
if (disposeUI) {
|