facebookarchive / react-360

Create amazing 360 and VR content using React
https://facebook.github.io/react-360
Other
8.73k stars 1.23k forks source link

Double Slashes in .obj files #454

Open MatthewAwesome opened 6 years ago

MatthewAwesome commented 6 years ago

Description The OBJ loader fails when double slashes (//) are encountered in .obj files.

Expected behavior Ideally, the loader would accommodate the double slash expression, which is used to link a vertex index to a corresponding normal index in the absence of a texture coordinate.

Actual behavior In a web-loaded view (Chrome), an error is fired when attempting to load a .obj file containing double slashes. Take for example the following snippet from a .obj file I attempted to load, which threw an error.

f 56035// 56040// 56037//

Solution I managed to address this issue via modifying the OBJParser.js file in react-vr-web . This was done by changing the appropriate regex to accommodate one or two slashes in sequence as opposed to the existing which accommodated only a single slash. Existing: const TRIPLET_TEST = /^\s*(-?\d+)\/?(-?\d+)?(\/-?\d+)?\s*/; Modified: const TRIPLET_TEST = /^\s*(-?\d+)\/{0,2}(-?\d+)?(\/{0,2}-?\d+)?\s*/;

Additional Information

andrewimm commented 6 years ago

Yet another case where the lack of spec for OBJ creates some odd instances in the open.

While your fix is correct, I think the intent would be better expressed by breaking out the final slash

/^\s*(-?\d+)\/?(-?\d+)?(\/-?\d+)?\s*/

becomes

/^\s*(-?\d+)\/?(-?\d+)?\/?(-?\d+)?\s*/

Will get a fix out shortly