Search in sources :

Example 1 with TextureAttribute

use of gaiasky.util.gdx.shader.attribute.TextureAttribute in project gaiasky by langurmonkey.

the class Star method initModel.

private void initModel(final AssetManager manager) {
    Texture tex = manager.get(Settings.settings.data.dataFile("tex/base/star.jpg"), Texture.class);
    Texture lut = manager.get(Settings.settings.data.dataFile("tex/base/lut.jpg"), Texture.class);
    tex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    Map<String, Object> params = new TreeMap<>();
    params.put("quality", 120L);
    params.put("diameter", 1d);
    params.put("flip", false);
    Pair<IntModel, Map<String, Material>> pair = ModelCache.cache.getModel("sphere", params, Bits.indexes(Usage.Position, Usage.Normal, Usage.TextureCoordinates), GL20.GL_TRIANGLES);
    IntModel model = pair.getFirst();
    Material mat = pair.getSecond().get("base");
    mat.clear();
    mat.set(new TextureAttribute(TextureAttribute.Diffuse, tex));
    mat.set(new TextureAttribute(TextureAttribute.Normal, lut));
    // Only to activate view vector (camera position)
    mat.set(new ColorAttribute(ColorAttribute.Specular));
    mat.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));
    Matrix4 modelTransform = new Matrix4();
    mc = new ModelComponent(false);
    mc.initialize(null);
    mc.env = new Environment();
    mc.env.set(new ColorAttribute(ColorAttribute.AmbientLight, 1f, 1f, 1f, 1f));
    mc.env.set(new FloatAttribute(FloatAttribute.Time, 0f));
    mc.instance = new IntModelInstance(model, modelTransform);
    // Relativistic effects
    if (Settings.settings.runtime.relativisticAberration)
        mc.rec.setUpRelativisticEffectsMaterial(mc.instance.materials);
    mc.setModelInitialized(true);
}
Also used : IntModelInstance(gaiasky.util.gdx.model.IntModelInstance) BlendingAttribute(gaiasky.util.gdx.shader.attribute.BlendingAttribute) Material(gaiasky.util.gdx.shader.Material) TreeMap(java.util.TreeMap) Texture(com.badlogic.gdx.graphics.Texture) Matrix4(com.badlogic.gdx.math.Matrix4) ModelComponent(gaiasky.scenegraph.component.ModelComponent) Environment(gaiasky.util.gdx.shader.Environment) FloatAttribute(gaiasky.util.gdx.shader.attribute.FloatAttribute) IntModel(gaiasky.util.gdx.model.IntModel) ColorAttribute(gaiasky.util.gdx.shader.attribute.ColorAttribute) Map(java.util.Map) TreeMap(java.util.TreeMap) TextureAttribute(gaiasky.util.gdx.shader.attribute.TextureAttribute)

Example 2 with TextureAttribute

use of gaiasky.util.gdx.shader.attribute.TextureAttribute in project gaiasky by langurmonkey.

the class StarGroup method initModel.

private void initModel(final AssetManager manager) {
    Texture tex = manager.get(Settings.settings.data.dataFile("tex/base/star.jpg"), Texture.class);
    Texture lut = manager.get(Settings.settings.data.dataFile("tex/base/lut.jpg"), Texture.class);
    tex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    Map<String, Object> params = new TreeMap<>();
    params.put("quality", 120L);
    params.put("diameter", 1d);
    params.put("flip", false);
    Pair<IntModel, Map<String, Material>> pair = ModelCache.cache.getModel("sphere", params, Bits.indexes(Usage.Position, Usage.Normal, Usage.Tangent, Usage.BiNormal, Usage.TextureCoordinates), GL20.GL_TRIANGLES);
    IntModel model = pair.getFirst();
    Material mat = pair.getSecond().get("base");
    mat.clear();
    mat.set(new TextureAttribute(TextureAttribute.Diffuse, tex));
    mat.set(new TextureAttribute(TextureAttribute.Normal, lut));
    // Only to activate view vector (camera position)
    mat.set(new ColorAttribute(ColorAttribute.Specular));
    mat.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));
    Matrix4 modelTransform = new Matrix4();
    mc = new ModelComponent(false);
    mc.initialize(null);
    mc.env = new Environment();
    mc.env.set(new ColorAttribute(ColorAttribute.AmbientLight, 1f, 1f, 1f, 1f));
    mc.env.set(new FloatAttribute(FloatAttribute.Time, 0f));
    mc.instance = new IntModelInstance(model, modelTransform);
    // Relativistic effects
    if (Settings.settings.runtime.relativisticAberration)
        mc.rec.setUpRelativisticEffectsMaterial(mc.instance.materials);
    mc.setModelInitialized(true);
}
Also used : IntModelInstance(gaiasky.util.gdx.model.IntModelInstance) BlendingAttribute(gaiasky.util.gdx.shader.attribute.BlendingAttribute) Material(gaiasky.util.gdx.shader.Material) Texture(com.badlogic.gdx.graphics.Texture) Matrix4(com.badlogic.gdx.math.Matrix4) ModelComponent(gaiasky.scenegraph.component.ModelComponent) Environment(gaiasky.util.gdx.shader.Environment) FloatAttribute(gaiasky.util.gdx.shader.attribute.FloatAttribute) IntModel(gaiasky.util.gdx.model.IntModel) ColorAttribute(gaiasky.util.gdx.shader.attribute.ColorAttribute) TextureAttribute(gaiasky.util.gdx.shader.attribute.TextureAttribute)

Example 3 with TextureAttribute

use of gaiasky.util.gdx.shader.attribute.TextureAttribute in project gaiasky by langurmonkey.

the class VRContext method loadRenderModel.

private IntModel loadRenderModel(String name, String modelNumber, String manufacturer, VRControllerRole role) {
    if (models.containsKey(name))
        return models.get(name);
    // FIXME we load the models synchronously cause we are lazy
    IntModel model = null;
    if (false) {
        int error;
        PointerBuffer modelPointer = PointerBuffer.allocateDirect(1);
        while (true) {
            error = VRRenderModels.VRRenderModels_LoadRenderModel_Async(name, modelPointer);
            if (error != VR.EVRRenderModelError_VRRenderModelError_Loading)
                break;
        }
        if (error != VR.EVRRenderModelError_VRRenderModelError_None)
            return null;
        RenderModel renderModel = new RenderModel(modelPointer.getByteBuffer(RenderModel.SIZEOF));
        PointerBuffer texturePointer = PointerBuffer.allocateDirect(1);
        while (true) {
            error = VRRenderModels.VRRenderModels_LoadTexture_Async(renderModel.diffuseTextureId(), texturePointer);
            if (error != VR.EVRRenderModelError_VRRenderModelError_Loading)
                break;
        }
        if (error != VR.EVRRenderModelError_VRRenderModelError_None) {
            VRRenderModels.VRRenderModels_FreeRenderModel(renderModel);
            return null;
        }
        RenderModelTextureMap renderModelTexture = new RenderModelTextureMap(texturePointer.getByteBuffer(RenderModelTextureMap.SIZEOF));
        // convert to a Model
        IntMesh mesh = new IntMesh(true, renderModel.unVertexCount(), renderModel.unTriangleCount() * 3, new VertexAttribute[] { VertexAttribute.Position(), VertexAttribute.Normal(), VertexAttribute.TexCoords(0) });
        IntMeshPart meshPart = new IntMeshPart(name, mesh, 0, renderModel.unTriangleCount() * 3, GL20.GL_TRIANGLES);
        RenderModelVertex.Buffer vertices = renderModel.rVertexData();
        float[] packedVertices = new float[8 * renderModel.unVertexCount()];
        int i = 0;
        while (vertices.remaining() > 0) {
            RenderModelVertex v = vertices.get();
            packedVertices[i++] = v.vPosition().v(0);
            packedVertices[i++] = v.vPosition().v(1);
            packedVertices[i++] = v.vPosition().v(2);
            packedVertices[i++] = v.vNormal().v(0);
            packedVertices[i++] = v.vNormal().v(1);
            packedVertices[i++] = v.vNormal().v(2);
            packedVertices[i++] = v.rfTextureCoord().get(0);
            packedVertices[i++] = v.rfTextureCoord().get(1);
        }
        mesh.setVertices(packedVertices);
        // Shorts to Integers
        int[] indices = new int[renderModel.unTriangleCount() * 3];
        ShortBuffer sb = renderModel.IndexData();
        sb.rewind();
        int j = 0;
        while (sb.hasRemaining()) {
            short index = sb.get();
            indices[j++] = index;
        }
        mesh.setIndices(indices);
        Pixmap pixmap = new Pixmap(renderModelTexture.unWidth(), renderModelTexture.unHeight(), Format.RGBA8888);
        byte[] pixels = new byte[renderModelTexture.unWidth() * renderModelTexture.unHeight() * 4];
        renderModelTexture.rubTextureMapData(pixels.length).get(pixels);
        pixmap.getPixels().put(pixels);
        pixmap.getPixels().position(0);
        Texture texture = new Texture(new PixmapTextureData(pixmap, pixmap.getFormat(), true, true));
        Material material = new Material(new TextureAttribute(TextureAttribute.Diffuse, texture));
        model = new IntModel();
        model.meshes.add(mesh);
        model.meshParts.add(meshPart);
        model.materials.add(material);
        IntNode node = new IntNode();
        node.id = name;
        node.parts.add(new IntNodePart(meshPart, material));
        model.nodes.add(node);
        model.manageDisposable(mesh);
        model.manageDisposable(texture);
        VRRenderModels.VRRenderModels_FreeRenderModel(renderModel);
        VRRenderModels.VRRenderModels_FreeTexture(renderModelTexture);
    } else {
        OwnObjLoader ol = new OwnObjLoader();
        if (manufacturer == null || manufacturer.equalsIgnoreCase("Oculus")) {
            if (isControllerLeft(name, modelNumber, role)) {
                model = ol.loadModel(Settings.settings.data.dataFileHandle("models/controllers/oculus/oculus-left.obj"));
            } else if (isControllerRight(name, modelNumber, role)) {
                model = ol.loadModel(Settings.settings.data.dataFileHandle("models/controllers/oculus/oculus-right.obj"));
            } else {
                logger.info("WARN: Could not parse controller name - Manufacturer: " + manufacturer + ", Name: " + name + ", ModelNumber: " + modelNumber);
            }
        } else {
            // HTC
            if (isControllerRight(name, modelNumber, role) || isControllerLeft(name, modelNumber, role)) {
                model = ol.loadModel(Settings.settings.data.dataFileHandle("models/controllers/vive/vr_controller_vive.obj"));
            } else {
                logger.info("WARN: Could not parse controller name - Manufacturer: " + manufacturer + ", Name: " + name + ", ModelNumber: " + modelNumber);
            }
        }
        // Load default
        if (model == null) {
            logger.info("WARN: Could not find suitable controller model, using default...");
            model = ol.loadModel(Settings.settings.data.dataFileHandle("models/controllers/vive/vr_controller_vive.obj"));
        }
    }
    models.put(name, model);
    return model;
}
Also used : PointerBuffer(org.lwjgl.PointerBuffer) PixmapTextureData(com.badlogic.gdx.graphics.glutils.PixmapTextureData) Material(gaiasky.util.gdx.shader.Material) OwnObjLoader(gaiasky.util.gdx.loader.OwnObjLoader) Texture(com.badlogic.gdx.graphics.Texture) ShortBuffer(java.nio.ShortBuffer) Pixmap(com.badlogic.gdx.graphics.Pixmap) IntMesh(gaiasky.util.gdx.mesh.IntMesh) TextureAttribute(gaiasky.util.gdx.shader.attribute.TextureAttribute)

Example 4 with TextureAttribute

use of gaiasky.util.gdx.shader.attribute.TextureAttribute in project gaiasky by langurmonkey.

the class SpacecraftGui method doneLoading.

/**
 * Constructs the interface
 */
public void doneLoading(AssetManager assetManager) {
    aiTexture = assetManager.get(Settings.settings.data.dataFile("tex/base/attitudeindicator.png"), Texture.class);
    aiTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    aiPointerTexture = assetManager.get("img/ai-pointer.png", Texture.class);
    aiPointerTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    aiVelTex = assetManager.get("img/ai-vel.png", Texture.class);
    aiVelTex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    aiAntivelTex = assetManager.get("img/ai-antivel.png", Texture.class);
    aiAntivelTex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    aiVelDec = Decal.newDecal(new TextureRegion(aiVelTex));
    aiAntivelDec = Decal.newDecal(new TextureRegion(aiAntivelTex));
    Material mat = new Material(new TextureAttribute(TextureAttribute.Diffuse, aiTexture), new ColorAttribute(ColorAttribute.Specular, 0.3f, 0.3f, 0.3f, 1f), new DepthTestAttribute(GL20.GL_LESS, aiCam.near, aiCam.far, true));
    aiModel = new IntModelBuilder().createSphere(1.6f, 30, 30, false, mat, Bits.indexes(Usage.Position, Usage.Normal, Usage.Tangent, Usage.BiNormal, Usage.TextureCoordinates));
    aiTransform = new Matrix4();
    aiModelInstance = new IntModelInstance(aiModel, aiTransform);
    aiViewport = new ExtendViewport(indicatorw * Settings.settings.program.ui.scale, indicatorh * Settings.settings.program.ui.scale, aiCam);
    buildGui();
    EventManager.instance.subscribe(this, gaiasky.event.Event.SPACECRAFT_STABILISE_CMD, gaiasky.event.Event.SPACECRAFT_STOP_CMD, gaiasky.event.Event.SPACECRAFT_INFO, gaiasky.event.Event.SPACECRAFT_NEAREST_INFO, gaiasky.event.Event.SPACECRAFT_THRUST_INFO);
    EventManager.instance.unsubscribe(this, gaiasky.event.Event.SPACECRAFT_LOADED);
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) IntModelBuilder(gaiasky.util.gdx.IntModelBuilder) IntModelInstance(gaiasky.util.gdx.model.IntModelInstance) ExtendViewport(com.badlogic.gdx.utils.viewport.ExtendViewport) Material(gaiasky.util.gdx.shader.Material) DepthTestAttribute(gaiasky.util.gdx.shader.attribute.DepthTestAttribute) ColorAttribute(gaiasky.util.gdx.shader.attribute.ColorAttribute) Texture(com.badlogic.gdx.graphics.Texture) Matrix4(com.badlogic.gdx.math.Matrix4) TextureAttribute(gaiasky.util.gdx.shader.attribute.TextureAttribute)

Aggregations

Texture (com.badlogic.gdx.graphics.Texture)4 Material (gaiasky.util.gdx.shader.Material)4 TextureAttribute (gaiasky.util.gdx.shader.attribute.TextureAttribute)4 Matrix4 (com.badlogic.gdx.math.Matrix4)3 IntModelInstance (gaiasky.util.gdx.model.IntModelInstance)3 ColorAttribute (gaiasky.util.gdx.shader.attribute.ColorAttribute)3 ModelComponent (gaiasky.scenegraph.component.ModelComponent)2 IntModel (gaiasky.util.gdx.model.IntModel)2 Environment (gaiasky.util.gdx.shader.Environment)2 BlendingAttribute (gaiasky.util.gdx.shader.attribute.BlendingAttribute)2 FloatAttribute (gaiasky.util.gdx.shader.attribute.FloatAttribute)2 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 PixmapTextureData (com.badlogic.gdx.graphics.glutils.PixmapTextureData)1 ExtendViewport (com.badlogic.gdx.utils.viewport.ExtendViewport)1 IntModelBuilder (gaiasky.util.gdx.IntModelBuilder)1 OwnObjLoader (gaiasky.util.gdx.loader.OwnObjLoader)1 IntMesh (gaiasky.util.gdx.mesh.IntMesh)1 DepthTestAttribute (gaiasky.util.gdx.shader.attribute.DepthTestAttribute)1 ShortBuffer (java.nio.ShortBuffer)1