- jMonkeyEngine 3.0 Beginner’s Guide
- Ruth Kusterer
- 316字
- 2021-08-13 17:02:08
Populating the scene
Now you know where you are, and how to position and transform 3D objects. When you start populating the scene, you face the issue of handling possibly hundreds of objects. In order to keep track of all your stuff, the jMonkeyEngine provides you with a special data structure—the scene graph. The scene graph manages all elements in a 3D scene. We call the elements in the 3D scene spatials.
Spatials are attached to one another in a parent-child relationship. When we speak of attaching a spatial, we mean that we add the spatial to the scene. When we speak of detaching a spatial, we remove it from the scene.
One specific parent spatial in every game is the root node of the scene. Every spatial that is attached to this one root node, directly or indirectly, is part of the scene graph.
Tip
JMonkeyEngine speeds up large scenes by ignoring spatials that are out of view or behind the camera. This feature is called culling. To make a spatial disappear temporarily without detaching it from the scene, tell the engine to cull it by setting geom.setCullHint(CullHint.Always);
; similarly, you can use CullHint.Never
to keep a spatial, such as a sky box, always visible. To reset the culling behavior back to its default, set it to CullHint.Inherit
.

Let's have a look at the BasicGame
template. We extend all our games from SimpleApplication
because we want to inherit a certain class field: spatial called rootNode
. This rootNode
object gives us access to the scene graph. You remember the rootNode
from Main.java
when we added the blue cube geom
to the scene?
rootNode.attachChild(geom);
In the examples here, you have now encountered a geometry (the blue cube) and a node, the rootNode
object. Both are derived from com.jme3.scene.Spatial, and both are elements of the scene graph. What is the difference between a geometry and a node?
- Learning ROS for Robotics Programming(Second Edition)
- 密碼學原理與Java實現
- Web交互界面設計與制作(微課版)
- JavaScript前端開發與實例教程(微課視頻版)
- Learning Laravel 4 Application Development
- MySQL數據庫基礎實例教程(微課版)
- Spring Boot企業級項目開發實戰
- Mastering Unity 2D Game Development(Second Edition)
- Learning jQuery(Fourth Edition)
- 移動增值應用開發技術導論
- Maker基地嘉年華:玩轉樂動魔盒學Scratch
- Java Web開發實例大全(基礎卷) (軟件工程師開發大系)
- 軟件測試技術
- Tableau Dashboard Cookbook
- 讓Python遇上Office:從編程入門到自動化辦公實踐