The Three.js .obj loader fails to load .obj files exported from 3Ds Max

I am attempting to import a .obj file into Three.js using their 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;

                        }

                    } );

Everything works flawlessly with Blender models, but I encounter an issue when trying to load my custom 3Ds Max models. The .obj file fails to load in the browser and triggers an error message. Could it be due to incorrect exporting or is Three.js incompatible with the 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

Answer №1

I'm currently facing the same issue:

Error: Found unexpected line: s 2

This error occurred while using an .obj file exported from 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware.

After trying @2pha's suggestion mentioned here to add object names manually, I still encountered the 'Unexpected line' error.

Although my solution doesn't address the root cause of this issue, I found that importing the .obj file into Blender () and then exporting it as an .obj file resolved the problem. The .obj file generated by Blender v2.76 (sub 0) OBJ Exporter could be imported seamlessly using Three.js THREE.OBJLoader without any additional manual intervention.

Hopefully, Three.js or 3ds Max will rectify this error soon (progress can be tracked for Three.js here). In the meantime, there's no time to waste.

Update: I've submitted a pull request to address this issue: https://github.com/mrdoob/three.js/pull/8118. Meanwhile, you can update your smoothing_pattern to accommodate multiple digits:

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

Answer №2

I've encountered the same issue using the 3ds Max Wavefront OBJ Exporter v0.97b along with version 74 of threejs.

Although I haven't found a solution yet, it seems that the problem lies in how OBJLoader.js processes the obj file. The script is looking for smoothing groups in the format \^s\s+([01]|on|off)\, which only recognizes "s 1" or "s 0", resulting in errors when encountering "s 2" and higher values. You can verify this regex pattern with https://regex101.com if you're not familiar with regular expressions like myself ;)

An alternative workaround is to import the file into Blender and then export it, as Blender will only use "s 1" and "s off" parameters during the export process, bypassing this issue.

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

Steps for inserting a script tag in an Angular component

My Angular/Typescript website needs to integrate a third-party script that generates a table. However, I'm facing issues with rendering the table within the home.component.html file. I've managed to embed the script, but it doesn't seem to ...

"How to Develop an Eraser Tool Using EaselJs - Exploring Further Possibilities

Currently, I am working on creating a Bitmap eraser on easelJS. I feel like I've made significant progress towards achieving this goal, but I'm still a bit unsure of the next steps... Here is a demo of my progress so far: http://jsfiddle.net/bor ...

What is the correct way to populate the parameter value for the JavaScript in the http://valums.com/ajax-upload/ implementation?

Can anyone provide guidance on how to correctly populate a parameter value for the JavaScript? I am looking to pass an image title like below: params: { param1: imgTitle }, Where $("#ImageTitle").val(); is linked to <input type="text" id="Im ...

Tips for retrieving IDs when a selection is made in fcbkcomplete? Check out the example on jsfiddle!

Take a look at the code snippet below. I am attempting to extract the ids of the selected items in the fcbkcomplete box and display them as comma-separated values in the textbox with the id="interest". Although I wrote a function for this purpose, it is no ...

Javascript code for identifying objects in an array with specific properties and values

I have a collection of objects. Each object contains a boolean property named available, along with various other properties. While I am aware that the available property is present, the rest of the properties are unknown. For example: var myObjects = [ ...

Transfer a csv file from a static webpage to an S3 bucket

Looking to create a webpage for uploading csv files to an S3 bucket? I recently followed a tutorial on the AWS website that might be helpful. Check it out here. I made some modifications to accept filename parameters in my method, and everything seems to ...

ExpressJS authentication -> PassportJS: Issue with setting headers after they have been sent

Currently, I am implementing authentication in Express.js using Passport.js. Below is the code snippet from my login.js file: passport.use(new LocalStrategy( function(username, password, done) { //console.log(username); Usercollectio ...

Broadening the capabilities of jQuery through a versatile function

Currently, I am in the process of developing a generic function for my website using jQuery that will be utilized across the entire site to display success or error messages. After careful consideration, I have decided to transform this function into a plu ...

How to incorporate markdown files as strings in Next.js

Is there a way to bring in markdown files as strings in Next.js for use on both the client and server sides? ...

Attempting to extract the desired aggregations from a two-dimensional JSON array

Looking to parse through this JSON 2D array (snapshot data example below) to calculate the total cases and deaths for each date, disregarding the state column. While achievable in SQL, it poses a challenge in JavaScript. Ultimately, the summarized data wi ...

Using jQuery to easily transfer the direct image URL from an input field to a designated div element

In order to enhance the learning experience of 8th-grade chemistry students studying the periodic table of elements, I am working on a project that involves creating an "Augmented Reality" tool. The goal is to allow students to input a direct URL for an im ...

`How can we efficiently transfer style props to child components?`

Is there a way to pass Props in the Style so that each component has a unique background image? Take a look at this component: countries.astro --- import type { Props } from 'astro'; const { country, description } = Astro.props as Props; --- & ...

The event listener for onChange on my dropdown menu is not functioning as expected

Hey, I'm trying to achieve something when my select box changes. Here's my code snippet: function Task(){ const prints = (e) =>{ console.log("it prints"); } const prints2 = (e) =>{ console.log("it ...

Is it possible to obtain the output of a JavaScript file directly? (kind of like AJAX)

My previous experience with AJAX involved a server-side language like PHP generating xHTML with attached JS. The JS would then query another file using parameters set in either GET or POST. The output of the queried file would be returned to the JS, which ...

The datetimepicker Jquery seems to be malfunctioning when used with an asp textbox, yet it functions properly

After downloading a bootstrap admin template from Google to incorporate into my web application, I wanted to implement a datetimepicker using jQuery on an asp:textbox. To demonstrate this, I used the following HTML control: <input type="text" class="f ...

Ensure the computed variable is always up-to-date using Firebase in VueJS

After a successful sign-in through Firebase authentication, I need to update a navigation link. The user login changes are managed within the created hook using .onAuthStateChanged() data () { return { user: null, additionaluserinfo: nul ...

Having trouble getting the Bootstrap 5 Modal to function properly within an Electron app

Facing an issue with my web app using Bootstrap 5, as the modal is not displaying properly. Below is the HTML code for the modal and the button that triggers it: <div class="modal" tabindex="-1" id=&quo ...

Troubleshooting: The issue of receiving a 403 error when trying to access

I'm currently using Codeigniter 3 and have encountered an issue with a script. When the code is in my HTML file, everything works perfectly fine. However, if I move the code to an external file, I receive a 403 error. The location of my JavaScript fi ...

CSS2DRenderer does not belong to the Three.js library

Before we dive in, let me provide some background information: I recently incorporated three.js into a default React project using npm. Now, I'm interested in integrating this example that utilizes CSS2D. Unfortunately, I encountered an error when a ...

What sets apart window.location = MVC File() from the success( window.location = result ) in $.ajax?

These two snippets of code may seem similar in function, but they actually behave differently: window.location = "../PlanView/ExportAsPDF"; $.ajax({ url: '../PlanView/ExportAsPDF', data: { }, success: function (stream) { window.loca ...