Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How are relative internal URLs resolved when x3d content is supplied by string? #148

Closed
gwhitney opened this issue Aug 31, 2023 · 1 comment
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@gwhitney
Copy link
Contributor

I have a VRML97 file that internally refers to a png via a relative URL. When I use a URL to that VRML97 file as the src attribute, the png loads fine. When I fetch the text and feed it to the browser via createX3DFromString, it can no longer find the png. Is there any way to control the resolution of relative URLs when I load content this way, or do I just have to be sure to replace any relative URLs in the string with absolute URLs before I pass it to createX3DFromString? (The point of fetching and then parsing is to do some preprocessing on the VRML97 code before rendering it.) Thanks for any guidance.

@create3000
Copy link
Owner

create3000 commented Aug 31, 2023

Relative URLs are always resolved against the URL of the current execution context, i.e. the surrounding scene. If you have a Script node, and within this Script node you load a scene via createX3DFromString, all relative URLs are resolved against the URL of the scene to which the Script node belongs.

If you are using the external browser, i.e. within a HTML script element, you can use the baseURL property to control this behavior:

<script>
async function load (x3dSyntax)
{
   const canvas = X3D.createBrowser();
   const browser = canvas .browser;

   browser .baseURL = "https://example.com";  
   const scene = await browser .createX3DFromString (x3dSyntax)
}

load (...)
</script>

See also https://create3000.github.io/x_ite/reference/browser-services#baseurl.

@create3000 create3000 added help wanted Extra attention is needed question Further information is requested labels Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants