Having trouble with syntax when using THREE.TextureLoader?

Attempting to implement a panoramic viewer code using three.js version r68. To utilize the raycaster function, upgraded the three.js version to r121. However, encountered an issue while modifying the code:

var texture = THREE.ImageUtils.loadTexture('img/pano2.jpg', new THREE.UVMapping(), function() { 
init();
animate();                                                                                                        
});

Changed it to:

var loader = new THREE.TextureLoader();
loader.load(
    'img/demo.jpg',
    function(texture){
        var material = new THREE.MeshBasicMaterial({map: texture});
},
    function(){
        init();
        animate();
},
    function ( err ) {
        console.error( 'An error occurred.' );
    }
);

No errors were displayed, but the render and animate functions (included in the init function) did not proceed as expected. Unclear whether the issue lies with the texture or the init function. Appreciate any suggestions.

References consulted:

  1. Three.JS TextureLoader Documentation

  2. Troubleshooting Three.TextureLoader

Full code snippet below:

<!DOCTYPE html>
<html>
    <head>
        <title>Panorama1</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
       ...
       [Truncated for brevity]
    </body>
</html>

Original code:

<!DOCTYPE html>
<html>
   ...
   [Omitted for conciseness]
</html>

Source Code Link: ThreeJS 360 Panorama on GitHub

Thank you for your attention!

Update: Following @prisoner849's suggestion, the init and animate functions now execute correctly. However, the scene remains black on both Chrome and Firefox. https://i.sstatic.net/ZImPc.png

Answer №1

Give this method a try:

let material; // defined as a global variable

...

loader.load(
    'img/demo.jpg',
    function(texture){
        material = new THREE.MeshBasicMaterial({map: texture});
        init();
        animate();
    },
    undefined,
    function ( err ) {
        console.error( 'Oops! An error occurred.' );
    }
);

In your current setup, you are invoking init() and animate() within the onProgress callback. However, they should be called inside onLoad, immediately after

material = new THREE.MeshBasicMaterial({map: texture});
.

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 execute 2 statements concurrently in Angular 7?

My goal is to add a key rating inside the listing object. However, I am facing an issue where the rating key is not displaying on the console. I suspect that it might be due to the asynchronous nature of the call. Can someone help me identify what mistak ...

Displaying buttons within a component's onPress function will reveal the most recent information. Utilizing React-N

Currently, I am working on loading a component that contains an array from redux (for example, test). I have successfully created buttons with the correct titles, however, there seems to be an issue with the onPress function not displaying the expected v ...

Every character entered in JSP should trigger an instant retrieval of the corresponding string in the servlet

Having a JSP file that contains a text field: <form action="someServlet" method=post> <input type ="text" name="user" id="uname"> <button type="submit" id="submit">Submit</button> </form> When typing each letter in the JSP, ...

dont forget to preserve the checkbox and radio button selections when the page is refreshed

I have developed a filter using jQuery and Laravel (PHP) to filter data based on checkbox or radio button selections. However, after refreshing the page, the checked state of the checkboxes or radio buttons is lost. I need the checked state to persist even ...

Tips for utilizing a shared controller in an Angular Material popup dialogue

Within my project, Angular Material is being used for various dialogs, primarily for alert purposes. However, I now find myself in need of a more complex dialog. The example provided on the Angular Material site showcases how to create a dialog: function ...

How can I access my API by connecting Node.js to MongoDB remotely?

I have been working on developing an application using Node.js, Express, and MongoDB. I followed some teamtreehouse tutorials to set up Node.js and MongoDB on a Digital Ocean Server. However, when trying to access my API through various URL variations, I e ...

Currently, I am working on developing a Discord bot using discord.js within Visual Studio Code. So far, all of the commands that I have implemented are functioning properly except for one. This specific command is a

Currently, I am immersed in the development of a comprehensive AIO Discord Bot similar to popular ones like "Dyno Bot" or "Carl Bot." The initial phase involved creating basic commands such as ping, avatar, and so on. Now, I have ventured into crafting a ...

Learn the steps for inserting or updating data in a local JSON file solely through JavaScript

Currently, I am in the process of reading a JSON file and removing an element once it finds an exact match. My goal is to then push the remaining data back into the JSON file after deletion. readJsonFile("./objects.json", function(jsonData){ let parsedD ...

Is there a way to trigger the animation of this text effect only when the mouse is scrolled to that specific section?

Here is a cool typing text effect created using HTML, CSS, and JavaScript. Check out the code below: (function($) { var s, spanizeLetters = { settings: { letters: $('.js-spanize'), }, init: function() { ...

Retrieve the JSON data based on a specific key after a specified period

Hello there, I am encountering an issue with a specific JSON key. Let's say I have an external file containing JSON data structured like this: { "key 1":[ { "linkName":"key name 1.1", "linkUrl":"key URL 1.1" }, ...

Why is it that Vue3 Toastify struggles to identify the toast object that they clearly mention we should be using?

Currently, I have integrated a vue3 package known as vue3.toastify for managing my toast notifications. The guidelines provided in the documentation clearly mention that to modify default transitions globally, the following code snippet must be implemente ...

While utilizing Ajax with Spring, it is possible to send a JavaScript object and receive it as a custom object. However, there was an issue with

One of my challenges in Java is working with a custom class that looks like this: public class AddressesVO { private Long addressId; private String address; public Long getAddressId() { return addressId; } public void setAddressId(Long addressId ...

Is it possible to combine the outcomes of a SQL query that produces numerous entities with identical identifiers?

Currently working on my first Node.js API project. Within the '/posts' endpoint, I am receiving data in this format: [ { "POST_ID": 1, "POST_TITLE": "Post N.1", "POST_DESCRIPTION" ...

Modify every audio mixer for Windows

Currently working on developing software for Windows using typescript. Looking to modify the audio being played on Windows by utilizing the mixer for individual applications similar to the built-in Windows audio mixer. Came across a plugin called win-audi ...

What is the process for implementing a title search filter in Vue.js?

Hey there, hoping you're having a good night! I've been trying to set up a bookstore using Vue.js with code retrieved from a Json api. However, I'm encountering some issues with the "computed" property. Here's the code snippet: new Vue ...

Use jQuery to change the background color when clicked

Below is the HTML code with UL and LI elements: <UL> <LI><span id='select1'>Text</span></LI> <LI><span id='select2'>Text</span></LI> <LI><span id='select3'>Tex ...

Is there a proven method to instantly update local state in React/Redux without needing to wait for a response from an API call?

Summary: Are there any well-known solutions using React/Redux to achieve a fast and responsive UI, while seamlessly updating an API/database even in cases of failed requests? I want to develop an application featuring a "card view" functionality using htt ...

Top technique for verifying the presence of duplicates within an array of objects

How can I efficiently check for duplicates in typescript within a large array of objects and return true or false based on the results? let testArray: { id: number, name: string }[] = [ { "id": 0, "name": "name1" }, ...

Using jQuery to alter an href link's attribute

I am currently attempting to modify the content of a href using jQuery. After researching various solutions on this platform, I came across one that I am trying to use for implementation: How to change the href for a hyperlink using jQuery My current app ...

Troubleshooting a problem with dynamic options in Materialize select set

I'm currently facing an issue with my two dependent dropdowns, country and state. When I select a country, I use JavaScript to populate the respective states in the state dropdown. However, even though the options are added correctly when I inspect th ...