Using Three.js for 3D modeling in web development, the JSONLoader coupled

While dealing with heavy models, I am experimenting with displaying the loading percentage dynamically when loading JSON data. I conducted a basic test using the loadAjaxJSON method...

The loading process shows the percentage completion, but it never reaches the callback function.

I'm unsure if this issue is caused by a missing declaration, incorrect context parameters, or something else entirely. Unfortunately, I couldn't find any relevant documentation on this matter.

var loader = new THREE.JSONLoader( true );
loader.loadAjaxJSON(
            document,           // < context ??
            'try.js',
            function ( geometry, materials ) { CreateScene( geometry, materials ); },
            false,              // < texturePath
            function( progress, result ) { console.log((progress.loaded / progress.total * 100).toFixed());}
            )

Console :

7 13 20 .. 100
TypeError: a.parse is not a function [three.min.js (ligne 204)]

Answer №1

Instead of always relying on documentation, it can sometimes be quicker to check the actual sources directly. If you need to see the code for JSONLoader, you can find it here: https://github.com/mrdoob/three.js/blob/master/src/loaders/JSONLoader.js. Within this context, there are two key methods that should be included: parse and onLoadComplete. You simply need to pass the loader as the context and take a shortcut by looking at the loadAjaxJSON method for loading. Regarding texturePath, within the load method you'll find how it should be structured:

texturePath = texturePath && (typeof texturePath === "string") ? texturePath : this.extractUrlBase(url);

If you delve deeper, you'll notice that extractUrlBase will return './'. Therefore, in your case, your code should resemble this:

var loader = new THREE.JSONLoader(true);
loader.loadAjaxJSON(
        loader,           // context 
        'try.js',
        function(geometry, materials) { CreateScene(geometry, materials); },
        './', // texturePath or loader.extractUrlBase('try.js'), 
        function(progress, result) { console.log((progress.loaded / progress.total * 100).toFixed());}
        )

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

Using React Hooks to dynamically adjust onClick behavior based on history.location.path

I have a button that executes a function, but I want it to execute one of two functions based on the current URL (one button - two actions depending on location). Here is the current functionality of the button: const showApplyButton = () => { ret ...

What could be the reason for the error message when using rs.send with a string input?

I'm a beginner in node and express, and I was trying to create an HTML form that takes two numbers and displays the result using "express" and "node". However, when I use rs.send(result), I encounter the following error: https://i.sstatic.net/FcUNJ.p ...

Challenges encountered when attempting to access files from the filesystem on vercel

Currently, I am working on a website that includes a "blog" section with markdown files. The setup reads the files seamlessly from the file system without any errors... except when deployed on Vercel. In that case, it throws a "No such file or directory" e ...

What is the process for extracting image data from a fancybox gallery image when it is clicked?

I successfully implemented a gallery using fancybox. The gallery includes dynamically generated titles, and I am currently working on retrieving the URL of a clicked image and accessing a hidden input value containing the post's URL. Below is the co ...

Is there an Angular directive that can replicate a mouseenter event?

Is there a way to simulate a mouseenter event with a directive? I have been searching for a directive that can simulate a mouseenter event, but all I have found so far is one that binds a function to mouse over or karma tests for simulating mouse over. W ...

Issue with Vue-ChartJS where adding datasets does not refresh the chart display

I am currently utilizing Vue-ChartJS to showcase a chart on my website. However, I have encountered an issue when trying to update the datasets using the Push Function - the chart does not update as expected (even though it should according to the document ...

What steps can I take to ensure that a callback is added only once?

Here is a section of code that I am working with: .factory('Auth', function($firebaseAuth) { var ref = new Firebase('https://myfirebase.firebaseio.com'); return $firebaseAuth(ref); }) and an accompanying controller: .controller("Logi ...

Issue with post-processing filters in Three.JS r71: Transparent renderer is not functioning as expected

I am attempting to implement a BloomPass on my current scene and want the background of the containing page to show through. However, when I apply the BloomPass, the background turns black. You can see my example here:http://plnkr.co/edit/0mp0jaGVF6it52HY ...

What is the best way to identify and retrieve the objects that do not match when comparing two arrays of objects

obj1 represents the original object while obj2 symbolizes the modified object. The goal is to extract the key-value pairs and types for all changed objects within the obje2 array of objects. Therefore, I am looking for a solution where if the values for " ...

Can Vuex mapActions be utilized within a module that is exported?

Is it possible to utilize Vuex mapActions from an external module imported into a component? I am working on standardizing a set of functions in a vue.js web application. My goal is to import these functions into each component and pass necessary values f ...

Creating a double-layered donut chart with Chart.js

I'm attempting to create a unique pie chart that illustrates an array of countries on the first level and their respective cities on the second level. After modifying the data in a JSON file to align with my goal, it doesn't seem to be working a ...

Tips for adding style to a group of SVG elements:

I currently have an array of .svg icons, each with unique properties that I need to customize: <svg width="24" height="24" viewBox="0 0 24 24"> ... </svg> import styled from 'styled-components'; import Github from 'assets/git ...

Restrict the number of requests made to the Facebook graph_url_engagement_count API

Encountering the following error message: "(#613) Calls to graph_url_engagement_count have exceeded the rate of 10 calls per 3600 seconds." I am looking for a way to ensure that my API calls for a specific link stay within the limit. Please note that the ...

Encountering an error with TypeScript in combination with Angular 2 and Grunt. The error message is TS

Currently in my angular2 Project, I am utilizing grunt for automating the compilation of my typescript files. Everything seems to be working fine as my files are compiling, but I keep encountering errors: app/webapp/ng2/audit_logs/auditLogs.ts(2,3): erro ...

What is the process for displaying the editor logo icon as a preview in files when the "default open program" is set to Atom?

For instance: When I designate Visual Studio as the default program for opening 'hello.js' files, Windows displays a preview icon like this: https://i.sstatic.net/qIbv0.png However, when I change the default program to Windows Notepad, I see: ...

"Upon clicking, toggle the addition or removal of the overflow hidden

I'm currently working on a function to add and remove the CSS property .css('overflow-y','hidden') using an onclick event, which I have successfully implemented. However, I am encountering an issue when attempting to remove this CS ...

How do I choose the specific financial date of April 1st in the datepicker selection?

I am trying to set the minimum date as 1st April 2018 and the maximum date as the current date. These are the methods I have already attempted: $("#primarySaleDatePicker").pickadate({ min: new Date(2018, 3, 1), max: 'today', ...

Using either Javascript or JQuery to update every cell in a particular column of a table

I need to use a button to add "OK" in the Status column of table tblItem, which is initially empty. How can I achieve this using JavaScript or JQuery? The table has an id of tblItem Id Item Price Status 1 A 15 2 B 20 3 C ...

AngularJS: Transitioning from Expressions to Javascript (Coffeescript)

Looking to convert an expression into JavaScript in order to maintain an object's value in $scope: <dl class = "mortgage-information"> <dt><abbr title = "Loan-to-value Ratio">LTV</abbr></dt> <dd>{{(total_fi ...

Enhancing your scene with new objects using three.js

Exploring the possibilities with three.js, I am working with two shapes: "squares" and a "sphere". Each shape has an associated button. When the user clicks a button, the corresponding shape is added to the scene. However, there can only be one square and ...