use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class BlockMeshShapeGenerator method getStandaloneMesh.
@Override
public Mesh getStandaloneMesh() {
if (mesh == null || mesh.isDisposed()) {
Block block = getBlock();
StandardMeshData meshData = new StandardMeshData();
int nextIndex = 0;
Vector3f light0 = new Vector3f(1, 1, 1);
for (BlockPart dir : BlockPart.allParts()) {
BlockMeshPart part = block.getPrimaryAppearance().getPart(dir);
if (part != null) {
for (int i = 0; i < part.size(); i++) {
meshData.position.put(part.getVertex(i));
meshData.color0.put(Color.white);
meshData.normal.put(part.getNormal(i));
meshData.uv0.put(part.getTexCoord(i));
meshData.light0.put(light0);
}
for (int i = 0; i < part.indicesSize(); ++i) {
meshData.indices.put(nextIndex + part.getIndex(i));
}
if (block.isDoubleSided()) {
for (int i = 0; i < part.indicesSize(); i += 3) {
meshData.indices.put(nextIndex + part.getIndex(i + 1));
meshData.indices.put(nextIndex + part.getIndex(i));
meshData.indices.put(nextIndex + part.getIndex(i + 2));
}
}
nextIndex += part.size();
}
}
mesh = Assets.generateAsset(new ResourceUrn(getBaseUrn(), block.getURI().toString()), meshData, Mesh.class);
}
return mesh;
}
use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class BlockCommands method listShapes.
@Command(shortDescription = "Lists all available shapes\nYou can filter by adding the beginning of words after the" + " commands, e.g.: \"listShapes engine: core\" will list all shapes from the engine and modules starting with 'core'", requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String listShapes(@CommandParam(value = "startsWith", required = false) String[] startsWith) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Shapes");
stringBuilder.append(Console.NEW_LINE);
stringBuilder.append("-----------");
stringBuilder.append(Console.NEW_LINE);
List<ResourceUrn> sortedUris = sortItems(Assets.list(BlockShape.class));
for (ResourceUrn uri : sortedUris) {
if (!uriStartsWithAnyString(uri.toString(), startsWith)) {
continue;
}
stringBuilder.append(uri.toString());
stringBuilder.append(Console.NEW_LINE);
}
return stringBuilder.toString();
}
use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class BlockCommands method giveBlock.
/**
* Called by 'give' command in ItemCommands.java to attempt to put a block in the player's inventory when no item is found.
* Called by 'giveBulkBlock' command in BlockCommands.java to put a block in the player's inventory.
*
* @return Null if not found, otherwise success or warning message
*/
public String giveBlock(@Sender EntityRef sender, @CommandParam("blockName") String uri, @CommandParam(value = "quantity", required = false) Integer quantityParam, @CommandParam(value = "shapeName", required = false) String shapeUriParam) {
Set<ResourceUrn> matchingUris = Assets.resolveAssetUri(uri, BlockFamilyDefinition.class);
BlockFamily blockFamily = null;
if (matchingUris.size() == 1) {
Optional<BlockFamilyDefinition> def = Assets.get(matchingUris.iterator().next(), BlockFamilyDefinition.class);
if (def.isPresent()) {
if (def.get().isFreeform()) {
if (shapeUriParam == null) {
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 + "'";
} else if (resolvedShapeUris.size() > 1) {
StringBuilder builder = new StringBuilder();
builder.append("Found block. Non-unique shape name, possible matches: ");
Iterator<ResourceUrn> shapeUris = sortItems(resolvedShapeUris).iterator();
while (shapeUris.hasNext()) {
builder.append(shapeUris.next().toString());
if (shapeUris.hasNext()) {
builder.append(", ");
}
}
return builder.toString();
}
blockFamily = blockManager.getBlockFamily(new BlockUri(def.get().getUrn(), resolvedShapeUris.iterator().next()));
}
} else {
blockFamily = blockManager.getBlockFamily(new BlockUri(def.get().getUrn()));
}
}
if (blockFamily == null) {
// Should never be reached
return "Block not found";
}
int defaultQuantity = blockFamily.getArchetypeBlock().isStackable() ? 16 : 1;
int quantity = quantityParam != null ? quantityParam : defaultQuantity;
return giveBlock(blockFamily, quantity, sender);
} else if (matchingUris.size() > 1) {
StringBuilder builder = new StringBuilder();
builder.append("Non-unique block name, possible matches: ");
Joiner.on(", ").appendTo(builder, matchingUris);
return builder.toString();
}
return null;
}
use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class WorldAtlasImpl method buildAtlas.
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);
}
use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class WorldAtlasImpl method createTextureAtlas.
private void createTextureAtlas(final Texture texture) {
final Map<Name, Map<Name, SubtextureData>> textureAtlases = Maps.newHashMap();
final Vector2f texSize = new Vector2f(getRelativeTileSize(), getRelativeTileSize());
tileIndexes.forEachEntry((tileUri, index) -> {
Vector2f coords = getTexCoords(index);
SubtextureData subtextureData = new SubtextureData(texture, new Rectanglef(coords, coords).setSize(texSize));
Map<Name, SubtextureData> textureAtlas = textureAtlases.get(tileUri.getModuleName());
if (textureAtlas == null) {
textureAtlas = Maps.newHashMap();
textureAtlases.put(tileUri.getModuleName(), textureAtlas);
}
textureAtlas.put(tileUri.getResourceName(), subtextureData);
return true;
});
for (Map.Entry<Name, Map<Name, SubtextureData>> atlas : textureAtlases.entrySet()) {
AtlasData data = new AtlasData(atlas.getValue());
Assets.generateAsset(new ResourceUrn(atlas.getKey(), new Name("terrain")), data, Atlas.class);
}
}
Aggregations