Hi,
I’ve been tracking/toying with Xith for some time now,
and like it a lot.
I would like to propose to enhance Xith3D picking somewhat.
Currently Xith3D uses the standard OpenGL picking mechanism with a select buffer,
and picking by Node.
PickRenderResult.getNodes() lists the (I think: single) Node picked
and a zmin, zmax value.
This use of OpenGL picking is quite specific to picking Node’s and:
- does not allow identification of primitives (which quad of the
immense quadarray has been picked?) - does not allow the application to provide (multiple) pick names
(the cell picked has this cellId, this segmentId, this clusterId etc.
Admittedly I haven’t seen a number of identification codes > 3,
and we packed them into a single int. Works, but caused a bit of a range
limitation ) - any future node predraw hooks for DIY OpenGL drawing cannot get
custom pick results back.
The proposal below attempts to remedy this and keep on using standard OpenGL picking.
-
add to Node:
// when true, the first name on the stack will be the primitive index.
// this allows getting (close) to the picked coordinates, for applications that do
// not want to deal with custom names.
// geoArray.getValidVertexCount()/# vertices_per_primitive for normal geometry
// igeoArray.getValidIndexCount()/# vertices_per_primitive for indexed geometry ???
</not thought through>
boolean pickPrimitiveIndex = false;// the number of names that this node can use for identifying its pick result
// value 0 means that only the default node picking is available.
int customNameStackDepth = 0; -
change PickRenderResult
private Node node; // should be just one Node + all of its sub-identification,
private int[] names; // so complete contents of name stack at pick time - 1
// (the name used to identify the node itself) -
to allow multiple custom names per primitive of a Node, add to GeomContainer
// array of size nameStackDepth, containing the pick names per primitive
// the pickNames could be java int arrays, subject to GC
</not thought through>
GeomDataInterface[] pickNames; -
add GeomNioIntData (similar to GeomNioFloatData) for use as pickNames
The biggest change is with rendering: with custom names per primitive, we can’t use
glDrawArrays or glDrawElements for drawing.
When in pick mode && custom picking is enabled, drawing needs to revert to drawing
per primitive:
- if (pickPrimitiveIndex) push current primitive index
- push all custom (customNameStackDepth) names on the stack
- draw primitive, using the appropriate glArrayElement() call
- pop all custom names off the stack
- if (pickPrimitiveIndex) pop
Thus, ShapeAtomPeer needs to be aware of the pickMode.
Additionally proper checking of the pickNames data should be done,
customNameStackDepth + #internal names should be checked to be < GL_NAME_STACK_DEPTH,
(allthough this is not likely to be a problem as GL_NAME_STACK_DEPTH >= 64 …)
convertSelectBuffer would need to be changed etc…
But in the end this would provide a very flexible (configurable per Node) picking mechanism.
What do you think?
Does this conflict with other developments in the pipeline?
Cheers,
Robert
