예제 #1
0
        internal static List <Item> ImportFromHierarchy(NJS_OBJECT objm, EditorItemSelection selectionManager, OnScreenDisplay osd, bool multiple = false)
        {
            List <Item> createdItems = new List <Item>();

            if (objm.Attach != null)
            {
                objm.Attach.ProcessVertexData();
                LevelItem lvlitem = new LevelItem(objm.Attach, new Vertex(objm.Position.X, objm.Position.Y, objm.Position.Z), objm.Rotation, levelItems.Count, selectionManager)
                {
                    Visible = true
                };
                createdItems.Add(lvlitem);
            }
            if (multiple)
            {
                if (objm.Children != null && objm.Children.Count > 0)
                {
                    foreach (NJS_OBJECT child in objm.Children)
                    {
                        createdItems.AddRange(ImportFromHierarchy(child, selectionManager, osd, true));
                    }
                }
            }
            return(createdItems);
        }
예제 #2
0
        public static List <SETItem> Load(byte[] setfile, EditorItemSelection selectionManager)
        {
            bool bigendianbk = ByteConverter.BigEndian;

            // Load the value as both Little and Big Endian and compare the result.
            // If the BE number is larger, this is an LE file.
            ByteConverter.BigEndian = false;
            uint test_le = ByteConverter.ToUInt32(setfile, 0);

            ByteConverter.BigEndian = true;
            uint test_be = ByteConverter.ToUInt32(setfile, 0);

            if (test_be > test_le)
            {
                ByteConverter.BigEndian = false;
            }
            int            count   = ByteConverter.ToInt32(setfile, 0);
            List <SETItem> list    = new List <SETItem>(count);
            int            address = 0x20;

            for (int j = 0; j < count; j++)
            {
                SETItem ent = new SETItem(setfile, address, selectionManager);
                list.Add(ent);
                address += 0x20;
            }
            ByteConverter.BigEndian = bigendianbk;
            return(list);
        }
예제 #3
0
        public SplineData(PathData splineData, EditorItemSelection selectionManager)
            : base(selectionManager)
        {
            this.splineData = splineData;

            selectionManager.SelectionChanged += selectionManager_SelectionChanged;
            vertexHelper.PointChanged         += vertexHelper_PointChanged;
        }
예제 #4
0
        public SplineData(EditorItemSelection selectionManager)
            : base(selectionManager)
        {
            splineData = new PathData();

            selectionManager.SelectionChanged += selectionManager_SelectionChanged;
            vertexHelper.PointChanged         += vertexHelper_PointChanged;
        }
예제 #5
0
 public DeathZoneItem(Device device, EditorItemSelection selectionManager)
     : base(selectionManager)
 {
     this.device = device;
     Model       = new NJS_OBJECT();
     ImportModel();
     Paste();
 }
예제 #6
0
 /// <summary>
 /// Creates a LevelItem from an existing COL data.
 /// </summary>
 /// <param name="col"></param>
 /// <param name="dev">Current Direct3d Device.</param>
 public LevelItem(COL col, Device dev, int index, EditorItemSelection selectionManager)
     : base(selectionManager)
 {
     this.index = index;
     COL        = col;
     col.Model.ProcessVertexData();
     Mesh = col.Model.Attach.CreateD3DMesh(dev);
 }
예제 #7
0
        public static void DuplicateSelection(EditorItemSelection selection, out bool errorFlag, out string errorMsg)
        {
            if (selection.ItemCount < 0)
            {
                errorFlag = true; errorMsg = "Negative selection count... what did you do?!?"; return;
            }

            List <Item> newItems     = new List <Item>();
            List <Item> currentItems = selection.GetSelection();

            // duplicate goes here
            for (int i = 0; i < selection.ItemCount; i++)
            {
                if (currentItems[i] is MissionSETItem)
                {
                    MissionSETItem originalItem = (MissionSETItem)currentItems[i];
                    MissionSETItem newItem      = new MissionSETItem(originalItem.GetBytes(), 0, originalItem.GetPRMBytes(), 0, selection);

                    MissionSETItems[Character].Add(newItem);
                    newItems.Add(newItem);
                }
                else if (currentItems[i] is SETItem)
                {
                    SETItem originalItem = (SETItem)currentItems[i];
                    SETItem newItem      = new SETItem(originalItem.GetBytes(), 0, selection);

                    //SETItems[Character].Add(newItem);
                    AddSETItem(Character, newItem);
                    newItems.Add(newItem);
                }
                else if (currentItems[i] is LevelItem)
                {
                    LevelItem originalItem = (LevelItem)currentItems[0];
                    LevelItem newItem      = new LevelItem(originalItem.CollisionData.Model.Attach, originalItem.Position, originalItem.Rotation, levelItems.Count, selection);

                    newItem.CollisionData.SurfaceFlags = originalItem.CollisionData.SurfaceFlags;
                    newItems.Add(newItem);
                }
                else if (currentItems[i] is CAMItem)
                {
                    CAMItem originalItem = (CAMItem)currentItems[i];
                    CAMItem newItem      = new CAMItem(originalItem.GetBytes(), 0, selection);

                    CAMItems[Character].Add(newItem);
                    newItems.Add(newItem);
                }
            }

            selection.Clear();
            selection.Add(newItems);

            changes.Push("Duplicate Item");

            InvalidateRenderState();

            errorFlag = false;
            errorMsg  = "";
        }
예제 #8
0
        public DeathZoneItem(EditorItemSelection selectionManager)
            : base(selectionManager)
        {
            Model = new NJS_OBJECT();
            ImportModel();

            rotateZYX = Model.RotateZYX;
            GetHandleMatrix();
        }
예제 #9
0
 public SETItem(ushort id, EditorItemSelection selectionManager)
     : base(selectionManager)
 {
     ID       = id;
     objdef   = GetObjectDefinition();
     Position = new Vertex();
     Rotation = new Rotation(objdef.DefaultXRotation, objdef.DefaultYRotation, objdef.DefaultZRotation);
     Scale    = new Vertex(objdef.DefaultXScale, objdef.DefaultYScale, objdef.DefaultZScale);
     isLoaded = true;
 }
예제 #10
0
        public DeathZoneItem(NJS_OBJECT model, SA1CharacterFlags flags, EditorItemSelection selectionManager)
            : base(selectionManager)
        {
            Model = model;
            model.ProcessVertexData();
            Flags = flags;
            Mesh  = Model.Attach.CreateD3DMesh();

            rotateZYX = Model.RotateZYX;
            GetHandleMatrix();
        }
예제 #11
0
        public MissionSETItem(MsnObjectList list, ushort id, EditorItemSelection selectionManager)
            : base(selectionManager)
        {
            ObjectList = list;
            ID         = id;
            objdef     = GetObjectDefinition();
            position   = new Vertex();
            rotation   = new Rotation(objdef.DefaultXRotation, objdef.DefaultYRotation, objdef.DefaultZRotation);
            scale      = new Vertex(objdef.DefaultXScale, objdef.DefaultYScale, objdef.DefaultZScale);
            isLoaded   = true;

            GetHandleMatrix();
        }
예제 #12
0
        public static List <SETItem> Load(byte[] setfile, EditorItemSelection selectionManager)
        {
            int            count   = ByteConverter.ToInt32(setfile, 0);
            List <SETItem> list    = new List <SETItem>(count);
            int            address = 0x20;

            for (int j = 0; j < count; j++)
            {
                SETItem ent = new SETItem(setfile, address, selectionManager);
                list.Add(ent);
                address += 0x20;
            }
            return(list);
        }
예제 #13
0
 void selectionManager_SelectionChanged(EditorItemSelection sender)
 {
     if (sender.ItemCount != 1)
     {
         vertexHelper.Enabled = false;
     }
     else
     {
         if (Selected)
         {
             vertexHelper.Enabled = (selectedKnot != -1);
         }
     }
 }
예제 #14
0
        public SETItem(byte[] file, int address, EditorItemSelection selectionManager)
            : base(selectionManager)
        {
            ushort _id = ByteConverter.ToUInt16(file, address);

            ID        = _id;
            ClipLevel = (byte)(_id >> 12);
            ushort xrot = BitConverter.ToUInt16(file, address + 2);
            ushort yrot = BitConverter.ToUInt16(file, address + 4);
            ushort zrot = BitConverter.ToUInt16(file, address + 6);

            Rotation = new Rotation(xrot, yrot, zrot);
            Position = new Vertex(file, address + 8);
            Scale    = new Vertex(file, address + 0x14);
            isLoaded = true;
            objdef   = GetObjectDefinition();
        }
예제 #15
0
        /// <summary>
        /// Creates a new CAM Item from a byte array and offset.
        /// </summary>
        /// <param name="file"></param>
        /// <param name="address"></param>
        public CAMItem(byte[] file, int address, EditorItemSelection selectionManager)
            : base(selectionManager)
        {
            CamType   = file[address];
            Unknown   = file[address + 1];
            PanSpeed  = file[address + 2];
            Priority  = file[address + 3];
            Unknown_2 = BitConverter.ToInt16(file, address + 4);
            Rotation  = new Rotation(0, BitConverter.ToInt16(file, address + 6), 0);
            Position  = new Vertex(file, address + 8);
            Scale     = new Vertex(file, address + 20);
            NotUsed   = BitConverter.ToInt32(file, address + 32);
            PointA    = new Vertex(file, address + 36);
            PointB    = new Vertex(file, address + 48);
            Variable  = BitConverter.ToSingle(file, address + 60);

            selectionManager.SelectionChanged += selectionManager_SelectionChanged;
        }
예제 #16
0
        /// <summary>
        ///  Create a new CAM Item from within the editor.
        /// </summary>
        /// <param name="dev">An active Direct3D device for meshing/material/rendering purposes.</param>
        public CAMItem(Vertex position, EditorItemSelection selectionManager)
            : base(selectionManager)
        {
            CamType = 0x23;

            Position = position;
            Rotation = new Rotation();
            Scale    = new Vertex(1, 1, 1);
            Priority = 2;
            PanSpeed = 0x14;

            PointA = new Vertex(position.X + 25, position.Y - 38, position.Z);
            PointB = new Vertex(position.X - 40, position.Y - 38, position.Z);

            Variable = 45f;

            selectionManager.SelectionChanged += selectionManager_SelectionChanged;
        }
예제 #17
0
        void selectionManager_SelectionChanged(EditorItemSelection sender)
        {
            if (sender.ItemCount != 1)
            {
                pointHelperA.Enabled = false;
                pointHelperB.Enabled = false;
            }
            else
            {
                if (Selected)
                {
                    pointHelperA.SetPoint(PointA);
                    pointHelperB.SetPoint(PointB);

                    pointHelperA.Enabled = true;
                    pointHelperB.Enabled = true;
                }
            }
        }
예제 #18
0
 /// <summary>
 /// Creates a LevelAnim from an existing GeoAnim data.
 /// </summary>
 public LevelAnim(GeoAnimData geoanim, int index, EditorItemSelection selectionManager)
     : base(selectionManager)
 {
     GeoAnim    = geoanim;
     this.index = index;
     GeoAnim.Model.ProcessVertexData();
     NJS_OBJECT[] models = GeoAnim.Model.GetObjects();
     Meshes = new Mesh[models.Length];
     for (int i = 0; i < models.Length; i++)
     {
         if (models[i].Attach != null)
         {
             try { Meshes[i] = models[i].Attach.CreateD3DMesh(); }
             catch { }
         }
     }
     CalculateBounds();
     GetHandleMatrix();
 }
예제 #19
0
        /// <summary>
        /// Creates a new CAM Item from a byte array and offset.
        /// </summary>
        /// <param name="file"></param>
        /// <param name="address"></param>
        public CAMItem(byte[] file, int address, EditorItemSelection selectionManager)
            : base(selectionManager)
        {
            CamType       = (SADXCamType)file[address];
            Priority      = file[address + 1];
            AdjustType    = (SADXCamAdjustType)file[address + 2];
            CollisionType = (SADXCamColType)file[address + 3];
            Rotation      = new Rotation(BitConverter.ToInt16(file, address + 4), BitConverter.ToInt16(file, address + 6), 0);
            Position      = new Vertex(file, address + 8);
            Scale         = new Vertex(file, address + 20);
            CameraAngleX  = BitConverter.ToInt16(file, address + 32);
            CameraAngleY  = BitConverter.ToInt16(file, address + 34);
            PointA        = new Vertex(file, address + 36);
            PointB        = new Vertex(file, address + 48);
            Variable      = BitConverter.ToSingle(file, address + 60);

            selectionManager.SelectionChanged += selectionManager_SelectionChanged;

            GetHandleMatrix();
        }
예제 #20
0
        /// <summary>
        ///  Create a new CAM Item from within the editor.
        /// </summary>
        /// <param name="dev">An active Direct3D device for meshing/material/rendering purposes.</param>
        public CAMItem(Vertex position, EditorItemSelection selectionManager)
            : base(selectionManager)
        {
            CamType = (SADXCamType.NEWFOLLOW);

            Position      = position;
            Rotation      = new Rotation();
            Scale         = new Vertex(1, 1, 1);
            Priority      = 0;
            AdjustType    = (SADXCamAdjustType.CamAdjust_RELATIVE3);
            CollisionType = (SADXCamColType.CamCol_Block);

            PointA = new Vertex(position.X + 25, position.Y - 38, position.Z);
            PointB = new Vertex(position.X - 40, position.Y - 38, position.Z);

            Variable = 45f;

            selectionManager.SelectionChanged += selectionManager_SelectionChanged;

            GetHandleMatrix();
        }
예제 #21
0
        public DeathZoneItem(NJS_OBJECT model, SA1CharacterFlags flags, EditorItemSelection selectionManager)
            : base(selectionManager)
        {
            Model = model;
            if (model.Attach is BasicAttach)
            {
                BasicAttach attach = (BasicAttach)model.Attach;
                if (attach.Material.Count == 0)
                {
                    attach.Material.Add(new NJS_MATERIAL());
                }
                attach.Material[0].DiffuseColor = System.Drawing.Color.FromArgb(96, 255, 0, 0);
                attach.Material[0].Flags        = 0x96102400;
            }
            model.ProcessVertexData();
            Flags = flags;

            Mesh = Model.Attach.CreateD3DMesh();

            rotateZYX = Model.RotateZYX;
            GetHandleMatrix();
        }
예제 #22
0
        void SelectionChanged(EditorItemSelection sender)
        {
            propertyGrid1.SelectedObjects = sender.GetSelection().ToArray();

            if (cam.mode == 1)
            {
                cam.FocalPoint = Item.CenterFromSelection(sender.GetSelection()).ToVector3();
            }

            if (sender.ItemCount > 0)             // set up gizmo
            {
                transformGizmo.Enabled = true;
                transformGizmo.SetGizmo(Item.CenterFromSelection(selectedItems.GetSelection()).ToVector3(),
                                        selectedItems.Get(0).TransformMatrix);
            }
            else
            {
                if (transformGizmo != null)
                {
                    transformGizmo.Enabled = false;
                }
            }
        }
예제 #23
0
 void selectionManager_SelectionChanged(EditorItemSelection sender)
 {
     selected = (sender.GetSelection().Contains(this));
 }
예제 #24
0
 public Item(EditorItemSelection selectionManager)
 {
     selectionManager.SelectionChanged += selectionManager_SelectionChanged;
 }
예제 #25
0
        public static List <Item> ImportFromFile(string filePath, EditorCamera camera, out bool errorFlag, out string errorMsg, EditorItemSelection selectionManager, OnScreenDisplay osd, bool multiple = false)
        {
            List <Item> createdItems = new List <Item>();

            if (!File.Exists(filePath))
            {
                errorFlag = true;
                errorMsg  = "File does not exist!";
                return(null);
            }

            DirectoryInfo filePathInfo = new DirectoryInfo(filePath);

            bool    importError    = false;
            string  importErrorMsg = "";
            Vector3 pos            = camera.Position + (-20 * camera.Look);

            switch (filePathInfo.Extension)
            {
            case ".sa1mdl":
                ModelFile  mf   = new ModelFile(filePath);
                NJS_OBJECT objm = mf.Model;
                osd.ClearMessageList();
                osd.AddMessage("Importing models, please wait...", 3000);
                osd.ClearMessageList();
                createdItems.AddRange(ImportFromHierarchy(objm, selectionManager, osd, multiple));
                osd.AddMessage("Stage import complete!", 100);
                break;

            case ".obj":
            case ".objf":
                LevelItem item = new LevelItem(filePath, new Vertex(pos.X, pos.Y, pos.Z), new Rotation(), levelItems.Count, selectionManager)
                {
                    Visible = true
                };

                createdItems.Add(item);
                break;

            case ".txt":
                NodeTable.ImportFromFile(filePath, out importError, out importErrorMsg, selectionManager);
                break;

            case ".dae":
            case ".fbx":
                Assimp.AssimpContext context = new Assimp.AssimpContext();
                Assimp.Configs.FBXPreservePivotsConfig conf = new Assimp.Configs.FBXPreservePivotsConfig(false);
                context.SetConfig(conf);
                Assimp.Scene scene = context.ImportFile(filePath, Assimp.PostProcessSteps.Triangulate);
                for (int i = 0; i < scene.RootNode.ChildCount; i++)
                {
                    osd.ClearMessageList();
                    osd.AddMessage("Importing model " + i.ToString() + " of " + scene.RootNode.ChildCount.ToString() + "...", 3000);
                    Assimp.Node        child  = scene.RootNode.Children[i];
                    List <Assimp.Mesh> meshes = new List <Assimp.Mesh>();
                    foreach (int j in child.MeshIndices)
                    {
                        meshes.Add(scene.Meshes[j]);
                    }
                    bool isVisible = true;
                    for (int j = 0; j < child.MeshCount; j++)
                    {
                        if (scene.Materials[meshes[j].MaterialIndex].Name.Contains("Collision"))
                        {
                            isVisible = false;
                            break;
                        }
                    }
                    ModelFormat mfmt = ModelFormat.Basic;
                    if (isVisible)
                    {
                        switch (geo.Format)
                        {
                        case LandTableFormat.SA2:
                            mfmt = ModelFormat.Chunk;
                            break;

                        case LandTableFormat.SA2B:
                            mfmt = ModelFormat.GC;
                            break;
                        }
                    }
                    NJS_OBJECT obj = AssimpStuff.AssimpImport(scene, child, mfmt, TextureBitmaps[leveltexs].Select(a => a.Name).ToArray(), !multiple);
                    {
                        //sa2 collision patch
                        if (obj.Attach.GetType() == typeof(BasicAttach))
                        {
                            BasicAttach ba = obj.Attach as BasicAttach;
                            foreach (NJS_MATERIAL mats in ba.Material)
                            {
                                mats.DoubleSided = true;
                            }
                        }
                        //cant check for transparent texture so i gotta force alpha for now, temporary
                        else if (obj.Attach.GetType() == typeof(ChunkAttach))
                        {
                            ChunkAttach ca = obj.Attach as ChunkAttach;
                            foreach (PolyChunk polys in ca.Poly)
                            {
                                if (polys.GetType() == typeof(PolyChunkMaterial))
                                {
                                    PolyChunkMaterial mat = polys as PolyChunkMaterial;
                                    mat.SourceAlpha      = AlphaInstruction.SourceAlpha;
                                    mat.DestinationAlpha = AlphaInstruction.InverseSourceAlpha;
                                }
                                else if (polys.GetType() == typeof(PolyChunkStrip))
                                {
                                    PolyChunkStrip str = polys as PolyChunkStrip;
                                    //str.UseAlpha = true;
                                }
                            }
                        }
                    }
                    obj.Attach.ProcessVertexData();
                    LevelItem newLevelItem = new LevelItem(obj.Attach, new Vertex(obj.Position.X + pos.X, obj.Position.Y + pos.Y, obj.Position.Z + pos.Z), obj.Rotation, levelItems.Count, selectionManager)
                    {
                        Visible = isVisible
                    };
                    createdItems.Add(newLevelItem);
                }
                osd.ClearMessageList();
                osd.AddMessage("Stage import complete!", 100);
                break;

            default:
                errorFlag = true;
                errorMsg  = "Invalid file format!";
                return(null);
            }

            StateChanged();

            errorFlag = importError;
            errorMsg  = importErrorMsg;

            return(createdItems);
        }
예제 #26
0
 public static LevelAnim ImportLevelAnimation(NJS_OBJECT objm, NJS_MOTION mot, EditorItemSelection selectionManager)
 {
     objm.ProcessVertexData();
     StateChanged();
     return(new LevelAnim(new GeoAnimData(objm, mot), levelAnims.Count, selectionManager));
 }
예제 #27
0
 public StartPosItem(NJS_OBJECT model, string textures, float offset, Vertex position, int yrot, Device dev, EditorItemSelection selectionManager)
     : base(selectionManager)
 {
     Model = model;
     model.ProcessVertexData();
     NJS_OBJECT[] models = model.GetObjects();
     Meshes = new Mesh[models.Length];
     for (int i = 0; i < models.Length; i++)
     {
         if (models[i].Attach != null)
         {
             Meshes[i] = models[i].Attach.CreateD3DMesh();
         }
     }
     texture     = textures;
     this.offset = offset;
     Position    = position;
     YRotation   = yrot;
 }
예제 #28
0
 protected override void DeleteInternal(EditorItemSelection selectionManager)
 {
 }
예제 #29
0
 public DeathZoneItem(NJS_OBJECT model, SA1CharacterFlags flags, Device device, EditorItemSelection selectionManager)
     : base(selectionManager)
 {
     Model = model;
     model.ProcessVertexData();
     Flags       = flags;
     Mesh        = Model.Attach.CreateD3DMesh(device);
     this.device = device;
 }
예제 #30
0
 protected override void DeleteInternal(EditorItemSelection selectionManager)
 {
     selectionManager.SelectionChanged -= selectionManager_SelectionChanged;
     LevelData.CAMItems[LevelData.Character].Remove(this);
 }