Index: js/viewer-f0/css/styles.css
===================================================================
--- js/viewer-f0/css/styles.css	(revision 173)
+++ js/viewer-f0/css/styles.css	(revision 188)
@@ -1,6 +1,4 @@
-#menu{
-    display: inline;
-    position: fixed;
-    left: 1050px;
+.menu{
+    float: right;
 }
 
@@ -16,2 +14,7 @@
     width: 400px;
 }
+
+.window{
+    height: 600px;
+    width: 1300px;
+}
Index: js/viewer-f0/f0def.xml
===================================================================
--- js/viewer-f0/f0def.xml	(revision 173)
+++ js/viewer-f0/f0def.xml	(revision 188)
@@ -3,9 +3,9 @@
 
  <CLASS ID="m" NAME="Model">
-    <GROUP NAME="Properties" />
-    <GROUP NAME="Visual" />
-    <PROP ID="se" NAME="startenergy" GROUP="0" FLAGS="1024" TYPE="f" />
-    <PROP ID="Vstyle" NAME="vis_style" GROUP="1" FLAGS="0" TYPE="s" MIN="0" MAX="-1" />
-</CLASS>
+  <GROUP NAME="Properties" />
+  <GROUP NAME="Visual" />
+  <PROP ID="se" NAME="startenergy" GROUP="0" FLAGS="1024" TYPE="f" />
+  <PROP ID="Vstyle" NAME="vis_style" GROUP="1" FLAGS="0" TYPE="s" MIN="0" MAX="-1" />
+ </CLASS>
 
  <CLASS ID="p" NAME="Part">
Index: js/viewer-f0/index.html
===================================================================
--- js/viewer-f0/index.html	(revision 173)
+++ js/viewer-f0/index.html	(revision 188)
@@ -19,18 +19,64 @@
 <script src="js/SmartLayout.js"></script>
 <script src="js/Structures/NeuroClass.js"></script>
-<script src="js/main.js"></script>
+<script src="js/Viewer.js"></script>
+
+<div class="window">
+    <div class="cont" id="container"></div>
+    <div class="cont" id="containerNeuron"></div>
+
+    <div class="menu">
+        <textarea id="geno">//0&#13;&#10;p:</textarea>
+
+        <div><input type="checkbox" id="axisBox"> Show axis for parts </input></div>
+        <div id="test">
+            <!-- Wywołanie openEmbeddedCreature z Viewer.js-->
+            <button onclick="openTextAreaCreature()">Render</button>
+        </div>
+    </div>
+</div>
+
+<div class="window">
+    <div class="cont" id="container1"></div>
+    <div class="cont" id="containerNeuron1"></div>
+
+    <div class="menu">
+        <div><input type="checkbox" id="axisBox1"> Show axis for parts </input></div>
+        <div id="test1">
+
+            <button onclick="openEmbeddedCreature()">Render</button>
+        </div>
+    </div>
+</div>
 
 
-<div class="cont" id="container"></div>
-<div class="cont" id="containerNeuron"></div>
+</body>
 
-<div id="menu">
-    <textarea id="geno">//0&#13;&#10;p:</textarea>
-    <div><input type="checkbox" id="axisBox"> Show axis for parts </input></div>
-    <div id="test">
-        <!-- Wywołanie openWindow z main.js-->
-        <button onclick="openWindow()">Render</button>
+<div class="window">
+    <div class="cont" id="container2"></div>
+    <div class="cont" id="containerNeuron2"></div>
+
+    <div class="menu">
+        <div><input type="checkbox" id="axisBox2"> Show axis for parts </input></div>
+        <div id="test2">
+
+            <button onclick="openCodeCreature()">Render</button>
+        </div>
     </div>
+</div>
 
+
+</body>
+
+<div class="window">
+    <div class="cont" id="container3"></div>
+    <div class="cont" id="containerNeuron3"></div>
+
+    <div class="menu">
+        <div><input type="checkbox" id="axisBox3"> Show axis for parts </input></div>
+        <div id="test3">
+
+            <button onclick="openFileCreature()">Render</button>
+        </div>
+    </div>
 </div>
 
Index: js/viewer-f0/js/NeuronDrawer.js
===================================================================
--- js/viewer-f0/js/NeuronDrawer.js	(revision 173)
+++ js/viewer-f0/js/NeuronDrawer.js	(revision 188)
@@ -1,9 +1,9 @@
-function NeuronDrawer() {
+function NeuronDrawer(context) {
     this._scene = undefined;
     this._camera = undefined;
     this._renderer = undefined;
-    this._canvasWidth = 500;
-    this._canvasHeight = 500;
-    this._containerContext = undefined;
+    this._canvasWidth = 400;
+    this._canvasHeight = 400;
+    this._containerContext = context;
     this._controls = undefined;
     this._showAxis = false;
@@ -12,6 +12,64 @@
     this._inputonly_symbol=[1,5, 25,40, 35,40, 45,50, 35,60, 25,60, 25,40];
     this._outputonly_symbol=[1,7, 75,50, 75,60, 55,60, 65,50, 55,40, 75,40, 75,50, 100,50];
-
-}
+    this._canvas = undefined;
+    this._neurons = undefined;
+}
+
+NeuronDrawer.prototype.initialize = function () {
+
+
+    //this._canvas = document.getElementById("containerNeuron");
+    /*
+    if (this._canvas.getContext){
+
+        // use getContext to use the canvas for drawing
+        var ctx = this._canvas.getContext('2d');
+
+        var lastX=this._canvas.width/2, lastY=this._canvas.height/2;
+        var dragStart,dragged;
+        this._canvas.addEventListener('mousedown',function(evt){
+            document.body.style.mozUserSelect = document.body.style.webkitUserSelect = document.body.style.userSelect = 'none';
+            lastX = evt.offsetX || (evt.pageX - canvas.offsetLeft);
+            lastY = evt.offsetY || (evt.pageY - canvas.offsetTop);
+            dragStart = ctx.transformedPoint(lastX,lastY);
+            dragged = false;
+        },false);
+
+        this._canvas.addEventListener('mousemove',function(evt){
+            lastX = evt.offsetX || (evt.pageX - this._canvas.offsetLeft);
+            lastY = evt.offsetY || (evt.pageY - this._canvas.offsetTop);
+            dragged = true;
+            if (dragStart){
+                var pt = ctx.transformedPoint(lastX,lastY);
+                ctx.translate(pt.x-dragStart.x,pt.y-dragStart.y);
+                redraw();
+            }
+        },false);
+        this._canvas.addEventListener('mouseup',function(evt){
+            dragStart = null;
+            if (!dragged) zoom(evt.shiftKey ? -1 : 1 );
+        },false);
+
+        // Filled triangle
+        ctx.beginPath();
+        ctx.moveTo(25,25);
+        ctx.lineTo(105,25);
+        ctx.lineTo(25,105);
+        ctx.fill();
+
+        // Stroked triangle
+        ctx.beginPath();
+        ctx.moveTo(125,125);
+        ctx.lineTo(125,45);
+        ctx.lineTo(45,125);
+        ctx.closePath();
+        ctx.stroke();
+
+    }
+    else
+        alert("dupa");
+    //this._debug();*/
+}
+
 
 NeuronDrawer.prototype.showPartAxis = function () {
@@ -23,5 +81,5 @@
     this._renderer.setClearColor(0xffffff, 1);
     this._renderer.setSize(this._canvasWidth, this._canvasHeight);
-    this._containerContext = $("#containerNeuron");
+    //this._containerContext = $("#containerNeuron");
     this._containerContext.append(this._renderer.domElement);
 }
@@ -126,7 +184,18 @@
 }
 
-NeuronDrawer.prototype.drawConnection = function (id, connections, einfos) {
-
-    var destination = connections[id].getDestination();
+NeuronDrawer.prototype.drawConnection = function (id, neurons, connections, einfos) {
+
+    var n2;
+
+    for(var iw = 0; iw < this._getNumberOfInputs(id,connections); iw++)
+    {
+        n2 = neurons[iw];
+
+        var yw = this._inputY(iw);
+        var xw = yw / 4;
+        this._drawLine()
+    }
+    
+    /*var destination = connections[id].getDestination();
     var numberOfConnToDest = 0;
     var numberOfDrawenCon = 0;
@@ -253,7 +322,26 @@
         //g.drawLine((int) ((10 + polozenieX + (x1 * 100)) * zoom), (int) ((10 + polozenieY + y1 * 100) * zoom), (int) ((10 + polozenieX + (x1 * 100)) * zoom), (int) ((15 + y2 * 100) * zoom));
     }
-
-}
-
+*/
+}
+
+NeuronDrawer.prototype._inputY = function(number, connections){
+    return (1 + number)*this._neurons[number].sizeY / ((this._getNumberOfInputs(number, connections)) + 1);
+}
+
+NeuronDrawer.prototype._drawLine = function(x1, y1, x2, y2){
+    var geometry = new THREE.Geometry();
+    geometry.vertices.push(new THREE.Vector3(x1, y1, 0));
+    geometry.vertices.push(new THREE.Vector3(x2, y2, 0));
+
+    var material = new THREE.LineBasicMaterial({
+        color: 0x0000ff
+    });
+
+    var SCALE = 1;
+
+    var line = new THREE.Line(geometry, material);
+    line.scale.set(SCALE, SCALE, SCALE);
+    this._scene.add(line);
+}
 
 NeuronDrawer.prototype._chooseSchema = function(number, neurons, connections, classes)
@@ -278,5 +366,40 @@
 }
 
+NeuronDrawer.prototype._getSize = function(scheme)
+{
+    var neuron = {sizeX: 0, sizeY: 0};
+    var position = 0;
+    var noOfBlocks = 0;//number of "blocks" to draw
+    var noOfLines = 0;//number of line to draw
+    noOfBlocks = scheme[position++];
+    for (var i = 0; i < noOfBlocks; i++) {
+        noOfLines = scheme[position++];
+
+        for (var j = 0; j < noOfLines; j++) {
+
+            if(scheme[position] > neuron.sizeX)
+                neuron.sizeX = scheme[position];
+            position++;
+            if(scheme[position] > neuron.sizeY)
+                neuron.sizeY = scheme[position];
+            position++;
+
+            if(scheme[position] > neuron.sizeX)
+                neuron.sizeX = scheme[position];
+            position++;
+            if(scheme[position] > neuron.sizeY)
+                neuron.sizeY = scheme[position];
+            position++;
+
+            position = position - 2;
+        }
+        position = position + 2;//move to value which define number of lines to draw
+    }
+    return neuron;
+}
+
 NeuronDrawer.prototype.drawNetwork = function (neurons, connections, layouts, classes) {
+
+    this._neurons = [];
 
     for (var i = 0; i < layouts.length; i++) {
@@ -284,10 +407,12 @@
 
         scheme = this._chooseSchema(i,neurons, connections, classes)
-
+        var neuronData = this._getSize(scheme);
+        neuronData.scheme = scheme;
+        this._neurons.push(neuronData);
         this.drawNeuron(layouts[i].x * 100  , -layouts[i].y * 100 , scheme);
     }
 
     //for (var i = 0; i < connections.length; i++)
-    //    this.drawConnection(i, connections, einfos);
+    //    this.drawConnection(i, neurons, connections, einfos);
 }
 
Index: js/viewer-f0/js/SmartLayout.js
===================================================================
--- js/viewer-f0/js/SmartLayout.js	(revision 173)
+++ js/viewer-f0/js/SmartLayout.js	(revision 188)
@@ -151,7 +151,4 @@
 }
 
-
-
-
 function canMerge(block, block2, dx, dy){
     var x1, y1, x2, y2;
Index: js/viewer-f0/js/Viewer.js
===================================================================
--- js/viewer-f0/js/Viewer.js	(revision 188)
+++ js/viewer-f0/js/Viewer.js	(revision 188)
@@ -0,0 +1,303 @@
+function Viewer() {
+    this.Mode = {
+        LINK: 0,
+        EMBEDDED: 1,
+        TEXTAREA: 2,
+        CODE: 3
+    };
+
+    this._showNeurons = true;
+    this._showVisualization = true;
+    this._visualizationContext = undefined;
+    this._neuronsContext = undefined;
+    this._context = undefined;
+    this._urlToXML = "f0def.xml";//"http://www.framsticks.com/files/apps/config/f0def.xml";
+    this._xml = undefined;
+    this._model = new Model();
+    this._part = new Part();
+    this._joint = new Joint();
+    this._neuro = new Neuro();
+    this._neuroConn = new NeuroConn();
+    this._parts = [];
+    this._joints = [];
+    this._neurons = [];
+    this._neuroConns = [];
+    this._neuroClasses = {};
+    this._modelOne = undefined;
+    this._graphicsEngine = undefined;
+    this._neuronDrawer = undefined;
+    this.downloadXML();
+    this.parseGeneXml();
+}
+
+Viewer.prototype.showVisualization = function(value, context){
+    this._showVisualization = value;
+    this._visualizationContext = context;
+}
+
+Viewer.prototype.showNeuron = function(value, context)
+{
+     this._showNeurons = true;
+     this._neuronsContext = context;
+}
+
+Viewer.prototype.downloadXML = function () {
+    var local = this;
+    $.ajax({
+        url: local._urlToXML,
+        dataType: "xml",
+        async: false,
+        success: function (xml) {
+            var xmlDoc = $.parseXML(xml);
+            $xml = $(xmlDoc);
+            local._xml = $(xml);
+        },
+        error: function () {
+            alert("Can't download file f0def.xml");
+        }
+    })
+};
+
+Viewer.prototype.parseGeneXml = function () {
+    this._parseClass($(this._xml.find("CLASS")));
+    this._parseNeuroClass($(this._xml.find("NEUROCLASS")))
+};
+
+Viewer.prototype._parseClass = function (nodes) {
+    var local = this;
+
+    nodes.each(function (entry) {
+        var node = $(nodes[entry]);
+
+        if (node.attr("NAME") == "Model") {
+            local._model.setModel(node);
+        }
+        else if (node.attr("NAME") == "Part")
+            local._part.setModel(node);
+        else if (node.attr("NAME") == "Joint")
+            local._joint.setModel(node);
+        else if (node.attr("NAME") == "Neuro")
+            local._neuro.setModel(node);
+        else if (node.attr("NAME") == "NeuroConn")
+            local._neuroConn.setModel(node);
+        else {
+            console.log("Could not recognize NAME:", node.attr("NAME"));
+        }
+
+    });
+};
+
+Viewer.prototype._parseNeuroClass = function (data) {
+
+    for (var i = 0; i < data.length; i++) {
+        var neuroClass = new NeuroClass();
+        this._neuroClasses[data[i].attributes[0].value] = neuroClass;
+        neuroClass.setModel(data);
+    }
+
+};
+
+Viewer.prototype.analyseLine = function (line) {
+    //ignore comment
+    if (line[0] == '#' || line == "")
+        return;
+
+    var object;
+    var type = line[0];
+    if (type == "p") {
+        object = $.extend(true, {}, this._part);
+        this._parts.push(object);
+    }
+    else if (type == "j") {
+        object = $.extend(true, {}, this._joint);
+        this._joints.push(object);
+    }
+    else if (type == "n") {
+        object = $.extend(true, {}, this._neuro);
+        this._neurons.push(object);
+    }
+    else if (type == "c") {
+        object = $.extend(true, {}, this._neuroConn);
+        this._neuroConns.push(object);
+    }
+    else if (type == "m") {
+        object = $.extend(true, {}, this._model);
+        this._modelOne = object;
+    }
+    else
+        throw new Error("Undefined element: \"" + type + "\"");
+
+    //remove char and ":"
+    line = line.substring(2);
+    var lines = line.match(/([^,"]+|"[^"]+")+/g);
+
+    if (lines != null)
+        lines.forEach(function (value) {
+            value = value.trim();
+            if (value == "")
+                object.setValue();
+            else if (value.indexOf("=") == -1) {
+                object.setValue(value);
+            }
+            else {
+                var name = value.substring(0, value.indexOf("="));
+                var val = value.substring(value.indexOf("=") + 1);
+                object.setValue(name, val);
+            }
+        })
+};
+
+Viewer.prototype.getCreature = function (mode, content) {
+
+    var lines = undefined;
+    if (mode == this.Mode.LINK)
+        lines = this._getCreatureFromLink(content);
+    else if (mode == this.Mode.EMBEDDED)
+        lines = this._getCreatureFromEmbeddedCode(content);
+    else if (mode == this.Mode.TEXTAREA)
+        lines = this._getCreatureFromTextArea(content);
+    else if (mode == this.Mode.CODE)
+        lines = this._getCreatureFromCode(content);
+    else {
+        throw "Wrong mode in function getCreature";
+    }
+    return lines;
+};
+
+
+Viewer.prototype._getCreatureFromLink = function (link) {
+    var lines = undefined;
+    $.ajax({
+        url: link,
+        async: false,
+        dataType: "text",
+        success: function (data) {
+            lines = data.split("\n");
+
+        },
+        error: function () {
+            alert("Can't download creature");
+        }
+    });
+    return lines;
+};
+
+Viewer.prototype._getCreatureFromTextArea = function (area) {
+    var lines = undefined;
+    lines = area.val();
+    lines = lines.split("\n");
+    return lines;
+};
+
+Viewer.prototype._getCreatureFromCode = function (code) {
+    var lines = code;
+    lines = lines.split("\n");
+    return lines;
+};
+
+Viewer.prototype._getCreatureFromEmbeddedCode = function (link) {
+    var lines = undefined;
+
+    $.ajax({
+        url: link,
+        async: false,
+        dataType: "html",
+        success: function (data) {
+            var geno = $($(data).find("div")[0]).comments().html();
+            geno = geno.replace("FRED_GEN", "");
+            lines = geno.split("\n");
+        },
+        error: function () {
+            alert("Can't download creature");
+        }
+    });
+
+    return lines;
+};
+
+Viewer.prototype.parseCreature = function (mode, content) {
+    var lines = this.getCreature(mode, content);
+    lines.splice(0, 1);
+    var local = this;
+    lines.forEach(function (value) {
+        local.analyseLine(value);
+    });
+};
+
+Viewer.prototype.renderCreature = function () {
+
+    if ($("#axisBox").is(":checked"))
+        this._graphicsEngine.showPartAxis();
+
+    for (var i = 0; i < this._parts.length; i++)
+        this._graphicsEngine.addPart(this._parts[i])
+
+    for (var i = 0; i < this._joints.length; i++) {
+        this._graphicsEngine.addJoint(this._joints[i]);
+    }
+
+};
+
+Viewer.prototype.mainLoop = function () {
+    this._graphicsEngine.initializeScene();
+    this.renderCreature();
+    this._graphicsEngine.debugTest();
+    this._graphicsEngine.renderScene();
+
+    this._neuronDrawer.initializeScene();
+    new SmartLayout(this._neurons, this._neuroConns);
+    this._neuronDrawer.drawNetwork(this._neurons, this._neuroConns, einfos, this._neuroClasses);
+    this._neuronDrawer.renderScene();
+
+};
+
+Viewer.prototype.run = function (mode, content) {
+    this.parseCreature(mode, content);
+
+    if (this._showVisualization) {
+        this._graphicsEngine = new GraphicsEngine(this._visualizationContext)
+        this._graphicsEngine.initializeScene();
+        this.renderCreature();
+        this._graphicsEngine.debugTest();
+        this._graphicsEngine.renderScene();
+    }
+    if (this._showNeurons) {
+        this._neuronDrawer = new NeuronDrawer(this._neuronsContext);
+        this._neuronDrawer.initializeScene();
+        new SmartLayout(this._neurons, this._neuroConns);
+        this._neuronDrawer.drawNetwork(this._neurons, this._neuroConns, einfos, this._neuroClasses);
+        this._neuronDrawer.renderScene();
+    }
+}
+
+function openTextAreaCreature() {
+    var viewer = new Viewer();
+
+    viewer.showVisualization(true, $("#container"));
+    viewer.showNeuron(true, $("#containerNeuron"));
+    viewer.run(viewer.Mode.TEXTAREA, $("#geno"));
+}
+
+function openEmbeddedCreature() {
+    var viewer = new Viewer();
+    viewer.showVisualization(true, $("#container1"));
+    viewer.showNeuron(true, $("#containerNeuron1"));
+    viewer.run(viewer.Mode.EMBEDDED, "http://ec.framsticks.com/www/index.php?PAGE=view_genotype&ID=55");
+}
+
+function openCodeCreature() {
+    var viewer = new Viewer();
+
+    viewer.showVisualization(true, $("#container2"));
+    viewer.showNeuron(true, $("#containerNeuron2"));
+    viewer.run(viewer.Mode.CODE, "//0\np:\np: x=1");
+}
+
+function openFileCreature() {
+    var viewer = new Viewer();
+
+    var debugCreatureName = "example4";
+    viewer.showVisualization(true, $("#container3"));
+    viewer.showNeuron(true, $("#containerNeuron3"));
+    viewer.run(viewer.Mode.LINK, "http://localhost:63343/FramestickFavi/creatures/" + debugCreatureName + ".txt");
+}
Index: js/viewer-f0/js/graphicsEngine.js
===================================================================
--- js/viewer-f0/js/graphicsEngine.js	(revision 173)
+++ js/viewer-f0/js/graphicsEngine.js	(revision 188)
@@ -1,9 +1,9 @@
-function GraphicsEngine() {
+function GraphicsEngine(context) {
     this._scene = undefined;
     this._camera = undefined;
     this._renderer = undefined;
-    this._canvasWidth = 500;
-    this._canvasHeight = 500;
-    this._containerContext = undefined;
+    this._canvasWidth = 400;
+    this._canvasHeight = 400;
+    this._containerContext = context;
     this._BALL_RADIUS = 0.25;
     this._controls = undefined;
@@ -21,5 +21,5 @@
     this._renderer.setClearColor(0x000000, 1);
     this._renderer.setSize(this._canvasWidth, this._canvasHeight);
-    this._containerContext = $("#container");
+    //this._containerContext = $("#container");
     this._containerContext.append(this._renderer.domElement);
 }
@@ -43,5 +43,5 @@
 GraphicsEngine.prototype._rotateObject = function (object, part) {
     object.rotateX(part.getXrot());
-    object.rotateY(part.getYrot());
+    object.rotateY(-part.getYrot());
     object.rotateZ(part.getZrot());
 }
@@ -74,12 +74,19 @@
 }
 
+GraphicsEngine.prototype._debugShow = function(object)
+{
+    var pos = object.position;
+    var scale = object.scale;
+    var rot = object.rotation
+    //console.log(pos.x, pos.y, pos.z , "|", rot.x, rot.y, rot.z,"|", scale.x, scale.y, scale.z);
+}
+
 GraphicsEngine.prototype._addEllipsoid = function (part) {
     var geometry = new THREE.SphereGeometry(1, 20, 20);
-    geometry.applyMatrix(new THREE.Matrix4().makeScale(part.getXshape(), part.getYshape(), part.getZshape()));
-
     var ellipsoidMaterial = new THREE.MeshPhongMaterial({color: 0xffffff});
     ellipsoidMaterial.color.setRGB(part.getR(), part.getG(), part.getB())
 
     var ellipsoid = new THREE.Mesh(geometry, ellipsoidMaterial);
+    ellipsoid.scale.set(part.getXshape(), part.getYshape(), part.getZshape())
     ellipsoid.position.set(part.getX(), part.getY(), part.getZ());
     this._rotateObject(ellipsoid, part);
@@ -88,4 +95,5 @@
     if(this._showAxis)
         ellipsoid.add(new THREE.AxisHelper(1));
+
     this._scene.add(ellipsoid);
 }
@@ -93,5 +101,4 @@
 GraphicsEngine.prototype._addCylinder = function (part) {
     var geometry = new THREE.CylinderGeometry(1, 1, 1, 10, 10, false);
-    geometry.applyMatrix(new THREE.Matrix4().makeScale(part.getZshape(), part.getXshape(), part.getYshape()));
 
     var material = new THREE.MeshLambertMaterial({color: 0xffffff});
@@ -99,17 +106,20 @@
 
     var cylinder = new THREE.Mesh(geometry, material);
+
+    cylinder.scale.set(part.getXshape(), part.getYshape(), part.getZshape())
     cylinder.position.set(part.getX(), part.getY(), part.getZ());
-    cylinder.overdraw = true;
     this._rotateObject(cylinder, part);
 
     this._parts.push(cylinder);
     if(this._showAxis)
-        cylinder.add(new THREE.AxisHelper(1));
+        cylinder.add(new THREE.AxisHelper(5));
+
     this._scene.add(cylinder);
+
 }
 
 GraphicsEngine.prototype._addCuboid = function (part) {
     var geometry = new THREE.CubeGeometry(2, 2, 2, 10, 10, 10);
-    geometry.applyMatrix(new THREE.Matrix4().makeScale(part.getXshape(), part.getYshape(), part.getZshape()));
+    //TODO: poprawić getXshape na getXscale
 
     var material = new THREE.MeshLambertMaterial({color: 0xffffff});
@@ -117,4 +127,5 @@
 
     var cube = new THREE.Mesh(geometry, material);
+    cube.scale.set(part.getXshape(), part.getYshape(), part.getZshape())
     cube.position.set(part.getX(), part.getY(), part.getZ());
     this._rotateObject(cube, part);
@@ -127,4 +138,5 @@
 
 GraphicsEngine.prototype.addPart = function (part) {
+    console.log(part.getX(),part.getY(),part.getZ(), "|", part.getXshape(),part.getYshape(),part.getZshape(),"|",part.getXrot(),part.getYrot(),part.getZrot())
     switch (part.getType()) {
         case 0:
@@ -196,5 +208,5 @@
 
         copy.rotateX(joint.getXrot());
-        copy.rotateY(joint.getYrot());
+        copy.rotateY(-joint.getYrot());
         copy.rotateZ(joint.getZrot());
 
@@ -233,4 +245,7 @@
     this._controls = new THREE.TrackballControls(this._camera, this._renderer.domElement)
     this._debug();
+
+
+
 }
 
@@ -255,5 +270,6 @@
 GraphicsEngine.prototype.debugTest = function()
 {
-
-}
-
+    for(var i = 0; i < this._parts.length; i++)
+        this._debugShow(this._parts[i]);
+}
+
Index: js/viewer-f0/js/main.js
===================================================================
--- js/viewer-f0/js/main.js	(revision 173)
+++ 	(revision )
@@ -1,238 +1,0 @@
-var Viewer =
-{
-
-    Mode: {
-        LINK: 0,
-        EMBEDDED: 1,
-        TEXTAREA: 2,
-        CODE : 3
-    },
-    context: undefined,
-    urlToXML: "f0def.xml",//"http://www.framsticks.com/files/apps/config/f0def.xml",
-    xml: undefined,
-    model: new Model(),
-    part: new Part(),
-    joint: new Joint(),
-    neuro: new Neuro(),
-    neuroConn: new NeuroConn(),
-    parts: [],
-    joints: [],
-    neurons: [],
-    neuroConns: [],
-    neuroClasses: {},
-    modelOne: undefined,
-    _graphicsEngine: new GraphicsEngine(),
-    _neuronDrawer: new NeuronDrawer(),
-    downloadXML: function () {
-        var local = this;
-        $.ajax({
-            url: local.urlToXML,
-            dataType: "xml",
-            async: false,
-            success: function (xml) {
-                var xmlDoc = $.parseXML(xml);
-                $xml = $(xmlDoc);
-                local.xml = $(xml);
-            },
-            error: function () {
-                alert("Can't download file f0def.xml");
-            }
-        })
-    },
-    parseGeneXml: function () {
-        this._parseClass($(this.xml.find("CLASS")));
-        this._parseNeuroClass($(this.xml.find("NEUROCLASS")))
-    },
-    _parseClass: function(nodes){
-        var local = this;
-
-        nodes.each(function (entry) {
-            var node = $(nodes[entry]);
-
-            if (node.attr("NAME") == "Model") {
-                local.model.setModel(node);
-            }
-            else if (node.attr("NAME") == "Part")
-                local.part.setModel(node);
-            else if (node.attr("NAME") == "Joint")
-                local.joint.setModel(node);
-            else if (node.attr("NAME") == "Neuro")
-                local.neuro.setModel(node);
-            else if (node.attr("NAME") == "NeuroConn")
-                local.neuroConn.setModel(node);
-            else {
-                console.log("Could not recognize NAME:", node.attr("NAME"));
-            }
-
-        });
-    },
-    _parseNeuroClass: function(data){
-
-        for(var i = 0; i < data.length; i++)
-        {
-            var neuroClass = new NeuroClass();
-            this.neuroClasses[data[i].attributes[0].value] = neuroClass;
-            neuroClass.setModel(data);
-        }
-
-    },
-    analyseLine: function (line) {
-        //ignore comment
-        if (line[0] == '#' || line == "")
-            return;
-
-        var object;
-        var type = line[0];
-        if (type == "p") {
-            object = $.extend(true, {}, this.part);
-            this.parts.push(object);
-        }
-        else if (type == "j") {
-            object = $.extend(true, {}, this.joint);
-            this.joints.push(object);
-        }
-        else if (type == "n") {
-            object = $.extend(true, {}, this.neuro);
-            this.neurons.push(object);
-        }
-        else if (type == "c") {
-            object = $.extend(true, {}, this.neuroConn);
-            this.neuroConns.push(object);
-        }
-        else if (type == "m") {
-            object = $.extend(true, {}, this.model);
-            this.modelOne = object;
-        }
-        else
-            throw new Error("Undefined element: \"" + type + "\"");
-
-        //remove char and ":"
-        line = line.substring(2);
-        var lines = line.match(/([^,"]+|"[^"]+")+/g);
-
-        if (lines != null)
-            lines.forEach(function (value) {
-                value = value.trim();
-                if (value == "")
-                    object.setValue();
-                else if (value.indexOf("=") == -1) {
-                    object.setValue(value);
-                }
-                else {
-                    var name = value.substring(0, value.indexOf("="));
-                    var val = value.substring(value.indexOf("=") + 1);
-                    object.setValue(name, val);
-                }
-            })
-    },
-    getCreature: function (mode, content) {
-
-        var lines = undefined;
-        if(mode == this.Mode.LINK)
-            lines = this._getCreatureFromLink(content);
-        else if(mode == this.Mode.EMBEDDED)
-            lines = this._getCreatureFromEmbeddedCode(content);
-        else if (mode == this.Mode.TEXTAREA)
-            lines = this._getCreatureFromTextArea(content);
-        else if(mode == this.Mode.CODE)
-            lines = this._getCreatureFromCode(content);
-        else
-        {
-            throw "Wrong mode in function getCreature";
-        }
-        return lines;
-    },
-    _getCreatureFromLink: function(link){
-        var lines = undefined;
-        $.ajax({
-            url: link,
-            async: false,
-            dataType: "text",
-            success: function (data) {
-                lines = data.split("\n");
-
-            },
-            error: function () {
-                alert("Can't download creature");
-            }
-        });
-        return lines;
-    },
-    _getCreatureFromTextArea: function(area){
-        var lines = undefined;
-        lines = area.val();
-        lines = lines.split("\n");
-        return lines;
-    },
-    _getCreatureFromCode: function(code){
-        var lines = code;
-        lines = lines.split("\n");
-        return lines;
-    },
-    _getCreatureFromEmbeddedCode: function(link){
-        var lines = undefined;
-
-        $.ajax({
-            url: link,
-            async: false,
-            dataType: "html",
-            success: function (data) {
-                var geno = $($(data).find("div")[0]).comments().html();
-                geno = geno.replace("FRED_GEN", "");
-                lines = geno.split("\n");
-            },
-            error: function () {
-                alert("Can't download creature");
-            }
-        });
-
-        return lines;
-    },
-    parseCreature: function (mode, content) {
-        var lines = this.getCreature(mode, content);
-        lines.splice(0, 1);
-        var local = this;
-        lines.forEach(function (value) {
-            local.analyseLine(value);
-        });
-    },
-    renderCreature: function () {
-
-        if($("#axisBox").is(":checked"))
-            this._graphicsEngine.showPartAxis();
-
-        for (var i = 0; i < this.parts.length; i++)
-            this._graphicsEngine.addPart(this.parts[i])
-
-        for (var i = 0; i < this.joints.length; i++) {
-            this._graphicsEngine.addJoint(this.joints[i]);
-        }
-
-    },
-    mainLoop: function () {
-        this._graphicsEngine.initializeScene();
-        this.renderCreature();
-        this._graphicsEngine.debugTest();
-        this._graphicsEngine.renderScene();
-
-        this._neuronDrawer.initializeScene();
-        new SmartLayout(this.neurons, this.neuroConns);
-        this._neuronDrawer.drawNetwork(this.neurons, this.neuroConns, einfos, this.neuroClasses);
-        this._neuronDrawer.renderScene();
-
-    }
-}
-
-function openWindow() {
-    var debugCreatureName = "example4";
-    Viewer.downloadXML();
-    Viewer.parseGeneXml();
-    //Viewer.parseCreature(Viewer.Mode.LINK, "http://localhost:63343/FramestickFavi/creatures/" + debugCreatureName + ".txt");
-    //Viewer.parseCreature(Viewer.Mode.TEXTAREA, $("#geno"));
-    //Viewer.parseCreature(Viewer.Mode.CODE, "//0\np:\np: x=1");
-    Viewer.parseCreature(Viewer.Mode.EMBEDDED, "http://ec.framsticks.com/www/index.php?PAGE=view_genotype&ID=55")
-    Viewer.mainLoop();
-
-
-
-}
