Blender models lose their texture when imported into Three.js

Currently, I am facing a challenge in exporting a model with texture from Blender to be used in Three.js. I am utilizing the Blender export to Three.js plugin for this purpose.

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

  1. (Red): This depicts the model within Blender before exporting, showcasing the marble texture applied to it.
  2. (Blue): The model after being exported to Three.js format (saved as fullBoard.js) and reopened in Blender.
  3. (Green): Following the export process using Three.js mentioned earlier.

Below is my JavaScript function used to initialize the model:

    function init2(){
    container = document.createElement( 'div' );
    document.body.appendChild( container );
    camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
    camera.position.z = 100;

    scene = new THREE.Scene();

    var ambient = new THREE.AmbientLight( 0x101010 );
    scene.add( ambient );

    var directionalLight = new THREE.DirectionalLight( 0xffeedd );
    directionalLight.position.set( 0.5, 2, 1 ).normalize();
    scene.add( directionalLight );

    renderer = new THREE.WebGLRenderer();
    renderer.setSize( window.innerWidth, window.innerHeight );
    container.appendChild( renderer.domElement );

    var loader  = new THREE.JSONLoader();

    loader.load( 'objects/fullBoard.js', function ( geometry, materials ) {
        var material1 = materials[ 0 ]; //black
        var material2 = materials[ 1 ]; //white
        mesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) );
        mesh.scale.set(5,5,5);
        scene.add( mesh );
    }  );

    document.addEventListener( 'mousemove', onDocumentMouseMove, false );
    window.addEventListener( 'resize', onWindowResize, false );

}

I have been encountering difficulties in finding a straightforward method to create custom 3D models for use with Three.js that include texture. I also experimented with exporting .dae files using the THREE.ColladaLoader(), but unfortunately, this approach did not retain the texture as expected.

Answer №1

If you're having trouble exporting blender procedural textures, don't worry! You can easily bake them into regular textures before exporting. There are plenty of helpful tutorials available online to guide you through the process.

Consider using a different exporter, such as binary GLTF (.glb), for smoother exporting experience.

In my experience, I've found that using the three.js exporter can lead to compatibility issues between revisions. Opting for formats like gltf or collada can ensure better interoperability with other programs in case you need to make changes later on without losing the original files.

Additionally, GLTF offers the advantage of compressing meshes, which can be incredibly beneficial for optimizing web-delivered content.

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

Mysterious AngularJS

I am currently working on minimizing and obfuscating my Angular code, however I have run into a complication. I came across the "Note on minification" page at http://docs.angularjs.org/tutorial/step_05 which has been helpful, but I'm defining my contr ...

Exploring the usage of multidimensional arrays in React components

How can I extract data such as teamId from the "teams" array using datas.map() method in a multidimensional array? Any tips or help would be appreciated. Is there another way to map out this data? { "gameId": 3226262256, "platformId": "NA1", " ...

What could be causing the entire app to malfunction when the Redux Provider tag is used

I am facing an issue while trying to integrate a React Toolkit app into my project. The error message I encountered is as follows: Error: Invalid hook call. Hooks can only be called inside the body of a function component. This error may occur due to one ...

Troubleshooting Bootstrap 4 Modal in JavaScript and Vue: Uncaught ReferenceError: $ is not defined

I'm struggling to figure out how to trigger a Bootstrap 4 modal from my Vue 3 app using JavaScript. Whenever I try to launch the modal, I keep encountering this error message: $ is not defined at eval When looking for solutions, I noticed that most a ...

HTML-Formatted Email Content

Similar Question: MailTo with HTML body I am looking to utilize JavaScript to send emails. I came across this helpful post: Sending emails with JavaScript. My goal is to include images, bold text, and color changes in the email content. Does anyone h ...

What was the reason for needing to employ `toObject()` in mongoose to determine if an object contains a certain property?

From what I understand, there is no .toObect() function in JavaScript, but it is used in mongoose to convert mongoose documents into objects so that JavaScript built-in functions can be used. I sometimes struggle with when to use it. There are instances w ...

Error in content policy for CSS in Stripe Checkout

I am currently attempting to integrate Stripe Checkout into my Ionic App. I have created a Directive that injects the form into my content view, however, upon execution, the CSS fails due to a content policy violation: checkout.js:2Refused to load the s ...

Using the AJAX loading method with an ID stored in a JavaScript variable

Hey there! Could someone please explain how I can use the AJAX load method to load a div whose ID is stored in a JavaScript variable? In other words, the div that needs to be loaded has its ID saved as a JavaScript variable. I'm facing an issue where ...

What is the best way to modify the class of my <li> element with JavaScript?

My asp.net project utilizes a master page that includes a list within it. <ul id="navigation"> <li id="li1" runat="server" class="selected"><a href="Events.aspx">Events</a></li> <li id="li2" runat="server ...

Substitute the division

Can I make the old div change its position and move to the side when I add a new div? And can all the old divs be hidden when adding four new divs? This is for my full news website and I want this applied to all four pages. First page: https://i.sstatic. ...

Passing props in Vue router results in the props being undefined

I am attempting to pass a props via the vue router using a router link that appears like this <router-link :to="{ name: 'product-details', params: { productId: 123 } }" class="product-sbb d-block"> Below are my routes { ...

Storing JSON values dynamically

On a PHP webpage, I am sending values using JSON. $result = mysql_query("SELECT * FROM user_info"); $i=1; while($row = mysql_fetch_array($result, MYSQL_NUM)) { if(is_array($row) && count($row)>0) { $res[&a ...

The font size of the textarea dynamically adjusts based on the size of the screen

Some strange behavior is occurring in the Android default browser when I set the width and height of a textarea to 100%. The font size of the textarea seems to increase based on the screen size, and even though I attempted to alert the font-size using jQue ...

A guide to retrieving the Java exception behind a ScriptException in JSR-223

My current setup involves running Javascripts through the JSR-223 script engine within JRE6. These scripts have the ability to access Java code and objects. In case an exception is generated by the Java code called from a JavaScript, the ScriptEngine will ...

Using a JavaScript variable within an Angular component: a step-by-step guide

I am currently working with some javascript code for mapbox in my .ts file within an angular component. My goal is to access a variable called polygonCoordinates[] from the javascript code and use it in my typescript code. Unfortunately, I'm facing di ...

PHP query Ajax navigation

UPDATED I have made progress with processing both menus in "process.php" and displaying the queries in index.php. process.php <?php $menu1 = $_POST["menu1"]; $menu2 = $_POST["menu2"]; if($menu1 == 0) { $sql = "SELECT * FROM Language WHERE ID = " ...

When attempting to execute an npm command, an error is encountered stating that chunk.sortModules is

It’s time to bring back an old project and make some modifications. I tried using git checkout 0.0.2 since that's the tag currently running on production, but it seems to be causing issues. After downloading the code to my PC, I removed the node_mo ...

Guide to placing content in a jQuery dialog box

When utilizing the $("#note_content").dialog() function, I am wanting to display the note_text content within the dialog box. Does anyone have suggestions on how this can be achieved? I want to ensure that the note_text is visibly displayed in the dialog ...

Is it possible to center-align the text in a Material-ui TextField and enforce a minimum numerical value at the same time?

I'm facing an issue with trying to center align the text inside the TextField and also set a minimum value of 0. It seems like I can only achieve one or the other, but not both simultaneously. I referred to the material-ui page on TextField for help, ...

Occasionally encountering the error message "Cannot find the length of undefined"

Recently, I developed a tool that required me to create a series of dropdown menus for selecting a profile/view id from Google Analytics. This process involved dynamically populating the next menu based on the user's selection in the previous one. Alt ...