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

Reads .3mf, .glb, .obj and .stl in pure Dart, returning each part with its name, mesh and colour. Draws nothing, so it runs on a server too.

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
160
points
94
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Reads .3mf, .glb, .obj and .stl in pure Dart, returning each part with its name, mesh and colour. Draws nothing, so it runs on a server too.

Repository (GitHub)
View/report issues

Topics

#mesh #gltf #geometry #graphics #parser

License

MIT (license)

Dependencies

archive, xml

More

Packages that depend on mesh3d