diff --git a/js/elementMenu.js b/js/elementMenu.js index 035c212de2fcd04f6fa7b1d2bf5e93ed46251c0f..571878e9fe572f7fb0800f5f1f4d68bd26ead93f 100644 --- a/js/elementMenu.js +++ b/js/elementMenu.js @@ -16,40 +16,44 @@ $(function(){ var boundingBox = new THREE.Box3(); boundingBox.setFromObject(modelMesh); - var xRange = []; - for (var x=boundingBox.min.x;x<boundingBox.max.x;x+=cubeDim){ - xRange.push(x); - } +// var xRange = []; +// for (var x=boundingBox.min.x;x<boundingBox.max.x;x+=cubeDim){ +// xRange.push(x); +// } +// +// var threads = new Parallel(xRange, {env:{boundingBox:boundingBox, three:three, cubeDim:cubeDim, modelMesh:modelMesh}}).require( +// {fn:THREE.Vector3,name:'Vector3'}, {fn:THREE.Raycaster,name:'Raycaster'}, {fn:THREE.Ray,name:'Ray'}, +// createCubeGeometry, {fn:THREE.BoxGeometry,name:'BoxGeometry'}, {fn:THREE.MeshLambertMaterial,name:'MeshLambertMaterial'}, +// {fn:THREE.Geometry,name:'Geometry'} +// ); +// threads.map(fillWithElements).then(three.render); +// +// function fillWithElements(x){ +// var cubeDim = global.env.cubeDim; - var threads = new Parallel(xRange, {env:{boundingBox:boundingBox, three:three, cubeDim:cubeDim, modelMesh:modelMesh}}).require( - {fn:THREE.Vector3,name:'Vector3'}, {fn:THREE.Raycaster,name:'Raycaster'}, {fn:THREE.Ray,name:'Ray'}, - createCubeGeometry, {fn:THREE.BoxGeometry,name:'BoxGeometry'}, {fn:THREE.MeshLambertMaterial,name:'MeshLambertMaterial'}, - {fn:THREE.Geometry,name:'Geometry'} - ); - threads.map(fillWithElements).then(three.render); - - function fillWithElements(x){ - var cubeDim = global.env.cubeDim; - - for (var y=global.env.boundingBox.min.y;y<global.env.boundingBox.max.y;y+=cubeDim){ - for (var z=global.env.boundingBox.min.z;z<global.env.boundingBox.max.z;z+=cubeDim){ - var raycaster = new Raycaster(new Vector3(x+cubeDim/2, y+cubeDim/2, z+cubeDim/2), - new Vector3(0, 0, 1), 0, global.env.boundingBox.max.z-z+cubeDim/2); -// if (raycaster.intersectObject(global.env.modelMesh).length % 2 == 1) { + for (var x=boundingBox.min.x;x<boundingBox.max.x;x+=cubeDim){ + for (var y=boundingBox.min.y;y<boundingBox.max.y;y+=cubeDim){ +// if () + for (var z=boundingBox.min.z;z<boundingBox.max.z;z+=cubeDim){ + var raycaster = new THREE.Raycaster(new THREE.Vector3(x+cubeDim/2, y+cubeDim/2, z+cubeDim/2), + new THREE.Vector3(0, 0, 1), 0, boundingBox.max.z-z+cubeDim/2); + var numIntersections = raycaster.intersectObject(modelMesh).length; + if (numIntersections % 2 == 1) { var mesh = createCubeGeometry(cubeDim); mesh.position.set(x+cubeDim/2, y+cubeDim/2, z+cubeDim/2); mesh.updateMatrix(); mesh.matrixAutoUpdate = false; - global.env.three.scene.add(mesh); -// } + three.scene.add(mesh); + } else if (numIntersections == 0){ + } } } } }); function createCubeGeometry(size){ - var geometry = new BoxGeometry(size, size, size); - var material = new MeshLambertMaterial( { color:0xffffff} ); + var geometry = new THREE.BoxGeometry(size, size, size); + var material = new THREE.MeshLambertMaterial( { color:0xffffff} ); return new THREE.Mesh( geometry, material ); }