2

I want to work with THREE.js and especially with CSG, so that I can subtract two obj models from each other using boolean operations. For this purpose I import the respective local files in a central JavaScript file, so that I can work with them in it.

With THREE.js, OBJLoader2, etc. I have solved it that way:

import * as THREE from './three.module.js';

import {OBJLoader2} from './OBJLoader2.js';

import {MTLLoader} from './MTLLoader.js';

Then I can access the corresponding elements. (e.g. const objLoader = new OBJLoader2();) So I am currently able to import obj models and visualize them in a canvas element.

Unfortunately I can't do this for the CSG.js file.

I found the file here: https://github.com/evanw/csg.js/blob/master/csg.js.

How do I import the local CSG.js file into my central JavaScript file?

import * as CSGfrom './CSG.js';

import {CSG} from './CSG.js';

Both imports unfortunately do not work.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Mec-Eng
  • 199
  • 10

1 Answers1

-1

Use my csg library :) Its more robust than the existing csg library.

https://github.com/manthrax/THREE-CSGMesh

manthrax
  • 4,918
  • 1
  • 17
  • 16
  • Thank you very much for reply. How can I convert an Object3D into a mesh? – Mec-Eng Jan 04 '20 at 15:10
  • 1
    function convert2BSP (object) { var BSP; object.traverse( function ( child ) { //console.dir(child); if ( child instanceof THREE.Mesh ) { //console.dir(child); BSP = child.clone(); BSP = CSG.fromMesh(BSP); } }); return BSP; } » I get the Mesh of the Object3D, but how can I Subtract? – Mec-Eng Jan 04 '20 at 15:52
  • 1
    Thank your very much, it works with your library :) – Mec-Eng Jan 04 '20 at 16:04