// @ts-check import * as T from 'three'; //import { FaceNormalsHelper } from 'three/examples/jsm/helpers/FaceNormalsHelper.js'; import { Scene } from './scene.js'; import Region from "./region.js"; let voxels = []; voxels[Region.I(0, 0, 0)] = true; let surfaceCubeGeometry = new T.BufferGeometry(); let surfaceCubeObject = new T.Mesh( surfaceCubeGeometry, new T.MeshPhongMaterial({color:0x666666, wireframe:false, flatShading:true, side:T.BackSide}) ); //var vnh = new FaceNormalsHelper( surfaceCubeObject, 1, 0xff0000 ); let rebuildSurface = inVoxels => { let { pos, ind } = Region.Surface(inVoxels); surfaceCubeGeometry.setAttribute("position", new T.BufferAttribute(pos, 3)); surfaceCubeGeometry.setIndex(ind); //surfaceCubeGeometry.computeVertexNormals(); }; rebuildSurface(voxels); Scene({ DOM:"canvas", Init(inScene) { let light = new T.PointLight(0xffffff, 1, 100) light.position.set(5, 5, -5); inScene.add(light) inScene.add(surfaceCubeObject); inScene.add(new T.GridHelper(10, 10)); inScene.add(new T.AxesHelper( 5 )); }, Update(inScene, inScreen, inDelta) { var i, hits, hit, index; if(inScreen.Drag > 0) { hits = inScreen.Ray.intersectObject(surfaceCubeObject); if(hits.length) { hit = hits[0]; for(i=1; i { let centerX = Math.round(x); let centerY = Math.round(y); let centerZ = Math.round(z); let deltaX = ax-centerX; let deltaY = ay-centerY; let deltaZ = az-centerZ; let absDeltaX = Math.abs(deltaX); let absDeltaY = Math.abs(deltaY); let absDeltaZ = Math.abs(deltaZ); let max = absDeltaX; if(absDeltaY > max){ max = absDeltaY; } if(absDeltaZ > max){ max = absDeltaZ; } let lerp = 0.49/max; if(lerp <= 1) { return [ centerX + deltaX*lerp, centerY + deltaY*lerp, centerZ + deltaZ*lerp ]; } else { return [ax, ay, az]; } } let average = (inArray, inPointInd, inOthersIndArray) => { let sum = [0, 0, 0]; for(let i=0; i { let count = inVertsArray.length/3; for(let t=0; t