Compare commits
No commits in common. "c101c2f2f887352316b07ffd057bd4cc0305710e" and "d62a1e73576d50e45310c2d0c0649cd24868f5b6" have entirely different histories.
c101c2f2f8
...
d62a1e7357
43
app.js
43
app.js
@ -1,52 +1,31 @@
|
|||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
import * as T from 'three';
|
import * as T from 'three';
|
||||||
import { VertexNormalsHelper } from 'three/examples/jsm/helpers/VertexNormalsHelper.js';
|
//import { FaceNormalsHelper } from 'three/examples/jsm/helpers/FaceNormalsHelper.js';
|
||||||
import { Scene } from './scene.js';
|
import { Scene } from './scene.js';
|
||||||
import Region from "./region.js";
|
import Region from "./region.js";
|
||||||
|
|
||||||
let voxels = [];
|
let voxels = [];
|
||||||
voxels[Region.I(0, 0, 0)] = true;
|
voxels[Region.I(0, 0, 0)] = true;
|
||||||
voxels[Region.I(1, 0, 0)] = true;
|
|
||||||
voxels[Region.I(1, 1, 0)] = true;
|
|
||||||
voxels[Region.I(1, 2, 0)] = true;
|
|
||||||
|
|
||||||
|
|
||||||
let surfaceCubeGeometry = new T.BufferGeometry();
|
let surfaceCubeGeometry = new T.BufferGeometry();
|
||||||
surfaceCubeGeometry.setAttribute("position", new T.BufferAttribute(new Float32Array(), 3));
|
|
||||||
let surfaceCubeObject = new T.Mesh(
|
let surfaceCubeObject = new T.Mesh(
|
||||||
surfaceCubeGeometry,
|
surfaceCubeGeometry,
|
||||||
new T.MeshPhongMaterial({color:0x666666, wireframe:false, flatShading:false, side:T.BackSide})
|
new T.MeshPhongMaterial({color:0x666666, wireframe:false, flatShading:true, side:T.BackSide})
|
||||||
);
|
);
|
||||||
|
|
||||||
let surfaceCubeNormalHelper;
|
//var vnh = new FaceNormalsHelper( surfaceCubeObject, 1, 0xff0000 );
|
||||||
|
|
||||||
let rebuildSurface = inVoxels =>
|
let rebuildSurface = inVoxels =>
|
||||||
{
|
{
|
||||||
let { pos, ind } = Region.Surface(inVoxels);
|
let { pos, ind } = Region.Surface(inVoxels);
|
||||||
|
|
||||||
let surfaceCubePositions = new T.BufferAttribute(pos, 3);
|
surfaceCubeGeometry.setAttribute("position", new T.BufferAttribute(pos, 3));
|
||||||
surfaceCubePositions.setUsage( T.DynamicDrawUsage );
|
|
||||||
|
|
||||||
surfaceCubeGeometry.dispose();
|
|
||||||
surfaceCubeGeometry = new T.BufferGeometry();
|
|
||||||
surfaceCubeGeometry.setAttribute("position", surfaceCubePositions);
|
|
||||||
surfaceCubeGeometry.setIndex(ind);
|
surfaceCubeGeometry.setIndex(ind);
|
||||||
surfaceCubeGeometry.computeVertexNormals();
|
|
||||||
surfaceCubeObject.geometry = surfaceCubeGeometry;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
rebuildSurface(voxels);
|
rebuildSurface(voxels);
|
||||||
|
|
||||||
surfaceCubeNormalHelper = new VertexNormalsHelper( surfaceCubeObject, -0.2 );
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const hitHelper = new T.Mesh
|
|
||||||
(
|
|
||||||
new T.BoxGeometry( 0.2, 0.2, 0.2 ),
|
|
||||||
new T.MeshBasicMaterial( {color: 0x00ff00} )
|
|
||||||
);
|
|
||||||
|
|
||||||
Scene({
|
Scene({
|
||||||
DOM:"canvas",
|
DOM:"canvas",
|
||||||
@ -54,15 +33,10 @@ Scene({
|
|||||||
{
|
{
|
||||||
let light = new T.PointLight(0xffffff, 1, 100)
|
let light = new T.PointLight(0xffffff, 1, 100)
|
||||||
light.position.set(5, 5, -5);
|
light.position.set(5, 5, -5);
|
||||||
inScene.add(light);
|
inScene.add(light)
|
||||||
|
|
||||||
inScene.add(surfaceCubeObject);
|
inScene.add(surfaceCubeObject);
|
||||||
|
inScene.add(new T.GridHelper(10, 10));
|
||||||
//inScene.add(new T.GridHelper(10, 10));
|
|
||||||
inScene.add(new T.AxesHelper( 5 ));
|
inScene.add(new T.AxesHelper( 5 ));
|
||||||
|
|
||||||
inScene.add( hitHelper );
|
|
||||||
inScene.add( surfaceCubeNormalHelper );
|
|
||||||
},
|
},
|
||||||
Update(inScene, inScreen, inDelta)
|
Update(inScene, inScreen, inDelta)
|
||||||
{
|
{
|
||||||
@ -78,16 +52,11 @@ Scene({
|
|||||||
if(hits[i].distance < hit.distance)
|
if(hits[i].distance < hit.distance)
|
||||||
{
|
{
|
||||||
hit = hits[i];
|
hit = hits[i];
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
index = Region.I(Math.floor(hit.point.x), Math.floor(hit.point.y), Math.floor(hit.point.z));
|
index = Region.I(Math.floor(hit.point.x), Math.floor(hit.point.y), Math.floor(hit.point.z));
|
||||||
voxels[index] = true;
|
voxels[index] = true;
|
||||||
rebuildSurface(voxels);
|
rebuildSurface(voxels);
|
||||||
inScene.remove(surfaceCubeNormalHelper);
|
|
||||||
surfaceCubeNormalHelper = new VertexNormalsHelper( surfaceCubeObject, -0.2 );
|
|
||||||
inScene.add(surfaceCubeNormalHelper);
|
|
||||||
hitHelper.position.set(hit.point.x, hit.point.y, hit.point.z);
|
|
||||||
console.log(index, hit);
|
console.log(index, hit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user