com.jme3.material.RenderState.BlendMode Java Examples

The following examples show how to use com.jme3.material.RenderState.BlendMode. 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
Source File: TextEntryComponent.java    From Lemur with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public TextEntryComponent( DocumentModel model, BitmapFont font ) {
    this.font = font;
    this.bitmapText = new BitmapText(font);
    bitmapText.setLineWrapMode(LineWrapMode.Clip);
    // Can't really do this since we don't know what
    // bucket it will actually end up in Gui or regular.
    //bitmapText.setQueueBucket( Bucket.Transparent );
    this.model = model;
    
    // Create a versioned reference for watching for updates, external or otherwise
    this.modelRef = model.createReference();
    this.caratRef = model.createCaratReference();

    cursorQuad = new Quad(getCursorWidth(), bitmapText.getLineHeight());
    cursor = new Geometry( "cursor", cursorQuad );
    GuiMaterial mat = GuiGlobals.getInstance().createMaterial(new ColorRGBA(1,1,1,0.75f), false);
    cursor.setMaterial(mat.getMaterial());
    cursor.getMaterial().getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
    cursor.setUserData("layer", 1);
    bitmapText.attachChild(cursor);

    if( model.getText() != null ) {
        resetText();
    }
}
 
Example #2
Source File: TextEntryComponent.java    From Lemur with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public TextEntryComponent clone() {
    TextEntryComponent result = (TextEntryComponent)super.clone();
    result.bitmapText = new BitmapText(font);
    bitmapText.setLineWrapMode(LineWrapMode.Clip);
    
    result.model = model.clone();
    result.preferredSize = null;
    result.textBox = null;
    result.keyHandler = result.new KeyHandler();
    result.cursorQuad = new Quad(getCursorWidth(), bitmapText.getLineHeight());
    result.cursor = new Geometry("cursor", cursorQuad);
    GuiMaterial mat = GuiGlobals.getInstance().createMaterial(new ColorRGBA(1,1,1,0.75f), false);
    result.cursor.setMaterial(mat.getMaterial());
    result.cursor.getMaterial().getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
    result.bitmapText.attachChild(cursor);
    result.resetText();

    return result;
}
 
Example #3
Source File: TerrainTestModifyHeight.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #4
Source File: TestPostWater.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void createBox() {
        //creating a transluscent box
        box = new Geometry("box", new Box(new Vector3f(0, 0, 0), 50, 50, 50));
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", new ColorRGBA(1.0f, 0, 0, 0.3f));
        mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
        //mat.getAdditionalRenderState().setDepthWrite(false);
        //mat.getAdditionalRenderState().setDepthTest(false);
        box.setMaterial(mat);
        box.setQueueBucket(Bucket.Translucent);


        //creating a post view port
//        ViewPort post=renderManager.createPostView("transpPost", cam);
//        post.setClearFlags(false, true, true);


        box.setLocalTranslation(-600, 0, 300);

        //attaching the box to the post viewport
        //Don't forget to updateGeometricState() the box in the simpleUpdate
        //  post.attachScene(box);

        rootNode.attachChild(box);
    }
 
Example #5
Source File: TestPostWater.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void createBox() {
        //creating a transluscent box
        box = new Geometry("box", new Box(50, 50, 50));
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", new ColorRGBA(1.0f, 0, 0, 0.3f));
        mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
        //mat.getAdditionalRenderState().setDepthWrite(false);
        //mat.getAdditionalRenderState().setDepthTest(false);
        box.setMaterial(mat);
        box.setQueueBucket(Bucket.Translucent);


        //creating a post view port
//        ViewPort post=renderManager.createPostView("transpPost", cam);
//        post.setClearFlags(false, true, true);


        box.setLocalTranslation(-600, 0, 300);

        //attaching the box to the post viewport
        //Don't forget to updateGeometricState() the box in the simpleUpdate
        //  post.attachScene(box);

        rootNode.attachChild(box);
    }
 
Example #6
Source File: TerrainTestModifyHeight.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 #7
Source File: StatsAppState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void loadDarken() {
    Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", new ColorRGBA(0,0,0,0.5f));
    mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

    darkenFps = new Geometry("StatsDarken", new Quad(200, fpsText.getLineHeight()));
    darkenFps.setMaterial(mat);
    darkenFps.setLocalTranslation(0, 0, -1);
    darkenFps.setCullHint(showFps && darkenBehind ? CullHint.Never : CullHint.Always);
    guiNode.attachChild(darkenFps);

    darkenStats = new Geometry("StatsDarken", new Quad(200, statsView.getHeight()));
    darkenStats.setMaterial(mat);
    darkenStats.setLocalTranslation(0, fpsText.getHeight(), -1);
    darkenStats.setCullHint(showStats && darkenBehind ? CullHint.Never : CullHint.Always);
    guiNode.attachChild(darkenStats);
}
 
Example #8
Source File: GLRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void changeBlendMode(RenderState.BlendMode blendMode) {
    if (blendMode != context.blendMode) {
        if (blendMode == RenderState.BlendMode.Off) {
            gl.glDisable(GL.GL_BLEND);
        } else if (context.blendMode == RenderState.BlendMode.Off) {
            gl.glEnable(GL.GL_BLEND);
        }

        context.blendMode = blendMode;
    }
}
 
Example #9
Source File: SceneComposerToolController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Material getAudioMarkerMaterial() {
    if (audioMarkerMaterial == null) {
        Material mat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
        Texture tex = manager.loadTexture("com/jme3/gde/scenecomposer/audionode.gif");
        mat.setTexture("ColorMap", tex);
        mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
        audioMarkerMaterial = mat;
    }
    return audioMarkerMaterial;
}
 
Example #10
Source File: SceneComposerToolController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Material getLightMarkerMaterial() {
    if (lightMarkerMaterial == null) {
        Material mat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
        Texture tex = manager.loadTexture("com/jme3/gde/scenecomposer/lightbulb32.png");
        mat.setTexture("ColorMap", tex);
        mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
        lightMarkerMaterial = mat;
    }
    return lightMarkerMaterial;
}
 
Example #11
Source File: Picture.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Set the texture to put on the picture.
 * 
 * @param assetManager The {@link AssetManager} to use to load the material.
 * @param tex The texture
 * @param useAlpha If true, the picture will appear transparent and allow
 * objects behind it to appear through. If false, the transparent
 * portions will be the image's color at that pixel.
 */
public void setTexture(AssetManager assetManager, Texture2D tex, boolean useAlpha){
    if (getMaterial() == null){
        Material mat = new Material(assetManager, "Common/MatDefs/Gui/Gui.j3md");
        mat.setColor("Color", ColorRGBA.White);
        setMaterial(mat);
    }
    material.getAdditionalRenderState().setBlendMode(useAlpha ? BlendMode.Alpha : BlendMode.Off);
    material.setTexture("Texture", tex);
}
 
Example #12
Source File: J3MLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void readRenderStateStatement(String statement) throws IOException{
    String[] split = statement.split(whitespacePattern);
    if (split[0].equals("Wireframe")){
        renderState.setWireframe(parseBoolean(split[1]));
    }else if (split[0].equals("FaceCull")){
        renderState.setFaceCullMode(FaceCullMode.valueOf(split[1]));
    }else if (split[0].equals("DepthWrite")){
        renderState.setDepthWrite(parseBoolean(split[1]));
    }else if (split[0].equals("DepthTest")){
        renderState.setDepthTest(parseBoolean(split[1]));
    }else if (split[0].equals("Blend")){
        renderState.setBlendMode(BlendMode.valueOf(split[1]));
    }else if (split[0].equals("AlphaTestFalloff")){
        renderState.setAlphaTest(true);
        renderState.setAlphaFallOff(Float.parseFloat(split[1]));
    }else if (split[0].equals("PolyOffset")){
        float factor = Float.parseFloat(split[1]);
        float units = Float.parseFloat(split[2]);
        renderState.setPolyOffset(factor, units);
    }else if (split[0].equals("ColorWrite")){
        renderState.setColorWrite(parseBoolean(split[1]));
    }else if (split[0].equals("PointSprite")){
        renderState.setPointSprite(parseBoolean(split[1]));
    }else{
        throwIfNequal(null, split[0]);
    }
}
 
Example #13
Source File: TerrainSplatTexture.java    From OpenRTS with MIT License 5 votes vote down vote up
public void buildMaterial() {
		mat = new Material(am, "matdefs/MyTerrainLighting.j3md");

		Texture2D alpha0 = new Texture2D(new Image(Image.Format.RGBA8, atlas.getWidth(), atlas.getHeight(), atlas.getBuffer(0)));
		mat.setTexture("AlphaMap", alpha0);
//		mat.setTexture("AlphaMap", am.loadTexture("textures/alphatest.png"));

		Texture2D alpha1 = new Texture2D(new Image(Image.Format.RGBA8, atlas.getWidth(), atlas.getHeight(), atlas.getBuffer(1)));
		mat.setTexture("AlphaMap_1", alpha1);
		
		if(transp){
			mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
//			mat.setFloat("AlphaDiscardThreshold", 0.5f);
		}

		for (int i = 0; i < 12; i++) {
			if (diffuseMaps.size() > i) {
				if (i == 0) {
					mat.setTexture("DiffuseMap", diffuseMaps.get(i));
				} else {
					mat.setTexture("DiffuseMap_" + i, diffuseMaps.get(i));
				}

				mat.setFloat("DiffuseMap_" + i + "_scale", scales.get(i).floatValue());
				if (normaMaps.get(i) != null) {
					if (i == 0) {
						mat.setTexture("NormalMap", normaMaps.get(i));
					} else {
						mat.setTexture("NormalMap_" + i, normaMaps.get(i));
					}
				}
			}
		}
	}
 
Example #14
Source File: J3MLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void readRenderStateStatement(Statement statement) throws IOException{
    String[] split = statement.getLine().split(whitespacePattern);
    if (split[0].equals("Wireframe")){
        renderState.setWireframe(parseBoolean(split[1]));
    }else if (split[0].equals("FaceCull")){
        renderState.setFaceCullMode(FaceCullMode.valueOf(split[1]));
    }else if (split[0].equals("DepthWrite")){
        renderState.setDepthWrite(parseBoolean(split[1]));
    }else if (split[0].equals("DepthTest")){
        renderState.setDepthTest(parseBoolean(split[1]));
    }else if (split[0].equals("Blend")){
        renderState.setBlendMode(BlendMode.valueOf(split[1]));
    }else if (split[0].equals("BlendEquation")){
        renderState.setBlendEquation(BlendEquation.valueOf(split[1]));
    }else if (split[0].equals("BlendEquationAlpha")){
        renderState.setBlendEquationAlpha(RenderState.BlendEquationAlpha.valueOf(split[1]));
    }else if (split[0].equals("AlphaTestFalloff")){
        // Ignore for backwards compatbility
    }else if (split[0].equals("PolyOffset")){
        float factor = Float.parseFloat(split[1]);
        float units = Float.parseFloat(split[2]);
        renderState.setPolyOffset(factor, units);
    }else if (split[0].equals("ColorWrite")){
        renderState.setColorWrite(parseBoolean(split[1]));
    }else if (split[0].equals("PointSprite")){
        // Ignore for backwards compatbility
    }else if (split[0].equals("DepthFunc")){
        renderState.setDepthFunc(RenderState.TestFunction.valueOf(split[1]));
    }else if (split[0].equals("AlphaFunc")){
        renderState.setAlphaFunc(RenderState.TestFunction.valueOf(split[1]));
    }else if (split[0].equals("LineWidth")){
        renderState.setLineWidth(Float.parseFloat(split[1]));
    } else {
        throw new MatParseException(null, split[0], statement);
    }
}
 
Example #15
Source File: Picture.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Set the texture to put on the picture.
 * 
 * @param assetManager The {@link AssetManager} to use to load the material.
 * @param tex The texture
 * @param useAlpha If true, the picture will appear transparent and allow
 * objects behind it to appear through. If false, the transparent
 * portions will be the image's color at that pixel.
 */
public void setTexture(AssetManager assetManager, Texture2D tex, boolean useAlpha){
    if (getMaterial() == null){
        Material mat = new Material(assetManager, "Common/MatDefs/Gui/Gui.j3md");
        mat.setColor("Color", ColorRGBA.White);
        setMaterial(mat);
    }
    material.getAdditionalRenderState().setBlendMode(useAlpha ? BlendMode.Alpha : BlendMode.Off);
    material.setTexture("Texture", tex);
}
 
Example #16
Source File: ListBox.java    From Lemur with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@StyleDefaults(ELEMENT_ID)
public static void initializeDefaultStyles( Styles styles, Attributes attrs ) {
 
    ElementId parent = new ElementId(ELEMENT_ID);
    //QuadBackgroundComponent quad = new QuadBackgroundComponent(new ColorRGBA(0.5f, 0.5f, 0.5f, 1));
    QuadBackgroundComponent quad = new QuadBackgroundComponent(new ColorRGBA(0.8f, 0.9f, 0.1f, 1));
    quad.getMaterial().getMaterial().getAdditionalRenderState().setBlendMode(BlendMode.Exclusion);
    styles.getSelector(parent.child(SELECTOR_ID), null).set("background", quad, false);        
}
 
Example #17
Source File: FbxMaterial.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Material createMaterial() {
	Material m = new Material(scene.assetManager, "Common/MatDefs/Light/Lighting.j3md");
	m.setName(name);
	ambientColor.multLocal(ambientFactor);
	diffuseColor.multLocal(diffuseFactor);
	specularColor.multLocal(specularFactor);
	m.setColor("Ambient", new ColorRGBA(ambientColor.x, ambientColor.y, ambientColor.z, 1));
	m.setColor("Diffuse", new ColorRGBA(diffuseColor.x, diffuseColor.y, diffuseColor.z, 1));
	m.setColor("Specular", new ColorRGBA(specularColor.x, specularColor.y, specularColor.z, 1));
	m.setFloat("Shininess", shininessExponent);
	m.setBoolean("UseMaterialColors", true);
	m.setFloat("AlphaDiscardThreshold", 0.5f); // TODO replace with right way in JME to set "Aplha Test"
	m.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
	return m;
}
 
Example #18
Source File: TestJoystick.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public ButtonView( String name, float x, float y, float width, float height ) {
    super( "Button:" + name );
    setLocalTranslation( x, y, -0.5f );
    
    material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    material.setColor( "Color", hilite );
    material.getAdditionalRenderState().setBlendMode( BlendMode.Alpha ); 

    Geometry g = new Geometry( "highlight", new Quad(width, height) );
    g.setMaterial(material); 
    attachChild(g);
    
    resetState();            
}
 
Example #19
Source File: IconComponent.java    From Lemur with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void createIcon() {
    Vector2f imageSize = getEffectiveIconSize();
    float width = iconScale.x * imageSize.x;
    float height = iconScale.y * imageSize.y;
    Quad q = new Quad(width, height);
    icon = new Geometry("icon:" + imagePath, q);
    if( material == null ) {
        material = GuiGlobals.getInstance().createMaterial(lit);
        material.setColor(color);
        material.setTexture(image);

        material.getMaterial().getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
        // AlphaTest and AlphaFalloff are deprecated in favor of the material
        // parameter... in fact in current JME there are no-ops.
        //material.getMaterial().getAdditionalRenderState().setAlphaTest(true);
        //material.getMaterial().getAdditionalRenderState().setAlphaFallOff(0.01f);
        material.getMaterial().setFloat("AlphaDiscardThreshold", 0.1f);
    }

    icon.setMaterial(material.getMaterial());

    // Leave it invisible until the first time we are reshaped.
    // Without this, there is a noticeable one-frame jump from
    // 0,0,0 to it's proper position.
    icon.setCullHint(CullHint.Always);

    // Just in case but it should never happen
    if( isAttached() ) {
        getNode().attachChild(icon);
    }
}
 
Example #20
Source File: TbtQuadBackgroundComponent.java    From Lemur with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void createMaterial() {
    material = GuiGlobals.getInstance().createMaterial(texture, lit);
    if( color != null ) {
        material.setColor(color);
    }
    material.getMaterial().getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
}
 
Example #21
Source File: QuadBackgroundComponent.java    From Lemur with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void createMaterial() {
    material = GuiGlobals.getInstance().createMaterial(color, lit);
    if( texture != null ) {
        material.setTexture(texture);
    }
    material.getMaterial().getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
    // AlphaTest and AlphaFalloff are deprecated in favor of the material
    // parameter... in fact in current JME there are no-ops.
    //material.getMaterial().getAdditionalRenderState().setAlphaTest(true);
    //material.getMaterial().getAdditionalRenderState().setAlphaFallOff(0.1f);
    material.getMaterial().setFloat("AlphaDiscardThreshold", 0.1f);
}
 
Example #22
Source File: MaterialManager.java    From OpenRTS with MIT License 4 votes vote down vote up
private static void initBaseMaterials() {
	ColorRGBA lotColorBase = new ColorRGBA(200f / 255f, 200f / 255f, 200f / 255f, 255f / 255f);
	ColorRGBA concreteColor = new ColorRGBA(90f / 255f, 100f / 255f, 255f / 255f, 255f / 255f);
	ColorRGBA redConcreteColor = ColorRGBA.Red;
	ColorRGBA blueConcreteColor = ColorRGBA.Blue;
	ColorRGBA yellowConcreteColor = ColorRGBA.Yellow;
	ColorRGBA cyanConcreteColor = new ColorRGBA(0, 1, 1, 0.4f);
	ColorRGBA blackConcreteColor = ColorRGBA.Black;
	ColorRGBA greenConcreteColor = ColorRGBA.Green;
	ColorRGBA floorColor = ColorRGBA.Gray;
	ColorRGBA windowsColor = ColorRGBA.White;
	ColorRGBA itemColor = ColorRGBA.LightGray;
	ColorRGBA roadsColor = ColorRGBA.LightGray;
	ColorRGBA terrainColor = new ColorRGBA(0f / 255f, 50f / 255f, 14f / 255f, 255f / 255f);

	am.registerLocator("assets/", FileLocator.class);

	contourMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
	contourMaterial.setColor("Color", blackConcreteColor);

	blockContourMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
	blockContourMaterial.setColor("Color", redConcreteColor);

	lotContourMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
	lotContourMaterial.setColor("Color", blueConcreteColor);

	lotMaterial1 = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
	lotMaterial1.setColor("Color", lotColorBase);

	lotMaterial2 = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
	lotMaterial2.setColor("Color", lotColorBase);

	lotMaterial3 = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
	lotMaterial3.setColor("Color", lotColorBase);

	// debug material
	debugMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
	debugMaterial.setColor("Color", redConcreteColor);
	// debug texture material
	// debugTextureMaterial = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
	// debugTextureMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
	// debugTextureMaterial.setTexture("DiffuseMap", assetManager.loadTexture("Textures/UVTest.jpg"));
	// debugTextureMaterial.setFloat("Shininess", 128f); // [0,128]

	// Red Material
	redMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
	redMaterial.setColor("Color", redConcreteColor);
	redMaterial.setColor("GlowColor", redConcreteColor);

	// Concrete Material
	yellowMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
	yellowMaterial.setColor("Color", yellowConcreteColor);

	// Concrete Material
	cyanMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
	cyanMaterial.setColor("Color", cyanConcreteColor);
	cyanMaterial.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

	// Concrete Material
	blackMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
	blackMaterial.setColor("Color", blackConcreteColor);

	// Concrete Material
	greenMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
	greenMaterial.setColor("Color", greenConcreteColor);
	greenMaterial.setColor("GlowColor", greenConcreteColor);

	// Item Material
	itemMaterial = new Material(am, "Common/MatDefs/Light/Lighting.j3md");
	itemMaterial.setColor("Diffuse", itemColor);
	itemMaterial.setBoolean("UseMaterialColors", true);

	// gradient blue
	for (int i = 0; i < 4; i++) {
		gradientMaterial.add(new Material(am, "Common/MatDefs/Misc/Unshaded.j3md"));
		gradientMaterial.get(i).setColor("Color", new ColorRGBA(i * 30 / 255f, i * 30 / 255f, i * 85 / 255f, 1));
	}
}
 
Example #23
Source File: TestMaterialCompare.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static void main(String[] args) {
    AssetManager assetManager = JmeSystem.newAssetManager(
            TestMaterialCompare.class.getResource("/com/jme3/asset/Desktop.cfg"));
    
    // Cloned materials
    Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat1.setName("mat1");
    mat1.setColor("Color", ColorRGBA.Blue);

    Material mat2 = mat1.clone();
    mat2.setName("mat2");
    testEquality(mat1, mat2, true);

    // Cloned material with different render states
    Material mat3 = mat1.clone();
    mat3.setName("mat3");
    mat3.getAdditionalRenderState().setBlendMode(BlendMode.ModulateX2);
    testEquality(mat1, mat3, false);

    // Two separately loaded materials
    Material mat4 = assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m");
    mat4.setName("mat4");
    Material mat5 = assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m");
    mat5.setName("mat5");
    testEquality(mat4, mat5, true);
    
    // Comparing same textures
    TextureKey originalKey = (TextureKey) mat4.getTextureParam("DiffuseMap").getTextureValue().getKey();
    TextureKey tex1key = new TextureKey("Models/Sign Post/Sign Post.jpg", false);
    tex1key.setGenerateMips(true);
    
    // Texture keys from the original and the loaded texture
    // must be identical, otherwise the resultant textures not identical
    // and thus materials are not identical!
    if (!originalKey.equals(tex1key)){
        System.out.println("TEXTURE KEYS ARE NOT EQUAL");
    }
    
    Texture tex1 = assetManager.loadTexture(tex1key);
    mat4.setTexture("DiffuseMap", tex1);
    testEquality(mat4, mat5, true);
    
    // Change some stuff on the texture and compare, materials no longer equal
    tex1.setWrap(Texture.WrapMode.MirroredRepeat);
    testEquality(mat4, mat5, false);
    
    // Comparing different textures
    Texture tex2 = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
    mat4.setTexture("DiffuseMap", tex2);
    testEquality(mat4, mat5, false);

    // Two materials created the same way
    Material mat6 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat6.setName("mat6");
    mat6.setColor("Color", ColorRGBA.Blue);
    testEquality(mat1, mat6, true);

    // Changing a material param
    mat6.setColor("Color", ColorRGBA.Green);
    testEquality(mat1, mat6, false);
}
 
Example #24
Source File: HelloMaterial.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void simpleInitApp() {

  /** A simple textured cube -- in good MIP map quality. */
  Box boxshape1 = new Box(new Vector3f(-3f,1.1f,0f), 1f,1f,1f);
  Geometry cube = new Geometry("My Textured Box", boxshape1);
  Material mat_stl = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  Texture tex_ml = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
  mat_stl.setTexture("ColorMap", tex_ml);
  cube.setMaterial(mat_stl);
  rootNode.attachChild(cube);

  /** A translucent/transparent texture, similar to a window frame. */
  Box boxshape3 = new Box(new Vector3f(0f,0f,0f), 1f,1f,0.01f);
  Geometry window_frame = new Geometry("window frame", boxshape3);
  Material mat_tt = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  mat_tt.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
  mat_tt.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);  // activate transparency
  window_frame.setQueueBucket(Bucket.Transparent);
  window_frame.setMaterial(mat_tt);
  rootNode.attachChild(window_frame);

  /** A cube with its base color "leaking" through a partially transparent texture */
  Box boxshape4 = new Box(new Vector3f(3f,-1f,0f), 1f,1f,1f);
  Geometry cube_leak = new Geometry("Leak-through color cube", boxshape4);
  Material mat_tl = new Material(assetManager, "Common/MatDefs/Misc/ColoredTextured.j3md");
  mat_tl.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
  mat_tl.setColor("Color", new ColorRGBA(1f,0f,1f, 1f)); // purple
  cube_leak.setMaterial(mat_tl);
  rootNode.attachChild(cube_leak);
  // cube_leak.setMaterial((Material) assetManager.loadAsset( "Materials/LeakThrough.j3m"));

  /** A bumpy rock with a shiny light effect. To make bumpy objects you must create a NormalMap. */
  Sphere rock = new Sphere(32,32, 2f);
  Geometry shiny_rock = new Geometry("Shiny rock", rock);
  rock.setTextureMode(Sphere.TextureMode.Projected); // better quality on spheres
  TangentBinormalGenerator.generate(rock);           // for lighting effect
  Material mat_lit = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
  mat_lit.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg"));
  mat_lit.setTexture("NormalMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond_normal.png"));
  mat_lit.setFloat("Shininess", 5f); // [0,128]
  shiny_rock.setMaterial(mat_lit);
  shiny_rock.setLocalTranslation(0,2,-2); // Move it a bit
  shiny_rock.rotate(1.6f, 0, 0);          // Rotate it a bit
  rootNode.attachChild(shiny_rock);
  /** Must add a light to make the lit object visible! */
  DirectionalLight sun = new DirectionalLight();
  sun.setDirection(new Vector3f(1,0,-2).normalizeLocal());
  sun.setColor(ColorRGBA.White);
  rootNode.addLight(sun);

}
 
Example #25
Source File: HelloMaterial.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {

  /** A simple textured cube -- in good MIP map quality. */
  Box cube1Mesh = new Box( 1f,1f,1f);
  Geometry cube1Geo = new Geometry("My Textured Box", cube1Mesh);
  cube1Geo.setLocalTranslation(new Vector3f(-3f,1.1f,0f));
  Material cube1Mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  Texture cube1Tex = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
  cube1Mat.setTexture("ColorMap", cube1Tex);
  cube1Geo.setMaterial(cube1Mat);
  rootNode.attachChild(cube1Geo);

  /** A translucent/transparent texture, similar to a window frame. */
  Box cube2Mesh = new Box( 1f,1f,0.01f);
  Geometry cube2Geo = new Geometry("window frame", cube2Mesh);
  Material cube2Mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  cube2Mat.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
  cube2Mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);  // activate transparency
  cube2Geo.setQueueBucket(Bucket.Transparent);
  cube2Geo.setMaterial(cube2Mat);
  rootNode.attachChild(cube2Geo);

  /** A bumpy rock with a shiny light effect. To make bumpy objects you must create a NormalMap. */
  Sphere sphereMesh = new Sphere(32,32, 2f);
  Geometry sphereGeo = new Geometry("Shiny rock", sphereMesh);
  sphereMesh.setTextureMode(Sphere.TextureMode.Projected); // better quality on spheres
  TangentBinormalGenerator.generate(sphereMesh);           // for lighting effect
  Material sphereMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
  sphereMat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg"));
  sphereMat.setTexture("NormalMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond_normal.png"));
  sphereMat.setBoolean("UseMaterialColors",true);    
  sphereMat.setColor("Diffuse",ColorRGBA.White);
  sphereMat.setColor("Specular",ColorRGBA.White);
  sphereMat.setFloat("Shininess", 64f); // [0,128]
  sphereGeo.setMaterial(sphereMat);
  //sphereGeo.setMaterial((Material) assetManager.loadMaterial("Materials/MyCustomMaterial.j3m"));
  sphereGeo.setLocalTranslation(0,2,-2); // Move it a bit
  sphereGeo.rotate(1.6f, 0, 0);          // Rotate it a bit
  rootNode.attachChild(sphereGeo);
  
  /** Must add a light to make the lit object visible! */
  DirectionalLight sun = new DirectionalLight();
  sun.setDirection(new Vector3f(1,0,-2).normalizeLocal());
  sun.setColor(ColorRGBA.White);
  rootNode.addLight(sun);
}
 
Example #26
Source File: SceneEditTool.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
     * Create the axis marker that is selectable
     */
    protected Node createAxisMarker() {
        float size = 2;
        float arrowSize = size;
        float planeSize = size * 0.7f;

        Quaternion YAW090 = new Quaternion().fromAngleAxis(-FastMath.PI / 2, new Vector3f(0, 1, 0));
        Quaternion PITCH090 = new Quaternion().fromAngleAxis(FastMath.PI / 2, new Vector3f(1, 0, 0));

        redMat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
        redMat.getAdditionalRenderState().setWireframe(true);
        redMat.setColor("Color", ColorRGBA.Red);
        //redMat.getAdditionalRenderState().setDepthTest(false);
        greenMat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
        greenMat.getAdditionalRenderState().setWireframe(true);
        greenMat.setColor("Color", ColorRGBA.Green);
        //greenMat.getAdditionalRenderState().setDepthTest(false);
        blueMat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
        blueMat.getAdditionalRenderState().setWireframe(true);
        blueMat.setColor("Color", ColorRGBA.Blue);
        //blueMat.getAdditionalRenderState().setDepthTest(false);
        yellowMat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
        yellowMat.getAdditionalRenderState().setWireframe(false);
        yellowMat.setColor("Color", new ColorRGBA(1f, 1f, 0f, 0.25f));
        yellowMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
        yellowMat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
        //yellowMat.getAdditionalRenderState().setDepthTest(false);
        cyanMat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
        cyanMat.getAdditionalRenderState().setWireframe(false);
        cyanMat.setColor("Color", new ColorRGBA(0f, 1f, 1f, 0.25f));
        cyanMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
        cyanMat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
        //cyanMat.getAdditionalRenderState().setDepthTest(false);
        magentaMat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
        magentaMat.getAdditionalRenderState().setWireframe(false);
        magentaMat.setColor("Color", new ColorRGBA(1f, 0f, 1f, 0.25f));
        magentaMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
        magentaMat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
        //magentaMat.getAdditionalRenderState().setDepthTest(false);

        orangeMat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
        orangeMat.getAdditionalRenderState().setWireframe(false);
        orangeMat.setColor("Color", new ColorRGBA(251f / 255f, 130f / 255f, 0f, 0.4f));
        orangeMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
        orangeMat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);

        Node axis = new Node();

        // create arrows
        Geometry arrowX = new Geometry("arrowX", new Arrow(new Vector3f(arrowSize, 0, 0)));
        Geometry arrowY = new Geometry("arrowY", new Arrow(new Vector3f(0, arrowSize, 0)));
        Geometry arrowZ = new Geometry("arrowZ", new Arrow(new Vector3f(0, 0, arrowSize)));
        axis.attachChild(arrowX);
        axis.attachChild(arrowY);
        axis.attachChild(arrowZ);

        // create planes
        quadXY = new Geometry("quadXY", new Quad(planeSize, planeSize));
        quadXZ = new Geometry("quadXZ", new Quad(planeSize, planeSize));
        quadXZ.setLocalRotation(PITCH090);
        quadYZ = new Geometry("quadYZ", new Quad(planeSize, planeSize));
        quadYZ.setLocalRotation(YAW090);
//        axis.attachChild(quadXY);
//        axis.attachChild(quadXZ);
//        axis.attachChild(quadYZ);

        axis.setModelBound(new BoundingBox());
        return axis;
    }
 
Example #27
Source File: PopupState.java    From Lemur with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected GuiMaterial createBlockerMaterial( ColorRGBA color ) {
    GuiMaterial result = GuiGlobals.getInstance().createMaterial(color, false);
    Material mat = result.getMaterial();
    mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
    return result; 
}