|
@@ -38,6 +38,8 @@
|
|
|
var cubeGeo, cubeMaterial;
|
|
|
var i, intersector;
|
|
|
|
|
|
+ var objects = [];
|
|
|
+
|
|
|
init();
|
|
|
animate();
|
|
|
|
|
@@ -51,7 +53,7 @@
|
|
|
info.style.top = '10px';
|
|
|
info.style.width = '100%';
|
|
|
info.style.textAlign = 'center';
|
|
|
- info.innerHTML = '<a href="http://threejs.org" target="_blank">three.js</a> - voxel painter - webgl<br><strong>click</strong>: add voxel, <strong>control + click</strong>: remove voxel, <strong>shift + click</strong>: rotate';
|
|
|
+ info.innerHTML = '<a href="http://threejs.org" target="_blank">three.js</a> - voxel painter - webgl<br><strong>click</strong>: add voxel, <strong>shift + click</strong>: remove voxel, <strong>control</strong>: rotate';
|
|
|
container.appendChild( info );
|
|
|
|
|
|
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 10000 );
|
|
@@ -103,6 +105,8 @@
|
|
|
plane.visible = false;
|
|
|
scene.add( plane );
|
|
|
|
|
|
+ objects.push( plane );
|
|
|
+
|
|
|
mouse2D = new THREE.Vector3( 0, 10000, 0.5 );
|
|
|
|
|
|
// Lights
|
|
@@ -165,6 +169,12 @@
|
|
|
|
|
|
function setVoxelPosition( intersector ) {
|
|
|
|
|
|
+ if ( intersector.face === null ) {
|
|
|
+
|
|
|
+ console.log( intersector )
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
normalMatrix.getNormalMatrix( intersector.object.matrixWorld );
|
|
|
|
|
|
tmpVec.copy( intersector.face.normal );
|
|
@@ -188,7 +198,7 @@
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
- var intersects = raycaster.intersectObjects( scene.children );
|
|
|
+ var intersects = raycaster.intersectObjects( objects );
|
|
|
|
|
|
if ( intersects.length > 0 ) {
|
|
|
|
|
@@ -196,12 +206,14 @@
|
|
|
|
|
|
// delete cube
|
|
|
|
|
|
- if ( isCtrlDown ) {
|
|
|
+ if ( isShiftDown ) {
|
|
|
|
|
|
if ( intersector.object != plane ) {
|
|
|
|
|
|
scene.remove( intersector.object );
|
|
|
|
|
|
+ objects.splice( objects.indexOf( intersector.object ), 1 );
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// create cube
|
|
@@ -217,6 +229,8 @@
|
|
|
voxel.updateMatrix();
|
|
|
scene.add( voxel );
|
|
|
|
|
|
+ objects.push( voxel );
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -257,7 +271,7 @@
|
|
|
|
|
|
function render() {
|
|
|
|
|
|
- if ( isShiftDown ) {
|
|
|
+ if ( isCtrlDown ) {
|
|
|
|
|
|
theta += mouse2D.x * 1.5;
|
|
|
|
|
@@ -265,7 +279,7 @@
|
|
|
|
|
|
raycaster = projector.pickingRay( mouse2D.clone(), camera );
|
|
|
|
|
|
- var intersects = raycaster.intersectObjects( scene.children );
|
|
|
+ var intersects = raycaster.intersectObjects( objects );
|
|
|
|
|
|
if ( intersects.length > 0 ) {
|
|
|
|