1(function () { 2 // Shared Lib 3 var CANVAS_ID = 'application-canvas'; 4 5 // Needed as we will have edge cases for particular versions of iOS 6 // returns null if not iOS 7 var getIosVersion = function () { 8 if (/iP(hone|od|ad)/.test(navigator.platform)) { 9 var v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/); 10 var version = [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)]; 11 return version; 12 } 13 14 return null; 15 }; 16 17 var lastWindowHeight = window.innerHeight; 18 var lastWindowWidth = window.innerWidth; 19 var windowSizeChangeIntervalHandler = null; 20 21 var pcBootstrap = { 22 reflowHandler: null, 23 iosVersion: getIosVersion(), 24 25 createCanvas: function () { 26 var canvas = document.createElement('canvas'); 27 canvas.setAttribute('id', CANVAS_ID); 28 canvas.setAttribute('tabindex', 0); 29 30 // Disable I-bar cursor on click+drag 31 canvas.onselectstart = function () { return false; }; 32 33 // Disable long-touch select on iOS devices 34 canvas.style['-webkit-user-select'] = 'none'; 35 36 document.body.appendChild(canvas); 37 38 return canvas; 39 }, 40 41 42 resizeCanvas: function (app, canvas) { 43 canvas.style.width = ''; 44 canvas.style.height = ''; 45 app.resizeCanvas(canvas.width, canvas.height); 46 47 var fillMode = app._fillMode; 48 49 if (fillMode === pc.FILLMODE_NONE || fillMode === pc.FILLMODE_KEEP_ASPECT) { 50 if ((fillMode === pc.FILLMODE_NONE && canvas.clientHeight < window.innerHeight) || (canvas.clientWidth / canvas.clientHeight >= window.innerWidth / window.innerHeight)) { 51 canvas.style.marginTop = Math.floor((window.innerHeight - canvas.clientHeight) / 2) + 'px'; 52 } else { 53 canvas.style.marginTop = ''; 54 } 55 } 56 57 lastWindowHeight = window.innerHeight; 58 lastWindowWidth = window.innerWidth; 59 60 // Work around when in landscape to work on iOS 12 otherwise 61 // the content is under the URL bar at the top 62 if (this.iosVersion && this.iosVersion[0] <= 12) { 63 window.scrollTo(0, 0); 64 } 65 }, 66 67 reflow: function (app, canvas) { 68 this.resizeCanvas(app, canvas); 69 70 // Poll for size changes as the window inner height can change after the resize event for iOS 71 // Have one tab only, and rotate from portrait -> landscape -> portrait 72 if (windowSizeChangeIntervalHandler === null) { 73 windowSizeChangeIntervalHandler = setInterval(function () { 74 if (lastWindowHeight !== window.innerHeight || lastWindowWidth !== window.innerWidth) { 75 this.resizeCanvas(app, canvas); 76 } 77 }.bind(this), 100); 78 79 // Don't want to do this all the time so stop polling after some short time 80 setTimeout(function () { 81 if (!!windowSizeChangeIntervalHandler) { 82 clearInterval(windowSizeChangeIntervalHandler); 83 windowSizeChangeIntervalHandler = null; 84 } 85 }, 2000); 86 } 87 } 88 }; 89 90 // Expose the reflow to users so that they can override the existing 91 // reflow logic if need be 92 window.pcBootstrap = pcBootstrap; 93})(); 94 95 96(function () { 97 // template varants 98 var LTC_MAT_1 = []; 99 var LTC_MAT_2 = []; 100 101 // varants 102 var canvas = pcBootstrap.createCanvas(); 103 var app = new pc.AppBase(canvas); 104 105 function initCSS() { 106 if (document.head.querySelector) { 107 // css media query for aspect ratio changes 108 // TODO: Change these from private properties 109 var css = `@media screen and (min-aspect-ratio: ${app._width}/${app._height}) { 110 #application-canvas.fill-mode-KEEP_ASPECT { 111 width: auto; 112 height: 100%; 113 margin: 0 auto; 114 } 115 }`; 116 document.head.querySelector('style').innerHTML += css; 117 } 118 119 // Configure resolution and resize event 120 if (canvas.classList) { 121 canvas.classList.add(`fill-mode-${app.fillMode}`); 122 } 123 } 124 125 function displayError(html) { 126 var div = document.createElement('div'); 127 div.innerHTML = `<table style="background-color: #8CE; width: 100%; height: 100%;"> 128 <tr> 129 <td align="center"> 130 <div style="display: table-cell; vertical-align: middle;"> 131 <div style="">${html}</div> 132 </div> 133 </td> 134 </tr> 135 </table>`; 136 document.body.appendChild(div); 137 } 138 139 function createGraphicsDevice(callback) { 140 var deviceOptions = window.CONTEXT_OPTIONS ? window.CONTEXT_OPTIONS : {}; 141 142 if (typeof window.Promise === 'function') { 143 var LEGACY_WEBGL = 'webgl'; 144 var deviceTypes = [...deviceOptions.deviceTypes, LEGACY_WEBGL]; 145
146 var gpuLibPath = window.ASSET_PREFIX ? (window.ASSET_PREFIX.replace(/\/$/g, '') + '/') : ''; 147 148 // new graphics device creation function with promises 149 var gfxOptions = { 150 deviceTypes: deviceTypes, 151 glslangUrl: gpuLibPath + 'glslang.js', 152 twgslUrl: gpuLibPath + 'twgsl.js', 153 powerPreference: deviceOptions.powerPreference, 154 antialias: deviceOptions.antialias !== false, 155 alpha: deviceOptions.alpha === true, 156 preserveDrawingBuffer: !!deviceOptions.preserveDrawingBuffer 157 }; 158 159 pc.createGraphicsDevice(canvas, gfxOptions).then((device) => { 160 callback(device); 161 }).catch((e) => { 162 console.error('Device creation error:', e); 163 callback(null); 164 }) 165 } else { 166 var igl1 = deviceOptions.deviceTypes.indexOf('webgl1'); 167 var igl2 = deviceOptions.deviceTypes.indexOf('webgl2'); 168 169 // old webgl graphics device creation 170 var options = { 171 powerPreference: deviceOptions.powerPreference, 172 antialias: deviceOptions.antialias !== false, 173 alpha: deviceOptions.transparentCanvas !== false, 174 preserveDrawingBuffer: !!deviceOptions.preserveDrawingBuffer, 175 preferWebGl2: igl2 > igl1 176 }; 177 178 if (pc.platform.browser && !!navigator.xr) { 179 options.xrCompatible = true; 180 } 181 182 callback(new pc.WebglGraphicsDevice(canvas, options)); 183 } 184 } 185 186 function initApp(device) { 187 try { 188 var createOptions = new pc.AppOptions(); 189 createOptions.graphicsDevice = device; 190 191 createOptions.componentSystems = [ 192 pc.RigidBodyComponentSystem, 193 pc.CollisionComponentSystem, 194 pc.JointComponentSystem, 195 pc.AnimationComponentSystem, 196 pc.AnimComponentSystem, 197 pc.ModelComponentSystem, 198 pc.RenderComponentSystem, 199 pc.CameraComponentSystem, 200 pc.LightComponentSystem, 201 pc.script.legacy ? pc.ScriptLegacyComponentSystem : pc.ScriptComponentSystem, 202 pc.AudioSourceComponentSystem, 203 pc.SoundComponentSystem, 204 pc.AudioListenerComponentSystem, 205 pc.ParticleSystemComponentSystem, 206 pc.ScreenComponentSystem, 207 pc.ElementComponentSystem, 208 pc.ButtonComponentSystem, 209 pc.ScrollViewComponentSystem, 210 pc.ScrollbarComponentSystem, 211 pc.SpriteComponentSystem, 212 pc.LayoutGroupComponentSystem, 213 pc.LayoutChildComponentSystem, 214 pc.ZoneComponentSystem, 215 pc.GSplatComponentSystem, 216 ].filter(Boolean); 217 218 createOptions.resourceHandlers = [ 219 pc.RenderHandler, 220 pc.AnimationHandler, 221 pc.AnimClipHandler, 222 pc.AnimStateGraphHandler, 223 pc.ModelHandler, 224 pc.MaterialHandler, 225 pc.TextureHandler, 226 pc.TextHandler, 227 pc.JsonHandler, 228 pc.AudioHandler, 229 pc.ScriptHandler, 230 pc.SceneHandler, 231 pc.CubemapHandler, 232 pc.HtmlHandler, 233 pc.CssHandler, 234 pc.ShaderHandler, 235 pc.HierarchyHandler, 236 pc.FolderHandler, 237 pc.FontHandler, 238 pc.BinaryHandler, 239 pc.TextureAtlasHandler, 240 pc.SpriteHandler, 241 pc.TemplateHandler, 242 pc.ContainerHandler, 243 pc.GSplatHandler 244 ].filter(Boolean); 245 246 createOptions.elementInput = new pc.ElementInput(canvas, { 247 useMouse: INPUT_SETTINGS.useMouse, 248 useTouch: INPUT_SETTINGS.useTouch 249 }); 250 createOptions.keyboard = INPUT_SETTINGS.useKeyboard ? new pc.Keyboard(window) : null; 251 createOptions.mouse = INPUT_SETTINGS.useMouse ? new pc.Mouse(canvas) : null; 252 createOptions.gamepads = INPUT_SETTINGS.useGamepads ? new pc.GamePads() : null; 253 createOptions.touch = INPUT_SETTINGS.useTouch && pc.platform.touch ? new pc.TouchDevice(canvas) : null; 254 createOptions.assetPrefix = window.ASSET_PREFIX || ''; 255 createOptions.scriptPrefix = window.SCRIPT_PREFIX || ''; 256 createOptions.scriptsOrder = window.SCRIPTS || []; 257 createOptions.soundManager = new pc.SoundManager(); 258 createOptions.lightmapper = pc.Lightmapper; 259 createOptions.batchManager = pc.BatchManager; 260 createOptions.xr = pc.XrManager; 261 262 app.init(createOptions); 263 return true; 264 265 } catch (e) { 266 displayError('Could not initialize application. Error: ' + e); 267 console.error(e); 268 return false;
269 } 270 } 271 272 function configure() { 273 app.configure(window.CONFIG_FILENAME, (err) => { 274 if (err) { 275 console.error(err); 276 return; 277 } 278 279 initCSS(); 280 281 if (LTC_MAT_1.length && LTC_MAT_2.length && app.setAreaLightLuts.length === 2) { 282 app.setAreaLightLuts(LTC_MAT_1, LTC_MAT_2); 283 } 284 285 // do the first reflow after a timeout because of 286 // iOS showing a squished iframe sometimes 287 setTimeout(() => { 288 pcBootstrap.reflow(app, canvas); 289 pcBootstrap.reflowHandler = function () { 290 pcBootstrap.reflow(app, canvas); 291 }; 292 293 window.addEventListener('resize', pcBootstrap.reflowHandler, false); 294 window.addEventListener('orientationchange', pcBootstrap.reflowHandler, false); 295 296 app.preload(() => { 297 app.scenes.loadScene(window.SCENE_PATH, (err) => { 298 if (err) { 299 console.error(err); 300 return; 301 } 302 303 app.start(); 304 }) 305 }) 306 }); 307 }); 308 } 309 310 function main() { 311 createGraphicsDevice((device) => { 312 if (!device) { 313 return; 314 } 315 316 if (!initApp(device)) { 317 return; 318 } 319 320 if (window.PRELOAD_MODULES.length) { 321 loadModules(window.PRELOAD_MODULES, window.ASSET_PREFIX, () => { 322 configure(() => { 323 console.timeEnd('start'); 324 }); 325 }) 326 } else { 327 configure(); 328 } 329 }); 330 } 331 main(); 332})(); // Add scope to avoid polluting window scope
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.