Skip to content

Commit

Permalink
Allow selecting renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
shmuelzon committed Jul 13, 2024
1 parent 6d9131f commit 75e3cda
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 12 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ the room they're located in. Please verify the list matches your expectations.
* Sensitivity - [1, 100] The degree by which two pixels need to be different
from one another to be taken into account for the generated overlay image.
Only relevant for "room overlay" light mixing mode
* Renderer - Select which rendering engine to use, YafaRay or SunFlow
* Quality - Choose the rendering quality (low or high)
* Output directory - The location on your PC where the floor plan images and
YAML will be saved

Expand Down Expand Up @@ -95,7 +97,7 @@ When using the "Room overlay" light mixing mode, it's also suggested to:
* Close all the doors between individually lighted rooms

## Possible Future Enhancements
- [ ] Allow selecting renderer (SunFlow/Yafaray)
- [x] Allow selecting renderer (SunFlow/Yafaray)
- [x] Allow selecting quality (high/low)
- [ ] Allow selecting date/time of render
- [ ] Create multiple renders for multiple hours of the day and display in Home
Expand Down
Binary file modified doc/options.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ HomeAssistantFloorPlan.Panel.lightMixingModeComboBox.OVERLAY.text=Room overlay
HomeAssistantFloorPlan.Panel.lightMixingModeComboBox.FULL.text=Complete renders
HomeAssistantFloorPlan.Panel.sensitivityLabel.text=Sensitivity:

HomeAssistantFloorPlan.Panel.QualityLabel.text=Quality:
HomeAssistantFloorPlan.Panel.QualityComboBox.LOW.text=Low
HomeAssistantFloorPlan.Panel.QualityComboBox.HIGH.text=High
HomeAssistantFloorPlan.Panel.rendererLabel.text=Renderer:
HomeAssistantFloorPlan.Panel.rendererComboBox.SUNFLOW.text=SunFlow
HomeAssistantFloorPlan.Panel.rendererComboBox.YAFARAY.text=YafaRay
HomeAssistantFloorPlan.Panel.qualityLabel.text=Quality:
HomeAssistantFloorPlan.Panel.qualityComboBox.LOW.text=Low
HomeAssistantFloorPlan.Panel.qualityComboBox.HIGH.text=High

HomeAssistantFloorPlan.Panel.outputDirectoryLabel.text=Output directory:
HomeAssistantFloorPlan.Panel.outputDirectory.title=Choose floor-plan output directory
Expand Down
19 changes: 16 additions & 3 deletions src/com/shmuelzon/HomeAssistantFloorPlan/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
public class Controller {
public enum Property {COMPLETED_RENDERS, LIGHT_MIXING_MODE}
public enum LightMixingMode {CSS, OVERLAY, FULL}
public enum Renderer {YAFARAY, SUNFLOW}
public enum Quality {HIGH, LOW}

private Home home;
Expand All @@ -55,7 +56,8 @@ public enum Quality {HIGH, LOW}
private int renderWidth = 1024;
private int renderHeight = 576;
private boolean useExistingRenders = true;
private Quality quality;
private Renderer renderer = Renderer.YAFARAY;
private Quality quality = Quality.HIGH;

class StateIcon {
public String name;
Expand All @@ -81,7 +83,6 @@ public Controller(Home home) {
lightsNames = new ArrayList<String>(lights.keySet());
lightsPower = getLightsPower(lights);
homeAssistantEntities = getHomeAssistantEntities();
this.quality = Quality.HIGH;
}

public void addPropertyChangeListener(Property property, PropertyChangeListener listener) {
Expand Down Expand Up @@ -158,6 +159,14 @@ public void setUserExistingRenders(boolean useExistingRenders) {
this.useExistingRenders = useExistingRenders;
}

public Renderer getRenderer() {
return renderer;
}

public void setRenderer(Renderer renderer) {
this.renderer = renderer;
}

public Quality getQuality() {
return quality;
}
Expand Down Expand Up @@ -381,8 +390,12 @@ private void prepareScene(List<String> onLights) {
}

private BufferedImage renderScene() throws IOException {
Map<Renderer, String> rendererToClassName = new HashMap<Renderer, String>() {{
put(Renderer.SUNFLOW, "com.eteks.sweethome3d.j3d.PhotoRenderer");
put(Renderer.YAFARAY, "com.eteks.sweethome3d.j3d.YafarayRenderer");
}};
AbstractPhotoRenderer photoRenderer = AbstractPhotoRenderer.createInstance(
"com.eteks.sweethome3d.j3d.YafarayRenderer",
rendererToClassName.get(renderer),
home, null, this.quality == Quality.LOW ? AbstractPhotoRenderer.Quality.LOW : AbstractPhotoRenderer.Quality.HIGH);
BufferedImage image = new BufferedImage(renderWidth, renderHeight, BufferedImage.TYPE_INT_RGB);
photoRenderer.render(image, home.getCamera(), null);
Expand Down
36 changes: 31 additions & 5 deletions src/com/shmuelzon/HomeAssistantFloorPlan/Panel.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ private enum ActionType {BROWSE, START, CLOSE}
private JComboBox lightMixingModeComboBox;
private JLabel sensitivityLabel;
private JSpinner sensitivitySpinner;
private JLabel rendererLabel;
private JComboBox rendererComboBox;
private JLabel qualityLabel;
private JComboBox qualityComboBox;
private JLabel outputDirectoryLabel;
Expand Down Expand Up @@ -223,14 +225,31 @@ public void stateChanged(ChangeEvent ev) {
}
});

rendererLabel = new JLabel();
rendererLabel.setText(resource.getString("HomeAssistantFloorPlan.Panel.rendererLabel.text"));
rendererComboBox = new JComboBox<Controller.Renderer>(Controller.Renderer.values());
rendererComboBox.setSelectedItem(controller.getRenderer());
rendererComboBox.setRenderer(new DefaultListCellRenderer() {
public Component getListCellRendererComponent(JList<?> jList, Object o, int i, boolean b, boolean b1) {
Component rendererComponent = super.getListCellRendererComponent(jList, o, i, b, b1);
setText(resource.getString(String.format("HomeAssistantFloorPlan.Panel.rendererComboBox.%s.text", ((Controller.Renderer)o).name())));
return rendererComponent;
}
});
rendererComboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
controller.setRenderer((Controller.Renderer)rendererComboBox.getSelectedItem());
}
});

qualityLabel = new JLabel();
qualityLabel.setText(resource.getString("HomeAssistantFloorPlan.Panel.QualityLabel.text"));
qualityLabel.setText(resource.getString("HomeAssistantFloorPlan.Panel.qualityLabel.text"));
qualityComboBox = new JComboBox<Controller.Quality>(Controller.Quality.values());
qualityComboBox.setSelectedItem(controller.getQuality());
qualityComboBox.setRenderer(new DefaultListCellRenderer() {
public Component getListCellRendererComponent(JList<?> jList, Object o, int i, boolean b, boolean b1) {
Component rendererComponent = super.getListCellRendererComponent(jList, o, i, b, b1);
setText(resource.getString(String.format("HomeAssistantFloorPlan.Panel.QualityComboBox.%s.text", ((Controller.Quality)o).name())));
setText(resource.getString(String.format("HomeAssistantFloorPlan.Panel.qualityComboBox.%s.text", ((Controller.Quality)o).name())));
return rendererComponent;
}
});
Expand Down Expand Up @@ -306,6 +325,7 @@ private void setComponentsEnabled(boolean enabled) {
heightSpinner.setEnabled(enabled);
lightMixingModeComboBox.setEnabled(enabled);
sensitivitySpinner.setEnabled(enabled);
rendererComboBox.setEnabled(enabled);
qualityComboBox.setEnabled(enabled);
outputDirectoryTextField.setEnabled(enabled);
outputDirectoryBrowseButton.setEnabled(enabled);
Expand Down Expand Up @@ -358,13 +378,19 @@ private void layoutComponents() {
3, 3, 1, 1, 0, 0, GridBagConstraints.CENTER,
GridBagConstraints.HORIZONTAL, insets, 0, 0));

/* Fifth row (Quality) */
add(qualityLabel, new GridBagConstraints(
/* Fifth row (Renderer + Quality) */
add(rendererLabel, new GridBagConstraints(
0, 4, 1, 1, 0, 0, GridBagConstraints.CENTER,
GridBagConstraints.HORIZONTAL, insets, 0, 0));
add(qualityComboBox, new GridBagConstraints(
add(rendererComboBox, new GridBagConstraints(
1, 4, 1, 1, 0, 0, GridBagConstraints.CENTER,
GridBagConstraints.HORIZONTAL, insets, 0, 0));
add(qualityLabel, new GridBagConstraints(
2, 4, 1, 1, 0, 0, GridBagConstraints.CENTER,
GridBagConstraints.HORIZONTAL, insets, 0, 0));
add(qualityComboBox, new GridBagConstraints(
3, 4, 1, 1, 0, 0, GridBagConstraints.CENTER,
GridBagConstraints.HORIZONTAL, insets, 0, 0));

/* Sixth row (Output directory) */
add(outputDirectoryLabel, new GridBagConstraints(
Expand Down

0 comments on commit 75e3cda

Please sign in to comment.