我尝试使用在 Stack Overflow 上找到的以下代码从 Three.js 场景中的几何图形中导出 OBJ。几何图形正在被 GLSL 着色器置换,因此顶点的置换似乎不会随几何图形一起导出。当我将 OBJ 导入 Blender 时,我只得到没有移位的平面。您可以在http://kineticvideo.co检查位移的工作版本
如何在使用 GLSL 着色器置换几何体时导出 OBJ?请帮忙。我的印象是顶点的位移实际上会在 Three.js 几何体中实时更新,但看起来即使我设置了 geometry.verticesNeedUpdate = true; 位移实际上发生在网格中,而不是几何体中。
如果是这样,我如何使用网格而不是几何导出 OBJ?
Three.js 中声明几何和顶点着色器的代码片段:
videoMaterial = new THREE.ShaderMaterial( {
uniforms: {
"tDiffuse": { type: "t", value: texture },
"multiplier": { type: "f", value: 66.6 },
"displace": { type: "f", value: 33.3 },
"opacity": { type: "f", value: 1.0 },
"originX": { type: "f", value: 0.0 },
"originY": { type: "f", value: 0.0 },
"originZ": { type: "f", value: -2000.0 }
},
vertexShader: RuttEtraShader.vertexShader,
fragmentShader: RuttEtraShader.fragmentShader,
depthWrite: true,
depthTest: true,
wireframe: false,
transparent: true,
overdraw: false
});
videoMaterial.renderToScreen = true;
videoMaterial.wireframe = true;
geometry = new THREE.PlaneGeometry(720, 360, 720, 360);
geometry.overdraw = false;
geometry.dynamic = true;
geometry.verticesNeedUpdate = true;
mesh = new THREE.Mesh( geometry, videoMaterial );
这是我使用的函数,它导出几何,但不是位移:
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;
console.log(s);
}