From 63940db13153be69d0da1c93d2788a12585b533a Mon Sep 17 00:00:00 2001 From: Sakai-san Date: Thu, 2 Oct 2025 14:29:58 +0200 Subject: [PATCH] Add support for quoted filenames in mtllib entries - Handle quoted filenames (single or double quotes) in mtllib statements - Support filenames with spaces when properly quoted - Maintain backward compatibility with unquoted filenames --- src/OBJFile.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/OBJFile.js b/src/OBJFile.js index f4c9e6e..b1faa56 100644 --- a/src/OBJFile.js +++ b/src/OBJFile.js @@ -28,7 +28,15 @@ class OBJFile { for (let i = 0; i < lines.length; i += 1) { const line = _stripComments(lines[i]); - const lineItems = line.replace(/\s+/g, ' ').trim().split(' '); + // splitting by blanks. For mtllib entry, balanced quote (single or double) around referreed file is stripped and file name having blanks is supported. + let lineItems; + let mtllibMatch = line.match(/^\s*(mtllib)\s+(['"]?)(.*?)\2\s*$/i); + + if (mtllibMatch) { + lineItems = [mtllibMatch[1].toLowerCase(), mtllibMatch[3]]; + } else { + lineItems = line.replace(/\s+/g, ' ').trim().split(' '); + } switch (lineItems[0].toLowerCase()) { case 'o': // Start A New Model