使用STLLoader进行CSG操作 [英] CSG operation with STLLoader

查看:340
本文介绍了使用STLLoader进行CSG操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ThreeCSG.js对导入的STL网格文件执行布尔操作。
这是代码..

I am trying to perform a boolean operation on an imported STL mesh file using the ThreeCSG.js. Here is the code..

function openFile() {
filePath = document.form.selectedFile.value;
var loader = new THREE.STLLoader();
loader.addEventListener('load', function(event) {
//A simple cube geometry imported from STL file.

var geometry = event.content;
var cube_mesh = new THREE.Mesh(geometry);
cube_mesh.position.x = -7;
var cube_bsp = new ThreeBSP(cube_mesh);
//Create a sphere
var sphere_geometry = new THREE.SphereGeometry(1.8, 32, 32);
var sphere_mesh = new THREE.Mesh(sphere_geometry);
sphere_mesh.position.x = -7;
var sphere_bsp = new ThreeBSP(sphere_mesh);
//subtract cube from sphere
var subtract_bsp = cube_bsp.subtract(sphere_bsp);
var result = subtract_bsp.toMesh(new THREE.MeshLambertMaterial({shading:  THREE.SmoothShading, map: THREE.ImageUtils.loadTexture('texture.png')}));
result.geometry.computeVertexNormals();
scene.add(result);

});
loader.load(filePath);
}

但它似乎不起作用。我正在使用three.js R62并使用STLLoader.js导入STL文件。

But it doesn't seem to work. I am using three.js R62 and importing a STL file using the STLLoader.js.

我刚刚开始学习Three.js而不完全确定导入的网格文件由ThreeCSG.js支持。但是,在理论上,CSG操作应该对导入的网格文件起作用,因为它们处理程序中创建的网格几何。

I have just started learning Three.js and not entirely sure if the imported mesh files are supported by ThreeCSG.js. However, in thoery the CSG operations should work on the imported mesh files as they work on the mesh geometries created within the program.

有任何建议吗?

推荐答案

好的,我自己想出了答案。对于任何初学者都是three.js的人来说,了解UVs纹理映射的概念非常重要。请参阅此处 http://wiki.blender.org/index .PHP /文件:2.6 /手动/纹理/制图/ UV 。现在,没有UV协议。在STL文件中可用,因此许多three.js函数不能按预期工作。一种方法,我发现克服这个问题是在混合器中导入STL文件并执行UV映射,然后将几何文件导出为JSON对象(您还需要使用blender安装three.js导出器)。然后,您可以使用three.js

OK figured out the answer myself. For anyone who is a beginner with three.js, it is important to understand the concept of UVs texture mapping. See here http://wiki.blender.org/index.php/Doc:2.6/Manual/Textures/Mapping/UV. Now, there is no UV co-ords. available in the STL files so many of the three.js functions don't work as desired. One way, I found to overcome this issue was to import the STL files in blender and perform a UV mapping and then export the geometry files as a JSON object (You will also need to install a three.js exporter with blender). You can then perform Boolean operations on the JSON geometries with three.js

这篇关于使用STLLoader进行CSG操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆