Ejemplo n.º 1
0
        internal void SaveNonIndexedData(EndianBinaryWriter output, bool is16Bit)
        {
            if (Obj1StripsCcw.Count != 0)
            {
                Obj1StripsCcw.SaveNonIndexed(output, is16Bit);
            }

            if (Obj1StripsCw.Count != 0)
            {
                Obj1StripsCw.SaveNonIndexed(output, is16Bit);
            }

            if (Obj2StripsCcw.Count != 0 || Obj2StripsCw.Count != 0)
            {
                // Extra header
                output.Write(TransformMatrixSpecificIdxsObj2, 0, 8);
                output.Write(Obj2StripsCcw.SizeOfNonIndexed(is16Bit));
                output.Write(Obj2StripsCw.SizeOfNonIndexed(is16Bit));
                output.Write(0);
                output.Write(0);
                output.Write(0);
                output.Write(0);

                Obj2StripsCcw.SaveNonIndexed(output, is16Bit);
                Obj2StripsCw.SaveNonIndexed(output, is16Bit);
            }
        }
Ejemplo n.º 2
0
        internal int SizeOfNonIndexedData(bool is16Bit)
        {
            int size = 0;

            if (Obj1StripsCcw.Count != 0)
            {
                size += Obj1StripsCcw.SizeOfNonIndexed(is16Bit);
            }

            if (Obj1StripsCw.Count != 0)
            {
                size += Obj1StripsCw.SizeOfNonIndexed(is16Bit);
            }

            if (Obj2StripsCcw.Count != 0 || Obj2StripsCw.Count != 0)
            {
                size += 0x20; // Extra header
                size += Obj2StripsCcw.SizeOfNonIndexed(is16Bit);
                size += Obj2StripsCw.SizeOfNonIndexed(is16Bit);
            }

            return(size);
        }
Ejemplo n.º 3
0
        internal void LoadNonIndexedData(EndianBinaryReader input, HeaderSectionInfo headerSectionInfo, bool is16Bit)
        {
            if ((headerSectionInfo.SectionFlags & 0x01) != 0 && headerSectionInfo.Chunk1Size == 0)
            {
                throw new InvalidGmaFileException("GcmfMeshType1: Chunk1, but chunk1Size == 0?");
            }
            if ((headerSectionInfo.SectionFlags & 0x01) == 0 && headerSectionInfo.Chunk1Size != 0)
            {
                throw new InvalidGmaFileException("GcmfMeshType1: No chunk1, but chunk1Size != 0?");
            }

            if ((headerSectionInfo.SectionFlags & 0x01) != 0)
            {
                Obj1StripsCcw.LoadNonIndexed(input, headerSectionInfo.Chunk1Size, headerSectionInfo.VertexFlags, is16Bit);
            }

            if ((headerSectionInfo.SectionFlags & 0x02) != 0 && headerSectionInfo.Chunk2Size == 0)
            {
                throw new InvalidGmaFileException("GcmfMeshType1: Chunk2, but chunk2Size == 0?");
            }
            else if ((headerSectionInfo.SectionFlags & 0x02) == 0 && headerSectionInfo.Chunk2Size != 0)
            {
                throw new InvalidGmaFileException("GcmfMeshType1: No chunk2, but chunk2Size != 0?");
            }

            if ((headerSectionInfo.SectionFlags & 0x02) != 0)
            {
                Obj1StripsCw.LoadNonIndexed(input, headerSectionInfo.Chunk2Size, headerSectionInfo.VertexFlags, is16Bit);
            }

            if ((headerSectionInfo.SectionFlags & 0xFF) == 0x0F) // Those are always used together
            {
                // Read extra header before two extra chunks
                input.Read(TransformMatrixSpecificIdxsObj2, 0, 8);
                int chunk3Size = input.ReadInt32();
                int chunk4Size = input.ReadInt32();
                if (input.ReadUInt32() != 0)
                {
                    throw new InvalidGmaFileException("Expected GcmfMeshType1[ExtraHdr-0x10] == 0");
                }
                if (input.ReadUInt32() != 0)
                {
                    throw new InvalidGmaFileException("Expected GcmfMeshType1[ExtraHdr-0x14] == 0");
                }
                if (input.ReadUInt32() != 0)
                {
                    throw new InvalidGmaFileException("Expected GcmfMeshType1[ExtraHdr-0x18]== 0");
                }
                if (input.ReadUInt32() != 0)
                {
                    throw new InvalidGmaFileException("Expected GcmfMeshType1[ExtraHdr-0x1C] == 0");
                }

                if (chunk3Size == 0)
                {
                    throw new InvalidGmaFileException("GcmfMeshType1: Chunk3, but chunk3Size == 0?");
                }

                if (chunk4Size == 0)
                {
                    throw new InvalidGmaFileException("GcmfMeshType1: Chunk4, but chunk4Size == 0?");
                }

                Obj2StripsCcw.LoadNonIndexed(input, chunk3Size, headerSectionInfo.VertexFlags, is16Bit);
                Obj2StripsCw.LoadNonIndexed(input, chunk4Size, headerSectionInfo.VertexFlags, is16Bit);
            }
            else if ((headerSectionInfo.SectionFlags & 0xFC) != 0)
            {
                throw new InvalidGmaFileException("GcmfMeshType1: Unknown present chunk flags at chunk10.");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This is the same as render(), but it skips the material setup step,
        /// so when rendering all triangle meshes, they only need to be set up once.
        /// </summary>
        internal void RenderInternal(IRenderer renderer, GcmfRenderContext context)
        {
            /*
             * if (Layer == GcmfTriangleMeshLayer.Layer1)
             * {
             *  GL.Disable(EnableCap.Blend);
             *  GL.DepthMask(true);
             * }
             * else
             * {
             *  GL.DepthMask(false);
             *  GL.Enable(EnableCap.Blend);
             *  GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
             * }
             */

            // Set up the renderer according to the render flags set
            renderer.SetTwoSidedFaces((RenderFlags & RenderFlag.TwoSided) != 0);

            // Very rarely a mesh with a material id set to 0xFFFF ((ushort)-1) is seen.
            // I believe this is just a that it didn't have a material assigned.
            if (PrimaryMaterialIdx != ushort.MaxValue)
            {
                renderer.BindMaterial(PrimaryMaterialIdx);
            }
            else
            {
                renderer.UnbindMaterial();
            }

            // Patch the non-null default transformation matrix indexes (for obj1)
            // with the specific indexes set for this mesh
            for (int i = 0; i < TransformMatrixSpecificIdxsObj1.Length; i++)
            {
                if (TransformMatrixSpecificIdxsObj1[i] != byte.MaxValue)
                {
                    context.TransformMatrixIdxs[i] = TransformMatrixSpecificIdxsObj1[i];
                }
            }

            renderer.SetFrontFaceDirection(FrontFaceDirection.Ccw);
            Obj1StripsCcw.Render(renderer, context);

            renderer.SetFrontFaceDirection(FrontFaceDirection.Cw);
            Obj1StripsCw.Render(renderer, context);

            // Patch the non-null default transformation matrix indexes (for obj2)
            // with the specific indexes set for this mesh
            for (int i = 0; i < TransformMatrixSpecificIdxsObj2.Length; i++)
            {
                if (TransformMatrixSpecificIdxsObj2[i] != byte.MaxValue)
                {
                    context.TransformMatrixIdxs[i] = TransformMatrixSpecificIdxsObj2[i];
                }
            }

            renderer.SetFrontFaceDirection(FrontFaceDirection.Ccw);
            Obj2StripsCcw.Render(renderer, context);

            renderer.SetFrontFaceDirection(FrontFaceDirection.Cw);
            Obj2StripsCw.Render(renderer, context);
        }