Java 类org.lwjgl.assimp.AIMaterial 实例源码

项目:Mass    文件:StaticMeshLoader.java   
/**
 * Loads one or more meshes at the specified resource path with 
 * the textures at the specified texture path with the specified flags.
 * 
 * @param resourcePath - Path for the mesh resource to load.
 * @param texturesDir - Path for the textures to use for the mesh.
 * @param flags - Flags for the Assimp importer to use.
 * 
 * @return Mesh array with the loaded meshes.
 * 
 * @throws Exception
 */
public static Mesh[] load(String resourcePath, String texturesDir, int flags) throws Exception {
    AIScene aiScene = Assimp.aiImportFile(resourcePath, flags);
       if (aiScene == null) {
           throw new Exception("Error loading model");
       }

       int numMaterials = aiScene.mNumMaterials();
       PointerBuffer aiMaterials = aiScene.mMaterials();
       List<Material> materials = new ArrayList<>();
       for (int i = 0; i < numMaterials; i++) {
           AIMaterial aiMaterial = AIMaterial.create(aiMaterials.get(i));
           processMaterial(aiMaterial, materials, texturesDir);
       }

       int numMeshes = aiScene.mNumMeshes();
       PointerBuffer aiMeshes = aiScene.mMeshes();
       Mesh[] meshes = new Mesh[numMeshes];
       for (int i = 0; i < numMeshes; i++) {
           AIMesh aiMesh = AIMesh.create(aiMeshes.get(i));
           Mesh mesh = processMesh(aiMesh, materials);
           meshes[i] = mesh;
       }

       return meshes;
}
项目:lwjglbook    文件:StaticMeshesLoader.java   
public static Mesh[] load(String resourcePath, String texturesDir, int flags) throws Exception {
    AIScene aiScene = aiImportFile(resourcePath, flags);
    if (aiScene == null) {
        throw new Exception("Error loading model");
    }

    int numMaterials = aiScene.mNumMaterials();
    PointerBuffer aiMaterials = aiScene.mMaterials();
    List<Material> materials = new ArrayList<>();
    for (int i = 0; i < numMaterials; i++) {
        AIMaterial aiMaterial = AIMaterial.create(aiMaterials.get(i));
        processMaterial(aiMaterial, materials, texturesDir);
    }

    int numMeshes = aiScene.mNumMeshes();
    PointerBuffer aiMeshes = aiScene.mMeshes();
    Mesh[] meshes = new Mesh[numMeshes];
    for (int i = 0; i < numMeshes; i++) {
        AIMesh aiMesh = AIMesh.create(aiMeshes.get(i));
        Mesh mesh = processMesh(aiMesh, materials);
        meshes[i] = mesh;
    }

    return meshes;
}
项目:lwjglbook    文件:StaticMeshesLoader.java   
public static Mesh[] load(String resourcePath, String texturesDir, int flags) throws Exception {
    AIScene aiScene = aiImportFile(resourcePath, flags);
    if (aiScene == null) {
        throw new Exception("Error loading model");
    }

    int numMaterials = aiScene.mNumMaterials();
    PointerBuffer aiMaterials = aiScene.mMaterials();
    List<Material> materials = new ArrayList<>();
    for (int i = 0; i < numMaterials; i++) {
        AIMaterial aiMaterial = AIMaterial.create(aiMaterials.get(i));
        processMaterial(aiMaterial, materials, texturesDir);
    }

    int numMeshes = aiScene.mNumMeshes();
    PointerBuffer aiMeshes = aiScene.mMeshes();
    Mesh[] meshes = new Mesh[numMeshes];
    for (int i = 0; i < numMeshes; i++) {
        AIMesh aiMesh = AIMesh.create(aiMeshes.get(i));
        Mesh mesh = processMesh(aiMesh, materials);
        meshes[i] = mesh;
    }

    return meshes;
}
项目:lwjglbook    文件:StaticMeshesLoader.java   
public static Mesh[] load(String resourcePath, String texturesDir, int flags) throws Exception {
    AIScene aiScene = aiImportFile(resourcePath, flags);
    if (aiScene == null) {
        throw new Exception("Error loading model");
    }

    int numMaterials = aiScene.mNumMaterials();
    PointerBuffer aiMaterials = aiScene.mMaterials();
    List<Material> materials = new ArrayList<>();
    for (int i = 0; i < numMaterials; i++) {
        AIMaterial aiMaterial = AIMaterial.create(aiMaterials.get(i));
        processMaterial(aiMaterial, materials, texturesDir);
    }

    int numMeshes = aiScene.mNumMeshes();
    PointerBuffer aiMeshes = aiScene.mMeshes();
    Mesh[] meshes = new Mesh[numMeshes];
    for (int i = 0; i < numMeshes; i++) {
        AIMesh aiMesh = AIMesh.create(aiMeshes.get(i));
        Mesh mesh = processMesh(aiMesh, materials);
        meshes[i] = mesh;
    }

    return meshes;
}
项目:oreon-engine    文件:AssimpStaticModelLoader.java   
private static Material processMaterial(AIMaterial aiMaterial, String texturesDir) {

        AIString path = AIString.calloc();
        Assimp.aiGetMaterialTexture(aiMaterial, Assimp.aiTextureType_DIFFUSE, 0, path, (IntBuffer) null, null, null, null, null, null);
        String textPath = path.dataString();

        Texture diffuseTexture = null;
        if (textPath != null && textPath.length() > 0) {
            diffuseTexture = new Texture();
            diffuseTexture.setPath(texturesDir + "/" + textPath);
        }

        AIColor4D color = AIColor4D.create();
        Vec3f diffuseColor = null;
        int result = Assimp.aiGetMaterialColor(aiMaterial, Assimp.AI_MATKEY_COLOR_AMBIENT, Assimp.aiTextureType_NONE, 0, color);
        if (result == 0) {
            diffuseColor = new Vec3f(color.r(), color.g(), color.b());
        }

        Material material = new Material();
        material.setDiffusemap(diffuseTexture);
        material.setColor(diffuseColor);

        return material;
    }
项目:JavaGraphicsEngine    文件:AssimpLoader.java   
/**
 * Loads a model file and a texture to a {@link TexturedModel}.  This method requires flags that will determine how
 * how the mesh is handled.
 * 
 * @param modelPath         Path to the model
 * @param texturePath       Path to the texture.  If the model contains a material library,
 *                          the material library should point to the texture's folder.
 * @param flags             Flags separated by the Binary OR operator, "|"
 * @return                  Array of {@link TexturedModel}s that were contained by the
 *                          model file.
 */
public static TexturedModel[] load(String modelPath, String texturePath, int flags) {
    AIScene aiScene = aiImportFile(modelPath, flags);
    if (aiScene == null)
        throw new RuntimeException("Could not load model: " + modelPath + "\nWith flags " + flags);

    int numMaterials = aiScene.mNumMaterials();
    PointerBuffer aiMaterials = aiScene.mMaterials();
    List<Material> materials = new ArrayList<Material>();
    for (int i = 0; i < numMaterials; i++) {
        AIMaterial aiMaterial = AIMaterial.create(aiMaterials.get(i));
        processMat(aiMaterial, materials, texturePath);
    }

    int numMeshes = aiScene.mNumMeshes();
    PointerBuffer aiMeshes = aiScene.mMeshes();
    TexturedModel[] meshes = new TexturedModel[numMeshes];
    for (int i = 0; i < numMeshes; i++) {
        AIMesh aiMesh = AIMesh.create(aiMeshes.get(i));
        TexturedModel mesh = processStaticMesh(aiMesh, materials);
        String name = modelPath.split("/")[modelPath.split("/").length - 1];
        String tex = texturePath.split("/")[texturePath.split("/").length - 1];
        DBObject obj = new DBObject(name, DBObjectType.MODEL);
        obj.addArray(DBArray.createFloatArray("vertices", mesh.getModelData().getVertices()));
        obj.addArray(DBArray.createFloatArray("textureCoords", mesh.getModelData().getTextureCoords()));
        obj.addArray(DBArray.createFloatArray("normals", mesh.getModelData().getNormals()));
        obj.addArray(DBArray.createIntegerArray("indices", mesh.getModelData().getIndices()));
        obj.addString(DBString.create("texture", tex));
        AssetCache.db.addObject(obj);
        meshes[i] = mesh;
    }
    AssetCache.db.serialize("assets.lum");
    return meshes;
}
项目:lwjglbook    文件:AnimMeshesLoader.java   
public static AnimGameItem loadAnimGameItem(String resourcePath, String texturesDir, int flags)
        throws Exception {
    AIScene aiScene = aiImportFile(resourcePath, flags);
    if (aiScene == null) {
        throw new Exception("Error loading model");
    }

    int numMaterials = aiScene.mNumMaterials();
    PointerBuffer aiMaterials = aiScene.mMaterials();
    List<Material> materials = new ArrayList<>();
    for (int i = 0; i < numMaterials; i++) {
        AIMaterial aiMaterial = AIMaterial.create(aiMaterials.get(i));
        processMaterial(aiMaterial, materials, texturesDir);
    }

    List<Bone> boneList = new ArrayList<>();
    int numMeshes = aiScene.mNumMeshes();
    PointerBuffer aiMeshes = aiScene.mMeshes();
    Mesh[] meshes = new Mesh[numMeshes];
    for (int i = 0; i < numMeshes; i++) {
        AIMesh aiMesh = AIMesh.create(aiMeshes.get(i));
        Mesh mesh = processMesh(aiMesh, materials, boneList);
        meshes[i] = mesh;
    }

    AINode aiRootNode = aiScene.mRootNode();
    Matrix4f rootTransfromation = AnimMeshesLoader.toMatrix(aiRootNode.mTransformation());
    Node rootNode = processNodesHierarchy(aiRootNode, null);
    Map<String, Animation> animations = processAnimations(aiScene, boneList, rootNode, rootTransfromation);
    AnimGameItem item = new AnimGameItem(meshes, animations);

    return item;
}
项目:lwjglbook    文件:AnimMeshesLoader.java   
public static AnimGameItem loadAnimGameItem(String resourcePath, String texturesDir, int flags)
        throws Exception {
    AIScene aiScene = aiImportFile(resourcePath, flags);
    if (aiScene == null) {
        throw new Exception("Error loading model");
    }

    int numMaterials = aiScene.mNumMaterials();
    PointerBuffer aiMaterials = aiScene.mMaterials();
    List<Material> materials = new ArrayList<>();
    for (int i = 0; i < numMaterials; i++) {
        AIMaterial aiMaterial = AIMaterial.create(aiMaterials.get(i));
        processMaterial(aiMaterial, materials, texturesDir);
    }

    List<Bone> boneList = new ArrayList<>();
    int numMeshes = aiScene.mNumMeshes();
    PointerBuffer aiMeshes = aiScene.mMeshes();
    Mesh[] meshes = new Mesh[numMeshes];
    for (int i = 0; i < numMeshes; i++) {
        AIMesh aiMesh = AIMesh.create(aiMeshes.get(i));
        Mesh mesh = processMesh(aiMesh, materials, boneList);
        meshes[i] = mesh;
    }

    AINode aiRootNode = aiScene.mRootNode();
    Matrix4f rootTransfromation = AnimMeshesLoader.toMatrix(aiRootNode.mTransformation());
    Node rootNode = processNodesHierarchy(aiRootNode, null);
    Map<String, Animation> animations = processAnimations(aiScene, boneList, rootNode, rootTransfromation);
    AnimGameItem item = new AnimGameItem(meshes, animations);

    return item;
}
项目:oreon-engine    文件:AssimpStaticModelLoader.java   
public static List<Model> loadModel(String path, String file) {

    List<Model> models = new ArrayList<>();
    List<Material> materials = new ArrayList<>();

    path = AssimpStaticModelLoader.class.getClassLoader().getResource(path).getPath().toString();

    if (path.startsWith("/"))
        path = path.substring(1);

    AIScene aiScene = Assimp.aiImportFile(path + "/" + file, 0);

    if (aiScene.mMaterials() != null){
        for (int i=0; i<aiScene.mNumMaterials(); i++){
            AIMaterial aiMaterial = AIMaterial.create(aiScene.mMaterials().get(i));
            Material material = processMaterial(aiMaterial, path);
            materials.add(material);
        }
    }

    for (int i=0; i<aiScene.mNumMeshes(); i++){
        AIMesh aiMesh = AIMesh.create(aiScene.mMeshes().get(i));
        Mesh mesh = processMesh(aiMesh);
        Model model = new Model();
        model.setMesh(mesh);
        int materialIndex = aiMesh.mMaterialIndex();
        model.setMaterial(materials.get(materialIndex));
        models.add(model);
    }

    return models;
}