Coder Social home page Coder Social logo

blender3mfformat's Introduction

Blender 3MF Format

This is a Blender add-on that allows importing and exporting 3MF files.

3D Manufacturing Format files (.3mf) are a file format for triangular meshes intended to serve as exchange format for 3D printing applications. They can communicate not only the model, but also the intent and material of a 3D printing job from the CAD software to the CAM software (slicer). In this scenario, Blender serves as the CAD software. To that end, the aim of this add-on is to make Blender a more viable alternative as CAD software for additive manufacturing.

Installation

This add-on requires Blender 2.80 or newer. It is tested on version 2.80, 2.83, 2.93 3.0 and 3.3.

To install this add-on, currently you need to tell Blender where to find a .zip archive with the add-on inside.

  1. Download the latest release from the releases page. This is a .zip archive.
  2. In Blender, go to Edit -> Preferences and open the Add-ons tab on the left.
  3. Click on the Install... button at the top. Navigate to the .zip you downloaded.
  4. Under the "Community" category, find the add-on called "Import-Export: 3MF format". Make sure that it's enabled. (Note: If searching with the search box, exclude the "Import-Export" text since this is the category, not part of the add-on name. Just search for "3MF" instead.)

The add-on is being considered for inclusion in Blender as a community add-on here. This would make it easier to install.

Usage

When this add-on is installed, a new entry will appear under the File -> Import menu called "3D Manufacturing Format". When you click that, you'll be able to select 3MF files to import into your Blender scene. A new entry will also appear under the File -> Export menu with the same name. This allows you to export your scene to a 3MF file.

Screenshot

The following options are available when importing 3MF files:

  • Scale: A scaling factor to apply to the scene after importing. All of the mesh data loaded from the 3MF files will get scaled by this factor from the origin of the coordinate system. They are not scaled individually from the centre of each mesh, but all from the coordinate origin.

The following options are available when exporting to 3MF:

  • Selection only: Only export the objects that are selected. Other objects will not be included in the 3MF file.
  • Scale: A scaling factor to apply to the models in the 3MF file. The models are scaled by this factor from the coordinate origin.
  • Apply modifiers: Apply the modifiers to the mesh data before exporting. This embeds these modifiers permanently in the file. If this is disabled, the unmodified meshes will be saved to the 3MF file instead.
  • Precision: Number of decimals to use for coordinates in the 3MF file. Greater precision will result in a larger file size.

Scripting

From a script, you can import a 3MF mesh by executing the following function call:

bpy.ops.import_mesh.threemf(filepath="/path/to/file.3mf")

This import function has two relevant parameters:

  • filepath: A path to the 3MF file to import.
  • global_scale (default 1): A scaling factor to apply to the scene after importing. All of the mesh data loaded from the 3MF files will get scaled by this factor from the origin of the coordinate system.

You can export a 3MF mesh by executing the following function call:

bpy.ops.export_mesh.threemf(filepath="/path/to/file.3mf")

This export function has five relevant parameters:

  • filepath: The location to store the 3MF file.
  • use_selection (default False): Only export the objects that are selected. Other objects will not be included in the 3MF file.
  • global_scale (default 1): A scaling factor to apply to the models in the 3MF file. The models are scaled by this factor from the coordinate origin.
  • use_mesh_modifiers (default True): Apply the modifiers to the mesh data before exporting. This embeds these modifiers permanently in the file. If this is disabled, the unmodified meshes will be saved to the 3MF file instead.
  • coordinate_precision (default 4): Number of decimals to use for coordinates in the 3MF file. Greater precision will result in a larger file size.

Support

This add-on currently supports the full 3MF Core Specification version 1.2.3. However there are a number of places where it deviates from the specification on purpose.

The 3MF specification demands that consumers of 3MF files (i.e. importing 3MF files) must fail quickly and catastrophically when anything is wrong. If a single field is wrong, the entire archive should not get loaded. This add-on has the opposite approach: If something small is wrong with the file, the rest of the file can still be loaded, but for instance without loading that particular triangle that's wrong. You'll get an incomplete file and a warning is placed in the Blender log.

The 3MF specification is also not designed to handle loading multiple 3MF files at once, or to load 3MF files into existing scenes together with other 3MF files. This add-on will try to load as much as possible, but if there are conflicts with parts of the files, it will load neither. One example is the scene metadata such as the title of the scene. If loading two files with the same title, that title is kept. However when combining files with multiple titles, no title will be loaded.

No 3MF format extensions are currently supported. That is a goal for future development.

blender3mfformat's People

Contributors

ansonl avatar cfnz avatar deuracell avatar donpavlov avatar ghostkeeper avatar iviar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

blender3mfformat's Issues

Import and Export object dimensions and translations scaled by changes to Unit Scale.

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.

image

Write materials

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.

Building the scene

Read out the <build> tag and all of its <item>s. Create a Blender object for each of them.

Read out transformations

We need to read the transformations applied to these objects.

The transformations need to be added to the Blender objects as affine transformation matrices.

Export transformations

In order or the meshes to end up in the correct spot again, we need to store the object transformation in the 3MF file.

Export function fails

Export function fails on latest master on Blender 2.90.0. Not sure if it's intended being still a test release.

3mf blender export

Ensure stability through automated tests

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.

3.6 3MF Blender Compatibility Workaround

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!

Importing object resources

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.

Blender code style compliance

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-compliance. For this repository this means converting all tabs to 4 spaces. We will not adhere to the 80-character line limit.
  • Use single quotes for enum-like strings.
  • Add # <pep8 compliant> to the files that are compliant.

Install fix

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

Metadata is not saved for resource objects without mesh

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.

Use the correct units

The 3MF specification specifies that documents can specify a unit. We need to read this unit and apply it to the mesh.

MustPreserve relationship

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.

python script?

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,

Changing license from AGPL to GPL for inclusion in default Blender package

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.

MustPreserve relationships from one archive is applied to other archives

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.

Diffuse texture maps not supported on Import or Export

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.

Read out metadata

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.

installation fails silently

After installing the plugin I get a notification saying that the plugin is installed. However, I cannot find it in the list under any category nor I can find the new entry in the import menu.

Screen Shot 2021-04-29 at 09 37 24

Export objects

Create new object resources from the scene when exporting.

Texture not included in export

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?

SUPPOPRT STRUCTURES

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

SUPPORTS

I'd be happy to do some of the work if you could get me started.
singleSupportPrussaSlicer
singleSupportPrussaSlicer3mf.zip

Unconventional file names

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.

Export functionality

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.

When installed, plugin is not shown

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.

Write metadata to export

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.

Log information

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!

Objects are imported empty without any mesh

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

Read out materials

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.

Generate thumbnails

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.

Reuse mesh data that is the same

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.

Exported 3MF files fail on open in 3D-Builder and Netfabb

Software:
OS: Win10
Blender: 2.82.7
Netfabb: 2020.3
3D Builder: 18.0.1931.0

Recipe:

  1. Start blender (has default cube)
  2. Export to 3MF
  3. Try to load in 3D Builder or Netfabb

First error encountered is the same in both:
0x80004005

The fixes are simple, perhaps I'll submit a pull request.

3MF Consortium Support

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

AttributeError: 'NoneType' object has no attribute 'name' when object has blank Material

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.

image

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.

Does not work with Blender 3.5

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.

Error import/export the 3mf file

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

https://blender.stackexchange.com/a/275934/155512

Support for components

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.

Preserve PrintTickets

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.

Add option for maximum export precision

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.

Support for Blender 2.90.1

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.