3D 模型變圖片:可信任的開放 3D 平台整理,用 three.js 做出小套房情境圖

3D 模型變圖片:可信任的開放 3D 平台整理,用 three.js 做出小套房情境圖(文章封面)

3D 實戰教學 / 測試日期 2026 年 11 月

最近社群討論區常看到一個話題:越來越多平台把 3D 模型檔公開,而且開放用程式直接取用。像美國大都會藝術博物館在 2026 年 2 月一口氣公開了 100 多件館藏的高解析 3D 模型,多數可以免費下載、自由使用。

問題是:哪些平台可以放心用?要怎麼用程式把模型抓下來?抓下來之後,又怎麼變成一張可以放進簡報、貼文或教材的圖片?這篇整理可信任的平台與授權,再用兩個實際做過的範例示範:一個是把單一模型轉成透明背景 PNG,另一個是用線上的家具模型加上 three.js,組出一間有角色在看電視、煮菜的小套房,從不同角度輸出四張情境圖。

先看成果,下面這張圖裡的家具全部是從網路上的 CC0 模型庫即時載入,房間、燈光和鏡頭則是程式寫的:

用 three.js 組成的小套房全景:左邊廚房與餐桌,右邊沙發、電視與盆栽,三個機器人角色分別在煮菜、吃早餐、看電視
圖 1 小套房全景:家具來自 Poly Haven,角色來自 three.js 官方範例,全部由程式組合與渲染

30 秒看重點

CC0

Poly Haven 的 2,387 件素材全部 CC0,可商用、不用標示,API 不需要金鑰

100+

大都會博物館 2026 年 2 月公開的 3D 模型數,多數在 Open Access 計畫下可自由使用

GLB

網頁、遊戲引擎、AR 都吃的 3D 通用格式,可以想成「3D 界的 JPG」

約 80 行

把一個 GLB 轉成透明背景 PNG 所需的網頁程式長度(範例一)

4 張

同一個小套房場景,換 4 組鏡頭就輸出 4 張不同情境的圖(範例二)

資料:Poly Haven API(2026 年 11 月實查)、The Met 新聞稿,詳見文末資料來源。

00先搞懂格式:GLB 就是 3D 界的 JPG

照片有 JPG、PNG,3D 模型也有通用格式。現在最常見的是 glTF,以及把模型、材質、貼圖打包成單一檔案的 GLB。它由制定 WebGL 的 Khronos 組織維護,網頁上的 three.js、Babylon.js,遊戲引擎 Unity、Godot,以及手機 AR 都能直接讀。

為什麼「能用程式取用」很重要

以前下載 3D 模型要一個個點網頁、解壓縮、匯入軟體。現在平台提供 API,加上 GLB 可以直接在瀏覽器載入,程式就能自己搜尋模型、下載、擺進場景、拍照輸出。換句話說,3D 模型變成可以被程式「呼叫」的素材,這也是 AI 能幫你寫 3D 程式的前提。

01可信任的開放 3D 平台:先看授權,再看 API

下面六個來源都是機構或長期經營的平台,授權寫得清楚。表格最後一欄是用程式取得模型的方式:

平台(說明)授權程式怎麼取得
Poly Haven
南非團隊經營,人工製作的寫實模型、貼圖、HDRI;目前 2,387 件素材,其中 521 個模型
全部 CC0,可商用、免標示免金鑰 API(api.polyhaven.com),請求要帶 User-Agent
Sketchfab
全球最大的 3D 模型分享平台,超過 100 萬個 CC 授權的免費模型
每件不同(CC0、CC BY 等),多數可商用Download API;使用者要登入 Sketchfab 帳號(OAuth),提供 glTF、GLB、USDZ
史密森尼學會 Open Access
美國博物館群的文物、標本 3D 掃描,約 3,400 個 CC0 的 3D 套件
標示 CC0 的可商用3D API(官方標示為 alpha 版),提供 glTF、GLB、OBJ、USD
大都會藝術博物館 The Met
2026 年 2 月起公開 100 多件館藏的高解析 3D 模型,之後陸續增加
多數在 Open Access 計畫下為 CC0在作品頁手動下載;館藏 API 目前提供資料,但還沒有 3D 下載網址
NASA 3D Resources
太空船、探測器、行星等模型
免費使用,依 NASA 媒體使用規範GitHub 儲存庫直接下載
Khronos glTF Sample Assets
glTF 標準組織的測試模型,最適合練習
每件寫在 metadata.json,部分為 CC0GitHub raw 網址可直接載入(範例一使用)

資料:各平台官方頁面與 API,2026 年 11 月查詢;Poly Haven 數量為 API 實查,史密森尼數量依 Hugging Face 上的 CC0 整理資料集。

看授權,先看這兩個字

CC0 代表作者放棄權利,商用、修改都不必標示;CC BY 可以商用,但要標示作者。Sketchfab 和 Khronos 範例庫是「每件不同」,用之前要點進該模型確認。

02想讓 AI 直接生出 3D 檔:三個常見選擇

另一種「用程式做出 3D 檔」的方式,是讓 AI 從一張圖片或一段文字生成模型。社群(例如 Reddit 的本地 AI 討論區)目前最常被推薦的免費開源模型是微軟的 TRELLIS.2;不想自己架設的人,則多半用雲端 API:

工具(說明)授權/費用怎麼使用
Microsoft TRELLIS.2
單張圖片轉 3D,40 億參數,輸出含 PBR 材質的網格
MIT 開源自己架設;需要高階 NVIDIA 顯卡,多份整理指出約 24GB 顯示記憶體
騰訊 Hunyuan3D
圖片或文字轉 3D,形狀與貼圖分開生成
騰訊社群授權,不適用於歐盟、英國、南韓自己架設,或使用線上版
Meshy API
雲端服務,文字轉 3D、圖片轉 3D、自動綁骨
預先購買點數;Meshy-6 圖片轉 3D 每次 20–35 點REST API,回傳 GLB 等格式

資料:TRELLIS.2 專案頁、Hunyuan3D-2 授權條款、Meshy API 價格頁(2026 年 11 月)。

AI 生成的模型很適合快速做出「沒有現成模型」的東西,但看不到的那一面是 AI 推測出來的,拓樸也常需要整理。要放進正式作品,現成的 CC0 模型通常比較穩定。

03用程式取得模型:兩個 API 範例

Poly Haven:不用註冊就能查

1

查清單

/assets?type=models 列出全部模型,加 categories=furniture 只看家具

2

查檔案

/files/模型代號 回傳各種格式與解析度的下載網址

3

載入

取 gltf 的 1k 版本,貼圖與 .bin 的網址在 include 欄位裡

Poly Haven API 查詢

# 1. 列出 Poly Haven 所有「家具」類模型(回傳 JSON)
curl -A "MyClassDemo/1.0" "https://api.polyhaven.com/assets?type=models&categories=furniture"

# 2. 查沙發 sofa_02 的檔案清單:gltf → 1k → gltf → url 就是模型網址
curl -A "MyClassDemo/1.0" "https://api.polyhaven.com/files/sofa_02"

Sketchfab:要使用者登入

Sketchfab 為了防止濫用,下載一定要先申請。流程是使用者登入取得 token、呼叫 download 端點拿到暫時網址、下載 ZIP 再解壓縮:

Sketchfab 下載申請

# Sketchfab:先讓使用者用 OAuth 登入取得 token,再申請下載
curl "https://api.sketchfab.com/v3/models/{模型UID}/download" \
  -H "Authorization: Bearer {使用者的 OAuth token}"
# 回傳的 gltf.url 是暫時網址(約 5 分鐘內有效),下載後解壓縮就是 scene.gltf

04範例一:一個 GLB 變成透明背景 PNG

第一個範例是最小可用的工具:一個網頁載入 GLB,可以拖曳旋轉、調角度,按一下就下載透明背景的 PNG。範例模型用 Khronos 範例庫裡的收音機(CC0),也可以換成任何 GLB 網址,或直接選電腦裡的檔案。

3D 模型轉圖片小工具的畫面:上方有網址欄、選擇檔案、角度滑桿、透明背景與下載 PNG 按鈕,中間是透明背景上的 3D 收音機
圖 2 範例一實際在 Chrome 執行的畫面,棋盤格代表透明背景
1

存成檔案

把下面的程式碼存成 viewer.html

2

用本機網站開啟

在同一個資料夾執行 python -m http.server 8000,再開 http://localhost:8000/viewer.html

3

調整並下載

拖曳旋轉或拉角度滑桿,按「下載 PNG」

viewer.html(範例一)

<!doctype html>
<html lang="zh-Hant">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>3D 模型轉圖片小工具</title>
<style>
  body { margin: 0; font-family: system-ui, sans-serif; background: #eef1f6; color: #1a1f2e; }
  #bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px; background: #fff; border-bottom: 1px solid #ccd; }
  #bar input[type=text] { flex: 1 1 360px; padding: 6px 8px; }
  #bar button { padding: 6px 14px; border: 0; border-radius: 6px; background: #2E6BFF; color: #fff; cursor: pointer; }
  #msg { padding: 8px 12px; font-size: 14px; }
  #stage { display: flex; justify-content: center; padding: 16px; }
  canvas { max-width: 100%; height: auto; border-radius: 8px; background: repeating-conic-gradient(#ddd 0 25%, #fff 0 50%) 0 0 / 20px 20px; }
</style>
<script type="importmap">
{ "imports": {
  "three": "https://cdn.jsdelivr.net/npm/three@0.187.0/build/three.module.js",
  "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.187.0/examples/jsm/"
} }
</script>
</head>
<body>
<div id="bar">
  <input type="text" id="url" value="https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Assets/main/Models/BoomBox/glTF-Binary/BoomBox.glb">
  <button id="loadUrl">載入網址</button>
  <input type="file" id="file" accept=".glb">
  <label>角度 <input type="range" id="az" min="0" max="360" value="35"></label>
  <label><input type="checkbox" id="transparent" checked> 透明背景</label>
  <button id="shot">下載 PNG</button>
</div>
<div id="msg">拖曳畫面可以旋轉,滾輪可以縮放。</div>
<div id="stage"><canvas id="c"></canvas></div>

<script type="module">
import * as THREE from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';

// 網址參數:?model=模型網址&az=角度&w=寬&h=高&bg=ffffff(不給 bg 就是透明)
const q = new URLSearchParams(location.search);
const W = +q.get('w') || 1200, H = +q.get('h') || 900;
const canvas = document.getElementById('c');
const msg = document.getElementById('msg');

// preserveDrawingBuffer: true 才能把畫面存成圖片
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true, preserveDrawingBuffer: true });
renderer.setPixelRatio(1);
renderer.setSize(W, H, false);
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.outputColorSpace = THREE.SRGBColorSpace;

const scene = new THREE.Scene();
scene.environment = new THREE.PMREMGenerator(renderer).fromScene(new RoomEnvironment(), 0.04).texture;
const camera = new THREE.PerspectiveCamera(35, W / H, 0.01, 1000);
const controls = new OrbitControls(camera, canvas);
controls.addEventListener('change', render);

let model = null, radius = 1;
function setBackground() {
  const bg = q.get('bg');
  const transparent = document.getElementById('transparent').checked && !bg;
  scene.background = transparent ? null : new THREE.Color('#' + (bg || 'ffffff'));
}
function placeCamera(azDeg) {
  const a = THREE.MathUtils.degToRad(azDeg);
  const d = radius * 3.2;
  camera.position.set(Math.sin(a) * d, radius * 0.8, Math.cos(a) * d);
  camera.near = radius / 100; camera.far = radius * 100; camera.updateProjectionMatrix();
  controls.target.set(0, 0, 0); controls.update();
}
function render() { renderer.render(scene, camera); }

async function loadModel(src) {
  window.__ready = false;
  msg.textContent = '載入中…';
  const gltf = await new GLTFLoader().loadAsync(src);
  if (model) scene.remove(model);
  model = gltf.scene;
  // 把模型移到畫面中心,並依大小決定相機距離
  const box = new THREE.Box3().setFromObject(model);
  const center = box.getCenter(new THREE.Vector3());
  model.position.sub(center);
  radius = box.getSize(new THREE.Vector3()).length() / 2;
  scene.add(model);
  setBackground();
  placeCamera(+document.getElementById('az').value);
  render();
  msg.textContent = '載入完成,可以旋轉後按「下載 PNG」。';
  window.__ready = true;
}

function downloadPNG() {
  render();
  const a = document.createElement('a');
  a.download = 'model-' + Date.now() + '.png';
  a.href = canvas.toDataURL('image/png');
  a.click();
}

document.getElementById('loadUrl').onclick = () => loadModel(document.getElementById('url').value).catch(e => msg.textContent = '載入失敗:' + e.message);
document.getElementById('file').onchange = e => { const f = e.target.files[0]; if (f) loadModel(URL.createObjectURL(f)); };
document.getElementById('az').oninput = e => { placeCamera(+e.target.value); render(); };
document.getElementById('transparent').onchange = () => { setBackground(); render(); };
document.getElementById('shot').onclick = downloadPNG;

if (q.get('az')) document.getElementById('az').value = q.get('az');
loadModel(q.get('model') || document.getElementById('url').value).catch(e => { msg.textContent = '載入失敗:' + e.message; window.__error = e.message; });
</script>
</body>
</html>

能存成圖片的關鍵

建立 WebGLRenderer 時要加 preserveDrawingBuffer: true,再用 canvas.toDataURL 取出畫面;alpha: true 加上不設背景色,輸出的 PNG 就是透明背景。

進階:一次輸出很多張

要做商品圖、教材圖時,常需要很多模型乘上很多角度。下面這支 Python 腳本用 Playwright 開啟同一個 viewer.html,靠網址參數換模型與角度,3 個模型 × 3 個角度一次輸出 9 張 PNG(我們實測過,背景確實是透明的):

batch_render.py

"""批次把 3D 模型轉成 PNG:每個模型輸出 3 個角度。
使用前:
  pip install playwright
  playwright install chromium
  在 viewer.html 所在資料夾執行:python -m http.server 8000
然後另開一個終端機執行:python batch_render.py
"""
import asyncio, base64
from pathlib import Path
from urllib.parse import quote
from playwright.async_api import async_playwright

BASE = 'http://localhost:8000/viewer.html'
RAW = 'https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Assets/main/Models'
MODELS = {
    'boombox': f'{RAW}/BoomBox/glTF-Binary/BoomBox.glb',
    'avocado': f'{RAW}/Avocado/glTF-Binary/Avocado.glb',
    'bottle': f'{RAW}/WaterBottle/glTF-Binary/WaterBottle.glb',
}
ANGLES = [0, 45, 135]          # 相機繞模型的角度
OUT = Path('renders'); OUT.mkdir(exist_ok=True)

async def main():
    async with async_playwright() as p:
        browser = await p.chromium.launch(args=['--enable-unsafe-swiftshader', '--use-angle=swiftshader'])
        page = await browser.new_page(viewport={'width': 1300, 'height': 1100})
        for name, url in MODELS.items():
            for az in ANGLES:
                await page.goto(f'{BASE}?model={quote(url, safe="")}&az={az}&w=1200&h=900')
                await page.wait_for_function('window.__ready === true || window.__error', timeout=120000)
                path = OUT / f'{name}_{az:03d}.png'
                data = await page.evaluate("document.getElementById('c').toDataURL('image/png')")
                path.write_bytes(base64.b64decode(data.split(',')[1]))   # 直接取畫布像素,保留透明背景
                print('已輸出', path)
        await browser.close()

asyncio.run(main())

執行方式

# 在 viewer.html 所在的資料夾開一個本機網站
python -m http.server 8000

# 另開一個終端機,安裝套件後執行批次輸出
pip install playwright
playwright install chromium
python batch_render.py

05範例二:用線上模型組一間小套房

接下來把多個模型組成一個有故事的場景。這間 6 公尺 × 4.5 公尺的小套房分成廚房、餐桌和客廳三區,三個角色分別在煮菜、吃早餐、看電視。程式的結構只有四步:

1

用方塊蓋房間

地板、兩面牆、窗戶、掛畫、地毯都是 BoxGeometry,只蓋後牆和左牆,像娃娃屋一樣從外面看進去

2

載入 15 件家具

從 Poly Haven API 載入,每件只要寫代號、座標、旋轉與縮放

3

放角色、定姿勢

同一個角色模型複製三份,分別停在 Sitting、Idle 動作的某一格

4

一個情境一組鏡頭

每組鏡頭記錄位置、看向哪裡、視角,切換後重新渲染再存圖

用到的模型來源授權
沙發、電視、電視櫃、茶几、盆栽、抽屜櫃Poly Haven(sofa_02、television_02 等)CC0
電爐、平底鍋、琺瑯鍋、砧板、電熱水壺、木櫃Poly Haven(electric_stove、brass_pan_01 等)CC0
圓桌、餐椅、可頌Poly Haven(round_wooden_table_01 等)CC0
機器人角色(含 14 種動作)three.js 官方範例 RobotExpressive,作者 Tomás LaulhéCC0
房間、地毯、電視畫面、鍋裡的菜程式用方塊和球體畫出來自製

資料:Poly Haven 與 three.js 儲存庫中的授權說明,2026 年 11 月確認。

同一個場景換三組鏡頭,就得到三張不同情境的圖:

機器人坐在沙發上看電視,前方是茶几、發著藍光的電視和盆栽
圖 3 看電視:鏡頭放在沙發後方偏右,電視畫面用發光平面加點光源
機器人站在白色電爐前煮菜,鍋裡有紅黃綠的食材,旁邊是木頭櫃與砧板
圖 4 煮菜:鏡頭從角色右前方拍,鍋裡的菜是程式畫的小球
機器人坐在圓形木桌前,桌上放著一個可頌,背景有窗戶和木櫃
圖 5 吃早餐:鏡頭移到桌子另一側,才看得到角色的臉

為什麼主角是機器人

能自由使用、又內建坐、站、走、揮手等動作的人物模型其實不多。RobotExpressive 是 CC0,而且一個檔案就有 14 種動作,很適合入門。想換成真人角色,把 GLB 網址換掉、改用該模型的動作名稱即可,但記得先確認那個角色的授權。

room.html(範例二,完整程式)

<!doctype html>
<html lang="zh-Hant">
<head>
<meta charset="utf-8">
<title>小套房 3D 場景:用程式產生情境圖</title>
<style>
  body { margin: 0; font-family: system-ui, sans-serif; background: #22252b; color: #fff; }
  #bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 12px; }
  #bar button { padding: 6px 14px; border: 0; border-radius: 6px; background: #2E6BFF; color: #fff; cursor: pointer; }
  #msg { font-size: 14px; margin-left: 8px; }
  canvas { display: block; width: 100%; height: auto; }
</style>
</head>
<body>
<div id="bar">
  <button data-view="overview">全景</button>
  <button data-view="tv">看電視</button>
  <button data-view="cook">煮菜</button>
  <button data-view="eat">吃早餐</button>
  <button id="save">下載目前畫面 PNG</button>
  <span id="msg">模型載入中,第一次約需 20–40 秒…</span>
</div>
<canvas id="c"></canvas>

<script type="module">
// three.js 從 jsDelivr 載入(+esm 版本不需要 importmap)
import * as THREE from 'https://cdn.jsdelivr.net/npm/three@0.187.0/+esm';
import { GLTFLoader } from 'https://cdn.jsdelivr.net/npm/three@0.187.0/examples/jsm/loaders/GLTFLoader.js/+esm';
import { RoomEnvironment } from 'https://cdn.jsdelivr.net/npm/three@0.187.0/examples/jsm/environments/RoomEnvironment.js/+esm';
import * as SkeletonUtils from 'https://cdn.jsdelivr.net/npm/three@0.187.0/examples/jsm/utils/SkeletonUtils.js/+esm';

const W = 1600, H = 900;
const msg = document.getElementById('msg');

// ---------- 1. 渲染器、燈光 ----------
const renderer = new THREE.WebGLRenderer({ canvas: document.getElementById('c'), antialias: true, preserveDrawingBuffer: true });
renderer.setPixelRatio(1);
renderer.setSize(W, H, false);
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;

const scene = new THREE.Scene();
scene.background = new THREE.Color('#e9e4dc');
scene.environment = new THREE.PMREMGenerator(renderer).fromScene(new RoomEnvironment(), 0.04).texture;
scene.environmentIntensity = 0.6;
const sun = new THREE.DirectionalLight('#fff4e0', 2.2);
sun.position.set(3, 6, 4);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.bias = -0.0005;
Object.assign(sun.shadow.camera, { left: -5, right: 5, top: 5, bottom: -5 });
scene.add(sun, new THREE.HemisphereLight('#ffffff', '#b59b7c', 0.6));

// ---------- 2. 用方塊做房間(地板、兩面牆、窗戶、掛畫、地毯) ----------
function box(w, h, d, color, x, y, z, extra = {}) {
  const m = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), new THREE.MeshStandardMaterial({ color, roughness: 0.9, ...extra }));
  m.position.set(x, y, z);
  m.castShadow = m.receiveShadow = true;
  scene.add(m);
  return m;
}
box(6, 0.05, 4.5, '#c49a6c', 0, -0.025, 0);            // 地板 6m x 4.5m
box(6, 2.7, 0.1, '#f2ede4', 0, 1.35, -2.3);             // 後牆
box(0.1, 2.7, 4.5, '#ebe4d8', -3.05, 1.35, 0);          // 左牆
box(0.04, 1.2, 1.4, '#ffffff', -2.99, 1.55, 0.6);       // 窗框
box(0.02, 1.08, 1.28, '#bcd8ec', -2.97, 1.55, 0.6, { roughness: 0.1, metalness: 0.2 });
box(0.9, 0.6, 0.04, '#3b3f4a', 1.6, 1.6, -2.24);        // 掛畫
box(0.82, 0.52, 0.02, '#e7b75b', 1.6, 1.6, -2.21);
box(1.6, 0.01, 1.1, '#7d8c99', 1.6, 0.006, -0.5);       // 客廳地毯
box(1.3, 0.01, 0.7, '#d8cdbb', -1.9, 0.006, -1.25);     // 廚房地墊
box(1.7, 0.01, 1.7, '#b9a48a', -1.5, 0.006, 1.1);       // 餐桌地毯

// ---------- 3. 從 Poly Haven API 下載家具(CC0) ----------
async function loadPolyHaven(slug) {
  const files = await (await fetch('https://api.polyhaven.com/files/' + slug)).json();
  const g = files.gltf['1k'].gltf;                       // 1k 貼圖版本的 glTF
  const map = {};
  for (const [name, info] of Object.entries(g.include || {})) map[name] = info.url;
  const manager = new THREE.LoadingManager();
  manager.setURLModifier(url => {                        // 把 .bin 與貼圖換成 API 給的真實網址
    for (const name in map) if (url.endsWith(name)) return map[name];
    return url;
  });
  return (await new GLTFLoader(manager).loadAsync(g.url)).scene;
}
const FURNITURE = [
  // [Poly Haven 代號, x, y, z, 旋轉, 縮放]
  ['electric_stove', -1.9, 0, -1.95, 0, 1],
  ['modern_wooden_cabinet', -2.75, 0, -0.3, Math.PI / 2, 1],
  ['brass_pan_01', -1.68, 0.86, -1.7, 0.9, 1],
  ['pot_enamel_01', -2.02, 0.86, -2.08, 0, 1],
  ['wooden_cutting_board', -2.72, 0.68, -0.95, Math.PI / 2, 1],
  ['vintage_electric_kettle', -2.78, 0.68, 0.15, 0.4, 1],
  ['drawer_cabinet', 0.45, 0, -2.0, 0, 1],
  ['side_table_01', 1.6, 0, -2.0, 0, 1],
  ['television_02', 1.6, 0.55, -2.0, 0, 1.5],
  ['potted_plant_02', 2.6, 0, -1.85, 0, 1],
  ['modern_coffee_table_01', 1.6, 0, -0.6, Math.PI / 2, 1],
  ['sofa_02', 1.6, 0, 0.6, Math.PI, 1],
  ['round_wooden_table_01', -1.5, 0, 0.9, 0, 0.75],
  ['dining_chair_02', -1.5, 0, 1.6, -Math.PI / 2, 1],
  ['croissant', -1.45, 0.76, 0.75, 0.3, 1],
];
const models = await Promise.all(FURNITURE.map(f => loadPolyHaven(f[0])));
models.forEach((m, i) => {
  const [, x, y, z, ry, s] = FURNITURE[i];
  m.position.set(x, y, z);
  m.rotation.y = ry;
  m.scale.setScalar(s);
  m.traverse(c => { if (c.isMesh) c.castShadow = c.receiveShadow = true; });
  scene.add(m);
});

// ---------- 4. 小道具:電視畫面發光、鍋裡的菜、爐火 ----------
const screen = new THREE.Mesh(new THREE.PlaneGeometry(0.38, 0.28),
  new THREE.MeshStandardMaterial({ color: '#000000', emissive: '#8fd0ff', emissiveIntensity: 1.6 }));
screen.position.set(1.59, 1.0, -1.8);
scene.add(screen);
const tvLight = new THREE.PointLight('#9fd6ff', 1.5, 3);
tvLight.position.set(1.6, 1.0, -1.5);
scene.add(tvLight);

const pan = models[2];
const panBox = new THREE.Box3().setFromObject(pan);
const panCenter = panBox.getCenter(new THREE.Vector3());
['#e85d3a', '#7cc35b', '#f2c94c', '#e85d3a', '#7cc35b'].forEach((color, i) => {
  const food = new THREE.Mesh(new THREE.SphereGeometry(0.022, 12, 10), new THREE.MeshStandardMaterial({ color, roughness: 0.6 }));
  food.position.set(panCenter.x + Math.cos(i * 1.3) * 0.05, panBox.max.y - 0.01, panCenter.z + Math.sin(i * 1.3) * 0.05);
  scene.add(food);
});
const fire = new THREE.PointLight('#ff7a3d', 0.8, 1.2);
fire.position.set(panCenter.x, 1.0, panCenter.z);
scene.add(fire);

// ---------- 5. 角色:three.js 範例的 RobotExpressive(CC0,內建動作) ----------
const robotGltf = await new GLTFLoader().loadAsync('https://raw.githubusercontent.com/mrdoob/three.js/r180/examples/models/gltf/RobotExpressive/RobotExpressive.glb');
function addRobot(action, time, x, y, z, ry) {
  const robot = SkeletonUtils.clone(robotGltf.scene);    // 同一個模型複製多個角色
  robot.scale.setScalar(0.27);
  robot.position.set(x, y, z);
  robot.rotation.y = ry;
  robot.traverse(c => { if (c.isMesh) c.castShadow = true; });
  const mixer = new THREE.AnimationMixer(robot);
  mixer.clipAction(robotGltf.animations.find(a => a.name === action)).play();
  mixer.update(time);                                    // 停在動作的某一格,當作姿勢
  scene.add(robot);
  return robot;
}
addRobot('Idle', 0.5, -1.9, 0, -1.28, Math.PI);          // 站在爐子前煮菜
addRobot('Sitting', 1.0, 1.6, 0.17, 0.32, Math.PI);      // 坐在沙發看電視
addRobot('Sitting', 1.0, -1.5, 0.2, 1.5, Math.PI);       // 坐在餐桌前吃早餐

// ---------- 6. 鏡頭位置:每個情境一組 ----------
const camera = new THREE.PerspectiveCamera(45, W / H, 0.05, 100);
const VIEWS = {
  overview: { pos: [4.5, 4.2, 5.5], target: [0, 0.6, -0.5], fov: 40 },
  tv:       { pos: [2.9, 1.5, 1.9], target: [1.55, 0.75, -1.6], fov: 45 },
  cook:     { pos: [-0.35, 1.55, -0.7], target: [-1.95, 0.85, -1.7], fov: 46 },
  eat:      { pos: [-0.75, 1.45, -0.45], target: [-1.55, 0.75, 1.25], fov: 46 },
};
let current = 'overview';
function show(name) {
  const v = VIEWS[name];
  current = name;
  camera.fov = v.fov;
  camera.position.set(...v.pos);
  camera.lookAt(...v.target);
  camera.updateProjectionMatrix();
  renderer.render(scene, camera);
}
document.querySelectorAll('[data-view]').forEach(b => b.onclick = () => show(b.dataset.view));
document.getElementById('save').onclick = () => {
  const a = document.createElement('a');
  a.download = 'room-' + current + '.png';
  a.href = renderer.domElement.toDataURL('image/png');
  a.click();
};
show('overview');
msg.textContent = '完成!點上方按鈕切換情境,再下載圖片。';
window.__room = { show, VIEWS, renderer };               // 給自動化腳本用
</script>
</body>
</html>

實測結果

這份程式在 Chrome 直接執行,第一次開啟需要從 Poly Haven 下載 15 件模型,約 20–40 秒;之後瀏覽器有快取會快很多。程式不需要安裝任何套件,存成 HTML 檔用本機網站開啟即可。

06交給 AI 改場景:一段提示詞就夠

會用 API 和 three.js 的概念之後,其實不用自己從零寫。把需求講清楚交給 Claude、ChatGPT 或 Gemini,通常第一次就能得到可以執行的版本,再請它微調座標和鏡頭:

提示詞/小套房場景

請用 three.js(0.187.0 版,從 jsDelivr 的 +esm 網址載入)寫一個單一 HTML 檔:

1. 用方塊做一間 6m × 4.5m 的小套房:地板、後牆、左牆、窗戶、地毯,前面和右邊不做牆,方便從外面看進去。
2. 家具從 Poly Haven API 載入:用 https://api.polyhaven.com/files/代號 取得 gltf 的 1k 版本,再用 LoadingManager 的 setURLModifier,把 .bin 和貼圖換成 include 裡的真實網址。我要放:沙發 sofa_02、電視 television_02、電視櫃 side_table_01、電爐 electric_stove、平底鍋 brass_pan_01、盆栽 potted_plant_02。
3. 角色用 three.js 官方範例的 RobotExpressive.glb,用 SkeletonUtils.clone 複製兩個:一個播 Sitting 動作坐在沙發上看電視,一個播 Idle 動作站在電爐前。
4. 準備三組鏡頭(全景、看電視、煮菜),畫面上方用按鈕切換;另一顆按鈕把目前畫面下載成 1600×900 的 PNG(renderer 要開 preserveDrawingBuffer)。
5. 開啟陰影,用 RoomEnvironment 當環境光,整體是溫暖的木頭色調。
6. 程式碼加上中文註解,標出每個家具的座標方便我之後調整。

拿到程式後,最常需要調的是三件事:家具的座標(模型擺歪或穿模)、角色的高度(坐下時要剛好在座墊上)、鏡頭位置(角色不要擋住主角道具)。把截圖丟回給 AI,說「機器人擋住鍋子了,鏡頭往右前方移」,它就能幫你改。

授權一件一件看

同一個平台裡授權可能不同。CC0 最放心;CC BY 要標示作者;寫著 NC(非商用)的就不能放進收費課程或商品。

第一次載入比較慢

15 件 1k 貼圖的模型加起來好幾十 MB,網路慢時要等久一點。正式上線時建議把模型下載到自己的主機或 CDN。

角色與動作要另外找

開放的家具很多,但有動作的人物模型少。常見的角色平台各有使用條款,放進公開作品前先讀清楚。

AI 生成模型有極限

看不到的面是推測的,細節和拓樸常需要整理;自架開源模型需要高階顯卡,雲端 API 則按次計費。

今天就試做:三個步驟

1

先挑模型

到 Poly Haven 挑 3 件喜歡的家具,記下網址最後的代號。

2

套進範例

把 room.html 的 FURNITURE 清單換成你的代號,調整座標。

3

換鏡頭出圖

新增一組 VIEWS 鏡頭,按下載,做出你的第一張情境圖。

本文重點

  1. 越來越多機構與平台公開 3D 模型,Poly Haven、史密森尼、大都會博物館的 CC0 模型可以放心商用。
  2. GLB 是 3D 界的通用格式,瀏覽器裡的 three.js 可以直接載入。
  3. Poly Haven API 不用金鑰;Sketchfab 要使用者登入;大都會博物館目前要手動下載。
  4. 渲染器開啟 preserveDrawingBuffer,就能把 3D 畫面存成 PNG,不設背景就是透明圖。
  5. 一個場景搭配多組鏡頭,就能批次產生不同情境的圖片;細節調整可以交給 AI。

想一想

如果要幫你的課程或產品做一組情境圖,你會選哪個場景、放哪些模型?哪些畫面用 3D 程式做會比用 AI 直接生圖更合適?

資料來源

  1. The Metropolitan Museum of Art(2026-02-26)。The Met to Publish Over 100 Three-Dimensional Models
  2. Poly Haven。License
  3. Poly Haven。API 使用說明(llms.txt)
  4. Sketchfab。Download API:Downloading models
  5. Smithsonian。Smithsonian 3D API 與 Voyager 開源資源
  6. Hugging Face。Smithsonian Open Access 3D 資料集
  7. NASA。NASA 3D Resources
  8. Khronos Group。glTF Sample Assets
  9. Microsoft Research。TRELLIS.2 專案頁
  10. Tencent。Hunyuan3D-2 授權條款
  11. Meshy。API Pricing
  12. three.js。RobotExpressive 模型說明

本文 3D 情境圖與工具截圖為程式實際渲染與執行畫面;封面插畫為 AI 生成的示意圖。


Edit with Tr.Bug

Follow me on:LinkedIn | 探教育TempEDU