Пример #1
0
        /// <summary>
        /// Updates the skeleton from a baked animation if one is already loaded.
        /// </summary>
        public void UpdateSkeleton(SkeletalAnim SkeletalAnim, int index)
        {
            if (SkeletalAnim == null)
            {
                return;
            }

            var skeleton = SkeletalAnim.CreateBakedSkeleton(index);

            CachedModel.Skeleton = skeleton;
        }
Пример #2
0
        /// <summary>
        /// Updates the mesh indices from a baked skeleton if one is already loaded
        /// </summary>
        public void UpdateBoneIndices()
        {
            if (SkeletalAnim == null || updated)
            {
                return;
            }
            updated = true;

            int[] indexTable = new int[10];
            for (int i = 0; i < 10; i++)
            {
                indexTable[i] = -1;
            }

            for (int m = 0; m < Models.Count; m++)
            {
                var meshIndices = SkeletalAnim.GetMeshIndexGroups(m);
                for (int i = 0; i < meshIndices.Count; i++)
                {
                    if (Models[m].Meshes.Count <= i)
                    {
                        break;
                    }

                    foreach (var indexGrp in meshIndices[i])
                    {
                        foreach (var boneIndices in indexGrp.BoneIndices)
                        {
                            int index = boneIndices.RiggingIndex / 3;
                            indexTable[index] = indexGrp.Index - boneIndices.BoneIndexShift;
                        }
                    }
                    foreach (var meshGroup in Models[m].Meshes[i].Groups)
                    {
                        ApplyBoneTransforms(Models[m], meshGroup, indexTable);
                    }
                }
            }
        }
Пример #3
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);
            }
        }