Trouble arises when trying to display the colors of a Blender imported mesh in Three.js

I am attempting to showcase interconnected cubes, which have been imported from Blender, using Three.js.

I am utilizing the most recent versions of Three.js and Blender 2.78a.

To start off, I created my cube object following this example: However, I have a unique set of interconnected cubes.

https://i.sstatic.net/rLCi8.png

The 3D object above was crafted in Blender, then exported as a mesh using the Three.js .js exporter.

Attached is the marmelab.json file.

{
    "metadata":{
        "generator":"io_three",
        "faces":6,
        "type":"Geometry",
        "version":3,
        "materials":1,
        "normals":6,
        "vertices":24,
        "uvs":1
    },
    "faces":[43,8,10,12,14,0,0,1,2,3,0,0,0,0,43,16,18,20,22,0,3,0,1,2,1,1,1,1,43,9,15,19,17,0,3,0,1,2,2,2,2,2,43,1,13,21,5,0,3,0,1,2,3,3,3,3,43,3,11,23,7,0,3,0,1,2,4,4,4,4,43,2,0,4,6,0,3,0,1,2,5,5,5,5],
    "materials":[{
        "DbgIndex":0,
        "blending":"NormalBlending",
        "opacity":1,
        "depthWrite":true,
        "visible":true,
        "transparent":false,
        "colorEmissive":[0,0,0],
        "colorDiffuse":[0.8,0.432941,0],
        "wireframe":false,
        "DbgName":"01 - Default",
        "specularCoef":11,
        "colorSpecular":[0.18,0.18,0.18],
        "DbgColor":15658734,
        "depthTest":true,
        "shading":"phong"
    }],
    "normals":[0,0,1,0,0,-1,0,1,-0,1,0,-0,0,-1,-0,-1,0,-0],
    "name":"Untitled.001Geometry.1",
    "vertices":[-0.307576,-0,-0.433258,-0.002776,-0,-0.433258,-0.307576,-0,-0.738058,-0.002776,-0,-0.738058,-0.307576,0.3048,-0.433258,-0.002776,0.3048,-0.433258,-0.307576,0.3048,-0.738058,-0.002776,0.3048,-0.738058,-0.307576,-0,-0.433258,-0.307576,-0,-0.433258,-0.307576,-0,-0.738058,-0.307576,-0,-0.738058,-0.002776,... [Truncated for brevity]
    "uvs":[[1,0,1,1,0,1,0,0]]
}

Javascript code to load the mesh and display it:

var scene, camera, renderer;

var WIDTH  = window.innerWidth;
var HEIGHT = window.innerHeight;

var SPEED = 0.01;

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

    initMesh();
    initCamera();
    initLights();
    initRenderer();

    document.body.appendChild(renderer.domElement);
}

function initCamera() {
    camera = new THREE.PerspectiveCamera(70, WIDTH / HEIGHT, 1, 10);
    camera.position.set(0, 3.5, 5);
    camera.lookAt(scene.position);
}


function initRenderer() {
    renderer = new THREE.WebGLRenderer({ antialias: true });
    renderer.setSize(WIDTH, HEIGHT);
}

function initLights() {
    var light = new THREE.AmbientLight(0xffffff);
    scene.add(light);
}

var mesh = null;
function initMesh() {
    var loader = new THREE.JSONLoader();
    loader.load('./marmelab.json', function(geometry, materials) {
        mesh = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial(materials));
        mesh.scale.x = mesh.scale.y = mesh.scale.z = 0.75;
        mesh.translation = THREE.GeometryUtils.center(geometry);
        scene.add(mesh);
    });
}

function rotateMesh() {
    if (!mesh) {
        return;
    }

    mesh.rotation.x -= SPEED * 2;
    mesh.rotation.y -= SPEED;
    mesh.rotation.z -= SPEED * 3;
}

function render() {
    requestAnimationFrame(render);
    rotateMesh();
    renderer.render(scene, camera);
}

init();
render();

Upon viewing the shape in the browser, while retained, the color appears as white.

What could be missing in this setup?

Thank you in advance for your assistance.

https://i.sstatic.net/XP3bT.png

Answer №1

UPDATE

I have made changes to the Plunker by updating it with the most recent version of three.js. This update has resolved the issue with your JSON data without any modifications - http://plnkr.co/edit/RwkgzrvfqzYlWtShhpjt?p=preview

In addition, I have conducted successful tests using my own more intricate model - http://plnkr.co/edit/SWXv1GyKIGryORiNYlgx?p=preview

The root cause of the problem lies in the utilization of an outdated version of three.js. Initially, I tested it with the version provided on the website you referenced. It is likely that you also used a similar version based on the outcomes.

Around revision 70, there was a modification in the exporter where they ceased exporting the colorAmbient property. Consequently, that older iteration of Three.js necessitated its presence.

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

Delay execution of Selenium WebDriver until the element appears on the screen

After scouring Google and the SO site, I was able to find answers for JAVA but not for node.js. I have a web application that has a slow loading time. I want the selenium program to wait until the page is fully loaded before taking any actions. Below is ...

What is the best way to access data from a static config.json file in TypeScript within a Vue component following the execution of a build:electron command in Vue CLI 3?

Hey there! I've been considering whether it's feasible to include a config.json file in a Vue CLI 3 project that can be dynamically read at runtime, both during development and production stages. This config.json file will hold key strings that ...

What is the best way to extract the data from a Json array and store it in an ArrayList?

Let me start by mentioning that I am a novice, so any assistance would be greatly appreciated. I have developed a car class within a form application. Each car instance has three properties: spaceNum, make, and model. All cars are stored in an ArrayList. ...

Creating an object key using a passed literal argument in TypeScript

Can the following scenario be achieved? Given an argument, how can we identify the object key and access it? Any potential solutions? async function checkKey(arg:'key1'|'key2'){ // fetchResult returns an object with either {key1:&apo ...

Transform the JSON data in a column into separate new columns

I am facing a challenge with a sub-Yelp Dataset in csv format where the attributes column is in json format. I have been struggling to convert this column into new columns using various code snippets from different sources without success. Each row in the ...

Creating a Vue.js vuetify input that restricts the user to entering only three digits before the decimal point and two digits after the decimal point

I am looking to implement a restriction on the total number of input digits to 3. Users should be able to enter numbers like 333, 123, etc. However, if they include a decimal point, they should only be allowed to enter 2 digits after the decimal point. Val ...

Retrieving a subset of an array column in Sequelize: A comprehensive guide

I am currently working with a table that has an array column named tokens When querying this table using npm sequelize, I sometimes encounter an issue where the tokens column contains up to 20k elements, even though I only need 10 elements from it. In st ...

The textures in Three.js appear to blend seamlessly into the distance as they

My threejs scene has a camera setup like this: var VIEW_ANGLE = 45, ASPECT = SCREEN_WIDTH / SCREEN_HEIGHT, NEAR = 0.1, FAR = 8000; camera = new THREE.PerspectiveCamera(VIEW_ANGLE, ASPECT, NEAR, FAR); The material creation looks like this: var floorText ...

What is the best way to encode a JSON string for CSV processing?

Is it possible to store a JSON string properly in a CSV column as a string? I have been successful in generating the CSV file, but parsing the CSV file with the JSON data is proving to be a challenge. I have attempted different formats such as "{"prop": " ...

The Electron BrowserWindow event triggered when the window is closed

Is it possible to retrieve values when closing a BrowserWindow in electron? Ideally, I am looking for a method to access the variables from the close event: win.on('closed', function(variables can be accessed) { console.log(variables + ...

Navigate to a different subdomain and place a cookie on the newly redirected subdomain

The version of Express is 4.x NodeJS is running on version 12.x At a.example.com, I have a listener for the GET method that redirects to b.example.com and sets a cookie on b.example.com. app.get('/foo', (req, res) => { res.cookie(' ...

Learn how to display HTML content in trNgGrid using the $sce.trustAsHtml method

I am currently working with a table that has search options implemented using trNgGrid.js. The data for this table comes from a Sharepoint list where one of the columns contains HTML content that I need to display. To achieve this, I attempted using $sce. ...

Deciphering the JSON data from a Retrofit response

I recently made a request using the Retrofit API and received the following JSON response: {"success":true,"data":{"token_id":"pPt9AKl0Cg","token_key":"8ax224sFrJZZkStAQuER"}} Now I'm wondering how to effectively parse this JSON. Creating a new mode ...

Does anyone know of a Java JSON library that follows a similar structure to XMLEncoder?

After researching multiple JSON libraries for Java, I have noticed that not many of them adhere to the same serialization pattern as core Java. Ideally, I am looking for a native Java JSON serialization object to use. However, if that is not available, I ...

I am experiencing an issue where my ajax code is unable to display the

After spending countless hours trying to make this work, I find myself stuck. I've set up a simple guestbook page and have created this code to generate a JSON file: <?php /* Constants for database settings */ define("DBHOST", "localhost"); defin ...

Generating a folder on-the-fly and uploading a file using a multipart request in Node.js

My current challenge involves dynamically creating folders when a user loads a file. This is necessary to store each user's files separately in order to avoid conflicts if a file is deleted. Additionally, I need to create the file path on my computer ...

What is the best way to make a div pull its background image directly from the internet instead of using the cached version?

Running relevant Javascript every fifteen minutes to fetch the appropriate image from the internet: document.getElementById('weatherbug').style.background = "url('http://tinyurl.com/jwltx5s') repeat scroll -1px -24px transparent"; The ...

I am encountering difficulties trying to create a draggable stacked bar chart using d3 v4. The main challenge lies in properly translating the svg elements during the dragging process

const dragFunction = d3.drag() .on("start", startDrag) .on("drag", duringDrag) .on("end", endDrag) function startDrag(d) { d3.event.sourceEvent.stopPropagation(); d3.event.sourceEvent.pre ...

Troubleshooting the issue with fetching JSON data using PHP curl

I'm dealing with a PHP script that is supposed to retrieve JSON output from a URL, but it's only displaying plain text output at the moment. Strangely enough, when I run the same cURL command in my terminal, the output is properly formatted as JS ...

Task within a mapping function?

I am facing an issue with the following code snippet: this.array1 = this.array1.map(a => (a.name = "Harold")); It seems like there is a syntax error, and I can't figure out why. My intention is to set the "name" property of eve ...