Search in sources :

Example 1 with MeshComponent

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);
    }
}
Also used : MeshComponent(org.terasology.rendering.logic.MeshComponent) LightComponent(org.terasology.rendering.logic.LightComponent) BlockFamily(org.terasology.world.block.family.BlockFamily)

Example 2 with 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;
    }
}
Also used : BlockComponent(org.terasology.world.block.BlockComponent) MeshComponent(org.terasology.rendering.logic.MeshComponent) BlockRegionComponent(org.terasology.world.block.regions.BlockRegionComponent) Vector3f(org.terasology.math.geom.Vector3f) Block(org.terasology.world.block.Block) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 3 with MeshComponent

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();
    }
}
Also used : MeshComponent(org.terasology.rendering.logic.MeshComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent)

Example 4 with MeshComponent

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);
    }
}
Also used : BlockComponent(org.terasology.world.block.BlockComponent) MeshComponent(org.terasology.rendering.logic.MeshComponent) PojoEntityManager(org.terasology.entitySystem.entity.internal.PojoEntityManager) FastRandom(org.terasology.utilities.random.FastRandom) MeshComponent(org.terasology.rendering.logic.MeshComponent) BlockComponent(org.terasology.world.block.BlockComponent) Component(org.terasology.entitySystem.Component) LocationComponent(org.terasology.logic.location.LocationComponent) LocationComponent(org.terasology.logic.location.LocationComponent)

Example 5 with MeshComponent

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);
    }
}
Also used : BlockComponent(org.terasology.world.block.BlockComponent) MeshComponent(org.terasology.rendering.logic.MeshComponent) FastRandom(org.terasology.utilities.random.FastRandom) MeshComponent(org.terasology.rendering.logic.MeshComponent) BlockComponent(org.terasology.world.block.BlockComponent) Component(org.terasology.entitySystem.Component) LocationComponent(org.terasology.logic.location.LocationComponent) LocationComponent(org.terasology.logic.location.LocationComponent)

Aggregations

MeshComponent (org.terasology.rendering.logic.MeshComponent)7 LocationComponent (org.terasology.logic.location.LocationComponent)5 BlockComponent (org.terasology.world.block.BlockComponent)4 Component (org.terasology.entitySystem.Component)3 FastRandom (org.terasology.utilities.random.FastRandom)3 EntityRef (org.terasology.entitySystem.entity.EntityRef)2 PojoEntityManager (org.terasology.entitySystem.entity.internal.PojoEntityManager)2 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)1 Vector3f (org.terasology.math.geom.Vector3f)1 LightComponent (org.terasology.rendering.logic.LightComponent)1 Block (org.terasology.world.block.Block)1 BlockFamily (org.terasology.world.block.family.BlockFamily)1 BlockRegionComponent (org.terasology.world.block.regions.BlockRegionComponent)1