最近の更新 (Recent Changes)

2013-10-23
2013-10-20
2013-09-12

最新檔案發佈

AndroidBenchmark (1.1)2011-09-26 14:01
AndroidSample_GoMyWay (1.0)2012-04-04 12:22
KinectJME (0.2)2012-01-16 19:12
lib-jar (2011-09-01)2011-09-01 15:18
locale_ja (1.0)2011-09-16 00:06
mikumikustudio (2011-09-02)2011-09-02 20:05
MMSAssetManagerForAndroid (0.21)2012-09-15 22:50
nativebullet (2011-10-15)2011-10-15 08:21
Samples (0.55)2011-09-03 01:23

Wikiガイド(Guide)

サイドバー (Side Bar)

シーングラフ

このページではシーングラフの基礎について学びます。

動画

http://www.nicovideo.jp/watch/sm21811012

シーングラフとは

シーングラフとは、画面に表示するためのオブジェクトをツリー構造で表した物です。

シーングラフを構成するクラス

Spatial

Spatialはシーングラフに配置するすべてのオブジェクトの親クラスです。

Node

Nodeは子を持つことの出来るオブジェクトです。

Node自体は画面に表示されません。

Geometry

Geometryは実際に画面に表示されるオブジェクトです。

座標系

jMonkeyEingineはOpenGLですので右手座標系を使用しています。

座標系の変換

Spatialはローカルの座標系(位置(location)、回転(rotation)、大きさ(scale))を持っています。

Nodeの座標系を変更すると、Nodeの子として配置されているすべてのSpatialの座標系が影響を受けます。

実際にシーングラフを作ってみる

package com.example.app
import com.jme3.app.SimpleApplication
import com.jme3.math.{FastMath, ColorRGBA, Vector3f}
import com.jme3.scene._
import com.jme3.material.Material
import com.jme3.system.JmeSystem
import projectkyoto.jme3.mmd.{CartoonEdgeProcessor, UpdateControl, PMDNode}
import projectkyoto.mmd.file.VMDFile
import projectkyoto.jme3.mmd.vmd.VMDControl
import com.jme3.light.{PointLight, AmbientLight, DirectionalLight}
import com.jme3.scene.shape.Box

class MainApp extends SimpleApplication {
  var redMat : Material = null
  var blueMat : Material = null
  var greenMat : Material = null
  var yellowMat : Material = null
  def simpleInitApp() {
    val dl = new DirectionalLight
    dl.setDirection(new Vector3f(1,0,-5).normalizeLocal())
    dl.setColor(ColorRGBA.White.mult(0.5f))
    rootNode.addLight(dl)

    val al = new AmbientLight
    al.setColor(ColorRGBA.White.mult(0.5f))
    rootNode.addLight(al)

    initMaterials()
    initScene()


  }
  def initScene() {
    val node1 = new Node()
    rootNode.attachChild(node1)
    val node2 = new Node()
    node2.move(-2f,-1f,0f)
    node1.attachChild(node2)
    val node3 = new Node()
    node3.move(2f,-1f,0f)
    node1.attachChild(node3)

    val redGeom = createBox(redMat)
    node2.attachChild(redGeom)
    val blueGeom = createBox(blueMat)
    blueGeom.move(2f,0f,0f)
    node2.attachChild(blueGeom)

    val greenGeom = createBox(greenMat)
    node3.attachChild(greenGeom)
    val yellowGeom = createBox(yellowMat)
    yellowGeom.move(2f,0f,0f)
    node3.attachChild(yellowGeom)

    node1.addControl(new RotateControl)

  }
  def initMaterials() {
    redMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md")
    redMat.setBoolean("UseMaterialColors", true)
    redMat.setColor("Ambient", ColorRGBA.Red)
    redMat.setColor("Diffuse", ColorRGBA.Red)

    blueMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md")
    blueMat.setBoolean("UseMaterialColors", true)
    blueMat.setColor("Ambient", ColorRGBA.Blue)
    blueMat.setColor("Diffuse", ColorRGBA.Blue)

    greenMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md")
    greenMat.setBoolean("UseMaterialColors", true)
    greenMat.setColor("Ambient", ColorRGBA.Green)
    greenMat.setColor("Diffuse", ColorRGBA.Green)

    yellowMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md")
    yellowMat.setBoolean("UseMaterialColors", true)
    yellowMat.setColor("Ambient", ColorRGBA.Yellow)
    yellowMat.setColor("Diffuse", ColorRGBA.Yellow)

  }

  def createBox(mat : Material) : Spatial = {
    val box = new Box(0.5f,0.5f,0.5f)
    val geom = new Geometry("geom", box)
    geom.setMaterial(mat)
    geom
  }
}

RotateControl

package com.example.app

import com.jme3.scene.control.AbstractControl
import com.jme3.renderer.{ViewPort, RenderManager}
import com.jme3.math.FastMath

/**
 * Created with IntelliJ IDEA.
 * User: kobayasi
 * Date: 13/09/07
 * Time: 10:31
 * To change this template use File | Settings | File Templates.
 */
class RotateControl extends AbstractControl{
  def controlRender(p1: RenderManager, p2: ViewPort) {}

  def controlUpdate(tpf: Float) {
    spatial.rotate(FastMath.PI * tpf, 0f, 0f)
  }
}

インデックスに戻る

tutorial2