surface rendering
This commit is contained in:
parent
13b0384c54
commit
56147ed325
58
index.html
58
index.html
@ -20,18 +20,42 @@
|
|||||||
<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;
|
voxels[Region.I(3, 2, 2)] = true;
|
||||||
console.log(Region.Surface(voxels));
|
let surface = Region.Surface(voxels)
|
||||||
|
console.log(surface);
|
||||||
|
|
||||||
</script>
|
let surfaceGeometry = new THREE.BufferGeometry();
|
||||||
<!--
|
surfaceGeometry.setAttribute('position', new THREE.BufferAttribute(surface.vert, 3) );
|
||||||
<script type="module">
|
surfaceGeometry.setIndex(surface.triPointVert);
|
||||||
import { Scene, THREE } from './scene.js';
|
surfaceGeometry.computeVertexNormals();
|
||||||
|
|
||||||
|
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];
|
||||||
@ -92,19 +116,6 @@ console.log(Region.Surface(voxels));
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
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];
|
||||||
@ -119,7 +130,6 @@ console.log(Region.Surface(voxels));
|
|||||||
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,
|
||||||
@ -142,10 +152,7 @@ console.log(Region.Surface(voxels));
|
|||||||
5, 0, 0,
|
5, 0, 0,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
return {
|
||||||
/*
|
|
||||||
Scene(
|
|
||||||
{
|
|
||||||
DOM:"canvas",
|
DOM:"canvas",
|
||||||
Init(inScene)
|
Init(inScene)
|
||||||
{
|
{
|
||||||
@ -157,8 +164,9 @@ console.log(Region.Surface(voxels));
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
};
|
||||||
*/
|
|
||||||
|
Scene(surfaceTest());
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -131,6 +131,6 @@ export const Region =
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {vertices, voxPointVert, triPointVert, vertPointNeighbors};
|
return {vert:new Float32Array(vertices.flat()), voxPointVert, triPointVert, vertPointNeighbors};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
5
scene.js
5
scene.js
@ -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, 10);
|
const camera = new T.PerspectiveCamera(80, 2, 0.1, 100);
|
||||||
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,7 +45,8 @@ 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, 0, 2);
|
camera.position.set(0, 5, -5);
|
||||||
|
camera.lookAt(new T.Vector3(0,0,0));
|
||||||
controls.update();
|
controls.update();
|
||||||
|
|
||||||
inSettings.Init(scene);
|
inSettings.Init(scene);
|
||||||
|
Loading…
Reference in New Issue
Block a user