Search in sources :

Example 1 with NodeComponent

use of io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent in project nhglib by VoidZombie.

the class Main method onKeyInput.

@Override
public void onKeyInput(NhgInput input) {
    if (scene != null) {
        NodeComponent nodeComponent = cameraNode;
        switch(input.getName()) {
            case "strafeRight":
                nodeComponent.translate(0.1f * Gdx.graphics.getDeltaTime(), 0, 0);
                break;
            case "strafeLeft":
                nodeComponent.translate(-0.1f * Gdx.graphics.getDeltaTime(), 0, 0);
                break;
            case "forward":
                nodeComponent.translate(0, 0, -0.1f * Gdx.graphics.getDeltaTime());
                break;
            case "backward":
                nodeComponent.translate(0, 0, 0.1f * Gdx.graphics.getDeltaTime());
                break;
            case "jump":
                cameraNode.rotate(0, 0, 0.1f);
                break;
            case "sprint":
                cameraNode.rotate(0, 0, -0.1f);
                break;
            case "exit":
                nhg.messaging.send(new Message(Strings.Events.engineDestroy));
                break;
        }
        nodeComponent.applyTransforms();
    }
}
Also used : Message(io.github.voidzombie.nhglib.runtime.messaging.Message) NodeComponent(io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent)

Example 2 with NodeComponent

use of io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent in project nhglib by VoidZombie.

the class TestNodeSystem method process.

@Override
protected void process(int entityId) {
    NodeComponent nodeComponent = nodeMapper.get(entityId);
    MessageComponent messageComponent = messageMapper.get(entityId);
    Array<Message> messages = messageComponent.getMessages();
    for (Message message : messages) {
        if (message.is("printNode")) {
            Logger.log(this, "id: %d, x: %f, y: %f, z: %f", nodeComponent.id, nodeComponent.getX(), nodeComponent.getY(), nodeComponent.getZ());
            messageComponent.consume(message);
        }
    }
}
Also used : Message(io.github.voidzombie.nhglib.runtime.messaging.Message) NodeComponent(io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent) MessageComponent(io.github.voidzombie.nhglib.runtime.ecs.components.common.MessageComponent)

Example 3 with NodeComponent

use of io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent in project nhglib by VoidZombie.

the class EntityJson method parse.

@Override
public void parse(JsonValue jsonValue) {
    String id = jsonValue.getString("id");
    int entity = sceneGraph.addSceneEntity(id, parentEntity);
    JsonValue componentsJson = jsonValue.get("components");
    for (JsonValue componentJsonValue : componentsJson) {
        String type = componentJsonValue.getString("type");
        ComponentJson componentJson = SceneUtils.componentJsonFromType(type);
        if (componentJson != null) {
            componentJson.entity = entity;
            componentJson.entities = entities;
            componentJson.parse(componentJsonValue);
        }
    }
    JsonValue entitiesJson = jsonValue.get("entities");
    if (entitiesJson != null) {
        for (JsonValue entityJsonValue : entitiesJson) {
            EntityJson entityJson = new EntityJson(entities);
            entityJson.sceneGraph = sceneGraph;
            entityJson.parentEntity = entity;
            entityJson.parse(entityJsonValue);
        }
    }
    TransformJson transformJson = new TransformJson();
    transformJson.parse(jsonValue.get("transform"));
    NodeComponent nodeComponent = entities.getComponent(entity, NodeComponent.class);
    nodeComponent.setTransform(transformJson.position, transformJson.rotation, transformJson.scale);
    output = entity;
}
Also used : JsonValue(com.badlogic.gdx.utils.JsonValue) NodeComponent(io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent)

Example 4 with NodeComponent

use of io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent in project nhglib by VoidZombie.

the class LargeWorldStrategy method update.

@Override
public void update(Scene scene, Bounds bounds, NodeComponent referenceNodeComponent) {
    if (referenceNodeComponent != null) {
        Bounds.Info boundsInfo = bounds.boundsInfo(referenceNodeComponent.getTranslation());
        if (!boundsInfo.inBounds) {
            NodeComponent rootNodeComponent = entities.getComponent(scene.sceneGraph.getRootEntity(), NodeComponent.class);
            float xTranslation = bounds.getWidth() * boundsInfo.widthSide;
            float yTranslation = bounds.getHeight() * boundsInfo.heightSide;
            float zTranslation = bounds.getDepth() * boundsInfo.depthSide;
            rootNodeComponent.translate(-xTranslation, -yTranslation, -zTranslation, true);
        }
    }
}
Also used : Bounds(io.github.voidzombie.nhglib.utils.data.Bounds) NodeComponent(io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent)

Example 5 with NodeComponent

use of io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent in project nhglib by VoidZombie.

the class SceneManager method unloadScene.

public void unloadScene(final Scene scene) {
    Observable.fromIterable(scene.sceneGraph.getEntities()).filter(new Predicate<Integer>() {

        @Override
        public boolean test(Integer entity) throws Exception {
            return modelMapper.has(entity);
        }
    }).doFinally(new Action() {

        @Override
        public void run() throws Exception {
            int rootEntity = scene.sceneGraph.getRootEntity();
            NodeComponent nodeComponent = nodeMapper.get(rootEntity);
            nodeComponent.setTranslation(0, 0, 0);
            nodeComponent.setRotation(0, 0, 0);
            nodeComponent.setScale(1, 1, 1);
            nodeComponent.applyTransforms();
        }
    }).subscribe(new Consumer<Integer>() {

        @Override
        public void accept(Integer integer) throws Exception {
            ModelComponent modelComponent = modelMapper.get(integer);
            assets.unloadAsset(modelComponent.asset);
        }
    });
}
Also used : Action(io.reactivex.functions.Action) ModelComponent(io.github.voidzombie.nhglib.runtime.ecs.components.graphics.ModelComponent) NodeComponent(io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent)

Aggregations

NodeComponent (io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent)13 JsonValue (com.badlogic.gdx.utils.JsonValue)3 ModelComponent (io.github.voidzombie.nhglib.runtime.ecs.components.graphics.ModelComponent)3 Message (io.github.voidzombie.nhglib.runtime.messaging.Message)3 Matrix4 (com.badlogic.gdx.math.Matrix4)2 Vector3 (com.badlogic.gdx.math.Vector3)2 Scene (io.github.voidzombie.nhglib.graphics.scenes.Scene)2 Bounds (io.github.voidzombie.nhglib.utils.data.Bounds)2 Camera (com.badlogic.gdx.graphics.Camera)1 FPSLogger (com.badlogic.gdx.graphics.FPSLogger)1 Environment (com.badlogic.gdx.graphics.g3d.Environment)1 Material (com.badlogic.gdx.graphics.g3d.Material)1 Model (com.badlogic.gdx.graphics.g3d.Model)1 ModelCache (com.badlogic.gdx.graphics.g3d.ModelCache)1 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)1 ImmediateModeRenderer20 (com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer20)1 Quaternion (com.badlogic.gdx.math.Quaternion)1 Vector2 (com.badlogic.gdx.math.Vector2)1 Asset (io.github.voidzombie.nhglib.assets.Asset)1 GammaCorrectionAttribute (io.github.voidzombie.nhglib.graphics.shaders.attributes.GammaCorrectionAttribute)1