Added accurate planet generation
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
@@ -90,10 +90,7 @@ public abstract class ClientLauncher extends ApplicationCore implements Platform
|
|||||||
assets.load(mods);
|
assets.load(mods);
|
||||||
assets.load(schematics);
|
assets.load(schematics);
|
||||||
|
|
||||||
assets.loadRun("contentinit", ContentLoader.class, () -> {
|
assets.loadRun("contentinit", ContentLoader.class, () -> content.init(), () -> content.load());
|
||||||
content.init();
|
|
||||||
content.load();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -3,12 +3,11 @@ package mindustry.graphics;
|
|||||||
import arc.graphics.*;
|
import arc.graphics.*;
|
||||||
import arc.graphics.VertexAttributes.*;
|
import arc.graphics.VertexAttributes.*;
|
||||||
import arc.graphics.gl.*;
|
import arc.graphics.gl.*;
|
||||||
import arc.math.*;
|
|
||||||
import arc.math.geom.*;
|
import arc.math.geom.*;
|
||||||
import arc.util.ArcAnnotate.*;
|
import arc.util.ArcAnnotate.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import arc.util.noise.*;
|
|
||||||
import mindustry.graphics.PlanetGrid.*;
|
import mindustry.graphics.PlanetGrid.*;
|
||||||
|
import mindustry.maps.planet.*;
|
||||||
|
|
||||||
public class PlanetMesh{
|
public class PlanetMesh{
|
||||||
private float[] floats = new float[3 + 3 + 1];
|
private float[] floats = new float[3 + 3 + 1];
|
||||||
@@ -16,19 +15,12 @@ public class PlanetMesh{
|
|||||||
private Mesh mesh;
|
private Mesh mesh;
|
||||||
private PlanetGrid grid;
|
private PlanetGrid grid;
|
||||||
|
|
||||||
private float color;
|
private boolean lines = false;
|
||||||
private boolean lines;
|
private float radius = 1f, intensity = 0.2f;
|
||||||
private float radius;
|
|
||||||
|
|
||||||
private Simplex sim = new Simplex();
|
private PlanetGenerator gen = new PlanetGenerator();
|
||||||
private RidgedPerlin rid = new RidgedPerlin(2, 2);
|
|
||||||
private Color[] colors = {Color.royal, Color.royal, Color.royal, Color.tan, Color.valueOf("3f9a50"), Color.valueOf("3f9a50"), Color.gray, Color.white, Color.white};
|
|
||||||
private Vec3 normal = new Vec3();
|
|
||||||
|
|
||||||
public PlanetMesh(int divisions, float radius, boolean lines, Color color){
|
public PlanetMesh(int divisions){
|
||||||
this.radius = radius;
|
|
||||||
this.lines = lines;
|
|
||||||
this.color = color.toFloatBits();
|
|
||||||
this.grid = PlanetGrid.newGrid(divisions);
|
this.grid = PlanetGrid.newGrid(divisions);
|
||||||
|
|
||||||
int vertices = grid.tiles.length * 12 * (3 + 3 + 1);
|
int vertices = grid.tiles.length * 12 * (3 + 3 + 1);
|
||||||
@@ -77,7 +69,7 @@ public class PlanetMesh{
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(Corner corner : c){
|
for(Corner corner : c){
|
||||||
corner.v.setLength(radius + elevation(corner.bv));
|
corner.v.setLength(radius + elevation(corner.bv)*intensity);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(Corner corner : c){
|
for(Corner corner : c){
|
||||||
@@ -115,20 +107,15 @@ public class PlanetMesh{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Vec3 normal(Vec3 v1, Vec3 v2, Vec3 v3){
|
private Vec3 normal(Vec3 v1, Vec3 v2, Vec3 v3){
|
||||||
return normal.set(v2).sub(v1).crs(v3.x - v1.x, v3.y - v1.y, v3.z - v1.z).nor();
|
return Tmp.v32.set(v2).sub(v1).crs(v3.x - v1.x, v3.y - v1.y, v3.z - v1.z).nor();
|
||||||
}
|
}
|
||||||
|
|
||||||
private float elevation(Vec3 v){
|
private float elevation(Vec3 v){
|
||||||
if(lines) return 0;
|
return gen.getHeight(v);
|
||||||
|
|
||||||
Color c = color(v);
|
|
||||||
if(c == Color.royal) return 0.19f;
|
|
||||||
return ((float)sim.octaveNoise3D(8, 0.7, 1 / 2.0, v.x, v.y, v.z)) / 3f + (rid.getValue(v.x, v.y, v.z, 1f) + 1f) / 12f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Color color(Vec3 v){
|
private Color color(Vec3 v){
|
||||||
float f = ((float)sim.octaveNoise3D(6, 0.6, 1 / 2.0, v.x, v.y, v.z)) * 0.5f + 0.5f * ((rid.getValue(v.x, v.y, v.z, 1f) + 1f) / 2f);
|
return gen.getColor(v, elevation(v));
|
||||||
return colors[Mathf.clamp((int)(f * colors.length), 0, colors.length - 1)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verts(Vec3 a, Vec3 b, Vec3 c, Vec3 normal, Color color){
|
private void verts(Vec3 a, Vec3 b, Vec3 c, Vec3 normal, Color color){
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package mindustry.maps.planet;
|
||||||
|
|
||||||
|
import arc.graphics.*;
|
||||||
|
import arc.math.*;
|
||||||
|
import arc.math.geom.*;
|
||||||
|
import arc.util.*;
|
||||||
|
import arc.util.noise.*;
|
||||||
|
|
||||||
|
public class PlanetGenerator{
|
||||||
|
Pixmap pix = new Pixmap("planets/colors.png");
|
||||||
|
Simplex noise = new Simplex();
|
||||||
|
int waterLevel = 5;
|
||||||
|
float water = waterLevel / (float)(pix.getHeight());
|
||||||
|
float scl = 5f;
|
||||||
|
|
||||||
|
public float getHeight(Vec3 position){
|
||||||
|
position = Tmp.v33.set(position).scl(scl);
|
||||||
|
|
||||||
|
float height = Mathf.pow((float)noise.octaveNoise3D(7, 0.48f, 1f/3f, position.x, position.y, position.z), 2.4f);
|
||||||
|
if(height <= water){
|
||||||
|
return water;
|
||||||
|
}
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color getColor(Vec3 position, float height){
|
||||||
|
position = Tmp.v33.set(position).scl(scl);
|
||||||
|
float rad = scl;
|
||||||
|
float temp = Mathf.clamp(Math.abs(position.y * 2f) / (rad));
|
||||||
|
float tnoise = (float)noise.octaveNoise3D(7, 0.48f, 1f/3f, position.x, position.y + 999f, position.z);
|
||||||
|
temp = Mathf.lerp(temp, tnoise, 0.5f);
|
||||||
|
height *= 1.2f;
|
||||||
|
height = Mathf.clamp(height);
|
||||||
|
|
||||||
|
return Tmp.c1.set(pix.getPixel((int)(temp * (pix.getWidth()-1)), (int)((1f-height) * (pix.getHeight()-1))));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,23 +2,25 @@ package mindustry.type;
|
|||||||
|
|
||||||
import arc.scene.ui.layout.*;
|
import arc.scene.ui.layout.*;
|
||||||
import arc.util.ArcAnnotate.*;
|
import arc.util.ArcAnnotate.*;
|
||||||
|
import arc.util.*;
|
||||||
import mindustry.ctype.*;
|
import mindustry.ctype.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
|
|
||||||
public class Planet extends UnlockableContent{
|
public class Planet extends UnlockableContent{
|
||||||
/** Mesh used for rendering. */
|
/** Mesh used for rendering. Created on load(). */
|
||||||
public @NonNull PlanetMesh mesh;
|
public PlanetMesh mesh;
|
||||||
/** Grid used for the sectors on the planet. */
|
/** Grid used for the sectors on the planet. */
|
||||||
public @NonNull PlanetGrid grid;
|
public @NonNull PlanetGrid grid;
|
||||||
|
|
||||||
public Planet(String name, PlanetMesh mesh){
|
public Planet(String name){
|
||||||
super(name);
|
super(name);
|
||||||
this.mesh = mesh;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//mods
|
@Override
|
||||||
Planet(String name){
|
public void load(){
|
||||||
super(name);
|
Time.mark();
|
||||||
|
mesh = new PlanetMesh(6);
|
||||||
|
Log.info("Time to generate planet mesh: {0}", Time.elapsed());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Planets cannot be viewed in the database dialog. */
|
/** Planets cannot be viewed in the database dialog. */
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ public class DeployDialog extends FloatingDialog{
|
|||||||
setFilter(TextureFilter.Linear);
|
setFilter(TextureFilter.Linear);
|
||||||
}}){{
|
}}){{
|
||||||
float[] time = {0};
|
float[] time = {0};
|
||||||
setColor(Color.fromGray(0.3f));
|
setColor(Color.gray(0.3f));
|
||||||
setScale(1.5f);
|
setScale(1.5f);
|
||||||
update(() -> {
|
update(() -> {
|
||||||
setOrigin(Align.center);
|
setOrigin(Align.center);
|
||||||
@@ -141,7 +141,7 @@ public class DeployDialog extends FloatingDialog{
|
|||||||
Stack sub = new Stack();
|
Stack sub = new Stack();
|
||||||
|
|
||||||
if(slot.getZone() != null){
|
if(slot.getZone() != null){
|
||||||
sub.add(new Table(f -> f.margin(4f).add(new Image()).color(Color.fromGray(0.1f)).grow()));
|
sub.add(new Table(f -> f.margin(4f).add(new Image()).color(Color.gray(0.1f)).grow()));
|
||||||
|
|
||||||
sub.add(new Table(f -> f.margin(4f).add(new Image(slot.getZone().preview).setScaling(Scaling.fit)).update(img -> {
|
sub.add(new Table(f -> f.margin(4f).add(new Image(slot.getZone().preview).setScaling(Scaling.fit)).update(img -> {
|
||||||
TextureRegionDrawable draw = (TextureRegionDrawable)img.getDrawable();
|
TextureRegionDrawable draw = (TextureRegionDrawable)img.getDrawable();
|
||||||
@@ -255,7 +255,7 @@ public class DeployDialog extends FloatingDialog{
|
|||||||
}
|
}
|
||||||
|
|
||||||
stack.setSize(Tmp.v1.x, Tmp.v1.y);
|
stack.setSize(Tmp.v1.x, Tmp.v1.y);
|
||||||
stack.add(new Table(t -> t.margin(4f).add(new Image(node.zone.preview).setScaling(Scaling.stretch)).color(node.zone.unlocked() ? Color.darkGray : Color.fromGray(0.2f)).grow()));
|
stack.add(new Table(t -> t.margin(4f).add(new Image(node.zone.preview).setScaling(Scaling.stretch)).color(node.zone.unlocked() ? Color.darkGray : Color.gray(0.2f)).grow()));
|
||||||
stack.update(() -> stack.setPosition(node.x + panX + width / 2f, node.y + panY + height / 2f, Align.center));
|
stack.update(() -> stack.setPosition(node.x + panX + width / 2f, node.y + panY + height / 2f, Align.center));
|
||||||
|
|
||||||
Button button = new Button(Styles.squaret);
|
Button button = new Button(Styles.squaret);
|
||||||
|
|||||||
Reference in New Issue
Block a user