use of maspack.render.Renderer in project artisynth_core by artisynth.
the class TextTester method addContent.
@Override
protected void addContent(MultiViewer mv) {
final HashMap<String, Font> fontMap = new HashMap<>();
for (Font font : GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts()) {
fontMap.put(font.getName(), font);
}
mv.addRenderable(new SimpleSelectable() {
JFrame debugframe = null;
@Override
public void updateBounds(Vector3d pmin, Vector3d pmax) {
Point3d p1 = new Point3d(-3, -3, -3);
Point3d p2 = new Point3d(3, 3, 3);
p1.updateBounds(pmin, pmax);
p2.updateBounds(pmin, pmax);
}
@Override
public void render(Renderer renderer, int flags) {
if (debugframe == null) {
TextImageStore store = ((GLViewer) renderer).getTextRenderer().getImageStore();
debugframe = TextImageStore.createDisplayFrame(store);
debugframe.setVisible(true);
}
renderer.setShading(Shading.FLAT);
renderer.setColor(Color.WHITE);
renderer.setFaceStyle(FaceStyle.FRONT_AND_BACK);
// renderer.drawSphere (Point3d.ZERO, 0.01);
Font font = new Font(Font.SANS_SERIF, 0, 54);
renderer.drawText(font, "Hello world! And goodnight to all.", new float[] { 0.4f, 0.3f, 0.3f }, 0.25);
renderer.setColor(Color.ORANGE);
String text = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
renderer.drawText(font, text, new float[] { -2f, 0f, 0f }, 0.25);
Font comic = fontMap.get("Comic Sans MS");
if (comic == null) {
comic = new Font(Font.MONOSPACED, Font.BOLD, 32);
} else {
comic = comic.deriveFont(Font.BOLD, 32);
}
renderer.setColor(Color.CYAN);
text = "Cowabunga";
Rectangle2D rect = renderer.getTextBounds(comic, text, 0.25);
renderer.drawText(comic, text, new float[] { -(float) (rect.getWidth()), 0.5f, 0f }, 0.25);
renderer.setColor(Color.MAGENTA);
text = "Flip me!";
font = new Font(Font.SERIF, Font.PLAIN, 64);
rect = renderer.getTextBounds(font, text, 0.3);
renderer.pushModelMatrix();
RigidTransform3d trans = new RigidTransform3d(new Vector3d(0, -0.4, 0), new AxisAngle(0, 1, 0, Math.toRadians(30)));
renderer.mulModelMatrix(trans);
renderer.setFaceStyle(FaceStyle.FRONT);
renderer.drawText(font, text, Point3d.ZERO, 0.3);
trans = new RigidTransform3d(Vector3d.ZERO, new AxisAngle(0, 1, 0, Math.PI));
renderer.mulModelMatrix(trans);
renderer.drawText(font, text, new Point3d(-rect.getWidth(), 0, 0), 0.3);
trans = new RigidTransform3d(Vector3d.ZERO, new AxisAngle(0.1, 1, 0, Math.PI * 1));
renderer.mulModelMatrix(trans);
renderer.setShading(Shading.NONE);
renderer.setFaceStyle(FaceStyle.FRONT_AND_BACK);
renderer.setColor(Color.GREEN);
text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean sagittis hendrerit consequat. Duis id purus neque. Nulla luctus pretium lorem vel convallis. Praesent non ex eu risus porttitor scelerisque vel et lorem. Maecenas ultricies imperdiet tortor, ac varius enim. Integer sagittis dui lacus. Nulla vitae egestas orci. Phasellus vel metus vitae nibh imperdiet imperdiet ut a urna.";
drawMultiline(renderer, font, text, new float[] { -1.75f, -0.2f, -0.5f }, 0.1, 2);
renderer.popModelMatrix();
}
public void drawMultiline(Renderer renderer, Font font, String text, float[] loc, double size, double linelength) {
float left = loc[0];
float[] nloc = { loc[0], loc[1], loc[2] };
Rectangle2D rect = renderer.getTextBounds(font, text, size);
float lineheight = (float) (rect.getHeight());
String[] words = text.split(" ");
int w = 0;
while (w < words.length) {
String word = words[w];
nloc[0] += renderer.drawText(font, word, nloc, size);
++w;
while (w < words.length && nloc[0] < left + linelength) {
word = " " + words[w];
rect = renderer.getTextBounds(font, word, size);
double ll = nloc[0] + rect.getWidth();
if (ll < left + linelength) {
renderer.drawText(font, word, nloc, size);
++w;
}
nloc[0] = (float) ll;
}
// newline
nloc[0] = left;
nloc[1] -= lineheight;
}
}
@Override
public void prerender(RenderList list) {
}
@Override
public int getRenderHints() {
return 0;
}
@Override
public int numSelectionQueriesNeeded() {
return 0;
}
@Override
public boolean isSelectable() {
return false;
}
@Override
public void getSelection(LinkedList<Object> list, int qid) {
}
@Override
public void setSelected(boolean set) {
}
@Override
public boolean isSelected() {
return false;
}
});
mv.setAxialView(AxisAlignedRotation.X_Y);
}
use of maspack.render.Renderer 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.Renderer in project artisynth_core by artisynth.
the class InstanceTest method addContent.
@Override
protected void addContent(MultiViewer mv) {
SimpleSelectable renderable = new SimpleSelectable() {
RenderObject robj = null;
@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) {
if (robj == null) {
robj = new RenderObject();
float x = 0.5f;
robj.addPoint(new float[] { -x, -x, -x });
robj.addPoint(new float[] { x, -x, -x });
robj.addPoint(new float[] { -x, x, -x });
robj.addPoint(new float[] { x, x, -x });
robj.addPoint(new float[] { -x, -x, x });
robj.addPoint(new float[] { x, -x, x });
robj.addPoint(new float[] { -x, x, x });
robj.addPoint(new float[] { x, x, x });
robj.addLine(0, 1);
robj.addLine(1, 3);
robj.addLine(3, 2);
robj.addLine(2, 0);
robj.addLine(4, 5);
robj.addLine(5, 7);
robj.addLine(7, 6);
robj.addLine(6, 4);
robj.createLineGroup();
robj.addLine(0, 4);
robj.addLine(4, 5);
robj.addLine(5, 1);
robj.addLine(1, 0);
}
// renderer.drawPoints (robj, PointStyle.POINT, 10);
renderer.setFrontColor(new float[] { 0.8f, 0.8f, 0.8f, 1.0f });
renderer.drawPoints(robj, PointStyle.SPHERE, 0.1);
renderer.drawLines(robj, 0, LineStyle.CYLINDER, 0.025);
renderer.drawLines(robj, 1, LineStyle.SOLID_ARROW, 0.05);
}
@Override
public void prerender(RenderList list) {
}
@Override
public int getRenderHints() {
return 0;
}
@Override
public int numSelectionQueriesNeeded() {
return 0;
}
@Override
public boolean isSelectable() {
return false;
}
@Override
public void getSelection(LinkedList<Object> list, int qid) {
}
@Override
public void setSelected(boolean set) {
}
@Override
public boolean isSelected() {
// TODO Auto-generated method stub
return false;
}
};
mv.addRenderable(renderable);
for (SimpleViewerApp app : mv.getWindows()) {
app.viewer.setAxialView(AxisAlignedRotation.X_Y);
}
}
use of maspack.render.Renderer in project artisynth_core by artisynth.
the class PrimitivesTest method addContent.
@Override
protected void addContent(MultiViewer mv) {
SimpleSelectable renderable = new SimpleSelectable() {
RenderProps props = new RenderProps();
@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) {
props.setFaceColor(Color.CYAN);
renderer.setFaceColoring(props, false);
renderer.setColor(props.getFaceColorF());
Shading savedShading = renderer.setShading(Shading.NONE);
renderer.setPointSize(20f);
renderer.drawPoint(new float[] { 0.1f, 0.2f, 0.3f });
renderer.setLineWidth(20f);
renderer.drawLine(new float[] { -0.1f, -0.2f, -0.3f }, new float[] { -0.3f, -0.2f, -0.1f });
renderer.setShading(savedShading);
renderer.drawTriangle(new float[] { 0.1f, 0.1f, -0.1f }, new float[] { 0.3f, 0.1f, -0.1f }, new float[] { 0.1f, 0.3f, -0.1f });
}
@Override
public void prerender(RenderList list) {
}
@Override
public int getRenderHints() {
return 0;
}
@Override
public int numSelectionQueriesNeeded() {
return 0;
}
@Override
public boolean isSelectable() {
return false;
}
@Override
public void getSelection(LinkedList<Object> list, int qid) {
}
@Override
public void setSelected(boolean set) {
}
@Override
public boolean isSelected() {
// TODO Auto-generated method stub
return false;
}
};
mv.addRenderable(renderable);
}
use of maspack.render.Renderer in project artisynth_core by artisynth.
the class TriangleLightingTest method addContent.
@Override
protected void addContent(MultiViewer mv) {
SimpleSelectable renderable = new SimpleSelectable() {
RenderProps props = new RenderProps();
@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) {
props.setFaceColor(Color.WHITE);
props.setBackColor(Color.WHITE);
renderer.setFaceColoring(props, /*highlight=*/
false);
renderer.setShading(Shading.SMOOTH);
renderer.setFaceStyle(FaceStyle.FRONT_AND_BACK);
renderer.setColor(props.getFaceColorF());
renderer.setBackColor(props.getBackColorF());
renderer.drawTriangle(new float[] { 1, 1, 0 }, new float[] { -1, 1, 0 }, new float[] { -1, -1, 0 });
renderer.drawTriangle(new float[] { -1, -1, 0 }, new float[] { 1, -1, 0 }, new float[] { 1, 1, 0 });
renderer.setDepthOffset(1);
renderer.drawAxes(RigidTransform3d.IDENTITY, 1, 1, false);
renderer.setDepthOffset(0);
}
@Override
public void prerender(RenderList list) {
}
@Override
public int getRenderHints() {
return 0;
}
@Override
public int numSelectionQueriesNeeded() {
return 0;
}
@Override
public boolean isSelectable() {
return false;
}
@Override
public void getSelection(LinkedList<Object> list, int qid) {
}
@Override
public void setSelected(boolean set) {
}
@Override
public boolean isSelected() {
// TODO Auto-generated method stub
return false;
}
};
mv.addRenderable(renderable);
mv.setAxialView(AxisAlignedRotation.X_Y);
}
Aggregations