Board index FlightGear Development Aircraft

Releasing of Submodels

Questions and discussion about creating aircraft. Flight dynamics, 3d models, cockpits, systems, animation, textures.

Releasing of Submodels

Postby RobAndrew » Thu Aug 23, 2018 2:11 pm

Hello there everyone,

Recently I've come across quite a few aircraft models that hold Submodels, but have no key to release them. (Tornado, F35, Eurofighter etc.) Now I've looked through the Submodels wiki page and have tried to implement the info. I'm only referring to bombs at the moment to keep it simple. Once that's done I can hopefully move on to missiles and guiding (I'm guessing this requires fox2.nas though, whole different story) and then implementing bombable.
I believe this only requires the editing of various xml files, namely the "Submodels" directory and the aircraft "set.xml" file, so without further ado...
Here is what I've done: this is the Submodel in the Submodel xml. For the F35. I will say that i'm only referring to one pylon at the moment.

Code: Select all
<submodel>
    <name>mk82</name>
    <model>Aircraft/F-35B/Models/Payload/mk82/MK-82-LD.xml</model>
    <trigger>controls/armament/trigger</trigger>
    <speed>10</speed>
    <repeat>false</repeat>
    <delay>0</delay>
    <count>1</count>
    <x-m>2.15</x-m>
    <y-m>-4.27</y-m>
    <z-m>-0.1</z-m>
    <pitch-deg>0</pitch-deg>   
    <pitch-offset> 0.5 </pitch-offset>
    <life>1.0</life>
    <wind>false</wind>
    <weight>250</weight>
    <cd>0.193</cd>
    <eda>0.00136354</eda>
    <collision>true</collision>
    <collision-report>sim/ai/aircraft/collision/bullet</collision-report>
    <impact>true</impact>
    <impact-report>sim/ai/aircraft/impact/bullet</impact-report>
    <submodel-path>Aircraft/F-35B/Models/Effects/submodels.xml</submodel-path>
  </submodel>


And here is the added code bits I've put in to the set xml. File

Code: Select all
<submodels>
         <serviceable type="bool">true</serviceable>
         <path>Aircraft/F-35B/Submodels.xml</path>
         <path>Aircraft/F-35B/Models/Payload/loads.xml</path>
      </submodels>


This, which is inside of the "sim" tags...

Code: Select all
<key n=“1”>
                         <name>u</name>
                         <desc>jettison port pylon stores.</desc> 
 
                         <!—-port inner -—>
                         <binding>
                         <command>property-assign</command>
                         <property>controls/armament/station[1]/jettison-all</property>
                         <value type=“bool”>1</value>
                         </binding> 
                      </key>


...and this, under the "Map keys" section and inside of the "input" "keyboard" tags

None of this seems to be working though. I'm pretty sure there's something wrong with what I'm putting in the set xml. File as now I can't even select the model to fly with!
Can anyone possibly point me in the right direction? I am very new to this and am still learning! Apologies if there is already a discussion for this. I did take a quick look but don't pause to say i'm blind if need be! :mrgreen:

Thank you very much for looking!
RobAndrew
 
Posts: 86
Joined: Thu Jul 12, 2018 4:59 pm
Version: 2017.3.1
OS: Mac OSX 10.11.6

Re: Releasing of Submodels

Postby Thorsten » Thu Aug 23, 2018 2:18 pm

Before you re-invent the wheel, there's several aircraft which are equipped with fully working weapons systems (including guided missiles) - maybe you look for Op Red Flag and see whether there's already what you want?
Thorsten
 
Posts: 10587
Joined: Mon Nov 02, 2009 8:33 am

Re: Releasing of Submodels

Postby RobAndrew » Thu Aug 23, 2018 4:53 pm

That's not a bad idea actually, i'll try and find them now!

Thanks!
RobAndrew
 
Posts: 86
Joined: Thu Jul 12, 2018 4:59 pm
Version: 2017.3.1
OS: Mac OSX 10.11.6

Re: Releasing of Submodels

Postby PINTO » Fri Aug 24, 2018 12:59 am

Check my sig. :)

We are active on discord as well.
Actively developing the MiG-21bis (link to repo) (link to thread)

http://opredflag.com is an active flightgear dogfighting community (using a system that isn’t bombable)
User avatar
PINTO
 
Posts: 935
Joined: Wed Oct 21, 2015 6:28 pm
Callsign: pinto
Version: 2016.3.0
OS: Win10

Re: Releasing of Submodels

Postby PINTO » Fri Aug 24, 2018 1:11 am

This is how I do submodel bombs. Rockets are slightly different.

The TL;DR with submodels:
When it's loaded on the pylon, it is not a submodel, but a model that previously was hidden, but now is not. See: https://github.com/l0k1/MiG-21bis/blob/master/Models/Stores.xml

There is a trigger property that can initiate the submodel.

Taken from https://github.com/l0k1/MiG-21bis/blob/master/Submodels.xml#L214
Code: Select all
   
<submodel>
        <name>FAB-500</name>
        <model>Aircraft/MiG-21bis/Models/Stores/FAB-500/FAB-500-sub.xml</model>
        <trigger>payload/released/FAB-500[1]</trigger>
        <trigger-once>true</trigger-once>
        <speed>0.0</speed>
        <repeat>true</repeat>
        <delay>20</delay>
        <count>-1</count>
        <x-offset>-1.14829</x-offset>
        <y-offset>-6.922572</y-offset>
        <z-offset>-1.1</z-offset>
        <yaw-offset>0.0</yaw-offset>
        <pitch-offset>-3.0</pitch-offset>
        <eda>1.0</eda>
        <weight>520.0</weight>
        <cd>0.3</cd>
        <collision>true</collision>
        <collision-report>sim/ai/aircraft/collision/cannon</collision-report>
        <impact>true</impact>
        <impact-report>sim/ai/aircraft/impact/bomb</impact-report>
        <submodel-path>Aircraft/MiG-21bis/Models/Effects/FAB-500/fab-500-sub.xml</submodel-path>

    </submodel>


So when payload/released/FAB-500[1] gets set to 1, it triggers the submodel, which is the free floating bomb. In addition the code that triggers the submodel also hides the bomb on the wing. Trigger code is here. Be warned that nasal file is a little dense.

Missiles are a whole nother ballgame. The code I'm currently using is the latest and greatest, but this version can also be found on Leto's/Necolatis' F-16. You can read through the readme at the start of that file. This code can also handle dumb bombs and gps-guided bombs, and other unpowered or high drag munitions if you'd rather.

In addition, you'll need radar code that defines a Contacts object, even if you're releasing the missile at nothing. Here's my radar code. Unlike the guided-missiles.nas, this one you'll probably have to do some work implementing.

You'll also have to set up a bunch of parameters for the missile that define guidance modes, navigation modes, thrust, etc etc. This takes a lot of trial and error to get all the parameters right. Here's my parameter list for the R-60. You can scroll up/down for some more missiles.

And then you'll need to write in the trigger logic, the aiming/target selection logic, etc. etc. It's complex, but also very powerful.

Leto's F-16 has some code that helps standardize some of this, which may help you somewhat.
Actively developing the MiG-21bis (link to repo) (link to thread)

http://opredflag.com is an active flightgear dogfighting community (using a system that isn’t bombable)
User avatar
PINTO
 
Posts: 935
Joined: Wed Oct 21, 2015 6:28 pm
Callsign: pinto
Version: 2016.3.0
OS: Win10

Re: Releasing of Submodels

Postby RobAndrew » Fri Aug 24, 2018 8:19 am

:shock: That's A LOT of code! :lol:

Thanks for the heads up!...so if I wanted to implement said nasal code to a different model, I presume I'd need to edit the names, locations, weights etc. inside those nasal commands for it to work with the rest of the coding? (e.g. from FAB500 to GBU16)
RobAndrew
 
Posts: 86
Joined: Thu Jul 12, 2018 4:59 pm
Version: 2017.3.1
OS: Mac OSX 10.11.6

Re: Releasing of Submodels

Postby PINTO » Fri Aug 24, 2018 6:15 pm

Regarding the "names, locations, weights"... if only it were that easy haha. The MiG-21 payloads.nas is fairly specific to the MiG-21.

I have some time, so I'll walk you through some stuff. First part will be payload setup, second part for submodels. I may have missed something, I apologize if I did.

This is assuming JSBSim, I've no idea if YASim works the same. Also, this is how I do this, there are possibly other ways to accomplish this that may be better or worse. Necolatis' method he is using on the F-16 seems easier than this, but there's still nasal and coding. I'm not well versed enough in his method enough to speak to it, but if you'd like to investigate it, his repo is right here. He's also one of the major authors of the guided-missile code, and knows it better than anybody.

All that said, here's how I do it.

To add a new "payload" to the equipment menu:

First, in your jsbsim file, you need to add new pointmasses. For the MiG-21, there are 5 pylons, so we add 5 of these:

Code: Select all
   <pointmass name="station1"><!-- left wing outboard pylon pointmass 0 -->
      <weight unit="LBS"> 0 </weight>
      <location name="POINTMASS" unit="M">
          <x>  1.20 </x>
          <y> -2.73 </y>
          <z> -0.15 </z>
      </location>
   </pointmass>


Weight should be 0, and the name should be unique for each, and the pointmass name="" should be unique for each. MiG-21 code here. If the JSBSim VRP is 0,0,0 (which it should be, IMO), then you can easily find the coordinates for each pylon in blender.

Next, in our set file, we are going to define the pylon, and what munition options it has. You should also include a "none" option.
Code: Select all
   <payload>
      <weight n="0">
         <name>Left wing outboard pylon (#3)</name>
         <selected>none</selected>
         <weight-lb alias="/fdm/jsbsim/inertia/pointmass-weight-lbs[0]"/>
         <opt>
            <name>none</name>
            <lbs>0</lbs>
            <weight-lb>0</weight-lb>
         </opt>
         <opt>
            <name>R-3S</name>
            <lbs>165</lbs>
            <weight-lb>165</weight-lb>
         </opt>
      </weight>
   </payload>


You will need a <weight> for each pylon, and an <opt> for each munition. Here's how I have it set up in the MiG-21bis. At this point, if you select one of these options in the equipment menu, it will add the weight to the airframe (not drag!), however you still wont be able to see it in the external view.

To enable it in the external view, here is how I accomplish this. I have a Stores.xml which is called from my main model xml file

In the stores.xml, for each missile, I have an include, and a conditional that only displays the munition if the munition is selected in the equipment menu. For instance, here's the leftmost Kh-25MP (with a slight modification to make the conditional property clearer here):

Code: Select all
   <model>
      <name>Kh-25MP Left</name>
      <path>Aircraft/MiG-21bis/Models/Stores/KH-25MP/KH-25MP.xml</path>
      <offsets>
         <x-m> 0.23552 </x-m>
         <y-m>-2.10877 </y-m>
         <z-m>-0.25002 </z-m>
         <pitch-deg>0.0</pitch-deg>
      </offsets>
   </model>
   
   <animation>
      <object-name>Kh-25MP Left</object-name>
      <type>select</type>
      <condition>
         <equals>
            <property>/payload/weight[1]/selected</property>
            <value>Kh-25MP</value>
         </equals>
      </condition>
   </animation>


Each missile for each pylon needs one of these.

If you are still with me, awesome! That's part 1. Now, onto how to release as a submodel.

For each bomb/submodel you want to release, you need one submodel entry per pylon.

Code: Select all
    <submodel>
        <name>FAB-100</name>
        <model>Aircraft/MiG-21bis/Models/Stores/FAB-100/FAB-100-sub.xml</model>
        <trigger>payload/released/FAB-100[1]</trigger>
        <trigger-once>true</trigger-once>
        <speed>0.0</speed>
        <repeat>true</repeat>
        <delay>20</delay>
        <count>-1</count>
        <offsets>
            <x-m> 0.20</x-m>
            <y-m>-2.11 </y-m>
            <z-m>-0.25</z-m>
        </offsets>
        <eda>1.0</eda>
        <weight>220.0</weight>
        <cd>0.3</cd>
        <collision>true</collision>
        <collision-report>sim/ai/aircraft/collision/cannon</collision-report>
        <impact>true</impact>
        <impact-report>sim/ai/aircraft/impact/bomb</impact-report>
        <submodel-path>Aircraft/MiG-21bis/Models/Effects/Bomb/Bomb-Submodel.xml</submodel-path>
    </submodel>


This is the actual model that will be floating through the air. <model> points to what model you want to appear, <trigger> should be unique (probably), <submodel-path> is for the explosion at the end, and points to another model/particle system, whatever you want to use for the big boom. If you want to have bomb messages, you'll also need <impact-report> and <collision-report>.

You have two options for the trigger. You can either bind a key to release each pylon (so, for instance, 'h' releases pylon 1, 'j' releases pylon 2, and so on), or you can use nasal to write some trigger propagation code. The MiG-21 uses a knob to select bombs on pylons 1 and 2, 3 and 4, or 1 through 4. Trigger propagation logic is here, and the actual trigger "pulling" is here. Basically what it does is figure out where the knob is, and the other function sets that <trigger> property we set up earlier to 1. Depending on your plane, you'll want to rewrite that as you see fit.

After all that is successful, you should be able to drop bombs. For an explosion message, when the bomb hits the ground, it sets the "/ai/models/model-impact" property. You use a setlistener() on this property, and can read it to see what type of bomb hit. My impact listener code is here, but keep in mind I also use it for guns and rockets. If you're only using bombs, it can be simplified. It's also really important in my humble opinion to include an option to make the messages either display over MP or not.

So, that's submodel bombs. Guided missiles are much more complicated, so if you'd like a "guide" on those, let me know. If you've never done nasal before, I'd recommend trying to get submodel bombs working with the trigger propagation first. TL;DR, guided missiles will include creating a radar or targeting scheme, defining the target, actually targeting the target, defining a bunch of missile properties, selecting the missile/trigger propagation, and a bunch of testing the missile flight characteristics.
Actively developing the MiG-21bis (link to repo) (link to thread)

http://opredflag.com is an active flightgear dogfighting community (using a system that isn’t bombable)
User avatar
PINTO
 
Posts: 935
Joined: Wed Oct 21, 2015 6:28 pm
Callsign: pinto
Version: 2016.3.0
OS: Win10

Re: Releasing of Submodels

Postby RobAndrew » Fri Aug 24, 2018 6:57 pm

WOW! Thank you very much for the lesson! Very informative! Surely I can't be the first person to have brought this sort of thing up! I feel a little bad now as i'm sure this is all online somewhere else, but i just haven't seen it :oops: Surprising that not much of this is in the adding Submodels Wiki. I guess its just a different way of doing it?
Of course it was never going to be as easy as I first thought. I'll give it some time, try and wrap my head around it and give it a go with a capable aircraft. Again, like previously mentioned, i'm trying to keep it REALLY basic for now. Just dropping one bomb off of a pylon is a huge success for me! god knows how i'm going to fit the rest in, but i'm exited to learn about it all!

Again, thank you so much for the help! I'm not sure how many people would be obliged to teach a lesson like this though a computer screen. It can't be easy!

I'll keep you updated with my progress. Hey, maybe I can even contribute to the development of the flight sim one day :D One can only dream :wink:
RobAndrew
 
Posts: 86
Joined: Thu Jul 12, 2018 4:59 pm
Version: 2017.3.1
OS: Mac OSX 10.11.6

Re: Releasing of Submodels

Postby RobAndrew » Fri Aug 24, 2018 8:22 pm

I've finally done it! well, half of it...

Thanks to @PINTO i've managed to do half of the equation, and get the model to disappear from the pylon by using a certain button. Now i've realised that it will probably take a nasal script to animate the object falling (Unless there's another way?) the trouble is, to me nasal seems like a completely different language from another planet in a different galaxy out of a different universe! I'm completely new to it so barely understand it and how it works. Is there anywhere anyone can point me towards for a good manual on nasal scripting? i've briefly looked at the flightier wiki articles.
RobAndrew
 
Posts: 86
Joined: Thu Jul 12, 2018 4:59 pm
Version: 2017.3.1
OS: Mac OSX 10.11.6


Return to Aircraft

Who is online

Users browsing this forum: AhrefsBot [Bot] and 2 guests