本文介绍了将three.js网格作为OBJ或STL导出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为一个参数化的Three.js网格对象创建一个导出为OBJ或STL链接。
与上的导出选项一样


$ b $

$ p

解决方案

要使用.obj格式的网格,我使用这个简单的函数:

  THREE.saveGeometryToObj = function(geometry){
var s ='';
for(i = 0; i< geometry.vertices.length; i ++){
s + ='v'+(geometry.vertices [i] .x)+''+
geometry.vertices [i] .y +''+
geometry.vertices [i] .z +'\\\
';
}

for(i = 0; i
s + ='f'+(geometry.faces [ i] .a + 1)+''+
(geometry.faces [i] .b + 1)+''+
(geometry.faces [i] .c + 1);

if(geometry.faces [i] .d!== undefined){
s + =''+(geometry.faces [i] .d + 1);
}
s + ='\\\
';
}

return s;
}


I would like to create an export as OBJ or STL link for a parametric Three.js mesh object.Just like the export option on http://www.3dtin.com

Any advice would be appreciated.

解决方案

To get mesh in .obj format I use this simple function:

THREE.saveGeometryToObj = function (geometry) {
var s = '';
for (i = 0; i < geometry.vertices.length; i++) {
    s+= 'v '+(geometry.vertices[i].x) + ' ' +
    geometry.vertices[i].y + ' '+
    geometry.vertices[i].z + '\n';
}

for (i = 0; i < geometry.faces.length; i++) {

    s+= 'f '+ (geometry.faces[i].a+1) + ' ' +
    (geometry.faces[i].b+1) + ' '+
    (geometry.faces[i].c+1);

    if (geometry.faces[i].d !== undefined) {
        s+= ' '+ (geometry.faces[i].d+1);
    }
    s+= '\n';
}

return s;
}

这篇关于将three.js网格作为OBJ或STL导出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 22:56