Ejemplo n.º 1
0
 public GcmfRenderContext(Gcmf gcmf)
 {
     this.Gcmf = gcmf;
     this.TransformMatrixIdxs = new byte[8];
     for (int i = 0; i < TransformMatrixIdxs.Length; i++)
     {
         TransformMatrixIdxs[i] = byte.MaxValue;
     }
 }
Ejemplo n.º 2
0
        public void CopyFlags(Gcmf other)
        {
            //if(Meshes.Count != other.Meshes.Count)
            //{
            //    throw new InvalidOperationException("Replacing model must have the same number of meshes.");
            //}
            SectionFlags               = other.SectionFlags;
            BoundingSphereCenter       = other.BoundingSphereCenter;
            TransformMatrices          = other.TransformMatrices;
            TransformMatrixDefaultIdxs = other.TransformMatrixDefaultIdxs;
            Type8Unknown1              = other.Type8Unknown1;
            Type8Unknown2              = other.Type8Unknown2;

            if (Meshes.Count == other.Meshes.Count)
            {
                for (int i = 0; i < Meshes.Count && i < other.Meshes.Count; i++)
                {
                    GcmfMesh thisMesh  = Meshes[i];
                    GcmfMesh otherMesh = other.Meshes[i];

                    thisMesh.Layer = otherMesh.Layer;

                    thisMesh.RenderFlags = otherMesh.RenderFlags;
                    thisMesh.Unk4        = otherMesh.Unk4;
                    thisMesh.Unk8        = otherMesh.Unk8;
                    thisMesh.UnkC        = otherMesh.UnkC;
                    thisMesh.Unk10       = otherMesh.Unk10;
                    // Header section info (Section flags)
                    thisMesh.Unk14 = otherMesh.Unk14;
                    // Header section info (Vertex flags)
                    thisMesh.TransformMatrixSpecificIdxsObj1 = otherMesh.TransformMatrixSpecificIdxsObj1;
                    thisMesh.TransformMatrixSpecificIdxsObj2 = otherMesh.TransformMatrixSpecificIdxsObj2;
                    thisMesh.BoundingSphereCenter            = otherMesh.BoundingSphereCenter;
                    thisMesh.Unk3C = otherMesh.Unk3C;
                    thisMesh.Unk40 = otherMesh.Unk40;
                }
            }

            if (Materials.Count == other.Materials.Count)
            {
                for (int i = 0; i < Materials.Count && i < other.Materials.Count; i++)
                {
                    GcmfMaterial thisMaterial  = Materials[i];
                    GcmfMaterial otherMaterial = other.Materials[i];

                    thisMaterial.Flags           = otherMaterial.Flags;
                    thisMaterial.Unk6            = otherMaterial.Unk6;
                    thisMaterial.AnisotropyLevel = otherMaterial.AnisotropyLevel;
                    thisMaterial.UnkC            = otherMaterial.UnkC;
                    thisMaterial.Unk10           = otherMaterial.Unk10;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a new Gma model from a loaded OBJ/MTL model.
        /// </summary>
        /// <param name="model">The model to load the .GMA file from.</param>
        /// <param name="textureIndexMapping">Correspondence between the textures defined in the model materials and .TPL texture indices.</param>
        public Gma(ObjMtlModel model, Dictionary <Bitmap, int> textureIndexMapping)
            : this()
        {
            if (model.Objects.ContainsKey("") && model.Objects[""].Meshes.SelectMany(m => m.Faces).Any())
            {
                throw new InvalidOperationException("Geometry is not allowed outside of named objects.");
            }

            foreach (KeyValuePair <string, ObjMtlObject> objectEntry in model.Objects)
            {
                Gcmf modelObject = new Gcmf(objectEntry.Value, textureIndexMapping);
                this.Add(new GmaEntry(objectEntry.Key, modelObject));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Load a Gma model from the given .GMA stream.
        /// </summary>
        private void Load(EndianBinaryReader input, GxGame game)
        {
            int numObjs           = input.ReadInt32();
            int modelBasePosition = input.ReadInt32();

            List <GmaEntryOffsets> entryOffs = new List <GmaEntryOffsets>();

            for (int i = 0; i < numObjs; i++)
            {
                entryOffs.Add(new GmaEntryOffsets
                {
                    ModelOffset = input.ReadInt32(),
                    NameOffset  = input.ReadInt32()
                });
            }

            int nameBasePosition = Convert.ToInt32(input.BaseStream.Position);

            foreach (GmaEntryOffsets entryOff in entryOffs)
            {
                // There are some "empty" entries, without any data or a name.
                // We insert null into the container in this case.
                if (entryOff.ModelOffset != -1 || entryOff.NameOffset != 0)
                {
                    input.BaseStream.Position = nameBasePosition + entryOff.NameOffset;
                    string name = input.ReadAsciiString();

                    input.BaseStream.Position = modelBasePosition + entryOff.ModelOffset;
                    Gcmf model = new Gcmf();
                    model.Load(input, game);

                    Add(new GmaEntry(name, model));
                }
                else
                {
                    Add(null);
                }
            }
        }
Ejemplo n.º 5
0
        public void Load(ObjMtlModel model, Dictionary <Bitmap, int> textureIndexMapping, string name, bool preserveFlags)
        {
            if (model.Objects.ContainsKey("") && model.Objects[""].Meshes.SelectMany(m => m.Faces).Any())
            {
                throw new InvalidOperationException("Geometry is not allowed outside of named objects.");
            }

            if (model.Objects.Count != 1)
            {
                throw new InvalidObjMtlFileException("Only replace 1 model with 1 model");
            }

            int entryIndex = GetEntryIndex(name);

            foreach (KeyValuePair <string, ObjMtlObject> objectEntry in model.Objects)
            {
                Gcmf modelObject = new Gcmf(objectEntry.Value, textureIndexMapping);
                if (preserveFlags)
                {
                    modelObject.CopyFlags(this[entryIndex].ModelObject);
                }
                this[entryIndex] = new GmaEntry(name, modelObject);
            }
        }
Ejemplo n.º 6
0
 /// <summary>Create a new GmaEntry with the given name and associated model object.</summary>
 public GmaEntry(string name, Gcmf modelObject)
 {
     Name        = name;
     ModelObject = modelObject;
 }