@Override public Optional<TextureData> getAssetData(ResourceUrn urn) throws IOException { if (TerasologyConstants.ENGINE_MODULE.equals(urn.getModuleName()) && TextureUtil.COLOR_RESOURCE_NAME.equals(urn.getResourceName())) { Name fragmentName = urn.getFragmentName(); if (!fragmentName.isEmpty()) { Color color = TextureUtil.getColorForColorName(fragmentName.toLowerCase()); return Optional.of(TextureDataFactory.newInstance(color)); } } return Optional.empty(); } }
@Override public Optional<TextureData> getAssetData(ResourceUrn urn) throws IOException { if (TerasologyConstants.ENGINE_MODULE.equals(urn.getModuleName()) && TextureUtil.NOISE_RESOURCE_NAME.equals(urn.getResourceName())) { Name fragmentName = urn.getFragmentName(); if (!fragmentName.isEmpty()) { String[] parts = fragmentName.toLowerCase().split("\\."); if (parts.length == 5) { String type = parts[0]; int size = Integer.parseInt(parts[1]); long seed = Long.parseLong(parts[2]); int min = Integer.parseInt(parts[3]); int max = Integer.parseInt(parts[4]); TextureData textureData; switch (type) { case "white": return Optional.of(TextureDataFactory.createWhiteNoiseTexture(size, seed, min, max)); } } } } return Optional.empty(); } }
private void testRepeatedColorInDataTexture(Color expectedColor, int expectedRed, int expectedGreen, int expectedBlue, int expectedAlpha) { TextureData textureData = TextureDataFactory.newInstance(expectedColor); ByteBuffer[] buffers = textureData.getBuffers(); assertEquals(1, buffers.length); ByteBuffer buffer = buffers[0]; for (int offsetCounter = 0; offsetCounter < 4 * 16; offsetCounter++) { int offset = offsetCounter * 4; assertEquals(expectedRed, buffer.get(0 + offset)); assertEquals(expectedGreen, buffer.get(1 + offset)); assertEquals(expectedBlue, buffer.get(2 + offset)); assertEquals(expectedAlpha, buffer.get(3 + offset)); } assertEquals(16, textureData.getWidth()); assertEquals(16, textureData.getHeight()); assertEquals(FilterMode.NEAREST, textureData.getFilterMode()); assertEquals(WrapMode.REPEAT, textureData.getWrapMode()); assertEquals(Texture.Type.TEXTURE2D, textureData.getType()); } }