官术网_书友最值得收藏!

Retrieving an attachment node

In many games, the characters can be customized to carry different equipment or clothes. In these situations, jMonkeyEngine's Attachments node is extremely useful. It lets us choose a bone and creates a node for us that will follow that particular bone's movement and rotation, without any further work from our side.

Getting ready

We'll need a rigged model with SkeletonControl. Fortunately, the Jaime model is already rigged and animated. We'll also need something to attach to it. What goes well with monkeys if not bananas?

How to do it…

  1. Open the model in the SceneComposer window by right-clicking on it in Projects and selecting Edit in SceneComposer.
  2. Expand the SkeletonControl class. Located under Root is a Bone called IKhand.R, as shown in the following screenshot:
  3. Right-click on IKhand.R and select Get attachment Node.
  4. We should now see a node called IKhand.R_attachnode created at the top level of the hierarchy. Attach the banana to the node by dragging it into the SceneExplorer window. The banana should now appear in Jaime's hand.

    Tip

    The banana will not fit perfectly in this recipe. To achieve a perfect fit, the best way will be to create an actual bone, just for attachments, in the modeling program of our choice. Since the attached item is attached using the model's center point, we can expect to have to tweak the position of the items as well.

  5. To prove that the banana will actually follow the movement of the model, we can play an animation. Select AnimControl in the SceneExplorer window and look at the Properties window. Choose an animation from the drop-down menu.

How it works...

When we first call getAttachmentsNode on a Bone object, it will create a new node. It will then keep track of it and update its translation, rotation, and scale according to the values of the Bone object. It works as a regular node in most regards, with the difference being that it follows the IKhand.R bone's movements during animations. It is very handy, isn't it?

There's more…

All this is, of course, possible to do using code as well. Just like in the SDK, we use the following SkeletonControl class to achieve this:

mySpatial.getControl(SkeletonControl.class).getAttachmentsNode("my   bone");
主站蜘蛛池模板: 榆中县| 德庆县| 岚皋县| 井研县| 麦盖提县| 南澳县| 如东县| 扎囊县| 安阳县| 屯留县| 合水县| 庐江县| 亚东县| 长治县| 靖西县| 突泉县| 墨竹工卡县| 芒康县| 婺源县| 荃湾区| 丰城市| 江油市| 三都| 鄂托克旗| 桦川县| 陆川县| 溧水县| 昌乐县| 双牌县| 内丘县| 忻州市| 突泉县| 喀喇沁旗| 宜春市| 阳江市| 常宁市| 新安县| 株洲市| 江山市| 栾川县| 大田县|