( Note: the starter tutorials in this wiki are not always up to date
with the latest development version of jME. You can find up to date
source files for the tutorials here: https://jme.dev.java.net/source/browse/jme/src/jmetest/TutorialGuide/
)
(注解:这份指南在wiki上并不一定是跟最新的jME开发版本一样.你可以在http://code.google.com/p/jmonkeyengine/source/browse/#svn/trunk/src/jmetest/TutorialGuide
找到最新的源码文件)
This program introduces the TriMesh class and how to make your own objects from scratch. We will make a flat rectangle:
这个程序介绍TriMesh类,下面来做一个平面矩形.
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.math.Vector2f;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.TexCoords;
import com.jme.scene.TriMesh;
import com.jme.util.geom.BufferUtils;
/**
* Started Date: Jul 20, 2004<br><br>
*
* Demonstrates making a new TriMesh object from scratch.
*
* @author Jack Lindamood
*/
public class HelloTriMesh extends SimpleGame {
public static void main(String[] args) {
HelloTriMesh app = new HelloTriMesh();
app.setConfigShowMode(ConfigShowMode.AlwaysShow);
app.start();
}
protected void simpleInitGame() {
// TriMesh is what most of what is drawn in jME actually is
TriMesh m=new TriMesh("My Mesh");
// Vertex positions for the mesh
Vector3f[] vertexes={
new Vector3f(0,0,0),
new Vector3f(1,0,0),
new Vector3f(0,1,0),
new Vector3f(1,1,0)
};
// Normal directions for each vertex position
Vector3f[] normals={
new Vector3f(0,0,1),
new Vector3f(0,0,1),
new Vector3f(0,0,1),
new Vector3f(0,0,1)
};
// Color for each vertex position
ColorRGBA[] colors={
new ColorRGBA(1,0,0,1),
new ColorRGBA(1,0,0,1),
new ColorRGBA(0,1,0,1),
new ColorRGBA(0,1,0,1)
};
// Texture Coordinates for each position
Vector2f[] texCoords={
new Vector2f(0,0),
new Vector2f(1,0),
new Vector2f(0,1),
new Vector2f(1,1)
};
// The indexes of Vertex/Normal/Color/TexCoord sets. Every 3 makes a triangle.
int[] indexes={
0,1,2,1,2,3
};
// Feed the information to the TriMesh
m.reconstruct(BufferUtils.createFloatBuffer(vertexes), BufferUtils.createFloatBuffer(normals),
BufferUtils.createFloatBuffer(colors), TexCoords.makeNew(texCoords), BufferUtils.createIntBuffer(indexes));
// Create a bounds
m.setModelBound(new BoundingBox());
m.updateModelBound();
// Attach the mesh to my scene graph
rootNode.attachChild(m);
// Let us see the per vertex colors
lightState.setEnabled(false);
}
}
The first new thing here is:
// TriMesh is what most of what is drawn in jME actually is
TriMesh m=new TriMesh("My Mesh");
WARNING: Do not ever use the constructor new TriMesh(). Always use new
TriMesh(“String name”). The empty constructor is for internal use only
and will not render correctly. The same goes for Node, Box, Sphere, and
anything else that extends com.jme.scene.Spatial;
警告:永远不要使用空的TriMesh构造体.而使用带名称的TriMesh构造体.空构造体尽在内部使用,并且不会被正确的渲染.跟Node,Box,Sphere一样,凡是继承自com.jme.scene.Spatial都使用带名字的构造体.
If you were to look at the class header for the Box and Sphere class we were using, you’d see
你可以看看Box和Sphere的文件头,都是继承自TriMesh的
public class Box extends TriMesh
and
public class Sphere extends TriMesh
TriMesh is the parent class of both Box and Sphere. They are made
from it. You’ll notice that most things actually drawn are from
TriMesh.
TriMesh是Box和Sphere的父类.
// Vertex positions for the mesh
Vector3f[] vertexes={
new Vector3f(0,0,0),
new Vector3f(1,0,0),
new Vector3f(0,1,0),
new Vector3f(1,1,0) };
This creates positions for the corners of the rectangle we’re about to make. Now let’s give each vertex a normal:
设置矩形的一角.
// Normal directions for each vertex position
Vector3f[] normals={
new Vector3f(0,0,1),
new Vector3f(0,0,1),
new Vector3f(0,0,1),
new Vector3f(0,0,1) };
The normal for vertex[0] is normal[0], just like the normal for
vertex[i] is normal[i]. Normals are a very common 3D graphics concept.
For more information on how normals work with triangles, please visit
jME’s math links. Basicly, they point in a direction where the light is
its brightest (but not we don’t use lighting at all in this example).
After normals, each vertex can have a color:
// Color for each vertex position
ColorRGBA[] colors={
new ColorRGBA(1,0,0,1),
new ColorRGBA(1,0,0,1),
new ColorRGBA(0,1,0,1),
new ColorRGBA(0,1,0,1) };
In the last program, we assigned a solid blue color to every vertex
of our box (ColorRGBA.blue which is the equivalent of new
ColorRGBA(0,0,1,1)). In this program, we give the first two vertexes
the color red, and the last two green. You’ll notice the first two
vertex positions are vertexes[0]=(0,0,0) and vertexes[1]=(1,0,0) which
are the lower part of our rectangle and the last two are
vertexes[2]=(0,1,0) and vertexes[3]=(1,1,0) which are the upper parts.
Looking at the picture you can see how the rectangle does a smooth
transition from red to green from bottom to top. Next, we assign
texture coordinates:
// Texture Coordinates for each position
Vector2f[] texCoords={
new Vector2f(0,0),
new Vector2f(1,0),
new Vector2f(0,1),
new Vector2f(1,1) };
If you’ve worked with any 3D graphics before, the concept of texture
coordinates is the same in jME as it is anywhere. Vector2f is just like
a Vector3f, but it has 2 floats (notice the 2f in Vector2f) instead of
3 floats (notice the 3f in Vector3f). These two floats are x, y. I’ll
go into texturing later, but for now I
throw this in just so you can get the pattern of how constructing a
TriMesh works. Finally, I have to make indexes for my TriMesh:
// The indexes of Vertex/Normal/Color/TexCoord sets. Every 3
// makes a triangle.
int[] indexes={
0,1,2,1,2,3
};
TriMesh means Triangle mesh. It is a collection of triangles. Your
indexes array must always be a length of modulus 3 (3,6,9,12,15,etc).
That’s because triangles always have 3 coordinates. Notice this is made
up of two triangles. If I had {0,1,2,1,2,3,2,3,0}, that would be 3
triangles. Lets look at the first set of 0,1,2. This means that my
TriMesh object’s first triangle is drawn by connecting vertexes [0] →
vertexes [1] → vertexes [2]. Vertex [0] has a normal of normals [0], a
color of colors [0], a texture coordinate of texCoords [0]. The next
triangle is drawn from vertexes [1] → vertexes [2] → vertexes [3]. Note
that it would be illegal to have the following:
int[] indexes={
0,1,2,1,2,4
};
This is illegal because there are no vertexes[4]. After making all
our data, we finally feed it into the TriMesh, then attach it after
creating a bounds
// Feed the information to the TriMesh
m.reconstruct(BufferUtils.createFloatBuffer(vertexes),BufferUtils.createFloatBuffer(normals),
BufferUtils.createFloatBuffer(colors),BufferUtils.createFloatBuffer(texCoords),
BufferUtils.createIntBuffer(indexes));
// Create a bounds
m.setModelBound(new BoundingBox());
m.updateModelBound();
// Attach the mesh to my scene graph
rootNode.attachChild(m); // Let us see the per vertex colors
lightState.setEnabled(false);
The last line will make more sense after you’ve completed a few more chapters. For now, just realize
that it turns on the per-vertex colors we need to see the rainbow effect on the box.
Note that I don’t use the texCoords really in this example (They only have meaning when you use a
picture on your object). I could have used the following:
m.reconstruct(BufferUtils.createFloatBuffer(vertexes),BufferUtils.createFloatBuffer(normals),
BufferUtils.createFloatBuffer(colors),null,BufferUtils.createIntBuffer(indexes));
I could even have done the following:
m.reconstruct(BufferUtils.createFloatBuffer(vertexes),null,null,null,BufferUtils.createIntBuffer(indexes));
Then I could have drawn a grey, boring TriMesh. Here is a picture of the scene graph:
相关推荐
标签:ant-jme.jar.zip,ant,jme,jar.zip包下载,依赖包
代码测试环境:JME-2核心板+1T指令周期的STC单片机(51内核 STC12LE5A60S2)+33M晶振 单片机工作电压3.3V 程序默认IO连接方式: 控制线:RS-P3^5; WR-P3^6; RD-P3^7; CS-P1^0; REST-P1^2; 数据线: DB0-DB7依次连接P0^0...
RPG手机游戏开发代码,是一个完整的开发代码
联想LXH- JME2207P(FN)键盘驱动,联想键盘的FN功能键不能用?!you out了!!从现在开始妈妈再也不用担心键盘的功能键不能用的问题了!!很难找的,今天分享了。需要的赶紧来下载吧。
jme-3.0.10 兼容): 版本:1.+ 分支:jme_3.0 JME3-JFX 需要 java 8,但是可以使用 java 7 在纹理上绘制视频。对于 jME SDK,您应该创建一个 java 8 平台,但是 java8 支持非常糟糕(因为它基于 netbeans 7)。 ...
com.jme3.animation com.jme3.app com.jme3.app.state com.jme3.asset com.jme3.asset.pack com.jme3.asset.plugins com.jme3.audio com.jme3.audio.joal ...jme3tools.preview
联想FN功能键 jme2207p键盘驱动支援 XP windows7
TankBattle是一款塔防游戏,用于在JME3中演示AI框架。 使用的技术: 原子迷你 Libgdx嵌入,Libgdx-ai JME3代理 其他贡献库。
jME3 的一般熟悉以及中高级 Java 知识。 迷你简单游戏 项目介绍 Minie 是 JMonkeyEngine 的新物理附加组件: Minie 包括一些教程和一组简单的测试/演示应用程序,但到目前为止还没有示例游戏。 JMonkeyEngine 同样...
角形闪存卡 - 第 1 天
联想键盘 LXB JME 7155P 驱动 功能键有效亲测 有音量调节键 邮件 关机 网页 各种功能键全部有效
游戏开发引擎JME3中文翻译文档,简单点例子分享
本文档是JME 的javadoc 文档 JME是一个高性能的3D图形API,采用LWJGL作为底层支持。它的后续版本将支持JOGL。JME和Java 3D具有类似的场景结构,开发者必须以树状方式组织自己的场景。JME有一套很好的优化机制,这...
基于jmonkeyengine游戏引擎,纯java开发,单机3d小游戏demo
jME版本 :jME_2.0.1_Stable 开发工具:MyEclipse8.5 操作系统:Window7/Vista FlagRush1——通过SimpleGame创建你的第一个应用程序 FlagRush2——从你的应用程序中移除SimpleGame FlagRush3——创建地形 FlagRush...
JME教程.rar
NULL 博文链接:https://hjk685.iteye.com/blog/2181913
NULL 博文链接:https://hjk685.iteye.com/blog/767080
JME程序设计实例教程 JME程序设计实例教程 JME程序设计实例教程
jme-remoterpiui-demo RemoteRPIUIControllerDemo MIDlet 该程序允许从JME Emulator远程控制在Raspberry Pi上运行的RPIUIDemoMIDlet应用程序(jme-rpiui-demo存储库)。 该程序连接到RPIUIDemoMIDlet的服务器套接...