use of gg.moonflower.pollen.pinwheel.api.client.geometry.GeometryModel in project pollen by MoonflowerTeam.
the class AnimatedGeometryEntityModel method setupAnim.
@Override
public void setupAnim(T entity, float limbSwing, float limbSwingAmount, float animationTicks, float netHeadYaw, float headPitch) {
GeometryModel model = this.getModel();
model.resetTransformation();
if (model instanceof AnimatedModel && this.animations.length > 0) {
ProfilerFiller profiler = Minecraft.getInstance().getProfiler();
profiler.push("createMolangRuntime");
MolangRuntime.Builder builder = this.createRuntime(entity, limbSwing, limbSwingAmount, netHeadYaw, headPitch);
if (entity instanceof MolangVariableProvider)
builder.setVariables((MolangVariableProvider) entity);
if (this.variableProvider != null)
builder.setVariables(this.variableProvider);
profiler.popPush("applyMolangAnimation");
((AnimatedModel) model).applyAnimations(animationTicks / 20F, builder, this.getAnimations());
profiler.pop();
}
}
use of gg.moonflower.pollen.pinwheel.api.client.geometry.GeometryModel in project pollen by MoonflowerTeam.
the class LocalGeometryModelLoader method reload.
@Override
public CompletableFuture<Map<ResourceLocation, GeometryModel>> reload(ResourceManager resourceManager, Executor backgroundExecutor, Executor gameExecutor) {
return CompletableFuture.supplyAsync(() -> {
Map<ResourceLocation, GeometryModel> modelLocations = new HashMap<>();
for (ResourceLocation modelLocation : resourceManager.listResources(FOLDER, name -> name.endsWith(".json"))) {
try (Resource resource = resourceManager.getResource(modelLocation)) {
GeometryModelData[] models = GeometryModelParser.parseModel(IOUtils.toString(resource.getInputStream(), StandardCharsets.UTF_8));
for (GeometryModelData model : models) {
ResourceLocation id = new ResourceLocation(modelLocation.getNamespace(), model.getDescription().getIdentifier());
if (modelLocations.put(id, model.create()) != null)
LOGGER.warn("Duplicate geometry model with id '" + id + "'");
}
} catch (Exception e) {
LOGGER.error("Failed to load geometry file '" + modelLocation.getNamespace() + ":" + modelLocation.getPath().substring(FOLDER.length(), modelLocation.getPath().length() - 5) + "'", e);
}
}
LOGGER.info("Loaded " + modelLocations.size() + " geometry models.");
return modelLocations;
}, backgroundExecutor);
}
use of gg.moonflower.pollen.pinwheel.api.client.geometry.GeometryModel in project pollen by MoonflowerTeam.
the class DeprecatedLocalGeometryModelLoader method reload.
@Override
public CompletableFuture<Map<ResourceLocation, GeometryModel>> reload(ResourceManager resourceManager, Executor backgroundExecutor, Executor gameExecutor) {
return CompletableFuture.supplyAsync(() -> {
Set<ResourceLocation> deprecatedFiles = new HashSet<>();
Map<ResourceLocation, GeometryModel> modelLocations = new HashMap<>();
for (ResourceLocation modelLocation : resourceManager.listResources(FOLDER, name -> name.endsWith(".json"))) {
try (Resource resource = resourceManager.getResource(modelLocation)) {
GeometryModelData[] models = GeometryModelParser.parseModel(IOUtils.toString(resource.getInputStream(), StandardCharsets.UTF_8));
for (GeometryModelData model : models) {
ResourceLocation id = new ResourceLocation(modelLocation.getNamespace(), model.getDescription().getIdentifier());
if (modelLocations.put(id, model.create()) != null)
LOGGER.warn("Duplicate geometry model with id '" + id + "'");
}
deprecatedFiles.add(modelLocation);
} catch (Exception ignored) {
}
}
deprecatedFiles.stream().map(ResourceLocation::getNamespace).forEach(namespace -> LOGGER.error("Mod: " + namespace + " is using deprecated Pollen models. Geometry models should be relocated to 'assets/" + namespace + "/" + LocalGeometryModelLoader.FOLDER.substring(0, LocalGeometryModelLoader.FOLDER.length() - 1) + "'"));
LOGGER.info("Loaded " + modelLocations.size() + " geometry models.");
return modelLocations;
}, backgroundExecutor);
}
use of gg.moonflower.pollen.pinwheel.api.client.geometry.GeometryModel in project pollen by MoonflowerTeam.
the class CosmeticModelLoader method reload.
@Override
public CompletableFuture<Map<ResourceLocation, GeometryModel>> reload(ResourceManager resourceManager, Executor backgroundExecutor, Executor gameExecutor) {
ExecutorService executor = FileCache.createOnlineWorker();
FileCache cache = FileCache.timed(executor, 1, TimeUnit.DAYS);
Map<ResourceLocation, GeometryModel> models = new ConcurrentHashMap<>();
return CompletableFuture.allOf(EntitlementManager.getAllEntitlements().filter(entitlement -> entitlement instanceof ModelEntitlement).flatMap(entitlement -> Arrays.stream(((ModelEntitlement) entitlement).getModelUrls())).distinct().map(url -> loadModel(cache, url).thenAcceptAsync(json -> {
if (json == null)
return;
try {
for (GeometryModelData model : GeometryModelParser.parseModel(json)) {
ResourceLocation id = new ResourceLocation(Pollen.MOD_ID, model.getDescription().getIdentifier());
if (models.put(id, GeometryModel.create(model)) != null)
LOGGER.warn("Duplicate geometry model with id: " + id);
}
} catch (Exception e) {
LOGGER.error("Failed to parse cosmetic model: " + json, e);
}
}, gameExecutor)).toArray(CompletableFuture[]::new)).thenApplyAsync(__ -> {
executor.shutdown();
try {
if (!executor.awaitTermination(10, TimeUnit.SECONDS))
LOGGER.warn("Took more than 10 seconds to terminate online worker");
} catch (Exception e) {
LOGGER.error("Failed to terminate online worker", e);
}
return models;
}, gameExecutor);
}
use of gg.moonflower.pollen.pinwheel.api.client.geometry.GeometryModel in project pollen by MoonflowerTeam.
the class PollenCosmeticLayer method render.
@Override
public void render(PoseStack matrixStack, MultiBufferSource buffer, int packedLight, T entity, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) {
if (GeometryTextureManager.isReloading() || GeometryModelManager.isReloading())
return;
EntitlementManager.getEntitlements(entity.getUUID()).forEach(entitlement -> {
if (entitlement instanceof RenderableCosmetic) {
RenderableCosmetic cosmetic = (RenderableCosmetic) entitlement;
if (!cosmetic.isEnabled())
return;
ResourceLocation modelName = cosmetic.getModelKey();
if (modelName == null)
return;
GeometryModel model = GeometryModelManager.getModel(modelName);
ResourceLocation textureKey = cosmetic.getTextureKey();
if (model == GeometryModel.EMPTY || textureKey == null)
return;
GeometryModelRenderer.copyModelAngles(this.getParentModel(), model);
GeometryModelRenderer.render(model, textureKey, buffer, matrixStack, packedLight, OverlayTexture.NO_OVERLAY, cosmetic.getRed(), cosmetic.getGreen(), cosmetic.getBlue(), cosmetic.getAlpha());
}
});
}
Aggregations