搜索插件、代码仓与 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 项

源码仓库

使用此插件的项目

暂无相关数据。