bolajiev commited on
Commit ·
1707749
1
Parent(s): a60c2be
Add Glow toggle and strength slider — user-controllable bloom
Browse files- app.py +7 -4
- compiler.py +8 -3
app.py
CHANGED
|
@@ -49,7 +49,7 @@ EXAMPLES = [
|
|
| 49 |
]
|
| 50 |
|
| 51 |
|
| 52 |
-
def generate(prompt: str, use_mock: bool):
|
| 53 |
prompt = (prompt or "").strip()
|
| 54 |
if not prompt:
|
| 55 |
return gr.update(), gr.update(), gr.update(), "Type a prompt first."
|
|
@@ -70,7 +70,7 @@ def generate(prompt: str, use_mock: bool):
|
|
| 70 |
note = f"Model error, used mock fallback. ({type(e).__name__})"
|
| 71 |
|
| 72 |
scene = build_scene(extract_json(raw))
|
| 73 |
-
html = compile_html(scene)
|
| 74 |
pretty = json.dumps(scene.model_dump(), indent=2)
|
| 75 |
return iframe(html), html, pretty, note
|
| 76 |
|
|
@@ -98,6 +98,9 @@ with gr.Blocks(title="ThreeGen", theme=gr.themes.Soft()) as demo:
|
|
| 98 |
with gr.Row():
|
| 99 |
btn = gr.Button("Generate", variant="primary")
|
| 100 |
mock = gr.Checkbox(label="Mock (no GPU)", value=False)
|
|
|
|
|
|
|
|
|
|
| 101 |
gr.Examples(examples=EXAMPLES, inputs=prompt)
|
| 102 |
status = gr.Markdown("")
|
| 103 |
|
|
@@ -115,8 +118,8 @@ with gr.Blocks(title="ThreeGen", theme=gr.themes.Soft()) as demo:
|
|
| 115 |
scene_json = gr.Code(language="json", label="scene graph")
|
| 116 |
|
| 117 |
outputs = [preview, code, scene_json, status]
|
| 118 |
-
btn.click(generate, [prompt, mock], outputs)
|
| 119 |
-
prompt.submit(generate, [prompt, mock], outputs)
|
| 120 |
demo.load(_initial, None, outputs)
|
| 121 |
|
| 122 |
|
|
|
|
| 49 |
]
|
| 50 |
|
| 51 |
|
| 52 |
+
def generate(prompt: str, use_mock: bool, glow: bool, glow_strength: float):
|
| 53 |
prompt = (prompt or "").strip()
|
| 54 |
if not prompt:
|
| 55 |
return gr.update(), gr.update(), gr.update(), "Type a prompt first."
|
|
|
|
| 70 |
note = f"Model error, used mock fallback. ({type(e).__name__})"
|
| 71 |
|
| 72 |
scene = build_scene(extract_json(raw))
|
| 73 |
+
html = compile_html(scene, glow=glow, glow_strength=glow_strength)
|
| 74 |
pretty = json.dumps(scene.model_dump(), indent=2)
|
| 75 |
return iframe(html), html, pretty, note
|
| 76 |
|
|
|
|
| 98 |
with gr.Row():
|
| 99 |
btn = gr.Button("Generate", variant="primary")
|
| 100 |
mock = gr.Checkbox(label="Mock (no GPU)", value=False)
|
| 101 |
+
with gr.Row():
|
| 102 |
+
glow = gr.Checkbox(label="Glow", value=True)
|
| 103 |
+
glow_strength = gr.Slider(0.0, 2.0, value=0.9, step=0.1, label="Glow strength")
|
| 104 |
gr.Examples(examples=EXAMPLES, inputs=prompt)
|
| 105 |
status = gr.Markdown("")
|
| 106 |
|
|
|
|
| 118 |
scene_json = gr.Code(language="json", label="scene graph")
|
| 119 |
|
| 120 |
outputs = [preview, code, scene_json, status]
|
| 121 |
+
btn.click(generate, [prompt, mock, glow, glow_strength], outputs)
|
| 122 |
+
prompt.submit(generate, [prompt, mock, glow, glow_strength], outputs)
|
| 123 |
demo.load(_initial, None, outputs)
|
| 124 |
|
| 125 |
|
compiler.py
CHANGED
|
@@ -161,11 +161,13 @@ TEMPLATE = """<!DOCTYPE html>
|
|
| 161 |
__OBJECTS__
|
| 162 |
|
| 163 |
// ---- bloom post-processing ----
|
|
|
|
|
|
|
| 164 |
const composer = new EffectComposer(renderer);
|
| 165 |
composer.addPass(new RenderPass(scene, camera));
|
| 166 |
const bloom = new UnrealBloomPass(
|
| 167 |
new THREE.Vector2(window.innerWidth, window.innerHeight),
|
| 168 |
-
|
| 169 |
0.4, // radius
|
| 170 |
0.0 // threshold (0 = everything blooms a little)
|
| 171 |
);
|
|
@@ -177,7 +179,8 @@ TEMPLATE = """<!DOCTYPE html>
|
|
| 177 |
const t = clock.getElapsedTime();
|
| 178 |
__ANIM__
|
| 179 |
controls.update();
|
| 180 |
-
composer.render();
|
|
|
|
| 181 |
}
|
| 182 |
animate();
|
| 183 |
|
|
@@ -193,12 +196,14 @@ TEMPLATE = """<!DOCTYPE html>
|
|
| 193 |
"""
|
| 194 |
|
| 195 |
|
| 196 |
-
def compile_html(scene: Scene) -> str:
|
| 197 |
html = TEMPLATE
|
| 198 |
html = html.replace("__BG__", scene.background)
|
| 199 |
html = html.replace("__LIGHTS__", lights_js(scene))
|
| 200 |
html = html.replace("__OBJECTS__", objects_js(scene))
|
| 201 |
html = html.replace("__ANIM__", animation_js(scene.animation))
|
|
|
|
|
|
|
| 202 |
return html
|
| 203 |
|
| 204 |
|
|
|
|
| 161 |
__OBJECTS__
|
| 162 |
|
| 163 |
// ---- bloom post-processing ----
|
| 164 |
+
const USE_BLOOM = __USE_BLOOM__;
|
| 165 |
+
const BLOOM_STRENGTH = __BLOOM_STRENGTH__;
|
| 166 |
const composer = new EffectComposer(renderer);
|
| 167 |
composer.addPass(new RenderPass(scene, camera));
|
| 168 |
const bloom = new UnrealBloomPass(
|
| 169 |
new THREE.Vector2(window.innerWidth, window.innerHeight),
|
| 170 |
+
BLOOM_STRENGTH,
|
| 171 |
0.4, // radius
|
| 172 |
0.0 // threshold (0 = everything blooms a little)
|
| 173 |
);
|
|
|
|
| 179 |
const t = clock.getElapsedTime();
|
| 180 |
__ANIM__
|
| 181 |
controls.update();
|
| 182 |
+
if (USE_BLOOM) composer.render();
|
| 183 |
+
else renderer.render(scene, camera);
|
| 184 |
}
|
| 185 |
animate();
|
| 186 |
|
|
|
|
| 196 |
"""
|
| 197 |
|
| 198 |
|
| 199 |
+
def compile_html(scene: Scene, glow: bool = True, glow_strength: float = 0.9) -> str:
|
| 200 |
html = TEMPLATE
|
| 201 |
html = html.replace("__BG__", scene.background)
|
| 202 |
html = html.replace("__LIGHTS__", lights_js(scene))
|
| 203 |
html = html.replace("__OBJECTS__", objects_js(scene))
|
| 204 |
html = html.replace("__ANIM__", animation_js(scene.animation))
|
| 205 |
+
html = html.replace("__USE_BLOOM__", "true" if glow else "false")
|
| 206 |
+
html = html.replace("__BLOOM_STRENGTH__", str(float(glow_strength)))
|
| 207 |
return html
|
| 208 |
|
| 209 |
|