GreasedLine Export to gltf obj

Hi,

I am having some issues when exporting GreasedLine.

gltf (download via inspector Debug Tab):
When I export this scene https://playground.babylonjs.com/#H1LRZ3#98 as gltf and import it in sandbox.playground.com I can see the nodes and they have vertices, but they will not be shown in the viewport. I do not expect to have an extension for gltf, but it would rather be nice, if it exports like normal LineMesh, which would be shown as a hairline with colors.

obj (downloads directly):
Here is a version that directly downloads an .obj file, it wont export any of the lines: https://playground.babylonjs.com/#H1LRZ3#714

Currently my fallback is, to create an additional LineMesh that will be hidden in viewport, but will be exported.

Kind regards!

1 Like

Hi there! I’ll have a look at this later. Thanks for reporting.

3 Likes

Hi!

You can’t export a GreasedLineMesh to GLTF. GRL uses specific materials - vertex shaders to move the vertices to the desired positions and to display the line correctly (always facing the camera, variable width, etc) and specific fragment shaders to achieve dashing, coloring, visibility, etc.

However you can serialize a GreasedLineMesh for later use.

The only way to correctly export a GreasedLineMesh is to write a custom exporter which could create the resulting mesh on the CPU.

2 Likes

Hi roland,
yes that is what I thought and why it would be easier to maybe export it as a simple line. For those who want to have it exported, i guess your proposal is better suited. And others would need to use my approach of just making a LinesMesh copy for export. That is probably the cleaner approach.

(In my case i am more interested in the actual line data from point to point and not the visualisation. Since its rather CAD related. So LinesMesh is good enough.)

1 Like

Since there is already some work done on reconstructing the line surface taking the variable widths into account on the CPU side for picking purposes, it would help a lot while making a GLTF exporter. I believe it will do no harm if you ask for such functionality in the Feature requests category.

Ah, I didn’t catch the ask on the first read. It’s true that we cannot correctly export a GreasedLineMesh because of its custom shaders.

However, the greased line *vertex data itself should be available on export. It’s not visible because its fill mode defaults to TRIANGLES when, practically speaking, it should be LINES. We make this change already when exporting LineMesh– maybe we can throw in a quick check for GreasedLineMesh at the same time. The output won’t be correct, but at least it will be a little less incorrect :slight_smile:

1 Like

I created a PR for exporting GreasedLine meshes to GLTF. It needs to be extended to fully support all features of GRL.

PG: https://playground.babylonjs.com/?snapshot=refs/pull/16056/merge#TCURLI#3

Imported to Blender:

3 Likes

Awesome, thanks so much!!

1 Like

Wow super nice!
I somehow missed quite some replies. Thanks a lot for the progress :slight_smile:

1 Like

Thanks a lot !

1 Like