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); }
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); }
public SplineData(PathData splineData, EditorItemSelection selectionManager) : base(selectionManager) { this.splineData = splineData; selectionManager.SelectionChanged += selectionManager_SelectionChanged; vertexHelper.PointChanged += vertexHelper_PointChanged; }
public SplineData(EditorItemSelection selectionManager) : base(selectionManager) { splineData = new PathData(); selectionManager.SelectionChanged += selectionManager_SelectionChanged; vertexHelper.PointChanged += vertexHelper_PointChanged; }
public DeathZoneItem(Device device, EditorItemSelection selectionManager) : base(selectionManager) { this.device = device; Model = new NJS_OBJECT(); ImportModel(); Paste(); }
/// <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); }
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 = ""; }
public DeathZoneItem(EditorItemSelection selectionManager) : base(selectionManager) { Model = new NJS_OBJECT(); ImportModel(); rotateZYX = Model.RotateZYX; GetHandleMatrix(); }
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; }
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(); }
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(); }
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); }
void selectionManager_SelectionChanged(EditorItemSelection sender) { if (sender.ItemCount != 1) { vertexHelper.Enabled = false; } else { if (Selected) { vertexHelper.Enabled = (selectedKnot != -1); } } }
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(); }
/// <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; }
/// <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; }
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; } } }
/// <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(); }
/// <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(); }
/// <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(); }
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(); }
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; } } }
void selectionManager_SelectionChanged(EditorItemSelection sender) { selected = (sender.GetSelection().Contains(this)); }
public Item(EditorItemSelection selectionManager) { selectionManager.SelectionChanged += selectionManager_SelectionChanged; }
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); }
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)); }
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; }
protected override void DeleteInternal(EditorItemSelection selectionManager) { }
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; }
protected override void DeleteInternal(EditorItemSelection selectionManager) { selectionManager.SelectionChanged -= selectionManager_SelectionChanged; LevelData.CAMItems[LevelData.Character].Remove(this); }