@Override public Material getMaterial(String assetId) { return Assets.getMaterial(assetId).orElseThrow(() -> new RuntimeException("Failed to resolve required asset: '" + assetId + "'")); }
/** * Utility method to conveniently retrieve materials from the Assets system, * hiding the relative complexity of the exception handling. * * @param materialUrn a ResourceUrn instance providing the name of the material to be obtained. * @return a Material instance * @throws RuntimeException if the material couldn't be resolved through the asset system. */ public static Material getMaterial(ResourceUrn materialUrn) { String materialName = materialUrn.toString(); return Assets.getMaterial(materialName).orElseThrow(() -> new RuntimeException("Failed to resolve required asset: '" + materialName + "'")); } }
@Override public void renderAlphaBlend() { Material material = Assets.getMaterial(PARTICLE_MATERIAL_URI).get(); material.enable(); Vector3f camPos = worldRenderer.getActiveCamera().getPosition(); particleSystemManager.getParticleEmittersByDataComponent(ParticleDataSpriteComponent.class).forEach(p -> drawParticles(material, p, camPos)); }
public LwjglCanvasRenderer(Context context) { // TODO use context to get assets instead of static methods this.textureMat = Assets.getMaterial("engine:UITexture").get(); this.billboard = Assets.getMesh("engine:UIBillboard").get(); this.fontMeshBuilder = new FontMeshBuilder(context.get(AssetManager.class).getAsset("engine:UIUnderline", Material.class).get()); // failure to load these can be due to failing shaders or missing resources this.renderingConfig = context.get(Config.class).getRendering(); this.uiScale = this.renderingConfig.getUiScale() / 100f; this.renderingConfig.subscribe(RenderingConfig.UI_SCALE, this); }
public static void addOrUpdateItemMeshComponent(ItemComponent itemComponent, MutableComponentContainer entity) { if (itemComponent != null) { MeshComponent meshComponent = null; if (entity.hasComponent(MeshComponent.class)) { meshComponent = entity.getComponent(MeshComponent.class); } else { meshComponent = new MeshComponent(); } meshComponent.material = Assets.getMaterial("engine:droppedItem").get(); if (itemComponent.icon != null) { meshComponent.mesh = IconMeshFactory.getIconMesh(itemComponent.icon); } entity.addOrSaveComponent(meshComponent); } }
public void renderWithLightValue(float sunlight, float blockLight) { if (meshGenerator == null) { return; } Material mat = Assets.getMaterial("engine:prog.block").orElseThrow(() -> new RuntimeException("Missing engine material")); mat.activateFeature(ShaderProgramFeature.FEATURE_USE_MATRIX_STACK); mat.enable(); mat.setFloat("sunlight", sunlight); mat.setFloat("blockLight", blockLight); Mesh mesh = meshGenerator.getStandaloneMesh(); if (mesh != null) { mesh.render(); } mat.deactivateFeature(ShaderProgramFeature.FEATURE_USE_MATRIX_STACK); }
public CanvasImpl(NUIManager nuiManager, Context context, CanvasRenderer renderer) { this.renderer = renderer; this.nuiManager = nuiManager; this.time = context.get(Time.class); this.keyboard = context.get(InputSystem.class).getKeyboard(); this.mouse = context.get(InputSystem.class).getMouseDevice(); this.meshMat = Assets.getMaterial("engine:UILitMesh").get(); this.whiteTexture = Assets.getTexture("engine:white").get(); this.renderingConfig = context.get(Config.class).getRendering(); this.uiScale = this.renderingConfig.getUiScale() / 100f; this.renderingConfig.subscribe(RenderingConfig.UI_SCALE, this); }
private void initialize() { Tessellator tessellator = new Tessellator(); TessellatorHelper.addBlockMesh(tessellator, new Vector4f(1, 1, 1, 1f), textureRegion.min(), textureRegion.size(), 1.001f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f); overlayMesh = tessellator.generateMesh(); tessellator = new Tessellator(); TessellatorHelper.addBlockMesh(tessellator, new Vector4f(1, 1, 1, .2f), textureRegion.min(), textureRegion.size(), 1.001f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f); overlayMesh2 = tessellator.generateMesh(); defaultTextured = Assets.getMaterial("engine:prog.defaultTextured").get(); }
@Override public void render(Camera camera) { glDepthMask(false); if (camera.isReflected()) { glCullFace(GL_BACK); } else { glCullFace(GL_FRONT); } Material shader = Assets.getMaterial("engine:prog.sky").get(); shader.enable(); // Draw the skysphere drawSkysphere(camera.getzFar()); if (camera.isReflected()) { glCullFace(GL_FRONT); } else { glCullFace(GL_BACK); } glDepthMask(true); }
public static void addOrUpdateBlockMeshComponent(BlockItemComponent blockItemComponent, MutableComponentContainer entity) { if (blockItemComponent != null) { MeshComponent meshComponent = null; if (entity.hasComponent(MeshComponent.class)) { meshComponent = entity.getComponent(MeshComponent.class); } else { meshComponent = new MeshComponent(); } BlockFamily blockFamily = blockItemComponent.blockFamily; if (blockFamily == null) { return; } meshComponent.mesh = blockFamily.getArchetypeBlock().getMeshGenerator().getStandaloneMesh(); meshComponent.material = Assets.getMaterial("engine:terrain").get(); meshComponent.translucent = blockFamily.getArchetypeBlock().isTranslucent(); float luminance = blockFamily.getArchetypeBlock().getLuminance() / 15f; meshComponent.selfLuminance = luminance; if (luminance > 0 && !entity.hasComponent(LightComponent.class)) { LightComponent lightComponent = entity.addComponent(new LightComponent()); //scale the light back if it is a less bright block lightComponent.lightAttenuationRange *= luminance; } entity.addOrSaveComponent(meshComponent); } } }
glDisable(GL_DEPTH_TEST); Vector3f cameraPosition = worldRenderer.getActiveCamera().getPosition(); Material material = Assets.getMaterial("engine:white").get(); material.setFloat("sunlight", 1.0f, true); material.setFloat("blockLight", 1.0f, true);