当前位置: 编程技术>移动开发
本页文章导读:
▪M3G课程:进阶篇(四)模型 M3G教程:进阶篇(四)模型
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.m3g.Camera;
import javax.microedition.m3g.Graphics3D;
import javax.microedition.m3g.Light;
imp.........
▪ wtk下可以播放, 真机下为啥就放不出来呢 wtk上可以播放, 真机上为啥就放不出来呢?
很简单的一个j2me播放程序 , 装到手机上就是放不出来, 为什么呢?
......
▪ 3DS MAX导出M3G卡通片 3DS MAX导出M3G动画
1、用3D Studio Max或者Maya的插件h3texporter导出的文件格式是.h3t的文件。.h3t的文件是一个文本文件,可以用记事本,写字板或者其他的文本编辑工具打开。.h3t文件描述了所创建.........
[1]M3G课程:进阶篇(四)模型
来源: 互联网 发布时间: 2014-02-18
M3G教程:进阶篇(四)模型
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.m3g.Camera;
import javax.microedition.m3g.Graphics3D;
import javax.microedition.m3g.Light;
import javax.microedition.m3g.Loader;
import javax.microedition.m3g.Object3D;
import javax.microedition.m3g.Transform;
import javax.microedition.m3g.World;
public class M3GCanvas extends GameCanvas implements Runnable {
public static final int FPS = 50; //每秒绘制的帧数
// Thread-control
boolean running = false;
boolean done = true;
// If the game should end
public static boolean gameOver = false;
// Rendering hints
public static final int STRONG_RENDERING_HINTS = Graphics3D.ANTIALIAS
| Graphics3D.TRUE_COLOR | Graphics3D.DITHER;
public static final int WEAK_RENDERING_HINTS = 0;
public static int RENDERING_HINTS = STRONG_RENDERING_HINTS;
// Key array
boolean[] key = new boolean[5];
// Key constants
public static final int FIRE = 0;
public static final int UP = 1;
public static final int DOWN = 2;
public static final int LEFT = 3;
public static final int RIGHT = 4;
// Global identity matrix
Transform identity = new Transform();
// Camera rotation
float camRot = 0.0f;
double camSine = 0.0f;
double camCosine = 0.0f;
// Head bobbing
float headDeg = 0.0f;
private Graphics3D g3d;
private World world;
private boolean runnable=true;
private Thread thread;
private Camera camera;
protected M3GCanvas() {
super(false);
setFullScreenMode(true);
g3d = Graphics3D.getInstance();
//Load our world
loadWorld();
// Load our camera
loadCamera();
}
/** Loads our camera */
private void loadCamera() {
// BAD!
if (world == null)
return;
// Get the active camera from the world
camera = world.getActiveCamera();
// Create a light
Light l = new Light();
// Make sure it's AMBIENT
l.setMode(Light.AMBIENT);
// We want a little higher intensity
l.setIntensity(3.0f);
// Add it to our world
world.addChild(l);
}
/** Loads our world */
private void loadWorld() {
try {
// Loading the world is very simple. Note that I like to use a
// res-folder that I keep all files in. If you normally just put
// your
// resources in the project root, then load it from the root.
Object3D[] buffer = Loader.load("/map.m3g");
// Find the world node, best to do it the "safe" way
for (int i = 0; i < buffer.length; i++) {
if (buffer[i] instanceof World) {
world = (World) buffer[i];
break;
}
}
// Clean objects
buffer = null;
} catch (Exception e) {
// ERROR!
System.out.println("Loading error!");
reportException(e);
}
}
private void moveCamera() {
// Check controls
if (key[LEFT]) {
camRot += 5.0f;
} else if (key[RIGHT]) {
camRot -= 5.0f;
}
// Set the orientation
camera.setOrientation(camRot, 0.0f, 1.0f, 0.0f);
// Calculate trigonometry for camera movement
double rads = Math.toRadians(camRot);
camSine = Math.sin(rads);
camCosine = Math.cos(rads);
if (key[UP]) {
// Move forward
camera.translate(-2.0f * (float) camSine, 0.0f, -2.0f
* (float) camCosine);
// Bob head
headDeg += 0.5f;
// A simple way to "bob" the camera as the user moves
camera.translate(0.0f, (float) Math.sin(headDeg) / 3.0f, 0.0f);
} else if (key[DOWN]) {
// Move backward
camera.translate(2.0f * (float) camSine, 0.0f,
2.0f * (float) camCosine);
// Bob head
headDeg -= 0.5f;
// A simple way to "bob" the camera as the user moves
camera.translate(0.0f, (float) Math.sin(headDeg) / 3.0f, 0.0f);
}
// If the user presses the FIRE key, let's quit
if (key[FIRE])
System.out.println("Fire");
}
private void reportException(Exception e) {
System.out.println(e.getMessage());
System.out.println(e);
e.printStackTrace();
}
protected void process() {
int keys = getKeyStates();
if ((keys & GameCanvas.FIRE_PRESSED) != 0)
key[FIRE] = true;
else
key[FIRE] = false;
if ((keys & GameCanvas.UP_PRESSED) != 0)
key[UP] = true;
else
key[UP] = false;
if ((keys & GameCanvas.DOWN_PRESSED) != 0)
key[DOWN] = true;
else
key[DOWN] = false;
if ((keys & GameCanvas.LEFT_PRESSED) != 0)
key[LEFT] = true;
else
key[LEFT] = false;
if ((keys & GameCanvas.RIGHT_PRESSED) != 0)
key[RIGHT] = true;
else
key[RIGHT] = false;
}
public void run() {
Graphics g = getGraphics();
while (runnable) {
long startTime = System.currentTimeMillis();
//Call the process method (computes keys)
process();
//Move the camera around
moveCamera();
try {
//First bind the graphics object. We use our pre-defined rendering
// hints.
g3d.bindTarget(g, true, RENDERING_HINTS);
//Now, just render the world. Simple as pie!
g3d.render(world);
} finally {
g3d.releaseTarget();
}
flushGraphics();
long endTime = System.currentTimeMillis();
long costTime = endTime - startTime;
if(costTime<1000/FPS)
{
try{
Thread.sleep(1000/FPS-costTime);
}
catch(Exception e){
e.printStackTrace();
}
}
}
System.out.println("Canvas stopped");
}
public void start()
{
thread=new Thread(this);
thread.start();
}
public void stop()
{
this.runnable=false;
try {
thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
效果如下:
[2] wtk下可以播放, 真机下为啥就放不出来呢
来源: 互联网 发布时间: 2014-02-18
wtk上可以播放, 真机上为啥就放不出来呢?
很简单的一个j2me播放程序 , 装到手机上就是放不出来, 为什么呢?
很简单的一个j2me播放程序 , 装到手机上就是放不出来, 为什么呢?
[3] 3DS MAX导出M3G卡通片
来源: 互联网 发布时间: 2014-02-18
3DS MAX导出M3G动画
1、用3D Studio Max或者Maya的插件h3texporter导出的文件格式是.h3t的文件。.h3t的文件是一个文本文件,可以用记事本,写字板或者其他的文本编辑工具打开。.h3t文件描述了所创建的模型的所有信息(例如顶点信息,面的信息,骨骼动画的信息,关键帧的信息等)。
2、将.h3t文件用转换工具M3G Converter转换成为.m3g文件从而用JSR184API识别和导入。
相关下载:
这个插件是由日本的HI公司所开发的,具体的插件可以在下面的link下载:http://www.mascotcapsule.com/toolkit/m3g/en/index.html。这个链接页面上有上面提到的插件跟工具下载链接。
注意事项:
1、导出h3t文件切记贴图文件也在导出路径下,否则会出现M3G模块没有贴图的情况。
2、物体的材质必须选择“H3T Material”,如下:
3、对于面的贴图出现纹理坐标不对的情况,可以在3ds max中加个修改器“UVW贴图”,将参数“贴图”改为“面”就可以了(或者使用“平面项”,并调整其长度跟宽度跟你的平面对应)
4、如果导出的h3t文件和m3g文件都能在M3G Viewer中播放,而导入J2ME项目时出现异常:
java.io.IOException: no ':' in URL
at javax.microedition.m3g.Loader.loadHelper(+375)
......
请检查我是否把纹理图像也拷进项目里,而且不能使用TGA格式,目前我只发现PNG格式是支持的,不知还支持哪些格式。
以下是我从魔兽的模型文件中转换过来的样图:
最新技术文章: