Search in sources :

Example 26 with Model

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

the class SpawnInfluencerPanel method initializeComponents.

protected void initializeComponents() {
    super.initializeComponents();
    pointSpawnShapeValue = new PointSpawnShapeValue();
    lineSpawnShapeValue = new LineSpawnShapeValue();
    rectangleSpawnShapeValue = new RectangleSpawnShapeValue();
    ellipseSpawnShapeValue = new EllipseSpawnShapeValue();
    cylinderSpawnShapeValue = new CylinderSpawnShapeValue();
    meshSpawnShapeValue = new UnweightedMeshSpawnShapeValue();
    weightMeshSpawnShapeValue = new WeightMeshSpawnShapeValue();
    lineSpawnShapeValue.setDimensions(6, 6, 6);
    rectangleSpawnShapeValue.setDimensions(6, 6, 6);
    ellipseSpawnShapeValue.setDimensions(6, 6, 6);
    cylinderSpawnShapeValue.setDimensions(6, 6, 6);
    pointSpawnShapeValue.setActive(true);
    lineSpawnShapeValue.setActive(true);
    rectangleSpawnShapeValue.setActive(true);
    ellipseSpawnShapeValue.setActive(true);
    cylinderSpawnShapeValue.setActive(true);
    meshSpawnShapeValue.setActive(true);
    weightMeshSpawnShapeValue.setActive(true);
    Model defaultModel = editor.assetManager.get(FlameMain.DEFAULT_MODEL_PARTICLE);
    Array<Model> models = new Array<Model>();
    models.add(defaultModel);
    int i = 0;
    JPanel panel = new JPanel(new GridBagLayout());
    EditorPanel.addContent(panel, i, 0, new JLabel("Shape"), false, GridBagConstraints.WEST, GridBagConstraints.NONE, 0, 0);
    EditorPanel.addContent(panel, i++, 1, shapeCombo = new JComboBox(new DefaultComboBoxModel(spawnShapes)), false, GridBagConstraints.WEST, GridBagConstraints.NONE, 1, 0);
    EditorPanel.addContent(panel, i, 0, edgesLabel = new JLabel("Edges"), false, GridBagConstraints.WEST, GridBagConstraints.NONE, 0, 0);
    EditorPanel.addContent(panel, i++, 1, edgesCheckbox = new JCheckBox(), false, GridBagConstraints.WEST, GridBagConstraints.NONE, 0, 0);
    EditorPanel.addContent(panel, i, 0, sideLabel = new JLabel("Side"), false, GridBagConstraints.WEST, GridBagConstraints.NONE, 0, 0);
    EditorPanel.addContent(panel, i++, 1, sideCombo = new JComboBox(new DefaultComboBoxModel(SpawnSide.values())), false, GridBagConstraints.WEST, GridBagConstraints.NONE, 1, 0);
    edgesCheckbox.setHorizontalTextPosition(SwingConstants.LEFT);
    i = 0;
    addContent(i++, 0, panel, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL);
    addContent(i++, 0, meshPanel = new TemplatePickerPanel<Model>(editor, models, this, Model.class, new LoaderButton.ModelLoaderButton(editor), true, false), false, GridBagConstraints.WEST, GridBagConstraints.NONE);
    addContent(i++, 0, xPanel = new RangedNumericPanel(editor, pointSpawnShapeValue.xOffsetValue, "X Offset", "Amount to offset a particle's starting X location, in world units.", false));
    addContent(i++, 0, yPanel = new RangedNumericPanel(editor, pointSpawnShapeValue.yOffsetValue, "Y Offset", "Amount to offset a particle's starting Y location, in world units.", false));
    addContent(i++, 0, zPanel = new RangedNumericPanel(editor, pointSpawnShapeValue.zOffsetValue, "Z Offset", "Amount to offset a particle's starting Z location, in world units.", false));
    addContent(i++, 0, widthPanel = new ScaledNumericPanel(editor, pointSpawnShapeValue.getSpawnWidth(), "Duration", "Spawn Width", "Width of the spawn shape, in world units.", true));
    addContent(i++, 0, heightPanel = new ScaledNumericPanel(editor, pointSpawnShapeValue.getSpawnWidth(), "Duration", "Spawn Height", "Height of the spawn shape, in world units.", true));
    addContent(i++, 0, depthPanel = new ScaledNumericPanel(editor, pointSpawnShapeValue.getSpawnWidth(), "Duration", "Spawn Depth", "Depth of the spawn shape, in world units.", true), false);
    meshPanel.setIsAlwayShown(true);
    onTemplateChecked(defaultModel, true);
    shapeCombo.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            String shape = (String) shapeCombo.getSelectedItem();
            if (shape == SPAWN_SHAPE_POINT) {
                setPrimitiveSpawnShape(pointSpawnShapeValue, false, null);
            } else if (shape == SPAWN_SHAPE_LINE) {
                setPrimitiveSpawnShape(lineSpawnShapeValue, false, null);
            } else if (shape == SPAWN_SHAPE_RECTANGLE) {
                setPrimitiveSpawnShape(rectangleSpawnShapeValue, true, null);
            } else if (shape == SPAWN_SHAPE_ELLIPSE) {
                setPrimitiveSpawnShape(ellipseSpawnShapeValue, true, ellipseSpawnShapeValue.getSide());
            } else if (shape == SPAWN_SHAPE_CYLINDER) {
                setPrimitiveSpawnShape(cylinderSpawnShapeValue, true, null);
            } else if (shape == SPAWN_SHAPE_MESH) {
                setMeshSpawnShape(meshSpawnShapeValue);
            } else if (shape == SPAWN_SHAPE_WEIGHT_MESH) {
                setMeshSpawnShape(weightMeshSpawnShapeValue);
            }
            editor.restart();
        }
    });
    edgesCheckbox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            SpawnInfluencer influencer = (SpawnInfluencer) editor.getEmitter().findInfluencer(SpawnInfluencer.class);
            PrimitiveSpawnShapeValue shapeValue = (PrimitiveSpawnShapeValue) influencer.spawnShapeValue;
            shapeValue.setEdges(edgesCheckbox.isSelected());
            setEdgesVisible(true);
        }
    });
    sideCombo.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            SpawnSide side = (SpawnSide) sideCombo.getSelectedItem();
            SpawnInfluencer influencer = (SpawnInfluencer) editor.getEmitter().findInfluencer(SpawnInfluencer.class);
            EllipseSpawnShapeValue shapeValue = (EllipseSpawnShapeValue) influencer.spawnShapeValue;
            shapeValue.setSide(side);
        }
    });
}
Also used : RectangleSpawnShapeValue(com.badlogic.gdx.graphics.g3d.particles.values.RectangleSpawnShapeValue) JPanel(javax.swing.JPanel) PrimitiveSpawnShapeValue(com.badlogic.gdx.graphics.g3d.particles.values.PrimitiveSpawnShapeValue) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) CylinderSpawnShapeValue(com.badlogic.gdx.graphics.g3d.particles.values.CylinderSpawnShapeValue) WeightMeshSpawnShapeValue(com.badlogic.gdx.graphics.g3d.particles.values.WeightMeshSpawnShapeValue) SpawnInfluencer(com.badlogic.gdx.graphics.g3d.particles.influencers.SpawnInfluencer) JComboBox(javax.swing.JComboBox) SpawnSide(com.badlogic.gdx.graphics.g3d.particles.values.PrimitiveSpawnShapeValue.SpawnSide) JLabel(javax.swing.JLabel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) PointSpawnShapeValue(com.badlogic.gdx.graphics.g3d.particles.values.PointSpawnShapeValue) Array(com.badlogic.gdx.utils.Array) JCheckBox(javax.swing.JCheckBox) EllipseSpawnShapeValue(com.badlogic.gdx.graphics.g3d.particles.values.EllipseSpawnShapeValue) ActionListener(java.awt.event.ActionListener) UnweightedMeshSpawnShapeValue(com.badlogic.gdx.graphics.g3d.particles.values.UnweightedMeshSpawnShapeValue) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) Model(com.badlogic.gdx.graphics.g3d.Model) LineSpawnShapeValue(com.badlogic.gdx.graphics.g3d.particles.values.LineSpawnShapeValue)

Example 27 with Model

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

the class EffectPanel method createDefaultModelInstanceController.

private ParticleController createDefaultModelInstanceController() {
    //Emission
    RegularEmitter emitter = new RegularEmitter();
    emitter.getDuration().setLow(3000);
    emitter.getEmission().setHigh(80);
    emitter.getLife().setHigh(500, 1000);
    emitter.getLife().setTimeline(new float[] { 0, 0.66f, 1 });
    emitter.getLife().setScaling(new float[] { 1, 1, 0.3f });
    emitter.setMaxParticleCount(100);
    //Color
    ColorInfluencer.Random colorInfluencer = new ColorInfluencer.Random();
    //Spawn
    EllipseSpawnShapeValue spawnShapeValue = new EllipseSpawnShapeValue();
    spawnShapeValue.setDimensions(1, 1, 1);
    SpawnInfluencer spawnSource = new SpawnInfluencer(spawnShapeValue);
    //Velocity
    DynamicsInfluencer velocityInfluencer = new DynamicsInfluencer();
    //Directional
    DynamicsModifier.CentripetalAcceleration velocityValue = new DynamicsModifier.CentripetalAcceleration();
    velocityValue.strengthValue.setHigh(5, 11);
    velocityValue.strengthValue.setActive(true);
    //velocityValue.setActive(true);
    velocityInfluencer.velocities.add(velocityValue);
    return new ParticleController("ModelInstance Controller", emitter, new ModelInstanceRenderer(editor.getModelInstanceParticleBatch()), new ModelInfluencer.Single((Model) editor.assetManager.get(FlameMain.DEFAULT_MODEL_PARTICLE)), spawnSource, colorInfluencer, velocityInfluencer);
}
Also used : DynamicsInfluencer(com.badlogic.gdx.graphics.g3d.particles.influencers.DynamicsInfluencer) ModelInfluencer(com.badlogic.gdx.graphics.g3d.particles.influencers.ModelInfluencer) RegularEmitter(com.badlogic.gdx.graphics.g3d.particles.emitters.RegularEmitter) ModelInstanceRenderer(com.badlogic.gdx.graphics.g3d.particles.renderers.ModelInstanceRenderer) DynamicsModifier(com.badlogic.gdx.graphics.g3d.particles.influencers.DynamicsModifier) EllipseSpawnShapeValue(com.badlogic.gdx.graphics.g3d.particles.values.EllipseSpawnShapeValue) ParticleController(com.badlogic.gdx.graphics.g3d.particles.ParticleController) ColorInfluencer(com.badlogic.gdx.graphics.g3d.particles.influencers.ColorInfluencer) ListSelectionModel(javax.swing.ListSelectionModel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) DefaultTableModel(javax.swing.table.DefaultTableModel) Model(com.badlogic.gdx.graphics.g3d.Model) SpawnInfluencer(com.badlogic.gdx.graphics.g3d.particles.influencers.SpawnInfluencer)

Example 28 with Model

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

the class ModelLoader method loadSync.

@Override
public Model loadSync(AssetManager manager, String fileName, FileHandle file, P parameters) {
    ModelData data = null;
    synchronized (items) {
        for (int i = 0; i < items.size; i++) {
            if (items.get(i).key.equals(fileName)) {
                data = items.get(i).value;
                items.removeIndex(i);
            }
        }
    }
    if (data == null)
        return null;
    final Model result = new Model(data, new TextureProvider.AssetTextureProvider(manager));
    // need to remove the textures from the managed disposables, or else ref counting
    // doesn't work!
    Iterator<Disposable> disposables = result.getManagedDisposables().iterator();
    while (disposables.hasNext()) {
        Disposable disposable = disposables.next();
        if (disposable instanceof Texture) {
            disposables.remove();
        }
    }
    data = null;
    return result;
}
Also used : Disposable(com.badlogic.gdx.utils.Disposable) ModelData(com.badlogic.gdx.graphics.g3d.model.data.ModelData) Model(com.badlogic.gdx.graphics.g3d.Model) TextureProvider(com.badlogic.gdx.graphics.g3d.utils.TextureProvider) ModelTexture(com.badlogic.gdx.graphics.g3d.model.data.ModelTexture) Texture(com.badlogic.gdx.graphics.Texture)

Example 29 with Model

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

the class MultipleRenderTargetTest method create.

@Override
public void create() {
    //use default prepend shader code for batch, some gpu drivers are less forgiving
    batch = new SpriteBatch();
    //depth texture not currently sampled
    ShaderProgram.pedantic = false;
    modelCache = new ModelCache();
    ShaderProgram.prependVertexCode = Gdx.app.getType().equals(Application.ApplicationType.Desktop) ? "#version 140\n #extension GL_ARB_explicit_attrib_location : enable\n" : "#version 300 es\n";
    ShaderProgram.prependFragmentCode = Gdx.app.getType().equals(Application.ApplicationType.Desktop) ? "#version 140\n #extension GL_ARB_explicit_attrib_location : enable\n" : "#version 300 es\n";
    renderContext = new RenderContext(new DefaultTextureBinder(DefaultTextureBinder.ROUNDROBIN));
    shaderProvider = new BaseShaderProvider() {

        @Override
        protected Shader createShader(Renderable renderable) {
            return new MRTShader(renderable);
        }
    };
    renderableSorter = new DefaultRenderableSorter() {

        @Override
        public int compare(Renderable o1, Renderable o2) {
            return o1.shader.compareTo(o2.shader);
        }
    };
    mrtSceneShader = new ShaderProgram(Gdx.files.internal("data/g3d/shaders/mrtscene.vert"), Gdx.files.internal("data/g3d/shaders/mrtscene.frag"));
    if (!mrtSceneShader.isCompiled()) {
        System.out.println(mrtSceneShader.getLog());
    }
    quad = createFullScreenQuad();
    camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.near = 1f;
    camera.far = 100f;
    camera.position.set(3, 5, 10);
    camera.lookAt(0, 2, 0);
    camera.up.set(0, 1, 0);
    camera.update();
    cameraController = new FirstPersonCameraController(camera);
    cameraController.setVelocity(50);
    Gdx.input.setInputProcessor(cameraController);
    frameBuffer = new MRTFrameBuffer(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 3);
    AssetManager assetManager = new AssetManager();
    assetManager.load("data/g3d/materials/cannon.g3db", Model.class);
    assetManager.finishLoading();
    Model scene = assetManager.get("data/g3d/materials/cannon.g3db");
    cannon = new ModelInstance(scene, "Cannon_LP");
    cannon.transform.setToTranslationAndScaling(0, 0, 0, 0.001f, 0.001f, 0.001f);
    ModelBuilder modelBuilder = new ModelBuilder();
    for (int i = 0; i < NUM_LIGHTS; i++) {
        modelBuilder.begin();
        Light light = new Light();
        light.color.set(MathUtils.random(1f), MathUtils.random(1f), MathUtils.random(1f));
        light.position.set(MathUtils.random(-10f, 10f), MathUtils.random(10f, 15f), MathUtils.random(-10f, 10f));
        light.vy = MathUtils.random(10f, 20f);
        light.vx = MathUtils.random(-10f, 10f);
        light.vz = MathUtils.random(-10f, 10f);
        MeshPartBuilder meshPartBuilder = modelBuilder.part("light", GL20.GL_TRIANGLES, VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorPacked | VertexAttributes.Usage.Normal, new Material());
        meshPartBuilder.setColor(light.color.x, light.color.y, light.color.z, 1f);
        meshPartBuilder.sphere(0.2f, 0.2f, 0.2f, 10, 10);
        light.lightInstance = new ModelInstance(modelBuilder.end());
        lights.add(light);
    }
    modelBuilder.begin();
    MeshPartBuilder meshPartBuilder = modelBuilder.part("floor", GL20.GL_TRIANGLES, VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorPacked | VertexAttributes.Usage.Normal, new Material());
    meshPartBuilder.setColor(0.2f, 0.2f, 0.2f, 1f);
    meshPartBuilder.box(0, -0.1f, 0f, 20f, 0.1f, 20f);
    floorInstance = new ModelInstance(modelBuilder.end());
    Gdx.input.setInputProcessor(new InputMultiplexer(this, cameraController));
}
Also used : RenderContext(com.badlogic.gdx.graphics.g3d.utils.RenderContext) AssetManager(com.badlogic.gdx.assets.AssetManager) Material(com.badlogic.gdx.graphics.g3d.Material) DefaultRenderableSorter(com.badlogic.gdx.graphics.g3d.utils.DefaultRenderableSorter) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) MeshPartBuilder(com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder) Shader(com.badlogic.gdx.graphics.g3d.Shader) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) BaseShaderProvider(com.badlogic.gdx.graphics.g3d.utils.BaseShaderProvider) ModelCache(com.badlogic.gdx.graphics.g3d.ModelCache) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) Renderable(com.badlogic.gdx.graphics.g3d.Renderable) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) Model(com.badlogic.gdx.graphics.g3d.Model) FirstPersonCameraController(com.badlogic.gdx.graphics.g3d.utils.FirstPersonCameraController) DefaultTextureBinder(com.badlogic.gdx.graphics.g3d.utils.DefaultTextureBinder)

Example 30 with Model

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

the class ModelBuilder method begin.

/** Begin building a new model */
public void begin() {
    if (model != null)
        throw new GdxRuntimeException("Call end() first");
    node = null;
    model = new Model();
    builders.clear();
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) Model(com.badlogic.gdx.graphics.g3d.Model)

Aggregations

Model (com.badlogic.gdx.graphics.g3d.Model)34 Material (com.badlogic.gdx.graphics.g3d.Material)14 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)7 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)7 Texture (com.badlogic.gdx.graphics.Texture)6 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)5 Environment (com.badlogic.gdx.graphics.g3d.Environment)4 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)4 Vector3 (com.badlogic.gdx.math.Vector3)4 BoundingBox (com.badlogic.gdx.math.collision.BoundingBox)4 com.badlogic.gdx.physics.bullet.collision.btBoxShape (com.badlogic.gdx.physics.bullet.collision.btBoxShape)4 com.badlogic.gdx.physics.bullet.collision.btSphereShape (com.badlogic.gdx.physics.bullet.collision.btSphereShape)4 com.badlogic.gdx.physics.bullet.dynamics.btRigidBody (com.badlogic.gdx.physics.bullet.dynamics.btRigidBody)4 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)3 DirectionalLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)3 Node (com.badlogic.gdx.graphics.g3d.model.Node)3 com.badlogic.gdx.physics.bullet.collision.btCollisionShape (com.badlogic.gdx.physics.bullet.collision.btCollisionShape)3 AssetDescriptor (com.badlogic.gdx.assets.AssetDescriptor)2 AssetManager (com.badlogic.gdx.assets.AssetManager)2 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)2