Planet cleanup

This commit is contained in:
Anuken 2020-01-18 17:03:03 -05:00
parent 47695f1f8c
commit b2f9b2ef77
6 changed files with 59 additions and 40 deletions

View file

@ -1,6 +1,7 @@
package mindustry.content;
import mindustry.ctype.*;
import mindustry.maps.planet.*;
import mindustry.type.*;
public class Planets implements ContentList{
@ -10,7 +11,8 @@ public class Planets implements ContentList{
@Override
public void load(){
starter = new Planet("//TODO"){{
detail = 6;
generator = new TestPlanetGenerator();
}};
}
}

View file

@ -18,9 +18,10 @@ public class PlanetMesh{
private boolean lines = false;
private float radius = 1f, intensity = 0.2f;
private PlanetGenerator gen = new PlanetGenerator();
private final PlanetGenerator gen;
public PlanetMesh(int divisions){
public PlanetMesh(int divisions, PlanetGenerator gen){
this.gen = gen;
this.grid = PlanetGrid.newGrid(divisions);
int vertices = grid.tiles.length * 12 * (3 + 3 + 1);
@ -115,7 +116,7 @@ public class PlanetMesh{
}
private Color color(Vec3 v){
return gen.getColor(v, elevation(v));
return gen.getColor(v);
}
private void verts(Vec3 a, Vec3 b, Vec3 c, Vec3 normal, Color color){

View file

@ -1,37 +1,9 @@
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))));
}
public interface PlanetGenerator{
float getHeight(Vec3 position);
Color getColor(Vec3 position);
}

View file

@ -0,0 +1,40 @@
package mindustry.maps.planet;
import arc.graphics.*;
import arc.math.*;
import arc.math.geom.*;
import arc.util.*;
import arc.util.noise.*;
public class TestPlanetGenerator implements PlanetGenerator{
Pixmap pix = new Pixmap("planets/colors.png");
Simplex noise = new Simplex();
int waterLevel = 5;
float water = waterLevel / (float)(pix.getHeight());
float scl = 5f;
@Override
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;
}
@Override
public Color getColor(Vec3 position){
float height = getHeight(position);
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))));
}
}

View file

@ -2,15 +2,21 @@ package mindustry.type;
import arc.scene.ui.layout.*;
import arc.util.ArcAnnotate.*;
import arc.util.*;
import mindustry.ctype.*;
import mindustry.graphics.*;
import mindustry.maps.planet.*;
public class Planet extends UnlockableContent{
/** Mesh used for rendering. Created on load(). */
public PlanetMesh mesh;
/** Grid used for the sectors on the planet. */
public @NonNull PlanetGrid grid;
/** Generator that will make the planet. */
public @NonNull PlanetGenerator generator;
/** Detail in divisions. Must be between 1 and 10. 6 is a good number.*/
public int detail = 3;
/** Size in terms of divisions. This only controls the amount of sectors on the planet, not the visuals. */
public int size = 3;
public Planet(String name){
super(name);
@ -18,9 +24,7 @@ public class Planet extends UnlockableContent{
@Override
public void load(){
Time.mark();
mesh = new PlanetMesh(6);
Log.info("Time to generate planet mesh: {0}", Time.elapsed());
mesh = new PlanetMesh(detail, generator);
}
/** Planets cannot be viewed in the database dialog. */

View file

@ -1,3 +1,3 @@
org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=ff62d39e0fa294117a885010b05b2b29412b4024
archash=ec97ef07c9e241dbc26ef5b5a83ff87a2e40b11a