Search in sources :

Example 21 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project nhglib by VoidZombie.

the class MessageComponentJson method parse.

@Override
public void parse(JsonValue jsonValue) {
    MessageComponent messageComponent = entities.createComponent(entity, MessageComponent.class);
    JsonValue filters = jsonValue.get("filters");
    messageComponent.subscribe(filters.asStringArray());
    output = messageComponent;
}
Also used : JsonValue(com.badlogic.gdx.utils.JsonValue) MessageComponent(io.github.voidzombie.nhglib.runtime.ecs.components.common.MessageComponent)

Example 22 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project nhglib by VoidZombie.

the class ModelComponentJson method parse.

@Override
public void parse(JsonValue jsonValue) {
    ModelComponent modelComponent = entities.createComponent(entity, ModelComponent.class);
    String type = jsonValue.getString("graphicsType");
    JsonValue asset = jsonValue.get("asset");
    boolean enabled = jsonValue.getBoolean("enabled", true);
    AssetJson assetJson = new AssetJson();
    assetJson.parse(asset);
    JsonValue materialsJson = jsonValue.get("materials");
    if (materialsJson != null) {
        for (JsonValue mat : materialsJson) {
            PbrMaterialJson pbrMaterialJson = new PbrMaterialJson();
            pbrMaterialJson.parse(mat);
            modelComponent.pbrMaterials.add(pbrMaterialJson.get());
        }
    }
    modelComponent.type = ModelComponent.Type.fromString(type);
    modelComponent.asset = assetJson.get();
    modelComponent.enabled = enabled;
    output = modelComponent;
}
Also used : PbrMaterialJson(io.github.voidzombie.nhglib.data.models.serialization.PbrMaterialJson) ModelComponent(io.github.voidzombie.nhglib.runtime.ecs.components.graphics.ModelComponent) JsonValue(com.badlogic.gdx.utils.JsonValue) AssetJson(io.github.voidzombie.nhglib.data.models.serialization.AssetJson)

Example 23 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project nhglib by VoidZombie.

the class InputJson method parse.

@Override
public void parse(JsonValue jsonValue) {
    JsonValue contextsJson = jsonValue.get("contexts");
    for (JsonValue contextJson : contextsJson) {
        String name = contextJson.getString("name");
        JsonValue inputsJson = contextJson.get("inputs");
        InputContext inputContext = new InputContext(name);
        for (JsonValue inputJson : inputsJson) {
            inputContext.addInput(inputFromJson(inputJson));
        }
        inputContexts.add(inputContext);
    }
}
Also used : JsonValue(com.badlogic.gdx.utils.JsonValue) InputContext(io.github.voidzombie.nhglib.input.models.InputContext)

Example 24 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project nhglib by VoidZombie.

the class PbrMaterialJson method parse.

@Override
public void parse(JsonValue jsonValue) {
    pbrMaterial = new PbrMaterial();
    pbrMaterial.targetNode = jsonValue.getString("targetNode", "");
    JsonValue albedoJson = jsonValue.get("albedo");
    JsonValue metalnessJson = jsonValue.get("metalness");
    JsonValue roughnessJson = jsonValue.get("roughness");
    JsonValue normalJson = jsonValue.get("normal");
    JsonValue ambientOcclusionJson = jsonValue.get("ambientOcclusion");
    TextureLoader.TextureParameter params = new TextureLoader.TextureParameter();
    params.minFilter = Texture.TextureFilter.MipMap;
    params.magFilter = Texture.TextureFilter.Linear;
    params.genMipMaps = true;
    if (albedoJson != null) {
        AssetJson albedoAssetJson = new AssetJson();
        albedoAssetJson.parse(albedoJson.get("asset"));
        pbrMaterial.albedoAsset = albedoAssetJson.get();
        pbrMaterial.albedoAsset.parameters = params;
    }
    if (metalnessJson != null) {
        AssetJson metalnessAssetJson = new AssetJson();
        metalnessAssetJson.parse(metalnessJson.get("asset"));
        pbrMaterial.metalnessAsset = metalnessAssetJson.get();
        pbrMaterial.metalnessAsset.parameters = params;
    }
    if (roughnessJson != null) {
        AssetJson roughnessAssetJson = new AssetJson();
        roughnessAssetJson.parse(roughnessJson.get("asset"));
        pbrMaterial.roughnessAsset = roughnessAssetJson.get();
        pbrMaterial.roughnessAsset.parameters = params;
    }
    if (normalJson != null) {
        AssetJson normalAssetJson = new AssetJson();
        normalAssetJson.parse(normalJson.get("asset"));
        pbrMaterial.normalAsset = normalAssetJson.get();
        pbrMaterial.normalAsset.parameters = params;
    }
    if (ambientOcclusionJson != null) {
        AssetJson ambientOcclusionAssetJson = new AssetJson();
        ambientOcclusionAssetJson.parse(ambientOcclusionJson.get("asset"));
        pbrMaterial.ambientOcclusionAsset = ambientOcclusionAssetJson.get();
        pbrMaterial.ambientOcclusionAsset.parameters = params;
    }
}
Also used : TextureLoader(com.badlogic.gdx.assets.loaders.TextureLoader) JsonValue(com.badlogic.gdx.utils.JsonValue) PbrMaterial(io.github.voidzombie.nhglib.graphics.utils.PbrMaterial)

Example 25 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project nhglib by VoidZombie.

the class Main method engineStarted.

@Override
public void engineStarted() {
    super.engineStarted();
    Nhg.debugLogs = true;
    Gdx.input.setCursorCatched(true);
    world = new NhgWorld(nhg.messaging, nhg.entities, nhg.assets, new DefaultWorldStrategy(), new Bounds(2f, 2f, 2f));
    fpsLogger = new FPSLogger();
    renderer20 = new ImmediateModeRenderer20(false, true, 0);
    nhg.input.addListener(this);
    nhg.assets.queueAsset(new Asset("scene", "myscene.nhs", Scene.class));
    nhg.assets.queueAsset(new Asset("inputMap", "input.nhc", JsonValue.class));
    GraphicsSystem graphicsSystem = nhg.entities.getEntitySystem(GraphicsSystem.class);
    graphicsSystem.setClearColor(Color.GRAY);
    Environment environment = graphicsSystem.getEnvironment();
    GammaCorrectionAttribute gammaCorrectionAttribute = new GammaCorrectionAttribute();
    gammaCorrectionAttribute.gammaCorrection = true;
    environment.set(gammaCorrectionAttribute);
    // Subscribe to asset events
    nhg.messaging.get(Strings.Events.assetLoaded, Strings.Events.assetLoadingFinished).subscribe(new Consumer<Message>() {

        @Override
        public void accept(Message message) throws Exception {
            if (message.is(Strings.Events.assetLoaded)) {
                Asset asset = (Asset) message.data.get(Strings.Defaults.assetKey);
                if (asset.is("scene")) {
                    scene = nhg.assets.get(asset);
                    world.loadScene(scene);
                    world.setReferenceEntity("camera");
                    ModelBuilder mb = new ModelBuilder();
                    Model planeModel = mb.createBox(2f, 0.01f, 20f, new Material(), VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal | VertexAttributes.Usage.TextureCoordinates);
                    int plane = scene.sceneGraph.createSceneEntity("plane");
                    scene.sceneGraph.addSceneEntity(plane);
                    ModelComponent modelComponent = nhg.entities.createComponent(plane, ModelComponent.class);
                    modelComponent.initWithModel(planeModel);
                    NodeComponent nodeComponent = nhg.entities.getComponent(plane, NodeComponent.class);
                    nodeComponent.setTranslation(0, 0, 0, true);
                    Integer cameraEntity = scene.sceneGraph.getSceneEntity("camera");
                    cameraNode = nhg.entities.getComponent(cameraEntity, NodeComponent.class);
                } else if (asset.is("inputMap")) {
                    nhg.input.fromJson((JsonValue) nhg.assets.get(asset));
                    nhg.input.setActiveContext("game", true);
                    nhg.input.setActiveContext("global", true);
                }
            }
        }
    });
}
Also used : NhgWorld(io.github.voidzombie.nhglib.graphics.worlds.NhgWorld) Message(io.github.voidzombie.nhglib.runtime.messaging.Message) GammaCorrectionAttribute(io.github.voidzombie.nhglib.graphics.shaders.attributes.GammaCorrectionAttribute) Bounds(io.github.voidzombie.nhglib.utils.data.Bounds) JsonValue(com.badlogic.gdx.utils.JsonValue) Material(com.badlogic.gdx.graphics.g3d.Material) Scene(io.github.voidzombie.nhglib.graphics.scenes.Scene) FPSLogger(com.badlogic.gdx.graphics.FPSLogger) ImmediateModeRenderer20(com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer20) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) ModelComponent(io.github.voidzombie.nhglib.runtime.ecs.components.graphics.ModelComponent) DefaultWorldStrategy(io.github.voidzombie.nhglib.graphics.worlds.strategies.impl.DefaultWorldStrategy) Model(com.badlogic.gdx.graphics.g3d.Model) NodeComponent(io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent) Asset(io.github.voidzombie.nhglib.assets.Asset) GraphicsSystem(io.github.voidzombie.nhglib.runtime.ecs.systems.impl.GraphicsSystem) Environment(com.badlogic.gdx.graphics.g3d.Environment)

Aggregations

JsonValue (com.badlogic.gdx.utils.JsonValue)25 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)7 Array (com.badlogic.gdx.utils.Array)5 Color (com.badlogic.gdx.graphics.Color)3 Environment (com.badlogic.gdx.graphics.g3d.Environment)3 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)3 Matrix4 (com.badlogic.gdx.math.Matrix4)3 Vector3 (com.badlogic.gdx.math.Vector3)3 FileHandle (com.badlogic.gdx.files.FileHandle)2 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)2 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)2 Quaternion (com.badlogic.gdx.math.Quaternion)2 Json (com.badlogic.gdx.utils.Json)2 ReadOnlySerializer (com.badlogic.gdx.utils.Json.ReadOnlySerializer)2 SerializationException (com.badlogic.gdx.utils.SerializationException)2 ReflectionException (com.badlogic.gdx.utils.reflect.ReflectionException)2 ArrayListGameObject (com.nilunder.bdx.GameObject.ArrayListGameObject)2 ModelComponent (io.github.voidzombie.nhglib.runtime.ecs.components.graphics.ModelComponent)2 NodeComponent (io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent)2 GraphicsSystem (io.github.voidzombie.nhglib.runtime.ecs.systems.impl.GraphicsSystem)2