Search in sources :

Example 1 with LabeledComponentBase

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;
}
Also used : ControlPanel(artisynth.core.gui.ControlPanel) LabeledComponentBase(maspack.widgets.LabeledComponentBase) JSeparator(javax.swing.JSeparator)

Example 2 with LabeledComponentBase

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);
}
Also used : JPanel(javax.swing.JPanel) RigidTransform3d(maspack.matrix.RigidTransform3d) Color(java.awt.Color) ColorMapProps(maspack.render.ColorMapProps) RenderProps(maspack.render.RenderProps) PolygonalMesh(maspack.geometry.PolygonalMesh) RenderList(maspack.render.RenderList) BumpMapProps(maspack.render.BumpMapProps) IsRenderable(maspack.render.IsRenderable) JFrame(javax.swing.JFrame) Vector3d(maspack.matrix.Vector3d) Renderer(maspack.render.Renderer) LabeledComponentBase(maspack.widgets.LabeledComponentBase) NormalMapProps(maspack.render.NormalMapProps)

Example 3 with LabeledComponentBase

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();
    }
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent) LabeledComponentBase(maspack.widgets.LabeledComponentBase) GenericPropertyHandle(maspack.properties.GenericPropertyHandle) Property(maspack.properties.Property) EditingProperty(maspack.properties.EditingProperty) Point(java.awt.Point)

Example 4 with LabeledComponentBase

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);
}
Also used : WavefrontReader(maspack.geometry.io.WavefrontReader) JPanel(javax.swing.JPanel) JFrame(javax.swing.JFrame) Color(java.awt.Color) RenderProps(maspack.render.RenderProps) LabeledComponentBase(maspack.widgets.LabeledComponentBase) IOException(java.io.IOException) File(java.io.File) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 5 with LabeledComponentBase

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;
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent) LabeledComponentBase(maspack.widgets.LabeledComponentBase) InternalErrorException(maspack.util.InternalErrorException) CompositeProperty(maspack.properties.CompositeProperty) EditingProperty(maspack.properties.EditingProperty) Property(maspack.properties.Property)

Aggregations

LabeledComponentBase (maspack.widgets.LabeledComponentBase)12 EditingProperty (maspack.properties.EditingProperty)6 Property (maspack.properties.Property)6 ModelComponent (artisynth.core.modelbase.ModelComponent)5 ControlPanel (artisynth.core.gui.ControlPanel)3 Point (java.awt.Point)3 IOException (java.io.IOException)3 Point (artisynth.core.mechmodels.Point)2 CompositeComponent (artisynth.core.modelbase.CompositeComponent)2 MutableCompositeComponent (artisynth.core.modelbase.MutableCompositeComponent)2 Color (java.awt.Color)2 Component (java.awt.Component)2 JComponent (javax.swing.JComponent)2 JFrame (javax.swing.JFrame)2 JPanel (javax.swing.JPanel)2 PolygonalMesh (maspack.geometry.PolygonalMesh)2 GenericPropertyHandle (maspack.properties.GenericPropertyHandle)2 RenderProps (maspack.render.RenderProps)2 File (java.io.File)1 JSeparator (javax.swing.JSeparator)1