白季飞龙的个人主页

jMonkey大杂烩

jMonkey开发环境搭建

jMonkey可以直接下载SDK(NetBeans带全部jMonkey的库和一些方便编辑素材的NetBeans插件), 也可以使用其他IDE直接配置

以Gradle+Kotlin+SpringBoot+jMonkey为例:

build.gradle

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }

    dependencies {
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.50'
        classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.0.3.RELEASE'
    }
}

apply plugin: 'application'
apply plugin: 'kotlin'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

mainClassName = 'bj.App'

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib"
    compile 'org.springframework.boot:spring-boot-starter'

    compile 'org.jmonkeyengine:jme3-core:3.1.0-stable'
    compile 'org.jmonkeyengine:jme3-desktop:3.1.0-stable'
    compile 'org.jmonkeyengine:jme3-lwjgl:3.1.0-stable'
}

repositories {
    jcenter()
    mavenCentral()
}

依赖说明:

一个简单的例子(显示一个球体的网格线)

package bj

import com.jme3.app.SimpleApplication
import com.jme3.light.AmbientLight
import com.jme3.material.Material
import com.jme3.math.ColorRGBA
import com.jme3.scene.Geometry
import com.jme3.scene.shape.Sphere
import com.jme3.system.AppSettings
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.context.event.ApplicationReadyEvent
import org.springframework.context.ApplicationListener

/**
 * Created by BaiJiFeiLong@gmail.com at 18-6-27 下午10:08
 */
@SpringBootApplication
open class App : SimpleApplication(), ApplicationListener<ApplicationReadyEvent> {
    override fun simpleInitApp() {
        flyCam.moveSpeed = 10f // 镜头移动速度提高到10倍
        rootNode.addLight(AmbientLight(ColorRGBA.Green)) // 添加环境光源,绿光
        // 添加球体(5条纬线,12条经线,半径1)
        rootNode.attachChild(Geometry("MyBall", Sphere(5, 12, 1f)).apply {
            // 球体设置反光材质
            material = Material(assetManager, "Common/MatDefs/Light/Lighting.j3md").apply {
                // 显示材质线条
                additionalRenderState.isWireframe = true
            }
        })
    }

    override fun onApplicationEvent(event: ApplicationReadyEvent?) {
        showSettings = false // 隐藏jMonkey设置对话框
        settings = AppSettings(true).apply {
            // 设置窗体分辨率
            setResolution(768, 900)
        }
        start() // 启动应用
    }

    companion object {
        @JvmStatic
        fun main(args: Array<String>) {
            System.setProperty("java.awt.headless", "false") // 将headless模式设为false,否则Spring会设为true,导致应用因无法显示jMonkey设置对话框而奔溃
            SpringApplication.run(App::class.java, *args);
        }
    }
}

漫漫路,莫论逍遥;潜心修,只为悟道