Search in sources :

Example 46 with Type

use of com.jme3.effect.ParticleMesh.Type in project jmonkeyengine by jMonkeyEngine.

the class MatParam method getValueAsString.

/**
     * Returns the material parameter value as it would appear in a J3M
     * file. E.g.<br/>
     * <code>
     * MaterialParameters {<br/>
     *     ABC : 1 2 3 4<br/>
     * }<br/>
     * </code>
     * Assuming "ABC" is a Vector4 parameter, then the value
     * "1 2 3 4" would be returned by this method.
     * <br/><br/>
     * @return material parameter value as it would appear in a J3M file.
     */
public String getValueAsString() {
    switch(type) {
        case Boolean:
        case Float:
        case Int:
            return value.toString();
        case Vector2:
            Vector2f v2 = (Vector2f) value;
            return v2.getX() + " " + v2.getY();
        /* 
This may get used at a later point of time
When arrays can be inserted in J3M files

            case Vector2Array:
                Vector2f[] v2Arr = (Vector2f[]) value;
                String v2str = "";
                for (int i = 0; i < v2Arr.length ; i++) {
                    v2str += v2Arr[i].getX() + " " + v2Arr[i].getY() + "\n";
                }
                return v2str;
*/
        case Vector3:
            Vector3f v3 = (Vector3f) value;
            return v3.getX() + " " + v3.getY() + " " + v3.getZ();
        /*
            case Vector3Array:
                Vector3f[] v3Arr = (Vector3f[]) value;
                String v3str = "";
                for (int i = 0; i < v3Arr.length ; i++) {
                    v3str += v3Arr[i].getX() + " "
                            + v3Arr[i].getY() + " "
                            + v3Arr[i].getZ() + "\n";
                }
                return v3str;
            case Vector4Array:
                // can be either ColorRGBA, Vector4f or Quaternion
                if (value instanceof Vector4f) {
                    Vector4f[] v4arr = (Vector4f[]) value;
                    String v4str = "";
                    for (int i = 0; i < v4arr.length ; i++) {
                        v4str += v4arr[i].getX() + " "
                                + v4arr[i].getY() + " "
                                + v4arr[i].getZ() + " "
                                + v4arr[i].getW() + "\n";
                    }
                    return v4str;
                } else if (value instanceof ColorRGBA) {
                    ColorRGBA[] colorArr = (ColorRGBA[]) value;
                    String colStr = "";
                    for (int i = 0; i < colorArr.length ; i++) {
                        colStr += colorArr[i].getRed() + " "
                                + colorArr[i].getGreen() + " "
                                + colorArr[i].getBlue() + " "
                                + colorArr[i].getAlpha() + "\n";
                    }
                    return colStr;
                } else if (value instanceof Quaternion) {
                    Quaternion[] quatArr = (Quaternion[]) value;
                    String quatStr = "";
                    for (int i = 0; i < quatArr.length ; i++) {
                        quatStr += quatArr[i].getX() + " "
                                + quatArr[i].getY() + " "
                                + quatArr[i].getZ() + " "
                                + quatArr[i].getW() + "\n";
                    }
                    return quatStr;
                } else {
                    throw new UnsupportedOperationException("Unexpected Vector4Array type: " + value);
                }
*/
        case Vector4:
            // can be either ColorRGBA, Vector4f or Quaternion
            if (value instanceof Vector4f) {
                Vector4f v4 = (Vector4f) value;
                return v4.getX() + " " + v4.getY() + " " + v4.getZ() + " " + v4.getW();
            } else if (value instanceof ColorRGBA) {
                ColorRGBA color = (ColorRGBA) value;
                return color.getRed() + " " + color.getGreen() + " " + color.getBlue() + " " + color.getAlpha();
            } else if (value instanceof Quaternion) {
                Quaternion quat = (Quaternion) value;
                return quat.getX() + " " + quat.getY() + " " + quat.getZ() + " " + quat.getW();
            } else {
                throw new UnsupportedOperationException("Unexpected Vector4 type: " + value);
            }
        case Texture2D:
        case Texture3D:
        case TextureArray:
        case TextureBuffer:
        case TextureCubeMap:
            Texture texVal = (Texture) value;
            TextureKey texKey = (TextureKey) texVal.getKey();
            if (texKey == null) {
                // often does as well, even implicitly. 
                return texVal + ":returned null key";
            }
            String ret = "";
            if (texKey.isFlipY()) {
                ret += "Flip ";
            }
            //Wrap mode
            ret += getWrapMode(texVal, Texture.WrapAxis.S);
            ret += getWrapMode(texVal, Texture.WrapAxis.T);
            ret += getWrapMode(texVal, Texture.WrapAxis.R);
            //Min and Mag filter
            Texture.MinFilter def = Texture.MinFilter.BilinearNoMipMaps;
            if (texVal.getImage().hasMipmaps() || texKey.isGenerateMips()) {
                def = Texture.MinFilter.Trilinear;
            }
            if (texVal.getMinFilter() != def) {
                ret += "Min" + texVal.getMinFilter().name() + " ";
            }
            if (texVal.getMagFilter() != Texture.MagFilter.Bilinear) {
                ret += "Mag" + texVal.getMagFilter().name() + " ";
            }
            return ret + "\"" + texKey.getName() + "\"";
        default:
            // parameter type not supported in J3M
            return null;
    }
}
Also used : TextureKey(com.jme3.asset.TextureKey) Texture(com.jme3.texture.Texture)

Example 47 with Type

use of com.jme3.effect.ParticleMesh.Type in project jmonkeyengine by jMonkeyEngine.

the class Material method setTexture.

/**
     * Pass a texture to the material shader.
     *
     * @param name the name of the texture defined in the material definition
     * (j3md) (for example Texture for Lighting.j3md)
     * @param value the Texture object previously loaded by the asset manager
     */
public void setTexture(String name, Texture value) {
    if (value == null) {
        // clear it
        clearParam(name);
        return;
    }
    VarType paramType = null;
    switch(value.getType()) {
        case TwoDimensional:
            paramType = VarType.Texture2D;
            break;
        case TwoDimensionalArray:
            paramType = VarType.TextureArray;
            break;
        case ThreeDimensional:
            paramType = VarType.Texture3D;
            break;
        case CubeMap:
            paramType = VarType.TextureCubeMap;
            break;
        default:
            throw new UnsupportedOperationException("Unknown texture type: " + value.getType());
    }
    setTextureParam(name, paramType, value);
}
Also used : VarType(com.jme3.shader.VarType)

Example 48 with Type

use of com.jme3.effect.ParticleMesh.Type in project jmonkeyengine by jMonkeyEngine.

the class ParticleEmitter method read.

@Override
public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule ic = im.getCapsule(this);
    shape = (EmitterShape) ic.readSavable("shape", DEFAULT_SHAPE);
    if (shape == DEFAULT_SHAPE) {
        // Prevent reference to static
        shape = shape.deepClone();
    }
    meshType = ic.readEnum("meshType", ParticleMesh.Type.class, ParticleMesh.Type.Triangle);
    int numParticles = ic.readInt("numParticles", 0);
    enabled = ic.readBoolean("enabled", true);
    particlesPerSec = ic.readFloat("particlesPerSec", 0);
    lowLife = ic.readFloat("lowLife", 0);
    highLife = ic.readFloat("highLife", 0);
    gravity = (Vector3f) ic.readSavable("gravity", null);
    imagesX = ic.readInt("imagesX", 1);
    imagesY = ic.readInt("imagesY", 1);
    startColor = (ColorRGBA) ic.readSavable("startColor", null);
    endColor = (ColorRGBA) ic.readSavable("endColor", null);
    startSize = ic.readFloat("startSize", 0);
    endSize = ic.readFloat("endSize", 0);
    worldSpace = ic.readBoolean("worldSpace", false);
    this.setIgnoreTransform(worldSpace);
    facingVelocity = ic.readBoolean("facingVelocity", false);
    faceNormal = (Vector3f) ic.readSavable("faceNormal", new Vector3f(Vector3f.NAN));
    selectRandomImage = ic.readBoolean("selectRandomImage", false);
    randomAngle = ic.readBoolean("randomAngle", false);
    rotateSpeed = ic.readFloat("rotateSpeed", 0);
    switch(meshType) {
        case Point:
            particleMesh = new ParticlePointMesh();
            this.setMesh(particleMesh);
            break;
        case Triangle:
            particleMesh = new ParticleTriMesh();
            this.setMesh(particleMesh);
            break;
        default:
            throw new IllegalStateException("Unrecognized particle type: " + meshType);
    }
    this.setNumParticles(numParticles);
    //        particleMesh.initParticleData(this, particles.length);
    //        particleMesh.setImagesXY(imagesX, imagesY);
    particleInfluencer = (ParticleInfluencer) ic.readSavable("influencer", DEFAULT_INFLUENCER);
    if (particleInfluencer == DEFAULT_INFLUENCER) {
        particleInfluencer = particleInfluencer.clone();
    }
    if (im.getFormatVersion() == 0) {
        // find it in the controls and take it out, then add the proper one in
        for (int i = 0; i < controls.size(); i++) {
            Object obj = controls.get(i);
            if (obj instanceof ParticleEmitter) {
                controls.remove(i);
                // now add the proper one in
                controls.add(new ParticleEmitterControl(this));
                break;
            }
        }
        // compatability before gravity was not a vector but a float
        if (gravity == null) {
            gravity = new Vector3f();
            gravity.y = ic.readFloat("gravity", 0);
        }
    } else {
        // since the parentEmitter is not loaded, it must be
        // loaded separately
        control = getControl(ParticleEmitterControl.class);
        control.parentEmitter = this;
    }
}
Also used : Type(com.jme3.effect.ParticleMesh.Type) InputCapsule(com.jme3.export.InputCapsule) Vector3f(com.jme3.math.Vector3f)

Example 49 with Type

use of com.jme3.effect.ParticleMesh.Type in project jmonkeyengine by jMonkeyEngine.

the class LwjglContext method initOpenCL.

protected void initOpenCL(long window) {
    logger.info("Initialize OpenCL with LWJGL3");
    //        try {
    //            CL.create();
    //        } catch (Exception ex) {
    //            logger.log(Level.SEVERE, "Unable to initialize OpenCL", ex);
    //            return;
    //        }
    //load platforms and devices
    StringBuilder platformInfos = new StringBuilder();
    ArrayList<LwjglPlatform> platforms = new ArrayList<>();
    for (long p : getPlatforms()) {
        platforms.add(new LwjglPlatform(p));
    }
    platformInfos.append("Available OpenCL platforms:");
    for (int i = 0; i < platforms.size(); ++i) {
        LwjglPlatform platform = platforms.get(i);
        platformInfos.append("\n * Platform ").append(i + 1);
        platformInfos.append("\n *   Name: ").append(platform.getName());
        platformInfos.append("\n *   Vendor: ").append(platform.getVendor());
        platformInfos.append("\n *   Version: ").append(platform.getVersion());
        platformInfos.append("\n *   Profile: ").append(platform.getProfile());
        platformInfos.append("\n *   Supports interop: ").append(platform.hasOpenGLInterop());
        List<LwjglDevice> devices = platform.getDevices();
        platformInfos.append("\n *   Available devices:");
        for (int j = 0; j < devices.size(); ++j) {
            LwjglDevice device = devices.get(j);
            platformInfos.append("\n *    * Device ").append(j + 1);
            platformInfos.append("\n *    *   Name: ").append(device.getName());
            platformInfos.append("\n *    *   Vendor: ").append(device.getVendor());
            platformInfos.append("\n *    *   Version: ").append(device.getVersion());
            platformInfos.append("\n *    *   Profile: ").append(device.getProfile());
            platformInfos.append("\n *    *   Compiler version: ").append(device.getCompilerVersion());
            platformInfos.append("\n *    *   Device type: ").append(device.getDeviceType());
            platformInfos.append("\n *    *   Compute units: ").append(device.getComputeUnits());
            platformInfos.append("\n *    *   Work group size: ").append(device.getMaxiumWorkItemsPerGroup());
            platformInfos.append("\n *    *   Global memory: ").append(device.getGlobalMemorySize()).append("B");
            platformInfos.append("\n *    *   Local memory: ").append(device.getLocalMemorySize()).append("B");
            platformInfos.append("\n *    *   Constant memory: ").append(device.getMaximumConstantBufferSize()).append("B");
            platformInfos.append("\n *    *   Supports double: ").append(device.hasDouble());
            platformInfos.append("\n *    *   Supports half floats: ").append(device.hasHalfFloat());
            platformInfos.append("\n *    *   Supports writable 3d images: ").append(device.hasWritableImage3D());
            platformInfos.append("\n *    *   Supports interop: ").append(device.hasOpenGLInterop());
        }
    }
    logger.info(platformInfos.toString());
    //choose devices
    PlatformChooser chooser = null;
    if (settings.getOpenCLPlatformChooser() != null) {
        try {
            chooser = (PlatformChooser) Class.forName(settings.getOpenCLPlatformChooser()).newInstance();
        } catch (Exception ex) {
            logger.log(Level.WARNING, "unable to instantiate custom PlatformChooser", ex);
        }
    }
    if (chooser == null) {
        chooser = new DefaultPlatformChooser();
    }
    List<? extends Device> choosenDevices = chooser.chooseDevices(platforms);
    List<Long> devices = new ArrayList<>(choosenDevices.size());
    LwjglPlatform platform = null;
    for (Device d : choosenDevices) {
        if (!(d instanceof LwjglDevice)) {
            logger.log(Level.SEVERE, "attempt to return a custom Device implementation from PlatformChooser: {0}", d);
            return;
        }
        LwjglDevice ld = (LwjglDevice) d;
        if (platform == null) {
            platform = ld.getPlatform();
        } else if (platform != ld.getPlatform()) {
            logger.severe("attempt to use devices from different platforms");
            return;
        }
        devices.add(ld.getDevice());
    }
    if (devices.isEmpty()) {
        logger.warning("no devices specified, no OpenCL context created");
        return;
    }
    logger.log(Level.INFO, "chosen platform: {0}", platform.getName());
    logger.log(Level.INFO, "chosen devices: {0}", choosenDevices);
    //create context
    try {
        long c = createContext(platform.getPlatform(), devices, window);
        clContext = new com.jme3.opencl.lwjgl.LwjglContext(c, (List<LwjglDevice>) choosenDevices);
    } catch (final Exception ex) {
        logger.log(Level.SEVERE, "Unable to create OpenCL context", ex);
        return;
    }
    logger.info("OpenCL context created");
}
Also used : Device(com.jme3.opencl.Device) LwjglDevice(com.jme3.opencl.lwjgl.LwjglDevice) ArrayList(java.util.ArrayList) PlatformChooser(com.jme3.opencl.PlatformChooser) DefaultPlatformChooser(com.jme3.opencl.DefaultPlatformChooser) RendererException(com.jme3.renderer.RendererException) LwjglDevice(com.jme3.opencl.lwjgl.LwjglDevice) LwjglPlatform(com.jme3.opencl.lwjgl.LwjglPlatform) List(java.util.List) ArrayList(java.util.ArrayList) DefaultPlatformChooser(com.jme3.opencl.DefaultPlatformChooser)

Example 50 with Type

use of com.jme3.effect.ParticleMesh.Type in project jmonkeyengine by jMonkeyEngine.

the class LwjglContext method querySupportedFormats.

@Override
public ImageFormat[] querySupportedFormats(MemoryAccess access, Image.ImageType type) {
    long memFlags = Utils.getMemoryAccessFlags(access);
    int typeFlag = LwjglImage.decodeImageType(type);
    Utils.tempBuffers[0].b16i.rewind();
    //query count
    int ret = CL10.clGetSupportedImageFormats(context, memFlags, typeFlag, null, Utils.tempBuffers[0].b16i);
    Utils.checkError(ret, "clGetSupportedImageFormats");
    int count = Utils.tempBuffers[0].b16i.get(0);
    if (count == 0) {
        return new ImageFormat[0];
    }
    //get formats
    CLImageFormat.Buffer formatsB = new CLImageFormat.Buffer(BufferUtils.createByteBuffer(count * CLImageFormat.SIZEOF));
    ret = CL10.clGetSupportedImageFormats(context, memFlags, typeFlag, formatsB, (IntBuffer) null);
    Utils.checkError(ret, "clGetSupportedImageFormats");
    //convert formats
    ImageFormat[] formats = new ImageFormat[count];
    for (int i = 0; i < count; ++i) {
        CLImageFormat f = formatsB.get();
        Image.ImageChannelOrder channelOrder = LwjglImage.encodeImageChannelOrder(f.image_channel_order());
        Image.ImageChannelType channelType = LwjglImage.encodeImageChannelType(f.image_channel_data_type());
        formats[i] = new ImageFormat(channelOrder, channelType);
    }
    return formats;
}
Also used : VertexBuffer(com.jme3.scene.VertexBuffer) FrameBuffer(com.jme3.texture.FrameBuffer) ByteBuffer(java.nio.ByteBuffer) IntBuffer(java.nio.IntBuffer) IntBuffer(java.nio.IntBuffer) ImageFormat(com.jme3.opencl.Image.ImageFormat)

Aggregations

ArrayList (java.util.ArrayList)18 Structure (com.jme3.scene.plugins.blender.file.Structure)12 Vector3f (com.jme3.math.Vector3f)11 Pointer (com.jme3.scene.plugins.blender.file.Pointer)10 IOException (java.io.IOException)10 List (java.util.List)9 ColorRGBA (com.jme3.math.ColorRGBA)8 Texture (com.jme3.texture.Texture)8 Geometry (com.jme3.scene.Geometry)6 Image (com.jme3.texture.Image)6 BoundingBox (com.jme3.bounding.BoundingBox)5 BoundingSphere (com.jme3.bounding.BoundingSphere)5 Light (com.jme3.light.Light)5 TemporalMesh (com.jme3.scene.plugins.blender.meshes.TemporalMesh)5 Uniform (com.jme3.shader.Uniform)5 Material (com.jme3.material.Material)4 Quaternion (com.jme3.math.Quaternion)4 Transform (com.jme3.math.Transform)4 Mesh (com.jme3.scene.Mesh)4 BlenderFileException (com.jme3.scene.plugins.blender.file.BlenderFileException)4