use of artisynth.core.mechmodels.RigidBody in project artisynth_core by artisynth.
the class RigidBodyAgent method initializePrototype.
protected void initializePrototype(ModelComponent comp, Class type) {
if (type == RigidBody.class) {
RigidBody mkr = (RigidBody) comp;
RenderProps.setPointRadius(mkr, getDefaultPointRadius());
} else {
throw new InternalErrorException("unimplemented type " + type);
}
}
use of artisynth.core.mechmodels.RigidBody 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 artisynth.core.mechmodels.RigidBody 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 artisynth.core.mechmodels.RigidBody in project artisynth_core by artisynth.
the class RigidBodyConnectorList method selectionChanged.
@Override
public void selectionChanged(SelectionEvent e) {
ModelComponent c = e.getLastAddedComponent();
if (myState == State.SelectingBodyA) {
if (c instanceof RigidBody) {
myBodyA = (RigidBody) c;
setState(State.SelectingBodyB);
}
} else if (myState == State.SelectingBodyB) {
if (c instanceof RigidBody) {
myBodyB = (RigidBody) c;
setState(State.SelectingLocation);
}
}
}
use of artisynth.core.mechmodels.RigidBody in project artisynth_core by artisynth.
the class RigidBodyEditor method applyAction.
public void applyAction(String actionCommand, LinkedList<ModelComponent> selection, Rectangle popupBounds) {
if (containsMultipleSelection(selection, RigidBody.class)) {
if (actionCommand == "Select markers") {
LinkedList<ModelComponent> list = (LinkedList<ModelComponent>) selection.clone();
for (ModelComponent c : list) {
FrameMarker[] mkrs = ((RigidBody) c).getFrameMarkers();
for (int i = 0; i < mkrs.length; i++) {
myMain.getSelectionManager().addSelected(mkrs[i]);
}
myMain.getSelectionManager().removeSelected(c);
}
}
if (containsSingleSelection(selection, RigidBody.class)) {
if (actionCommand == "Edit geometry and inertia ...") {
if (myEditManager.acquireEditLock()) {
RigidBody body = (RigidBody) selection.get(0);
RigidBodyGeometryAgent agent = new RigidBodyGeometryAgent(myMain, body);
agent.show(popupBounds);
}
} else if (actionCommand == "Save mesh as ...") {
RigidBody body = (RigidBody) selection.get(0);
PolygonalMesh mesh = body.getMesh();
EditorUtils.saveMesh(mesh, mesh != null ? mesh.getMeshToWorld() : null);
} else if (actionCommand == "Attach particles ...") {
if (myEditManager.acquireEditLock()) {
RigidBody body = (RigidBody) selection.get(0);
// XXX should be more general than this ... what if mechModel
// is a sub model?
MechModel mech = (MechModel) body.getGrandParent();
myMain.getSelectionManager().clearSelections();
AttachParticleBodyAgent agent = new AttachParticleBodyAgent(myMain, mech, body);
agent.show(popupBounds);
}
} else if (actionCommand == "Add mesh inspector") {
RigidBody body = (RigidBody) selection.get(0);
MechModel mech = (MechModel) body.getGrandParent();
EditablePolygonalMeshComp editMesh = new EditablePolygonalMeshComp(body.getSurfaceMesh());
double size = RenderableUtils.getRadius(editMesh);
RenderProps.setVisible(editMesh, true);
RenderProps.setPointStyle(editMesh, Renderer.PointStyle.SPHERE);
RenderProps.setPointRadius(editMesh, 0.05 * size);
mech.addRenderable(editMesh);
}
}
}
}
Aggregations