QML/3D Demo - Behold the Monkey God
-
0:01 - 0:03Welcome to the first what we hope will be
-
0:03 - 0:05a number of tutorials about QML/3d
-
0:05 - 0:07It's important to remember
-
0:07 - 0:09that QML/3d is still under development
-
0:09 - 0:10so what you see in this tutorial
-
0:10 - 0:14may have changed considerably by the time QML/3d is officially released
-
0:14 - 0:16That being said however
-
0:16 - 0:18this tutorial should give you some idea
-
0:18 - 0:20of the capabilities of QML/3d as they currently stand
-
0:20 - 0:22and give you a grounding in QML/3d development
-
0:22 - 0:25as newer versions become available
-
0:25 - 0:27So now i've done the boring introduction part
-
0:27 - 0:30let's actually get down to writing some QML code
-
0:30 - 0:31If you've already dabbled in QML
-
0:31 - 0:34a lot of what I'm doing will be familiar to you
-
0:34 - 0:36QML/3d files also import headers
-
0:36 - 0:39for example the Qt 4.7 import
-
0:39 - 0:43but in addition to that we add the labs.threed 1.0
-
0:43 - 0:46this contains all the 3d information we'll need
-
0:46 - 0:47Now if you're watching this tutorial
-
0:47 - 0:51I'm sure you're fairly familiar with 3d applications as it stands
-
0:51 - 0:52however for the newcomers
-
0:52 - 0:55a 3d application basically needs 3 things
-
0:55 - 0:57first up we need somewhere to actually draw stuff
-
0:57 - 1:00in QML/3d this specified as a viewport
-
1:00 - 1:02a viewport can be the actual window itself
-
1:02 - 1:07or it can be an area of the window in which we are drawing 3d content
-
1:07 - 1:09Secondly we need a camera position
-
1:09 - 1:12The camera position specifies
-
1:12 - 1:14what angle we're looking at the world from
-
1:14 - 1:17where we're actually looking in 3d space
-
1:17 - 1:20In QML/3d we have an actual camera object
-
1:20 - 1:22here I'm setting the camera's eye position
-
1:22 - 1:25this will give me a view from slightly above
-
1:25 - 1:29The final thing we need for a 3d scene is and actual 3d object
-
1:29 - 1:33and I'll also assign the mesh property of the item3d
-
1:33 - 1:36Mesh object is an actual thing which supports a variety of file formats
-
1:36 - 1:42.3ds files, .obj files and bezier patches
-
1:42 - 1:45It's a monkey. It's flat shaded
-
1:45 - 1:47but not very exciting
-
1:47 - 1:50though you can see that I can already manipulate it in 3d space
-
1:50 - 1:52which is quite useful
-
1:52 - 1:53So let's do a little bit more
-
1:53 - 1:58So here I am setting the ForceSmooth parameter
-
1:58 - 2:02and I'm also going to assign a few more variables to this
-
2:02 - 2:04we'll set a different scale
-
2:04 - 2:08and give the monkey a particular position
-
2:08 - 2:10as you can see here
-
2:10 - 2:13I'll also move the camera slightly
-
2:13 - 2:16and most intersetingly, we'll apply an effect
-
2:16 - 2:21in this case the effect object I'm going to specify is the material for the mokey
-
2:21 - 2:23Actually create a material object
-
2:24 - 2:27and assign some properties for that object
-
2:27 - 2:29in this case
-
2:30 - 2:34the ambient colours
-
2:34 - 2:35and the specular colours for the object
-
2:35 - 2:42So, we'll just specify that in the standard kind of format
-
2:43 - 2:47and I'll also assign the shinyness of this particular material to 200
-
2:47 - 2:50that's a value between 0 and 255
-
2:50 - 2:52so this is quite a shiny object
-
2:52 - 2:54let's see what that looks like
-
2:54 - 2:56That's much cooler
-
2:56 - 2:57It's a shiny monkey idol!
-
2:57 - 3:02The kind of thing that Indiana Jones would love to have on his mantlepiece
-
3:02 - 3:03so having added one object
-
3:03 - 3:06let's add another just for fun
-
3:06 - 3:07we'll have to assign an ID
-
3:07 - 3:08this time: penguin
-
3:08 - 3:12and once again set the mesh property to mesh object
-
3:12 - 3:16this time a file called penguin.3ds
-
3:16 - 3:18No prizes for guessing what that is
-
3:18 - 3:23Oh my God! A monkey has vomitted out a giant penguin!
-
3:23 - 3:26This is part of the problem with using 3rd party models
-
3:26 - 3:27very often they're too large
-
3:27 - 3:29on the wrong axis
-
3:29 - 3:30off centre
-
3:30 - 3:32any number of problems
-
3:32 - 3:35and what we have to do is actually correct those at the code level
-
3:35 - 3:37Now this is a problem that is being worked on in QML/3d
-
3:37 - 3:41but for the moment I can demonstrate a simple solution
-
3:41 - 3:42by rescaling it
-
3:42 - 3:45and applying a transform
-
3:50 - 3:53and we apply a rotation 3d
-
3:54 - 3:57we give it angle
-
3:58 - 4:03and we apply it to a particular axis
-
4:05 - 4:07again we do the same thing
-
4:07 - 4:11this time a different axis
-
4:12 - 4:15and now the penguin should be in the correct position
-
4:19 - 4:20Low and behold
-
4:20 - 4:24our tiny penguin is now worshiping a golden monkey idol
-
4:24 - 4:28quite inspired really
-
4:32 - 4:35let's make it a bit more exciting
-
4:35 - 4:39QML/3d uses exactly the same kind of animations animations as QML
-
4:39 - 4:42so here I'm setting a sequential animaiton
-
4:42 - 4:43setting it to be running
-
4:43 - 4:45and it's a number animation
-
4:45 - 4:49and what we're going to be animating with this particular one
-
4:49 - 4:52is the penguin tilt
-
4:52 - 4:57which as you saw from earlier is a rotation 3d
-
4:58 - 5:01so we'll set it to go to -45 degrees
-
5:01 - 5:02that's an easing curve there
-
5:02 - 5:07it just tells you how fast the animation accelerates and decelerates
-
5:07 - 5:12gives you an idea of what it's going look loke when it actually animates
-
5:12 - 5:13and we'll apply another animation
-
5:13 - 5:16this time directly onto a property of the item itself
-
5:16 - 5:22it's on the Y property there - of the parent item
-
5:23 - 5:27and again a number animation
-
5:30 - 5:32slightly shorter this time
-
5:32 - 5:35and the same easing curve
-
5:36 - 5:40It's a dancing penguin
-
5:41 - 5:44So now our little penguin worshiper is jumping up and down and dancing
-
5:44 - 5:47what he really needs though is some friends
-
5:47 - 5:48if I wanted to do that normally
-
5:48 - 5:52I'd have to cut and paste this entire section time and time and time again
-
5:52 - 5:54which can get tiresome
-
5:54 - 5:56so what we can do instead is create a new file
-
5:56 - 5:58grab the imports there
-
5:58 - 6:00take that entire Item3d
-
6:00 - 6:02drop it in there like so
-
6:02 - 6:04and call it "Penguin.qml"
-
6:04 - 6:06now it needs to start with a capital P
-
6:06 - 6:09because it's going to be invoked as a separate object of its own
-
6:09 - 6:11there we go - I'm invoking it
-
6:11 - 6:13and we get the same effect
-
6:13 - 6:18but now we no longer need to have that entire big chunk of text in our main file
-
6:18 - 6:19one of the advantages of that
-
6:19 - 6:21is that we can quickly and easily
-
6:21 - 6:23put multiple penguins in
-
6:23 - 6:28each of them can be manipulated as if it were its own item
-
6:29 - 6:32so I'll throw four penguins in
-
6:32 - 6:34give them slightly separate positions
-
6:34 - 6:37offset from each other
-
6:39 - 6:40and behold
-
6:40 - 6:42a mighty tribe of penguins
-
6:42 - 6:44well, four ...
-
6:44 - 6:48one of the other things we can do with QML/3d
-
6:48 - 6:49which is very similar to QML
-
6:49 - 6:53is use the inheritance property on animations
-
6:53 - 6:55which is basically part of the entire structure
-
6:55 - 6:56of the QML language
-
6:56 - 7:01here we're encasing all the penguins in an Item3d
-
7:01 - 7:04and anything we do to that Item3d in terms of transformations
-
7:04 - 7:06or animations
-
7:06 - 7:09will automatically be applied to those child items
-
7:09 - 7:12in this case our family of penguins
-
7:12 - 7:15so here I'll apply a transformation
-
7:15 - 7:21rotating them slightly around the axis there
-
7:21 - 7:26so now you can see the slight offset from the centre
-
7:26 - 7:27and added to that
-
7:27 - 7:29we'll add an animation
-
7:29 - 7:31I've only been using the SequentialNumber animations here
-
7:31 - 7:34but the full range of QML animations are available
-
7:34 - 7:37and I could animate such properties as colour and so on
-
7:37 - 7:41in this case we're going to be animating the transformation we just made
-
7:41 - 7:44around the vertical axis
-
7:44 - 7:46so the penguins, all being well
-
7:46 - 7:48will move backwards and forwards in sync
-
7:48 - 7:50while they jump up and down
-
7:50 - 7:55and bow to their mighty monkey God
-
7:57 - 7:59Behold the mightyMonkey God!
-
7:59 - 8:02as his followers dance in obescence to his glory
-
8:02 - 8:08it kind of makes me wish I was a disembodied monkey head really
-
8:08 - 8:10here's the thing
-
8:10 - 8:12I have to make a bit of a confession
-
8:12 - 8:15to make things more interesting I've slipped in a couple of extra items here
-
8:15 - 8:19just enough to make things just that touch cooler
-
8:19 - 8:20check it out
-
8:20 - 8:23monkeys dancing on a pedistal
-
8:23 - 8:26okay, in my life it doesn't get much better than that
-
8:26 - 8:31but, I think we can still go one better
-
8:31 - 8:33we can give it a background image
-
8:33 - 8:37now this is a classic example of integrating standard QML
-
8:37 - 8:39with QML/3d
-
8:39 - 8:43in this case using QML StandardImage
-
8:48 - 8:52and I'm also going to throw some lights on the penguins there
-
8:52 - 8:55just to make it a bit more exciting
-
8:55 - 8:58let's check that out
- Title:
- QML/3D Demo - Behold the Monkey God
- Description:
-
A QML/3D demo/tutorial.
QML/3D combines Qt's QML with Qt/3D to provide developers and designers with a way of creating content rich 3d applications quickly and easily.
QML/3D is still under active development, so expect major changes over coming months.
- Video Language:
- English
- Duration:
- 09:35
sam.bristow edited English subtitles for QML/3D Demo - Behold the Monkey God | ||
sam.bristow edited English subtitles for QML/3D Demo - Behold the Monkey God |