use of com.badlogic.gdx.graphics.g3d.Model in project libgdx by libgdx.
the class VehicleTest method create.
@Override
public void create() {
super.create();
instructions = "Tap to shoot\nArrow keys to drive\nR to reset\nLong press to toggle debug mode\nSwipe for next test";
final Model chassisModel = objLoader.loadModel(Gdx.files.internal("data/car.obj"));
disposables.add(chassisModel);
chassisModel.materials.get(0).clear();
chassisModel.materials.get(0).set(ColorAttribute.createDiffuse(Color.RED), ColorAttribute.createSpecular(Color.WHITE));
final Model wheelModel = objLoader.loadModel(Gdx.files.internal("data/wheel.obj"));
disposables.add(wheelModel);
wheelModel.materials.get(0).clear();
wheelModel.materials.get(0).set(ColorAttribute.createDiffuse(Color.BLACK), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(128));
Texture checkboard = new Texture(Gdx.files.internal("data/g3d/checkboard.png"));
final Model largeGroundModel = modelBuilder.createBox(200f, 2f, 200f, new Material(TextureAttribute.createDiffuse(checkboard), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(16f)), Usage.Position | Usage.Normal | Usage.TextureCoordinates);
largeGroundModel.manageDisposable(checkboard);
disposables.add(largeGroundModel);
world.addConstructor("largeground", new BulletConstructor(largeGroundModel, 0f));
BoundingBox bounds = new BoundingBox();
Vector3 chassisHalfExtents = chassisModel.calculateBoundingBox(bounds).getDimensions(new Vector3()).scl(0.5f);
Vector3 wheelHalfExtents = wheelModel.calculateBoundingBox(bounds).getDimensions(new Vector3()).scl(0.5f);
world.addConstructor("chassis", new BulletConstructor(chassisModel, 5f, new btBoxShape(chassisHalfExtents)));
world.addConstructor("wheel", new BulletConstructor(wheelModel, 0, null));
for (int i = 0; i < 1000; i += 200) world.add("largeground", 0f, -1f, i);
chassis = world.add("chassis", 0, 3f, 0);
wheels[0] = world.add("wheel", 0, 0, 0);
wheels[1] = world.add("wheel", 0, 0, 0);
wheels[2] = world.add("wheel", 0, 0, 0);
wheels[3] = world.add("wheel", 0, 0, 0);
// Create the vehicle
raycaster = getRaycaster();
tuning = new btVehicleTuning();
vehicle = new btRaycastVehicle(tuning, (btRigidBody) chassis.body, raycaster);
chassis.body.setActivationState(Collision.DISABLE_DEACTIVATION);
((btDynamicsWorld) world.collisionWorld).addVehicle(vehicle);
vehicle.setCoordinateSystem(0, 1, 2);
btWheelInfo wheelInfo;
Vector3 point = new Vector3();
Vector3 direction = new Vector3(0, -1, 0);
Vector3 axis = new Vector3(-1, 0, 0);
wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(0.9f, -0.8f, 0.7f), direction, axis, wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, true);
wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(-0.9f, -0.8f, 0.7f), direction, axis, wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, true);
wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(0.9f, -0.8f, -0.5f), direction, axis, wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, false);
wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(-0.9f, -0.8f, -0.5f), direction, axis, wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, false);
}
use of com.badlogic.gdx.graphics.g3d.Model in project libgdx by libgdx.
the class Animation3DTest method onLoaded.
@Override
protected void onLoaded() {
if (skydome == null) {
skydome = new ModelInstance(assets.get("data/g3d/skydome.g3db", Model.class));
floorModel.getMaterial("concrete").set(TextureAttribute.createDiffuse(assets.get("data/g3d/concrete.png", Texture.class)));
floorModel.getMaterial("tree").set(TextureAttribute.createDiffuse(assets.get("data/tree.png", Texture.class)), new BlendingAttribute());
instances.add(new ModelInstance(floorModel, "floor"));
instances.add(tree = new ModelInstance(floorModel, "tree"));
assets.load("data/g3d/knight.g3db", Model.class);
loading = true;
} else if (character == null) {
character = new ModelInstance(assets.get("data/g3d/knight.g3db", Model.class));
BoundingBox bbox = new BoundingBox();
character.calculateBoundingBox(bbox);
character.transform.setToRotation(Vector3.Y, 180).trn(0, -bbox.min.y, 0);
instances.add(character);
animation = new AnimationController(character);
animation.animate("Idle", -1, 1f, null, 0.2f);
status = idle;
for (Animation anim : character.animations) Gdx.app.log("Test", anim.id);
// Now attach the node of another model at the tip of this knights sword:
ship = assets.get("data/g3d/ship.obj", Model.class).nodes.get(0).copy();
ship.detach();
// offset from the sword node to the tip of the sword, in rest pose
ship.translation.x = 10f;
ship.rotation.set(Vector3.Z, 90f);
ship.scale.scl(5f);
ship.parts.get(0).enabled = false;
character.getNode("sword").addChild(ship);
}
}
use of com.badlogic.gdx.graphics.g3d.Model in project libgdx by libgdx.
the class PairCacheTest method create.
@Override
public void create() {
super.create();
instructions = "Tap to toggle view\nLong press to toggle debug mode\nSwipe for next test\nCtrl+drag to rotate\nScroll to zoom";
world.addConstructor("collisionBox", new BulletConstructor(world.getConstructor("box").model));
// Create the entities
final float dX = BOX_X_MAX - BOX_X_MIN;
final float dY = BOX_Y_MAX - BOX_Y_MIN;
final float dZ = BOX_Z_MAX - BOX_Z_MIN;
for (int i = 0; i < BOXCOUNT; i++) world.add("collisionBox", BOX_X_MIN + dX * (float) Math.random(), BOX_Y_MIN + dY * (float) Math.random(), BOX_Z_MIN + dZ * (float) Math.random()).setColor(0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 1f);
manifoldArray = new btPersistentManifoldArray();
disposables.add(manifoldArray);
overviewCam = camera;
overviewCam.position.set(BOX_X_MAX, BOX_Y_MAX, BOX_Z_MAX);
overviewCam.lookAt(Vector3.Zero);
overviewCam.far = 150f;
overviewCam.update();
frustumCam = new PerspectiveCamera(camera.fieldOfView, camera.viewportWidth, camera.viewportHeight);
frustumCam.far = Vector3.len(BOX_X_MAX, BOX_Y_MAX, BOX_Z_MAX);
frustumCam.update();
final Model ghostModel = FrustumCullingTest.createFrustumModel(frustumCam.frustum.planePoints);
disposables.add(ghostModel);
// The ghost object does not need to be shaped as a camera frustum, it can have any collision shape.
ghostObject = FrustumCullingTest.createFrustumObject(frustumCam.frustum.planePoints);
disposables.add(ghostObject);
world.add(ghostEntity = new BulletEntity(ghostModel, ghostObject, 0, 0, 0));
disposables.add(ghostEntity);
shapeRenderer = new ShapeRenderer();
disposables.add(shapeRenderer);
}
use of com.badlogic.gdx.graphics.g3d.Model in project libgdx by libgdx.
the class MeshSpawnShapeValue method load.
@Override
public void load(AssetManager manager, ResourceData data) {
SaveData saveData = data.getSaveData();
AssetDescriptor descriptor = saveData.loadAsset();
if (descriptor != null) {
Model model = (Model) manager.get(descriptor);
setMesh(model.meshes.get((Integer) saveData.load("index")), model);
}
}
use of com.badlogic.gdx.graphics.g3d.Model in project libgdx by libgdx.
the class ModelInfluencer method load.
@Override
public void load(AssetManager manager, ResourceData resources) {
SaveData data = resources.getSaveData();
AssetDescriptor descriptor;
while ((descriptor = data.loadAsset()) != null) {
Model model = (Model) manager.get(descriptor);
if (model == null)
throw new RuntimeException("Model is null");
models.add(model);
}
}
Aggregations