示例#1
0
        public ISampleSelector MakeBlockSampleSelector(SamplerInfo samplerInfo)
        {
            var state = Dataservice.GetSamplerState(samplerInfo.StratumCode, samplerInfo.SampleGroupCode);

            var freq = samplerInfo.SamplingFrequency;

            if (freq == 0)
            {
                return(new ZeroFrequencySelecter());
            }

            if (state == null)
            {
                return(new BlockSelecter(freq, samplerInfo.InsuranceFrequency));
            }
            else
            {
                return(new BlockSelecter(freq,
                                         samplerInfo.InsuranceFrequency,
                                         state.BlockState,
                                         state.Counter,
                                         state.InsuranceIndex,
                                         state.InsuranceCounter));
            }
        }
示例#2
0
        public ISampleSelector MakeSystematicSampleSelector(SamplerInfo samplerInfo)
        {
            var state = Dataservice.GetSamplerState(samplerInfo.StratumCode, samplerInfo.SampleGroupCode);

            var freq = samplerInfo.SamplingFrequency;

            if (freq == 0)
            {
                return(new ZeroFrequencySelecter());
            }
            else
            {
                if (state != null)
                {
                    return(new SystematicSelecter(freq,
                                                  samplerInfo.InsuranceFrequency,
                                                  state.Counter,
                                                  state.InsuranceIndex,
                                                  state.InsuranceCounter,
                                                  state.SystematicIndex));
                }
                else
                {
                    return(new SystematicSelecter(freq, samplerInfo.InsuranceFrequency, true));
                }
            }
        }
示例#3
0
        public ISampleSelector MakeThreePSampleSelector(SamplerInfo samplerInfo)
        {
            if (samplerInfo is null)
            {
                throw new ArgumentNullException(nameof(samplerInfo));
            }

            var state = Dataservice.GetSamplerState(samplerInfo.StratumCode, samplerInfo.SampleGroupCode);

            if (state != null)
            {
                var selector = new ThreePSelecter(samplerInfo.KZ,
                                                  samplerInfo.InsuranceFrequency,
                                                  state.Counter,
                                                  state.InsuranceIndex,
                                                  state.InsuranceCounter);
                selector.StratumCode     = samplerInfo.StratumCode;
                selector.SampleGroupCode = samplerInfo.SampleGroupCode;
                return(selector);
            }
            else
            {
                var selector = new ThreePSelecter(samplerInfo.KZ, samplerInfo.InsuranceFrequency);
                selector.StratumCode     = samplerInfo.StratumCode;
                selector.SampleGroupCode = samplerInfo.SampleGroupCode;
                return(selector);
            }
        }
示例#4
0
        internal Sampler(GraphicsDevice graphicsDevice, SamplerInfo info)
            : base(graphicsDevice, new System.Diagnostics.StackTrace(1))
        {
            Info = info;

            if ((Info.MagFilter == TextureFilter.Anisotropic || Info.MinFilter == TextureFilter.Anisotropic) && (!graphicsDevice.OpenGLCapabilities.SupportsAnisotropicFiltering || Info.MaximumAnisotropy > graphicsDevice.OpenGLCapabilities.MaxAnisotropicFiltering))
            {
                throw new PlatformNotSupportedException("Anisotropic filtering is not supported at that level or at all.");
            }

            if (Info.MaximumAnisotropy == 0 && (Info.MagFilter == TextureFilter.Anisotropic || Info.MinFilter == TextureFilter.Anisotropic))
            {
                throw new ArgumentException("MaximumAnisotropy must not be 0");
            }

            if (Info.MipLodBias > graphicsDevice.OpenGLCapabilities.MaxTextureLoDBias)
            {
                throw new PlatformNotSupportedException("MipLoDBias is higher than max lod bias.");
            }


            SamplerID = GL.GenSampler();

            //AddressMode
            GL.SamplerParameter(SamplerID, SamplerParameterName.TextureWrapS, (float)EnumConverter.Convert(Info.AddressU));
            GL.SamplerParameter(SamplerID, SamplerParameterName.TextureWrapT, (float)EnumConverter.Convert(Info.AddressV));
            GL.SamplerParameter(SamplerID, SamplerParameterName.TextureWrapR, (float)EnumConverter.Convert(Info.AddressW));
            graphicsDevice.CheckGLError();

            //Filtering
            Tuple <TextureMinFilter, TextureMagFilter> filter = EnumConverter.Convert(Info.MinFilter, Info.MagFilter, Info.MipFilter);
            TextureMinFilter min = (TextureMinFilter)filter.Item1;
            TextureMagFilter mag = (TextureMagFilter)filter.Item2;

            GL.SamplerParameter(SamplerID, SamplerParameterName.TextureMinFilter, (float)min);
            GL.SamplerParameter(SamplerID, SamplerParameterName.TextureMagFilter, (float)mag);
            GL.SamplerParameter(SamplerID, SamplerParameterName.TextureMaxAnisotropyExt, Info.MaximumAnisotropy);

            //Border color
            GL.SamplerParameter(SamplerID, SamplerParameterName.TextureBorderColor, new float[] { Info.BorderColor.R, Info.BorderColor.G, Info.BorderColor.B, Info.BorderColor.A });

            //Compare modes
            if (Info.Type == SamplerType.Comparison)
            {
                GL.SamplerParameter(SamplerID, SamplerParameterName.TextureCompareMode, (float)TextureCompareMode.CompareRefToTexture);
                GL.SamplerParameter(SamplerID, SamplerParameterName.TextureCompareFunc, (float)EnumConverter.Convert(Info.ComparisonFunction));
            }
            else
            {
                GL.SamplerParameter(SamplerID, SamplerParameterName.TextureCompareMode, (float)TextureCompareMode.None);
            }

            //LoD
            GL.SamplerParameter(SamplerID, SamplerParameterName.TextureMinLod, Info.MinimumLod);
            GL.SamplerParameter(SamplerID, SamplerParameterName.TextureMaxLod, Info.MaximumLod);
            GL.SamplerParameter(SamplerID, SamplerParameterName.TextureLodBias, Info.MipLodBias);


            graphicsDevice.CheckGLError();
        }
示例#5
0
        public ISampleSelector MakeSampleSelecter(SamplerInfo samplerInfo)
        {
            if (samplerInfo == null)
            {
                throw new ArgumentNullException("samplerInfo");
            }
            var method = samplerInfo.Method;

            if (samplerInfo.UseExternalSampler)
            {
                return(new ExternalSampleSelectorPlaceholder()
                {
                    Frequency = samplerInfo.SamplingFrequency,
                    SampleGroupCode = samplerInfo.SampleGroupCode,
                    StratumCode = samplerInfo.StratumCode,
                });
            }

            switch (method)
            {
            case "100":
            case "FIX":
            case "PNT":
            case "FIXCNT":
            {
                return(new HundredPCTSelector());
            }

            case "STR":
            {
                return(MakeBlockSampleSelector(samplerInfo));
            }

            case "S3P":
            {
                return(MakeS3PSampleSelector(samplerInfo));
            }

            case "3P":
            case "P3P":
            case "F3P":
            {
                return(MakeThreePSampleSelector(samplerInfo));
            }

            case "FCM":
            case "PCM":
            {
                return(MakeSystematicSampleSelector(samplerInfo));
            }

            default:
            {
                return(null);
            }
            }
        }
示例#6
0
            protected override void ReadBinaryData(FileReader reader, Header header)
            {
                ReadName(reader);
                reader.Seek(0x10); // 0-padding

                // color arrays with key counts
                Color0Array      = new STColorArray(reader.ReadUInt32());
                Color0AlphaArray = new STColorArray(reader.ReadUInt32(), true);
                Color1Array      = new STColorArray(reader.ReadUInt32());
                Color1AlphaArray = new STColorArray(reader.ReadUInt32(), true);
                ScaleArray       = new STColorArray(reader.ReadUInt32());
                UnknownCount     = reader.ReadUInt32();
                reader.Seek(0x38); // 0-padding

                Unknown0 = reader.ReadBytes(0x30);


                BlinkIntensity0 = reader.ReadSingle();
                BlinkIntensity1 = reader.ReadSingle();
                BlinkDuration0  = reader.ReadSingle();
                BlinkDuration1  = reader.ReadSingle();

                Unknown1 = reader.ReadBytes(0x2c0);

                Radius = reader.ReadSingle();
                reader.Seek(0x0c); // 0-padding

                // random and animated color table
                Color0Array.ReadColorData(reader);
                Color0AlphaArray.ReadColorData(reader);
                Color1Array.ReadColorData(reader);
                Color1AlphaArray.ReadColorData(reader);
                Unknown2 = reader.ReadBytes(0x40);
                ScaleArray.ReadColorData(reader);

                Unknown3 = reader.ReadBytes(0x328);

                // constant colors
                ConstantColor0 = new STColor(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                ConstantColor1 = new STColor(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());

                Unknown4 = reader.ReadBytes(0x30);

                // samplers
                for (int i = 0; i < 3; ++i)
                {
                    SamplerInfo samplerInfo = new SamplerInfo();
                    samplerInfo.ReadSamplerData(reader);
                    Samplers.Add(samplerInfo);
                }

                Unknown5 = reader.ReadBytes(0x30);
            }
        public void GetSamplerBySampleGroupCode_STR_MockedDS(string method)
        {
            var stCode     = "00";
            var sgCode     = "01";
            var freq       = 5;
            var iFreq      = 2;
            var blockState = new String(BlockSelecter.GenerateBlock(freq).Select(x => x ? '-' : 'x').ToArray());

            var sInfo = new SamplerInfo()
            {
                SamplingFrequency  = freq,
                InsuranceFrequency = iFreq,
                SampleGroupCode    = sgCode,
                StratumCode        = stCode,
                Method             = method,
            };

            var sState = new SamplerState()
            {
                SampleGroupCode    = sgCode,
                StratumCode        = stCode,
                SampleSelectorType = nameof(BlockSelecter),
                BlockState         = blockState,
            };

            var mockSids = new Mock <ISamplerInfoDataservice>();

            mockSids.Setup(x => x.GetSamplerInfo(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(sInfo);
            mockSids.Setup(x => x.GetSamplerState(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(sState);

            var ssRepo = new SampleSelectorRepository(mockSids.Object);

            var sampler = ssRepo.GetSamplerBySampleGroupCode(stCode, sgCode);

            sampler.Should().NotBeNull();

            sampler.StratumCode.Should().Be(stCode);
            sampler.SampleGroupCode.Should().Be(sgCode);

            sampler.Should().BeAssignableTo <IFrequencyBasedSelecter>();

            var freqSampler = sampler as IFrequencyBasedSelecter;

            freqSampler.Frequency.Should().Be(freq);
            freqSampler.Sample().Should().NotBeNull();

            var samplerAgain = ssRepo.GetSamplerBySampleGroupCode(stCode, sgCode);

            samplerAgain.Should().BeSameAs(sampler);
        }
示例#8
0
        public ISampleSelector MakeS3PSampleSelector(SamplerInfo samplerState)
        {
            var state = Dataservice.GetSamplerState(samplerState.StratumCode, samplerState.SampleGroupCode);

            if (state != null)
            {
                return(new S3PSelector(samplerState.SamplingFrequency, samplerState.KZ, state.Counter, state.BlockState));
            }
            else
            {
                return(new S3PSelector(samplerState.SamplingFrequency, samplerState.KZ));
            }
        }
        public void GetSamplerBySampleGroupCode_3P_MockedDS(string method)
        {
            var stCode = "00";
            var sgCode = "01";
            var kz     = 101;
            var kpi    = 50;
            var iFreq  = 2;

            var sInfo = new SamplerInfo()
            {
                KZ = kz,
                InsuranceFrequency = iFreq,
                SampleGroupCode    = sgCode,
                StratumCode        = stCode,
                Method             = method,
            };

            var sState = new SamplerState()
            {
                SampleGroupCode = sgCode,
                StratumCode     = stCode,
            };

            var mockSids = new Mock <ISamplerInfoDataservice>();

            mockSids.Setup(x => x.GetSamplerInfo(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(sInfo);
            mockSids.Setup(x => x.GetSamplerState(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(sState);

            var ssRepo = new SampleSelectorRepository(mockSids.Object);

            var sampler = ssRepo.GetSamplerBySampleGroupCode(stCode, sgCode);

            sampler.Should().NotBeNull();

            sampler.StratumCode.Should().Be(stCode);
            sampler.SampleGroupCode.Should().Be(sgCode);

            sampler.Should().BeAssignableTo <IThreePSelector>();

            var threePSampler = sampler as IThreePSelector;

            threePSampler.Sample(kpi).Should().NotBeNull();

            var samplerAgain = ssRepo.GetSamplerBySampleGroupCode(stCode, sgCode);

            samplerAgain.Should().BeSameAs(sampler);
        }
示例#10
0
        public ISampleSelector MakeThreePSampleSelector(SamplerInfo samplerInfo)
        {
            var state = Dataservice.GetSamplerState(samplerInfo.StratumCode, samplerInfo.SampleGroupCode);

            if (state != null)
            {
                return(new ThreePSelecter(samplerInfo.KZ,
                                          samplerInfo.InsuranceFrequency,
                                          state.Counter,
                                          state.InsuranceIndex,
                                          state.InsuranceCounter));
            }
            else
            {
                return(new ThreePSelecter(samplerInfo.KZ, samplerInfo.InsuranceFrequency));
            }
        }
示例#11
0
        public ISampleSelector MakeBlockSampleSelector(SamplerInfo samplerInfo)
        {
            if (samplerInfo is null)
            {
                throw new ArgumentNullException(nameof(samplerInfo));
            }

            var state = Dataservice.GetSamplerState(samplerInfo.StratumCode, samplerInfo.SampleGroupCode);

            var freq = samplerInfo.SamplingFrequency;

            if (freq == 0)
            {
                // frequency shouldn't be 0,
                // but I don't want it to break the program if it is, so for now lets just track it
                Analytics.TrackEvent("ZeroFrequencySelecter Created", new Dictionary <string, string> {
                    { "Method", "MakeBlockSampleSelector" },
                });
                return(new ZeroFrequencySelecter(samplerInfo.StratumCode, samplerInfo.SampleGroupCode));
            }

            // we need to gruard against a empty block state
            // if a block selector is initialized with a frequency of 0
            // then the block state will be empty
            if (state != null && string.IsNullOrWhiteSpace(state.BlockState) == false)
            {
                var selector = new BlockSelecter(freq,
                                                 samplerInfo.InsuranceFrequency,
                                                 state.BlockState,
                                                 state.Counter,
                                                 state.InsuranceIndex,
                                                 state.InsuranceCounter);
                selector.StratumCode     = samplerInfo.StratumCode;
                selector.SampleGroupCode = samplerInfo.SampleGroupCode;
                return(selector);
            }
            else
            {
                var selector = new BlockSelecter(freq, samplerInfo.InsuranceFrequency);
                selector.StratumCode     = samplerInfo.StratumCode;
                selector.SampleGroupCode = samplerInfo.SampleGroupCode;
                return(selector);
            }
        }
示例#12
0
        public ISampleSelector MakeSystematicSampleSelector(SamplerInfo samplerInfo)
        {
            if (samplerInfo is null)
            {
                throw new ArgumentNullException(nameof(samplerInfo));
            }

            var state = Dataservice.GetSamplerState(samplerInfo.StratumCode, samplerInfo.SampleGroupCode);

            var freq = samplerInfo.SamplingFrequency;

            if (freq == 0)
            {
                // frequency shouldn't be 0,
                // but I don't want it to break the program if it is, so for now lets just track it
                Analytics.TrackEvent("ZeroFrequencySelecter Created", new Dictionary <string, string> {
                    { "Method", "MakeSystematicSampleSelector" },
                });
                return(new ZeroFrequencySelecter(samplerInfo.StratumCode, samplerInfo.SampleGroupCode));
            }
            else
            {
                if (state != null)
                {
                    var selecter = new SystematicSelecter(freq,
                                                          samplerInfo.InsuranceFrequency,
                                                          state.Counter,
                                                          state.InsuranceIndex,
                                                          state.InsuranceCounter,
                                                          state.SystematicIndex);
                    selecter.StratumCode     = samplerInfo.StratumCode;
                    selecter.SampleGroupCode = samplerInfo.SampleGroupCode;
                    return(selecter);
                }
                else
                {
                    var selecter = new SystematicSelecter(freq, samplerInfo.InsuranceFrequency, true);
                    selecter.StratumCode     = samplerInfo.StratumCode;
                    selecter.SampleGroupCode = samplerInfo.SampleGroupCode;
                    return(selecter);
                }
            }
        }
示例#13
0
文件: Sampler.cs 项目: K0bin/DotGame
        public Sampler(GraphicsDevice graphicsDevice, SamplerInfo info)
            : base(graphicsDevice, new StackTrace(1))
        {
            this.Info = info;

            Handle = new SamplerState(graphicsDevice.Device, new SamplerStateDescription()
            {
                Filter             = EnumConverter.Convert(info.Type, info.MinFilter, info.MagFilter, info.MipFilter),
                AddressU           = EnumConverter.Convert(info.AddressU),
                AddressV           = EnumConverter.Convert(info.AddressV),
                AddressW           = EnumConverter.Convert(info.AddressW),
                BorderColor        = SharpDX.Color.FromRgba(info.BorderColor.ToRgba()),
                ComparisonFunction = EnumConverter.Convert(info.ComparisonFunction),
                MaximumAnisotropy  = info.MaximumAnisotropy,
                MinimumLod         = info.MinimumLod,
                MaximumLod         = info.MaximumLod,
                MipLodBias         = info.MipLodBias
            });
        }
示例#14
0
        public ISampleSelector MakeS3PSampleSelector(SamplerInfo samplerState)
        {
            if (samplerState is null)
            {
                throw new ArgumentNullException(nameof(samplerState));
            }

            var state = Dataservice.GetSamplerState(samplerState.StratumCode, samplerState.SampleGroupCode);

            if (state != null)
            {
                var selector = new S3PSelector(samplerState.SamplingFrequency, samplerState.KZ, state.Counter, state.BlockState);
                selector.StratumCode     = samplerState.StratumCode;
                selector.SampleGroupCode = samplerState.SampleGroupCode;
                return(selector);
            }
            else
            {
                var selector = new S3PSelector(samplerState.SamplingFrequency, samplerState.KZ);
                selector.StratumCode     = samplerState.StratumCode;
                selector.SampleGroupCode = samplerState.SampleGroupCode;
                return(selector);
            }
        }
示例#15
0
        public void Read(ResFile TargetSwitchBFRES, FileData f)
        {
            Nodes.Add(TModels);
            Nodes.Add(TMaterialAnim);
            Nodes.Add(TVisualAnim);
            Nodes.Add(TShapeAnim);
            Nodes.Add(TSceneAnim);
            Nodes.Add(TEmbedded);
            ImageKey         = "bfres";
            SelectedImageKey = "bfres";

            AnimationCountTotal = TargetSwitchBFRES.SkeletalAnims.Count
                                  + TargetSwitchBFRES.BoneVisibilityAnims.Count
                                  + TargetSwitchBFRES.MaterialAnims.Count
                                  + TargetSwitchBFRES.ShapeAnims.Count;

            FSKACount = TargetSwitchBFRES.SkeletalAnims.Count;
            FVISCount = TargetSwitchBFRES.BoneVisibilityAnims.Count;
            FMAACount = TargetSwitchBFRES.MaterialAnims.Count;
            FSHACount = TargetSwitchBFRES.ShapeAnims.Count;

            Console.WriteLine("Name = " + TargetSwitchBFRES.Name);

            int ModelCur = 0;

            //FMDLs -Models-
            foreach (Model mdl in TargetSwitchBFRES.Models)
            {
                FMDL_Model model = new FMDL_Model(); //This will store VBN data and stuff
                model.Text = mdl.Name;

                TModels.Nodes.Add(model);

                ReadSkeleton(model, mdl);

                model.skeleton.reset();
                model.skeleton.update();

                foreach (int node in model.Node_Array)
                {
                    Console.WriteLine(model.skeleton.bones[node].Text);
                }

                //MeshTime!!
                foreach (Shape shp in mdl.Shapes)
                {
                    Mesh poly = new Mesh();
                    poly.Text            = shp.Name;
                    poly.MaterialIndex   = shp.MaterialIndex;
                    poly.VertexSkinCount = shp.VertexSkinCount;
                    poly.boneIndx        = shp.BoneIndex;
                    poly.fmdlIndx        = ModelCur;

                    foreach (int bn in shp.SkinBoneIndices)
                    {
                        poly.BoneIndexList.Add(model.skeleton.bones[bn].Text, bn);
                    }

                    TModels.Nodes[ModelCur].Nodes.Add(poly);


                    ReadVertexBuffer(mdl, shp, poly, model);

                    poly.BoundingCount = shp.SubMeshBoundings.Count;

                    int CurLOD = 0;
                    foreach (var lod in shp.Meshes)
                    {
                        Mesh.LOD_Mesh lodmsh = new Mesh.LOD_Mesh();
                        lodmsh.index = CurLOD++;

                        uint   FaceCount    = lod.IndexCount;
                        uint[] indicesArray = lod.GetIndices().ToArray();


                        for (int face = 0; face < FaceCount; face++)
                        {
                            lodmsh.faces.Add((int)indicesArray[face] + (int)lod.FirstVertex);
                        }

                        poly.lodMeshes.Add(lodmsh);
                    }

                    foreach (Bounding bnd in shp.SubMeshBoundings)
                    {
                        Mesh.BoundingBox box = new Mesh.BoundingBox();
                        box.Center = new Vector3(bnd.Center.X, bnd.Center.Y, bnd.Center.Z);
                        box.Extent = new Vector3(bnd.Extent.X, bnd.Extent.Y, bnd.Extent.Z);

                        poly.boundingBoxes.Add(box); //Each box is by LOD mesh. This will be in a seperate class later so only one will be added
                    }
                    foreach (float r in shp.RadiusArray)
                    {
                        poly.radius.Add(r);
                    }

                    // Read materials
                    Material mat = mdl.Materials[shp.MaterialIndex];

                    poly.material.Name = mat.Name;

                    int SampIndex = 0;
                    foreach (var smp in mat.SamplerDict)
                    {
                        poly.material.Samplers.Add(smp.Key, SampIndex);
                        SampIndex++;
                    }

                    MaterialData.ShaderAssign shaderassign = new MaterialData.ShaderAssign();

                    if (mat.ShaderAssign != null)
                    {
                        shaderassign.ShaderModel   = mat.ShaderAssign.ShadingModelName;
                        shaderassign.ShaderArchive = mat.ShaderAssign.ShaderArchiveName;

                        int o = 0;
                        foreach (var op in mat.ShaderAssign.ShaderOptionDict)
                        {
                            shaderassign.options.Add(op.Key, mat.ShaderAssign.ShaderOptions[o]);
                            o++;
                        }
                        int sa = 0;
                        foreach (var smp in mat.ShaderAssign.SamplerAssignDict)
                        {
                            //       Console.WriteLine($"{smp.Key} ---> {mat.ShaderAssign.SamplerAssigns[sa]}");
                            if (!shaderassign.samplers.ContainsKey(mat.ShaderAssign.SamplerAssigns[sa]))
                            {
                                shaderassign.samplers.Add(mat.ShaderAssign.SamplerAssigns[sa], smp.Key);
                            }
                            sa++;
                        }

                        int va = 0;
                        foreach (var att in mat.ShaderAssign.AttribAssignDict)
                        {
                            shaderassign.attributes.Add(att.Key, mat.ShaderAssign.AttribAssigns[va]);
                            va++;
                        }
                    }
                    else
                    {
                        shaderassign.ShaderModel   = "Not Assigned";
                        shaderassign.ShaderArchive = "Not Assigned";
                    }
                    poly.material.shaderassign = shaderassign;

                    ReadTextureRefs(mat, poly);
                    if (mat.ShaderParamData != null)
                    {
                        ReadShaderParams(mat, poly);
                    }
                    if (mat.RenderInfos != null)
                    {
                        ReadRenderInfo(mat, poly);
                    }

                    foreach (Sampler smp in mdl.Materials[shp.MaterialIndex].Samplers)
                    {
                        SamplerInfo s = new SamplerInfo();
                        s.WrapModeU = (int)smp.WrapModeU;
                        s.WrapModeV = (int)smp.WrapModeV;
                        s.WrapModeW = (int)smp.WrapModeW;
                        poly.material.samplerinfo.Add(s);
                    }

                    model.poly.Add(poly);
                }
                models.Add(model);
                ModelCur++;
            }
        }
示例#16
0
 public ISampler CreateSampler(SamplerInfo info)
 {
     return(new Sampler(graphicsDevice, info));
 }
示例#17
0
 internal extern static unsafe ErrorCode GetSamplerInfo(IntPtr sampler, SamplerInfo param_name, IntPtr param_value_size, IntPtr param_value, [Out] IntPtr *param_value_size_ret);
示例#18
0
        public void Read(ResFile TargetWiiUBFRES)
        {
            Nodes.Add(TModels);
            Nodes.Add(TTextures);
            Nodes.Add(TShaderparam);
            Nodes.Add(TColoranim);
            Nodes.Add(TTextureSRT);
            Nodes.Add(TTexturePat);
            Nodes.Add(TBonevisabilty);
            Nodes.Add(TVisualAnim);
            Nodes.Add(TShapeAnim);
            Nodes.Add(TSceneAnim);
            Nodes.Add(TEmbedded);
            ImageKey         = "bfres";
            SelectedImageKey = "bfres";

            FSKACount = TargetWiiUBFRES.SkeletalAnims.Count;
            FTXPCount = TargetWiiUBFRES.TexPatternAnims.Count;
            FSHUCount = TargetWiiUBFRES.ColorAnims.Count + TargetWiiUBFRES.TexSrtAnims.Count + TargetWiiUBFRES.ShaderParamAnims.Count;

            AnimationCountTotal = FSKACount + FTXPCount + FSHUCount;

            FTEXContainer = new FTEXContainer();
            foreach (Texture tex in TargetWiiUBFRES.Textures.Values)
            {
                string TextureName = tex.Name;
                FTEX   texture     = new FTEX();
                texture.ReadFTEX(tex);

                TTextures.Nodes.Add(texture);

                FTEXContainer.FTEXtextures.Add(texture.Text, texture);
                Runtime.FTEXContainerList.Add(FTEXContainer);
            }

            int ModelCur = 0;

            //FMDLs -Models-
            foreach (Model mdl in TargetWiiUBFRES.Models.Values)
            {
                FMDL_Model model = new FMDL_Model(); //This will store VBN data and stuff
                model.Text = mdl.Name;

                TModels.Nodes.Add(model);

                model.Node_Array = new int[mdl.Skeleton.MatrixToBoneList.Count];
                int nodes = 0;
                foreach (ushort node in mdl.Skeleton.MatrixToBoneList)
                {
                    model.Node_Array[nodes] = node;
                    nodes++;
                }

                foreach (Syroot.NintenTools.Bfres.Bone bn in mdl.Skeleton.Bones.Values)
                {
                    Bone bone = new Bone(model.skeleton);
                    bone.Text        = bn.Name;
                    bone.boneId      = bn.BillboardIndex;
                    bone.parentIndex = bn.ParentIndex;
                    bone.scale       = new float[3];
                    bone.rotation    = new float[4];
                    bone.position    = new float[3];

                    if (bn.FlagsRotation == BoneFlagsRotation.Quaternion)
                    {
                        bone.boneRotationType = 1;
                    }
                    else
                    {
                        bone.boneRotationType = 0;
                    }

                    bone.scale[0]    = bn.Scale.X;
                    bone.scale[1]    = bn.Scale.Y;
                    bone.scale[2]    = bn.Scale.Z;
                    bone.rotation[0] = bn.Rotation.X;
                    bone.rotation[1] = bn.Rotation.Y;
                    bone.rotation[2] = bn.Rotation.Z;
                    bone.rotation[3] = bn.Rotation.W;
                    bone.position[0] = bn.Position.X;
                    bone.position[1] = bn.Position.Y;
                    bone.position[2] = bn.Position.Z;

                    model.skeleton.bones.Add(bone);
                }
                model.skeleton.reset();
                model.skeleton.update();

                //MeshTime!!
                int ShapeCur = 0;
                foreach (Shape shp in mdl.Shapes.Values)
                {
                    Mesh poly = new Mesh();
                    poly.Text            = shp.Name;
                    poly.MaterialIndex   = shp.MaterialIndex;
                    poly.VertexSkinCount = shp.VertexSkinCount;
                    poly.boneIndx        = shp.BoneIndex;
                    poly.fmdlIndx        = ModelCur;

                    foreach (int bn in shp.SkinBoneIndices)
                    {
                        if (!poly.BoneIndexList.ContainsKey(model.skeleton.bones[bn].Text))
                        {
                            poly.BoneIndexList.Add(model.skeleton.bones[bn].Text, bn);
                        }
                    }

                    TModels.Nodes[ModelCur].Nodes.Add(poly);

                    //Create a buffer instance which stores all the buffer data
                    VertexBufferHelper helper = new VertexBufferHelper(mdl.VertexBuffers[shp.VertexBufferIndex], TargetWiiUBFRES.ByteOrder);

                    //Set each array first from the lib if exist. Then add the data all in one loop
                    Syroot.Maths.Vector4F[] vec4Positions = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4Normals   = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4uv0       = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4uv1       = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4uv2       = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4c0        = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4t0        = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4b0        = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4w0        = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4i0        = new Syroot.Maths.Vector4F[0];


                    foreach (VertexAttrib att in mdl.VertexBuffers[shp.VertexBufferIndex].Attributes.Values)
                    {
                        Mesh.VertexAttribute attr = new Mesh.VertexAttribute();
                        attr.Name = att.Name;
                        // attr.Format = att.Format;

                        if (att.Name == "_p0")
                        {
                            vec4Positions = WiiUAttributeData(att, helper, "_p0");
                        }
                        if (att.Name == "_n0")
                        {
                            vec4Normals = WiiUAttributeData(att, helper, "_n0");
                        }
                        if (att.Name == "_u0")
                        {
                            vec4uv0 = WiiUAttributeData(att, helper, "_u0");
                        }
                        if (att.Name == "_u1")
                        {
                            vec4uv1 = WiiUAttributeData(att, helper, "_u1");
                        }
                        if (att.Name == "_u2")
                        {
                            vec4uv2 = WiiUAttributeData(att, helper, "_u2");
                        }
                        if (att.Name == "_c0")
                        {
                            vec4c0 = WiiUAttributeData(att, helper, "_c0");
                        }
                        if (att.Name == "_t0")
                        {
                            vec4t0 = WiiUAttributeData(att, helper, "_t0");
                        }
                        if (att.Name == "_b0")
                        {
                            vec4b0 = WiiUAttributeData(att, helper, "_b0");
                        }
                        if (att.Name == "_w0")
                        {
                            vec4w0 = WiiUAttributeData(att, helper, "_w0");
                        }
                        if (att.Name == "_i0")
                        {
                            vec4i0 = WiiUAttributeData(att, helper, "_i0");
                        }

                        poly.vertexAttributes.Add(attr);
                    }
                    for (int i = 0; i < vec4Positions.Length; i++)
                    {
                        Vertex v = new Vertex();
                        if (vec4Positions.Length > 0)
                        {
                            v.pos = new Vector3(vec4Positions[i].X, vec4Positions[i].Y, vec4Positions[i].Z);
                        }
                        if (vec4Normals.Length > 0)
                        {
                            v.nrm = new Vector3(vec4Normals[i].X, vec4Normals[i].Y, vec4Normals[i].Z);
                        }
                        if (vec4uv0.Length > 0)
                        {
                            v.uv0 = new Vector2(vec4uv0[i].X, vec4uv0[i].Y);
                        }
                        if (vec4uv1.Length > 0)
                        {
                            v.uv1 = new Vector2(vec4uv1[i].X, vec4uv1[i].Y);
                        }
                        if (vec4uv2.Length > 0)
                        {
                            v.uv2 = new Vector2(vec4uv2[i].X, vec4uv2[i].Y);
                        }
                        if (vec4w0.Length > 0)
                        {
                            v.boneWeights.Add(vec4w0[i].X);
                            v.boneWeights.Add(vec4w0[i].Y);
                            v.boneWeights.Add(vec4w0[i].Z);
                            v.boneWeights.Add(vec4w0[i].W);
                        }
                        if (vec4i0.Length > 0)
                        {
                            v.boneIds.Add((int)vec4i0[i].X);
                            v.boneIds.Add((int)vec4i0[i].Y);
                            v.boneIds.Add((int)vec4i0[i].Z);
                            v.boneIds.Add((int)vec4i0[i].W);
                        }
                        if (vec4t0.Length > 0)
                        {
                            v.tan = new Vector4(vec4t0[i].X, vec4t0[i].Y, vec4t0[i].Z, vec4t0[i].W);
                        }
                        if (vec4b0.Length > 0)
                        {
                            v.bitan = new Vector4(vec4b0[i].X, vec4b0[i].Y, vec4b0[i].Z, vec4b0[i].W);
                        }
                        if (vec4c0.Length > 0)
                        {
                            v.col = new Vector4(vec4c0[i].X, vec4c0[i].Y, vec4c0[i].Z, vec4c0[i].W);
                        }

                        if (poly.VertexSkinCount == 1)
                        {
                            Matrix4 sb = model.skeleton.bones[model.Node_Array[v.boneIds[0]]].transform;
                            //  Console.WriteLine(model.skeleton.bones[model.Node_Array[v.boneIds[0]]].Text);
                            v.pos = Vector3.TransformPosition(v.pos, sb);
                            v.nrm = Vector3.TransformNormal(v.nrm, sb);
                        }
                        if (poly.VertexSkinCount == 0)
                        {
                            Matrix4 NoBindFix = model.skeleton.bones[poly.boneIndx].transform;
                            v.pos = Vector3.TransformPosition(v.pos, NoBindFix);
                            v.nrm = Vector3.TransformNormal(v.nrm, NoBindFix);
                        }

                        poly.vertices.Add(v);
                    }

                    //shp.Meshes.Count - 1 //For going to the lowest poly LOD mesh


                    poly.BoundingCount = shp.SubMeshBoundings.Count;

                    int CurLOD = 0;
                    foreach (var lod in shp.Meshes)
                    {
                        Mesh.LOD_Mesh lodmsh = new Mesh.LOD_Mesh();
                        lodmsh.index = CurLOD++;

                        uint   FaceCount    = lod.IndexCount;
                        uint[] indicesArray = lod.GetIndices().ToArray();

                        for (int face = 0; face < FaceCount; face++)
                        {
                            lodmsh.faces.Add((int)indicesArray[face] + (int)lod.FirstVertex);
                        }

                        poly.lodMeshes.Add(lodmsh);
                    }

                    foreach (Bounding bnd in shp.SubMeshBoundings)
                    {
                        Mesh.BoundingBox box = new Mesh.BoundingBox();
                        box.Center = new Vector3(bnd.Center.X, bnd.Center.Y, bnd.Center.Z);
                        box.Extent = new Vector3(bnd.Extent.X, bnd.Extent.Y, bnd.Extent.Z);

                        poly.boundingBoxes.Add(box); //Each box is by LOD mesh. This will be in a seperate class later so only one will be added
                    }
                    foreach (float r in shp.RadiusArray)
                    {
                        poly.radius.Add(r);
                    }

                    // Read materials
                    Material mat = mdl.Materials[shp.MaterialIndex];

                    int SampIndex = 0;
                    foreach (var smp in mat.Samplers)
                    {
                        poly.material.Samplers.Add(smp.Key, SampIndex);
                        SampIndex++;
                    }

                    int AlbedoCount = 0;

                    string TextureName = "";

                    MaterialData.ShaderAssign shaderassign = new MaterialData.ShaderAssign();

                    if (mat.ShaderAssign != null) //Some special cases (env models) have none
                    {
                        shaderassign.ShaderModel   = mat.ShaderAssign.ShadingModelName;
                        shaderassign.ShaderArchive = mat.ShaderAssign.ShaderArchiveName;


                        int o = 0;
                        foreach (var op in mat.ShaderAssign.ShaderOptions)
                        {
                            shaderassign.options.Add(op.Key, mat.ShaderAssign.ShaderOptions[o]);
                            o++;
                        }

                        int sa = 0;
                        foreach (var smp in mat.ShaderAssign.SamplerAssigns)
                        {
                            shaderassign.samplers.Add(smp.Key, mat.ShaderAssign.SamplerAssigns[sa]);
                            sa++;
                        }

                        int va = 0;
                        foreach (var att in mat.ShaderAssign.AttribAssigns)
                        {
                            shaderassign.attributes.Add(att.Key, mat.ShaderAssign.AttribAssigns[va]);
                            va++;
                        }
                    }

                    poly.material.shaderassign = shaderassign;

                    int id = 0;
                    foreach (TextureRef tex in mdl.Materials[shp.MaterialIndex].TextureRefs)
                    {
                        TextureName = tex.Name;

                        MatTexture texture = new MatTexture();

                        texture.wrapModeS = (int)mdl.Materials[shp.MaterialIndex].Samplers[id].TexSampler.ClampX;
                        texture.wrapModeT = (int)mdl.Materials[shp.MaterialIndex].Samplers[id].TexSampler.ClampY;


                        bool IsAlbedo = HackyTextureList.Any(TextureName.Contains);

                        if (mdl.Materials[shp.MaterialIndex].Samplers[id].Name == "_a0")
                        {
                            poly.material.HasDiffuseMap = true;
                            texture.hash = 0;
                            texture.Type = MatTexture.TextureType.Diffuse;
                        }
                        if (mdl.Materials[shp.MaterialIndex].Samplers[id].Name == "_a1")
                        {
                            poly.material.HasDiffuseLayer = true;
                            texture.hash = 19;
                            texture.Type = MatTexture.TextureType.DiffuseLayer2;
                        }
                        if (mdl.Materials[shp.MaterialIndex].Samplers[id].Name == "_n0")
                        {
                            texture.hash = 1;
                            poly.material.HasNormalMap = true;
                            texture.Type = MatTexture.TextureType.Normal;
                        }
                        if (mdl.Materials[shp.MaterialIndex].Samplers[id].Name == "_s0")
                        {
                            texture.hash = 4;
                            poly.material.HasSpecularMap = true;
                            texture.Type = MatTexture.TextureType.Specular;
                        }
                        if (mdl.Materials[shp.MaterialIndex].Samplers[id].Name == "_b0")
                        {
                            texture.hash = 2;
                            poly.material.HasShadowMap = true;
                            texture.Type = MatTexture.TextureType.Shadow;
                        }
                        if (mdl.Materials[shp.MaterialIndex].Samplers[id].Name == "_b1")
                        {
                            texture.hash = 3;
                            poly.material.HasLightMap = true;
                            texture.Type = MatTexture.TextureType.Light;
                        }
                        if (mdl.Materials[shp.MaterialIndex].Samplers[id].Name == "_e0")
                        {
                            texture.hash = 8;
                            poly.material.HasEmissionMap = true;
                            texture.Type = MatTexture.TextureType.Emission;
                        }

                        texture.Name = TextureName;
                        poly.material.textures.Add(texture);
                        id++;
                    }

                    foreach (Sampler smp in mat.Samplers.Values)
                    {
                        SamplerInfo s = new SamplerInfo();
                        s.WrapModeU = (int)smp.TexSampler.ClampX;
                        s.WrapModeV = (int)smp.TexSampler.ClampY;
                        s.WrapModeW = (int)smp.TexSampler.ClampZ;
                        poly.material.samplerinfo.Add(s);
                    }

                    poly.material.Name = mdl.Materials[shp.MaterialIndex].Name;
                    if (mdl.Materials[shp.MaterialIndex].ShaderParamData != null) //Some special cases (env models) have none
                    {
                        using (Syroot.BinaryData.BinaryDataReader reader = new Syroot.BinaryData.BinaryDataReader(new MemoryStream(mdl.Materials[shp.MaterialIndex].ShaderParamData)))
                        {
                            reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
                            foreach (Syroot.NintenTools.Bfres.ShaderParam param in mdl.Materials[shp.MaterialIndex].ShaderParams.Values)
                            {
                                ShaderParam prm = new ShaderParam();

                                prm.Type = param.Type;
                                prm.Name = param.Name;

                                switch (param.Type)
                                {
                                case ShaderParamType.Float:
                                    reader.Seek(param.DataOffset, SeekOrigin.Begin);
                                    prm.Value_float = reader.ReadSingle();
                                    break;

                                case ShaderParamType.Float2:
                                    reader.Seek(param.DataOffset, SeekOrigin.Begin);
                                    prm.Value_float2 = new Vector2(
                                        reader.ReadSingle(),
                                        reader.ReadSingle());
                                    break;

                                case ShaderParamType.Float3:
                                    reader.Seek(param.DataOffset, SeekOrigin.Begin);
                                    prm.Value_float3 = new Vector3(
                                        reader.ReadSingle(),
                                        reader.ReadSingle(),
                                        reader.ReadSingle()); break;

                                case ShaderParamType.Float4:
                                    reader.Seek(param.DataOffset, SeekOrigin.Begin);
                                    prm.Value_float4 = new Vector4(
                                        reader.ReadSingle(),
                                        reader.ReadSingle(),
                                        reader.ReadSingle(),
                                        reader.ReadSingle()); break;

                                case ShaderParamType.TexSrt:
                                    reader.Seek(param.DataOffset, SeekOrigin.Begin);
                                    ShaderParam.TextureSRT texSRT = new ShaderParam.TextureSRT();
                                    texSRT.Mode      = reader.ReadSingle(); //Scale mode, Maya, max ect
                                    texSRT.scale     = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                                    texSRT.rotate    = reader.ReadSingle();
                                    texSRT.translate = new Vector2(reader.ReadSingle(), reader.ReadSingle());

                                    prm.Value_TexSrt = texSRT; break;
                                }
                                poly.material.matparam.Add(param.Name, prm);
                            }
                            reader.Close();
                        }
                    }


                    model.poly.Add(poly);
                    ShapeCur++;
                }
                models.Add(model);
                ModelCur++;
            }
        }
示例#19
0
文件: Core.cs 项目: Sidd710/tempRepo
 internal extern static unsafe int GetSamplerInfo(IntPtr sampler, SamplerInfo param_name, IntPtr param_value_size, IntPtr param_value, [OutAttribute] IntPtr *param_value_size_ret);
示例#20
0
        public void Read(ResFile TargetWiiUBFRES)
        {
            Nodes.Add(TModels);
            Nodes.Add(TTextures);
            Nodes.Add(TShaderparam);
            Nodes.Add(TColoranim);
            Nodes.Add(TTextureSRT);
            Nodes.Add(TTexturePat);
            Nodes.Add(TBonevisabilty);
            Nodes.Add(TVisualAnim);
            Nodes.Add(TShapeAnim);
            Nodes.Add(TSceneAnim);
            Nodes.Add(TEmbedded);
            ImageKey         = "bfres";
            SelectedImageKey = "bfres";

            FSKACount = TargetWiiUBFRES.SkeletalAnims.Count;

            textures.Clear();

            foreach (Texture tex in TargetWiiUBFRES.Textures.Values)
            {
                string TextureName = tex.Name;
                FTEX   texture     = new FTEX();
                texture.ReadFTEX(tex);
                textures.Add(TextureName, texture);
                TTextures.Nodes.Add(texture);
            }

            int ModelCur = 0;

            //FMDLs -Models-
            foreach (Model mdl in TargetWiiUBFRES.Models.Values)
            {
                FMDL_Model model = new FMDL_Model(); //This will store VBN data and stuff
                model.Text = mdl.Name;

                TModels.Nodes.Add(model);

                model.Node_Array = new int[mdl.Skeleton.MatrixToBoneList.Count];
                int nodes = 0;
                foreach (ushort node in mdl.Skeleton.MatrixToBoneList)
                {
                    model.Node_Array[nodes] = node;
                    nodes++;
                }

                foreach (Syroot.NintenTools.Bfres.Bone bn in mdl.Skeleton.Bones.Values)
                {
                    Bone bone = new Bone(model.skeleton);
                    bone.Text        = bn.Name;
                    bone.boneId      = bn.BillboardIndex;
                    bone.parentIndex = bn.ParentIndex;
                    bone.scale       = new float[3];
                    bone.rotation    = new float[4];
                    bone.position    = new float[3];

                    if (bn.FlagsRotation == BoneFlagsRotation.Quaternion)
                    {
                        bone.boneRotationType = 1;
                    }
                    else
                    {
                        bone.boneRotationType = 0;
                    }

                    bone.scale[0]    = bn.Scale.X;
                    bone.scale[1]    = bn.Scale.Y;
                    bone.scale[2]    = bn.Scale.Z;
                    bone.rotation[0] = bn.Rotation.X;
                    bone.rotation[1] = bn.Rotation.Y;
                    bone.rotation[2] = bn.Rotation.Z;
                    bone.rotation[3] = bn.Rotation.W;
                    bone.position[0] = bn.Position.X;
                    bone.position[1] = bn.Position.Y;
                    bone.position[2] = bn.Position.Z;

                    model.skeleton.bones.Add(bone);
                }
                model.skeleton.reset();
                model.skeleton.update();

                //MeshTime!!
                int ShapeCur = 0;
                foreach (Shape shp in mdl.Shapes.Values)
                {
                    Mesh poly = new Mesh();
                    poly.Text          = shp.Name;
                    poly.MaterialIndex = shp.MaterialIndex;
                    poly.matrFlag      = shp.VertexSkinCount;
                    poly.fsklindx      = shp.BoneIndex;

                    TModels.Nodes[ModelCur].Nodes.Add(poly);

                    //Create a buffer instance which stores all the buffer data
                    VertexBufferHelper helper = new VertexBufferHelper(mdl.VertexBuffers[shp.VertexBufferIndex], TargetWiiUBFRES.ByteOrder);

                    // VertexBufferHelperAttrib uv1 = helper["_u1"];


                    Vertex v = new Vertex();
                    foreach (VertexAttrib att in mdl.VertexBuffers[shp.VertexBufferIndex].Attributes.Values)
                    {
                        if (att.Name == "_p0")
                        {
                            Console.WriteLine(att.Name);
                            VertexBufferHelperAttrib position      = helper["_p0"];
                            Syroot.Maths.Vector4F[]  vec4Positions = position.Data;

                            foreach (Syroot.Maths.Vector4F p in vec4Positions)
                            {
                                v.pos.Add(new Vector3 {
                                    X = p.X, Y = p.Y, Z = p.Z
                                });
                            }
                        }
                        if (att.Name == "_n0")
                        {
                            Console.WriteLine(att.Name);
                            VertexBufferHelperAttrib normal      = helper["_n0"];
                            Syroot.Maths.Vector4F[]  vec4Normals = normal.Data;

                            foreach (Syroot.Maths.Vector4F n in vec4Normals)
                            {
                                v.nrm.Add(new Vector3 {
                                    X = n.X, Y = n.Y, Z = n.Z
                                });
                            }
                        }
                        if (att.Name == "_u0")
                        {
                            Console.WriteLine(att.Name);
                            VertexBufferHelperAttrib uv0     = helper["_u0"];
                            Syroot.Maths.Vector4F[]  vec4uv0 = uv0.Data;

                            foreach (Syroot.Maths.Vector4F u in vec4uv0)
                            {
                                v.uv0.Add(new Vector2 {
                                    X = u.X, Y = u.Y
                                });
                            }
                        }
                        if (att.Name == "_u1")
                        {
                            Console.WriteLine(att.Name);
                            VertexBufferHelperAttrib uv1     = helper["_u1"];
                            Syroot.Maths.Vector4F[]  vec4uv1 = uv1.Data;

                            foreach (Syroot.Maths.Vector4F u in vec4uv1)
                            {
                                v.uv1.Add(new Vector2 {
                                    X = u.X, Y = u.Y
                                });
                            }
                        }
                        if (att.Name == "_u2")
                        {
                            Console.WriteLine(att.Name);
                            VertexBufferHelperAttrib uv2     = helper["_u2"];
                            Syroot.Maths.Vector4F[]  vec4uv2 = uv2.Data;

                            foreach (Syroot.Maths.Vector4F u in vec4uv2)
                            {
                                v.uv2.Add(new Vector2 {
                                    X = u.X, Y = u.Y
                                });
                            }
                        }
                        if (att.Name == "_c0")
                        {
                            Console.WriteLine(att.Name);
                            VertexBufferHelperAttrib c0     = helper["_c0"];
                            Syroot.Maths.Vector4F[]  vec4c0 = c0.Data;

                            foreach (Syroot.Maths.Vector4F c in vec4c0)
                            {
                                v.col.Add(new Vector4 {
                                    X = c.X, Y = c.Y, Z = c.Z, W = c.W
                                });
                            }
                        }
                        if (att.Name == "_t0")
                        {
                            Console.WriteLine(att.Name);
                            VertexBufferHelperAttrib t0     = helper["_t0"];
                            Syroot.Maths.Vector4F[]  vec4t0 = t0.Data;

                            foreach (Syroot.Maths.Vector4F u in vec4t0)
                            {
                                v.tans.Add(new Vector4 {
                                    X = u.X, Y = u.Y, Z = u.Z, W = u.W
                                });
                            }
                        }
                        if (att.Name == "_b0")
                        {
                            Console.WriteLine(att.Name);
                            VertexBufferHelperAttrib b0     = helper["_b0"];
                            Syroot.Maths.Vector4F[]  vec4b0 = b0.Data;

                            foreach (Syroot.Maths.Vector4F u in vec4b0)
                            {
                                v.bitans.Add(new Vector4 {
                                    X = u.X, Y = u.Y, Z = u.Z, W = u.W
                                });
                            }
                        }
                        if (att.Name == "_w0")
                        {
                            Console.WriteLine(att.Name);
                            VertexBufferHelperAttrib w0     = helper["_w0"];
                            Syroot.Maths.Vector4F[]  vec4w0 = w0.Data;

                            foreach (Syroot.Maths.Vector4F w in vec4w0)
                            {
                                v.weights.Add(new Vector4 {
                                    X = w.X, Y = w.Y, Z = w.Z, W = w.W
                                });
                            }
                        }
                        if (att.Name == "_i0")
                        {
                            Console.WriteLine(att.Name);
                            VertexBufferHelperAttrib i0     = helper["_i0"];
                            Syroot.Maths.Vector4F[]  vec4i0 = i0.Data;

                            foreach (Syroot.Maths.Vector4F i in vec4i0)
                            {
                                v.nodes.Add(new Vector4 {
                                    X = i.X, Y = i.Y, Z = i.Z, W = i.W
                                });
                            }
                        }
                    }
                    poly.vertices = v;

                    //shp.Meshes.Count - 1 //For going to the lowest poly LOD mesh

                    int LODCount = 0;

                    uint   FaceCount    = FaceCount = shp.Meshes[LODCount].IndexCount;
                    uint[] indicesArray = shp.Meshes[LODCount].GetIndices().ToArray();

                    poly.BoundingCount = shp.SubMeshBoundings.Count;

                    for (int face = 0; face < FaceCount; face++)
                    {
                        poly.faces.Add((int)indicesArray[face] + (int)shp.Meshes[LODCount].FirstVertex);
                    }

                    int AlbedoCount = 0;

                    string TextureName = "";
                    int    id          = 0;
                    foreach (TextureRef tex in mdl.Materials[shp.MaterialIndex].TextureRefs)
                    {
                        TextureName = tex.Name;

                        MatTexture texture = new MatTexture();

                        poly.Nodes.Add(new TreeNode {
                            Text = TextureName
                        });

                        if (mdl.Materials[shp.MaterialIndex].Samplers[id].Name == "_a0")
                        {
                            if (AlbedoCount == 0)
                            {
                                try
                                {
                                    poly.texHashs.Add(textures[TextureName].texture.display);
                                    AlbedoCount++;
                                }
                                catch
                                {
                                    poly.texHashs.Add(0);
                                }
                                poly.TextureMapTypes.Add("Diffuse");
                            }
                        }
                        if (mdl.Materials[shp.MaterialIndex].Samplers[id].Name == "_a1")
                        {
                            try
                            {
                                poly.texHashs.Add(textures[TextureName].texture.display);
                                AlbedoCount++;
                            }
                            catch
                            {
                                poly.texHashs.Add(0);
                            }
                            poly.TextureMapTypes.Add("Diffuse_Layer");
                        }
                        if (mdl.Materials[shp.MaterialIndex].Samplers[id].Name == "_n0")
                        {
                            try
                            {
                                poly.texHashs.Add(textures[TextureName].texture.display);
                            }
                            catch
                            {
                                poly.texHashs.Add(1);
                            }
                            poly.material.HasNormalMap = true;
                            poly.TextureMapTypes.Add("Normal");
                        }
                        if (mdl.Materials[shp.MaterialIndex].Samplers[id].Name == "_b0")
                        {
                            try
                            {
                                poly.texHashs.Add(textures[TextureName].texture.display);
                            }
                            catch
                            {
                                poly.texHashs.Add(2);
                            }
                            poly.TextureMapTypes.Add("Bake1");
                        }
                        if (mdl.Materials[shp.MaterialIndex].Samplers[id].Name == "_b1")
                        {
                            try
                            {
                                poly.texHashs.Add(textures[TextureName].texture.display);
                            }
                            catch
                            {
                                poly.texHashs.Add(3);
                            }
                            poly.TextureMapTypes.Add("Bake2");
                        }
                        id++;
                        texture.Name = TextureName;
                    }

                    poly.material.Name = mdl.Materials[shp.MaterialIndex].Name;

                    foreach (Sampler smp in mdl.Materials[shp.MaterialIndex].Samplers.Values)
                    {
                        SamplerInfo s = new SamplerInfo();
                        s.WrapModeU = (int)smp.TexSampler.ClampX;
                        s.WrapModeV = (int)smp.TexSampler.ClampY;
                        s.WrapModeW = (int)smp.TexSampler.ClampZ;
                        poly.material.samplerinfo.Add(s);
                    }

                    using (Syroot.BinaryData.BinaryDataReader reader = new Syroot.BinaryData.BinaryDataReader(new MemoryStream(mdl.Materials[shp.MaterialIndex].ShaderParamData)))
                    {
                        reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
                        foreach (Syroot.NintenTools.Bfres.ShaderParam param in mdl.Materials[shp.MaterialIndex].ShaderParams.Values)
                        {
                            ShaderParam prm = new ShaderParam();

                            prm.Type = param.Type;

                            switch (param.Type)
                            {
                            case ShaderParamType.Float:
                                reader.Seek(param.DataOffset, SeekOrigin.Begin);
                                prm.Value_float = reader.ReadSingle();
                                break;

                            case ShaderParamType.Float2:
                                reader.Seek(param.DataOffset, SeekOrigin.Begin);
                                prm.Value_float2 = new Vector2(
                                    reader.ReadSingle(),
                                    reader.ReadSingle());
                                break;

                            case ShaderParamType.Float3:
                                reader.Seek(param.DataOffset, SeekOrigin.Begin);
                                prm.Value_float3 = new Vector3(
                                    reader.ReadSingle(),
                                    reader.ReadSingle(),
                                    reader.ReadSingle()); break;

                            case ShaderParamType.Float4:
                                reader.Seek(param.DataOffset, SeekOrigin.Begin);
                                prm.Value_float4 = new Vector4(
                                    reader.ReadSingle(),
                                    reader.ReadSingle(),
                                    reader.ReadSingle(),
                                    reader.ReadSingle()); break;
                            }
                            poly.material.matparam.Add(param.Name, prm);
                        }
                        reader.Close();
                    }
                    model.poly.Add(poly);
                    ShapeCur++;
                }
                models.Add(model);
                ModelCur++;
            }
        }
示例#21
0
        public ISampleSelector MakeSampleSelecter(SamplerInfo samplerInfo)
        {
            if (samplerInfo is null)
            {
                throw new ArgumentNullException(nameof(samplerInfo));
            }

            var method             = samplerInfo.Method;
            var sampleSelectortype = samplerInfo.SampleSelectorType;

            //if ((sg.TallyMethod & CruiseDAL.Enums.TallyMode.Manual) == CruiseDAL.Enums.TallyMode.Manual)
            //{
            //    return null;
            //}

            switch (method)
            {
            case "100":
            case "FIX":
            case "PNT":
            case "FIXCNT":
            {
                return(new HundredPCTSelector());
            }

            case "STR":
            {
                // default sample selector for STR is blocked
                if (sampleSelectortype == SAMPLESELECTORTYPE_SYSTEMATICSELECTER)
                {
                    return(MakeSystematicSampleSelector(samplerInfo));
                }
                else
                {
                    return(MakeBlockSampleSelector(samplerInfo));
                }
            }

            case "S3P":
            {
                return(MakeS3PSampleSelector(samplerInfo));
            }

            case "3P":
            case "P3P":
            case "F3P":
            {
                return(MakeThreePSampleSelector(samplerInfo));
            }

            case "FCM":
            case "PCM":
            {
                // default sample selector for plot methods is systematic
                if (sampleSelectortype == SAMPLESELECTORTYPE_BLOCKSELECTER)
                {
                    return(MakeBlockSampleSelector(samplerInfo));
                }
                else
                {
                    return(MakeSystematicSampleSelector(samplerInfo));
                }
            }

            case null:
            { throw new NullReferenceException("method should not be null"); }

            default:
            {
                return(null);
            }
            }
        }
示例#22
0
            public void Read(FileReader reader, Header ptclHeader)
            {
                uint Position = (uint)reader.Position;

                Color0Array = new ColorData[8];
                Color1Array = new ColorData[8];

                reader.Seek(Position + 880, SeekOrigin.Begin);
                for (int i = 0; i < 8; i++)
                {
                    Color0Array[i]   = new ColorData();
                    Color0Array[i].R = reader.ReadSingle();
                    Color0Array[i].G = reader.ReadSingle();
                    Color0Array[i].B = reader.ReadSingle();
                    float time = reader.ReadSingle();

                    int red   = Utils.FloatToIntClamp(Color0Array[i].R);
                    int green = Utils.FloatToIntClamp(Color0Array[i].G);
                    int blue  = Utils.FloatToIntClamp(Color0Array[i].B);

                    Color0s[i] = Color.FromArgb(255, red, green, blue);
                }
                for (int i = 0; i < 8; i++)
                {
                    Color0Array[i].A = reader.ReadSingle();
                    float padding  = reader.ReadSingle();
                    float padding2 = reader.ReadSingle();
                    float time     = reader.ReadSingle();

                    int alpha = Utils.FloatToIntClamp(Color0Array[i].A);
                }
                for (int i = 0; i < 8; i++)
                {
                    Color1Array[i]   = new ColorData();
                    Color1Array[i].R = reader.ReadSingle();
                    Color1Array[i].G = reader.ReadSingle();
                    Color1Array[i].B = reader.ReadSingle();
                    float time = reader.ReadSingle();

                    int red   = Utils.FloatToIntClamp(Color1Array[i].R);
                    int green = Utils.FloatToIntClamp(Color1Array[i].G);
                    int blue  = Utils.FloatToIntClamp(Color1Array[i].B);

                    Color1s[i] = Color.FromArgb(255, red, green, blue);
                }
                for (int i = 0; i < 8; i++)
                {
                    Color1Array[i].A = reader.ReadSingle();
                    float padding  = reader.ReadSingle();
                    float padding2 = reader.ReadSingle();
                    float time     = reader.ReadSingle();

                    int alpha = Utils.FloatToIntClamp(Color1Array[i].A);
                }

                if (ptclHeader.VFXVersion >= 22)
                {
                    reader.Seek(Position + 2464, SeekOrigin.Begin);
                }
                else
                {
                    reader.Seek(Position + 2472, SeekOrigin.Begin);
                }

                for (int i = 0; i < 3; i++)
                {
                    SamplerInfo samplerInfo = new SamplerInfo();
                    samplerInfo.Read(reader);
                    Samplers.Add(samplerInfo);
                }
            }
示例#23
0
 public static extern Error clGetSamplerInfo(OpenCLSampler sampler, SamplerInfo param_name, IntPtr param_value_size, IntPtr param_value, IntPtr param_value_size_ret);
示例#24
0
 internal extern static unsafe int GetSamplerInfo(IntPtr sampler, SamplerInfo param_name, IntPtr param_value_size, IntPtr param_value, [OutAttribute] IntPtr* param_value_size_ret);
示例#25
0
 public static InfoBuffer GetSamplerInfo(Sampler sampler, SamplerInfo paramName, out ErrorCode error)
 {
     return GetInfo(GetSamplerInfo, sampler, paramName, out error);
 }
示例#26
0
 public static InfoBuffer GetSamplerInfo(Sampler sampler, SamplerInfo paramName, out ErrorCode error)
 {
     return(GetInfo(GetSamplerInfo, sampler, paramName, out error));
 }
示例#27
0
        public void Read(ResFile TargetSwitchBFRES, FileData f)
        {
            Nodes.Add(TModels);
            Nodes.Add(TMaterialAnim);
            Nodes.Add(TVisualAnim);
            Nodes.Add(TShapeAnim);
            Nodes.Add(TSceneAnim);
            Nodes.Add(TEmbedded);
            ImageKey         = "bfres";
            SelectedImageKey = "bfres";

            FSKACount = TargetSwitchBFRES.SkeletalAnims.Count;
            FVISCount = TargetSwitchBFRES.BoneVisibilityAnims.Count;
            FMAACount = TargetSwitchBFRES.MaterialAnims.Count;

            Console.WriteLine("Name = " + TargetSwitchBFRES.Name);

            foreach (ExternalFile ext in TargetSwitchBFRES.ExternalFiles)
            {
                f = new FileData(ext.Data);

                f.Endian = Endianness.Little;

                string EmMagic = f.readString(f.pos(), 4);

                if (EmMagic.Equals("BNTX")) //Textures
                {
                    int  temp = f.pos();
                    BNTX t    = new BNTX();
                    t.ReadBNTX(f);
                    TEmbedded.Nodes.Add(t);
                }
            }

            int ModelCur = 0;

            //FMDLs -Models-
            foreach (Model mdl in TargetSwitchBFRES.Models)
            {
                FMDL_Model model = new FMDL_Model(); //This will store VBN data and stuff
                model.Text = mdl.Name;

                TModels.Nodes.Add(model);

                ReadSkeleton(model, mdl);

                model.skeleton.reset();
                model.skeleton.update();

                //MeshTime!!
                foreach (Shape shp in mdl.Shapes)
                {
                    Mesh poly = new Mesh();
                    poly.Text          = shp.Name;
                    poly.MaterialIndex = shp.MaterialIndex;
                    poly.matrFlag      = shp.VertexSkinCount;
                    poly.fsklindx      = shp.BoneIndex;

                    TModels.Nodes[ModelCur].Nodes.Add(poly);


                    ReadVertexBuffer(mdl, shp, poly);


                    //  int LODCount = shp.Meshes.Count - 1; //For going to the lowest poly LOD mesh
                    int LODCount = 0;

                    uint   FaceCount    = FaceCount = shp.Meshes[LODCount].IndexCount;
                    uint[] indicesArray = shp.Meshes[LODCount].GetIndices().ToArray();

                    poly.BoundingCount = shp.SubMeshBoundings.Count;

                    for (int face = 0; face < FaceCount; face++)
                    {
                        poly.faces.Add((int)indicesArray[face] + (int)shp.Meshes[LODCount].FirstVertex);
                    }

                    foreach (Bounding bnd in shp.SubMeshBoundings)
                    {
                        Mesh.BoundingBox box = new Mesh.BoundingBox();
                        box.Center = new Vector3(bnd.Center.X, bnd.Center.Y, bnd.Center.Z);
                        box.Extent = new Vector3(bnd.Extent.X, bnd.Extent.Y, bnd.Extent.Z);

                        poly.boundingBoxes.Add(box); //Each box is by LOD mesh. This will be in a seperate class later so only one will be added
                    }
                    foreach (float r in shp.RadiusArray)
                    {
                        poly.radius.Add(r);
                    }

                    // Read materials
                    Material mat = mdl.Materials[shp.MaterialIndex];

                    poly.material.Name = mat.Name;

                    ReadTextureRefs(mat, poly);
                    ReadShaderParams(mat, poly);
                    ReadRenderInfo(mat, poly);

                    foreach (Sampler smp in mdl.Materials[shp.MaterialIndex].Samplers)
                    {
                        SamplerInfo s = new SamplerInfo();
                        s.WrapModeU = (int)smp.WrapModeU;
                        s.WrapModeV = (int)smp.WrapModeV;
                        s.WrapModeW = (int)smp.WrapModeW;
                        poly.material.samplerinfo.Add(s);
                    }

                    model.poly.Add(poly);
                }
                models.Add(model);
                ModelCur++;
            }
        }
示例#28
0
 public static Error clGetSamplerInfo(OpenCLSampler sampler, SamplerInfo param_name, IntPtr param_value_size, IntPtr param_value, IntPtr param_value_size_ret)
 {
     Console.WriteLine("Calling Error clGetSamplerInfo(OpenCLSampler sampler, SamplerInfo param_name, IntPtr param_value_size, IntPtr param_value, IntPtr param_value_size_ret)");
     return default(Error);
 }