开发者

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


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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜