Search in sources :

Example 96 with Type

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

the class SceneLoader method loadConnections.

private void loadConnections(FbxElement element) {
    for (FbxElement e : element.children) {
        if (e.id.equals("C")) {
            String type = (String) e.properties.get(0);
            long objId, refId;
            FbxObject obj, ref;
            switch(type) {
                case "OO":
                    objId = (Long) e.properties.get(1);
                    refId = (Long) e.properties.get(2);
                    obj = allObjects.get(objId);
                    ref = allObjects.get(refId);
                    if (ref != null) {
                        ref.link(obj);
                    } else if (refId == 0) {
                        obj.linkToZero();
                    }
                    break;
                case "OP":
                    objId = (Long) e.properties.get(1);
                    refId = (Long) e.properties.get(2);
                    String propName = (String) e.properties.get(3);
                    obj = allObjects.get(objId);
                    ref = allObjects.get(refId);
                    if (ref != null)
                        ref.link(obj, propName);
                    break;
            }
        }
    }
}
Also used : FbxElement(com.jme3.scene.plugins.fbx.file.FbxElement) FbxObject(com.jme3.scene.plugins.fbx.objects.FbxObject)

Example 97 with Type

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

the class SceneLoader method parseLight.

private void parseLight(Attributes attribs) throws SAXException {
    if (node == null || node.getParent() == null) {
        throw new SAXException("dotScene parse error: light can only appear under a node");
    }
    checkTopNode("node");
    String lightType = parseString(attribs.getValue("type"), "point");
    if (lightType.equals("point")) {
        light = new PointLight();
    } else if (lightType.equals("directional") || lightType.equals("sun")) {
        light = new DirectionalLight();
        // Assuming "normal" property is not provided
        ((DirectionalLight) light).setDirection(Vector3f.UNIT_Z);
    } else if (lightType.equals("spotLight") || lightType.equals("spot")) {
        light = new SpotLight();
    } else if (lightType.equals("omni")) {
        // XXX: It doesn't seem any exporters actually emit this type?
        light = new AmbientLight();
    } else {
        logger.log(Level.WARNING, "No matching jME3 LightType found for OGRE LightType: {0}", lightType);
    }
    logger.log(Level.FINEST, "{0} created.", light);
    if (!parseBool(attribs.getValue("visible"), true)) {
    // set to disabled
    }
    // "attach" it to the parent of this node
    if (light != null) {
        node.getParent().addLight(light);
    }
}
Also used : DirectionalLight(com.jme3.light.DirectionalLight) PointLight(com.jme3.light.PointLight) SpotLight(com.jme3.light.SpotLight) AmbientLight(com.jme3.light.AmbientLight) SAXException(org.xml.sax.SAXException)

Example 98 with Type

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

the class MaterialLoader method readTextureImage.

private void readTextureImage(String content) {
    // texture image def
    String path = null;
    // find extension
    int extStart = content.lastIndexOf(".");
    for (int i = extStart; i < content.length(); i++) {
        char c = content.charAt(i);
        if (Character.isWhitespace(c)) {
            // extension ends here
            path = content.substring(0, i).trim();
            content = content.substring(i + 1).trim();
            break;
        }
    }
    if (path == null) {
        path = content.trim();
        content = "";
    }
    Scanner lnScan = new Scanner(content);
    String mips = null;
    String type = null;
    if (lnScan.hasNext()) {
        // more params
        type = lnScan.next();
    //            if (!lnScan.hasNext("\n") && lnScan.hasNext()){
    //                mips = lnScan.next();
    //                if (lnScan.hasNext()){
    // even more params..
    // will have to ignore
    //                }
    //            }
    }
    boolean genMips = true;
    boolean cubic = false;
    if (type != null && type.equals("0"))
        genMips = false;
    if (type != null && type.equals("cubic")) {
        cubic = true;
    }
    TextureKey texKey = new TextureKey(folderName + path, false);
    texKey.setGenerateMips(genMips);
    if (cubic) {
        texKey.setTextureTypeHint(Texture.Type.CubeMap);
    }
    try {
        Texture loadedTexture = assetManager.loadTexture(texKey);
        textures[texUnit].setImage(loadedTexture.getImage());
        textures[texUnit].setMinFilter(loadedTexture.getMinFilter());
        textures[texUnit].setMagFilter(loadedTexture.getMagFilter());
        textures[texUnit].setAnisotropicFilter(loadedTexture.getAnisotropicFilter());
        textures[texUnit].setKey(loadedTexture.getKey());
        // XXX: Is this really neccessary?
        textures[texUnit].setWrap(WrapMode.Repeat);
        if (texName != null) {
            textures[texUnit].setName(texName);
            texName = null;
        } else {
            textures[texUnit].setName(texKey.getName());
        }
    } catch (AssetNotFoundException ex) {
        logger.log(Level.WARNING, "Cannot locate {0} for material {1}", new Object[] { texKey, matName });
        textures[texUnit].setImage(PlaceholderAssets.getPlaceholderImage(assetManager));
        textures[texUnit].setKey(texKey);
    }
}
Also used : Scanner(java.util.Scanner) Texture(com.jme3.texture.Texture)

Example 99 with Type

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

the class MeshLoader method pushTexCoord.

private void pushTexCoord(Attributes attribs) throws SAXException {
    if (texCoordIndex >= 8) {
        // More than 8 not supported by ogre.
        return;
    }
    Type type = TEXCOORD_TYPES[texCoordIndex];
    VertexBuffer tcvb = mesh.getBuffer(type);
    FloatBuffer buf = (FloatBuffer) tcvb.getData();
    buf.put(parseFloat(attribs.getValue("u")));
    if (tcvb.getNumComponents() >= 2) {
        buf.put(parseFloat(attribs.getValue("v")));
        if (tcvb.getNumComponents() >= 3) {
            buf.put(parseFloat(attribs.getValue("w")));
            if (tcvb.getNumComponents() == 4) {
                buf.put(parseFloat(attribs.getValue("x")));
            }
        }
    }
    texCoordIndex++;
}
Also used : Type(com.jme3.scene.VertexBuffer.Type)

Example 100 with Type

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

the class J3MOutputCapsule method formatMatParam.

private String formatMatParam(MatParam param) {
    VarType type = param.getVarType();
    Object val = param.getValue();
    switch(type) {
        case Boolean:
        case Float:
        case Int:
            return val.toString();
        case Vector2:
            Vector2f v2 = (Vector2f) val;
            return v2.getX() + " " + v2.getY();
        case Vector3:
            Vector3f v3 = (Vector3f) val;
            return v3.getX() + " " + v3.getY() + " " + v3.getZ();
        case Vector4:
            // can be either ColorRGBA, Vector4f or Quaternion
            if (val instanceof Vector4f) {
                Vector4f v4 = (Vector4f) val;
                return v4.getX() + " " + v4.getY() + " " + v4.getZ() + " " + v4.getW();
            } else if (val instanceof ColorRGBA) {
                ColorRGBA color = (ColorRGBA) val;
                return color.getRed() + " " + color.getGreen() + " " + color.getBlue() + " " + color.getAlpha();
            } else if (val instanceof Quaternion) {
                Quaternion quat = (Quaternion) val;
                return quat.getX() + " " + quat.getY() + " " + quat.getZ() + " " + quat.getW();
            } else {
                throw new UnsupportedOperationException("Unexpected Vector4 type: " + val);
            }
        default:
            // parameter type not supported in J3M
            return null;
    }
}
Also used : VarType(com.jme3.shader.VarType)

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