开发者

parsing .obj 3D graphics file with JavaScript

开发者 https://www.devze.com 2023-03-03 20:03 出处:网络
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 wh

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


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;
    });
}


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 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消