use of maspack.render.Renderable in project artisynth_core by artisynth.
the class Main method computeDraggerToWorld.
protected double computeDraggerToWorld(RigidTransform3d TDW, List<ModelComponent> draggables, Dragger3dBase dragger) {
double radius = 0;
if (dragger != null) {
TDW.set(dragger.getDraggerToWorld());
}
HasCoordinateFrame singleCompWithFrame = null;
if (draggables.size() == 1 && draggables.get(0) instanceof HasCoordinateFrame) {
singleCompWithFrame = (HasCoordinateFrame) draggables.get(0);
}
Point3d pmin = null;
Point3d pmax = null;
if (dragger == null || singleCompWithFrame == null) {
// need to compute bounds if there is no dragger (to determine
// radius), or if there is no single component with a frame (to
// determine the transform).
pmin = new Point3d(inf, inf, inf);
pmax = new Point3d(-inf, -inf, -inf);
for (ModelComponent c : draggables) {
((Renderable) c).updateBounds(pmin, pmax);
}
radius = pmin.distance(pmax);
}
if (singleCompWithFrame != null) {
singleCompWithFrame.getPose(TDW);
if (dragger == null && getInitDraggersInWorldCoords()) {
TDW.R.setIdentity();
}
} else {
TDW.p.add(pmin, pmax);
TDW.p.scale(0.5);
}
return radius;
}
use of maspack.render.Renderable in project artisynth_core by artisynth.
the class SelectionPopup method actionPerformed.
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
LinkedList<ModelComponent> selectedItems = mySelectionManager.getCurrentSelection();
if (command.equals("Edit reference list properties ...")) {
createPropertyDialog(selectedItems);
} else if (command.equals("Edit reference properties ...")) {
createPropertyDialog(myRefComponentSelection);
}
if (command.equals("Edit properties ...")) {
LinkedList<ModelComponent> selection = myPropertyEditSelection;
if (myRefComponentSelection.size() > 0 && myRefComponentSelection.size() < selection.size()) {
selection = new LinkedList<ModelComponent>();
for (ModelComponent c : myPropertyEditSelection) {
if (!(c instanceof ReferenceComponent)) {
selection.add(c);
}
}
}
createPropertyDialog(selection);
} else if (command.equals("Edit render props ...") || command.equals("Set render props ...")) {
LinkedList<ModelComponent> renderables = new LinkedList<ModelComponent>();
for (ModelComponent c : myPropertyEditSelection) {
if (c instanceof Renderable) {
renderables.add(c);
}
}
RenderPropsDialog dialog = new RenderPropsDialog("Edit render properties", renderables);
if (dialog.numProperties() == 0) {
JOptionPane.showMessageDialog(myParentGUIComponent, "No common render properties for selected components", "no common render properties", JOptionPane.INFORMATION_MESSAGE);
} else {
if (myLocateRenderPropEditClose) {
GuiUtils.locateRelative(dialog, myLastBounds, 0.5, 0.5, 0, 0.5);
} else {
dialog.locateRight(myMain.getFrame());
}
myMain.registerWindow(dialog);
dialog.setTitle("RenderProps for " + getNameForSelection(myPropertyEditSelection));
dialog.setVisible(true);
}
} else if (command.equals("Clear render props")) {
for (ModelComponent c : myPropertyEditSelection) {
if (c instanceof Renderable) {
((Renderable) c).setRenderProps(null);
}
}
requestViewerUpdate();
} else if (command.equals("Set visible")) {
for (ModelComponent c : myPropertyEditSelection) {
if (c instanceof RenderableComponent) {
setVisible((RenderableComponent) c, true);
}
}
requestViewerUpdate();
} else if (command.equals("Set invisible")) {
for (ModelComponent c : myPropertyEditSelection) {
if (c instanceof RenderableComponent) {
setVisible((RenderableComponent) c, false);
}
}
requestViewerUpdate();
} else if (command.equals("Enable tracing")) {
RootModel rootModel = myMain.getRootModel();
for (ModelComponent c : myPropertyEditSelection) {
if (c instanceof Traceable) {
Traceable tr = (Traceable) c;
if (!rootModel.isTracing(tr)) {
rootModel.enableTracing(tr);
}
}
}
} else if (command.equals("Disable tracing")) {
RootModel rootModel = myMain.getRootModel();
for (ModelComponent c : myPropertyEditSelection) {
if (c instanceof Traceable) {
Traceable tr = (Traceable) c;
if (rootModel.isTracing(tr)) {
rootModel.disableTracing(tr);
}
}
}
} else if (command.equals("Clear trace")) {
RootModel rootModel = myMain.getRootModel();
for (ModelComponent c : myPropertyEditSelection) {
if (c instanceof Traceable) {
Traceable tr = (Traceable) c;
if (rootModel.isTracing(tr)) {
rootModel.clearTracing(tr);
}
}
}
myMain.rerender();
} else if (command.equals("Add tracing probe")) {
addTracing(myPropertyEditSelection);
} else if (command.equals("Save as ...")) {
EditorUtils.saveComponent(selectedItems.get(0));
} else if (command == "Delete") {
deleteSelection();
} else if (command.equals("Delete reference(s)")) {
deleteRefComponentSelection();
} else if (command == "Duplicate") {
duplicateSelection();
} else {
// EditorBase editor = myEditActionMap.get (command);
// if (editor != null) {
// editor.applyAction (command, selectedItems, myLastBounds);
// }
EditorBase editor = myEditActionMap.getEditor(command);
if (editor != null) {
editor.applyAction(command, selectedItems, myLastBounds);
}
}
}
use of maspack.render.Renderable in project artisynth_core by artisynth.
the class Muscle method prerender.
@Override
public void prerender(RenderList list) {
RenderProps props = myRenderProps;
if (props == null) {
if (getParent() instanceof Renderable) {
props = ((Renderable) getParent()).getRenderProps();
}
}
if (props != null && myExcitationColor != null) {
if (myRenderColor == null) {
myRenderColor = new float[3];
}
float[] baseColor = props.getLineColorF();
double s = Math.min(getNetExcitation() / getMaxColoredExcitation(), 1);
ColorUtils.interpolateColor(myRenderColor, baseColor, myExcitationColor, s);
} else {
myRenderColor = null;
}
}
use of maspack.render.Renderable in project artisynth_core by artisynth.
the class FemBeamMech method build.
public void build(String[] args) {
femPath = "models/mech/models/fem/";
modPath = "models/mech/";
int nn = 2;
myFemMod = FemFactory.createTetGrid(null, 0.6, 0.2, 0.2, nn * 3, nn * 1, nn * 1);
myFemMod.setName("fem");
myFemMod.setDensity(myDensity);
myFemMod.setBounds(new Point3d(-0.6, 0, 0), new Point3d(0.6, 0, 0));
myFemMod.setLinearMaterial(60000, 0.33, true);
myFemMod.setStiffnessDamping(0.002);
myFemMod.setImplicitIterations(100);
myFemMod.setImplicitPrecision(0.001);
myFemMod.setSurfaceRendering(SurfaceRender.Shaded);
Renderable elems = myFemMod.getElements();
RenderProps.setLineWidth(elems, 2);
RenderProps.setLineColor(elems, Color.BLUE);
Renderable nodes = myFemMod.getNodes();
RenderProps.setPointStyle(nodes, Renderer.PointStyle.SPHERE);
RenderProps.setPointRadius(nodes, 0.005);
RenderProps.setPointColor(nodes, Color.GREEN);
// fix the leftmost nodes
double EPS = 1e-9;
for (FemNode3d n : myFemMod.getNodes()) {
if (n.getPosition().x < -0.3 + EPS) {
myLeftNodes.add(n);
}
}
System.out.println("fixed nodes:");
for (FemNode3d n : myLeftNodes) {
n.setDynamic(false);
}
RenderProps.setFaceColor(myFemMod, new Color(0.4f, 0.4f, 1.0f));
myFemMod.setProfiling(true);
RigidBody anchorBox = new RigidBody("anchorBox");
PolygonalMesh mesh = MeshFactory.createBox(0.1, 0.3, 0.3);
anchorBox.setMesh(mesh, /* fileName= */
null);
RigidTransform3d X = new RigidTransform3d();
X.p.set(-0.35, 0, 0);
anchorBox.setPose(X);
anchorBox.setDynamic(false);
myMechMod = new MechModel("mech");
myMechMod.addModel(myFemMod);
myMechMod.addRigidBody(anchorBox);
System.out.println("models: " + myMechMod.findComponent("models"));
System.out.println("models/fem: " + myMechMod.findComponent("models/fem"));
myMechMod.setIntegrator(Integrator.BackwardEuler);
addModel(myMechMod);
myMechMod.setProfiling(true);
// add marker to lower right corner element
Point3d corner = new Point3d(0.3, -0.1, -0.1);
FemElement cornerElem = null;
for (FemElement e : myFemMod.getElements()) {
FemNode[] nodeList = e.getNodes();
for (int i = 0; i < nodeList.length; i++) {
if (nodeList[i].getPosition().epsilonEquals(corner, 1e-8)) {
cornerElem = e;
break;
}
}
}
if (cornerElem != null) {
FemMarker mkr = new FemMarker(0.3, -0.07, -0.03);
myFemMod.addMarker(mkr, cornerElem);
RenderProps.setPointStyle(mkr, Renderer.PointStyle.SPHERE);
RenderProps.setPointRadius(mkr, 0.01);
RenderProps.setPointColor(mkr, Color.WHITE);
Particle part = new Particle(1, 0.5, -0.07, -0.03);
RenderProps.setPointStyle(part, Renderer.PointStyle.SPHERE);
RenderProps.setPointRadius(part, 0.01);
part.setDynamic(false);
myMechMod.addParticle(part);
AxialSpring spr = new AxialSpring(1000, 0, 0);
myMechMod.attachAxialSpring(part, mkr, spr);
RenderProps.setLineStyle(spr, Renderer.LineStyle.SPINDLE);
RenderProps.setLineRadius(spr, 0.01);
RenderProps.setLineColor(spr, Color.GREEN);
}
int numWays = 0;
double res = 0.2;
for (int i = 0; i < numWays; i++) {
addWayPoint(new WayPoint((i + 1) * res, true));
}
addControlPanel(myMechMod, myFemMod);
}
use of maspack.render.Renderable in project artisynth_core by artisynth.
the class RootModel method updateBounds.
public void updateBounds(Vector3d pmin, Vector3d pmax) {
for (Model m : myModels) {
if (m instanceof Renderable) {
((Renderable) m).updateBounds(pmin, pmax);
}
}
myOutputProbes.updateBounds(pmin, pmax);
myRenderables.updateBounds(pmin, pmax);
}
Aggregations