You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
4.0 KiB
92 lines
4.0 KiB
/*
|
|
* Copyright (c) 2009-2010 jMonkeyEngine
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions are
|
|
* met:
|
|
*
|
|
* * Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
*
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
*
|
|
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
|
* may be used to endorse or promote products derived from this software
|
|
* without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
package jme3test.helloworld;
|
|
|
|
import com.jme3.app.SimpleApplication;
|
|
import com.jme3.font.BitmapText;
|
|
import com.jme3.light.DirectionalLight;
|
|
import com.jme3.material.Material;
|
|
import com.jme3.math.Vector3f;
|
|
import com.jme3.scene.Geometry;
|
|
import com.jme3.scene.Spatial;
|
|
import com.jme3.scene.shape.Box;
|
|
|
|
/** Sample 3 - how to load an OBJ model, and OgreXML model,
|
|
* a material/texture, or text. */
|
|
public class HelloAssets extends SimpleApplication {
|
|
|
|
public static void main(String[] args) {
|
|
HelloAssets app = new HelloAssets();
|
|
app.start();
|
|
}
|
|
|
|
@Override
|
|
public void simpleInitApp() {
|
|
|
|
/** Load a teapot model (OBJ file from test-data) */
|
|
Spatial teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
|
|
Material mat_default = new Material( assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
|
|
teapot.setMaterial(mat_default);
|
|
rootNode.attachChild(teapot);
|
|
|
|
/** Create a wall (Box with material and texture from test-data) */
|
|
Box box = new Box(Vector3f.ZERO, 2.5f,2.5f,1.0f);
|
|
Spatial wall = new Geometry("Box", box );
|
|
Material mat_brick = new Material( assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
|
mat_brick.setTexture("ColorMap", assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg"));
|
|
wall.setMaterial(mat_brick);
|
|
wall.setLocalTranslation(2.0f,-2.5f,0.0f);
|
|
rootNode.attachChild(wall);
|
|
|
|
/** Display a line of text (default font from test-data) */
|
|
guiNode.detachAllChildren();
|
|
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
|
|
BitmapText helloText = new BitmapText(guiFont, false);
|
|
helloText.setSize(guiFont.getCharSet().getRenderedSize());
|
|
helloText.setText("Hello World");
|
|
helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);
|
|
guiNode.attachChild(helloText);
|
|
|
|
/** Load a Ninja model (OgreXML + material + texture from test_data) */
|
|
Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
|
|
ninja.scale(0.05f, 0.05f, 0.05f);
|
|
ninja.rotate(0.0f, -3.0f, 0.0f);
|
|
ninja.setLocalTranslation(0.0f, -5.0f, -2.0f);
|
|
rootNode.attachChild(ninja);
|
|
/** You must add a light to make the model visible */
|
|
DirectionalLight sun = new DirectionalLight();
|
|
sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
|
|
rootNode.addLight(sun);
|
|
|
|
}
|
|
}
|
|
|