Search in sources :

Example 16 with Material

use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.

the class MaterialTest method material.

private void material(String path) {
    AssetManager assetManager = TestUtil.createAssetManager();
    material = new Material(assetManager, path);
    geometry.setMaterial(material);
}
Also used : AssetManager(com.jme3.asset.AssetManager)

Example 17 with Material

use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.

the class LoadJ3mdTest method testShaderNodesMaterialDefLoading.

@Test
public void testShaderNodesMaterialDefLoading() {
    supportGlsl(100);
    material("testMatDef.j3md");
    material.selectTechnique("Default", renderManager);
    assertEquals(material.getActiveTechnique().getDef().getShaderNodes().size(), 2);
    Shader s = material.getActiveTechnique().getDef().getShader(TestUtil.createAssetManager(), myCaps, material.getActiveTechnique().getDynamicDefines());
    assertEquals(s.getSources().size(), 2);
}
Also used : Shader(com.jme3.shader.Shader) Test(org.junit.Test)

Example 18 with Material

use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.

the class SceneLoader method loadObjects.

private void loadObjects(FbxElement element) throws IOException {
    FbxObject obj = null;
    for (FbxElement e : element.children) {
        switch(e.id) {
            case "Geometry":
                FbxMesh mesh = new FbxMesh(this, e);
                obj = mesh;
                if (mesh.geometries != null)
                    geomMap.put(mesh.id, mesh);
                break;
            case "Material":
                obj = new FbxMaterial(this, e);
                break;
            case "Model":
                FbxNode node = new FbxNode(this, e);
                obj = node;
                modelMap.put(node.id, node);
                if (node.isLimb())
                    limbMap.put(node.id, node);
                break;
            case "Pose":
                FbxBindPose pose = new FbxBindPose(this, e);
                obj = pose;
                bindMap.put(pose.id, pose);
                break;
            case "Texture":
                obj = new FbxTexture(this, e);
                break;
            case "Video":
                obj = new FbxImage(this, e);
                break;
            case "Deformer":
                obj = loadDeformer(e);
                break;
            case "AnimationLayer":
                FbxObject layer = new FbxObject(this, e);
                obj = layer;
                alayerMap.put(layer.id, layer);
                break;
            case "AnimationCurve":
                obj = new FbxAnimCurve(this, e);
                break;
            case "AnimationCurveNode":
                obj = new FbxAnimNode(this, e);
                break;
            default:
                obj = null;
        }
        if (obj != null)
            allObjects.put(obj.id, obj);
    }
}
Also used : FbxElement(com.jme3.scene.plugins.fbx.file.FbxElement) FbxObject(com.jme3.scene.plugins.fbx.objects.FbxObject) FbxNode(com.jme3.scene.plugins.fbx.objects.FbxNode) FbxAnimCurve(com.jme3.scene.plugins.fbx.objects.FbxAnimCurve) FbxTexture(com.jme3.scene.plugins.fbx.objects.FbxTexture) FbxMesh(com.jme3.scene.plugins.fbx.objects.FbxMesh) FbxBindPose(com.jme3.scene.plugins.fbx.objects.FbxBindPose) FbxAnimNode(com.jme3.scene.plugins.fbx.objects.FbxAnimNode) FbxMaterial(com.jme3.scene.plugins.fbx.objects.FbxMaterial) FbxImage(com.jme3.scene.plugins.fbx.objects.FbxImage)

Example 19 with Material

use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.

the class ParticlesModifier method postMeshCreationApply.

@Override
public void postMeshCreationApply(Node node, BlenderContext blenderContext) {
    LOGGER.log(Level.FINE, "Applying particles modifier to: {0}", node);
    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);
                // TODO: divide into several pieces
                emitter.setMaterial(material);
            }
        }
    }
    if (meshes.size() > 0 && emitterShape instanceof EmitterMeshVertexShape) {
        ((EmitterMeshVertexShape) emitterShape).setMeshes(meshes);
    }
    node.attachChild(emitter);
}
Also used : ParticleEmitter(com.jme3.effect.ParticleEmitter) Geometry(com.jme3.scene.Geometry) Spatial(com.jme3.scene.Spatial) EmitterShape(com.jme3.effect.shapes.EmitterShape) ArrayList(java.util.ArrayList) MaterialHelper(com.jme3.scene.plugins.blender.materials.MaterialHelper) TemporalMesh(com.jme3.scene.plugins.blender.meshes.TemporalMesh) Mesh(com.jme3.scene.Mesh) Material(com.jme3.material.Material) EmitterMeshVertexShape(com.jme3.effect.shapes.EmitterMeshVertexShape)

Example 20 with Material

use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.

the class Face method loadAll.

/**
     * Loads all faces of a given mesh.
     * @param meshStructure
     *            the mesh structure we read the faces from
     * @param userUVGroups
     *            UV groups defined by the user
     * @param verticesColors
     *            the vertices colors of the mesh
     * @param temporalMesh
     *            the temporal mesh the faces will belong to
     * @param blenderContext
     *            the blender context
     * @return list of faces read from the given mesh structure
     * @throws BlenderFileException
     *             an exception is thrown when problems with file reading occur
     */
public static List<Face> loadAll(Structure meshStructure, Map<String, List<Vector2f>> userUVGroups, List<byte[]> verticesColors, TemporalMesh temporalMesh, BlenderContext blenderContext) throws BlenderFileException {
    LOGGER.log(Level.FINE, "Loading all faces from mesh: {0}", meshStructure.getName());
    List<Face> result = new ArrayList<Face>();
    MeshHelper meshHelper = blenderContext.getHelper(MeshHelper.class);
    if (meshHelper.isBMeshCompatible(meshStructure)) {
        LOGGER.fine("Reading BMesh.");
        Pointer pMLoop = (Pointer) meshStructure.getFieldValue("mloop");
        Pointer pMPoly = (Pointer) meshStructure.getFieldValue("mpoly");
        if (pMPoly.isNotNull() && pMLoop.isNotNull()) {
            List<Structure> polys = pMPoly.fetchData();
            List<Structure> loops = pMLoop.fetchData();
            for (Structure poly : polys) {
                int materialNumber = ((Number) poly.getFieldValue("mat_nr")).intValue();
                int loopStart = ((Number) poly.getFieldValue("loopstart")).intValue();
                int totLoop = ((Number) poly.getFieldValue("totloop")).intValue();
                boolean smooth = (((Number) poly.getFieldValue("flag")).byteValue() & 0x01) != 0x00;
                Integer[] vertexIndexes = new Integer[totLoop];
                for (int i = loopStart; i < loopStart + totLoop; ++i) {
                    vertexIndexes[i - loopStart] = ((Number) loops.get(i).getFieldValue("v")).intValue();
                }
                // uvs always must be added wheater we have texture or not
                Map<String, List<Vector2f>> uvCoords = new HashMap<String, List<Vector2f>>();
                for (Entry<String, List<Vector2f>> entry : userUVGroups.entrySet()) {
                    List<Vector2f> uvs = entry.getValue().subList(loopStart, loopStart + totLoop);
                    uvCoords.put(entry.getKey(), new ArrayList<Vector2f>(uvs));
                }
                List<byte[]> vertexColors = null;
                if (verticesColors != null && verticesColors.size() > 0) {
                    vertexColors = new ArrayList<byte[]>(totLoop);
                    for (int i = loopStart; i < loopStart + totLoop; ++i) {
                        vertexColors.add(verticesColors.get(i));
                    }
                }
                result.add(new Face(vertexIndexes, smooth, materialNumber, uvCoords, vertexColors, temporalMesh));
            }
        }
    } else {
        LOGGER.fine("Reading traditional faces.");
        Pointer pMFace = (Pointer) meshStructure.getFieldValue("mface");
        List<Structure> mFaces = pMFace.isNotNull() ? pMFace.fetchData() : null;
        if (mFaces != null && mFaces.size() > 0) {
            // indicates if the material with the specified number should have a texture attached
            for (int i = 0; i < mFaces.size(); ++i) {
                Structure mFace = mFaces.get(i);
                int materialNumber = ((Number) mFace.getFieldValue("mat_nr")).intValue();
                boolean smooth = (((Number) mFace.getFieldValue("flag")).byteValue() & 0x01) != 0x00;
                int v1 = ((Number) mFace.getFieldValue("v1")).intValue();
                int v2 = ((Number) mFace.getFieldValue("v2")).intValue();
                int v3 = ((Number) mFace.getFieldValue("v3")).intValue();
                int v4 = ((Number) mFace.getFieldValue("v4")).intValue();
                int vertCount = v4 == 0 ? 3 : 4;
                // uvs always must be added wheater we have texture or not
                Map<String, List<Vector2f>> faceUVCoords = new HashMap<String, List<Vector2f>>();
                for (Entry<String, List<Vector2f>> entry : userUVGroups.entrySet()) {
                    List<Vector2f> uvCoordsForASingleFace = new ArrayList<Vector2f>(vertCount);
                    for (int j = 0; j < vertCount; ++j) {
                        uvCoordsForASingleFace.add(entry.getValue().get(i * 4 + j));
                    }
                    faceUVCoords.put(entry.getKey(), uvCoordsForASingleFace);
                }
                List<byte[]> vertexColors = null;
                if (verticesColors != null && verticesColors.size() > 0) {
                    vertexColors = new ArrayList<byte[]>(vertCount);
                    vertexColors.add(verticesColors.get(v1));
                    vertexColors.add(verticesColors.get(v2));
                    vertexColors.add(verticesColors.get(v3));
                    if (vertCount == 4) {
                        vertexColors.add(verticesColors.get(v4));
                    }
                }
                result.add(new Face(vertCount == 4 ? new Integer[] { v1, v2, v3, v4 } : new Integer[] { v1, v2, v3 }, smooth, materialNumber, faceUVCoords, vertexColors, temporalMesh));
            }
        }
    }
    LOGGER.log(Level.FINE, "Loaded {0} faces.", result.size());
    return result;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Pointer(com.jme3.scene.plugins.blender.file.Pointer) Vector2f(com.jme3.math.Vector2f) ArrayList(java.util.ArrayList) List(java.util.List) Structure(com.jme3.scene.plugins.blender.file.Structure)

Aggregations

Material (com.jme3.material.Material)285 Geometry (com.jme3.scene.Geometry)165 Vector3f (com.jme3.math.Vector3f)110 Box (com.jme3.scene.shape.Box)79 Texture (com.jme3.texture.Texture)69 DirectionalLight (com.jme3.light.DirectionalLight)49 Sphere (com.jme3.scene.shape.Sphere)43 Node (com.jme3.scene.Node)39 ColorRGBA (com.jme3.math.ColorRGBA)38 Spatial (com.jme3.scene.Spatial)35 Quaternion (com.jme3.math.Quaternion)31 Quad (com.jme3.scene.shape.Quad)26 Texture2D (com.jme3.texture.Texture2D)21 KeyTrigger (com.jme3.input.controls.KeyTrigger)20 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)19 ArrayList (java.util.ArrayList)19 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)18 TextureKey (com.jme3.asset.TextureKey)17 ParticleEmitter (com.jme3.effect.ParticleEmitter)17 AmbientLight (com.jme3.light.AmbientLight)16