public void Merge(H3DDict <H3DLight> Lights) { foreach (H3DLight Light in Lights) { this.Lights.Add(new Light(Light)); } }
public void Merge(H3DDict <H3DLUT> LUTs) { foreach (H3DLUT LUT in LUTs) { this.LUTs.Add(LUT.Name, new LUT(LUT)); } }
public void Merge(H3DDict <H3DTexture> Textures) { foreach (H3DTexture Texture in Textures) { this.Textures.Add(Texture.Name, new Texture(Texture)); } }
public void Merge(H3DDict <H3DModel> Models) { foreach (H3DModel Model in Models) { this.Models.Add(new Model(this, Model)); } }
public static H3D MergeFromBytearray(byte[] data, Renderer Renderer, H3D Scene = null) { if (Scene == null) { //Renderer.DeleteAll(); Scene = new H3D(); } H3DDict <H3DBone> Skeleton = null; if (Scene.Models.Count > 0) { Skeleton = Scene.Models[0].Skeleton; } H3D Data = SPICA.Formats.CtrGfx.Gfx.Open(new MemoryStream(data)); if (Data != null) { Scene.Merge(Data); Renderer.Merge(Data); } return(Scene); }
private void SetAnimation(int[] Indices, H3DDict <H3DAnimation> SrcAnims, AnimationType Type) { List <H3DAnimation> Animations = new List <H3DAnimation>(Indices.Length); foreach (int i in Indices) { Animations.Add(SrcAnims[i]); } if (Type == AnimationType.Skeletal && Indices.Length == 1) { foreach (H3DAnimation SklAnim in Animations) { int MIndex = Scene.MaterialAnimations.Find(SklAnim.Name); if (MIndex != -1 && !MatAnimsList.SelectedIndices.Contains(MIndex)) { MatAnimsList.Select(MIndex); } } } AnimGrp.Frame = 0; AnimGrp.SetAnimations(Animations, Type); AnimGrp.UpdateState(); AnimSeekBar.Value = AnimGrp.Frame; AnimSeekBar.Maximum = AnimGrp.FramesCount; UpdateAnimationTransforms(); UpdateAnimLbls(); UpdateViewport(); }
public SkeletalAnimation(H3DDict <H3DBone> Skeleton) { this.Skeleton = Skeleton; FrameSkeleton = new Bone[Skeleton.Count]; Transforms = new Matrix4[Skeleton.Count]; for (int i = 0; i < Skeleton.Count; i++) { FrameSkeleton[i] = new Bone(); FrameSkeleton[i].ParentIndex = Skeleton[i].ParentIndex; if (Skeleton[i].ParentIndex != -1) { if (Skeleton[i].ParentIndex >= i) { Debug.WriteLine("[SPICA.Renderer|SkeletalAnimation] Skeleton is not properly sorted!"); } FrameSkeleton[i].Parent = FrameSkeleton[Skeleton[i].ParentIndex]; } } }
private bool GetBoneRT( H3DAnimation Anim, H3DDict <H3DBone> Skeleton, string Name, int Frame, out Vector3 Rotation, out Vector3 Translation) { if (!Skeleton.Contains(Name)) { Rotation = Vector3.Zero; Translation = Vector3.Zero; return(false); } H3DBone PoseBone = Skeleton[Name]; Rotation = PoseBone.Rotation; Translation = PoseBone.Translation; H3DAnimationElement Bone = Anim.Elements.Find(x => x.Name == Name); if (Bone != null) { H3DAnimTransform Transform = (H3DAnimTransform)Bone.Content; if (Transform.RotationX.Exists) { Rotation.X = Transform.RotationX.GetFrameValue(Frame); } if (Transform.RotationY.Exists) { Rotation.Y = Transform.RotationY.GetFrameValue(Frame); } if (Transform.RotationZ.Exists) { Rotation.Z = Transform.RotationZ.GetFrameValue(Frame); } if (Transform.TranslationX.Exists) { Translation.X = Transform.TranslationX.GetFrameValue(Frame); } if (Transform.TranslationY.Exists) { Translation.Y = Transform.TranslationY.GetFrameValue(Frame); } if (Transform.TranslationZ.Exists) { Translation.Z = Transform.TranslationZ.GetFrameValue(Frame); } } return(true); }
public void Merge(H3DDict <H3DLUT> LUTs) { foreach (H3DLUT LUT in LUTs) { if (!this.LUTs.ContainsKey(LUT.Name)) { this.LUTs.Add(LUT.Name, new LUT(LUT)); } } }
public void Merge(H3DDict <H3DTexture> Textures) { foreach (H3DTexture Texture in Textures) { if (this.Textures.ContainsKey(Texture.Name)) { this.Textures.Remove(Texture.Name); } this.Textures.Add(Texture.Name, new Texture(Texture)); } }
public MaterialAnimation(H3DDict <H3DMaterial> Materials) { this.Materials = Materials; States = new MaterialState[Materials.Count]; for (int i = 0; i < States.Length; i++) { States[i] = new MaterialState(); } }
private void SetAnimation(int Index, H3DDict <H3DAnimation> SrcAnims, AnimationType Type) { if (Index != -1) { SetAnimation(new int[] { Index }, SrcAnims, Type); } else { SetAnimation(new int[0], SrcAnims, Type); } }
public GFModel(H3DModel mdl, H3DDict <H3DLUT> H3DLUTs) : this() { Name = mdl.Name; foreach (H3DBone Bone in mdl.Skeleton) { Skeleton.Add(new GFBone(Bone, mdl.Skeleton)); } foreach (H3DMaterial Material in mdl.Materials) { H3DMesh Mesh = null; foreach (H3DMesh M in mdl.Meshes) { if (mdl.Materials[M.MaterialIndex] == Material) { Mesh = M; break; } } Materials.Add(new GFMaterial(Material, Mesh)); } Transform = mdl.WorldTransform; PokemonBBoxGen.CreateModelBBox(mdl); H3DMetaDataValue BBox = mdl.MetaData[mdl.MetaData.Find(PokemonBBoxGen.BBOX_MIN_MAX)]; List <float> BBoxMinMax = (List <float>)BBox.Values; BBoxMinVector = new Vector4(BBoxMinMax[0], BBoxMinMax[1], BBoxMinMax[2], 1); BBoxMaxVector = new Vector4(BBoxMinMax[3], BBoxMinMax[4], BBoxMinMax[5], 1); foreach (H3DLUT LUT in H3DLUTs) { if (LUT.Name.Equals(DefaultLUTName)) { foreach (H3DLUTSampler Sampler in LUT.Samplers) { LUTs.Add(new GFLUT() { Type = GetLUTType(Sampler.Name, mdl.Materials), Name = Sampler.Name, Table = Sampler.Table }); } } } foreach (H3DMesh Mesh in mdl.Meshes) { Meshes.Add(new GFMesh(Mesh, mdl)); } }
public void Merge(H3DDict <H3DShader> Shaders) { if (Shaders.Count > 0) { foreach (H3DShader Shader in Shaders) { this.Shaders.Add(Shader.Name, new VertexShader(Shader)); } UpdateAllShaders(); } }
private string GetBonePath(H3DBone bone, H3DDict <H3DBone> skeleton, string currentPath = "") { currentPath = bone.Name + currentPath; if (bone.ParentIndex < 0) { return(currentPath); } else { return(GetBonePath(skeleton[bone.ParentIndex], skeleton, "/" + currentPath)); } }
public static PICAVertex[] GetWorldSpaceVertices(H3DDict <H3DBone> Skeleton, H3DMesh Mesh) { PICAVertex[] Vertices = Mesh.GetVertices(); bool[] TransformedVertices = new bool[Vertices.Length]; //Smooth meshes are already in World Space, so we don't need to do anything. if (Mesh.Skinning != H3DMeshSkinning.Smooth) { foreach (H3DSubMesh SM in Mesh.SubMeshes) { foreach (ushort i in SM.Indices) { if (TransformedVertices[i]) { continue; } TransformedVertices[i] = true; PICAVertex v = Vertices[i]; if (Skeleton != null && Skeleton.Count > 0 && SM.Skinning != H3DSubMeshSkinning.Smooth) { int b = SM.BoneIndices[v.Indices[0]]; Matrix4x4 Transform = Skeleton[b].GetWorldTransform(Skeleton); v.Position = Vector4.Transform(new Vector3( v.Position.X, v.Position.Y, v.Position.Z), Transform); v.Normal.W = 0; v.Normal = Vector4.Transform(v.Normal, Transform); v.Normal = Vector4.Normalize(v.Normal); } Vertices[i] = v; } } } return(Vertices); }
public static H3D IdentifyAndOpen(string FileName, H3DDict <H3DBone> Skeleton = null) { H3D Output = null; using (FileStream FS = new FileStream(FileName, FileMode.Open)){ Output = IdentifyAndOpen(FS, Skeleton); } if (Output == null) { Output = FormatIdentifier.IdentifyAndOpen(FileName, Skeleton); } return(Output); }
public GFBone(H3DBone Bone, H3DDict <H3DBone> Skeleton) { Flags = (byte)(Bone.ParentIndex == -1 ? 2 : 1); Name = Bone.Name; Rotation = Bone.Rotation; Translation = Bone.Translation; Scale = Bone.Scale; if (Bone.ParentIndex != -1) { Parent = Skeleton[Bone.ParentIndex].Name; } else { Parent = "Origin"; } }
public static H3D OpenAsH3D(Stream input, GFPackage.Header header, H3DDict <H3DBone> skeleton) { var output = new H3D(); var reader = new BinaryReader(input); var index = 0; foreach (var entry in header.Entries) { input.Seek(entry.Address, SeekOrigin.Begin); if (index == 20) { break; } if (index == 0) { var motPack = new GF1MotionPack(reader); foreach (var mot in motPack) { var anim = mot.ToH3DSkeletalAnimation(skeleton); anim.Name = $"Motion_{index++}"; output.SkeletalAnimations.Add(anim); } } else { var data = reader.ReadBytes(entry.Length); if (data.Length > 4 && data[0] == 'B' && data[1] == 'C' && data[2] == 'H' && data[3] == '\0') { output.Merge(H3D.Open(data)); } } } return(output); }
public static H3D OpenAsH3D(Stream Input, GFPackage.Header Header, H3DDict <H3DBone> Skeleton) { H3D Output = new H3D(); BinaryReader Reader = new BinaryReader(Input); int Index = 0; foreach (GFPackage.Entry Entry in Header.Entries) { Input.Seek(Entry.Address, SeekOrigin.Begin); if (Index == 20) { break; } if (Index == 0) { GF1MotionPack MotPack = new GF1MotionPack(Reader); foreach (GF1Motion Mot in MotPack) { H3DAnimation Anim = Mot.ToH3DSkeletalAnimation(Skeleton); Anim.Name = $"Motion_{Index++}"; Output.SkeletalAnimations.Add(Anim); } } else { byte[] Data = Reader.ReadBytes(Entry.Length); if (Data.Length > 4 && Data[0] == 'B' && Data[1] == 'C' && Data[2] == 'H' && Data[3] == '\0') { Output.Merge(H3D.Open(Data)); } } } return(Output); }
public static H3D Merge(string[] FileNames, Renderer Renderer, H3D Scene = null) { if (Scene == null) { //Renderer.DeleteAll(); Scene = new H3D(); } int OpenFiles = 0; using (FrmLoading Form = new FrmLoading(FileNames.Length)) foreach (string FileName in FileNames) { Form.Proceed(FileName); H3DDict <H3DBone> Skeleton = null; if (Scene.Models.Count > 0) { Skeleton = Scene.Models[0].Skeleton; } H3D Data = FormatIdentifier.IdentifyAndOpen(FileName, Skeleton); if (Data != null) { Scene.Merge(Data); Renderer.Merge(Data); OpenFiles++; } } if (OpenFiles == 0) { MessageBox.Show( "Unsupported file format!", "Can't open file!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return(Scene); }
public void Merge(H3DDict <H3DShader> Shaders) { if (Shaders.Count > 0) { foreach (H3DShader Shader in Shaders) { if (!this.Shaders.ContainsKey(Shader.Name)) { VertexShader VSh = new VertexShader(Shader); this.Shaders.Add(Shader.Name, VSh); //System.IO.File.WriteAllText("D:/_REWorkspace/shader/gfl_pokemon/" + VSh.Name + ".vsh", VSh.CodeVtx); } } UpdateAllShaders(); } }
private void AddNodeGroup <T>(H3DDict <T> SubSections, BCHGroupNode Folder) where T : SPICA.Formats.Common.INamed { if (SubSections == null || SubSections.Count == 0) { return; } Nodes.Add(Folder); if (Folder.Type == BCHGroupType.Textures) { PluginRuntime.bchTexContainers.Add(Folder); } for (int i = 0; i < SubSections?.Count; i++) { var section = SubSections[i] as SPICA.Formats.Common.INamed; switch (Folder.Type) { case BCHGroupType.Models: var CMDLWrapper = new H3DModelWrapper((H3DModel)section, this); Folder.AddNode(CMDLWrapper); break; case BCHGroupType.SkeletalAnim: var CSKAWrapper = new H3DSkeletalAnimWrapper((H3DAnimation)section, this); Folder.AddNode(CSKAWrapper); break; case BCHGroupType.Textures: { var wrapper = new H3DTextureWrapper((H3DTexture)section, this); wrapper.ImageKey = "texture"; wrapper.SelectedImageKey = "texture"; Folder.AddNode(wrapper); Textures.Add(wrapper); } break; default: Folder.AddNode(new Toolbox.Library.NodeWrappers.STGenericWrapper(SubSections[i].Name)); break; } } }
private static PICAVertex[] GetWorldSpaceVertices(H3DDict <H3DBone> skeleton, H3DMesh mesh) { var vertices = mesh.GetVertices(); var transformedVertices = new bool[vertices.Length]; //Smooth meshes are already in World Space, so we don't need to do anything. if (mesh.Skinning != H3DMeshSkinning.Smooth) { foreach (var sm in mesh.SubMeshes) { foreach (var i in sm.Indices) { if (transformedVertices[i]) { continue; } transformedVertices[i] = true; var v = vertices[i]; if (skeleton != null && skeleton.Count > 0 && sm.Skinning != H3DSubMeshSkinning.Smooth) { int b = sm.BoneIndices[v.Indices[0]]; var transform = skeleton[b].GetWorldTransform(skeleton); v.Position = System.Numerics.Vector4.Transform(new System.Numerics.Vector3(v.Position.X, v.Position.Y, v.Position.Z), transform); v.Normal.W = 0; v.Normal = System.Numerics.Vector4.Transform(v.Normal, transform); v.Normal = System.Numerics.Vector4.Normalize(v.Normal); } vertices[i] = v; } } } return(vertices); }
public H3DAnimation ToH3DSkeletalAnimation(H3DDict <H3DBone> Skeleton) { List <GFBone> GFSkeleton = new List <GFBone>(); foreach (H3DBone Bone in Skeleton) { GFSkeleton.Add(new GFBone() { Name = Bone.Name, Parent = Bone.ParentIndex != -1 ? Skeleton[Bone.ParentIndex].Name : string.Empty, Flags = (byte)(Bone.ParentIndex == -1 ? 2 : 1), //TODO: Fix, 2 = Identity and 1 Normal bone? Translation = Bone.Translation, Rotation = Bone.Rotation, Scale = Bone.Scale, }); } return(ToH3DSkeletalAnimation(GFSkeleton)); }
public static List <PICAVertex> GetVerticesList(H3DDict <H3DBone> Skeleton, H3DMesh Mesh) { List <PICAVertex> Output = new List <PICAVertex>(); PICAVertex[] Vertices = Mesh.GetVertices(); foreach (H3DSubMesh SM in Mesh.SubMeshes) { foreach (ushort i in SM.Indices) { PICAVertex v = Vertices[i]; if (Skeleton != null && Skeleton.Count > 0 && SM.Skinning != H3DSubMeshSkinning.Smooth) { int b = SM.BoneIndices[v.Indices[0]]; Matrix4x4 Transform = Skeleton[b].GetWorldTransform(Skeleton); v.Position = Vector4.Transform(new Vector3( v.Position.X, v.Position.Y, v.Position.Z), Transform); v.Normal.W = 0; v.Normal = Vector4.Transform(v.Normal, Transform); v.Normal = Vector4.Normalize(v.Normal); } for (int b = 0; b < 4 && v.Weights[b] > 0; b++) { v.Indices[b] = SM.BoneIndices[v.Indices[b]]; } Output.Add(v); } } return(Output); }
public static H3D Merge(string[] FileNames, Renderer Renderer, H3D Scene = null) { int OpenFiles = 0; foreach (string FileName in FileNames) { H3DDict <H3DBone> Skeleton = null; if (Scene != null && Scene.Models.Count > 0) { Skeleton = Scene.Models[0].Skeleton; } H3D Data = FormatIdentifier.IdentifyAndOpen(FileName, Skeleton); if (Data != null) { if (Scene == null) { Scene = Data; } else { Scene.Merge(Data); } Renderer.Merge(Data); OpenFiles++; } } if (OpenFiles == 0) { MessageBox.Show( "Unsupported file format!", "Can't open file!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return(Scene); }
public static H3D OpenAsH3D(Stream input, GFPackage.Header header, H3DDict <H3DBone> skeleton) { var output = new H3D(); //Skeletal Animations input.Seek(header.Entries[0].Address, SeekOrigin.Begin); var motPack = new GF1MotionPack(input); foreach (var mot in motPack) { var sklAnim = mot.ToH3DSkeletalAnimation(skeleton); sklAnim.Name = $"Motion_{mot.Index}"; output.SkeletalAnimations.Add(sklAnim); } //Material Animations input.Seek(header.Entries[1].Address, SeekOrigin.Begin); var packHeader = GFPackage.GetPackageHeader(input); foreach (var entry in packHeader.Entries) { input.Seek(entry.Address, SeekOrigin.Begin); if (entry.Length > 0) { var data = new byte[entry.Length]; input.Read(data, 0, data.Length); var matAnims = H3D.Open(data); output.Merge(matAnims); } } return(output); }
public static H3D OpenAsH3D(Stream Input, GFPackage.Header Header, H3DDict <H3DBone> Skeleton) { H3D Output = new H3D(); //Skeletal Animations Input.Seek(Header.Entries[0].Address, SeekOrigin.Begin); GF1MotionPack MotPack = new GF1MotionPack(Input); foreach (GF1Motion Mot in MotPack) { H3DAnimation SklAnim = Mot.ToH3DSkeletalAnimation(Skeleton); SklAnim.Name = $"Motion_{Mot.Index}"; Output.SkeletalAnimations.Add(SklAnim); } //Material Animations Input.Seek(Header.Entries[1].Address, SeekOrigin.Begin); GFPackage.Header PackHeader = GFPackage.GetPackageHeader(Input); foreach (GFPackage.Entry Entry in PackHeader.Entries) { Input.Seek(Entry.Address, SeekOrigin.Begin); if (Entry.Length > 0) { byte[] Data = new byte[Entry.Length]; Input.Read(Data, 0, Data.Length); H3D MatAnims = H3D.Open(Data); Output.Merge(MatAnims); } } return(Output); }
private void SetAnimation(int[] Indices, H3DDict <H3DMaterialAnim> SrcAnims) { List <H3DAnimation> Animations = new List <H3DAnimation>(Indices.Length); foreach (int i in Indices) { Animations.Add(SrcAnims[i]); } AnimGrp.Frame = 0; AnimGrp.SetAnimations(Animations, AnimationType.Material); AnimGrp.UpdateState(); AnimSeekBar.Value = AnimGrp.Frame; AnimSeekBar.Maximum = AnimGrp.FramesCount; UpdateAnimationTransforms(); UpdateAnimLbls(); UpdateViewport(); }