What I got now is a very basic setup that consists of an image and a button. When the button is pressed, luxconsole starts and renders a preview image, which is then after a fixed time saved to disk and loaded back into SketchUp.
Top: initial situation, Bottom: situation a few seconds after pushing the "refresh preview" button.
Pretty much everything is hardcoded now, but seeing that SU2LUX already contains material exporting code, I have the feeling that it shouldn't be terribly hard to integrate a preview there. However, there are two issues that I think should be investigated first:
1. luxconsole opens a window and closes after rendering, it would be nicer not to show it at all
2. the preview image is fetched after a fixed time; if the image is not ready by then the script will try to load an image that doesn't exist
3. There should be either a more elegant system to decide when to load the preview, progressive rendering or some system that tries to reload the preview after some time if at the initial time the preview isn't ready yet.
I assume that issue 1 is either easy to fix or unfixable, but issue 2 needs some work before starting any larger efforts. In particular when loading large image textures, it is likely that the preview image won't be ready in time. I can see two options, but of course there may be others still:
A. check if the image exists, if not, wait a second and check again; after a long time, give up
B. instead of waiting for a fixed number of seconds, wait for some feedback from luxconsole, like image data being sent through a pipe
Any feedback is appreciated.
pipe_test.rb:
- Code: Select all
@previewWindow = UI::WebDialog.new("Luxrender Material Editor", true, "preferences_test_window", 500, 500, 900, 400, true)
html = "c:/luxrender/skp_export/materialpreviewtest.html"
@previewWindow.set_url(html)
@previewWindow.show {}
def updatePreview
# first write the file
pipe = IO.popen("c:/lx08/luxconsole.exe -s c:/luxrender/skp_export/preview.lxs","r") # start rendering
id = UI.start_timer(7, false){@previewWindow.execute_script("updatePreviewJS()")}
end
@previewWindow.add_action_callback("get_data") do |web_dialog,actionname| updatePreview
end
- Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>SU2LUX Texture Editor Test</title>
<script>
function callRuby(pass_me_on) {
window.location.href = 'skp:get_data@' + pass_me_on; // lets Ruby know we want to start preview rendering action
}
function updatePreviewJS(){
document.getElementById("preview_image").src = "preview.png"; // updates preview image using saved image
}
</script>
</head>
<body>
<img src="empty_preview.png" id="preview_image">
<input type="button" id="preset_load" onclick="callRuby('update_preview')" value="refresh preview"> <!-- clicking triggers rendering process via Ruby !-->
</body>
</html>
