Exemple #1
0
        public override void Import()
        {
            List <TRModel> levelModels = Level.Models.ToList();
            int            i           = levelModels.FindIndex(m => m.ID == (short)Definition.Entity);

            if (i == -1)
            {
                levelModels.Add(Definition.Model);
                Level.Models = levelModels.ToArray();
                Level.NumModels++;
            }
            else if (!_ignoreEntities.Contains(Definition.Entity))
            {
                // Replacement occurs for the likes of aliases taking the place of another
                // e.g. WhiteTiger replacing BengalTiger in GW
                Level.Models[i] = Definition.Model;
            }

            // If we have replaced Lara, we need to update models such as CameraTarget, FlameEmitter etc
            // as these use Lara's hips as placeholders. This means we can avoid texture corruption in
            // TRView but it's also needed for the shower cutscene in HSH. If these entities are found,
            // their starting mesh and mesh tree indices are just remapped to Lara's.
            if (Definition.Entity == TR2Entities.Lara)
            {
                foreach (TR2Entities dependent in _laraDependentModels)
                {
                    TRModel dependentModel = levelModels.Find(m => m.ID == (short)dependent);
                    if (dependentModel != null)
                    {
                        dependentModel.MeshTree     = Definition.Model.MeshTree;
                        dependentModel.StartingMesh = Definition.Model.StartingMesh;
                    }
                }
            }
        }
Exemple #2
0
        private void DisguiseEntity(TR2CombinedLevel level, TR2Entities guiser, TR2Entities targetEntity)
        {
            List <TRModel> models        = level.Data.Models.ToList();
            int            existingIndex = models.FindIndex(m => m.ID == (short)guiser);

            if (existingIndex != -1)
            {
                models.RemoveAt(existingIndex);
            }

            TRModel disguiseAsModel = models[models.FindIndex(m => m.ID == (short)targetEntity)];

            if (targetEntity == TR2Entities.BirdMonster && level.Is(LevelNames.CHICKEN))
            {
                // We have to keep the original model for the boss, so in
                // this instance we just clone the model for the guiser
                models.Add(new TRModel
                {
                    Animation    = disguiseAsModel.Animation,
                    FrameOffset  = disguiseAsModel.FrameOffset,
                    ID           = (uint)guiser,
                    MeshTree     = disguiseAsModel.MeshTree,
                    NumMeshes    = disguiseAsModel.NumMeshes,
                    StartingMesh = disguiseAsModel.StartingMesh
                });
            }
            else
            {
                disguiseAsModel.ID = (uint)guiser;
            }

            level.Data.Models    = models.ToArray();
            level.Data.NumModels = (uint)models.Count;
        }
        public static TRMesh[] GetModelMeshes(TR2Level level, TR2Entities entity)
        {
            TRModel model = GetModel(level, entity);

            if (model != null)
            {
                return(GetModelMeshes(level, model));
            }
            return(null);
        }
        public static TRMesh[] GetModelMeshes(TR2Level level, TRModel model)
        {
            List <TRMesh> meshes      = new List <TRMesh>();
            int           meshPointer = model.StartingMesh;

            for (int j = 0; j < model.NumMeshes; j++)
            {
                meshes.Add(GetMesh(level, meshPointer + j));
            }
            return(meshes.ToArray());
        }
        public static TRMeshTreeNode[] GetModelMeshTrees(TR2Level level, TRModel model)
        {
            List <TRMeshTreeNode> nodes = new List <TRMeshTreeNode>();
            int index = (int)model.MeshTree / 4;

            for (int i = 0; i < model.NumMeshes; i++)
            {
                int offset = index + i;
                if (offset < level.MeshTrees.Length)
                {
                    nodes.Add(level.MeshTrees[offset]);
                }
            }
            return(nodes.ToArray());
        }
        private int GetModelAnimationCount(TR2Level level, TRModel model)
        {
            TRModel nextModel  = model;
            int     modelIndex = level.Models.ToList().IndexOf(model) + 1;

            while (modelIndex < level.NumModels)
            {
                nextModel = level.Models[modelIndex++];
                if (nextModel.Animation != ushort.MaxValue)
                {
                    break;
                }
            }

            ushort nextStartAnimation = nextModel.Animation;

            if (model == nextModel)
            {
                nextStartAnimation = (ushort)level.NumAnimations;
            }

            return(model.Animation == ushort.MaxValue ? 0 : nextStartAnimation - model.Animation);
        }
 public static TRMesh GetModelFirstMesh(TR2Level level, TRModel model)
 {
     return(GetMesh(level, model.StartingMesh));
 }