static void ProcessTree(ObjectTreeNode parent, ArchiveFileInfo file, string[] paths, int index)
        {
            string currentPath = paths[index];

            if (paths.Length - 1 == index)
            {
                var    fileNode = new ObjectTreeNode(currentPath);
                string ext      = Utils.GetExtension(currentPath);
                if (FileImageKeys.Lookup.ContainsKey(ext))
                {
                    fileNode.ImageKey = FileImageKeys.Lookup[ext];
                }
                else
                {
                    fileNode.ImageKey = "File";
                }
                fileNode.Type = ext;
                fileNode.Size = STMath.GetFileSize(file.GetFileSize());
                fileNode.Tag  = file;

                parent.AddChild(fileNode);
                return;
            }

            var node = FindFolderNode(parent, currentPath);

            if (node == null)
            {
                node          = new ObjectTreeNode(currentPath);
                node.ImageKey = "Folder";
                parent.AddChild(node);
            }

            ProcessTree(node, file, paths, index + 1);
        }
        static ObjectTreeNode LoadModelFormat(IModelFormat modelFormat)
        {
            IFileFormat fileFormat = (IFileFormat)modelFormat;
            var         model      = modelFormat.ToGeneric();

            ObjectTreeNode root = new ObjectTreeNode(fileFormat.FileInfo.FileName)
            {
                Tag = modelFormat
            };
            ObjectTreeNode meshFolder     = new ObjectTreeNode("Meshes");
            ObjectTreeNode textureFolder  = new ObjectTreeNode("Textures");
            ObjectTreeNode skeletonFolder = new ObjectTreeNode("Skeleton");

            foreach (var mesh in model.Meshes)
            {
                meshFolder.AddChild(LoadMesh(mesh));
            }

            foreach (var tex in model.Textures)
            {
                textureFolder.AddChild(LoadTextureFormat(tex));
            }

            if (model.Skeleton != null)
            {
                skeletonFolder.Children.AddRange(model.Skeleton.CreateBoneTree());
            }

            if (meshFolder.ChildCount > 0)
            {
                root.AddChild(meshFolder);
            }
            if (textureFolder.ChildCount > 0)
            {
                root.AddChild(textureFolder);
            }
            if (skeletonFolder.ChildCount > 0)
            {
                root.AddChild(skeletonFolder);
            }

            return(root);
        }
Ejemplo n.º 3
0
        public ObjectTreeNode CreateTreeHiearchy()
        {
            ObjectTreeNode root = new ObjectTreeNode(Name)
            {
                Tag = this
            };
            ObjectTreeNode meshFolder     = new ObjectTreeNode("Meshes");
            ObjectTreeNode textureFolder  = new ObjectTreeNode("Textures");
            ObjectTreeNode skeletonFolder = new ObjectTreeNode("Skeleton");

            root.ImageKey = "Model";

            foreach (var mesh in Meshes)
            {
                meshFolder.AddChild(LoadMesh(mesh));
            }

            foreach (var tex in Textures)
            {
                textureFolder.AddChild(LoadTextureFormat(tex));
            }

            if (Skeleton != null)
            {
                skeletonFolder.Children.AddRange(Skeleton.CreateBoneTree());
            }

            if (meshFolder.ChildCount > 0)
            {
                root.AddChild(meshFolder);
            }
            if (textureFolder.ChildCount > 0)
            {
                root.AddChild(textureFolder);
            }
            if (skeletonFolder.ChildCount > 0)
            {
                root.AddChild(skeletonFolder);
            }

            return(root);
        }
Ejemplo n.º 4
0
        private ObjectTreeNode ReadChunk(ChunkTable.ChunkDataEntry entry)
        {
            var subNode = new ObjectTreeNode(entry.ChunkType.ToString() + $"_{entry.ChunkType.ToString("X")}_Flags_{entry.Flags}_OFFSET_{entry.ChunkOffset}_SIZE_{entry.ChunkSize}");

            subNode.Tag = entry.Data;
            foreach (var child in entry.SubData)
            {
                subNode.AddChild(ReadChunk(child));
            }
            return(subNode);
        }
        public static ObjectTreeNode OpenFormat(ImageList imageList, IFileFormat fileFormat)
        {
            ObjectTreeNode hiearchyNode = null;

            if (fileFormat is IArchiveFile)
            {
                hiearchyNode = LoadArchiveFormat((IArchiveFile)fileFormat);
                if (fileFormat is ObjectTreeNode)
                {
                    hiearchyNode.OnBeforeExpand();
                    foreach (var child in ((ObjectTreeNode)fileFormat).Children)
                    {
                        hiearchyNode.AddChild(child);
                    }
                }
            }
            else if (fileFormat is ObjectTreeNode)
            {
                hiearchyNode = (ObjectTreeNode)fileFormat;
            }
            else if (fileFormat is ITextureContainer)
            {
                hiearchyNode = LoadTextureContainerFormat(imageList, (ITextureContainer)fileFormat);
            }
            else if (fileFormat is STGenericTexture)
            {
                hiearchyNode = LoadTextureFormat((STGenericTexture)fileFormat);
            }
            else if (fileFormat is IModelFormat)
            {
                hiearchyNode = LoadModelFormat((IModelFormat)fileFormat);
            }
            else if (fileFormat is IModelSceneFormat)
            {
                hiearchyNode = LoadModelFormat((IModelSceneFormat)fileFormat);
            }
            else
            {
                hiearchyNode = new ObjectTreeNode(fileFormat.FileInfo.FileName)
                {
                    Tag = fileFormat,
                }
            };

            hiearchyNode.OnBeforeExpand();

            if (fileFormat is IArchiveFile && fileFormat is ITextureContainer)
            {
                hiearchyNode.Children.AddRange(LoadTextureContainerFormat(imageList, (ITextureContainer)fileFormat).Children);
            }

            return(hiearchyNode);
        }
        public static List <ObjectTreeNode> CreateMaterialChunkList(Stream materialStream, Stream lookupStream, List <ModelChunk.MeshInfo> meshes)
        {
            List <uint[]> materialPointers = GetLookupPointers(meshes, lookupStream);

            for (int i = 0; i < meshes.Count; i++)
            {
                materialPointers[i] = materialPointers[i].Where(x => x != 0 && x < materialStream.Length).ToArray();

                for (int j = 0; j < materialPointers[i].Length; j++)
                {
                    Console.WriteLine($"pointer_{i} { materialPointers[i][j]}");
                }
            }

            materialPointers = materialPointers.OrderBy(x => x[0]).ToList();

            List <ObjectTreeNode> meshNodes = new List <ObjectTreeNode>();

            using (var reader = new FileReader(materialStream, true))
            {
                for (int i = 0; i < meshes.Count; i++)
                {
                    ObjectTreeNode meshNode = new ObjectTreeNode();
                    meshNodes.Add(meshNode);

                    uint[] pointers = materialPointers[i];
                    for (int j = 0; j < pointers.Length; j++)
                    {
                        uint size = 0;
                        if (j + 1 < pointers.Length)
                        {
                            size = pointers[j + 1] - pointers[j];
                        }
                        else if (i + 1 < meshes.Count)
                        {
                            size = materialPointers[i + 1][0] - pointers[j];
                        }
                        else
                        {
                            size = (uint)materialStream.Length - pointers[j];
                        }

                        Console.WriteLine($"pointer {pointers[j]} size {size}");

                        ObjectTreeNode matNode = new ObjectTreeNode($"Mat_{j}");
                        matNode.Tag = new SubStream(materialStream, pointers[j], size);
                        meshNode.AddChild(matNode);
                    }
                }
            }
            return(meshNodes);
        }
        static ObjectTreeNode LoadTextureContainerFormat(ImageList imageList, ITextureContainer textureContainer)
        {
            IFileFormat    fileFormat = (IFileFormat)textureContainer;
            ObjectTreeNode root       = new ObjectTreeNode(fileFormat.FileInfo.FileName);

            root.Tag      = fileFormat;
            root.ImageKey = "TextureContainer";

            foreach (var tex in textureContainer.TextureList)
            {
                root.AddChild(LoadTextureFormat(tex));
            }

            return(root);
        }
Ejemplo n.º 8
0
        private void LoadAnimations()
        {
            ObjectTreeNode animFolder = new ObjectTreeNode("Animations");

            this.AddChild(animFolder);

            foreach (var anim in Header.MotionData.Animations)
            {
                anim.AnimationNextFrame += OnAnimationNextFrame;
                animFolder.AddChild(new ObjectTreeNode(anim.Name)
                {
                    Tag = anim
                });
            }
        }
Ejemplo n.º 9
0
        public void Load(Stream stream)
        {
            _stream = stream;
            using (var reader = new FileReader(stream, true)) {
                reader.SetByteOrder(true);
                reader.SeekBegin(12);
                if (reader.ReadUInt32() == 0x78340300)
                {
                    Version = GameVersion.LM3;
                }
            }

            Tag = this;

            //Parse dictionary
            if (Version == GameVersion.LM3)
            {
                DictFile = new LM3.DICT_Parser(stream);
            }
            else
            {
                DictFile = new LM2.DICT_Parser(stream);
            }
            this.Label = FileInfo.FileName;

            DictFile.FilePath = FileInfo.FilePath;

            //Parse seperate data file
            string dataPath = FileInfo.FilePath.Replace(".dict", ".data");

            if (File.Exists(dataPath))
            {
                _dataStream = File.OpenRead(dataPath);
                DataFile    = new DATA_Parser(_dataStream, Version, DictFile);

                var root = LoadChunkTabe();
                Children.AddRange(root.Children);

                int index = 0;

                var subNode = new ObjectTreeNode("Data Entries");
                AddChild(subNode);
                foreach (var child in DataFile.Table.DataEntries)
                {
                    subNode.AddChild(ReadChunk(child));
                }
            }
        }
Ejemplo n.º 10
0
        private ObjectTreeNode CreateModelNode(Model modelContainer, string fileName, int index, bool isRigged)
        {
            var model        = modelContainer.Models[index];
            var genericModel = model.ToGeneric();

            genericModel.Name = $"{fileName}_SubModel{index}";
            foreach (var texture in modelContainer.TextureContainer.Textures)
            {
                genericModel.Textures.Add(texture);
            }

            ObjectTreeNode modelNode = genericModel.CreateTreeHiearchy();

            modelNode.Tag = model;

            if (isRigged)
            {
                ObjectTreeNode skeletonFolder = new ObjectTreeNode("Skeleton");
                skeletonFolder.Tag = genericModel.Skeleton;
                modelNode.AddChild(skeletonFolder);
            }
            return(modelNode);
        }
Ejemplo n.º 11
0
        private void LoadTextures()
        {
            var textureFolder = new ObjectTreeNode("Textures");

            this.AddChild(textureFolder);

            GenericTextures = new List <STGenericTexture>();
            for (int i = 0; i < Header.TextureCount; i++)
            {
                var data = Header.Textures[i].ImageData;
                var name = Header.Textures[i].Name;
                var info = Header.Textures[i].TextureInfo;
                var tex  = new PartyStudio.HSFTexture(name, info, data);
                if (Header.Textures[i].HasPaletteData())
                {
                    var palette = Header.Textures[i].PaletteData;
                    var format  = Decode_Gamecube.PaletteFormats.IA8;
                    if (info.Format == 0x09 || info.Format == 0x0B)
                    {
                        format = Decode_Gamecube.PaletteFormats.RGB565;
                    }
                    if (info.Format == 0x0A)
                    {
                        format = Decode_Gamecube.PaletteFormats.RGB5A3;
                    }
                    ((Toolbox.Core.Imaging.GamecubeSwizzle)tex.Platform).SetPalette(palette, format);

                    // tex.SetPaletteData(palette, Decode_Gamecube.ToGenericPaletteFormat(format));
                }

                textureFolder.AddChild(new ObjectTreeNode(tex.Name)
                {
                    Tag = tex, ImageKey = "Texture"
                });
                GenericTextures.Add(tex);
            }
        }
Ejemplo n.º 12
0
        private void LoadMeshes()
        {
            ObjectTreeNode meshesFolder = new ObjectTreeNode("Meshes");

            this.AddChild(meshesFolder);

            foreach (var mesh in Header.Meshes)
            {
                Dictionary <int, List <STVertex> > VertexMatMapper = new Dictionary <int, List <STVertex> >();

                int index = 0;
                foreach (var primative in mesh.Primitives)
                {
                    if (!VertexMatMapper.ContainsKey(primative.MaterialIndex))
                    {
                        VertexMatMapper.Add(primative.MaterialIndex, new List <STVertex>());
                    }

                    var vertices = VertexMatMapper[primative.MaterialIndex];
                    switch (primative.Type)
                    {
                    case PrimitiveType.Triangle:
                        vertices.Add(ToGenericVertex(mesh, primative.Vertices[0], Skeleton));
                        vertices.Add(ToGenericVertex(mesh, primative.Vertices[1], Skeleton));
                        vertices.Add(ToGenericVertex(mesh, primative.Vertices[2], Skeleton));
                        break;

                    case PrimitiveType.Quad:
                        vertices.Add(ToGenericVertex(mesh, primative.Vertices[0], Skeleton));
                        vertices.Add(ToGenericVertex(mesh, primative.Vertices[1], Skeleton));
                        vertices.Add(ToGenericVertex(mesh, primative.Vertices[2], Skeleton));
                        vertices.Add(ToGenericVertex(mesh, primative.Vertices[1], Skeleton));
                        vertices.Add(ToGenericVertex(mesh, primative.Vertices[3], Skeleton));
                        vertices.Add(ToGenericVertex(mesh, primative.Vertices[2], Skeleton));
                        break;

                    case PrimitiveType.TriangleStrip:
                        var verts = new List <STVertex>();

                        foreach (var dv in primative.Vertices)
                        {
                            verts.Add(ToGenericVertex(mesh, dv, Skeleton));
                        }
                        verts = ConvertTriStrips(verts);

                        vertices.AddRange(verts);
                        break;
                    }
                }

                foreach (var poly in VertexMatMapper)
                {
                    HSFMesh genericMesh = new HSFMesh();
                    genericMesh.Name = mesh.Name;
                    GenericMeshes.Add(genericMesh);

                    meshesFolder.AddChild(new ObjectTreeNode(mesh.Name)
                    {
                        Tag      = genericMesh,
                        ImageKey = "Mesh",
                    });

                    int objectIndex = Header.ObjectData.Objects.IndexOf(mesh.ObjectData);
                    if (objectIndex != -1)
                    {
                        var bone = Skeleton.Bones[objectIndex];
                        genericMesh.ObjectNode = bone;
                        bone.Visible           = false;
                    }

                    HSFMaterialWrapper genericMat = new HSFMaterialWrapper(this);

                    STPolygonGroup group = new STPolygonGroup();
                    group.Material = genericMat;
                    genericMesh.PolygonGroups.Add(group);

                    var matData = Header.Materials[poly.Key].MaterialData;

                    genericMat.Material = Header.Materials[poly.Key];
                    genericMat.Name     = Header.Materials[poly.Key].Name;

                    var pass_flags = matData.AltFlags & HSF_Renderer.PASS_BITS;
                    if (pass_flags != 0 || (matData.TransparencyInverted != 0 &&
                                            matData.VertexMode == 0))
                    {
                        genericMesh.IsTransparent = true;
                        group.IsTransparentPass   = true;
                    }

                    genericMat.Mesh = mesh;

                    var attributes = Header.Materials[poly.Key].Textures;
                    for (int i = 0; i < attributes.Count; i++)
                    {
                        var attribute = attributes[i].Item2;
                        var texIndex  = attribute.TextureIndex;
                        genericMat.Attributes.Add(attribute);

                        group.Material.TextureMaps.Add(new HSFMatTexture(this)
                        {
                            Attribute    = attribute,
                            Name         = Header.Textures[texIndex].Name,
                            TextureIndex = texIndex,
                            Type         = i == 0 ? STTextureType.Diffuse : STTextureType.None,
                            WrapU        = ConvertWrapMode(attribute.WrapS),
                            WrapV        = ConvertWrapMode(attribute.WrapT),
                            MagFilter    = STTextureMagFilter.Linear,
                            MinFilter    = STTextureMinFilter.Linear,
                        });
                    }

                    genericMesh.Vertices.AddRange(poly.Value);
                    genericMesh.Optmize(group);
                }
            }
        }
Ejemplo n.º 13
0
        private ObjectTreeNode LoadChunkTabe()
        {
            ObjectTreeNode root = new ObjectTreeNode();

            Dictionary <ChunkFileType, ObjectTreeNode> FileContainers = new Dictionary <ChunkFileType, ObjectTreeNode>();
            Dictionary <uint, DATA_Parser.FileEntry>   animationFiles = new Dictionary <uint, DATA_Parser.FileEntry>();

            foreach (var file in DataFile.Files)
            {
                if (!animationFiles.ContainsKey(file.Hash))
                {
                    animationFiles.Add(file.Hash, file);
                }
                if (!GlobalFileList.ContainsKey(file.Hash))
                {
                    GlobalFileList.Add(file.Hash, file);
                }
            }

            Dictionary <string, ObjectTreeNode> fileGrouper = new Dictionary <string, ObjectTreeNode>();

            foreach (var file in DataFile.Files)
            {
                ChunkFileType type = file.ChunkEntry.ChunkType;
                if (!FileContainers.ContainsKey(type))
                {
                    FileContainers.Add(type, new ObjectTreeNode(type.ToString() + $"_{type.ToString("X")}"));
                    root.AddChild(FileContainers[type]);
                }

                var folder   = FileContainers[file.ChunkEntry.ChunkType];
                var fileNode = new ObjectTreeNode(file.Hash.ToString());
                fileNode.Tag = file.ChunkEntry.Data;

                if (type == ChunkFileType.Model)
                {
                    fileNode = new ModelWrapper(file, DataFile);
                }
                if (type == ChunkFileType.AnimationData)
                {
                    fileNode = new AnimationWrapper(file, DataFile);
                }
                if (type == ChunkFileType.Texture)
                {
                    fileNode = new TextureWrapper(file, DataFile);
                }
                if (type == ChunkFileType.Skeleton)
                {
                    fileNode = new SkeletonWrapper(file, DataFile);
                }
                if (type == ChunkFileType.Script)
                {
                    fileNode = new ScriptWrapper(file, DataFile);
                }
                if (type == ChunkFileType.AnimationBundles)
                {
                    fileNode = new AnimationBundleWrapper(file, DataFile, animationFiles);
                }

                //Attempt to group common hashes
                if (type == ChunkFileType.Model)
                {
                    fileGrouper.Add(fileNode.Label, fileNode);
                }

                if (type != ChunkFileType.Model && fileGrouper.ContainsKey(fileNode.Label))
                {
                    ObjectTreeNode tfolder = new ObjectTreeNode(type.ToString());
                    tfolder.AddChild(fileNode);
                    fileGrouper[fileNode.Label].AddChild(tfolder);
                }
                else
                {
                    folder.AddChild(fileNode);
                }

                if (type == ChunkFileType.Model)
                {
                    ObjectTreeNode chunkList = new ObjectTreeNode("Chunks");
                    fileNode.AddChild(chunkList);

                    foreach (var child in file.ChunkEntry.SubData)
                    {
                        chunkList.AddChild(ReadChunk(child));
                    }
                }
                else
                {
                    foreach (var child in file.ChunkEntry.SubData)
                    {
                        fileNode.AddChild(ReadChunk(child));
                    }
                }

                fileNode.Label += $"_({folder.ChildCount})";
                if (ExtensionList.ContainsKey(file.ChunkEntry.ChunkType))
                {
                    fileNode.Label += ExtensionList[file.ChunkEntry.ChunkType];
                }

                if (Hashing.HashNames.ContainsKey(file.Hash))
                {
                    fileNode.Label = Hashing.HashNames[file.Hash];
                }
            }
            return(root);
        }
Ejemplo n.º 14
0
        public void Load(Stream stream)
        {
            Header = new RSC_Parser(FileInfo.FileName, stream);

            //Load all the resources
            foreach (var file in Header.Files)
            {
                if (file.Type == RSC_Parser.ResourceType.MapObjectParams)
                {
                    Scenes.Add(new SceneData(file.FileData));
                }
                if (file.Type == RSC_Parser.ResourceType.TextureContainer)
                {
                    file.OpenFileFormatOnLoad = true;
                }
            }

            ObjectTreeNode mapFolder   = new ObjectTreeNode("Maps");
            ObjectTreeNode modelFolder = new ObjectTreeNode("Models");
            ObjectTreeNode sceneFolder = new ObjectTreeNode("Scene");

            ObjectTreeNode currentModel = null;

            foreach (var file in Header.Files)
            {
                Console.WriteLine($"Reading FILE {file.FileName} {file.Type}");
                if (file.Type == RSC_Parser.ResourceType.StaticModel || file.Type == RSC_Parser.ResourceType.RiggedModel)
                {
                    string fileName = Path.GetFileNameWithoutExtension(file.FileName);

                    var            modelContainer     = new Model(file.FileData, file.FileName, (uint)file.Type);
                    ObjectTreeNode modelContainerNode = new ObjectTreeNode($"{fileName}");
                    modelContainerNode.ImageKey = "Model";
                    modelFolder.AddChild(modelContainerNode);
                    modelContainerNode.Tag = modelContainer;
                    currentModel           = modelContainerNode;

                    if (file.Type == RSC_Parser.ResourceType.StaticModel)
                    {
                        currentModel.Tag = modelContainer.Models[0];
                    }

                    var firstNode = CreateModelNode(modelContainer, fileName, 0,
                                                    file.Type == RSC_Parser.ResourceType.RiggedModel);

                    foreach (var child in firstNode.Children)
                    {
                        modelContainerNode.AddChild(child);
                    }

                    for (int i = 0; i < modelContainer.Models.Count; i++)
                    {
                        if (i == 0)
                        {
                            continue;
                        }

                        var modelNode = CreateModelNode(modelContainer, fileName, i,
                                                        file.Type == RSC_Parser.ResourceType.RiggedModel);

                        modelContainerNode.AddChild(modelNode);
                    }


                    if (file.Type == RSC_Parser.ResourceType.RiggedModel)
                    {
                        ObjectTreeNode modelAnimationsFolder = new ObjectTreeNode("Animations");
                        modelContainerNode.AddChild(modelAnimationsFolder);
                    }
                }
                if (file.Type == RSC_Parser.ResourceType.MapModel)
                {
                    string fileName = Path.GetFileNameWithoutExtension(file.FileName);

                    var model        = new MapModel(file.FileData, file.FileName, (uint)file.Type);
                    var genericModel = model.ToGeneric();
                    genericModel.Name = $"{fileName}";
                    ObjectTreeNode modelNode = genericModel.CreateTreeHiearchy();
                    modelNode.Tag = model;
                    modelFolder.AddChild(modelNode);
                    currentModel = modelNode;

                    MapModels.Add(model);
                }
                if (file.Type == RSC_Parser.ResourceType.SkeletonAnimation)
                {
                    var anim = new SkeletalAnim(file.FileData, file.FileName);
                    if (currentModel != null)
                    {
                        var model = ((Model)currentModel.Tag);
                        if (model.SkeletalAnim != null)
                        {
                            continue;
                        }

                        model.SkeletalAnim = anim;
                        model.UpdateSkeleton();
                        model.UpdateBoneIndices();
                        Runtime.BonePointSize = 6;

                        /* foreach (var modelNode in currentModel.Children) {
                         *   var modelgroup = (ModelGroup)modelNode.Tag;
                         *   var nodes = modelgroup.ToGeneric().Skeleton.CreateBoneTree();
                         *   foreach (var node in nodes)
                         *       modelNode.Children[1].AddChild(node);
                         * }*/

                        var animations = anim.ToGeneric();
                        foreach (var animation in animations)
                        {
                            var animNode = new ObjectTreeNode(animation.Name);
                            animNode.Tag = animation;
                            currentModel.Children[model.Models.Count + 2].AddChild(animNode);
                        }

                        currentModel.Tag = model.Models[0];
                        currentModel     = null;
                    }
                }
                if (file.Type == RSC_Parser.ResourceType.LightingData)
                {
                    string fileName = Path.GetFileName(file.FileName);

                    var lightingData = new LightingData(file.FileData);
                    var lightingNode = new ObjectTreeNode(fileName);
                    lightingNode.Tag = lightingData;
                    for (int i = 0; i < lightingData.Lights.Length; i++)
                    {
                        var light = lightingData.Lights[i];
                        lightingNode.AddChild(new ObjectTreeNode()
                        {
                            Label = $"Light{i}",
                            Tag   = light,
                        });
                    }
                    this.AddChild(lightingNode);
                }
            }

            if (modelFolder.Children.Count > 0)
            {
                this.AddChild(modelFolder);
            }
        }
Ejemplo n.º 15
0
        private void LoadSkeleton()
        {
            ObjectTreeNode skeletonFolder = new ObjectTreeNode("Skeleton");

            this.AddChild(skeletonFolder);

            for (int i = 0; i < Header.ObjectCount; i++)
            {
                var info = Header.ObjectData.Objects[i];
                var name = Header.ObjectData.ObjectNames[i];
                if (name == string.Empty)
                {
                    name = $"Object_{i}";
                }

                //Add a dummy bone. Some bone data is set at runtime and uses large random values
                if (info.ChildrenCount > Header.ObjectCount)
                {
                    Skeleton.Bones.Add(new HSFBoneWrapper(info, Skeleton)
                    {
                        Name          = name,
                        ParentIndex   = -1,
                        Position      = new Vector3(),
                        Scale         = Vector3.One,
                        EulerRotation = new Vector3(),
                    });
                }
                else
                {
                    Skeleton.Bones.Add(new HSFBoneWrapper(info, Skeleton)
                    {
                        Name        = name,
                        ParentIndex = -1,
                        Position    = new OpenTK.Vector3(
                            info.BaseTransform.Translate.X,
                            info.BaseTransform.Translate.Y,
                            info.BaseTransform.Translate.Z) * HSF_Renderer.PreviewScale,
                        EulerRotation = new OpenTK.Vector3(
                            MathHelper.DegreesToRadians(info.BaseTransform.Rotate.X),
                            MathHelper.DegreesToRadians(info.BaseTransform.Rotate.Y),
                            MathHelper.DegreesToRadians(info.BaseTransform.Rotate.Z)),
                        Scale = new OpenTK.Vector3(
                            info.BaseTransform.Scale.X == 0 ? 1 : info.BaseTransform.Scale.X,
                            info.BaseTransform.Scale.Y == 0 ? 1 : info.BaseTransform.Scale.Y,
                            info.BaseTransform.Scale.Z == 0 ? 1 : info.BaseTransform.Scale.Z),
                    });
                }
            }

            for (int i = 0; i < Header.ObjectCount; i++)
            {
                if (Header.ObjectData.Objects[i].ChildrenCount > Header.ObjectCount)
                {
                    Skeleton.Bones[i].ParentIndex = -1;
                }
                else
                {
                    Skeleton.Bones[i].ParentIndex = Header.ObjectData.Objects[i].ParentIndex;
                }
            }

            var boneNodes = Skeleton.CreateBoneTree();

            foreach (var bone in boneNodes)
            {
                skeletonFolder.AddChild(bone);
            }

            Skeleton.PreviewScale = 0.05f;
            Skeleton.Reset();
            Skeleton.Update();
        }
Ejemplo n.º 16
0
        public void Serilazed_Details_Object_With_ObjectTreeNode_Exists()
        {
            // arrange
            var scenario = new Scenario {
                Name = ScenarioName, Description = "a scenario for testing trees in details", Status = "failed"
            };

            // A tree containing most important item types that need to be supported
            // (same types are allowed for items in tree nodes as for values in Details --> reuse code from
            // SerializableDictionary!).

            // Root node with string as item
            var rootNode = new ObjectTreeNode <object> {
                Item = "Root"
            };

            rootNode.AddDetail(
                "detailKey",
                "Tree nodes can have again details, use same serialization as already tested!");

            // node one with object description as item
            var childWithObject = new ObjectTreeNode <object>();
            var objDescription  = new ObjectDescription("serviceCall", "AddressWebService.getAdress");

            objDescription.AddDetail("justADetail", "just an example");
            childWithObject.Item = objDescription;
            rootNode.AddChild(childWithObject);

            // node two with object reference as item
            var childWithObjectRef = new ObjectTreeNode <object>();
            var objRef             = new ObjectReference("serviceCall", "AddressWebService.getAdress");

            childWithObjectRef.Item = objRef;
            rootNode.AddChild(childWithObjectRef);

            // node three with List of Strings as item
            var childWithList = new ObjectTreeNode <IObjectTreeNode <object> >();
            var list          = new ObjectList <object> {
                "item1", "item2", "item3"
            };

            childWithList.Item = list;
            rootNode.AddChild(childWithList);

            // node four with details as item
            var childWithDetails = new ObjectTreeNode <object>();
            var detailsMap       = new Details();

            detailsMap.AddDetail("key1", "value1");
            detailsMap.AddDetail("key2", "value2");
            detailsMap.AddDetail("anyGenericObjectReference", new ObjectReference("serviceCall", "MainDB.getUsers"));
            detailsMap.AddDetail(
                "anyGenericObject",
                new ObjectDescription("configuration", "my_dummy_mocks_configuration.properties"));
            childWithDetails.Item = detailsMap;
            rootNode.AddChild(childWithDetails);

            scenario.AddDetail("exampleTree", rootNode);

            // act
            writer.SaveScenario(SerializationUseCase, scenario);
            writer.Flush();

            // assert
            Assert.IsTrue(File.Exists(docuFiles.GetScenarioFile(BranchName, BuildName, SerializationUseCase, ScenarioName)));

            scenario.Status = "success";
            writer.SaveScenario(SerializationUseCase, scenario);
        }
        public void Serilazed_Details_Object_With_ObjectTreeNode_Exists()
        {
            // arrange
            var scenario = new Scenario { Name = ScenarioName, Description = "a scenario for testing trees in details", Status = "failed" };

            // A tree containing most important item types that need to be supported
            // (same types are allowed for items in tree nodes as for values in Details --> reuse code from
            // SerializableDictionary!).

            // Root node with string as item
            var rootNode = new ObjectTreeNode<object> { Item = "Root" };
            rootNode.AddDetail(
                "detailKey",
                "Tree nodes can have again details, use same serialization as already tested!");

            // node one with object description as item
            var childWithObject = new ObjectTreeNode<object>();
            var objDescription = new ObjectDescription("serviceCall", "AddressWebService.getAdress");
            objDescription.AddDetail("justADetail", "just an example");
            childWithObject.Item = objDescription;
            rootNode.AddChild(childWithObject);

            // node two with object reference as item
            var childWithObjectRef = new ObjectTreeNode<object>();
            var objRef = new ObjectReference("serviceCall", "AddressWebService.getAdress");
            childWithObjectRef.Item = objRef;
            rootNode.AddChild(childWithObjectRef);

            // node three with List of Strings as item
            var childWithList = new ObjectTreeNode<IObjectTreeNode<object>>();
            var list = new ObjectList<object> { "item1", "item2", "item3" };
            childWithList.Item = list;
            rootNode.AddChild(childWithList);

            // node four with details as item
            var childWithDetails = new ObjectTreeNode<object>();
            var detailsMap = new Details();
            detailsMap.AddDetail("key1", "value1");
            detailsMap.AddDetail("key2", "value2");
            detailsMap.AddDetail("anyGenericObjectReference", new ObjectReference("serviceCall", "MainDB.getUsers"));
            detailsMap.AddDetail(
                "anyGenericObject",
                new ObjectDescription("configuration", "my_dummy_mocks_configuration.properties"));
            childWithDetails.Item = detailsMap;
            rootNode.AddChild(childWithDetails);

            scenario.AddDetail("exampleTree", rootNode);

            // act
            writer.SaveScenario(SerializationUseCase, scenario);
            writer.Flush();

            // assert
            Assert.IsTrue(File.Exists(docuFiles.GetScenarioFile(BranchName, BuildName, SerializationUseCase, ScenarioName)));

            scenario.Status = "success";
            writer.SaveScenario(SerializationUseCase, scenario);
        }
Ejemplo n.º 18
0
        private void SelectionChanged(ObjectTreeNode obj)
        {
            obj.OnClick();

            bool tryUpdateViewport = false;

            if (Runtime.SelectedBoneIndex != -1)
            {
                tryUpdateViewport         = true;
                Runtime.SelectedBoneIndex = -1;
            }

            if (obj.Tag is ArchiveFileInfo)
            {
                var fileInfo = (ArchiveFileInfo)obj.Tag;

                if (fileInfo.OpenFileFormatOnLoad)
                {
                    fileInfo.FileFormat = fileInfo.OpenFile();
                }
                if (fileInfo.FileFormat != null)
                {
                    var fileNode = ObjectListWrapperLoader.OpenFormat(imgList, fileInfo.FileFormat);
                    obj.Tag = fileInfo.FileFormat;
                    foreach (var child in fileNode.Children)
                    {
                        obj.AddChild(child);
                    }
                    SelectionChanged(obj);
                    return;
                }

                ArchiveFilePanel hexEditor = GetActiveEditor <ArchiveFilePanel>();
                hexEditor.LoadFile(this, fileInfo);
            }
            else if (obj.Tag is STGenericTexture)
            {
                var tex = (STGenericTexture)obj.Tag;

                ImageEditorBase editor = GetActiveEditor <ImageEditorBase>();
                editor.LoadProperties(tex.DisplayProperties);
                editor.LoadImage(tex);
            }
            else if (obj.Tag is IPropertyDisplay)
            {
                var property = (IPropertyDisplay)obj.Tag;

                STPropertyGrid editor = GetActiveEditor <STPropertyGrid>();
                editor.LoadProperty(property.PropertyDisplay);
            }
            else if (obj.Tag is IEditorDisplay)
            {
                var property = (IEditorDisplay)obj.Tag;
                Console.WriteLine($"IEditorDisplay {property}");

                var gui = GUIGenerator.Generate(property);
                gui.Dock = DockStyle.Fill;

                STPanel editor = GetActiveEditor <STPanel>();
                editor.Controls.Clear();
                editor.Controls.Add(gui);
            }
            else if (obj.Tag is System.IO.Stream)
            {
                var stream = (System.IO.Stream)obj.Tag;

                HexEditor hexEditor = GetActiveEditor <HexEditor>();
                hexEditor.LoadData(stream);
            }
            else if (obj.Tag is IVideoFormat)
            {
                VideoPlayer editor = GetActiveEditor <VideoPlayer>();
                editor.LoadVideoFile((IVideoFormat)obj.Tag);
            }
            else if (obj.Tag is STGenericMesh)
            {
                var mesh = (STGenericMesh)obj.Tag;
                mesh.SelectMesh?.Invoke(mesh, EventArgs.Empty);

                if (WorkspacePanel == null)
                {
                    WorkspacePanel = CreateWorkspacePanel();
                }

                WorkspacePanel workspace  = GetActiveEditor <WorkspacePanel>(WorkspacePanel);
                var            meshEditor = workspace.GetActiveEditor <MeshEditor>();
                meshEditor.LoadMesh(mesh);
                workspace.UpdateViewport();
                ObjectHiearchy.Focus();
            }
            else if (obj.Tag is STGenericMaterial)
            {
                var mat = (STGenericMaterial)obj.Tag;

                if (WorkspacePanel == null)
                {
                    WorkspacePanel = CreateWorkspacePanel();
                }

                WorkspacePanel workspace      = GetActiveEditor <WorkspacePanel>(WorkspacePanel);
                var            materialEditor = workspace.GetActiveEditor <MaterialEditor>();
                materialEditor.LoadMaterial(mat);
                workspace.UpdateViewport();
            }
            else if (obj.Tag is IModelFormat)
            {
                if (WorkspacePanel == null)
                {
                    WorkspacePanel = CreateWorkspacePanel();
                }

                WorkspacePanel workspace = GetActiveEditor <WorkspacePanel>(WorkspacePanel);
                workspace.LoadFileFormat((IModelFormat)(obj.Tag));
                workspace.UpdateViewport();
            }
            else if (obj.Tag is IModelSceneFormat)
            {
                if (WorkspacePanel == null)
                {
                    WorkspacePanel = CreateWorkspacePanel();
                }

                WorkspacePanel workspace = GetActiveEditor <WorkspacePanel>(WorkspacePanel);
                workspace.LoadFileFormat((IModelSceneFormat)(obj.Tag));
                workspace.UpdateViewport();
            }
            else if (obj.Tag is STAnimation)
            {
                if (WorkspacePanel == null)
                {
                    WorkspacePanel = CreateWorkspacePanel();
                }

                WorkspacePanel workspace = GetActiveEditor <WorkspacePanel>(WorkspacePanel);
                workspace.LoadFileFormat((STAnimation)(obj.Tag));
                workspace.UpdateViewport();
            }
            else if (obj.Tag is STBone)
            {
                var bone = (STBone)obj.Tag;
                Runtime.SelectedBoneIndex = bone.Index;
                WorkspacePanel.UpdateViewport();
            }

            if (tryUpdateViewport && WorkspacePanel != null)
            {
                WorkspacePanel.UpdateViewport();
            }
            // else
            //    GetActiveEditor<STPanel>();
        }