Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

parsing .obj 3D graphics file with JavaScript

I have a question. I know that its not possible to parse .obj 3D graphics file using JavaScript and we have to convert it into some other format (preferably JSON). But I want to know why? Why we can't parse .obj file using JavaScript?

I would really appreciate your comments and answers.

Thanks Vik

like image 326
Vik Avatar asked Oct 21 '25 08:10

Vik


2 Answers

Sure you can... why not? It's a text file, just go ahead and parse it.

Here, I'll even get you started:

var objText = getObjFile();
var obj = {};
var vertexMatches = objText.match(/^v( -?\d+(\.\d+)?){3}$/gm);
if (vertexMatches)
{
    obj.vertices = vertexMatches.map(function(vertex)
    {
        var vertices = vertex.split(" ");
        vertices.shift();
        return vertices;
    });
}
like image 119
gilly3 Avatar answered Oct 23 '25 22:10

gilly3


Of course you can. I have even written my own library for parsing 3D formats - K3D.js. It also supports MD2, 3DS and Collada. OBJ was the easiest to code :)

like image 39
Ivan Kuckir Avatar answered Oct 23 '25 21:10

Ivan Kuckir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!