Search in sources :

Example 21 with Model

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

the class BasicShapesTest method create.

@Override
public void create() {
    super.create();
    final Texture texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    disposables.add(texture);
    final Material material = new Material(TextureAttribute.createDiffuse(texture), ColorAttribute.createSpecular(1, 1, 1, 1), FloatAttribute.createShininess(8f));
    final long attributes = Usage.Position | Usage.Normal | Usage.TextureCoordinates;
    final Model sphere = modelBuilder.createSphere(4f, 4f, 4f, 24, 24, material, attributes);
    disposables.add(sphere);
    world.addConstructor("sphere", new BulletConstructor(sphere, 10f, new btSphereShape(2f)));
    final Model cylinder = modelBuilder.createCylinder(4f, 6f, 4f, 16, material, attributes);
    disposables.add(cylinder);
    world.addConstructor("cylinder", new BulletConstructor(cylinder, 10f, new btCylinderShape(tmpV1.set(2f, 3f, 2f))));
    final Model capsule = modelBuilder.createCapsule(2f, 6f, 16, material, attributes);
    disposables.add(capsule);
    world.addConstructor("capsule", new BulletConstructor(capsule, 10f, new btCapsuleShape(2f, 2f)));
    final Model box = modelBuilder.createBox(4f, 4f, 2f, material, attributes);
    disposables.add(box);
    world.addConstructor("box2", new BulletConstructor(box, 10f, new btBoxShape(tmpV1.set(2f, 2f, 1f))));
    final Model cone = modelBuilder.createCone(4f, 6f, 4f, 16, material, attributes);
    disposables.add(cone);
    world.addConstructor("cone", new BulletConstructor(cone, 10f, new btConeShape(2f, 6f)));
    // Create the entities
    world.add("ground", 0f, 0f, 0f).setColor(0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 1f);
    world.add("sphere", 0, 5, 5);
    world.add("cylinder", 5, 5, 0);
    world.add("box2", 0, 5, 0);
    world.add("capsule", 5, 5, 5);
    world.add("cone", 10, 5, 0);
}
Also used : com.badlogic.gdx.physics.bullet.collision.btBoxShape(com.badlogic.gdx.physics.bullet.collision.btBoxShape) com.badlogic.gdx.physics.bullet.collision.btCylinderShape(com.badlogic.gdx.physics.bullet.collision.btCylinderShape) com.badlogic.gdx.physics.bullet.collision.btConeShape(com.badlogic.gdx.physics.bullet.collision.btConeShape) com.badlogic.gdx.physics.bullet.collision.btSphereShape(com.badlogic.gdx.physics.bullet.collision.btSphereShape) com.badlogic.gdx.physics.bullet.collision.btCapsuleShape(com.badlogic.gdx.physics.bullet.collision.btCapsuleShape) Model(com.badlogic.gdx.graphics.g3d.Model) Material(com.badlogic.gdx.graphics.g3d.Material) Texture(com.badlogic.gdx.graphics.Texture)

Example 22 with Model

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

the class RayPickRagdollTest method createCapsuleModel.

protected Model createCapsuleModel(float radius, float height) {
    final Model result = modelBuilder.createCapsule(radius, height + radius * 2f, 16, new Material(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE)), Usage.Position | Usage.Normal);
    disposables.add(result);
    return result;
}
Also used : Model(com.badlogic.gdx.graphics.g3d.Model) Material(com.badlogic.gdx.graphics.g3d.Material)

Example 23 with Model

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

the class Basic3DSceneTest method doneLoading.

private void doneLoading() {
    Model model = assets.get("data/g3d/invaders.g3dj", Model.class);
    for (int i = 0; i < model.nodes.size; i++) {
        String id = model.nodes.get(i).id;
        ModelInstance instance = new ModelInstance(model, id);
        Node node = instance.getNode(id);
        instance.transform.set(node.globalTransform);
        node.translation.set(0, 0, 0);
        node.scale.set(1, 1, 1);
        node.rotation.idt();
        instance.calculateTransforms();
        if (id.equals("space")) {
            space = instance;
            continue;
        }
        instances.add(instance);
        if (id.equals("ship"))
            ship = instance;
        else if (id.startsWith("block"))
            blocks.add(instance);
        else if (id.startsWith("invader"))
            invaders.add(instance);
    }
    loading = false;
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) Node(com.badlogic.gdx.graphics.g3d.model.Node) Model(com.badlogic.gdx.graphics.g3d.Model)

Example 24 with Model

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

the class OcclusionCullingTest method create.

@Override
public void create() {
    Gdx.input.setOnscreenKeyboardVisible(true);
    super.create();
    GLProfiler.enable();
    StringBuilder sb = new StringBuilder();
    sb.append("Swipe for next test\n");
    sb.append("Long press to toggle debug mode\n");
    sb.append("Ctrl+drag to rotate\n");
    sb.append("Scroll to zoom\n");
    sb.append("Tap to spawn dynamic entity, press\n");
    sb.append("'0' to spawn ").append(KEY_SPAWN_OCCLUDEE_AMOUNT).append(" static entities\n");
    sb.append("'1' to set normal/disabled/occlusion-culling\n");
    sb.append("'2' to change camera\n");
    sb.append("'3' to toggle camera movement\n");
    sb.append("'4' to cycle occlusion buffer sizes\n");
    sb.append("'5' to toggle occlusion buffer image\n");
    sb.append("'6' to toggle shadows\n");
    instructions = sb.toString();
    AssetManager assets = new AssetManager();
    disposables.add(assets);
    for (String modelName : OCCLUDEE_PATHS_DYNAMIC) assets.load(modelName, Model.class);
    assets.load(DEFAULT_TEX_PATH, Texture.class);
    Camera shadowCamera = ((DirectionalShadowLight) light).getCamera();
    shadowCamera.viewportWidth = shadowCamera.viewportHeight = 120;
    // User controlled camera
    overviewCam = camera;
    overviewCam.position.set(overviewCam.direction).nor().scl(-100);
    overviewCam.lookAt(Vector3.Zero);
    overviewCam.far = camera.far *= 2;
    overviewCam.update(true);
    // Animated frustum camera model
    frustumCam = new PerspectiveCamera(FRUSTUM_CAMERA_FOV, camera.viewportWidth, camera.viewportHeight);
    frustumCam.far = FRUSTUM_CAMERA_FAR;
    frustumCam.update(true);
    final Model frustumModel = FrustumCullingTest.createFrustumModel(frustumCam.frustum.planePoints);
    frustumModel.materials.first().set(new ColorAttribute(ColorAttribute.AmbientLight, Color.WHITE));
    disposables.add(frustumModel);
    frustumInstance = new ModelInstance(frustumModel);
    spriteBatch = new SpriteBatch();
    disposables.add(spriteBatch);
    shapeRenderer = new ShapeRenderer();
    disposables.add(shapeRenderer);
    oclBuffer = new OcclusionBuffer(OCL_BUFFER_EXTENTS[0], OCL_BUFFER_EXTENTS[0]);
    disposables.add(oclBuffer);
    occlusionCuller = new OcclusionCuller() {

        @Override
        public boolean isOccluder(btCollisionObject object) {
            return (object.getCollisionFlags() & CF_OCCLUDER_OBJECT) != 0;
        }

        @Override
        public void onObjectVisible(btCollisionObject object) {
            visibleEntities.add(world.entities.get(object.getUserValue()));
        }
    };
    disposables.add(occlusionCuller);
    // Add occluder walls
    final Model occluderModel = modelBuilder.createBox(OCCLUDER_DIM.x, OCCLUDER_DIM.y, OCCLUDER_DIM.z, new Material(ColorAttribute.createDiffuse(Color.WHITE)), VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);
    disposables.add(occluderModel);
    world.addConstructor("wall", new BulletConstructor(occluderModel, 0, new btBoxShape(tmpV1.set(OCCLUDER_DIM).scl(0.5f))));
    float y = OCCLUDER_DIM.y * 0.5f;
    addOccluder("wall", 0, tmpV1.set(20, y, 0));
    addOccluder("wall", -60, tmpV1.set(10, y, 20));
    addOccluder("wall", 60, tmpV1.set(10, y, -20));
    addOccluder("wall", 0, tmpV1.set(-20, y, 0));
    addOccluder("wall", 60, tmpV1.set(-10, y, 20));
    addOccluder("wall", -60, tmpV1.set(-10, y, -20));
    // Add ground
    final Model groundModel = modelBuilder.createBox(GROUND_DIM.x, GROUND_DIM.y, GROUND_DIM.z, new Material(ColorAttribute.createDiffuse(Color.WHITE)), VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);
    btCollisionShape groundShape = new btBoxShape(tmpV1.set(GROUND_DIM).scl(0.5f));
    world.addConstructor("big_ground", new BulletConstructor(groundModel, 0, groundShape));
    BulletEntity e = world.add("big_ground", 0, -GROUND_DIM.y * 0.5f, 0f);
    e.body.setFriction(1f);
    e.setColor(Color.FOREST);
    // Occludee entity constructors. Scale models uniformly and set a default diffuse texture.
    BoundingBox bb = new BoundingBox();
    assets.finishLoadingAsset(DEFAULT_TEX_PATH);
    TextureAttribute defaultTexture = new TextureAttribute(TextureAttribute.Diffuse, assets.get(DEFAULT_TEX_PATH, Texture.class));
    for (int i = 0; i < OCCLUDEE_PATHS_DYNAMIC.length; i++) {
        String modelPath = OCCLUDEE_PATHS_DYNAMIC[i];
        OCCLUDEE_PATHS_STATIC[i] = "static" + modelPath;
        assets.finishLoadingAsset(modelPath);
        Model model = assets.get(modelPath, Model.class);
        if (!model.materials.first().has(TextureAttribute.Diffuse))
            model.materials.first().set(defaultTexture);
        Vector3 dim = model.calculateBoundingBox(bb).getDimensions(tmpV1);
        float scaleFactor = OCCLUDEE_MAX_EXTENT / Math.max(dim.x, Math.max(dim.y, dim.z));
        for (Node node : model.nodes) node.scale.scl(scaleFactor);
        btCollisionShape shape = new btBoxShape(dim.scl(scaleFactor * 0.5f));
        world.addConstructor(modelPath, new BulletConstructor(model, 1, shape));
        world.addConstructor(OCCLUDEE_PATHS_STATIC[i], new BulletConstructor(model, 0, shape));
    }
    // Add occludees
    for (int i = 0; i < STARTING_OCCLUDEE_AMOUNT; i++) addRandomOccludee(false);
}
Also used : com.badlogic.gdx.physics.bullet.collision.btBoxShape(com.badlogic.gdx.physics.bullet.collision.btBoxShape) DirectionalShadowLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalShadowLight) StringBuilder(com.badlogic.gdx.utils.StringBuilder) Node(com.badlogic.gdx.graphics.g3d.model.Node) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) com.badlogic.gdx.physics.bullet.collision.btCollisionShape(com.badlogic.gdx.physics.bullet.collision.btCollisionShape) BoundingBox(com.badlogic.gdx.math.collision.BoundingBox) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) Camera(com.badlogic.gdx.graphics.Camera) com.badlogic.gdx.physics.bullet.collision.btCollisionObject(com.badlogic.gdx.physics.bullet.collision.btCollisionObject) TextureAttribute(com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute) AssetManager(com.badlogic.gdx.assets.AssetManager) Material(com.badlogic.gdx.graphics.g3d.Material) Vector3(com.badlogic.gdx.math.Vector3) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) Model(com.badlogic.gdx.graphics.g3d.Model) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)

Example 25 with Model

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

the class ConstraintsTest method create.

@Override
public void create() {
    super.create();
    final Model barModel = modelBuilder.createBox(10f, 1f, 1f, new Material(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE)), Usage.Position | Usage.Normal);
    disposables.add(barModel);
    // mass = 0: static body
    world.addConstructor("bar", new BulletConstructor(barModel, 0f));
    // Create the entities
    world.add("ground", 0f, 0f, 0f).setColor(0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 1f);
    BulletEntity bar = world.add("bar", 0f, 7f, 0f);
    bar.setColor(0.75f + 0.25f * (float) Math.random(), 0.75f + 0.25f * (float) Math.random(), 0.75f + 0.25f * (float) Math.random(), 1f);
    BulletEntity box1 = world.add("box", -4.5f, 6f, 0f);
    box1.setColor(0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 1f);
    btPoint2PointConstraint constraint = new btPoint2PointConstraint((btRigidBody) bar.body, (btRigidBody) box1.body, tmpV1.set(-5, -0.5f, -0.5f), tmpV2.set(-0.5f, 0.5f, -0.5f));
    ((btDynamicsWorld) world.collisionWorld).addConstraint(constraint, false);
    constraints.add(constraint);
    BulletEntity box2 = null;
    for (int i = 0; i < 10; i++) {
        if (i % 2 == 0) {
            box2 = world.add("box", -3.5f + (float) i, 6f, 0f);
            box2.setColor(0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 1f);
            constraint = new btPoint2PointConstraint((btRigidBody) box1.body, (btRigidBody) box2.body, tmpV1.set(0.5f, -0.5f, 0.5f), tmpV2.set(-0.5f, -0.5f, 0.5f));
        } else {
            box1 = world.add("box", -3.5f + (float) i, 6f, 0f);
            box1.setColor(0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 1f);
            constraint = new btPoint2PointConstraint((btRigidBody) box2.body, (btRigidBody) box1.body, tmpV1.set(0.5f, 0.5f, -0.5f), tmpV2.set(-0.5f, 0.5f, -0.5f));
        }
        ((btDynamicsWorld) world.collisionWorld).addConstraint(constraint, false);
        constraints.add(constraint);
    }
    constraint = new btPoint2PointConstraint((btRigidBody) bar.body, (btRigidBody) box1.body, tmpV1.set(5f, -0.5f, -0.5f), tmpV2.set(0.5f, 0.5f, -0.5f));
    ((btDynamicsWorld) world.collisionWorld).addConstraint(constraint, false);
    constraints.add(constraint);
}
Also used : com.badlogic.gdx.physics.bullet.dynamics.btRigidBody(com.badlogic.gdx.physics.bullet.dynamics.btRigidBody) com.badlogic.gdx.physics.bullet.dynamics.btDynamicsWorld(com.badlogic.gdx.physics.bullet.dynamics.btDynamicsWorld) com.badlogic.gdx.physics.bullet.dynamics.btPoint2PointConstraint(com.badlogic.gdx.physics.bullet.dynamics.btPoint2PointConstraint) Model(com.badlogic.gdx.graphics.g3d.Model) Material(com.badlogic.gdx.graphics.g3d.Material) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) com.badlogic.gdx.physics.bullet.dynamics.btTypedConstraint(com.badlogic.gdx.physics.bullet.dynamics.btTypedConstraint) com.badlogic.gdx.physics.bullet.dynamics.btPoint2PointConstraint(com.badlogic.gdx.physics.bullet.dynamics.btPoint2PointConstraint)

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