normals helper
This commit is contained in:
parent
d62a1e7357
commit
594c6ac8dc
28
app.js
28
app.js
@ -1,7 +1,7 @@
|
||||
// @ts-check
|
||||
|
||||
import * as T from 'three';
|
||||
//import { FaceNormalsHelper } from 'three/examples/jsm/helpers/FaceNormalsHelper.js';
|
||||
import { VertexNormalsHelper } from 'three/examples/jsm/helpers/VertexNormalsHelper.js';
|
||||
import { Scene } from './scene.js';
|
||||
import Region from "./region.js";
|
||||
|
||||
@ -12,10 +12,11 @@ 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})
|
||||
new T.MeshPhongMaterial({color:0x666666, wireframe:false, flatShading:true, side:T.DoubleSide})
|
||||
);
|
||||
|
||||
//var vnh = new FaceNormalsHelper( surfaceCubeObject, 1, 0xff0000 );
|
||||
|
||||
let surfaceCubeNormalHelper;
|
||||
|
||||
let rebuildSurface = inVoxels =>
|
||||
{
|
||||
@ -23,9 +24,21 @@ let rebuildSurface = inVoxels =>
|
||||
|
||||
surfaceCubeGeometry.setAttribute("position", new T.BufferAttribute(pos, 3));
|
||||
surfaceCubeGeometry.setIndex(ind);
|
||||
|
||||
surfaceCubeGeometry.computeVertexNormals();
|
||||
if(surfaceCubeNormalHelper) surfaceCubeNormalHelper.update();
|
||||
};
|
||||
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({
|
||||
DOM:"canvas",
|
||||
@ -33,10 +46,15 @@ Scene({
|
||||
{
|
||||
let light = new T.PointLight(0xffffff, 1, 100)
|
||||
light.position.set(5, 5, -5);
|
||||
inScene.add(light)
|
||||
inScene.add(light);
|
||||
|
||||
inScene.add(surfaceCubeObject);
|
||||
|
||||
inScene.add(new T.GridHelper(10, 10));
|
||||
inScene.add(new T.AxesHelper( 5 ));
|
||||
|
||||
inScene.add( hitHelper );
|
||||
inScene.add( surfaceCubeNormalHelper );
|
||||
},
|
||||
Update(inScene, inScreen, inDelta)
|
||||
{
|
||||
@ -52,11 +70,13 @@ Scene({
|
||||
if(hits[i].distance < hit.distance)
|
||||
{
|
||||
hit = hits[i];
|
||||
|
||||
}
|
||||
}
|
||||
index = Region.I(Math.floor(hit.point.x), Math.floor(hit.point.y), Math.floor(hit.point.z));
|
||||
voxels[index] = true;
|
||||
rebuildSurface(voxels);
|
||||
hitHelper.position.set(hit.point.x, hit.point.y, hit.point.z);
|
||||
console.log(index, hit);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user