bambulab / BambuStudio

PC Software for BambuLab and other 3D printers
GNU Affero General Public License v3.0
2.23k stars 300 forks source link

Directly Import colored 3D files #1892

Closed xuhao1 closed 6 months ago

xuhao1 commented 1 year ago

Is your feature request related to a problem? Please describe. When I trying to import STEP, obj or 3MF with color/texture. It will loss color in Bambu Studio

Describe the solution you'd like When import these 3D file, the color/texture will be keep, so we can directly edit the color/texture in 3D software like Fusion360, and use bambu X1CC to print it. That will benefit a lot to use Bambu create impressive 3D arts.

Describe alternatives you've considered No

Additional context No

mypillowsateyou commented 1 year ago

This would be an amazing feature. I reverse engineered the color info in the .3mf file and I have a workaround in place that I use to import .obj files with vertex color data. Here is a screenshot of a test I did where I transferred a color indexed and dithered texture to vertex colors of an obj with over a million triangles in Blender:

image

here is the Python script:

import json
import os

import bpy

# Define your filenames
obj_filename = 'obj_file_here.obj'
model_filename = 'model_file_here.model'

blend_file_path = bpy.data.filepath
blend_dir = os.path.dirname(blend_file_path)

print(f'Blend file path: {blend_file_path}')
print(f'Blend directory: {blend_dir}')

# Get the current script directory
script_dir = blend_dir
print(f'Script directory: {script_dir}')

# Combine the directory with the filenames
full_obj_path = os.path.join(script_dir, obj_filename)
full_model_path = os.path.join(script_dir, model_filename)

print(f'OBJ file path: {full_obj_path}')
print(f'Model file path: {full_model_path}')

# Set up Bambu Studio color array
bambu_studio_colors = ['4', '8', '0C', '1C', '2C', '3C', '4C', '5C', '6C', '7C', '8C', '9C', 'AC', 'BC', 'CC', 'DC']

next_color_index = 0
color_mapping = {}

# Read .obj file
print("Reading .obj file...")
with open(full_obj_path, 'r') as file:
    obj_lines = file.readlines()

vertices = []
faces = []

for i, line in enumerate(obj_lines):
    if(i%100000==0):
        print(f"Processing line {i+1} in .obj file...")
    row = line.strip().split(' ')
    if row[0] == 'v':
        r, g, b = row[4], row[5], row[6]
        vertices.append({'r': r, 'g': g, 'b': b})
    elif row[0] == 'f':
        vertex_indices = [int(v.split('/')[0]) - 1 for v in row[1:4]]
        colors = [vertices[index] for index in vertex_indices]

        if None in colors:
            print(f'Missing color data for face at row {i + 1}')
            continue

        color_counts = {}
        for color in colors:
            color_string = json.dumps(color)
            if color_string in color_counts:
                color_counts[color_string] += 1
            else:
                color_counts[color_string] = 1

        max_count = -1
        most_frequent_color = None
        for color_string, count in color_counts.items():
            if count > max_count:
                max_count = count
                most_frequent_color = color_string

        faces.append(most_frequent_color)

print(f"Total vertices: {len(vertices)}")
print(f"Total faces: {len(faces)}")

print("Generating face color mappings...")
face_color_mappings = []
for i, color_string in enumerate(faces):
    if color_string not in color_mapping:
        if next_color_index < len(bambu_studio_colors) and next_color_index < 16:
            color_mapping[color_string] = bambu_studio_colors[next_color_index]
            next_color_index += 1
        else:
            color_mapping[color_string] = 'error'
    color_code = color_mapping[color_string]
    color = json.loads(color_string)
    face_color_mappings.append([f'Face {i + 1}', color['r'], color['g'], color['b'], color_code])

print(f"Total colors: {len(color_mapping)}")
print("Color mappings:")
for color_string, color_code in color_mapping.items():
    color = json.loads(color_string)
    r = int(float(color['r']) * 255)
    g = int(float(color['g']) * 255)
    b = int(float(color['b']) * 255)
    print(f"Color RGB({r}, {g}, {b}) -> Color code: {color_code}")

# Read .model file
print("Reading .model file...")
with open(full_model_path, 'r') as file:
    model_lines = file.readlines()

triangle_count = 0
face_index = 0
for i, line in enumerate(model_lines):
    if(i%100000==0):
        print(f"Processing line {i+1} in .model file...")
    line = line.strip()
    if line.startswith('<triangle') and line.endswith('/>'):
        triangle_count += 1
        color_code = face_color_mappings[face_index][4]
        line = line.replace('/>', f' paint_color="{color_code}"/>')
        face_index += 1
    model_lines[i] = line

print(f"Total triangles: {triangle_count}")

# Write new .model file
print("Writing new .model file...")
new_model_path = os.path.join(script_dir, 'new_' + model_filename)
with open(new_model_path, 'w') as file:
    for line in model_lines:
        file.write(line + '\n')

print("Done!")

For anyone curious this is Blender geometry nodes I used to map my texture (which is indexed, 7 colors) to vertex Color attribute, very important to use Closest in Image Texture node and Point domain in Store Named Attribute, I do not recommend baking, it always seemed to stray from the original 7 colors and therefore become useless for my script:

image

Hope my workaround helps inspire a real feature implementation

lanewei120 commented 1 year ago

thanks very much for this suggestion

we will evaluate this solution and give the feedback later

xuhao1 commented 1 year ago

@mypillowsateyou Amazing work you have done!

lanewei120 commented 1 year ago

@mypillowsateyou the most important thing is to tranfrom the the vertex color to face's color, so currently it seems you set the color of the face to either the most frequently used color among all its vertices or to the color of a specific vertex?

mypillowsateyou commented 1 year ago

@lanewei120 yes exactly, the script uses the most frequent color of the face's vertices, otherwise it will just use the color of the first vertex if all three are different colors, for me this was good enough

tinogithub commented 1 year ago

@mypillowsateyou Sounds like an approach I would like to try however I run in an error running your script. In line 46: IndexError: list index out of range

Before I begin changing your code I would like to know if I started correctly.

  1. I used Blender 3.4 to export the standard monkey "Suzanne" model to an obj.
  2. Imported into Bambu Lab 1.7.7.89
  3. Saved and later extracted the .3mf-file
  4. In your script I referenced the model-file to the extracted subdirectory /3D/Objects
  5. Loaded and started your script in blender

Looking at the error I wondered that your script says in line 46 r, g, b = row[4], row[5], row[6]

however i seem to cound just 4 rows i.e.: v 0.021875 0.008203 0.038281

Maybe I am misundestanding something?

Thank you for help

creechoftheeast commented 11 months ago

This would be a great addition. Currently, I'm using nozzleboss addon for blender to export gcode for multicolor prints.

VickyTGAW commented 10 months ago

Looking at the error I wondered that your script says in line 46 r, g, b = row[4], row[5], row[6]

however i seem to cound just 4 rows i.e.: v 0.021875 0.008203 0.038281

Maybe I am misundestanding something?

Thank you for help

I found when going to the Export->Wavefront (.obj) option in Blender, I had to check the Color under the Geometry Options section. Then the V lines in the resulting .obj file included the extra data:

v -4.616998 3.848527 15.021108 0.7608 0.7412 0.4314

ScottFerg56 commented 10 months ago

+1 for support for recognizing material/color information already present in imported 3D files, especially in my case, OBJ/MTL and STEP. Transferring the actual colors is not so important to me as simply recognizing the different materials in the geometry and allowing them to be assigned from the colors available in the AMS. Thanks!

THE-SIMPLE-MARK commented 10 months ago

+1 for support for recognizing material/color information already present in imported 3D files, especially in my case, OBJ/MTL and STEP. Transferring the actual colors is not so important to me as simply recognizing the different materials in the geometry and allowing them to be assigned from the colors available in the AMS. Thanks!

Exactly, I'm facing the same problem as well.

I want to add multi color support (painting included) to my online model viewer but I don't want to write my own logic to interface with Bambu's own propriatery spin-off of the 3mf standard. This would be sooo easy to do if Bambu would at least check for any colors and at least separate them in the editor once you import it so filaments can be assigned afterwards. I'm currently looking for any easier methods than the python script mentioned above in combination with using OBJs.

I already brought this up with to a couple of people over at the Bambu Lab Official discord community in the #mqtt channel, so you'll find answers there. If we ever get any, that is.

mypillowsateyou commented 9 months ago

+1 for support for recognizing material/color information already present in imported 3D files, especially in my case, OBJ/MTL and STEP. Transferring the actual colors is not so important to me as simply recognizing the different materials in the geometry and allowing them to be assigned from the colors available in the AMS. Thanks!

I saw your comment and felt inspired to make a better workaround than my previous one. I learned a lot about Blender geometry nodes since then and came up with a way to extract a manifold shell of each material of an object. You can see the result of this extraction here:

image

The geometry nodes modifier is pretty simple to use, just specify a shell thickness in mm and the material slot you want to extract. There is a calculation which finds the distance internally to the other side of the geometry when raycast from each vertex position, and the thickness is capped at half of that so the shell doesn't protrude out the other side of the geometry. Here is some example geometry generated from a black and white version and a many color version of a random shape:

image

.blend and .3mf files included for you to play with, hope others find this useful as well. I think I will also work on some geometry nodes that takes a textured model and generates a copy with new materials assigned to each face based on the color of that face, and limited by some number of materials like 4, 8, 16 depending on how many AMS slots you have. Combine that with the geometry nodes I included here and you would be able to 3D print any manifold textured model with relative ease

Let me know how your experiments go :)

separate model by materials.zip

ScottFerg56 commented 9 months ago

@mypillowsateyou I don't use Blender. I'm actually creating OBJ and STEP files from scratch in my own program. I'll likely wind up creating 3MF as well, before this is done. That Bambu uses 3MF for its project files suggests I could write compatible files with usable color content. If that process were documented somewhere, it would certainly help. Part of my justification for buying the X1C was to make sure the model-creating program I'm developing was useful on the best printer on the market. Presently, that goal is blocked!

THE-SIMPLE-MARK commented 9 months ago

@mypillowsateyou I don't use Blender. I'm actually creating OBJ and STEP files from scratch in my own program. I'll likely wind up creating 3MF as well, before this is done. That Bambu uses 3MF for its project files suggests I could write compatible files with usable color content. If that process were documented somewhere, it would certainly help. Part of my justification for buying the X1C was to make sure the model-creating program I'm developing was useful on the best printer on the market. Presently, that goal is blocked!

Even after Bambu's recent efforts to standardize their 3mf, it's still not up to standard. Instead of using color groups as defined by the 3mf consortium, they attach a color property to each triangle.

I have yet to make my logic for converting STEP/OBJ files to 3mf, but this is something I plan to do in the next couple of weeks. Thankfully their method of storing the color seems pretty standard.

These are all the things I found which are not up to the 3mf consortium standard, every other information is available on their site, so converting to a .model and then making custom a custom drawing utility shouldn't be that hard.

mypillowsateyou commented 9 months ago

@mypillowsateyou I don't use Blender. I'm actually creating OBJ and STEP files from scratch in my own program. I'll likely wind up creating 3MF as well, before this is done. That Bambu uses 3MF for its project files suggests I could write compatible files with usable color content. If that process were documented somewhere, it would certainly help. Part of my justification for buying the X1C was to make sure the model-creating program I'm developing was useful on the best printer on the market. Presently, that goal is blocked!

Even after Bambu's recent efforts to standardize their 3mf, it's still not up to standard. Instead of using color groups as defined by the 3mf consortium, they attach a color property to each triangle.

I have yet to make my logic for converting STEP/OBJ files to 3mf, but this is something I plan to do in the next couple of weeks. Thankfully their method of storing the color seems pretty standard.

  • They have a project config XML which stores data about the filaments in the project in a very unconventional way (each property has an array as the value, where each array item refers to a filament configured in the project).
  • Then, each .model file is an XML containing the triangles that make up that model. Each triangle can contain 2 properties (the names of which I don't remember). One is a simple number from 1-16 indicating the filament for that triangle based on the project XML config I talked about above. Then there's another property which contains a string which I presume is for keeping track of the brush strokes of that triangle, I have yet to determine the format of that one.

These are all the things I found which are not up to the 3mf consortium standard, every other information is available on their site, so converting to a .model and then making custom a custom drawing utility shouldn't be that hard.

Regarding the formatting of that string, it does track the brush strokes by describing a tree for each triangle of the mesh, and at the leaves of that tree lies the filament code to be used for that recursed triangle. When you paint colors on a mesh it is creating this tree on the fly and if you zoom in you can see everything resolves down to triangles (not geometry triangles, just for which filament to use at that area)

Looking at this triangle as an example, the upper right half of this face:

image

For this triangle the string is "4C4C44C44C44C4344C34C4C34C434C4344C3"

It was a while back when I wrote my original script but I determined it follows these rules: a. the string recursion seems to happen reading the string backwards b. "3" means recurse the current triangle c. other values assign a filament, according to these codes ['4', '8', '0C', '1C', '2C', '3C', '4C', '5C', '6C', '7C', '8C', '9C', 'AC', 'BC', 'CC', 'DC']. Note that the string is parsed backwards but the code remains forward, i.e. 4C in the string DOES mean filament code 4C, don't flip a C4 into filament code 4C d. in the recursion (which divides each triangle into 4), the middle triangle is first, then each corner triangle, not sure what the absolute order is, could just be the order of vertices of the original triangle

image

If we walk through the string backwards we can see the logic in the image, this string is for the upper right triangle of the face of the cube we are looking at, in this case I had yellow filament assigned to 4C and green to 4, and the order of recursion from this perspective seems to be middle triangle, top left, top right, bottom right:

a. 3, recurse the current triangle b. 4C, the middle triangle uses filament code 4C c. 4, looks like the top left triangle uses filament code 4 d. 3, recurse the top right sub triangle e. 4, middle triangle uses filament code 4 f. 4C, top left triangle uses 4C g. 3, recurse top right triangle h. 4, middle is green i. 4C, top left is yellow j. 3, recurse top right k. 4C, middle yellow l. 4C, top left yellow m. 3, recurse n. 4C o. 4 p. 3 q. 4 r. 4C s. 4 t. 4C, the first bottom right triangle which finally completes the recursion, the next code is for the triangle layer above u. 4, bottom right completing this layer v. 4C, bottom right completing layer w. 4, x. 4C y. 4C, completing the tree

Probably would have helped if I used 16 different codes to help identify the triangles haha, hopefully you follow the logic and if not I can try to create a better example

So in my script above, I decided not to go with this level of complexity and just mapped each mesh triangle to a single filament code, instead of a long string with all this recursion there is only a single code for one layer and no recursion

THE-SIMPLE-MARK commented 9 months ago

@mypillowsateyou I don't use Blender. I'm actually creating OBJ and STEP files from scratch in my own program. I'll likely wind up creating 3MF as well, before this is done. That Bambu uses 3MF for its project files suggests I could write compatible files with usable color content. If that process were documented somewhere, it would certainly help. Part of my justification for buying the X1C was to make sure the model-creating program I'm developing was useful on the best printer on the market. Presently, that goal is blocked!

Even after Bambu's recent efforts to standardize their 3mf, it's still not up to standard. Instead of using color groups as defined by the 3mf consortium, they attach a color property to each triangle. I have yet to make my logic for converting STEP/OBJ files to 3mf, but this is something I plan to do in the next couple of weeks. Thankfully their method of storing the color seems pretty standard.

  • They have a project config XML which stores data about the filaments in the project in a very unconventional way (each property has an array as the value, where each array item refers to a filament configured in the project).
  • Then, each .model file is an XML containing the triangles that make up that model. Each triangle can contain 2 properties (the names of which I don't remember). One is a simple number from 1-16 indicating the filament for that triangle based on the project XML config I talked about above. Then there's another property which contains a string which I presume is for keeping track of the brush strokes of that triangle, I have yet to determine the format of that one.

These are all the things I found which are not up to the 3mf consortium standard, every other information is available on their site, so converting to a .model and then making custom a custom drawing utility shouldn't be that hard.

Regarding the formatting of that string, it does track the brush strokes by describing a tree for each triangle of the mesh, and at the leaves of that tree lies the filament code to be used for that recursed triangle. When you paint colors on a mesh it is creating this tree on the fly and if you zoom in you can see everything resolves down to triangles (not geometry triangles, just for which filament to use at that area)

Looking at this triangle as an example, the upper right half of this face: ...

@mypillowsateyou Sorry for the amount of questions, but can you explain more about the simpler method you talked about the end of your message? If I understand it correctly, the method used by Bambu uses the string method so the model itself does not need more triangles to be added.

I assume what you do is actually add those triangles which (which the Bambu method would "virtually" iterate through) and just add the property to that triangle which assigns the filament color, correct?

SaltWei commented 9 months ago

Thanks everyone! This is really really a good suggestion and we had already noticed this feature from internal tester. Manual coloring is really time-consuming. We will investigate how to keep color of obj file firstly. And then step file. Because step file is imported by OCCT lib. Will also investigate whether occt support importing color information.

mypillowsateyou commented 9 months ago

@THE-SIMPLE-MARK no problem the more we all understand and put out there the more likely we get an integrated solution from BL

Yes exactly, it looks like the string is pretty much a way to store the color information for each mesh triangle in a highly compressed manner compared to either creating new geometry or generating a UV mapped texture

For the second question, the script I wrote doesn't add new mesh triangles, just fills out the recursing filament slot property of each existing triangle in the .model file, based on the vertex colors of each triangle in a source .obj file. In the script only a single filament slot code is assigned to a triangle from the array mentioned before with "4" corresponding to slot 1, "8" to slot 2, "0C" to slot 3, etc instead of doing any recursing

With this method the coloring resolution only goes as deep as there are polygons in the mesh, each mesh triangle has one filament assigned

I just found out something else as well, if you have an object with multiple parts where each part is assigned a different color through the Objects hierarchy, the color information is not stored on a per triangle basis but looks like it is located in Metadata/model_settings.config of the .3mf file. For each tag there is an tag which looks like it sets the filament for that entire part

image image
THE-SIMPLE-MARK commented 9 months ago

Thanks everyone! This is really really a good suggestion and we had already noticed this feature from internal tester. Manual coloring is really time-consuming. We will investigate how to keep color of obj file firstly. And then step file. Because step file is imported by OCCT lib. Will also investigate whether occt support importing color information.

@SaltWei Thanks so much for the response! Can we get an ETA regarding the OBJ support? I don't want to implement my own solution if this feature gets implemented in the coming 1-3 months.

ukdavewood commented 9 months ago

Started investigating this area myself today too and found this thread via a search for paint_color.
What I was aiming to do is

  1. Export a coloured 3mf from blender.
  2. Load it into Bambu Studio and then save it straight back out uncoloured in BS 3mf format
  3. Automatically pick up on any saved 3mf files and then run a script which:
  4. like @mypillowsateyou simply goes through the BS 3mf file triangles and creates a paint_color entry for every corresponding triangle in the blender exported 3mf file with a p1 entry. - Have spent a while trying to figure out what paint_color values mean - but think I will just go with the list specified above in this thread.
  5. Write out an updated BS format 3mf file and then automatically re-open it in BS

An alternative completely different approach to this is to write some sort of script in Blender that automatically splits up objects by materials but also includes some geometry behind all of the splits to fill in all of the gaps.

nhnifong commented 9 months ago

Those compact strings appear to come from FacetsAnnotation::get_triangle_as_string() which is writing a hexadecimal representation of the selector map produced by TriangleSelector.serialize, but hats off to @mypillowsateyou for apparently reverse engineering it without looking at the source, among many other impressive feats.

https://github.com/bambulab/BambuStudio/blob/master/src/libslic3r/Model.cpp#L3651 https://github.com/bambulab/BambuStudio/blob/f6930bb6ab5005184dab3c0fb060394d2fb2f3dc/src/libslic3r/TriangleSelector.cpp#L1625

This code appears to be part of libslic3r and is identical between BambuStudio and PrusaSlicer. The blender 3mf exporting plugin does not appear to have support for exporting color yet, as the authors said "there aren't very many good color 3d printers anyways" 4 years ago. :P https://github.com/Ghostkeeper/Blender3mfFormat

But apparently Solidworks can export a colored 3mf file. it would be interesting to see where a simple colored 3mf file exported with solidworks differes from one saved in bambu studio or prusaslicer. does solidworks use the serialized recursive triangle selectors in the FacetsAnnotation data? It is very unlikely that it does unless they were specifically targeting prusaslicer.

The 3MF spec does not appear to exactly specify how textured models are supposed to be represented, but this recursive triangle selector trick just strikes me as kind of brittle and not extensible.

I would suggest to Bambu labs to take the initiative to store actual texture images and UV maps in the 3mf file, document the format publicly and clearly, and leave it to blender contributers and others to write export plugins that can match that format.

Within Bambu Studio, specifically libslic3r, add a new method similar to select_patch() in TriangleSelector which samples the texture using the UV map at a configurable resolution, and decides whether a given sample point should be selected or not depending on a user chosen target color and sensitivity value.

nhnifong commented 9 months ago

or if saving the texture in 3mf is too complicated, continue saving the triangleselectors, but aim only to provide a painting tool that can fill areas by sampling a UV mapped texture from some other 3D file format.

SaltWei commented 9 months ago

@SaltWei Thanks so much for the response! Can we get an ETA regarding the OBJ support? I don't want to implement my own solution if this feature gets implemented in the coming 1-3 months.

3 months should be OK for obj support. We are moving at the moment

Haidiye00 commented 8 months ago

img_v3_0294_accce76d-0bb6-4515-8c18-fe32f2aaec8g image image Hello, I have learned about three ways to store colors in obj files: vertex storage, lighting information storage in mtl files, and texture coordinate mtl+png storage. May I ask which of the three methods mentioned above is more commonly used and which is less commonly used? Looking forward to your reply

CptJackieSparrow commented 8 months ago

Waow, this was extremely usefull! Thank you for sharing matey @mypillowsateyou ! Though i wonder is it possible to import Bambu exported 3MF with color data TO blender? Reverse of what you've did? Couldn't find anything like it online. Tbh, bambu has better coloring tools than blender, for workflow at least! I coudn't extract color data from 3mf files unfortunately..

Haidiye00 commented 7 months ago

Hello,obj import color function has been released, supporting vertex color and mtl color import. PNG color is currently not supported, please try the new version. thanks

amoose136 commented 7 months ago

Yay! You have no idea the lengths I had to go to last year to procedurally color some parts using Blender. Vertex color and mtl color support makes it so much more simple. Now all I need is a nice dynamic subdivision node setup (sort of like this: https://youtu.be/rP6mujoskmw ) and it should be almost trivial to convert a uv image textured object into something the slicer can use.

Haidiye00 commented 7 months ago

Thank you, thank you for your affirmation. We will continue to work hard.

amoose136 commented 7 months ago

Worked for me in a quick test. https://www.youtube.com/watch?v=X4TbP9kpcz4

nhnifong commented 7 months ago

I've tested using the following blend file and found that some imported colors are very different from what they were in blender Consider the selected cockpit part here. It has a brown base with a material base color of 86,62,43

cockpit_part.zip

image

I exported the selected object with the following settings. Triangulate mesh is necessary to prevent an error when importing in bambu studio but that seems reasonable. image

The color assigned to the base once imported in bambu studio is 23,13,6.

image

This is pretty minor, because we can always change the color after importing to match what filament we have, but I thought I would let you know. No other issues from what I can find.

Haidiye00 commented 7 months ago

image There will indeed be a color difference issue because we did not use Phong lighting to pre render and obtain this color. We only used the diffuse color, so there will be differences

nhnifong commented 7 months ago

I cannot see multiple colors imported on this test file.

color experiment.zip

It should look like this, but after import into bambu studio it's all one color image

Haidiye00 commented 7 months ago

image Hello, you did not provide the mtl file for obj file.like this : image

nhnifong commented 7 months ago

I see. I thought everything was contained in the OBJ. thank you for the response.

mypillowsateyou commented 6 months ago

image There will indeed be a color difference issue because we did not use Phong lighting to pre render and obtain this color. We only used the diffuse color, so there will be differences

I think the difference comes from the fact that Bambu Studio is showing the raw (linear) color space, but Blender does not default to raw color space, using instead something like sRGB (non-linear) or however the user has it configured. Look at this for example, shown first with sRGB and then raw colors

image

Bambu Studio is using the raw linear color space when displaying the colors and matching when importing the .obj, causing dark colors to appear much darker, and so dark in fact it is automatically mapping my brown and grey colors to black instead of to the grey and brown filaments I have loaded

image

So in whatever software we are generating our models from, we can set the color space to raw/linear to see how it will import into Bambu Studio and adjust our colors there before exporting, or it would be great if Bambu could add an option during import to treat colors as linear, sRGB, or other color spaces

By the way, kudos to everyone who worked on implementing the import with color, the implementation is far beyond what I had hoped for!!!

Haidiye00 commented 6 months ago

Thank you for your suggestion. I will take some time to learn about the benefits of SRGB and consider how to improve it. Thank you~

KodeMunkie commented 6 months ago

@Haidiye00 Please can you filter duplicates in the popup dialog please? This print has just four colors (I know as I created it programmatically from a fixed palette matching my AMS filaments). image

Haidiye00 commented 6 months ago

Hello, can I provide your OBJ file?thanks

KodeMunkie commented 6 months ago

Hello, can I provide your OBJ file?thanks

@Haidiye00 sure. The original needs repairing due to an edges issue so I've provided the Windows Service "repaired" version (nb. model is not as designed, it's now missing a few layers), but it this has the same issue of too many identical colours on import.

This model is large so may lock up BambuStudio for a bit on loading (my machine is quite high spec so it's not too bad, a couple of minutes)*. When it's loaded there should only be 4 colours, white, red, blue and yellow. bbl-test.zip

*On a related note you might want to consider doing the loading on a background thread to the UI since if you click off BambuStudio and back on during the OBJ load Windows tells you it's unresponsive/offers to kill Bambu Studio as it's greyed out.

Haidiye00 commented 6 months ago

Thank you for your files and testing. We have identified the issue and are currently working on resolving it. image The algorithm results are 6 that should be the best.

There is currently a manual solutionimage

KodeMunkie commented 6 months ago

That's great :) Interestingly, the colour component channels programmatically should have been either 0 or 255, which I thought was a related bug in your importer doing shading, but could be that the third party ply/obj exporter I'm using is modifying the per vertex colour. I'll double check the RGBs manually this evening in a text editor since it should only have 4 primary colours in that file.

Haidiye00 commented 6 months ago

这真是太好了:)有趣的是,以编程方式,颜色分量通道应该是 0 或 255,我认为这是您的导入器进行着色时的一个相关错误,但可能是我正在使用的第三方 ply/obj 导出器正在修改每个顶点颜色。今晚我将在文本编辑器中手动仔细检查 RGB,因为它在该文件中_应该_只有 4 种原色。

MDZamxSxdk After our algorithm detection, there are five colors, and the duplicates have been removed. There may be a slight color distance deviation between the algorithm and the original color, which should be normal. This has no significant impact. After entering the Bambu software, you can also make modifications.

KodeMunkie commented 6 months ago

That seems better but there is no magenta (255,0,255) in the original algorithm I'm using. I'm commenting at the moment from a phone so can't check my file itself, but the histogram of the actual colour usage should show 0 instances for it. As mentioned this is also likely to be a bug in the exporters in my code :( but will check.

Haidiye00 commented 6 months ago

这似乎更好,但是我使用的原始算法中没有洋红色(255,0,255)。我现在正在通过手机发表评论,因此无法检查我的文件本身,但实际颜色使用的直方图应显示 0 个实例。如前所述,这也可能是我代码中导出器的错误:(但会检查。

image These green box positions are magenta

KodeMunkie commented 6 months ago

Thanks that saved me checking :) Now I have to find how they are getting into my export 😂 I bet it's doing some kind of 50/50 blending between 255.0.0 and 0,0,255 somewhere, and the additional differences are rounding errors, but these are my problems :)

KodeMunkie commented 6 months ago

Please note I've added the PLY ticket in Orcaslicer rather than here as I require multiple printer brand support for colour PLY files, not sure if it should have been in this project. Please also note that another variant of my test file (as STL) is causing Bambu Studio to outright crash https://github.com/bambulab/BambuStudio/issues/4039 .

Apologies for going off topic, this is just added for clarification on whether Orcaslicer was the best place for the color PLY ticket and awareness of the instability in the BS beta slicer that might affect the way the slicer works in (final) models I may distribute that are created by the same software (models are valid).

Haidiye00 commented 6 months ago

This feature has been released in the latest version. Please download and use it. Thank you~

mew1033 commented 6 months ago

@Haidiye00 Is there a ticket for the PNG texture version of this? It sounds like it's being worked on, I just wanted to follow development.

Haidiye00 commented 6 months ago

这个PNG纹理版本有票吗?听起来它正在开发中,我只是想关注开发。

PNG import is currently under development.

FEMit160 commented 4 months ago

@haidiye00. Just wanted to say thank you for all your hard work incorporating the reading of color data for obj file import. It is a game changer.

I do have another request, would you be able to do the same for importing VRML (.wrl) files and maintaining color? VRML file are an older format, but many sofware programs still use it. They encode the color per vertex/face as well, all in one file.

Thanks again!

Haidiye01 commented 4 months ago

Can you provide some VRML (. wrl) files? Let's take a look at this format. Additionally, I suggest that you use Blender software to convert VRML (. wrl) files into obj files.