Planet cleanup
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package mindustry.content;
|
package mindustry.content;
|
||||||
|
|
||||||
import mindustry.ctype.*;
|
import mindustry.ctype.*;
|
||||||
|
import mindustry.maps.planet.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
|
|
||||||
public class Planets implements ContentList{
|
public class Planets implements ContentList{
|
||||||
@@ -10,7 +11,8 @@ public class Planets implements ContentList{
|
|||||||
@Override
|
@Override
|
||||||
public void load(){
|
public void load(){
|
||||||
starter = new Planet("//TODO"){{
|
starter = new Planet("//TODO"){{
|
||||||
|
detail = 6;
|
||||||
|
generator = new TestPlanetGenerator();
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,9 +18,10 @@ public class PlanetMesh{
|
|||||||
private boolean lines = false;
|
private boolean lines = false;
|
||||||
private float radius = 1f, intensity = 0.2f;
|
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);
|
this.grid = PlanetGrid.newGrid(divisions);
|
||||||
|
|
||||||
int vertices = grid.tiles.length * 12 * (3 + 3 + 1);
|
int vertices = grid.tiles.length * 12 * (3 + 3 + 1);
|
||||||
@@ -115,7 +116,7 @@ public class PlanetMesh{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Color color(Vec3 v){
|
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){
|
private void verts(Vec3 a, Vec3 b, Vec3 c, Vec3 normal, Color color){
|
||||||
|
|||||||
@@ -1,37 +1,9 @@
|
|||||||
package mindustry.maps.planet;
|
package mindustry.maps.planet;
|
||||||
|
|
||||||
import arc.graphics.*;
|
import arc.graphics.*;
|
||||||
import arc.math.*;
|
|
||||||
import arc.math.geom.*;
|
import arc.math.geom.*;
|
||||||
import arc.util.*;
|
|
||||||
import arc.util.noise.*;
|
|
||||||
|
|
||||||
public class PlanetGenerator{
|
public interface PlanetGenerator{
|
||||||
Pixmap pix = new Pixmap("planets/colors.png");
|
float getHeight(Vec3 position);
|
||||||
Simplex noise = new Simplex();
|
Color getColor(Vec3 position);
|
||||||
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))));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
40
core/src/mindustry/maps/planet/TestPlanetGenerator.java
Normal file
40
core/src/mindustry/maps/planet/TestPlanetGenerator.java
Normal 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))));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,15 +2,21 @@ 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.*;
|
||||||
|
import mindustry.maps.planet.*;
|
||||||
|
|
||||||
public class Planet extends UnlockableContent{
|
public class Planet extends UnlockableContent{
|
||||||
/** Mesh used for rendering. Created on load(). */
|
/** Mesh used for rendering. Created on load(). */
|
||||||
public 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;
|
||||||
|
/** 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){
|
public Planet(String name){
|
||||||
super(name);
|
super(name);
|
||||||
@@ -18,9 +24,7 @@ public class Planet extends UnlockableContent{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(){
|
public void load(){
|
||||||
Time.mark();
|
mesh = new PlanetMesh(detail, generator);
|
||||||
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. */
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
org.gradle.daemon=true
|
org.gradle.daemon=true
|
||||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||||
archash=ff62d39e0fa294117a885010b05b2b29412b4024
|
archash=ec97ef07c9e241dbc26ef5b5a83ff87a2e40b11a
|
||||||
|
|||||||
Reference in New Issue
Block a user