public static Mesh NewBoltMesh(Vector2 vector, SimpleCurve strDist = null, SimpleCurve widthDist = null, SimpleCurve strTime = null, SimpleCurve widthTime = null, float originVariance = 0.0f, float capSize = 1.0f, float vertexInterval = 0.25f)
        {
            LightningLaserBoltMeshMaker.lightningOrigin = vector;

            /*
             * lightningOrigin.x += Rand.Range(-originVariance, originVariance);
             * lightningOrigin.y += Rand.Range(-originVariance, originVariance);
             */
            LightningLaserBoltMeshMaker.MakeVerticesBase(vertexInterval, originVariance);
            LightningLaserBoltMeshMaker.PeturbVerticesRandomly(strDist);
            LightningLaserBoltMeshMaker.DoubleVertices(widthDist);
            return(LightningLaserBoltMeshMaker.MeshFromVerts());
        }
        public static Mesh NewBoltMesh(Vector2 vector, float str = 3f, float width = 1f, float originVariance = 0.0f, float capSize = 1.0f, float vertexInterval = 0.25f)
        {
            LightningLaserBoltMeshMaker.lightningOrigin = vector;

            /*
             * lightningOrigin.x += Rand.Range(-originVariance, originVariance);
             * lightningOrigin.y += Rand.Range(-originVariance, originVariance);
             */
            LightningLaserBoltMeshMaker.MakeVerticesBase(vertexInterval, originVariance);
            LightningLaserBoltMeshMaker.PeturbVerticesRandomly(str);
            LightningLaserBoltMeshMaker.DoubleVertices(width, capSize);
            return(LightningLaserBoltMeshMaker.MeshFromVerts(width));
        }
Beispiel #3
0
        public override void Draw()
        {
            SetupDrawing();

            Color color    = projDef.graphicData.color;
            Color colorTwo = projDef.graphicData.colorTwo;

            color.a    *= Opacity;
            colorTwo.a *= (Opacity * projDef.flareOpacityMod);
            LaserBeamGraphic.BeamMatPropertyBlock.SetColor(ShaderPropertyIDs.Color, color);
            LaserBeamGraphic.FlareMatPropertyBlock.SetColor(ShaderPropertyIDs.Color, colorTwo);
            LaserBeamGraphic.FlareMatPropertyBlock.SetColor(ShaderPropertyIDs.ColorTwo, color);
            if (Lightning)
            {
                Vector3 vector;
                vector.x = (float)b.x;
                vector.y = (float)b.y;
                vector.z = (float)b.z;
                float distance = Vector3.Distance(a, b);

                for (int i = 0; i < projDef.ArcCount; i++)
                {
                    if (this.projDef.graphicData != null)
                    {
                        if (this.projDef.graphicData.graphicClass != null)
                        {
                            if (!Find.TickManager.Paused && Find.TickManager.TicksGame % this.projDef.flickerFrameTime == 0)
                            {
                                if (this.projDef.graphicData.graphicClass == typeof(Graphic_Flicker))
                                {
                                    //    Log.Message("Graphic_Flicker get mat for arc " + (i + 1));
                                    mats[i] = projDef.GetBeamMaterial((this.projDef.materials.IndexOf(mats[i]) + 1 < this.projDef.materials.Count ? this.projDef.materials.IndexOf(mats[i]) + 1 : 0)) ?? projDef.graphicData.Graphic.MatSingle;
                                }
                                else if (this.projDef.graphicData.graphicClass == typeof(Graphic_Random))
                                {
                                    //    Log.Message("Graphic_Random get mat for arc " + (i + 1));
                                    mats[i] = this.projDef.materials.RandomElement() ?? projDef.graphicData.Graphic.MatSingle;
                                }
                            }
                        }
                    }
                    float mult = Mathf.InverseLerp(projDef.lifetime, 0f, ticks);
                    //    if (Find.TickManager.TicksGame % this.projDef.flickerFrameTime != 0)  Log.Message("Mult for Arc "+(i+1)+" : "+mult);
                    if (!Find.TickManager.Paused && Find.TickManager.TicksGame % this.projDef.LightningFrameTime == 0)
                    {
                        if (projDef.lightningArcVarianceDistCurve != null && projDef.lightningArcWidthDistCurve != null)
                        {
                            meshes[i] = meshes[i] != null && Static ? meshes[i] : LightningLaserBoltMeshMaker.NewBoltMesh(new Vector2(0, -(distance + 0.25f)), projDef.lightningArcVarianceDistCurve, projDef.lightningArcWidthDistCurve, projDef.lightningArcVarianceTimeCurve, projDef.lightningArcWidthTimeCurve, i == 0 ? 0f : 0.5f, projDef.capSize);
                        }
                        else
                        {
                            meshes[i] = meshes[i] != null && Static ? meshes[i] : LightningLaserBoltMeshMaker.NewBoltMesh(new Vector2(0, -(distance + 0.25f)), projDef.LightningVariance, beamWidth * mult, i == 0 ? 0f : 0.5f, projDef.capSize);
                        }
                    }
                    Graphics.DrawMesh(this.meshes[i], this.b, Quaternion.LookRotation((vector - this.a).normalized), FadedMaterialPool.FadedVersionOf(mats[i], Opacity), 0, null, 0, LaserBeamGraphic.BeamMatPropertyBlock, 0);
                    Graphics.DrawMesh(this.meshes[i], this.b, Quaternion.LookRotation((vector - this.a).normalized), FadedMaterialPool.FadedVersionOf(projDef.flareMat ?? FlareMat, Opacity * 0.5f), 0, null, 0, LaserBeamGraphic.FlareMatPropertyBlock, 0);
                }
            }
            else
            {
                if (this.projDef.graphicData != null)
                {
                    if (this.projDef.graphicData.graphicClass != null)
                    {
                        if (!Find.TickManager.Paused && Find.TickManager.TicksGame % this.projDef.flickerFrameTime == 0)
                        {
                            if (this.projDef.graphicData.graphicClass == typeof(Graphic_Flicker))
                            {
                                //    Log.Message("Graphic_Flicker get mat for beam ");
                                materialBeam = projDef.GetBeamMaterial((this.projDef.materials.IndexOf(materialBeam) + 1 < this.projDef.materials.Count ? this.projDef.materials.IndexOf(materialBeam) + 1 : 0)) ?? projDef.graphicData.Graphic.MatSingle;
                            }
                            if (this.projDef.graphicData.graphicClass == typeof(Graphic_Random))
                            {
                                //    Log.Message("Graphic_Random get mat for beam ");
                                materialBeam = projDef.GetBeamMaterial(0) ?? projDef.graphicData.Graphic.MatSingle;
                            }
                        }
                    }
                }
                Graphics.DrawMesh(mesh, drawingMatrixBeam, FadedMaterialPool.FadedVersionOf(materialBeam, Opacity), 0, null, 0, LaserBeamGraphic.BeamMatPropertyBlock);
                Graphics.DrawMesh(mesh, drawingMatrixFlare, projDef.flareMat ?? FlareMat, 0, null, 0, LaserBeamGraphic.FlareMatPropertyBlock);
                //    Graphics.DrawMesh(mesh, drawingMatrix, FadedMaterialPool.FadedVersionOf(materialBeam, opacity), 0);
            }
        }
Beispiel #4
0
        public void SetupDrawing()
        {
            if (mesh != null)
            {
                return;
            }

            materialBeam = projDef.GetBeamMaterial(colorIndex) ?? LaserBeamGraphic.BeamMat;

            if (this.projDef.graphicData != null)
            {
                if (this.projDef.graphicData.graphicClass != null)
                {
                    if (this.projDef.graphicData.graphicClass == typeof(Graphic_Flicker))
                    {
                        //    Log.Message("Graphic_Flicker get mat for arc " + (i + 1));
                        materialBeam = projDef.GetBeamMaterial((this.projDef.materials.IndexOf(materialBeam) + 1 < this.projDef.materials.Count ? this.projDef.materials.IndexOf(materialBeam) + 1 : 0)) ?? projDef.graphicData.Graphic.MatSingle;
                    }
                    if (this.projDef.graphicData.graphicClass == typeof(Graphic_Random))
                    {
                        materialBeam = projDef.GetBeamMaterial(0) ?? projDef.graphicData.Graphic.MatSingle;
                    }
                }
            }
            beamWidth      = projDef.beamWidth;
            flareWidth     = projDef.flareWidth;
            flareWidthMod  = projDef.flareWidthMod;
            flareLength    = projDef.flareLength;
            flareLengthMod = projDef.flareLengthMod;
            Quaternion rotation = Quaternion.LookRotation(a - b);
            //    Quaternion rotation = Quaternion.LookRotation(b - a);
            Vector3 dir = (b - a).normalized;

            beamLength = (b - a).magnitude;

            Vector3 drawingScale    = new Vector3(beamWidth, 1f, beamLength);
            Vector3 drawingPosition = (a + b) / 2;

            //    drawingPosition.y = AltitudeLayer.MetaOverlays.AltitudeFor();
            drawingMatrixBeam.SetTRS(drawingPosition, rotation, drawingScale);
            if (flareWidth == -1)
            {
                flareWidth = beamWidth * flareWidthMod;
            }
            if (flareLength == -1)
            {
                flareLength = beamLength * flareLengthMod;
            }
            Quaternion rotationFlare        = Quaternion.LookRotation(a - b);
            Vector3    drawingScaleFlare    = new Vector3(flareWidth, 1f, flareLength);
            Vector3    drawingPositionFlare = a + (dir * flareLength) / 2; //FlarePos(a,b, 0.1f);

            drawingMatrixFlare.SetTRS(drawingPositionFlare, rotationFlare, drawingScaleFlare);
            float textureRatio = 1.0f * materialBeam.mainTexture.width / materialBeam.mainTexture.height;
            float seamTexture  = projDef.seam < 0 ? textureRatio : projDef.seam;
            float capLength    = beamWidth / textureRatio / 2f * seamTexture;
            float seamGeometry = beamLength <= capLength * 2 ? 0.5f : capLength * 2 / beamLength;

            if (Lightning && meshes.Count < projDef.ArcCount * (Static ? 1 :  (projDef.lifetime / projDef.LightningFrameTime)))
            {
                float distance = Vector3.Distance(a, b);
                for (int i = 0; i < projDef.ArcCount; i++)
                {
                    if (projDef.lightningArcVarianceDistCurve != null && projDef.lightningArcWidthDistCurve != null)
                    {
                        meshes.Add(LightningLaserBoltMeshMaker.NewBoltMesh(new Vector2(0, -(distance + 0.25f)), projDef.lightningArcVarianceDistCurve, projDef.lightningArcWidthDistCurve, projDef.lightningArcVarianceTimeCurve, projDef.lightningArcWidthTimeCurve, i == 0 ? 0f : 0.5f, projDef.capSize));
                    }
                    else
                    {
                        meshes.Add(LightningLaserBoltMeshMaker.NewBoltMesh(new Vector2(0, -(distance + 0.25f)), projDef.LightningVariance, beamWidth, i * 0.1f, projDef.capSize));
                    }
                    mats.Add(projDef.GetBeamMaterial(i) ?? LaserBeamGraphic.BeamMat);
                }
                //    this.mesh = LightningBoltMeshMakerOG.NewBoltMesh(new Vector2(0, -(distance + 0.25f)), def.LightningVariance);
            }
            else
            {
                this.mesh = MeshMakerLaser.Mesh(seamTexture, seamGeometry);
            }
        }