Skip to content

Fixed bug with vertex positions - #1

Open
tengotengo wants to merge 1 commit into
mikolalysenko:masterfrom
tengotengo:master
Open

Fixed bug with vertex positions#1
tengotengo wants to merge 1 commit into
mikolalysenko:masterfrom
tengotengo:master

Conversation

@tengotengo

Copy link
Copy Markdown

Vertices marked with v has 2 spaces after values, so yeah

@mikolalysenko

Copy link
Copy Markdown
Owner

Can you post a test case which was failing earlier?

@tengotengo

Copy link
Copy Markdown
Author

I'm sorry, obj files that were exported from 3dsMax have 2 spaces after each "v", which is weird.

here's a screenshot http://ii.pe/Tengiz_1439592782.jpg

@mikolalysenko

Copy link
Copy Markdown
Owner

Ok. Maybe a better way to fix this is to modify the tokenizer to be whitespace insensitive. Perhaps you could modify the line which splits on ' ' to split on `/\w+/'?

@mikolalysenko

Copy link
Copy Markdown
Owner

Err that should be \s or whatever the regex pattern is for whitespace.

@tengotengo

Copy link
Copy Markdown
Author

yes sir, great solution!
But perhaps simply checking if (toks[1] === '') { toks.shift() } would be faster?
Your choice

@tengotengo

Copy link
Copy Markdown
Author

of in line 25, instead of this:
v.push([+toks[1], +toks[2], +toks[3]])
do like this:
v.push([+toks[toks.length-3], +toks[toks.length-2], +toks[toks.length-1]])

@mikolalysenko

Copy link
Copy Markdown
Owner

What if some other code generated an example where the components of the vector 3 were spaced differently, for example:

v  1    3                    5

@tengotengo

Copy link
Copy Markdown
Author

excellent question.
I just found an obj file where double spacing occurs not just after "v" but also after "vt" and "vn"
I guess the right thing to do would be to split that string using white-space regex, like you suggested at the very beginning

@tengotengo

Copy link
Copy Markdown
Author

I don't see why would anyone generate it using multiple spaces between values, but I could definitely get it if someone used, for example, \t character as a separator. Hence /\s+/ would be ideal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants