ghostkeeper / blender3mfformat Goto Github PK
View Code? Open in Web Editor NEWBlender add-on to import/export 3MF files
License: GNU General Public License v2.0
Blender add-on to import/export 3MF files
License: GNU General Public License v2.0
Installed 2.93.3 and manually installed the importer/exporter.
Console window says it was installed but it is not in the list of installed addons nor does it show up in the import/export dialogs.
Doesn't seem to be working.
Hi,
Thanks for this add on.
What will be its python script to call? will it be like normal method to import and export as stl? like below?
import bpy
import os
bpy.ops.import_scene.3mf(filepath='xx/xxx/1.3mf')
bpy.ops.export_mesh.stl(filepath='1.stl')
Cheers,
When exporting my model I get an error that 'NoneType' object has no attribute 'keys' unsure where the script is looking for 'keys'.
I am on Blender 2.92.0.
Let me know if I can help troubleshoot.
Software:
OS: Win10
Blender: 2.82.7
Netfabb: 2020.3
3D Builder: 18.0.1931.0
Recipe:
First error encountered is the same in both:
0x80004005
The fixes are simple, perhaps I'll submit a pull request.
If something goes wrong, we need to leave a trace so that a developer or an advanced user can figure out what's going on. Build a logging system, please!
Version 1.0 is supposed to be stable. One way to improve stability is to add automated tests.
For this version, we'll only require unit tests. Integration and functional tests are easier done manually. This will make it easier to maintain while we're still adding loads of functionality.
In order or the meshes to end up in the correct spot again, we need to store the object transformation in the 3MF file.
I've followed the download instructions and tried some troubleshooting, but it seems like blender will not currently install the add on for some reason. Please advise if this is an issue only I am having or if the code is somehow no longer compatible with the current version of blender.
Thanks!
The 3MF specification specifies that documents can specify a unit. We need to read this unit and apply it to the mesh.
I put the followin on the blender scripting and this does not work.
<script>
import bpy
bpy.ops.import_mesh.threemf(filepath="c:\work\sample.3mf")
<error message>
AttributeError: Calling operator "bpy.ops.import_mesh.threemf" error, could not be found
I asked this the blender community and let me know how to fix.
<fix point>
bl_idname = "export_mesh.3mf"
to
bl_idname = "export_mesh.three_mf"
in %AppData%\Blender Foundation\Blender\3.3\scripts\addons\io_mesh_3mf\export_3mf.py
We need to read out all of the metadata associated with a build, and store it so that it can be retrieved later when we export the 3MF scene again. This is required by the 3MF specification. Metadata, at least some of it, needs to be retained through saves and loads.
One possible complication of this is that the export may not have the same subset of objects as the import. We may need to duplicate the metadata information over all of the objects in the scene.
Print tickets are part of the core specifications. For a full implementation we'd need to read those and write them back. However Blender can do nothing with PrintTickets since it doesn't have any logic for how to 3D print anything. So we merely need to preserve the PrintTickets so that they get written down again when exporting to 3MF.
Since PrintTickets need to be associated with a model, they need to be stored in the metadata of the objects involved. Perhaps the metadata of a group.
Ideally we'd repair them if they are broken, to the best of our ability. However if that involves just deserialising to XML and serialising again when saving, that's fine too.
Hey @Ghostkeeper and all, I am exec director of the 3MF consortium and would like to see if the consortium can help in any way?
When you are all happy with the implementation I would also like to help promote the functionality.
Let me know if there is any interest in joining a call to discuss?
Thanks for all of your effort on this.
Duann
I recently installed on blender 2.83, but even if on
C:\Users\<user>\AppData\Roaming\Blender Foundation\Blender\2.83\scripts\addons
the folder appears, the plugin is not shown under preferences->community, so it can't be enabled.
Does the importing of the 3MF files keep the color and texture information in 3MF files? After I tried importing some 3MF files, I don't see any color information in the imported object from Blender.
3MF contains several ways to re-use meshes in order to reduce the file size. When exporting, we are not using any of these. The problem with implementing this is that we need to somehow figure out that two meshes are the same but under a different transformation. Blender doesn't provide any information on whether the mesh data is the same (but transformed) and has no easy way to compute that either.
To implement that, we'd need to perform a least squares fit to find the transformation matrix that best matches one mesh on another. This would need to be performed for every pair of meshes, which could become very costly in performance.
That's why this feature would also need to include a check mark in the export menu to decide whether to try and optimise the file size or not. The check mark needs to be disabled by default, because people don't normally care about file size much.
Hello Ghostkeeper.
I don't know if you plan to contiinue you're work here, but it would be cool to bee able to generate support structures in blender,
Perhaps at least create the support anchor points in blender so we could import the 3mf into PrusaSlicer for EXAMPLE
I'd be happy to do some of the work if you could get me started.
singleSupportPrussaSlicer3mf.zip
When we export, we need to write down the appropriate metadata as it was read from a 3MF file that was imported. If available in Blender, we also need to read out some metadata (e.g. object name?) that Blender has available and add that to the 3MF file.
One possible complication of this is that the 3MF file contains a single set of metadata for the entire scene, but this scene may be composed of many 3MF files that were imported and have different sets of metadata. If there is a conflict, we should not save that metadata. We should only save the metadata which is common to all objects in the scene.
Let's say there is a resource object like this:
<object objectid="3">
<metadatagroup>
<metadata name="Title">Some group of objects</metadata>
</metadatagroup>
<components>
<component objectid="1" />
<component objectid="2" />
</components>
</object>
This metadata currently won't get stored. Currently we store the metadata in the mesh of the Blender object (the object's data
field, which is then a mesh). However this object has no mesh, so there is nothing to store it in. The code that stores the metadata is actually conditional to there being mesh data in the object.
As a solution, we could store the metadata in an empty mesh. The exporter will then perhaps split it to a separate group, but the metadata is retained.
The materials created in Blender need to be stored in the 3MF file when exporting models, so that they can be preserved throughout exports and saves.
Should Blender 2.90.1 be supported?
I'm new to Blender but believe I followed the instructions correctly. I downloaded the "Big Bang" release of this addon. It was saved into my Downloads folder. I went to Edit>Preferences>Addons>Install... and selected the ZIP file Blender3mfFormat-1.0.0.zip from that folder. This message was logged:
Modules Installed () from 'C:\Users\cc\Downloads\Blender3mfFormat-1.0.0.zip' into 'C:\Users\cc\AppData\Roaming\Blender Foundation\Blender\2.90\scripts\addons'
However, the "Import Export" entry for it does not appear in the list. Searching for "3mf" clears the addons list. I've clicked "refresh" and restarted Blender.
In the addons folder printed in the log message there is a single folder "io_mesh_3mf" which contains __init__.py
and some other files, including metadata.py
, import_3mf.py
and export_3mf.py
(constants, annotations, and unit_conversions are the other three).
The log message "Modules Installed ()" makes my think that no modules were installed/detected. I removed the folder and did the install again, the log message did change:
Modules Installed (io_mesh_3mf) from 'C:\Users\cc\Downloads\Blender3mfFormat-1.0.0.zip' into 'C:\Users\cc\AppData\Roaming\Blender Foundation\Blender\2.90\scripts\addons'
This may have been printed the first time I installed it but I lost the message after a restart. Regardless, the addon doesn't appear in the UI even though this appears to have been successful.
This is an initial setup on a new Windows 10 machine. Are there external dependencies that need to be installed as well? From PowerShell I ran python __init__.py
and it exited silently. After restarting blender again neither the addon nor the File>Import/Export menu entries appear.
Create new object resources from the scene when exporting.
When Blender is correctly set up in millimetres (scale_length = 0.001 and length_unit = millimeters) exported 3mf files are 1000 times too small and on import 1000 times too large as are the object positions in relation to the world origin.
While this is easily fixed by exporting at 1000 scale and importing at 0.001 I think this is unexpected behaviour.
This is not an issue with import and export of STLs with the same Blender settings.
I have tried changing the code of the Addon locally but that always seems to break it, probably because I have no idea how Addons work other than how to install them.
When loading an archive, it is possible that the archive contains a MustPreserve relationship pointing to a target that is not in the archive. If that target is present in a different 3MF archive and that archive is loaded as well, then the MustPreserve relationship from one archive is applied to the file in the other archive. As a result, the file from the other archive is preserved, even though that archive didn't indicate that the file should be preserved.
If a file does not have the MustPreserve relationship in one archive, the file SHOULD NOT be preserved, according to the specification. As such, preserving that file is undesirable.
The object resources may have <components>
tags that define additional copies of other objects with some transformations. We need to add those to the resources, so that they can be used in a build.
We need to fill the object resources with vertices and triangles from the meshes we're exporting.
Title basically sums it up. The addon is working and importing 3mf objects, but unfortunately they all come empty and without any mesh. The same files open up just fine on Simplify, so I can't exactly tell what's going on. Just a heads up that is not working properly. If you guys want/need, I can send in any necessary data to help improve the addon. Feel free to contact me. TY
When exporting 3MF files it serialises the floats from the mesh. This has some rounding error. Unfortunately a lot of that rounding error ends up in the file. I'd like to introduce some purposeful rounding, e.g. to nanometres, as an option when exporting.
While it's recommended that the model is stored in /3D/3dmodel.model
, this is not necessarily always the case. The model may be stored elsewhere. The relations file should indicate where the model is. Maybe there are multiple. We need to support this, even though it's unconventional.
It is optional for a 3MF file writer to generate thumbnails of the objects that are being drawn. Blender has a very good rendering system that is certainly capable of generating those thumbnails and saving them in the file.
Read out the <build>
tag and all of its <item>
s. Create a Blender object for each of them.
Files that have the MustPreserve relationship SHOULD be preserved when importing and then exporting, according to the specification. I'm not sure what we can do if the user imports multiple 3MF files, but we can at least preserve the latest imported one.
If you set material -> surface -> base color to Image texture and select, say, a PNG, the current object will have a texture which you can show with the "Viewport Shading" view mode.
If you then export this to e.g. .obj
, this information is retained by means of a .mtl
file which will link to the png.
But if you export a .3mf
using this very plugin, it's not included - the 3mf zip only includes the structure information.
I'm very new to all of this, but isn't the "all in one" feature the selling point of 3mf? Surely this would have been reported here already, but it hasn't been. So is it me who's doing something wrong / what am I missing?
The addon installs as a "testing" addon but this option is no longer available with Blender 3.5. Manually installing the addon into the Blender addon folder does not work. The addon cannot be enabled in the Blender program as it does not appear on the list.
Implement support for reading tags from the 3MF files.
Each of the Objects need to be converted into a separate resource for the build to use.
This plug-in would be a lot more useful if it could import/export (diffuse) texture maps. (Suggestion: the implementation of obj import/export of texture maps and uv's is pretty easy to follow.)
One of many example test files from 3MF consortium's test suite:
https://github.com/3MFConsortium/test_suites/blob/master/suite2_core_prod_matl/positive_test_cases/P_XPM_0104_01.3mf
This would require support for the materials extension, so this is more of a feature request than a bug:
<model ... xmlns:m="http://schemas.microsoft.com/3dmanufacturing/material/2015/02" ... >
This is pretty easy to add with ElementTree which you're using.
and texture2d:
<m:texture2d ...>
and texture2dgroup:
<m:texture2dgroup ...>
There is a 1:1 mapping to the OBJ uv's in texture2dgroup if you're following the obj implementation.
The 3MF document can specify materials that the object must be built out of, each containing a colour. Triangles can refer to these materials as well. We should read out these materials and apply them to the meshes in the scene.
I have just imported the 3mf input/export zip, and it imported a test file well. However, in exporting a slightly modified version (holes drilled), it reported an error. I attach a screen shot, in case it helps.
3mf error report.docx
We need to read the transformations applied to these objects.
The transformations need to be added to the Blender objects as affine transformation matrices.
Blender is considering the 3MF addon for inclusion in Blender addon package by default. This would make it easier for people to start using the addon. The thread on the Blender site is: https://projects.blender.org/blender/blender-addons/pulls/104950#issuecomment-1044583
Part of this requires moving the addon license from AGPL to GPL 2.0 or later.
@DonPavlov and @Deuracell, are you okay with this license change in order for this 3MF addon to be included in Blender by default? Thanks.
Hi, sometimes when I try to export objects, I get the below exception.
Traceback (most recent call last):
File "C:\Users\ansonl\AppData\Roaming\Blender Foundation\Blender\2.90\scripts\addons\io_mesh_3mf\export_3mf.py", line 116, in execute
self.material_name_to_index = self.write_materials(resources_element, blender_objects)
File "C:\Users\ansonl\AppData\Roaming\Blender Foundation\Blender\2.90\scripts\addons\io_mesh_3mf\export_3mf.py", line 221, in write_materials
material_name = material.name
AttributeError: 'NoneType' object has no attribute 'name'
location: <unknown location>:-1
It happens when one of the objects had a Material created and assigned to it and then the material was deleted in the material menu with the X button next the material.
This leaves a blank material entry in the materials list for the object. This seems to be fixed by deleting the empty material with the "-" button in the list, but it would be nice if the 3MF addon did not error on this.
I tried importing the current master branch of the addon into Blender with the same error results.
Tried installing in 2.9.1.0 but it never shows up in the list of add-ons
We need to read basic vertex and triangle data from the 3MF file.
These need to be added to the object resources.
In order to get accepted as an add-on in Blender, we need to comply to their code style. Unfortunately the Blender developers have succumbed to the prisoner's dilemma of "everyone is using spaces to indent, so we must do the same", and since they are in the lead here we must comply. There code style is listed here. There are a number of changes that we need to do:
# <pep8 compliant>
to the files that are compliant.Chat GPT helped get this add on fixed for 3.5 blender for mac.
Quote from ChatGpt
"It appears that the issue is related to the path where the add-on is located. The error message indicates that the source file is in the add-on search path, which can cause conflicts. To resolve this, you should move the source file(s) for your add-on to a location outside of the add-on search path.
Here are the steps to resolve the issue:
Move Source Files: Move the source files for your add-on, specifically the io_mesh_3mf directory, to a location outside of the Blender add-on search path. Based on the path you provided, it should be moved to a different directory.
Update Import Statements: Review your import statements in the add-on code and make sure they reference the correct paths after you've moved the source files.
Reload the Add-on: After making these changes, disable and then re-enable the add-on in Blender's preferences to ensure that the changes take effect.
By moving the source files outside of the add-on search path, you should be able to resolve the issue and use your add-on without encountering the "Source file is in the add-on search path" error."
DO this
1). Download the zip file
2). move file io_mesh_3mf out of file Blender3mfFormat-master
3). compress or zip file io_mesh_3mf
4). go to install blender add on
5). instal io_mesh_3mf
6). enable add on
Should work.
or install this file and download into blender
io_mesh_3mf.zip
We need to implement an export function so that the Blender objects can be stored in a 3MF archive.
This issue only concerns creating a 3MF-compliant archive. The individual features of 3MF are implemented in other issues.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.