use of com.badlogic.gdx.graphics.g3d.ModelInstance in project libgdx by libgdx.
the class FogTest method create.
@Override
public void create() {
modelBatch = new ModelBatch();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
environment.set(new ColorAttribute(ColorAttribute.Fog, 0.13f, 0.13f, 0.13f, 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(30f, 10f, 30f);
cam.lookAt(0, 0, 0);
cam.near = 0.1f;
cam.far = 45f;
cam.update();
ModelBuilder modelBuilder = new ModelBuilder();
model = modelBuilder.createBox(5f, 5f, 5f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal);
instance = new ModelInstance(model);
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 FrameBufferCubemapTest method renderScene.
public void renderScene() {
Gdx.gl.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight());
Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST);
// Render scene to screen
super.render();
// Render scene to cubemap
camFb.position.set(cam.position);
camFb.near = cam.near;
camFb.far = cam.far;
fb.begin();
while (fb.nextSide()) {
fb.getSide().getUp(camFb.up);
fb.getSide().getDirection(camFb.direction);
camFb.update();
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
modelBatch.begin(camFb);
for (ModelInstance instance : instances) modelBatch.render(instance, lights);
if (space != null)
modelBatch.render(space);
modelBatch.end();
}
fb.end();
}
use of com.badlogic.gdx.graphics.g3d.ModelInstance in project libgdx by libgdx.
the class MaterialTest method create.
@Override
public void create() {
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), true);
// Create material attributes. Each material can contain x-number of attributes.
textureAttribute = new TextureAttribute(TextureAttribute.Diffuse, texture);
colorAttribute = new ColorAttribute(ColorAttribute.Diffuse, Color.ORANGE);
blendingAttribute = new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
ModelBuilder builder = new ModelBuilder();
model = builder.createBox(1, 1, 1, new Material(), Usage.Position | Usage.Normal | Usage.TextureCoordinates);
model.manageDisposable(texture);
modelInstance = new ModelInstance(model);
modelInstance.transform.rotate(Vector3.X, 45);
material = modelInstance.materials.get(0);
builder.begin();
MeshPartBuilder mpb = builder.part("back", GL20.GL_TRIANGLES, Usage.Position | Usage.TextureCoordinates, new Material(textureAttribute));
mpb.rect(-2, -2, -2, 2, -2, -2, 2, 2, -2, -2, 2, -2, 0, 0, 1);
backModel = builder.end();
background = new ModelInstance(backModel);
modelBatch = new ModelBatch();
camera = new PerspectiveCamera(45, 4, 4);
camera.position.set(0, 0, 3);
camera.direction.set(0, 0, -1);
camera.update();
Gdx.input.setInputProcessor(this);
}
use of com.badlogic.gdx.graphics.g3d.ModelInstance in project libgdx by libgdx.
the class ViewportTest3 method create.
public void create() {
modelBatch = new ModelBatch();
modelBuilder = new ModelBuilder();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.f));
shadowLight = new DirectionalLight();
shadowLight.set(0.8f, 0.8f, 0.8f, -0.5f, -1f, 0.7f);
environment.add(shadowLight);
modelBatch = new ModelBatch();
camera = new PerspectiveCamera();
camera.fieldOfView = 67;
camera.near = 0.1f;
camera.far = 300f;
camera.position.set(0, 0, 100);
camera.lookAt(0, 0, 0);
viewports = ViewportTest1.getViewports(camera);
viewport = viewports.first();
names = ViewportTest1.getViewportNames();
name = names.first();
ModelBuilder modelBuilder = new ModelBuilder();
Model boxModel = modelBuilder.createBox(50f, 50f, 50f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal);
boxInstance = new ModelInstance(boxModel);
boxInstance.transform.rotate(1, 0, 0, 30);
boxInstance.transform.rotate(0, 1, 0, 30);
Gdx.input.setInputProcessor(new InputAdapter() {
public boolean keyDown(int keycode) {
if (keycode == Input.Keys.SPACE) {
int index = (viewports.indexOf(viewport, true) + 1) % viewports.size;
name = names.get(index);
viewport = viewports.get(index);
resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
return false;
}
});
}
use of com.badlogic.gdx.graphics.g3d.ModelInstance in project nhglib by VoidZombie.
the class SceneManager method loadAssets.
private void loadAssets(Integer entity) {
final ModelComponent modelComponent = modelMapper.get(entity);
// Group all assets
final Array<Asset> allAssets = new Array<>();
final Asset modelAsset = modelComponent.asset;
for (PbrMaterial mat : modelComponent.pbrMaterials) {
if (mat.albedoAsset != null) {
allAssets.add(mat.albedoAsset);
}
if (mat.metalnessAsset != null) {
allAssets.add(mat.metalnessAsset);
}
if (mat.roughnessAsset != null) {
allAssets.add(mat.roughnessAsset);
}
if (mat.normalAsset != null) {
allAssets.add(mat.normalAsset);
}
if (mat.ambientOcclusionAsset != null) {
allAssets.add(mat.ambientOcclusionAsset);
}
}
// Start loading them
assets.queueAsset(modelAsset);
// Wait for them
messaging.get(Strings.Events.assetLoaded).subscribe(new Consumer<Message>() {
@Override
public void accept(Message message) throws Exception {
Asset asset = (Asset) message.data.get(Strings.Defaults.assetKey);
if (asset != null) {
if (asset.is(modelAsset.alias)) {
Model model = assets.get(asset);
modelComponent.model = new ModelInstance(model);
if (modelComponent.model.animations.size > 0) {
modelComponent.animationController = new AnimationController(modelComponent.model);
}
assets.queueAssets(allAssets);
} else {
if (allAssets.contains(asset, false)) {
temporaryLoadedAssets.add(asset);
allAssets.removeValue(asset, false);
Bundle bundle = new Bundle();
bundle.put("size", allAssets.size);
bundle.put("modelComponent", modelComponent);
sizeSubject.onNext(bundle);
}
}
}
}
});
}
Aggregations