在这里我们将向您展示在您的jsr184 midlet中怎样使用3d帖图
这是一个可以获得非常漂亮的效果和意想不到的性能的方法;窍门就是渲染你的3d world到一个image2d对象,并且将这个image2d对象作为帖图。这样一来帖图本身就是一个包含动画的3d场景。
在这个例子中,我们需要创建两个world对象。
第一个是用来渲染一个四棱锥到image2d对象中;第二个用来渲染一个用刚刚建立的image2d对象作为帖图的多边形
渲染四棱锥到image2d
texg3d.bindtarget(scenetexture); // 绑定一个image2d图形对象
texg3d.render(texworld); // 渲染四棱锥到这个image2d
g3d.bindtarget(g); // 绑定graphics 到g3d
g3d.render(world); // 渲染该 world
帖图的长宽必须是2的指数 (2, 4, 8, 16 ? 256).
scenetexture = new image2d(image2d.rgb, 64, 64);
使用这个iamge2d作为帖图并且赋给多边形
现在使用我们刚刚生成的image2d创建一个帖图;并且设置该帖图到平面的 appearance。
texture2d texture1 = new texture2d(scenetexture);
texture1.setblending(texture2d.func_replace);
texture1.setwrapping(texture2d.wrap_clamp, texture2d.wrap_clamp);
texture1.setfiltering(texture2d.filter_nearest, texture2d.filter_nearest);
appearance.settexture(0, texture1);
mesh.setappearance(0, appearance);
这样一来我们就把scenetexture设置在了帖图上了,我们可以通过及时的改变texworld来改变这个帖图,也就是说我们获得了一个动画帖图。
源代码
英文原文
译者心得:
这篇文章介绍了一种非常有意思的特效果,作者很巧妙的通过绑定一个image2d对象到graphics3d上,并且将一个world对象渲染到了该graphics3d上,从而获得了一个及时的动画帖图,这是一个很高明的做法。换一个简单的说法,就是作者在这里渲染了两个world一个渲染到帖图上一个渲染到屏幕,似乎这样解释更容易明白了。
这里既然是介绍帖图的那么,我就来个大家补充一些东西。
对于初学mobile3d的人来说,及时生成模型的过程中有一个设置是比较难理解的
// the texture coordinates is scaled down to 0-1 values in the settextcoords method
short []textures = new short[] {0, 255, 255, 255, 127, 0,
0, 255, 255, 255, 127, 0,
0, 255, 255, 255, 127, 0,
0, 255, 255, 255, 127, 0,
0, 0, 255, 0, 255, 255,
0, 0, 255, 255, 0, 255};
texture_array = new vertexarray(textures.length / 2, 2, 2);
texture_array.set(0, textures.length / 2, textures);
vertexbuffer.settexcoords(0, texture_array, (
vertexbuffer.settexcoords(1, texture_array, (
这里textures其实设置的是每个顶点对应在帖图中的位置,也许有人在这里要问,帖图的尺寸是1为单位的,而这里这个数组只可以设置成short类型的,那么我如何获得帖图中的某个位置呢?在这个例子中就给出解决的方法。在设置顶点对应帖图坐标的时候在这个例子中给出的是大于1的正整数。而在设置多边形的时候vertexbuffer.settexcoords(0, texture_array, (
这里调用两次vertexbuffer.settexcoords(0, texture_array, (
闽公网安备 35060202000074号