Using Three.js to load blender JSON files

Hey there! I'm currently facing some challenges when it comes to importing models from Blender into three.js.

Currently, I am using the latest version of three.js (R71). I have successfully installed the three.js exporter in Blender and it works fine.

Below is the HTML code snippet:

<body>
    <font size="+6"><b>TFG</b></font><br>
    <a href="../index.html">Go back</a>
    <hr>
    <div id='container'></div>      
    <script src="libs/ThreeJSV71/build/three.min.js"></script>
    <script src="libs/OrbitControls.js"></script>
    <script src="libs/Coordinates.js"></script>
    <script src="libs/dat.gui.min.js"></script>
    <script src="libs/stats.min.js"></script>   
    <script src="libs/ColladaLoader.js"></script>   

    <script src="threejs/tfg2.js"></script>
    <br>
</body>

The following file is tfg2.js where the model is loaded:

var width = window.innerWidth,
    height = window.innerHeight,
    clock = new THREE.Clock(),
    scene,
    camera,
    renderer,
    ambientLight,
    directionalLight,
    loader,
    modelo = new THREE.Object3D();

init();
function init()
{
    scene =new THREE.Scene();

    camera = new THREE.PerspectiveCamera(40, width/height, 1000);
    camera.position.set(0,1,5);

    renderer = new THREE.WebGLRenderer({antialias: true});
    renderer.setSize(width,height); 
    renderer.setClearColor(new THREE.Color(0x0000AA));
    document.getElementById('container').appendChild(renderer.domElement);

    ambientLight = new THREE.AmbientLight(0xffffff);
    scene.add(ambientLight);

    directionalLight = new THREE.DirectionalLight(0xffffff);
    directionalLight.position.set(0,1,0);
    scene.add(directionalLight);

    scene.add(new THREE.GridHelper(10,1));
    loader = new THREE.JSONLoader();
    loader.load('blender/json/camara.json', function(geometry,materials)
    {
        modelo = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial(materials));
        scene.add(modelo);
    });
}

When attempting to view the results, nothing appears on the webpage and the JavaScript console doesn't display any errors. However, if I export the model in Collada format or another .js format that I have, the model is visible. But I specifically need to use JSON.

What could be going wrong?EDIT:

Added: modelo.position.set(0,0,0) inside the callback to ensure the model is at the origin point.

Answer №1

Without encountering any errors, here are some steps you can take:

  1. When exporting the object from Blender, ensure that the object is translated to the origin. Navigate to origin>> select origin to geometry>> translate the object to x, y, z coordinates of zero. This will position your camera at 0,1,5 xyz respectively, which may be where your object's camera is not aligned.

  2. Alternatively, try translating the child of the scene to the origin.

This approach might resolve the issue you're experiencing. It appears there are no error messages or warnings in the log file.

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

Passport.authenticate() fails to redirect users to the desired destination

I am encountering an issue with the passport middleware while trying to authenticate a user. The redirection doesn't seem to be working and I'm unsure what the problem is. Here is the code snippet from the project, and the complete project is av ...

What is the process for iterating through an object array using Gson for deserialization?

[{bulkNo=91200256, cardType=CDMA_PP, denomination=300, endSerial=6048233, epfId=2254, nextSerialValue=6048226, startSerial=6048225}, {bulkNo=12050021, cardType=CDMA_PP, denomination=200, endSerial=6057151, epfId=2254, nextSerialValue=6057131, startSerial=6 ...

Is it possible to update the URL dynamically in a Next.js application without relying on the <Link> component?

I'm looking for a way to dynamically change the URL on a page without using <Link>. Specifically, I want to switch to a different URL when a variable changes from false to true, regardless of user interaction. Currently, I'm achieving this ...

Manage and update events in the Angular Bootstrap Calendar

For the past few days, I have been working on integrating a calendar into my project. I decided to repurpose an example provided by the developer. One issue that I've come across is related to the functionality of deleting events when using the dropdo ...

Steps for running example of JavaScript colormap:

After discovering a JavaScript example on this GitHub repository, I decided to give it a try by following the steps outlined in this helpful answer, while using Windows 7. Here's what I did: First, I installed node. Next, I installed browserify. The ...

Verify the occurrence of a search result and if it appears more than once, only show it once using JavaScript

Hello all. Currently, I am developing an online users script using NodeJS and SocketIO. The functionality works fine, however, I am encountering an issue where if a user connects from multiple browsers, windows, or devices, it displays duplicate results li ...

Navigating Angular's Credit Card Input Functionality

I am looking to limit the input capacity to 16 numbers and add a space between each set of 4 numbers. After conducting an extensive search for a credit card input that allows users to enter 16 digits with a " - " or space in between, all results were for ...

What steps should I follow to incorporate channel logic into my WebSocket application, including setting up event bindings?

I'm currently tackling a major obstacle: my very own WebSocket server. The authentication and basic functionality are up and running smoothly, but I'm facing some challenges with the actual logic implementation. To address this, I've create ...

Utilize jQuery to set a cookie, then apply the bodyclass retrieved from the cookie upon page

I have a button that changes the body class to .blackout For this, I am utilizing js-cookie library to manage cookies. The code snippet associated with my button is shown below: <script> $('#boToggle').on('click', function(e) { ...

Looking to utilize Axios in React to make API calls based on different categories upon clicking - how can I achieve this?

My current issue involves making an API call upon clicking, but all I see in my console is null. My goal is to have different API categories called depending on which item is clicked. const [category, setCategory] = useState(""); useEffect(() => { ...

Can one sever the connection using the bittorrent protocol?

At this time, A and B are in the process of transferring files directly. My goal is to execute code that severs the connection between the torrent and B. I attempted to disconnect the ongoing connection with codes provided here which included the followi ...

The latest iteration of three.js appears to disrupt how light is reflected on meshes

After upgrading from three.js version r110 to r124 for the new features, I noticed a significant change in the way my meshes reflect light. Suddenly, everything looks different and it's quite disappointing! ...

Received an error while parsing JSON in the VBA post method request body using "MSXML2.XMLHTTP": Unexpected character '^' encountered. Expected to see '{' or '[' instead

I am facing a challenge in retrieving a JSON response object using the query API below. In VBA, when attempting to read the responseText, I encounter an empty result. Interestingly, the same request returns correct data in PostMan. Moreover, sending differ ...

Loop through each div using jQuery and dynamically add or remove a class to

I am looking to create an infinite loop that adds a class to each div with a timeout in between. Currently, I have implemented it like this: $(document).ready(function() { $('.small-bordered-box').each(function(i) { var $t = $(this); ...

The emission from Socket.io is originating from the recipient's browser without being transmitted to the sender's browser

Hey there, I'm fairly new to socket.io and not completely sure if what I'm doing is the standard way, but everything seems to be working fine so I guess it's okay. I've been working on a chat application where messages are stored in a d ...

Enhancing many-to-many relationships with additional fields in Objection.js

I have a question that I haven't been able to find a clear answer to in the objection.js documentation. In my scenario, I have two Models: export class Language extends BaseId { name: string; static tableName = 'Languages'; st ...

Combining Arrays with Identical IDs into a Single Object

When two objects in the data array share the same id, only the first one will be chosen and the rest will be discarded. It is important that multiple assets with the same id are grouped together in one object. const myMap = cardDetails.map((card) => { ...

Engage with a specific element within the Document Object Model even in the absence of a 'ref' attribute

Is there a better way to set focus on a button within a React component without using ref? The button is part of a third-party library and not immediately available upon componentDidMount. Currently, I am using setTimeout and querySelector which feels like ...

The Bootstrap tabs are not correctly displaying the content

Hey there, I'm currently working on a project that involves using bootstrap tabs (BS4) within a form. One of the requirements is to have forward and back buttons for form navigation, and I'd like to leverage BS4's tab('show') fun ...

Using command line arguments to pass parameters to package.json

"scripts": { "start": "gulp", ... }, I have a specific npm package that I'm using which requires passing parameters to the start command. Can anyone help me with how to pass these parameters in the command line? For example, is it possible ...