Created
July 22, 2015 09:33
-
-
Save gidili/a5fd2d1b037fc2341409 to your computer and use it in GitHub Desktop.
modification to selection logic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Set up the listeners use to detect mouse movement and windoe resizing | |
*/ | |
var setupListeners = function() { | |
if(!VARS.listenersCreated){ | |
// when the mouse moves, call the given function | |
VARS.renderer.domElement.addEventListener('mousedown', function(event) { | |
var intersects = GEPPETTO.getIntersectedObjects(); | |
if ( intersects.length > 0 ) { | |
var selected = ""; | |
// sort intersects | |
var compare = function(a,b) { | |
if (a.distance < b.distance) | |
return -1; | |
if (a.distance > b.distance) | |
return 1; | |
return 0; | |
} | |
intersects.sort(compare); | |
// Iterate and get the first visible item (they are now ordered by proximity) | |
for(var i = 0; i<intersects.length; i++){ | |
// figure out if the entity is visible | |
var instancePath = intersects[ i ].object.name; | |
var visible = eval(instancePath + '.visible'); | |
if(visible){ | |
selected = instancePath; | |
break; | |
} | |
} | |
if(selected == ""){ | |
selected = intersects[ 0 ].object.parent.name; | |
} | |
if (VARS.meshes.hasOwnProperty(selected) || VARS.splitMeshes.hasOwnProperty(selected)) { | |
GEPPETTO.G.unSelectAll(); | |
GEPPETTO.Console.executeCommand(selected + '.select()'); | |
} | |
} | |
}, false); | |
VARS.renderer.domElement.addEventListener('mousemove', function(event) { | |
VARS.mouse.x = (event.clientX / window.innerWidth) * 2 - 1; | |
VARS.mouse.y = -(event.clientY / window.innerHeight) * 2 + 1; | |
}, false); | |
window.addEventListener('resize', function() { | |
var container = $(VARS.container), | |
width = container.width(), | |
height = container.height(); | |
VARS.camera.aspect = (width) / (height); | |
VARS.camera.updateProjectionMatrix(); | |
VARS.renderer.setSize(width, height); | |
}, false); | |
document.addEventListener("keydown", GEPPETTO.Vanilla.checkKeyboard, false); | |
VARS.listenersCreated = true; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment