Search in sources :

Example 1 with FaceCullMode

use of com.jme3.material.RenderState.FaceCullMode in project jmonkeyengine by jMonkeyEngine.

the class MaterialContext method applyMaterial.

/**
     * Applies material to a given geometry.
     * 
     * @param geometry
     *            the geometry
     * @param geometriesOMA
     *            the geometries OMA
     * @param userDefinedUVCoordinates
     *            UV coords defined by user
     * @param blenderContext
     *            the blender context
     */
public void applyMaterial(Geometry geometry, Long geometriesOMA, Map<String, List<Vector2f>> userDefinedUVCoordinates, BlenderContext blenderContext) {
    Material material = null;
    if (shadeless) {
        material = new Material(blenderContext.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
        if (!transparent) {
            diffuseColor.a = 1;
        }
        material.setColor("Color", diffuseColor);
    } else {
        material = new Material(blenderContext.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
        material.setBoolean("UseMaterialColors", Boolean.TRUE);
        // setting the colors
        if (!transparent) {
            diffuseColor.a = 1;
        }
        material.setColor("Diffuse", diffuseColor);
        material.setColor("Specular", specularColor);
        material.setFloat("Shininess", shininess);
        material.setColor("Ambient", new ColorRGBA(ambientFactor, ambientFactor, ambientFactor, 1f));
    }
    // applying textures
    int textureIndex = 0;
    if (loadedTextures != null && loadedTextures.size() > 0) {
        if (loadedTextures.size() > TextureHelper.TEXCOORD_TYPES.length) {
            LOGGER.log(Level.WARNING, "The blender file has defined more than {0} different textures. JME supports only {0} UV mappings.", TextureHelper.TEXCOORD_TYPES.length);
        }
        for (CombinedTexture combinedTexture : loadedTextures) {
            if (textureIndex < TextureHelper.TEXCOORD_TYPES.length) {
                String usedUserUVSet = combinedTexture.flatten(geometry, geometriesOMA, userDefinedUVCoordinates, blenderContext);
                this.setTexture(material, combinedTexture.getMappingType(), combinedTexture.getResultTexture());
                List<Vector2f> uvs = combinedTexture.getResultUVS();
                if (uvs != null && uvs.size() > 0) {
                    VertexBuffer uvCoordsBuffer = new VertexBuffer(TextureHelper.TEXCOORD_TYPES[textureIndex++]);
                    uvCoordsBuffer.setupData(Usage.Static, 2, Format.Float, BufferUtils.createFloatBuffer(uvs.toArray(new Vector2f[uvs.size()])));
                    geometry.getMesh().setBuffer(uvCoordsBuffer);
                }
                if (usedUserUVSet != null) {
                    userDefinedUVCoordinates = new HashMap<>(userDefinedUVCoordinates);
                    userDefinedUVCoordinates.remove(usedUserUVSet);
                }
            } else {
                LOGGER.log(Level.WARNING, "The texture could not be applied because JME only supports up to {0} different UV's.", TextureHelper.TEXCOORD_TYPES.length);
            }
        }
    }
    if (userDefinedUVCoordinates != null && userDefinedUVCoordinates.size() > 0) {
        LOGGER.fine("Storing unused, user defined UV coordinates sets.");
        if (userDefinedUVCoordinates.size() > TextureHelper.TEXCOORD_TYPES.length) {
            LOGGER.log(Level.WARNING, "The blender file has defined more than {0} different UV coordinates for the mesh. JME supports only {0} UV coordinates buffers.", TextureHelper.TEXCOORD_TYPES.length);
        }
        for (Entry<String, List<Vector2f>> entry : userDefinedUVCoordinates.entrySet()) {
            if (textureIndex < TextureHelper.TEXCOORD_TYPES.length) {
                List<Vector2f> uvs = entry.getValue();
                VertexBuffer uvCoordsBuffer = new VertexBuffer(TextureHelper.TEXCOORD_TYPES[textureIndex++]);
                uvCoordsBuffer.setupData(Usage.Static, 2, Format.Float, BufferUtils.createFloatBuffer(uvs.toArray(new Vector2f[uvs.size()])));
                geometry.getMesh().setBuffer(uvCoordsBuffer);
            } else {
                LOGGER.log(Level.WARNING, "The user's UV set named: '{0}' could not be stored because JME only supports up to {1} different UV's.", new Object[] { entry.getKey(), TextureHelper.TEXCOORD_TYPES.length });
            }
        }
    }
    // applying additional data
    material.setName(name);
    if (vertexColor) {
        material.setBoolean(shadeless ? "VertexColor" : "UseVertexColor", true);
    }
    material.getAdditionalRenderState().setFaceCullMode(faceCullMode != null ? faceCullMode : blenderContext.getBlenderKey().getFaceCullMode());
    if (transparent) {
        material.setTransparent(true);
        material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
        geometry.setQueueBucket(Bucket.Transparent);
    }
    geometry.setMaterial(material);
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA) VertexBuffer(com.jme3.scene.VertexBuffer) Vector2f(com.jme3.math.Vector2f) Material(com.jme3.material.Material) List(java.util.List) CombinedTexture(com.jme3.scene.plugins.blender.textures.CombinedTexture)

Example 2 with FaceCullMode

use of com.jme3.material.RenderState.FaceCullMode in project jmonkeyengine by jMonkeyEngine.

the class BlenderKey method read.

@Override
public void read(JmeImporter e) throws IOException {
    super.read(e);
    InputCapsule ic = e.getCapsule(this);
    fps = ic.readInt("fps", DEFAULT_FPS);
    featuresToLoad = ic.readInt("features-to-load", FeaturesToLoad.ALL);
    loadUnlinkedAssets = ic.readBoolean("load-unlinked-assets", false);
    assetRootPath = ic.readString("asset-root-path", null);
    fixUpAxis = ic.readBoolean("fix-up-axis", true);
    generatedTexturePPU = ic.readInt("generated-texture-ppu", 128);
    usedWorld = ic.readString("used-world", null);
    defaultMaterial = (Material) ic.readSavable("default-material", null);
    faceCullMode = ic.readEnum("face-cull-mode", FaceCullMode.class, FaceCullMode.Off);
    layersToLoad = ic.readInt("layers-to=load", -1);
    mipmapGenerationMethod = ic.readEnum("mipmap-generation-method", MipmapGenerationMethod.class, MipmapGenerationMethod.GENERATE_WHEN_NEEDED);
    skyGeneratedTextureSize = ic.readInt("sky-generated-texture-size", 1000);
    skyGeneratedTextureRadius = ic.readFloat("sky-generated-texture-radius", 1f);
    skyGeneratedTextureShape = ic.readEnum("sky-generated-texture-shape", SkyGeneratedTextureShape.class, SkyGeneratedTextureShape.SPHERE);
    optimiseTextures = ic.readBoolean("optimise-textures", false);
    animationMatchMethod = ic.readEnum("animation-match-method", AnimationMatchMethod.class, AnimationMatchMethod.AT_LEAST_ONE_NAME_MATCH);
    pointsSize = ic.readFloat("points-size", 1);
    linesWidth = ic.readFloat("lines-width", 1);
}
Also used : InputCapsule(com.jme3.export.InputCapsule) FaceCullMode(com.jme3.material.RenderState.FaceCullMode)

Example 3 with FaceCullMode

use of com.jme3.material.RenderState.FaceCullMode in project jmonkeyengine by jMonkeyEngine.

the class BlenderKey method write.

@Override
public void write(JmeExporter e) throws IOException {
    super.write(e);
    OutputCapsule oc = e.getCapsule(this);
    oc.write(fps, "fps", DEFAULT_FPS);
    oc.write(featuresToLoad, "features-to-load", FeaturesToLoad.ALL);
    oc.write(loadUnlinkedAssets, "load-unlinked-assets", false);
    oc.write(assetRootPath, "asset-root-path", null);
    oc.write(fixUpAxis, "fix-up-axis", true);
    oc.write(generatedTexturePPU, "generated-texture-ppu", 128);
    oc.write(usedWorld, "used-world", null);
    oc.write(defaultMaterial, "default-material", null);
    oc.write(faceCullMode, "face-cull-mode", FaceCullMode.Off);
    oc.write(layersToLoad, "layers-to-load", -1);
    oc.write(mipmapGenerationMethod, "mipmap-generation-method", MipmapGenerationMethod.GENERATE_WHEN_NEEDED);
    oc.write(skyGeneratedTextureSize, "sky-generated-texture-size", 1000);
    oc.write(skyGeneratedTextureRadius, "sky-generated-texture-radius", 1f);
    oc.write(skyGeneratedTextureShape, "sky-generated-texture-shape", SkyGeneratedTextureShape.SPHERE);
    oc.write(optimiseTextures, "optimise-textures", false);
    oc.write(animationMatchMethod, "animation-match-method", AnimationMatchMethod.AT_LEAST_ONE_NAME_MATCH);
    oc.write(pointsSize, "points-size", 1);
    oc.write(linesWidth, "lines-width", 1);
}
Also used : OutputCapsule(com.jme3.export.OutputCapsule)

Aggregations

InputCapsule (com.jme3.export.InputCapsule)1 OutputCapsule (com.jme3.export.OutputCapsule)1 Material (com.jme3.material.Material)1 FaceCullMode (com.jme3.material.RenderState.FaceCullMode)1 ColorRGBA (com.jme3.math.ColorRGBA)1 Vector2f (com.jme3.math.Vector2f)1 VertexBuffer (com.jme3.scene.VertexBuffer)1 CombinedTexture (com.jme3.scene.plugins.blender.textures.CombinedTexture)1 List (java.util.List)1