use of com.loohp.interactivechatdiscordsrvaddon.resources.models.Coordinates3D in project InteractiveChat-DiscordSRV-Addon by LOOHP.
the class ModelRenderer method renderBlockModel.
private void renderBlockModel(Model renderModel, BufferedImage image, ModelDisplay displayData, ModelGUILight lightData, boolean usePlayerPosition) {
AffineTransform baseTransform;
if (usePlayerPosition) {
renderModel.translate(-16 / 2.0, -16 / 2.0, -16 / 2.0);
renderModel.rotate(0, 180, 0, false);
renderModel.translate(16 / 2.0, 16 / 2.0, 16 / 2.0);
baseTransform = AffineTransform.getTranslateInstance(image.getWidth() / 2.0, (double) image.getHeight() / 7 * 5);
baseTransform.concatenate(AffineTransform.getScaleInstance(image.getWidth() / 39.09375, image.getWidth() / 39.09375));
} else {
baseTransform = AffineTransform.getTranslateInstance(image.getWidth() / 2.0, image.getHeight() / 2.0);
baseTransform.concatenate(AffineTransform.getScaleInstance(image.getWidth() / 16.0, image.getHeight() / 16.0));
}
renderModel.translate(-16 / 2.0, -16 / 2.0, -16 / 2.0);
if (displayData != null) {
Coordinates3D scale = displayData.getScale();
renderModel.scale(scale.getX(), scale.getY(), scale.getZ());
Coordinates3D rotation = displayData.getRotation();
renderModel.rotate(rotation.getX(), rotation.getY(), rotation.getZ(), false);
Coordinates3D transform = displayData.getTranslation();
renderModel.translate(transform.getX(), transform.getY(), transform.getZ());
}
renderModel.updateLighting(lightData.getLightVector(), lightData.getAmbientLevel(), lightData.getMaxLevel());
renderModel.render(image, renderModel.getComponents().size() <= QUALITY_THRESHOLD, baseTransform, renderingService).join();
}
use of com.loohp.interactivechatdiscordsrvaddon.resources.models.Coordinates3D in project InteractiveChat-DiscordSRV-Addon by LOOHP.
the class ModelRenderer method renderPlayer.
public RenderResult renderPlayer(int width, int height, ResourceManager manager, boolean post1_8, boolean slim, Map<String, TextureResource> providedTextures, TintIndexData tintIndexData, Map<PlayerModelItemPosition, PlayerModelItem> modelItems) {
String cacheKey = cacheKey(width, height, manager.getUuid(), slim, cacheKeyModelItems(modelItems), cacheKeyProvidedTextures(providedTextures));
Cache<?> cachedRender = Cache.getCache(cacheKey);
if (cachedRender != null) {
RenderResult cachedResult = (RenderResult) cachedRender.getObject();
if (cachedResult.isSuccessful()) {
return cachedResult;
}
}
BlockModel playerModel = manager.getModelManager().resolveBlockModel(slim ? PLAYER_MODEL_SLIM_RESOURCELOCATION : PLAYER_MODEL_RESOURCELOCATION, InteractiveChat.version.isOld(), Collections.emptyMap());
if (playerModel == null) {
return new RenderResult(MODEL_NOT_FOUND, null);
}
Model playerRenderModel = generateStandardRenderModel(playerModel, manager, providedTextures, tintIndexData, false, true);
for (PlayerModelItem playerModelItem : modelItems.values()) {
BlockModel itemBlockModel = playerModelItem.getModelKey() == null ? null : manager.getModelManager().resolveBlockModel(playerModelItem.getModelKey(), InteractiveChat.version.isOld(), playerModelItem.getPredicate());
Model itemRenderModel = null;
if (itemBlockModel != null) {
if (itemBlockModel.getRawParent() == null || !itemBlockModel.getRawParent().contains("/")) {
itemRenderModel = generateStandardRenderModel(itemBlockModel, manager, playerModelItem.getProvidedTextures(), playerModelItem.getTintIndexData(), playerModelItem.isEnchanted(), false);
} else if (itemBlockModel.getRawParent().equals(ModelManager.ITEM_BASE)) {
BufferedImage image = new BufferedImage(INTERNAL_W, INTERNAL_H, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = image.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
for (int i = 0; itemBlockModel.getTextures().containsKey(ModelManager.ITEM_BASE_LAYER + i); i++) {
String resourceLocation = itemBlockModel.getTextures().get(ModelManager.ITEM_BASE_LAYER + i);
if (!resourceLocation.contains(":")) {
resourceLocation = ResourceRegistry.DEFAULT_NAMESPACE + ":" + resourceLocation;
}
TextureResource resource = playerModelItem.getProvidedTextures().get(resourceLocation);
if (resource == null) {
resource = manager.getTextureManager().getTexture(resourceLocation);
}
BufferedImage texture = resource.getTexture();
texture = tintIndexData.applyTint(texture, 1);
if (resource.hasTextureMeta()) {
TextureMeta meta = resource.getTextureMeta();
if (meta.hasProperties()) {
TextureProperties properties = meta.getProperties();
if (properties.isBlur()) {
texture = ImageUtils.applyGaussianBlur(texture);
}
}
if (meta.hasAnimation()) {
TextureAnimation animation = meta.getAnimation();
if (animation.hasWidth() && animation.hasHeight()) {
texture = ImageUtils.copyAndGetSubImage(texture, 0, 0, animation.getWidth(), animation.getHeight());
} else {
texture = ImageUtils.copyAndGetSubImage(texture, 0, 0, texture.getWidth(), texture.getWidth());
}
}
}
if (resourceLocation.equals(ResourceRegistry.MAP_MARKINGS_LOCATION)) {
ImageUtils.xor(image, ImageUtils.resizeImageAbs(texture, image.getWidth(), image.getHeight()), 200);
} else {
g.drawImage(texture, 0, 0, image.getWidth(), image.getHeight(), null);
}
}
g.dispose();
image = tintIndexData.applyTint(image, 0);
if (playerModelItem.isEnchanted()) {
image = enchantmentGlintProvider.apply(image);
}
itemRenderModel = generateItemRenderModel(16, 16, 16, image);
}
}
if (itemRenderModel != null) {
itemRenderModel.translate(-16 / 2.0, -16 / 2.0, -16 / 2.0);
ModelDisplay displayData = itemBlockModel.getRawDisplay().get(playerModelItem.getPosition().getModelDisplayPosition());
boolean flipX = playerModelItem.getPosition().isLiteralFlipped();
boolean isMirror = false;
if (displayData == null && playerModelItem.getPosition().getModelDisplayPosition().hasFallback()) {
displayData = itemBlockModel.getRawDisplay().get(playerModelItem.getPosition().getModelDisplayPosition().getFallback());
isMirror = true;
}
if (isMirror || !flipX) {
if (displayData != null) {
Coordinates3D scale = displayData.getScale();
itemRenderModel.scale(scale.getX(), scale.getY(), scale.getZ());
Coordinates3D rotation = displayData.getRotation();
itemRenderModel.rotate(rotation.getX(), rotation.getY(), rotation.getZ() + (post1_8 ? 10 : 0), false);
Coordinates3D transform = displayData.getTranslation();
itemRenderModel.translate(transform.getX(), transform.getY() + (post1_8 ? -10 : 0), transform.getZ() + (post1_8 ? -2.75 : 0));
}
if (flipX) {
itemRenderModel.flipAboutPlane(false, true, true);
}
} else {
if (displayData != null) {
Coordinates3D scale = displayData.getScale();
itemRenderModel.scale(scale.getX(), scale.getY(), scale.getZ());
Coordinates3D rotation = displayData.getRotation();
itemRenderModel.rotate(rotation.getX(), -rotation.getY(), -rotation.getZ(), false);
Coordinates3D transform = displayData.getTranslation();
itemRenderModel.translate(-transform.getX(), transform.getY(), transform.getZ());
}
}
if (playerModelItem.getPosition().yIsZAxis()) {
if (post1_8) {
itemRenderModel.rotate(180, 180, 0, false);
} else {
itemRenderModel.rotate(90, 0, 0, true);
}
}
double scale = playerModelItem.getPosition().getScale();
itemRenderModel.scale(scale, scale, scale);
itemRenderModel.translate((16 * scale) / 2, (16 * scale) / 2, (16 * scale) / 2);
Coordinates3D defaultTranslation = playerModelItem.getPosition().getDefaultTranslate();
itemRenderModel.translate(defaultTranslation.getX(), defaultTranslation.getY(), defaultTranslation.getZ());
playerRenderModel.append(itemRenderModel);
}
}
playerRenderModel.translate(-16 / 2.0, -16 / 2.0, -16 / 2.0);
playerRenderModel.rotate(0, 180, 0, false);
playerRenderModel.translate(16 / 2.0, 16 / 2.0, 16 / 2.0);
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
renderPlayerModel(playerRenderModel, image, playerModel.getGUILight());
RenderResult result = new RenderResult(image, null);
Cache.putCache(cacheKey, result, cacheTimeoutSupplier.getAsLong());
return result;
}
Aggregations