示例#1
0
        void Update()
        {
            var beam = GetComponent <VolumetricLightBeam>();

            if (beam)
            {
                var meshCollider = gameObject.GetOrAddComponent <MeshCollider>();
                Debug.Assert(meshCollider);

                var rangeEnd        = beam.fadeEnd * rangeMultiplier;
                var lerpedRadiusEnd = Mathf.LerpUnclamped(beam.coneRadiusStart, beam.coneRadiusEnd, rangeMultiplier);

                m_Mesh                  = MeshGenerator.GenerateConeZ_Radius(rangeEnd, beam.coneRadiusStart, lerpedRadiusEnd, kMeshColliderNumSides, 0, false);
                m_Mesh.hideFlags        = Consts.ProceduralObjectsHideFlags;
                meshCollider.sharedMesh = m_Mesh;

                if (setIsTrigger)
                {
                    meshCollider.convex    = true;
                    meshCollider.isTrigger = true;
                }

                GameObject.Destroy(this);
            }
        }
        public void RegenerateMesh()
        {
            Debug.Assert(this.m_Master);
            base.gameObject.layer = Config.Instance.geometryLayerID;
            base.gameObject.tag   = Config.Instance.geometryTag;
            if (this.coneMesh && this.m_CurrentMeshType == MeshType.Custom)
            {
                UnityEngine.Object.DestroyImmediate(this.coneMesh);
            }
            this.m_CurrentMeshType = this.m_Master.geomMeshType;
            MeshType mMaster = this.m_Master.geomMeshType;

            if (mMaster == MeshType.Shared)
            {
                this.coneMesh = GlobalMesh.mesh;
                this.meshFilter.sharedMesh = this.coneMesh;
            }
            else if (mMaster != MeshType.Custom)
            {
                Debug.LogError("Unsupported MeshType");
            }
            else
            {
                this.coneMesh           = MeshGenerator.GenerateConeZ_Radius(1f, 1f, 1f, this.m_Master.geomCustomSides, this.m_Master.geomCustomSegments, this.m_Master.geomCap);
                this.coneMesh.hideFlags = Consts.ProceduralObjectsHideFlags;
                this.meshFilter.mesh    = this.coneMesh;
            }
            this.UpdateMaterialAndBounds();
        }
示例#3
0
        public void RegenerateMesh()
        {
            Debug.Assert(Object.op_Implicit((Object)this.m_Master));
            ((Component)this).get_gameObject().set_layer(Config.Instance.geometryLayerID);
            ((Component)this).get_gameObject().set_tag(Config.Instance.geometryTag);
            if (Object.op_Implicit((Object)this.coneMesh) && this.m_CurrentMeshType == MeshType.Custom)
            {
                Object.DestroyImmediate((Object)this.coneMesh);
            }
            this.m_CurrentMeshType = this.m_Master.geomMeshType;
            switch (this.m_Master.geomMeshType)
            {
            case MeshType.Shared:
                this.coneMesh = GlobalMesh.mesh;
                this.meshFilter.set_sharedMesh(this.coneMesh);
                break;

            case MeshType.Custom:
                this.coneMesh = MeshGenerator.GenerateConeZ_Radius(1f, 1f, 1f, this.m_Master.geomCustomSides, this.m_Master.geomCustomSegments, this.m_Master.geomCap);
                ((Object)this.coneMesh).set_hideFlags(Consts.ProceduralObjectsHideFlags);
                this.meshFilter.set_mesh(this.coneMesh);
                break;

            default:
                Debug.LogError((object)"Unsupported MeshType");
                break;
            }
            this.UpdateMaterialAndBounds();
        }
        public static Mesh GenerateConeZ_RadiusAndAngle(float lengthZ, float radiusStart, float coneAngle, int numSides, int numSegments, bool cap)
        {
            Debug.Assert(lengthZ > 0f);
            Debug.Assert((coneAngle <= 0f ? false : coneAngle < 180f));
            float single = lengthZ * Mathf.Tan(coneAngle * 0.0174532924f * 0.5f);

            return(MeshGenerator.GenerateConeZ_Radius(lengthZ, radiusStart, single, numSides, numSegments, cap));
        }
示例#5
0
        /// <summary>
        /// Generate the cone mesh and calls UpdateMaterialAndBounds.
        /// Since this process involves recreating a new mesh, make sure to not call it at every frame during playtime.
        /// </summary>
        public void RegenerateMesh()
        {
            Debug.Assert(m_Master);
            gameObject.layer = Config.Instance.geometryLayerID;
            gameObject.tag = Config.Instance.geometryTag;

            if (coneMesh)
            { DestroyImmediate(coneMesh); }

            coneMesh = MeshGenerator.GenerateConeZ_Radius(1f, 1f, 1f, m_Master.geomSides, kNbSegments, m_Master.geomCap);
            coneMesh.hideFlags = Consts.ProceduralObjectsHideFlags;
            meshFilter.mesh = coneMesh;
            UpdateMaterialAndBounds();
        }
        public static Mesh GenerateConeZ_RadiusAndAngle(
            float lengthZ,
            float radiusStart,
            float coneAngle,
            int numSides,
            int numSegments,
            bool cap)
        {
            Debug.Assert((double)lengthZ > 0.0);
            Debug.Assert((double)coneAngle > 0.0 && (double)coneAngle < 180.0);
            float radiusEnd = lengthZ * Mathf.Tan((float)((double)coneAngle * (Math.PI / 180.0) * 0.5));

            return(MeshGenerator.GenerateConeZ_Radius(lengthZ, radiusStart, radiusEnd, numSides, numSegments, cap));
        }
示例#7
0
        /// <summary>
        /// Generate the cone mesh and calls UpdateMaterialAndBounds.
        /// Since this process involves recreating a new mesh, make sure to not call it at every frame during playtime.
        /// </summary>
        public void RegenerateMesh()
        {
            Debug.Assert(m_Master);

            if (Config.Instance.geometryOverrideLayer)
            {
                gameObject.layer = Config.Instance.geometryLayerID;
            }
            else
            {
                gameObject.layer = m_Master.gameObject.layer;
            }

            gameObject.tag = Config.Instance.geometryTag;

            if (coneMesh && m_CurrentMeshType == MeshType.Custom)
            {
                DestroyImmediate(coneMesh);
            }

            m_CurrentMeshType = m_Master.geomMeshType;

            switch (m_Master.geomMeshType)
            {
            case MeshType.Custom:
            {
                coneMesh           = MeshGenerator.GenerateConeZ_Radius(1f, 1f, 1f, m_Master.geomCustomSides, m_Master.geomCustomSegments, m_Master.geomCap, Config.Instance.useSinglePassShader);
                coneMesh.hideFlags = Consts.ProceduralObjectsHideFlags;
                meshFilter.mesh    = coneMesh;
                break;
            }

            case MeshType.Shared:
            {
                coneMesh = GlobalMesh.Get();
                meshFilter.sharedMesh = coneMesh;
                break;
            }

            default:
            {
                Debug.LogError("Unsupported MeshType");
                break;
            }
            }

            UpdateMaterialAndBounds();
        }
        private void Update()
        {
            VolumetricLightBeam component = base.GetComponent <VolumetricLightBeam>();

            if (component)
            {
                MeshCollider orAddComponent = base.gameObject.GetOrAddComponent <MeshCollider>();
                Debug.Assert(orAddComponent);
                float single  = component.fadeEnd * this.rangeMultiplier;
                float single1 = Mathf.LerpUnclamped(component.coneRadiusStart, component.coneRadiusEnd, this.rangeMultiplier);
                this.m_Mesh               = MeshGenerator.GenerateConeZ_Radius(single, component.coneRadiusStart, single1, 8, 0, false);
                this.m_Mesh.hideFlags     = Consts.ProceduralObjectsHideFlags;
                orAddComponent.sharedMesh = this.m_Mesh;
                if (this.setIsTrigger)
                {
                    orAddComponent.convex    = true;
                    orAddComponent.isTrigger = true;
                }
                UnityEngine.Object.Destroy(this);
            }
        }
示例#9
0
        private void Update()
        {
            VolumetricLightBeam component = (VolumetricLightBeam)((Component)this).GetComponent <VolumetricLightBeam>();

            if (!Object.op_Implicit((Object)component))
            {
                return;
            }
            MeshCollider orAddComponent = ((Component)this).get_gameObject().GetOrAddComponent <MeshCollider>();

            Debug.Assert(Object.op_Implicit((Object)orAddComponent));
            float lengthZ   = component.fadeEnd * this.rangeMultiplier;
            float radiusEnd = Mathf.LerpUnclamped(component.coneRadiusStart, component.coneRadiusEnd, this.rangeMultiplier);

            this.m_Mesh = MeshGenerator.GenerateConeZ_Radius(lengthZ, component.coneRadiusStart, radiusEnd, 8, 0, false);
            ((Object)this.m_Mesh).set_hideFlags(Consts.ProceduralObjectsHideFlags);
            orAddComponent.set_sharedMesh(this.m_Mesh);
            if (this.setIsTrigger)
            {
                orAddComponent.set_convex(true);
                ((Collider)orAddComponent).set_isTrigger(true);
            }
            Object.Destroy((Object)this);
        }
示例#10
0
        public static Mesh Get()
        {
            var needDoubleSided = Config.Instance.requiresDoubleSidedMesh;

            if (ms_Mesh == null ||
                ms_DoubleSided != needDoubleSided)
            {
                Destroy();

                ms_Mesh = MeshGenerator.GenerateConeZ_Radius(
                    lengthZ: 1f,
                    radiusStart: 1f,
                    radiusEnd: 1f,
                    numSides: Config.Instance.sharedMeshSides,
                    numSegments: Config.Instance.sharedMeshSegments,
                    cap: true,
                    doubleSided: needDoubleSided);

                ms_Mesh.hideFlags = Consts.ProceduralObjectsHideFlags;
                ms_DoubleSided    = needDoubleSided;
            }

            return(ms_Mesh);
        }
示例#11
0
        void ComputeZone()
        {
            if (m_Beam)
            {
                var rangeEnd        = m_Beam.fallOffEnd * rangeMultiplier;
                var lerpedRadiusEnd = Mathf.LerpUnclamped(m_Beam.coneRadiusStart, m_Beam.coneRadiusEnd, rangeMultiplier);

                if (m_Beam.dimensions == Dimensions.Dim3D)
                {
                    var meshCollider = gameObject.GetOrAddComponent <MeshCollider>();
                    Debug.Assert(meshCollider);

                    int sides = Mathf.Min(m_Beam.geomSides, kMeshColliderNumSides);
                    var mesh  = MeshGenerator.GenerateConeZ_Radius(rangeEnd, m_Beam.coneRadiusStart, lerpedRadiusEnd, sides, 0, false, false);
                    mesh.hideFlags = Consts.ProceduralObjectsHideFlags;

                    meshCollider.sharedMesh = mesh;
                    meshCollider.convex     = setIsTrigger;
                    meshCollider.isTrigger  = setIsTrigger;
                }
                else
                {
                    if (m_PolygonCollider2D == null)
                    {
                        m_PolygonCollider2D = gameObject.GetOrAddComponent <PolygonCollider2D>();
                        Debug.Assert(m_PolygonCollider2D);
                    }

                    var polyCoordsLS = new Vector2[] // polygon coord in local space
                    {
                        new Vector2(0.0f, -m_Beam.coneRadiusStart),
                        new Vector2(rangeEnd, -lerpedRadiusEnd),
                        new Vector2(rangeEnd, lerpedRadiusEnd),
                        new Vector2(0.0f, m_Beam.coneRadiusStart)
                    };

                    if (m_DynamicOcclusionRaycasting && m_DynamicOcclusionRaycasting.planeEquationWS.IsValid())
                    {
                        var plane3dWS = m_DynamicOcclusionRaycasting.planeEquationWS;

                        if (Utils.IsAlmostZero(plane3dWS.normal.z))
                        {
                            // Compute 2 points on the plane in world space
                            // Use this technique instead of transforming the plane's normal to fully support scaling

                            var ptOnPlane1 = plane3dWS.ClosestPointOnPlaneCustom(Vector3.zero);
                            var ptOnPlane2 = plane3dWS.ClosestPointOnPlaneCustom(Vector3.up);

                            if (Utils.IsAlmostZero(Vector3.SqrMagnitude(ptOnPlane1 - ptOnPlane2)))
                            {
                                ptOnPlane1 = plane3dWS.ClosestPointOnPlaneCustom(Vector3.right);
                            }

                            // Compute 2 points on the plane in local space
                            ptOnPlane1 = transform.InverseTransformPoint(ptOnPlane1);
                            ptOnPlane2 = transform.InverseTransformPoint(ptOnPlane2);

                            // Compute plane equation in local space
                            var plane2dLS = PolygonHelper.Plane2D.FromPoints(ptOnPlane1, ptOnPlane2);
                            if (plane2dLS.normal.x > 0.0f)
                            {
                                plane2dLS.Flip();
                            }

                            polyCoordsLS = plane2dLS.CutConvex(polyCoordsLS);
                        }
                    }

                    m_PolygonCollider2D.points    = polyCoordsLS;
                    m_PolygonCollider2D.isTrigger = setIsTrigger;
                }
            }
        }