Is there a way to batch render material swap? For instance, I have to render a chair, but I have to render it in 37 seat fabrics. I know I can do a region render and just render the seat over and over. But it's still the process of swapping the fabric and hitting render again. Any way to batch it so it's just Render > Swap Fabric > Render > Swap Fabric > etc... ?
Announcement
Collapse
No announcement yet.
Batching Material Replacement
Collapse
X
-
Hi,
We've prepared a script that you can try.
First you need to prepare your scene:
1.Create a Wrapper material and apply it to the parts of the chair you want to swap the materials of. The script will use the first Wrapper material as an identifier of what needs to be replaced.
2. Add "Replacement_" in the name of each material variation (for the materials you want to be replacing with).β
β
Then you can run the following to implement a subscriber:
Code:class MySubscriber def initialize(context, path, materials) @context = context @path = path @materials = materials context.subscribe(self) context.renderer.subscribe(self) end def on_model_exporter_created(model_exporter_created) model_exporter_created.subscribe(self) end def on_model_exported(exporter) renderer = exporter.renderer wrapper = renderer.grep(:MtlWrapper).first material = @materials.pop exporter.export_material(material) wrapper[:base_material] = renderer["/#{material.display_name}"] puts wrapper[:base_material] settings_output = renderer.grep(:SettingsOutput).first settings_output[:img_file] = "#{@path}/#{material.display_name}.png" puts("#{@path}/#{material.display_name}.png") end def on_state_changed(renderer, old_state, new_state, instant) if @materials.empty? clean_up elsif new_state == :idleDone next_render end end def next_render VRay::Command.render_production(context: @context) end def clean_up @context.unsubscribe(self) @context.renderer.unsubscribe(self) end endβ
Code:context = VRay::Context.active path = ENV['HOME'] materials = context.model.materials.select { |m| m.display_name[/Replacement/] } MySubscriber.new(context, path, materials)
The scene is going to be rendered multiple times, once for each material Replacement_.
Additional notes:
1. Replace the path value in the second script with an output folder of your liking. If you don't do that, the output images will be saved in C:/users/user
path = "C:\temp\chair_renders"
2. Change the /Replacement/ string in the second script with another keyword if do not want to use the default one.
3. Rerun the second script to render a batch again. Otherwise a regular render will be performed.
Let me know if that works for you?
KonstantinLast edited by konstantin_chaos; 13-03-2024, 03:45 AM.
Comment
Comment