use of org.terasology.engine.rendering.logic.MeshComponent in project Terasology by MovingBlocks.
the class IterateComponentsBenchmark method iterateMultipleComponent.
@Benchmark
public void iterateMultipleComponent(StateObject state) {
for (EntityRef entity : state.entityManager.getEntitiesWith(MeshComponent.class, LocationComponent.class)) {
LocationComponent loc = entity.getComponent(LocationComponent.class);
MeshComponent meshComp = entity.getComponent(MeshComponent.class);
loc.getLocalPosition();
}
}
use of org.terasology.engine.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();
hasTarget = target.exists();
if (hasTarget) {
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(new Vector3f());
Block block = worldProvider.getBlock(blockPos);
aabb.set(block.getBounds(blockPos));
} else {
MeshComponent mesh = target.getComponent(MeshComponent.class);
if (mesh != null && mesh.mesh != null) {
aabb.set(mesh.mesh.getAABB());
aabb.transform(new Matrix4f().translationRotateScale(location.getWorldPosition(new Vector3f()), location.getWorldRotation(new Quaternionf()), location.getWorldScale()));
}
}
}
}
}
use of org.terasology.engine.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.engine.rendering.logic.MeshComponent in project Terasology by MovingBlocks.
the class ItemCommonSystem method addOrUpdateItemMeshComponent.
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);
}
}
Aggregations