Using the FBXLoader Class

8 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€60.73
List Price:  €86.76
You save:  €26.03
£52.26
List Price:  £74.67
You save:  £22.40
CA$96.65
List Price:  CA$138.09
You save:  CA$41.43
A$108.94
List Price:  A$155.63
You save:  A$46.69
S$91.27
List Price:  S$130.40
You save:  S$39.12
HK$543.17
List Price:  HK$775.99
You save:  HK$232.82
CHF 56.49
List Price:  CHF 80.70
You save:  CHF 24.21
NOK kr728.92
List Price:  NOK kr1,041.35
You save:  NOK kr312.43
DKK kr453.48
List Price:  DKK kr647.86
You save:  DKK kr194.37
NZ$116.49
List Price:  NZ$166.43
You save:  NZ$49.93
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.19
৳8,499.86
List Price:  ৳12,143.18
You save:  ৳3,643.32
₹5,958.92
List Price:  ₹8,513.11
You save:  ₹2,554.18
RM305.85
List Price:  RM436.95
You save:  RM131.10
₦112,301.75
List Price:  ₦160,437.95
You save:  ₦48,136.20
₨19,699.56
List Price:  ₨28,143.44
You save:  ₨8,443.87
฿2,315.75
List Price:  ฿3,308.36
You save:  ฿992.61
₺2,673.74
List Price:  ₺3,819.79
You save:  ₺1,146.05
B$415.18
List Price:  B$593.14
You save:  B$177.96
R1,307.79
List Price:  R1,868.36
You save:  R560.56
Лв120.48
List Price:  Лв172.12
You save:  Лв51.64
₩99,329.46
List Price:  ₩141,905.31
You save:  ₩42,575.85
₪258.20
List Price:  ₪368.88
You save:  ₪110.67
₱3,959.29
List Price:  ₱5,656.38
You save:  ₱1,697.08
¥9,867.68
List Price:  ¥14,097.29
You save:  ¥4,229.61
MX$1,375.77
List Price:  MX$1,965.48
You save:  MX$589.70
QR254.99
List Price:  QR364.29
You save:  QR109.29
P964.11
List Price:  P1,377.36
You save:  P413.25
KSh9,072.69
List Price:  KSh12,961.55
You save:  KSh3,888.85
E£3,531.11
List Price:  E£5,044.66
You save:  E£1,513.55
ብር9,325.92
List Price:  ብር13,323.32
You save:  ብር3,997.39
Kz63,830.88
List Price:  Kz91,190.88
You save:  Kz27,360
CLP$67,726.52
List Price:  CLP$96,756.32
You save:  CLP$29,029.80
CN¥509.94
List Price:  CN¥728.52
You save:  CN¥218.58
RD$4,218.99
List Price:  RD$6,027.39
You save:  RD$1,808.40
DA9,284.08
List Price:  DA13,263.54
You save:  DA3,979.46
FJ$159.98
List Price:  FJ$228.55
You save:  FJ$68.57
Q539.02
List Price:  Q770.07
You save:  Q231.04
GY$14,659.61
List Price:  GY$20,943.20
You save:  GY$6,283.59
ISK kr8,813.14
List Price:  ISK kr12,590.74
You save:  ISK kr3,777.60
DH646.94
List Price:  DH924.24
You save:  DH277.30
L1,210.80
List Price:  L1,729.79
You save:  L518.98
ден3,755.86
List Price:  ден5,365.75
You save:  ден1,609.88
MOP$559.47
List Price:  MOP$799.27
You save:  MOP$239.80
N$1,307.97
List Price:  N$1,868.61
You save:  N$560.64
C$2,573.90
List Price:  C$3,677.16
You save:  C$1,103.25
रु9,537.71
List Price:  रु13,625.88
You save:  रु4,088.17
S/261.88
List Price:  S/374.14
You save:  S/112.25
K289.26
List Price:  K413.25
You save:  K123.99
SAR262.61
List Price:  SAR375.18
You save:  SAR112.56
ZK1,995.15
List Price:  ZK2,850.34
You save:  ZK855.18
L302.11
List Price:  L431.61
You save:  L129.49
Kč1,521.65
List Price:  Kč2,173.88
You save:  Kč652.23
Ft24,736.02
List Price:  Ft35,338.69
You save:  Ft10,602.66
SEK kr665.84
List Price:  SEK kr951.25
You save:  SEK kr285.40
ARS$78,594.19
List Price:  ARS$112,282.22
You save:  ARS$33,688.03
Bs484.19
List Price:  Bs691.72
You save:  Bs207.53
COP$297,190.71
List Price:  COP$424,576.35
You save:  COP$127,385.64
₡35,158.13
List Price:  ₡50,228.06
You save:  ₡15,069.92
L1,810.73
List Price:  L2,586.88
You save:  L776.14
₲559,780.71
List Price:  ₲799,721.01
You save:  ₲239,940.30
$U2,963.96
List Price:  $U4,234.41
You save:  $U1,270.45
zł259.77
List Price:  zł371.12
You save:  zł111.34
Already have an account? Log In

Transcript

If you go to three gs.org and look at the examples, let's just type in FX to filter it. And we choose SPX, loader SPX, then we get a dancing guy, no like a robot. Very, very, very simple to use. And if we have a quick look at the source, you can see that it's linking to a variety of source files, including FB x loader dot j s. In the init function, which is called we create a camera control scene light, familiar stuff if you've been following the course from the beginning. And, and then we create a loader new three dot SPX loader and we call the load method that takes a path to the FX file that you load in. And it takes a callback function which is called when the loading is complete.

In this we get the object and we define a mixer, which is a new three animation mixer. Passing the object in as a single parameter. And mixes is a global variable for this. Define here is an array and we push our new mixer into that array. And then we find the first animation and we use the clip action methods Have the mixer. And we save that in a variable that we called action.

And then we play the animation we started playing immediately. This just iterates over all the children and children have children inside the object itself. And if it finds a mesh, then it defines cast shadow and receive shadow to true. So shadows are working for that particular mesh. And then obviously, to see this, we need to add it to our scene. There's one last thing that you need to do when you're using animations.

And that's in your animate method. You need to go through all the mixes in turn. This is kind of old fashioned code rather than using for each and Update the that particular mixer based on how much time is elapsed, since we last call the animate function. And then of course, we can render it. And the result of that is, is just that. So very, very simple class to use.

But lots and lots of functionality going on there. terrific, terrific beta code. Let's have a look at how we use it in our game. If you look in the libs folder, which is above our game, you'll see that FX loader is one of the libraries in there. And you can see that it's been created by Kyle Larson and you can see some limitations of it. pretty small limitations but is that there?

There is another limitation, which is that any euler angles have to be defined in x y Zed order. So if you find that your 3d application program does the honor angles in a different order, then you're gonna have to probably bring it into blender or something like that to convert it into an ability to be able to use it because there has to be an x y Zed order. So let's have a look at the one folder for our game. Look at game dot j s. Online one to eight. That's where we create our loader. And the first thing we're going to do is loading the girl walk at the x, which is actually the geometry of the girl and animation walk We again assign an animation mixer and save that as a property of the objects.

Then we save the the mixer in the player object which we defined in the game that saves all the various information about our player. We also get the root, which is the root bone, called a for the mixer. And we just give our objects a name. So we can find it when we're doing some debugging. We do the Traverse, like we've seen previously, we add it to the scene. And then we make sure we've got a reference to our object in our player.

And then our play a walk which is going to be animation zero. We're also going to load in lots more FTP access, and that's what this load next on in does. Pass it in. In the load that we've already created, before we look at that, recall that we created a property of this class, which is this elements, which is a series of names of animations. So now we go to load next on him, it pops off the next item in the array. So that makes the array one, one item smaller.

And we create a reference to this called game. Remember inside this function here, this will refer to the loader and not to the game, so it's a way of referencing game. And then we create a full path. That's the assets path. SPX forward slash, the name name dot SPX. So that's the full path to our SPX file, which is stored in the assets folder.

You'll see them the mole there, there's, there's quite a few that we're not using that. And then in our game player objects, we save the first animation of this particular objects as a property. If our n ns array is not yet of length zero, then we load in the next animation. But if it is of length zero, then we can delete it. We don't need any more. We set our action to look around.

And we say that the game is ready and active and ready, ready for user to play. So that's what we're doing. And that ensures that once all these have loaded, she's doing the action. Look around. Okay, so that's the SPX loader class. We're getting there.

In the next video we're going to look at how this motion, okay is using this joystick

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.