The model is failing to load in the three.js environment

After spending the entire day experimenting with different solutions, I am still unable to solve my problem. Despite trying various examples from previous years, my objects are not appearing as expected.

I have experimented with three different formats: .json, .js, and now .mtl with .obj. The current code I am working with is shown below:

function addModels() {
var mtlLoader = new THREE.MTLLoader();

mtlLoader.load("../models/lampa.mtl", function (materials) {
    materials.preload();

    var objLoader = new THREE.OBJLoader();

    objLoader.setMaterials(materials);
    objLoader.load("../models/lampa.obj", function (mesh) {
        mesh.scale.set(1,1,1);
        mesh.position.set(0,0,0);

        scene.add(mesh);
    })
})

Additionally, here is the HTML file containing the script that runs on canvas:

   var camera;
var scene;
var renderer = new THREE.WebGLRenderer();
var controls;

//Simple functions to initialise scene and render it.
initialise();
render();
//animate();


//add models
addModels();

function initialise() {

    // Create a scene
    scene = new THREE.Scene();

    // Add the camera
    camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000);
    camera.position.set(0, 100, 250);

    // Add scene elements
    addWalls();
    addKerbs();
    // Add lights
    addLights();
    // Create the WebGL Renderer
    renderer = new THREE.WebGLRenderer();
    renderer.setSize( window.innerWidth, window.innerHeight );

    //add Grass
    createGrass();
    addGrass();

    // Append the renderer to the body
    document.body.appendChild( renderer.domElement );

    // Add a resize event listener
    window.addEventListener( 'resize', Resize, false );

    // Add the orbit controls
    controls = new THREE.OrbitControls(camera, renderer.domElement);
    controls.target = new THREE.Vector3(0, 100, 0);
}

//rendering function
function render() {
    renderer.render( scene, camera );
    requestAnimationFrame( render );
    controls.update();
}

//Window resize.
function Resize() {
    camera.aspect = window.innerWidth / window.innerHeight;
    camera.updateProjectionMatrix();
    renderer.setSize( window.innerWidth, window.innerHeight );
}

function animate() {
    requestAnimationFrame(animate);
    render();
    status.update();
    renderer.render(scene,camera);
}

Placing addModels() within the initialize function results in an error like this: https://i.sstatic.net/C1xnJ.png

I would greatly appreciate any insights or assistance. Thank you.

Answer №1

I deeply apologize for any inconvenience caused. It seems that all is well now, just needed to update three.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 correct way to integrate a HTML/CSS/JS theme into a Vue project effectively?

As a newcomer, I recently acquired a bootstrap theme that comes with HTML, CSS, and JavaScript files. My goal now is to integrate this theme into Vue in order to make it fully functional. The challenge I am facing is how to successfully incorporate the the ...

Trouble with the Ngx-Captcha feature

I am currently utilizing https://www.npmjs.com/package/ngx-captcha/v/11.0.0. <ngx-recaptcha2 #captchaElem [siteKey]="'6Leh1ZIjAAAAAG8g0BuncTRT-VMjh3Y7HblZ9XSZ'" (success)="handleSuccess($event)" [useGlobalDomain]="fals ...

Showing the precise age in years by utilizing the provided 'Date of Birth' selected from the datePicker

Is it possible to retrieve the date entered in the datePicker and use it to populate the current age field in a PHP file using either PHP or Javascript? if ($key == 'currentage') { $group[] = $this->form->createEleme ...

Creating a new object with the help of the reduce function in JavaScript

Hey there, I'm facing a challenge with creating a new object based on the response from the backend. This is the response that was returned to me: acl:[ { "user_type":5, "user_id":"c7e5cb45ba764ad7ad29b5bdd4f12128", "user_n ...

Can you choose text in jQuery context by referencing a sibling element context?

In this example, the code appears as follows: <ul> <li><strong>This is a list header.</strong> And I want this text to vanish because it's not a list header!</li> </ul> The corresponding JavaScript code is: $( ...

Accessing elements from an array and performing addition on those that are numerical

I am trying to figure out how to extract the values from an array created by some code and then combine them into a single variable: var selector = 'input[name^="Textbook"]'; $(selector).on('click', function() { ...

React-select-pagination is failing to retrieve data while scrolling

Struggling to load over 20,000 options using react-select from a Node API database? The page was barely loading until I implemented "react-select-async-pagination". However, there's a problem - the data is only fetched once. import React, { useRef, us ...

Submitting AJAX form to a PHP script instead of a traditional submission

I'm facing an issue with using AJAX to post a basic insert query to the database. The problem arises from generating multiple PHP forms in a while loop, all sharing the same class for HTML forms. I tried using the live function in AJAX but it hasn&apo ...

Best method to determine if three points in time are less than thirty minutes apart

In the form, there are 3 date/time input boxes with a requirement that the user cannot select times within half an hour of each other. I successfully converted all values to epoch format using a Javascript version of strtotime. However, I am unsure how to ...

The result from noty.js is coming back as undefined

Recently, I started using noty.js but I encountered an issue while trying to execute the basic example for creating a noty. The error message I kept receiving was: Uncaught TypeError: Property 'noty' of object function (a,b){return new e.fn.init ...

There seems to be an issue with AJAX file uploading functionality in Django

I'm facing an issue with uploading files using the onchange event and AJAX. I am only able to get the file path on the backend, not the actual file itself. My goal is to modify the code so that when a PDF file is selected, it automatically gets upload ...

Contrasting React useRef with global variable usage in this scenario

Scenario 1: Utilizing let variable outside of function component https://codepen.io/evan-jin/pen/VwWOPJV?editors=0010 Scenario 2: Implementing React.useRef in Parent function component https://codepen.io/evan-jin/pen/VwWOpvg?editors=0010 Scenario 1 let ...

Prevent scrolling using mousewheel click (auxclick event)

Currently working with Angular 9 and encountering an issue with the (auxClick) event triggering on a mousewheel click. The problem arises when attempting to use this event while there is a scroll present on the page, as it does not trigger correctly due to ...

Is there a way for me to trigger the event multiple times?

First of all, thank you for your input - this is my initial attempt at solving this issue. Currently, I am facing a problem where the buttons only work once. Ideally, I want them to be functional every time because users will frequently change search terms ...

What is the best way to save high-resolution images created with HTML5 canvas?

Currently, there is a JavaScript script being used to load and manipulate images using the fabricjs library. The canvas dimensions are set to 600x350 pixels. When smaller images are uploaded onto the canvas and saved as a file on disk, everything works c ...

Struggling to get getInitialProps working in dynamic routes with Next.js?

I am encountering an issue. The return value from the getInitialProps function is not being passed to the parent component. However, when I console.log the values inside the getInitialProps function, they appear to be correct. Here is the code snippet: i ...

Exploring AngularJS - Understanding how dependency injection works in services, factories, filters, and beyond

Currently, I am using plugins and libraries in my Angular app by directly referencing their functions/methods without considering dependency injection. This approach is common in most apps, but I want to optimize the use of these resources. One such libra ...

Leveraging ReactJS properties within a mesh component

Encountered an unusual ReactJS element syntax {..props} within a mesh element. Why is {...props} inside "mesh"? Normally, if there are properties present then they can be defined, but in this case it's using {..props}. How does this syntax work and wh ...

Restricting the user to input only once, using MeteorJs framework

I have been developing an application that allows users to book courses, and I am looking to restrict them to booking each course only once. Below is the current code snippet that I have written for this functionality, and any assistance from you all would ...

Retrieve specific JSON elements and showcase on an HTML webpage

I created a simple webpage where users can input the name of an actor and I want to show all the movies that actor has been in. Currently, I have hardcoded the API URL for Bradley Cooper. How can I retrieve all movie titles, release years, overviews, and ...