Having an issue with the OBJLoader.js not loading properly in three.js

Encountering an error using OBJLoader.js to load an obj model with the following message:

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")
.

Showcasing my complete code below.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>3D Model</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>
        // Creating a scene
        var scene = new THREE.Scene();

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

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

        // Creating a loader
        var loader = new THREE.OBJLoader();

        // Loading the model
        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);
        });

        // Render loop
        var render = function () {
            requestAnimationFrame( render );
            renderer.render( scene, camera );
        };

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

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

If you have any insights on what might be causing this issue, please share. I appreciate any suggestions on how to effectively display my OBJ model on a webpage since previous attempts found online were unsuccessful for me.

Answer №1

cdnjs provides only the essential files, excluding examples, loaders, and controls. Would you consider using a different CDN? The following links are viable alternatives:

https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="abdfc3d9ceceeb9b859a9a92">[email protected]</a>/build/three.min.js
https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1a6e72687f7f5a2a342b2b23">[email protected]</a>/examples/js/loaders/OBJLoader.js

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to search for and isolate an array object within an array of objects using Javascript?

I am attempting to narrow down the list based on offerings const questions = [ { "id": 2616, "offerings": [{"code": "AA"},{"code": "AB"}]}, { "id": 1505, "offerings": [ ...

Arrange items in a particular order

I need help sorting the object below by name. The desired order is 1)balloon 2)term 3)instalment. loanAdjustmentList = [ { "description": "Restructure Option", "name": "instalment", " ...

Tips for incorporating jQuery to load Rails form partials and submit them as a single form:

Trying to improve the readability of my Rails HTML code, I decided to extract certain portions into partials and then used jQuery to render these partials. However, a problem arose where the form seems disconnected after implementing this approach. It appe ...

Navigating React Redux Pages Using React Router

At the moment, I am exploring the possibility of creating an application using React and Redux. Most examples I've come across make use of React Router, so I'm curious about its purpose. My application will consist of multiple pages (at least 20 ...

Creating a cube with rounded edges and corners using BufferGeometry and split vertices: a step-by-step guide

I am new to the world of THREE.JS and recently I created a cube by drawing 6 sides, each composed of two triangles. This resulted in a total of 6 vertices for each side, with the shared vertices split accordingly. I then proceeded to uv map a texture to ea ...

Moving through divisions that share a common class name using jquery

I am experimenting with a plugin that allows me to attach popups to images. My goal is to enable navigation between all popups using previous and next buttons upon clicking on a popup. Below is the element when it's displayed: <div class="imp-too ...

What is the method to retrieve text from a div element with Webdriver-IO?

Is there a way to extract the value from the following HTML element using Webdriver-IO for automated testing? <div class="metric-value ng-binding" ng-style="{'font-size': vis.params.fontSize+'pt'}" style="font-size: 60 ...

Transform the array of strings

I'm currently working with an array that looks like this: ["[Date.UTC(2016,09,30),250500.00]","[Date.UTC(2016,09,29),255100.83]", "[Date.UTC(2016,09,28),255600.82]"] What would be the best way to transform it into a structure like this? [[Date.UTC( ...

Error: Unable to access the toISOString property of an undefined object

https://i.sstatic.net/jtZnQ.png import './ExpenseItem.css'; function ExpenseItem(props){ return ( <div className="expense-item"> <div>{props.date.toISOString()}</div> <div className="expen ...

What makes fastify-plugin better than simply calling a regular function?

I recently came across a detailed explanation of how fastify-plugin operates and its functionality. Despite understanding the concept, I am left with a lingering question; what sets it apart from a standard function call without using the .register() metho ...

JavaScript: Check array before adding new item to avoid duplicates

Is there a way in JavaScript to determine if an item already exists in an array? I am using the following code to add items to my array: const booked_hours = []; for (let i = 0; i < apptid_set.size; i++) { const book_hours = [...book_tim ...

Updating a field in Mongoose by referencing an item from another field that is an array

I have developed an innovative Expense Tracker Application, where users can conveniently manage their expenses through a User Collection containing fields such as Name, Amount, Expenses Array, Incomes Array, and more. The application's database is p ...

The functionality of Angular-ui-router becomes compromised when run through gulp for minification

I have a simple angular.js application that adheres to the best practices mentioned here. angular .module('myApp', ['ui.router']); (function() { function configureRoutes($stateProvider, $urlRouterProvider) { $urlRouterPr ...

"Enhancing Error Handling in Express with Node.js Middleware for Parsing

I've been working on developing a middleware to manage errors, but I'm struggling to send the correct format to my frontend. Below, I'll outline my various attempts in the hopes of getting some guidance on this issue. Attempt 1 app.use(fun ...

Guide on invoking setImmediate prior to or above .on('data') in fast-csv using Node.js

I'm currently utilizing fast-csv (https://www.npmjs.com/package/fast-csv) for parsing a csv file. The file could possibly contain 10k records, leading to significant delays in parsing and blocking other operations on the server. To address this issu ...

A step-by-step guide on performing requests sequentially within a useEffect hook

My useEffect function triggers a request when changing dependencies (department and two dates fields). useEffect(() => { getFilteredRestReport({ date_start: formatDatePatchPoint(date[0]), date_end: formatDatePatchPoint(date[1]), de ...

Updating information with AJAX upon clicking a hyperlink

I am trying to implement AJAX for replacing the contents within a div. The setup of the application is quite complex, but I have simplified it to focus on getting the basic concept to work first. Currently, my goal is simply to replace a div based on the ...

Error encountered while rendering content in an Angular template

I'm currently integrating ngx-carousel into my application. Interestingly, the carousel works perfectly when I manually input the data. However, when trying to fetch the data from the server, it fails to work as expected. Take a look at my code snip ...

Seeking assistance with exporting a Vue single file component that relies on Swiper.js for functionality

I'm having trouble figuring out how to properly export a Vue SFC that includes the mySwiper object. I would appreciate seeing an example from someone who has experience with this. Below is the JavaScript portion of my SFC <script> import Swiper ...

three.js: Determining the right time to translate or rotate geometry versus mesh transformations

When working on creating multiple STLs for 3D printing or milling, I also incorporate CSG and utilize raytracing to detect features of the models. My scene remains mostly static, with the need to only rearrange the models by moving them around. However, I ...