World Flights picking

45 views
Skip to first unread message

Jasper Speicher

unread,
Sep 8, 2011, 12:15:19 AM9/8/11
to PhiloGL
I looked at the picking colors in world flights. Seems that there are
only one set of floats per sphere, rather than pervert-ex [sic]?

Nicolas Garcia Belmonte

unread,
Sep 8, 2011, 1:28:11 AM9/8/11
to phi...@googlegroups.com
Hi Jasper - If you wanted to have different events per face that makes
a mesh then you would be able to have color per vertex. In the world
flights example I have a mesh which is a set of unconnected spheres,
and I only want to know if the user is clicking on one of those
spheres, and not on which part of the sphere the user is clicking on.

In that example I create a single mesh of many spheres because it only
requires a single GL call to render all of them (instead of looping
per each sphere and render it with a GL call which would be much more
expensive).

Does that make any sense? :)

On Wed, Sep 7, 2011 at 9:15 PM, Jasper Speicher <jas...@tellart.com> wrote:
> I looked at the picking colors in world flights. Seems that there are
> only one set of floats per sphere, rather than pervert-ex [sic]?
>

--
Nicolas Garcia Belmonte - http://philogb.github.com/

Jasper Speicher

unread,
Sep 8, 2011, 1:30:21 PM9/8/11
to PhiloGL
It does make sense as a motivation, but I do not understand how the
picking colors are mapped to the vertices. How would one know which
color goes with which group of vertices when rendering the picking
scene, since they have differing count, and the mapping depends on
vertices per sphere, which is arbitrary information that is not
contained in the mesh.

Also, nothing happens when I click a sphere in the demo (Mac Lion,
Chrome 14.0.835.157 beta)

Best,
Jasper

ps thank you so much for this fabulous library and all of the very
helpful examples. it is very kind of you to offer this, and so much of
your attention, to the community.

Nicolas Garcia Belmonte

unread,
Sep 8, 2011, 2:19:57 PM9/8/11
to phi...@googlegroups.com
Hi - Thanks for the kind words!

I turned off picking in the example because there were too many points
and they were too small to be clicked, so the interaction was kind of
uncomfortable. You can make the cities layer pickable again by setting
`pickable: true` here:

https://github.com/senchalabs/philogl/blob/master/examples/worldFlights/index.js#L123

You can find more information on model constructor configuration
properties here:

http://senchalabs.github.com/philogl/doc/o3d.html#O3D:Model:constructor

The pickingColors array is created by you, and should have the same
amount of components than the vertices of the mesh. Remember that this
is only if you want to find out which part of a mesh is being clicked,
for just knowing which model in the scene has been clicked there is an
easier picking method in the framework.

Thing of the pickingColors array as an array of indices that will
point to the vertices / face you want to match with. For example, pear
each sphere I have created a different color. Those colors are taken
from the index of the sphere in the array of spheres I'm creating
here:

https://github.com/senchalabs/philogl/blob/master/examples/worldFlights/cities.js#L39

Once a user clicks on the mesh, I get the pixel in the pick method and
return the original sphere index in the array:

https://github.com/senchalabs/philogl/blob/master/examples/worldFlights/index.js#L128

Then, on the events object here:

https://github.com/senchalabs/philogl/blob/master/examples/worldFlights/index.js#L384

You shoud add a new listener for clicking for example:

onClick: function() {
console.log(arguments);
}

if you click on a city you should get the proper index.

Does that make any sense? Please let me know if you have any other questions.

Nicolas.

--

Reply all
Reply to author
Forward
0 new messages