Blender Product Studio
Turns a raw model (often a Meshy AI GLB) into product-photo-ready scenes and outputs. All Blender work goes through the Blender connector's execute-code tool. Run the code in small steps and check each one with a viewport screenshot.
| Request | Section |
|---|---|
| polish, make it shiny/glossy, product lighting | A. Product polish |
| HDRI, studio setup, environment lighting | B. Studio setup |
| make it look like metal/wood/marble, apply texture | C. Texture apply |
| pedestal, showroom, build a scene | D. Scene builder |
| colour/finish options, material variants | E. Material swap |
| compare lighting, try environments | F. HDRI showcase |
| export for web, Three.js viewer | G. Web export |
Never clear the scene unless the user asks, or they're importing a fresh model and confirm. Name new objects clearly (Studio_Ground, Key, Pedestal).
PolyHaven helper (B–F)
This runs inside Blender, which downloads from PolyHaven's free public API on the user's machine. Cache files in ~/BlenderAssets/polyhaven/.
import bpy, os, json, urllib.request
CACHE = os.path.expanduser('~/BlenderAssets/polyhaven'); os.makedirs(CACHE, exist_ok=True)
UA = {'User-Agent': 'blender-product-studio'}
def ph_json(url):
return json.load(urllib.request.urlopen(urllib.request.Request(url, headers=UA)))
def ph_get(url):
path = os.path.join(CACHE, url.split('/')[-1])
if not os.path.exists(path):
with urllib.request.urlopen(urllib.request.Request(url, headers=UA)) as r, open(path, 'wb') as f:
f.write(r.read())
return path
def ph_search(kind='textures', category=None): # kind: hdris | textures | models
q = f'https://api.polyhaven.com/assets?t={kind}' + (f'&c={category}' if category else '')
return list(ph_json(q).keys())
def ph_hdri(asset_id, res='2k', strength=1.0, rot_deg=0):
import math
files = ph_json(f'https://api.polyhaven.com/files/{asset_id}')
path = ph_get(files['hdri'][res]['hdr']['url'])
w = bpy.context.scene.world or bpy.data.worlds.new('World')
bpy.context.scene.world = w; w.use_nodes = True
nt = w.node_tree; nt.nodes.clear()
tc = nt.nodes.new('ShaderNodeTexCoord'); mp = nt.nodes.new('ShaderNodeMapping')
env = nt.nodes.new('ShaderNodeTexEnvironment'); env.image = bpy.data.images.load(path, check_existing=True)
bg = nt.nodes.new('ShaderNodeBackground'); out = nt.nodes.new('ShaderNodeOutputWorld')
mp.inputs['Rotation'].default_value[2] = math.radians(rot_deg)
bg.inputs['Strength'].default_value = strength
nt.links.new(tc.outputs['Generated'], mp.inputs['Vector']); nt.links.new(mp.outputs['Vector'], env.inputs['Vector'])
nt.links.new(env.outputs['Color'], bg.inputs['Color']); nt.links.new(bg.outputs['Background'], out.inputs['Surface'])
def ph_material(asset_id, res='2k', scale=1.0):
if asset_id in bpy.data.materials: return bpy.data.materials[asset_id]
files = ph_json(f'https://api.polyhaven.com/files/{asset_id}')
def get(*keys):
for k in keys:
if k in files: return ph_get(files[k][res]['jpg']['url'])
mat = bpy.data.materials.new(asset_id); mat.use_nodes = True
nt = mat.node_tree; bsdf = nt.nodes['Principled BSDF']
tc = nt.nodes.new('ShaderNodeTexCoord'); mp = nt.nodes.new('ShaderNodeMapping')
mp.inputs['Scale'].default_value = (scale, scale, scale)
nt.links.new(tc.outputs['UV'], mp.inputs['Vector'])
def tex(path, non_color=False):
n = nt.nodes.new('ShaderNodeTexImage'); n.image = bpy.data.images.load(path, check_existing=True)
if non_color: n.image.colorspace_settings.name = 'Non-Color'
nt.links.new(mp.outputs['Vector'], n.inputs['Vector']); return n
if p := get('Diffuse', 'diff'): nt.links.new(tex(p).outputs['Color'], bsdf.inputs['Base Color'])
if p := get('Rough', 'rough'): nt.links.new(tex(p, True).outputs['Color'], bsdf.inputs['Roughness'])
if p := get('nor_gl', 'Normal'):
nm = nt.nodes.new('ShaderNodeNormalMap')
nt.links.new(tex(p, True).outputs['Color'], nm.inputs['Color']); nt.links.new(nm.outputs['Normal'], bsdf.inputs['Normal'])
if p := get('Metal', 'metal'): nt.links.new(tex(p, True).outputs['Color'], bsdf.inputs['Metallic'])
return mat
def assign(obj_name, mat):
o = bpy.data.objects[obj_name]
if o.data.materials: o.data.materials[0] = mat
else: o.data.materials.append(mat)
If an asset ID 404s, call ph_search with a category (e.g. metal, wood, studio) and pick the closest match. Objects without UVs need bpy.ops.uv.smart_project() in Edit Mode first.
A. Product polish
- Import if a file was given:
bpy.ops.import_scene.gltf(filepath=...). - Clean Meshy materials. Meshy normal/roughness maps cause dotty reflections, so unlink anything going into Normal/Roughness/Metallic, remove NORMAL_MAP/SEPARATE_COLOR nodes and unused image nodes, and keep Base Color.
- Principled BSDF: Roughness 0.02, Specular IOR Level 1.0, Coat Weight 1.0, Coat Roughness 0, Metallic 0.1, IOR 1.8, Transmission Weight 0.05. These are tunable: roughness 0 is a mirror, 1 is matte.
- Replace existing lights with a 4-point area rig. Location, colour: Key (2,-2,3), size 3, (1,.95,.9); Fill (-2.5,-1,2), size 4, (.9,.95,1); Rim (0,2,2.5), size 2, white; Bounce (0,0,-1) facing up, size 5. Energy (W) per preset:
- studio: 350/250/250/100
- dramatic: 500/80/400/50
- soft: 200/200/150/150
- World: colour (0.15,0.15,0.18), strength 0.3.
- Engine:
BLENDER_EEVEEwithscene.eevee.use_raytracing = True(wrap it in try) for smooth reflections while orbiting. Set the viewport to RENDERED and frame the selection.
B. Studio setup
Run ph_hdri(id, res, strength, rot). Optionally add a ground plane (size 10 at z = model bottom − 0.01) with ph_material(ground_id). Set the viewport to RENDERED.
Studio HDRIs: studio_small_09 (clean white), studio_small_08 (warm), studio_small_03 (soft), photo_studio_loft_hall, industrial_sunset_02_puresky (golden hour), kloppenheim_06_puresky (overcast), royal_esplanade (grand interior), venice_sunset, snowy_park_01, meadow_2.
C. Texture apply
Run assign(obj, ph_material(id, res, scale)). Popular IDs: brushed_metal, carbon_fiber, marble_01, wood_cabinet_worn_long, concrete_wall_003, leather_red_02, fabric_pattern_07. If an ID isn't found, search.
D. Scene builder
HDRI + ground + optional cylinder pedestal (radius ≈ 0.7× the model footprint, height ≈ 0.3× model height, placed under the model, model moved to sit on top) + optional PolyHaven models (/files/<id> → gltf entry, import, place beside the product without overlapping it).
Presets:
- showroom: studio_small_09 + marble_01 ground + pedestal
- outdoor: kloppenheim_06_puresky + concrete_wall_003
- minimal: studio_small_03, no ground
- dramatic: industrial_sunset_02_puresky + dark concrete + pedestal
E. Material swap (variant renders)
For each texture: assign it to the target object, set scene.render.filepath = <out>/<object>_<texture>.png, and render a still with bpy.ops.render.render(write_still=True). Use Cycles, 64 samples, 1920x1080. Render one variant per tool call to avoid timeouts.
Presets:
- metals: brushed_metal, rusty_metal, painted_metal_02, corrugated_iron
- woods: wood_cabinet_worn_long, plywood, bark_brown_02, wood_floor
- stones: marble_01, concrete_wall_003, rock_face, gravel_floor_02
- fabrics: fabric_pattern_07, leather_red_02, denim_fabric, burlap_01
F. HDRI showcase
Same loop over HDRIs (1k is enough), output <out>/hdri_<id>.png. Default set: studio_small_09, studio_small_03, photo_studio_loft_hall, royal_esplanade, industrial_sunset_02_puresky, kloppenheim_06_puresky. Sets: studios / outdoor / dramatic. Afterwards, offer a side-by-side grid (PIL or ffmpeg tile) and show it.
G. Three.js web export
- Export:
bpy.ops.export_scene.gltf(filepath=<out>/<name>.glb, export_format='GLB', export_draco_mesh_compression_enable=True, export_apply=True). - Write
<name>.htmlnext to it, using a single-file Three.js viewer with an import map from a pinned CDN version (e.g. [email protected] on cdn.jsdelivr.net), GLTFLoader + DRACOLoader, OrbitControls with damping,autoRotate(unless the user says no), a 3-point light rig plus RoomEnvironment for reflections, ACES tone mapping, background#111111(or the user's colour), auto-framing from the model's bounding box, and a responsive resize handler. - If they want a single file, base64-embed the GLB as a data URI. Note that
file://blocks loading a separate GLB in most browsers, so suggest serving it locally (python -m http.server) or using the embedded version. - Offer to publish the viewer as an artifact when they want a shareable link.
Rules
- Do one step per execute call and check with a screenshot. If a call fails, fix and retry at most twice, then report.
- Never overwrite the user's materials without asking. Duplicate them first (
mat.copy()) when changing the look of an existing asset. - Report output file paths at the end.