1

I'm working on a UWP project which uses the Windows MapControl. I want to add 3d models to the map. I know how to do this from 3mf files. But now I would like to make procedural meshes and add these to the map.

I have found documentation on how to create a 3mf file in code: https://learn.microsoft.com/en-us/windows/uwp/devices-sensors/generate-3mf

I followed this documentation to create a Printing3D3MFPackage.

But then I try to create a MapModel3D from this 3mf package, like this:

//package is of type Printing3D3MFPackage
var streamReference = RandomAccessStreamReference.CreateFromStream(package.ModelPart);
var myModel = await MapModel3D.CreateFrom3MFAsync(streamReference, MapModel3DShadingOption.Smooth);

And I get this exception:

System.Runtime.InteropServices.COMException: 'Unspecified error

Failed to create MapModel3D from 3MF stream.'

So I guess these streams aren't compatible.

Does anyone know how to do this?

Stef
  • 315
  • 3
  • 14

1 Answers1

2

Try this instead:

…
await package.SaveModelToPackageAsync(model);
var packageStream = await localPackage.SaveAsync();
var streamReference = RandomAccessStreamReference.CreateFromStream(packageStream );
var myModel = await MapModel3D.CreateFrom3MFAsync(streamReference, MapModel3DShadingOption.Smooth);
user8709
  • 1,342
  • 13
  • 31
  • Ah yes, ofcourse, you're right. I was assigning the modelpart instead of the entire package as a stream. Thanks, it works perfectly now! – Stef Jun 21 '18 at 08:25