public static FragmentOperationContainer Load(Utility utility)
        {
            var foc = new FragmentOperationContainer();

            CGFXDebug.LoadStart(foc, utility);

            ///////// DEPTH /////////
            // See also SPICA GfxFragOp / GfxFragOpDepth
            foc.DepthFlags           = utility.ReadU32();
            foc.DepthPICACommandsRaw = utility.ReadUInts(4);


            ///////// BLEND /////////
            // See also SPICA GfxFragOp / GfxFragOpBlend
            foc.BlendMode            = (BlendModeType)utility.ReadU32();
            foc.BlendColor           = ColorFloat.Read(utility);
            foc.BlendPICACommandsRaw = utility.ReadUInts(6);


            ///////// STENCIL /////////
            // See also SPICA GfxFragOp / GfxFragOpStencil
            foc.StencilOperationRaw = utility.ReadUInts(4);

            return(foc);
        }
Пример #2
0
        public static TextureSampler Load(TextureMapper parent, Utility utility)
        {
            var s = new TextureSampler();

            CGFXDebug.LoadStart(s, utility);

            // This has a TypeId here...
            s.TypeId = utility.ReadU32();
            if (s.TypeId != 0x80000000)
            {
                throw new InvalidOperationException($"TextureSampler: Expected type 0x80000000, got {s.TypeId}");
            }

            // Just reading the offset but we'll resolve this later
            var ownerModelOffset = utility.ReadOffset();

            s.Parent = parent;

            s.MinFilter = (TextureMinFilter)utility.ReadU32();

            s.BorderColor = ColorFloat.Read(utility);
            s.LODBias     = utility.ReadFloat();

            return(s);
        }
        public static TextureMapper Load(Utility utility)
        {
            var tm = new TextureMapper();

            CGFXDebug.LoadStart(tm, utility);

            tm.TypeId = utility.ReadU32();
            if (tm.TypeId != 0x80000000)
            {
                throw new InvalidOperationException($"TextureMapper: Expected type 0x80000000, got {tm.TypeId}");
            }

            tm.DynamicAllocator = utility.ReadU32();

            // Texture Reference
            tm.TextureReference = utility.LoadDICTObj <TextureReference>();

            // Sampler
            utility.LoadIndirect(() =>
            {
                tm.TextureSampler = TextureSampler.Load(tm, utility);
            });

            tm.Commands       = utility.ReadUInts(14);
            tm.CommandsLength = utility.ReadU32();  // Seems to be length of the aforementioned "Commands"?

            // I think this is a fair sanity check??
            if (tm.CommandsLength != (14 * 4))
            {
                throw new InvalidOperationException("CommandsLength mismatch");
            }

            return(tm);
        }
        // Load the standard pattern of [UINT COUNT][UINT OFFSET TO TABLE] -> [UINT OFFSET 1][UINT OFFSET 2]...
        public IEnumerable <TDICTObj> LoadDICTObjList <TDICTObj>()
            where TDICTObj : ChunkDICTObject, new()
        {
            TDICTObj[] result = null;

            CGFXDebug.LoadStart($"HEADER of list of {typeof(TDICTObj).Name} [LoadDICTObjList]", this);

            var count         = ReadU32();
            var locationTable = ReadOffset();

            if (count > 0)
            {
                result = new TDICTObj[count];

                PushReadPosition();
                SetReadPosition(locationTable);

                CGFXDebug.LoadStart($"List of {typeof(TDICTObj).Name} [LoadDICTObjList]", this);

                for (var index = 0; index < count; index++)
                {
                    result[index] = LoadDICTObj <TDICTObj>();
                }

                PopReadPosition();
            }

            return(result);
        }
        // Load a list of non-ChunkDICTObject arbitrary objects from a list of pointers
        public TObj[] LoadIndirectObjList <TObj>(Func <TObj> loadAction)
        {
            TObj[] result = null;

            CGFXDebug.LoadStart($"HEADER of list of {typeof(TObj).Name} [LoadIndirectObjList]", this);

            var numObjects = ReadU32();
            var offset     = ReadOffset();

            if (offset > 0)
            {
                PushReadPosition();
                SetReadPosition(offset);

                CGFXDebug.LoadStart($"List of {typeof(TObj).Name} [LoadIndirectObjList]", this);

                result = new TObj[numObjects];
                for (var objIndex = 0; objIndex < numObjects; objIndex++)
                {
                    var objOffset = ReadOffset();
                    PushReadPosition();
                    SetReadPosition(objOffset);

                    result[objIndex] = loadAction();

                    PopReadPosition();
                }

                PopReadPosition();
            }

            return(result);
        }
        public static MaterialColorContainer Load(Utility utility)
        {
            var mcc = new MaterialColorContainer();

            CGFXDebug.LoadStart(mcc, utility);

            mcc.EmissionF  = ColorFloat.Read(utility);
            mcc.AmbientF   = ColorFloat.Read(utility);
            mcc.DiffuseF   = ColorFloat.Read(utility);
            mcc.Specular0F = ColorFloat.Read(utility);
            mcc.Specular1F = ColorFloat.Read(utility);
            mcc.Constant0F = ColorFloat.Read(utility);
            mcc.Constant1F = ColorFloat.Read(utility);
            mcc.Constant2F = ColorFloat.Read(utility);
            mcc.Constant3F = ColorFloat.Read(utility);
            mcc.Constant4F = ColorFloat.Read(utility);
            mcc.Constant5F = ColorFloat.Read(utility);

            mcc.Emission  = Color.Read(utility);
            mcc.Ambient   = Color.Read(utility);
            mcc.Diffuse   = Color.Read(utility);
            mcc.Specular0 = Color.Read(utility);
            mcc.Specular1 = Color.Read(utility);
            mcc.Constant0 = Color.Read(utility);
            mcc.Constant1 = Color.Read(utility);
            mcc.Constant2 = Color.Read(utility);
            mcc.Constant3 = Color.Read(utility);
            mcc.Constant4 = Color.Read(utility);
            mcc.Constant5 = Color.Read(utility);

            mcc.CommandCache = utility.ReadU32();

            return(mcc);
        }
        }                                           // SPICA doesn't note this, unknown, found through testing

        public override void Load(Utility utility)
        {
            // NOT caling base.Load() as this doesn't use the usual header
            CGFXDebug.LoadStart(this, utility);

            TypeId = utility.ReadU32();
            if (TypeId != 0x80000000)
            {
                throw new InvalidOperationException($"DICTObjAnimGroup: Unexpected TypeId {TypeId.ToString("X8")}");
            }

            Flags      = utility.ReadU32();
            Name       = utility.ReadString();
            MemberType = utility.ReadI32();

            Elements = utility.LoadDICTFromOffset <ChunkDICTAnimGroupElement>();

            var count = utility.ReadU32();

            BlendOperationTypes = utility.ReadInts(count);

            EvaluationTiming = (AnimEvaluationTiming)utility.ReadU32();

            Unknown = utility.ReadU32();
        }
Пример #8
0
            }                                                   // Raw PICA200 GPU commands

            public static TexEnv Load(Utility utility)
            {
                var te = new TexEnv();

                CGFXDebug.LoadStart(te, utility);

                te.Constant    = (GfxTexEnvConstant)utility.ReadU32();
                te.RawCommands = utility.ReadUInts(6);

                return(te);
            }
            }                                   // Found during discovery of unread bytes, no idea what this is for

            public static GfxBoundingBox Load(Utility utility)
            {
                var bb = new GfxBoundingBox();

                CGFXDebug.LoadStart(bb, utility);

                bb.Center      = Vector3.Read(utility);
                bb.Orientation = Matrix3x3.Read(utility);
                bb.Size        = Vector3.Read(utility);
                bb.Unknown     = utility.ReadFloat();

                return(bb);
            }
Пример #10
0
        }                                                       // NOTE -- Ohana3DS had THREE unknown uints, but SPICA only reads TWO uints here

        public static RasterizationContainer Load(Utility utility)
        {
            var rc = new RasterizationContainer();

            CGFXDebug.LoadStart(rc, utility);

            rc.IsPolygonOffsetEnabled = (utility.ReadU32() & 1) > 0;
            rc.FaceCulling            = (CullMode)utility.ReadU32();
            rc.PolygonOffsetUnit      = utility.ReadFloat();

            rc.FaceCullingCommand = utility.ReadUInts(2);

            return(rc);
        }
Пример #11
0
            public static FragLightLUT Load(Utility utility)
            {
                var fll = new FragLightLUT();

                CGFXDebug.LoadStart(fll, utility);

                fll.Input = (PICALUTInput)utility.ReadU32();
                fll.Scale = (PICALUTScale)utility.ReadU32();

                utility.LoadIndirect(() =>
                {
                    fll.Sampler = LUTReference.Load(utility);
                });

                return(fll);
            }
            public static GfxSubMesh Load(Utility utility)
            {
                var sm = new GfxSubMesh();

                CGFXDebug.LoadStart(sm, utility);

                // Bone Indices
                sm.BoneIndices = utility.LoadIndirectValueList(() => utility.ReadU32())?.ToList();

                // Skinning
                sm.Skinning = (SubMeshSkinning)utility.ReadU32();

                // Faces
                sm.Faces = utility.LoadIndirectObjList(() => Face.Load(utility)).ToList();

                return(sm);
            }
        // Either way, chunks are always read the same...
        private static TChunk Load <TChunk>(Utility utility, TChunk chunk)
            where TChunk : Chunk
        {
            CGFXDebug.LoadStart(chunk, utility);

            var startPosition = utility.GetReadPosition();
            var magic         = utility.ReadMagic();
            var chunkSize     = utility.ReadU32();

            // Call Chunk's load routine
            chunk.LoadInternal(utility, chunkSize);

            // No matter what, make sure we've seeked to the end of chunk by this point!
            utility.SetReadPosition(startPosition + chunkSize);

            return(chunk);
        }
Пример #14
0
        public static LUTReference Load(Utility utility)
        {
            var lr = new LUTReference();

            CGFXDebug.LoadStart(lr, utility);

            lr.TypeId = utility.ReadU32();
            if (lr.TypeId != 0x40000000)
            {
                throw new InvalidOperationException($"Unexpected TypeId {lr.TypeId}");
            }

            lr.SamplerName = utility.ReadString();
            lr.TableName   = utility.ReadString();

            lr.LUT = utility.LoadDICTFromOffset <ChunkDICTLUT>();

            return(lr);
        }
        public static VertexBuffer Load(Utility utility)
        {
            VertexBuffer result = null;

            // This one's a little unusual because we actually instantiate different
            // resultant objects by the TypeId we read...
            var typeId = utility.ReadU32();

            if (typeId == 0x40000001)
            {
                result = new VertexAttribute();
            }
            else if (typeId == 0x40000002)
            {
                result = new VertexBufferInterleaved();
            }
            else if (typeId == 0x80000000)
            {
                result = new VertexBufferFixed();
            }
            else
            {
                throw new NotImplementedException($"VertexBuffer Load: Unsupported TypeId {typeId}");
            }

            CGFXDebug.LoadStart(result, utility, hasDynamicType: true);

            // Common values...
            result.TypeId   = typeId;
            result.AttrName = (PICAAttributeName)utility.ReadU32();
            result.Type     = (GfxVertexBufferType)utility.ReadU32();

            // Verification that the type matches the TypeId..
            if (result.TypeId != result.ExpectedTypeId)
            {
                throw new InvalidOperationException($"Instantiated type {result.GetType().Name} but it expected TypeId {result.ExpectedTypeId.ToString("X8")} instead of {typeId.ToString("X8")}");
            }

            // If all good, continue the load!
            result.LoadInternal(utility);

            return(result);
        }
Пример #16
0
        public static FragmentShader Load(Utility utility)
        {
            var fs = new FragmentShader();

            CGFXDebug.LoadStart(fs, utility);

            fs.TexEnvBufferColorF = ColorFloat.Read(utility);

            // Fragment Shader
            fs.FragmentFlags     = utility.ReadU32();
            fs.TranslucencyKind  = (TranslucencyKind)utility.ReadU32();
            fs.FresnelSelector   = (GfxFresnelSelector)utility.ReadU32();
            fs.BumpTexture       = utility.ReadI32();
            fs.BumpMode          = (GfxBumpMode)utility.ReadU32();
            fs.IsBumpRenormalize = utility.ReadU32() == 1;

            // Fragment Lighting
            CGFXDebug.LoadStart($"HEADER of list of FragLightLUTs", utility);
            utility.LoadIndirect(() =>
            {
                CGFXDebug.LoadStart($"List of FragLightLUTs", utility);
                fs.ReflectanceRSampler  = GetFragLightLUT(utility);
                fs.ReflectanceGSampler  = GetFragLightLUT(utility);
                fs.ReflectanceBSampler  = GetFragLightLUT(utility);
                fs.Distribution0Sampler = GetFragLightLUT(utility);
                fs.Distribution1Sampler = GetFragLightLUT(utility);
                fs.FresnelSampler       = GetFragLightLUT(utility);
            });

            fs.TextureEnvironments = new TexEnv[6];
            for (var i = 0; i < fs.TextureEnvironments.Length; i++)
            {
                fs.TextureEnvironments[i] = TexEnv.Load(utility);
            }

            fs.AlphaTestRawCommands = utility.ReadUInts(2);

            fs.FragmentShaderRawCommands = utility.ReadUInts(6);

            return(fs);
        }
Пример #17
0
        public static MetaDataBase Load(Utility utility)
        {
            MetaDataBase result = null;

            // We need to load the TypeId because it tells us what kind of MetaData to expect...
            var typeId = utility.ReadU32();

            if (typeId == 0x80000000u)
            {
                result = new MetaDataSingle();
            }
            else if (typeId == 0x40000000)
            {
                result = new MetaDataColor();
            }
            else if (typeId == 0x20000000)
            {
                result = new MetaDataInteger();
            }
            else if (typeId == 0x10000000)
            {
                result = new MetaDataString();
            }

            if (result == null)
            {
                throw new NotImplementedException($"Unknown MetaData type {typeId.ToString("X8")}!");
            }

            CGFXDebug.LoadStart(result, utility, hasDynamicType: true);

            // Otherwise, proceed...
            result.TypeId = typeId;
            result.Name   = utility.ReadString();
            result.Type   = (MetaDataType)utility.ReadU32();

            result.LoadInternal(utility);

            return(result);
        }
Пример #18
0
        public static BlendShape Load(Utility utility)
        {
            // TODO -- Neither Ohana3DS nor SPICA implemented this other than recognizing
            // it has a list of GfxBlendShapeTargets and a list of GfxVertexBufferTypes.
            // The former of which it currently has no definition for. However, if we
            // get lucky and these just aren't used, then I'm not going to worry about
            // it right now...

            //public List<GfxBlendShapeTarget> Targets;
            //public List<GfxVertexBufferType> Types;

            var bs = new BlendShape();

            CGFXDebug.LoadStart(bs, utility);

            bs.TypeId = utility.ReadU32();
            if (bs.TypeId != 0x00000000)
            {
                throw new InvalidOperationException($"BlendShape: Unexpected typeId {bs.TypeId}");
            }


            // The 4 UInts here WOULD BE:
            //  Count of Targets
            //  Offset to Targets
            //  Count of Types
            //  Offset to Types
            bs.Stubs = utility.ReadUInts(4);

            // ... but just make sure they're all unused for now
            for (var i = 0; i < 4; i++)
            {
                if (bs.Stubs[i] != 0)
                {
                    throw new NotImplementedException("BlendShape: Trying to fetch data, NOT IMPLEMENTED");
                }
            }

            return(bs);
        }
Пример #19
0
        public static Face Load(Utility utility)
        {
            var f = new Face();

            CGFXDebug.LoadStart(f, utility);

            f.FaceDescriptors = utility.LoadIndirectObjList(() => FaceDescriptor.Load(utility)).ToList();

            // FIXME CHECKME -- I hope these aren't offsets??? (I just got a single 0x00000000 from one file, so hoping it's nothing)
            f.BufferObjs = utility.LoadIndirectValueList(() => utility.ReadU32());

            // This is a rule?
            if (f.BufferObjs.Length != f.FaceDescriptors.Count)
            {
                throw new InvalidOperationException("Count mismatch between bufferObjCount and numFaceDescriptors");
            }

            f.Flags        = utility.ReadU32();
            f.CommandAlloc = utility.ReadU32();

            return(f);
        }
Пример #20
0
        public virtual void Load(Utility utility)
        {
            CGFXDebug.LoadStart(this, utility);

            TypeId = utility.ReadU32();
            if (!VerifyTypeId(TypeId))
            {
                throw new InvalidOperationException($"ChunkDICTObject Load: ERROR reading DICT -- unexpected type ID '{TypeId.ToString("X8")}'");
            }


            var magic = utility.ReadMagic();

            if (magic != Utility.MakeMagic(Magic))
            {
                throw new InvalidOperationException($"ChunkDICTObject Load: ERROR reading DICT -- expected magic '{Magic}', got '{Utility.GetMagicString(magic)}'");
            }

            Revision = utility.ReadU32();
            Name     = utility.ReadString();

            MetaDatas = utility.LoadDICTFromOffset <ChunkDICTMetaData>();
        }
Пример #21
0
        public static AnimGroupElementBase Load(Utility utility)
        {
            AnimGroupElementBase result = null;

            // We need to load the TypeId because it tells us what kind of AnimGroupElement to expect...
            var typeId = utility.ReadU32();

            if (typeId == 0x00080000)
            {
                result = new AnimGroupMeshNodeVis();
            }
            else if (typeId == 0x01000000)
            {
                result = new AnimGroupMesh();
            }
            else if (typeId == 0x02000000)
            {
                result = new AnimGroupTexSampler();
            }
            else if (typeId == 0x04000000)
            {
                result = new AnimGroupBlendOp();
            }
            else if (typeId == 0x08000000)
            {
                result = new AnimGroupMaterialColor();
            }
            else if (typeId == 0x10000000)
            {
                result = new AnimGroupModel();
            }
            else if (typeId == 0x20000000)
            {
                result = new AnimGroupTexMapper();
            }
            else if (typeId == 0x40000000)
            {
                result = new AnimGroupBone();
            }
            else if (typeId == 0x80000000)
            {
                result = new AnimGroupTexCoord();
            }

            if (result == null)
            {
                throw new NotImplementedException($"Unknown AnimGroupElement type {typeId.ToString("X8")}!");
            }

            CGFXDebug.LoadStart(result, utility, hasDynamicType: true);

            // Otherwise, proceed...
            result.TypeId       = typeId;
            result.Name         = utility.ReadString();
            result.MemberOffset = utility.ReadI32();
            result.BlendOpIndex = utility.ReadI32();
            result.ObjType      = (AnimGroupObjType)utility.ReadU32();
            result.MemberType   = utility.ReadU32();
            result.MaterialPtr  = utility.ReadU32();

            result.LoadInternal(utility);

            return(result);
        }