package com.graphicsengine.io;

import java.io.IOException;
import java.io.Reader;

import com.google.gson.Gson;
import com.graphicsengine.exporter.GraphicsEngineNodeExporter;
import com.graphicsengine.geometry.GraphicsEngineMeshFactory;
import com.graphicsengine.scene.GraphicsEngineNodeFactory;
import com.graphicsengine.scene.GraphicsEngineNodeType;
import com.nucleus.geometry.MeshFactory;
import com.nucleus.io.GSONSceneFactory;
import com.nucleus.scene.Node;
import com.nucleus.scene.NodeFactory;
import com.nucleus.scene.RootNode;

/**
 * Implementation of the scenefactory for the graphics engine, this shall take care of all nodes/datatypes that
 * are specific for the graphics engine.
 * 
 * @author Richard Sahlin
 *
 */
public class GSONGraphicsEngineFactory extends GSONSceneFactory {

    @Override
    protected RootNode getSceneFromJson(Gson gson, Reader reader) {
        return gson.fromJson(reader, GraphicsEngineRootNode.class);
    }

    @Override
    protected RootNode createSceneData() {
        return new GraphicsEngineRootNode();
    }

    @Override
    protected void createNodeExporter() {
        nodeExporter = new GraphicsEngineNodeExporter();
    }

    @Override
    protected void registerNodeExporters() {
        super.registerNodeExporters();
        nodeExporter.registerNodeExporter(GraphicsEngineNodeType.values(), new GraphicsEngineNodeExporter());
    }

    @Override
    protected Node createNode(RootNode scene, Node source, Node parent) throws IOException {
        Node created = nodeFactory.create(renderer, source, meshFactory, scene);
        setViewFrustum(source, created);
        createChildNodes(scene, source, created);
        created.onCreated();
        return created;
    }

    /**
     * Utility method to get the default nodefactory
     * 
     * @return
     */
    public static NodeFactory getNodeFactory() {
        return new GraphicsEngineNodeFactory();
    }

    public static MeshFactory getMeshFactory() {
        return new GraphicsEngineMeshFactory();
    }

}

@@ -102,24 +102,60 @@
 .gson.Gson;%0A
+import com.google.gson.GsonBuilder;%0A
 import com.g
@@ -259,32 +259,84 @@
 ineMeshFactory;%0A
+import com.graphicsengine.io.gson.NodeDeserializer;%0A
 import com.graph
@@ -881,16 +881,89 @@
 tory %7B%0A%0A
+    private NodeDeserializer nodeDeserializer = new NodeDeserializer();%0A%0A
     @Ove
@@ -2194,10 +2194,324 @@
 %0A    %7D%0A%0A
+    @Override%0A    protected void registerTypeAdapter(GsonBuilder builder) %7B%0A        super.registerTypeAdapter(builder);%0A        builder.registerTypeAdapter(Node.class, nodeDeserializer);%0A    %7D%0A%0A    protected void setGson(Gson gson) %7B%0A        super.setGson(gson);%0A        nodeDeserializer.setGson(gson);%0A    %7D%0A    %0A
 %7D%0A

Add method to register type adapter