mapv-cloudrenderengine
Version:
CloudRenderEngine 是由百度地图开放平台FE团队推出的基于一个基于Unreal Engine 5 引擎封装的JavaScript API三维孪生SDK,支持前端开发人员快速完成实时三维数字孪生系统的开发,构建智慧城市、交通、文旅、园区、元宇宙、BIM等场景业务应用。 开发者使用CloudRenderEngine 提供的丰富API可以完成三维场景交互、动态数据展示、巡航、模型单体化应用等功能。CloudRenderEngine 降低了UE研发的门槛,提升数字孪生场景构建的效率,是一款具备强地
1 lines • 229 kB
JavaScript
import{Vector2 as e,Vector3 as t,Quaternion as i,Matrix4 as s,MathUtils as a,Euler as o,Matrix3 as n,Layers as r,FileLoader as l,Color as h,Group as d,MeshBasicMaterial as c,PlaneBufferGeometry as u,Mesh as p,SpriteMaterial as m,Sprite as g}from"three";import f from"earcut";import*as y from"@tweenjs/tween.js";import b from"axios";import x from"@mars3d/heatmap.js";const v={CLEAR_SKIES:"clearSkies",PARTLY_CLOUDY:"partlyCloudy",CLOUDY:"cloudy",FOGGY:"foggy",OVERCAST:"overcast",RAIN:"rain",LIGHT_RAIN:"lightRain",THUNDER_STORM:"thunderstorm",SNOW:"snow",LIGHT_SNOW:"lightSnow",BLIZZARD:"blizzard",SAND_DUST_CALM:"sandDustCalm",SAND_DUST_STORM:"sandDustStorm"},S={VOLUMETRIC_CLOUDS:"Volumetric Clouds",STATIC_CLOUDS:"Static Clouds",DYNAMIC_CLOUDS:"2D Dynamic Clouds",NO_CLOUDS:"No Clouds",VOLUMETRIC_AURORA:"Volumetric Aurora"},N={SKY_ATMOSPHERE:"Sky Atmosphere",SIMPLIFIED_COLOR:"Simplified Color"},U={SET_MOUSE_CURSOR_SHOW:"setMouseCursorShow",SET_CLICK_EVENT:"setClickEvent",SET_EDIT_STATUS:"setEditStatus",SWITCH_EDIT_MODE:"switchEditMode",SAVE_EDIT_RESULT:"saveEditResult",ZOOM_IN:"zoomIn",ZOOM_OUT:"zoomOut",EXIT:"exitClient",ENABLE_TERRAIN:"enableTerrain",ENABLE_POI:"enablePOIByTag",PRELOAD_LOCATION:"preLoadLocation",FOCUS_ACTOR_BY_ID:"focusActorByID",ENABLE_DATALAYER:"Scene_enableDataLayerByName",ENABLE_FPS:"Scene_setFPS",OBJECT_BOUNDINGBOX:"Interact_objectBoundingBox",ASSET_MODEL:"Gis_generateAssetModel",BUILD_GROWTHANIMATE:"Interact_buildGrowth"},w={NAVIGATION:"Camera_navigation",NAVIGATION_PAUSE:"Camera_navigationPause",NAVIGATION_STOP:"Camera_navigationStop",MOVE_TO:"Camera_moveTo",ZOOM_IN:"Camera_zoomIn",ZOOM_OUT:"Camera_zoomOut",PROJECT:"Camera_project",UNPROJECT:"Camera_unproject",UPDATE:"Camera_update",FOCUS_ON:"Camera_focusOn",Constrain_Shape:"Camera_constrainShape",MOVE:"Camera_move",ROTATE:"Camera_rotate",RESET_CAMERA_FOCUS:"Camera_resetCameraFocus"},C={ENABLE_3DTILES_BY_NAME:"Scene_enableTilesByName",SWITCH_TERRAIN_MODE:"Scene_switchTerrainMode",HIDDEN_3DTILES_ITEM:"Scene_hiddenTilesItem",EVENT_LAYER_BUILDING:"Scene_eventLayerBuilding",UPDATA_SLOPE_ANALYSIS:"Scene_updateSlopeAnalysis",GET_ALTITUDE:"Scene_getAltitude",SET_PLANE_POI_MODE:"Scene_setPlanePoiMode"},T={EXIT_CLIENT:"Application_exitClient",RESTART_LEVEL:"Application_restartLevel",RESTART_GAME:"Application_restartGame",CREATE_TRAFFIC_STREAM:"Application_createTrafficStream",CLOSE_TRAFFIC_STREAM:"Application_closeTrafficStream",FOLLOW_TRAFFIC_STREAM_ITEM:"Application_followTrafficStreamItem",ADD_EVENT_LISTENER:"Application_addEvent",REMOVE_EVENT_LISTENER:"Application_removeEvent",RESET_WORLD_CENTER:"Application_resetWorldCenter",CONSOLE_COMMAND:"Application_ConsoleCommand"},O={ADD:"Gis_AddCommonGISLayer",REMOVE:"Gis_RemoveCommonGISLayer",DESTORY:"Gis_DestoryCommonGISLayer",DESTORY_ALL:"Gis_DestoryAllGenerationLayer",UPDATE:"Gis_UpdateCommonGISLayer",VISIBLE:"Gis_VisibleCommonGISLayer"},z={ENABLE_DRAW:"Gis_enableDraw",CLOSE_DRAW:"Gis_closeDraw",ENABLE_MEASURE:"Gis_enableMeasure",CLOSE_MEASURE:"Gis_closeMeasure",DESTORY_DRAW:"Gis_clearDraw",DESTORY_MEASURE:"Gis_clearMeasure"},R={SOLID:"solid",DASHED:"dashed",ARROW:"arrow",GRADIENT:"gradient"},E={CENTER:"Ground_Center",STAND:"Stand",SIDE:"Ground_Side",SIDE:"Cylinder"},I={LINEAR:"Linear",CURVE:"Curve",CONSTANT:"Constant"},M={QualityControlOwnership:0,Response:1,Command:2,FreezeFrame:3,UnfreezeFrame:4,VideoEncoderAvgQP:5,LatencyTest:6,InitialSettings:7,FileExtension:8,FileMimeType:9,FileContents:10,Mouse:21,Keyboard:22,InputControlOwnership:12,Protocol:255},A={LockedMouse:0,HoveringMouse:1},D={controlScheme:A.HoveringMouse,suppressBrowserKeys:!1,fakeMouseWithTouches:!1},P={IFrameRequest:0,RequestQualityControl:1,FpsRequest:2,AverageBitrateRequest:3,StartStreaming:4,StopStreaming:5,LatencyTest:6,RequestInitialSettings:7,UIInteraction:50,Command:51,KeyDown:60,KeyUp:61,KeyPress:62,MouseEnter:70,MouseLeave:71,MouseDown:72,MouseUp:73,MouseMove:74,MouseWheel:75,TouchStart:80,TouchEnd:81,TouchMove:82,GamepadButtonPressed:90,GamepadButtonReleased:91,GamepadAnalog:92},L={MainButton:0,AuxiliaryButton:1,SecondaryButton:2,FourthButton:3,FifthButton:4},k={PrimaryButton:1,SecondaryButton:2,AuxiliaryButton:4,FourthButton:8,FifthButton:16},B={BackSpace:8,Shift:16,Control:17,Alt:18,RightShift:253,RightControl:254,RightAlt:255},_={FIRE_BIG:"P_Fire_Big",FIRE_SMALL:"P_Fire_Small",FIRE_FLAMETHROWER:"P_Flamethrower",SMOKE_SMALL_BLACK:"P_Smoke_A",SMOKE_BIG_BLACK:"P_Smoke_B",SMOKE_SMALL_YELLOW:"P_Smoke_C",SMOKE_BIG_YELLOW:"P_Smoke_D",SPARK_A:"P_Sparks_E",FOG_MASS:"P_Mass_Fog",NS_Spark:"NS_Spark",NS_Firefly:"NS_Firefly"};var F=Object.freeze({__proto__:null,ApplicationControl:T,CameraControl:w,ControlSchemeType:A,DrawAndMeasureControl:z,GisControl:O,InteractMOD:U,LineDirectionOptions:E,LineSplineTypeOptions:I,LineTypeOptions:R,MessageType:P,MouseButton:L,MouseButtonsMask:k,ParticleKind:_,SceneControl:C,SkyColorMode:N,SkyMode:S,SpecialKeyCodes:B,ToClientMessageType:M,UDS:v,WS_OPEN_STATE:1,inputOptions:D});class W{constructor(e,t={}){this.cloudRender=e,this.weather=t.weather||v.PARTLY_CLOUDY,this.hour=t.hour||8,this.minute=t.minute||10,this.weatherType=v,this.init()}changeWeather(e){if(!e)return;Object.values(v).indexOf(e)<0||(this.weather=e,this.cloudRender.emitUIInteraction({excuteName:"Scene_changeWeather",params:{WeatherType:e}}))}changeTime(e=10,t=10){this.hour=e,this.minute=Math.floor(10*t/6);const i=(this.hour<10?"0"+this.hour:""+this.hour)+(this.minute<10?"0"+this.minute:""+this.minute);this.cloudRender.emitUIInteraction({excuteName:"Scene_changeTime",params:{Time:i}})}setVolumeFog(e,t=1e3){const i=Math.max(Math.min(1e5,t),10);this.cloudRender.emitUIInteraction({excuteName:"Scene_setVolumenFog",params:{Enable:e,Distance:100*i}})}setAtmosphericFog(e=.0075){const t=Math.max(Math.min(1,e),0);this.cloudRender.emitUIInteraction({excuteName:"Scene_setBaseFog",params:{BaseFogDensity:t}})}setSkyMode(e){if(!e)return!1;if(Object.values(S).indexOf(e)<0)return!1;this.cloudRender.emitUIInteraction({excuteName:"Scene_setSkyMode",params:{SkyMode:e}})}setSkyColorMode(e){if(!e)return!1;if(Object.values(N).indexOf(e)<0)return!1;this.cloudRender.emitUIInteraction({excuteName:"Scene_setSkyColorMode",params:{SkyColorMode:e}})}changeWeatherEffectParameters(e){this.cloudRender.emitUIInteraction({excuteName:"Scene_changeWeatherEffects",params:JSON.stringify(e)})}init(){this.changeWeather(this.weather),this.changeTime(this.hour,this.minute)}}const H=function(e){e=void 0!==e?e:{},this.forceTURN=e.forceTURN;let t=this;const i=new URLSearchParams(window.location.search);this.cfg=void 0!==e.peerConnectionOptions?e.peerConnectionOptions:{},this.cfg.sdpSemantics="unified-plan",this.cfg.offerExtmapAllowMixed=!1,i.has("ForceTURN")&&(this.forceTURN=i.has("ForceTURN")),this.forceTURN&&(console.log("Forcing TURN usage by setting ICE Transport Policy in peer connection config."),this.cfg.iceTransportPolicy="relay"),this.cfg.bundlePolicy="balanced",this.forceMaxBundle=i.has("ForceMaxBundle"),this.forceMaxBundle&&(this.cfg.bundlePolicy="max-bundle"),this.pcClient=null,this.dcClient=null,this.tnClient=null,this.sdpConstraints={offerToReceiveAudio:1,offerToReceiveVideo:1,voiceActivityDetection:!1},this.dataChannelOptions={ordered:!0,maxPacketLifeTime:3e3},this.startVideoMuted=void 0!==e.startVideoMuted&&e.startVideoMuted,this.autoPlayAudio=void 0===e.autoPlayAudio||e.autoPlayAudio,this.useMic=i.has("useMic"),this.useMic||console.log("Microphone access is not enabled. Pass ?useMic in the url to enable it.");let s="localhost"===location.hostname||"127.0.0.1"===location.hostname,a="https:"===location.protocol;!this.useMic||s||a||(this.useMic=!1,console.error("Microphone access in the browser will not work if you are not on HTTPS or localhost. Disabling mic access."),console.error("For testing you can enable HTTP microphone access Chrome by visiting chrome://flags/ and enabling 'unsafely-treat-insecure-origin-as-secure'")),this.preferSFU=i.has("preferSFU"),console.log(this.preferSFU?"The browser will signal it would prefer an SFU connection. Remove ?preferSFU from the url to signal for P2P usage.":"The browser will signal for a P2P connection. Pass ?preferSFU in the url to signal for SFU usage."),this.latencyTestTimings={TestStartTimeMs:null,UEReceiptTimeMs:null,UEEncodeMs:null,UECaptureToSendMs:null,UETransmissionTimeMs:null,BrowserReceiptTimeMs:null,FrameDisplayDeltaTimeMs:null,Reset:function(){this.TestStartTimeMs=null,this.UEReceiptTimeMs=null,this.UEEncodeMs=null,this.UECaptureToSendMs=null,this.UETransmissionTimeMs=null,this.BrowserReceiptTimeMs=null,this.FrameDisplayDeltaTimeMs=null},SetUETimings:function(e){this.UEReceiptTimeMs=e.ReceiptTimeMs,this.UEEncodeMs=e.EncodeMs,this.UECaptureToSendMs=e.CaptureToSendMs,this.UETransmissionTimeMs=e.TransmissionTimeMs,this.BrowserReceiptTimeMs=Date.now(),this.OnAllLatencyTimingsReady(this)},SetFrameDisplayDeltaTime:function(e){null==this.FrameDisplayDeltaTimeMs&&(this.FrameDisplayDeltaTimeMs=Math.round(e),this.OnAllLatencyTimingsReady(this))},OnAllLatencyTimingsReady:function(e){}},this.createWebRtcVideo=function(){let e=document.createElement("video");if(e.id="streamingVideo",e.playsInline=!0,e.disablepictureinpicture=!0,e.muted=t.startVideoMuted,e.addEventListener("loadedmetadata",(function(e){t.onVideoInitialised&&t.onVideoInitialised()}),!0),"requestVideoFrameCallback"in HTMLVideoElement.prototype){const i=(s,a)=>{if(a.receiveTime&&a.expectedDisplayTime){let e=a.presentationTime-a.receiveTime;t.aggregatedStats||(t.aggregatedStats={}),t.aggregatedStats.receiveToCompositeMs=e}e.requestVideoFrameCallback(i)};e.requestVideoFrameCallback(i)}return e},this.video=this.createWebRtcVideo(),this.availableVideoStreams=new Map;const o=function(e){console.info("Signaling state change. |",e.srcElement.signalingState,"|")},n=function(e){console.info("Browser ICE connection |",e.srcElement.iceConnectionState,"|")},r=function(e){console.info("Browser ICE gathering |",e.srcElement.iceGatheringState,"|")},l=function(e){if(e.track&&console.log("Got track. | Kind="+e.track.kind+" | Id="+e.track.id+" | readyState="+e.track.readyState+" |"),"audio"!=e.track.kind){e.track.kind;for(const i of e.streams)t.availableVideoStreams.has(i.id)||t.availableVideoStreams.set(i.id,i);t.video.srcObject=e.streams[0],e.track.onunmute=()=>{t.video.srcObject=e.streams[0],t.onNewVideoTrack(e.streams)}}else h(e.streams[0])},h=function(e){if(t.video.srcObject!=e&&t.video.srcObject&&t.video.srcObject!==e){let i=document.createElement("Audio");if(i.srcObject=e,t.autoPlayAudio)i.play();else{let e=function(){i.play(),t.video.removeEventListener("click",e)};t.video.addEventListener("click",e)}console.log("Created new audio element to play seperate audio stream.")}},d=function(e){console.log("Data channel created for us by browser as we are a receiving peer."),t.dcClient=e.channel,c(t.dcClient)},c=function(e){try{return e.binaryType="arraybuffer",e.onopen=function(e){console.log("Data channel connected"),t.onDataChannelConnected&&t.onDataChannelConnected()},e.onclose=function(e){console.log("Data channel connected",e)},e.onmessage=function(e){if(t.onDataChannelMessage)if("string"==typeof e.data){const i=function(e){var t,i,s=new Array;t=e.length;for(var a=0;a<t;a++)(i=e.charCodeAt(a))>=65536&&i<=1114111?(s.push(i>>18&7|240),s.push(i>>12&63|128),s.push(i>>6&63|128),s.push(63&i|128)):i>=2048&&i<=65535?(s.push(i>>12&15|224),s.push(i>>6&63|128),s.push(63&i|128)):i>=128&&i<=2047?(s.push(i>>6&31|192),s.push(63&i|128)):s.push(255&i);return new Uint8Array(s).buffer}(e.data);t.onDataChannelMessage(i)}else t.onDataChannelMessage(e.data)},e.onerror=function(e){console.error("Data channel error",e)},e}catch(e){return console.warn("No data channel",e),null}},u=function(e){let i=e.candidate;i&&i.candidate&&(console.log("%c[Browser ICE candidate]","background: violet; color: black","| Type=",i.type,"| Protocol=",i.protocol,"| Address=",i.address,"| Port=",i.port,"|"),t.onWebRtcCandidate(i))},p=function(e){e.sdp=e.sdp.replace("useinbandfec=1","useinbandfec=1;stereo=1;sprop-maxcapturerate=48000")},m=function(e){e.onsignalingstatechange=o,e.oniceconnectionstatechange=n,e.onicegatheringstatechange=r,e.ontrack=l,e.onicecandidate=u,e.ondatachannel=d},g=async function(e){let i=e.getTransceivers().length>0;if(e.addTransceiver("video",{direction:"recvonly"}),t.useMic){let s=!!t.useMic&&{autoGainControl:!1,channelCount:1,echoCancellation:!1,latency:0,noiseSuppression:!1,sampleRate:48e3,volume:1};const a=await navigator.mediaDevices.getUserMedia({video:!1,audio:s});if(a)if(i){for(let t of e.getTransceivers())if(t&&t.receiver&&t.receiver.track&&"audio"===t.receiver.track.kind)for(const e of a.getTracks())e.kind&&"audio"==e.kind&&(t.sender.replaceTrack(e),t.direction="sendrecv")}else for(const t of a.getTracks())t.kind&&"audio"==t.kind&&e.addTransceiver(t,{direction:"sendrecv"});else e.addTransceiver("audio",{direction:"recvonly"})}else e.addTransceiver("audio",{direction:"recvonly"})};this.setVideoEnabled=function(e){t.video.srcObject.getTracks().forEach((t=>t.enabled=e))},this.startLatencyTest=function(e){t.video&&(t.latencyTestTimings.Reset(),t.latencyTestTimings.TestStartTimeMs=Date.now(),e(t.latencyTestTimings.TestStartTimeMs))},this.handleCandidateFromServer=function(e){let i=new RTCIceCandidate(e);console.log("%c[Unreal ICE candidate]","background: pink; color: black","| Type=",i.type,"| Protocol=",i.protocol,"| Address=",i.address,"| Port=",i.port,"|"),t.forceTURN&&i.candidate.indexOf("relay")<0?console.warn("Dropping candidate because it was not TURN relay.","| Type=",i.type,"| Protocol=",i.protocol,"| Address=",i.address,"| Port=",i.port,"|"):t.pcClient.addIceCandidate(i).catch((function(e){console.error("Failed to add ICE candidate",e)}))},this.createOffer=function(){t.pcClient&&(console.log("Closing existing PeerConnection"),t.pcClient.close(),t.pcClient=null),t.pcClient=new RTCPeerConnection(t.cfg),m(t.pcClient),g(t.pcClient).finally((function(){var e;t.dcClient=function(e,t,i){let s=e.createDataChannel(t,i);return console.log(`Created datachannel (${t})`),c(s),s}(t.pcClient,"cirrus",t.dataChannelOptions),(e=t.pcClient).createOffer(t.sdpConstraints).then((function(i){p(i),e.setLocalDescription(i),t.onWebRtcOffer&&t.onWebRtcOffer(i)}),(function(){console.warn("Couldn't create offer")}))}))},this.receiveOffer=function(e){let i=new RTCSessionDescription(e);t.pcClient||(console.log("Creating a new PeerConnection in the browser.",t.cfg),t.pcClient=new RTCPeerConnection(t.cfg),m(t.pcClient),t.pcClient.setRemoteDescription(i).then((()=>{g(t.pcClient).finally((function(){t.pcClient.createAnswer().then((e=>t.pcClient.setLocalDescription(e))).then((()=>{t.onWebRtcAnswer&&t.onWebRtcAnswer(t.pcClient.currentLocalDescription)})).then((()=>{let e=t.pcClient.getReceivers();for(let t of e)t.playoutDelayHint=0})).catch((e=>console.error("createAnswer() failed:",e)))}))})))},this.receiveAnswer=function(e){let i=new RTCSessionDescription(e);t.pcClient.setRemoteDescription(i);let s=t.pcClient.getReceivers();for(let e of s)e.playoutDelayHint=0},this.close=function(){t.pcClient&&(console.log("Closing existing peerClient"),t.pcClient.close(),t.pcClient=null),t.aggregateStatsIntervalId&&clearInterval(t.aggregateStatsIntervalId)},this.send=function(e){if(t.dcClient&&"open"==t.dcClient.readyState)try{t.dcClient.send(e)}catch(e){console.error("dcClient.send error: ",e)}},this.getStats=function(e){t.pcClient&&e&&t.pcClient.getStats(null).then((t=>{e(t)}))},this.aggregateStats=function(e){let i=(t.aggregatedStats||(t.aggregatedStats={}),function(e){let i={};e.forEach((e=>{"inbound-rtp"!=e.type||e.isRemote||"video"!=e.mediaType&&!e.id.toLowerCase().includes("video")||(i.timestamp=e.timestamp,i.bytesReceived=e.bytesReceived,i.framesDecoded=e.framesDecoded,i.packetsLost=e.packetsLost,i.bytesReceivedStart=t.aggregatedStats&&t.aggregatedStats.bytesReceivedStart?t.aggregatedStats.bytesReceivedStart:e.bytesReceived,i.framesDecodedStart=t.aggregatedStats&&t.aggregatedStats.framesDecodedStart?t.aggregatedStats.framesDecodedStart:e.framesDecoded,i.timestampStart=t.aggregatedStats&&t.aggregatedStats.timestampStart?t.aggregatedStats.timestampStart:e.timestamp,t.aggregatedStats&&t.aggregatedStats.timestamp&&(t.aggregatedStats.bytesReceived&&(i.bitrate=8*(i.bytesReceived-t.aggregatedStats.bytesReceived)/(i.timestamp-t.aggregatedStats.timestamp),i.bitrate=Math.floor(i.bitrate),i.lowBitrate=t.aggregatedStats.lowBitrate&&t.aggregatedStats.lowBitrate<i.bitrate?t.aggregatedStats.lowBitrate:i.bitrate,i.highBitrate=t.aggregatedStats.highBitrate&&t.aggregatedStats.highBitrate>i.bitrate?t.aggregatedStats.highBitrate:i.bitrate),t.aggregatedStats.bytesReceivedStart&&(i.avgBitrate=8*(i.bytesReceived-t.aggregatedStats.bytesReceivedStart)/(i.timestamp-t.aggregatedStats.timestampStart),i.avgBitrate=Math.floor(i.avgBitrate)),t.aggregatedStats.framesDecoded&&(i.framerate=(i.framesDecoded-t.aggregatedStats.framesDecoded)/((i.timestamp-t.aggregatedStats.timestamp)/1e3),i.framerate=Math.floor(i.framerate),i.lowFramerate=t.aggregatedStats.lowFramerate&&t.aggregatedStats.lowFramerate<i.framerate?t.aggregatedStats.lowFramerate:i.framerate,i.highFramerate=t.aggregatedStats.highFramerate&&t.aggregatedStats.highFramerate>i.framerate?t.aggregatedStats.highFramerate:i.framerate),t.aggregatedStats.framesDecodedStart&&(i.avgframerate=(i.framesDecoded-t.aggregatedStats.framesDecodedStart)/((i.timestamp-t.aggregatedStats.timestampStart)/1e3),i.avgframerate=Math.floor(i.avgframerate)))),"track"!=e.type||"video_label"!=e.trackIdentifier&&"video"!=e.kind||(i.framesDropped=e.framesDropped,i.framesReceived=e.framesReceived,i.framesDroppedPercentage=e.framesDropped/e.framesReceived*100,i.frameHeight=e.frameHeight,i.frameWidth=e.frameWidth,i.frameHeightStart=t.aggregatedStats&&t.aggregatedStats.frameHeightStart?t.aggregatedStats.frameHeightStart:e.frameHeight,i.frameWidthStart=t.aggregatedStats&&t.aggregatedStats.frameWidthStart?t.aggregatedStats.frameWidthStart:e.frameWidth),"candidate-pair"==e.type&&e.hasOwnProperty("currentRoundTripTime")&&0!=e.currentRoundTripTime&&(i.currentRoundTripTime=e.currentRoundTripTime)})),t.aggregatedStats.receiveToCompositeMs&&(i.receiveToCompositeMs=t.aggregatedStats.receiveToCompositeMs,t.latencyTestTimings.SetFrameDisplayDeltaTime(t.aggregatedStats.receiveToCompositeMs)),t.aggregatedStats=i,t.onAggregatedStats&&t.onAggregatedStats(i)});t.aggregateStatsIntervalId=setInterval((()=>{t.getStats(i)}),e)}};!function(e,t){void 0===t&&(t={});var i=t.insertAt;if("undefined"!=typeof document){var s=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");a.type="text/css","top"===i&&s.firstChild?s.insertBefore(a,s.firstChild):s.appendChild(a),a.styleSheet?a.styleSheet.cssText=e:a.appendChild(document.createTextNode(e))}}("/* 视频流送的视频组件样式 */\nvideo {\n position: absolute;\n width: 100%;\n height: 100%;\n}\n\n/* 视频流送的整体根组件属性 */\n#player {\n width: 100%;\n height: 100%;\n position: relative;\n background-color: #000;\n}\n\n/* 如果不是链接后直接加载(即connect_on_load: false)那么便会显示该画面,用于配置显示蒙版的样式 */\n#videoPlayOverlay {\n z-index: 30;\n position: absolute;\n font-size: 1.8em;\n width: 100%;\n height: 100%;\n color: white;\n background-color: rgba(100, 100, 100, .7);\n}\n\n/* State for element to be clickable */\n/* 待开始页面显示状态的样式 */\n.clickableState {\n align-items: center;\n justify-content: center;\n display: flex;\n cursor: pointer;\n}\n\n.textDisplayState {\n width: 100%;\n height: 100%;\n display: flex;\n align-items: center;\n justify-content: center;\n}\n\n/* State to hide overlay, WebRTC communication is in progress and or is playing */\n/* 待开始页面隐藏 */\n.hiddenState {\n display: none;\n}\n\n/* 如果不是链接后直接加载(即connect_on_load: false)那么便会显示该按钮文字,用于配置显示样式 */\n#playButton {\n display: inline-block;\n height: auto;\n}");class G{addEventListener(e,t){void 0===this._listeners&&(this._listeners={}),this._needsDispatchedToUE=!1;const i=this._listeners;void 0===i[e]&&(i[e]=[]),-1===i[e].indexOf(t)&&(i[e].push(t),this._needsDispatchedToUE=!0,this._dispatchAddListenerTypes||(this._dispatchAddListenerTypes=[]),this._dispatchAddListenerTypes.push(e))}hasEventListener(e,t){if(void 0===this._listeners)return!1;const i=this._listeners;return void 0!==i[e]&&-1!==i[e].indexOf(t)}removeEventListener(e,t){if(void 0===this._listeners)return;this._needsDispatchedToUE=!1;const i=this._listeners[e];if(void 0!==i){const s=i.indexOf(t);-1!==s&&(i.splice(s,1),this._needsDispatchedToUE=!0,this._dispatchRemoveListenerTypes||(this._dispatchRemoveListenerTypes=[]),this._dispatchRemoveListenerTypes.push(e))}}dispatchEvent(e){if(void 0===this._listeners)return;const t=this._listeners[e.type];if(void 0!==t){e.target=this;const i=t.slice(0);for(let t=0,s=i.length;t<s;t++)e.index=t,i[t].call(this,e);e.target=null}}}class V extends G{constructor(t){super(),this.haveEvents="GamepadEvent"in window,this.haveWebkitEvents="WebKitGamepadEvent"in window,this.cloudRenderEngine=t,this.playerElement=document.getElementById("player"),this.promiseResponses=[],this.scene=this.cloudRenderEngine.scene,this.interactiveObjects=new Map,this.blacklist=new Set,this.mousedownTime=null,this.mouse=new e(0,0),this.selection=[],this.logMessages=!1,this.inputOptions=t.inputOptions,this.playerElement&&(this.playerElement.tabIndex<10&&(this.playerElement.tabIndex=1e3),this.playerElement.addEventListener("contextmenu",(e=>{e.preventDefault()}),!1))}updateObjectsWithEvent(){const e=new Map;this.scene&&this.scene.children.length&&this.scene.children.forEach(((t,i)=>{t._listeners&&e.set(t.uuid,t)})),this.interactiveObjects.clear(),this.interactiveObjects=e}isKeyCodeBrowserKey(e){return e>=112&&e<=123||9===e}getKeyCode(e){return e.keyCode===B.Shift&&"ShiftRight"===e.code?B.RightShift:e.keyCode===B.Control&&"ControlRight"===e.code?B.RightControl:e.keyCode===B.Alt&&"AltRight"===e.code?B.RightAlt:e.keyCode}registerKeyboardEvents(){const e=this;document.onkeydown=function(t){e.print_inputs&&console.log(`key down ${t.keyCode}, repeat = ${t.repeat}`),e.cloudRenderEngine.sendInputData(new Uint8Array([P.KeyDown,e.getKeyCode(t),t.repeat]).buffer),t.keyCode===B.BackSpace&&document.onkeypress({charCode:B.BackSpace}),e.inputOptions.suppressBrowserKeys&&e.isKeyCodeBrowserKey(t.keyCode)&&t.preventDefault()},document.onkeyup=function(t){e.print_inputs&&console.log(`key up ${t.keyCode}`),e.cloudRenderEngine.sendInputData(new Uint8Array([P.KeyUp,e.getKeyCode(t)]).buffer),e.inputOptions.suppressBrowserKeys&&e.isKeyCodeBrowserKey(t.keyCode)&&t.preventDefault()},document.onkeypress=function(t){e.print_inputs&&console.log(`key press ${t.charCode}`);let i=new DataView(new ArrayBuffer(3));i.setUint8(0,P.KeyPress),i.setUint16(1,t.charCode,!0),e.cloudRenderEngine.sendInputData(i.buffer)}}resizePlayerStyleToFillWindow(e){let t=e.getElementsByTagName("VIDEO"),i=window.innerHeight/window.innerWidth,s=e.clientHeight/e.clientWidth,a=t.videoHeight/t.videoWidth;isNaN(a)?(this.styleWidth=window.innerWidth,this.styleHeight=window.innerHeight,this.styleTop=0,this.styleLeft=0,e.style="top: "+this.styleTop+"px; left: "+this.styleLeft+"px; width: "+this.styleWidth+"px; height: "+this.styleHeight+"px; cursor: "+this.styleCursor+"; "+this.styleAdditional):i<s?(this.styleWidth=Math.floor(window.innerHeight/a),this.styleHeight=window.innerHeight,this.styleTop=0,this.styleLeft=Math.floor(.5*(window.innerWidth-this.styleWidth)),e.style="top: "+this.styleTop+"px; left: "+this.styleLeft+"px; width: "+this.styleWidth+"px; height: "+this.styleHeight+"px; cursor: "+this.styleCursor+"; "+this.styleAdditional):(this.styleWidth=window.innerWidth,this.styleHeight=Math.floor(window.innerWidth*a),this.styleTop=Math.floor(.5*(window.innerHeight-this.styleHeight)),this.styleLeft=0,e.style="top: "+this.styleTop+"px; left: "+this.styleLeft+"px; width: "+this.styleWidth+"px; height: "+this.styleHeight+"px; cursor: "+this.styleCursor+"; "+this.styleAdditional)}resizePlayerStyleToActualSize(e){let t=e.getElementsByTagName("VIDEO");if(t.length>0){this.styleWidth=t[0].videoWidth,this.styleHeight=t[0].videoHeight;let i=Math.floor(.5*(window.innerHeight-this.styleHeight)),s=Math.floor(.5*(window.innerWidth-this.styleWidth));this.styleTop=i>0?i:0,this.styleLeft=s>0?s:0,e.style="top: "+this.styleTop+"px; left: "+this.styleLeft+"px; width: "+this.styleWidth+"px; height: "+this.styleHeight+"px; cursor: "+this.styleCursor+"; "+this.styleAdditional}}resizePlayerStyleToArbitrarySize(e){e.style="top: 0px; left: 0px; width: "+this.styleWidth+"px; height: "+this.styleHeight+"px; cursor: "+this.styleCursor+"; "+this.styleAdditional}setupFreezeFrameOverlay(){this.cloudRenderEngine.freezeFrameOverlay=document.createElement("div"),this.cloudRenderEngine.freezeFrameOverlay.id="this.cloudRenderEngine.freezeFrameOverlay",this.cloudRenderEngine.freezeFrameOverlay.style.display="none",this.cloudRenderEngine.freezeFrameOverlay.style.pointerEvents="none",this.cloudRenderEngine.freezeFrameOverlay.style.position="absolute",this.cloudRenderEngine.freezeFrameOverlay.style.zIndex="20";let e=document.createElement("img");e.style.position="absolute",this.cloudRenderEngine.freezeFrameOverlay.appendChild(e)}showFreezeFrameOverlay(){this.cloudRenderEngine.freezeFrame.valid&&(this.cloudRenderEngine.freezeFrameOverlay.classList.add("freezeframeBackground"),this.cloudRenderEngine.freezeFrameOverlay.style.display="block")}invalidateFreezeFrameOverlay(){this.cloudRenderEngine.freezeFrameOverlay.style.display="none",this.cloudRenderEngine.freezeFrame.valid=!1,this.cloudRenderEngine.freezeFrameOverlay.classList.remove("freezeframeBackground"),this.cloudRenderEngine.webRtcPlayerObj&&this.cloudRenderEngine.webRtcPlayerObj.setVideoEnabled(!0)}resizeFreezeFrameOverlay(){if(0!==this.cloudRenderEngine.freezeFrame.width&&0!==this.cloudRenderEngine.freezeFrame.height){let e=0,t=0,i=0,s=0,a=document.getElementById("enlarge-display-to-fill-window-tgl"),o=document.getElementById("player");if(null!==a&&a.checked){let a=window.innerWidth/window.innerHeight;let o=this.cloudRenderEngine.freezeFrame.width/this.cloudRenderEngine.freezeFrame.height;a<o?(e=window.innerWidth,t=Math.floor(window.innerWidth/o),i=Math.floor(.5*(window.innerHeight-t)),s=0):(e=Math.floor(window.innerHeight*o),t=window.innerHeight,i=0,s=Math.floor(.5*(window.innerWidth-e)))}else{let a=o.offsetWidth/o.offsetHeight;let n=this.cloudRenderEngine.freezeFrame.width/this.cloudRenderEngine.freezeFrame.height;a<n?(e=o.offsetWidth,t=Math.floor(o.offsetWidth/n),i=Math.floor(.5*(o.offsetHeight-t)),s=0):(e=Math.floor(o.offsetHeight*n),t=o.offsetHeight,i=0,s=Math.floor(.5*(o.offsetWidth-e)))}let n=document.getElementById("this.cloudRenderEngine.freezeFrameOverlay").childNodes[0];this.cloudRenderEngine.freezeFrameOverlay.style.width=o.offsetWidth+"px",this.cloudRenderEngine.freezeFrameOverlay.style.height=o.offsetHeight+"px",this.cloudRenderEngine.freezeFrameOverlay.style.left="0px",this.cloudRenderEngine.freezeFrameOverlay.style.top="0px",n.style.width=e+"px",n.style.height=t+"px",n.style.left=s+"px",n.style.top=i+"px"}}resizePlayerStyle(e){let t=document.getElementById("player");if(!t)return;if(this.cloudRenderEngine.updateVideoStreamSize(),t.classList.contains("fixed-size"))return void this.setupMouseAndFreezeFrame(t);let i=document.getElementById("enlarge-display-to-fill-window-tgl"),s=window.innerWidth<t.videoWidth||window.innerHeight<t.videoHeight;null!==i?i.checked||s?this.resizePlayerStyleToFillWindow(t):this.resizePlayerStyleToActualSize(t):this.resizePlayerStyleToArbitrarySize(t),this.setupMouseAndFreezeFrame(t)}setupMouseAndFreezeFrame(e){this.playerElementClientRect=e.getBoundingClientRect(),this.cloudRenderEngine.setupNormalizeAndQuantize(),this.resizeFreezeFrameOverlay()}onOrientationChange(e){const t=this;clearTimeout(this._orientationChangeTimeout),this._orientationChangeTimeout=setTimeout((function(){t.resizePlayerStyle()}),500)}setupHtmlEvents(){const e=this;if(window.addEventListener("resize",(e=>{this.resizePlayerStyle(e)}),!0),window.addEventListener("orientationchange",(e=>{this.onOrientationChange(e)})),this.haveEvents?(window.addEventListener("gamepadconnected",(e=>{this.gamepadConnectHandler(e)})),window.addEventListener("gamepaddisconnected",(e=>{this.gamepadDisconnectHandler(e)}))):this.haveWebkitEvents&&(window.addEventListener("webkitgamepadconnected",(e=>{this.gamepadConnectHandler(e)})),window.addEventListener("webkitgamepaddisconnected",(e=>{this.gamepadDisconnectHandler(e)}))),this.cloudRenderEngine.isShowTestUI){document.getElementById("overlayButton").addEventListener("click",(e=>{this.onExpandOverlay_Click(e)}));let t=document.getElementById("enlarge-display-to-fill-window-tgl");null!==t&&(t.onchange=function(t){e.resizePlayerStyle()}),this.cloudRenderEngine.qualityControlOwnershipCheckBox=document.getElementById("quality-control-ownership-tgl"),null!==this.cloudRenderEngine.qualityControlOwnershipCheckBox&&(this.cloudRenderEngine.qualityControlOwnershipCheckBox.onchange=function(t){e.cloudRenderEngine.requestQualityControl()});let i=document.getElementById("encoder-params-submit");null!==i&&(i.onclick=function(t){let i=document.getElementById("encoder-min-qp-text").value,s=document.getElementById("encoder-max-qp-text").value;e.cloudRenderEngine.emitCommand({ConsoleCommand:"PixelStreaming.Encoder.MinQP "+i}),e.cloudRenderEngine.emitCommand({ConsoleCommand:"PixelStreaming.Encoder.MaxQP "+s})});let s=document.getElementById("webrtc-params-submit");null!==s&&(s.onclick=function(t){let i=document.getElementById("webrtc-fps-text").value,s=1e3*document.getElementById("webrtc-min-bitrate-text").value,a=1e3*document.getElementById("webrtc-max-bitrate-text").value;e.cloudRenderEngine.emitCommand({ConsoleCommand:"PixelStreaming.WebRTC.Fps "+i}),e.cloudRenderEngine.emitCommand({ConsoleCommand:"PixelStreaming.WebRTC.MinBitrate "+s}),e.cloudRenderEngine.emitCommand({ConsoleCommand:"PixelStreaming.WebRTC.MaxBitrate "+a})});let a=document.getElementById("show-fps-button");null!==a&&(a.onclick=function(t){e.cloudRenderEngine.emitCommand({ConsoleCommand:"Stat FPS"})});let o=document.getElementById("match-viewport-res-tgl");null!==o&&(o.onchange=function(t){e.cloudRenderEngine.matchViewportResolution=o.checked});let n=document.getElementById("show-stats-tgl");null!==n&&(n.onchange=function(e){document.getElementById("statsContainer").style.display=e.target.checked?"block":"none"});let r=document.getElementById("test-latency-button");r&&(r.onclick=()=>{this.sendStartLatencyTest()}),this.cloudRenderEngine.setupToggleWithUrlParams("prefer-sfu-tgl","preferSFU"),this.cloudRenderEngine.setupToggleWithUrlParams("use-mic-tgl","useMic"),this.cloudRenderEngine.setupToggleWithUrlParams("force-turn-tgl","ForceTURN");let l=document.getElementById("stream-select"),h=document.getElementById("track-select");l&&(l.onchange=function(t){const i=e.cloudRenderEngine.webRtcPlayerObj.availableVideoStreams.get(l.value);e.cloudRenderEngine.webRtcPlayerObj.video.srcObject=i,e.cloudRenderEngine.streamTrackSource=i,e.cloudRenderEngine.webRtcPlayerObj.video.play(),e.cloudRenderEngine.updateTrackList()},h&&(h.onchange=function(t){if(e.cloudRenderEngine.streamTrackSource||(e.cloudRenderEngine.streamTrackSource=e.cloudRenderEngine.webRtcPlayerObj.availableVideoStreams.get(l.value)),e.cloudRenderEngine.streamTrackSource)for(const t of e.cloudRenderEngine.streamTrackSource.getVideoTracks())if(t.id===h.value){e.cloudRenderEngine.webRtcPlayerObj.video.srcObject=new MediaStream([t]),e.cloudRenderEngine.webRtcPlayerObj.video.play(),l.value="";break}}))}}onExpandOverlay_Click(){document.getElementById("overlay").classList.toggle("overlay-shown")}gamepadConnectHandler(e){console.log("Gamepad connect handler")}gamepadDisconnectHandler(e){console.log("Gamepad disconnect handler"),console.log("gamepad: "+e.gamepad.id+" disconnected"),delete this.cloudRenderEngine.controllers[e.gamepad.index]}emitMouseMove(e,t,i,s){this.cloudRenderEngine.print_inputs&&console.log(`emitMouseMove x: ${e}, y:${t}, dX: ${i}, dY: ${s}`);let a=this.cloudRenderEngine.normalizeAndQuantizeUnsigned(e,t),o=this.cloudRenderEngine.normalizeAndQuantizeSigned(i,s),n=new DataView(new ArrayBuffer(9));n.setUint8(0,P.MouseMove),n.setUint16(1,a.x,!0),n.setUint16(3,a.y,!0),n.setInt16(5,o.x,!0),n.setInt16(7,o.y,!0),this.cloudRenderEngine.sendInputData(n.buffer)}emitMouseDown(e,t,i){this.print_inputs&&console.log(`mouse button ${e} down at (${t}, ${i})`);let s=this.cloudRenderEngine.normalizeAndQuantizeUnsigned(t,i),a=new DataView(new ArrayBuffer(6));a.setUint8(0,P.MouseDown),a.setUint8(1,e),a.setUint16(2,s.x,!0),a.setUint16(4,s.y,!0),this.cloudRenderEngine.sendInputData(a.buffer)}emitMouseUp(e,t,i){this.print_inputs&&console.log(`mouse button ${e} up at (${t}, ${i})`);let s=this.cloudRenderEngine.normalizeAndQuantizeUnsigned(t,i),a=new DataView(new ArrayBuffer(6));a.setUint8(0,P.MouseUp),a.setUint8(1,e),a.setUint16(2,s.x,!0),a.setUint16(4,s.y,!0),this.cloudRenderEngine.sendInputData(a.buffer)}emitMouseWheel(e,t,i){this.print_inputs&&console.log(`mouse wheel with delta ${e} at (${t}, ${i})`);let s=this.cloudRenderEngine.normalizeAndQuantizeUnsigned(t,i),a=new DataView(new ArrayBuffer(7));a.setUint8(0,P.MouseWheel),a.setInt16(1,e,!0),a.setUint16(3,s.x,!0),a.setUint16(5,s.y,!0),this.cloudRenderEngine.sendInputData(a.buffer)}releaseMouseButtons(e,t,i){e&k.PrimaryButton&&this.emitMouseUp(L.MainButton,t,i),e&k.SecondaryButton&&this.emitMouseUp(L.SecondaryButton,t,i),e&k.AuxiliaryButton&&this.emitMouseUp(L.AuxiliaryButton,t,i),e&k.FourthButton&&this.emitMouseUp(L.FourthButton,t,i),e&k.FifthButton&&this.emitMouseUp(L.FifthButton,t,i)}pressMouseButtons(e,t,i){e&k.PrimaryButton&&this.emitMouseDown(L.MainButton,t,i),e&k.SecondaryButton&&this.emitMouseDown(L.SecondaryButton,t,i),e&k.AuxiliaryButton&&this.emitMouseDown(L.AuxiliaryButton,t,i),e&k.FourthButton&&this.emitMouseDown(L.FourthButton,t,i),e&k.FifthButton&&this.emitMouseDown(L.FifthButton,t,i)}registerInputs(e){e&&(this.registerMouseEnterAndLeaveEvents(e),this.registerTouchEvents(e))}registerMouseEnterAndLeaveEvents(e){const t=this;e.onmouseenter=function(i){t.print_inputs&&console.log("mouse enter");let s=new DataView(new ArrayBuffer(1));s.setUint8(0,P.MouseEnter),t.cloudRenderEngine.sendInputData(s.buffer),e.pressMouseButtons(i)},e.onmouseleave=function(i){t.print_inputs&&console.log("mouse leave");let s=new DataView(new ArrayBuffer(1));s.setUint8(0,P.MouseLeave),t.cloudRenderEngine.sendInputData(s.buffer),e.releaseMouseButtons(i)}}registerLockedMouseEvents(e){const t=this;let i=e.width/2,s=e.height/2;function a(){document.pointerLockElement===e||document.mozPointerLockElement===e?(console.log("Pointer locked"),document.addEventListener("mousemove",o,!1)):(console.log("The pointer lock status is now unlocked"),document.removeEventListener("mousemove",o,!1))}function o(e){i+=e.movementX,s+=e.movementY,i>t.styleWidth&&(i-=t.styleWidth),s>t.styleHeight&&(s-=t.styleHeight),i<0&&(i=t.styleWidth+i),s<0&&(s=t.styleHeight-s),t.emitMouseMove(i,s,e.movementX,e.movementY)}e.requestPointerLock=e.requestPointerLock||e.mozRequestPointerLock,document.exitPointerLock=document.exitPointerLock||document.mozExitPointerLock,e.onclick=function(){e.requestPointerLock()},document.addEventListener("pointerlockchange",a,!1),document.addEventListener("mozpointerlockchange",a,!1),e.onmousedown=function(e){t.emitMouseDown(e.button,i,s)},e.onmouseup=function(e){t.emitMouseUp(e.button,i,s)},e.onmousewheel=function(e){t.emitMouseWheel(e.wheelDelta,i,s)},e.pressMouseButtons=function(e){t.pressMouseButtons(e.buttons,i,s)},e.releaseMouseButtons=function(e){t.releaseMouseButtons(e.buttons,i,s)}}registerHoveringMouseEvents(e){const t=this;e.onpointermove=function(e){t.emitMouseMove(e.offsetX,e.offsetY,e.movementX,e.movementY),e.preventDefault()},e.onpointerdown=function(e){t.emitMouseDown(e.button,e.offsetX,e.offsetY),e.preventDefault()},e.onpointerup=function(e){t.emitMouseUp(e.button,e.offsetX,e.offsetY),e.preventDefault()},e.oncontextmenu=function(e){t.emitMouseUp(e.button,e.offsetX,e.offsetY),e.preventDefault()},"onmousewheel"in e?e.onmousewheel=function(e){t.emitMouseWheel(e.wheelDelta,e.offsetX,e.offsetY),e.preventDefault()}:e.addEventListener("DOMMouseScroll",(function(e){t.emitMouseWheel(-120*e.detail,e.offsetX,e.offsetY),e.preventDefault()}),!1),e.pressMouseButtons=function(e){t.pressMouseButtons(e.buttons,e.offsetX,e.offsetY)},e.releaseMouseButtons=function(e){t.releaseMouseButtons(e.buttons,e.offsetX,e.offsetY)}}registerTouchEvents(e){const t=this;let i=[9,8,7,6,5,4,3,2,1,0],s={};function a(e){let t=i.pop();void 0===t&&console.log("exhausted touch indentifiers"),s[e.identifier]=t}function o(i,a){let o=new DataView(new ArrayBuffer(2+7*a.length));o.setUint8(0,i),o.setUint8(1,a.length);let n=2;for(let i=0;i<a.length;i++){let r=a[i],l=r.clientX-e.offsetLeft,h=r.clientY-e.offsetTop;t.print_inputs&&console.log(`F${s[r.identifier]}=(${l}, ${h})`);let d=t.cloudRenderEngine.normalizeAndQuantizeUnsigned(l,h);o.setUint16(n,d.x,!0),n+=2,o.setUint16(n,d.y,!0),n+=2,o.setUint8(n,s[r.identifier],!0),n+=1,o.setUint8(n,255*r.force,!0),n+=1,o.setUint8(n,d.inRange?1:0,!0),n+=1}t.cloudRenderEngine.sendInputData(o.buffer)}if(this.inputOptions.fakeMouseWithTouches){let i;e.ontouchstart=function(s){if(void 0===i){let a=s.changedTouches[0];i={id:a.identifier,x:a.clientX-t.playerElementClientRect.left,y:a.clientY-t.playerElementClientRect.top},e.onmouseenter(s),t.emitMouseDown(L.MainButton,i.x,i.y)}s.preventDefault()},e.ontouchend=function(s){for(let a=0;a<s.changedTouches.length;a++){let o=s.changedTouches[a];if(o.identifier===i.id){let a=o.clientX-t.playerElementClientRect.left,n=o.clientY-t.playerElementClientRect.top;t.emitMouseUp(L.MainButton,a,n),e.onmouseleave(s),i=void 0;break}}s.preventDefault()},e.ontouchmove=function(e){for(let s=0;s<e.touches.length;s++){let a=e.touches[s];if(a.identifier===i.id){let e=a.clientX-t.playerElementClientRect.left,s=a.clientY-t.playerElementClientRect.top;t.emitMouseMove(e,s,e-i.x,s-i.y),i.x=e,i.y=s;break}}e.preventDefault()}}else e.ontouchstart=function(e){for(let t=0;t<e.changedTouches.length;t++)a(e.changedTouches[t]);t.print_inputs&&console.log("touch start"),o(P.TouchStart,e.changedTouches),e.preventDefault()},e.ontouchend=function(e){t.print_inputs&&console.log("touch end"),o(P.TouchEnd,e.changedTouches);for(let t=0;t<e.changedTouches.length;t++)a=e.changedTouches[t],i.push(s[a.identifier]),delete s[a.identifier];var a;e.preventDefault()},e.ontouchmove=function(e){t.print_inputs&&console.log("touch move"),o(P.TouchMove,e.touches),e.preventDefault()}}callRespone(e){const{uuid:t,classType:i}=e;if(this.interactiveObjects.has(t)){this.interactiveObjects.get(t).dispatchEvent(e)}else"cloudrenderengine"===i.toLowerCase()?this.cloudRenderEngine.dispatchEvent(e):"scene"===i.toLowerCase()?this.scene&&this.scene.dispatchEvent(e):"camera"===i.toLowerCase()&&this.cloudRenderEngine.camera&&this.cloudRenderEngine.camera.dispatchEvent(e)}}let J=0;const Y=new t,q=new i,X=new s,K=new t,Q=new t,Z=new t,ee=new i,te=new t(1,0,0),ie=new t(0,1,0),se=new t(0,0,1),ae={type:"added"},oe={type:"removed"};class ne extends G{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:J++}),this.uuid=a.generateUUID(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=ne.DEFAULT_UP.clone();const e=new t,l=new o,h=new i,d=new t(1,1,1);l._onChange((function(){h.setFromEuler(l,!1)})),h._onChange((function(){l.setFromQuaternion(h,void 0,!1)})),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:e},rotation:{configurable:!0,enumerable:!0,value:l},quaternion:{configurable:!0,enumerable:!0,value:h},scale:{configurable:!0,enumerable:!0,value:d},modelViewMatrix:{value:new s},normalMatrix:{value:new n}}),this.matrix=new s,this.matrixWorld=new s,this.matrixAutoUpdate=ne.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.matrixWorldAutoUpdate=ne.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.layers=new r,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.userData={}}onBeforeRender(){}onAfterRender(){}applyMatrix4(e){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(e),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(e){return this.quaternion.premultiply(e),this}setRotationFromAxisAngle(e,t){this.quaternion.setFromAxisAngle(e,t)}setRotationFromEuler(e){this.quaternion.setFromEuler(e,!0)}setRotationFromMatrix(e){this.quaternion.setFromRotationMatrix(e)}setRotationFromQuaternion(e){this.quaternion.copy(e)}rotateOnAxis(e,t){return q.setFromAxisAngle(e,t),this.quaternion.multiply(q),this}rotateOnWorldAxis(e,t){return q.setFromAxisAngle(e,t),this.quaternion.premultiply(q),this}rotateX(e){return this.rotateOnAxis(te,e)}rotateY(e){return this.rotateOnAxis(ie,e)}rotateZ(e){return this.rotateOnAxis(se,e)}translateOnAxis(e,t){return Y.copy(e).applyQuaternion(this.quaternion),this.position.add(Y.multiplyScalar(t)),this}translateX(e){return this.translateOnAxis(te,e)}translateY(e){return this.translateOnAxis(ie,e)}translateZ(e){return this.translateOnAxis(se,e)}localToWorld(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(this.matrixWorld)}worldToLocal(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(X.copy(this.matrixWorld).invert())}lookAt(e,t,i){e.isVector3?K.copy(e):K.set(e,t,i);const s=this.parent;this.updateWorldMatrix(!0,!1),Q.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?X.lookAt(Q,K,this.up):X.lookAt(K,Q,this.up),this.quaternion.setFromRotationMatrix(X),s&&(X.extractRotation(s.matrixWorld),q.setFromRotationMatrix(X),this.quaternion.premultiply(q.invert()))}add(e){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return e===this?(console.error("THREE.Object3D.add: object can't be added as a child of itself.",e),this):(e&&e.isObject3D?(null!==e.parent&&e.parent.remove(e),e.parent=this,this.children.push(e),e.dispatchEvent(ae)):console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.",e),this)}remove(e){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.remove(arguments[e]);return this}const t=this.children.indexOf(e);return-1!==t&&(e.parent=null,this.children.splice(t,1),e.dispatchEvent(oe)),this}removeFromParent(){const e=this.parent;return null!==e&&e.remove(this),this}clear(){for(let e=0;e<this.children.length;e++){const t=this.children[e];t.parent=null,t.dispatchEvent(oe)}return this.children.length=0,this}attach(e){return this.updateWorldMatrix(!0,!1),X.copy(this.matrixWorld).invert(),null!==e.parent&&(e.parent.updateWorldMatrix(!0,!1),X.multiply(e.parent.matrixWorld)),e.applyMatrix4(X),this.add(e),e.updateWorldMatrix(!1,!0),this}getObjectById(e){return this.getObjectByProperty("id",e)}getObjectByName(e){return this.getObjectByProperty("name",e)}getObjectByProperty(e,t){if(this[e]===t)return this;for(let i=0,s=this.children.length;i<s;i++){const s=this.children[i].getObjectByProperty(e,t);if(void 0!==s)return s}}getObjectsByProperty(e,t){let i=[];this[e]===t&&i.push(this);for(let s=0,a=this.children.length;s<a;s++){const a=this.children[s].getObjectsByProperty(e,t);a.length>0&&(i=i.concat(a))}return i}getWorldPosition(e){return this.updateWorldMatrix(!0,!1),e.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Q,e,Z),e}getWorldScale(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Q,ee,e),e}getWorldDirection(e){this.updateWorldMatrix(!0,!1);const t=this.matrixWorld.elements;return e.set(t[8],t[9],t[10]).normalize()}raycast(){}traverse(e){e(this);const t=this.children;for(let i=0,s=t.length;i<s;i++)t[i].traverse(e)}traverseVisible(e){if(!1===this.visible)return;e(this);const t=this.children;for(let i=0,s=t.length;i<s;i++)t[i].traverseVisible(e)}traverseAncestors(e){const t=this.parent;null!==t&&(e(t),t.traverseAncestors(e))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(e){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||e)&&(null===this.parent?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix),this.matrixWorldNeedsUpdate=!1,e=!0);const t=this.children;for(let i=0,s=t.length;i<s;i++){const s=t[i];!0!==s.matrixWorldAutoUpdate&&!0!==e||s.updateMatrixWorld(e)}}updateWorldMatrix(e,t){const i=this.parent;if(!0===e&&null!==i&&!0===i.matrixWorldAutoUpdate&&i.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),null===this.parent?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix),!0===t){const e=this.children;for(let t=0,i=e.length;t<i;t++){const i=e[t];!0===i.matrixWorldAutoUpdate&&i.updateWorldMatrix(!1,!0)}}}toJSON(e){const t=void 0===e||"string"==typeof e,i={};t&&(e={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},i.metadata={version:4.5,type:"Object",generator:"Object3D.toJSON"});const s={};function a(t,i){return void 0===t[i.uuid]&&(t[i.uuid]=i.toJSON(e)),i.uuid}if(s.uuid=this.uuid,s.type=this.type,""!==this.name&&(s.name=this.name),!0===this.castShadow&&(s.castShadow=!0),!0===this.receiveShadow&&(s.receiveShadow=!0),!1===this.visible&&(s.visible=!1),!1===this.frustumCulled&&(s.frustumCulled=!1),0!==this.renderOrder&&(s.renderOrder=this.renderOrder),Object.keys(this.userData).length>0&&(s.userData=this.userData),s.layers=this.layers.mask,s.matrix=this.matrix.toArray(),s.up=this.up.toArray(),!1===this.matrixAutoUpdate&&(s.matrixAutoUpdate=!1),this.isInstancedMesh&&(s.type="InstancedMesh",s.count=this.count,s.instanceMatrix=this.instanceMatrix.toJSON(),null!==this.instanceColor&&(s.instanceColor=this.instanceColor.toJSON())),this.isScene)this.background&&(this.background.isColor?s.background=this.background.toJSON():this.background.isTexture&&(s.background=this.background.toJSON(e).uuid)),this.environment&&this.environment.isTexture&&!0!==this.environment.isRenderTargetTexture&&(s.environment=this.environment.toJSON(e).uuid);else if(this.isMesh||this.isLine||this.isPoints){s.geometry=a(e.geometries,this.geometry);const t=this.geometry.parameters;if(void 0!==t&&void 0!==t.shapes){const i=t.shapes;if(Array.isArray(i))for(let t=0,s=i.length;t<s;t++){const s=i[t];a(e.shapes,s)}else a(e.shapes,i)}}if(this.isSkinnedMesh&&(s.bindMode=this.bindMode,s.bindMatrix=this.bindMatrix.toArray(),void 0!==this.skeleton&&(a(e.skeletons,this.skeleton),s.skeleton=this.skeleton.uuid)),void 0!==this.material)if(Array.isArray(this.material)){const t=[];for(let i=0,s=this.material.length;i<s;i++)t.push(a(e.materials,this.material[i]));s.material=t}else s.material=a(e.materials,this.material);if(this.children.length>0){s.children=[];for(let t=0;t<this.children.length;t++)s.children.push(this.children[t].toJSON(e).object)}if(this.animations.length>0){s.animations=[];for(let t=0;t<this.animations.length;t++){const i=this.animations[t];s.animations.push(a(e.animations,i))}}if(t){const t=o(e.geometries),s=o(e.materials),a=o(e.textures),n=o(e.images),r=o(e.shapes),l=o(e.skeletons),h=o(e.animations),d=o(e.nodes);t.length>0&&(i.geometries=t),s.length>0&&(i.materials=s),a.length>0&&(i.textures=a),n.length>0&&(i.images=n),r.length>0&&(i.shapes=r),l.length>0&&(i.skeletons=l),h.length>0&&(i.animations=h),d.length>0&&(i.nodes=d)}return i.object=s,i;function o(e){const t=[];for(const i in e){const s=e[i];delete s.metadata,t.push(s)}return t}}clone(e){return(new this.constructor).copy(this,e)}copy(e,t=!0){if(this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),this.rotation.order=e.rotation.order,this.quaternion.copy(e.quaternion),this.scale.copy(e.scale),this.matrix.copy(e.matrix),this.matrixWorld.copy(e.matrixWorld),this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrixWorldNeedsUpdate=e.matrixWorldNeedsUpdate,this.matrixWorldAutoUpdate=e.matrixWorldAutoUpdate,this.layers.mask=e.layers.mask,this.visible=e.visible,this.castShadow=e.castShadow,this.receiveShadow=e.receiveShadow,this.frustumCulled=e.frustumCulled,this.renderOrder=e.renderOrder,this.userData=JSON.parse(JSON.stringify(e.userData)),!0===t)for(let t=0;t<e.children.length;t++){const i=e.children[t];this.add(i.clone())}return this}}ne.DEFAULT_UP=new t(0,1,0),ne.DEFAULT_MATRIX_AUTO_UPDATE=!0,ne.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;class re extends ne{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.childrenSet=new Set,this.backgroundBlurriness=0,this.backgroundIntensity=1,this.overrideMaterial=null}copy(e,t){return super.copy(e,t),null!==e.background&&(this.background=e.background.clone()),null!==e.environment&&(this.environment=e.environment.clone()),null!==e.fog&&(this.fog=e.fog.clone()),this.backgroundBlurriness=e.backgroundBlurriness,this.backgroundIntensity=e.backgroundIntensity,null!==e.overrideMaterial&&(this.overrideMaterial=e.overrideMaterial.clone()),this.matrixAutoUpdate=e.matrixAutoUpdate,this}toJSON(e){const t=super.toJSON(e);return null!==this.fog&&(t.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(t.backgroundBlurriness=this.backgroundBlurriness),1!==this.backgroundIntensity&&(t.backgroundIntensity=this.backgroundIntensity),t}get autoUpdate(){return console.warn("THREE.Scene: autoUpdate was renamed to matrixWorldAutoUpdate in r144."),this.matrixWorldAutoUpdate}set autoUpdate(e){console.warn("THREE.Scene: autoUpdate was renamed to matrixWorldAutoUpdate in r144."),this.matrixWorldAutoUpdate=e}}class le extends ne{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new s,this._level=0,this._levelChange=0,this.projectionMatrix=new s,this.projectionMatrixInverse=new s;let e=new t,i=-9999,a=-9999,o=-9999,n=-180,r=180,l=-89,h=0,d=-9999,c=-9999;this.needsUpd