Skip to main content

mesh3d 0.1.0 copy "mesh3d: ^0.1.0" to clipboard
mesh3d: ^0.1.0 copied to clipboard

Reads 3D models in pure Dart — .3mf, .glb, .obj and .stl — and returns their parts, each with a name, a mesh and a colour. Draws nothing, so it runs in a Flutter app and on a server alike.

example/mesh3d_example.dart

// Reads a 3D model and reports what it found.
//
//   dart run example/mesh3d_example.dart path/to/model.glb
import 'dart:io';

import 'package:mesh3d/mesh3d.dart';

void main(List<String> arguments) {
  if (arguments.isEmpty) {
    print('Usage: dart run example/mesh3d_example.dart <file>');
    print('Formats: .3mf, .glb, .obj (or a .zip with its .mtl), .stl');
    exitCode = 64;
    return;
  }

  final Model3d model;
  try {
    // No format given: it comes from the file's signature, not its extension.
    model = readModel(File(arguments.first).readAsBytesSync());
  } on Model3dException catch (error) {
    print('Could not read it: ${error.message}');
    exitCode = 65;
    return;
  }

  print('${model.format.extension} · ${model.parts.length} part(s) '
      '· ${model.unit}');

  for (final part in model.parts) {
    print('  ${part.name.isEmpty ? "(unnamed)" : part.name}  '
        '${part.triangleCount} triangles  ${part.color ?? "no colour"}');
  }

  // What the file asked for and the reader does not do. Worth showing to
  // whoever sent it: drawing it wrong in silence is worse than refusing.
  for (final warning in model.warnings) {
    print('  ! ${warning.message}');
  }
}
1
likes
150
points
95
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Reads 3D models in pure Dart — .3mf, .glb, .obj and .stl — and returns their parts, each with a name, a mesh and a colour. Draws nothing, so it runs in a Flutter app and on a server alike.

Repository (GitHub)
View/report issues

Topics

#mesh #gltf #geometry #graphics #parser

License

MIT (license)

Dependencies

archive, xml

More

Packages that depend on mesh3d