@ferdinand said in Find objects within GLTF-file by name and attach them to the scene.:
Sorry, I did overlook the 'without having to load the complete gltf in memory' part of your initial question.
No worries I also understand that Cinema4D cannot implement a mechanism as I describe for all possible file formats.
What you could do, given your GLTF file is in JSON format, is mangle it into place, given that Python has very nice JSON support. But making sure that this file stays valid, when you remove elements from it, might be not so trivial. I am also not sure if you will ever come out here with a net-win where mangling the file in Python first and then loading it outpaces just loading the full file.
I have to look into that. Given that loading the whole file can easily take 5 minutes, even an approach like this might be a winner. However, you're absolutely right about introducing quite some potential instability when mangling with the file. Also, I did write GLTF
everywhere, but there may be also GLB
files, which should be treated the same way.
Could you shed some light on where this becomes relevant? Are your files so large that loading is a bottleneck? I struggle to see a bit where this could become a scenario with GLTF.
In the end this is all a bit hypothetical. You do not disclose if there are material, animations, etc., and most importantly how the scene hierarchy is, e.g., could an
Eberhardt{n}
hold descendant nodes that must be preserved, e.g.,Ebertraudt
is the first child ofEberhardt42
. This would of course make this all much more complicated.
Of course! I'm happy to share, I just didn't want to blast too many details in this post to avoid distraction from the main question. In the end this will be a basic plugin for placing 3D text along curves.
Imagine a font with 3D letters. This font is saved in a single GLTF file. Each character is a node with a single mesh. No materials, no animations, no nested meshes.* The nodes are not nested, Eberhardt
cannot be a child of Ebertraut
. I do already have a couple of these files and also an already working plugin for Blender. In Blender, I copied the internal function to load gltf's and interjected some code between indexing and loading the file. When the index is created, I reiterate over it and build a new scene tree with only the matching objects, and then continue the normal loading process with the new scene tree. So this is very similar to your file-mangling approach, and it's super fast. I could take this function and plug it in, but I'd need to disentangle it from the internal Blender specific dependencies which I assume to be a significant effort.
The reason why I don't want to load the whole file into memory is because these files can be a gigabyte or even more. If the whole file is loaded into RAM, then it occupies a lot of space there. However, we may write just a couple of letters, so the most of the occupied RAM could be free. It does need to be in the file though! Also, loading a file like this may take 5 literal Minutes, which is - combined with the loss of RAM - an inconvenience I'd love to avoid. What is important, is that the user will have their own project to work with, and whatever this plugin is doing is running on the side. This is why I want to occupy the least amount of RAM possible.
*At least for now a simple mesh per character is fine. In a happy future it would be great to add support for materials, animations, etc - but this seems already complicated enough to get working.
When you want to also support 2024, I would suggest that you just monkey patch
mxutils.IterateTree
(as this seems to be all you need). I have dumped the implementation of it at the end. Doing it like that, would have the benefit that you would native code for 2025.
Beautiful, thank you!
I hope that this cleared up some question marks. I get the feeling that I won't get around writing a custom gltf/glb loader. As you said, I can't expect that c4d already provides me with the functions I need, but I still wanted to ask just in case I am overlooking something.