use of maspack.widgets.LabeledComponentBase in project artisynth_core by artisynth.
the class FemMuscleBeams method createControlPanel.
protected ControlPanel createControlPanel() {
MechModel mech = (MechModel) models().get("mech");
FemMuscleModel beamFibres = (FemMuscleModel) (mech.models().get("Fibre beam"));
FemMuscleModel beamMaterial = (FemMuscleModel) (mech.models().get("Material beam"));
ControlPanel panel = new ControlPanel("Muscle controls");
panel.addLabel("Fibre beam:");
for (MuscleBundle mb : beamFibres.getMuscleBundles()) {
LabeledComponentBase comp = panel.addWidget(mb.getName(), mb, "excitation");
comp.setLabelFontColor(mb.getRenderProps().getLineColor());
}
for (MuscleExciter mc : beamFibres.getMuscleExciters()) {
panel.addWidget(mc.getName(), mc, "excitation");
}
panel.addWidget(new JSeparator());
panel.addLabel("Material beam:");
for (MuscleBundle mb : beamMaterial.getMuscleBundles()) {
LabeledComponentBase comp = panel.addWidget(mb.getName(), mb, "excitation");
comp.setLabelFontColor(mb.getRenderProps().getLineColor());
}
for (MuscleExciter mc : beamMaterial.getMuscleExciters()) {
panel.addWidget(mc.getName(), mc, "excitation");
}
return panel;
}
use of maspack.widgets.LabeledComponentBase 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.widgets.LabeledComponentBase in project artisynth_core by artisynth.
the class ControlPanel method updateReferences.
@Override
public void updateReferences(boolean undo, Deque<Object> undoInfo) {
super.updateReferences(undo, undoInfo);
boolean changed = false;
if (undo) {
Object obj;
while ((obj = undoInfo.removeFirst()) != NULL_OBJ) {
WidgetRemoveInfo info = (WidgetRemoveInfo) obj;
myPanel.addPropertyWidget(info.myProp, info.myComp, info.myIdx);
changed = true;
}
} else {
// remove soft references which aren't in the hierarchy any more:
ArrayList<WidgetRemoveInfo> removeList = new ArrayList<WidgetRemoveInfo>();
for (int i = 0; i < myPanel.numWidgets(); i++) {
if (myPanel.getWidget(i) instanceof LabeledComponentBase) {
LabeledComponentBase widget = (LabeledComponentBase) myPanel.getWidget(i);
Property prop = myPanel.getWidgetProperty(widget);
if (prop instanceof GenericPropertyHandle) {
ModelComponent comp = ComponentUtils.getPropertyComponent(prop);
if (comp != null && !ComponentUtils.isConnected(this, comp)) {
removeList.add(new WidgetRemoveInfo(prop, widget, i));
changed = true;
}
} else {
// TODO - handle other cases
}
}
}
for (WidgetRemoveInfo info : removeList) {
myPanel.removeWidget(info.myComp);
}
undoInfo.addAll(removeList);
undoInfo.addLast(NULL_OBJ);
}
if (changed && myFrame != null) {
myFrame.pack();
}
}
use of maspack.widgets.LabeledComponentBase in project artisynth_core by artisynth.
the class TextureHeartTest method addContent.
@Override
protected void addContent(MultiViewer mv) {
JFrame frame = new JFrame();
JPanel controls = new JPanel();
frame.add(controls);
String heartObjFilename = PathFinder.findSourceDir(this) + "/data/heart/HumanHeart.obj";
WavefrontReader reader = null;
try {
reader = new WavefrontReader(new File(heartObjFilename));
PolygonalMesh mesh = reader.readMesh();
RenderProps rprops = mesh.getRenderProps();
if (rprops == null) {
rprops = new RenderProps();
}
rprops.setShading(Shading.SMOOTH);
rprops.setFaceColor(new Color(0.8f, 0.8f, 0.8f));
rprops.getColorMap().setColorMixing(ColorMixing.MODULATE);
rprops.setSpecular(new Color(0.4f, 0.4f, 0.4f));
rprops.getBumpMap().setScaling(0.5f);
rprops.setShininess(128);
// mesh.setRenderProps(rprops);
// FixedMeshBody fm = new FixedMeshBody (mesh);
// fm.setRenderProps (mesh.getRenderProps ());
// RenderProps rprops = mesh.getRenderProps();
LabeledComponentBase base = PropertyWidget.create("Map", rprops.getColorMap(), "enabled");
controls.add(base);
base = PropertyWidget.create("Bump map", rprops.getBumpMap(), "enabled");
controls.add(base);
base = PropertyWidget.create("Lighting", rprops, "shading");
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);
mv.addRenderable(mesh);
} catch (IOException e) {
e.printStackTrace();
}
if (reader != null) {
reader.close();
}
mv.autoFitViewers();
frame.pack();
frame.setVisible(true);
}
use of maspack.widgets.LabeledComponentBase in project artisynth_core by artisynth.
the class PropertyWidgetDialog method createWidget.
public LabeledComponentBase createWidget() {
if (getModelComponent() == null || getPropertyInfo() == null) {
throw new IllegalStateException("component and/or property not set");
}
LabeledComponentBase widget;
ModelComponent comp = getModelComponent();
String propPath = getPropertyPath();
Property prop = comp.getProperty(propPath);
if (prop == null) {
throw new InternalErrorException("property '" + propPath + "' not found for component " + comp.getClass());
}
if (CompositeProperty.class.isAssignableFrom(prop.getInfo().getValueClass())) {
// replace prop with an EditingProperty, since
// CompositePropertyWidgets only work properly with those
prop = createEditingProperty(prop);
}
if (isSliderSelected()) {
widget = PropertyWidget.create(prop, getSliderMinimum(), getSliderMaximum());
} else {
widget = PropertyWidget.create(prop);
}
String labelText = myLabelTextField.getStringValue();
widget.setLabelText(labelText);
if (!myLabelFontColorSelector.valueIsNull()) {
widget.setLabelFontColor(myLabelFontColorSelector.getColor());
}
if (!myBackgroundColorSelector.valueIsNull()) {
widget.setBackgroundColor(myBackgroundColorSelector.getColor());
}
return widget;
}
Aggregations