public bool BuilldDecalFromCollectedPolygons(DecalProjection decalProjection)
 {
     this.CleanResult();
     this.decalMeshClipper.Clip(decalProjection, this.collectedPolygonsMeshBuilder, this.meshBuilder);
     this.decalUVProjector.Project(this.meshBuilder, decalProjection);
     return(true);
 }
 public void DrawDecals(UpdateEvent evt, StreaminWeaponNode weaponNode, [JoinAll] SingleNode <DecalManagerComponent> decalManagerNode)
 {
     if (decalManagerNode.component.EnableDecals)
     {
         StreamingDecalProjectorComponent streamingDecalProjector = weaponNode.streamingDecalProjector;
         DecalManagerComponent            component = decalManagerNode.component;
         if ((weaponNode.streamHit.StaticHit != null) && ((streamingDecalProjector.LastDecalCreationTime + streamingDecalProjector.DecalCreationPeriod) <= Time.time))
         {
             streamingDecalProjector.LastDecalCreationTime = Time.time;
             Vector3         barrelOriginWorld = new MuzzleVisualAccessor(weaponNode.muzzlePoint).GetBarrelOriginWorld();
             Vector3         normalized        = (weaponNode.streamHit.StaticHit.Position - barrelOriginWorld).normalized;
             DecalProjection decalProjection   = new DecalProjection {
                 AtlasHTilesCount      = streamingDecalProjector.AtlasHTilesCount,
                 AtlasVTilesCount      = streamingDecalProjector.AtlasVTilesCount,
                 SurfaceAtlasPositions = streamingDecalProjector.SurfaceAtlasPositions,
                 HalfSize   = streamingDecalProjector.HalfSize,
                 Up         = streamingDecalProjector.Up,
                 Distantion = streamingDecalProjector.Distance,
                 Ray        = new Ray(barrelOriginWorld - normalized, normalized)
             };
             Mesh mesh = null;
             if (component.DecalMeshBuilder.Build(decalProjection, ref mesh))
             {
                 component.BulletHoleDecalManager.AddDecal(mesh, streamingDecalProjector.Material, streamingDecalProjector.Color, streamingDecalProjector.LifeTime);
             }
         }
     }
 }
 private void DrawHammerHitDecals(Vector3 shotDirection, PelletThrowingGraphicsNode weapon, SingleNode <DecalManagerComponent> decalManagerNode, DecalSettingsComponent settings)
 {
     if (settings.EnableDecals && (settings.MaxDecalsForHammer > 0))
     {
         DecalMeshBuilder              decalMeshBuilder       = decalManagerNode.component.DecalMeshBuilder;
         BulletHoleDecalManager        bulletHoleDecalManager = decalManagerNode.component.BulletHoleDecalManager;
         MuzzlePointComponent          muzzlePoint            = weapon.muzzlePoint;
         HammerDecalProjectorComponent hammerDecalProjector   = weapon.hammerDecalProjector;
         Vector3 barrelOriginWorld = new MuzzleVisualAccessor(muzzlePoint).GetBarrelOriginWorld();
         decalMeshBuilder.Clean();
         DecalProjection projection2 = new DecalProjection {
             HalfSize   = hammerDecalProjector.CombineHalfSize,
             Distantion = hammerDecalProjector.Distance,
             Ray        = new Ray(barrelOriginWorld - shotDirection, shotDirection)
         };
         DecalProjection decalProjection = projection2;
         if (decalMeshBuilder.CompleteProjectionByRaycast(decalProjection) && decalMeshBuilder.CollectPolygons(decalProjection))
         {
             Vector3     localDirection = muzzlePoint.Current.InverseTransformVector(shotDirection);
             Vector3[]   vectorArray    = PelletDirectionsCalculator.GetRandomDirections(weapon.hammerPelletCone, muzzlePoint.Current.rotation, localDirection);
             List <Mesh> list           = new List <Mesh>(vectorArray.Length);
             for (int i = 0; i < Math.Min(vectorArray.Length, settings.MaxDecalsForHammer); i++)
             {
                 Vector3 direction = vectorArray[i];
                 projection2 = new DecalProjection {
                     AtlasHTilesCount      = hammerDecalProjector.AtlasHTilesCount,
                     AtlasVTilesCount      = hammerDecalProjector.AtlasVTilesCount,
                     SurfaceAtlasPositions = hammerDecalProjector.SurfaceAtlasPositions,
                     HalfSize   = hammerDecalProjector.HalfSize,
                     Up         = hammerDecalProjector.Up,
                     Distantion = hammerDecalProjector.Distance,
                     Ray        = new Ray(barrelOriginWorld - shotDirection, direction)
                 };
                 DecalProjection projection3 = projection2;
                 if (decalMeshBuilder.CompleteProjectionByRaycast(projection3))
                 {
                     decalMeshBuilder.BuilldDecalFromCollectedPolygons(projection3);
                     Mesh mesh = null;
                     if (decalMeshBuilder.GetResultToMesh(ref mesh))
                     {
                         list.Add(mesh);
                     }
                 }
             }
             if (list.Count != 0)
             {
                 CombineInstance[] combine = new CombineInstance[list.Count];
                 for (int j = 0; j < list.Count; j++)
                 {
                     combine[j].mesh = list[j];
                 }
                 Mesh decalMesh = new Mesh();
                 decalMesh.CombineMeshes(combine, true, false);
                 decalMesh.RecalculateBounds();
                 bulletHoleDecalManager.AddDecal(decalMesh, hammerDecalProjector.Material, hammerDecalProjector.Color, hammerDecalProjector.LifeTime);
             }
         }
     }
 }
        public bool CompleteProjectionByRaycast(DecalProjection decalProjection)
        {
            RaycastHit hit;

            if (!Physics.Raycast(decalProjection.Ray.origin, decalProjection.Ray.direction, out hit, decalProjection.Distantion, LayerMasks.VISUAL_STATIC))
            {
                return(false);
            }
            decalProjection.ProjectionHit = hit;
            return(hit.normal.Equals(Vector3.zero) || true);
        }
        private void UpdateDecalMesh()
        {
            DecalProjection decalProjection = new DecalProjection {
                Ray                   = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f)),
                Distantion            = this.projectDistantion,
                HalfSize              = this.projectSize,
                AtlasHTilesCount      = this.hTilesCount,
                AtlasVTilesCount      = this.vTilesCount,
                SurfaceAtlasPositions = this.surfaceAtlasPositions
            };

            this.meshBuilder.Build(decalProjection, ref this.decalMesh);
        }
Exemple #6
0
        protected GameObject DrawGraffiti(DecalManagerComponent managerComponent, DynamicDecalProjectorComponent decalProjector, Vector3 position, Vector3 direction, Vector3 up)
        {
            DecalProjection decalProjection = new DecalProjection {
                AtlasHTilesCount      = decalProjector.AtlasHTilesCount,
                AtlasVTilesCount      = decalProjector.AtlasVTilesCount,
                SurfaceAtlasPositions = decalProjector.SurfaceAtlasPositions,
                HalfSize   = decalProjector.HalfSize,
                Up         = up,
                Distantion = decalProjector.Distance,
                Ray        = new Ray(position, direction)
            };
            Mesh mesh = null;

            return(!managerComponent.DecalMeshBuilder.Build(decalProjection, ref mesh) ? null : managerComponent.GraffitiDynamicDecalManager.AddGraffiti(mesh, decalProjector.Material, decalProjector.Color, decalProjector.LifeTime));
        }
 public bool Build(DecalProjection decalProjection, ref Mesh mesh)
 {
     this.Clean();
     if (!this.CompleteProjectionByRaycast(decalProjection))
     {
         return(false);
     }
     if (!this.CollectPolygons(decalProjection))
     {
         return(false);
     }
     this.BuilldDecalFromCollectedPolygons(decalProjection);
     this.GetResultToMesh(ref mesh);
     return(true);
 }
Exemple #8
0
        protected void DrawHitDecal(DecalManagerComponent managerComponent, DynamicDecalProjectorComponent decalProjector, Vector3 position, Vector3 direction)
        {
            DecalProjection decalProjection = new DecalProjection {
                AtlasHTilesCount      = decalProjector.AtlasHTilesCount,
                AtlasVTilesCount      = decalProjector.AtlasVTilesCount,
                SurfaceAtlasPositions = decalProjector.SurfaceAtlasPositions,
                HalfSize   = decalProjector.HalfSize,
                Up         = decalProjector.Up,
                Distantion = decalProjector.Distance,
                Ray        = new Ray(position, direction)
            };
            Mesh mesh = null;

            if (managerComponent.DecalMeshBuilder.Build(decalProjection, ref mesh))
            {
                managerComponent.BulletHoleDecalManager.AddDecal(mesh, decalProjector.Material, decalProjector.Color, decalProjector.LifeTime);
            }
        }
 public bool CollectPolygons(DecalProjection decalProjection) =>
 this.decalPolygonCollector.Collect(decalProjection, this.collectedPolygonsMeshBuilder);