Search code examples
javascriptthree.js3dsmax

Three.js .obj loader not working with 3Ds Max .obj


I am trying to load a .obj into Three.js using there objLoader.

var loader = new THREE.OBJLoader( manager );
                loader.load( 'obj/gate-2.obj', function ( object ) {

                    object.traverse( function ( child ) {

                        if ( child instanceof THREE.Mesh ) {

                            child.material.map = texture;

                        }

                    } );

All works fine using blender models however whenever I try to use my own custom 3Ds Max models, the .obj won't load within the browser and gives out an error. Am I exporting wrong or does Three.js not support 3Ds Max .obj exporter?

Error Message

    Error: Unexpected line: s 2
parseOBJLoader.js:339
(anonymous function)OBJLoader.js:24
(anonymous function)three.min.js:376:387

Solution

  • I am currently experiencing this exact same error:

    Error: Unexpected line: s 2
    

    Using an .obj file exported by 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware.

    I've followed @2pha's link related to the missing object names, and while this is true, after inserting the object names manually, I still experienced the 'Unexpected line' error.

    My solution, while not a specific fix for the reasons why this error is happening, is to import the .obj file within Blender (https://www.blender.org/), and immediately export an .obj file. It seems the .obj file created by the Blender v2.76 (sub 0) OBJ Exporter can be imported with no addition manual labor using the Three.js THREE.OBJLoader.

    I hope one day Three.js or 3ds Max will correct this error (it seems to be in the works for Three.js here), but in the meantime ain't nobody got time for that.

    Update: I've submitted a pull request to fix this issue: https://github.com/mrdoob/three.js/pull/8118, in the meantime you can modify your smoothing_pattern to support multiple digits:

    Line 220: var smoothing_pattern = /^s\s+(\d+|on|off)/;