Opened 2 years ago

Last modified 2 years ago

#8999 assigned enhancement

Add option to save GLTF with faceted triangle appearance

Reported by: kristen.browne@… Owned by: Eric Pettersen
Priority: high Milestone:
Component: Input/Output Version:
Keywords: Cc: Elaine Meng, Tom Goddard
Blocked By: Blocking:
Notify when closed: Platform: all
Project: ChimeraX

Description

There is a GLTF header value material interpolation with values smooth or flat that controls if triangles are flat shaded. Kristen wants flat shading for NIH3D pipeline when the output is single color models intended for 3D printing.

On May 11, 2023, at 2:19 PM, Browne, Kristen (NIH/NIAID) [C] wrote:

https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/vertexandattributes:interpolation

I think this is what we’re after. It’s defaulting to smooth and we need to set it to flat for any of the -print presets.

Thanks!

K

Kristen Browne, MSc, MscBMC
Contractor – MSC, Inc. | A Guidehouse Company
3D Modeling and Biovisualization Specialist
Bioinformatics and Computational Biosciences Branch (BCBB)
OCICB/OSMO/OD/NIAID/NIH

---

From: Tom Goddard
Subject: Re: gltf smoothing attribute:
Date: May 11, 2023 at 3:11:19 PM PDT
To: "Browne, Kristen (NIH/NIAID) [C]"

Hi Kristen,

Wow! I have read so much of the GLTF spec but still there are parts I never saw, and this is one of them. So this material "interpolation: flat" setting tells it to not interpolate across triangles. That is simpler than removing normal vectors. I am a bit puzzled that it says that all fragments (ie pixels) inside a triangle get the same shading, but if normal vectors are provide how is that shading computed? Does it use the average of the 3 normal vectors? That would give a different appearance than if there were no normal vectors.

It should be easy to add an option when saving gltf to use flat interpolation instead of the default smooth.

Tom

Attachments (1)

emd1080_flat.png (838.9 KB ) - added by Tom Goddard 2 years ago.
Image of GLB written by ChimeraX with new flatLighting option viewed in BabylonJS sandbox

Download all attachments as: .zip

Change History (3)

comment:1 by Tom Goddard, 2 years ago

Cc: Elaine Meng Eric Pettersen added

I added a flatLighting option to the save command for gltf format (e.g. save myscene.glb flat True). It omits all vertex normal vectors from the GLTF file resulting in each triangle being flat shaded. The flatLighting default is false.

The suggestion in the description to use the Material { interpolation: flat } setting does not work. That option is in Google's "filament" library but is not part of the GLTF 2.0 standard. So BabylonJS gives a warning about the undefined option and ignores it. I tried the option in the filament web viewer (https://google.github.io/filament/viewer/) and it did not even work in filament. The solution I used of removing the normal vectors works in BabylonJS giving a nice faceted appearance (tested on atoms, bond, ribbons and density maps). It gives a somewhat faceted appearance but does not look good in the filament viewer. I does not appear the filament viewer conforms well to the GLTF standard.

comment:2 by Tom Goddard, 2 years ago

Cc: Tom Goddard added; Eric Pettersen removed
Owner: changed from Tom Goddard to Eric Pettersen

The NIH3D ChimeraX script will have to be modified to write out the GLTF models intended for 3D printing using the new flatLighting option. And the NIH3D pipeline would need to be updated to a current ChimeraX daily build to use this option.

Reassigning this ticket to Eric to update the NIH3D scripts.

by Tom Goddard, 2 years ago

Attachment: emd1080_flat.png added

Image of GLB written by ChimeraX with new flatLighting option viewed in BabylonJS sandbox

Note: See TracTickets for help on using tickets.