diff options
author | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-03 00:30:36 +0000 |
---|---|---|
committer | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-03 00:30:36 +0000 |
commit | 8dc465e39dd10bd23a4f24481d2bf146404596a7 (patch) | |
tree | e0da44eaee7bd4402a9844e1b68c50149cd290dd /o3d/samples/picking.html | |
parent | acaae862120b887d04432fd81e2c2c47cbd1256c (diff) | |
download | chromium_src-8dc465e39dd10bd23a4f24481d2bf146404596a7.zip chromium_src-8dc465e39dd10bd23a4f24481d2bf146404596a7.tar.gz chromium_src-8dc465e39dd10bd23a4f24481d2bf146404596a7.tar.bz2 |
Updates the picking library to have a PickManager and
support both not picking invisible objects and
the option to pick even if invisible.
The idea is you can do something like this
// Make a picking manager
var pm = o3djs.picking.createPickManager(rootTransform);
... // add a bunch of transforms.
// generate picking objects.
pm.update();
// Get the picking object that was created for some specific transform
var info = pm.getTransformInfo(someTransform);
// Set properties on that object related to picking
info.pickEvenIfInvisible = true;
I think this is just a first step. How an object should
be defined as pickable is up for debate. As it is,
you can basically override info.isPickable.
as in
info.isPickable = function() {
// do something custom.
}
You can also start adding things easier like
info.onPick = function() {
// do something.
}
and then write code like
info = pm.pick(worldRay);
if (info) {
info.onPick();
}
While you could have done that before there was no
easy way to find a the TransformInfo for a
specific Transform. Now you can use
PickManager.getTransformInfo
Review URL: http://codereview.chromium.org/452027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33632 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/samples/picking.html')
-rw-r--r-- | o3d/samples/picking.html | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/o3d/samples/picking.html b/o3d/samples/picking.html index f4a73a0..3466ff5 100644 --- a/o3d/samples/picking.html +++ b/o3d/samples/picking.html @@ -81,7 +81,7 @@ var g_math; var g_client; var g_pack; var g_viewInfo; -var g_treeInfo; // information about the transform graph. +var g_pickManager; // information about the transform graph. var g_pickInfoElem; var g_debugHelper; var g_debugLineGroup; @@ -93,11 +93,10 @@ var g_highlightShape; var g_finished = false; // for selenium testing. function updateInfo() { - if (!g_treeInfo) { - g_treeInfo = o3djs.picking.createTransformInfo(g_client.root, - null); + if (!g_pickManager) { + g_pickManager = o3djs.picking.createPickManager(g_client.root); } - g_treeInfo.update(); + g_pickManager.update(); } function unSelectAll() { @@ -108,6 +107,8 @@ function unSelectAll() { o3djs.shape.deleteDuplicateShape(g_highlightShape, g_pack); g_highlightShape = null; g_selectedInfo = null; + // Turn off the debug line. + g_debugLine.setVisible(false); } } @@ -152,9 +153,9 @@ function pick(e) { // transform graph and only pick against that subgraph. // Even better, make a separate transform graph with only cubes on it to // represent the animals and use that instead of the actual animals. - g_treeInfo.update(); + g_pickManager.update(); - var pickInfo = g_treeInfo.pick(worldRay); + var pickInfo = g_pickManager.pick(worldRay); if (pickInfo) { select(pickInfo); g_pickInfoElem.innerHTML = pickInfo.shapeInfo.shape.name; @@ -188,7 +189,6 @@ function pick(e) { g_debugLine.setVisible(true); g_debugLine.setEndPoints(worldPosition, normalSpot); } else { - g_debugLine.setVisible(false); g_pickInfoElem.innerHTML = '--nothing--'; } } @@ -198,9 +198,9 @@ function onrender(renderEvent) { g_flashTimer = g_flashTimer % 0.5; if (g_selectedInfo) { if (g_flashTimer < 0.25) { - g_highlightMaterial.getParam('color').value = [1, 1, 1, 1]; + g_highlightMaterial.getParam('emissive').value = [1, 1, 1, 1]; } else { - g_highlightMaterial.getParam('color').value = [0, 0, 0, 1]; + g_highlightMaterial.getParam('emissive').value = [0, 0, 0, 1]; } } } @@ -249,7 +249,7 @@ function loadScene(pack, fileName, parent) { // Update our info updateInfo(); - g_treeInfo.dump(''); + g_pickManager.dump(''); g_finished = true; // for selenium testing. } @@ -292,6 +292,7 @@ function initStep2(clientElements) { g_debugLineGroup = g_debugHelper.createDebugLineGroup(g_client.root); g_debugLine = g_debugLineGroup.addLine(); g_debugLine.setColor([0,1,0,1]); + g_debugLine.setVisible(false); // Create a material for highlighting. g_highlightMaterial = o3djs.material.createConstantMaterial( |