Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

three.js new lighting and color management - add colorspace to ImageTexture #146

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kielnino
Copy link

For the transition to the new lighting-model in three.js there were a few updates made to meshcat.

To render obj-files with textures correctly in this new version, the textures need to have the colorSpace attribute set accordingly (see discussion here). This MR adds the parameter to the json.

@kielnino
Copy link
Author

I know that this can be also done via kwargs like this:

material = g.MeshLambertMaterial(map=g.ImageTexture(image=g.PngImage.from_file(texture_file), colorSpace="srgb"))

but as srgb is the new default, I would prefer to set it in the code directly.

@kielnino
Copy link
Author

The same goes for the g.PointCloud. If we set the color as a numpy-array of RGB-colors, we now need to convert them to linear:

#suppose colors is a np.array of srgb values (range 0. - 1.) with shape (N, 3)

def srgb_to_linear(srgb):
    linear = np.where(srgb <= 0.0404482362771082, srgb / 12.92, ((srgb + 0.055) / 1.055) ** 2.4)
    return linear

colors_linear = srgb_to_linear(colors).T if colors is not None else None
g.PointCloud(position=points.T, color=colors_linear)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant