I have an .obj file which has Vertex Colors in it. That is it doesn't have seperate .mtl file for its Texture . The .obj File itself contains the color for each vertex.
I wanted to load it using three.js
I knew I can load a normal .obj file with .mtl using :
objLoader = new THREE.OBJLoader();
objLoader.load('meshlabshristi3.obj', function(object) {
scene.add(object);
});
But mine has vertex colors so I found it can be done with OBJLoader2.js so tried executing it like :
var objLoader = new THREE.OBJLoader2();
objLoader.load('assets/faceimage9.obj', function(object) {
scene.add(object);
});
But it throws errors saying
OBJLoader2.js:6 Uncaught SyntaxError: Cannot use import statement outside a module
index.html:80 Uncaught TypeError: THREE.OBJLoader2 is not a constructor
at init (index.html:80)
at index.html:31
Am I doing it wrong or is there any other problem . Can anyone post the exact code to load a vertex colored mesh . Thanks in advance for anyone who tried to read and solve it ...
If anyone need a vertex colored mesh to work on I had attached below.. Vertex Colored Model
For the comment below I attach this image:

Both OBJLoader and OBJLoader2 seem work just fine.
You just need to set
material.vertexColors = trueon all the materials (or all the ones that have vertex colors)As for the error
If you're using ES6 modules you need to put your script in
<script type="module">script tag, and organize the files the same as they are organized in the three.js repo. NamelyAnd then use import statements to load everything
See: this answer
If you want to do it the old deprecated way with a multiple script tags instead of
importthen use the files fromexamples/jsinstead ofexamples/jsmin which case you can put them anywhere but assuming you keep them in the same place thenNote it uses
three.min.jsnotthree.module.js