use of maspack.matrix.RigidTransform3d in project artisynth_core by artisynth.
the class MultiViewerTesterBase method loadStanfordBunny.
protected static PolygonalMesh loadStanfordBunny() {
// read Standford bunny directly
String bunnyURL = "http://graphics.stanford.edu/~mdfisher/Data/Meshes/bunny.obj";
// bunny
File bunnyFile = new File("tmp/data/stanford_bunny.obj");
PolygonalMesh bunny = null;
try {
if (!bunnyFile.exists()) {
bunnyFile.getParentFile().mkdirs();
// read file directly from remote
FileCacher cacher = new FileCacher();
cacher.initialize();
cacher.cache(new URIx(bunnyURL), bunnyFile);
cacher.release();
}
WavefrontReader reader = new WavefrontReader(bunnyFile);
bunny = new PolygonalMesh();
reader.readMesh(bunny);
// bunny.computeVertexNormals();
// normalize bunny
double r = bunny.computeRadius();
Vector3d c = new Vector3d();
bunny.computeCentroid(c);
c.negate();
bunny.scale(1.0 / r);
c.z -= 0.5;
bunny.transform(new RigidTransform3d(c, new AxisAngle(1, 0, 0, Math.PI / 2)));
reader.close();
} catch (IOException e1) {
e1.printStackTrace();
System.out.println("Unable to load stanford bunny... requires internet connection");
bunny = null;
}
return bunny;
}
use of maspack.matrix.RigidTransform3d 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.matrix.RigidTransform3d 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.matrix.RigidTransform3d in project artisynth_core by artisynth.
the class RigidTransformWidget method updateInternalValue.
/**
* Updates the internal representation of the value, updates any result
* holders, and returns true if the new value differs from the old value.
*/
protected boolean updateInternalValue(Object value) {
if (!valuesEqual(value, myValue)) {
myTranslationField.maskValueChangeListeners(true);
myRotationField.maskValueChangeListeners(true);
if (value instanceof RigidTransform3d) {
RigidTransform3d newX = (RigidTransform3d) value;
if (myTranslationField.valueIsVoid() || !newX.p.equals(getTranslation())) {
myTranslationField.setValue(newX.p);
}
RotationMatrix3d R = new RotationMatrix3d();
if (!myRotationField.valueIsVoid()) {
R.setAxisAngle(getRotation());
}
if (myRotationField.valueIsVoid() || !newX.R.equals(R)) {
AxisAngle newAxisAngle = new AxisAngle();
newX.R.getAxisAngle(newAxisAngle);
myRotationField.setValue(newAxisAngle);
}
value = new RigidTransform3d(newX);
} else if (value == Property.VoidValue) {
myTranslationField.setValue(Property.VoidValue);
myRotationField.setValue(Property.VoidValue);
}
myTranslationField.maskValueChangeListeners(false);
myRotationField.maskValueChangeListeners(false);
myValue = value;
return true;
} else {
return false;
}
}
use of maspack.matrix.RigidTransform3d in project artisynth_core by artisynth.
the class RigidTransformWidget method initialize.
private void initialize(String fmtStr) {
myTranslationField = new VectorField("Pos:", 3);
myTranslationField.setVoidValueEnabled(true);
myRotationField = new AxisAngleField("Rot:");
myRotationField.setVoidValueEnabled(true);
myPanel = new LabeledComponentPanel();
myTranslationField.addValueChangeListener(new ValueChangeListener() {
public void valueChange(ValueChangeEvent e) {
if (!myRotationField.valueIsVoid()) {
RigidTransform3d X = new RigidTransform3d();
X.p.set(getTranslation());
X.R.setAxisAngle(getRotation());
updateValue(X);
}
}
});
myRotationField.addValueChangeListener(new ValueChangeListener() {
public void valueChange(ValueChangeEvent e) {
if (!myTranslationField.valueIsVoid()) {
RigidTransform3d X = new RigidTransform3d();
X.p.set(getTranslation());
X.R.setAxisAngle(getRotation());
updateValue(X);
}
}
});
myPanel.addWidget(myTranslationField);
myPanel.addWidget(myRotationField);
if (myTranslationField.getColumns() > myRotationField.getColumns()) {
myRotationField.setColumns(myTranslationField.getColumns());
} else {
myTranslationField.setColumns(myRotationField.getColumns());
}
myTranslationField.setFormat(fmtStr);
addMajorComponent(myPanel);
}
Aggregations