mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-03-15 11:20:39 -07:00
Asteroid progress
This commit is contained in:
parent
1eebb48baa
commit
c4b1bf3e55
12 changed files with 102 additions and 46 deletions
Binary file not shown.
|
Before Width: | Height: | Size: 228 B After Width: | Height: | Size: 193 B |
|
|
@ -1,8 +1,10 @@
|
|||
package mindustry.content;
|
||||
|
||||
import arc.graphics.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.noise.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.graphics.*;
|
||||
|
|
@ -85,18 +87,18 @@ public class Planets implements ContentList{
|
|||
}
|
||||
};
|
||||
|
||||
meshLoader = () -> new HexMesh(this, new HexMesher(){
|
||||
Simplex sim = new Simplex(id);
|
||||
@Override
|
||||
public float getHeight(Vec3 position){
|
||||
return (float)sim.octaveNoise3D(2, 0.55, 0.45f, 5f + position.x, 5f + position.y, 5f + position.z) * 14f;
|
||||
meshLoader = () -> {
|
||||
Seq<GenericMesh> meshes = new Seq<>();
|
||||
|
||||
meshes.add(new NoiseMesh(this, 0, 2, Pal.gray, radius, 2, 0.55f, 0.45f, 14f));
|
||||
int am = Mathf.random(3, 6);
|
||||
|
||||
for(int j = 0; j < am; j++){
|
||||
meshes.add(new MatMesh(new NoiseMesh(this, j + 1, 1, Pal.gray, 0.025f + Mathf.random(0.046f), 2, 0.6f, 0.38f, 20f), new Mat3D().setToTranslation(Tmp.v31.setToRandomDirection().setLength(Mathf.random(0.3f, 1.3f)))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColor(Vec3 position){
|
||||
return Pal.gray;
|
||||
}
|
||||
}, 2, Shaders.planet);
|
||||
return new MultiMesh(meshes.toArray(GenericMesh.class));
|
||||
};
|
||||
}};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -151,11 +151,6 @@ public class ContentLoader{
|
|||
ColorMapper.load();
|
||||
}
|
||||
|
||||
public void dispose(){
|
||||
initialize(Content::dispose);
|
||||
clear();
|
||||
}
|
||||
|
||||
/** Get last piece of content created for error-handling purposes. */
|
||||
public @Nullable Content getLastAdded(){
|
||||
return lastAdded;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import mindustry.*;
|
|||
import mindustry.mod.Mods.*;
|
||||
|
||||
/** Base class for a content type that is loaded in {@link mindustry.core.ContentLoader}. */
|
||||
public abstract class Content implements Comparable<Content>, Disposable{
|
||||
public abstract class Content implements Comparable<Content>{
|
||||
public short id;
|
||||
/** Info on which mod this content was loaded from. */
|
||||
public ModContentInfo minfo = new ModContentInfo();
|
||||
|
|
@ -39,11 +39,6 @@ public abstract class Content implements Comparable<Content>, Disposable{
|
|||
return minfo.error != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose(){
|
||||
//does nothing by default
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Content c){
|
||||
return Integer.compare(id, c.id);
|
||||
|
|
|
|||
7
core/src/mindustry/graphics/g3d/GenericMesh.java
Normal file
7
core/src/mindustry/graphics/g3d/GenericMesh.java
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package mindustry.graphics.g3d;
|
||||
|
||||
import arc.math.geom.*;
|
||||
|
||||
public interface GenericMesh{
|
||||
void render(Mat3D projection, Mat3D transform);
|
||||
}
|
||||
|
|
@ -15,6 +15,9 @@ public class HexMesh extends PlanetMesh{
|
|||
super(planet, MeshBuilder.buildHex(mesher, divisions, false, planet.radius, 0.2f), shader);
|
||||
}
|
||||
|
||||
public HexMesh(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preRender(){
|
||||
Shaders.planet.lightDir.set(planet.solarSystem.position).sub(planet.position).rotate(Vec3.Y, planet.getRotation()).nor();
|
||||
|
|
|
|||
22
core/src/mindustry/graphics/g3d/MatMesh.java
Normal file
22
core/src/mindustry/graphics/g3d/MatMesh.java
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package mindustry.graphics.g3d;
|
||||
|
||||
import arc.math.geom.*;
|
||||
|
||||
//TODO maybe this is a bad idea
|
||||
/** A GenericMesh that wraps and applies an additional transform to a generic mesh. */
|
||||
public class MatMesh implements GenericMesh{
|
||||
private static final Mat3D tmp = new Mat3D();
|
||||
|
||||
GenericMesh mesh;
|
||||
Mat3D mat;
|
||||
|
||||
public MatMesh(GenericMesh mesh, Mat3D mat){
|
||||
this.mesh = mesh;
|
||||
this.mat = mat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Mat3D projection, Mat3D transform){
|
||||
mesh.render(projection, tmp.set(transform).mul(mat));
|
||||
}
|
||||
}
|
||||
18
core/src/mindustry/graphics/g3d/MultiMesh.java
Normal file
18
core/src/mindustry/graphics/g3d/MultiMesh.java
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package mindustry.graphics.g3d;
|
||||
|
||||
import arc.math.geom.*;
|
||||
|
||||
public class MultiMesh implements GenericMesh{
|
||||
GenericMesh[] meshes;
|
||||
|
||||
public MultiMesh(GenericMesh... meshes){
|
||||
this.meshes = meshes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Mat3D projection, Mat3D transform){
|
||||
for(var v : meshes){
|
||||
v.render(projection, transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
28
core/src/mindustry/graphics/g3d/NoiseMesh.java
Normal file
28
core/src/mindustry/graphics/g3d/NoiseMesh.java
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package mindustry.graphics.g3d;
|
||||
|
||||
import arc.graphics.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.noise.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
public class NoiseMesh extends HexMesh{
|
||||
Simplex sim;
|
||||
|
||||
public NoiseMesh(Planet planet, int seed, int divisions, Color color, float radius, int octaves, float persistence, float scale, float mag){
|
||||
this.planet = planet;
|
||||
this.sim = new Simplex(planet.id + seed);
|
||||
this.shader = Shaders.planet;
|
||||
this.mesh = MeshBuilder.buildHex(new HexMesher(){
|
||||
@Override
|
||||
public float getHeight(Vec3 position){
|
||||
return (float)sim.octaveNoise3D(octaves, persistence, scale, 5f + position.x, 5f + position.y, 5f + position.z) * mag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColor(Vec3 position){
|
||||
return color;
|
||||
}
|
||||
}, divisions, false, radius, 0.2f);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,14 +3,13 @@ package mindustry.graphics.g3d;
|
|||
import arc.graphics.*;
|
||||
import arc.graphics.gl.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
/** Defines a mesh that is rendered for a planet. Subclasses provide a mesh and a shader. */
|
||||
public abstract class PlanetMesh implements Disposable{
|
||||
protected final Mesh mesh;
|
||||
protected final Planet planet;
|
||||
protected final Shader shader;
|
||||
public abstract class PlanetMesh implements GenericMesh{
|
||||
protected Mesh mesh;
|
||||
protected Planet planet;
|
||||
protected Shader shader;
|
||||
|
||||
public PlanetMesh(Planet planet, Mesh mesh, Shader shader){
|
||||
this.planet = planet;
|
||||
|
|
@ -18,9 +17,12 @@ public abstract class PlanetMesh implements Disposable{
|
|||
this.shader = shader;
|
||||
}
|
||||
|
||||
public PlanetMesh(){}
|
||||
|
||||
/** Should be overridden to set up any shader parameters such as planet position, normals, etc. */
|
||||
public abstract void preRender();
|
||||
|
||||
@Override
|
||||
public void render(Mat3D projection, Mat3D transform){
|
||||
preRender();
|
||||
shader.bind();
|
||||
|
|
@ -29,9 +31,4 @@ public abstract class PlanetMesh implements Disposable{
|
|||
shader.apply();
|
||||
mesh.render(shader, Gl.triangles);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose(){
|
||||
mesh.dispose();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -173,8 +173,8 @@ public class PlanetRenderer implements Disposable{
|
|||
}
|
||||
|
||||
batch.proj(cam.combined);
|
||||
renderOrbit(planet);
|
||||
|
||||
renderOrbit(planet);
|
||||
}
|
||||
|
||||
public void renderOrbit(Planet planet){
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public class Planet extends UnlockableContent{
|
|||
/** intersect() temp var. */
|
||||
private static final Vec3 intersectResult = new Vec3();
|
||||
/** Mesh used for rendering. Created on load() - will be null on the server! */
|
||||
public @Nullable PlanetMesh mesh;
|
||||
public @Nullable GenericMesh mesh;
|
||||
/** Position in global coordinates. Will be 0,0,0 until the Universe updates it. */
|
||||
public Vec3 position = new Vec3();
|
||||
/** Grid used for the sectors on the planet. Null if this planet can't be landed on. */
|
||||
|
|
@ -76,7 +76,7 @@ public class Planet extends UnlockableContent{
|
|||
/** Satellites orbiting this planet. */
|
||||
public Seq<Satellite> satellites = new Seq<>();
|
||||
/** Loads the mesh. Clientside only. Defaults to a boring sphere mesh. */
|
||||
protected Prov<PlanetMesh> meshLoader = () -> new ShaderSphereMesh(this, Shaders.unlit, 2);
|
||||
protected Prov<GenericMesh> meshLoader = () -> new ShaderSphereMesh(this, Shaders.unlit, 2);
|
||||
|
||||
public Planet(String name, Planet parent, float radius){
|
||||
super(name);
|
||||
|
|
@ -217,9 +217,6 @@ public class Planet extends UnlockableContent{
|
|||
|
||||
/** Regenerates the planet mesh. For debugging only. */
|
||||
public void reloadMesh(){
|
||||
if(mesh != null){
|
||||
mesh.dispose();
|
||||
}
|
||||
mesh = meshLoader.get();
|
||||
}
|
||||
|
||||
|
|
@ -249,14 +246,6 @@ public class Planet extends UnlockableContent{
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose(){
|
||||
if(mesh != null){
|
||||
mesh.dispose();
|
||||
mesh = null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets a sector a tile position. */
|
||||
public Sector getSector(Ptile tile){
|
||||
return sectors.get(tile.id);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue