Unable to load JSON data model

I have been working on loading a JSON model and displaying it on the canvas, but I am encountering an issue where nothing is being drawn on the screen. Even when I try to use an alert inside the loader.load callback, the alert never shows up because the callback is not being called. I am starting to suspect that there might be something wrong with the JSON file itself, which I downloaded from this source:

Here is the code snippet I am using:

<head>
        <title> Teapot </title>
        <style> 
            canvas {width:100%; height:100%; background-color: black} 
            body {background-color: white};
        </style>
    </head>
    <body>
        <h1 align="center"> Teapot </h1>
        <script src="/Users/ramy/Documents/HTML/mrdoob-three.js-58e4622/build/three.min.js"></script>
        <script type="text/javascript">
            // Scene initialization
            var scene= new THREE.Scene();
            var camera= new THREE.PerspectiveCamera(75,window.innerWidth/window.innerHeight,0.1,1000);
            var renderer= new THREE.WebGLRenderer();
            renderer.setSize(window.innerWidth,window.innerHeight);
            document.body.appendChild(renderer.domElement);
            camera.position.z= 50;

            // Teapot creation
            var teapot;
            var loader= new THREE.JSONLoader();
            loader.load("/Users/ramy/Documents/HTML/teapot.json", 
                function(geometry) {
                    var material= new THREE.MeshBasicMaterial({color:0x00ff00});
                    teapot= new THREE.Mesh(geometry,material);
                    scene.add(teapot);
                    render();
                });

            // Rendering
            var render= function() {
                requestAnimationFrame(render);
                renderer.render(scene,camera);
            }
        </script>
    </body>
</html>

Answer №1

It seems like the model format you're working with differs from what is exported from Blender using the Three.js plugin or the Python script converter. One key indicator is that Three.js has a JSON format with a metadata block:

"metadata" :
{
    "formatVersion" : 3.1,
    "generatedBy"   : "Blender 2.65 Exporter",
    "vertices"      : 25253,
    "faces"         : 49658,
    "normals"       : 25252,
    "colors"        : 0,
    "uvs"           : [25399],
    "materials"     : 8,
    "morphTargets"  : 0,
    "bones"         : 0
},

Additionally, your file contains:

"vertexPositions"
"vertexNormals"
"vertexTextureCoords"
"indices"

Instead of:

"vertices"
"normals" 
"uvs"
"faces" 

My suspicion is that the file was created in a generic Model to JSON format, not the specific Three.js JSON format. Can you confirm which exporter was used?

Edit: Just to clarify, the JSON format being used is not compatible with the Three.js JSONLoader. You'll either need to locate the original file and convert it using the recommended methods, or manually adjust the JSON file to adhere to the Three.js JSON format.

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's useEffect function with an empty dependency array to trigger a change in the

In the React application I'm currently working on, the useEffect function is triggered whenever the prop value changes from an empty array to another empty array. I am fetching query parameters from the page and passing them down to a component that ...

Unraveling the mysteries of an undefined entity

When the variable response is undefined, attempting to retrieve its property status will result in an error: Error: Unable to access property 'status' of undefined const { response, response: { status }, request, config, } = error as A ...

Attempting to update an AJAX field with the returned value, but it only updates after clicking away from it

Image of form utilizing AJAX & JS The current setup involves a maintainer that uses AJAX to update the "Calc" field in response to a number entered in the "Order No" field. The issue is that the "Calc" field does not update immediately after typing in the ...

Parsing improperly formatted JSON from an HTTP GET request can be done using either AngularJS or JQuery

Trying to decipher a poorly formatted JSON response from a remote server that looks something like this: //[ {},{} ] In my AngularJS code: $http.get('http://www.example.com/badjson') .success(function(data) { console.log(data); }) ...

Employ a pivot table to visually display an array of object data

I am attempting to utilize a pivot table to organize the data provided below: $.pivotUtilities.tipsData=[ {status:"open",year:2014,value:100.00}, {status:"open",year:2015,value:200.00}, {status:"open",year:2016,va ...

Encountering an issue where attempting to map through a property generated by the getStaticProps function results in a "cannot read properties

Greetings, I am fairly new to the world of Next.js and React, so kindly bear with me as I share my query. I have written some code within the getStaticProps function in Next.js to fetch data from an API and return it. The data seems to be processed correct ...

Issue: ASSERTION ERROR: token must be declared [Expecting => null is not undefined <=Actual]

I encountered an error while working on my project. The only special thing I did was use oidc(openId) for authentication. I made some changes to the bootstrap project and now the first component that is running is the home-main component, which includes t ...

Utilizing Chart.js to extract and display specific data values from an external JSON file

I am currently engaged in a journey of self-exploration where I aim to create a chart depicting the number of anime shows with comedy or fantasy genres. The data for my chart will be sourced from an external JSON file (anime.json) on my computer. Initially ...

Incorporate a background image property using Jquery

Can anyone help me with adding the css background-image:url("xxxxx") property to my code? jQuery('#'+$trackID+' .sc_thumb').attr('src',$thumb_url); jQuery('#'+$trackID+' .sc_container').css('display& ...

Limit DerbyJS to re-rendering specific DOM elements

Currently, DerbyJS (visit http://derbyjs.com) functions by replacing everything in the body tag of the document each time a link is clicked. Is there a way to utilize the template, but replace only the content inside #main-content instead of refreshing th ...

Tips for transferring <form> information to an object array within a React application

I am currently working on a basic component that takes an input message, displays it in a list below the input field when submitted. However, I am facing an issue where clicking the submit button only results in a blank bullet point appearing below. impo ...

Alternative to dynamic arrays in Javascript

I successfully implemented a masonry grid using Flexbox. Initially, the items were ordered vertically, so I developed a function to rearrange them horizontally: Original Order: 1 4 7 2 5 8 3 6 9 New Order (with my sorting function): 1 2 3 4 5 6 7 8 9 ...

What is the reason behind the necessity of using setTimeout with a delay of at least 50ms for JS .focus()

Problem While creating a page for a client at work, I encountered an issue with a slide-out search bar. When clicking the button to open the search input field (which starts off hidden), I want the focus to shift to that input field. Oddly, I found that ...

Is there a way to assign a class to particular HTML elements only if they include a specific value?

Consider the following HTML snippet: <div id="stuff"> <span>1</span><span>2</span><span>3</span> </div> I want to select specific elements like this: $('#stuff').find('<span>1</span ...

Is there a way to navigate to a specific <li> element using scrolling?

Is there a way to direct a user to a URL and have it automatically scroll to a specific <li> element? For example, navigating to mysite.com/something.html#someItem should take the user directly to: Something here ...

What is the best way in React to handle large operations, such as filtering and mapping a 10000-row array, asynchronously in order to prevent the UI from being blocked?

Currently, my table contains a large amount of data. Whenever I apply a filter, the data needs to be filtered and remapped, causing a delay of approximately 1-2 seconds. However, during this processing time, the UI becomes unresponsive. Is there a method ...

Conceal the parent div from its sibling within the same parent container

My goal is to conceal a parent component from its child element. I attempted to achieve this by using the parent component as a background while adding additional backgrounds to the child elements for overriding purposes. However, this method did not work ...

Tips for sending JSON-formatted data from a route to jQuery

Currently, I am facing a challenge with passing a JSON file retrieved from an API to jQuery. The goal is to implement an infinite scroll functionality using jQuery before displaying it in an EJS file. The issue arises when `res.json(data)` is utilized; ins ...

What is preventing the image from showing up as a texture in this web GL?

There seems to be an issue with displaying the image and I'm unable to identify the cause. The image can be found at: https://i.sstatic.net/O7Z3U.jpg. Do I need to specify a particular property for the texture or define it differently? Or could it s ...

Tips for refreshing a nested state in React

Currently, I am facing an issue with updating a nested value in a React state. My goal is to update data that is deeply nested, specifically 3 levels deep. Let me provide you with the state structure that contains the data: const [companies, setCompanies ...