.obj file looses color

I have one .obj file which is generated via blender the file contains the color but, when I load the file using three js it loose color and show only the grey color.

I have attached the file. Request to please look into the same so, that I can complete the work.

Test-2.obj (73.6 KB)

`

		import * as THREE from 'https://threejs.org/build/three.module.js';
		import { OBJLoader } from 'https://threejs.org/examples/jsm/loaders/OBJLoader.js';

		let container;

		let camera, scene, renderer;

		let mouseX = 0, mouseY = 0;

		let windowHalfX = window.innerWidth / 2;
		let windowHalfY = window.innerHeight / 2;

		let object;

		init();
		animate();


		function init() {

			container = document.createElement( 'div' );
			document.body.appendChild( container );

			camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
			camera.position.z = 250;

			// scene

			scene = new THREE.Scene();

			const ambientLight = new THREE.AmbientLight( 0xcccccc, 0.4 );
			scene.add( ambientLight );

			const pointLight = new THREE.PointLight( 0xffffff, 0.8 );
			camera.add( pointLight );
			scene.add( camera );

			// manager

			function loadModel() {

				object.traverse( function ( child ) {

					if ( child.isMesh ) child.material.map = texture;

				} );

				object.position.y = - 95;
				scene.add( object );

			}

			const manager = new THREE.LoadingManager( loadModel );

			manager.onProgress = function ( item, loaded, total ) {

				console.log( item, loaded, total );

			};

			// texture

			const textureLoader = new THREE.TextureLoader( manager );
			const texture = textureLoader.load( 'https://threejs.org/examples/textures/uv_grid_opengl.jpg' );

			// model

			function onProgress( xhr ) {

				if ( xhr.lengthComputable ) {

					const percentComplete = xhr.loaded / xhr.total * 100;
					console.log( 'model ' + Math.round( percentComplete, 2 ) + '% downloaded' );

				}

			}

			function onError() {}

			const loader = new OBJLoader( manager );
			
			loader.load( 'models/Test-2.obj', function ( obj ) {

				object = obj;

			}, onProgress, onError );

			//

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

			document.addEventListener( 'mousemove', onDocumentMouseMove );

			//

			window.addEventListener( 'resize', onWindowResize );

		}

		function onWindowResize() {

			windowHalfX = window.innerWidth / 2;
			windowHalfY = window.innerHeight / 2;

			camera.aspect = window.innerWidth / window.innerHeight;
			camera.updateProjectionMatrix();

			renderer.setSize( window.innerWidth, window.innerHeight );

		}

		function onDocumentMouseMove( event ) {

			mouseX = ( event.clientX - windowHalfX ) / 2;
			mouseY = ( event.clientY - windowHalfY ) / 2;

		}

		//

		function animate() {

			requestAnimationFrame( animate );
			render();

		}

		function render() {

			camera.position.x += ( mouseX - camera.position.x ) * .05;
			camera.position.y += ( - mouseY - camera.position.y ) * .05;

			camera.lookAt( scene.position );

			renderer.render( scene, camera );

		}

	</script>`

You are only loading the OBJ file which has no material or color information. There should a corresponding MTL file that contains these data.

BTW: Why are you not using glTF? If you want to load an asset into your app, the more modern glTF is the much better alternative compared to OBJ. Blender can export glTF by default.

Here are simple examples. For glTF and OBJ/MTL.

From the Collection of examples from discourse.threejs.org

* discourse.threejs.hofk.de BeginnerExample
// … step 03: load 3D models - gltf is recommended

and
2021 LoadOBJbyModule
:slightly_smiling_face:

@Mugen87 - Thank you so much for your quick response. Also, can I also get the example where I can use MTL and OBJ to load the color as well ?

Further, I will discuss with team if we can use glTF format.

@holk - Thanks you so much for your response.

There is the following official OBJ/MTL example:

https://threejs.org/examples/#webgl_loader_obj_mtl

@Mugen87 - Superb Support. Prompt Reply.

Thanks you so much once again.