• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ImageToAwt类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中jme3tools.converters.ImageToAwt的典型用法代码示例。如果您正苦于以下问题:Java ImageToAwt类的具体用法?Java ImageToAwt怎么用?Java ImageToAwt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ImageToAwt类属于jme3tools.converters包,在下文中一共展示了ImageToAwt类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: readJMETexture

import jme3tools.converters.ImageToAwt; //导入依赖的package包/类
@FXThread
private @NotNull Image readJMETexture(final int width, final int height, @NotNull final String externalForm,
                                      @NotNull final Path cacheFile) {

    final Editor editor = Editor.getInstance();
    final AssetManager assetManager = editor.getAssetManager();
    final Texture texture = assetManager.loadTexture(externalForm);

    final BufferedImage textureImage;
    try {
        textureImage = ImageToAwt.convert(texture.getImage(), false, true, 0);
    } catch (final UnsupportedOperationException e) {
        EditorUtil.handleException(LOGGER, this, e);
        return Icons.IMAGE_512;
    }

    final int imageWidth = textureImage.getWidth();
    final int imageHeight = textureImage.getHeight();

    return scaleAndWrite(width, height, cacheFile, textureImage, imageWidth, imageHeight);
}
 
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:22,代码来源:JavaFXImageManager.java


示例2: saveIfNeedTexture

import jme3tools.converters.ImageToAwt; //导入依赖的package包/类
/**
 * Save if need a texture.
 *
 * @param texture the texture.
 */
private static void saveIfNeedTexture(@NotNull final Texture texture) {

    final Image image = texture.getImage();
    if (!image.isChanged()) return;

    final AssetKey key = texture.getKey();
    final Path file = notNull(getRealFile(key.getName()));
    final BufferedImage bufferedImage = ImageToAwt.convert(image, false, true, 0);

    try (final OutputStream out = Files.newOutputStream(file, WRITE, TRUNCATE_EXISTING, CREATE)) {
        ImageIO.write(bufferedImage, "png", out);
    } catch (final IOException e) {
        e.printStackTrace();
    }

    image.clearChanges();
}
 
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:23,代码来源:MaterialUtils.java


示例3: scale

import jme3tools.converters.ImageToAwt; //导入依赖的package包/类
@Override
public void scale(int width, int height) {
       if (width < 0 && height < 0) {
           return;
       } else if (width < 0) {
           width = Math.round(width
                   * (height == 0 ? 1 : ((float) height / height)));
       } else if (height < 0) {
           height = Math.round(height
                   * (width == 0 ? 1 : ((float) width / width)));
       }
       BufferedImage bim = ImageToAwt.convert(image, false, true, 0);
       System.err.println("scaling image from " + image.getWidth() + " x " + image.getHeight() + " to " + width + " x " + height);
       BufferedImage tbim = new BufferedImage(width, height, bim.getType());
       tbim.getGraphics().drawImage(bim, 0, 0, width, height, null);
       image = new AWTLoader().load(tbim, false);
   }
 
开发者ID:rockfireredmoon,项目名称:icetone,代码行数:18,代码来源:XHTMLFSImage.java


示例4: scale

import jme3tools.converters.ImageToAwt; //导入依赖的package包/类
/**
 * This method scales the given texture to the given size.
 * 
 * @param texture
 *            the texture to be scaled
 * @param width
 *            new width of the texture
 * @param height
 *            new height of the texture
 */
private void scale(Texture2D texture, int width, int height) {
    // first determine if scaling is required
    boolean scaleRequired = texture.getImage().getWidth() != width || texture.getImage().getHeight() != height;

    if (scaleRequired) {
        Image image = texture.getImage();
        BufferedImage sourceImage = ImageToAwt.convert(image, false, true, 0);

        int sourceWidth = sourceImage.getWidth();
        int sourceHeight = sourceImage.getHeight();

        BufferedImage targetImage = new BufferedImage(width, height, sourceImage.getType());

        Graphics2D g = targetImage.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g.drawImage(sourceImage, 0, 0, width, height, 0, 0, sourceWidth, sourceHeight, null);
        g.dispose();

        Image output = new ImageLoader().load(targetImage, false);
        image.setWidth(width);
        image.setHeight(height);
        image.setData(output.getData(0));
        image.setFormat(output.getFormat());
    }
}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:36,代码来源:CombinedTexture.java


示例5: multipleTexSouthLoadButtonActionPerformed

import jme3tools.converters.ImageToAwt; //导入依赖的package包/类
private void multipleTexSouthLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleTexSouthLoadButtonActionPerformed
    Component view = editorSouth.getCustomEditor();
    view.setVisible(true);
    if (editorSouth.getValue() != null) {
        Texture tex = (Texture) editorSouth.getValue();
        String selected = tex.getKey().getName();

        if (selected.toLowerCase().endsWith(".dds")) {
            if (ddsPreview == null) {
                ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager());
            }
            ddsPreview.requestPreview(selected, "", 80, 80, southPic, null);

        } else {
            Icon newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0));
            southPic.setIcon(newicon);
        }
    }
}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:20,代码来源:SkyboxVisualPanel2.java


示例6: multipleTexNorthLoadButtonActionPerformed

import jme3tools.converters.ImageToAwt; //导入依赖的package包/类
private void multipleTexNorthLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleTexNorthLoadButtonActionPerformed
    Component view = editorNorth.getCustomEditor();
    view.setVisible(true);
    if (editorNorth.getValue() != null) {
        Texture tex = (Texture) editorNorth.getValue();
        String selected = tex.getKey().getName();

        if (selected.toLowerCase().endsWith(".dds")) {
            if (ddsPreview == null) {
                ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager());
            }
            ddsPreview.requestPreview(selected, "", 80, 80, northPic, null);

        } else {
            Icon newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0));
            northPic.setIcon(newicon);
        }
    }
}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:20,代码来源:SkyboxVisualPanel2.java


示例7: multipleTexEastLoadButtonActionPerformed

import jme3tools.converters.ImageToAwt; //导入依赖的package包/类
private void multipleTexEastLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleTexEastLoadButtonActionPerformed
    Component view = editorEast.getCustomEditor();
    view.setVisible(true);
    if (editorEast.getValue() != null) {
        Texture tex = (Texture) editorEast.getValue();
        String selected = tex.getKey().getName();

        if (selected.toLowerCase().endsWith(".dds")) {
            if (ddsPreview == null) {
                ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager());
            }
            ddsPreview.requestPreview(selected, "", 80, 80, eastPic, null);

        } else {
            Icon newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0));
            eastPic.setIcon(newicon);
        }
    }
}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:20,代码来源:SkyboxVisualPanel2.java


示例8: multipleTexWestLoadButtonActionPerformed

import jme3tools.converters.ImageToAwt; //导入依赖的package包/类
private void multipleTexWestLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleTexWestLoadButtonActionPerformed
    Component view = editorWest.getCustomEditor();
    view.setVisible(true);
    if (editorWest.getValue() != null) {
        Texture tex = (Texture) editorWest.getValue();
        String selected = tex.getKey().getName();

        if (selected.toLowerCase().endsWith(".dds")) {
            if (ddsPreview == null) {
                ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager());
            }
            ddsPreview.requestPreview(selected, "", 80, 80, westPic, null);

        } else {
            Icon newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0));
            westPic.setIcon(newicon);
        }
    }
}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:20,代码来源:SkyboxVisualPanel2.java


示例9: multipleTexTopLoadButtonActionPerformed

import jme3tools.converters.ImageToAwt; //导入依赖的package包/类
private void multipleTexTopLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleTexTopLoadButtonActionPerformed
    Component view = editorTop.getCustomEditor();
    view.setVisible(true);
    if (editorTop.getValue() != null) {
        Texture tex = (Texture) editorTop.getValue();
        String selected = tex.getKey().getName();

        if (selected.toLowerCase().endsWith(".dds")) {
            if (ddsPreview == null) {
                ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager());
            }
            ddsPreview.requestPreview(selected, "", 80, 80, topPic, null);

        } else {
            Icon newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0));
            topPic.setIcon(newicon);
        }
    }
}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:20,代码来源:SkyboxVisualPanel2.java


示例10: multipleTexBottomLoadButtonActionPerformed

import jme3tools.converters.ImageToAwt; //导入依赖的package包/类
private void multipleTexBottomLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleTexBottomLoadButtonActionPerformed
    Component view = editorBottom.getCustomEditor();
    view.setVisible(true);
    if (editorBottom.getValue() != null) {
        Texture tex = (Texture) editorBottom.getValue();
        String selected = tex.getKey().getName();

        if (selected.toLowerCase().endsWith(".dds")) {
            if (ddsPreview == null) {
                ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager());
            }
            ddsPreview.requestPreview(selected, "", 80, 80, bottomPic, null);

        } else {
            Icon newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0));
            bottomPic.setIcon(newicon);
        }
    }
}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:20,代码来源:SkyboxVisualPanel2.java


示例11: singleTexLoadButtonActionPerformed

import jme3tools.converters.ImageToAwt; //导入依赖的package包/类
private void singleTexLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_singleTexLoadButtonActionPerformed
    Component view = editorSingle.getCustomEditor();
    view.setVisible(true);
    if (editorSingle.getValue() != null) {
        Texture tex = (Texture) editorSingle.getValue();
        String selected = tex.getKey().getName();

        if (selected.toLowerCase().endsWith(".dds")) {
            if (ddsPreview == null) {
                ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager());
            }
            ddsPreview.requestPreview(selected, "", 80, 80, singlePic, null);

        } else {

            Icon newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0));
            singlePic.setIcon(newicon);
        }
    }
}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:21,代码来源:SkyboxVisualPanel2.java


示例12: convertToNormalMapTexture

import jme3tools.converters.ImageToAwt; //导入依赖的package包/类
/**
 * This method converts the given texture into normal-map texture.
 * 
 * @param source
 *            the source texture
 * @param strengthFactor
 *            the normal strength factor
 * @return normal-map texture
 */
public Image convertToNormalMapTexture(Image source, float strengthFactor) {
    BufferedImage sourceImage = ImageToAwt.convert(source, false, false, 0);

    BufferedImage heightMap = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
    BufferedImage bumpMap = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
    ColorConvertOp gscale = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
    gscale.filter(sourceImage, heightMap);

    Vector3f S = new Vector3f();
    Vector3f T = new Vector3f();
    Vector3f N = new Vector3f();

    for (int x = 0; x < bumpMap.getWidth(); ++x) {
        for (int y = 0; y < bumpMap.getHeight(); ++y) {
            // generating bump pixel
            S.x = 1;
            S.y = 0;
            S.z = strengthFactor * this.getHeight(heightMap, x + 1, y) - strengthFactor * this.getHeight(heightMap, x - 1, y);
            T.x = 0;
            T.y = 1;
            T.z = strengthFactor * this.getHeight(heightMap, x, y + 1) - strengthFactor * this.getHeight(heightMap, x, y - 1);

            float den = (float) Math.sqrt(S.z * S.z + T.z * T.z + 1);
            N.x = -S.z;
            N.y = -T.z;
            N.z = 1;
            N.divideLocal(den);

            // setting thge pixel in the result image
            bumpMap.setRGB(x, y, this.vectorToColor(N.x, N.y, N.z));
        }
    }
    ByteBuffer byteBuffer = BufferUtils.createByteBuffer(source.getWidth() * source.getHeight() * 3);
    ImageToAwt.convert(bumpMap, Format.RGB8, byteBuffer);
    return new Image(Format.RGB8, source.getWidth(), source.getHeight(), byteBuffer);
}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:46,代码来源:TextureHelper.java


示例13: castToUVS

import jme3tools.converters.ImageToAwt; //导入依赖的package包/类
/**
 * This method alters the images to fit them into UV coordinates of the
 * given target texture.
 * 
 * @param targetTexture
 *            the texture to whose UV coordinates we fit current images
 * @param blenderContext
 *            the blender context
 */
public void castToUVS(TriangulatedTexture targetTexture, BlenderContext blenderContext) {
    int[] sourceSize = new int[2], targetSize = new int[2];
    ImageLoader imageLoader = new ImageLoader();
    TextureHelper textureHelper = blenderContext.getHelper(TextureHelper.class);
    for (TriangleTextureElement entry : faceTextures) {
        TriangleTextureElement targetFaceTextureElement = targetTexture.getFaceTextureElement(entry.faceIndex);
        Vector2f[] dest = targetFaceTextureElement.uv;

        // get the sizes of the source and target images
        sourceSize[0] = entry.image.getWidth();
        sourceSize[1] = entry.image.getHeight();
        targetSize[0] = targetFaceTextureElement.image.getWidth();
        targetSize[1] = targetFaceTextureElement.image.getHeight();

        // create triangle transformation
        AffineTransform affineTransform = textureHelper.createAffineTransform(entry.uv, dest, sourceSize, targetSize);

        // compute the result texture
        BufferedImage sourceImage = ImageToAwt.convert(entry.image, false, true, 0);

        BufferedImage targetImage = new BufferedImage(targetSize[0], targetSize[1], sourceImage.getType());
        Graphics2D g = targetImage.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g.drawImage(sourceImage, affineTransform, null);
        g.dispose();

        Image output = imageLoader.load(targetImage, false);
        entry.image = output;
        entry.uv[0].set(dest[0]);
        entry.uv[1].set(dest[1]);
        entry.uv[2].set(dest[2]);
    }
}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:43,代码来源:TriangulatedTexture.java


示例14: displayPreview

import jme3tools.converters.ImageToAwt; //导入依赖的package包/类
private void displayPreview() {
    if (!"".equals(textureName)) {
        Texture tex = manager.loadTexture(textureName);
        Icon newicon = null;
        if (textureName.toLowerCase().endsWith(".dds")) {
            if (ddsPreview == null) {
                ddsPreview = new DDSPreview(manager);
            }
            ddsPreview.requestPreview(textureName, "", 80, 80, texturePreview, null);
        } else {
            newicon = ImageUtilities.image2Icon(resizeImage(ImageToAwt.convert(tex.getImage(), false, true, 0)));
        }
        texturePreview.setIcon(newicon);
    }
}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:16,代码来源:TexturePanel.java


示例15: doSaveAlphaImages

import jme3tools.converters.ImageToAwt; //导入依赖的package包/类
/**
 * Save the terrain's alpha maps to disk, in the Textures/terrain-alpha/ directory
 * @throws IOException
 */
private synchronized void doSaveAlphaImages(Terrain terrain) {

    if (terrain == null) {
        getTerrain(rootNode);
        return;
    }
    
    AssetManager manager = SceneApplication.getApplication().getAssetManager();
    String assetFolder = null;
    if (manager != null && manager instanceof ProjectAssetManager)
        assetFolder = ((ProjectAssetManager)manager).getAssetFolderName();
    if (assetFolder == null)
        throw new IllegalStateException("AssetManager was not a ProjectAssetManager. Could not locate image save directories.");

    Texture alpha1 = doGetAlphaTexture(terrain, 0);
    BufferedImage bi1 = ImageToAwt.convert(alpha1.getImage(), false, true, 0);
    File imageFile1 = new File(assetFolder+alpha1.getKey().getName());
    Texture alpha2 = doGetAlphaTexture(terrain, 1);
    BufferedImage bi2 = ImageToAwt.convert(alpha2.getImage(), false, true, 0);
    File imageFile2 = new File(assetFolder+alpha2.getKey().getName());
    Texture alpha3 = doGetAlphaTexture(terrain, 2);
    BufferedImage bi3 = ImageToAwt.convert(alpha3.getImage(), false, true, 0);
    File imageFile3 = new File(assetFolder+alpha3.getKey().getName());
    try {
        ImageIO.write(bi1, "png", imageFile1);
        ImageIO.write(bi2, "png", imageFile2);
        ImageIO.write(bi3, "png", imageFile3);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    
}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:37,代码来源:TerrainEditorController.java


示例16: valueChanged

import jme3tools.converters.ImageToAwt; //导入依赖的package包/类
public void valueChanged(TreeSelectionEvent e) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1.getLastSelectedPathComponent();

    if (node == null) //Nothing is selected.	
    {
        return;
    }

    //Object nodeInfo = node.getUserObject();
    if (node.isLeaf()) {
        String selected = TreeUtil.getPath(node.getUserObjectPath());
        selected = selected.substring(0, selected.lastIndexOf("/"));
        Icon newicon = null;
        if (selected.toLowerCase().endsWith(".dds")) {
            if (ddsPreview == null) {
                ddsPreview = new DDSPreview(assetManager);
            }
            ddsPreview.requestPreview(selected, (String) node.getUserObject(), 450, 450, imagePreviewLabel, infoLabel);

        } else {
            Texture tex = assetManager.loadTexture(selected);
            newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0));
            imagePreviewLabel.setIcon(newicon);
            infoLabel.setText(" " + node.getUserObject() + "    w : " + newicon.getIconWidth() + "    h : " + newicon.getIconHeight());
        }

    } else {
        imagePreviewLabel.setIcon(null);
        infoLabel.setText("");

    }

}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:34,代码来源:TextureBrowser.java


示例17: checkPackedTextureProps

import jme3tools.converters.ImageToAwt; //导入依赖的package包/类
/**
 * Prompts user to save packed textures
 *
 * @param mat
 * @param param
 */
private void checkPackedTextureProps(Material mat) {
    Collection<MatParam> params = mat.getParams();
    for (Iterator<MatParam> it = new ArrayList<MatParam>(params).iterator(); it.hasNext();) {
        MatParam param = it.next();
        MaterialProperty prop = new MaterialProperty(param);
        if (prop.getValue() == null) {
            switch (param.getVarType()) {
                case Texture2D:
                case Texture3D:
                case TextureArray:
                case TextureBuffer:
                case TextureCubeMap:
                    try {
                        MatParamTexture texParam = mat.getTextureParam(param.getName());
                        Texture tex = texParam.getTextureValue();
                        Image img = tex.getImage();
                        if (img == null) {
                            logger.log(Level.INFO, "No image found");
                            return;
                        }
                        BufferedImage image = ImageToAwt.convert(img, false, false, 0);
                        ByteArrayOutputStream out = new ByteArrayOutputStream();
                        ImageWriter imgWrtr = ImageIO.getImageWritersByFormatName("png").next();
                        ImageOutputStream imgOutStrm;
                        imgOutStrm = ImageIO.createImageOutputStream(out);
                        imgWrtr.setOutput(imgOutStrm);
                        ImageWriteParam jpgWrtPrm = imgWrtr.getDefaultWriteParam();
                        imgWrtr.write(null, new IIOImage(image, null, null), jpgWrtPrm);
                        imgOutStrm.close();
                        out.close();
                        String texturePath = material.getName();
                        texturePath = "Textures/" + texturePath + "-" + param.getName() + ".png";
                        StoreTextureWizardWizardAction act = new StoreTextureWizardWizardAction(manager, out.toByteArray(), texturePath);
                        act.actionPerformed(null);
                        texturePath = act.getName();
                        TextureKey texKey = new TextureKey(texturePath);
                        TextureKey oldKey = (TextureKey)tex.getKey();
                        if(oldKey!=null){
                            Beans.copyProperties(texKey, oldKey);
                        }
                        //TODO: seems like flip is removed due to ImageToAwt
                        texKey.setFlipY(false);
                        Texture texture = manager.loadTexture(texKey);
                        MatParamTexture newParam = new MatParamTexture(texParam.getVarType(), texParam.getName(), texture, null);
                        materialParameters.put(newParam.getName(), new MaterialProperty(newParam));
                    } catch (Exception ex) {
                        Exceptions.printStackTrace(ex);
                    }
                    break;
                default:
            }
        } else {
            materialParameters.put(param.getName(), prop);
        }
    }
}
 
开发者ID:jMonkeyEngine,项目名称:sdk,代码行数:63,代码来源:EditableMaterialFile.java


示例18: getImage

import jme3tools.converters.ImageToAwt; //导入依赖的package包/类
public static BufferedImage getImage(Image img){
    return createFlipped(ImageToAwt.convert(img, false, false, 0));
}
 
开发者ID:MultiverseKing,项目名称:HexGrid_JME,代码行数:4,代码来源:ImageConverter.java


示例19: doCreateTerrain

import jme3tools.converters.ImageToAwt; //导入依赖的package包/类
protected Spatial doCreateTerrain(Node parent,
                                   int totalSize,
                                   int patchSize,
                                   int alphaTextureSize,
                                   float[] heightmapData,
                                   String sceneName,
                                   org.openide.nodes.Node selectedNode) throws IOException
   {
       final ProjectAssetManager manager = selectedNode.getLookup().lookup(ProjectAssetManager.class);
       
       Terrain terrain = new TerrainQuad("terrain-"+sceneName, patchSize, totalSize, heightmapData); //TODO make this pluggable for different Terrain implementations
       com.jme3.material.Material mat = new com.jme3.material.Material(manager, "Common/MatDefs/Terrain/TerrainLighting.j3md");

       String assetFolder = "";
       if (manager != null && manager instanceof ProjectAssetManager)
           assetFolder = ((ProjectAssetManager)manager).getAssetFolderName();

       // write out 3 alpha blend images
       for (int i=0; i<TerrainEditorController.NUM_ALPHA_TEXTURES; i++) {
           BufferedImage alphaBlend = new BufferedImage(alphaTextureSize, alphaTextureSize, BufferedImage.TYPE_INT_ARGB);
           if (i == 0) {
               // the first alpha level should be opaque so we see the first texture over the whole terrain
               for (int h=0; h<alphaTextureSize; h++)
                   for (int w=0; w<alphaTextureSize; w++)
                       alphaBlend.setRGB(w, h, 0x00FF0000);//argb
           }
           File alphaFolder = new File(assetFolder+"/Textures/terrain-alpha/");
           if (!alphaFolder.exists())
               alphaFolder.mkdir();
           String alphaBlendFileName = "/Textures/terrain-alpha/"+sceneName+"-"+((Node)terrain).getName()+"-alphablend"+i+".png";
           File alphaImageFile = new File(assetFolder+alphaBlendFileName);
           ImageIO.write(alphaBlend, "png", alphaImageFile);
           Texture tex = manager.loadAsset(new TextureKey(alphaBlendFileName, false));
           if (i == 0)
               mat.setTexture("AlphaMap", tex);
           else if (i == 1)
               mat.setTexture("AlphaMap_1", tex);
           else if (i == 2)
               mat.setTexture("AlphaMap_2", tex);
       }
       
       Texture defaultTexture = manager.loadTexture(TerrainEditorController.DEFAULT_TERRAIN_TEXTURE);
       
       // copy the default texture to the assets folder if it doesn't exist there yet
       String dirtTextureName = "/Textures/dirt.jpg";
       File dirtTextureFile = new File(assetFolder+dirtTextureName);
       if (!dirtTextureFile.exists()) {
           BufferedImage bi = ImageToAwt.convert(defaultTexture.getImage(), false, true, 0);
           ImageIO.write(bi, "jpg", dirtTextureFile);
       }
       // give the first layer default texture
       Texture dirtTexture = manager.loadTexture(dirtTextureName);
       dirtTexture.setWrap(WrapMode.Repeat);
       mat.setTexture("DiffuseMap", dirtTexture);
       mat.setFloat("DiffuseMap_0_scale", TerrainEditorController.DEFAULT_TEXTURE_SCALE);
       mat.setBoolean("WardIso", true);

       ((Node)terrain).setMaterial(mat);
       ((Node)terrain).setModelBound(new BoundingBox());
       ((Node)terrain).updateModelBound();
       ((Node)terrain).setLocalTranslation(0, 0, 0);
       ((Node)terrain).setLocalScale(1f, 1f, 1f);

       // add the lod control
       TerrainLodControl control = new TerrainLodControl(terrain, SceneApplication.getApplication().getCamera());
       control.setLodCalculator(new DistanceLodCalculator(patchSize, 2.7f));
((Node)terrain).addControl(control);

       parent.attachChild((Node)terrain);

       //setNeedsSave(true);
       //addSpatialUndo(parent, (Node)terrain, jmeNodeParent);
       
       return (Spatial)terrain;
   }
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:76,代码来源:AddTerrainAction.java



注:本文中的jme3tools.converters.ImageToAwt类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java WebUtil类代码示例发布时间:2022-05-23
下一篇:
Java SWTBotEditor类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap