use of org.terasology.rendering.logic.MeshComponent in project Terasology by MovingBlocks.
the class ItemCommonSystem method addOrUpdateBlockMeshComponent.
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);
}
}
use of org.terasology.rendering.logic.MeshComponent in project Terasology by MovingBlocks.
the class LocalPlayerSystem method onTargetChanged.
@ReceiveEvent
public void onTargetChanged(PlayerTargetChangedEvent event, EntityRef entity) {
EntityRef target = event.getNewTarget();
if (target.exists()) {
LocationComponent location = target.getComponent(LocationComponent.class);
if (location != null) {
BlockComponent blockComp = target.getComponent(BlockComponent.class);
BlockRegionComponent blockRegion = target.getComponent(BlockRegionComponent.class);
if (blockComp != null || blockRegion != null) {
Vector3f blockPos = location.getWorldPosition();
Block block = worldProvider.getBlock(blockPos);
aabb = block.getBounds(blockPos);
} else {
MeshComponent mesh = target.getComponent(MeshComponent.class);
if (mesh != null && mesh.mesh != null) {
aabb = mesh.mesh.getAABB();
aabb = aabb.transform(location.getWorldRotation(), location.getWorldPosition(), location.getWorldScale());
}
}
}
} else {
aabb = null;
}
}
use of org.terasology.rendering.logic.MeshComponent in project Terasology by MovingBlocks.
the class IterateMultipleComponentBenchmark method run.
@Override
public void run() {
for (EntityRef entity : entityManager.getEntitiesWith(MeshComponent.class, LocationComponent.class)) {
LocationComponent loc = entity.getComponent(LocationComponent.class);
MeshComponent meshComp = entity.getComponent(MeshComponent.class);
loc.getLocalPosition();
}
}
use of org.terasology.rendering.logic.MeshComponent in project Terasology by MovingBlocks.
the class IterateMultipleComponentBenchmark method setup.
@Override
public void setup() {
FastRandom rand = new FastRandom(0L);
rawEntityData = Lists.newArrayList();
for (int i = 0; i < 1000; ++i) {
List<Component> entityData = Lists.newArrayList();
if (rand.nextFloat() < 0.75f) {
entityData.add(new LocationComponent());
}
if (rand.nextFloat() < 0.5f) {
entityData.add(new MeshComponent());
}
if (rand.nextFloat() < 0.25f) {
entityData.add(new BlockComponent());
}
rawEntityData.add(entityData);
}
entityManager = new PojoEntityManager();
for (List<Component> rawEntity : rawEntityData) {
entityManager.create(rawEntity);
}
}
use of org.terasology.rendering.logic.MeshComponent in project Terasology by MovingBlocks.
the class EntityCreateBenchmark method setup.
@Override
public void setup() {
FastRandom rand = new FastRandom(0L);
rawEntityData = Lists.newArrayList();
for (int i = 0; i < 1000; ++i) {
List<Component> entityData = Lists.newArrayList();
if (rand.nextFloat() < 0.75f) {
entityData.add(new LocationComponent());
}
if (rand.nextFloat() < 0.5f) {
entityData.add(new MeshComponent());
}
if (rand.nextFloat() < 0.25f) {
entityData.add(new BlockComponent());
}
rawEntityData.add(entityData);
}
}
Aggregations