搜尋套件、儲存庫與 APP 分類

babylonjs_viewer 封面
套件詳情v1.3.0

babylonjs_viewer

使用 BabylonJS 查看器渲染 3D 模型

AndroidiOSmacOS
近 30 天下載
110
喜歡數
68
Pub 分數
140

安裝套件

flutter pub add babylonjs_viewer

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

babylonjs_viewer 套件透過 BabylonJS(一個強大的 JavaScript 3D 引擎)讓 Flutter 應用程式能夠呈現 3D 模型。它提供了一種跨平台的方式,在 Android、iOS 和 macOS 上顯示和互動 3D 資產。透過利用 WebView 實現基於 Web 的渲染,該套件允許開發者在不需實作原生 3D 引擎的情況下整合豐富的 3D 可視化功能。適用於需要互動式 3D 內容的應用程式,例如產品預覽、建築可視化或教育工具。

適用情境

  • 3D產品視覺化
  • 互動式建築模型
  • 教育類3D內容
  • 虛擬遊覽
  • 遊戲資產預覽

主要特色

  • 透過 WebView 的基於 Web 的 3D 繪製
  • 支援多種3D格式
  • 跨平台相容性
  • 互動式相機控制
  • 輕量級整合

適合對象

  • 開發支援3D的Flutter應用的開發者
  • 需要輕量級3D渲染的應用程式
  • 原型設計3D體驗
  • 面向移動和桌面的專案

使用建議

  • WebView 性能限制
  • 有限的原生3D API存取
  • 依賴外部 BabylonJS 庫
  • 複雜模型的記憶體使用量更高
  • 如果未捆綁,則需要互聯網進行初始載入

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

babylonjs_viewer

3D Model viewer with BabylonJS Viewer for Flutter. This project highly inspired from model_viewer flutter pub package. Its simple model viewer, next release, json settings will be implented

Pub.dev

https://pub.dev/packages/babylonjs_viewer

Install

This will add a line like this to your package's pubspec.yaml (and run an implicit dart pub get):

dependencies:
  babylonjs_viewer: ^1.3.0
What's new in 1.3.0
  • Update dependency to webview_flutter 4.10.0
Why I need Controller

Controller is optional. You can use this controller for run Javascript code, go back, get current url, change url and many others that WebView Flutter can allow. Functions is optional. You can use this parameter for add javascript code to your viewer. Examples can be found at bottom of this document

Requirements

On your Android Project (android/app/build.gradle) set the "minSdkVersion" to 19

defaultConfig {
        applicationId "com.example.example"
        minSdkVersion 19
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

Then add the line "android:usesCleartextTraffic="true"" to your android manifest (android/app/src/main/AndroidManifest.xml)

<application
        android:label="example"
        android:icon="@mipmap/ic_launcher"
        android:usesCleartextTraffic="true">

On your iOS Project go to the info.plist file (ios/Runner/Info.plist) and add the following line

<key>io.flutter.embedded_views_preview</key>
<true/>

Import it

Now in your Dart code, you can use:

import 'package:babylonjs_viewer/babylonjs_viewer.dart';

Using

  class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        home: Scaffold(
          appBar: AppBar(title: Text("BabylonJS Viewer")),
          body: BabylonJSViewer(
            src: 'https://models.babylonjs.com/boombox.glb',
          ),
        ),
      );
    }
  }

Asset, FILE or HTTP(s)

HTTP(s)

  BabylonJSViewer(
    src: 'https://models.babylonjs.com/boombox.glb',
  ),

FILE

  BabylonJSViewer(
    src: 'file:///path/to/MyModel.glb',
  ),

Asset

  BabylonJSViewer(
    src: 'assets/MyModel.glb',
  ),
Controller and Function Example

Add webview_flutter to your pubspec.yaml

dependencies:
  webview_flutter: ^4.10.0

Add this to your state

import 'package:webview_flutter/webview_flutter.dart';

WebViewController? _controller;

Add your custom javascript functions. This will print to your flutter console.

BabylonJSViewer(
  controller: (WebViewController controller) {
    _controller = controller;
  },
  functions:
      '''function sayHello() { Print.postMessage("Hello World!"); }''',
  src:
      'https://models.babylonjs.com/boombox.glb',
),

Use this function wherever you want

ElevatedButton(
  onPressed: () {
      _controller?.runJavaScript('''
sayHello();
''');
  },
  child: const Text("Run Function")),
Use case for Controller and Function

You can access to viewer variable of babylonjs viewer. You can found all methods on there

In this example show you that how you can toggle auto rotate.

BabylonJSViewer(
  controller: (WebViewController controller) {
    _controller = controller;
  },
  functions: '''
function toggleAutoRotate(texture) {
let viewer = BabylonViewer.viewerManager.getViewerById('viewer-id');
viewer.sceneManager.camera.useAutoRotationBehavior = !viewer.sceneManager.camera.useAutoRotationBehavior
}
''',
  src:
      'https://models.babylonjs.com/boombox.glb',
),

use this function

ElevatedButton(
  onPressed: () {
      _controller?.runJavascript('''
toggleAutoRotate();
''');
  },
  child: const Text("Toggle")),

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。