# How to use OBJFileLoader with vertex colors in ES6/Vite setup?

**URL:** <https://forum.babylonjs.com/t/how-to-use-objfileloader-with-vertex-colors-in-es6-vite-setup/49317>\
**Category:** Questions\
**Created:** [April 3, 2024, 1:57pm UTC](https://forum.babylonjs.com/t/how-to-use-objfileloader-with-vertex-colors-in-es6-vite-setup/49317 "2024-04-03T13:57:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BobDylan](https://avatars.discourse-cdn.com/v4/letter/b/7c8e57/32.png) [@BobDylan](https://forum.babylonjs.com/u/BobDylan)\
**Post date:** [April 3, 2024, 1:57pm UTC](https://forum.babylonjs.com/t/how-to-use-objfileloader-with-vertex-colors-in-es6-vite-setup/49317/1 "2024-04-03T13:57:38Z")

</div>

I’m using Vite with Typescript as my build-system.  
I exported a mesh in Blender to OBJ-format, with colors included.  
I managed to get OBJ-file loading working by including this in the typescript file, where I import the mesh :

```auto
import * as BABYLON from '@babylonjs/core/Legacy/legacy';
import '@babylonjs/loaders/OBJ/objFileLoader';

```

However, to get colors of the imported obj file working (I don’t use a material or texture), the documentation says I should add the following:

`BABYLON.OBJFileLoader.IMPORT_VERTEX_COLORS = true;`

But this doesn’t work with my setup.` BABYLON.OBJFileLoader` is `undefined`.

Any idea how to enable vertex colors in this case?

UPDATE:  
It seems the Blender exporter to OBJ is not including colors after all, so it could never work anyway. When I display the file in 3D Viewer it’s grayscale. Has anybody ever managed to use/make an OBJ file with colors?

---

<div class="post-metadata">

**Author:** ![srzerbetto](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/srzerbetto/32/20941_2.png) [@srzerbetto](https://forum.babylonjs.com/u/srzerbetto)\
**Post date:** [April 9, 2024, 12:01pm UTC](https://forum.babylonjs.com/t/how-to-use-objfileloader-with-vertex-colors-in-es6-vite-setup/49317/2 "2024-04-09T12:01:36Z")

</div>

Hey @BobDylan , how are you doing?

I found this question that seems to show how to do it in Blender:

[mesh - Export Model With Material Colors to MeshLab - Blender Stack Exchange](https://blender.stackexchange.com/questions/44851/export-model-with-material-colors-to-meshlab)

Can you see if that works for you?

Also for the Babylon.js loader to be available you would have to import it as:

`import { OBJFileLoader } from '@babylonjs/loaders/OBJ/objFileLoader';`

And use it as:

`OBJFileLoader.IMPORT_VERTEX_COLORS = true;`

---

<div class="post-metadata">

**Author:** ![BobDylan](https://avatars.discourse-cdn.com/v4/letter/b/7c8e57/32.png) [@BobDylan](https://forum.babylonjs.com/u/BobDylan)\
**Post date:** [April 9, 2024, 1:29pm UTC](https://forum.babylonjs.com/t/how-to-use-objfileloader-with-vertex-colors-in-es6-vite-setup/49317/3 "2024-04-09T13:29:07Z")

</div>

Thanks for the reply, the code works now, but I still can’t seem to export a working model from Blender to `.obj` format. I tried all options I could find. Windows 3D Viewer still doesn’t show the colors, though, and importing the model into Babylon fails somehow:  
`Unable to load from meshes/tree.obj: OK`

I finally gave up on using `.obj`, and went for the `.babylon` format instead.
