@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;
}
java类com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute的实例源码
DepthShader.java 文件源码
项目:libgdxcn
阅读 26
收藏 0
点赞 0
评论 0
FramebufferToTextureTest.java 文件源码
项目:libgdxcn
阅读 29
收藏 0
点赞 0
评论 0
@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();
}
AreaDisplayable.java 文件源码
项目:HelixEngine
阅读 34
收藏 0
点赞 0
评论 0
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);
}
}
Game3d.java 文件源码
项目:GdxStudio
阅读 27
收藏 0
点赞 0
评论 0
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);
}
Terrain.java 文件源码
项目:gdx-proto
阅读 32
收藏 0
点赞 0
评论 0
/**
* 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;
}
ModelManager.java 文件源码
项目:gdx-proto
阅读 31
收藏 0
点赞 0
评论 0
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();
}
Sky.java 文件源码
项目:gdx-proto
阅读 43
收藏 0
点赞 0
评论 0
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;
}
Shadow.java 文件源码
项目:gdx-proto
阅读 27
收藏 0
点赞 0
评论 0
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
);
}
WorldShaderProvider.java 文件源码
项目:Cubes_2
阅读 23
收藏 0
点赞 0
评论 0
@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);
}
Assets.java 文件源码
项目:Cubes_2
阅读 20
收藏 0
点赞 0
评论 0
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;
}
WorldShaderProvider.java 文件源码
项目:Cubes
阅读 25
收藏 0
点赞 0
评论 0
@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);
}
PointSpriteSoftParticleBatch.java 文件源码
项目:nhglib
阅读 32
收藏 0
点赞 0
评论 0
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));
}
NhgModelLoader.java 文件源码
项目:nhglib
阅读 23
收藏 0
点赞 0
评论 0
@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;
}
PBRTextureAttribute.java 文件源码
项目:LibGDX-PBR
阅读 21
收藏 0
点赞 0
评论 0
@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;
}
MaterialWrapper.java 文件源码
项目:Argent
阅读 25
收藏 0
点赞 0
评论 0
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);
}
AttributeTypeAdapter.java 文件源码
项目:Argent
阅读 26
收藏 0
点赞 0
评论 0
@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();
}
AttributeTypeAdapter.java 文件源码
项目:Argent
阅读 27
收藏 0
点赞 0
评论 0
@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;
}
BasicShapesTest.java 文件源码
项目:eamaster
阅读 16
收藏 0
点赞 0
评论 0
@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);
}
Entity.java 文件源码
项目:Radix
阅读 38
收藏 0
点赞 0
评论 0
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);
}
}
EntityModel.java 文件源码
项目:Radix
阅读 34
收藏 0
点赞 0
评论 0
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;
}
GameRenderer.java 文件源码
项目:Radix
阅读 41
收藏 0
点赞 0
评论 0
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);
}
}
ModelShader.java 文件源码
项目:Mundus
阅读 33
收藏 0
点赞 0
评论 0
@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);
}
MaterialAsset.java 文件源码
项目:Mundus
阅读 50
收藏 0
点赞 0
评论 0
/**
* 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;
}
GameScene.java 文件源码
项目:GdxDemo3D
阅读 31
收藏 0
点赞 0
评论 0
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;
}
}
}
}
ModelFactory.java 文件源码
项目:GdxDemo3D
阅读 34
收藏 0
点赞 0
评论 0
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);
}
BillboardParticleBatch.java 文件源码
项目:libgdxcn
阅读 26
收藏 0
点赞 0
评论 0
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;
}
BillboardParticleBatch.java 文件源码
项目:libgdxcn
阅读 23
收藏 0
点赞 0
评论 0
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;
}
PointSpriteParticleBatch.java 文件源码
项目:libgdxcn
阅读 22
收藏 0
点赞 0
评论 0
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));
}
TextureRegion3DTest.java 文件源码
项目:libgdxcn
阅读 17
收藏 0
点赞 0
评论 0
@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)));
}
MaterialTest.java 文件源码
项目:libgdxcn
阅读 23
收藏 0
点赞 0
评论 0
@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);
}