Beispiel #1
0
        /* Didn't work. Caused slowdown.
         * public void SetRenderQueues(Part activePart)
         * {
         *  SortedList<float, Part> partRanges = new SortedList<float, Part>();
         *  foreach (Part p in FlightGlobals.ActiveVessel.Parts)
         *  {
         *      if (p.internalModel == null) continue;
         *      partRanges.Add(Vector3.Distance(p.collider.bounds.center, activePart.collider.bounds.center), p);
         *  }
         *
         *  int queue = 2000;
         *  foreach (var pr in partRanges)
         *  {
         *      if (pr.Value.internalModel == null) continue;
         *      Renderer[] renderers = pr.Value.internalModel.GetComponentsInChildren<Renderer>();
         *      foreach (var r in renderers)
         *      {
         *          foreach (var m in r.materials)
         *          {
         *              m.renderQueue = queue;
         *              if (queue == 2000) queue--;
         *              queue--;
         *          }
         *      }
         *  }
         * }*/

        public static void ChangeMesh(GameObject original)
        {
            try
            {
                string modelPath = "FreeIva/Models/HatchMask";
                Debug.Log("#Changing mesh");
                GameObject hatchMask = GameDatabase.Instance.GetModel(modelPath);
                if (hatchMask != null)
                {
                    MeshFilter mfC = original.GetComponent <MeshFilter>();
                    MeshFilter mfM = hatchMask.GetComponent <MeshFilter>();
                    Mesh       m   = FreeIva.Instantiate(mfM.mesh) as Mesh;
                    mfC.mesh = m;
                    Debug.Log("#Changed mesh");
                }
                else
                {
                    Debug.LogError("[Free IVA] HatchMask.dae not found at " + modelPath);
                }
            }
            catch (Exception ex)
            {
                Debug.LogError("[Free IVA] Error Loading mesh: " + ex.Message + ", " + ex.StackTrace);
            }
        }
Beispiel #2
0
        public static void ChangeHelmetMesh(GameObject original, Part p)
        {
            //http://forum.kerbalspaceprogram.com/threads/87562-Changing-the-EVA-Kerbal-model/page4
            try
            {
                string modelPath = "FreeIva/Models/TestSphere";
                Debug.Log("#Changing helmet mesh");
                GameObject testSphere = GameDatabase.Instance.GetModel(modelPath);
                if (testSphere != null)
                {
                    MeshFilter mfC = original.GetComponent <MeshFilter>();

                    MeshFilter mfM = null;
                    foreach (ProtoCrewMember c in p.protoModuleCrew)
                    {
                        if (c.KerbalRef.headTransform != null)
                        {
                            mfM = c.KerbalRef.headTransform.GetComponentInChildren <MeshFilter>();

                            /*MeshFilter[] mfs = c.KerbalRef.headTransform.GetComponentsInChildren<MeshFilter>();
                             * foreach (var mf in mfs)
                             * {
                             *  Debug.Log(mf);
                             *  mfM = mf;
                             *  break;
                             * }*/
                        }
                        if (mfM != null)
                        {
                            break;
                        }
                    }

                    Mesh m = FreeIva.Instantiate(mfM.mesh) as Mesh;
                    mfC.mesh = m;
                    Debug.Log("#Changed mesh");
                }
                else
                {
                    Debug.LogError("[Free IVA] TestSphere.dae not found at " + modelPath);
                }
            }
            catch (Exception ex)
            {
                Debug.LogError("[Free IVA] Error Loading mesh: " + ex.Message + ", " + ex.StackTrace);
            }
        }