Having trouble rendering image-based textures on a mesh imported from Blender

Two cubes are created with the following code using the same material. The first cube's geometry is generated with new THREE.BoxGeometry(), while the second cube's geometry is imported from Blender. The first cube displays the expected texture loaded from an image, whereas the second cube appears to show only one color from the image (see result). What is causing this difference and how can the material on the cube loaded from Blender be properly set?

Any help would be appreciated!

test.js:

var scene, camera, renderer;

function init() {
    scene = new THREE.Scene();
    scene.fog = new THREE.FogExp2(0xcccccc, 0.002);
    var light = new THREE.AmbientLight(0xffffff);
    scene.add(light);
    initObjects();
    camera = new THREE.PerspectiveCamera(20, window.innerWidth / window.innerHeight, 1, 1000);
    camera.position.set(20, 20, 20);
    camera.lookAt(scene.position);
    renderer = new THREE.WebGLRenderer({ antialias: true });
    renderer.setSize(window.innerWidth, window.innerHeight);
    document.body.appendChild(renderer.domElement);
}

function initObjects() {
    var material_leather_brown = new THREE.MeshLambertMaterial({map: THREE.ImageUtils.loadTexture('brown_leather.jpg')});
    scene.add(new THREE.Mesh(new THREE.BoxGeometry(2, 2, 2), material_leather_brown.clone()));
    var loader = new THREE.JSONLoader();
    loader.load('cube.json', function (geometry) {
        scene.add(new THREE.Mesh(geometry, material_leather_brown.clone()));});
}

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

init();
render();

cube.json:

{
    "metadata": {
        "type": "Geometry",
        "generator": "io_three",
        "uvs": 0,
        "faces": 6,
        "version": 3,
        "vertices": 8,
        "normals": 8
    },
    "uvs": [],
    "faces": [33,0,1,2,3,0,1,2,3,33,4,7,6,5,4,5,6,7,33,0,4,5,1,0,4,7,1,33,1,5,6,2,1,7,6,2,33,2,6,7,3,2,6,5,3,33,4,0,3,7,4,0,3,5],
    "normals": [0.577349,-0.577349,-0.577349,0.577349,-0.577349,0.577349,-0.577349,-0.577349,0.577349,-0.577349,-0.577349,-0.577349,0.577349,0.577349,-0.577349,-0.577349,0.577349,-0.577349,-0.577349,0.577349,0.577349,0.577349,0.577349,0.577349],
    "vertices": [1,0.000214,-6.19525,1,0.000214,-4.19525,-1,0.000214,-4.19525,-1,0.000214,-6.19525,1,2.00021,-6.19525,0.999999,2.00021,-4.19525,-1,2.00021,-4.19525,-1,2.00021,-6.19525],
    "name": "CubeGeometry"
}

test.html:

<!doctype html>
<html style="height: 100%;">
<head>
    <title>Test</title>
    <style>
        html, body {height: 100%;}
    </style>
</head>
<body>
    <script src="three.min.js"></script>
    <script src="test.js"></script>
</body>
</html>

brown_leather.jpg

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

What is causing the recursion function to return "NaN" in this scenario?

I'm trying to calculate the total sum of absolute differences between consecutive elements in an array using a function called sumAbsArr, but it seems to be returning NaN. var arr = [1, 5, 2]; var n = 3; var cur = 0; console.log(sumAbsArr(arr, n, ...

Scaling texture to fit on a plane in THREE.js

I am attempting to 'fit-to-scale' a mapped image texture on a single plane, aiming to simulate the behavior of object-fit:cover. The image map needs to scale proportionally in order to cover the entire plane completely. I have experimented with ...

I am puzzled by this error in Typescript: "Why does the element have an 'any' type when the Object type lacks an index signature?"

Looking to extract an array of keys from an object with nested properties, my current code: public static getKeys(obj: Object) { let keys: string[] = []; for (let k in obj) { if (typeof obj[k] == "Object" && obj[k] !== null) { ...

My controller in AngularJS is having trouble fetching the latest values of the $scope variables

In my code, I've included the relevant snippet below. The base angularJS seems to be functioning properly as the HTML document doesn't display {{}} variables but instead remains blank. I suspect that this is due to the variables receiving a null ...

At times, $http may give an error code of 0 while other times it

I am facing an issue with my Angular controller that processes form data, manipulates it, and sends it to the server using $http for saving. Sometimes, the code works perfectly - the success function is triggered. Other times, however, I receive error cod ...

What is the reason JavaScript function aliasing fails to work?

When Firebug is not enabled, I have some Firebug console function calls that I wanted to disable by checking if the console object is defined. This implementation works in IE6 and FF3, but unfortunately not in Chrome: var log; if(console){ log = consol ...

Developing a simple component

Is there a variance in performance when working with dumb components in React? There are two methods to achieve the same outcome. function Comp(props) { ... } const Comp = props => { ... } ...

Tips for editing events in the "react-big-calendars" component

I am looking to implement a feature where users can click on events in a calendar and then edit either the dates or event titles. Can this functionality be achieved using "react-big-calendar"? If not, are there any other packages you can recommend? <Cal ...

At the ready stance for a particular grade of students attending a class

I have created a page with a navigation menu that can be scrolled using the wheel mouse. My goal is to ensure that the li item with the 'selected' class is always positioned in the first position on the left. Is there a way to achieve this using ...

Exploring the world of functional programming within nested arrays

I have been shifting towards functional programming over imperative programming recently. Imagine I have a nested array data structure and my goal is to update the values of the innermost arrays. What approach would be most effective? Here is the imperat ...

Trouble with _.keys function in Firebug - not detecting all items

I currently have a post stored in $scope.mydata within the controller. I pass this data as a parameter to a service that returns a function. The service looks like: module.factory('myservice', function () { return function servicefunction(m ...

Utilizing jQuery to extract the id and update its content

One of my tasks involves working with a table generated by PHP and incorporating a modal that allows users to change the text produced by the variable $l_id. I have a link with a class "eloc" that triggers the display of the modal div section. By intercept ...

Obtain a listing of values that appear multiple times within an array

I need a solution to find values that appear more than once in an array. The current code I have is quite complex. var arr = [1, 2, 3, 4, 2, 3]; var flag = {} var exist2arr = []; for(var i = 0; i < arr.length; i++){ for(var j = 0 ; j < arr.leng ...

Harnessing the power of JavaScript functions to display an image when clicked

Looking for help with making an image appear when clicking on one of three images? Despite trying different approaches, the desired result is still not achieved. I'm aware of using if else statements but exploring other methods. Any insights on what m ...

Is there a solution for passing multiseries data in JSON that works with AnyChart in ReactJS since the standard method is not functioning correctly?

I need help implementing a column chart using AnyChart in react with multi-series data. Below is a sample JSON structure that I am having trouble passing to the chart. const multiSeriesSettings = { width: 800, height: 600, type: "column", ...

Configuring babel-loader in webpack for optimal HMR functionality

Recently, I encountered an issue while trying to add Hot Module Replacement (HMR) to my project. Despite the console showing that HMR was enabled and detecting changes in files, the view was not re-rendering. The console would display: [HMR] Updated modul ...

Do JavaScript objects need to be encapsulated?

Currently in the process of developing a node.js application and in search of methods to establish the datamodel. The JSON format is utilized for data transmitted to and from the client, while communication with the MongoDB database is also done using JSO ...

Implementing a feature to effortlessly select all or unselect all with just a few clicks in the filter checkboxes using React

I've implemented a checkbox filter function, but I'm trying to enhance it by adding an option for checking all or unchecking all checkboxes. Additionally, I would like to integrate TypeScript into the code. Any guidance on how to achieve this wou ...

The radio input is not being properly checked using ng-checked in Angular

The ng-checked attribute is causing issues in the application, specifically with radio buttons. It seems to be working fine for checkboxes but not for radio buttons. <input type="radio" class="radio" name="job_class_radio" ng-checked="key===jobClassDat ...

What is the reason for needing to refresh when submitting form data in a Node application with an HTTP POST

Code Snippet - Angular .state('studentInfo.newStudent', { url : '/new/student', templateUrl: 'students/new-student.html', controller : function($state, $http){ this.saveStudent = func ...