@Override public int compareTo(Attribute o) { if (type != o.type) return type < o.type ? -1 : 1; PbrTextureAttribute other = (PbrTextureAttribute) 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; }
@Override public int compareTo(Attribute o) { if (type != o.type) return type < o.type ? -1 : 1; IBLAttribute other = (IBLAttribute) o; final int c = textureDescription.compareTo(other.textureDescription); if (c != 0) return c; if (uvIndex != other.uvIndex) return uvIndex - other.uvIndex; return 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; }
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); }
@Override public void write(final JsonWriter out, final Material value) throws IOException { if(value == null) { out.nullValue(); return; } out.beginObject(); out.name("id").value(value.id); ArrayList<Attribute> attrList = new ArrayList<>(); value.iterator().forEachRemaining(attrList::add); out.name("attributes").value(JSONSerializer.instance().serialize(attrList)); out.endObject(); }
@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(); }
@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; }
private void addAttributeForm(Attribute attribute, final Material material) { if (attribute instanceof ColorAttribute) { final ColorAttribute colorAttribute = (ColorAttribute) attribute; String type = ColorAttribute.getAttributeAlias(colorAttribute.type); ColorForm.ColorChangeListener colorChangeListener = new ColorForm.ColorChangeListener() { @Override public void onColorChange(float r, float g, float b) { //replace(material, colorAttribute, attribute); listener.onMaterialChange(material); } }; final ColorForm colorAttributeForm = new ColorForm( getSkin(), "ColorAttribute " + type, colorAttribute.color, colorChangeListener, new RemoveTableListener() { @Override public void onRemove(Table table) { material.remove(colorAttribute.type); listener.onMaterialChange(material); removeActor(table); pack(); listener.onMaterialChange(material); } }); add(colorAttributeForm).colspan(2).left().fill(); row(); } pack(); }
private void replace(Material m, Attribute oldAttribute, Attribute newAttribute) { Iterator<Attribute> iterator = m.iterator(); while (iterator.hasNext()) { Attribute next = iterator.next(); if (next.equals(oldAttribute)) { iterator.remove(); } } m.set(newAttribute); }
public GsonMaterial(Material material) { Iterator<Attribute> iterator = material.iterator(); while (iterator.hasNext()) { Attribute next = iterator.next(); if (next instanceof ColorAttribute) { colorAttributes.add((ColorAttribute) next); } } this.id = material.id; }
private void loadSphere(String planetId) { ModelLoader loader = new ObjLoader(); sphereModel = loader.loadModel(Gdx.files.internal("models/sphere01.obj"), new SphereTextureProvider(planetId)); environmentSphere = new ModelInstance(sphereModel); Attribute attribute = environmentSphere.materials.get(0).get( ColorAttribute.getAttributeType(ColorAttribute.DiffuseAlias)); ((ColorAttribute) attribute).color.r = 1; ((ColorAttribute) attribute).color.g = 1; ((ColorAttribute) attribute).color.b = 1; }
protected void bindMaterial (final Renderable renderable) { if (currentMaterial == renderable.material) return; int cullFace = config.defaultCullFace == -1 ? defaultCullFace : config.defaultCullFace; int depthFunc = config.defaultDepthFunc == -1 ? defaultDepthFunc : config.defaultDepthFunc; float depthRangeNear = 0f; float depthRangeFar = 1f; boolean depthMask = true; currentMaterial = renderable.material; for (final Attribute attr : currentMaterial) { final long t = attr.type; if (BlendingAttribute.is(t)) { context.setBlending(true, ((BlendingAttribute)attr).sourceFunction, ((BlendingAttribute)attr).destFunction); set(u_opacity, ((BlendingAttribute)attr).opacity); } else if ((t & IntAttribute.CullFace) == IntAttribute.CullFace) cullFace = ((IntAttribute)attr).value; else if ((t & FloatAttribute.AlphaTest) == FloatAttribute.AlphaTest) set(u_alphaTest, ((FloatAttribute)attr).value); else if ((t & DepthTestAttribute.Type) == DepthTestAttribute.Type) { DepthTestAttribute dta = (DepthTestAttribute)attr; depthFunc = dta.depthFunc; depthRangeNear = dta.depthRangeNear; depthRangeFar = dta.depthRangeFar; depthMask = dta.depthMask; } else if (!config.ignoreUnimplemented) throw new GdxRuntimeException("Unknown material attribute: " + attr.toString()); } context.setCullFace(cullFace); context.setDepthTest(depthFunc, depthRangeNear, depthRangeFar); context.setDepthMask(depthMask); }
protected void bindMaterial(final Renderable renderable) { if (currentMaterial == renderable.material) return; int cullFace = config.defaultCullFace == -1 ? GL20.GL_BACK : config.defaultCullFace; int depthFunc = config.defaultDepthFunc == -1 ? GL20.GL_LEQUAL : config.defaultDepthFunc; float depthRangeNear = 0f; float depthRangeFar = 1f; boolean depthMask = true; currentMaterial = renderable.material; for (final Attribute attr : currentMaterial) { final long t = attr.type; if (BlendingAttribute.is(t)) { context.setBlending(true, ((BlendingAttribute)attr).sourceFunction, ((BlendingAttribute)attr).destFunction); } else if ((t & DepthTestAttribute.Type) == DepthTestAttribute.Type) { DepthTestAttribute dta = (DepthTestAttribute)attr; depthFunc = dta.depthFunc; depthRangeNear = dta.depthRangeNear; depthRangeFar = dta.depthRangeFar; depthMask = dta.depthMask; } else if(!config.ignoreUnimplemented) throw new GdxRuntimeException("Unknown material attribute: "+attr.toString()); } context.setCullFace(cullFace); context.setDepthTest(depthFunc, depthRangeNear, depthRangeFar); context.setDepthMask(depthMask); }
protected void bindMaterial(final Renderable renderable) { if (currentMaterial == renderable.material) return; int cullFace = config.defaultCullFace == -1 ? defaultCullFace : config.defaultCullFace; int depthFunc = config.defaultDepthFunc == -1 ? defaultDepthFunc : config.defaultDepthFunc; float depthRangeNear = 0f; float depthRangeFar = 1f; boolean depthMask = true; currentMaterial = renderable.material; for (final Attribute attr : currentMaterial) { final long t = attr.type; if (BlendingAttribute.is(t)) { context.setBlending(true, ((BlendingAttribute) attr).sourceFunction, ((BlendingAttribute) attr).destFunction); } else if ((t & IntAttribute.CullFace) == IntAttribute.CullFace) cullFace = ((IntAttribute) attr).value; else if ((t & DepthTestAttribute.Type) == DepthTestAttribute.Type) { DepthTestAttribute dta = (DepthTestAttribute) attr; depthFunc = dta.depthFunc; depthRangeNear = dta.depthRangeNear; depthRangeFar = dta.depthRangeFar; depthMask = dta.depthMask; } else if (!config.ignoreUnimplemented) throw new GdxRuntimeException("Unknown material attribute: " + attr.toString()); } context.setCullFace(cullFace); context.setDepthTest(depthFunc, depthRangeNear, depthRangeFar); context.setDepthMask(depthMask); }
@Override public Attribute copy() { return new PbrTextureAttribute(this); }
@Override public Attribute copy() { return new GammaCorrectionAttribute(); }
@Override public int compareTo(Attribute o) { return 0; }
@Override public Attribute copy() { return null; }
@Override public int compareTo(Attribute o) { if (type != o.type) return type < o.type ? -1 : 1; return 0; }
@Override public Attribute copy () { return new PBRTextureAttribute(this); }
@Override public Attribute copy() { return new TerrainTextureAttribute(this); }
@Override public int compareTo(Attribute o) { if (type != o.type) return type < o.type ? -1 : 1; TerrainTexture otherValue = ((TerrainTextureAttribute) o).terrainTexture; return terrainTexture.equals(otherValue) ? 0 : -1; }
@Override public int compareTo(Attribute o) { if (type != o.type) return type < o.type ? -1 : 1; return 0; // FIXME implement comparing }
@Override public int compareTo(Attribute o) { return -1; // FIXME implement comparing }
public MaterialForm(Skin skin, final Material material, String materialId, final MaterialChangeListener listener) { this.listener = listener; final Iterator<Attribute> iterator = material.iterator(); defaults().left().top().pad(4); add(new Label("Material: " + materialId, skin)).left().top().colspan(2); row(); setSkin(skin); final SelectBox<String> attributeSelectBox = new SelectBox<String>(skin); attributeSelectBox.setItems( "diffuseColor", "specularColor", "ambientColor", "emissiveColor", "reflectionColor", "ambientLightColor", "fogColor" ); add(attributeSelectBox); TextButton addButton = new TextButton("add", skin); addButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { String selected = attributeSelectBox.getSelected(); long attributeType = ColorAttribute.getAttributeType(selected); ColorAttribute colorAttribute = new ColorAttribute(attributeType); material.set(colorAttribute); addAttributeForm(colorAttribute, material); listener.onMaterialChange(material); } }); add(addButton); row(); while (iterator.hasNext()) { Attribute attribute = iterator.next(); addAttributeForm(attribute, material); } }
@Override public Attribute copy() { return new WaterAttribute(); }
@Override public Attribute copy() { return new WaterElevationAttribute(height); }
@Override public Attribute copy() { return new SolidTerrainAttribute(); }
@Override public Attribute copy () { return new DepthTestAttribute(this); }
@Override public Attribute copy () { return new FloatAttribute(type, value); }
@Override public Attribute copy () { return new TextureAttribute(this); }
@Override public Attribute copy () { return new ColorAttribute(this); }
@Override public Attribute copy () { return new IntAttribute(type, value); }
@Override public Attribute copy () { return new CubemapAttribute(this); }
@Override public Attribute copy () { return new TestAttribute(value); }
@Override protected boolean equals (Attribute other) { return ((TestAttribute)other).value == value; }