11import { GUI } from 'dat.gui' ;
2- import { AmbientLight , BufferGeometry , Color , DoubleSide , Float32BufferAttribute ,
2+ import { AmbientLight , BackSide , BufferGeometry , Color , Float32BufferAttribute ,
3+ FrontSide ,
34 LineBasicMaterial , LineSegments , Mesh , MeshPhongMaterial , PerspectiveCamera ,
45 PointLight , Scene , Triangle , Vector3 , WebGLRenderer } from 'three' ;
56import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js' ;
@@ -11,10 +12,10 @@ const struct = new HalfedgeDS();
1112
1213const params = {
1314 shape : Shape . Sphere ,
14- holes : 0 ,
15+ holes : 30 ,
1516}
1617
17- const bgColor = 0x555555 ;
18+ const bgColor = 0x444444 ;
1819
1920// Init renderer
2021const renderer = new WebGLRenderer ( { antialias : true } ) ;
@@ -62,19 +63,25 @@ window.addEventListener('resize', function () {
6263} , false ) ;
6364
6465// Init mesh
65- const meshMaterial = new MeshPhongMaterial ( {
66- color : 0x777777 ,
66+ const meshFrontMaterial = new MeshPhongMaterial ( {
67+ color : 0x555577 ,
6768 flatShading : true ,
68- side : DoubleSide ,
69+ side : FrontSide ,
6970} ) ;
70- const mesh = new Mesh ( new BufferGeometry ( ) , meshMaterial ) ;
71+ const meshBackMaterial = new MeshPhongMaterial ( {
72+ color : 0x333355 ,
73+ flatShading : true ,
74+ side : BackSide ,
75+ } )
76+ const mesh = new Mesh ( new BufferGeometry ( ) , meshFrontMaterial ) ;
77+ const backMesh = new Mesh ( mesh . geometry , meshBackMaterial ) ;
7178scene . add ( mesh ) ;
79+ scene . add ( backMesh ) ;
7280
7381// Init half edges visualizations
7482const structMaterial = new LineBasicMaterial ( {
7583 depthTest : true ,
7684 depthWrite : false ,
77- side : DoubleSide ,
7885 vertexColors : true ,
7986} ) ;
8087
@@ -182,20 +189,22 @@ function updateHolesGui() {
182189 const index = mesh . geometry . getIndex ( ) ;
183190 const position = mesh . geometry . getAttribute ( 'position' ) ;
184191 const nbOfFaces = index ? index . count / 3 : position . count / 3 ;
185- holesGUI . max ( nbOfFaces / 3 ) ;
186- params . holes = Math . min ( params . holes , nbOfFaces / 3 ) ;
192+ holesGUI . max ( nbOfFaces / 2 ) ;
193+ params . holes = Math . min ( params . holes , nbOfFaces / 2 ) ;
187194 holesGUI . setValue ( params . holes ) ;
188195}
189196
190197function shapeChanged ( ) {
191198 setupMeshGeometry ( mesh , params . shape ) ;
199+ backMesh . geometry = mesh . geometry ;
192200 updateHolesGui ( ) ;
193201 build ( ) ;
194202}
195203
196204
197205const debounceBuild = debounce ( 200 , ( ) => {
198206 setupMeshGeometry ( mesh , params . shape ) ;
207+ backMesh . geometry = mesh . geometry ;
199208 removeTrianglesFromGeometry ( mesh . geometry , params . holes ) ;
200209 struct . clear ( ) ;
201210 const startTime = performance . now ( ) ;
0 commit comments