搜索插件、代码仓与 APP 分类

插件详情v1.0.2+1

flutter_3d_objects

一个渲染 Wavefront 3D 对象文件的 Flutter 包项目。

AndroidiOSmacOSWindowsLinux
近 30 天下载
2
喜欢数
5
Pub 分数
135

安装插件

flutter pub add flutter_3d_objects

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 包,可在 Flutter 应用中渲染 Wavefront (.obj) 3D 模型文件。它支持 Android、iOS、macOS、Windows 和 Linux 多个平台,非常适合跨平台 3D 可视化。该包与 Flutter 的 widget 系统无缝集成,使开发者能够在其 UI 中嵌入交互式 3D 对象。对于需要显示 3D 资产的应用程序(如产品预览、教育工具或增强现实体验)尤其有用。

适合场景

  • 3D产品可视化
  • 带有3D模型的教育类应用程序
  • 增强现实界面
  • 交互式3D UI组件
  • 游戏开发原型

主要特点

  • 支持 Wavefront .obj 文件
  • 跨平台兼容性
  • 与 Flutter 小部件集成
  • 轻便且易于使用
  • 实时3D渲染

适合对象

  • 开发支持3D的Flutter应用的开发者
  • 教育软件创作者
  • 产品展示应用
  • AR/VR 原型设计团队
  • UI 设计师探索 3D 元素

使用建议

  • 仅限 .obj 文件格式
  • 无内置动画支持
  • 需要3D模型优化
  • 可能对低端设备产生性能影响
  • 无纹理映射功能

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

[Flutter 3D Objects]

pub package style: effective dart License: MIT

This package allows Flutter developers to easily display 3D models in their applications. It supports the .obj file format and provides functionalities to manipulate the scene, including setting camera positions and adding objects with child objects.

Features:

  • Display 3D models from .obj files
  • Add and manipulate objects within the scene
  • Set camera positions to adjust the view
  • Support for hierarchical object structures

Setup

How to use this

  • Add dependency in pubspec.yaml
dependencies:
  flutter:
    sdk: flutter
flutter_3d_objects:
  • Add 3D Models in assets, file type should be .obj
flutter:
assets:
  - assets/p.obj
  - assets/c.obj

Usage

void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Cube(
            onSceneCreated: (Scene scene) {
              scene.world.add(
                Object(
                  fileName: 'assets/c.obj',
                  position: Vector3(1, 1, 1),
                  scale: Vector3(1, 1, 1),
                ),
              );
            },
          ),
        ),
      ),
    );
  }
}

Example

//Create a variable
late Scene _scene;
double x = 0;
double y = 3;
double z = 8;
late AnimationController _controller;
late Animation<double> _animation;
Object? _p;

// Create Function
void _onSceneCreated(Scene scene) {
   _scene = scene;
   scene.camera.position.z = z;
   scene.camera.position.y = y;
   scene.camera.position.x = x;
   _p = Object(
       position: Vector3(0, -2.5, 0),
       scale: Vector3(4, 4, 4),
       fileName: 'assets/p.obj',
       children: [
         Object(
           fileName: 'assets/c.obj',
           position: Vector3(0.25, 0.15, -0.24),
           scale: Vector3(0.8, 0.8, 0.8),
         ),
       ]);
   scene.world.add(_p!);
 }

//Function to rotate
void rotateLeft() {
   _animateRotation(90);
 }

 void rotateRight() {
   _animateRotation(-90);
 }

 void _animateRotation(double angle) {
   final double begin = _p!.rotation.y;
   final double end = _p!.rotation.y + angle;

   _animation = Tween<double>(begin: begin, end: end).animate(_controller)
     ..addListener(() {
       setState(() {
         _p!.rotation.y = _animation.value;
         _p!.updateTransform();
         _scene.update();
       });
     });

   _controller.forward(from: 0);
 }

// In main widget function
Scaffold(
     appBar: AppBar(
       title: const Text(''),
     ),
     body: Stack(
       children: [
         Cube(
           interactive: false,
           zoom: false,
           onSceneCreated: _onSceneCreated,
         ),
         Positioned(
           bottom: 10,
           left: 0,
           right: 0,
           child: Row(
             mainAxisAlignment: MainAxisAlignment.spaceEvenly,
             children: [
               ElevatedButton(
                 onPressed: rotateLeft,
                 child: const Text('Left'),
               ),
               ElevatedButton(
                 onPressed: rotateRight,
                 child: const Text('Right'),
               ),
             ],
           ),
         ),
       ],
     ),
   );

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目

暂无相关数据。