private void Initialize()
        {
            //Based on Kronal Vessel Viewer CoM axes rendering
            if (_rendererMaterial == null)
            {
                Material lineMaterial;

                if (!FARAssets.materialDict.TryGetValue("FARGraphMaterial", out lineMaterial))
                {
                    //TODO: definitely replace this with a proper shader when we can
                    FARLogger.Warning("Could not load cross-section shader; using fallback shader");
                    lineMaterial = new Material(Shader.Find("Sprites/Default"));
                }

                _rendererMaterial                  = new Material(lineMaterial);
                _rendererMaterial.hideFlags        = HideFlags.HideAndDontSave;
                _rendererMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
                _rendererMaterial.renderQueue      = 4500;
            }

            FARLogger.Debug("Creating renderers with material " + _rendererMaterial);
            FARLogger.Debug("Area color: " + _crossSectionColor + ", Deriv: " + _derivColor + ", Coeff: " + Color.cyan + ", Marking: " + _axisColor);
            _areaRenderer  = CreateNewRenderer(_crossSectionColor, 0.1f, _rendererMaterial);
            _derivRenderer = CreateNewRenderer(_derivColor, 0.1f, _rendererMaterial);
            _coeffRenderer = CreateNewRenderer(Color.cyan, 0.1f, _rendererMaterial);

            _markingRenderers = new List <LineRenderer>();
            _markingRenderers.Add(CreateNewRenderer(_axisColor, 0.1f, _rendererMaterial));
        }
Esempio n. 2
0
        LineRenderer CreateNewRenderer(Color color, float width, Material material)
        {
            GameObject o = new GameObject();

            LineRenderer renderer = o.gameObject.AddComponent <LineRenderer>();

            // need to copy the material properties so the same material is not
            // reused between renderers
            Material rendererMaterial = new Material(material);

            // rendererMaterial.CopyPropertiesFromMaterial(material);

            renderer.useWorldSpace = false;
            if (material.HasProperty("_Color"))
            {
                // FARLogger.Info("Setting _Color on " + material + "to " + color);
                rendererMaterial.SetColor(colorId, color);
            }
            else
            {
                FARLogger.Warning("Material " + material + " has no _Color property");
            }
            renderer.material = rendererMaterial;
            // renderer.startColor = color;
            // renderer.endColor = color;
            renderer.enabled = false;
            //renderer.startWidth = width;   // Rodhern: Downgrade to KSP 1.3.1
            //renderer.endWidth = width;     //  --
            renderer.SetWidth(width, width); //  --
            renderer.sortingOrder = 1;

            return(renderer);
        }
Esempio n. 3
0
        private static LineRenderer CreateNewRenderer(Color color, float width, Material material)
        {
            var o = new GameObject();

            LineRenderer renderer = o.gameObject.AddComponent <LineRenderer>();

            // need to copy the material properties so the same material is not
            // reused between renderers
            var rendererMaterial = new Material(material);

            renderer.useWorldSpace = false;
            if (material.HasProperty(ShaderPropertyIds._Color))
            {
                rendererMaterial.SetColor(ShaderPropertyIds._Color, color);
            }
            else
            {
                FARLogger.Warning("Material " + material + " has no _Color property");
            }
            renderer.material     = rendererMaterial;
            renderer.enabled      = false;
            renderer.startWidth   = width;
            renderer.endWidth     = width;
            renderer.sortingOrder = 1;

            return(renderer);
        }
        public static void LoadConfiguration()
        {
            string[] namesTmp = Enum.GetNames(typeof(KSPActionGroup));
            var      names    = new string[namesTmp.Length - 1];

            for (int i = 0; i < namesTmp.Length - 1; ++i)
            {
                names[i] = namesTmp[i];
            }
            var agTypes = new KSPActionGroup[names.Length];

            actionGroupDropDown = new GUIDropDown <KSPActionGroup> [3];

            for (int i = 0; i < agTypes.Length; i++)
            {
                agTypes[i] = (KSPActionGroup)Enum.Parse(typeof(KSPActionGroup), names[i]);
            }
            // straight forward, reading the (action name, action group) tuples
            PluginConfiguration config = FARDebugAndSettings.config;

            for (int i = 0; i < ACTION_COUNT; ++i)
            {
                try
                {
                    // don't forget to initialize the gui
                    string currentGuiString = currentGuiStrings[i] = id2actionGroup[i].ToString();
                    id2actionGroup[i] =
                        (KSPActionGroup)Enum.Parse(typeof(KSPActionGroup),
                                                   config.GetValue(configKeys[i], currentGuiString));
                    FARLogger.Info($"Loaded AG {configKeys[i]} as {currentGuiString}");
                }
                catch (Exception e)
                {
                    FARLogger.Warning("Error reading config key '" +
                                      configKeys[i] +
                                      "' with value '" +
                                      config.GetValue(configKeys[i], "n/a") +
                                      "' gave " +
                                      e);
                }

                int initIndex = 0;
                for (int j = 0; j < agTypes.Length; j++)
                {
                    if (id2actionGroup[i] != agTypes[j])
                    {
                        continue;
                    }
                    initIndex = j;
                    break;
                }

                var dropDown = new GUIDropDown <KSPActionGroup>(names, agTypes, initIndex);
                actionGroupDropDown[i] = dropDown;
            }
        }
Esempio n. 5
0
        public bool Update()
        {
            if (done)
            {
                return(true);
            }

            // even if this job is cancelled we have to wait for the async jobs to finish before we can release the resources

            switch (state)
            {
            case State.Readback:
                if (!info.readbackRequest.done)
                {
                    return(false);
                }
                if (info.readbackRequest.hasError)
                {
                    FARLogger.Warning("Error in readback request");
                    return(true);
                }

                info.readbackRequest.WaitForCompletion();
                if (info.device is PhysicalDevice.GPU)
                {
                    info.pixelCounts = info.readbackRequest.GetData <int>();
                    return(true);
                }

                // don't submit a new job if we're cancelled
                if (cancelled)
                {
                    return(true);
                }

                info.texture = info.readbackRequest.GetData <uint>();
                countHandle  = Renderer.CountPixels(info.texture, info.pixelCounts);
                state        = State.CountJob;
                return(false);

            case State.CountJob:
                if (!countHandle.IsCompleted)
                {
                    return(false);
                }
                countHandle.Complete();
                return(true);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
    public static PhysicalDevice Select(this PhysicalDevice device)
    {
        if (device is not PhysicalDevice.GPU || supportsComputeShaders)
        {
            return(device);
        }

        if (!computeWarningIssued)
        {
            return(PhysicalDevice.CPU);
        }

        FARLogger.Warning("Compute shaders are not supported on your system!");
        computeWarningIssued = true;

        return(PhysicalDevice.CPU);
    }
        public IEnumerator Load()
        {
            // wait for the other loading to be done
            if (State == Progress.InProgress)
            {
                yield return(new WaitWhile(() => State == Progress.InProgress));

                yield break;
            }

            State = Progress.InProgress;

            // wait for config to be loaded fully
            while (FARConfig.IsLoading)
            {
                yield return(null);
            }

            NeedsReload = false;

            string path = Url;

            FARLogger.DebugFormat("Loading asset bundle from {0}", path);
            AssetBundleCreateRequest createRequest = AssetBundle.LoadFromFileAsync(path);

            yield return(createRequest);

            AssetBundle assetBundle = createRequest.assetBundle;

            if (assetBundle == null)
            {
                FARLogger.Error($"Could not load asset bundle from {path}");
                State = Progress.Error;
                yield break;
            }

            AssetBundleRequest loadRequest = assetBundle.LoadAllAssetsAsync <T>();

            yield return(loadRequest);

            LoadedAssets.Clear();
            foreach (Object asset in loadRequest.allAssets)
            {
                if (!LoadedAssets.ContainsKey(asset.name))
                {
                    if (asset is T t)
                    {
                        LoadedAssets.Add(asset.name, t);
                    }
                    else
                    {
                        FARLogger
                        .Warning($"Invalid asset type {asset.GetType().ToString()}, expected {typeof(T).ToString()}");
                    }
                }
                else
                {
                    FARLogger.DebugFormat("Asset {0} is duplicated", asset);
                }
            }

            FARLogger.DebugFormat("Completed loading assets from {0}", path);

            State = Progress.Completed;
        }