public static void AddDecal(uint ID, uint ParentID, ref MyDecalTopoData data, MyDecalFlags flags, string sourceTarget, string material, int matIndex) { if (m_decals.Count == m_decalsQueueSize) { MarkForRemove(m_decals.First.Value); } MyScreenDecal decal = new MyScreenDecal(); decal.FadeTimestamp = uint.MaxValue; decal.ID = ID; decal.ParentID = ParentID; decal.Data = data; decal.Flags = flags; decal.OBBox = ComputeOBB(ref data, flags); decal.SourceTarget = sourceTarget; decal.Material = material; decal.MaterialId = X.TEXT_(material); decal.MaterialIndex = matIndex; DecalNode node = m_decals.AddLast(decal); m_nodeMap[ID] = node; List <DecalNode> handles; bool found = m_entityDecals.TryGetValue(ParentID, out handles); if (!found) { handles = new List <DecalNode>(); m_entityDecals.Add(ParentID, handles); } handles.Add(node); }
public static bool GetDecalTopoData(uint decalId, out MyDecalTopoData data) { DecalNode node; bool found = m_nodeMap.TryGetValue(decalId, out node); if (!found) { data = new MyDecalTopoData(); return(false); } data = node.Value.TopoData; return(true); }
private static Matrix ComputeOBB(ref MyDecalTopoData data, MyDecalFlags flags) { var perp = Vector3.CalculatePerpendicularVector(data.Normal); if (data.Rotation != 0) { // Rotate around normal Quaternion q = Quaternion.CreateFromAxisAngle(data.Normal, data.Rotation); perp = new Vector3((new Quaternion(perp, 0) * q).ToVector4()); } Matrix pos = Matrix.CreateWorld(data.Position, data.Normal, perp); return(Matrix.CreateScale(data.Scale) * pos); }
internal static void AddDecal(uint ID, uint ParentID, ref MyDecalTopoData topoData, MyDecalFlags flags, string sourceTarget, string material, int matIndex) { if (m_decals.Count >= m_decalsQueueSize && m_decals.Count != 0) { MarkForRemove(m_decals.First); } MyScreenDecal decal = new MyScreenDecal(); decal.FadeTimestamp = uint.MaxValue; decal.ID = ID; decal.ParentID = ParentID; decal.TopoData = topoData; decal.Flags = flags; decal.SourceTarget = sourceTarget; decal.Material = material; decal.MaterialId = X.TEXT_(material); decal.MaterialIndex = matIndex; if (!flags.HasFlag(MyDecalFlags.World)) { var parent = MyIDTracker <MyActor> .FindByID(ParentID); if (parent == null) { return; } decal.TopoData.WorldPosition = Vector3D.Transform(topoData.MatrixCurrent.Translation, ref parent.WorldMatrix); } DecalNode node = m_decals.AddLast(decal); m_nodeMap[ID] = node; List <DecalNode> handles; bool found = m_entityDecals.TryGetValue(ParentID, out handles); if (!found) { handles = new List <DecalNode>(); m_entityDecals.Add(ParentID, handles); } handles.Add(node); }
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); }