1
\$\begingroup\$

I'm creating my own flight simulator game from scratch, using Swift and Metal, for learning purposes, and I'm wondering how I can move certain parts of my aircraft model.

My model is a free OBJ file that I downloaded from the internet, with multiple submeshes representing different parts of the aircraft, such as the landing gear, flaps, ailerons, etc. The nose gear for example is composed of multiple submeshes itself (tires, struts), all of which I'm trying to figure out how to animate (to put the gear down or up).

While I've figured out how to translate, rotate and scale the model as a whole, I'm struggling trying to do the same for the individual submeshes. I've figured out how to move the submeshes relative to the world origin (by including a submeshModelMatrix as part of my vertex shader computation), but what I want is to move the submesh(es) relative to their own origin (to for example, rotate the landing gear into the wheel wells, or animate the flaps/ailerons).

I figure I'd have to somehow translate the submesh to the world origin, do my transformations, then translate it back to it's original position relative to the model, but how do I even determine the correct translation to the origin (aka the vector I have to subtract from the submesh vertices in the first step)?

Perhaps I'm loading my model incorrectly, or I'm missing some information in my loading process that would make this easier (like what is the local origin for each submesh) ?

Here's my project: https://github.com/albertinopadin/ToyFlightSimulator

And here is the code that loads models in: https://github.com/albertinopadin/ToyFlightSimulator/blob/main/ToyFlightSimulator%20Shared/Assets/Mesh.swift#L120

Here's the obj model aircraft I'm using: https://downloadfree3d.com/3d-models/aircraft/jet/boeing-fa-18f-super-hornet/

Would appreciate a good breakdown on how this is normally handled, as I'm definitely a noob here. Thanks!

PS. I managed to animate the missiles firing / bombs falling by not rendering the submesh attached to the aircraft, and instead instantiating an entire model node that only renders the missile or bomb as it flies away. I did this as a hack, it seems very wasteful to have to load the entire model only to render a small part of it. I'm hoping to not have to do this for the landing gear / control surfaces.

\$\endgroup\$
2
  • \$\begingroup\$ Have you looked into "skeletal animation"? \$\endgroup\$
    – DMGregory
    Commented Jul 4, 2023 at 1:38
  • \$\begingroup\$ @DMGregory I think that's what I need to do! I looked a bit into it, and it looks like to do this I'd need to import the fbx file into my project - unfortunately it looks like Swift/Metal/ModelIO don't support fbx files and I'd have to convert the fbx file into USDZ (which fails when I tried it with Reality Converter...). I'm thinking maybe I can do a bit of a hack by loading in each model submesh as a node who's parent is the model (or mesh), and then do my transformations that way... but at least in the case of obj files it doesn't look like they have any skeletal info on their own. \$\endgroup\$
    – Tino
    Commented Jul 5, 2023 at 1:10

0

You must log in to answer this question.

Browse other questions tagged .