archematics/src/giveAwrl.civet

28 lines
1004 B
Plaintext
Raw Normal View History

import https://code.jquery.com/jquery-3.7.1.js
X3D from https://create3000.github.io/code/x_ite/latest/x_ite.mjs
{convert} from ./deps/vrml1to97/index.js
certainlyHandled := '.x3d .gltf .glb .obj .stl .ply'.split ' '
// 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.
canvas := X3D.createBrowser()
$(canvas).css width: '150px', height: '150px'
browser := X3D.getBrowser canvas
browser.setBrowserOption 'StraightenHorizon', false
site := $('a[href^="http"]')
url := site.attr('href') ?? ''
if certainlyHandled.some((ext) => url.includes ext)
canvas.setAttribute 'src', url
else if url.includes '.wrl'
// Need to obtain the text and check what level it is
response := await fetch url
text .= await response.text()
if /#\s*VRML\s*V?1[.]/i.test text
text = convert text
browser.baseURL = url
scene := await browser.createX3DFromString text
browser.replaceWorld scene
site.after(canvas)