2023-08-31 05:30:41 +00:00
|
|
|
import https://code.jquery.com/jquery-3.7.1.js
|
2023-09-05 01:50:52 +00:00
|
|
|
X3D from https://create3000.github.io/code/x_ite/latest/x_ite.mjs
|
|
|
|
{convert} from ./deps/vrml1to97/index.js
|
2023-08-31 05:30:41 +00:00
|
|
|
|
|
|
|
certainlyHandled := '.x3d .gltf .glb .obj .stl .ply'.split ' '
|
2023-09-11 18:20:09 +00:00
|
|
|
// The next line will need to change when we handle pages with more than
|
|
|
|
// one link, since we will potentially need a canvas for each one.
|
2023-09-05 01:50:52 +00:00
|
|
|
canvas := X3D.createBrowser()
|
2023-09-11 18:20:09 +00:00
|
|
|
$(canvas).css width: '150px', height: '150px'
|
2023-09-11 01:52:39 +00:00
|
|
|
browser := X3D.getBrowser canvas
|
|
|
|
browser.setBrowserOption 'StraightenHorizon', false
|
2023-09-05 01:50:52 +00:00
|
|
|
site := $('a[href^="http"]')
|
2023-09-11 01:52:39 +00:00
|
|
|
url := site.attr('href') ?? ''
|
|
|
|
|
2023-09-05 01:50:52 +00:00
|
|
|
if certainlyHandled.some((ext) => url.includes ext)
|
2023-09-11 01:52:39 +00:00
|
|
|
canvas.setAttribute 'src', url
|
2023-09-05 01:50:52 +00:00
|
|
|
else if url.includes '.wrl'
|
|
|
|
// Need to obtain the text and check what level it is
|
|
|
|
response := await fetch url
|
|
|
|
text .= await response.text()
|
2023-09-11 03:44:16 +00:00
|
|
|
if /#\s*VRML\s*V?1[.]/i.test text
|
|
|
|
text = convert text
|
|
|
|
browser.baseURL = url
|
2023-09-05 01:50:52 +00:00
|
|
|
scene := await browser.createX3DFromString text
|
2023-09-11 03:44:16 +00:00
|
|
|
browser.replaceWorld scene
|
2023-09-11 01:52:39 +00:00
|
|
|
|
2023-09-05 01:50:52 +00:00
|
|
|
site.after(canvas)
|