Esempio n. 1
0
        public bool ShouldIgnoreSegment(TR2Entities entity, TexturedTileSegment segment)
        {
            if (IgnoreEntityTextures.ContainsKey(entity))
            {
                if (IgnoreEntityTextures[entity].Count == 0)
                {
                    return(true);
                }

                foreach (int textureIndex in IgnoreEntityTextures[entity])
                {
                    if (segment.IsObjectTextureFor(textureIndex))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 2
0
        private void Pack()
        {
            using (TexturePacker packer = new TexturePacker(Level))
            {
                List <TR2Entities> removals = new List <TR2Entities>();
                if (ClearUnusedSprites)
                {
                    removals.Add(TR2Entities.Map_M_U);
                }

                if (EntitiesToRemove != null)
                {
                    removals.AddRange(EntitiesToRemove);
                }
                packer.RemoveModelSegments(removals, TextureRemap);

                ApplyFlamePatch();

                if (ClearUnusedSprites)
                {
                    RemoveUnusedSprites(packer);
                }

                List <TexturedTileSegment> allSegments = new List <TexturedTileSegment>();
                foreach (List <TexturedTileSegment> segmentList in _importSegments.Values)
                {
                    // We only add unique segments, so if another segment already exists,
                    // remap the definition's segment to that one. Example of when this is
                    // needed is importing the dragon as DragonBack duplicates a lot of
                    // DragonFront, so this will greatly reduce the import cost.
                    for (int i = 0; i < segmentList.Count; i++)
                    {
                        TexturedTileSegment segment = segmentList[i];
                        int j = FindMatchingSegment(allSegments, segment);
                        if (j == -1)
                        {
                            allSegments.Add(segment);
                        }
                        else
                        {
                            TexturedTileSegment otherSegment = allSegments[j];
                            segmentList[i] = allSegments[j];
                            foreach (IndexedTRObjectTexture texture in segment.Textures)
                            {
                                if (!otherSegment.IsObjectTextureFor(texture.Index))
                                {
                                    otherSegment.AddTexture(texture);
                                }
                            }
                        }
                    }
                }

                packer.AddRectangles(allSegments);
                packer.Pack(true);

                if (packer.OrphanedRectangles.Count > 0)
                {
                    List <string> entityNames = new List <string>();
                    foreach (TRModelDefinition def in Definitions)
                    {
                        entityNames.Add(def.Entity.ToString());
                    }
                    throw new PackingException(string.Format
                                               (
                                                   "Failed to pack {0} rectangles for model types [{1}].",
                                                   packer.OrphanedRectangles.Count,
                                                   string.Join(", ", entityNames)
                                               ));
                }
            }
        }