o3d 是一個 Flutter 套件,可簡化在行動與 Web 平台上整合 GLB 格式的 3D 物件。它提供一個易於使用的控制器,用於呈現、動畫與互動 3D 模型,無需深入瞭解 3D 圖形程式設計。專為希望提升應用程式沉浸式 3D 內容的開發者設計,o3d 可有效率地載入與管理 3D 資產。此套件支援 Android、iOS 與 Web,非常適合需要輕量級 3D 可視化的跨平台應用。
適用情境
新增互動式3D產品預覽
創建教育類3D可視化
提升遊戲體驗
建構虛擬遊覽
在AR/VR應用中整合3D模型
主要特色
支援 GLB 3D 模型格式
跨平台相容性(Android、iOS、Web)
用於加載和控制3D物件的簡單API
內建動畫和互動處理
輕量且針對效能進行了優化
適合對象
Flutter 開發者初識 3D
需要3D模型顯示的應用程式
教育和電子商務應用
互動式網路和移動體驗
使用建議
需要 GLB 格式的 3D 模型
僅限基本的3D互動
效能可能在低階裝置上有所差異
無內建物理或進階動畫
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
O3D - Model Viewer for Flutter
This is a Flutter widget for rendering interactive
3D models in the glTF and GLB formats.
The widget embeds Google's <model-viewer>
web component in a WebView.
cameraTarget: use controller.cameraTarget(20, 20, 5)x, y, z
cameraOrbit: use controller.cameraOrbit(1.2, 1, 4)(theta)deg, (phi)deg, (radius)m
availableAnimations: use controller.availableAnimations().then((animations) => log("Available animations: $animations"));
play: use controller.play()[optional] repetitions => play(repetitions: 2)
pause: use controller.pause()
Renders glTF and GLB models. (Also, USDZ models on iOS 12+.)
Supports animated models, with a configurable auto-play setting.
Optionally supports launching the model into an AR viewer.
Optionally auto-rotates the model, with a configurable delay.
Supports a configurable background color for the widget.
Installation
in pubspec.yaml
dependencies:o3d:^3.1.0
AndroidManifest.xml (Android 9+ only)
Test on real device and to use this widget on Android 9+ devices, your app must be permitted to make an HTTP connection
to http://localhost:XXXXX.
Android 9 (API level 28) changed the default for android:usesCleartextTraffic from true
to false,
so you will need to configure your app's android/app/src/main/AndroidManifest.xml as follows:
To use this widget on iOS, you need to opt-in to the embedded views preview
by adding a boolean property to your app's ios/Runner/Info.plist file, with
the key io.flutter.embedded_views_preview and the value YES:
We use
the Google APP
, com.google.android.googlequicksearchbox to display interactive 3D models on Android.
The model displays in 'ar_preferred' mode by default, Scene Viewer launches in AR native mode as the
entry mode.
If Google Play Services for AR (ARCore, com.google.ar.core)
isn't present, Scene Viewer gracefully falls back to 3D mode as the entry mode.
Note that due to browsers' CORS security restrictions, the model file
must be served with a Access-Control-Allow-Origin: * HTTP header.
Frequently Asked Questions
Q: Why doesn't my 3D model load and/or render?
A: There are several reasons why your model URL could fail to load and
render:
It might not be possible to parse the provided glTF or GLB file.
Some tools can produce invalid files when exporting glTF. Always
run your model files through the glTF Validator to check for this.