Search in sources :

Example 1 with IntModelInstance

use of gaiasky.util.gdx.model.IntModelInstance in project gaiasky by langurmonkey.

the class ModelComponent method doneLoading.

public void doneLoading(AssetManager manager, Matrix4 localTransform, float[] cc, boolean mesh) {
    this.manager = manager;
    this.cc = cc;
    IntModel model;
    if (staticLight) {
        // If lazy texture init, we turn off the lights until the texture is loaded
        float level = Settings.settings.scene.initialization.lazyTexture ? 0f : staticLightLevel;
        ColorAttribute alight = new ColorAttribute(ColorAttribute.AmbientLight, level, level, level, 1f);
        env.set(alight);
        updateStaticLight = Settings.settings.scene.initialization.lazyTexture;
    }
    // CREATE MAIN MODEL INSTANCE
    if (!mesh || !Settings.settings.scene.initialization.lazyMesh) {
        Pair<IntModel, Map<String, Material>> modelMaterial = initModelFile();
        model = modelMaterial.getFirst();
        instance = new IntModelInstance(model, localTransform);
        this.modelInitialised = true;
    }
    // INITIALIZE MATERIAL
    if ((forceInit || !Settings.settings.scene.initialization.lazyTexture) && mtc != null) {
        mtc.initMaterial(manager, instance, cc, culling);
        mtc.texLoading = false;
        mtc.texInitialised = true;
    }
    // COLOR IF NO TEXTURE
    if (mtc == null && instance != null) {
        addColorToMat();
    }
    // Subscribe to new graphics quality setting event
    EventManager.instance.subscribe(this, Event.GRAPHICS_QUALITY_UPDATED, Event.SSR_CMD);
    this.modelInitialised = this.modelInitialised || !Settings.settings.scene.initialization.lazyMesh;
    this.modelLoading = false;
}
Also used : IntModelInstance(gaiasky.util.gdx.model.IntModelInstance) IntModel(gaiasky.util.gdx.model.IntModel) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with IntModelInstance

use of gaiasky.util.gdx.model.IntModelInstance 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 3 with IntModelInstance

use of gaiasky.util.gdx.model.IntModelInstance in project gaiasky by langurmonkey.

the class StarCluster method initModel.

public void initModel() {
    if (clusterTex == null) {
        clusterTex = new Texture(Settings.settings.data.dataFileHandle("data/tex/base/cluster-tex.png"), true);
        clusterTex.setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.Linear);
    }
    if (model == null) {
        Material mat = new Material(new BlendingAttribute(GL20.GL_ONE, GL20.GL_ONE), new ColorAttribute(ColorAttribute.Diffuse, cc[0], cc[1], cc[2], cc[3]));
        IntModelBuilder modelBuilder = ModelCache.cache.mb;
        modelBuilder.begin();
        // create part
        IntMeshPartBuilder bPartBuilder = modelBuilder.part("sph", GL20.GL_LINES, Bits.indexes(Usage.Position), mat);
        bPartBuilder.icosphere(1, 3, false, true);
        model = (modelBuilder.end());
        modelTransform = new Matrix4();
    }
    mc = new ModelComponent(false);
    mc.initialize(null);
    DirectionalLight dLight = new DirectionalLight();
    dLight.set(1, 1, 1, 1, 1, 1);
    mc.env = new Environment();
    mc.env.add(dLight);
    mc.env.set(new ColorAttribute(ColorAttribute.AmbientLight, 1.0f, 1.0f, 1.0f, 1f));
    mc.env.set(new FloatAttribute(FloatAttribute.Shininess, 0.2f));
    mc.instance = new IntModelInstance(model, modelTransform);
    // Relativistic effects
    if (Settings.settings.runtime.relativisticAberration)
        mc.rec.setUpRelativisticEffectsMaterial(mc.instance.materials);
    // Gravitational waves
    if (Settings.settings.runtime.gravitationalWaves)
        mc.rec.setUpGravitationalWavesMaterial(mc.instance.materials);
}
Also used : IntModelBuilder(gaiasky.util.gdx.IntModelBuilder) IntModelInstance(gaiasky.util.gdx.model.IntModelInstance) BlendingAttribute(gaiasky.util.gdx.shader.attribute.BlendingAttribute) ModelComponent(gaiasky.scenegraph.component.ModelComponent) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) Environment(gaiasky.util.gdx.shader.Environment) Material(gaiasky.util.gdx.shader.Material) FloatAttribute(gaiasky.util.gdx.shader.attribute.FloatAttribute) ColorAttribute(gaiasky.util.gdx.shader.attribute.ColorAttribute) IntMeshPartBuilder(gaiasky.util.gdx.IntMeshPartBuilder) Texture(com.badlogic.gdx.graphics.Texture) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 4 with IntModelInstance

use of gaiasky.util.gdx.model.IntModelInstance 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 5 with IntModelInstance

use of gaiasky.util.gdx.model.IntModelInstance in project gaiasky by langurmonkey.

the class AtmosphereComponent method doneLoading.

public void doneLoading(Material planetMat, float planetSize) {
    this.planetSize = planetSize;
    setUpAtmosphericScatteringMaterial(planetMat);
    Material atmMat;
    if (mc.instance == null) {
        Pair<IntModel, Map<String, Material>> pair = ModelCache.cache.getModel("sphere", params, Bits.indexes(Usage.Position, Usage.Normal), GL20.GL_TRIANGLES);
        IntModel atmosphereModel = pair.getFirst();
        atmMat = pair.getSecond().get("base");
        setUpAtmosphericScatteringMaterial(atmMat);
        atmMat.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));
        // CREATE ATMOSPHERE MODEL
        mc.instance = new IntModelInstance(atmosphereModel, this.localTransform);
    } else {
        atmMat = mc.instance.materials.get(0);
        setUpAtmosphericScatteringMaterial(atmMat);
    }
}
Also used : IntModelInstance(gaiasky.util.gdx.model.IntModelInstance) BlendingAttribute(gaiasky.util.gdx.shader.attribute.BlendingAttribute) Material(gaiasky.util.gdx.shader.Material) IntModel(gaiasky.util.gdx.model.IntModel) Map(java.util.Map)

Aggregations

IntModelInstance (gaiasky.util.gdx.model.IntModelInstance)8 Material (gaiasky.util.gdx.shader.Material)7 IntModel (gaiasky.util.gdx.model.IntModel)6 Matrix4 (com.badlogic.gdx.math.Matrix4)5 BlendingAttribute (gaiasky.util.gdx.shader.attribute.BlendingAttribute)5 ColorAttribute (gaiasky.util.gdx.shader.attribute.ColorAttribute)5 Map (java.util.Map)5 Texture (com.badlogic.gdx.graphics.Texture)4 ModelComponent (gaiasky.scenegraph.component.ModelComponent)4 Environment (gaiasky.util.gdx.shader.Environment)4 FloatAttribute (gaiasky.util.gdx.shader.attribute.FloatAttribute)4 TextureAttribute (gaiasky.util.gdx.shader.attribute.TextureAttribute)3 DirectionalLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)2 IntModelBuilder (gaiasky.util.gdx.IntModelBuilder)2 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 ExtendViewport (com.badlogic.gdx.utils.viewport.ExtendViewport)1 IntMeshPartBuilder (gaiasky.util.gdx.IntMeshPartBuilder)1 DepthTestAttribute (gaiasky.util.gdx.shader.attribute.DepthTestAttribute)1 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1