Site icon Flutter Packages | Pub dev Packages – Flutter Mobile App World

A Flutter 3D widget that renders Wavefront’s object files

Flutter Cube

A Flutter 3D widget that renders Wavefront’s object files.

Getting Started

Add flutter_cube as a dependency in your pubspec.yaml file.

dependencies:
  flutter_cube: ^0.0.4

Add Wavefront’s object files to assets.

flutter:
  assets:
    - assets/cube/cube.obj
    - assets/cube/cube.mtl
    - assets/cube/flutter.png

Import and add the Cube widget to your project.

import 'package:flutter_cube/flutter_cube.dart';
... ...
  
@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Cube(
          onSceneCreated: (Scene scene) {
            scene.world.add(Object(fileName: 'assets/cube/cube.obj'));
          },
        ),
      ),
    );
  }

Use obj file from sdcard

import 'package:flutter_cube/flutter_cube.dart';
... ...
@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Cube(
          onSceneCreated: (Scene scene) {
            scene.world.add(
              Object(
                fileName: '/sdcard/cube/cube.obj', isAsset: false,
              ),
            );
          },
        ),
      ),
    );
  }

Screenshot

Download Flutter 3D Cube Widget source code on GitHub

https://github.com/zesage/flutter_cube

Exit mobile version