[standalone] Python: Microsoft .3mf to Blender-usable .ply

I got myself 3D scanned in the Microsoft tent at the Maker Faire today, and was given a flash drive with the scan on it to take with me. I got back to my computer this evening and discovered that the scan was saved as a .3mf file, Microsoft’s new format for their 3D printer functionality (which is included by default in all Windows 10 installs). Microsoft’s tools for viewing and printing (and otherwise working with) this filetype are not compatible with anything before Windows 8.1. (I guess they’re trying to convince those of us still running Win7 - or Linux or OSX - to upgrade.) That’s OK, I wasn’t planning to use their tools anyways; I was planning to import the model into Blender. I looked through all the import-export plugins, and .3mf was not there, which bothered me but did not really surprise me due to the youth of the format. I started searching the internet for a way to convert this file to another format and found nothing. I did not find a single tool for converting .3mf into any other format, let alone one that Blender could import.

This dearth was something that I could not abide. I decided that it was my duty to create a tool to convert .3mf files to something, anything, usable. I settled on .ply because it is a very simple format that supports vertex colors, which was what I needed. It is essentially the exact same thing as Microsoft’s .3mf, except with different syntax (.ply simply uses spaces and line breaks to separate data, whereas .3mf is, for some unknown reason, complete and proper XML). It took me about three and a half hours to get it working (my Python skills are not exactly stellar), which makes me wonder why nobody else seems to have done it.

Without further ado, here you go! As the file header comments say, you should be running a 64-bit release of Python 3 for best results. Extract the .3mf file with 7-zip (or something similar), place the .model file in the same directory as the script file, and watch it go. If there is significant interest, I may update the script so that it simply asks the user to point it to the .3mf file and then goes from there. Heck, I might even turn it into a proper Blender addon, although that’s far less likely. (If anybody else wants to do either of those things then by all means go for it; the X11 license lets you do that - and a whole lot more - with my code.)

Enjoy!

Thanks for sharing, flyingfences, this useful code…may be a add-on soon?
Byebye
Spirou4D

ERROR!
I have tried it like you said:
i extrakted the 3mf File with 7 zip then I posted the skript into the new python file opened out of IDLE and saved it in the 3D ordner witch containes the .model File and opened the .py.
At first it looked as if it would work but then this ERROR message was displayed this is the whole text that i got:


Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:16:59) [MSC v.1900 32 bit (Intel)] on win32
Type “copyright”, “credits” or “license()” for more information.
>>>
============ RESTART: C:\Users schm\Desktop\3D\3ms_Converter.py ============
initializing
parsing the file…done
extracting: colors…vertices…triangles…done
matching colors to vertices…Traceback (most recent call last):
File “C:\Users schm\Desktop\3D\3ms_Converter.py”, line 32, in <module>
cols[int(tris[n].attributes[‘v1’].value)] = colors[int(tris[n].attributes[‘colorid’].value.split(’,’)[0])].attributes[‘value’].value
File “C:\Users schm\AppData\Local\Programs\Python\Python35-32\lib\xml\dom\minidom.py”, line 552, in getitem
return self._attrs[attname_or_tuple]
KeyError: ‘colorid’
>>>

With blender-usable .ply, that should mean it’s possible to integrate Instant Meshes for Blender right?

Sorry for the delay; I’ve had other things going on.

It looks like you’re running a 32-bit install of Python. You could be running into a memory issue. Try it with a 64-bit install and see how it goes.

I myself have not tried it, but I don’t see any reason that it wouldn’t be possible.

after getting the ply object it still does not import the texture, is it there? how can i make it texturized?
thanks for the code and post!

The .3mf and .ply filetypes do not store “textures” in the usual sense; they store vertex colors. If your .3mf file had colors, then the color data is included in the .ply file and is in fact imported into Blender, which just does not show the vertex colors by default. If you want to render your model with the colors that were originally in the .3mf file, you need to set the material for the object to use the vertex colors.

If you are using the Blender Internal renderer, there is an checkbox in the materials panel under Options labelled “Vertex Color Paint” that will get you the desired result.

If you are using Cycles renderer then you will need to use materials nodes. You create a new Add->Input->Attribute and name it “Col”, then you can use the Color output from that for the Color input in your shaders.

I hope that this is the answer that you were looking for. If I have misunderstood your question in some way, then I apologize.

I know this is necro’ing a thread, but Internet searches keep pointing to this.

The .3mf and .ply filetypes do not store “textures” in the usual sense;

That isn’t strictly accurate, at least for .3mf files. For most 3D printing, yes, but not for the types of 3D manufacturing we are doing. We print full textures and need an actual bitmap, not just texture colors.

Right in the spec, it says:

Texture coordinate materials

3MF supports the use of 2D images to color the surfaces of 3D models. This way, the model can convey much more color data per triangle face (as opposed to having just one color value per triangle vertex).

Any chance you’re still working on the exporter?

It turns out, what we need is an exporter to .3MF that also preserves textures, but I just wanted to set the record straight in case people were confused.

    == John ==