public bool Deserialize(JObject janim) { if (janim == null) { return(false); } if (janim["Frames"] != null) { FrameCount = janim["Frames"].Value <int>(); } if (janim["AniPerSec"] != null) { AnimPerSec = janim["AniPerSec"].Value <float>(); } if (janim["IsLoop"] != null) { IsLoop = janim["IsLoop"].Value <bool>(); } foreach (JObject jbone in janim["Bones"]) { CBone bone = new CBone(); if (bone.Deserialize(jbone) == true) { Bones.Add(bone); } } return(true); }
void CreateBoneOverview(GameSkeleton skeleton) { SelectedBone = null; Bones.Clear(); BoneCount = 0; if (skeleton == null) { return; } BoneCount = skeleton.BoneCount; for (int i = 0; i < skeleton.BoneCount; i++) { var parentBoneId = skeleton.GetParentBone(i); if (parentBoneId == -1) { Bones.Add(CreateNode(i, parentBoneId, skeleton.BoneNames[i])); } else { var treeParent = GetParent(Bones, parentBoneId); if (treeParent != null) { treeParent.Children.Add(CreateNode(i, parentBoneId, skeleton.BoneNames[i])); } } } }
public void NewBoneAnim() { var boneAnim = new BoneAnimNode("NewBoneTarget", true); if (Nodes.Count <= 0) { foreach (var bone in Bones) { Nodes.Add(bone); } this.Expand(); } Nodes.Add(boneAnim); Bones.Add(boneAnim); if (SkeletalAnimU != null) { boneAnim.BoneAnimU = new ResU.BoneAnim() { Name = boneAnim.Text }; } else { boneAnim.BoneAnim = new BoneAnim() { Name = boneAnim.Text }; } }
void CreateBoneOverview(GameSkeleton skeleton) { var boneIndexsUsed = _meshNode.Geometry.GetUniqeBlendIndices(); Bones.Clear(); if (skeleton == null) { return; } for (int i = 0; i < skeleton.BoneCount; i++) { var parentBoneId = skeleton.GetParentBone(i); if (parentBoneId == -1) { Bones.Add(CreateNode(i, parentBoneId, skeleton.BoneNames[i], boneIndexsUsed)); } else { var treeParent = GetParent(Bones, parentBoneId); if (treeParent != null) { treeParent.Children.Add(CreateNode(i, parentBoneId, skeleton.BoneNames[i], boneIndexsUsed)); } } } Bones = FilterHelper.FilterBoneList("", true, Bones); }
// --- Bones. public void AddBone(BoneData bone) { if (bone == null) { throw new ArgumentNullException("bone cannot be null."); } Bones.Add(bone); }
internal void RebuildSkeleton(Model3D model) { Bones.Clear(); foreach (var boneName in BoneNames) { Bones.Add(model.Find <Node3D>(boneName)); } }
public void Reload() { //Set the remap table RemapTable.Clear(); if (Skeleton.MatrixToBoneList != null) { for (int i = 0; i < Skeleton.MatrixToBoneList.Count; i++) { RemapTable.Add(Skeleton.MatrixToBoneList[i]); } } foreach (var bone in Skeleton.Bones.Values) { var genericBone = new BfresBone(this) { BoneData = bone, Name = bone.Name, ParentIndex = bone.ParentIndex, Position = new OpenTK.Vector3( bone.Position.X, bone.Position.Y, bone.Position.Z) * GLFrameworkEngine.GLContext.PreviewScale, Scale = new OpenTK.Vector3( bone.Scale.X, bone.Scale.Y, bone.Scale.Z), ParentSkeletonData = Skeleton, }; if (Skeleton.FlagsScaling == SkeletonFlagsScaling.Maya) { genericBone.UseSegmentScaleCompensate = true; } if (bone.FlagsRotation == BoneFlagsRotation.EulerXYZ) { genericBone.EulerRotation = new OpenTK.Vector3( bone.Rotation.X, bone.Rotation.Y, bone.Rotation.Z); } else { genericBone.Rotation = new OpenTK.Quaternion( bone.Rotation.X, bone.Rotation.Y, bone.Rotation.Z, bone.Rotation.W); } Bones.Add(genericBone); } Reset(); }
/// <summary> /// Add a new bone to the chain at the selected location or at the end if no location is selected. /// </summary> void AddBone() { BoneData newBone = new BoneData(); newBone.Length = 50; newBone.Weight = 1; // insert at the end if no bone is selected //if (_boneList.SelectedIndex == -1) Bones.Add(newBone); //else // Bones.Insert (_boneList.SelectedIndex, newBone); }
private void AttemptToAddPrimaryBone(IBone boneToAdd) { if (!string.IsNullOrEmpty(PrimaryBoneID)) { throw new Exception(string.Concat("Primary bone already exists - ID: ", PrimaryBoneID)); } else { SetBoneStandardValues(boneToAdd); Bones.Add(boneToAdd.ID, boneToAdd); PrimaryBoneID = boneToAdd.ID; } }
internal void Read(EndianBinaryReader reader) { long boneIDsOffset = reader.ReadOffset(); long boneMatricesOffset = reader.ReadOffset(); long boneNamesOffset = reader.ReadOffset(); long meshExDataOffset = reader.ReadOffset(); int boneCount = reader.ReadInt32(); long boneParentIDsOffset = reader.ReadOffset(); reader.ReadAtOffset(boneIDsOffset, () => { Bones.Capacity = boneCount; for (int i = 0; i < boneCount; i++) { var bone = new Bone(); bone.ID = reader.ReadInt32(); Bones.Add(bone); } }); reader.ReadAtOffset(boneMatricesOffset, () => { foreach (var bone in Bones) { bone.Matrix = reader.ReadMatrix4x4(); } }); reader.ReadAtOffset(boneNamesOffset, () => { foreach (var bone in Bones) { bone.Name = reader.ReadStringOffset(StringBinaryFormat.NullTerminated); } }); reader.ReadAtOffset(meshExDataOffset, () => { ExData = new MeshExData(); ExData.Read(reader); }); reader.ReadAtOffset(boneParentIDsOffset, () => { foreach (var bone in Bones) { bone.ParentID = reader.ReadInt32(); } }); }
internal G1MGBone(Span <byte> data, ModelSection section) { Section = section; var offset = 0; for (var i = 0; i < section.Count; ++i) { var count = MemoryMarshal.Read <int>(data.Slice(offset)); offset += 4; Bones.Add(MemoryMarshal.Cast <byte, ModelGeometryBone>(data.Slice(offset, count * SizeHelper.SizeOf <ModelGeometryBone>())).ToArray()); offset += count * SizeHelper.SizeOf <ModelGeometryBone>(); } }
public void Read(EndianBinaryReader er) { GrannyUtils.SubreadUInt64Pointer( er, ser => { this.Name = ser.ReadStringNT(); }); var boneCount = er.ReadUInt32(); GrannyUtils.SubreadUInt64Pointer(er, ser => { for (var i = 0; i < boneCount; ++i) { Bones.Add(ser.ReadNew <GrannyBone>()); } }); }
void AddExecute() { Int64 startTicks = Log.VIEWMODEL("(BoneDetailViewModel) Enter", Common.LOG_APPNAME); var wrapper = new BoneWrapper(new Domain.Bone()); wrapper.PropertyChanged += Wrapper_PropertyChanged; _BoneDataService.Add(wrapper.Model); Bones.Add(wrapper); wrapper.Name = ""; // Trigger the validation Log.VIEWMODEL("(BoneDetailViewModel) Exit", Common.LOG_APPNAME, startTicks); }
//public void CopyBoneTransformsFrom(Matrix4[] sourceBoneTransforms) { } //public void CopyBoneTransformsTo(Matrix4[] destinationBoneTransforms) { } public int AddMesh(ModelMesh mesh, int parentBoneIndex = 0) { bool addBone = true; ModelBone b = new ModelBone { Index = -1 }; if (Bones.Count > 0) { b.Parent = Bones[parentBoneIndex]; Bones[parentBoneIndex].Children.Add(b); int childBoneCount = CountChildrenOf(parentBoneIndex); if (parentBoneIndex + childBoneCount < Bones.Count) { int index = parentBoneIndex + childBoneCount; addBone = false; Bones.Insert(index, b); b.Index = index; } } if (addBone) { Bones.Add(b); b.Index = Bones.Count - 1; } else { Bones.ReIndex(); } if (mesh != null) { b.Type = BoneType.Mesh; b.Attachment = mesh; mesh.Parent = Bones[b.Index]; Meshes.Add(mesh); } else { // Just a bone } return(b.Index); }
/// <summary> /// Add a new bone to the chain at the selected location or at the end if no location is selected. /// </summary> void AddBone() { BoneData newBone = new BoneData(); newBone.Length = 50; newBone.PropertyChanged += BonePropertyChanged; // insert at the end if no bone is selected if (_boneList.SelectedIndex == -1) { Bones.Add(newBone); } else { Bones.Insert(_boneList.SelectedIndex, newBone); } }
private void AttemptToAddChildBone(IBone boneToAdd, string parentBoneID) { if (Bones.ContainsKey(boneToAdd.ID)) { throw new Exception(string.Concat("Bone IDs must be unique! ID: ", boneToAdd.ID)); } else if (!Bones.ContainsKey(parentBoneID)) { throw new Exception(string.Concat("Parent does not exist! Child ID: ", boneToAdd.ID, " expected parent ID: ", parentBoneID)); } else { SetBoneStandardValues(boneToAdd); boneToAdd.Parent = Bones[parentBoneID]; Bones.Add(boneToAdd.ID, boneToAdd); Bones[parentBoneID].Children.Add(boneToAdd); } }
/// <summary> /// Adds a new bone to the model with the given information /// </summary> /// <param name="Name">The tag name of this bone</param> /// <param name="ParentIndex">The parent index of this bone, -1 for a root bone</param> /// <param name="GlobalPosition">The global space position of this bone</param> /// <param name="GlobalRotation">The global space rotation of this bone</param> /// <param name="LocalPosition">The local parent space position of this bone</param> /// <param name="LocalRotation">The local parent space rotation of this bone</param> /// <param name="Scale">The scale of this bone, 1.0 is default</param> public void AddBone(string Name, int ParentIndex, Vector3 GlobalPosition, Quaternion GlobalRotation, Vector3 LocalPosition, Quaternion LocalRotation, Vector3 Scale) { var Bone = new SEModelBone() { BoneName = Name, BoneParent = ParentIndex }; // Set matricies Bone.GlobalPosition = GlobalPosition; Bone.GlobalRotation = GlobalRotation; Bone.LocalPosition = LocalPosition; Bone.LocalRotation = LocalRotation; // Set scale Bone.Scale = Scale; // Add Bones.Add(Bone); }
internal override void ReadBody(EndianBinaryReader reader, StringSet stringSet) { StartIndex = reader.ReadInt32(); Count = reader.ReadInt32(); ExternalName = stringSet.ReadString(reader); Name = stringSet.ReadString(reader); Bones.Capacity = Count; for (int i = 0; i < Count; i++) { Bones.Add(new OsageBone()); } // Either means rotation info on FT, or integrated SKP on old DT/AC reader.ReadOffset(() => { long current = reader.Position; { if (reader.ReadUInt32() == 0) // Integrated SKP, yet to support. { return; } } reader.SeekBegin(current); foreach (var bone in Bones) { bone.ReadOsgBlockInfo(reader, stringSet); } }); if (reader.AddressSpace == AddressSpace.Int64) { reader.SkipNulls(4 * sizeof(ulong)); } else { reader.SkipNulls(5 * sizeof(uint)); } }
private async Task LoadBonesLookupAsync() { Int64 startTicks = Log.VIEWMODEL("(DogDetailViewModel) Enter", Common.LOG_APPNAME); Bones.Clear(); //ProgrammingLanguages.Add(new NullLookupItem()); Bones.Add(new NullLookupItem { DisplayMember = " - " }); var lookup = await _BoneLookupDataService .GetBoneLookupAsync(); foreach (var lookupItem in lookup) { Bones.Add(lookupItem); } Log.VIEWMODEL("(DogDetailViewModel) Exit", Common.LOG_APPNAME, startTicks); }
public M2BoneAnimator(Stormlib.MPQFile file, M2Info parent) { string AnimPath = parent.FileDirectory + parent.ModelName; M2Animation[] anims = new M2Animation[parent.Header.nAnimations]; file.Position = parent.Header.ofsAnimations; file.Read(anims); Stormlib.MPQFile[] AnimFiles = new Stormlib.MPQFile[parent.Header.nAnimations]; for (int i = 0; i < parent.Header.nAnimations; ++i) { string full = AnimPath + anims[i].AnimationID.ToString("D4") + "-" + anims[i].SubAnimationID.ToString("D2") + ".anim"; if (Stormlib.MPQFile.Exists(full)) { Console.WriteLine(full); AnimFiles[i] = new Stormlib.MPQFile(full); } } Animations.AddRange(anims); this.file = file; var bones = new M2Bone[parent.Header.nBones]; file.Position = parent.Header.ofsBones; file.Read(bones); foreach (var bone in bones) { M2AnimationBone ab = new M2AnimationBone(bone, this, file, parent.GlobalSequences, AnimFiles); Bones.Add(ab); ab.BoneIndex = Bones.Count - 1; } foreach (var bone in Bones) { bone.Init(); } }
// private async void OpenDetailView(OpenDetailViewEventArgs args) // { // Int64 startTicks = Log.EVENT("(BoneDetailViewModel) Enter", Common.LOG_APPNAME); // await LoadAsync(args.Id); // Log.EVENT("(BoneDetailViewModel) Exit", Common.LOG_APPNAME, startTicks); // } #endregion #region Public Methods public override async Task LoadAsync(int id) { Int64 startTicks = Log.VIEWMODEL("(BoneDetailViewModel) Enter Id:({id})", Common.LOG_APPNAME); Id = id; foreach (var wrapper in Bones) { wrapper.PropertyChanged -= Wrapper_PropertyChanged; } Bones.Clear(); var items = await _BoneDataService.AllAsync(); foreach (var model in items) { var wrapper = new BoneWrapper(model); wrapper.PropertyChanged += Wrapper_PropertyChanged; Bones.Add(wrapper); } Log.VIEWMODEL("(BoneDetailViewModel) Exit", Common.LOG_APPNAME, startTicks); }
public void Push(SkinnedMeshRenderer renderer) { var mesh = renderer.sharedMesh; if (mesh == null) { Debug.LogWarningFormat("{0} has no mesh", renderer.name); return; } Result.SourceSkinnedMeshRenderers.Add(renderer); Result.MeshMap.Sources.Add(mesh); var indexOffset = Positions.Count; var boneIndexOffset = Bones.Count; Positions.AddRange(mesh.vertices); Normals.AddRange(mesh.normals); UV.AddRange(mesh.uv); Tangents.AddRange(mesh.tangents); if (mesh.vertexCount == mesh.boneWeights.Length) { BoneWeights.AddRange(mesh.boneWeights.Select(x => AddBoneIndexOffset(x, boneIndexOffset)).ToArray()); BindPoses.AddRange(mesh.bindposes); Bones.AddRange(renderer.bones); } else { // Bone Count 0 уБо SkinnedMeshRenderer var rigidBoneWeight = new BoneWeight { boneIndex0 = boneIndexOffset, weight0 = 1f, }; BoneWeights.AddRange(Enumerable.Range(0, mesh.vertexCount).Select(x => rigidBoneWeight).ToArray()); BindPoses.Add(renderer.transform.localToWorldMatrix); Bones.Add(renderer.transform); } for (int i = 0; i < mesh.subMeshCount && i < renderer.sharedMaterials.Length; ++i) { var indices = mesh.GetIndices(i).Select(x => x + indexOffset); var mat = renderer.sharedMaterials[i]; var sameMaterialSubMeshIndex = SubMeshes.FindIndex(x => ReferenceEquals(x.Material, mat)); if (sameMaterialSubMeshIndex >= 0) { SubMeshes[sameMaterialSubMeshIndex].Indices.AddRange(indices); } else { SubMeshes.Add(new SubMesh { Indices = indices.ToList(), Material = mat, }); } } for (int i = 0; i < mesh.blendShapeCount; ++i) { var positions = (Vector3[])mesh.vertices.Clone(); var normals = (Vector3[])mesh.normals.Clone(); var tangents = mesh.tangents.Select(x => (Vector3)x).ToArray(); mesh.GetBlendShapeFrameVertices(i, 0, positions, normals, tangents); BlendShapes.Add(new BlendShape { VertexOffset = indexOffset, FrameWeight = mesh.GetBlendShapeFrameWeight(i, 0), Name = mesh.GetBlendShapeName(i), Positions = positions, Normals = normals, Tangents = tangents, }); } }
internal void Read(EndianBinaryReader reader) { long bonesOffset = reader.ReadOffset(); int positionCount = reader.ReadInt32(); long positionsOffset = reader.ReadOffset(); long field02Offset = reader.ReadOffset(); int boneName1Count = reader.ReadInt32(); long boneNames1Offset = reader.ReadOffset(); int boneName2Count = reader.ReadInt32(); long boneNames2Offset = reader.ReadOffset(); long parentIndicesOffset = reader.ReadOffset(); reader.ReadAtOffset(bonesOffset, () => { while (true) { var boneEntry = new BoneEntry(); boneEntry.Read(reader); if (boneEntry.Name == "End") { break; } Bones.Add(boneEntry); } }); reader.ReadAtOffset(positionsOffset, () => { Positions.Capacity = positionCount; for (int i = 0; i < positionCount; i++) { Positions.Add(reader.ReadVector3()); } }); reader.ReadAtOffset(field02Offset, () => { Field02 = reader.ReadInt32(); }); reader.ReadAtOffset(boneNames1Offset, () => { BoneNames1.Capacity = boneName1Count; for (int i = 0; i < boneName1Count; i++) { BoneNames1.Add(reader.ReadStringOffset(StringBinaryFormat.NullTerminated)); } }); reader.ReadAtOffset(boneNames2Offset, () => { BoneNames2.Capacity = boneName2Count; for (int i = 0; i < boneName2Count; i++) { BoneNames2.Add(reader.ReadStringOffset(StringBinaryFormat.NullTerminated)); } }); reader.ReadAtOffset(parentIndicesOffset, () => { ParentIndices.Capacity = boneName2Count; for (int i = 0; i < boneName2Count; i++) { ParentIndices.Add(reader.ReadInt16()); } }); }
private protected virtual void AddingBone(BoneGraphics bone) { Bones.Add(bone); Grids.Add(bone.BoneGrid); Grids[^ 1].Name = $"G{Grids.Count - 1}";
internal void Read(EndianBinaryReader reader) { long bonesOffset = reader.ReadOffset(); int positionCount = reader.ReadInt32(); long positionsOffset = reader.ReadOffset(); long unknownValueOffset = reader.ReadOffset(); int objectBoneNameCount = reader.ReadInt32(); long objectBoneNamesOffset = reader.ReadOffset(); int motionBoneNameCount = reader.ReadInt32(); long motionBoneNamesOffset = reader.ReadOffset(); long parentIndicesOffset = reader.ReadOffset(); reader.ReadAtOffset(bonesOffset, () => { while (true) { var bone = new Bone(); bone.Read(reader); if (bone.Name == "End") { break; } Bones.Add(bone); } }); reader.ReadAtOffset(positionsOffset, () => { Positions.Capacity = positionCount; for (int i = 0; i < positionCount; i++) { Positions.Add(reader.ReadVector3()); } }); reader.ReadAtOffset(unknownValueOffset, () => { UnknownValue = reader.ReadInt32(); }); reader.ReadAtOffset(objectBoneNamesOffset, () => { ObjectBoneNames.Capacity = objectBoneNameCount; for (int i = 0; i < objectBoneNameCount; i++) { ObjectBoneNames.Add(reader.ReadStringOffset(StringBinaryFormat.NullTerminated)); } }); reader.ReadAtOffset(motionBoneNamesOffset, () => { MotionBoneNames.Capacity = motionBoneNameCount; for (int i = 0; i < motionBoneNameCount; i++) { MotionBoneNames.Add(reader.ReadStringOffset(StringBinaryFormat.NullTerminated)); } }); reader.ReadAtOffset(parentIndicesOffset, () => { ParentIndices.Capacity = motionBoneNameCount; for (int i = 0; i < motionBoneNameCount; i++) { ParentIndices.Add(reader.ReadInt16()); } }); }
private void Read(BinaryReader br, Dictionary <string, BinaryReader> sequenceGroups) { Header = new Header { ID = ID.Idst, Version = Version.Goldsource, Name = br.ReadFixedLengthString(Encoding.ASCII, 64), Size = br.ReadInt32(), EyePosition = br.ReadVector3(), HullMin = br.ReadVector3(), HullMax = br.ReadVector3(), BoundingBoxMin = br.ReadVector3(), BoundingBoxMax = br.ReadVector3(), Flags = br.ReadInt32() }; // Read all the nums/offsets from the header var sections = new int[(int)Section.NumSections][]; for (var i = 0; i < (int)Section.NumSections; i++) { var sec = (Section)i; int indexNum; if (sec == Section.Texture || sec == Section.Skin) { indexNum = 3; } else { indexNum = 2; } sections[i] = new int[indexNum]; for (var j = 0; j < indexNum; j++) { sections[i][j] = br.ReadInt32(); } } // Bones var num = SeekToSection(br, Section.Bone, sections); var numBones = num; for (var i = 0; i < num; i++) { var bone = new Bone { Name = br.ReadFixedLengthString(Encoding.ASCII, 32), Parent = br.ReadInt32(), Flags = br.ReadInt32(), Controllers = br.ReadIntArray(6), Position = br.ReadVector3(), Rotation = br.ReadVector3(), PositionScale = br.ReadVector3(), RotationScale = br.ReadVector3() }; Bones.Add(bone); } // Bone controllers num = SeekToSection(br, Section.BoneController, sections); for (var i = 0; i < num; i++) { var boneController = new BoneController { Bone = br.ReadInt32(), Type = br.ReadInt32(), Start = br.ReadSingle(), End = br.ReadSingle(), Rest = br.ReadInt32(), Index = br.ReadInt32() }; BoneControllers.Add(boneController); } // Hitboxes num = SeekToSection(br, Section.Hitbox, sections); for (var i = 0; i < num; i++) { var hitbox = new Hitbox { Bone = br.ReadInt32(), Group = br.ReadInt32(), Min = br.ReadVector3(), Max = br.ReadVector3() }; Hitboxes.Add(hitbox); } // Sequence groups num = SeekToSection(br, Section.SequenceGroup, sections); for (var i = 0; i < num; i++) { var group = new SequenceGroup { Label = br.ReadFixedLengthString(Encoding.ASCII, 32), Name = br.ReadFixedLengthString(Encoding.ASCII, 64) }; br.ReadBytes(8); // unused SequenceGroups.Add(group); } // Sequences num = SeekToSection(br, Section.Sequence, sections); for (var i = 0; i < num; i++) { var sequence = new Sequence { Name = br.ReadFixedLengthString(Encoding.ASCII, 32), Framerate = br.ReadSingle(), Flags = br.ReadInt32(), Activity = br.ReadInt32(), ActivityWeight = br.ReadInt32(), NumEvents = br.ReadInt32(), EventIndex = br.ReadInt32(), NumFrames = br.ReadInt32(), NumPivots = br.ReadInt32(), PivotIndex = br.ReadInt32(), MotionType = br.ReadInt32(), MotionBone = br.ReadInt32(), LinearMovement = br.ReadVector3(), AutoMovePositionIndex = br.ReadInt32(), AutoMoveAngleIndex = br.ReadInt32(), Min = br.ReadVector3(), Max = br.ReadVector3(), NumBlends = br.ReadInt32(), AnimationIndex = br.ReadInt32(), BlendType = br.ReadIntArray(2), BlendStart = br.ReadSingleArray(2), BlendEnd = br.ReadSingleArray(2), BlendParent = br.ReadInt32(), SequenceGroup = br.ReadInt32(), EntryNode = br.ReadInt32(), ExitNode = br.ReadInt32(), NodeFlags = br.ReadInt32(), NextSequence = br.ReadInt32() }; var seqGroup = SequenceGroups[sequence.SequenceGroup]; // Only load seqence group 0 for now (others are in other files) if (sequence.SequenceGroup == 0) { var pos = br.BaseStream.Position; sequence.Blends = LoadAnimationBlends(br, sequence, numBones); br.BaseStream.Position = pos; } else if (sequenceGroups.ContainsKey(seqGroup.Name)) { var reader = sequenceGroups[seqGroup.Name]; sequence.Blends = LoadAnimationBlends(reader, sequence, numBones); } Sequences.Add(sequence); } // Textures num = SeekToSection(br, Section.Texture, sections); var firstTextureIndex = Textures.Count; for (var i = 0; i < num; i++) { var texture = new Texture { Name = br.ReadFixedLengthString(Encoding.ASCII, 64), Flags = (TextureFlags)br.ReadInt32(), Width = br.ReadInt32(), Height = br.ReadInt32(), Index = br.ReadInt32() }; Textures.Add(texture); } // Texture data for (var i = firstTextureIndex; i < firstTextureIndex + num; i++) { var t = Textures[i]; br.BaseStream.Position = t.Index; t.Data = br.ReadBytes(t.Width * t.Height); t.Palette = br.ReadBytes(256 * 3); Textures[i] = t; } // Skins var skinSection = sections[(int)Section.Skin]; var numSkinRefs = skinSection[0]; var numSkinFamilies = skinSection[1]; br.BaseStream.Seek(skinSection[2], SeekOrigin.Begin); for (var i = 0; i < numSkinFamilies; i++) { var skin = new SkinFamily { Textures = br.ReadShortArray(numSkinRefs) }; Skins.Add(skin); } // Body parts num = SeekToSection(br, Section.BodyPart, sections); for (var i = 0; i < num; i++) { var part = new BodyPart { Name = br.ReadFixedLengthString(Encoding.ASCII, 64), NumModels = br.ReadInt32(), Base = br.ReadInt32(), ModelIndex = br.ReadInt32() }; var pos = br.BaseStream.Position; part.Models = LoadModels(br, part); br.BaseStream.Position = pos; BodyParts.Add(part); } // Attachments num = SeekToSection(br, Section.Attachment, sections); for (var i = 0; i < num; i++) { var attachment = new Attachment { Name = br.ReadFixedLengthString(Encoding.ASCII, 32), Type = br.ReadInt32(), Bone = br.ReadInt32(), Origin = br.ReadVector3(), Vectors = br.ReadVector3Array(3) }; Attachments.Add(attachment); } // Transitions // Sounds & Sound groups aren't used }
public void Push(MeshRenderer renderer) { var meshFilter = renderer.GetComponent <MeshFilter>(); if (meshFilter == null) { Debug.LogWarningFormat("{0} has no mesh filter", renderer.name); return; } var mesh = meshFilter.sharedMesh; if (mesh == null) { Debug.LogWarningFormat("{0} has no mesh", renderer.name); return; } Result.SourceMeshRenderers.Add(renderer); Result.MeshMap.Sources.Add(mesh); var indexOffset = Positions.Count; var boneIndexOffset = Bones.Count; Positions.AddRange(mesh.vertices .Select(x => renderer.transform.TransformPoint(x)) ); Normals.AddRange(mesh.normals .Select(x => renderer.transform.TransformVector(x)) ); UV.AddRange(mesh.uv); Tangents.AddRange(mesh.tangents .Select(t => { var v = renderer.transform.TransformVector(t.x, t.y, t.z); return(new Vector4(v.x, v.y, v.z, t.w)); }) ); var self = renderer.transform; var bone = self.parent; if (bone == null) { Debug.LogWarningFormat("{0} is root gameobject.", self.name); return; } var bindpose = bone.worldToLocalMatrix; BoneWeights.AddRange(Enumerable.Range(0, mesh.vertices.Length) .Select(x => new BoneWeight() { boneIndex0 = Bones.Count, weight0 = 1, }) ); BindPoses.Add(bindpose); Bones.Add(bone); for (int i = 0; i < mesh.subMeshCount && i < renderer.sharedMaterials.Length; ++i) { var indices = mesh.GetIndices(i).Select(x => x + indexOffset); var mat = renderer.sharedMaterials[i]; var sameMaterialSubMeshIndex = SubMeshes.FindIndex(x => ReferenceEquals(x.Material, mat)); if (sameMaterialSubMeshIndex >= 0) { SubMeshes[sameMaterialSubMeshIndex].Indices.AddRange(indices); } else { SubMeshes.Add(new SubMesh { Indices = indices.ToList(), Material = mat, }); } } }
/// <summary> /// Loads the file from the specified stream. /// </summary> /// <param name="stream">The stream to read from.</param> public override void Load(Stream stream) { BinaryReader reader = new BinaryReader(stream, Encoding.GetEncoding("us-ascii")); string identifier = reader.ReadString(7); int version; if (string.Compare(identifier, FILE_IDENTIFIER_2, false) == 0) { version = 2; } else if (string.Compare(identifier, FILE_IDENTIFIER_3, false) == 0) { version = 3; } else { throw new FileIdentifierMismatchException(FilePath, string.Format("{0} / {1}", FILE_IDENTIFIER_2, FILE_IDENTIFIER_3), identifier); } int boneCount = reader.ReadInt32(); if (boneCount >= MAXIMUM_BONE_COUNT) { throw new InvalidBoneCountException(); } for (int i = 0; i < boneCount; i++) { Bone bone = new Bone { Parent = reader.ReadInt32(), Name = reader.ReadNullTerminatedString(), Translation = reader.ReadVector3(), Rotation = reader.ReadQuaternion(true) }; Bones.Add(bone); } int dummyCount = reader.ReadInt32(); if (boneCount >= MAXIMUM_BONE_COUNT) { throw new InvalidBoneCountException(); } for (int i = 0; i < dummyCount; i++) { Bone dummy = new Bone { Name = reader.ReadNullTerminatedString(), Parent = reader.ReadInt32(), Translation = reader.ReadVector3() }; if (version == 3) { dummy.Rotation = reader.ReadQuaternion(true); } DummyBones.Clear(); } }
private void LoadAnimData(ResU.SkeletalAnim ska) { Nodes.Clear(); Bones.Clear(); CanLoop = ska.FlagsAnimSettings.HasFlag(ResU.SkeletalAnimFlags.Looping); foreach (ResU.BoneAnim bn in ska.BoneAnims) { BoneAnimNode bone = new BoneAnimNode(bn.Name, false); bone.BoneAnimU = bn; bone.UseSegmentScaleCompensate = bn.ApplySegmentScaleCompensate; Bones.Add(bone); // Nodes.Add(bone); if (ska.FlagsRotate == ResU.SkeletalAnimFlagsRotate.EulerXYZ) { bone.RotType = Animation.RotationType.EULER; } else { bone.RotType = Animation.RotationType.QUATERNION; } if (bn.FlagsBase.HasFlag(ResU.BoneAnimFlagsBase.Scale)) { bone.XSCA.Keys.Add(new KeyFrame() { Frame = 0, Value = bn.BaseData.Scale.X, IsKeyed = true }); bone.YSCA.Keys.Add(new KeyFrame() { Frame = 0, Value = bn.BaseData.Scale.Y, IsKeyed = true }); bone.ZSCA.Keys.Add(new KeyFrame() { Frame = 0, Value = bn.BaseData.Scale.Z, IsKeyed = true }); } if (bn.FlagsBase.HasFlag(ResU.BoneAnimFlagsBase.Rotate)) { bone.XROT.Keys.Add(new KeyFrame() { Frame = 0, Value = bn.BaseData.Rotate.X, IsKeyed = true }); bone.YROT.Keys.Add(new KeyFrame() { Frame = 0, Value = bn.BaseData.Rotate.Y, IsKeyed = true }); bone.ZROT.Keys.Add(new KeyFrame() { Frame = 0, Value = bn.BaseData.Rotate.Z, IsKeyed = true }); bone.WROT.Keys.Add(new KeyFrame() { Frame = 0, Value = bn.BaseData.Rotate.W, IsKeyed = true }); } if (bn.FlagsBase.HasFlag(ResU.BoneAnimFlagsBase.Translate)) { bone.XPOS.Keys.Add(new KeyFrame() { Frame = 0, Value = bn.BaseData.Translate.X, IsKeyed = true }); bone.YPOS.Keys.Add(new KeyFrame() { Frame = 0, Value = bn.BaseData.Translate.Y, IsKeyed = true }); bone.ZPOS.Keys.Add(new KeyFrame() { Frame = 0, Value = bn.BaseData.Translate.Z, IsKeyed = true }); } for (int curve = 0; curve < bn.Curves.Count; curve++) { Animation.KeyGroup keyGroup = CurveHelper.CreateTrackWiiU(bn.Curves[curve]); keyGroup.AnimDataOffset = bn.Curves[curve].AnimDataOffset; switch (keyGroup.AnimDataOffset) { case (int)TrackType.XPOS: bone.XPOS.Keys.AddRange(keyGroup.Keys); break; case (int)TrackType.YPOS: bone.YPOS.Keys.AddRange(keyGroup.Keys); break; case (int)TrackType.ZPOS: bone.ZPOS.Keys.AddRange(keyGroup.Keys); break; case (int)TrackType.XROT: bone.XROT.Keys.AddRange(keyGroup.Keys); break; case (int)TrackType.YROT: bone.YROT.Keys.AddRange(keyGroup.Keys); break; case (int)TrackType.ZROT: bone.ZROT.Keys.AddRange(keyGroup.Keys); break; case (int)TrackType.WROT: bone.WROT.Keys.AddRange(keyGroup.Keys); break; case (int)TrackType.XSCA: bone.XSCA.Keys.AddRange(keyGroup.Keys); break; case (int)TrackType.YSCA: bone.YSCA.Keys.AddRange(keyGroup.Keys); break; case (int)TrackType.ZSCA: bone.ZSCA.Keys.AddRange(keyGroup.Keys); break; default: throw new Exception("Unknown Anim Offset " + keyGroup.AnimDataOffset); } } } }
public Template(PakFile Pak, PakFile.PakTag Item, bool loadMesh) { var reader = Pak.Reader; reader.EndianType = EndianFormat.LittleEndian; reader.StreamOrigin = Item.Offset; reader.SeekTo(0); reader.ReadInt16(); //E402 reader.ReadInt32(); //filesize (EOB offset?) #region Block E502 reader.ReadInt16(); //E502 reader.ReadInt32(); //EOB offset reader.ReadInt32(); //LPTA (probs part of the string) Name = reader.ReadNullTerminatedString(); reader.ReadByte(); //00 #endregion #region Block 1603 reader.ReadInt16(); //1603 reader.ReadInt32(); //EOB offset reader.ReadBytes(3); //02 01 01 #endregion #region Block 5501 reader.ReadInt16(); //5501 reader.ReadInt32(); //address int count = reader.ReadInt32(); Materials = new List <MatRefBlock_5601>(); for (int i = 0; i < count; i++) { Materials.Add(new MatRefBlock_5601(reader)); } #endregion reader.ReadInt16(); //0100 reader.ReadInt32(); //address #region Block F000 xF000 = reader.ReadInt16(); reader.ReadInt32(); //EOB offset x2C01 = reader.ReadInt16(); reader.ReadInt32(); //EOB offset count = reader.ReadInt32(); Objects = new List <Node>(); for (int i = 0; i < count; i++) { Objects.Add(new Node(reader, loadMesh)); } foreach (var obj in Objects) { if (obj.isInheritor) { Objects[obj._2901.InheritID].isInherited = true; } } #endregion reader.ReadInt16(); //0100 reader.ReadInt32(); //address #region Block E802 reader.ReadInt16(); //E802 reader.ReadInt32(); //address count = reader.ReadInt32(); for (int i = 0; i < count; i++) { Bones.Add(new BoneBlock_E902(reader)); } #endregion //havent mapped this block, assumed anim/sound related _E602 = new unkBlock_XXXX(reader, 0xE602); reader.ReadInt16(); //0100 reader.ReadInt32(); //address if (reader.PeekUInt16() == 0xBA01) { unkStrBlk = new StringBlock_BA01(reader); } //contains data count, havent seen used _1D02 = new unkBlock_XXXX(reader, 0x1D02); //int16 count, [int16, int16] * count if (reader.PeekUInt16() == 0x1103) { _1103 = new unkBlock_XXXX(reader, 0x1103); } //contains null term string, used on IGA models _0403 = new unkBlock_XXXX(reader, 0x0403); if (reader.PeekUInt16() == 0x0503) { _0503 = new Block_0503(reader); } #region Block 0803 reader.ReadInt16(); //0803 reader.ReadInt32(); //address to end of bounds values reader.ReadInt32(); //bounds count? var min = new RealQuat(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); var max = new RealQuat(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); RenderBounds = new RealBoundingBox(); RenderBounds.XBounds = new RealBounds(min.x, max.x); RenderBounds.YBounds = new RealBounds(min.y, max.y); RenderBounds.ZBounds = new RealBounds(min.z, max.z); #endregion _0E03 = new Block_0E03(reader); //contains length prefixed string if (reader.PeekUInt16() == 0x1203) { _1203 = new unkBlock_XXXX(reader, 0x1203); } reader.ReadInt16(); //0100 reader.ReadInt32(); //address to EOF reader.StreamOrigin = 0; }