- jMonkeyEngine 3.0 Cookbook
- Rickard Edén
- 570字
- 2021-09-03 10:00:46
Using Scene Composer
Here, we'll go through the basics of using Scene Composer in the SDK. Scene Composer is a place where we can preview objects, prepare them for in-game usage, and combine them to form scenes. Further usage includes viewing a model's skeleton and bones setup or playing animations. You can also apply materials, lighting, and set some basic geometry data.
Getting ready
Having some models to play around with will be useful if you want to create an interesting scene. We will use the Jaime model from the test-data library. You can find it in the Jaime folder inside Models and copy it to your project.
How to do it…
Let's start by creating a scene we can use to test our recipes later.
- Right-click on the Scenes folder inside Project Assets, select New, and then select Empty jME3 Scene. The scene will open automatically in the SceneComposer window.
- A scene is just an empty node, and needs to be populated to be useful. To have something to look at, let's add the Jaime model to the scene. Find it in the folder structure, right-click on Jaime.j3o, and select Link in SceneComposer. The SceneComposer window looks as follows:
- Now, most likely, all we can see is a blue, wire-frame box. This is because there are no lights in the scene. At the top-left part of the screen, there is a button with a light bulb on it.
- By clicking on it, we should get PointLight following the camera; it is not part of the scene, however.
Tip
Linking versus adding
Adding means you add an instance of the object itself to the scene. This can then be modified separately to the original object.
Linking means you add a reference to the object in the scene. Apart from making the scene smaller, any modifications to the original object will also affect the objects in the scene.
- Basic camera orientation in the scene includes dragging with the left mouse button to rotate the camera. Dragging with the right mouse button pressed moves the camera sideways, up, and down. The mouse wheel zooms in and out.
- The second icon in the top bar of the SceneComposer window is the Move icon. By clicking on it, you will see three different colored planes by Jaime. These will be highlighted as you move your mouse over them. If you press the left mouse button while they're highlighted, you will move the object in the dimensions of that plane.
- The same rules apply to the next icon, Rotation. Note, though, that scaling is uniform across all the axes.
Tip
If you want to have total control over your transformations, you can use the Properties window to set the exact values for translation, rotation, and scale.
If you'd like to have an in-depth knowledge of the SDK, have a look at the videos on http://hub.jmonkeyengine.org.
How it works...
Scene Composer runs an instance of a jME application and what you see is very much what you will get when watching the scene in the game (minus the camera light). Use it to preview and tweak your assets before bringing them inside your application.
There's more…
Now that we have a scene, what's needed to load it into an application? Just the following lines of code are needed, really:
Spatial scene = assetManager.loadModel("Scenes/TestScene.j3o"); rootNode.attachChild(scene);
Add the preceding code in the simpleInitApp()
method of Main.java
.