コード例 #1
0
        public void CheckSubdivision()
        {
            if (quad != null && FlightGlobals.ActiveVessel != null)
            {
                distance = Vector3.Distance(FlightGlobals.ActiveVessel.transform.position, quad.transform.position);
                int distLimit = (int)(120 + (FlightGlobals.currentMainBody.Radius / 450000) * 800);
                if (overrideDistLimit)
                {
                    distLimit = customDistLimit;
                }
                if (distance < distLimit && subdivided == false)
                {
                    subdivided = true;

                    var quadMeshFilter   = quad.GetComponent <MeshFilter>();
                    var quadMeshRenderer = quad.GetComponent <MeshRenderer>();



                    newQuad      = new GameObject();
                    newQuad.name = quad.name + "FAKE";
                    newQuad.transform.position = quad.gameObject.transform.position;
                    newQuad.transform.rotation = quad.gameObject.transform.rotation;

                    newQuad.transform.parent = quad.gameObject.transform;

                    newQuad.transform.localPosition = Vector3.zero;
                    newQuad.transform.localRotation = Quaternion.identity;
                    newQuad.transform.localScale    = Vector3.one;
                    newQuad.transform.parent        = quad.gameObject.transform;

                    trueMaterial = quad.GetComponent <MeshRenderer>().sharedMaterial;    //reference to sharedMaterial

                    Mesh mesh = Instantiate(quadMeshFilter.sharedMesh);
                    MeshHelper.Subdivide(mesh, subdivisionLevel);

                    newQuad.AddComponent <MeshFilter>();
                    var newQuadMeshFilter = newQuad.GetComponent <MeshFilter>();

                    newQuadMeshFilter.sharedMesh = mesh;
                    newQuad.AddComponent <MeshRenderer>();
                    var newQuadMeshRenderer = newQuad.GetComponent <MeshRenderer>();
                    //Material[] newMaterials = new Material[1];


                    //newQuadMeshRenderer.materials = new Material[2];
                    //newQuadMeshRenderer.materials[0] = FlightGlobals.currentMainBody.pqsController.surfaceMaterial;
                    //newQuadMeshRenderer.materials[1] = GetGrassMaterial();
                    newQuadMeshRenderer.sharedMaterial = quad.GetComponent <MeshRenderer>().sharedMaterial;//FlightGlobals.currentMainBody.pqsController.surfaceMaterial;//GrassMaterial.grassMaterial;
                    //newMaterials[0] = GetGrassMaterial();
                    //newMaterials[1] = GetGrassMaterial();
                    //newQuadMeshRenderer.materials = newMaterials;
                    newQuadMeshRenderer.enabled = true;

                    quadMeshRenderer.material = transparent;
                    quadMeshRenderer.material.SetTexture("_MainTex", Resources.FindObjectsOfTypeAll <Texture>().FirstOrDefault(t => t.name == "BeyondHome/Terrain/DDS/BlankAlpha"));

                    QuadMeshDictionary.subdividedQuadList.Add(newQuad.name, newQuad);
                }
                else if (distance >= 1200 && subdivided == true)
                {
                    string newQuadName = quad.name + "FAKE";
                    if (QuadMeshDictionary.subdividedQuadList.ContainsKey(newQuadName))
                    {
                        QuadMeshDictionary.subdividedQuadList[newQuadName].DestroyGameObject();    //Change to Destroy()
                        QuadMeshDictionary.subdividedQuadList.Remove(newQuadName);
                        quad.GetComponent <QuadMeshes>().subdivided       = false;
                        quad.GetComponent <MeshRenderer>().sharedMaterial = trueMaterial;  //Don't make it transparent anymore
                    }
                }
                Debug.Log("Distance (Vessel): " + distance);
            }
        }
コード例 #2
0
        public override void OnQuadBuilt(PQ quad)
        {
            //SUBDIVISION MOD

            try
            {
                if (quad.subdivision == FlightGlobals.currentMainBody.pqsController.maxLevel && HighLogic.LoadedScene == GameScenes.FLIGHT)
                {
                    quad.gameObject.AddComponent <QuadMeshes>();
                    quad.gameObject.GetComponent <QuadMeshes>().quad              = quad;
                    quad.gameObject.GetComponent <QuadMeshes>().subdivisionLevel  = subdivisionLevel;
                    quad.gameObject.GetComponent <QuadMeshes>().overrideDistLimit = overrideDistLimit;
                    quad.gameObject.GetComponent <QuadMeshes>().customDistLimit   = customDistLimit;
                }
            }
            catch (Exception e)
            {
                Debug.Log("Something went wrong with a quad! " + e.ToString());
            }

            //ADAPTIVE PARALLAX

            try
            {
                double highPoint = 0;
                double lowPoint  = 0;

                float lowStart  = ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.LowStart;
                float lowEnd    = ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.LowEnd;
                float highStart = ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.HighStart;
                float highEnd   = ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.HighEnd;
                try
                {
                    highPoint = quad.meshVertMax;
                    lowPoint  = quad.meshVertMin;
                }
                catch
                {
                    Debug.Log("Highpoint / Lowpoint not set!");
                }
                double quadAltitude = Vector3.Distance(quad.transform.position, FlightGlobals.currentMainBody.transform.position);
                quad.GetComponent <MeshRenderer>().sharedMaterial = ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.ParallaxMaterial;

                if (highPoint <= highStart)
                {
                    //LOW-MID
                    quad.GetComponent <MeshRenderer>().sharedMaterial = ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.ParallaxMaterialDOUBLELOW;
                }
                if (lowPoint >= lowEnd)
                {
                    //MID-HIGH
                    quad.GetComponent <MeshRenderer>().sharedMaterial = ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.ParallaxMaterialDOUBLEHIGH;
                }


                if (highPoint < lowStart)
                {
                    //LOW
                    quad.GetComponent <MeshRenderer>().sharedMaterial = ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.ParallaxMaterialSINGLELOW;
                    //quad.GetComponent<MeshRenderer>().sharedMaterial.SetTexture("_SurfaceTexture", ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.LoadTexture(ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.SurfaceTexture));
                    //quad.GetComponent<MeshRenderer>().sharedMaterial.SetTexture("_BumpMap", ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.LoadTexture(ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.SurfaceTextureBumpMap));
                }
                if (highPoint < highStart && lowPoint > lowEnd)
                {
                    //MID
                    quad.GetComponent <MeshRenderer>().sharedMaterial = ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.ParallaxMaterialSINGLEMID;
                    //quad.GetComponent<MeshRenderer>().sharedMaterial.SetTexture("_SurfaceTexture", ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.LoadTexture(ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.SurfaceTextureMid));
                    //quad.GetComponent<MeshRenderer>().sharedMaterial.SetTexture("_BumpMap", ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.LoadTexture(ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.BumpMapMid));
                }
                if (lowPoint > highEnd)
                {
                    //HIGH
                    quad.GetComponent <MeshRenderer>().sharedMaterial = ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.ParallaxMaterialSINGLEHIGH;
                    //quad.GetComponent<MeshRenderer>().sharedMaterial.SetTexture("_SurfaceTexture", ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.LoadTexture(ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.SurfaceTextureHigh));
                    //quad.GetComponent<MeshRenderer>().sharedMaterial.SetTexture("_BumpMap", ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.LoadTexture(ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.BumpMapHigh));
                }

                if (lowPoint < lowStart && highPoint > highStart)
                {
                    //LOW-MID-HIGH
                    quad.GetComponent <MeshRenderer>().sharedMaterial = ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.ParallaxMaterial;
                }
                //Steep calculation
                Vector3 normalVector = Vector3.Normalize(quad.transform.position - FlightGlobals.currentMainBody.transform.position);
                bool    hasSteep     = false;

                if (quadLocalMaxSlope < 0.975)   //0.05 = 1/20
                {
                    hasSteep = true;
                }
                if (hasSteep)
                {
                    if (highPoint < lowStart)
                    {
                        //LOW
                        quad.GetComponent <MeshRenderer>().sharedMaterial = ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.ParallaxMaterialSINGLESTEEPLOW;
                        //quad.GetComponent<MeshRenderer>().sharedMaterial.SetTexture("_SurfaceTexture", ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.LoadTexture(ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.SurfaceTexture));
                        //quad.GetComponent<MeshRenderer>().sharedMaterial.SetTexture("_BumpMap", ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.LoadTexture(ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.SurfaceTextureBumpMap));
                    }
                    if (highPoint < highStart &&
                        lowPoint > ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.LowEnd)
                    {
                        //MID
                        quad.GetComponent <MeshRenderer>().sharedMaterial = ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.ParallaxMaterialSINGLESTEEPMID;
                        //quad.GetComponent<MeshRenderer>().sharedMaterial.SetTexture("_SurfaceTexture", ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.LoadTexture(ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.SurfaceTextureMid));
                        //quad.GetComponent<MeshRenderer>().sharedMaterial.SetTexture("_BumpMap", ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.LoadTexture(ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.BumpMapMid));
                    }
                    if (lowPoint > ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.HighEnd)
                    {
                        //HIGH
                        quad.GetComponent <MeshRenderer>().sharedMaterial = ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.ParallaxMaterialSINGLESTEEPHIGH;
                        //quad.GetComponent<MeshRenderer>().sharedMaterial.SetTexture("_SurfaceTexture", ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.LoadTexture(ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.SurfaceTextureHigh));
                        //quad.GetComponent<MeshRenderer>().sharedMaterial.SetTexture("_BumpMap", ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.LoadTexture(ParallaxShaderLoader.parallaxBodies[FlightGlobals.currentMainBody.name].ParallaxBodyMaterial.BumpMapHigh));
                    }
                }
            }
            catch
            {
                Debug.Log("Something went wrong with a quad! (AdaptiveParallax)");
            }
        }