diff --git a/index.html b/index.html
index b40a603..0125396 100644
--- a/index.html
+++ b/index.html
@@ -125,29 +125,33 @@ let surfaceTest = () =>
*/
- let surface = Region.Surface(voxels);
- let vertsCube = new Float32Array(surface.vertices.flat());
+/*
+ let testGeometry = new THREE.BufferGeometry();
+ let testAttribute = new THREE.BufferAttribute(new Float32Array(0));
+ testGeometry.setAttribute("position", testAttribute, 3);
+
+ console.log(testGeometry);
+ testAttribute.array = new Float32Array([1, 2, 3]);
+ testAttribute.needsUpdate = true;
+ console.log(testGeometry);
+*/
+
let surfaceCubeGeometry = new THREE.BufferGeometry();
- surfaceCubeGeometry.setAttribute('position', new THREE.BufferAttribute(vertsCube, 3) );
- surfaceCubeGeometry.setIndex(surface.triPointVert);
- surfaceCubeGeometry.computeVertexNormals(true);
let surfaceCubeObject = new THREE.Mesh(
surfaceCubeGeometry,
- new THREE.MeshBasicMaterial({color:0x666666, wireframe:true, side:THREE.DoubleSide})
+ new THREE.MeshPhongMaterial({color:0x666666, wireframe:false, flatShading:true, side:THREE.DoubleSide})
);
-
-
- let vertsSmooth = new Float32Array(smooth(surface.vertices.flat(), surface.vertPointNeighbors, 10));
- let surfaceSmoothGeometry = new THREE.BufferGeometry();
- surfaceSmoothGeometry.setAttribute('position', new THREE.BufferAttribute(vertsSmooth, 3) );
- surfaceSmoothGeometry.setIndex(surface.triPointVert);
- surfaceSmoothGeometry.computeVertexNormals(true);
- let surfaceSmoothObject = new THREE.Mesh(
- surfaceSmoothGeometry,
- new THREE.MeshBasicMaterial({color:0xffffff, wireframe:true, side:THREE.DoubleSide, flatShading:true})
- );
-
-
+
+ let rebuildSurface = inVoxels =>
+ {
+ let surface = Region.Surface(inVoxels);
+ let vertsCube = new Float32Array(surface.vertices.flat());
+
+ surfaceCubeGeometry.setAttribute("position", new THREE.BufferAttribute(vertsCube, 3));
+ surfaceCubeGeometry.setIndex(surface.triPointVert);
+ surfaceCubeGeometry.computeVertexNormals(true);
+ };
+ rebuildSurface(voxels);
return {
DOM:"canvas",
@@ -157,12 +161,34 @@ let surfaceTest = () =>
light.position.set(5, 5, -5);
inScene.add(light)
inScene.add(surfaceCubeObject);
- inScene.add(surfaceSmoothObject);
+ //inScene.add(surfaceSmoothObject);
inScene.add(new THREE.GridHelper(10, 10));
inScene.add(new THREE.AxesHelper( 5 ));
},
- Update(inScene, inDelta){}
+ 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
+ {
+ Screen.Event = e;
+ Screen.Dirty = true;
+ Screen.Mouse.x = ( e.clientX / renderer.domElement.clientWidth ) * 2 - 1;
+ Screen.Mouse.y = - ( e.clientY / renderer.domElement.clientHeight ) * 2 + 1;
+ Screen.Ray.setFromCamera( Screen.Mouse, Screen.Camera );
+ },
+ HandleMove:e=>
+ {
+ Screen.Drag = Screen.Down ? 2 : 0;
+ Screen.Update(e);
+ },
+ HandlePress:e=>
+ {
+ Screen.Down = true;
+ Screen.Drag = 1;
+ Screen.Update(e);
+ },
+ HandleRelease:e=>
+ {
+ Screen.Down = false;
+ Screen.Drag = 0;
+ Screen.Update(e);
+ }
+ };
+ renderer.domElement.addEventListener("pointermove", Screen.HandleMove);
+ renderer.domElement.addEventListener("pointerdown", Screen.HandlePress);
+ renderer.domElement.addEventListener("pointerup", Screen.HandleRelease);
+
+
const update = inTime =>
{
let timeNew = new Date();
let timeDelta = timeNew - inTime;
let delta = timeDelta * 0.001;
- inSettings.Update(scene, delta);
+ inSettings.Update(scene, Screen, delta);
+ Screen.Dirty = false;
controls.update();
dirty = true;