Search in sources :

Example 21 with Format

use of com.jme3.scene.VertexBuffer.Format in project jmonkeyengine by jMonkeyEngine.

the class TextureAtlas method convertImageToAwt.

private Image convertImageToAwt(Image source) {
    //use awt dependent classes without actual dependency via reflection
    try {
        Class clazz = Class.forName("jme3tools.converters.ImageToAwt");
        if (clazz == null) {
            return null;
        }
        Image newImage = new Image(format, source.getWidth(), source.getHeight(), BufferUtils.createByteBuffer(source.getWidth() * source.getHeight() * 4), null, ColorSpace.Linear);
        clazz.getMethod("convert", Image.class, Image.class).invoke(clazz.newInstance(), source, newImage);
        return newImage;
    } catch (InstantiationException ex) {
    } catch (IllegalAccessException ex) {
    } catch (IllegalArgumentException ex) {
    } catch (InvocationTargetException ex) {
    } catch (NoSuchMethodException ex) {
    } catch (SecurityException ex) {
    } catch (ClassNotFoundException ex) {
    }
    return null;
}
Also used : Image(com.jme3.texture.Image) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 22 with Format

use of com.jme3.scene.VertexBuffer.Format in project jmonkeyengine by jMonkeyEngine.

the class TextureAtlas method getAtlasTexture.

/**
     * Creates a new atlas texture for the given map name.
     * @param mapName
     * @return the atlas texture
     */
public Texture getAtlasTexture(String mapName) {
    if (images == null) {
        return null;
    }
    byte[] image = images.get(mapName);
    if (image != null) {
        //TODO check if color space shouldn't be sRGB
        Texture2D tex = new Texture2D(new Image(format, atlasWidth, atlasHeight, BufferUtils.createByteBuffer(image), null, ColorSpace.Linear));
        tex.setMagFilter(Texture.MagFilter.Bilinear);
        tex.setMinFilter(Texture.MinFilter.BilinearNearestMipMap);
        tex.setWrap(Texture.WrapMode.EdgeClamp);
        return tex;
    }
    return null;
}
Also used : Texture2D(com.jme3.texture.Texture2D) Image(com.jme3.texture.Image)

Example 23 with Format

use of com.jme3.scene.VertexBuffer.Format in project jmonkeyengine by jMonkeyEngine.

the class TextureAtlas method drawImage.

private void drawImage(Image source, int x, int y, String mapName) {
    if (images == null) {
        images = new HashMap<String, byte[]>();
    }
    byte[] image = images.get(mapName);
    //Texture Atlas should linearize the data if the source image isSRGB        
    if (image == null) {
        image = new byte[atlasWidth * atlasHeight * 4];
        images.put(mapName, image);
    }
    //TODO: all buffers?
    ByteBuffer sourceData = source.getData(0);
    int height = source.getHeight();
    int width = source.getWidth();
    Image newImage = null;
    for (int yPos = 0; yPos < height; yPos++) {
        for (int xPos = 0; xPos < width; xPos++) {
            int i = ((xPos + x) + (yPos + y) * atlasWidth) * 4;
            if (source.getFormat() == Format.ABGR8) {
                int j = (xPos + yPos * width) * 4;
                //a
                image[i] = sourceData.get(j);
                //b
                image[i + 1] = sourceData.get(j + 1);
                //g
                image[i + 2] = sourceData.get(j + 2);
                //r
                image[i + 3] = sourceData.get(j + 3);
            } else if (source.getFormat() == Format.BGR8) {
                int j = (xPos + yPos * width) * 3;
                //a
                image[i] = 1;
                //b
                image[i + 1] = sourceData.get(j);
                //g
                image[i + 2] = sourceData.get(j + 1);
                //r
                image[i + 3] = sourceData.get(j + 2);
            } else if (source.getFormat() == Format.RGB8) {
                int j = (xPos + yPos * width) * 3;
                //a
                image[i] = 1;
                //b
                image[i + 1] = sourceData.get(j + 2);
                //g
                image[i + 2] = sourceData.get(j + 1);
                //r
                image[i + 3] = sourceData.get(j);
            } else if (source.getFormat() == Format.RGBA8) {
                int j = (xPos + yPos * width) * 4;
                //a
                image[i] = sourceData.get(j + 3);
                //b
                image[i + 1] = sourceData.get(j + 2);
                //g
                image[i + 2] = sourceData.get(j + 1);
                //r
                image[i + 3] = sourceData.get(j);
            } else if (source.getFormat() == Format.Luminance8) {
                int j = (xPos + yPos * width) * 1;
                //a
                image[i] = 1;
                //b
                image[i + 1] = sourceData.get(j);
                //g
                image[i + 2] = sourceData.get(j);
                //r
                image[i + 3] = sourceData.get(j);
            } else if (source.getFormat() == Format.Luminance8Alpha8) {
                int j = (xPos + yPos * width) * 2;
                //a
                image[i] = sourceData.get(j + 1);
                //b
                image[i + 1] = sourceData.get(j);
                //g
                image[i + 2] = sourceData.get(j);
                //r
                image[i + 3] = sourceData.get(j);
            } else {
                //ImageToAwt conversion
                if (newImage == null) {
                    newImage = convertImageToAwt(source);
                    if (newImage != null) {
                        source = newImage;
                        sourceData = source.getData(0);
                        int j = (xPos + yPos * width) * 4;
                        //a
                        image[i] = sourceData.get(j);
                        //b
                        image[i + 1] = sourceData.get(j + 1);
                        //g
                        image[i + 2] = sourceData.get(j + 2);
                        //r
                        image[i + 3] = sourceData.get(j + 3);
                    } else {
                        throw new UnsupportedOperationException("Cannot draw or convert textures with format " + source.getFormat());
                    }
                } else {
                    throw new UnsupportedOperationException("Cannot draw textures with format " + source.getFormat());
                }
            }
        }
    }
}
Also used : Image(com.jme3.texture.Image) ByteBuffer(java.nio.ByteBuffer)

Example 24 with Format

use of com.jme3.scene.VertexBuffer.Format in project jmonkeyengine by jMonkeyEngine.

the class OGLESContext method createView.

/**
     * <code>createView</code> creates the GLSurfaceView that the renderer will
     * draw to. <p> The result GLSurfaceView will receive input events and
     * forward them to the Application. Any rendering will be done into the
     * GLSurfaceView. Only one GLSurfaceView can be created at this time. The
     * given configType specifies how to determine the display configuration.
     *
     * @return GLSurfaceView The newly created view
     */
public GLSurfaceView createView(Context context) {
    // NOTE: We assume all ICS devices have OpenGL ES 2.0.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // below 4.0, check OpenGL ES 2.0 support.
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        ConfigurationInfo info = am.getDeviceConfigurationInfo();
        if (info.reqGlEsVersion < 0x20000) {
            throw new UnsupportedOperationException("OpenGL ES 2.0 is not supported on this device");
        }
    } else if (Build.VERSION.SDK_INT < 9) {
        throw new UnsupportedOperationException("jME3 requires Android 2.3 or later");
    }
    // Start to set up the view
    GLSurfaceView view = new GLSurfaceView(context);
    logger.log(Level.INFO, "Android Build Version: {0}", Build.VERSION.SDK_INT);
    if (androidInput == null) {
        if (Build.VERSION.SDK_INT >= 14) {
            androidInput = new AndroidInputHandler14();
        } else if (Build.VERSION.SDK_INT >= 9) {
            androidInput = new AndroidInputHandler();
        }
    }
    androidInput.setView(view);
    androidInput.loadSettings(settings);
    // setEGLContextClientVersion must be set before calling setRenderer
    // this means it cannot be set in AndroidConfigChooser (too late)
    view.setEGLContextClientVersion(2);
    view.setFocusableInTouchMode(true);
    view.setFocusable(true);
    // setFormat must be set before AndroidConfigChooser is called by the surfaceview.
    // if setFormat is called after ConfigChooser is called, then execution
    // stops at the setFormat call without a crash.
    // We look at the user setting for alpha bits and set the surfaceview
    // PixelFormat to either Opaque, Transparent, or Translucent.
    // ConfigChooser will do it's best to honor the alpha requested by the user
    // For best rendering performance, use Opaque (alpha bits = 0).
    int curAlphaBits = settings.getAlphaBits();
    logger.log(Level.FINE, "curAlphaBits: {0}", curAlphaBits);
    if (curAlphaBits >= 8) {
        logger.log(Level.FINE, "Pixel Format: TRANSLUCENT");
        view.getHolder().setFormat(PixelFormat.TRANSLUCENT);
        view.setZOrderOnTop(true);
    } else if (curAlphaBits >= 1) {
        logger.log(Level.FINE, "Pixel Format: TRANSPARENT");
        view.getHolder().setFormat(PixelFormat.TRANSPARENT);
    } else {
        logger.log(Level.FINE, "Pixel Format: OPAQUE");
        view.getHolder().setFormat(PixelFormat.OPAQUE);
    }
    AndroidConfigChooser configChooser = new AndroidConfigChooser(settings);
    view.setEGLConfigChooser(configChooser);
    view.setRenderer(this);
    // reloading all the OpenGL objects.
    if (Build.VERSION.SDK_INT >= 11) {
        view.setPreserveEGLContextOnPause(true);
    }
    return view;
}
Also used : AndroidInputHandler(com.jme3.input.android.AndroidInputHandler) AndroidInputHandler14(com.jme3.input.android.AndroidInputHandler14) ActivityManager(android.app.ActivityManager) GLSurfaceView(android.opengl.GLSurfaceView) ConfigurationInfo(android.content.pm.ConfigurationInfo)

Example 25 with Format

use of com.jme3.scene.VertexBuffer.Format in project chordatlas by twak.

the class MiniGen method inBounds.

private boolean inBounds(Matrix4d mini, List<double[]> bounds) {
    // mini matrix is in mini-mesh format: a translation from a 255^3 cube in the first quadrant
    // trans.offset is a transform from that space, into jme rendered space (cartesian in meters, around the origin)
    Matrix4d m = new Matrix4d();
    m.mul(Jme3z.fromMatrix(trans.offset), mini);
    for (Point2d p : Arrays.stream(cubeCorners).map(c -> {
        Point3d tmp = new Point3d();
        m.transform(c, tmp);
        return new Point2d(tmp.x, tmp.z);
    }).collect(Collectors.toList())) {
        for (double[] bound : bounds) {
            if (bound[0] < p.x && bound[1] > p.x && bound[2] < p.y && bound[3] > p.y)
                return true;
        }
    }
    return false;
}
Also used : Matrix4d(javax.vecmath.Matrix4d) XStream(com.thoughtworks.xstream.XStream) Arrays(java.util.Arrays) Matrix4d(javax.vecmath.Matrix4d) Face(org.twak.utils.geom.ObjDump.Face) Mode(com.jme3.scene.Mesh.Mode) Tuple3d(javax.vecmath.Tuple3d) MiniTransform(org.twak.readTrace.MiniTransform) Loop(org.twak.utils.collections.Loop) Node(com.jme3.scene.Node) AlignTool(org.twak.tweed.tools.AlignTool) Map(java.util.Map) Material(com.jme3.material.Material) ChangeListener(javax.swing.event.ChangeListener) Point3d(javax.vecmath.Point3d) ChangeEvent(javax.swing.event.ChangeEvent) ListDownLayout(org.twak.utils.ui.ListDownLayout) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) List(java.util.List) JSlider(javax.swing.JSlider) JCheckBox(javax.swing.JCheckBox) Mesh(com.jme3.scene.Mesh) JPanel(javax.swing.JPanel) Geometry(com.jme3.scene.Geometry) ActionListener(java.awt.event.ActionListener) LinearForm3D(org.twak.utils.geom.LinearForm3D) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) Pair(org.twak.utils.Pair) Vector3d(javax.vecmath.Vector3d) Filez(org.twak.utils.Filez) Tweed(org.twak.tweed.Tweed) ArrayList(java.util.ArrayList) Spatial(com.jme3.scene.Spatial) JComponent(javax.swing.JComponent) JButton(javax.swing.JButton) Files(java.nio.file.Files) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) BlendMode(com.jme3.material.RenderState.BlendMode) ActionEvent(java.awt.event.ActionEvent) File(java.io.File) Loopz(org.twak.utils.collections.Loopz) Point2d(javax.vecmath.Point2d) Jme3z(org.twak.siteplan.jme.Jme3z) EventMoveHandle(org.twak.tweed.EventMoveHandle) HandleMe(org.twak.tweed.handles.HandleMe) ObjDump(org.twak.utils.geom.ObjDump) ModelKey(com.jme3.asset.ModelKey) ColorRGBA(com.jme3.math.ColorRGBA) Collections(java.util.Collections) Transform(com.jme3.math.Transform) Point2d(javax.vecmath.Point2d) Point3d(javax.vecmath.Point3d)

Aggregations

Image (com.jme3.texture.Image)20 ByteBuffer (java.nio.ByteBuffer)19 Format (com.jme3.texture.Image.Format)13 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)8 ColorRGBA (com.jme3.math.ColorRGBA)7 BufferedImage (java.awt.image.BufferedImage)7 TextureCubeMap (com.jme3.texture.TextureCubeMap)6 Vector3f (com.jme3.math.Vector3f)4 TexturePixel (com.jme3.scene.plugins.blender.textures.TexturePixel)4 PixelInputOutput (com.jme3.scene.plugins.blender.textures.io.PixelInputOutput)4 Texture2D (com.jme3.texture.Texture2D)4 DataInputStream (java.io.DataInputStream)4 AssetNotFoundException (com.jme3.asset.AssetNotFoundException)3 LittleEndien (com.jme3.util.LittleEndien)3 InputStream (java.io.InputStream)3 TextureKey (com.jme3.asset.TextureKey)2 VRAPI (com.jme3.input.vr.VRAPI)2 MatParam (com.jme3.material.MatParam)2 Material (com.jme3.material.Material)2