Jump to content

kubi

Members
  • Posts

    81
  • Joined

  • Last visited

Everything posted by kubi

  1. You are right. 1500 was too small. For the sphere r=0.5, not r=1...
  2. The saga continues. Now with a sphere... Why doesn't it appear? using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; namespace KspCelestialOverlay { [KSPAddon(KSPAddon.Startup.EveryScene, false)] internal class KspCelestialOverlay : MonoBehaviour { public const int GridLevel = 5; public static KspCelestialOverlay Instance { get; private set; } private CelestialBody body; private Mesh mesh; static GameObject sphere = null; public void Awake() { var scene = HighLogic.LoadedScene; Debug.LogError("KspCelestialOverlay Awake scene=" + scene.ToString() + " " + Time.time.ToString("0.0000")); // we do it in the trackstation only if (scene != GameScenes.TRACKSTATION) { Debug.LogError("KspCelestialOverlay Awake disabling"); enabled = false; } } // called only is enabled == true public void Start() { Debug.LogError("KspCelestialOverlay Start " + Time.time.ToString("0.0000")); if (Instance != null) Destroy(Instance.gameObject); Instance = this; if (HighLogic.LoadedScene != GameScenes.TRACKSTATION) { Debug.LogError("KspCelestialOverlay Start not in trackstation wtf?!"); return; } /* mesh = gameObject.AddComponent<MeshFilter>().mesh; var renderer = gameObject.AddComponent<MeshRenderer>(); */ Debug.LogError("KspCelestialOverlay Start2 " + Time.time.ToString("0.0000")); if (sphere == null) { Debug.LogError("KspCelestialOverlay createsphere " + Time.time.ToString("0.0000")); sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.collider.enabled = false; Destroy(sphere.collider); } } public void Update() { if (HighLogic.LoadedScene != GameScenes.TRACKSTATION) { Debug.LogError("KspCelestialOverlay Update not in trackstation wtf?!"); return; } if (!MapView.MapIsEnabled || MapView.MapCamera == null) { Debug.LogError("KspCelestialOverlay Update mapviewproblem"); gameObject.renderer.enabled = false; return; } var target = MapView.MapCamera.target; var newBody = getTargetBody(target); if (newBody == null) { Debug.LogError("KspCelestialOverlay Update newbody==null wtf?!"); return; } // do it once when a body is selected if (newBody != body) { body = newBody; Debug.LogError("KspCelestialOverlay Update body.name " + body.name + " " + body.Radius.ToString("0.00")); /* Vector3[] vertices = { new Vector3(0,0,0), new Vector3(0,0,1), new Vector3(0,1,0), new Vector3(1,0,0) }; int[] triangles = { 1,3,2, 0,1,2, 0,1,3, 0,2,3 }; mesh.vertices = vertices; mesh.triangles = triangles; mesh.Optimize(); gameObject.layer = 10; gameObject.transform.parent = ScaledSpace.Instance.scaledSpaceTransforms.Single(t => t.name == body.name); gameObject.transform.localScale = Vector3.one * 2025f; gameObject.transform.localPosition = Vector3.zero; gameObject.transform.localRotation = Quaternion.identity; gameObject.renderer.enabled = true; gameObject.renderer.castShadows = false; gameObject.renderer.receiveShadows = false; gameObject.renderer.material.color = Color.green; */ sphere.layer = 10; sphere.transform.parent = ScaledSpace.Instance.scaledSpaceTransforms.Single(t => t.name == body.name); sphere.transform.localScale = Vector3.one * 1500f; sphere.transform.localPosition = Vector3.zero; sphere.transform.localRotation = Quaternion.identity; sphere.renderer.enabled = true; sphere.renderer.castShadows = false; sphere.renderer.receiveShadows = false; sphere.renderer.material.color = Color.red; } } public void OnDestroy() { Debug.LogError("KspCelestialOverlay Ondestroy " + Time.time.ToString("0.0000")); } private static CelestialBody getTargetBody(MapObject target) { if (target == null) return null; switch (target.type) { case MapObject.MapObjectType.CELESTIALBODY: return target.celestialBody; case MapObject.MapObjectType.MANEUVERNODE: return target.maneuverNode.patch.referenceBody; case MapObject.MapObjectType.VESSEL: return target.vessel.mainBody; default: return null; } } } }
  3. Instead of gameObject.transform.parent = body.GetTransform(); gameObject.transform.parent = ScaledSpace.Instance.scaledSpaceTransforms.Single(t => t.name == body.name); solved the issue.
  4. Hi, I'm working on a simple plugin that should display a triangle at the selected celestial body in map (tracking station) view. I think I'm OK with the Start(), Awake() and Update() callbacks, but the mesh is not displayed. Could anyone comment? using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; namespace KspCelestialOverlay { [KSPAddon(KSPAddon.Startup.EveryScene, false)] internal class KspCelestialOverlay : MonoBehaviour { public const int GridLevel = 5; public static KspCelestialOverlay Instance { get; private set; } private CelestialBody body; private Mesh mesh; private static RenderingManager renderingManager; public void Awake() { var scene = HighLogic.LoadedScene; Debug.LogError("KspCelestialOverlay Awake scene=" + scene.ToString() + " " + Time.time.ToString("0.0000")); // we do it in the trackstation only if (scene != GameScenes.TRACKSTATION) { Debug.LogError("KspCelestialOverlay Awake disabling"); enabled = false; } } // called only is enabled == true public void Start() { Debug.LogError("KspCelestialOverlay Start " + Time.time.ToString("0.0000")); if (Instance != null) Destroy(Instance.gameObject); Instance = this; if (HighLogic.LoadedScene != GameScenes.TRACKSTATION) { Debug.LogError("KspCelestialOverlay Start not in trackstation wtf?!"); return; } mesh = gameObject.AddComponent<MeshFilter>().mesh; var renderer = gameObject.AddComponent<MeshRenderer>(); } public void Update() { if (HighLogic.LoadedScene != GameScenes.TRACKSTATION) { Debug.LogError("KspCelestialOverlay Update not in trackstation wtf?!"); return; } if (!MapView.MapIsEnabled || MapView.MapCamera == null) { Debug.LogError("KspCelestialOverlay Update mapviewproblem"); gameObject.renderer.enabled = false; return; } var target = MapView.MapCamera.target; var newBody = getTargetBody(target); if (newBody == null) { Debug.LogError("KspCelestialOverlay Update newbody==null wtf?!"); return; } // do it once when a body is selected if (newBody != body) { body = newBody; Debug.LogError("KspCelestialOverlay Update body.name " + body.name + " " + body.Radius.ToString("0.00")); Vector3[] vertices = { new Vector3(0,0,1), new Vector3(0,1,0), new Vector3(1,0,0) }; int[] triangles = { 0, 1, 2 }; mesh.vertices = vertices; mesh.triangles = triangles; mesh.Optimize(); gameObject.layer = 10; gameObject.transform.parent = body.GetTransform(); gameObject.transform.localScale = Vector3.one * 2000000f; gameObject.transform.localPosition = Vector3.zero; gameObject.transform.localRotation = Quaternion.identity; gameObject.renderer.enabled = true; } } public void OnDestroy() { Debug.LogError("KspCelestialOverlay Ondestroy " + Time.time.ToString("0.0000")); } private static CelestialBody getTargetBody(MapObject target) { if (target == null) return null; switch (target.type) { case MapObject.MapObjectType.CELESTIALBODY: return target.celestialBody; case MapObject.MapObjectType.MANEUVERNODE: return target.maneuverNode.patch.referenceBody; case MapObject.MapObjectType.VESSEL: return target.vessel.mainBody; default: return null; } } } }
  5. I'm looking into SCANsat a bit and would like to extend it by providing the scanned map on a sphere around planets instead of a planar representation. I think it could be quite nice to have the maps in 3D. Is/was there any activity for this? I'm totally new in programming for unity/KSP and having some issues with it, but progressing quite well. I managed to write a simple partless plugin that is activated (for the sake of simplicity) in the tracking station view. I understand all of the Start(), Awake(), and Update() callbacks. I could also create a mesh (a simple triangle now). But what I can't solve is to show the triangle near Kerbin or any of the selected celestial bodies. Is there any simple tutorial how to draw anything in the map view?
  6. Great mod! Just visited the Jool system for some science. Would it be possible to put some degree values on the edge of the map? For example a small tick every 15 degrees.
×
×
  • Create New...