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

一点对m3g模型文件解析的工作

    博客分类:
  • J2ME
阅读更多

因为最近不会在m3g文件上继续工作,把之前一点少少的工作放出来,希望可以有点帮助

/*
 * Main.java
 *
 * Created on 2005年5月15日, 下午11:41
 */
package m3gloader;
import java.io.*;
import java.util.zip.*;
/**
 *
 * @author admin
 */
public class Main {
    
    /** Creates a new instance of Main */
    public Main() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {
        File f=new File("otokka_jump2.m3g");
        System.out.println("\nFile \""+f.toString()+"\" exists? : "+f.exists());
        if(!f.exists())
            err("File "+f.toString()+" does not exists!");
        FileInputStream fis=new FileInputStream(f);
        M3GDataInputStream dis=new M3GDataInputStream(fis);
        System.out.println("====== File identifier ======");
        byte[] fileIdentifier=new byte[12];
        if(dis.available()>=12){
            dis.read(fileIdentifier);
            System.out.println("File Identifier is: ");
            for(int l=0;l<fileIdentifier.length;l++)
                System.out.print(fileIdentifier[l]+" ");
            System.out.print("\nFile Identifier characters is: \n");
            System.out.println(new String(fileIdentifier));
            System.out.println("====== end of file identifier ======\n");
        } else
            err("File Identifier Error! ");
        
        /*
        Section 0: Header Object
         */
        System.out.println("====== Section 0: Header Object ======");
        if(dis.available()<5)
            err("Section 0: Header error! ");
        System.out.println("CompressionScheme: "+dis.readByte());
        UInt32 totalSectionLength=dis.readUInt32();
        //We have read 5 bytes.So we just check if (totalSectionLength.longvalue()-5) is available.
        if(dis.available()<totalSectionLength.longvalue()-5)
            err("Section 0: Content error! ");
        System.out.println("TotalSectionLength: "+totalSectionLength);
        System.out.println("UncompressedLength: "+dis.readUInt32());
        System.out.println("$$$$$$ Objects $$$$$$");
        System.out.println("ObjectType: "+dis.readByte());
        //length1 is the length of 1st object we load, length2 is the 2nd.
        UInt32 length1=dis.readUInt32();
        System.out.println("Length: "+length1);
        
        System.out.print("VersionNumber: ");
        System.out.print(dis.readByte()+".");
        System.out.println(dis.readByte());
        
        System.out.println("hasExternalReferences: "+dis.readBoolean());
        System.out.println("TotalFileSize: "+dis.readUInt32());
        System.out.println("ApproximateContentSize: "+dis.readUInt32());
        
        /*
        Head Object contain:
        Byte[2] VersionNumber
        Boolean hasExternalReferences
        UInt32  TotalFileSize
        UInt32  ApproximateContentSize
        String  AuthoringField
        So AuthoringField's length is object (length-11)
         */
        byte[] authoringField=new byte[length1.intvalue()-11];
        dis.readFully(authoringField);
        System.out.println("------ AuthoringField ------");
        System.out.println(new String(authoringField,"UTF-8"));
        System.out.println("------ End of AuthoringField ------");
        System.out.println("$$$$$$ End of Objects $$$$$$");
        System.out.println("Checksum: "+dis.readUInt32());
        System.out.println("====== End of Section 0: Header Object ======\n");
        
        
        //new section
        System.out.println(dis.readByte());
        System.out.println(dis.readUInt32());
        System.out.println(dis.readUInt32());
        M3GInflaterInputStream iis=new M3GInflaterInputStream(fis);
        System.out.println(iis.read());
        System.out.println(iis.readUInt32());
        /////////////////////a camera
        //user id
        System.out.println(iis.readUInt32());
        //animation track
        System.out.println(iis.readUInt32());
        //user para
        System.out.println(iis.readUInt32());
        //hasComponentTransform;
        System.out.println(iis.read());
        //hasGeneralTransform;
        System.out.println(iis.read());
        //enable rendering
        System.out.println(iis.read());
        // enablePicking;
        System.out.println(iis.read());
        // alphaFactor;
        System.out.println(iis.read());
        //scope;
        System.out.println(iis.readUInt32());    
        //hasAlignment;
        System.out.println(iis.read());
        //h
        System.out.println(iis.read());
        System.out.println(iis.readUInt32());    
        System.out.println(iis.readUInt32());    
        System.out.println(iis.readUInt32());    
        System.out.println(iis.readUInt32());    
/////////////next object/////////////////////
        //image 2d
        System.out.println(iis.read());
        System.out.println(iis.readUInt32());
        //user id
        System.out.println(iis.readUInt32());
        //animation tracks
        System.out.println(iis.readUInt32());
        //user object
        System.out.println(iis.readUInt32());
        //format
        System.out.println(iis.read());
        //is mutable
        System.out.println(iis.read());
        //width
        System.out.println(iis.readUInt32());
        //height
        System.out.println(iis.readUInt32());
        //  palette;
        System.out.println(iis.read());
        //pixels;
        System.out.println(iis.read());
        /*
        for(int l=0;l<4894;l++)
            iis.read();
        System.out.println(iis.read());
        System.out.println(iis.readUInt32());
        
        for(int l=0;l<40;l++)
            iis.read();
        System.out.println(iis.read());
        System.out.println(iis.readUInt32());
        
        for(int l=0;l<66;l++)
            iis.read();
        System.out.println(iis.read());
        System.out.println(iis.readUInt32());
        
        for(int l=0;l<66;l++)
            iis.read();
        System.out.println(iis.read());
        System.out.println(iis.readUInt32());
        
        for(int l=0;l<66;l++)
            iis.read();
        System.out.println(iis.read());
        System.out.println(iis.readUInt32());
        
        for(int l=0;l<41;l++)
            iis.read();
        System.out.println(iis.read());
        System.out.println(iis.readUInt32());
        
        for(int l=0;l<29;l++)
            iis.read();
        System.out.println(iis.read());
        System.out.println(iis.readUInt32());
        
        for(int l=0;l<25;l++)
            iis.read();
        System.out.println(iis.read());
        System.out.println(iis.readUInt32());
        
        for(int l=0;l<68;l++)
            iis.read();
        System.out.println(iis.read());
        System.out.println(iis.readUInt32());
    */
        dis.close();
        fis.close();
    }
    
    public static void err(String msg){
        System.out.println("\n**** An error has occured!!! The program was terminated!!! The errot infomation is: ");
        System.out.println(msg+"\n");
        System.exit(0);
    }
    
    static class M3GDataInputStream extends DataInputStream{
        
        public M3GDataInputStream(InputStream in){
            super(in);
        }
        
        public UInt32 readUInt32() throws IOException {
            int ch1 = in.read();
            int ch2 = in.read();
            int ch3 = in.read();
            long ch4 = in.read();
            //System.out.println(ch1+" "+ch2+" "+ch3+" "+ch4);
            if ((ch1 | ch2 | ch3 | ch4) < 0)
                throw new EOFException();
            return new UInt32((ch1 << 0) + (ch2 << 8) + (ch3 << 16) + (ch4 << 24));
        }
    }
    
    static class M3GInflaterInputStream extends InflaterInputStream{
        
        public M3GInflaterInputStream(InputStream in){
            super(in,new Inflater(),32);
        }
        
        public UInt32 readUInt32() throws IOException {
            int ch1 = super.read();
            int ch2 = super.read();
            int ch3 = super.read();
            long ch4 = super.read();
            //System.out.println(ch1+" "+ch2+" "+ch3+" "+ch4);
            if ((ch1 | ch2 | ch3 | ch4) < 0)
                throw new EOFException();
            return new UInt32((ch1 << 0) + (ch2 << 8) + (ch3 << 16) + (ch4 << 24));
        }
    }
    static class Float32{
        
    }
    static class UInt32{
        private long value;
        
        public UInt32(long value){
            this.value=value;
            Integer f=new Integer(2);
            
        }
        
        public long longvalue(){
            return value;
        }
        
        public int intvalue(){
            if(value > 2147483647 && value < -2147483648)
                throw new ClassCastException();
            return (int)value;
        }
        
        public String toString(){
            return Long.toString(value);
        }
    }
}

 

分享到:
评论

相关推荐

    解析m3u播放列表对应的音乐文件

    第二部分是对获取到的m3u文件进行解析,Android中并没有提供现成的方法来解析m3u文件;第三部分是显示解析结果,并利用MediaPlayer来播放列表。 在访问网络上的m3u文件时,我们需要使用HttpConnect类来封装网络访问...

    用python对m3u8格式视频解析

    用python对m3u8格式视频解析

    P2P版M3U8解析源码1.2.1版.zip_P2P解析m3u8源码_m3u8 p2p解析_p2p加速m3u8接口_p2p视频解

    m3u8解析源码加速p2p视频解析,m3u8解析源码加速

    宝箧印塔模型设计m3g

    《宝箧印塔模型设计与实现——基于Java M3G技术》 在移动设备领域,尤其是在支持Java 2 Micro Edition(J2ME)的手机上,实现三维图形渲染是一项技术挑战。本文将深入探讨如何利用Java M3G(Mobile 3D Graphics)...

    M3G API Docs

    在“Mobile3DGraphicsAPI”这个压缩包文件中,通常会包含M3G API的详细说明文档、示例代码、参考手册和可能的开发工具,这些资源可以帮助开发者更深入地理解和使用M3G API。通过阅读这些文档,开发者可以逐步学习并...

    m3u8直链解析源码

    安装教程 将ckplayer文件夹全部上传至网站空间根目录即可 接口测试:http://你的域名/ckplayer/m3u8.php?url= 播放地址要有效才能解析,失效的地址无法解析 可自行整合到其他程序中!

    java将m3u8格式转成视频文件的方法

    Java 将 M3U8 格式转成视频文件的方法 Java 是当前最流行的编程语言之一,广泛应用于 Android 和 Web 开发中。在视频处理方面,Java 也提供了强大的支持。M3U8 是一种广泛使用的视频流格式,经常用于直播和点播等...

    ts文件按m3u8文件顺序合并程序

    使用方法:将 ts所有分段文件、m3u8文件和本程序放于同一目录下,m3u8文件名必须是local.m3u8,然后运行程序即可得到完整的ts文件index.ts 注意事项:1. 如果出现莫名其妙的错误,则可能是文件路径有中文,改为英文...

    m3u8_m3u8下载_

    输入m3u8地址,解析m3u8内容,进行下载并合并成为MP4文件

    PHP智能切换解析线路3.0[线路切换] 支持M3U8 MP4缓存

    增加redis缓存+cache文件缓存(极速响应)注释:MP4格式的直接redis缓存.m3u8直接进行cache文件缓存 根据API解析的类型进行自动分类缓存 根据平台规则缓存 调用方法:http://你的域名/auto.php?url= 自备解析json...

    ffmpeg自动下载m3u8合并为ts(自动解析key文件)

    Fmpeg 是领先的多媒体框架,能够解码、编码、转码、混合、解密、流媒体、过滤和播放人类和机器创造的几乎所有东西 支持mov mp4 wma avi flv互相转换 支持ts合并为avi ...m3u8自动下载带key合并为ts教程在资源内

    解析m3u8音频文件 MediaPlayer 播放

    使用MediaPlayer 播放m3u8音频文件

    m3u8解析下载

    m3u8解析下载的工具,从视频网站找到一个m3u8lian'jie

    【python爬虫】爬取网页视频,解析m3u8文件,获取ts并合成mp4

    python爬虫相关: 由于很多网站上的视频只提供在线观看,...利用requests获取网页源代码中的m3u8链接,对链接进行逐步解析,获取ts列表,下载所有ts文件,将其合并生成mp4文件。做到对视频的爬取。 同名博文相关代码。

    m3_import 3ds Max 的M3模型导入

    M3 Import Script,3ds Max 的M3模型导入

    M3GToolkit-0.5.0

    《M3GToolkit-0.5.0:深入解析M3G文件检查工具》 M3GToolkit-0.5.0是一款专为J2ME(Java 2 Micro Edition)开发者设计的实用工具,用于检查和分析M3G(Mobile 3D Graphics)文件。在移动设备上的3D图形开发中,M3G...

    M3G 的快速模式编程

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

    自动生成M3U文件

    在IT领域,M3U(M3U8)文件是一种常用的音频和视频播放列表格式,由用户或应用程序创建,用于指示媒体播放器按顺序播放一系列的媒体文件。这些文件通常包含有指向媒体文件URL的简单文本列表。在这个场景中,我们将...

    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的轻量级版本,专为嵌入式...

    M3铜柱-散热片封装PCB文件3D封装AD库

    HD-1、HD-2、HD-3、M3x4+6_L、M3x4+6_N、M3x4_L、M3x4_N、M3x5+6_L、M3x5+6_N、M3x5_L、M3x5_N、M3x6+6_L、M3x6+6_N、M3x6_L、M3x6_N、M3x7+6_L、M3x8+6_N、M3x12+6_N、M3x15_N、M3x16+6_L、M3x21+6_N、M3x21+6_N、...

Global site tag (gtag.js) - Google Analytics