The Flutter3DViewer widget is the primary entry point for rendering 3D models in your Flutter application. It supports both standard 3D models (like .glb and .gltf) and .obj models via specialized constructors.
Standard 3D Models (.glb, .gltf)
Use the default constructor to load standard web-optimized 3D models. You can provide a Flutter3DController to programmatically control animations, camera, and variants.
OBJ Models
Use the Flutter3DViewer.obj constructor specifically for .obj files. This constructor allows you to define initial camera positioning and scaling parameters.
Key Features
- Source Support: Load models via asset addresses, URLs, or local file paths.
- Gesture Interceptor: Includes an
activeGestureInterceptor (enabled by default) to prevent gesture conflicts on iOS and certain Android devices. - Lifecycle Callbacks: Monitor loading progress, successful loads, and errors via
onProgress, onLoad, and onError.
// Loading a standard GLB model
Flutter3DViewer(
src: 'assets/models/my_model.glb',
onProgress: (progress) => print('Loading: $progress'),
onLoad: (address) => print('Loaded: $address'),
onError: (error) => print('Error: $error'),
);
// Loading an OBJ model with specific camera settings
Flutter3DViewer.obj(
src: 'assets/models/my_model.obj',
scale: 2.0,
cameraX: 0.0,
cameraY: 5.0,
cameraZ: 15.0,
);