Outline changes

This commit is contained in:
Anuken
2020-09-18 21:14:04 -04:00
parent 8dd1c5f1f8
commit aae045b5dd
14 changed files with 8440 additions and 7579 deletions

View File

@ -2,6 +2,7 @@ package mindustry.tools;
import arc.*;
import arc.files.*;
import arc.func.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
@ -312,23 +313,36 @@ public class Generators{
type.load();
type.init();
//TODO decide whether to keep weapon outlines or not
if(true)
for(Weapon weapon : type.weapons){
if(weapon.rotate && outlined.add(weapon.name) && ImagePacker.has(weapon.name)){
ImagePacker.get(weapon.name).outline(4, Pal.darkerMetal).save(weapon.name);
Color outc = Pal.darkerMetal;
//Func<Image, Image> outlineS = i -> i.shadow(0.8f, 9);
Func<Image, Image> outline = i -> i.outline(4, outc);
Cons<TextureRegion> outliner = t -> {
if(t != null && t.found()){
ImagePacker.replace(t, outline.get(ImagePacker.get(t)));
}
};
((GenRegion)Core.atlas.find(weapon.name)).path.delete();
for(Weapon weapon : type.weapons){
if(outlined.add(weapon.name) && ImagePacker.has(weapon.name)){
outline.get(ImagePacker.get(weapon.name)).save(weapon.name + "-outline");
//old outline
//ImagePacker.get(weapon.name).outline(4, Pal.darkerMetal).save(weapon.name);
}
}
Image image = ImagePacker.get(type.parts > 0 ? type.partRegions[0] : type.region);
for(int i = 1; i < type.parts; i++){
image.draw(ImagePacker.get(type.partRegions[i]));
}
if(type.parts > 0){
image.save(type.name);
}
//baseRegion, legRegion, region, shadowRegion, cellRegion,
// occlusionRegion, jointRegion, footRegion, legBaseRegion, baseJointRegion, outlineRegion;
outliner.get(type.jointRegion);
outliner.get(type.footRegion);
outliner.get(type.legBaseRegion);
outliner.get(type.baseJointRegion);
Image image = ImagePacker.get(type.region);
outline.get(image).save(type.name + "-outline");
//ImagePacker.replace(type.region, outline.get(image));
if(type.constructor.get() instanceof Mechc){
image.drawCenter(type.baseRegion);
@ -337,15 +351,7 @@ public class Generators{
image.draw(type.region);
}
Image baseCell = ImagePacker.get(type.parts > 0 ? type.partCellRegions[0] : type.cellRegion);
for(int i = 1; i < type.parts; i++){
baseCell.draw(ImagePacker.get(type.partCellRegions[i]));
}
if(type.parts > 0){
image.save(type.name + "-cell");
}
Image baseCell = ImagePacker.get(type.cellRegion);
Image cell = new Image(type.cellRegion.width, type.cellRegion.height);
cell.each((x, y) -> cell.draw(x, y, baseCell.getColor(x, y).mul(Color.valueOf("ffa665"))));

View File

@ -4,6 +4,7 @@ import arc.func.*;
import arc.graphics.Color;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import arc.struct.*;
import arc.util.*;
import mindustry.tools.ImagePacker.*;
@ -88,6 +89,49 @@ class Image{
return out;
}
Image shadow(float alpha, int rad){
Image out = silhouette(new Color(0f, 0f, 0f, alpha)).blur(rad);
out.draw(this);
return out;
}
Image silhouette(Color color){
Image out = copy();
each((x, y) -> out.draw(x, y, getColor(x, y).set(color.r, color.g, color.b, this.color.a * color.a)));
return out;
}
Image blur(int radius){
Image out = copy();
Color c = new Color();
int[] sum = {0};
for(int x = 0; x < out.width; x++){
for(int y = 0; y < out.height; y++){
sum[0] = 0;
Geometry.circle(x, y, radius, (cx, cy) -> {
int rx = Mathf.clamp(cx, 0, out.width - 1), ry = Mathf.clamp(cy, 0, out.height - 1);
Color other = getColor(rx, ry);
c.r += other.r;
c.g += other.g;
c.b += other.b;
c.a += other.a;
sum[0] ++;
});
c.mula(1f / sum[0]);
out.draw(x, y, c);
}
}
return out;
}
void each(Intc2 cons){
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){

View File

@ -163,6 +163,15 @@ public class ImagePacker{
return new Image(imageCache.get(((AtlasRegion)region).name));
}
static void replace(String name, Image image){
image.save(name);
((GenRegion)Core.atlas.find(name)).path.delete();
}
static void replace(TextureRegion region, Image image){
replace(((GenRegion)region).name, image);
}
static void err(String message, Object... args){
throw new IllegalArgumentException(Strings.format(message, args));
}