Drafting with AI
Stable diffusion
Stable Diffusion은 2022년에 출시된 딥러닝 기반의 text-to-image 모델입니다. 주로 텍스트 설명을 기반으로 상세한 이미지를 생성하는 데 사용되며, inpainting, outpainting, 텍스트 프롬프트로 안내되는 image-to-image 변환과 같은 다른 작업에도 적용될 수 있습니다.
An image generated by Stable Diffusion based on the text prompt:
"a photograph of an astronaut riding a horse"
이 AI를 사용하여 이미지를 생성하면 몇 줄의 텍스트만으로도 쉽고 빠르게 그럴듯한 렌더링 이미지를 얻을 수 있습니다. 이것이 건축 분야에서 어떻게 활용될 수 있는지 살펴보겠습니다.

"a photograph of an astronaut riding a horse"
이 AI를 사용하여 이미지를 생성하면 몇 줄의 텍스트만으로도 쉽고 빠르게 그럴듯한 렌더링 이미지를 얻을 수 있습니다. 이것이 건축 분야에서 어떻게 활용될 수 있는지 살펴보겠습니다.
Application in the field of architecture
건축 설계 분야에서 자주 사용되는 여러 rendering engine이 있지만, 좋은 렌더링을 위해서는 정밀한 모델링이 필요합니다. 디자인 프로젝트 시작 단계에서는 매우 간단한 모델이나 스케치를 AI에 입력하고, prompt를 입력하여 우리가 구상하는 것에 대한 대략적인 아이디어를 얻을 수 있습니다.
먼저, 간단한 예시를 살펴보겠습니다. 아래 예시는 Rhino의
Demo for using stable diffusion in Rhino environment
Prompt: Colorful basketball court, Long windows, Sunlight
먼저, rhino viewport를 캡처하기 위한 코드를 작성해야 합니다. 현재 *.gh 파일이 위치한 경로에 저장되도록 만들었습니다.
다음으로,
먼저, 간단한 예시를 살펴보겠습니다. 아래 예시는 Rhino의
GhPython
환경에서 rhino viewport를 캡처한 다음 ControlNet of the stable diffusion API를 사용하여 원하는 방향으로 이미지를 렌더링하는 예시입니다. 
Prompt: Colorful basketball court, Long windows, Sunlight
먼저, rhino viewport를 캡처하기 위한 코드를 작성해야 합니다. 현재 *.gh 파일이 위치한 경로에 저장되도록 만들었습니다.
def capture_activated_viewport(
self, save_name="draft.png", return_size=False
):
"""
Capture and save the currently activated viewport
to the location of the current *.gh file path
"""
save_path = os.path.join(CURRENT_DIR, save_name)
viewport = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.CaptureToBitmap()
viewport.Save(save_path, Imaging.ImageFormat.Png)
if return_size:
return save_path, viewport.Size
return save_path
다음으로,
stable-diffusion-webui
repository를 clone한 후 local API server를 실행해야 합니다. local API server 실행에 필요한 설정은 이 AUTOMATIC1111/stable-diffusion-webui repository를 참조하세요. 모든 설정이 완료되면 API 호출을 통해 원하는 method를 요청할 수 있습니다. AUTOMATIC1111/stable-diffusion-webui/wiki/API의 API 가이드를 참조했습니다. Drafting
Python은 HTTP를 사용하기 위한
Physical model
From the left, Drfat view · Rendered view
Prompt: Isometric view, River, Trees, 3D printed white model with illumination
Interior view
From the left, Drfat view · Rendered view
Prompt: Interior view with sunlight, Curtain wall with city view, Colorful sofas, Cushions on the sofas, Transparent glass table, Fabric stools, Some flower pots
Floor plan
From the left, Drfat view · Rendered view
Prompt: Top view, With sunlight and shadows, Some flower pots, Colorful furnitures, Conceptual image
Skyscrappers in the city
From the left, Drfat view · Rendered view
Prompt: Skyscrapers in the city, Night scene with many stars in the sky, Neon sign has shine brightly, Milky way in the sky
Contour
From the left, Drfat view · Rendered view
Prompt: Bird's eye view, Colorful master plan, Bright photograph, River
Gabled houses
From the left, Drfat view · Rendered view
Prompt: Two points perspective, White clouds, Colorful houses, Sunlight
Kitchen
From the left, Drfat view · Rendered view
Prompt: Front view, Kitchen with black color interior, Illuminations
urllib
이라는 내장 모듈을 제공합니다. GhPython
에서 사용된 API 요청 코드는 이 링크에서 확인할 수 있습니다.
import os
import json
import Rhino
import base64
import urllib2
import scriptcontext as sc
import System.Drawing.Imaging as Imaging
class D2R:
"""Convert Draft to Rendered using `stable diffusion webui` API"""
def __init__(
self, prompt, width=512, height=512, local_url="http://127.0.0.1:7860"
):
self.prompt = prompt
self.width = width
self.height = height
self.local_url = local_url
(...)
def render(self, image_path, seed=-1, steps=20, draft_size=None):
payload = {
"prompt": self.prompt,
"negative_prompt": "",
"resize_mode": 0,
"denoising_strength": 0.75,
"mask_blur": 36,
"inpainting_fill": 0,
"inpaint_full_res": "true",
"inpaint_full_res_padding": 72,
"inpainting_mask_invert": 0,
"initial_noise_multiplier": 1,
"seed": seed,
"sampler_name": "Euler a",
"batch_size": 1,
"steps": steps,
"cfg_scale": 4,
"width": self.width if draft_size is None else draft_size.Width,
"height": self.height if draft_size is None else draft_size.Height,
"restore_faces": "false",
"tiling": "false",
"alwayson_scripts": {
"ControlNet": {
"args": [
{
"enabled": "true",
"input_image": self._get_decoded_image_to_base64(image_path),
"module": self.module_pidinet_scribble,
"model": self.model_scribble,
"processor_res": 1024,
},
]
}
}
}
request = urllib2.Request(
url=self.local_url + "/sdapi/v1/txt2img",
data=json.dumps(payload),
headers={'Content-Type': 'application/json'}
)
try:
response = urllib2.urlopen(request)
response_data = response.read()
rendered_save_path = os.path.join(CURRENT_DIR, "rendered.png")
converted_save_path = os.path.join(CURRENT_DIR, "converted.png")
response_data_jsonify = json.loads(response_data)
used_seed = json.loads(response_data_jsonify["info"])["seed"]
used_params = response_data_jsonify["parameters"]
for ii, image in enumerate(response_data_jsonify["images"]):
if ii == len(response_data_jsonify["images"]) - 1:
self._save_base64_to_png(image, converted_save_path)
else:
self._save_base64_to_png(image, rendered_save_path)
return (
rendered_save_path,
converted_save_path,
used_seed,
used_params
)
except urllib2.HTTPError as e:
print("HTTP Error:", e.code, e.reason)
response_data = e.read()
print(response_data)
return None
if __name__ == "__main__":
CURRENT_FILE = sc.doc.Path
CURRENT_DIR = "\\".join(CURRENT_FILE.split("\\")[:-1])
prompt = (
"""
Interior view with sunlight,
Curtain wall with city view
Colorful Sofas,
Cushions on the sofas
Transparent glass Table,
Fabric stools,
Some flower pots
"""
)
d2r = D2R(prompt=prompt)
draft, draft_size = d2r.capture_activated_viewport(return_size=True)
rendered, converted, seed, params = d2r.render(
draft, seed=-1, steps=50, draft_size=draft_size
)


From the left, Drfat view · Rendered view
Prompt: Isometric view, River, Trees, 3D printed white model with illumination


From the left, Drfat view · Rendered view
Prompt: Interior view with sunlight, Curtain wall with city view, Colorful sofas, Cushions on the sofas, Transparent glass table, Fabric stools, Some flower pots


From the left, Drfat view · Rendered view
Prompt: Top view, With sunlight and shadows, Some flower pots, Colorful furnitures, Conceptual image


From the left, Drfat view · Rendered view
Prompt: Skyscrapers in the city, Night scene with many stars in the sky, Neon sign has shine brightly, Milky way in the sky


From the left, Drfat view · Rendered view
Prompt: Bird's eye view, Colorful master plan, Bright photograph, River


From the left, Drfat view · Rendered view
Prompt: Two points perspective, White clouds, Colorful houses, Sunlight


From the left, Drfat view · Rendered view
Prompt: Front view, Kitchen with black color interior, Illuminations