Search in sources :

Example 1 with GeometryModel

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();
    }
}
Also used : GeometryModel(gg.moonflower.pollen.pinwheel.api.client.geometry.GeometryModel) MolangRuntime(io.github.ocelot.molangcompiler.api.MolangRuntime) MolangVariableProvider(io.github.ocelot.molangcompiler.api.bridge.MolangVariableProvider) ProfilerFiller(net.minecraft.util.profiling.ProfilerFiller)

Example 2 with GeometryModel

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);
}
Also used : GeometryModel(gg.moonflower.pollen.pinwheel.api.client.geometry.GeometryModel) HashMap(java.util.HashMap) ResourceLocation(net.minecraft.resources.ResourceLocation) Resource(net.minecraft.server.packs.resources.Resource) GeometryModelData(gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelData)

Example 3 with GeometryModel

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);
}
Also used : GeometryModel(gg.moonflower.pollen.pinwheel.api.client.geometry.GeometryModel) HashMap(java.util.HashMap) ResourceLocation(net.minecraft.resources.ResourceLocation) Resource(net.minecraft.server.packs.resources.Resource) GeometryModelData(gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelData) HashSet(java.util.HashSet)

Example 4 with GeometryModel

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);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) JsonObject(com.google.gson.JsonObject) Platform(gg.moonflower.pollen.api.platform.Platform) Arrays(java.util.Arrays) BackgroundLoader(gg.moonflower.pollen.pinwheel.api.common.util.BackgroundLoader) java.util.concurrent(java.util.concurrent) EntitlementManager(gg.moonflower.pollen.core.client.entitlement.EntitlementManager) ResourceManager(net.minecraft.server.packs.resources.ResourceManager) FileInputStream(java.io.FileInputStream) JsonParser(com.google.gson.JsonParser) Pollen(gg.moonflower.pollen.core.Pollen) FileCache(gg.moonflower.pollen.pinwheel.api.client.FileCache) GeometryModelData(gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelData) GeometryModel(gg.moonflower.pollen.pinwheel.api.client.geometry.GeometryModel) InputStreamReader(java.io.InputStreamReader) GeometryModelParser(gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelParser) Logger(org.apache.logging.log4j.Logger) Map(java.util.Map) ModelEntitlement(gg.moonflower.pollen.core.client.entitlement.ModelEntitlement) LogManager(org.apache.logging.log4j.LogManager) GeometryModel(gg.moonflower.pollen.pinwheel.api.client.geometry.GeometryModel) ResourceLocation(net.minecraft.resources.ResourceLocation) ModelEntitlement(gg.moonflower.pollen.core.client.entitlement.ModelEntitlement) GeometryModelData(gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelData) FileCache(gg.moonflower.pollen.pinwheel.api.client.FileCache)

Example 5 with GeometryModel

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());
        }
    });
}
Also used : GeometryModel(gg.moonflower.pollen.pinwheel.api.client.geometry.GeometryModel) ResourceLocation(net.minecraft.resources.ResourceLocation) RenderableCosmetic(gg.moonflower.pollen.core.client.entitlement.RenderableCosmetic)

Aggregations

GeometryModel (gg.moonflower.pollen.pinwheel.api.client.geometry.GeometryModel)5 ResourceLocation (net.minecraft.resources.ResourceLocation)4 GeometryModelData (gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelData)3 HashMap (java.util.HashMap)2 Resource (net.minecraft.server.packs.resources.Resource)2 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 Platform (gg.moonflower.pollen.api.platform.Platform)1 Pollen (gg.moonflower.pollen.core.Pollen)1 EntitlementManager (gg.moonflower.pollen.core.client.entitlement.EntitlementManager)1 ModelEntitlement (gg.moonflower.pollen.core.client.entitlement.ModelEntitlement)1 RenderableCosmetic (gg.moonflower.pollen.core.client.entitlement.RenderableCosmetic)1 FileCache (gg.moonflower.pollen.pinwheel.api.client.FileCache)1 GeometryModelParser (gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelParser)1 BackgroundLoader (gg.moonflower.pollen.pinwheel.api.common.util.BackgroundLoader)1 MolangRuntime (io.github.ocelot.molangcompiler.api.MolangRuntime)1 MolangVariableProvider (io.github.ocelot.molangcompiler.api.bridge.MolangVariableProvider)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 Arrays (java.util.Arrays)1