Search in sources :

Example 1 with BlendingAttribute

use of com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute in project libgdx by libgdx.

the class Animation3DTest method onLoaded.

@Override
protected void onLoaded() {
    if (skydome == null) {
        skydome = new ModelInstance(assets.get("data/g3d/skydome.g3db", Model.class));
        floorModel.getMaterial("concrete").set(TextureAttribute.createDiffuse(assets.get("data/g3d/concrete.png", Texture.class)));
        floorModel.getMaterial("tree").set(TextureAttribute.createDiffuse(assets.get("data/tree.png", Texture.class)), new BlendingAttribute());
        instances.add(new ModelInstance(floorModel, "floor"));
        instances.add(tree = new ModelInstance(floorModel, "tree"));
        assets.load("data/g3d/knight.g3db", Model.class);
        loading = true;
    } else if (character == null) {
        character = new ModelInstance(assets.get("data/g3d/knight.g3db", Model.class));
        BoundingBox bbox = new BoundingBox();
        character.calculateBoundingBox(bbox);
        character.transform.setToRotation(Vector3.Y, 180).trn(0, -bbox.min.y, 0);
        instances.add(character);
        animation = new AnimationController(character);
        animation.animate("Idle", -1, 1f, null, 0.2f);
        status = idle;
        for (Animation anim : character.animations) Gdx.app.log("Test", anim.id);
        // Now attach the node of another model at the tip of this knights sword:
        ship = assets.get("data/g3d/ship.obj", Model.class).nodes.get(0).copy();
        ship.detach();
        // offset from the sword node to the tip of the sword, in rest pose
        ship.translation.x = 10f;
        ship.rotation.set(Vector3.Z, 90f);
        ship.scale.scl(5f);
        ship.parts.get(0).enabled = false;
        character.getNode("sword").addChild(ship);
    }
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) BlendingAttribute(com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute) AnimationController(com.badlogic.gdx.graphics.g3d.utils.AnimationController) BoundingBox(com.badlogic.gdx.math.collision.BoundingBox) Model(com.badlogic.gdx.graphics.g3d.Model) Animation(com.badlogic.gdx.graphics.g3d.model.Animation)

Example 2 with BlendingAttribute

use of com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute in project libgdx by libgdx.

the class ModelInstanceRenderer method update.

@Override
public void update() {
    for (int i = 0, positionOffset = 0, c = controller.particles.size; i < c; ++i, positionOffset += renderData.positionChannel.strideSize) {
        ModelInstance instance = renderData.modelInstanceChannel.data[i];
        float scale = hasScale ? renderData.scaleChannel.data[i] : 1;
        float qx = 0, qy = 0, qz = 0, qw = 1;
        if (hasRotation) {
            int rotationOffset = i * renderData.rotationChannel.strideSize;
            qx = renderData.rotationChannel.data[rotationOffset + ParticleChannels.XOffset];
            qy = renderData.rotationChannel.data[rotationOffset + ParticleChannels.YOffset];
            qz = renderData.rotationChannel.data[rotationOffset + ParticleChannels.ZOffset];
            qw = renderData.rotationChannel.data[rotationOffset + ParticleChannels.WOffset];
        }
        instance.transform.set(renderData.positionChannel.data[positionOffset + ParticleChannels.XOffset], renderData.positionChannel.data[positionOffset + ParticleChannels.YOffset], renderData.positionChannel.data[positionOffset + ParticleChannels.ZOffset], qx, qy, qz, qw, scale, scale, scale);
        if (hasColor) {
            int colorOffset = i * renderData.colorChannel.strideSize;
            ColorAttribute colorAttribute = (ColorAttribute) instance.materials.get(0).get(ColorAttribute.Diffuse);
            BlendingAttribute blendingAttribute = (BlendingAttribute) instance.materials.get(0).get(BlendingAttribute.Type);
            colorAttribute.color.r = renderData.colorChannel.data[colorOffset + ParticleChannels.RedOffset];
            colorAttribute.color.g = renderData.colorChannel.data[colorOffset + ParticleChannels.GreenOffset];
            colorAttribute.color.b = renderData.colorChannel.data[colorOffset + ParticleChannels.BlueOffset];
            if (blendingAttribute != null)
                blendingAttribute.opacity = renderData.colorChannel.data[colorOffset + ParticleChannels.AlphaOffset];
        }
    }
    super.update();
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) BlendingAttribute(com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)

Example 3 with BlendingAttribute

use of com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute in project libgdx by libgdx.

the class Model method convertMaterial.

protected Material convertMaterial(ModelMaterial mtl, TextureProvider textureProvider) {
    Material result = new Material();
    result.id = mtl.id;
    if (mtl.ambient != null)
        result.set(new ColorAttribute(ColorAttribute.Ambient, mtl.ambient));
    if (mtl.diffuse != null)
        result.set(new ColorAttribute(ColorAttribute.Diffuse, mtl.diffuse));
    if (mtl.specular != null)
        result.set(new ColorAttribute(ColorAttribute.Specular, mtl.specular));
    if (mtl.emissive != null)
        result.set(new ColorAttribute(ColorAttribute.Emissive, mtl.emissive));
    if (mtl.reflection != null)
        result.set(new ColorAttribute(ColorAttribute.Reflection, mtl.reflection));
    if (mtl.shininess > 0f)
        result.set(new FloatAttribute(FloatAttribute.Shininess, mtl.shininess));
    if (mtl.opacity != 1.f)
        result.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, mtl.opacity));
    ObjectMap<String, Texture> textures = new ObjectMap<String, Texture>();
    // FIXME uvScaling/uvTranslation totally ignored
    if (mtl.textures != null) {
        for (ModelTexture tex : mtl.textures) {
            Texture texture;
            if (textures.containsKey(tex.fileName)) {
                texture = textures.get(tex.fileName);
            } else {
                texture = textureProvider.load(tex.fileName);
                textures.put(tex.fileName, texture);
                disposables.add(texture);
            }
            TextureDescriptor descriptor = new TextureDescriptor(texture);
            descriptor.minFilter = texture.getMinFilter();
            descriptor.magFilter = texture.getMagFilter();
            descriptor.uWrap = texture.getUWrap();
            descriptor.vWrap = texture.getVWrap();
            float offsetU = tex.uvTranslation == null ? 0f : tex.uvTranslation.x;
            float offsetV = tex.uvTranslation == null ? 0f : tex.uvTranslation.y;
            float scaleU = tex.uvScaling == null ? 1f : tex.uvScaling.x;
            float scaleV = tex.uvScaling == null ? 1f : tex.uvScaling.y;
            switch(tex.usage) {
                case ModelTexture.USAGE_DIFFUSE:
                    result.set(new TextureAttribute(TextureAttribute.Diffuse, descriptor, offsetU, offsetV, scaleU, scaleV));
                    break;
                case ModelTexture.USAGE_SPECULAR:
                    result.set(new TextureAttribute(TextureAttribute.Specular, descriptor, offsetU, offsetV, scaleU, scaleV));
                    break;
                case ModelTexture.USAGE_BUMP:
                    result.set(new TextureAttribute(TextureAttribute.Bump, descriptor, offsetU, offsetV, scaleU, scaleV));
                    break;
                case ModelTexture.USAGE_NORMAL:
                    result.set(new TextureAttribute(TextureAttribute.Normal, descriptor, offsetU, offsetV, scaleU, scaleV));
                    break;
                case ModelTexture.USAGE_AMBIENT:
                    result.set(new TextureAttribute(TextureAttribute.Ambient, descriptor, offsetU, offsetV, scaleU, scaleV));
                    break;
                case ModelTexture.USAGE_EMISSIVE:
                    result.set(new TextureAttribute(TextureAttribute.Emissive, descriptor, offsetU, offsetV, scaleU, scaleV));
                    break;
                case ModelTexture.USAGE_REFLECTION:
                    result.set(new TextureAttribute(TextureAttribute.Reflection, descriptor, offsetU, offsetV, scaleU, scaleV));
                    break;
            }
        }
    }
    return result;
}
Also used : BlendingAttribute(com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute) ObjectMap(com.badlogic.gdx.utils.ObjectMap) ModelMaterial(com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial) FloatAttribute(com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute) TextureDescriptor(com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) ModelTexture(com.badlogic.gdx.graphics.g3d.model.data.ModelTexture) Texture(com.badlogic.gdx.graphics.Texture) ModelTexture(com.badlogic.gdx.graphics.g3d.model.data.ModelTexture) TextureAttribute(com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)

Example 4 with BlendingAttribute

use of com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute in project libgdx by libgdx.

the class DefaultShader method bindMaterial.

protected void bindMaterial(final Attributes attributes) {
    int cullFace = config.defaultCullFace == -1 ? defaultCullFace : config.defaultCullFace;
    int depthFunc = config.defaultDepthFunc == -1 ? defaultDepthFunc : config.defaultDepthFunc;
    float depthRangeNear = 0f;
    float depthRangeFar = 1f;
    boolean depthMask = true;
    for (final Attribute attr : attributes) {
        final long t = attr.type;
        if (BlendingAttribute.is(t)) {
            context.setBlending(true, ((BlendingAttribute) attr).sourceFunction, ((BlendingAttribute) attr).destFunction);
            set(u_opacity, ((BlendingAttribute) attr).opacity);
        } else if ((t & IntAttribute.CullFace) == IntAttribute.CullFace)
            cullFace = ((IntAttribute) attr).value;
        else if ((t & FloatAttribute.AlphaTest) == FloatAttribute.AlphaTest)
            set(u_alphaTest, ((FloatAttribute) attr).value);
        else if ((t & DepthTestAttribute.Type) == DepthTestAttribute.Type) {
            DepthTestAttribute dta = (DepthTestAttribute) attr;
            depthFunc = dta.depthFunc;
            depthRangeNear = dta.depthRangeNear;
            depthRangeFar = dta.depthRangeFar;
            depthMask = dta.depthMask;
        } else if (!config.ignoreUnimplemented)
            throw new GdxRuntimeException("Unknown material attribute: " + attr.toString());
    }
    context.setCullFace(cullFace);
    context.setDepthTest(depthFunc, depthRangeNear, depthRangeFar);
    context.setDepthMask(depthMask);
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) BlendingAttribute(com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute) PointLightsAttribute(com.badlogic.gdx.graphics.g3d.attributes.PointLightsAttribute) FloatAttribute(com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute) Attribute(com.badlogic.gdx.graphics.g3d.Attribute) TextureAttribute(com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute) IntAttribute(com.badlogic.gdx.graphics.g3d.attributes.IntAttribute) DirectionalLightsAttribute(com.badlogic.gdx.graphics.g3d.attributes.DirectionalLightsAttribute) CubemapAttribute(com.badlogic.gdx.graphics.g3d.attributes.CubemapAttribute) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) DepthTestAttribute(com.badlogic.gdx.graphics.g3d.attributes.DepthTestAttribute) SpotLightsAttribute(com.badlogic.gdx.graphics.g3d.attributes.SpotLightsAttribute) DepthTestAttribute(com.badlogic.gdx.graphics.g3d.attributes.DepthTestAttribute) FloatAttribute(com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute)

Example 5 with BlendingAttribute

use of com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute in project libgdx by libgdx.

the class DepthShader method render.

@Override
public void render(Renderable renderable, Attributes combinedAttributes) {
    if (combinedAttributes.has(BlendingAttribute.Type)) {
        final BlendingAttribute blending = (BlendingAttribute) combinedAttributes.get(BlendingAttribute.Type);
        combinedAttributes.remove(BlendingAttribute.Type);
        final boolean hasAlphaTest = combinedAttributes.has(FloatAttribute.AlphaTest);
        if (!hasAlphaTest)
            combinedAttributes.set(alphaTestAttribute);
        if (blending.opacity >= ((FloatAttribute) combinedAttributes.get(FloatAttribute.AlphaTest)).value)
            super.render(renderable, combinedAttributes);
        if (!hasAlphaTest)
            combinedAttributes.remove(FloatAttribute.AlphaTest);
        combinedAttributes.set(blending);
    } else
        super.render(renderable, combinedAttributes);
}
Also used : BlendingAttribute(com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute)

Aggregations

BlendingAttribute (com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute)10 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)5 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)4 TextureAttribute (com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)4 Material (com.badlogic.gdx.graphics.g3d.Material)3 DepthTestAttribute (com.badlogic.gdx.graphics.g3d.attributes.DepthTestAttribute)3 IntAttribute (com.badlogic.gdx.graphics.g3d.attributes.IntAttribute)3 Texture (com.badlogic.gdx.graphics.Texture)2 Attribute (com.badlogic.gdx.graphics.g3d.Attribute)2 Model (com.badlogic.gdx.graphics.g3d.Model)2 FloatAttribute (com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute)2 AnimationController (com.badlogic.gdx.graphics.g3d.utils.AnimationController)2 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)2 Color (com.badlogic.gdx.graphics.Color)1 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)1 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)1 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)1 Renderable (com.badlogic.gdx.graphics.g3d.Renderable)1 CubemapAttribute (com.badlogic.gdx.graphics.g3d.attributes.CubemapAttribute)1 DirectionalLightsAttribute (com.badlogic.gdx.graphics.g3d.attributes.DirectionalLightsAttribute)1