use of com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute in project libgdx by libgdx.
the class BillboardParticleBatch method setTexture.
public void setTexture(Texture texture) {
renderablePool.freeAll(renderables);
renderables.clear();
for (int i = 0, free = renderablePool.getFree(); i < free; ++i) {
Renderable renderable = renderablePool.obtain();
TextureAttribute attribute = (TextureAttribute) renderable.material.get(TextureAttribute.Diffuse);
attribute.textureDescription.texture = texture;
}
this.texture = texture;
}
use of com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute in project libgdx by libgdx.
the class PointSpriteParticleBatch method setTexture.
public void setTexture(Texture texture) {
TextureAttribute attribute = (TextureAttribute) renderable.material.get(TextureAttribute.Diffuse);
attribute.textureDescription.texture = texture;
}
use of com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute 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.attributes.TextureAttribute 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);
}
use of com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute in project libgdx by libgdx.
the class Model method convertMaterial.
protected Material convertMaterial(ModelMaterial mtl, TextureProvider textureProvider) {
Material result = new Material();
result.id = mtl.id;
if (mtl.ambient != null)
result.set(new ColorAttribute(ColorAttribute.Ambient, mtl.ambient));
if (mtl.diffuse != null)
result.set(new ColorAttribute(ColorAttribute.Diffuse, mtl.diffuse));
if (mtl.specular != null)
result.set(new ColorAttribute(ColorAttribute.Specular, mtl.specular));
if (mtl.emissive != null)
result.set(new ColorAttribute(ColorAttribute.Emissive, mtl.emissive));
if (mtl.reflection != null)
result.set(new ColorAttribute(ColorAttribute.Reflection, mtl.reflection));
if (mtl.shininess > 0f)
result.set(new FloatAttribute(FloatAttribute.Shininess, mtl.shininess));
if (mtl.opacity != 1.f)
result.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, mtl.opacity));
ObjectMap<String, Texture> textures = new ObjectMap<String, Texture>();
// FIXME uvScaling/uvTranslation totally ignored
if (mtl.textures != null) {
for (ModelTexture tex : mtl.textures) {
Texture texture;
if (textures.containsKey(tex.fileName)) {
texture = textures.get(tex.fileName);
} else {
texture = textureProvider.load(tex.fileName);
textures.put(tex.fileName, texture);
disposables.add(texture);
}
TextureDescriptor descriptor = new TextureDescriptor(texture);
descriptor.minFilter = texture.getMinFilter();
descriptor.magFilter = texture.getMagFilter();
descriptor.uWrap = texture.getUWrap();
descriptor.vWrap = texture.getVWrap();
float offsetU = tex.uvTranslation == null ? 0f : tex.uvTranslation.x;
float offsetV = tex.uvTranslation == null ? 0f : tex.uvTranslation.y;
float scaleU = tex.uvScaling == null ? 1f : tex.uvScaling.x;
float scaleV = tex.uvScaling == null ? 1f : tex.uvScaling.y;
switch(tex.usage) {
case ModelTexture.USAGE_DIFFUSE:
result.set(new TextureAttribute(TextureAttribute.Diffuse, descriptor, offsetU, offsetV, scaleU, scaleV));
break;
case ModelTexture.USAGE_SPECULAR:
result.set(new TextureAttribute(TextureAttribute.Specular, descriptor, offsetU, offsetV, scaleU, scaleV));
break;
case ModelTexture.USAGE_BUMP:
result.set(new TextureAttribute(TextureAttribute.Bump, descriptor, offsetU, offsetV, scaleU, scaleV));
break;
case ModelTexture.USAGE_NORMAL:
result.set(new TextureAttribute(TextureAttribute.Normal, descriptor, offsetU, offsetV, scaleU, scaleV));
break;
case ModelTexture.USAGE_AMBIENT:
result.set(new TextureAttribute(TextureAttribute.Ambient, descriptor, offsetU, offsetV, scaleU, scaleV));
break;
case ModelTexture.USAGE_EMISSIVE:
result.set(new TextureAttribute(TextureAttribute.Emissive, descriptor, offsetU, offsetV, scaleU, scaleV));
break;
case ModelTexture.USAGE_REFLECTION:
result.set(new TextureAttribute(TextureAttribute.Reflection, descriptor, offsetU, offsetV, scaleU, scaleV));
break;
}
}
}
return result;
}
Aggregations