uint? IMyDecalHandler.AddDecal(ref MyDecalRenderInfo data)
        {
            CheckEnabled();

            IReadOnlyList<MyDecalMaterial> materials;
            bool found = MyDecalMaterials.TryGetDecalMaterial(Source.String, data.Material.String, out materials);
            if (!found)
            {
                if (MyFakes.ENABLE_USE_DEFAULT_DAMAGE_DECAL)
                    found = MyDecalMaterials.TryGetDecalMaterial(DEFAULT, DEFAULT, out materials);

                if (!found)
                    return null;
            }

            int index = (int)Math.Round(MyRandom.Instance.NextFloat() * (materials.Count - 1));
            MyDecalMaterial material = materials[index];

            float rotation = material.Rotation;
            if (material.Rotation == float.PositiveInfinity)
                rotation = MyRandom.Instance.NextFloat() * MathHelper.TwoPi;

            var size = material.MinSize;
            if (material.MaxSize > material.MinSize)
                size += MyRandom.Instance.NextFloat() * (material.MaxSize - material.MinSize);

            MyDecalTopoData topoData = new MyDecalTopoData();
            topoData.Position = data.Position;
            topoData.Normal = data.Normal;
            topoData.Scale = new Vector3(size, size, material.Depth);
            topoData.Rotation = rotation;

            string sourceTarget = MyDecalMaterials.GetStringId(Source, data.Material);
            return MyRenderProxy.CreateDecal(data.RenderObjectId, ref topoData, data.Flags, sourceTarget, material.StringId, index);
        }
        void IMyDecalProxy.AddDecals(MyHitInfo hitInfo, MyStringHash source, object customdata, IMyDecalHandler decalHandler)
        {
            MyCharacterHitInfo charHitInfo = customdata as MyCharacterHitInfo;
            if (charHitInfo == null || charHitInfo.BoneIndex == -1)
                return;

            MyDecalRenderInfo renderable = new MyDecalRenderInfo();
            renderable.Position = charHitInfo.Triangle.IntersectionPointInObjectSpace;
            renderable.Normal = charHitInfo.Triangle.NormalInObjectSpace;
            renderable.RenderObjectId = Render.GetRenderObjectID();
            renderable.Material = MyStringHash.GetOrCompute(m_characterDefinition.PhysicalMaterial);

            var decalId = decalHandler.AddDecal(ref renderable);
            if (decalId == null)
                return;

            AddBoneDecal(decalId.Value, charHitInfo.HitPositionBindingPose, charHitInfo.HitNormalBindingPose, charHitInfo.BoneIndex);
        }
Exemple #3
0
        void IMyDecalProxy.AddDecals(MyHitInfo hitInfo, MyStringHash source, object customdata, IMyDecalHandler decalHandler)
        {
            MyDecalRenderInfo renderable = new MyDecalRenderInfo();
            MyCubeGridHitInfo gridHitInfo = customdata as MyCubeGridHitInfo;
            renderable.Flags = BlockDefinition.PhysicalMaterial.Transparent ? MyDecalFlags.Transparent : MyDecalFlags.None;
            if (FatBlock == null)
            {
                renderable.Position = Vector3D.Transform(hitInfo.Position, CubeGrid.PositionComp.WorldMatrixInvScaled);
                renderable.Normal = Vector3D.TransformNormal(hitInfo.Normal, CubeGrid.PositionComp.WorldMatrixInvScaled);
                renderable.RenderObjectId = CubeGrid.Render.GetRenderObjectID();
            }
            else
            {
                renderable.Position = Vector3D.Transform(hitInfo.Position, FatBlock.PositionComp.WorldMatrixInvScaled);
                renderable.Normal = Vector3D.TransformNormal(hitInfo.Normal, FatBlock.PositionComp.WorldMatrixInvScaled);
                renderable.RenderObjectId = FatBlock.Render.GetRenderObjectID();
            }
            renderable.Material = MyStringHash.GetOrCompute(BlockDefinition.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);
        }
Exemple #4
0
        void IMyDecalProxy.AddDecals(MyHitInfo hitInfo, MyStringHash source, object customdata, IMyDecalHandler decalHandler)
        {
            MyDecalRenderInfo renderable = new MyDecalRenderInfo();
            renderable.Flags = MyDecalFlags.World;
            renderable.Position = hitInfo.Position;
            renderable.Normal = hitInfo.Normal;
            renderable.RenderObjectId = Render.GetRenderObjectID();
            renderable.Material = Physics.GetMaterialAt(hitInfo.Position);

            decalHandler.AddDecal(ref renderable);
        }
        void IMyDecalProxy.AddDecals(MyHitInfo hitInfo, MyStringHash source, object customdata, IMyDecalHandler decalHandler)
        {
            MyDecalRenderInfo renderable = new MyDecalRenderInfo();
            renderable.Flags = BlockDefinition.PhysicalMaterial.Transparent ? MyDecalFlags.Transparent : MyDecalFlags.None;
            if (FatBlock == null)
            {
                renderable.Position = Vector3D.Transform(hitInfo.Position, CubeGrid.PositionComp.WorldMatrixInvScaled);
                renderable.Normal = Vector3D.TransformNormal(hitInfo.Normal, CubeGrid.PositionComp.WorldMatrixInvScaled);
                renderable.RenderObjectId = CubeGrid.Render.GetRenderObjectID();
            }
            else
            {
                renderable.Position = Vector3D.Transform(hitInfo.Position, FatBlock.PositionComp.WorldMatrixInvScaled);
                renderable.Normal = Vector3D.TransformNormal(hitInfo.Normal, FatBlock.PositionComp.WorldMatrixInvScaled);
                renderable.RenderObjectId = FatBlock.Render.GetRenderObjectID();
            }
            renderable.Material = MyStringHash.GetOrCompute(BlockDefinition.PhysicalMaterial.Id.SubtypeName);

            var decalId = decalHandler.AddDecal(ref renderable);
            if (decalId != null)
                CubeGrid.RenderData.AddDecal(Position, decalId.Value);
        }
Exemple #6
0
 void IMyDecalProxy.AddDecals(MyHitInfo hitInfo, MyStringHash source, object customdata, IMyDecalHandler decalHandler)
 {
     MyDecalRenderInfo info = new MyDecalRenderInfo();
     info.Position = hitInfo.Position;
     info.Normal = hitInfo.Normal;
     info.RenderObjectId = -1;
     info.Flags = MyDecalFlags.World;
     info.Material = Physics.MaterialType;
     decalHandler.AddDecal(ref info);
 }
Exemple #7
0
        uint? IMyDecalHandler.AddDecal(ref MyDecalRenderInfo data)
        {
            CheckEnabled();

            IReadOnlyList<MyDecalMaterial> materials;
            bool found = MyDecalMaterials.TryGetDecalMaterial(Source.String, data.Material.String, out materials);
            if (!found)
            {
                if (MyFakes.ENABLE_USE_DEFAULT_DAMAGE_DECAL)
                    found = MyDecalMaterials.TryGetDecalMaterial(DEFAULT, DEFAULT, out materials);

                if (!found)
                    return null;
            }

            MyDecalBindingInfo binding;
            if (data.Binding == null)
            {
                binding = new MyDecalBindingInfo();
                binding.Position = data.Position;
                binding.Normal = data.Normal;
                binding.Transformation = Matrix.Identity;
            }
            else
            {
                binding = data.Binding.Value;
            }

            int index = (int)Math.Round(MyRandom.Instance.NextFloat() * (materials.Count - 1));
            MyDecalMaterial material = materials[index];

            float rotation = material.Rotation;
            if (material.Rotation == float.PositiveInfinity)
                rotation = MyRandom.Instance.NextFloat() * MathHelper.TwoPi;

            var bindingPerp = Vector3.CalculatePerpendicularVector(binding.Normal);
            if (rotation != 0)
            {
                // Rotate around normal
                Quaternion q = Quaternion.CreateFromAxisAngle(binding.Normal, rotation);
                bindingPerp = new Vector3((new Quaternion(bindingPerp, 0) * q).ToVector4());
            }
            bindingPerp = Vector3.Normalize(bindingPerp);

            var size = material.MinSize;
            if (material.MaxSize > material.MinSize)
                size += MyRandom.Instance.NextFloat() * (material.MaxSize - material.MinSize);

            Vector3 scale = new Vector3(size, size, material.Depth);
            MyDecalTopoData topoData = new MyDecalTopoData();

            Matrix pos;
            Vector3 worldPosition;
            if (data.Flags.HasFlag(MyDecalFlags.World))
            {
                // Using tre translation component here would loose accuracy
                pos = Matrix.CreateWorld(Vector3.Zero, binding.Normal, bindingPerp);
                worldPosition = data.Position;
            }
            else
            {
                pos = Matrix.CreateWorld(binding.Position, binding.Normal, bindingPerp);
                worldPosition = Vector3.Invalid; // Set in the render thread
            }

            topoData.MatrixBinding = Matrix.CreateScale(scale) * pos;
            topoData.WorldPosition = worldPosition;
            topoData.MatrixCurrent = binding.Transformation * topoData.MatrixBinding;
            topoData.BoneIndices = data.BoneIndices;
            topoData.BoneWeights = data.BoneWeights;

            string sourceTarget = MyDecalMaterials.GetStringId(Source, data.Material);
            return MyRenderProxy.CreateDecal(data.RenderObjectId, ref topoData, data.Flags, sourceTarget, material.StringId, index);
        }
        void IMyDecalProxy.AddDecals(MyHitInfo hitInfo, MyStringHash source, object customdata, IMyDecalHandler decalHandler)
        {
            Debug.Assert(m_mapIdToBlock.Count > 0);
            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);

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