コード例 #1
0
        internal void Read(EndianBinaryReader reader, MeshSection section = null)
        {
            uint signature = reader.ReadUInt32();

            reader.SeekCurrent(4);

            int  subMeshCount, materialCount;
            long subMeshesOffset, materialsOffset;

            // X stores submesh/material count before the bounding sphere
            if (section?.Format == BinaryFormat.X)
            {
                subMeshCount    = reader.ReadInt32();
                materialCount   = reader.ReadInt32();
                BoundingSphere  = reader.ReadBoundingSphere();
                subMeshesOffset = reader.ReadOffset();
                materialsOffset = reader.ReadOffset();
            }

            else
            {
                BoundingSphere  = reader.ReadBoundingSphere();
                subMeshCount    = reader.ReadInt32();
                subMeshesOffset = reader.ReadOffset();
                materialCount   = reader.ReadInt32();
                materialsOffset = reader.ReadOffset();
            }

            SubMeshes.Capacity = subMeshCount;
            for (int i = 0; i < subMeshCount; i++)
            {
                reader.ReadAtOffset(subMeshesOffset + i * SubMesh.GetByteSize(section?.Format ?? BinaryFormat.DT), () =>
                {
                    var submesh = new SubMesh();
                    submesh.Read(reader, section);
                    SubMeshes.Add(submesh);
                });
            }

            Materials.Capacity = materialCount;
            for (int i = 0; i < materialCount; i++)
            {
                reader.ReadAtOffset(materialsOffset + i * Material.BYTE_SIZE, () =>
                {
                    var material = new Material();
                    material.Read(reader);
                    Materials.Add(material);
                });
            }
        }
コード例 #2
0
        internal void Read(EndianBinaryReader reader, MeshSection section = null)
        {
            reader.SeekCurrent(4);
            BoundingSphere    = reader.ReadBoundingSphere();
            MaterialIndex     = reader.ReadInt32();
            MaterialUVIndices = reader.ReadBytes(8);
            int  boneIndexCount    = reader.ReadInt32();
            long boneIndicesOffset = reader.ReadOffset();
            uint field00           = reader.ReadUInt32();

            PrimitiveType = ( PrimitiveType )reader.ReadUInt32();
            int  field01       = reader.ReadInt32();
            int  indexCount    = reader.ReadInt32();
            uint indicesOffset = reader.ReadUInt32();

            if (section != null)
            {
                reader.SeekCurrent(section.Format == BinaryFormat.X ? 0x18 : 0x14);
                BoundingBox = reader.ReadBoundingBox();
                Field00     = reader.ReadInt32();
            }
            else
            {
                BoundingBox = BoundingSphere.ToBoundingBox();
            }

            reader.ReadAtOffsetIf(field00 == 4, boneIndicesOffset, () =>
            {
                BoneIndices = reader.ReadUInt16s(boneIndexCount);
            });

            if (section == null)
            {
                reader.ReadAtOffset(indicesOffset, () =>
                {
                    Indices = reader.ReadUInt16s(indexCount);
                });
            }
            else
            {
                var indexReader = section.IndexData.Reader;

                indexReader.SeekBegin(section.IndexData.DataOffset + indicesOffset);
                Indices = indexReader.ReadUInt16s(indexCount);
            }
        }
コード例 #3
0
        internal void Write(EndianBinaryWriter writer, MeshSection section = null)
        {
            writer.Write(0);
            writer.Write(BoundingSphere);
            writer.Write(MaterialIndex);

            if (MaterialUVIndices?.Length == 8)
            {
                writer.Write(MaterialUVIndices);
            }
            else
            {
                writer.WriteNulls(8);
            }

            writer.Write(BoneIndices != null ? BoneIndices.Length : 0);
            writer.ScheduleWriteOffsetIf(BoneIndices != null, 4, AlignmentMode.Left, () =>
            {
                writer.Write(BoneIndices);
            });
            writer.Write(BoneIndices != null ? 4 : 0);

            writer.Write(( int )PrimitiveType);
            writer.Write(1);
            writer.Write(Indices.Length);

            // Modern Format
            if (section != null)
            {
                writer.Write(( uint )section.IndexData.AddIndices(Indices));
                writer.WriteNulls(section.Format == BinaryFormat.X ? 24 : 20);
                writer.Write(BoundingBox);
                writer.Write(Field00);
                writer.Write(0);
            }

            else
            {
                writer.ScheduleWriteOffset(4, AlignmentMode.Left, () =>
                {
                    writer.Write(Indices);
                });

                writer.WriteNulls(32);
            }
        }
コード例 #4
0
        internal void Write(EndianBinaryWriter writer, MeshSection section = null)
        {
            writer.Write(0x10000);
            writer.Write(0);

            if (section?.Format == BinaryFormat.X)
            {
                writer.Write(SubMeshes.Count);
                writer.Write(Materials.Count);
                writer.Write(BoundingSphere);
                writer.ScheduleWriteOffset(4, AlignmentMode.Left, ( Action )WriteSubMeshes);
                writer.ScheduleWriteOffset(4, AlignmentMode.Left, ( Action )WriteMaterials);
            }
            else
            {
                writer.Write(BoundingSphere);
                writer.Write(SubMeshes.Count);
                writer.ScheduleWriteOffset(4, AlignmentMode.Left, ( Action )WriteSubMeshes);
                writer.Write(Materials.Count);
                writer.ScheduleWriteOffset(4, AlignmentMode.Left, ( Action )WriteMaterials);
            }

            writer.WriteNulls(section?.Format == BinaryFormat.X ? 0x40 : 0x28);

            void WriteSubMeshes()
            {
                foreach (var subMesh in SubMeshes)
                {
                    subMesh.Write(writer, section);
                }
            }

            void WriteMaterials()
            {
                foreach (var material in Materials)
                {
                    material.Write(writer);
                }
            }
        }
コード例 #5
0
        public static VertexFlags GetFlags(MeshSection meshSec)
        {
            VertexFlags flags = new VertexFlags();

            flags.TextureCoordinateFormat = (CoordinateFormat)GetBitFieldRange(meshSec.VertexFlags, 0, 2);
            flags.ColorFormat             = (ColorFormat)GetBitFieldRange(meshSec.VertexFlags, 2, 3);
            flags.NormalFormat            = (CoordinateFormat)GetBitFieldRange(meshSec.VertexFlags, 5, 2);
            flags.PositionFormat          = (CoordinateFormat)GetBitFieldRange(meshSec.VertexFlags, 7, 2);
            flags.WeightFormat            = (CoordinateFormat)GetBitFieldRange(meshSec.VertexFlags, 9, 2);
            flags.IndicesFormat           = (byte)GetBitFieldRange(meshSec.VertexFlags, 11, 2);
            flags.Unused1 = (byte)GetBitFieldRange(meshSec.VertexFlags, 13, 1) == 1;
            flags.SkinningWeightsCount = (byte)GetBitFieldRange(meshSec.VertexFlags, 14, 3);
            flags.Unused2               = (byte)GetBitFieldRange(meshSec.VertexFlags, 17, 1) == 1;
            flags.MorphWeightsCount     = (byte)GetBitFieldRange(meshSec.VertexFlags, 18, 3);
            flags.Unused3               = (byte)GetBitFieldRange(meshSec.VertexFlags, 21, 2);
            flags.SkipTransformPipeline = (byte)GetBitFieldRange(meshSec.VertexFlags, 23, 1) == 1;
            flags.UniformDiffuseFlag    = (byte)GetBitFieldRange(meshSec.VertexFlags, 24, 1) == 1;
            flags.Unknown1              = (byte)GetBitFieldRange(meshSec.VertexFlags, 25, 3);
            flags.Primitive             = (PrimitiveType)GetBitFieldRange(meshSec.VertexFlags, 28, 4);

            return(flags);
        }
コード例 #6
0
        public string SectionToString(MeshSection sec)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("..Unknown01          : 0x{0}\n", sec.Unknown01.ToString("X8"));
            sb.AppendFormat("..Unknown02          : 0x{0}\n", sec.Unknown02.ToString("X8"));
            sb.AppendFormat("..SectionName        : {0}\n", sec.SectionName);
            sb.AppendFormat("..Unknown03          : 0x{0}\n", sec.Unknown03.ToString("X8"));
            sb.AppendFormat("..TriangleCount      : {0}\n", sec.TriangleCount);
            sb.AppendFormat("..StartIndex         : {0}\n", sec.StartIndex);
            sb.AppendFormat("..VertexBufferOffset : 0x{0}\n", sec.VertexBufferOffset.ToString("X8"));
            sb.AppendFormat("..VertexCount        : {0}\n", sec.VertexCount);
            sb.AppendFormat("..VertexStride       : 0x{0}\n", sec.VertexStride.ToString("X8"));
            sb.AppendFormat("..Unknown04          : 0x{0}\n", sec.Unknown04.ToString("X8"));
            sb.AppendFormat("..Unknown05          : 0x{0}\n", sec.Unknown05.ToString("X8"));
            sb.AppendFormat("..Unknown06          : 0x{0}\n", sec.Unknown06.ToString("X8"));
            sb.Append("..VertexEntries      : ");
            if (sec.VertexEntries != null)
            {
                foreach (VertexDescriptor v in sec.VertexEntries)
                {
                    sb.AppendFormat("[Type 0x{0} ; Offset 0x{1} ; Unknown 0x{2}]", v.VertexType.ToString("X"), v.Offset.ToString("X"), v.Unknown01.ToString("X"));
                }
            }
            sb.Append("\n..Unknown List       : ");
            foreach (int u in sec.Unknowns2)
            {
                sb.AppendFormat("0x{0}, ", u.ToString("X8"));
            }
            sb.Append("\n..Section Bone List  : ");
            foreach (int u in sec.SubBoneList)
            {
                sb.AppendFormat("{0}, ", u);
            }
            sb.Append("\n");
            return(sb.ToString());
        }
コード例 #7
0
        private MeshSection ReadMeshSection(Stream s)
        {
            MeshSection r = new MeshSection();

            r.Unknown01          = Helpers.ReadInt(s);
            r.Unknown02          = Helpers.ReadInt(s);
            r.SectionName        = SerializeString(s);
            r.Unknown03          = Helpers.ReadInt(s);
            r.TriangleCount      = Helpers.ReadInt(s);
            r.StartIndex         = Helpers.ReadInt(s);
            r.VertexBufferOffset = Helpers.ReadInt(s);
            r.VertexCount        = Helpers.ReadInt(s);
            r.Unknown04          = Helpers.ReadInt(s);
            r.Unknown05          = Helpers.ReadInt(s);
            r.Unknown06          = Helpers.ReadInt(s);
            r.VertexEntries      = new List <VertexDescriptor>();
            for (int i = 0; i < 16; i++)
            {
                VertexDescriptor VertexEntry = new VertexDescriptor();
                VertexEntry.VertexType = Helpers.ReadShort(s);
                VertexEntry.Offset     = s.ReadByte();
                VertexEntry.Unknown01  = s.ReadByte();
                if (VertexEntry.Offset != 0xFF)
                {
                    r.VertexEntries.Add(VertexEntry);
                }
            }
            r.VertexStride = Helpers.ReadInt(s);
            r.Unknowns2    = new int[19];
            for (int i = 0; i < 19; i++)
            {
                r.Unknowns2[i] = Helpers.ReadInt(s);
            }
            r.SubBoneList = new ushort[0];
            return(r);
        }
コード例 #8
0
ファイル: SubMesh.cs プロジェクト: ctrget/MikuMikuLibrary
        internal void Read(EndianBinaryReader reader, MeshSection section = null)
        {
            reader.SeekCurrent(4);
            BoundingSphere = reader.ReadBoundingSphere();
            int  indexTableCount   = reader.ReadInt32();
            long indexTablesOffset = reader.ReadOffset();
            var  attributes        = ( VertexFormatAttribute )reader.ReadUInt32();
            int  stride            = reader.ReadInt32();
            int  vertexCount       = reader.ReadInt32();
            var  elemItems         = reader.ReadUInt32s(section?.Format == BinaryFormat.X ? 49 : 28);

            Name = reader.ReadString(StringBinaryFormat.FixedLength, 64);

            IndexTables.Capacity = indexTableCount;
            for (int i = 0; i < indexTableCount; i++)
            {
                reader.ReadAtOffset(indexTablesOffset + (i * IndexTable.GetByteSize(section?.Format ?? BinaryFormat.DT)), () =>
                {
                    var indexTable = new IndexTable();
                    indexTable.Read(reader, section);
                    IndexTables.Add(indexTable);
                });
            }

            // Modern Format
            if (section != null)
            {
                ReadVertexAttributesModern();
            }
            else
            {
                ReadVertexAttributesClassic();
            }

            void ReadVertexAttributesClassic()
            {
                Vector4[] boneWeights = null;
                Vector4[] boneIndices = null;

                for (int i = 0; i < 28; i++)
                {
                    var attribute = ( VertexFormatAttribute )(1 << i);

                    reader.ReadAtOffsetIf((attributes & attribute) != 0, elemItems[i], () =>
                    {
                        switch (attribute)
                        {
                        case VertexFormatAttribute.Vertex:
                            Vertices = reader.ReadVector3s(vertexCount);
                            break;

                        case VertexFormatAttribute.Normal:
                            Normals = reader.ReadVector3s(vertexCount);
                            break;

                        case VertexFormatAttribute.Tangent:
                            Tangents = reader.ReadVector4s(vertexCount);
                            break;

                        case VertexFormatAttribute.UVChannel1:
                            UVChannel1 = reader.ReadVector2s(vertexCount);
                            break;

                        case VertexFormatAttribute.UVChannel2:
                            UVChannel2 = reader.ReadVector2s(vertexCount);
                            break;

                        case VertexFormatAttribute.Color:
                            Colors = reader.ReadColors(vertexCount);
                            break;

                        case VertexFormatAttribute.BoneWeight:
                            boneWeights = reader.ReadVector4s(vertexCount);
                            break;

                        case VertexFormatAttribute.BoneIndex:
                            boneIndices = reader.ReadVector4s(vertexCount);
                            break;

                        default:
                            Console.WriteLine("Unhandled vertex format element: {0}", attribute);
                            break;
                        }
                    });
                }

                if (boneWeights != null && boneIndices != null)
                {
                    BoneWeights = new BoneWeight[vertexCount];
                    for (int i = 0; i < vertexCount; i++)
                    {
                        // So apparently, FT uses -1 instead of 255 for weights that aren't used,
                        // and index tables can use bones more than 85 (85*3=255)
                        // For that reason, weight == 255 check won't and shouldn't be done anymore.

                        Vector4 weight4 = boneWeights[i];
                        Vector4 index4  = Vector4.Divide(boneIndices[i], 3);

                        var boneWeight = new BoneWeight
                        {
                            Weight1 = weight4.X,
                            Weight2 = weight4.Y,
                            Weight3 = weight4.Z,
                            Weight4 = weight4.W,
                            Index1  = ( int )index4.X,
                            Index2  = ( int )index4.Y,
                            Index3  = ( int )index4.Z,
                            Index4  = ( int )index4.W,
                        };
                        boneWeight.Validate();

                        BoneWeights[i] = boneWeight;
                    }
                }
            }

            void ReadVertexAttributesModern()
            {
                uint dataOffset     = elemItems[section.Format == BinaryFormat.X ? 27 : 13];
                uint attributeFlags = elemItems[section.Format == BinaryFormat.X ? 42 : 21];

                if (attributeFlags == 2 || attributeFlags == 4)
                {
                    Vertices   = new Vector3[vertexCount];
                    Normals    = new Vector3[vertexCount];
                    Tangents   = new Vector4[vertexCount];
                    UVChannel1 = new Vector2[vertexCount];
                    UVChannel2 = new Vector2[vertexCount];
                    Colors     = new Color[vertexCount];

                    if (attributeFlags == 4)
                    {
                        BoneWeights = new BoneWeight[vertexCount];
                    }

                    bool hasTangents   = false;
                    bool hasUVChannel2 = false;
                    bool hasColors     = false;

                    var vertexReader = section.VertexData.Reader;
                    for (int i = 0; i < vertexCount; i++)
                    {
                        vertexReader.SeekBegin(section.VertexData.DataOffset + dataOffset + (stride * i));
                        Vertices[i] = vertexReader.ReadVector3();
                        Normals[i]  = vertexReader.ReadVector3(VectorBinaryFormat.Int16);
                        vertexReader.SeekCurrent(2);
                        Tangents[i]   = vertexReader.ReadVector4(VectorBinaryFormat.Int16);
                        UVChannel1[i] = vertexReader.ReadVector2(VectorBinaryFormat.Half);
                        UVChannel2[i] = vertexReader.ReadVector2(VectorBinaryFormat.Half);
                        Colors[i]     = vertexReader.ReadColor(VectorBinaryFormat.Half);

                        if (attributeFlags == 4)
                        {
                            var boneWeight = new BoneWeight
                            {
                                Weight1 = vertexReader.ReadUInt16() / 32768f,
                                Weight2 = vertexReader.ReadUInt16() / 32768f,
                                Weight3 = vertexReader.ReadUInt16() / 32768f,
                                Weight4 = vertexReader.ReadUInt16() / 32768f,
                                Index1  = vertexReader.ReadByte() / 3,
                                Index2  = vertexReader.ReadByte() / 3,
                                Index3  = vertexReader.ReadByte() / 3,
                                Index4  = vertexReader.ReadByte() / 3,
                            };
                            boneWeight.Validate();

                            BoneWeights[i] = boneWeight;
                        }

                        // Normalize normal because precision
                        Normals[i] = Vector3.Normalize(Normals[i]);

                        // Checks to get rid of useless data after reading
                        if (Tangents[i] != Vector4.Zero)
                        {
                            hasTangents = true;
                        }
                        if (UVChannel1[i] != UVChannel2[i])
                        {
                            hasUVChannel2 = true;
                        }
                        if (!Colors[i].Equals(Color.White))
                        {
                            hasColors = true;
                        }
                    }

                    if (!hasTangents)
                    {
                        Tangents = null;
                    }
                    if (!hasUVChannel2)
                    {
                        UVChannel2 = null;
                    }
                    if (!hasColors)
                    {
                        Colors = null;
                    }
                }

                if (Tangents != null)
                {
                    for (int i = 0; i < Tangents.Length; i++)
                    {
                        float   direction = Tangents[i].W < 0.0f ? -1.0f : 1.0f;
                        Vector3 tangent   = Vector3.Normalize(new Vector3(Tangents[i].X, Tangents[i].Y, Tangents[i].Z));

                        Tangents[i] = new Vector4(tangent, direction);
                    }
                }
            }
        }
コード例 #9
0
ファイル: SubMesh.cs プロジェクト: ctrget/MikuMikuLibrary
        internal void Write(EndianBinaryWriter writer, MeshSection section = null)
        {
            writer.Write(0);
            writer.Write(BoundingSphere);
            writer.Write(IndexTables.Count);
            writer.ScheduleWriteOffset(4, AlignmentMode.Left, () =>
            {
                foreach (var indexTable in IndexTables)
                {
                    indexTable.Write(writer, section);
                }
            });

            int stride = 0;
            VertexFormatAttribute attributes = default(VertexFormatAttribute);

            if (section != null)
            {
                attributes = VertexFormatAttribute.UsesModernStorage;
                if (BoneWeights != null)
                {
                    stride = 56;
                }
                else
                {
                    stride = 44;
                }
            }

            else
            {
                if (Vertices != null)
                {
                    attributes |= VertexFormatAttribute.Vertex;
                    stride     += 12;
                }

                if (Normals != null)
                {
                    attributes |= VertexFormatAttribute.Normal;
                    stride     += 12;
                }

                if (Tangents != null)
                {
                    attributes |= VertexFormatAttribute.Tangent;
                    stride     += 16;
                }

                if (UVChannel1 != null)
                {
                    attributes |= VertexFormatAttribute.UVChannel1;
                    stride     += 8;
                }

                if (UVChannel2 != null)
                {
                    attributes |= VertexFormatAttribute.UVChannel2;
                    stride     += 8;
                }

                if (Colors != null)
                {
                    attributes |= VertexFormatAttribute.Color;
                    stride     += 16;
                }

                if (BoneWeights != null)
                {
                    attributes |= VertexFormatAttribute.BoneWeight | VertexFormatAttribute.BoneIndex;
                    stride     += 32;
                }
            }

            writer.Write(( int )attributes);
            writer.Write(stride);
            writer.Write(Vertices.Length);

            if (section != null)
            {
                WriteVertexAttributesModern();
            }
            else
            {
                WriteVertexAttributesClassic();
            }

            writer.Write(Name, StringBinaryFormat.FixedLength, 64);

            void WriteVertexAttributesClassic()
            {
                for (int i = 0; i < 28; i++)
                {
                    var attribute = ( VertexFormatAttribute )(1 << i);

                    writer.ScheduleWriteOffsetIf((attributes & attribute) != 0, 4, AlignmentMode.Left, () =>
                    {
                        switch (attribute)
                        {
                        case VertexFormatAttribute.Vertex:
                            writer.Write(Vertices);
                            break;

                        case VertexFormatAttribute.Normal:
                            writer.Write(Normals);
                            break;

                        case VertexFormatAttribute.Tangent:
                            writer.Write(Tangents);
                            break;

                        case VertexFormatAttribute.UVChannel1:
                            writer.Write(UVChannel1);
                            break;

                        case VertexFormatAttribute.UVChannel2:
                            writer.Write(UVChannel2);
                            break;

                        case VertexFormatAttribute.Color:
                            writer.Write(Colors);
                            break;

                        case VertexFormatAttribute.BoneWeight:
                            foreach (var weight in BoneWeights)
                            {
                                writer.Write(weight.Weight1);
                                writer.Write(weight.Weight2);
                                writer.Write(weight.Weight3);
                                writer.Write(weight.Weight4);
                            }
                            break;

                        case VertexFormatAttribute.BoneIndex:
                            foreach (var weight in BoneWeights)
                            {
                                writer.Write(weight.Index1 < 0 ? -1f : weight.Index1 * 3.0f);
                                writer.Write(weight.Index2 < 0 ? -1f : weight.Index2 * 3.0f);
                                writer.Write(weight.Index3 < 0 ? -1f : weight.Index3 * 3.0f);
                                writer.Write(weight.Index4 < 0 ? -1f : weight.Index4 * 3.0f);
                            }
                            break;
                        }
                    });
                }
            }

            void WriteVertexAttributesModern()
            {
                writer.WriteNulls(section.Format == BinaryFormat.X ? 0x6C : 0x34);
                writer.Write(( uint )section.VertexData.AddSubMesh(this, stride));
                writer.WriteNulls(section.Format == BinaryFormat.X ? 0x38 : 0x1C);
                writer.Write(BoneWeights != null ? 4 : 2);
                writer.WriteNulls(0x18);
            }
        }
コード例 #10
0
    void Restock()
    {
        float now = Time.time;
        MeshSection section = new MeshSection();

        if(startMeshLink)
        {
            Vector3 startPos = startObject.transform.position;
            startPos.x =  (startPos.x+(startObject.transform.localScale.x/2));
            startPos.y =  (0);
            section.point = startPos;
            if (alwaysUp)
                section.upDir = Vector3.up;
            else
                section.upDir = transform.TransformDirection(Vector3.up);
            section.time = now;
            section.heightOverride = startingHeight;
            section.usesOverride = true;
            sections.Add(section);
            startMeshLink = false;
        }
        else
        {
            section.point = position;
            if (alwaysUp)
                section.upDir = Vector3.up;
            else
                section.upDir = transform.TransformDirection(Vector3.up);
            section.time = now;
            if(useManualHeightOverride)
            {
                section.usesOverride = true;
                section.heightOverride = manualHeightOverride;
            }
            else
            {
                section.usesOverride = false;
            }
            sections.Add(section);
        }

        xSpacing = randomizer.Next(spacingMin,spacingMax);
        position.x += xSpacing;

        DepthPoint dp1 = new DepthPoint();
        DepthPoint dp2 = new DepthPoint();

        if(sections.Count>4)
        {
            dp1.point = transform.position;
            dp2.point = transform.position;
            dp2.point.z = extrusionWidth;
            extrudeDirection = dp1.point+dp2.point;
            depthPoints.Clear();
            depthPoints.Add(dp1);
            depthPoints.Add(dp2);
            extrudeRotation = Quaternion.LookRotation(extrudeDirection,Vector3.up);
        }
        else
        {
            dp1.point = sections[0].point;
            dp2.point = sections[0].point;
            dp2.point.z = extrusionWidth;
            extrudeDirection = dp1.point-dp2.point;
            depthPoints.Clear();
            depthPoints.Add(dp1);
            depthPoints.Add(dp2);
            extrudeRotation = Quaternion.LookRotation(extrudeDirection,Vector3.up);
        }
    }
コード例 #11
0
ファイル: Mesh.cs プロジェクト: tirnoney/DAIToolsWV
 private MeshSection ReadMeshSection(Stream s)
 {
     MeshSection r = new MeshSection();
     r.Unknown01 = Helpers.ReadInt(s);
     r.Unknown02 = Helpers.ReadInt(s);
     r.SectionName = SerializeString(s);
     r.Unknown03 = Helpers.ReadInt(s);
     r.TriangleCount = Helpers.ReadInt(s);
     r.StartIndex = Helpers.ReadInt(s);
     r.VertexBufferOffset = Helpers.ReadInt(s);
     r.VertexCount = Helpers.ReadInt(s);
     r.Unknown04 = Helpers.ReadInt(s);
     r.Unknown05 = Helpers.ReadInt(s);
     r.Unknown06 = Helpers.ReadInt(s);
     r.VertexEntries = new List<VertexDescriptor>();
     for (int i = 0; i < 16; i++)
     {
         VertexDescriptor VertexEntry = new VertexDescriptor();
         VertexEntry.VertexType = Helpers.ReadShort(s);
         VertexEntry.Offset = s.ReadByte();
         VertexEntry.Unknown01 = s.ReadByte();
         if (VertexEntry.Offset != 0xFF)
             r.VertexEntries.Add(VertexEntry);
     }
     r.VertexStride = Helpers.ReadInt(s);
     r.Unknowns2 = new int[19];
     for (int i = 0; i < 19; i++)
         r.Unknowns2[i] = Helpers.ReadInt(s);
     r.SubBoneList = new ushort[0];
     return r;
 }
コード例 #12
0
ファイル: Mesh.cs プロジェクト: tirnoney/DAIToolsWV
 public string SectionToString(MeshSection sec)
 {
     StringBuilder sb = new StringBuilder();
     sb.AppendFormat("..Unknown01          : 0x{0}\n", sec.Unknown01.ToString("X8"));
     sb.AppendFormat("..Unknown02          : 0x{0}\n", sec.Unknown02.ToString("X8"));
     sb.AppendFormat("..SectionName        : {0}\n", sec.SectionName);
     sb.AppendFormat("..Unknown03          : 0x{0}\n", sec.Unknown03.ToString("X8"));
     sb.AppendFormat("..TriangleCount      : {0}\n", sec.TriangleCount);
     sb.AppendFormat("..StartIndex         : {0}\n", sec.StartIndex);
     sb.AppendFormat("..VertexBufferOffset : 0x{0}\n", sec.VertexBufferOffset.ToString("X8"));
     sb.AppendFormat("..VertexCount        : {0}\n", sec.VertexCount);
     sb.AppendFormat("..VertexStride       : 0x{0}\n", sec.VertexStride.ToString("X8"));
     sb.AppendFormat("..Unknown04          : 0x{0}\n", sec.Unknown04.ToString("X8"));
     sb.AppendFormat("..Unknown05          : 0x{0}\n", sec.Unknown05.ToString("X8"));
     sb.AppendFormat("..Unknown06          : 0x{0}\n", sec.Unknown06.ToString("X8"));
     sb.Append("..VertexEntries      : ");
     if (sec.VertexEntries != null)
     foreach (VertexDescriptor v in sec.VertexEntries)
         sb.AppendFormat("[Type 0x{0} ; Offset 0x{1} ; Unknown 0x{2}]", v.VertexType.ToString("X"), v.Offset.ToString("X"), v.Unknown01.ToString("X"));
     sb.Append("\n..Unknown List       : ");
     foreach (int u in sec.Unknowns2)
         sb.AppendFormat("0x{0}, ", u.ToString("X8"));
     sb.Append("\n..Section Bone List  : ");
     foreach (int u in sec.SubBoneList)
         sb.AppendFormat("{0}, ", u);
     sb.Append("\n");
     return sb.ToString();
 }
コード例 #13
0
    void buildTerrain()
    {
        collisionNeedsUpdate = true;
        extrudeDirection     = new Vector3();
        extrudeRotation      = new Quaternion();
        extrusion            = new List <Matrix4x4>();
        triangles            = new List <int>();
        uv            = new List <Vector2>();
        vertices      = new List <Vector3>();
        sections      = new List <MeshSection>();
        depthPoints   = new List <DepthPoint>();
        newHeightData = new Vector3();
        mesh          = GetComponent <MeshFilter>().mesh;
        out_mesh      = GetComponent <MeshFilter>().sharedMesh;
        position      = transform.position;
        randomizer    = new System.Random();


        if (startObject != null)
        {
            startMeshLink = true;
        }
        else
        {
            startMeshLink = false;
        }

        while (sections.Count < geomBuffer)
        {
            Restock();
            //startPlaced = true;
        }

        if (sections.Count < 2)
        {
            return;
        }

        MeshSection currentSection      = sections[0];
        Matrix4x4   localSpaceTransform = transform.localToWorldMatrix;

        for (int i = 0; i < sections.Count; i++)
        {
            currentSection = sections[i];

            Vector3 upDir = currentSection.upDir;

            vertices.Add(localSpaceTransform.MultiplyPoint(currentSection.point));
            if (currentSection.usesOverride)
            {
                newHeightData.Set(currentSection.point.x, currentSection.heightOverride, currentSection.point.z);
            }
            else
            {
                newHeightData.Set(currentSection.point.x, randomizer.Next(heightMin, heightMax), currentSection.point.z);
            }
            vertices.Add(localSpaceTransform.MultiplyPoint(newHeightData + upDir * height));


            float u = 0.0f;
            if (i != 0)
            {
                u = Mathf.Clamp01((Time.time - currentSection.time) / time);
            }
            uv.Add(new Vector2(u, 0));
            uv.Add(new Vector2(u, 1));
        }

        ResetTris();
        mesh.Clear();
        if (meshc == null)
        {
            meshc = gameObject.AddComponent(typeof(MeshCollider)) as MeshCollider;
            if (floorPhysMat != null)
            {
                meshc.material = floorPhysMat;
            }
        }
    }
コード例 #14
0
    void Restock()
    {
        float       now     = Time.time;
        MeshSection section = new MeshSection();

        if (startMeshLink)
        {
            Vector3 startPos = startObject.transform.position;
            startPos.x    = (startPos.x + (startObject.transform.localScale.x / 2));
            startPos.y    = (0);
            section.point = startPos;
            if (alwaysUp)
            {
                section.upDir = Vector3.up;
            }
            else
            {
                section.upDir = transform.TransformDirection(Vector3.up);
            }
            section.time           = now;
            section.heightOverride = startingHeight;
            section.usesOverride   = true;
            sections.Add(section);
            startMeshLink = false;
        }
        else
        {
            section.point = position;
            if (alwaysUp)
            {
                section.upDir = Vector3.up;
            }
            else
            {
                section.upDir = transform.TransformDirection(Vector3.up);
            }
            section.time = now;
            if (useManualHeightOverride)
            {
                section.usesOverride   = true;
                section.heightOverride = manualHeightOverride;
            }
            else
            {
                section.usesOverride = false;
            }
            sections.Add(section);
        }


        xSpacing    = randomizer.Next(spacingMin, spacingMax);
        position.x += xSpacing;


        DepthPoint dp1 = new DepthPoint();
        DepthPoint dp2 = new DepthPoint();

        if (sections.Count > 4)
        {
            dp1.point        = transform.position;
            dp2.point        = transform.position;
            dp2.point.z      = extrusionWidth;
            extrudeDirection = dp1.point + dp2.point;
            depthPoints.Clear();
            depthPoints.Add(dp1);
            depthPoints.Add(dp2);
            extrudeRotation = Quaternion.LookRotation(extrudeDirection, Vector3.up);
        }
        else
        {
            dp1.point        = sections[0].point;
            dp2.point        = sections[0].point;
            dp2.point.z      = extrusionWidth;
            extrudeDirection = dp1.point - dp2.point;
            depthPoints.Clear();
            depthPoints.Add(dp1);
            depthPoints.Add(dp2);
            extrudeRotation = Quaternion.LookRotation(extrudeDirection, Vector3.up);
        }
    }