Search in sources :

Example 1 with IntModel

use of gaiasky.util.gdx.model.IntModel 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 IntModel

use of gaiasky.util.gdx.model.IntModel 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 IntModel

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

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

the class ModelCache method getModel.

public Pair<IntModel, Map<String, Material>> getModel(String shape, Map<String, Object> params, Bits attributes, int primitiveType) {
    String key = getKey(shape, params, attributes);
    IntModel model = null;
    Map<String, Material> materials = new HashMap<>();
    Material mat;
    if (modelCache.containsKey(key)) {
        model = modelCache.get(key);
        mat = model.materials.first();
    } else {
        mat = new Material();
        switch(shape) {
            case "sphere":
                int quality = ((Long) params.get("quality")).intValue();
                float diameter = params.containsKey("diameter") ? ((Double) params.get("diameter")).floatValue() : 1f;
                Boolean flip = params.containsKey("flip") ? (Boolean) params.get("flip") : false;
                model = mb.createSphere(diameter, diameter, diameter, quality, quality, flip, primitiveType, mat, attributes);
                modelCache.put(key, model);
                break;
            case "icosphere":
                int recursion = ((Long) params.get("recursion")).intValue();
                diameter = params.containsKey("diameter") ? ((Double) params.get("diameter")).floatValue() : 1f;
                flip = params.containsKey("flip") ? (Boolean) params.get("flip") : false;
                model = mb.createIcoSphere(diameter / 2, recursion, flip, false, primitiveType, mat, attributes);
                modelCache.put(key, model);
                break;
            case "octahedronsphere":
                int divisions = ((Long) params.get("divisions")).intValue();
                diameter = params.containsKey("diameter") ? ((Double) params.get("diameter")).floatValue() : 1f;
                flip = params.containsKey("flip") ? (Boolean) params.get("flip") : false;
                model = mb.createOctahedronSphere(diameter / 2, divisions, flip, false, primitiveType, mat, attributes);
                modelCache.put(key, model);
                break;
            case "plane":
            case "patch":
                int divisionsU = ((Long) params.get("divisionsu")).intValue();
                int divisionsV = ((Long) params.get("divisionsv")).intValue();
                float side = ((Double) params.get("side")).floatValue();
                model = mb.createPlane(side, divisionsU, divisionsV, primitiveType, mat, attributes);
                modelCache.put(key, model);
                break;
            case "disc":
                // Prepare model
                float diameter2 = (params.containsKey("diameter") ? ((Double) params.get("diameter")).floatValue() : 1f) / 2f;
                // Initialize disc model
                // TOP VERTICES
                VertexInfo vt00 = new VertexInfo();
                vt00.setPos(-diameter2, 0, -diameter2);
                vt00.setNor(0, 1, 0);
                vt00.setUV(0, 0);
                VertexInfo vt01 = new VertexInfo();
                vt01.setPos(diameter2, 0, -diameter2);
                vt01.setNor(0, 1, 0);
                vt01.setUV(0, 1);
                VertexInfo vt11 = new VertexInfo();
                vt11.setPos(diameter2, 0, diameter2);
                vt11.setNor(0, 1, 0);
                vt11.setUV(1, 1);
                VertexInfo vt10 = new VertexInfo();
                vt10.setPos(-diameter2, 0, diameter2);
                vt10.setNor(0, 1, 0);
                vt10.setUV(1, 0);
                // BOTTOM VERTICES
                VertexInfo vb00 = new VertexInfo();
                vb00.setPos(-diameter2, 0, -diameter2);
                vb00.setNor(0, 1, 0);
                vb00.setUV(0, 0);
                VertexInfo vb01 = new VertexInfo();
                vb01.setPos(diameter2, 0, -diameter2);
                vb01.setNor(0, 1, 0);
                vb01.setUV(0, 1);
                VertexInfo vb11 = new VertexInfo();
                vb11.setPos(diameter2, 0, diameter2);
                vb11.setNor(0, 1, 0);
                vb11.setUV(1, 1);
                VertexInfo vb10 = new VertexInfo();
                vb10.setPos(-diameter2, 0, diameter2);
                vb10.setNor(0, 1, 0);
                vb10.setUV(1, 0);
                mb.begin();
                mb.part("up", primitiveType, attributes, mat).rect(vt00, vt01, vt11, vt10);
                mb.part("down", primitiveType, attributes, mat).rect(vb00, vb10, vb11, vb01);
                model = mb.end();
                break;
            case "twofacedbillboard":
                // Prepare model
                diameter2 = (params.containsKey("diameter") ? ((Double) params.get("diameter")).floatValue() : 1f) / 2f;
                // Initialize disc model
                // TOP VERTICES
                vt00 = new VertexInfo();
                vt00.setPos(-diameter2, -diameter2, 0);
                vt00.setNor(0, 1, 0);
                vt00.setUV(1, 0);
                vt01 = new VertexInfo();
                vt01.setPos(-diameter2, diameter2, 0);
                vt01.setNor(0, 1, 0);
                vt01.setUV(1, 1);
                vt11 = new VertexInfo();
                vt11.setPos(diameter2, diameter2, 0);
                vt11.setNor(0, 1, 0);
                vt11.setUV(0, 1);
                vt10 = new VertexInfo();
                vt10.setPos(diameter2, -diameter2, 0);
                vt10.setNor(0, 1, 0);
                vt10.setUV(0, 0);
                // BOTTOM VERTICES
                vb00 = new VertexInfo();
                vb00.setPos(-diameter2, -diameter2, 0);
                vb00.setNor(0, 1, 0);
                vb00.setUV(1, 0);
                vb01 = new VertexInfo();
                vb01.setPos(-diameter2, diameter2, 0);
                vb01.setNor(0, 1, 0);
                vb01.setUV(1, 1);
                vb11 = new VertexInfo();
                vb11.setPos(diameter2, diameter2, 0);
                vb11.setNor(0, 1, 0);
                vb11.setUV(0, 1);
                vb10 = new VertexInfo();
                vb10.setPos(diameter2, -diameter2, 0);
                vb10.setNor(0, 1, 0);
                vb10.setUV(0, 0);
                mb.begin();
                mb.part("up", primitiveType, attributes, mat).rect(vt00, vt01, vt11, vt10);
                mb.part("down", primitiveType, attributes, mat).rect(vb00, vb10, vb11, vb01);
                model = mb.end();
                break;
            case "cylinder":
                // Use builder
                float width = ((Double) params.get("width")).floatValue();
                float height = ((Double) params.get("height")).floatValue();
                float depth = ((Double) params.get("depth")).floatValue();
                divisions = ((Long) params.get("divisions")).intValue();
                flip = params.containsKey("flip") ? (Boolean) params.get("flip") : false;
                model = mb.createCylinder(width, height, depth, divisions, flip, primitiveType, mat, attributes);
                break;
            case "ring":
                // Sphere with cylinder
                Material ringMat = new Material();
                materials.put("ring", ringMat);
                quality = ((Long) params.get("quality")).intValue();
                divisions = ((Long) params.get("divisions")).intValue();
                float innerRad = ((Double) params.get("innerradius")).floatValue();
                float outerRad = ((Double) params.get("outerradius")).floatValue();
                boolean sph = params.containsKey("sphere-in-ring") ? (Boolean) params.get("sphere-in-ring") : true;
                if (sph) {
                    model = ModelCache.cache.mb.createSphereRing(1, quality, quality, innerRad, outerRad, divisions, primitiveType, mat, ringMat, attributes);
                } else {
                    model = ModelCache.cache.mb.createRing(1, quality, quality, innerRad, outerRad, divisions, primitiveType, mat, ringMat, attributes);
                }
                break;
            case "cone":
                width = ((Double) params.get("width")).floatValue();
                height = ((Double) params.get("height")).floatValue();
                depth = ((Double) params.get("depth")).floatValue();
                divisions = ((Long) params.get("divisions")).intValue();
                int hDivisions = 0;
                if (params.containsKey("hdivisions")) {
                    hDivisions = ((Long) params.get("hdivisions")).intValue();
                }
                if (hDivisions == 0)
                    model = mb.createCone(width, height, depth, divisions, primitiveType, mat, attributes);
                else
                    model = mb.createCone(width, height, depth, divisions, hDivisions, primitiveType, mat, attributes);
                break;
            case "cube":
            case "box":
                if (params.containsKey("width")) {
                    width = ((Double) params.get("width")).floatValue();
                    height = ((Double) params.get("height")).floatValue();
                    depth = ((Double) params.get("depth")).floatValue();
                } else {
                    width = ((Double) params.get("size")).floatValue();
                    height = width;
                    depth = width;
                }
                model = mb.createBox(width, height, depth, mat, attributes);
                break;
        }
    }
    materials.put("base", mat);
    return new Pair<>(model, materials);
}
Also used : HashMap(java.util.HashMap) VertexInfo(gaiasky.util.gdx.IntMeshPartBuilder.VertexInfo) Material(gaiasky.util.gdx.shader.Material) IntModel(gaiasky.util.gdx.model.IntModel)

Example 5 with IntModel

use of gaiasky.util.gdx.model.IntModel 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

IntModel (gaiasky.util.gdx.model.IntModel)12 Material (gaiasky.util.gdx.shader.Material)7 IntModelInstance (gaiasky.util.gdx.model.IntModelInstance)6 Map (java.util.Map)5 BlendingAttribute (gaiasky.util.gdx.shader.attribute.BlendingAttribute)4 Texture (com.badlogic.gdx.graphics.Texture)3 Matrix4 (com.badlogic.gdx.math.Matrix4)3 ModelComponent (gaiasky.scenegraph.component.ModelComponent)3 Environment (gaiasky.util.gdx.shader.Environment)3 ColorAttribute (gaiasky.util.gdx.shader.attribute.ColorAttribute)3 FloatAttribute (gaiasky.util.gdx.shader.attribute.FloatAttribute)3 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)2 TextureAttribute (gaiasky.util.gdx.shader.attribute.TextureAttribute)2 HashMap (java.util.HashMap)2 DirectionalLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)1 ModelTexture (com.badlogic.gdx.graphics.g3d.model.data.ModelTexture)1 TextureProvider (com.badlogic.gdx.graphics.g3d.utils.TextureProvider)1 Disposable (com.badlogic.gdx.utils.Disposable)1 VertexInfo (gaiasky.util.gdx.IntMeshPartBuilder.VertexInfo)1 IntMeshPart (gaiasky.util.gdx.model.IntMeshPart)1