Examples of MaterialHelper


Examples of com.jme3.scene.plugins.blender.materials.MaterialHelper

    @Override
    public void apply(Node node, BlenderContext blenderContext) {
        if (invalid) {
            LOGGER.log(Level.WARNING, "Particles modifier is invalid! Cannot be applied to: {0}", node.getName());
        } else {
            MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class);
            ParticleEmitter emitter = particleEmitter.clone();

            // veryfying the alpha function for particles' texture
            Integer alphaFunction = MaterialHelper.ALPHA_MASK_HYPERBOLE;
            char nameSuffix = emitter.getName().charAt(emitter.getName().length() - 1);
            if (nameSuffix == 'B' || nameSuffix == 'N') {
                alphaFunction = MaterialHelper.ALPHA_MASK_NONE;
            }
            // removing the type suffix from the name
            emitter.setName(emitter.getName().substring(0, emitter.getName().length() - 1));

            // applying emitter shape
            EmitterShape emitterShape = emitter.getShape();
            List<Mesh> meshes = new ArrayList<Mesh>();
            for (Spatial spatial : node.getChildren()) {
                if (spatial instanceof Geometry) {
                    Mesh mesh = ((Geometry) spatial).getMesh();
                    if (mesh != null) {
                        meshes.add(mesh);
                        Material material = materialHelper.getParticlesMaterial(((Geometry) spatial).getMaterial(), alphaFunction, blenderContext);
                        emitter.setMaterial(material);// TODO: divide into several pieces
                    }
                }
            }
            if (meshes.size() > 0 && emitterShape instanceof EmitterMeshVertexShape) {
View Full Code Here

Examples of com.jme3.scene.plugins.blender.materials.MaterialHelper

     * @param blenderContext
     *            the blender context
     */
    protected void blendHSV(int type, float[] materialRGB, float fac, float[] pixelColor, BlenderContext blenderContext) {
        float oneMinusFactor = 1.0f - fac;
        MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class);

        switch (type) {
            case MTEX_BLEND_HUE: {// FIXME: not working well for image textures (works fine for generated textures)
                float[] colorTransformResult = new float[3];
                materialHelper.rgbToHsv(pixelColor[0], pixelColor[1], pixelColor[2], colorTransformResult);
                if (colorTransformResult[0] != 0.0f) {
                    float colH = colorTransformResult[0];
                    materialHelper.rgbToHsv(materialRGB[0], materialRGB[1], materialRGB[2], colorTransformResult);
                    materialHelper.hsvToRgb(colH, colorTransformResult[1], colorTransformResult[2], colorTransformResult);
                    materialRGB[0] = oneMinusFactor * materialRGB[0] + fac * colorTransformResult[0];
                    materialRGB[1] = oneMinusFactor * materialRGB[1] + fac * colorTransformResult[1];
                    materialRGB[2] = oneMinusFactor * materialRGB[2] + fac * colorTransformResult[2];
                }
                break;
            }
            case MTEX_BLEND_SAT: {
                float[] colorTransformResult = new float[3];
                materialHelper.rgbToHsv(materialRGB[0], materialRGB[1], materialRGB[2], colorTransformResult);
                float h = colorTransformResult[0];
                float s = colorTransformResult[1];
                float v = colorTransformResult[2];
                if (s != 0.0f) {
                    materialHelper.rgbToHsv(pixelColor[0], pixelColor[1], pixelColor[2], colorTransformResult);
                    materialHelper.hsvToRgb(h, oneMinusFactor * s + fac * colorTransformResult[1], v, materialRGB);
                }
                break;
            }
            case MTEX_BLEND_VAL: {
                float[] rgbToHsv = new float[3];
                float[] colToHsv = new float[3];
                materialHelper.rgbToHsv(materialRGB[0], materialRGB[1], materialRGB[2], rgbToHsv);
                materialHelper.rgbToHsv(pixelColor[0], pixelColor[1], pixelColor[2], colToHsv);
                materialHelper.hsvToRgb(rgbToHsv[0], rgbToHsv[1], oneMinusFactor * rgbToHsv[2] + fac * colToHsv[2], materialRGB);
                break;
            }
            case MTEX_BLEND_COLOR: {// FIXME: not working well for image textures (works fine for generated textures)
                float[] rgbToHsv = new float[3];
                float[] colToHsv = new float[3];
                materialHelper.rgbToHsv(pixelColor[0], pixelColor[1], pixelColor[2], colToHsv);
                if (colToHsv[2] != 0) {
                    materialHelper.rgbToHsv(materialRGB[0], materialRGB[1], materialRGB[2], rgbToHsv);
                    materialHelper.hsvToRgb(colToHsv[0], colToHsv[1], rgbToHsv[2], rgbToHsv);
                    materialRGB[0] = oneMinusFactor * materialRGB[0] + fac * rgbToHsv[0];
                    materialRGB[1] = oneMinusFactor * materialRGB[1] + fac * rgbToHsv[1];
                    materialRGB[2] = oneMinusFactor * materialRGB[2] + fac * rgbToHsv[2];
                }
                break;
View Full Code Here

Examples of com.jme3.scene.plugins.blender.materials.MaterialHelper

            }
            nurbList.add(nurb);
        }

        // getting materials
        MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class);
        MaterialContext[] materialContexts = materialHelper.getMaterials(curveStructure, blenderContext);
        Material defaultMaterial = null;
        if (materialContexts != null) {
            for (MaterialContext materialContext : materialContexts) {
                materialContext.setFaceCullMode(FaceCullMode.Off);
            }
View Full Code Here

Examples of com.jme3.scene.plugins.blender.materials.MaterialHelper

        blenderContext.putHelper(ObjectHelper.class, new ObjectHelper(inputStream.getVersionNumber(), blenderContext));
        blenderContext.putHelper(CurvesHelper.class, new CurvesHelper(inputStream.getVersionNumber(), blenderContext));
        blenderContext.putHelper(LightHelper.class, new LightHelper(inputStream.getVersionNumber(), blenderContext));
        blenderContext.putHelper(CameraHelper.class, new CameraHelper(inputStream.getVersionNumber(), blenderContext));
        blenderContext.putHelper(ModifierHelper.class, new ModifierHelper(inputStream.getVersionNumber(), blenderContext));
        blenderContext.putHelper(MaterialHelper.class, new MaterialHelper(inputStream.getVersionNumber(), blenderContext));
        blenderContext.putHelper(ConstraintHelper.class, new ConstraintHelper(inputStream.getVersionNumber(), blenderContext));
        blenderContext.putHelper(ParticlesHelper.class, new ParticlesHelper(inputStream.getVersionNumber(), blenderContext));
        blenderContext.putHelper(LandscapeHelper.class, new LandscapeHelper(inputStream.getVersionNumber(), blenderContext));
       
        // reading the blocks (dna block is automatically saved in the blender context when found)
View Full Code Here

Examples of com.jme3.scene.plugins.blender.materials.MaterialHelper

        String name = structure.getName();
        MeshContext meshContext = new MeshContext();
        LOGGER.log(Level.FINE, "Reading mesh: {0}.", name);

        LOGGER.fine("Loading materials.");
        MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class);
        MaterialContext[] materials = null;
        if ((blenderContext.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.MATERIALS) != 0) {
            materials = materialHelper.getMaterials(structure, blenderContext);
        }

        LOGGER.fine("Reading vertices.");
        MeshBuilder meshBuilder = new MeshBuilder(structure, materials, blenderContext);
        if (meshBuilder.isEmpty()) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.