Search in sources :

Example 11 with EntityRef

use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class GamePlayMetric method createTelemetryFieldToValue.

@Override
public Map<String, ?> createTelemetryFieldToValue() {
    localPlayer = CoreRegistry.get(LocalPlayer.class);
    EntityRef playerEntity = localPlayer.getCharacterEntity();
    if (playerEntity.hasComponent(GamePlayStatsComponent.class)) {
        GamePlayStatsComponent gamePlayStatsComponent = playerEntity.getComponent(GamePlayStatsComponent.class);
        distanceTraveled = gamePlayStatsComponent.distanceTraveled;
        playTimeMinute = (long) gamePlayStatsComponent.playTimeMinute;
        return super.createTelemetryFieldToValue();
    } else {
        return super.createTelemetryFieldToValue();
    }
}
Also used : LocalPlayer(org.terasology.logic.players.LocalPlayer) GamePlayStatsComponent(org.terasology.telemetry.GamePlayStatsComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 12 with EntityRef

use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class FloatingTextRenderer method render.

private void render(Iterable<EntityRef> floatingTextEntities) {
    Vector3f cameraPosition = camera.getPosition();
    for (EntityRef entity : floatingTextEntities) {
        LocationComponent location = entity.getComponent(LocationComponent.class);
        if (location == null) {
            continue;
        }
        Vector3f worldPos = location.getWorldPosition();
        if (!worldProvider.isBlockRelevant(worldPos)) {
            continue;
        }
        FloatingTextComponent floatingText = entity.getComponent(FloatingTextComponent.class);
        String[] linesOfText = floatingText.text.split("\n");
        Color baseColor = floatingText.textColor;
        Color shadowColor = floatingText.textShadowColor;
        boolean underline = false;
        int textWidth = 0;
        for (String singleLine : linesOfText) {
            if (font.getWidth(singleLine) > textWidth) {
                textWidth = font.getWidth(singleLine);
            }
        }
        FontMeshBuilder meshBuilder = new FontMeshBuilder(underlineMaterial);
        Map<Material, Mesh> meshMap = entityMeshCache.get(entity);
        if (meshMap == null) {
            meshMap = meshBuilder.createTextMesh(font, Arrays.asList(linesOfText), textWidth, HorizontalAlign.CENTER, baseColor, shadowColor, underline);
            entityMeshCache.put(entity, meshMap);
        }
        if (floatingText.isOverlay) {
            glDisable(GL_DEPTH_TEST);
        }
        glPushMatrix();
        float scale = METER_PER_PIXEL * floatingText.scale;
        glTranslated(worldPos.x - cameraPosition.x, worldPos.y - cameraPosition.y, worldPos.z - cameraPosition.z);
        OpenGLUtils.applyBillboardOrientation();
        glScaled(scale, -scale, scale);
        glTranslated(-textWidth / 2.0, 0.0, 0.0);
        for (Map.Entry<Material, Mesh> meshMapEntry : meshMap.entrySet()) {
            Mesh mesh = meshMapEntry.getValue();
            Material material = meshMapEntry.getKey();
            material.enable();
            material.bindTextures();
            material.setFloat4("croppingBoundaries", Float.MIN_VALUE, Float.MAX_VALUE, Float.MIN_VALUE, Float.MAX_VALUE);
            material.setFloat2("offset", 0.0f, 0.0f);
            material.setFloat("alpha", 1.0f);
            mesh.render();
        }
        glPopMatrix();
        // Revert to default state
        if (floatingText.isOverlay) {
            glEnable(GL_DEPTH_TEST);
        }
    }
}
Also used : Color(org.terasology.rendering.nui.Color) Mesh(org.terasology.rendering.assets.mesh.Mesh) Material(org.terasology.rendering.assets.material.Material) LocationComponent(org.terasology.logic.location.LocationComponent) FontMeshBuilder(org.terasology.rendering.assets.font.FontMeshBuilder) Vector3f(org.terasology.math.geom.Vector3f) EntityRef(org.terasology.entitySystem.entity.EntityRef) Map(java.util.Map)

Example 13 with EntityRef

use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class MeshRenderer method renderEntitiesByMaterial.

private void renderEntitiesByMaterial(SetMultimap<Material, EntityRef> meshByMaterial) {
    Vector3f cameraPosition = worldRenderer.getActiveCamera().getPosition();
    Quat4f worldRot = new Quat4f();
    Vector3f worldPos = new Vector3f();
    FloatBuffer tempMatrixBuffer44 = BufferUtils.createFloatBuffer(16);
    FloatBuffer tempMatrixBuffer33 = BufferUtils.createFloatBuffer(12);
    for (Material material : meshByMaterial.keySet()) {
        if (material.isRenderable()) {
            OpenGLMesh lastMesh = null;
            material.enable();
            material.setFloat("sunlight", 1.0f, true);
            material.setFloat("blockLight", 1.0f, true);
            material.setMatrix4("projectionMatrix", worldRenderer.getActiveCamera().getProjectionMatrix(), true);
            material.bindTextures();
            Set<EntityRef> entities = meshByMaterial.get(material);
            lastRendered = entities.size();
            for (EntityRef entity : entities) {
                MeshComponent meshComp = entity.getComponent(MeshComponent.class);
                LocationComponent location = entity.getComponent(LocationComponent.class);
                if (isHidden(entity, meshComp) || location == null || meshComp.mesh == null || !isRelevant(entity, location.getWorldPosition())) {
                    continue;
                }
                if (meshComp.mesh.isDisposed()) {
                    logger.error("Attempted to render disposed mesh");
                    continue;
                }
                location.getWorldRotation(worldRot);
                location.getWorldPosition(worldPos);
                float worldScale = location.getWorldScale();
                Transform toWorldSpace = new Transform(worldPos, worldRot, worldScale);
                Vector3f offsetFromCamera = new Vector3f();
                offsetFromCamera.sub(worldPos, cameraPosition);
                Matrix4f matrixCameraSpace = new Matrix4f(worldRot, offsetFromCamera, worldScale);
                AABB aabb = meshComp.mesh.getAABB().transform(toWorldSpace);
                if (worldRenderer.getActiveCamera().hasInSight(aabb)) {
                    if (meshComp.mesh != lastMesh) {
                        if (lastMesh != null) {
                            lastMesh.postRender();
                        }
                        lastMesh = (OpenGLMesh) meshComp.mesh;
                        lastMesh.preRender();
                    }
                    Matrix4f modelViewMatrix = MatrixUtils.calcModelViewMatrix(worldRenderer.getActiveCamera().getViewMatrix(), matrixCameraSpace);
                    MatrixUtils.matrixToFloatBuffer(modelViewMatrix, tempMatrixBuffer44);
                    MatrixUtils.matrixToFloatBuffer(MatrixUtils.calcNormalMatrix(modelViewMatrix), tempMatrixBuffer33);
                    material.setMatrix4("projectionMatrix", worldRenderer.getActiveCamera().getProjectionMatrix(), true);
                    material.setMatrix4("worldViewMatrix", tempMatrixBuffer44, true);
                    material.setMatrix3("normalMatrix", tempMatrixBuffer33, true);
                    material.setFloat3("colorOffset", meshComp.color.rf(), meshComp.color.gf(), meshComp.color.bf(), true);
                    material.setFloat("sunlight", worldRenderer.getMainLightIntensityAt(worldPos), true);
                    material.setFloat("blockLight", Math.max(worldRenderer.getBlockLightIntensityAt(worldPos), meshComp.selfLuminance), true);
                    lastMesh.doRender();
                }
            }
            if (lastMesh != null) {
                lastMesh.postRender();
            }
        }
    }
}
Also used : OpenGLMesh(org.terasology.rendering.opengl.OpenGLMesh) FloatBuffer(java.nio.FloatBuffer) Material(org.terasology.rendering.assets.material.Material) LocationComponent(org.terasology.logic.location.LocationComponent) Matrix4f(org.terasology.math.geom.Matrix4f) Vector3f(org.terasology.math.geom.Vector3f) Transform(org.terasology.math.Transform) EntityRef(org.terasology.entitySystem.entity.EntityRef) Quat4f(org.terasology.math.geom.Quat4f) AABB(org.terasology.math.AABB)

Example 14 with EntityRef

use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class MeshRenderer method renderEntities.

private void renderEntities(Iterable<EntityRef> entityRefs) {
    SetMultimap<Material, EntityRef> entitiesToRender = HashMultimap.create();
    for (EntityRef entity : entityRefs) {
        MeshComponent meshComponent = entity.getComponent(MeshComponent.class);
        if (meshComponent != null && meshComponent.material != null) {
            entitiesToRender.put(meshComponent.material, entity);
        }
    }
    renderEntitiesByMaterial(entitiesToRender);
}
Also used : Material(org.terasology.rendering.assets.material.Material) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 15 with EntityRef

use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class SkeletonRenderer method renderOverlay.

@Override
public void renderOverlay() {
    if (config.getRendering().getDebug().isRenderSkeletons()) {
        glDisable(GL_DEPTH_TEST);
        Vector3f cameraPosition = worldRenderer.getActiveCamera().getPosition();
        Material material = Assets.getMaterial("engine:white").get();
        material.setFloat("sunlight", 1.0f, true);
        material.setFloat("blockLight", 1.0f, true);
        material.setMatrix4("projectionMatrix", worldRenderer.getActiveCamera().getProjectionMatrix());
        glLineWidth(2);
        Vector3f worldPos = new Vector3f();
        FloatBuffer tempMatrixBuffer44 = BufferUtils.createFloatBuffer(16);
        FloatBuffer tempMatrixBuffer33 = BufferUtils.createFloatBuffer(12);
        for (EntityRef entity : entityManager.getEntitiesWith(SkeletalMeshComponent.class, LocationComponent.class)) {
            LocationComponent location = entity.getComponent(LocationComponent.class);
            location.getWorldPosition(worldPos);
            Vector3f worldPositionCameraSpace = new Vector3f();
            worldPositionCameraSpace.sub(worldPos, cameraPosition);
            float worldScale = location.getWorldScale();
            Matrix4f matrixCameraSpace = new Matrix4f(new Quat4f(0, 0, 0, 1), worldPositionCameraSpace, worldScale);
            Matrix4f modelViewMatrix = MatrixUtils.calcModelViewMatrix(worldRenderer.getActiveCamera().getViewMatrix(), matrixCameraSpace);
            MatrixUtils.matrixToFloatBuffer(modelViewMatrix, tempMatrixBuffer44);
            material.setMatrix4("worldViewMatrix", tempMatrixBuffer44, true);
            MatrixUtils.matrixToFloatBuffer(MatrixUtils.calcNormalMatrix(modelViewMatrix), tempMatrixBuffer33);
            material.setMatrix3("normalMatrix", tempMatrixBuffer33, true);
            SkeletalMeshComponent skeletalMesh = entity.getComponent(SkeletalMeshComponent.class);
            renderBone(skeletalMesh.rootBone, worldPos);
        }
        glEnable(GL_DEPTH_TEST);
    }
}
Also used : Matrix4f(org.terasology.math.geom.Matrix4f) Vector3f(org.terasology.math.geom.Vector3f) BaseVector3f(org.terasology.math.geom.BaseVector3f) Material(org.terasology.rendering.assets.material.Material) FloatBuffer(java.nio.FloatBuffer) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent) BaseQuat4f(org.terasology.math.geom.BaseQuat4f) Quat4f(org.terasology.math.geom.Quat4f)

Aggregations

EntityRef (org.terasology.entitySystem.entity.EntityRef)337 Test (org.junit.Test)106 ClientComponent (org.terasology.network.ClientComponent)49 LocationComponent (org.terasology.logic.location.LocationComponent)45 Vector3f (org.terasology.math.geom.Vector3f)44 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)36 Vector3i (org.terasology.math.geom.Vector3i)34 Command (org.terasology.logic.console.commandSystem.annotations.Command)28 StringComponent (org.terasology.entitySystem.stubs.StringComponent)26 NetworkComponent (org.terasology.network.NetworkComponent)21 EntityData (org.terasology.protobuf.EntityData)21 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)17 Block (org.terasology.world.block.Block)16 Component (org.terasology.entitySystem.Component)15 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)15 CharacterComponent (org.terasology.logic.characters.CharacterComponent)14 Quat4f (org.terasology.math.geom.Quat4f)14 BlockComponent (org.terasology.world.block.BlockComponent)13 Map (java.util.Map)11 LocalPlayer (org.terasology.logic.players.LocalPlayer)11