Having trouble bringing a 3D object into ThreeJS?

Encountering difficulties while trying to load a 3D object into Three.JS on my website. The 3D images were created in Blender and then exported to .JSON format using MrDoobs exporter addon.

edit: This is the exporter I am utilizing - https://github.com/mrdoob/three.js/tree/master/utils/exporters/blender

var loader = new THREE.JSONLoader();
loader.load('cube.json', function (loadedGeometry) {
var loadedMaterial = new THREE.MeshNormalMaterial({color: 0x55B663});
var loadedMesh = new THREE.Mesh(loadedGeometry, loadedMaterial);
loadedMesh.position.set(-0.8,1,9);
scene.add(loadedMesh);
});

This code works fine for me.

However, when I simply change 'cube.json' to 'tree.json' strange errors occur.

In Google Chrome, I see:

"three.min.js:387 Uncaught TypeError: Cannot read property 'length' of undefined"

In Firefox Firebug, I observe:

TypeError: p is undefined
...;d<D;d++)c.faceVertexUvs[d]=[]}k=0;for(l=p.length;k<l;)d=new THREE.Vector3,d.x=p...
three.min.js (line 387, col 221)

Contents of cube.JSON:

 // JSON data here 

A basic cube from Blender can be viewed at this image: https://i.sstatic.net/4R27J.png

Data for tree.JSON:

 // JSON data here 

An image of the tree in Blender: https://i.sstatic.net/yPlP2.png

Link to tree.blend file - mega.nz/#!U9UTxYYZ!-0X13Ur2E2d96BTbOVhhEBb1AiaV8g6r988XoTTV6XY

Any insights or suggestions would be greatly appreciated!

Answer №1

Have you ensured that you exported the files in the same manner?

The tree.json file does not contain any information regarding vertices, faces, and normals. It is possible that the export process was not done correctly.

When comparing the two JSON files, you will notice that the cube file includes three arrays (normals, faces, vertices) which are essential for building Geometry in three.js. These arrays are missing from the tree.json file.

Update 1: Upon testing the model you shared, I have identified the issue.

The Three.js exporter requires the object to be a Mesh, but Blender recognizes the provided model as a curve.

To successfully export it, follow these steps:

  • Select the object
  • Object -> Convert To -> Mesh from Curve/Meta/Surf/Text
  • Export to 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

How to effectively utilize `MutationObserver` for monitoring the properties of an `HTMLElement` instead of focusing on its attributes

By using the MutationObserver.observe() method, I am able to monitor changes in a specific attribute. For instance, if I have a Div element and the attribute value is modified, then the designated callback function will be executed. However, if the propert ...

Strange symbols keep appearing in my output from PHP

My current task involves generating a SQL query based on some inputs. I have a predefined SQL statement, in which I perform certain replacements, that will use these inputs to generate the required SQL through an ODBC connection. For now, I have stored th ...

Can you help me locate the bug in The Blender's Python script interpreter?

I am encountering an issue with a Python script in Blender. The error message that I receive is not clear to me, and I am seeking assistance in identifying the problem. I have uploaded the script and the hex code of the file to my message. Could it be a bu ...

What is the best way to shift a single vertex in AFrame?

When working with Three.js, I could easily manipulate vertices using this code: myObject.geometry.vertices[i].y += 12; However, in A-Frame, I am not able to see anything in the console.log. It seems that between versions 0.2.0 and 0.3.0, everything switch ...

Merge the elements of one array with the elements of another array simultaneously

Can a function be created that combines each value from two arrays, even if the arrays are of different lengths? For example: arr1 = ["apple", "banana", "cherry"]; arr2 = ["pear", "kiwi", "orange"] mergedArr= ["applepear", "applekiwi", "appleorange", " ...

Creating an array of objects in Node.js can be achieved by simply declaring an array

Here's the structure of my class: var Coin = { _id: null, createGame: function(id) { this._id = id; }, start: function() { } }; My issue is that I am unable to create an array of objects, as I can only create one. Can someo ...

Cleaning up HTML5 video content

I have been on the search for a solution that would allow me to "scrub" through HTML5 video. So far, I have not come across one and was considering developing my own. However, before diving into that process, I wanted to seek advice from the community here ...

Is there a way to alter the color of a single row within a column in a jtable based on a specific condition?

statusOfPayment: { title: 'Status of Payment', width: '8%', options: {'Paid': 'Paid', 'Due': 'Due'}, create: false, ...

Modify text input when a different option is selected (with both options originally coming from a database)

A dropdown menu is filled with options from a database, and the chosen option is compared to a variable $comp_cntry currently on the page: <select name="country"> <option value="--" disabled>Please Select...</option> <option v ...

Struggling to get a basic HTML form to function with JavaScript commands

In my form, there are two input fields and a button. Upon clicking the button, a JavaScript function is triggered which multiplies the values entered in the inputs. The result is then displayed in a <p> element and evaluated through an if else statem ...

How do server side cookies and javascript cookies interact with each other?

Can you explain the connection between the cookies generated by the Cookie Class in Servlet and document.cookie in JavaScript? ...

When utilizing the JavaScript createElement() method to create elements on keydown, it will not be compatible with jQuery's draggable() method

I'm currently developing a drag and drop feature for a project, allowing users to add items to a work area and then position them by dragging. I'm facing an issue where I want to create multiple instances of the same element using a key code, but ...

Anticipated the start of an array but received a string instead at the first line and first column

Encountered an error stating "Expected BEGIN_OBJECT but was STRING at line 1 column 1". Seeking assistance in resolving this issue. I have a ListOffers class that is designed to create objects from parsed JSON data. The code for the ListOffers and Offer c ...

How can URL parameters be connected to context in a React portfolio website?

I have a compact portfolio site created with React that showcases my work as both a graphic designer and an aspiring web developer. Upon arrival, visitors encounter a landing page where they can choose to explore either the "design" or "web" sections, sett ...

Eliminate forward slashes in MySQL queries within a Node.js environment

Here is the code snippet that I am working with. pool.getConnection(function (err, connection) { connection.query("delete from userFiles where type = 1 and typeId = " + taskId + " and fileName ...

Sliding out list elements with jQuery ladder effect

I'm stuck on a seemingly simple task and need some guidance. facepalm. Currently, my site at this link has a menu list item issue where they all come out from the left side after the picture loads. I want them to slide out one by one, starting from t ...

Utilize JavaScript to extract and transform plain text into a JSON object through the filtering process

After receiving the plain text data from an input source, I have the following information: 1 agri dev ban lt shortform1 346 346 343 343 9,671 346 3,330,659 78 -3.00 -0.87 3.00 0.87 361.80 400.07 449.86 472.00 283.00 2 Api Pwr Cpy shortform2 355 355 347 ...

What causes React Router to render the Navigation to the <Home/> component when the userData is still available, but redirects to "/login" otherwise?

I'm currently developing a Note-taking application using React with React Router for navigation. For creating routes, I am utilizing createBrowserRouter(). Below is the code snippet: import './App.css'; import NoteList from "./componen ...

Retrieve mongodb objects that fall within a specified date range

Within my collection, there is an example document structured as follows: { "_id" : ObjectId("5bbb299f06229dddbaab553b"), "phone" : "+38 (031) 231-23-21", "date_call" : "2018-10-08", "adress_delivery" : "1", "quantity_concrete" : "1", ...

Is there anyone available who can assist me in removing records from my Sequelize database?

I attempted to implement the code snippet below after coming across it on a popular platform, but for some reason, it doesn't seem to be functioning as expected. Posts.delete({ where: { createdAt: { isAfter: "2016-09-11" } } }) My goal is to remove ...