⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loadermanager.java

📁 M3DEA (Mobile 3D Engine API) 手机3D引擎API
💻 JAVA
字号:
/*
 *M3DEA - MOBILE 3D ENGINE API
 *Copyright (C) 2006 Alexandre Watanabe         alexandre_sw@yahoo.com.br     
 *		     Diego de Freitas           zenon_cc@yahoo.com.br
 *		     Paulo Rodrigo Priszculnik  paulorp@paulorp.trix.net
 *		     Rodrigo Arthur Lopes       raspl@terra.com.br
 *
 * This library is free software; you can redistribute it 
 * and/or modify it under the terms of the GNU Lesser General
 * Public License as published by the Free Software
 * Foundation; either version 2.1 of the License, or (at your
 * option) any later version.
 *
 * This library is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE. See the GNU Lesser General Public License for
 * more details.
 *
 * You should have received a copy of the GNU Lesser General
 * Public License along with this library; if not, write to
 * the Free Software Foundation, Inc., 59 Temple Place, Suite
 * 330, Boston, MA 02111-1307 USA
 *
 */

package m3dea.loader;

import java.io.IOException;
import javax.microedition.m3g.*;
import m3dea.entities.*;

/**
 * Classe que percorre a cena do arquivo .m3g e vai recuperando as malhas dos objetos de cena e passado para o BuilderScene a entidade e a malha
 */
public class LoaderManager 
{
    private static LoaderManager instance = null;
    
    private LoaderConfig config;
    private BuilderScene builder;
    
    private LoaderManager() 
    {             
    }
    
    /**
     * Recupera inst鈔cia de LoaderManager
     * @return inst鈔cia de LoaderManager
     */
    public static LoaderManager getInstance()
    {
        if(instance == null) instance = new LoaderManager();
        return instance;
    }
    
    /**
     * M閠odo que carrega arquivo .m3g e conforme configurado pelo LoaderConfig
     * @param filename arquivo de cena m3g a ser carregado
     * @param config LoaderConfig com as configura珲es de grupo
     * @param builder BuilderScene que vai adicionando 鄐 entidades no EntityManager
     * @throws java.io.IOException Se arquivo n鉶 puder ser encontrado ou lido
     */
    public void loadScene(String filename, LoaderConfig config, BuilderScene builder) throws IOException
    {
        this.config = config;
        this.builder = builder;
        
        Object3D[] buffer = Loader.load(filename);

        World world = null;
        // 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;
            }
        }
        
        builder.setWorld(world);
        for(int i = 0; i < world.getChildCount(); i++)
        {
            Node node = world.getChild(i);
            if(node instanceof Group) recNode((Group) node, node.getUserID());
            else if(node instanceof Camera) builder.createCamera((Camera)node);
        }
    }
    
    private void recNode(Group g, int userID)
    {
        for(int i = 0; i < g.getChildCount(); i++)
        {
            Node node = g.getChild(i);
            if(node instanceof Group) recNode((Group) node, userID);
            
            else if(node instanceof Mesh)
            {
                Entity entity = config.getEntity(userID);
                if(entity == null) continue;
                
                if(entity instanceof Item) builder.createItem((Item) entity, (Mesh) node);
                else if(entity instanceof Portal) builder.createPortal( (Portal) entity, (Mesh) node );
                else if(entity instanceof StaticEntity) builder.createStaticEntity((StaticEntity) entity, (Mesh) node);
                else if(entity instanceof Player) builder.createPlayer((Player) entity, (Mesh) node);
                else if(entity instanceof Sprite) builder.createSprite((Sprite) entity, (Mesh) node);
                                
                else builder.createEntity(entity, (Mesh) node);
            }
        }
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -