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

Semantics of url field #1199

Closed
npolys opened this issue Mar 29, 2022 · 19 comments
Closed

Semantics of url field #1199

npolys opened this issue Mar 29, 2022 · 19 comments

Comments

@npolys
Copy link

npolys commented Mar 29, 2022

In X3D, it is expected that if one url is not found, try the next in the list.

X3DOM fails this if the first url is not found;
in ImageTexture for example.

@andreasplesch
Copy link
Contributor

andreasplesch commented Mar 31, 2022

Confirmed, x3dom only looks at the first url and ignores subsequent ones. Is there are specific use case ? Due to cors, loading from non-origin servers is rare.

For ImageTexture loading x3dom uses the html Image element. It sets the src property to load the image.

https://developer.mozilla.org/en-US/docs/Web/API/Element/error_event maybe an option.

https://github.com/x3dom/x3dom/blob/master/src/util/Utils.js#L177 already uses onerror to try .dds texture loading.

Seems complicated to implement.

this.texture = this.cache.getTexture2D( gl, doc, tex._nameSpace.getURL( tex._vf.url[ 0 ] ),
is called from Texture.update

shape._webgl.texture.push( new x3dom.Texture( gl, shape._nameSpace.doc, this.cache, textures[ t ] ) );
create new Textures.

shape._webgl.texture[ t ].update();
calls update()

@andreasplesch
Copy link
Contributor

andreasplesch commented Mar 31, 2022

Looking at this more, the small patch for createTexture2D here

https://jsitor.com/4tCAhIRslT

may work for most situations. Trying the next url on error after dds rejection should be about right.

Only for ImageTexture and it does not do correct automatic blending for greyscale but should work for dds loading.

Needs checking for potential Background url confusion.

[Inline url needs different loading.]

@andreasplesch
Copy link
Contributor

Could you please give this a try and report back ? It should work to just redefine the x3dom.Utils.createTexture2D function as above, after loading x3dom.js.

@andreasplesch
Copy link
Contributor

Any luck ?

@n-polys
Copy link

n-polys commented Apr 4, 2022 via email

@npolys
Copy link
Author

npolys commented Apr 8, 2022

Thanks ~

I overloaded the function definition with what you supplied:
x3dom.Utils.createTexture2D

I think this error is because I am looking at a path like file:///:/C: first
... and fails at that, then stops.

Console:
Not allowed to load local resource: file:///C:/Users/enikoo/Desktop/MirrorWorlds/MossArtCenter/MossArtCenter_MayaProject/assets/MossArtsCenter_FromUnity_April_6_2017.fbm/MossArtsCenter_Model_trashcan_diffuse_MainTex.jpg

I have removed these addresses from my content with grep and now things are on relative paths.

@npolys
Copy link
Author

npolys commented Apr 8, 2022

also error with this patch in my case:

Uncaught RangeError: Invalid typed array length: 5
at new Uint32Array ()
at Object.x3dom.DDSLoader._read (x3dom.js:7:421745)
at XMLHttpRequest.o.onload (x3dom.js:7:421440)

@andreasplesch
Copy link
Contributor

file:// urls typically will not work.
It looks it tries a url, tries then dds, and then errors at dds loading. Does that url exist ? Firefox ?
Is it possible to reproduce ? Or share the scene ? Try x3dom.debug.js

@npolys
Copy link
Author

npolys commented Apr 8, 2022

Yes uncaught range error also happens in firefox, edge and chrome.

the scene is awkardly large but the imagetextures are like:
url='"C:/Users/enikoo/Desktop/MirrorWorlds/MossArtCenter/MossArtCenter_MayaProject/assets/MossArtsCenter_FromUnity_April_6_2017.fbm/White_Wall_Texture.png" "White_Wall_Texture.png" "C:/Users/enikoo/Desktop/MirrorWorlds/MossArtCenter_November/assets/Nov_27/Nov_METER_MossArt_fbxParts_binary2014-5-Exp/../../../../MossArtCenter/MossArtCenter_MayaProject/assets/MossArtsCenter_FromUnity_April_6_2017.fbm/White_Wall_Texture.png"'

@npolys
Copy link
Author

npolys commented Apr 8, 2022

@andreasplesch
Copy link
Contributor

with which url do you get the range error ?

are you using a http server for local files ?

@andreasplesch
Copy link
Contributor

int32Buffer = new Uint32Array( source, 128, 5 );

is probably where the range error occurs.

I think that means that the xmlhttprequest was successful:

var xhr = new XMLHttpRequest();

while the earlier Image.onload had failed. Not sure when this occurs but perhaps Image src loading is stricter about local cors.
It also means that the first UInt32Array constructor for a bufferview of 32 * 4 = 128 bytes was successful whereas the second one 5 * 4 = 20 bytes further in, from 128 to 148, fails. So the loaded buffer may be between 128 and 148 bytes long.

Is that a really small texture png ?

In any case, it would make sense to extend the check at

if ( source === undefined || source.byteLength < 128 )

to 148 bytes:

if ( source === undefined || source.byteLength < 148 ) 

Could you try this by overloading the function

x3dom.DDSLoader._read = function ( source )

with one which has the extended check ?

@andreasplesch
Copy link
Contributor

Here is the fixed function to test

x3dom.DDSLoader._read = function ( source )
{
    if ( source === undefined || source.byteLength < ( 128 + 5 * 4 ) )
    {
        return;
    }

    var dds =
    {
        isCompressed : false,
        isVolume     : false,
        isCubeMap    : false,
        targets      : [],
        data         : []
    };

    var int32Buffer = new Uint32Array( source, 0, 32 );

    //Parse DDS Header
    dds.header = x3dom.DDSLoader._readHeader( int32Buffer );

    int32Buffer = new Uint32Array( source, 128, 5 );

    //Parse DDS Header
    dds.header10 = x3dom.DDSLoader._readHeader10( dds, int32Buffer );

    //Check if the magic number is present
    if ( dds.header.dwMagic != 0x20534444 )
    {
        return;
    }

    //Check if the header size is correct
    if ( dds.header.dwSize != 0x7C )
    {
        return;
    }

    //Parse resource format
    if ( !x3dom.DDSLoader._readFormat( dds ) )
    {
        return;
    }

    x3dom.DDSLoader._readMipmapCount( dds );

    x3dom.DDSLoader._readType( dds );

    this._readData( dds, source );

    return dds;
};

Just add after loading x3dom.js .

@andreasplesch
Copy link
Contributor

Any errors with local urls ? Relative urls with a running server should work.

@andreasplesch
Copy link
Contributor

I tried with a local html and local urls but chrome will not allow it (unless security checks are disabled with a command line switch).

@andreasplesch
Copy link
Contributor

https://jsitor.com/4tCAhIRslT is updated to be more robust against mixed local and remote urls. Should also now sniff number of color components for proper alpha blending in any url. Any testing would be much appreciated.

@andreasplesch
Copy link
Contributor

@andreasplesch
Copy link
Contributor

See #1208, #1209, #1210 and #1211.

@andreasplesch
Copy link
Contributor

Please reopen as desirable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants