@mawa you can run transform across all the assets in bulk with a shell script. Here’s that script - with a few of things ive run commented out. Just drop assets in a “source” dir and run the script - and they’ll end up in “output”. I’m really loving this transform library. Im thinking that when someone uploads an asset, i’ll run it through a pipeline using this library to prep it as best i can as you suggest @jelster
for file in source/*.glb
do
filename="${file##*/}"
#gltf-transform optimize "$file" "output/$filename" --join false --flatten false --simplify 0.0
#gltf-transform optimize "$file" "output/$filename"
#gltf-transform optimize "$file" "output/$filename" --texture-compress webp
#gltf-transform resize "$file" "output/$filename" --width 1024 --height 1024
gltf-transform center "$file" "output/$filename"
done
@jelster regarding the duplicates - yea, i am loading and duplicating - to make sure that duplicate works without messing up the model (which is what’s happening in my app… this was the initial purpose of my PG actually - to debug this duplication case). Re: transforms - yea, this particular asset creator has got a bunch of odd stuff on his models. His source editor is Cinema4d, so maybe something in the process to FBX and then GLB is resulting in weird stuff. When I open his assets in Blender they dont look good. All those transforms have mal-impact. Funny that they look fine in Babylon.
Oh. Yea, which node should i be using to position? ^?
Maybe i’m using the root node incorrectly in general? Maybe that’s what’s causing this odd gizmo behavior too? That gizmo correctly modifies that sword… but it’s all askew after initial rotation. The gizmo doesn’t follow the meshes around.
Well, thank you. I guess I will have to give it a try. I was just hoping it would not be needed. To be honest, there are some things I do not fully understand. Like why can I normalize my asset to a unitcube and scaleto but cannot easily reposition the pivot? Either I’m missing something or something is missing?!
As exposed above, I would rather have it ‘an alternative’ than ‘an extension’. But that’s just ‘lazy me’ I suppose Thanks for your time anyways and have a great day
Yes, you can programmatically reset the GLB to the center of the world by using the Mesh class provided by Babylon.js.
BABYLON.SceneLoader.ImportMesh("", "path/to/your/glb/file.glb", "", scene, function (newMeshes) {
// Get the bounding box of all the meshes in the imported model
var boundingBox = BABYLON.Mesh.MergeMeshes(newMeshes).getBoundingInfo().boundingBox;
// Calculate the center point of the bounding box
var center = boundingBox.center;
// Iterate over all the meshes and set their position relative to the center point
newMeshes.forEach(function(mesh) {
mesh.position = mesh.position.subtract(center);
});
});
While not a terrible solution, it may have a potentially serious drawback of introducing side effects; you will want to check that MergeMeshes doesn’t mutate the original meshes for this to work properly
Something to check is that you’re exporting into a Left handed coordinate system, which is what BJS uses, but which some other tools and engines do not. It looks like the rotations are off by 90deg, which is why I mention it!
Me: He told me “Bring the Crane in from outer space” …
GPT3: I would need to find a way to get a crane from outer space. This could involve launching a rocket with the crane inside, or finding an existing crane in space and somehow retrieving it.
I’m glad the problem here is easier than that I bet aerospace engineers would love to just be able to set crane.position = new Vector3(0,0,0) (now that I think about it, would (0,0,0) be the center of the earth or its surface? )
I made world editor that imports any of 300,000 sketcfab models into the scene. First thing I do is resize the model to fit into 1x1x1 box, and place it 2 units in front of the view. That works only once the model is rendered (although calling computeWorldMatrix(true) on root mesh might or might not work).
Thanks for sharing. Mostly appreciated, though I still think that it’s a lot of code and trouble to achieve something that should be simple. I mean I start the same as you, normalizing to unit cube and compute to world matrix… fine. But from there, it turns into a factory of positioning and scaling and I simply do not quite understand why we need to have this and why someone like you has to go through all this code to achieve something that should be (in my opinion) available ‘out of the box’. May be it’s just me, I don’t know. Luckely, I have only about 50 models and not 300k to do
Oh, thanks and my apologies .
Looks like this is exactly the part I was missing. See, I don’t use the viewer.
I knew nothing about getHierarchyBoundingVectors, which seems to be precisly the part I needed. I’m just happy to see that chatGTP also doesn’t know about it… if I account the clumsy solution it has pulled out relying on merging meshes to retrieve the bounding box I’m gonna try that shortly and meanwhile, have a great day
OK, I can hereby now confirm that this solution works (and is actually ez once you know about it).
However, from my readings in this forum and the look at the PG examples from the API when searching for ‘getHierarchyBoundingVectors’, it seems to me like I’m not the only small brain knowing the *** of what he’s doing May be the above would deserve a couple of lines in the doc and a small PG (for those not using the viewer). Just a simple suggestion. I mean I’m good now so again, thanks a lot for that
Meanwhile, have a great sunday
Edit:@bigrig Following the above, I quickly added this to your PG. Thus “Bringing the crane in from outer space” without the need of launching a rocket nor editing or merging!?! the asset (this one’s for you chatGPT)
I’m gonna take this opportunity to share my anger about the faen designers posting assets (even for free) not respecting the rules of modelling for dummies course 1.0. The solution above works well for scaling and positioning but there’s this one thing it will never do, and this is ‘rotation’. EZ enough if coming from a right-handed system you can invert the scaling or rotate. BUT THEN, when the faen designer sets the axis neither facing forward nor backward but randomly rotated facing a direction that doesn’t make any sense, then you’re doomed. Nothing left but to edit the fancy thing or work it one by one on import. I mean I won’t shout after the poor guy creating a model as a hobby and posting it for free. But when an institution like the British Museum of Art releases 300 (beautiful) scans of great works of art and artefacts and the fancy designer doesn’t even take 10s. to set the axis correctly, it just makes me mad That’s it for this subject I suppose. I said what I had to.
All, have a great day
I believe the crane has officially been recovered, due to a concerted effort by the babylon community. NASA and all of the global governments thank you.