Java Code Examples for com.jme3.material.Material

The following examples show how to use com.jme3.material.Material. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Creates the data from a material
 * @param mat
 */
public void setAsMaterial(Material mat) throws IOException {
    assert (mat.getMaterialDef().getAssetName() != null);
    setName("MyMaterial");
    setMatDefName(mat.getMaterialDef().getAssetName());
    createBaseMaterialFile();
    materialParameters.clear();
    Collection<MatParam> params = mat.getParams();
    for (Iterator<MatParam> it = params.iterator(); it.hasNext();) {
        MatParam matParam = it.next();
        materialParameters.put(matParam.getName(), new MaterialProperty(matParam));
    }
    additionalRenderStates.put("Wireframe", new MaterialProperty("OnOff", "Wireframe", mat.getAdditionalRenderState().isWireframe() ? "On" : "Off"));
    additionalRenderStates.put("DepthWrite", new MaterialProperty("OnOff", "DepthWrite", mat.getAdditionalRenderState().isDepthWrite() ? "On" : "Off"));
    additionalRenderStates.put("DepthTest", new MaterialProperty("OnOff", "DepthTest", mat.getAdditionalRenderState().isDepthTest() ? "On" : "Off"));
    additionalRenderStates.put("ColorWrite", new MaterialProperty("OnOff", "ColorWrite", mat.getAdditionalRenderState().isColorWrite() ? "On" : "Off"));
    additionalRenderStates.put("PointSprite", new MaterialProperty("OnOff", "PointSprite", mat.getAdditionalRenderState().isPointSprite() ? "On" : "Off"));
    additionalRenderStates.put("FaceCull", new MaterialProperty("FaceCullMode", "FaceCull", mat.getAdditionalRenderState().getFaceCullMode().name()));
    additionalRenderStates.put("Blend", new MaterialProperty("BlendMode", "Blend", mat.getAdditionalRenderState().getBlendMode().name()));
    additionalRenderStates.put("AlphaTestFalloff", new MaterialProperty("Float", "AlphaTestFalloff", mat.getAdditionalRenderState().getAlphaFallOff() + ""));
    additionalRenderStates.put("PolyOffset", new MaterialProperty("Float,Float", "PolyOffset", mat.getAdditionalRenderState().getPolyOffsetUnits() + " " + mat.getAdditionalRenderState().getPolyOffsetFactor()));
    checkWithMatDef();
    setAsText(getUpdatedContent());
}
 
Example 2
public void makeToonish(Spatial spatial){
        if (spatial instanceof Node){
            Node n = (Node) spatial;
            for (Spatial child : n.getChildren())
                makeToonish(child);
        }else if (spatial instanceof Geometry){
            Geometry g = (Geometry) spatial;
            Material m = g.getMaterial();
            if (m.getMaterialDef().getName().equals("Phong Lighting")){
                Texture t = assetManager.loadTexture("Textures/ColorRamp/toon.png");
//                t.setMinFilter(Texture.MinFilter.NearestNoMipMaps);
//                t.setMagFilter(Texture.MagFilter.Nearest);
                m.setTexture("ColorRamp", t);
                m.setBoolean("UseMaterialColors", true);
                m.setColor("Specular", ColorRGBA.Black);
                m.setColor("Diffuse", ColorRGBA.White);
                m.setBoolean("VertexLighting", true);
            }
        }
    }
 
Example 3
public void makeToonish(Spatial spatial){
        if (spatial instanceof Node){
            Node n = (Node) spatial;
            for (Spatial child : n.getChildren())
                makeToonish(child);
        }else if (spatial instanceof Geometry){
            Geometry g = (Geometry) spatial;
            Material m = g.getMaterial();
            if (m.getMaterialDef().getName().equals("Phong Lighting")){
                Texture t = assetManager.loadTexture("Textures/ColorRamp/toon.png");
//                t.setMinFilter(Texture.MinFilter.NearestNoMipMaps);
//                t.setMagFilter(Texture.MagFilter.Nearest);
                m.setTexture("ColorRamp", t);
                m.setBoolean("UseMaterialColors", true);
                m.setColor("Specular", ColorRGBA.Black);
                m.setColor("Diffuse", ColorRGBA.White);
                m.setBoolean("VertexLighting", true);
            }
        }
    }
 
Example 4
@Override
    public void simpleInitApp() {
        Sphere sphMesh = new Sphere(32, 32, 1);
        sphMesh.setTextureMode(Sphere.TextureMode.Projected);
        sphMesh.updateGeometry(32, 32, 1, false, false);
        TangentBinormalGenerator.generate(sphMesh);

        Geometry sphere = new Geometry("Rock Ball", sphMesh);
        Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
        sphere.setMaterial(mat);
        rootNode.attachChild(sphere);

        lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
        lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
        rootNode.attachChild(lightMdl);

        pl = new PointLight();
        pl.setColor(ColorRGBA.White);
        pl.setPosition(new Vector3f(0f, 0f, 4f));
        rootNode.addLight(pl);

//        DirectionalLight dl = new DirectionalLight();
//        dl.setDirection(new Vector3f(1,-1,1).normalizeLocal());
//        dl.setColor(new ColorRGBA(0.22f, 0.15f, 0.1f, 1.0f));
//        rootNode.addLight(dl);
    }
 
Example 5
/** Initialize the materials used in this scene. */
public void initMaterials() {
  wall_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg");
  key.setGenerateMips(true);
  Texture tex = assetManager.loadTexture(key);
  wall_mat.setTexture("ColorMap", tex);

  stone_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
  key2.setGenerateMips(true);
  Texture tex2 = assetManager.loadTexture(key2);
  stone_mat.setTexture("ColorMap", tex2);

  floor_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.jpg");
  key3.setGenerateMips(true);
  Texture tex3 = assetManager.loadTexture(key3);
  tex3.setWrap(WrapMode.Repeat);
  floor_mat.setTexture("ColorMap", tex3);
}
 
Example 6
/**
 * Sets the texture to the given material.
 * 
 * @param material
 *            the material that we add texture to
 * @param mapTo
 *            the texture mapping type
 * @param texture
 *            the added texture
 */
private void setTexture(Material material, int mapTo, Texture texture) {
    switch (mapTo) {
        case MTEX_COL:
            material.setTexture(shadeless ? MaterialHelper.TEXTURE_TYPE_COLOR : MaterialHelper.TEXTURE_TYPE_DIFFUSE, texture);
            break;
        case MTEX_NOR:
            material.setTexture(MaterialHelper.TEXTURE_TYPE_NORMAL, texture);
            break;
        case MTEX_SPEC:
            material.setTexture(MaterialHelper.TEXTURE_TYPE_SPECULAR, texture);
            break;
        case MTEX_EMIT:
            material.setTexture(MaterialHelper.TEXTURE_TYPE_GLOW, texture);
            break;
        case MTEX_ALPHA:
            if (!shadeless) {
                material.setTexture(MaterialHelper.TEXTURE_TYPE_ALPHA, texture);
            } else {
                LOGGER.warning("JME does not support alpha map on unshaded material. Material name is " + name);
            }
            break;
        default:
            LOGGER.severe("Unknown mapping type: " + mapTo);
    }
}
 
Example 7
Source Project: jmonkeybuilder   Source File: AbstractSceneEditor3DPart.java    License: Apache License 2.0 6 votes vote down vote up
@JmeThread
protected @NotNull Geometry createGeometry(@NotNull final ScenePresentable.PresentationType presentationType) {

    final Material material = new Material(EditorUtil.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    material.setColor("Color", ColorRGBA.Yellow);
    material.getAdditionalRenderState().setWireframe(true);

    Geometry geometry;

    switch (presentationType) {
        case SPHERE: {
            geometry = new Geometry("Sphere", new Sphere(8, 8, 1));
            break;
        }
        default: {
            geometry = new Geometry("Box", new Box(1, 1, 1));
        }
    }

    geometry.setMaterial(material);
    return geometry;
}
 
Example 8
Source Project: MikuMikuStudio   Source File: HDRRenderer.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void renderProcessing(Renderer r, FrameBuffer dst, Material mat){
    if (dst == null){
        fsQuad.setWidth(mainSceneFB.getWidth());
        fsQuad.setHeight(mainSceneFB.getHeight());
        fbCam.resize(mainSceneFB.getWidth(), mainSceneFB.getHeight(), true);
    }else{
        fsQuad.setWidth(dst.getWidth());
        fsQuad.setHeight(dst.getHeight());
        fbCam.resize(dst.getWidth(), dst.getHeight(), true);
    }
    fsQuad.setMaterial(mat);
    fsQuad.updateGeometricState();
    renderManager.setCamera(fbCam, true);

    r.setFrameBuffer(dst);
    r.clearBuffers(true, true, true);
    renderManager.renderGeometry(fsQuad);
}
 
Example 9
@Override
public void simpleInitApp() {
    flyCam.setDragToRotate(true);
    
    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    geom.setMaterial(mat);
    rootNode.attachChild(geom);
    
    txt = new BitmapText(loadGuiFont(), false);
    txt.setText("Drag the corners of the application to resize it.\n" +
                "Current Size: " + settings.getWidth() + "x" + settings.getHeight());
    txt.setLocalTranslation(0, settings.getHeight(), 0);
    guiNode.attachChild(txt);
}
 
Example 10
public int compare(Geometry o1, Geometry o2) {
    Material m1 = o1.getMaterial();
    Material m2 = o2.getMaterial();

    int sortId = m1.compareTo(m2);

    if (sortId == 0){
        // use the same shader.
        // sort front-to-back then.
        float d1 = distanceToCam(o1);
        float d2 = distanceToCam(o2);

        if (d1 == d2)
            return 0;
        else if (d1 < d2)
            return -1;
        else
            return 1;
    }else{
        return sortId;
    }
}
 
Example 11
private void createRoundSpark(){
    roundspark = new ParticleEmitter("RoundSpark", EMITTER_TYPE, 20 * COUNT_FACTOR);
    roundspark.setStartColor(new ColorRGBA(1f, 0.29f, 0.34f, (float) (1.0 / COUNT_FACTOR_F)));
    roundspark.setEndColor(new ColorRGBA(0, 0, 0, 0.5f / COUNT_FACTOR_F));
    roundspark.setStartSize(1.2f);
    roundspark.setEndSize(1.8f);
    roundspark.setShape(new EmitterSphereShape(Vector3f.ZERO, 2f));
    roundspark.setParticlesPerSec(0);
    roundspark.setGravity(0, -.5f, 0);
    roundspark.setLowLife(1.8f);
    roundspark.setHighLife(2f);
    roundspark.getParticleInfluencer()
            .setInitialVelocity(new Vector3f(0, 3, 0));
    roundspark.getParticleInfluencer().setVelocityVariation(.5f);
    roundspark.setImagesX(1);
    roundspark.setImagesY(1);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/roundspark.png"));
    mat.setBoolean("PointSprite", POINT_SPRITE);
    roundspark.setMaterial(mat);
    explosionEffect.attachChild(roundspark);
}
 
Example 12
public void initMaterial() {
    mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg");
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    mat.setTexture("ColorMap", tex);

    mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
    key2.setGenerateMips(true);
    Texture tex2 = assetManager.loadTexture(key2);
    mat2.setTexture("ColorMap", tex2);

    mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.jpg");
    key3.setGenerateMips(true);
    Texture tex3 = assetManager.loadTexture(key3);
    tex3.setWrap(WrapMode.Repeat);
    mat3.setTexture("ColorMap", tex3);
}
 
Example 13
Source Project: jmonkeybuilder   Source File: GeometryTreeNode.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void accept(@NotNull final ChangeConsumer changeConsumer, @NotNull final Object object,
                   final boolean isCopy) {

    final Geometry geometry = getElement();

    if (object instanceof Material) {

        final Material material = (Material) object;

        if (isCopy) {

            final Material clone = material.clone();
            final PropertyOperation<ChangeConsumer, Geometry, Material> operation =
                    new PropertyOperation<>(geometry, "Material", clone, geometry.getMaterial());
            operation.setApplyHandler(Geometry::setMaterial);

            changeConsumer.execute(operation);
        }
    }

    super.accept(changeConsumer, object, isCopy);
}
 
Example 14
public void setupFloor(){
    Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
    mat.getTextureParam("DiffuseMap").getTextureValue().setWrap(WrapMode.Repeat);
    mat.getTextureParam("NormalMap").getTextureValue().setWrap(WrapMode.Repeat);
   // mat.getTextureParam("ParallaxMap").getTextureValue().setWrap(WrapMode.Repeat);
    mat.setFloat("Shininess",3);
  //  mat.setBoolean("VertexLighting", true);
    
    
    Box floor = new Box(50, 1f, 50);
    TangentBinormalGenerator.generate(floor);
    floor.scaleTextureCoordinates(new Vector2f(5, 5));
    Geometry floorGeom = new Geometry("Floor", floor);
    floorGeom.setMaterial(mat);
    floorGeom.setShadowMode(ShadowMode.Receive);
    rootNode.attachChild(floorGeom);
}
 
Example 15
@Override
public void simpleInitApp() {
  flyCam.setMoveSpeed(40);
  
  /** just a blue box floating in space */
  Box box1 = new Box(1, 1, 1);
  player = new Geometry("Player", box1);
  Material mat1 = new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md");
  mat1.setColor("Color", ColorRGBA.Blue);
  player.setMaterial(mat1);
  rootNode.attachChild(player);

  /** custom init methods, see below */
  initKeys();
  initAudio();
}
 
Example 16
public void initMaterial() {
    mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg");
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    mat.setTexture("ColorMap", tex);

    mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
    key2.setGenerateMips(true);
    Texture tex2 = assetManager.loadTexture(key2);
    mat2.setTexture("ColorMap", tex2);

    mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.jpg");
    key3.setGenerateMips(true);
    Texture tex3 = assetManager.loadTexture(key3);
    tex3.setWrap(WrapMode.Repeat);
    mat3.setTexture("ColorMap", tex3);
}
 
Example 17
@Override
public void simpleInitApp() {
    Spatial signpost = (Spatial) assetManager.loadAsset(new OgreMeshKey("Models/Sign Post/Sign Post.mesh.xml"));
    signpost.setMaterial( (Material) assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m"));
    TangentBinormalGenerator.generate(signpost);
    rootNode.attachChild(signpost);

    lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    lightMdl.setMaterial( (Material) assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    rootNode.attachChild(lightMdl);

    // flourescent main light
    pl = new PointLight();
    pl.setColor(new ColorRGBA(0.88f, 0.92f, 0.95f, 1.0f));
    rootNode.addLight(pl);
    
    AmbientLight al = new AmbientLight();
    al.setColor(new ColorRGBA(0.44f, 0.40f, 0.20f, 1.0f));
    rootNode.addLight(al);
    
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(1,-1,-1).normalizeLocal());
    dl.setColor(new ColorRGBA(0.92f, 0.85f, 0.8f, 1.0f));
    rootNode.addLight(dl);
}
 
Example 18
/**
 * Creates a BasicShadowRenderer
 * @param manager the asset manager
 * @param size the size of the shadow map (the map is square)
 */
public BasicShadowRenderer(AssetManager manager, int size) {
    shadowFB = new FrameBuffer(size, size, 1);
    shadowMap = new Texture2D(size, size, Format.Depth);
    shadowFB.setDepthTexture(shadowMap);
    shadowCam = new Camera(size, size);

    preshadowMat = new Material(manager, "Common/MatDefs/Shadow/PreShadow.j3md");
    postshadowMat = new Material(manager, "Common/MatDefs/Shadow/PostShadow.j3md");
    postshadowMat.setTexture("ShadowMap", shadowMap);

    dispPic.setTexture(manager, shadowMap, false);

    for (int i = 0; i < points.length; i++) {
        points[i] = new Vector3f();
    }
}
 
Example 19
Source Project: jmonkeybuilder   Source File: MaterialFileEditor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
@FxThread
protected void handleExternalChanges() {
    super.handleExternalChanges();

    final Path assetFile = notNull(getAssetFile(getEditFile()));
    final MaterialKey materialKey = new MaterialKey(toAssetPath(assetFile));

    final AssetManager assetManager = EditorUtil.getAssetManager();
    final Material material = assetManager.loadAsset(materialKey);

    reload(material);

    final EditorOperationControl operationControl = getOperationControl();
    operationControl.clear();
}
 
Example 20
@Override
public void simpleInitApp() {
    flyCam.setDragToRotate(true);
    
    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    geom.setMaterial(mat);
    rootNode.attachChild(geom);
    /*
     * Wait until both AWT panels are ready.
     */
    try {
        panelsAreReady.await();
    } catch (InterruptedException exception) {
        throw new RuntimeException("Interrupted while waiting for panels", exception);
    }

    panel.attachTo(true, viewPort);
    guiViewPort.setClearFlags(true, true, true);
    panel2.attachTo(false, guiViewPort);
}
 
Example 21
Source Project: jmonkeybuilder   Source File: MaterialFileEditor.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Reload the material.
 */
@FxThread
private void reload(@NotNull final Material material) {
    setCurrentMaterial(material);
    setIgnoreListeners(true);
    try {

        final MaterialEditor3DPart editor3DState = getEditor3DPart();
        editor3DState.updateMaterial(material);

        getSettingsTree().fill(new RootMaterialSettings(material));

        final ComboBox<String> materialDefinitionBox = getMaterialDefinitionBox();
        final ObservableList<String> items = materialDefinitionBox.getItems();
        items.clear();
        items.addAll(RESOURCE_MANAGER.getAvailableResources(FileExtensions.JME_MATERIAL_DEFINITION));

        final MaterialDef materialDef = material.getMaterialDef();
        materialDefinitionBox.getSelectionModel().select(materialDef.getAssetName());

    } finally {
        setIgnoreListeners(false);
    }
}
 
Example 22
@Override
public void simpleInitApp() {
    InstancedNode instancedNode = new InstancedNode("testInstancedNode");
    rootNode.attachChild(instancedNode);

    box = new Geometry("Box", new Box(0.5f, 0.5f, 0.5f));
    Material material = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    material.setBoolean("UseInstancing", true);
    material.setColor("Diffuse", ColorRGBA.Red);
    material.setBoolean("UseMaterialColors", true);
    box.setMaterial(material);

    instancedNode.attachChild(box);
    instancedNode.instance();

    pointLight = new PointLight();
    pointLight.setColor(ColorRGBA.White);
    pointLight.setRadius(10f);
    rootNode.addLight(pointLight);

    box.setLocalTranslation(new Vector3f(offset, 0, 0));
    pointLight.setPosition(new Vector3f(offset - 3f, 0, 0));

    cam.setLocation(new Vector3f(offset - 5f, 0, 0));
    cam.lookAtDirection(Vector3f.UNIT_X, Vector3f.UNIT_Y);
}
 
Example 23
private void createMarker() {
    // collision marker
    Sphere sphere = new Sphere(8, 8, 0.5f);
    marker = new Geometry("Marker");
    marker.setMesh(sphere);
    
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", new ColorRGBA(251f/255f, 130f/255f, 0f, 0.6f));
    mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
    
    marker.setMaterial(mat);
    rootNode.attachChild(marker);
    
    
    // surface normal marker
    Arrow arrow = new Arrow(new Vector3f(0,1,0));
    markerNormal = new Geometry("MarkerNormal");
    markerNormal.setMesh(arrow);
    markerNormal.setMaterial(mat);
    rootNode.attachChild(markerNormal);
}
 
Example 24
Source Project: jmonkeybuilder   Source File: MaterialUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Check a material on containing a texture.
 *
 * @param material  the material.
 * @param assetPath the path of the texture.
 * @return true if the material definition contains the texture.
 */
@FromAnyThread
private static boolean containsTexture(@NotNull Material material, @NotNull String assetPath) {

    var materialParams = material.getParams();

    for (var materialParam : materialParams) {

        if (materialParam.getVarType() != VarType.Texture2D) {
            continue;
        }

        var value = (Texture) materialParam.getValue();
        var textureKey = value == null ? null : (TextureKey) value.getKey();
        if (textureKey != null && StringUtils.equals(textureKey.getName(), assetPath)) {
            return true;
        }
    }

    return false;
}
 
Example 25
private void initScene() {
    //init cam location
    cam.setLocation(new Vector3f(0, 10, 10));
    cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);
    //init scene
    sceneNode = new Node("Scene");
    mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    geom.setMaterial(mat);
    sceneNode.attachChild(geom);

    // load sky
    sceneNode.attachChild(SkyFactory.createSky(assetManager, 
            "Textures/Sky/Bright/BrightSky.dds", 
            SkyFactory.EnvMapType.CubeMap));
    rootNode.attachChild(sceneNode);

    //add lightPos Geometry
    Sphere lite=new Sphere(8, 8, 3.0f);
    lightSphere=new Geometry("lightsphere", lite);
    lightSphere.setMaterial(mat);
    lightSphere.setLocalTranslation(lightPos);
    rootNode.attachChild(lightSphere);
}
 
Example 26
public void simpleInitApp() {
   ViewPort niftyView = renderManager.createPreView("NiftyView", new Camera(1024, 768));
   niftyView.setClearFlags(true, true, true);
    NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,
                                                      inputManager,
                                                      audioRenderer,
                                                      niftyView);
    nifty = niftyDisplay.getNifty();
    nifty.fromXml("all/intro.xml", "start");
    niftyView.addProcessor(niftyDisplay);

    Texture2D depthTex = new Texture2D(1024, 768, Format.Depth);
    FrameBuffer fb = new FrameBuffer(1024, 768, 1);
    fb.setDepthTexture(depthTex);

    Texture2D tex = new Texture2D(1024, 768, Format.RGBA8);
    tex.setMinFilter(MinFilter.Trilinear);
    tex.setMagFilter(MagFilter.Bilinear);

    fb.setColorTexture(tex);
    niftyView.setClearFlags(true, true, true);
    niftyView.setOutputFrameBuffer(fb);

    Box b = new Box(Vector3f.ZERO, 1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", tex);
    geom.setMaterial(mat);
    rootNode.attachChild(geom);
}
 
Example 27
@Override
public void simpleInitApp() {
    flyCam.setEnabled(false);

    Geometry blueBox = new Geometry("blue box", mesh);
    Material blueMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    blueMat.setColor("Color", ColorRGBA.Blue);
    blueBox.setMaterial(blueMat);
    rootNode.attachChild(blueBox);

    rightCam = cam.clone();
    rightCam.setViewPort(0.5f, 1f, 0f, 1f);

    rightView = renderManager.createMainView("right", rightCam);
    rightView.setClearFlags(true, true, true);
    rightView.setEnabled(false);
    rightView.attachScene(rootNode);

    Geometry redBox = new Geometry("red box", mesh);
    Material redMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    redMat.setColor("Color", ColorRGBA.Red);
    redBox.setMaterial(redMat);
    leftScene.attachChild(redBox);

    leftCam = cam.clone();
    leftCam.setViewPort(0f, 0.5f, 0f, 1f);

    leftView = renderManager.createMainView("left", leftCam);
    leftView.setClearFlags(true, true, true);
    leftView.setEnabled(false);
    leftView.attachScene(leftScene);

    inputManager.addMapping("lmb", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(this, "lmb");
}
 
Example 28
private static void testEquality(Material mat1, Material mat2, boolean expected) {
    if (mat2.contentEquals(mat1)) {
        System.out.print(mat1.getName() + " == " + mat2.getName());
        if (expected) {
            System.out.println(" EQUAL OK");
        } else {
            System.out.println(" EQUAL FAIL!");
        }
    } else {
        System.out.print(mat1.getName() + " != " + mat2.getName());
        if (!expected) {
            System.out.println(" EQUAL OK");
        } else {
            System.out.println(" EQUAL FAIL!");
        }
    }
    if (mat2.hashCode() == mat1.hashCode()){
        System.out.print(mat1.getName() + " == " + mat2.getName());
        if (expected) {
            System.out.println(" HASH OK");
        } else {
            System.out.println(" HASH FAIL!");
        }
    } else {
        System.out.print(mat1.getName() + " != " + mat2.getName());
        if (!expected) {
            System.out.println(" HASH OK");
        } else {
            System.out.println(" HASH FAIL!");
        }
    }
}
 
Example 29
public void setupSignpost(){
    Spatial signpost = assetManager.loadModel("Models/Sign Post/Sign Post.mesh.xml");
    Material mat = assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m");
    signpost.setMaterial(mat);
    signpost.rotate(0, FastMath.HALF_PI, 0);
    signpost.setLocalTranslation(12, 3.5f, 30);
    signpost.setLocalScale(4);
    signpost.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(signpost);
}
 
Example 30
Source Project: jmonkeybuilder   Source File: AbstractSceneEditor3DPart.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create the material to present selected models.
 */
@FromAnyThread
private @NotNull Material createColorMaterial(@NotNull final ColorRGBA color) {
    final Material material = new Material(EditorUtil.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    material.getAdditionalRenderState().setWireframe(true);
    material.setColor("Color", color);
    return material;
}