use of maspack.render.IsRenderable 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.IsRenderable in project artisynth_core by artisynth.
the class TextureEgyptianTest method addContent.
@Override
protected void addContent(MultiViewer mv) {
JFrame frame = new JFrame();
JPanel controls = new JPanel();
frame.add(controls);
PolygonalMesh plane = MeshFactory.createRectangle(4000, 400, 32, 8, /*texture=*/
true);
RenderProps rprops = plane.getRenderProps();
if (rprops == null) {
rprops = new RenderProps();
}
rprops.setShading(Shading.SMOOTH);
rprops.setShininess(20);
rprops.setFaceColor(new Color(155, 196, 30));
rprops.setSpecular(new Color(255, 113, 0));
rprops.setFaceStyle(FaceStyle.FRONT_AND_BACK);
plane.transform(new RigidTransform3d(Vector3d.ZERO, AxisAngle.ROT_X_90));
String srcDir = PathFinder.findSourceDir(this);
ColorMapProps dprops = new ColorMapProps();
dprops.setFileName(srcDir + "/data/specular_map.jpg");
dprops.setColorMixing(ColorMixing.MODULATE);
dprops.setEnabled(true);
NormalMapProps normalProps = new NormalMapProps();
normalProps.setFileName(srcDir + "/data/foil_normal_map2.png");
normalProps.setScaling(0.3f);
normalProps.setEnabled(true);
BumpMapProps bumpProps = new BumpMapProps();
bumpProps.setFileName(srcDir + "/data/egyptian_friz_2.png");
bumpProps.setScaling(2.5f);
bumpProps.setEnabled(true);
rprops.setColorMap(dprops);
rprops.setNormalMap(normalProps);
rprops.setBumpMap(bumpProps);
// FixedMeshBody fm = new FixedMeshBody(plane);
// fm.setRenderProps(rprops);
mv.addRenderable(plane);
if (false) {
mv.addRenderable(new IsRenderable() {
@Override
public void updateBounds(Vector3d pmin, Vector3d pmax) {
Point3d.X_UNIT.updateBounds(pmin, pmax);
Point3d.Y_UNIT.updateBounds(pmin, pmax);
Point3d.Z_UNIT.updateBounds(pmin, pmax);
Point3d.NEG_X_UNIT.updateBounds(pmin, pmax);
Point3d.NEG_Y_UNIT.updateBounds(pmin, pmax);
Point3d.NEG_Z_UNIT.updateBounds(pmin, pmax);
}
@Override
public void render(Renderer renderer, int flags) {
renderer.setColor(Color.CYAN);
renderer.setFaceStyle(FaceStyle.FRONT_AND_BACK);
renderer.drawSphere(Point3d.ZERO, 1);
}
@Override
public void prerender(RenderList list) {
// TODO Auto-generated method stub
}
@Override
public int getRenderHints() {
// TODO Auto-generated method stub
return 0;
}
});
}
mv.autoFitViewers();
LabeledComponentBase base = PropertyWidget.create("Color texture", rprops.getColorMap(), "enabled");
controls.add(base);
base = PropertyWidget.create("Normal map", rprops.getNormalMap(), "enabled");
controls.add(base);
base = PropertyWidget.create("Bump map", rprops.getBumpMap(), "enabled");
controls.add(base);
base = PropertyWidget.create("Specular", rprops.getColorMap(), "specularColoring");
controls.add(base);
base = PropertyWidget.create("Bump map scale", rprops.getBumpMap(), "scaling");
controls.add(base);
base = PropertyWidget.create("Normal map scale", rprops.getNormalMap(), "scaling");
controls.add(base);
frame.pack();
frame.setVisible(true);
}
use of maspack.render.IsRenderable in project artisynth_core by artisynth.
the class IsRenderableEditor method applyAction.
public void applyAction(String actionCommand, LinkedList<ModelComponent> selection, Rectangle popupBounds) {
if (glEditCmd.equals(actionCommand)) {
ArrayList<HasProperties> contained = new ArrayList<HasProperties>(selection.size());
for (ModelComponent mc : selection) {
if (mc instanceof IsRenderableHolder) {
IsRenderableHolder holder = (IsRenderableHolder) mc;
IsRenderable glr = holder.getRenderable();
if (glr instanceof HasProperties) {
contained.add((HasProperties) glr);
}
}
}
if (contained.size() > 0) {
createPropertyDialog(contained, true, popupBounds);
} else {
JOptionPane.showMessageDialog(null, "No properties for selected components", "No properties", JOptionPane.INFORMATION_MESSAGE);
}
}
}
use of maspack.render.IsRenderable 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);
}
use of maspack.render.IsRenderable in project artisynth_core by artisynth.
the class GLViewer method getBounds.
public boolean getBounds(Point3d pmin, Point3d pmax) {
for (int i = 0; i < 3; i++) {
pmin.set(i, Double.POSITIVE_INFINITY);
pmax.set(i, Double.NEGATIVE_INFINITY);
}
boolean boundsSet = false;
for (IsRenderable renderable : myRenderables) {
renderable.updateBounds(pmin, pmax);
boundsSet = true;
}
RenderList elist = myExternalRenderList;
if (elist != null) {
elist.updateBounds(pmin, pmax);
boundsSet = true;
}
if (!boundsSet) {
for (IsRenderable renderable : myDraggers) {
renderable.updateBounds(pmin, pmax);
}
}
// System.out.println (pmax);
if (pmin.x == Double.POSITIVE_INFINITY) {
// then no bounds were set, so
// use a default
pmin.set(-1, -1, -1);
pmax.set(1, 1, 1);
return false;
} else {
return true;
}
}
Aggregations