//--------------- Serialize / Deserialize --------------------
        public static byte[] Serialize(SWorldObject input)
        {
            ComposedPrimitives prims = new ComposedPrimitives();

            prims.AddValue(input.instanceID);
            prims.AddValue(input.activeInHierarchy);
            prims.AddValue(input.color.r);
            prims.AddValue(input.color.g);
            prims.AddValue(input.color.b);
            prims.AddValue(input.color.a);

            ComposedByteStream stream = new ComposedByteStream(input.meshes.Count + 2);
            stream.AddStream(prims.Compose());
            stream.AddStream(input.name);

            foreach (SMesh mesh in input.meshes)
                stream.AddStream(SMesh.Serialize(mesh));

            return stream.Compose();
        }
        public static SWorldObject Deserialize(byte[] input)
        {
            SWorldObject result = new SWorldObject();
            ComposedByteStream stream = ComposedByteStream.FromByteArray(input);
            ComposedPrimitives prims = ComposedPrimitives.FromByteArray(stream.ReadNextStream<byte>());

            result.instanceID = prims.ReadNextValue<int>();
            result.activeInHierarchy = prims.ReadNextValue<bool>();
            result.color = new Color(
                    prims.ReadNextValue<float>(),
                    prims.ReadNextValue<float>(),
                    prims.ReadNextValue<float>(),
                    prims.ReadNextValue<float>());

            result.name = stream.ReadNextStream();
            if (stream.streamCount > 2) {
                int iMax = stream.streamCount - 2;
                result.meshes = new List<SMesh>(iMax);
                for (int i = 0; i < iMax; i++)
                    result.meshes.Add(SMesh.Deserialize(stream.ReadNextStream<byte>()));
            }

            stream.Dispose();
            return result;
        }