## material preview in SketchUp

Discussion related to the exporter plugin for SketchUp.

Moderators: Ratow, coordinators

### material preview in SketchUp

After some initial attempt working on a material preview in SketchUp about a year ago, I had another stab at it yesterday. The point where I got stuck last time was how to get the rendered image back into SketchUp, so that's where I focused on. Instead of getting the image data back through a pipe, on dougal2's advice I'm now just loading the rendered image file from disk and that seems to work pretty well.

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| updatePreviewend

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>

Abel

Posts: 1412
Joined: Sat Oct 20, 2007 8:13 am
Location: Helsinki, Finland

### Re: material preview in SketchUp

In the meantime, I've been trying out option A today and it seems to be workable. I need to do a bit more testing though before I'm confident enough to start messing around in SU2LUX.

edit: here it is

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 {}@preview_renderingtime = 5@time_out = 10@retry_interval = 1@filename = "c:/luxrender/skp_export/preview.png"@luxconsole_path = "c:/lx08/luxconsole.exe"@luxconsole_options = " -s "@preview_lxs = "c:/luxrender/skp_export/preview.lxs" def updatePreview   preview_command = @luxconsole_path + @luxconsole_options + @preview_lxs   pipe = IO.popen(preview_command,"r") # start rendering   @d = UI.start_timer(@preview_renderingtime+1, false){                # sets timer one second longer than rendering time      file_exists = File.file? @filename         @times_waited = 0      while (!file_exists && @times_waited < @time_out)    # if no image is found, wait for file to be rendered         print("no image found, timing out in ", @time_out-@times_waited, " seconds\n")         sleep 1         @times_waited += 1      end         while (file_exists && ((Time.now()-File.mtime(@filename)) > @preview_renderingtime) && (@times_waited < @time_out))          puts("old preview found, waiting for update...")            # if an old image is found, wait for update         sleep 1         @times_waited += 1      end         if (@times_waited >= (@time_out))                  # if the waiting has surpassed the time out limit, give up         puts("preview is taking too long, aborting")         UI.messagebox("The preview rendering process is taking longer than expected. Please try increasing the timeout setting or report on the LuxRender forum.")      end      if (@times_waited < @time_out && (Time.now()-File.mtime(@filename)) < (@preview_renderingtime+@time_out))         puts("all is well, updating preview")         @previewWindow.execute_script("updatePreviewJS()")      end   }end

Abel

Posts: 1412
Joined: Sat Oct 20, 2007 8:13 am
Location: Helsinki, Finland

### Re: material preview in SketchUp

Thanks Abel, feel free to try and implement yourself, as I am busy with uni atm, but I will give it a shot if I have the time
lfrisken

Posts: 129
Joined: Fri Apr 24, 2009 5:46 am

### Re: material preview in SketchUp

lfrisken wrote:feel free to try and implement yourself

I'm working on that at the moment but it will take a while still. I'm mostly struggling with accessing the LuxRender material definitions within SketchUp; I get the impression that they are created at startup and when creating a new material, but I'm having trouble exporting one without accidentally adding a material to the list - or maybe I'm just worried about nothing. In any case, I'll do some more testing and hope to have something working within a week or two.

Abel

Posts: 1412
Joined: Sat Oct 20, 2007 8:13 am
Location: Helsinki, Finland

### Re: material preview in SketchUp

um, yep I think materials in the exporter at the moment were just a hack job to get some colour on the screen, so any work on them, even replacing the existing system would be a major improvement.
lfrisken

Posts: 129
Joined: Fri Apr 24, 2009 5:46 am

### Re: material preview in SketchUp

It took a while but I finally got something working.

It's a work in progress but as I'm progressing I notice that there are more and more areas of SU2LUX that I'm touching; before I make a complete mess out of it, it would be good if at least one of the committers could have a look to see if things are going in the right direction.

-there is now a preview image + refresh button in the Material preview field
-clicking the button will generate a lxs and lxm file for the material and render the image, which will then replace the current preview image
-on OS X, SU2LUX's Material editor dropdown now shows the available materials (this was broken before)

things that are far from ideal:
-when updating a material definition, a new preview gets rendered when pressing the refresh button, but the image doesn't get updated in the interface
-the preview scene is not suitable at all for transparent materials
-materials with textures throw an error
-when changing materials, the preview is not automatically updated
-on OS X, the active SketchUp material and the selected material in SU2LUX's Material editor are not synchronized

things that I ran into that were already broken:
-UV mapping scale is wrong on exported models
-the Material editor doesn't have a scroll bar on OS X

I've taken the latest version of SU2LUX as a starting point, so the one including donjuan's changes as committed by mimhotep. I hope to fix all issues I mentioned in the coming weeks, but seeing how busy life tends to be I'm not making any promises.
Attachments
fileutils.zip
SU2LUX_mat_preview.zip

Abel

Posts: 1412
Joined: Sat Oct 20, 2007 8:13 am
Location: Helsinki, Finland

### Re: material preview in SketchUp

hi,

Error windows skectup program " no found files fileutils.rb"

help !!!

thanks

Posts: 6
Joined: Fri Jan 23, 2009 2:16 pm

### Re: material preview in SketchUp

yblade wrote:Error windows skectup program " no found files fileutils.rb"

Sorry about that, I've now attached that file to my previous message. I'd suggest to wait until the next update though, the material system should get much more usable.

Abel

Posts: 1412
Joined: Sat Oct 20, 2007 8:13 am
Location: Helsinki, Finland

### Re: material preview in SketchUp

OK... its work!!
Greetings..

povmaniaco

Posts: 161
Joined: Tue Sep 01, 2009 1:27 pm
Location: Barcelona, Spain

### Re: material preview in SketchUp

Is the preview working right?
I added noise aware and outlierejection to the exporter but I didn't use this version with preview, because I didn't know it.
Is it functional now?
donjuan

Posts: 195
Joined: Fri Oct 28, 2011 12:37 pm
Location: Argentina

Next

### Who is online

Users browsing this forum: No registered users and 2 guests