Skip to content

Commit

Permalink
Sector outlines
Browse files Browse the repository at this point in the history
  • Loading branch information
GlennFolker committed Feb 16, 2024
1 parent a0ad38c commit 8e62936
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 28 deletions.
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ configure(allprojects){
}

useJitpack = Boolean.valueOf(mindustryBE)
isDev = project.hasProperty('modDev') && Boolean.valueOf(project.property('modDev') as String)
isDev = project.hasProperty('mod.dev') && Boolean.valueOf(project.property('mod.dev') as String)

localGltfrenzy = {
new File(rootDir.parent, 'glTFrenzy').exists()
Expand Down Expand Up @@ -197,7 +197,6 @@ jar{
}

if(!isDev) exclude '**/**Impl*'

doFirst{
logger.log(LogLevel.LIFECYCLE, "Building ${isDev ? 'developer' : 'user'} artifact.")

Expand Down Expand Up @@ -227,7 +226,7 @@ tasks.register('dex', Jar){
)

// Find `d8`.
def d8 = file("$sdkRoot/build-tools/$androidBuildVersion/d8")
def d8 = file("$sdkRoot/build-tools/$androidBuildVersion/${OS.isWindows ? 'd8.bat' : 'd8'}")
if(!d8.exists()){
throw new GradleException("Android SDK `build-tools;$androidBuildVersion` isn't installed or is corrupted")
}
Expand Down
13 changes: 9 additions & 4 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ if(JavaVersion.current().ordinal() < JavaVersion.VERSION_17.ordinal()){
}

rootProject.name = modArtifact

if(new File(rootDir.parent, 'glTFrenzy').exists()){
logger.log(LogLevel.LIFECYCLE, 'Compiling with local `glTFrenzy`.')
includeBuild '../glTFrenzy'
for(def local : ['glTFrenzy', 'EntityAnno']){
def prop = "local.${local.toLowerCase()}"
if(!hasProperty(prop) || Boolean.valueOf(getProperty(prop) as String)){
def dir = new File(rootDir.parent, local)
if(dir.exists()){
logger.log(LogLevel.LIFECYCLE, "Compiling with local `$local`.")
includeBuild dir
}
}
}
10 changes: 8 additions & 2 deletions src/confictura/content/CPlanets.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public static void load(){
structureOffset = -0.2125f;
structureScale = 0.05f;

sectorColor = monolithLighter;
sectorOffset = -0.15f;
sectorRadius = 0.08f;
sectorInnerRadius = 0.15f;
sectorDistance = 0.275f;

islands = new Island[]{
new Island(0.4f, island(0, 0.35f, -0.55f, 0.45f, monolithMid)){{
offset.set(0f, -0.23f, 0f);
Expand Down Expand Up @@ -86,10 +92,10 @@ private static IslandShaper island(int seed, float dstScale, float depth, float

hex.lowColor.set(Pal.darkerGray)
.lerp(Pal.stoneGray, Interp.pow4In.apply(Simplex.noise3d(seeded + 2, 3f, 0.3f, 5f, x + 31.41f, y + 59.26f, hex.low) / 2f + 0.5f))
.lerp(stroke, Interp.pow3In.apply(Ridged.noise3d(seeded + 3, x, y, hex.low, 1, 8f) / 2f + 0.5f));
.lerp(stroke.r, stroke.g, stroke.b, 0f, Interp.pow3In.apply(Ridged.noise3d(seeded + 3, x, y, hex.low, 1, 8f) / 2f + 0.5f));
hex.highColor.set(Pal.darkerGray)
.lerp(Pal.stoneGray, Interp.pow4In.apply(Simplex.noise3d(seeded + 2, 3f, 0.3f, 5f, x + 31.41f, y + 59.26f, hex.high) / 2f + 0.5f))
.lerp(stroke, Interp.pow3In.apply(Ridged.noise3d(seeded + 3, x, y, hex.high, 1, 8f) / 2f + 0.5f));
.lerp(stroke.r, stroke.g, stroke.b, 0f, Interp.pow3In.apply(Ridged.noise3d(seeded + 3, x, y, hex.high, 1, 8f) / 2f + 0.5f));
};
}
}
11 changes: 11 additions & 0 deletions src/confictura/graphics/g3d/CMeshBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ class Tile{
return end();
}

public static Mesh gridLines(PlanetGrid grid, Color color){
begin(grid.edges.length * 2);
for(var edge : grid.edges){
vert(edge.corners[0].v, nor.setZero(), color);
vert(edge.corners[1].v, nor.setZero(), color);
}

return end();
}

public static Mesh gridDistance(PlanetGrid grid, Color color, float radius){
return gridDistance(grid, new HexMesher(){
@Override
Expand Down Expand Up @@ -227,6 +237,7 @@ private static Mesh end(){
var last = mesh;
var buffer = mesh.getVerticesBuffer();
buffer.limit(buffer.position());
buffer.position(0);

mesh = null;
return last;
Expand Down
20 changes: 3 additions & 17 deletions src/confictura/util/StructUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,9 @@ private StructUtils(){
throw new AssertionError();
}

public static byte[] bytesToInt(int input){
return new byte[]{
(byte)(input >> 24),
(byte)(input >> 16),
(byte)(input >> 8),
(byte)input,
};
}

public static <T> boolean equals(T[] first, T[] second){
int len;
if((len = first.length) != second.length) return false;

for(int i = 0; i < len; i++){
if(!first[i].equals(second[i])) return false;
}
return true;
public static <T, R> R reduce(T[] array, R initial, Func2<T, R, R> reduce){
for(var item : array) initial = reduce.get(item, initial);
return initial;
}

public static <T> int reducei(T[] array, int initial, Reducei<T> reduce){
Expand Down
193 changes: 191 additions & 2 deletions src/confictura/world/planets/PortalPlanet.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import gltfrenzy.model.*;
import mindustry.graphics.*;
import mindustry.graphics.g3d.*;
import mindustry.graphics.g3d.PlanetGrid.*;
import mindustry.type.*;

import static arc.Core.*;
Expand All @@ -29,7 +30,8 @@
public class PortalPlanet extends Planet{
private static final Mat3D mat1 = new Mat3D(), mat2 = new Mat3D();
private static final Quat quat = new Quat();
private static final Vec3 v1 = new Vec3();
private static final Vec3 v1 = new Vec3(), v2 = new Vec3(), v3 = new Vec3();
private static final Intersect intersect = new Intersect();

public Island[] islands = {};
public float forcefieldRadius;
Expand All @@ -40,7 +42,15 @@ public class PortalPlanet extends Planet{
public @Nullable FrameBuffer depthBuffer;

public @Nullable AssetDescriptor<Node> structure;
public float structureOffset, structureScale;
public float structureOffset = 0f, structureScale = 1f;

public Color sectorColor = Color.white;
public float sectorOffset = 0f, sectorRadius = 1f, sectorInnerRadius = 2f, sectorDistance = 1f, sectorFade = 0.05f;

public static final int sectorSides = 8;

protected static final float[] vertices = new float[sectorSides * 3];
protected static final short[] indices = new short[(sectorSides - 2) * 3];

public PortalPlanet(String name, Planet parent, float radius){
super(name, parent, radius, 0);
Expand All @@ -49,6 +59,181 @@ public PortalPlanet(String name, Planet parent, float radius){
forcefieldRadius = radius;
}

static{
for(int i = 0, len = sectorSides - 2; i < len; i++){
int index = i * 3;
indices[index] = 0;
indices[index + 1] = (short)(i + 1);
indices[index + 2] = (short)(i + 2);
}
}

@Override
public void init(){
grid = createSectorGrid();
sectors.ensureCapacity(grid.tiles.length);
for(var tile : grid.tiles) sectors.add(new Sector(this, tile));

sectorApproxRadius = sectors.first().tile.v.dst(sectors.first().tile.corners[0].v);
gridMeshLoader = () -> CMeshBuilder.gridLines(grid, sectorColor);
super.init();
}

public PlanetGrid createSectorGrid(){
var grid = new PlanetGrid(0){};
grid.tiles = new Ptile[9];
grid.edges = new Edge[9 * sectorSides];
grid.corners = new Corner[9 * sectorSides];

float step = 360f / sectorSides, offset = -step / 2f;
for(int i = 0; i < 9; i++){
var tile = grid.tiles[i] = new Ptile(i, sectorSides);
tile.tiles = new Ptile[0];

for(int j = 0; j < sectorSides; j++){
int base = i * sectorSides;

var corner = grid.corners[base + j] = tile.corners[j] = new Corner(base + j);
corner.tiles = new Ptile[]{tile};
corner.edges = new Edge[2];

var edge = grid.edges[base + j] = tile.edges[j] = new Edge(base + j);
edge.tiles = new Ptile[]{tile};
}

for(int j = 0; j < sectorSides; j++){
var corner = tile.corners[j];
var edge = tile.edges[j];

corner.corners = new Corner[]{
tile.corners[Mathf.mod(j - 1, sectorSides)],
tile.corners[Mathf.mod(j + 1, sectorSides)]
};
corner.edges = new Edge[]{
tile.edges[Mathf.mod(j - 1, sectorSides)],
edge
};

edge.corners = new Corner[]{
corner,
tile.corners[Mathf.mod(j + 1, sectorSides)]
};
}
}

for(int i = -1; i < 8; i++){
var tile = grid.tiles[i + 1];
if(i == -1){
Tmp.v1.setZero();
}else{
Tmp.v1.trns(-i * 45f, sectorDistance);
}

tile.v.set(Tmp.v1.x, sectorOffset, Tmp.v1.y);
for(int j = 0; j < sectorSides; j++){
Tmp.v2.trns(offset - j * step, i == -1 ? sectorInnerRadius : sectorRadius);
tile.corners[j].v.set(tile.v).add(Tmp.v2.x, 0f, Tmp.v2.y);
}
}

return grid;
}

@Override
public boolean hasGrid(){
return true;
}

// TODO: This is just a workaround so the camera doesn't crash everytime.
@Override
public @Nullable Sector getLastSector(){
return null;
}

@Override
public @Nullable Sector getSector(Ray ray, float radius){
var intersect = intersect(ray, radius);
if(intersect == null) return null;

return sectors.find(t -> t.tile == intersect.intersected);
}

@Override
public @Nullable Intersect intersect(Ray ray, float radius){
for(var tile : grid.tiles){
for(int i = 0; i < sectorSides; i++){
intersect.set(tile.corners[i].v).rotate(Vec3.Y, -getRotation()).add(position);

int index = i * 3;
vertices[index] = intersect.x;
vertices[index + 1] = intersect.y;
vertices[index + 2] = intersect.z;
}

if(Intersector3D.intersectRayTriangles(ray, vertices, indices, 3, intersect)){
intersect.intersected = tile;
return intersect;
}
}
return null;
}

@Override
public void drawBorders(VertexBatch3D batch, Sector sector, Color base, float alpha){
var color = Tmp.c1.set(sectorColor).a((base.a + 0.3f + Mathf.absin(Time.globalTime, 5f, 0.3f)) * alpha);
var fade = Tmp.c2.set(color).a(0f);

var corners = sector.tile.corners;
for(int i = 0; i < corners.length; i++){
Corner curr = corners[i], next = corners[(i + 1) % corners.length];

v1.set(curr.v);
v2.set(next.v);
v3.set(curr.v).sub(0f, sectorFade, 0f);

batch.color(color);
batch.vertex(v1);
batch.color(color);
batch.vertex(v2);
batch.color(fade);
batch.vertex(v3);

batch.color(color);
batch.vertex(v1);
batch.color(fade);
batch.vertex(v3);
batch.color(color);
batch.vertex(v2);

v1.set(next.v);
v2.set(next.v).sub(0f, sectorFade, 0f);
v3.set(curr.v).sub(0f, sectorFade, 0f);

batch.color(color);
batch.vertex(v1);
batch.color(fade);
batch.vertex(v2);
batch.color(fade);
batch.vertex(v3);

batch.color(color);
batch.vertex(v1);
batch.color(fade);
batch.vertex(v3);
batch.color(fade);
batch.vertex(v2);
}

Blending.additive.apply();
batch.flush(Gl.triangles);
Blending.normal.apply();
}

@Override
public void drawSelection(VertexBatch3D batch, Sector sector, Color color, float stroke, float length){

}

@Override
public void load(){
super.load();
Expand Down Expand Up @@ -170,4 +355,8 @@ protected void render(Prov<? extends Shader> shaderProv, Mat3D projection, Mat3D
}
}
}

public static class Intersect extends Vec3{
public Ptile intersected;
}
}

0 comments on commit 8e62936

Please sign in to comment.