2525package de .bluecolored .bluemap .core .map .hires .entity ;
2626
2727import com .flowpowered .math .vector .Vector3f ;
28- import com .flowpowered .math .vector .Vector3i ;
2928import com .flowpowered .math .vector .Vector4f ;
3029import de .bluecolored .bluemap .core .map .TextureGallery ;
3130import de .bluecolored .bluemap .core .map .hires .RenderSettings ;
3938import de .bluecolored .bluemap .core .resources .pack .resourcepack .model .Model ;
4039import de .bluecolored .bluemap .core .resources .pack .resourcepack .texture .Texture ;
4140import de .bluecolored .bluemap .core .util .Direction ;
41+ import de .bluecolored .bluemap .core .util .math .Color ;
4242import de .bluecolored .bluemap .core .util .math .MatrixM4f ;
4343import de .bluecolored .bluemap .core .util .math .VectorM2f ;
4444import de .bluecolored .bluemap .core .util .math .VectorM3f ;
5353public class ResourceModelRenderer implements EntityRenderer {
5454 private static final float SCALE = 1f / 16f ;
5555
56- private final ResourcePack resourcePack ;
57- private final TextureGallery textureGallery ;
58- private final RenderSettings renderSettings ;
56+ final ResourcePack resourcePack ;
57+ final TextureGallery textureGallery ;
58+ final RenderSettings renderSettings ;
5959
6060 private final VectorM3f [] corners = new VectorM3f [8 ];
6161 private final VectorM2f [] rawUvs = new VectorM2f [4 ];
6262 private final VectorM2f [] uvs = new VectorM2f [4 ];
63+ private final Color tintColor = new Color ();
6364
64- private Part part ;
6565 private Model modelResource ;
6666 private TileModelView tileModel ;
6767 private int sunLight , blockLight ;
68+ private TintColorProvider tintProvider ;
6869
6970 @ SuppressWarnings ("unused" )
7071 public ResourceModelRenderer (ResourcePack resourcePack , TextureGallery textureGallery , RenderSettings renderSettings ) {
@@ -78,9 +79,23 @@ public ResourceModelRenderer(ResourcePack resourcePack, TextureGallery textureGa
7879
7980 @ Override
8081 public void render (Entity entity , BlockNeighborhood block , Part part , TileModelView tileModel ) {
81- this .part = part ;
82+ render (
83+ entity ,
84+ block ,
85+ part .getModel ().getResource (resourcePack ::getModel ),
86+ (index , color ) -> color .set (1f , 1f , 1f , 1f , true ),
87+ tileModel
88+ );
89+
90+ // apply transform
91+ if (part .isTransformed ())
92+ tileModel .transform (part .getTransformMatrix ());
93+ }
94+
95+ void render (Entity entity , BlockNeighborhood block , Model model , TintColorProvider tintProvider , TileModelView tileModel ) {
96+ this .modelResource = model ;
8297 this .tileModel = tileModel ;
83- this .modelResource = part . getModel (). getResource ( resourcePack :: getModel ) ;
98+ this .tintProvider = tintProvider ;
8499
85100 // light calculation
86101 LightData blockLightData = block .getLightData ();
@@ -105,10 +120,6 @@ public void render(Entity entity, BlockNeighborhood block, Part part, TileModelV
105120
106121 this .tileModel .initialize (modelStart );
107122
108- // apply model-transform
109- if (part .isTransformed ())
110- this .tileModel .transform (part .getTransformMatrix ());
111-
112123 }
113124
114125 private final MatrixM4f modelElementTransform = new MatrixM4f ();
@@ -152,25 +163,10 @@ private void buildModelElementResource(Element element, TileModelView blockModel
152163 );
153164 }
154165
155- private final VectorM3f faceRotationVector = new VectorM3f (0 , 0 , 0 );
156166 private void createElementFace (Element element , Direction faceDir , VectorM3f c0 , VectorM3f c1 , VectorM3f c2 , VectorM3f c3 ) {
157167 Face face = element .getFaces ().get (faceDir );
158168 if (face == null ) return ;
159169
160- Vector3i faceDirVector = faceDir .toVector ();
161-
162- // calculate faceRotationVector
163- faceRotationVector .set (
164- faceDirVector .getX (),
165- faceDirVector .getY (),
166- faceDirVector .getZ ()
167- );
168- faceRotationVector .rotateAndScale (element .getRotation ().getMatrix ());
169- makeRotationRelative (faceRotationVector );
170-
171- // face culling
172- if (renderSettings .isRenderTopOnly () && faceRotationVector .y < 0.01 ) return ;
173-
174170 // initialize the faces
175171 tileModel .initialize ();
176172 tileModel .add (2 );
@@ -228,9 +224,15 @@ private void createElementFace(Element element, Direction faceDir, VectorM3f c0,
228224 uvs [3 ].x , uvs [3 ].y
229225 );
230226
231- // ####### color
232- tileModel .setColor (face1 , 1f , 1f , 1f );
233- tileModel .setColor (face2 , 1f , 1f , 1f );
227+ // ####### face-tint
228+ if (face .getTintindex () >= 0 ) {
229+ tintProvider .setTintColor (face .getTintindex (), tintColor );
230+ tileModel .setColor (face1 , tintColor .r , tintColor .g , tintColor .b );
231+ tileModel .setColor (face2 , tintColor .r , tintColor .g , tintColor .b );
232+ } else {
233+ tileModel .setColor (face1 , 1f , 1f , 1f );
234+ tileModel .setColor (face2 , 1f , 1f , 1f );
235+ }
234236
235237 // ####### blocklight
236238 int emissiveBlockLight = Math .max (blockLight , element .getLightEmission ());
@@ -247,9 +249,8 @@ private void createElementFace(Element element, Direction faceDir, VectorM3f c0,
247249
248250 }
249251
250- private void makeRotationRelative (VectorM3f direction ){
251- if (part .isTransformed ())
252- direction .rotateAndScale (part .getTransformMatrix ());
252+ interface TintColorProvider {
253+ void setTintColor (int tintIndex , Color target );
253254 }
254255
255256}
0 commit comments