use of maspack.render.GL.GLViewer in project artisynth_core by artisynth.
the class AddComponentAgent method getDefaultPointRadius.
/**
* Returns a default value for the sphere radius render property.
*/
protected double getDefaultPointRadius() {
GLViewer viewer = myViewerManager.getViewer(0);
double r = viewer.estimateRadiusAndCenter(null);
// return 3*viewer.distancePerPixel (viewer.getCenter());
return 0.015 * r;
}
use of maspack.render.GL.GLViewer in project artisynth_core by artisynth.
the class RigidBodyAgent method updateScale.
private void updateScale() {
resetScaling();
Vector3d minBound = new Vector3d();
Vector3d maxBound = new Vector3d();
body.getMesh().getWorldBounds(minBound, maxBound);
double meshWidth = maxBound.x - minBound.x;
double meshHeight = maxBound.y - minBound.y;
GLViewer viewer = myMain.getMain().getViewer();
double distancePerPixel = viewer.distancePerPixel(viewer.getCenter());
double width = distancePerPixel * viewer.getScreenWidth() / 4;
double height = distancePerPixel * viewer.getScreenHeight() / 4;
double meshScale = 1;
if (meshScale * meshWidth > width || meshScale * meshHeight > height) {
for (int i = -1; width < meshScale * meshWidth && height < meshScale * meshHeight; i++) {
meshScale /= (i % 3 == 0) ? 2.5 : 2.0;
}
} else {
for (int i = -1; width > meshScale * meshWidth || height > meshScale * meshHeight; i++) {
double increment = (i % 3 == 0) ? 2.5 : 2.0;
if (width <= meshScale * meshWidth * increment || height <= meshScale * meshHeight * increment) {
break;
}
meshScale *= increment;
}
}
scaleField.setValue(meshScale);
}
use of maspack.render.GL.GLViewer in project artisynth_core by artisynth.
the class RigidBodyAgent method createPreviewBody.
private void createPreviewBody() {
resetScaling();
body = new RigidBody();
setProperties(body, getPrototypeComponent(myComponentType));
setProperties(myPrototype, myPrototype);
body.setMesh(myGeometryPanel.getMesh(), myGeometryPanel.getMeshFileName(), myGeometryPanel.getMeshTransform());
RigidTransform3d X = new RigidTransform3d();
X.p.set(positionField.getVectorValue());
X.R.setAxisAngle(orientationField.getAxisAngleValue());
body.setPose(X);
RenderProps props = body.createRenderProps();
props.setFaceStyle(Renderer.FaceStyle.NONE);
props.setDrawEdges(true);
props.setLineColor(Color.LIGHT_GRAY);
body.setRenderProps(props);
myMain.getWorkspace().getViewerManager().addRenderable(body);
rotator = new Transrotator3d();
GLViewer viewer = myMain.getMain().getViewer();
rotator.setDraggerToWorld(X);
rotator.setSize(viewer.distancePerPixel(viewer.getCenter()) * viewer.getScreenWidth() / 6);
rotator.addListener(new RigidBodyDraggerListener());
myMain.getWorkspace().getViewerManager().addDragger(rotator);
myGeometryPanel.setAttachedBody(body);
myMain.rerender();
}
use of maspack.render.GL.GLViewer in project artisynth_core by artisynth.
the class RigidBodyAgent method createGeometryPanel.
protected void createGeometryPanel() {
RigidBody protoBody = null;
int numExistingBodies = myModel.rigidBodies().size();
if (numExistingBodies > 0) {
protoBody = myModel.rigidBodies().get(numExistingBodies - 1);
}
myGeometryPanel = new GeometryInertiaPanel(myGeometrySettings, protoBody, /* editing= */
false);
myGeometryPanel.setBorder(GuiUtils.createTitledPanelBorder("Geometry And Inertia"));
if (myGeometrySettings == null) {
GLViewer viewer = myMain.getMain().getViewer();
double width = viewer.distancePerPixel(viewer.getCenter()) * viewer.getScreenWidth() / 6;
double boxScale = 1;
if (width > boxScale) {
for (int i = -1; width > boxScale; i++) {
boxScale *= (i % 3 == 0) ? 2.5 : 2.0;
}
} else {
for (int i = -1; width < boxScale; i++) {
boxScale /= (i % 3 == 0) ? 2.5 : 2.0;
}
}
myGeometryPanel.myBoxWidthsField.setValue(new Vector3d(boxScale, boxScale, boxScale));
}
geometrySelector = myGeometryPanel.myGeometrySelector;
geometrySelector.addValueChangeListener(this);
myGeometryPanel.myBoxWidthsField.addValueChangeListener(this);
myGeometryPanel.myPointRadiusField.addValueChangeListener(this);
myGeometryPanel.myPointSlicesField.addValueChangeListener(this);
myGeometryPanel.myMeshFileField.addValueChangeListener(this);
AffineTransformWidget meshXformWidget = myGeometryPanel.myMeshXformWidget;
meshXformWidget.getTranslationField().addValueChangeListener(this);
myGeometryPanel.myDensityField.setValue(1.0);
scaleField = meshXformWidget.getScaleField();
autoScaleBtn = new JButton("Auto Scale");
autoScaleBtn.addActionListener(this);
scaleField.addMajorComponent(autoScaleBtn);
addWidget(myGeometryPanel);
}
use of maspack.render.GL.GLViewer in project artisynth_core by artisynth.
the class RigidBodyAgent method valueChange.
public void valueChange(ValueChangeEvent evt) {
Object source = evt.getSource();
if (source == positionField) {
updateState();
updateDisplayGeometry();
if (geometrySelector.getValue() == GeometryType.Mesh && body != null) {
updateScale();
}
} else if (source == orientationField) {
updateDisplayGeometry();
} else if (source == geometrySelector) {
GLViewer viewer = myMain.getMain().getViewer();
double width = viewer.distancePerPixel(viewer.getCenter()) * viewer.getScreenWidth() / 6;
if (geometrySelector.getValue() == GeometryType.Mesh) {
File file = new File(myGeometryPanel.myMeshFileField.getStringValue());
if (!file.isFile()) {
fileCheck = false;
updateState();
}
resetPreviewModel();
if (body != null) {
updateScale();
}
} else {
fileCheck = true;
updateState();
double scale = 1;
if (width > scale) {
for (int i = -1; width > scale; i++) {
scale *= (i % 3 == 0) ? 2.5 : 2.0;
}
} else {
for (int i = -1; width < scale; i++) {
scale /= (i % 3 == 0) ? 2.5 : 2.0;
}
}
if (geometrySelector.getValue() == GeometryType.Box) {
myGeometryPanel.myBoxWidthsField.setValue(new Vector3d(scale, scale, scale));
} else if (geometrySelector.getValue() == GeometryType.Sphere) {
myGeometryPanel.myPointRadiusField.setValue(scale / 2);
}
resetPreviewModel();
myMain.rerender();
}
} else if (source == myGeometryPanel.myBoxWidthsField || source == myGeometryPanel.myPointRadiusField || source == myGeometryPanel.myPointSlicesField || source == myGeometryPanel.myMeshXformWidget.getTranslationField()) {
resetPreviewModel();
myMain.rerender();
} else if (source == myGeometryPanel.myMeshFileField) {
File file = new File(myGeometryPanel.myMeshFileField.getStringValue());
if (file.isFile()) {
fileCheck = true;
updateState();
resetPreviewModel();
if (body != null) {
updateScale();
}
} else {
fileCheck = false;
EditorUtils.showError(myDisplay, "File does not exist:" + file.getAbsolutePath());
}
} else {
super.valueChange(evt);
}
}
Aggregations