Search in sources :

Example 41 with Type

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

the class JoclContext method querySupportedFormats.

@Override
public ImageFormat[] querySupportedFormats(MemoryAccess access, Image.ImageType type) {
    if (type != Image.ImageType.IMAGE_2D && type != Image.ImageType.IMAGE_3D) {
        throw new UnsupportedOperationException("Jocl only supports 2D and 3D images");
    }
    long memFlags = Utils.getMemoryAccessFlags(access);
    CLImageFormat[] fx;
    if (type == Image.ImageType.IMAGE_2D) {
        fx = context.getSupportedImage2dFormats(Mem.valueOf((int) memFlags));
    } else {
        fx = context.getSupportedImage3dFormats(Mem.valueOf((int) memFlags));
    }
    //convert formats
    ImageFormat[] formats = new ImageFormat[fx.length];
    for (int i = 0; i < fx.length; ++i) {
        Image.ImageChannelOrder channelOrder = JoclImage.encodeImageChannelOrder(fx[i].getFormatImpl().getImageChannelOrder());
        Image.ImageChannelType channelType = JoclImage.encodeImageChannelType(fx[i].getFormatImpl().getImageChannelDataType());
        formats[i] = new ImageFormat(channelOrder, channelType);
    }
    return formats;
}
Also used : CLImageFormat(com.jogamp.opencl.CLImageFormat) ImageFormat(com.jme3.opencl.Image.ImageFormat) CLImageFormat(com.jogamp.opencl.CLImageFormat)

Example 42 with Type

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

the class CollisionShapeFactory method createSingleMeshShape.

/**
     * This type of collision shape is mesh-accurate and meant for immovable "world objects".
     * Examples include terrain, houses or whole shooter levels.<br>
     * Objects with "mesh" type collision shape will not collide with each other.
     */
private static MeshCollisionShape createSingleMeshShape(Geometry geom, Spatial parent) {
    Mesh mesh = geom.getMesh();
    Transform trans = getTransform(geom, parent);
    if (mesh != null && mesh.getMode() == Mesh.Mode.Triangles) {
        MeshCollisionShape mColl = new MeshCollisionShape(mesh);
        mColl.setScale(trans.getScale());
        return mColl;
    } else {
        return null;
    }
}
Also used : Transform(com.jme3.math.Transform)

Example 43 with Type

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

the class J3MLoader method parseTextureType.

private Texture parseTextureType(final VarType type, final String value) {
    final List<String> textureValues = tokenizeTextureValue(value);
    final List<TextureOptionValue> textureOptionValues = parseTextureOptions(textureValues);
    TextureKey textureKey = null;
    // If there is only one token on the value, it must be the path to the texture.
    if (textureValues.size() == 1) {
        textureKey = new TextureKey(textureValues.get(0), false);
    } else {
        String texturePath = value.trim();
        // If there are no valid "new" texture options specified but the path is split into several parts, lets parse the old way.
        if (isTexturePathDeclaredTheTraditionalWay(textureOptionValues, texturePath)) {
            boolean flipY = false;
            if (texturePath.startsWith("Flip Repeat ") || texturePath.startsWith("Repeat Flip ")) {
                texturePath = texturePath.substring(12).trim();
                flipY = true;
            } else if (texturePath.startsWith("Flip ")) {
                texturePath = texturePath.substring(5).trim();
                flipY = true;
            } else if (texturePath.startsWith("Repeat ")) {
                texturePath = texturePath.substring(7).trim();
            }
            // Support path starting with quotes (double and single)
            if (texturePath.startsWith("\"") || texturePath.startsWith("'")) {
                texturePath = texturePath.substring(1);
            }
            // Support path ending with quotes (double and single)
            if (texturePath.endsWith("\"") || texturePath.endsWith("'")) {
                texturePath = texturePath.substring(0, texturePath.length() - 1);
            }
            textureKey = new TextureKey(texturePath, flipY);
        }
        if (textureKey == null) {
            textureKey = new TextureKey(textureValues.get(textureValues.size() - 1), false);
        }
        // Apply texture options to the texture key
        if (!textureOptionValues.isEmpty()) {
            for (final TextureOptionValue textureOptionValue : textureOptionValues) {
                textureOptionValue.applyToTextureKey(textureKey);
            }
        }
    }
    switch(type) {
        case Texture3D:
            textureKey.setTextureTypeHint(Texture.Type.ThreeDimensional);
            break;
        case TextureArray:
            textureKey.setTextureTypeHint(Texture.Type.TwoDimensionalArray);
            break;
        case TextureCubeMap:
            textureKey.setTextureTypeHint(Texture.Type.CubeMap);
            break;
    }
    textureKey.setGenerateMips(true);
    Texture texture;
    try {
        texture = assetManager.loadTexture(textureKey);
    } catch (AssetNotFoundException ex) {
        logger.log(Level.WARNING, "Cannot locate {0} for material {1}", new Object[] { textureKey, key });
        texture = null;
    }
    if (texture == null) {
        texture = new Texture2D(PlaceholderAssets.getPlaceholderImage(assetManager));
        texture.setKey(textureKey);
        texture.setName(textureKey.getName());
    }
    // Apply texture options to the texture
    if (!textureOptionValues.isEmpty()) {
        for (final TextureOptionValue textureOptionValue : textureOptionValues) {
            textureOptionValue.applyToTexture(texture);
        }
    }
    return texture;
}
Also used : Texture2D(com.jme3.texture.Texture2D) Texture(com.jme3.texture.Texture)

Example 44 with Type

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

the class TangentBinormalGenerator method splitVertices.

//Don't remove splitmirorred boolean,It's not used right now, but i intend to
//make this method also split vertice with rotated tangent space and I'll
//add another splitRotated boolean 
private static List<VertexData> splitVertices(Mesh mesh, List<VertexData> vertexData, boolean splitMirorred) {
    int nbVertices = mesh.getBuffer(Type.Position).getNumElements();
    List<VertexData> newVertices = new ArrayList<VertexData>();
    Map<Integer, Integer> indiceMap = new HashMap<Integer, Integer>();
    FloatBuffer normalBuffer = mesh.getFloatBuffer(Type.Normal);
    for (int i = 0; i < vertexData.size(); i++) {
        ArrayList<TriangleData> triangles = vertexData.get(i).triangles;
        Vector3f givenNormal = new Vector3f();
        populateFromBuffer(givenNormal, normalBuffer, i);
        ArrayList<TriangleData> trianglesUp = new ArrayList<TriangleData>();
        ArrayList<TriangleData> trianglesDown = new ArrayList<TriangleData>();
        for (int j = 0; j < triangles.size(); j++) {
            TriangleData triangleData = triangles.get(j);
            if (parity(givenNormal, triangleData.normal) > 0) {
                trianglesUp.add(triangleData);
            } else {
                trianglesDown.add(triangleData);
            }
        }
        //if the vertex has triangles with opposite parity it has to be split
        if (!trianglesUp.isEmpty() && !trianglesDown.isEmpty()) {
            log.log(Level.FINE, "Splitting vertex {0}", i);
            //assigning triangle with the same parity to the original vertex
            vertexData.get(i).triangles.clear();
            vertexData.get(i).triangles.addAll(trianglesUp);
            //creating a new vertex
            VertexData newVert = new VertexData();
            //assigning triangles with opposite parity to it
            newVert.triangles.addAll(trianglesDown);
            newVertices.add(newVert);
            //keep vertex index to fix the index buffers later
            indiceMap.put(nbVertices, i);
            for (TriangleData tri : newVert.triangles) {
                for (int j = 0; j < tri.index.length; j++) {
                    if (tri.index[j] == i) {
                        tri.index[j] = nbVertices;
                    }
                }
            }
            nbVertices++;
        }
    }
    if (!newVertices.isEmpty()) {
        //we have new vertices, we need to update the mesh's buffers.
        for (Type type : VertexBuffer.Type.values()) {
            //skip tangent buffer as we're gonna overwrite it later
            if (type == Type.Tangent || type == Type.BindPoseTangent)
                continue;
            VertexBuffer vb = mesh.getBuffer(type);
            //They'll be initialized when Hardware Skinning is engaged
            if (vb == null || vb.getNumComponents() == 0)
                continue;
            Buffer buffer = vb.getData();
            //IndexBuffer has special treatement, only swapping the vertex indices is needed                
            if (type == Type.Index) {
                boolean isShortBuffer = vb.getFormat() == VertexBuffer.Format.UnsignedShort;
                for (VertexData vertex : newVertices) {
                    for (TriangleData tri : vertex.triangles) {
                        for (int i = 0; i < tri.index.length; i++) {
                            if (isShortBuffer) {
                                ((ShortBuffer) buffer).put(tri.triangleOffset + i, (short) tri.index[i]);
                            } else {
                                ((IntBuffer) buffer).put(tri.triangleOffset + i, tri.index[i]);
                            }
                        }
                    }
                }
                vb.setUpdateNeeded();
            } else {
                //copy the buffer in a bigger one and append nex vertices to the end
                Buffer newVerts = VertexBuffer.createBuffer(vb.getFormat(), vb.getNumComponents(), nbVertices);
                if (buffer != null) {
                    buffer.rewind();
                    bulkPut(vb.getFormat(), newVerts, buffer);
                    int index = vertexData.size();
                    newVerts.position(vertexData.size() * vb.getNumComponents());
                    for (int j = 0; j < newVertices.size(); j++) {
                        int oldInd = indiceMap.get(index);
                        for (int i = 0; i < vb.getNumComponents(); i++) {
                            putValue(vb.getFormat(), newVerts, buffer, oldInd * vb.getNumComponents() + i);
                        }
                        index++;
                    }
                    vb.updateData(newVerts);
                    //destroy previous buffer as it's no longer needed
                    destroyDirectBuffer(buffer);
                }
            }
        }
        vertexData.addAll(newVertices);
        mesh.updateCounts();
    }
    return vertexData;
}
Also used : FloatBuffer(java.nio.FloatBuffer) ShortBuffer(java.nio.ShortBuffer) IndexBuffer(com.jme3.scene.mesh.IndexBuffer) ByteBuffer(java.nio.ByteBuffer) IntBuffer(java.nio.IntBuffer) Buffer(java.nio.Buffer) DoubleBuffer(java.nio.DoubleBuffer) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FloatBuffer(java.nio.FloatBuffer) Type(com.jme3.scene.VertexBuffer.Type) Vector3f(com.jme3.math.Vector3f) IntBuffer(java.nio.IntBuffer) ShortBuffer(java.nio.ShortBuffer)

Example 45 with Type

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

the class BinaryExporter method save.

public void save(Savable object, OutputStream os) throws IOException {
    // reset some vars
    aliasCount = 1;
    idCount = 1;
    classes.clear();
    contentTable.clear();
    locationTable.clear();
    contentKeys.clear();
    // write signature and version
    os.write(ByteUtils.convertToBytes(FormatVersion.SIGNATURE));
    os.write(ByteUtils.convertToBytes(FormatVersion.VERSION));
    int id = processBinarySavable(object);
    // write out tag table
    int classTableSize = 0;
    int classNum = classes.keySet().size();
    // make all
    int aliasSize = ((int) FastMath.log(classNum, 256) + 1);
    // aliases a
    // fixed width
    os.write(ByteUtils.convertToBytes(classNum));
    for (String key : classes.keySet()) {
        BinaryClassObject bco = classes.get(key);
        // write alias
        byte[] aliasBytes = fixClassAlias(bco.alias, aliasSize);
        os.write(aliasBytes);
        classTableSize += aliasSize;
        // jME3 NEW: Write class hierarchy version numbers
        os.write(bco.classHierarchyVersions.length);
        for (int version : bco.classHierarchyVersions) {
            os.write(ByteUtils.convertToBytes(version));
        }
        classTableSize += 1 + bco.classHierarchyVersions.length * 4;
        // write classname size & classname
        byte[] classBytes = key.getBytes();
        os.write(ByteUtils.convertToBytes(classBytes.length));
        os.write(classBytes);
        classTableSize += 4 + classBytes.length;
        // for each field, write alias, type, and name
        os.write(ByteUtils.convertToBytes(bco.nameFields.size()));
        for (String fieldName : bco.nameFields.keySet()) {
            BinaryClassField bcf = bco.nameFields.get(fieldName);
            os.write(bcf.alias);
            os.write(bcf.type);
            // write classname size & classname
            byte[] fNameBytes = fieldName.getBytes();
            os.write(ByteUtils.convertToBytes(fNameBytes.length));
            os.write(fNameBytes);
            classTableSize += 2 + 4 + fNameBytes.length;
        }
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    // write out data to a seperate stream
    int location = 0;
    // keep track of location for each piece
    HashMap<String, ArrayList<BinaryIdContentPair>> alreadySaved = new HashMap<String, ArrayList<BinaryIdContentPair>>(contentTable.size());
    for (Savable savable : contentKeys) {
        // look back at previous written data for matches
        String savableName = savable.getClass().getName();
        BinaryIdContentPair pair = contentTable.get(savable);
        ArrayList<BinaryIdContentPair> bucket = alreadySaved.get(savableName + getChunk(pair));
        int prevLoc = findPrevMatch(pair, bucket);
        if (prevLoc != -1) {
            locationTable.put(pair.getId(), prevLoc);
            continue;
        }
        locationTable.put(pair.getId(), location);
        if (bucket == null) {
            bucket = new ArrayList<BinaryIdContentPair>();
            alreadySaved.put(savableName + getChunk(pair), bucket);
        }
        bucket.add(pair);
        byte[] aliasBytes = fixClassAlias(classes.get(savableName).alias, aliasSize);
        out.write(aliasBytes);
        location += aliasSize;
        BinaryOutputCapsule cap = contentTable.get(savable).getContent();
        out.write(ByteUtils.convertToBytes(cap.bytes.length));
        // length of bytes
        location += 4;
        out.write(cap.bytes);
        location += cap.bytes.length;
    }
    // write out location table
    // tag/location
    int numLocations = locationTable.keySet().size();
    os.write(ByteUtils.convertToBytes(numLocations));
    int locationTableSize = 0;
    for (Integer key : locationTable.keySet()) {
        os.write(ByteUtils.convertToBytes(key));
        os.write(ByteUtils.convertToBytes(locationTable.get(key)));
        locationTableSize += 8;
    }
    // write out number of root ids - hardcoded 1 for now
    os.write(ByteUtils.convertToBytes(1));
    // write out root id
    os.write(ByteUtils.convertToBytes(id));
    // append stream to the output stream
    out.writeTo(os);
    out = null;
    os = null;
    if (debug) {
        logger.fine("Stats:");
        logger.log(Level.FINE, "classes: {0}", classNum);
        logger.log(Level.FINE, "class table: {0} bytes", classTableSize);
        logger.log(Level.FINE, "objects: {0}", numLocations);
        logger.log(Level.FINE, "location table: {0} bytes", locationTableSize);
        logger.log(Level.FINE, "data: {0} bytes", location);
    }
}
Also used : IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Savable(com.jme3.export.Savable)

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