2

I have the following error while using OBJLoader.js to load obj model o Resource "https://cdnjs.cloudflare.com/ajax/libs/three.js/r119/OBJLoader.js" blocked due to mismatch (X-Content-Type-Options: nosniff) MIME type ("text/html").

My whole code below.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Model 3D</title>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r119/three.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r119/OBJLoader.js"></script>

    <style>
        body {
            margin: 0;
        }
    </style>

</head>
<body>
    <script>
        // Tworzymy scenę
        var scene = new THREE.Scene();

        // Tworzymy kamerę
        var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
        camera.position.z = 5;

        // Tworzymy render
        var renderer = new THREE.WebGLRenderer();
        renderer.setSize( window.innerWidth, window.innerHeight );
        document.body.appendChild( renderer.domElement );

        // Tworzymy loader
        var loader = new THREE.OBJLoader();

        // Załadowanie modelu
        loader.load( 'Rubix.obj', function ( object ) {
            scene.add( object );
            object.position.set(0, 0, 0);
            object.rotation.set(0, 0, 0);
            object.scale.set(1, 1, 1);
        });

        // Pętla renderująca
        var render = function () {
            requestAnimationFrame( render );
            renderer.render( scene, camera );
        };

        render();
    </script>
</body>
</html>

3D model: https://drive.google.com/file/d/1ScF-bSB46F7Ua4dQ0jw1sihmuTjahvom/view?usp=share_link

If you have any ideas what can go wrong please tell me. I will be grateful if you can propose me how to display my OBJ model on a webpage, because I tried ideas from the Internet and none of them worked for me.

1 Answer 1

3

cdnjs only serves the core files but not the examples/addons like loaders or controls. Do you mind using a different CDN instead? Below links should work as expected.

https://cdn.jsdelivr.net/npm/[email protected]/build/three.min.js
https://cdn.jsdelivr.net/npm/[email protected]/examples/js/loaders/OBJLoader.js
Sign up to request clarification or add additional context in comments.

7 Comments

I used your links and it's still black screen, however the error with MIME dismatch disapperaed. Now the error says "Error: Promised response from onMessage listener went out of scope"
This error is sometimes caused by browser extensions. Try to disable all installed addons, use a private tab or install a different browser.
I tried it on Chrome and now the access to local model is blocked. I updated the question with link to 3D model I try to insert. Can you try it by yourself if it works?
Are you hosting your application on a local web server? You have to do this otherwise security policies block the access. BTW: The model itself can be imported in the three.js editor so there is no issue with the loader.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.