public void SerializeVessel(Vessel vessel, ref MemoryBridge memoryBridge, VesselControl vesselControl)
        {
            Debug.Log("Vessel Control Awake");
            this.vessel        = vessel;
            this.memoryBridge  = memoryBridge;
            this.vesselControl = vesselControl;

            Debug.Log("Current Vessel " + vessel.name);

            // var kspPartList = this.vessel.Parts;
            Debug.Log("try to serialize custom part");

            //WORKS
            BuildVessel();
        }
        public void StartServer(string fileName)
        {
            vessel = FlightGlobals.ActiveVessel;
            Debug.Log("Server start");
            bridgeConnected         = false;
            clientTransmittingFloat = 0;
            this.fileName           = fileName;
            fileConstants           = gameObject.AddComponent(typeof(MemoryFileConstants)) as MemoryFileConstants;
            floatFile = gameObject.AddComponent(typeof(FloatFile)) as FloatFile;
            floatFile.StartServer(this);

            vesselControl = gameObject.AddComponent(typeof(VesselControl)) as VesselControl;
            vesselControl.ControlStart(vessel, this);

            cameraFeeds = new List <CameraFeed>();

            SetFloat("testfloat", 3);
            serverActive = true;
        }
        public MemoryPart(Part part, VesselControl vesselControl)
        {
            kspPart   = part;
            byteCount = 0;
            name      = part.name;
            uniqueID  = part.gameObject.GetInstanceID();
            try
            {
                parentID = part.parent.gameObject.GetInstanceID();
            }
            catch { Debug.Log(part.name + " does not have a parent"); }


            var modelMeshes = part.FindModelComponents <MeshFilter>();

            //var modelSkinnedMeshes = part.FindModelComponents<SkinnedMeshRenderer>();

            //  var combinedArray = new Mesh[modelMeshes.Count + modelSkinnedMeshes.Count];
            //  modelMeshes.CopyTo(combinedArray);
            offset = vesselControl.adjustedVessel.InverseTransformPoint(part.transform.position);//vesselControl.adjustedVessel.InverseTransformPoint(filter.transform.position);
            var tempParent = part.transform.parent;

            part.transform.SetParent(vesselControl.adjustedVessel);//vesselControl.vesselCOM);
            //  var rotOffset = Quaternion.Inverse(part.vessel.vesselTransform.rotation) * filter.transform.rotation;
            rotOffset = part.transform.localEulerAngles;

            part.transform.SetParent(tempParent);

            meshList = new List <ModelFilter>();

            //for uniqueID
            byteCount += 4;
            //for parent uniqueID
            byteCount += 4;
            //for meshfilter count
            byteCount += 4;
            //for localPosition vector3
            byteCount += 12;
            //for localRot vector3
            byteCount += 12;

            //for part name string count
            byteCount += 4;
            //for part name
            nameBytePackage = Encoding.ASCII.GetBytes(name);
            byteCount      += nameBytePackage.Length;


            foreach (var filter in modelMeshes)
            {
                Debug.Log(filter.transform.name + " filter found on part " + part.name);
                bool serialize = false;
                if (!filter.name.ToLower().Contains("col"))
                {
                    var gearModule = part.GetComponent <ModuleWheelBase>();
                    if (!gearModule)
                    {
                        serialize = true;
                    }
                }
                else
                {
                    var engineModule = part.GetComponent <ModuleEngines>();
                    if (engineModule)
                    {
                        serialize = true;
                    }
                }

                if (serialize)
                {
                    ModelFilter modelFilter = new ModelFilter();

                    byteCount += 12;
                    byteCount += 12;
                    byteCount += 12;

                    modelFilter.vesselPartOffset = part.transform.InverseTransformPoint(filter.transform.position); //vesselControl.adjustedVessel.InverseTransformPoint(filter.transform.position);
                    tempParent = filter.transform.parent;
                    filter.transform.SetParent(part.transform);                                                     //vesselControl.vesselCOM);
                    //  var rotOffset = Quaternion.Inverse(part.vessel.vesselTransform.rotation) * filter.transform.rotation;
                    modelFilter.vesselPartLocalEuler = filter.transform.localEulerAngles;
                    filter.transform.SetParent(tempParent);
                    modelFilter.lossyScale = filter.transform.lossyScale;

                    //for mesh length
                    byteCount += 4;

                    var mesh = filter.mesh;
                    modelFilter.byteArrMesh = MeshSerializer.WriteMesh(mesh, true);
                    meshList.Add(modelFilter);
                    byteCount += modelFilter.byteArrMesh.Length;
                }
            }


            //Texture2D texture = part.FindModelComponent<MeshRenderer>().material.GetTexture("_MainTex") as Texture2D;

            ////var tex = new Texture2D(texture.height, texture.width, TextureFormat.RGB24, false);
            ////Graphics.ConvertTexture(texture, tex);
            //Color32[] pix = texture.GetPixels32();
            //System.Array.Reverse(pix);
            //Texture2D destTex = new Texture2D(texture.width, texture.height);
            //destTex.SetPixels32(pix);
            //destTex.Apply();


            //byteArrTexture = destTex.GetRawTextureData();

            // byteCount = byteArrMesh.Length;// + byteArrTexture.Length;
            //  Debug.Log(part.name + " mesh byte length " + byteArrMesh.Length);
            //byteArrayList.Add(MeshSerializer.WriteMesh(mesh, true));
        }