use of com.badlogic.gdx.graphics.g3d.ModelInstance in project libgdx by libgdx.
the class ShaderCollectionTest method onLoaded.
@Override
protected void onLoaded() {
if (currentlyLoading == null || currentlyLoading.length() == 0)
return;
if (loadingMaterial) {
loadingMaterial = false;
if (currentMaterial != null && !currentMaterial.equals(currentlyLoading))
assets.unload(currentMaterial);
currentMaterial = currentlyLoading;
currentlyLoading = null;
ModelInstance instance = instances.get(0);
if (instance != null) {
instance.materials.get(0).clear();
instance.materials.get(0).set(assets.get(currentMaterial, Model.class).materials.get(0));
}
} else {
if (currentModel != null && !currentModel.equals(currentlyLoading))
assets.unload(currentModel);
currentModel = currentlyLoading;
currentlyLoading = null;
instances.clear();
animationControllers.clear();
final ModelInstance instance = new ModelInstance(assets.get(currentModel, Model.class), transform);
instances.add(instance);
if (instance.animations.size > 0)
animationControllers.put(instance, new AnimationController(instance));
instance.calculateBoundingBox(bounds);
cam.position.set(1, 1, 1).nor().scl(bounds.getDimensions(tmpV).len() * 0.75f).add(bounds.getCenter(tmpV));
cam.up.set(0, 1, 0);
cam.lookAt(inputController.target.set(bounds.getCenter(tmpV)));
cam.far = Math.max(100f, bounds.getDimensions(tmpV).len() * 2.0f);
cam.update();
moveRadius = bounds.getDimensions(tmpV).len() * 0.25f;
}
}
use of com.badlogic.gdx.graphics.g3d.ModelInstance in project libgdx by libgdx.
the class ShaderCollectionTest method switchAnimation.
protected void switchAnimation() {
for (ObjectMap.Entry<ModelInstance, AnimationController> e : animationControllers.entries()) {
int animIndex = 0;
if (e.value.current != null) {
for (int i = 0; i < e.key.animations.size; i++) {
final Animation animation = e.key.animations.get(i);
if (e.value.current.animation == animation) {
animIndex = i;
break;
}
}
}
animIndex = (animIndex + 1) % e.key.animations.size;
e.value.animate(e.key.animations.get(animIndex).id, -1, 1f, null, 0.2f);
}
}
use of com.badlogic.gdx.graphics.g3d.ModelInstance in project libgdx by libgdx.
the class SkeletonTest method switchAnimation.
protected void switchAnimation() {
for (ObjectMap.Entry<ModelInstance, AnimationController> e : animationControllers.entries()) {
int animIndex = 0;
if (e.value.current != null) {
for (int i = 0; i < e.key.animations.size; i++) {
final Animation animation = e.key.animations.get(i);
if (e.value.current.animation == animation) {
animIndex = i;
break;
}
}
}
animIndex = (animIndex + 1) % e.key.animations.size;
e.value.animate(e.key.animations.get(animIndex).id, -1, 1f, null, 0.2f);
}
}
use of com.badlogic.gdx.graphics.g3d.ModelInstance in project libgdx by libgdx.
the class TextureRegion3DTest method create.
@Override
public void create() {
Gdx.gl.glClearColor(0.2f, 0.3f, 1.0f, 0.f);
atlas = new TextureAtlas(Gdx.files.internal("data/testpack"));
regions = atlas.getRegions();
modelBatch = new ModelBatch(new DefaultShaderProvider());
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f));
environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(10f, 10f, 10f);
cam.lookAt(0, 0, 0);
cam.near = 0.1f;
cam.far = 300f;
cam.update();
ModelBuilder modelBuilder = new ModelBuilder();
final Material material = new Material(ColorAttribute.createDiffuse(1f, 1f, 1f, 1f), new TextureAttribute(TextureAttribute.Diffuse));
model = modelBuilder.createBox(5f, 5f, 5f, material, Usage.Position | Usage.Normal | Usage.TextureCoordinates);
instance = new ModelInstance(model);
attribute = instance.materials.get(0).get(TextureAttribute.class, TextureAttribute.Diffuse);
Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(cam)));
}
use of com.badlogic.gdx.graphics.g3d.ModelInstance in project libgdx by libgdx.
the class ModelTest method onLoaded.
@Override
protected void onLoaded() {
if (currentlyLoading == null || currentlyLoading.length() == 0)
return;
instances.clear();
animationControllers.clear();
final ModelInstance instance = new ModelInstance(assets.get(currentlyLoading, Model.class));
instance.transform = transform;
instances.add(instance);
if (instance.animations.size > 0)
animationControllers.put(instance, new AnimationController(instance));
currentlyLoading = null;
instance.calculateBoundingBox(bounds);
cam.position.set(1, 1, 1).nor().scl(bounds.getDimensions(tmpV1).len() * 0.75f + bounds.getCenter(tmpV2).len());
cam.up.set(0, 1, 0);
cam.lookAt(0, 0, 0);
cam.far = 50f + bounds.getDimensions(tmpV1).len() * 2.0f;
cam.update();
}
Aggregations