void IMyDecalProxy.AddDecals(MyHitInfo hitInfo, MyStringHash source, object customdata, IMyDecalHandler decalHandler)
        {
            Debug.Assert(m_mapIdToBlock.Count > 0);
            MyCubeGridHitInfo            gridHitInfo      = customdata as MyCubeGridHitInfo;
            MySlimBlock                  block            = m_mapIdToBlock.First().Value;
            MyPhysicalMaterialDefinition physicalMaterial = block.BlockDefinition.PhysicalMaterial;
            MyDecalRenderInfo            renderable       = new MyDecalRenderInfo();

            renderable.Flags          = physicalMaterial.Transparent ? MyDecalFlags.Transparent : MyDecalFlags.None;
            renderable.Position       = Vector3D.Transform(hitInfo.Position, CubeGrid.PositionComp.WorldMatrixInvScaled);
            renderable.Normal         = Vector3D.TransformNormal(hitInfo.Normal, CubeGrid.PositionComp.WorldMatrixInvScaled);
            renderable.RenderObjectId = CubeGrid.Render.GetRenderObjectID();
            renderable.Material       = MyStringHash.GetOrCompute(physicalMaterial.Id.SubtypeName);

            if (gridHitInfo != null)
            {
                VertexBoneIndicesWeights?boneIndicesWeights = gridHitInfo.Triangle.GetAffectingBoneIndicesWeights(ref m_boneIndexWeightTmp);
                if (boneIndicesWeights.HasValue)
                {
                    renderable.BoneIndices = boneIndicesWeights.Value.Indices;
                    renderable.BoneWeights = boneIndicesWeights.Value.Weights;

                    var decalId = decalHandler.AddDecal(ref renderable);
                    if (decalId != null)
                    {
                        CubeGrid.RenderData.AddDecal(Position, gridHitInfo, decalId.Value);
                    }

                    return;
                }
            }

            decalHandler.AddDecal(ref renderable);
        }
        /// <param name="damage">Not used for now but could be used as a multiplier instead of random decal size</param>
        public static void HandleAddDecal(IMyEntity entity, MyHitInfo hitInfo, MyStringHash material = default(MyStringHash), MyStringHash source = default(MyStringHash), object customdata = null, float damage = -1)
        {
            IMyDecalProxy proxy = entity as IMyDecalProxy;

            if (proxy != null)
            {
                AddDecal(proxy, ref hitInfo, damage, source, customdata, material);
                return;
            }

            MyCubeGrid grid = entity as MyCubeGrid;

            if (grid != null)
            {
                MyCubeGridHitInfo info = customdata as MyCubeGridHitInfo;
                MySlimBlock       block;
                if (info == null)
                {
                    block = grid.GetTargetedBlock(hitInfo.Position);
                    if (block == null)
                    {
                        return;
                    }

                    // If info is not provided, provide info with just block position
                    m_gridHitInfo.Position = block.Position;
                    customdata             = m_gridHitInfo;
                }
                else
                {
                    // If info is provided, lookup for the cube using provided position
                    MyCube cube;
                    bool   found = grid.TryGetCube(info.Position, out cube);
                    if (!found)
                    {
                        return;
                    }

                    block = cube.CubeBlock;
                }

                var compoundBlock = block != null ? block.FatBlock as MyCompoundCubeBlock : null;
                if (compoundBlock == null)
                {
                    proxy = block;
                }
                else
                {
                    proxy = compoundBlock;
                }
            }

            if (proxy == null)
            {
                return;
            }

            AddDecal(proxy, ref hitInfo, damage, source, customdata, material);
        }
Exemple #3
0
        public void AddDecal(Vector3I position, MyCubeGridHitInfo gridHitInfo, uint decalId)
        {
            MyCube cube;
            bool   found = m_gridRender.CubeGrid.TryGetCube(position, out cube);

            if (!found)
            {
                return;
            }

            if (gridHitInfo.CubePartIndex != -1)
            {
                var part = cube.Parts[gridHitInfo.CubePartIndex];
                var cell = GetCell(part.InstanceData.Translation);
                cell.AddCubePartDecal(part, decalId);
            }

            List <MyDecalPartIdentity> decals;

            found = m_cubeDecals.TryGetValue(position, out decals);
            if (!found)
            {
                decals = new List <MyDecalPartIdentity>();
                m_cubeDecals[position] = decals;
            }

            if (decals.Count > MAX_DECALS_PER_CUBE)
            {
                RemoveDecal(position, decals, 0);
                decals.RemoveAt(0);
            }

            decals.Add(new MyDecalPartIdentity()
            {
                DecalId = decalId, CubePartIndex = gridHitInfo.CubePartIndex
            });
        }
        public void AddDecal(Vector3I position, MyCubeGridHitInfo gridHitInfo, uint decalId)
        {
            MyCube cube;
            bool found = m_gridRender.CubeGrid.TryGetCube(position, out cube);
            if (!found)
                return;

            if (gridHitInfo.CubePartIndex != -1)
            {
                var part = cube.Parts[gridHitInfo.CubePartIndex];
                var cell = GetCell(part.InstanceData.Translation);
                cell.AddCubePartDecal(part, decalId);
            }

            List<MyDecalPartIdentity> decals;
            found = m_cubeDecals.TryGetValue(position, out decals);
            if (!found)
            {
                decals = new List<MyDecalPartIdentity>();
                m_cubeDecals[position] = decals;
            }

            if (decals.Count > MAX_DECALS_PER_CUBE)
            {
                RemoveDecal(position, decals, 0);
                decals.RemoveAt(0);
            }

            decals.Add(new MyDecalPartIdentity() { DecalId = decalId, CubePartIndex = gridHitInfo.CubePartIndex });
        }