Use floats for model-positions instead of doubles

This commit is contained in:
Lukas Rieger (Blue) 2024-02-09 15:30:23 +01:00
parent 73a77e5e0e
commit cc50e05262
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
3 changed files with 17 additions and 18 deletions

View File

@ -90,12 +90,12 @@ public BlockModelView rotate(float pitch, float yaw, float roll) {
return this; return this;
} }
public BlockModelView scale(double sx, double sy, double sz) { public BlockModelView scale(float sx, float sy, float sz) {
hiresTile.scale(start, size, sx, sy, sz); hiresTile.scale(start, size, sx, sy, sz);
return this; return this;
} }
public BlockModelView translate(double dx, double dy, double dz) { public BlockModelView translate(float dx, float dy, float dz) {
hiresTile.translate(start, size, dx, dy, dz); hiresTile.translate(start, size, dx, dy, dz);
return this; return this;
} }

View File

@ -62,7 +62,7 @@ public class HiresTileModel {
private int capacity; private int capacity;
private int size; private int size;
private double[] position; private float[] position;
private float[] color, uv, ao; private float[] color, uv, ao;
private byte[] sunlight, blocklight; private byte[] sunlight, blocklight;
private int[] materialIndex, materialIndexSort, materialIndexSortSupport; private int[] materialIndex, materialIndexSort, materialIndexSortSupport;
@ -86,9 +86,9 @@ public int add(int count) {
public HiresTileModel setPositions( public HiresTileModel setPositions(
int face, int face,
double x1, double y1, double z1, float x1, float y1, float z1,
double x2, double y2, double z2, float x2, float y2, float z2,
double x3, double y3, double z3 float x3, float y3, float z3
){ ){
int index = face * FI_POSITION; int index = face * FI_POSITION;
@ -247,9 +247,9 @@ public HiresTileModel rotateByQuaternion(
pz = qw * z + qx * y - qy * x; pz = qw * z + qx * y - qy * x;
pw = -qx * x - qy * y - qz * z; pw = -qx * x - qy * y - qz * z;
position[index] = pw * -qx + px * qw - py * qz + pz * qy; position[index] = (float) (pw * -qx + px * qw - py * qz + pz * qy);
position[index + 1] = pw * -qy + py * qw - pz * qx + px * qz; position[index + 1] = (float) (pw * -qy + py * qw - pz * qx + px * qz);
position[index + 2] = pw * -qz + pz * qw - px * qy + py * qx; position[index + 2] = (float) (pw * -qz + pz * qw - px * qy + py * qx);
} }
} }
@ -258,7 +258,7 @@ public HiresTileModel rotateByQuaternion(
public HiresTileModel scale( public HiresTileModel scale(
int start, int count, int start, int count,
double sx, double sy, double sz float sx, float sy, float sz
) { ) {
int end = start + count, index; int end = start + count, index;
for (int face = start; face < end; face++) { for (int face = start; face < end; face++) {
@ -275,7 +275,7 @@ public HiresTileModel scale(
public HiresTileModel translate( public HiresTileModel translate(
int start, int count, int start, int count,
double dx, double dy, double dz float dx, float dy, float dz
) { ) {
int end = start + count, index; int end = start + count, index;
for (int face = start; face < end; face++) { for (int face = start; face < end; face++) {
@ -329,7 +329,7 @@ public HiresTileModel transform(
float m30, float m31, float m32, float m33 float m30, float m31, float m32, float m33
) { ) {
int end = start + count, index; int end = start + count, index;
double x, y, z; float x, y, z;
for (int face = start; face < end; face++) { for (int face = start; face < end; face++) {
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
index = face * FI_POSITION + i * 3; index = face * FI_POSITION + i * 3;
@ -358,7 +358,7 @@ public HiresTileModel clear() {
private void ensureCapacity(int count) { private void ensureCapacity(int count) {
if (size + count > capacity){ if (size + count > capacity){
double[] _position = position; float[] _position = position;
float[] _color = color, _uv = uv, _ao = ao; float[] _color = color, _uv = uv, _ao = ao;
byte[] _sunlight = sunlight, _blocklight = blocklight; byte[] _sunlight = sunlight, _blocklight = blocklight;
int[] _materialIndex = materialIndex; int[] _materialIndex = materialIndex;
@ -381,7 +381,7 @@ private void setCapacity(int capacity) {
this.capacity = capacity; this.capacity = capacity;
// attributes capacity * per-vertex * per-face // attributes capacity * per-vertex * per-face
position = new double [capacity * FI_POSITION]; position = new float [capacity * FI_POSITION];
uv = new float [capacity * FI_UV]; uv = new float [capacity * FI_UV];
ao = new float [capacity * FI_AO]; ao = new float [capacity * FI_AO];
@ -645,7 +645,6 @@ private int compareMaterialIndex(int i1, int i2) {
private void swap(int face1, int face2) { private void swap(int face1, int face2) {
int i, if1, if2, vi; int i, if1, if2, vi;
double vd;
float vf; float vf;
byte vb; byte vb;
@ -653,9 +652,9 @@ private void swap(int face1, int face2) {
if1 = face1 * FI_POSITION; if1 = face1 * FI_POSITION;
if2 = face2 * FI_POSITION; if2 = face2 * FI_POSITION;
for (i = 0; i < FI_POSITION; i++){ for (i = 0; i < FI_POSITION; i++){
vd = position[if1 + i]; vf = position[if1 + i];
position[if1 + i] = position[if2 + i]; position[if1 + i] = position[if2 + i];
position[if2 + i] = vd; position[if2 + i] = vf;
} }
//swap uv //swap uv

View File

@ -259,7 +259,7 @@ private void createElementFace(Element element, Direction faceDir, VectorM3f c0,
// rotate uv's // rotate uv's
if (uvRotation != 0){ if (uvRotation != 0){
uvRotation *= TrigMath.DEG_TO_RAD; uvRotation = (float)(uvRotation * TrigMath.DEG_TO_RAD);
float cx = TrigMath.cos(uvRotation), cy = TrigMath.sin(uvRotation); float cx = TrigMath.cos(uvRotation), cy = TrigMath.sin(uvRotation);
for (VectorM2f uv : uvs) { for (VectorM2f uv : uvs) {
uv.translate(-0.5f, -0.5f); uv.translate(-0.5f, -0.5f);