simpleFace demo
by jmchen
HTML
<script src="http://je0606ff.github.io/Project/js/r69/three.min.js"></script>
JavaScript
function Vertex(x, y, z) {
this.xyz = new THREE.Vector3(x, y, z);
this.nxyz = new THREE.Vector3(x, y, z);
this.norm = new THREE.Vector3();
this.plist = [];
}
function Polygon() {
this.vertices = [];
this.norm = new THREE.Vector3(); /// polygon normal,
///// for computing vertex normal
}
/*
var v1 = new Vertex(0, 55, 2),
v2 = new Vertex(0, 5, 2),
v3 = new Vertex(5, 5, 5);
var indices = [];
indices.push(v1);
indices.push(v2);
indices.push(v3);
console.log(indices.length);
console.log(indices.indexOf(v2));
*/
var polylineDat = [0, 1, 2, 1, 2, 3, 1, -1, 1, 13,12,11];
var indexDat = [999, 1, 2, 3, 999, 1,2,4];
function Head() {
this.polygons = [];
this.vertices = [];
}
function make_vertices() {
var nVertex = polylineDat.length / 3;
for (var i = 0; i < nVertex; i++) {
var v = new Vertex(polylineDat[i * 3], polylineDat[i * 3 + 1], polylineDat[i * 3 + 2]);
head.vertices.push(v);
}
}
function make_face() {
make_vertices();
var npolygons = indexDat.length/4;
for (var i = 0; i < npolygons; i++) {
var p = new Polygon();
if (indexDat[4*i] === 999) {
var v1 = head.vertices[indexDat[4*i+1]-1];
var v2 = head.vertices[indexDat[4*i+2]-1];
var v3 = head.vertices[indexDat[4*i+3]-1];
p.vertices.push (v1);
p.vertices.push (v2);
p.vertices.push (v3);
// add_polygon_to_face
head.polygons.push (p);
v1.plist.push (p);
v2.plist.push (p);
v3.plist.push (p);
} else {
}
}
}
var head = new Head();
make_face();
console.log (head);