KhronosGroup / glTF

glTF – Runtime 3D Asset Delivery
Other
7.14k stars 1.14k forks source link

Sketchup glTF exporter doesn't use components #1662

Open jakakordez opened 5 years ago

jakakordez commented 5 years ago

I have a Sketchup file that has meshes arranged in a hierarchy of components. Each component represents a logical part of my model and has its own coordinate origin set properly (not aligned with the origin of the whole model).

I would expect that exporting the model would result in a glTF file where nodes would represent component instances (re-using the nodes isn't possible according to the glTF 2.0 specification because one node can't have multiple parents) and each node would have a transformation matrix set to represent the origin of its component. Nodes that represent same components should probably also reference same meshes. And finally since a node represents a component instance it should contain the name of the instance ('Instance' string instead of 'Definition' in 'Entity Info' window).

Instead component hirearchy is represented with nodes but doesn't bring any added value since all meshes are duplicated, all matrices are identities and all coordinates are set to global coordinates of the model. The model renders correctly but I would like to dynamically change transformations of components in my application to move some of its parts.

emackey commented 5 years ago

Hi @jakakordez,

glTF doesn't allow re-using nodes, but it does allow re-using the same mesh from multiple nodes at different points the scene graph, with different local transforms. This is typically how instancing is done within glTF, when the instances share the same material. For instances with different materials, separate glTF "mesh" objects are used that refer to the same accessors, so that vertex attributes and index lists can be re-used with a different material applied.

If the Sketchup exporter isn't taking advantage of this, please file an issue with the issue tracker for that project. Thanks!

jakakordez commented 5 years ago

I thought this is the right issue tracker as this exporter is mentioned in some of the other issues here. There is only one glTF Sketchup exporter repository on Github (https://github.com/YulioTech/SketchUp-glTF-Exporter-Ruby) which is a copy of the official one. I believe @CentaurMare is the developer of the official one but he seems to be inactive for more than a year. So where should I file this issue?

zellski commented 5 years ago

@jakakordez I don't think it's very likely that anyone here knows the details of how Sketchup handles plugins. I can't see anything on the extension page that allows you to contact the maintainer or, in fact, leave any kind of comment. Here on GitHub, their email address appears to be Centaurmare@outlook.com; that's probably your best bet.

Meanwhile, there's a decent chance that gltfpack can help by identifying identical meshes and collapsing them into one, but I haven't tried it myself. If you try it and you're successful, it'd be great if you could comment here so that other people who have similar problems in the future can find a solution.

CentaurMare commented 5 years ago

Hi, What was the issue?


From: Pär Winzell notifications@github.com Sent: Friday, 13 September 2019 4:40 AM To: KhronosGroup/glTF glTF@noreply.github.com Cc: Natty Centaurmare@outlook.com; Mention mention@noreply.github.com Subject: Re: [KhronosGroup/glTF] Sketchup glTF exporter doesn't use components (#1662)

@jakakordezhttps://github.com/jakakordez I don't think it's very likely that anyone here knows the details of how Sketchup handles plugins. I can't see anything on the extension page that allows you to contact the maintainer or, in fact, leave any kind of comment. Here on GitHub, their email address appears to be Centaurmare@outlook.commailto:Centaurmare@outlook.com; that's probably your best bet.

Meanwhile, there's a decent chance that gltfpackhttps://github.com/zeux/meshoptimizer#gltfpack can help by identifying identical meshes and collapsing them into one, but I haven't tried it myself. If you try it and you're successful, it'd be great if you could comment here so that other people who have similar problems in the future can find a solution.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/KhronosGroup/glTF/issues/1662?email_source=notifications&email_token=AHGR3DSGRHWI2WTFDLLTTOLQJKELTA5CNFSM4IMSAG7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6S3KDQ#issuecomment-530953486, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AHGR3DRC23ZYYFLCG4UND3TQJKELTANCNFSM4IMSAG7A.

HappyTorso commented 4 years ago

I am encountering the same issue as @jakakordez in that I am unable to maintain my local axes orientation and origin positioning for individual objects in scenes exported from Sketchup using @CentaurMare exporter.

The issue is detailed in this SE post: https://blender.stackexchange.com/q/159129/84455?stw=2

I believe this feature is important for all cases where the origin and axes are being used programmatically to manipulate assets or interact with them.

atteneder commented 4 years ago

In an issue reported recently I discovered that this sketchup exporter creates one huge positions buffer for all meshes/primitives, which might be the root of some of those problems.

That got me questioning: is it totally valid doing this? I mean creating one huge positions buffer and lots of per-primitive index arrays linking to them? Because if your API/engine does not support binding vertices with index buffers arbitrarily, this means you have to create lots of copies of the positions or some other separations magic.

atteneder commented 4 years ago

In an issue reported recently I discovered that this sketchup exporter creates one huge positions buffer for all meshes/primitives, which might be the root of some of those problems.

That got me questioning: is it totally valid doing this? I mean creating one huge positions buffer and lots of per-primitive index arrays linking to them? Because if your API/engine does not support binding vertices with index buffers arbitrarily, this means you have to create lots of copies of the positions or some other separations magic.

In the meantime I had a closer look at this. I created issue #1769 to not hijack this one:

promontis commented 4 years ago

@emackey So glTF does support multiple parents for a mesh, but not for a node, right? So it does support 'components', but only for meshes, not for nodes. Why doesn't it support multiple parents for a node?

In SketchUp, I can create a component which contains other components. How would you recommend the exporter to convert such SketchUp files?

donmccurdy commented 4 years ago

Nodes represent part of a scene graph, with an identifiable "world transform" in the scene. Attaching resources (mesh, light, camera, etc.) at a node simply instantiates those resources at that world transform. If you want to instantiate the same resources at a different location, a new node should be created at that location with the same resources attached to it.

promontis commented 4 years ago

@donmccurdy Thinking out load for this issue... I'm currently thinking of a simple (1) and advanced (2) case:

1) Given one component, named Box (which is just a box), and two instances of that Box.

This could result for glTF in a scene with two nodes and one mesh. Both two nodes would reference the one mesh. This is the most simple case, and is easy to implement.

2) Given one component, named Box, containing another component, named SmallBox, and two instances of that Box. The two instances of that Box also each contain SmallBox, because SmallBox is contained within Box. So, there are two instances of SmallBox and changing one SmallBox will also change the other instance, because both are contained within the component Box. When inspecting the Sketchup model using Ruby, I see that there are no two instances of SmallBox, but just one. There are two Smallbox meshes being rendered, because Box contains SmallBox and there are two instances of Box.

So, AFAIK, there currently is no way to express case 2 without 'loosing information'.

If we do this for glTF:

This would result in a correct glTF rendering the same amount of meshes. But reimporting the glTF file in SketchUp would not result in the same SketchUp model.

Any feedback is welcome 🤗

donmccurdy commented 4 years ago

I think that's all correct, yes. I don't think there's any straightforward way of representing this SketchUp feature as a standard scene graph. If I were the author of the SketchUp plugin, I think I would choose some naming convention ("Box.001", "Box.002") for nodes that provides a hint, and use it when the asset.generator string matches SketchUp's ID.

glTF is not an interchange format, and so it simplifies data to a more realtime-friendly structure. For example, quads are always converted to triangles. I don't know if this particular SketchUp feature exists in other formats, but an interchange format might be necessary if you need to repeatedly reopen the same file in SketchUp, and then export to glTF for the final viewer/application.