use of maspack.render.IsSelectable in project artisynth_core by artisynth.
the class GLColorSelector method processSelection.
@Override
public void processSelection(GL gl) {
if (myTotalMaxQ == 0) {
super.processSelection(gl);
return;
}
flushQueries(myGl);
HitRecord[] hits = null;
for (int id : myQueryBuffer) {
if (id != 0) {
// subtract the 1 offset
--id;
if (hits == null) {
hits = new HitRecord[myTotalMaxQ];
}
HitRecord rec = hits[id];
if (rec == null) {
rec = new HitRecord(0);
hits[id] = rec;
}
rec.size++;
}
}
myViewer.selectionEvent.setSelectedObjects(null);
if (hits == null) {
// then no queries were issued, so nothing to do ...
myViewer.selectionEvent.setSelectedObjects(null);
} else {
int qid = 0;
LinkedList<HitRecord> records = new LinkedList<HitRecord>();
// int[] result = new int[1];
Iterator<IsRenderable> it = myViewer.renderIterator();
while (it.hasNext()) {
IsRenderable r = it.next();
if (r instanceof IsSelectable) {
IsSelectable s = (IsSelectable) r;
int numq = s.numSelectionQueriesNeeded();
int nums = (numq >= 0 ? numq : 1);
if (s.isSelectable()) {
for (int i = 0; i < nums; i++) {
HitRecord rec;
if ((rec = hits[qid + i]) != null) {
if (numq < 0) {
rec.objs.add(s);
} else {
s.getSelection(rec.objs, i);
}
if (rec.objs.size() > 0) {
records.add(rec);
}
}
}
}
qid += nums;
}
}
Collections.sort(records);
ArrayList<LinkedList<?>> selObjs = new ArrayList<>(records.size());
for (int i = 0; i < records.size(); i++) {
selObjs.add(records.get(i).objs);
}
myViewer.selectionEvent.setSelectedObjects(selObjs);
}
super.processSelection(gl);
}
use of maspack.render.IsSelectable in project artisynth_core by artisynth.
the class GLOcclusionSelector method processSelection.
@Override
public void processSelection(GL gl) {
if (myTotalMaxQ == 0) {
super.processSelection(gl);
return;
}
// finish remaining queries
flushQueries((GL2GL3) gl);
// re-enable depth buffer
myViewer.setDepthEnabled(savedDepth);
if (myGLQueryTotal == 0) {
// then no queries were issued, so nothing to do ...
myViewer.setSelected(null);
} else {
int qid = 0;
LinkedList<HitRecord> records = new LinkedList<HitRecord>();
Iterator<IsRenderable> it = myViewer.renderIterator();
while (it.hasNext()) {
IsRenderable r = it.next();
if (r instanceof IsSelectable) {
IsSelectable s = (IsSelectable) r;
int numq = s.numSelectionQueriesNeeded();
int nums = (numq >= 0 ? numq : 1);
if (s.isSelectable()) {
for (int i = 0; i < nums; i++) {
if (myQuerySamples[qid + i] > 0) {
HitRecord rec = new HitRecord(myQuerySamples[qid + i]);
if (numq < 0) {
rec.objs.add(s);
} else {
s.getSelection(rec.objs, i);
}
if (rec.objs.size() > 0) {
records.add(rec);
}
}
}
}
qid += nums;
}
}
Collections.sort(records);
ArrayList<LinkedList<?>> selObjs = new ArrayList<>(records.size());
for (int i = 0; i < records.size(); i++) {
selObjs.add(records.get(i).objs);
}
myViewer.setSelected(selObjs);
}
// delete queries
((GL2GL3) myGl).glDeleteQueries(myGLQueries.length, myGLQueries, 0);
myGLQueries = null;
myGLQueryIds = null;
super.processSelection(gl);
}
Aggregations