1616import net .neoforged .neoforge .client .model .IQuadTransformer ;
1717import net .neoforged .neoforge .client .model .data .ModelData ;
1818import org .jetbrains .annotations .Nullable ;
19+ import org .joml .Math ;
1920import org .joml .Vector3f ;
2021
2122public class Outlines {
@@ -51,10 +52,10 @@ public void vertex(float pX, float pY, float pZ) {
5152 vertices [vertexIndex ++] = new Vector3f (pX , pY , pZ );
5253 if (vertexIndex == 4 ) {
5354 vertexIndex = 0 ;
54- lines .add (new Line (vertices [0 ], vertices [1 ]));
55- lines .add (new Line (vertices [1 ], vertices [2 ]));
56- lines .add (new Line (vertices [2 ], vertices [3 ]));
57- lines .add (new Line (vertices [3 ], vertices [0 ]));
55+ lines .add (Line . from (vertices [0 ], vertices [1 ]));
56+ lines .add (Line . from (vertices [1 ], vertices [2 ]));
57+ lines .add (Line . from (vertices [2 ], vertices [3 ]));
58+ lines .add (Line . from (vertices [3 ], vertices [0 ]));
5859 Arrays .fill (vertices , null );
5960 }
6061 }
@@ -74,16 +75,16 @@ public void unpack(BakedQuad pQuad) {
7475
7576 public record Line (float x1 , float y1 , float z1 , float x2 , float y2 , float z2 , float nX , float nY , float nZ , int hash ) {
7677
77- public Line ( float x1 , float y1 , float z1 , float x2 , float y2 , float z2 , float nX , float nY , float nZ ) {
78- this ( x1 , y1 , z1 , x2 , y2 , z2 , nX , nY , nZ , calculateHash ( x1 , y1 , z1 , x2 , y2 , z2 ));
79- }
80-
81- public Line ( Vector3f v1 , Vector3f v2 , Vector3f normal ) {
82- this ( v1 . x , v1 . y , v1 . z , v2 . x , v2 . y , v2 . z , normal . x , normal . y , normal . z );
83- }
84-
85- public Line ( Vector3f v1 , Vector3f v2 ) {
86- this (v1 , v2 , v2 .sub (v1 , new Vector3f ()). normalize ( ));
78+ public static Line from ( Vector3f v1 , Vector3f v2 ) {
79+ // normalise by the distance between the points
80+ float nX = v2 . x - v1 . x ;
81+ float nY = v2 . y - v1 . y ;
82+ float nZ = v2 . z - v1 . z ;
83+ float scalar = Math . invsqrt ( Math . fma ( nX , nX , Math . fma ( nY , nY , nZ * nZ )) );
84+ nX = nX * scalar ;
85+ nY = nY * scalar ;
86+ nZ = nZ * scalar ;
87+ return new Line (v1 . x , v1 . y , v1 . z , v2 . x , v2 .y , v2 . z , nX , nY , nZ , calculateHash (v1 . x , v1 . y , v1 . z , v2 . x , v2 . y , v2 . z ));
8788 }
8889
8990 private static int calculateHash (float x1 , float y1 , float z1 , float x2 , float y2 , float z2 ) {
0 commit comments