0

我正在对立方体和球体进行一些简单的 CSG 操作.. 为此,我在进行操作后使用了三个 csg.js 库形式“https://github.com/manthrax/THREE-CSGMesh”,我收到了类似“ Uncaught SyntaxError: The requested module './three-csg.js' does not provide an export named 'CSG'"
编码如下,并且还根据需要添加了其他两个库(csg-lib.js,csg-lib.js )

import { CSG } from "./three-csg.js";

// -----------------------------------------------------(scene, camera, renderer are defined)

const cubegeometry = new THREE.BoxGeometry( 0.02, 0.02, 0.02 );
const cubematerial = new THREE.MeshBasicMaterial( {color: 0x00ff00,} );
const cube = new THREE.Mesh( cubegeometry, cubematerial );
const cubegeometry = new THREE.BoxGeometry( 0.02, 0.02, 0.02 );
const cubematerial = new THREE.MeshBasicMaterial( {color: 0x00ff00,} );
const cube = new THREE.Mesh( cubegeometry, cubematerial );
const cubeCSG   = CSG.fromMesh(cube);
const sphereCSG = CSG.fromMesh(sphere);
const resultCSG = cubeCSG.subtract(sphereCSG); 
const CSGmaterial = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
const meshCSG = CSG.toMesh( resultCSG );
meshCSG.material = CSGmaterial;

scene.add( meshCSG );
4

1 回答 1

0

你看过演示的源代码吗?您需要做的就是删除花括号

import CSG from "./three-csg.js";
于 2021-08-17T19:28:22.123 回答