`
micheal19840929
  • 浏览: 163099 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

M3G教程:进阶篇(三)纹理

    博客分类:
  • J2ME
 
阅读更多

 

纹理(Texture)

java.lang.Object
  |
  +--javax.microedition.m3g.Object3D
        |
        +--javax.microedition.m3g.Transformable
              |
              +--javax.microedition.m3g.Texture2D

      An Appearance component encapsulating a two-dimensional texture image and a set of attributes specifying how the image is to be applied on submeshes. The attributes include wrapping, filtering, blending, and texture coordinate transformation.

 

Texture image data

      The texture image is stored as a reference to an Image2D. The image may be in any of the formats defined in Image2D. The width and height of the image must be non-negative powers of two, but they need not be equal. The maximum allowed size for a texture image is specific to each implementation, and it can be queried with Graphics3D.getProperties().

      Mipmap level images are generated automatically by repeated filtering of the base level image. No particular method of filtering is mandated, but a 2x2 box filter is recommended. It is not possible for the application to supply the mipmap level images explicitly.

      If the referenced Image2D is modified by the application, or a new Image2D is bound as the texture image, the modifications are immediately reflected in the Texture2D. Be aware, however, that switching to another texture image or updating the pre-existing image may trigger expensive operations, such as mipmap level image generation or (re)allocation of memory. It is therefore recommended that texture images not be updated unnecessarily.

 

Texture mapping

Transformation

      The first step in applying a texture image onto a submesh is to apply the texture transformation to the texture coordinates of each vertex of that submesh. The transformation is defined in the Texture2D object itself, while the texture coordinates are obtained from the VertexBuffer object associated with that submesh.

      The incoming texture coordinates may have either two or three components (see VertexBuffer), but for the purposes of multiplication with a 4x4 matrix they are augmented to have four components. If the third component is not given, it is implicitly set to zero. The fourth component is always assumed to be 1.

      The texture transformation is very similar to the node transformation. They both consist of translation, orientation and scale components, as well as a generic 4x4 matrix component. The order of concatenating the components is the same. The only difference is that the bottom row of the matrix part must be (0 0 0 1) in case of a node transformation but not in case of a texture transformation. The methods to manipulate the individual transformation components of both node and texture transformations are defined in the base class, Transformable.

      Formally, a homogeneous vector p = (s, t, r, 1), representing a point in texture space, is transformed to a point p' = (s', t', r', q') as follows:

      p' = T R S M p
where T, R and S denote the translation, orientation and scale components, respectively, and M is the generic 4x4 matrix.

      The translation, orientation and scale components of the texture transformation can be animated independently from each other. The matrix component is not animatable at all; it can only be changed using the setTransform method.

Projection

      The texture transformation described above yields the transformed texture coordinates (s', t', r', q') for each vertex of a triangle. The final texture coordinates for each rasterized fragment, in turn, are computed in two steps: interpolation and projection.

      1). Interpolation. The per-vertex texture coordinates are interpolated across the triangle to obtain the "un-projected" texture coordinate for each fragment. If the implementation supports perspective correction and the perspective correction flag in PolygonMode is enabled, this interpolation must perform some degree of perspective correction; otherwise, simple linear interpolation may (but does not have to) be used.

      2). Projection. The first three components of the interpolated texture coordinate are divided by the fourth component. Formally, the interpolated texture coordinate p' = (s', t', r', q') is transformed into p'' = (s'', t'', r'', 1) as follows:

p'' = p'/q' = (s'/q', t'/q', r'/q', 1) 
      Again, if perspective correction is either not supported or not enabled, the implementation may do the projection on a per-vertex basis and interpolate the projected values instead of the original values. Otherwise, some degree of perspective correction must be applied. Ideally, the perspective divide would be done for each fragment separately.

      The r'' component of the result may be ignored, because 3D texture images are not supported in this version of the API; only the first two components are required to index a 2D image.

Texel fetch
      The transformed, interpolated and projected s'' and t'' texture coordinates of a fragment are used to fetch texel(s) from the texture image according to the selected wrapping and filtering modes.

      The coordinates s'' and t'' relate to the texture image such that (0, 0) is the upper left corner of the image and (1, 1) is the lower right corner. Thus, s'' increases from left to right and t'' increases from top to bottom. The REPEAT and CLAMP texture wrapping modes define the treatment of coordinate values that are outside of the [0, 1] range.

      Note that the t'' coordinate is reversed with respect to its orientation in OpenGL; however, the texture image orientation is reversed as well. As a net result, there is no difference in actual texture coordinate values between this API and OpenGL in common texturing operations. The only difference arises when rendering to a texture image that is subsequently mapped onto an object. In that case, the t texture coordinates of the object need to be reversed (t' = 1 - t). If this is not done at the modeling stage, it can be done at run-time using the texture transformation. Of course, the whole issue of texture coordinate orientation is only relevant in cases where existing OpenGL code and meshes are ported to this API.

 

Texture filtering

 

      There are two independent components in the texture filtering mode: filtering between mipmap levels and filtering within a mipmap level. There are three choices for level filtering and two choices for image filtering, yielding the six combinations listed in the table below.

 

Level filterImage filterDescriptionOpenGL equivalent
BASE_LEVEL NEAREST Point sampling within the base level NEAREST
BASE_LEVEL LINEAR Bilinear filtering within the base level LINEAR
NEAREST NEAREST Point sampling within the nearest mipmap level NEAREST_MIPMAP_NEAREST
NEAREST LINEAR Bilinear filtering within the nearest mipmap level LINEAR_MIPMAP_NEAREST
LINEAR NEAREST Point sampling within two nearest mipmap levels NEAREST_MIPMAP_LINEAR
LINEAR LINEAR Bilinear filtering within two nearest mipmap levels (trilinear filtering) LINEAR_MIPMAP_LINEAR

Only the first combination (point sampling within the base level) must be supported by all implementations. Any of the other five options may be silently ignored.

 


      M3G限制纹理图片的长和宽都必须是2的次方,长和宽可以不一样。

      在程序运行过程中,不建议修改与Texture2D对象关联的Image2D引用。

      注意:纹理坐标(uv)与顶点坐标系的习惯略有不同,其原点在图片的左下角,左至右为正u方向,底至顶为正v方向。

      完整形式的纹理坐标可以表示为(s,t,r,q),其中(s,t)对应一般三维建模软件中的uv也就是平面纹理图片的(x,y);r在使用三维纹理时使用,因为JSR184不支持三维纹理,所以可能会被忽略,此时会使用默认值0;q为齐次坐标,通常为1。

 

纹理贴图有固定模式WRAP_CLAMP和重复模式WRAP_REPEAT

对于平面四个点的纹理坐标定义如下:

short[] texCoords = new short[]{
        	0,2,			//左下
        	2,2,			//右下
        	2,0,			//右上
        	0,0				//左上
};

 

使用的纹理贴图:

 

对于固定模式WRAP_CLAMP,其效果如下:

texture.setWrapping(Texture2D.WRAP_CLAMP,Texture2D.WRAP_CLAMP);

 

 

若使用重复模式WRAP_REPEAT:

texture.setWrapping(Texture2D.WRAP_REPEAT,Texture2D.WRAP_REPEAT);

 

分享到:
评论

相关推荐

    M3G API Docs

    通过M3G API,开发者可以创建复杂的3D场景,包括光照、纹理、动画以及物理模拟等元素,使得移动应用的视觉体验接近桌面级游戏。 **主要知识点**: 1. **基本概念**:理解M3G API中的关键术语,如节点(Node)、模型...

    M3G Viewer:查看M3G文件内容-开源

    M3G查看器是一个独立的应用程序,用于查看3D图形文件格式的内容,该格式是对移动3D图形API(M3G)的补充。

    M3G 的快速模式编程

    【M3G 快速模式编程】:M3G,全称Mobile 3D Graphics API,是基于JSR 184规范定义的一种为移动设备提供标准3D图形功能的API。它分为快速模式和保留模式。快速模式专注于单个3D对象的渲染,适合进行低级别的3D操作,...

    宝箧印塔模型设计m3g

    本文将深入探讨如何利用Java M3G(Mobile 3D Graphics)技术设计并实现“宝箧印塔”这一具有文化特色的三维模型。Java M3G是JSR 184(Mobile 3D Graphics API)的一部分,旨在为移动设备提供高效、轻量级的三维图形...

    Mobile 3D Graphics with OpenGL ES and M3G

    《Mobile 3D Graphics with OpenGL ES and M3G》是一本深入探讨移动设备上3D图形编程的专业书籍,主要关注于OpenGL ES和M3G这两个技术。OpenGL ES(OpenGL for Embedded Systems)是OpenGL的轻量级版本,专为嵌入式...

    M3M0:M3m0工具:crossed_swords:网站漏洞扫描程序和自动利用程序

    M3M0渗透测试工具 M3m0工具 :crossed_swords: 网站漏洞扫描程序和自动浏览器您可以使用此工具通过在网站中找到漏洞来检查安全性,也可以使用此工具来获取Shell | 污损| cPanels | 资料库 M3M0 :laptop:M3m0工具 :...

    M3GToolkit-0.5.0

    M3G标准支持包括几何、纹理、光照、动画等多种3D图形特性,使得开发者可以在资源有限的移动设备上实现复杂的3D场景。 M3GToolkit-0.5.0的核心功能在于其提供的EXE文件,位于解压后的BIN目录下。用户只需双击这个...

    jsr184+M3G+API.rar

    【标题】"jsr184+M3G+API.rar" 涉及到的主要技术是Java Mobile 3D Graphics API(JSR 184)和M3G(Mobile 3D Graphics)标准,以及相关的API接口。JSR 184是Java Community Process发布的一个规范,目的是为Java ME...

    M3Gtools 3D开发必备

    M3G(Mobile 3D Graphics)是一种专为移动设备设计的三维图形标准,它使得在手机和掌上设备上实现高质量的3D图形成为可能。M3GTools则是针对这一标准开发的一套工具集,对于3D开发者来说,它是不可或缺的助手。 M3...

    一款纯静态的M3U8播放器页面

    源码说明:一个纯静态的M3U8播放器页面,可以直接把M3U8的网址填进去进行播放,超级方便。 部署方法: 可以使用宝塔面板来部署 1,打开宝塔面板,添加一个网站 2,把压缩包上传到站点跟目录,然后解压 3,解压以后...

    联想BIOS_L-IG41M3 V1.1 版本:DMKT05AUS 新圆梦F208

    联想BIOS_L-IG41M3 V1.1 版本:DMKT05AUS 新圆梦F208 原机备份 支持Q9400 支持8G内存 需两条4G双面内存 两个BIOS文件 AFUWIN备份的BIOS BIOS_Backup_TooKit_V2.0备份的BIOS

    m3g 3d jsr184中文文档

    学习JSR 184和M3G API时,建议从基础概念入手,了解3D图形的基本原理,然后逐步深入到各个类和方法的使用。通过创建简单的3D场景,比如旋转的立方体或动态的纹理贴图,来熟悉API的运作方式。随着技能的提升,可以...

    tk_m3gtk_v4_5.zip_m3g_tk_m3g_tk_m3gtk_v4_5

    tk_m3gtk_v4_5.zip tk_m3gtk_v4_5.zip 一款M3G文件查看器,Java J2ME中保留模式中必用。

    m3u8Download:java下载m3u8视频,解密并合并ts java download m3u8 video,decrypt & merge ts slice

    m3u8Dowloadjava下载m3u8视频,解密并合并tsm3u8链接获取方式以及代码分析请参见:准备JDK:1.8开发环境:IntelliJ IDEA用于解密的jar包:bcprov-jdk16-139.jar了解一些m3u8标签作用...M3u8DownloadFactory.getInstance...

    jsr_184_midlet.rar_DEMO_jsr184_jsr184-m3g.jar_m3g

    手机 JAVA JSR184 M3G 游戏 DEMO

    M3U8Loader:M3U8装载机

    M3U8装载机加载m3u8并将段连接到mp4谷歌播放谢谢翻译: 中文: TayLin

    M3-ExerciciNomsCiutat:Exercici Curs IT学院

    M3-ExerciciNomsCiutat:Exercici Curs IT学院

    m3u8:m3u8文件下载器库以及chrome和firefox扩展

    m3u8 m3u8文件下载器库以及chrome和firefox扩展/插件用法下载并保存m3u8文件: var p = new m3u8_processor . DownloadFileAndSaveInputParams (){ m3u8FileUrl = < M3U8> , OutputFileName = @" C:\abc.avi " ,};...

    cortex_m3_development:使用qemu模拟器-易于学习和cortex-m3

    arm-none-eabi-gcc -mcpu = cortex-m3 -mthumb -g -c test.c -o test.o arm-none-eabi-gcc -mcpu = cortex-m3 -mthumb -g -c startup.c- o startup.o arm-none-eabi-ld -g -T standalone.ld startup.o test.o -o ...

    M3u Parser:m3u和m3u8解析器-开源

    使用Java的M3u和m3u8解析器

Global site tag (gtag.js) - Google Analytics