Search in sources :

Example 1 with JsonReader

use of com.badlogic.gdx.utils.JsonReader in project libgdx by libgdx.

the class ImportTest method create.

@Override
public void create() {
    super.create();
    ModelLoader g3djLoader = new G3dModelLoader(new JsonReader());
    model = g3djLoader.loadModel(Gdx.files.internal("data/g3d/btscene1.g3dj"));
    disposables.add(model);
    importer = new MyImporter((btDynamicsWorld) world.collisionWorld);
    importer.loadFile(Gdx.files.internal("data/g3d/btscene1.bullet"));
    camera.position.set(10f, 15f, 20f);
    camera.up.set(0, 1, 0);
    camera.lookAt(-10, 8, 0);
    camera.update();
}
Also used : ModelLoader(com.badlogic.gdx.assets.loaders.ModelLoader) G3dModelLoader(com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader) com.badlogic.gdx.physics.bullet.dynamics.btDynamicsWorld(com.badlogic.gdx.physics.bullet.dynamics.btDynamicsWorld) G3dModelLoader(com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader) JsonReader(com.badlogic.gdx.utils.JsonReader)

Example 2 with JsonReader

use of com.badlogic.gdx.utils.JsonReader in project bdx by GoranM.

the class Mesh method copy.

public Mesh copy(String newName) {
    Model uniqueModel = scene.createModel(new JsonReader().parse(serialized()));
    Mesh newMesh = new Mesh(uniqueModel, scene, newName);
    newMesh.materials.clear();
    for (NodePart part : uniqueModel.nodes.get(0).parts) {
        // Don't forget to cast to Material for it to be a true copy (see shader copying)
        Material newMat = new Material((Material) part.material);
        newMesh.materials.add(newMat);
        part.material = newMat;
    }
    return newMesh;
}
Also used : Model(com.badlogic.gdx.graphics.g3d.Model) JsonReader(com.badlogic.gdx.utils.JsonReader) NodePart(com.badlogic.gdx.graphics.g3d.model.NodePart)

Example 3 with JsonReader

use of com.badlogic.gdx.utils.JsonReader in project skin-composer by raeleus.

the class DialogFonts method initialize.

public void initialize(Main main, EventListener listener) {
    this.main = main;
    maxTextureWidth = 1024;
    maxTextureHeight = 1024;
    // extract max texture dimensions from defaults.json
    FileHandle defaultsFile = Gdx.files.local("texturepacker/defaults.json");
    if (defaultsFile.exists()) {
        JsonReader reader = new JsonReader();
        JsonValue val = reader.parse(defaultsFile);
        for (JsonValue child : val.iterator()) {
            if (child.name.equals("maxWidth") && child.isNumber()) {
                maxTextureWidth = child.asInt();
            } else if (child.name.equals("maxHeight") && child.isNumber()) {
                maxTextureHeight = child.asInt();
            }
        }
    }
    this.listener = listener;
    fonts = main.getJsonData().getFonts();
    freeTypeFonts = main.getJsonData().getFreeTypeFonts();
    drawables = main.getAtlasData().getDrawables();
    fontMap = new ObjectMap<>();
    produceAtlas();
    filesDroppedListener = (Array<FileHandle> files) -> {
        Iterator<FileHandle> iter = files.iterator();
        while (iter.hasNext()) {
            FileHandle file = iter.next();
            if (file.isDirectory() || !file.name().toLowerCase().endsWith(".fnt")) {
                iter.remove();
            }
        }
        if (files.size > 0) {
            fontNameDialog(files, 0);
        }
    };
    main.getDesktopWorker().addFilesDroppedListener(filesDroppedListener);
    populate();
}
Also used : Array(com.badlogic.gdx.utils.Array) FileHandle(com.badlogic.gdx.files.FileHandle) JsonValue(com.badlogic.gdx.utils.JsonValue) JsonReader(com.badlogic.gdx.utils.JsonReader)

Example 4 with JsonReader

use of com.badlogic.gdx.utils.JsonReader in project bladecoder-adventure-engine by bladecoder.

the class World method loadWorldDesc.

/**
 * Load the world description in 'world.json'.
 *
 * @throws IOException
 */
public void loadWorldDesc() throws IOException {
    String worldFilename = EngineAssetManager.WORLD_FILENAME;
    if (!EngineAssetManager.getInstance().getModelFile(worldFilename).exists()) {
        // Search the world file with ".json" ext if not found.
        worldFilename = EngineAssetManager.WORLD_FILENAME + ".json";
        if (!EngineAssetManager.getInstance().getModelFile(worldFilename).exists()) {
            EngineLogger.error("ERROR LOADING WORLD: world file not found.");
            dispose();
            throw new IOException("ERROR LOADING WORLD: world file not found.");
        }
    }
    SerializationHelper.getInstance().setMode(Mode.MODEL);
    JsonValue root = new JsonReader().parse(EngineAssetManager.getInstance().getModelFile(worldFilename).reader("UTF-8"));
    Json json = new Json();
    json.setIgnoreUnknownFields(true);
    int width = json.readValue("width", Integer.class, root);
    int height = json.readValue("height", Integer.class, root);
    // We know the world width, so we can set the scale
    EngineAssetManager.getInstance().setScale(width, height);
    float scale = EngineAssetManager.getInstance().getScale();
    setWidth((int) (width * scale));
    setHeight((int) (height * scale));
    setInitChapter(json.readValue("initChapter", String.class, root));
    verbs.read(json, root);
    I18N.loadWorld(EngineAssetManager.MODEL_DIR + EngineAssetManager.WORLD_FILENAME);
}
Also used : JsonValue(com.badlogic.gdx.utils.JsonValue) JsonReader(com.badlogic.gdx.utils.JsonReader) IOException(java.io.IOException) Json(com.badlogic.gdx.utils.Json)

Example 5 with JsonReader

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

the class SceneLoader method getScene.

private Scene getScene(byte[] bytes) {
    Scene scene = null;
    try {
        String json = new String(bytes, "UTF-8");
        SceneJson sceneJson = new SceneJson(entities);
        sceneJson.parse(new JsonReader().parse(json).get("scene"));
        scene = sceneJson.get();
    } catch (UnsupportedEncodingException e) {
        if (Nhg.debugLogs)
            e.printStackTrace();
    }
    return scene;
}
Also used : SceneJson(io.github.voidzombie.nhglib.data.models.serialization.SceneJson) JsonReader(com.badlogic.gdx.utils.JsonReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Scene(io.github.voidzombie.nhglib.graphics.scenes.Scene)

Aggregations

JsonReader (com.badlogic.gdx.utils.JsonReader)12 JsonValue (com.badlogic.gdx.utils.JsonValue)9 Json (com.badlogic.gdx.utils.Json)5 IOException (java.io.IOException)4 FileHandle (com.badlogic.gdx.files.FileHandle)2 Array (com.badlogic.gdx.utils.Array)2 ModelLoader (com.badlogic.gdx.assets.loaders.ModelLoader)1 com.badlogic.gdx.graphics (com.badlogic.gdx.graphics)1 Color (com.badlogic.gdx.graphics.Color)1 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)1 Environment (com.badlogic.gdx.graphics.g3d.Environment)1 Model (com.badlogic.gdx.graphics.g3d.Model)1 G3dModelLoader (com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader)1 NodePart (com.badlogic.gdx.graphics.g3d.model.NodePart)1 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)1 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)1 Matrix4 (com.badlogic.gdx.math.Matrix4)1 Vector3 (com.badlogic.gdx.math.Vector3)1 com.badlogic.gdx.physics.bullet.dynamics.btDynamicsWorld (com.badlogic.gdx.physics.bullet.dynamics.btDynamicsWorld)1 TintedDrawable (com.badlogic.gdx.scenes.scene2d.ui.Skin.TintedDrawable)1