welcom ! Handel home

2025年2月23日 星期日

Gazebo STL 3D 模型?顯示可用工具與方法

 如何顯示 STL 3D 模型?可用工具與方法

STL(Stereolithography)是一種常見的 3D 模型格式,主要用於 3D 列印、CAD 設計、機器人模擬 等。以下是一些 開源 / 免費 / 商業軟體程式方法,用來顯示與操作 STL 3D 模型。


1️⃣ 桌面應用軟體

這些軟體支援 STL 3D 模型顯示,適合不同應用場景,如 檢視、修改、模擬或 3D 列印

✅ 1. Blender(免費,開源 3D 建模)

  • 適用於:遊戲開發、動畫製作、機械設計
  • 下載Blender 官方網站
  • 如何載入 STL?
    1. 開啟 Blender
    2. FileImportSTL
    3. 瀏覽 STL 檔案並匯入
    4. 使用 旋轉 / 縮放 / 移動 來檢視 STL

✅ 2. FreeCAD(免費,開源 CAD 設計)

  • 適用於:機械設計、工程建模
  • 下載FreeCAD 官方網站
  • 如何載入 STL?
    1. FileOpen → 選擇 STL 檔案
    2. 可使用 測量工具 來檢視 STL 大小
    3. 可轉換為 可編輯的 BRep 模型 以便修改

✅ 3. MeshLab(免費,開源 3D 模型修復工具)

  • 適用於:STL 模型檢查、修復、編輯
  • 下載MeshLab 官方網站
  • 如何載入 STL?
    1. FileImport Mesh
    2. 選擇 STL 檔案
    3. 可使用 點雲 / 法線檢查 / 修復工具 來改善 STL 質量

✅ 4. Ultimaker Cura(免費,3D 列印預處理)

  • 適用於:3D 列印 STL 預覽與切片
  • 下載Cura 官方網站
  • 如何載入 STL?
    1. 開啟 Cura
    2. FileOpen File(s) → 選擇 STL
    3. 可調整模型尺寸,並預覽 3D 列印路徑

✅ 5. SolidWorks / AutoCAD / Fusion 360(商業 CAD 軟體)

  • 適用於:專業工程建模,支援 STL 檢視與修改
  • 如何載入 STL?
    • SolidWorksFileOpenSTL
    • AutoCAD → 需轉換為 DWG 格式
    • Fusion 360Insert Mesh 匯入 STL

2️⃣ 透過 Web 瀏覽器顯示 STL

不想安裝軟體?你可以使用 線上 STL 檢視工具 或自己寫 Web 應用來顯示 STL。

✅ 1. 使用線上 STL 檢視工具

網站連結特色
ViewSTLhttps://www.viewstl.com/簡單、免費,直接上傳 STL 觀看
STL Viewerhttps://www.creators3d.com/online-viewer支援 STL、OBJ、FBX 等格式
Autodesk Viewerhttps://viewer.autodesk.com/需註冊,支援 STL、DWG、Revit

✅ 2. 建立 Web 應用來顯示 STL(使用 Three.js)

如果你想 在瀏覽器內顯示 STL,可以使用 JavaScript + Three.js:

📌 index.html

html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>STL Viewer</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/three/examples/js/loaders/STLLoader.js"></script> </head> <body> <canvas id="canvas"></canvas> <script> const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); const renderer = new THREE.WebGLRenderer({ canvas: document.getElementById("canvas") }); renderer.setSize(window.innerWidth, window.innerHeight); document.body.appendChild(renderer.domElement); // 加載 STL const loader = new THREE.STLLoader(); loader.load('model.stl', function (geometry) { const material = new THREE.MeshStandardMaterial({ color: 0x00ff00 }); const mesh = new THREE.Mesh(geometry, material); scene.add(mesh); camera.position.z = 5; function animate() { requestAnimationFrame(animate); mesh.rotation.x += 0.01; mesh.rotation.y += 0.01; renderer.render(scene, camera); } animate(); }); </script> </body> </html>

📌 這段程式碼會在瀏覽器內顯示 STL 3D 模型,並可旋轉觀看!


3️⃣ 透過 Python 顯示 STL

如果你想在 Python 內顯示 STL,可以使用 matplotlibtrimesh

✅ 1. 使用 matplotlib(適合簡單 STL 可視化)

python

import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d.art3d import Poly3DCollection from stl import mesh # 讀取 STL 檔案 #your_mesh = mesh.Mesh.from_file('model.stl') # 讀取 STL 檔案 your_mesh = mesh.Mesh.from_file('stl_data2/base_link.stl') # 創建 3D 圖像 fig = plt.figure() ax = fig.add_subplot(111, projection='3d') # 畫出 STL 模型 ax.add_collection3d(Poly3DCollection(your_mesh.vectors, facecolors='cyan', linewidths=0.5, edgecolors='r', alpha=0.5)) # 設定視角 #scale = your_mesh.points.flatten(-1) #ax.auto_scale_xyz(scale, scale, scale) # 修正 `.flatten()`,不傳 `-1` scale = your_mesh.points.flatten() ax.auto_scale_xyz(scale, scale, scale) # 顯示圖形 plt.show()
 

🔹 需要安裝 numpy-stl

bash
pip install numpy-stl matplotlib

✅ 2. 使用 trimesh(更進階,支援 STL 渲染)

python
import trimesh # 讀取 STL 檔案 mesh = trimesh.load_mesh("model.stl") # 顯示 3D 模型 mesh.show()

🔹 需要安裝 trimesh

bash
pip install trimesh

📌 總結

方法適用場景推薦工具
桌面應用   3D 設計、列印、工程Blender、FreeCAD、MeshLab
Web 瀏覽器   在線查看 STLViewSTL、Three.js
Python   自動處理 3D 模型numpy-stltrimesh

🚀 如果你只是要檢視 STL,推薦使用 Blender 或 MeshLab。

如果你要在網頁顯示,使用 Three.js。如果你要寫程式處理 STL,

使用 Python 的 trimesh 

🎯

沒有留言: