Search in sources :

Example 1 with MeshComponent

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

Example 2 with MeshComponent

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()));
                }
            }
        }
    }
}
Also used : BlockComponent(org.terasology.engine.world.block.BlockComponent) MeshComponent(org.terasology.engine.rendering.logic.MeshComponent) Matrix4f(org.joml.Matrix4f) BlockRegionComponent(org.terasology.engine.world.block.regions.BlockRegionComponent) Vector3f(org.joml.Vector3f) Block(org.terasology.engine.world.block.Block) Quaternionf(org.joml.Quaternionf) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 3 with MeshComponent

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

Example 4 with 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);
    }
}
Also used : MeshComponent(org.terasology.engine.rendering.logic.MeshComponent)

Aggregations

MeshComponent (org.terasology.engine.rendering.logic.MeshComponent)4 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)2 LocationComponent (org.terasology.engine.logic.location.LocationComponent)2 Matrix4f (org.joml.Matrix4f)1 Quaternionf (org.joml.Quaternionf)1 Vector3f (org.joml.Vector3f)1 Benchmark (org.openjdk.jmh.annotations.Benchmark)1 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)1 LightComponent (org.terasology.engine.rendering.logic.LightComponent)1 Block (org.terasology.engine.world.block.Block)1 BlockComponent (org.terasology.engine.world.block.BlockComponent)1 BlockFamily (org.terasology.engine.world.block.family.BlockFamily)1 BlockRegionComponent (org.terasology.engine.world.block.regions.BlockRegionComponent)1