Compare commits

..

No commits in common. "4078e026efcbc02085d520ca95340b4c8647f0c7" and "13b0384c54a4b509886a0c9f7d83eef2c283a122" have entirely different histories.

3 changed files with 55 additions and 65 deletions

View File

@ -20,41 +20,18 @@
<body> <body>
<canvas></canvas> <canvas></canvas>
<script type="module"> <script type="module">
import { Scene, THREE } from './scene.js';
import { Region } from "./region.js"; import { Region } from "./region.js";
let surfaceTest = () =>
{
let voxels = []; let voxels = [];
voxels[Region.I(2, 2, 2)] = true; voxels[Region.I(2, 2, 2)] = true;
voxels[Region.I(2, 3, 2)] = true; voxels[Region.I(3, 2, 2)] = true;
let surface = Region.Surface(voxels) console.log(Region.Surface(voxels));
console.log(surface);
let surfaceGeometry = new THREE.BufferGeometry(); </script>
surfaceGeometry.setAttribute('position', new THREE.BufferAttribute(surface.vert, 3) ); <!--
surfaceGeometry.setIndex(surface.triPointVert); <script type="module">
surfaceGeometry.computeVertexNormals(); import { Scene, THREE } from './scene.js';
let surfaceObject = new THREE.Mesh(
surfaceGeometry,
new THREE.MeshBasicMaterial({color:0xaa9900, wireframe:true})
);
return {
DOM:"canvas",
Init(inScene)
{
inScene.add(surfaceObject);
inScene.add(new THREE.GridHelper(10, 10));
},
Update(inScene, inDelta){}
};
}
let smoothTest = () =>
{
let average = (inArray, inPointInd, ...inOthersInd) => let average = (inArray, inPointInd, ...inOthersInd) =>
{ {
let sum = [0, 0, 0]; let sum = [0, 0, 0];
@ -115,6 +92,19 @@ let smoothTest = () =>
} }
} }
} }
/*
let testPoints =
[
0, 0, 0,
0, 1, 0,
1, 1, 0
];
console.log(testPoints);
average(testPoints, 1, 0, 2);
console.log(testPoints);
*/
let path = (inPoints, inSmoothing, inColor) => let path = (inPoints, inSmoothing, inColor) =>
{ {
let clone = [...inPoints]; let clone = [...inPoints];
@ -129,6 +119,7 @@ let smoothTest = () =>
output.add( new THREE.Points( geometry, materialPoint ) ); output.add( new THREE.Points( geometry, materialPoint ) );
return output; return output;
} }
const points = const points =
[ [
4, 0, 0, 4, 0, 0,
@ -151,7 +142,10 @@ let smoothTest = () =>
5, 0, 0, 5, 0, 0,
]; ];
return {
/*
Scene(
{
DOM:"canvas", DOM:"canvas",
Init(inScene) Init(inScene)
{ {
@ -163,9 +157,8 @@ let smoothTest = () =>
} }
} }
}; );
*/
Scene(surfaceTest());
</script> </script>

View File

@ -104,19 +104,17 @@ export const Region =
{ {
let [x, y, z] = Region.XYZ(i); let [x, y, z] = Region.XYZ(i);
console.log("at", x, y, z);
// bottom: at, "up", corner, right // bottom: at, "up", corner, right
BA = i; BA = i;
BU = Region.I(x, y+1, z ); BU = Region.I(x+1, y, z);
BC = Region.I(x+1, y+1, z); BC = Region.I(x+1, y+1, z);
BR = Region.I(x+1, y, z ); BR = Region.I(x, y+1, z);
// top: at, "up" corner, right // top: at, "up" corner, right
TA = Region.I(x, y, z+1); TA = Region.I(x, y, z+1);
TU = Region.I(x, y+1, z+1); TU = Region.I(x+1, y, z+1);
TC = Region.I(x+1, y+1, z+1); TC = Region.I(x+1, y+1, z+1);
TR = Region.I(x+1, y, z+1); TR = Region.I(x, y+1, z+1);
// check: left, "down", below // check: left, "down", below
CL = Region.I(x-1, y, z); CL = Region.I(x-1, y, z);
@ -133,6 +131,6 @@ export const Region =
} }
} }
return {vert:new Float32Array(vertices.flat()), voxPointVert, triPointVert, vertPointNeighbors}; return {vertices, voxPointVert, triPointVert, vertPointNeighbors};
} }
}; };

View File

@ -6,7 +6,7 @@ export function Scene(inSettings)
{ {
const renderer = new T.WebGLRenderer({canvas:document.querySelector(inSettings.DOM)}); const renderer = new T.WebGLRenderer({canvas:document.querySelector(inSettings.DOM)});
const scene = new T.Scene(); const scene = new T.Scene();
const camera = new T.PerspectiveCamera(80, 2, 0.1, 100); const camera = new T.PerspectiveCamera(80, 2, 0.1, 10);
const light = new T.DirectionalLight(0xFFFFFF, 1); const light = new T.DirectionalLight(0xFFFFFF, 1);
const controls = new OrbitControls(camera, renderer.domElement); const controls = new OrbitControls(camera, renderer.domElement);
let dirty = false; let dirty = false;
@ -45,8 +45,7 @@ export function Scene(inSettings)
scene.add(light); scene.add(light);
//scene.add(new T.GridHelper(10, 10)); //scene.add(new T.GridHelper(10, 10));
light.position.set(-1, 2, 4); light.position.set(-1, 2, 4);
camera.position.set(0, 5, 5); camera.position.set(0, 0, 2);
camera.lookAt(new T.Vector3(0,0,0));
controls.update(); controls.update();
inSettings.Init(scene); inSettings.Init(scene);