paireks / dotbim-blender

Blender addon for dotbim files
MIT License
12 stars 4 forks source link

No colors #8

Closed seghier closed 1 year ago

seghier commented 1 year ago

Hello I use Blender 3.3.1 The file imported without colors, is this a bug or it works like that?

image

paireks commented 1 year ago

Hey, check out this: https://github.com/paireks/dotbim-blender#how-to-see-colors

Side-note: face_colors from 1.1.0 schema are still not supported, cause I had some issues to implement them properly. But normal colors should be fine.

seghier commented 1 year ago

Thanks, yes it work I add this to create materials, it is faster than Rhino.

matg = bpy.data.materials.new(f"{elt.type}") matg.diffuse_color = obj.color obj.active_material = matg

image

paireks commented 1 year ago

Yeah, the only issue you will have then is that after export from Blender doesn't use materials currently :)

If I remember correctly @Gorgious56 decided to stick to colors inside mesh to make things simplier. But maybe it's good to do something similiar to Grasshopper and allow 2 versions, one with colors inside mesh and one with materials :)

seghier commented 1 year ago

From Blender when export obj the materials exported as mtl file which can viewed and edited with text editor

newmtl Material
Kd 0.0 0.8 0.02         # rgb color

newmtl Material.001
Kd 0.800000 0.00 0.03          # rgb color
d 0.4        # tranparency = 1-d

Rhino or any other software import the mtl file as materials, maybe you can do the same, and other settings of the mtl file explained here: https://en.wikipedia.org/wiki/Wavefront_.obj_file Maybe it is easy to added

Gorgious56 commented 1 year ago

The color is associated to the object (object.color), specifically this property image

At the time polygon colors weren't part of dotbim schema but it should be relatively straightforward to add.

https://github.com/paireks/dotbim-blender/blob/0575aa482f42294d5de56a31b46c4a7cbed2c1c5/dotbim_to_blender.py#L40

It didn't make sense to add a material since AFAIK dotbim doesn't support custom shaders so defaulting to a single unlit color would save a bit of processing ressources. As I understand dotbim now supports vertex (or face ?) colors so that could be added as an attribute. Or a default emissive / principled bsdf material. that could be an option in the importer, using something akin to the 3 lines of code of @seghier to add a default material.

It also made more sense for roundtripping dotbim <> Blender since a material can be tied to many different colors so it would be a matter of preference which one should be exported and it roundtripping is harder (potential loss of information). Although I don't think it matters that much since dotbim (AFAIK, pls correct if it does) doesn't support material / shader defintion apart from a single color.

@paireks I might have a bit of time this week to update dotbim>blender and blender>dotbim, would you accept if I tried to implement it ? What features would you like ?

Gorgious56 commented 1 year ago

Haha I just reopened my vscode workspace and I totally forgot that I already started working on this a year and a half ago... image

I just have one question @paireks which version do you want to support ? The mesh color API has evolved a lot since I think version 3.5 where vertex color layers have been dropped in favor of color attributes. We can support both relatively easily but it's a bit of extra work and support down the line.

paireks commented 1 year ago

@Gorgious56 yes, dotbim doesn't support materials in that sense, only colors. So I think you're right with giving up on materials.

With face_colors added in 1.1.0 there is color for each face. That's the only missing feature I think. If you could try this I will be very happy, cause I tried it, but had some difficulties with it.

Regarding Blender's version: it's up to you, I will adapt to your decision :)

paireks commented 1 year ago

@Gorgious56 also here are example files that uses face_colors for tests:

And side-note that dotbimpy has updated to support these face_colors :)

Gorgious56 commented 1 year ago

So while writing the PR I also remembered why I didn't use materials. Linked meshes must share the same materials, so you can't have linked meshes with different colors. Well you can store the materials on the object but that's an obscure feature. I can add this as an option if need be, it shouldn't be too hard, let me know. Cheers

paireks commented 1 year ago

@Gorgious56 thank you very much! For me it works great! 2023-09-21_23h15_01 I will add a post on Linkedin about an update if you don't mind :)

Gorgious56 commented 1 year ago

Hehe please do. Happy to help. I think this issue can be closed since the latest few commits.

Cheers