private SkeletonFile Load(string path) { SkeletonFile template = SerializerService.DeserializeFile <SkeletonFile>(path); BoneNameFiles.Add(template); if (template.BasedOn != null) { SkeletonFile baseTemplate = this.Load("Data/Skeletons/" + template.BasedOn); template.CopyBaseValues(baseTemplate); } // Validate that all bone names are unique if (template.BoneNames != null) { HashSet <string> boneNames = new HashSet <string>(); foreach ((string orignal, string name) in template.BoneNames) { if (boneNames.Contains(name)) { throw new Exception($"Duplicate bone name: {name} in skeleton file: {path}"); } boneNames.Add(name); } } return(template); }
public static void SaveTemplate(SkeletonFile skeleton) { string name = "Generated_"; if (skeleton.ModelTypes != null) { for (int i = 0; i < skeleton.ModelTypes.Count; i++) { if (i > 0) { name += "_"; } name += skeleton.ModelTypes[i]; } } if (skeleton.Race != null) { name += "_" + skeleton.Race; } if (skeleton.Age != null) { name += "_" + skeleton.Age; } SerializerService.SerializeFile("Data/Skeletons/" + name + ".json", skeleton); BoneNameFiles.Add(skeleton); }
private void Load(SkeletonFile template) { BoneNameFiles.Add(template); if (template.BasedOn != null) { SkeletonFile baseTemplate = SerializerService.DeserializeFile <SkeletonFile>("Data/Skeletons/" + template.BasedOn); this.Load(baseTemplate); template.CopyBaseValues(baseTemplate); } }
public static void SaveTemplate(SkeletonFile skeleton) { string name = "Generated_" + skeleton.ModelType; if (skeleton.Race != null) { name += skeleton.Race; } SerializerService.SerializeFile("Data/Skeletons/" + name + ".json", skeleton); BoneNameFiles.Add(skeleton); }
// Load the skeleton file and its BasedOn values public async Task <Dictionary <string, Bone> > Load(Appearance.Races race) { if (this.precachedBones.ContainsKey(race)) { return(this.precachedBones[race]); } try { IFileService fileService = Services.Get <IFileService>(); Dictionary <string, Bone> bones = new Dictionary <string, Bone>(); string fileName = race.ToString(); while (!string.IsNullOrEmpty(fileName)) { SkeletonFile file = await fileService.Open <SkeletonFile>(SkeletonFile.File, SkeletonsDirectory + fileName); if (file == null) { throw new Exception("Failed to load skeleton file: " + fileName); } foreach ((string name, Bone bone) in file.Bones) { // If we already have this bone, then its being overwritten by a higher file. if (bones.ContainsKey(name)) { continue; } bone.Offsets.Name = name; bones[name] = bone; } // Get the based on value to load bones from. fileName = file.BasedOn; } return(bones); } catch (Exception ex) { throw new Exception("Failed to load skeleton for race: " + race, ex); } }
public override async Task Initialize() { await base.Initialize(); this.freezePosition = new NopHookViewModel(AddressService.SkeletonFreezePosition, 5); this.freezePosition2 = new NopHookViewModel(AddressService.SkeletonFreezePosition2, 5); this.freezeRot1 = new NopHookViewModel(AddressService.SkeletonFreezeRotation, 6); this.freezeRot2 = new NopHookViewModel(AddressService.SkeletonFreezeRotation2, 6); this.freezeRot3 = new NopHookViewModel(AddressService.SkeletonFreezeRotation3, 4); this.freezeScale1 = new NopHookViewModel(AddressService.SkeletonFreezeScale, 6); this.freeseScale2 = new NopHookViewModel(AddressService.SkeletonFreezeScale2, 6); this.freezePhysics1 = new NopHookViewModel(AddressService.SkeletonFreezePhysics, 4); this.freezePhysics2 = new NopHookViewModel(AddressService.SkeletonFreezePhysics2, 3); this.freezePhysics3 = new NopHookViewModel(AddressService.SkeletonFreezePhysics3, 4); GposeService.GposeStateChanging += this.OnGposeStateChanging; string[] templates = Directory.GetFiles("Data/Skeletons/", "*.json"); foreach (string templatePath in templates) { SkeletonFile template = SerializerService.DeserializeFile <SkeletonFile>(templatePath); this.Load(template); } }
public void Load(System.IO.Stream stream) { CanSave = false; using (var reader = new FileReader(stream)) { while (!reader.EndOfStream) { ChunkHeader chunk = new ChunkHeader(); chunk.Position = reader.Position; chunk.Identifier = reader.ReadUInt32(); uint unk = reader.ReadUInt32(); chunk.ChunkSize = reader.ReadUInt32(); chunk.ChunkId = reader.ReadUInt32(); chunk.NextFilePtr = reader.ReadUInt32(); chunk.FileSize = reader.ReadUInt32(); uint unk2 = reader.ReadUInt32(); uint unk3 = reader.ReadUInt32(); Chunks.Add(chunk); var Identifer = chunk.Identifier.Reverse(); switch (Identifer) { case ChunkTextureFile: if (chunk.ChunkSize > 0x88) { reader.Seek(chunk.Position + 0x88, System.IO.SeekOrigin.Begin); chunk.FileName = reader.ReadString(Syroot.BinaryData.BinaryStringFormat.ZeroTerminated); } break; case ChunkMetaInfo: break; case ChunkAnimInfo: if (chunk.ChunkSize > 0xB0) { // reader.Seek(chunk.Position + 0xB0, System.IO.SeekOrigin.Begin); // chunk.FileName = reader.ReadString(Syroot.BinaryData.BinaryStringFormat.ZeroTerminated); } break; case ChunkAnimData: AnimationFile animFile = new AnimationFile(); animFile.Read(reader); chunk.ChunkData = animFile; break; case ChunkSkeletonData: SkeletonFile skelFile = new SkeletonFile(); skelFile.Read(reader); chunk.ChunkData = skelFile; break; case ChunkModelData: ModelFile modelFile = new ModelFile(); modelFile.Read(reader); chunk.ChunkData = modelFile; break; case ChunkMaterialData: MaterialFile matFile = new MaterialFile(); matFile.Read(reader); chunk.ChunkData = matFile; break; } reader.Seek(chunk.Position + chunk.ChunkSize, System.IO.SeekOrigin.Begin); } ReadGPUFile(FilePath); } }
private void ReadGPUFile(string FileName) { string path = FileName.Replace("cpu", "gpu"); if (!System.IO.File.Exists(path)) { return; } int offset = 0; //Read the data based on CPU chunk info using (var reader = new FileReader(path)) { for (int i = 0; i < Chunks.Count; i++) { if (Chunks[i].FileSize != 0 || Chunks[i].FileName != string.Empty || Chunks[i].ChunkData != null) { long pos = reader.Position; var identifer = Chunks[i].Identifier.Reverse(); var fileInfo = new FileInfo(); //Get CPU chunk data if (Chunks[i].ChunkData != null) { if (Chunks[i].ChunkData is AnimationFile) { AnimationFile animFile = (AnimationFile)Chunks[i].ChunkData; fileInfo.FileName = animFile.FileName; fileInfo.FileData = animFile.Data; } if (Chunks[i].ChunkData is SkeletonFile) { SkeletonFile animFile = (SkeletonFile)Chunks[i].ChunkData; fileInfo.FileName = animFile.FileName; fileInfo.FileData = animFile.Data; } if (Chunks[i].ChunkData is MaterialFile) { MaterialFile animFile = (MaterialFile)Chunks[i].ChunkData; fileInfo.FileName = animFile.FileName; fileInfo.FileData = animFile.Data; } if (Chunks[i].ChunkData is MaterialFile) { MaterialFile animFile = (MaterialFile)Chunks[i].ChunkData; fileInfo.FileName = animFile.FileName; fileInfo.FileData = animFile.Data; } if (Chunks[i].ChunkData is ModelFile) { ModelFile modelFile = (ModelFile)Chunks[i].ChunkData; fileInfo.FileName = modelFile.FileName; byte[] BufferData = new byte[0]; if (Chunks[i].FileSize != 0) { BufferData = reader.ReadBytes((int)Chunks[i].FileSize); } fileInfo.FileData = Utils.CombineByteArray(modelFile.Data, modelFile.Data2, BufferData); //Don't advance the stream unless the chunk has a pointer if (Chunks[i].NextFilePtr != 0) { reader.Seek(pos + Chunks[i].NextFilePtr, System.IO.SeekOrigin.Begin); } } } else //Else get the data from GPU { if (Chunks[i].FileName != string.Empty) { fileInfo.FileName = $"{Chunks[i].FileName}"; } else { fileInfo.FileName = $"{i} {Chunks[i].ChunkId} {identifer.ToString("X")}"; } if (Chunks[i].FileSize != 0) { fileInfo.FileData = reader.ReadBytes((int)Chunks[i].FileSize); } else { fileInfo.FileData = new byte[0]; } } files.Add(fileInfo); //Don't advance the stream unless the chunk has a pointer if (Chunks[i].NextFilePtr != 0) { reader.Seek(pos + Chunks[i].NextFilePtr, System.IO.SeekOrigin.Begin); } } } } }
private async Task Generate(SkeletonViewModel memory) { SkeletonFile?skeletonFile = memory.GetSkeletonFile(this.Actor); bool autoSkeleton = false; if ((skeletonFile == null || skeletonFile.Parenting == null) && GposeService.Instance.IsGpose) { string message = LocalizationService.GetStringFormatted("Pose_GenerateSkeleton", this.Actor.DisplayName); bool? result = await GenericDialog.Show(message, LocalizationService.GetString("Pose_GenerateSkeletonTitle"), MessageBoxButton.YesNo); autoSkeleton = result == true; } // Get all bones this.Bones.Clear(); this.GetBones(memory.Body, "Body"); this.GetBones(memory.Head, "Head"); this.GetBones(memory.Hair, "Hair"); this.GetBones(memory.Met, "Met"); this.GetBones(memory.Top, "Top"); if (skeletonFile != null && skeletonFile.BoneNames != null) { foreach (BoneVisual3d bone in this.Bones) { string?newName; if (skeletonFile.BoneNames.TryGetValue(bone.BoneName, out newName)) { bone.BoneName = newName; } } } if (autoSkeleton) { try { // gnerate parenting await ParentingUtility.ParentBones(this, this.Bones); } catch (Exception ex) { Log.Write(Severity.Error, new Exception("Failed to generate skeleton file.", ex)); return; } if (skeletonFile == null) { skeletonFile = new SkeletonFile(); skeletonFile.ModelType = this.Actor.ModelType; skeletonFile.Race = this.Actor.Customize?.Race; } skeletonFile.Parenting = new Dictionary <string, string>(); foreach (BoneVisual3d bone in this.Bones) { if (bone.Parent == null) { continue; } skeletonFile.Parenting.Add(bone.BoneName, bone.Parent.BoneName); } PoseService.SaveTemplate(skeletonFile); } else if (skeletonFile != null && skeletonFile.Parenting != null) { // parenting from file foreach (BoneVisual3d bone in this.Bones) { string?parentBoneName; if (skeletonFile.Parenting.TryGetValue(bone.BoneName, out parentBoneName)) { bone.Parent = this.GetBone(parentBoneName); if (bone.Parent == null) { throw new Exception($"Failed to find target parent bone: {parentBoneName}"); } } else { this.Children.Add(bone); } } } else { // no parenting... PoseService.Instance.EnableParenting = false; foreach (BoneVisual3d bone in this.Bones) { this.Children.Add(bone); } } }
public ColladaSkeletonExporter(IRepository repository, SkeletonFile skeletonFile) { Repository = repository; SkeletonFile = skeletonFile; TNS = TemplateNameSpace; }
public void Load(System.IO.Stream stream) { CanSave = false; using (var reader = new FileReader(stream)) { reader.SetByteOrder(true); Text = FileName; while (!reader.EndOfStream) { ChunkHeader chunk = new ChunkHeader(); chunk.Position = reader.Position; chunk.Identifier = reader.ReadUInt32(); uint unk = reader.ReadUInt32(); chunk.ChunkSize = reader.ReadUInt32(); chunk.ChunkId = reader.ReadUInt32(); chunk.NextFilePtr = reader.ReadUInt32(); chunk.FileSize = reader.ReadUInt32(); uint unk2 = reader.ReadUInt32(); uint unk3 = reader.ReadUInt32(); Chunks.Add(chunk); var Identifer = chunk.Identifier.Reverse(); switch (Identifer) { case ChunkTextureFile: SWUTexture texture = new SWUTexture(); reader.SeekBegin(chunk.Position + 72); texture.ImageKey = "texture"; texture.SelectedImageKey = "texture"; texture.ReadChunk(reader); chunk.ChunkData = texture; if (chunk.ChunkSize > 244) { reader.Seek(chunk.Position + 244, System.IO.SeekOrigin.Begin); chunk.FileName = reader.ReadString(Syroot.BinaryData.BinaryStringFormat.ZeroTerminated); texture.Text = chunk.FileName; } Nodes.Add(texture); break; case ChunkMetaInfo: break; case ChunkAnimInfo: if (chunk.ChunkSize > 0xB0) { reader.Seek(chunk.Position + 0xB0, System.IO.SeekOrigin.Begin); chunk.FileName = reader.ReadString(Syroot.BinaryData.BinaryStringFormat.ZeroTerminated); } break; case ChunkAnimData: AnimationFile animFile = new AnimationFile(); animFile.Read(reader); chunk.ChunkData = animFile; break; case ChunkSkeletonData: SkeletonFile skelFile = new SkeletonFile(); skelFile.Read(reader); chunk.ChunkData = skelFile; break; case ChunkModelData: ModelFile modelFile = new ModelFile(); modelFile.Read(reader); chunk.ChunkData = modelFile; break; case ChunkMaterialData: MaterialFile matFile = new MaterialFile(); matFile.Read(reader); chunk.ChunkData = matFile; break; } reader.Seek(chunk.Position + chunk.ChunkSize, System.IO.SeekOrigin.Begin); } ReadGPUFile(FilePath); } TreeHelper.CreateFileDirectory(this); }