use of net.modificationstation.stationapi.api.util.math.Direction in project StationAPI by ModificationStation.
the class ModelHelper method toQuadLists.
/**
* Converts a mesh into an array of lists of vanilla baked quads.
* Useful for creating vanilla baked models when required for compatibility.
* The array indexes correspond to {@link Direction#getId()} with the
* addition of {@link #NULL_FACE_ID}.
*
* <p>Retrieves sprites from the block texture atlas via {@link SpriteFinder}.
*/
public static List<BakedQuad>[] toQuadLists(Mesh mesh) {
SpriteFinder finder = SpriteFinder.get(StationRenderAPI.getBakedModelManager().getAtlas(Atlases.GAME_ATLAS_TEXTURE));
@SuppressWarnings("unchecked") final ImmutableList.Builder<BakedQuad>[] builders = new ImmutableList.Builder[7];
for (int i = 0; i < 7; i++) {
builders[i] = ImmutableList.builder();
}
if (mesh != null) {
mesh.forEach(q -> {
final int limit = q.material().spriteDepth();
for (int l = 0; l < limit; l++) {
Direction face = q.cullFace();
builders[face == null ? 6 : face.getId()].add(q.toBakedQuad(l, finder.find(q, l), false));
}
});
}
@SuppressWarnings("unchecked") List<BakedQuad>[] result = new List[7];
for (int i = 0; i < 7; i++) {
result[i] = builders[i].build();
}
return result;
}
use of net.modificationstation.stationapi.api.util.math.Direction in project StationAPI by ModificationStation.
the class BakedModelRendererImpl method renderWorld.
@Override
public boolean renderWorld(BlockState state, BakedModel model, BlockView blockView, int x, int y, int z, int textureOverride) {
posAccessor.stationapi$setX(x);
posAccessor.stationapi$setY(y);
posAccessor.stationapi$setZ(z);
long seed = state.getRenderingSeed(pos);
if (!model.isVanillaAdapter()) {
BlockRenderContext context = CONTEXTS.get();
return context.render(blockView, model, state, pos, random, seed);
}
BlockBase block = state.getBlock();
if (textureOverride >= 0)
return true;
Tessellator t = Tessellator.INSTANCE;
StationTessellator fastT = StationTessellator.get(t);
light.initialize(block, blockView, x, y, z, Minecraft.isSmoothLightingEnabled() && model.useAmbientOcclusion());
boolean rendered = false;
ImmutableList<BakedQuad> qs;
BakedQuad q;
float[] qlight = light.light;
for (int quadSet = 0, size = DIRECTIONS.length; quadSet < size; quadSet++) {
Direction face = DIRECTIONS[quadSet];
random.setSeed(seed);
qs = model.getQuads(state, face, random);
if (!qs.isEmpty() && (face == null || block.isSideRendered(blockView, x + face.vector.x, y + face.vector.y, z + face.vector.z, quadSet))) {
rendered = true;
for (int j = 0, quadSize = qs.size(); j < quadSize; j++) {
q = qs.get(j);
light.calculateForQuad(q);
if (q.hasColour()) {
int i = StationRenderAPI.getBlockColours().getColour(state, blockView, pos, q.getColorIndex());
float r = redI2F(i);
float g = greenI2F(i);
float b = blueI2F(i);
if (GameRenderer.anaglyph3d) {
float colourMultiplierGreenTmp = (r * 30F + g * 70F) / 100F, colourMultiplierBlueTmp = (r * 30F + b * 70F) / 100F;
r = (r * 30F + g * 59F + b * 11F) / 100F;
g = colourMultiplierGreenTmp;
b = colourMultiplierBlueTmp;
}
fastT.quad(q.getVertexData(), x, y, z, colourF2I(r * qlight[0], g * qlight[0], b * qlight[0]), colourF2I(r * qlight[1], g * qlight[1], b * qlight[1]), colourF2I(r * qlight[2], g * qlight[2], b * qlight[2]), colourF2I(r * qlight[3], g * qlight[3], b * qlight[3]));
} else
fastT.quad(q.getVertexData(), x, y, z, colourF2I(qlight[0], qlight[0], qlight[0]), colourF2I(qlight[1], qlight[1], qlight[1]), colourF2I(qlight[2], qlight[2], qlight[2]), colourF2I(qlight[3], qlight[3], qlight[3]));
}
}
}
return rendered;
}
use of net.modificationstation.stationapi.api.util.math.Direction in project StationAPI by ModificationStation.
the class NormalHelper method computeFaceNormal.
/**
* Computes the face normal of the given quad and saves it in the provided non-null vector.
* If {@link QuadView#nominalFace()} is set will optimize by confirming quad is parallel to that
* face and, if so, use the standard normal for that face direction.
*
* <p>Will work with triangles also. Assumes counter-clockwise winding order, which is the norm.
* Expects convex quads with all points co-planar.
*/
public static void computeFaceNormal(@NotNull Vector3f saveTo, QuadView q) {
final Direction nominalFace = q.nominalFace();
if (GeometryHelper.isQuadParallelToFace(nominalFace, q)) {
Vec3i vec = nominalFace.vector;
saveTo.set(vec.x, vec.y, vec.z);
return;
}
final float x0 = q.x(0);
final float y0 = q.y(0);
final float z0 = q.z(0);
final float x1 = q.x(1);
final float y1 = q.y(1);
final float z1 = q.z(1);
final float x2 = q.x(2);
final float y2 = q.y(2);
final float z2 = q.z(2);
final float x3 = q.x(3);
final float y3 = q.y(3);
final float z3 = q.z(3);
final float dx0 = x2 - x0;
final float dy0 = y2 - y0;
final float dz0 = z2 - z0;
final float dx1 = x3 - x1;
final float dy1 = y3 - y1;
final float dz1 = z3 - z1;
float normX = dy0 * dz1 - dz0 * dy1;
float normY = dz0 * dx1 - dx0 * dz1;
float normZ = dx0 * dy1 - dy0 * dx1;
float l = (float) Math.sqrt(normX * normX + normY * normY + normZ * normZ);
if (l != 0) {
normX /= l;
normY /= l;
normZ /= l;
}
saveTo.set(normX, normY, normZ);
}
Aggregations