/** * Parametrized constructor. * * @param id The ID to assign to the widget */ public UIText(String id) { super(id); cursorTexture = Assets.getTexture("engine:white").get(); }
public Mesh build() { return Assets.generateAsset(meshData, Mesh.class); }
/** * @param urn The two-part uri for asset ("module:assetName") * @return The requested texture, or null if it doesn't exist */ public static Optional<Texture> getTexture(String urn) { return get(urn, Texture.class); }
public GLSLMaterial addShaderProgram(String title) { String uri = "engine:" + title; Optional<? extends Shader> shader = Assets.getShader(uri); checkState(shader.isPresent(), "Failed to resolve %s", uri); shader.get().recompile(); GLSLMaterial material = (GLSLMaterial) Assets.generateAsset(new ResourceUrn("engine:prog." + title), new MaterialData(shader.get()), Material.class); progamaticShaders.add(material); return material; }
private Texture generateNoiseTexture() { Optional<Texture> texture = Assets.getTexture("engine:ssaoNoise"); if (!texture.isPresent()) { ByteBuffer noiseValues = BufferUtils.createByteBuffer(SSAO_NOISE_SIZE * SSAO_NOISE_SIZE * 4); for (int i = 0; i < SSAO_NOISE_SIZE * SSAO_NOISE_SIZE; ++i) { Vector3f noiseVector = new Vector3f(randomGenerator.nextFloat(-1.0f, 1.0f), randomGenerator.nextFloat(-1.0f, 1.0f), 0.0f); noiseVector.normalize(); noiseValues.put((byte) ((noiseVector.x * 0.5 + 0.5) * 255.0f)); noiseValues.put((byte) ((noiseVector.y * 0.5 + 0.5) * 255.0f)); noiseValues.put((byte) ((noiseVector.z * 0.5 + 0.5) * 255.0f)); noiseValues.put((byte) 0x0); } noiseValues.flip(); return Assets.generateAsset(new ResourceUrn("engine:ssaoNoise"), new TextureData(SSAO_NOISE_SIZE, SSAO_NOISE_SIZE, new ByteBuffer[]{noiseValues}, Texture.WrapMode.REPEAT, Texture.FilterMode.NEAREST), Texture.class); } return texture.get(); } }
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); }
@Override public Optional<?> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return Assets.getTextureRegion(json.getAsString()); } }
@Override public void initialise() { explosionSounds.add(Assets.getSound("core:explode1")); explosionSounds.add(Assets.getSound("core:explode2")); explosionSounds.add(Assets.getSound("core:explode3")); explosionSounds.add(Assets.getSound("core:explode4")); explosionSounds.add(Assets.getSound("core:explode5")); }
@CommandParam(value = "quantity", required = false) Integer quantityParam, @CommandParam(value = "shapeName", required = false) String shapeUriParam) { Set<ResourceUrn> matchingUris = Assets.resolveAssetUri(uri, BlockFamilyDefinition.class); Optional<BlockFamilyDefinition> def = Assets.get(matchingUris.iterator().next(), BlockFamilyDefinition.class); if (def.isPresent()) { if (def.get().isFreeform()) { blockFamily = blockManager.getBlockFamily(new BlockUri(def.get().getUrn(), new ResourceUrn("engine:cube"))); } else { Set<ResourceUrn> resolvedShapeUris = Assets.resolveAssetUri(shapeUriParam, BlockShape.class); if (resolvedShapeUris.isEmpty()) { return "Found block. No shape found for '" + shapeUriParam + "'";
@Override public Material getMaterial(String assetId) { return Assets.getMaterial(assetId).orElseThrow(() -> new RuntimeException("Failed to resolve required asset: '" + assetId + "'")); }
@Override public void apply(AssetDataFile input, UIData assetData) throws IOException { try (JsonReader reader = new JsonReader(new InputStreamReader(input.openStream(), Charsets.UTF_8))) { JsonElement jsonElement = new JsonParser().parse(reader); String skinUri = jsonElement.getAsJsonObject().get("skin").getAsString(); String filePath = input.toString(); String moduleName = filePath.substring(1, filePath.indexOf('/', 1)); Optional<UISkin> skin = Assets.getSkin(moduleName + ":" + skinUri); if (skin.isPresent()) { assetData.getRootWidget().setSkin(skin.get()); } else { logger.warn("Failed to load skin " + skinUri + " for the delta file " + input.getFilename()); } } } }
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); }
font = Assets.getFont(readUntilCharacter(reader, '>')).get(); } else if (nextChar == 'c') { if (sb.length() > 0) {
private void loadPreviewImages(final GameInfo gameInfo) { List<Texture> textures = new ArrayList<>(); if (gameInfo != null && gameInfo.getSavePath() != null) { final List<BufferedImage> bufferedImages = GamePreviewImageProvider.getAllPreviewImages(gameInfo.getSavePath()); textures = bufferedImages .stream() .map(buffImage -> { TextureData textureData; try { textureData = AWTTextureFormat.convertToTextureData(buffImage, Texture.FilterMode.LINEAR); } catch (IOException e) { logger.error("Converting preview image to texture data {} failed", e); return null; } return Assets.generateAsset(new ResourceUrn(PREVIEW_IMAGE_URI_PATTERN + bufferedImages.indexOf(buffImage)), textureData, Texture.class); }) .filter(Objects::nonNull) .collect(Collectors.toList()); } if (textures.isEmpty()) { textures.add(Assets.getTexture(DEFAULT_PREVIEW_IMAGE_URI).get()); } previewSlideshow.clean(); textures.forEach(tex -> { UIImage image = new UIImage(null, tex, true); previewSlideshow.addImage(image); }); }
@Override public TextureRegion getFromString(String representation) { Optional<TextureRegionAsset> region = Assets.getTextureRegion(representation); if (region.isPresent()) { return region.get(); } else { logger.error("Failed to resolve texture region '" + representation + "'"); return Assets.getTextureRegion("engine:default").get(); } } }
/** * Plays a test dig sound at an offset from the player in the x and z axis. * * @param sender The entity sending the sound request * @param xOffset The x axis offset from the player to play the sound at. * @param zOffset The z axis offset from the player to play the sound at. */ @Command(shortDescription = "Plays a test sound") public void playTestSound(@Sender EntityRef sender, @CommandParam("xOffset") float xOffset, @CommandParam("zOffset") float zOffset) { Vector3f position = localPlayer.getPosition(); position.x += xOffset; position.z += zOffset; audioManager.playSound(Assets.getSound("engine:dig").get(), position); }
private void buildAtlas() { calculateAtlasSizes(); int numMipMaps = getNumMipmaps(); ByteBuffer[] data = createAtlasMipmaps(numMipMaps, TRANSPARENT_COLOR, tiles, "tiles.png"); ByteBuffer[] dataNormal = createAtlasMipmaps(numMipMaps, UNIT_Z_COLOR, tilesNormal, "tilesNormal.png", tilesGloss); ByteBuffer[] dataHeight = createAtlasMipmaps(numMipMaps, MID_RED_COLOR, tilesHeight, "tilesHeight.png"); TextureData terrainTexData = new TextureData(atlasSize, atlasSize, data, Texture.WrapMode.CLAMP, Texture.FilterMode.NEAREST); Texture terrainTex = Assets.generateAsset(new ResourceUrn("engine:terrain"), terrainTexData, Texture.class); TextureData terrainNormalData = new TextureData(atlasSize, atlasSize, dataNormal, Texture.WrapMode.CLAMP, Texture.FilterMode.NEAREST); Assets.generateAsset(new ResourceUrn("engine:terrainNormal"), terrainNormalData, Texture.class); TextureData terrainHeightData = new TextureData(atlasSize, atlasSize, dataHeight, Texture.WrapMode.CLAMP, Texture.FilterMode.LINEAR); Assets.generateAsset(new ResourceUrn("engine:terrainHeight"), terrainHeightData, Texture.class); MaterialData terrainMatData = new MaterialData(Assets.getShader("engine:block").get()); terrainMatData.setParam("textureAtlas", terrainTex); terrainMatData.setParam("colorOffset", new float[]{1, 1, 1}); terrainMatData.setParam("textured", true); Assets.generateAsset(new ResourceUrn("engine:terrain"), terrainMatData, Material.class); createTextureAtlas(terrainTex); }
EntityRef gazeEntity = GazeAuthoritySystem.getGazeEntityForCharacter(playerEntity); LocationComponent gazeLocation = gazeEntity.getComponent(LocationComponent.class); Set<ResourceUrn> matchingUris = Assets.resolveAssetUri(uri, BlockFamilyDefinition.class); targetSystem.updateTarget(gazeLocation.getWorldPosition(), gazeLocation.getWorldDirection(), maxDistance); EntityRef target = targetSystem.getTarget(); BlockComponent targetLocation = target.getComponent(BlockComponent.class); if (matchingUris.size() == 1) { Optional<BlockFamilyDefinition> def = Assets.get(matchingUris.iterator().next(), BlockFamilyDefinition.class); if (def.isPresent()) { BlockFamily blockFamily = blockManager.getBlockFamily(uri);
/** * 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 + "'")); } }
public ItemIcon() { tooltip = new UIList<>(); tooltip.setInteractive(false); tooltip.setSelectable(false); final UISkin defaultSkin = Assets.getSkin("core:itemTooltip").get(); tooltip.setSkin(defaultSkin); tooltip.setItemRenderer(new TooltipLineRenderer(defaultSkin)); tooltip.bindList(new DefaultBinding<>(new ArrayList<>())); }