Java 类com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute 实例源码
项目:libgdxcn
文件:DepthShader.java
@Override
public boolean canRender (Renderable renderable) {
if (renderable.material.has(BlendingAttribute.Type)) {
if ((materialMask & BlendingAttribute.Type) != BlendingAttribute.Type)
return false;
if (renderable.material.has(TextureAttribute.Diffuse) != ((materialMask & TextureAttribute.Diffuse) == TextureAttribute.Diffuse))
return false;
}
final boolean skinned = ((renderable.mesh.getVertexAttributes().getMask() & Usage.BoneWeight) == Usage.BoneWeight);
if (skinned != (numBones > 0)) return false;
if (!skinned) return true;
int w = 0;
final int n = renderable.mesh.getVertexAttributes().size();
for (int i = 0; i < n; i++) {
final VertexAttribute attr = renderable.mesh.getVertexAttributes().get(i);
if (attr.usage == Usage.BoneWeight) w |= (1 << attr.unit);
}
return w == weights;
}
项目:libgdxcn
文件:FramebufferToTextureTest.java
@Override
public void create () {
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), true);
texture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);
ObjLoader objLoader = new ObjLoader();
mesh = objLoader.loadObj(Gdx.files.internal("data/cube.obj"));
mesh.materials.get(0).set(new TextureAttribute(TextureAttribute.Diffuse, texture));
modelInstance = new ModelInstance(mesh);
modelBatch = new ModelBatch();
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(3, 3, 3);
cam.direction.set(-1, -1, -1);
batch = new SpriteBatch();
font = new BitmapFont();
}
项目:HelixEngine
文件:AreaDisplayable.java
public AreaDisplayable(Model model) {
instance = new ModelInstance(model);
animationController = new AnimationController(instance);
instance.transform.rotate(new Vector3(1, 0, 0), 90);
for (Material material : instance.materials) {
TextureAttribute ta
= (TextureAttribute) material.get(TextureAttribute.Diffuse);
ta.textureDescription.magFilter = Texture.TextureFilter.Nearest;
ta.textureDescription.minFilter = Texture.TextureFilter.Nearest;
material.set(ta);
material.set(ColorAttribute.createDiffuse(Color.WHITE));
BlendingAttribute ba = new BlendingAttribute(GL20.GL_SRC_ALPHA,
GL20.GL_ONE_MINUS_SRC_ALPHA);
material.set(ba);
}
}
项目:GdxStudio
文件:Game3d.java
public Game3d(){
ship = Asset.loadModelObj("ship");//loads an obj model
ship.scale(3f);
skydome = Asset.loadModel("skydome"); //loads a g3db model
builder = new ModelBuilder();
builder.begin();
MeshPartBuilder part = builder.part("floor", GL20.GL_TRIANGLES, Usage.Position |
Usage.TextureCoordinates | Usage.Normal, new Material());
for (float x = -200f; x < 200f; x += 10f) {
for (float z = -200f; z < 200f; z += 10f) {
part.rect(x, 0, z + 10f, x + 10f, 0, z + 10f, x + 10f, 0, z, x, 0, z, 0, 1, 0);
}
}
floor = new Actor3d(builder.end());
floor.materials.get(0).set(TextureAttribute.createDiffuse(Asset.tex("concrete").getTexture()));
knight = Asset.loadModel("knight");
knight.setPosition(-20f, 18f, 0f);
knight.setPitch(-90f);
addActor3d(floor);
addActor3d(skydome);
addActor3d(ship);
addActor3d(knight);
stage3d.getCamera().position.set(knight.getX()+ 13f, knight.getY() + 24f, knight.getZ() + 45f);
//Camera3d.followOffset(20f, 20f, -20f);
// Camera3d.followActor3d(knight, false);
}
项目:gdx-proto
文件:Terrain.java
/**
* Return a heightmap chunk
* TODO NOT IMPLEMENTED!
* @param heightmap
* @param tex
* @param width
* @param height
* @return
*/
public static TerrainChunk CreateHeightMapChunk (FileHandle heightmap, Texture tex, int width, int height) {
HeightMap hp = new HeightMap(heightmap, 10, 10, false, 3);
HeightMapModel md = new HeightMapModel(hp);
//Model model = md.ground;
md.ground.materials.get(0).set(TextureAttribute.createDiffuse(tex));
//btCollisionObject obj = new btCollisionObject();
//btCollisionShape shape = new btBvhTriangleMeshShape(model.meshParts);
//obj.setCollisionShape(shape);
////Physics.applyStaticGeometryCollisionFlags(obj);
//Physics.inst.addStaticGeometryToWorld(obj);
TerrainChunk ch = new TerrainChunk();
ch.setModelInstance(md.ground);
return ch;
}
项目:gdx-proto
文件:ModelManager.java
public void createBillboardTest() {
ModelBuilder mb = new ModelBuilder();
mb.begin();
long attr = Usage.TextureCoordinates | Usage.Position | Usage.Normal;
TextureRegion region = Assets.getAtlas().findRegion("sprites/test-guy");
Material mat = new Material(TextureAttribute.createDiffuse(region.getTexture()));
boolean blended = true;
float opacity = 1f;
mat.set(new BlendingAttribute(blended, GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, opacity));
MeshPartBuilder mpb = mb.part("rect", GL20.GL_TRIANGLES, attr, mat);
mpb.setUVRange(region);
// the coordinates are offset so that we can easily set the center position to align with the entity's body
float sz = 2f; // size
float b = -sz/2; // base
float max = sz/2; // max
Vector3 bl = new Vector3(b, b, 0f);
Vector3 br = new Vector3(b, max, 0f);
Vector3 tr = new Vector3(max, max, 0f);
Vector3 tl = new Vector3(max, b, 0f);
Vector3 norm = new Vector3(0f, 0f, 1f);
mpb.rect(bl, tl, tr, br, norm);
billboardTestModel = mb.end();
}
项目:gdx-proto
文件:Sky.java
public static void createSkyBox (Texture xpos, Texture xneg, Texture ypos, Texture yneg, Texture zpos, Texture zneg) {
modelInstance = new ModelInstance(model, "Skycube");
// Set material textures
modelInstance.materials.get(0).set(TextureAttribute.createDiffuse(xpos));
modelInstance.materials.get(1).set(TextureAttribute.createDiffuse(xneg));
modelInstance.materials.get(2).set(TextureAttribute.createDiffuse(ypos));
modelInstance.materials.get(3).set(TextureAttribute.createDiffuse(yneg));
modelInstance.materials.get(5).set(TextureAttribute.createDiffuse(zpos));
modelInstance.materials.get(4).set(TextureAttribute.createDiffuse(zneg));
//Disable depth test
modelInstance.materials.get(0).set(new DepthTestAttribute(0));
modelInstance.materials.get(1).set(new DepthTestAttribute(0));
modelInstance.materials.get(2).set(new DepthTestAttribute(0));
modelInstance.materials.get(3).set(new DepthTestAttribute(0));
modelInstance.materials.get(4).set(new DepthTestAttribute(0));
modelInstance.materials.get(5).set(new DepthTestAttribute(0));
enabled = true;
}
项目:gdx-proto
文件:Shadow.java
public static void init() {
list = new Array<>();
ModelBuilder mb = new ModelBuilder();
Vector3 norm = new Vector3(0f, 1f, 0f);
Texture texture = Assets.manager.get("textures/shadow.png", Texture.class);
Material material = new Material(TextureAttribute.createDiffuse(texture));
material.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, 0.7f));
//material.set(new DepthTestAttribute(0)); // disable depth testing
long attr = Usage.Position | Usage.TextureCoordinates;
float s = 1f;
model = mb.createRect(
-s, 0f, -s,// bl
-s, 0f, s, // tl
s, 0f, s, // tr
s, 0f, -s, // br
norm.x, norm.y, norm.z,
material,
attr
);
}
项目:Cubes_2
文件:WorldShaderProvider.java
@Override
public void begin(ShaderProgram program, Camera camera, RenderContext context) {
TextureAttribute textureAttribute = AmbientOcclusion.getTextureAttribute();
ao_unit = context.textureBinder.bind(textureAttribute.textureDescription);
program.setUniformi(u_aoTexture, ao_unit);
program.setUniformf(u_aoUVTransform, textureAttribute.offsetU, textureAttribute.offsetV,
textureAttribute.scaleU, textureAttribute.scaleV);
}
项目:Cubes_2
文件:Assets.java
private static PackedTextureSheet getPackedTextureSheet(AssetType... assetType) {
if (Adapter.isDedicatedServer())
return null;
TexturePacker texturePacker = new TexturePacker(2048, 2048, 1, true);
Pixmap pixmap;
getPacketTextureSheetFor(assetType, texturePacker, pixmap);
FileHandle fileHandle = assetsFolder.child("packed");
fileHandle.mkdirs();
Compatibility.get().nomedia(fileHandle);
fileHandle = fileHandle.child(assetType[0].name() + ".cim");
try {
PixmapIO.writeCIM(fileHandle, texturePacker.getPixmap());
} catch (GdxRuntimeException e) {
Log.error("Failed to write packed image", e);
}
Texture texture = new Texture(fileHandle);
texture.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);
PackedTextureSheet packedTextureSheet = new PackedTextureSheet(
new Material(TextureAttribute.createDiffuse(texture)));
packedTextureSheet.getMaterial().set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));
Map<Asset, TexturePacker.PackRectangle> rectangles = texturePacker.getRectangles();
int num = 0;
for (Map.Entry<Asset, TexturePacker.PackRectangle> entry : rectangles.entrySet()) {
num++;
TextureRegion textureRegion = new TextureRegion(texture, entry.getValue().x, entry.getValue().y,
entry.getValue().width, entry.getValue().height);
entry.getKey().setPackedTextureRegion(textureRegion, packedTextureSheet);
packedTextureSheet.getPackedTextures().put(entry.getKey().toString(), textureRegion);
}
for (AssetType type : assetType) {
type.setPackedTextureSheet(packedTextureSheet);
}
return packedTextureSheet;
}
项目:Cubes
文件:WorldShaderProvider.java
@Override
public void begin(ShaderProgram program, Camera camera, RenderContext context) {
TextureAttribute textureAttribute = AmbientOcclusion.getTextureAttribute();
ao_unit = context.textureBinder.bind(textureAttribute.textureDescription);
program.setUniformi(u_aoTexture, ao_unit);
program.setUniformf(u_aoUVTransform, textureAttribute.offsetU, textureAttribute.offsetV, textureAttribute.scaleU, textureAttribute.scaleV);
}
项目:nhglib
文件:PointSpriteSoftParticleBatch.java
protected void allocRenderable() {
renderable = new Renderable();
renderable.meshPart.primitiveType = GL20.GL_POINTS;
renderable.meshPart.offset = 0;
renderable.material = new Material(new BlendingAttribute(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA, 1f),
new DepthTestAttribute(GL20.GL_LEQUAL, false), TextureAttribute.createDiffuse((Texture) null));
}
项目:nhglib
文件:NhgModelLoader.java
@Override
public Model loadSync(AssetManager manager, String fileName, FileHandle file, P parameters) {
ModelData data = null;
synchronized (items) {
for (int i = 0; i < items.size; i++) {
if (items.get(i).key.equals(fileName)) {
data = items.get(i).value;
items.removeIndex(i);
}
}
}
if (data == null) return null;
final Model result = new Model(data, new TextureProvider.AssetTextureProvider(manager));
// need to remove the textures from the managed disposables, or else ref counting
// doesn't work!
Iterator<Disposable> disposables = result.getManagedDisposables().iterator();
while (disposables.hasNext()) {
Disposable disposable = disposables.next();
if (disposable instanceof Texture) {
disposables.remove();
}
}
// Automatically convert all materials to PBR
for (Material material : result.materials) {
TextureAttribute textureAttribute = (TextureAttribute) material.get(TextureAttribute.Diffuse);
if (textureAttribute != null) {
material.set(PbrTextureAttribute.createAlbedo(textureAttribute.textureDescription.texture));
}
}
data = null;
return result;
}
项目:LibGDX-PBR
文件:PBRTextureAttribute.java
@Override
public int compareTo (Attribute o) {
if (type != o.type) return type < o.type ? -1 : 1;
TextureAttribute other = (TextureAttribute)o;
final int c = textureDescription.compareTo(other.textureDescription);
if (c != 0) return c;
if (uvIndex != other.uvIndex) return uvIndex - other.uvIndex;
if (!MathUtils.isEqual(scaleU, other.scaleU)) return scaleU > other.scaleU ? 1 : -1;
if (!MathUtils.isEqual(scaleV, other.scaleV)) return scaleV > other.scaleV ? 1 : -1;
if (!MathUtils.isEqual(offsetU, other.offsetU)) return offsetU > other.offsetU ? 1 : -1;
if (!MathUtils.isEqual(offsetV, other.offsetV)) return offsetV > other.offsetV ? 1 : -1;
return 0;
}
项目:Argent
文件:MaterialWrapper.java
private <T extends Attribute> T getAttribute(long type, Class<T> cls) {
String alias = TextureAttribute.getAttributeAlias(type);
Attribute attr = mtl.get(type);
if(attr == null)
return null;
return cls.cast(attr);
}
项目:Argent
文件:AttributeTypeAdapter.java
@Override
public void write(JsonWriter out, Attribute value) throws IOException {
if(value == null) {
out.nullValue();
return;
}
out.beginObject();
String alias = value.getClass().getSimpleName();
out.name("type").value(value.type);
alias += "::" + value.getAttributeAlias(value.type);
out.name("alias").value(alias);
out.name("attrData").beginObject();
if(value instanceof TextureAttribute) {
out.name("offsetU").value(((TextureAttribute) value).offsetU);
out.name("offsetV").value(((TextureAttribute) value).offsetV);
out.name("scaleU").value(((TextureAttribute) value).scaleU);
out.name("scaleV").value(((TextureAttribute) value).scaleV);
out.name("textureDescriptor").value(JSONSerializer.instance().serialize(((TextureAttribute) value).textureDescription));
}else if(value instanceof ColorAttribute) {
out.name("colour").value(((ColorAttribute) value).color.toString());
}else if(value instanceof BlendingAttribute) {
out.name("alpha").value(((BlendingAttribute) value).opacity);
}
out.endObject();
out.endObject();
}
项目:Argent
文件:AttributeTypeAdapter.java
@Override
public Attribute read(JsonReader in) throws IOException {
Attribute attr = null;
long type = -1;
String alias = "";
in.beginObject();
while(in.hasNext()) {
switch(in.nextName()) {
case "type": type = in.nextLong(); break;
case "alias": alias = in.nextString(); break;
case "attrData":
attr = buildFromAlias(alias);
if(attr == null) break;
in.beginObject();
while(in.hasNext()) {
switch(in.nextName()) {
case "offsetU":
((TextureAttribute)attr).offsetU = (float) in.nextDouble(); break;
case "offsetV":
((TextureAttribute)attr).offsetV = (float) in.nextDouble(); break;
case "scaleU":
((TextureAttribute)attr).scaleU = (float) in.nextDouble(); break;
case "scaleV":
((TextureAttribute)attr).scaleV = (float) in.nextDouble(); break;
case "textureDescriptor":
((TextureAttribute)attr).textureDescription.set(JSONSerializer.instance().deserialize(in.nextString(), TextureDescriptor.class)); break;
case "colour":
((ColorAttribute)attr).color.set(Color.valueOf(in.nextString())); break;
case "alpha":
((BlendingAttribute)attr).opacity = (float) in.nextDouble(); break;
}
}
in.endObject();
break;
}
}
in.endObject();
return attr;
}
项目:eamaster
文件:BasicShapesTest.java
@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);
}
项目:Radix
文件:Entity.java
public void render(ModelBatch batch) {
if (model != null) {
// TODO: support subtle action. need to create instance every time?
ModelInstance instance = new ModelInstance(model);
instance.materials.get(0).set(TextureAttribute.createDiffuse(texture));
instance.transform.translate(position.getX(), position.getY(), position.getZ());
batch.render(instance);
}
}
项目:Radix
文件:EntityModel.java
private static ModelInstance getInstance(String objPath, String texturePath) {
Model model = loader.loadModel(Gdx.files.internal(objPath), new ObjLoader.ObjLoaderParameters(true));
ModelInstance instance = new ModelInstance(model);
Texture texture = new Texture(Gdx.files.internal(texturePath));
instance.materials.get(0).set(TextureAttribute.createDiffuse(texture));
return instance;
}
项目:Radix
文件:GameRenderer.java
private void drawBlockSelection() {
int curProgressInt = Math.round(RadixClient.getInstance().getPlayer().getBreakPercent() * 10) - 1;
if ((blockBreakModel == null || blockBreakStage != curProgressInt) && curProgressInt >= 0) {
if (blockBreakModel != null)
blockBreakModel.dispose();
blockBreakStage = curProgressInt;
ModelBuilder builder = new ModelBuilder();
blockBreakModel = builder.createBox(1f, 1f, 1f,
new Material(TextureAttribute.createDiffuse(blockBreakStages[blockBreakStage]),
new BlendingAttribute(),
FloatAttribute.createAlphaTest(0.25f)),
VertexAttributes.Usage.Position | VertexAttributes.Usage.TextureCoordinates);
blockBreakModelInstance = new ModelInstance(blockBreakModel);
}
Vec3i curBlk = RadixClient.getInstance().getSelectedBlock();
if (curBlk != null && curProgressInt >= 0) {
Gdx.gl.glPolygonOffset(100000, 2000000);
blockOverlayBatch.begin(RadixClient.getInstance().getCamera());
blockBreakModelInstance.transform.translate(curBlk.x + 0.5f, curBlk.y + 0.5f, curBlk.z + 0.5f);
blockOverlayBatch.render(blockBreakModelInstance);
blockBreakModelInstance.transform.translate(-(curBlk.x + 0.5f), -(curBlk.y + 0.5f), -(curBlk.z + 0.5f));
blockOverlayBatch.end();
Gdx.gl.glPolygonOffset(100000, -2000000);
}
}
项目:Mundus
文件:ModelShader.java
@Override
public void render(Renderable renderable) {
final MundusEnvironment env = (MundusEnvironment) renderable.environment;
setLights(env);
set(UNIFORM_TRANS_MATRIX, renderable.worldTransform);
// texture uniform
TextureAttribute diffuseTexture = ((TextureAttribute) (renderable.material.get(TextureAttribute.Diffuse)));
ColorAttribute diffuseColor = ((ColorAttribute) (renderable.material.get(ColorAttribute.Diffuse)));
if (diffuseTexture != null) {
set(UNIFORM_MATERIAL_DIFFUSE_TEXTURE, diffuseTexture.textureDescription.texture);
set(UNIFORM_MATERIAL_DIFFUSE_USE_TEXTURE, 1);
} else {
set(UNIFORM_MATERIAL_DIFFUSE_COLOR, diffuseColor.color);
set(UNIFORM_MATERIAL_DIFFUSE_USE_TEXTURE, 0);
}
// shininess
float shininess = ((FloatAttribute)renderable.material.get(FloatAttribute.Shininess)).value;
set(UNIFORM_MATERIAL_SHININESS, shininess);
// Fog
final Fog fog = env.getFog();
if (fog == null) {
set(UNIFORM_FOG_DENSITY, 0f);
set(UNIFORM_FOG_GRADIENT, 0f);
} else {
set(UNIFORM_FOG_DENSITY, fog.density);
set(UNIFORM_FOG_GRADIENT, fog.gradient);
set(UNIFORM_FOG_COLOR, fog.color);
}
// bind attributes, bind mesh & render; then unbinds everything
renderable.meshPart.render(program);
}
项目:Mundus
文件:MaterialAsset.java
/**
* Applies this material asset to the libGDX material.
*
* @param material
* @return
*/
public Material applyToMaterial(Material material) {
if (diffuseColor != null) {
material.set(new ColorAttribute(ColorAttribute.Diffuse, diffuseColor));
}
if (diffuseTexture != null) {
material.set(new TextureAttribute(TextureAttribute.Diffuse, diffuseTexture.getTexture()));
} else {
material.remove(TextureAttribute.Diffuse);
}
material.set(new FloatAttribute(FloatAttribute.Shininess, shininess));
return material;
}
项目:GdxDemo3D
文件:GameScene.java
private void setVColorBlendAttributes() {
Array<String> modelsIdsInScene = assets.getPlaceholderIdsByType(BlenderModel.class);
Array<BlenderModel> instancesWithId = new Array<BlenderModel>();
for (String id : modelsIdsInScene) {
instancesWithId.clear();
assets.getPlaceholders(id, BlenderModel.class, instancesWithId);
for (BlenderModel blenderModel : instancesWithId) {
// Maybe check if
// renderable.meshPart.mesh.getVertexAttribute(VertexAttributes.Usage.ColorUnpacked) != null
if (blenderModel.custom_properties.containsKey("v_color_material_blend")) {
Model model = assets.getAsset(id, Model.class);
String redMaterialName = blenderModel.custom_properties.get("v_color_material_red");
String greenMaterialName = blenderModel.custom_properties.get("v_color_material_green");
String blueMaterialName = blenderModel.custom_properties.get("v_color_material_blue");
TextureAttribute redTexAttr = (TextureAttribute)
model.getMaterial(redMaterialName).get(TextureAttribute.Diffuse);
TextureAttribute greenTexAttr = (TextureAttribute)
model.getMaterial(greenMaterialName).get(TextureAttribute.Diffuse);
TextureAttribute blueTexAttr = (TextureAttribute)
model.getMaterial(blueMaterialName).get(TextureAttribute.Diffuse);
VertexColorTextureBlend redAttribute =
new VertexColorTextureBlend(VertexColorTextureBlend.Red,
redTexAttr.textureDescription.texture);
VertexColorTextureBlend greenAttribute =
new VertexColorTextureBlend(VertexColorTextureBlend.Green,
greenTexAttr.textureDescription.texture);
VertexColorTextureBlend blueAttribute =
new VertexColorTextureBlend(VertexColorTextureBlend.Blue,
blueTexAttr.textureDescription.texture);
for (Node node : model.nodes) {
for (NodePart nodePart : node.parts) {
nodePart.material.set(redAttribute, greenAttribute, blueAttribute);
}
}
break;
}
}
}
}
项目:GdxDemo3D
文件:ModelFactory.java
public static Model buildBillboardModel(Texture texture, float width, float height) {
TextureRegion textureRegion = new TextureRegion(texture, texture.getWidth(), texture.getHeight());
Material material = new Material();
material.set(new TextureAttribute(TextureAttribute.Diffuse, textureRegion));
material.set(new ColorAttribute(ColorAttribute.AmbientLight, Color.WHITE));
material.set(new BlendingAttribute());
return ModelFactory.buildPlaneModel(width, height, material, 0, 0, 1, 1);
}
项目:libgdxcn
文件:BillboardParticleBatch.java
protected Renderable allocRenderable(){
Renderable renderable = new Renderable();
renderable.primitiveType = GL20.GL_TRIANGLES;
renderable.meshPartOffset = 0;
renderable.material = new Material( new BlendingAttribute(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA, 1f),
new DepthTestAttribute(GL20.GL_LEQUAL, false),
TextureAttribute.createDiffuse(texture));
renderable.mesh = new Mesh(false, MAX_VERTICES_PER_MESH, MAX_PARTICLES_PER_MESH*6, currentAttributes);
renderable.mesh.setIndices(indices);
renderable.shader = shader;
return renderable;
}
项目:libgdxcn
文件:BillboardParticleBatch.java
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;
}
项目:libgdxcn
文件:PointSpriteParticleBatch.java
protected void allocRenderable(){
renderable = new Renderable();
renderable.primitiveType = GL20.GL_POINTS;
renderable.meshPartOffset = 0;
renderable.material = new Material( new BlendingAttribute(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA, 1f),
new DepthTestAttribute(GL20.GL_LEQUAL, false),
TextureAttribute.createDiffuse((Texture)null));
}
项目:libgdxcn
文件:TextureRegion3DTest.java
@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)));
}
项目:libgdxcn
文件:MaterialTest.java
@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);
}
项目:libgdxcn
文件:MaterialTest.java
@Override
public boolean touchUp (int screenX, int screenY, int pointer, int button) {
if (!material.has(TextureAttribute.Diffuse))
material.set(textureAttribute);
else if (!material.has(ColorAttribute.Diffuse))
material.set(colorAttribute);
else if (!material.has(BlendingAttribute.Type))
material.set(blendingAttribute);
else
material.clear();
return super.touchUp(screenX, screenY, pointer, button);
}
项目:libgdxcn
文件:BasicShapesTest.java
@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);
}
项目:HelixEngine
文件:TilePermissionsGridDisplayable.java
public TilePermissionsGridDisplayable(Tile[][] tiles, TextureAtlas atlas) {
this.atlas = atlas;
MeshBuilder meshBuilder = new MeshBuilder();
meshBuilder.begin(VertexAttributes.Usage.Position |
VertexAttributes.Usage.TextureCoordinates,
GL20.GL_TRIANGLES);
for (int y = 0; y < tiles.length; y++) {
for (int x = 0; x < tiles[y].length; x++) {
// TODO: Cache regions
meshBuilder.setUVRange(
atlas.findRegion(tiles[y][x].getPermissions().name()));
meshBuilder.rect(x, y, 0,
x + 1, y, 0,
x + 1, y + 1, 0,
x, y + 1, 0,
0, 0, 1);
}
}
Mesh mesh = meshBuilder.end();
ModelBuilder modelBuilder = new ModelBuilder();
modelBuilder.begin();
TextureAttribute diffuse
= TextureAttribute.createDiffuse(atlas.getTextures().first());
modelBuilder.part("grid", mesh, GL20.GL_TRIANGLES, new Material(diffuse));
instance = new ModelInstance(modelBuilder.end());
instance.transform.translate(0, 0, Z_OFFSET);
}
项目:gaiasky
文件:SpacecraftGui.java
/**
* Constructs the interface
*/
public void doneLoading(AssetManager assetManager) {
skin = GlobalResources.skin;
aiTexture = assetManager.get("data/tex/attitudeindicator.png", Texture.class);
aiTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
aiPointerTexture = assetManager.get("img/ai-pointer.png", Texture.class);
aiPointerTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
aiVelTex = assetManager.get("img/ai-vel.png", Texture.class);
aiVelTex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
aiAntivelTex = assetManager.get("img/ai-antivel.png", Texture.class);
aiAntivelTex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
aiVelDec = Decal.newDecal(new TextureRegion(aiVelTex));
aiAntivelDec = Decal.newDecal(new TextureRegion(aiAntivelTex));
Material mat = new Material(new TextureAttribute(TextureAttribute.Diffuse, aiTexture), new ColorAttribute(ColorAttribute.Specular, 0.3f, 0.3f, 0.3f, 1f));
aiModel = new ModelBuilder2().createSphere(1 * GlobalConf.SCALE_FACTOR, 30, 30, false, mat, Usage.Position | Usage.Normal | Usage.TextureCoordinates);
aiTransform = new Matrix4();
aiModelInstance = new ModelInstance(aiModel, aiTransform);
aiViewport = new ExtendViewport(indicatorw, indicatorh, aiCam);
buildGui();
EventManager.instance.subscribe(this, Events.SPACECRAFT_STABILISE_CMD, Events.SPACECRAFT_STOP_CMD, Events.SPACECRAFT_INFO, Events.SPACECRAFT_NEAREST_INFO, Events.SPACECRAFT_THRUST_INFO);
EventManager.instance.unsubscribe(this, Events.SPACECRAFT_LOADED);
}
项目:gaiasky
文件:StarGroup.java
private static void initModel() {
if (mc == null) {
Texture tex = new Texture(Gdx.files.internal(GlobalConf.TEXTURES_FOLDER + "star.jpg"));
Texture lut = new Texture(Gdx.files.internal(GlobalConf.TEXTURES_FOLDER + "lut.jpg"));
tex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
Map<String, Object> params = new TreeMap<String, Object>();
params.put("quality", 120l);
params.put("diameter", 1d);
params.put("flip", false);
Pair<Model, Map<String, Material>> pair = ModelCache.cache.getModel("sphere", params, Usage.Position | Usage.Normal | Usage.TextureCoordinates);
Model model = pair.getFirst();
Material mat = pair.getSecond().get("base");
mat.clear();
mat.set(new TextureAttribute(TextureAttribute.Diffuse, tex));
mat.set(new TextureAttribute(TextureAttribute.Normal, lut));
// Only to activate view vector (camera position)
mat.set(new TextureAttribute(TextureAttribute.Specular, lut));
mat.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));
modelTransform = new Matrix4();
mc = new ModelComponent(false);
mc.env = new Environment();
mc.env.set(new ColorAttribute(ColorAttribute.AmbientLight, 1f, 1f, 1f, 1f));
mc.env.set(new FloatAttribute(FloatAttribute.Shininess, 0f));
mc.instance = new ModelInstance(model, modelTransform);
}
}
项目:gaiasky
文件:Star.java
public static void initModel() {
if (mc == null) {
Texture tex = new Texture(Gdx.files.internal(GlobalConf.TEXTURES_FOLDER + "star.jpg"));
Texture lut = new Texture(Gdx.files.internal(GlobalConf.TEXTURES_FOLDER + "lut.jpg"));
tex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
Map<String, Object> params = new TreeMap<String, Object>();
params.put("quality", 120l);
params.put("diameter", 1d);
params.put("flip", false);
Pair<Model, Map<String, Material>> pair = ModelCache.cache.getModel("sphere", params, Usage.Position | Usage.Normal | Usage.TextureCoordinates);
Model model = pair.getFirst();
Material mat = pair.getSecond().get("base");
mat.clear();
mat.set(new TextureAttribute(TextureAttribute.Diffuse, tex));
mat.set(new TextureAttribute(TextureAttribute.Normal, lut));
// Only to activate view vector (camera position)
mat.set(new TextureAttribute(TextureAttribute.Specular, lut));
mat.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));
modelTransform = new Matrix4();
mc = new ModelComponent(false);
mc.env = new Environment();
mc.env.set(new ColorAttribute(ColorAttribute.AmbientLight, 1f, 1f, 1f, 1f));
mc.env.set(new FloatAttribute(FloatAttribute.Shininess, 0f));
mc.instance = new ModelInstance(model, modelTransform);
}
}
项目:BotLogic
文件:Map.java
public Map(FileHandle handle) {
this.tileset = new TextureAtlas(Gdx.files.internal("tileset.atlas"));
this.floorEndRegion = this.tileset.findRegion("floor_end");
TextureAttribute textureAttribute = TextureAttribute.createDiffuse(this.tileset.getTextures().first());
this.material = new Material(textureAttribute);
this.primitiveType = GL20.GL_TRIANGLES;
this.robotStartPosition = new Vector3(0, 1.6f, 0);
parse(handle);
build();
}
项目:Vloxlands
文件:World.java
public World(int width, int depth) {
this.width = width;
this.depth = depth;
islands = new Island[width * depth];
highlight = new Material(TextureAttribute.createDiffuse(Vloxlands.assets.get("img/transparent.png", Texture.class)), ColorAttribute.createDiffuse(SELECTION));
dataMaps = new Material[Config.dataMaps.length][2];
for (int i = 0; i < dataMaps.length; i++) {
Material trp = new Material(TextureAttribute.createDiffuse(Vloxlands.assets.get("img/datamaps/" + Config.dataMaps[i].toLowerCase() + ".png", Texture.class)), new BlendingAttribute());
Material opq = Config.dataMapFullBlending[i] ? trp : new Material(TextureAttribute.createDiffuse(Vloxlands.assets.get("img/datamaps/" + Config.dataMaps[i].toLowerCase() + ".png", Texture.class)));
dataMaps[i] = new Material[] { opq, trp };
}
}
项目:gdx-proto
文件:HeightMapModel.java
public HeightMapModel(HeightMap hm) {
this.heightMap = hm;
String groundTexName = "textures/hm_paint.png";
groundTexture = new Texture(Gdx.files.internal(groundTexName), true);
groundTexture.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
groundTexture.setFilter(Texture.TextureFilter.MipMapLinearNearest, Texture.TextureFilter.Linear);
groundMat = new Material(TextureAttribute.createDiffuse(groundTexture)
, ColorAttribute.createSpecular(specular)
);
createGround();
}
项目:gdx-proto
文件:Box.java
/** create some boxes to fill the level with some test geometry */
public static void createBoxes(int count) {
ModelBuilder main = new ModelBuilder();
ModelBuilder mb = new ModelBuilder();
Material material = new Material();
if (Main.isClient()) {
material.set(TextureAttribute.createDiffuse(Assets.manager.get("textures/marble.jpg", Texture.class)));
}
main.begin();
//float x = GameWorld.WORLD_WIDTH;
//float y = GameWorld.WORLD_DEPTH;
for (int i = 0; i < count; i++) {
//float w = MathUtils.random(minW, maxW);
float w = 8f;
float d = 8f;
float h = (i+1)*5f;
tmp.set(10f + (w+2) * i, 0f, 10f + (d+2) * i);
if (Main.isClient()) {
mb.begin();
MeshPartBuilder mpb = mb.part("part-" + i, GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates, material);
mpb.box(w, h, d);
Model boxModel = mb.end();
Node node = main.node("box-" + i, boxModel);
node.translation.set(tmp);
q.idt();
node.rotation.set(q);
}
//node.translation.set(MathUtils.random(x), 0f, MathUtils.random(y));
//q.set(Vector3.X, -90);
mtx.set(q);
mtx.setTranslation(tmp);
btCollisionObject obj = Physics.inst.createBoxObject(tmp.set(w/2, h/2, d/2));
obj.setWorldTransform(mtx);
Physics.applyStaticGeometryCollisionFlags(obj);
Physics.inst.addStaticGeometryToWorld(obj);
}
Model finalModel = main.end();
instance = new ModelInstance(finalModel);
}