com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute Java Examples

The following examples show how to use com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute. 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: FloatAttributeUI.java    From gdx-gltf with Apache License 2.0 6 votes vote down vote up
public FloatAttributeUI(Skin skin, final FloatAttribute attribute) {
	super(skin);
	this.attribute = attribute;
	slider = new Slider(0, 1, .01f, false, skin);
	if(attribute != null){
		add(FloatAttribute.getAttributeAlias(attribute.type));
		add(slider).row();
		slider.setValue(attribute.value);
		slider.addListener(new ChangeListener() {
			@Override
			public void changed(ChangeEvent event, Actor actor) {
				attribute.value = slider.getValue();
			}
		});
	}
}
 
Example #2
Source File: GameRenderer.java    From Radix with MIT License 5 votes vote down vote up
private void drawBlockSelection() {
    int curProgressInt = Math.round(RadixClient.getInstance().getPlayer().getBreakPercent() * 10) - 1;
    if ((blockBreakModel == null || blockBreakStage != curProgressInt) && curProgressInt >= 0) {
        if (blockBreakModel != null)
            blockBreakModel.dispose();

        blockBreakStage = curProgressInt;

        ModelBuilder builder = new ModelBuilder();
        blockBreakModel = builder.createBox(1f, 1f, 1f,
                new Material(TextureAttribute.createDiffuse(blockBreakStages[blockBreakStage]),
                        new BlendingAttribute(),
                        FloatAttribute.createAlphaTest(0.25f)),
                VertexAttributes.Usage.Position | VertexAttributes.Usage.TextureCoordinates);
        blockBreakModelInstance = new ModelInstance(blockBreakModel);
    }

    Vec3i curBlk = RadixClient.getInstance().getSelectedBlock();
    if (curBlk != null && curProgressInt >= 0) {
        Gdx.gl.glPolygonOffset(100000, 2000000);
        blockOverlayBatch.begin(RadixClient.getInstance().getCamera());
        blockBreakModelInstance.transform.translate(curBlk.x + 0.5f, curBlk.y + 0.5f, curBlk.z + 0.5f);
        blockOverlayBatch.render(blockBreakModelInstance);
        blockBreakModelInstance.transform.translate(-(curBlk.x + 0.5f), -(curBlk.y + 0.5f), -(curBlk.z + 0.5f));
        blockOverlayBatch.end();
        Gdx.gl.glPolygonOffset(100000, -2000000);
    }
}
 
Example #3
Source File: ModelShader.java    From Mundus with Apache License 2.0 5 votes vote down vote up
@Override
public void render(Renderable renderable) {
    final MundusEnvironment env = (MundusEnvironment) renderable.environment;

    setLights(env);
    set(UNIFORM_TRANS_MATRIX, renderable.worldTransform);

    // texture uniform
    TextureAttribute diffuseTexture = ((TextureAttribute) (renderable.material.get(TextureAttribute.Diffuse)));
    ColorAttribute diffuseColor = ((ColorAttribute) (renderable.material.get(ColorAttribute.Diffuse)));

    if (diffuseTexture != null) {
        set(UNIFORM_MATERIAL_DIFFUSE_TEXTURE, diffuseTexture.textureDescription.texture);
        set(UNIFORM_MATERIAL_DIFFUSE_USE_TEXTURE, 1);
    } else {
        set(UNIFORM_MATERIAL_DIFFUSE_COLOR, diffuseColor.color);
        set(UNIFORM_MATERIAL_DIFFUSE_USE_TEXTURE, 0);
    }

    // shininess
    float shininess = ((FloatAttribute)renderable.material.get(FloatAttribute.Shininess)).value;
    set(UNIFORM_MATERIAL_SHININESS, shininess);

    // Fog
    final Fog fog = env.getFog();
    if (fog == null) {
        set(UNIFORM_FOG_DENSITY, 0f);
        set(UNIFORM_FOG_GRADIENT, 0f);
    } else {
        set(UNIFORM_FOG_DENSITY, fog.density);
        set(UNIFORM_FOG_GRADIENT, fog.gradient);
        set(UNIFORM_FOG_COLOR, fog.color);
    }

    // bind attributes, bind mesh & render; then unbinds everything
    renderable.meshPart.render(program);
}
 
Example #4
Source File: MaterialAsset.java    From Mundus with Apache License 2.0 5 votes vote down vote up
/**
 * Applies this material asset to the libGDX material.
 *
 * @param material
 * @return
 */
public Material applyToMaterial(Material material) {
    if (diffuseColor != null) {
        material.set(new ColorAttribute(ColorAttribute.Diffuse, diffuseColor));
    }
    if (diffuseTexture != null) {
        material.set(new TextureAttribute(TextureAttribute.Diffuse, diffuseTexture.getTexture()));
    } else {
        material.remove(TextureAttribute.Diffuse);
    }
    material.set(new FloatAttribute(FloatAttribute.Shininess, shininess));

    return material;
}
 
Example #5
Source File: GLTFMaterialExporter.java    From gdx-gltf with Apache License 2.0 4 votes vote down vote up
private void export(Material material) {
	if(base.materialMapping.contains(material, true)) return;
	base.materialMapping.add(material);
	
	GLTFMaterial m = new GLTFMaterial();
	if(base.root.materials == null) base.root.materials = new Array<GLTFMaterial>();
	base.root.materials.add(m);
	

	m.name = material.id;
	
	boolean blending = false;
	for(Attribute a : material){
		if(a.type == ColorAttribute.Diffuse){
			pbr(m).baseColorFactor = GLTFExportTypes.rgba(defaultNull(Color.WHITE, (ColorAttribute)a));
		}
		else if(a.type == PBRColorAttribute.BaseColorFactor){
			pbr(m).baseColorFactor = GLTFExportTypes.rgba(defaultNull(Color.WHITE, (PBRColorAttribute)a));
		}
		else if(a.type == ColorAttribute.Emissive){
			m.emissiveFactor = GLTFExportTypes.rgb(defaultNull(Color.BLACK, (ColorAttribute)a));
		}
		else if(a.type == BlendingAttribute.Type){
			blending = true;
		}
		else if(a.type == IntAttribute.CullFace){
			m.doubleSided = defaultNull(true, ((IntAttribute)a).value == 0);
		}
		else if(a.type == FloatAttribute.AlphaTest){
			m.alphaCutoff = ((FloatAttribute)a).value;
		}
		else if(a.type == PBRFloatAttribute.Metallic){
			pbr(m).metallicFactor = ((PBRFloatAttribute)a).value;
		}
		else if(a.type == PBRFloatAttribute.Roughness){
			pbr(m).roughnessFactor = ((PBRFloatAttribute)a).value;
		}
		else if(a.type == PBRTextureAttribute.BaseColorTexture){
			pbr(m).baseColorTexture = texture((PBRTextureAttribute)a);
		}
		else if(a.type == PBRTextureAttribute.MetallicRoughnessTexture){
			pbr(m).metallicRoughnessTexture = texture((PBRTextureAttribute)a);
		}
		else if(a.type == PBRTextureAttribute.EmissiveTexture){
			m.emissiveTexture = texture((PBRTextureAttribute)a);
		}
		else if(a.type == PBRTextureAttribute.NormalTexture){
			m.normalTexture = normalTexture((PBRTextureAttribute)a, material);
		}
		else if(a.type == PBRTextureAttribute.OcclusionTexture){
			m.occlusionTexture = occlusionTexture((PBRTextureAttribute)a, material);
		}
	}
	if(blending){
		if(m.alphaCutoff != null){
			m.alphaMode = "MASK";
		}else{
			m.alphaMode = "BLEND";
		}
	}
}
 
Example #6
Source File: Chunk.java    From Radix with MIT License 4 votes vote down vote up
private void updateModelInstances() {
    if(opaqueFaces != null) {
        if(opaqueModel != null)
            opaqueModel.dispose();

        Mesh opaqueMesh = mesher.meshFaces(opaqueFaces, meshBuilder);
        modelBuilder.begin();
        modelBuilder.part(String.format("c-%d,%d", startPosition.x, startPosition.z), opaqueMesh, GL20.GL_TRIANGLES,
                new Material(TextureAttribute.createDiffuse(NormalBlockRenderer.getBlockMap())));
        opaqueModel = modelBuilder.end();

        opaqueModelInstance = new ModelInstance(opaqueModel) {
            @Override
            public Renderable getRenderable(final Renderable out, final Node node,
                                            final NodePart nodePart) {
                super.getRenderable(out, node, nodePart);
                if(RadixClient.getInstance().isWireframe()) {
                    out.primitiveType = GL20.GL_LINES;
                } else {
                    out.primitiveType = GL20.GL_TRIANGLES;
                }
                return out;
            }
        };

        opaqueFaces = null;
    }

    if(translucentFaces != null) {
        if(translucentModel != null)
            translucentModel.dispose();

        Mesh translucentMesh = mesher.meshFaces(translucentFaces, meshBuilder);
        modelBuilder.begin();
        modelBuilder.part(String.format("c-%d,%d-t", startPosition.x, startPosition.z), translucentMesh, GL20.GL_TRIANGLES,
                new Material(TextureAttribute.createDiffuse(NormalBlockRenderer.getBlockMap()),
                        new BlendingAttribute(),
                        FloatAttribute.createAlphaTest(0.25f)));
        translucentModel = modelBuilder.end();

        translucentModelInstance = new ModelInstance(translucentModel) {
            @Override
            public Renderable getRenderable(final Renderable out, final Node node,
                                            final NodePart nodePart) {
                super.getRenderable(out, node, nodePart);
                if(RadixClient.getInstance().isWireframe()) {
                    out.primitiveType = GL20.GL_LINES;
                } else {
                    out.primitiveType = GL20.GL_TRIANGLES;
                }
                return out;
            }
        };

        translucentFaces = null;
    }
}