public virtual void Write(PackFileSerializer s, BinaryWriterEx bw)
 {
     bw.WriteSByte(m_sectionTag_0);
     bw.WriteSByte(m_sectionTag_1);
     bw.WriteSByte(m_sectionTag_2);
     bw.WriteSByte(m_sectionTag_3);
     bw.WriteSByte(m_sectionTag_4);
     bw.WriteSByte(m_sectionTag_5);
     bw.WriteSByte(m_sectionTag_6);
     bw.WriteSByte(m_sectionTag_7);
     bw.WriteSByte(m_sectionTag_8);
     bw.WriteSByte(m_sectionTag_9);
     bw.WriteSByte(m_sectionTag_10);
     bw.WriteSByte(m_sectionTag_11);
     bw.WriteSByte(m_sectionTag_12);
     bw.WriteSByte(m_sectionTag_13);
     bw.WriteSByte(m_sectionTag_14);
     bw.WriteSByte(m_sectionTag_15);
     bw.WriteSByte(m_sectionTag_16);
     bw.WriteSByte(m_sectionTag_17);
     bw.WriteSByte(m_sectionTag_18);
     bw.WriteSByte(m_nullByte);
     bw.WriteInt32(m_absoluteDataStart);
     bw.WriteInt32(m_localFixupsOffset);
     bw.WriteInt32(m_globalFixupsOffset);
     bw.WriteInt32(m_virtualFixupsOffset);
     bw.WriteInt32(m_exportsOffset);
     bw.WriteInt32(m_importsOffset);
     bw.WriteInt32(m_endOffset);
     bw.WriteInt32(m_pad_0);
     bw.WriteInt32(m_pad_1);
     bw.WriteInt32(m_pad_2);
     bw.WriteInt32(m_pad_3);
 }
Exemple #2
0
 public virtual void Write(PackFileSerializer s, BinaryWriterEx bw)
 {
     bw.WriteInt32(m_value);
 }
Exemple #3
0
 public virtual void Write(PackFileSerializer s, BinaryWriterEx bw)
 {
     bw.WriteInt32(m_firstTargetIdx);
     bw.WriteInt32(m_numTargets);
     s.WriteClassPointer <hkpConstraintInstance>(bw, m_limitConstraint);
 }
Exemple #4
0
        public static void WriteMeshFile(Stream stream, MESH_FILE meshFile)
        {
            using (var bw = new BinaryWriterEx(stream, Encoding.UTF8, true))
            {
                bw.WriteStruct(meshFile.Header);
                void WriteVector3(Vector3 v)
                {
                    bw.WriteSingle(v.X);
                    bw.WriteSingle(v.Y);
                    bw.WriteSingle(v.Z);
                }

                void WriteVector2(Vector2 v)
                {
                    bw.WriteSingle(v.X);
                    bw.WriteSingle(v.Y);
                }

                foreach (var pos in meshFile.Geometry.Positions)
                {
                    WriteVector3(pos);
                }

                foreach (var norm in meshFile.Geometry.Normals)
                {
                    WriteVector3(norm);
                }

                if (meshFile.Geometry.UVs != null && meshFile.Geometry.UVs.Length > 0)
                {
                    foreach (var uv in meshFile.Geometry.UVs)
                    {
                        WriteVector2(uv);
                    }
                }

                for (int i = 0; i < meshFile.Header.IndexCount; i++)
                {
                    bw.WriteInt32(meshFile.Geometry.Indices[i].VertexIndex);
                }


                //Round Edge Shader Data
                {
                    var allShaderData = meshFile.RoundEdgeShaderData.SelectMany(x => x.Coords).ToList();

                    bw.WriteInt32(allShaderData.Count * 2);
                    foreach (var shaderCoord in allShaderData)
                    {
                        WriteVector2(shaderCoord);
                    }

                    for (int i = 0; i < meshFile.Header.IndexCount; i++)
                    {
                        bw.WriteInt32(meshFile.Geometry.Indices[i].REShaderOffset);
                    }
                }

                //Average Normals
                {
                    bw.WriteInt32(meshFile.AverageNormals.Length + 1);
                    WriteVector3(new Vector3(83, 0, 0));

                    foreach (var avgNorm in meshFile.AverageNormals)
                    {
                        WriteVector3(avgNorm);
                    }

                    for (int i = 0; i < meshFile.Header.IndexCount; i++)
                    {
                        bw.WriteInt32(meshFile.Geometry.Indices[i].AverageNormalIndex);
                    }
                }

                if (meshFile.Geometry.Bones != null && meshFile.Geometry.Bones.Length > 0)
                {
                    //TODO: If flexible alternate meshes are supported, improve this code to include alternate meshes bones
                    //      and a way to retrieve the correct offsets in WriteCullingInfo

                    var allBones     = meshFile.Geometry.Bones.SelectMany(x => x.BoneWeights).ToList();
                    int boneDataSize = (allBones.Count * 8) + (meshFile.Header.VertexCount * 4);
                    bw.WriteInt32(boneDataSize);

                    var dataOffsets = new List <int>();
                    int totalOffset = 0;

                    for (int i = 0; i < meshFile.Header.VertexCount; i++)
                    {
                        var vertexBones = meshFile.Geometry.Bones[i];
                        bw.WriteInt32(vertexBones.BoneWeights.Length);
                        for (int j = 0; j < vertexBones.BoneWeights.Length; j++)
                        {
                            bw.WriteInt32(vertexBones.BoneWeights[j].BoneID);
                            bw.WriteSingle(vertexBones.BoneWeights[j].Weight);
                        }
                        //bone count (4 bytes) + bones data (id + weight = 8 bytes)
                        dataOffsets.Add(totalOffset);
                        totalOffset += 4 + (vertexBones.BoneWeights.Length * 8);
                    }

                    for (int i = 0; i < meshFile.Header.VertexCount; i++)
                    {
                        bw.WriteInt32(dataOffsets[i]);
                    }
                }

                //Mesh Culling Info
                {
                    bw.WriteInt32(meshFile.Cullings.Length);
                    WriteSizedBlock(bw, () =>
                    {
                        for (int i = 0; i < meshFile.Cullings.Length; i++)
                        {
                            WriteCullingInfo(bw, meshFile.Cullings[i]);
                        }
                    }, false);
                }
            }
        }
Exemple #5
0
        private static void WriteCullingInfo(BinaryWriterEx bw, MESH_CULLING culling)
        {
            void WriteVector3(Vector3 v)
            {
                bw.WriteSingle(v.X);
                bw.WriteSingle(v.Y);
                bw.WriteSingle(v.Z);
            }

            void WriteVector2(Vector2 v)
            {
                bw.WriteSingle(v.X);
                bw.WriteSingle(v.Y);
            }

            long startPos = bw.BaseStream.Position;

            WriteSizedBlock(bw, () =>
            {
                bw.WriteInt32(culling.Type);
                bw.WriteInt32(culling.FromVertex);
                bw.WriteInt32(culling.VertexCount);
                bw.WriteInt32(culling.FromIndex);
                bw.WriteInt32(culling.IndexCount);

                long vertexOffsetPos = bw.BaseStream.Position;
                bw.Write(0);//dummy offset;

                int extraDataVal = 0;

                if (culling.AdjacentStuds != null && culling.AdjacentStuds.Length > 0)
                {
                    extraDataVal = 2;
                }
                else if (culling.Studs != null && culling.Studs.Length > 0)
                {
                    extraDataVal = 1;
                }

                bw.Write(extraDataVal);

                if (extraDataVal > 0)
                {
                    WriteSizedBlock(bw, () =>
                    {
                        int itemCount = culling.Studs?.Length ?? 0;
                        bw.Write(itemCount);
                        for (int i = 0; i < itemCount; i++)
                        {
                            WriteSizedBlock(bw, () =>
                            {
                                bw.Write(culling.Studs[i].ConnectorIndex);
                                bw.Write(culling.Studs[i].Indices.Length);
                                for (int j = 0; j < culling.Studs[i].Indices.Length; j++)
                                {
                                    bw.Write(culling.Studs[i].Indices[j].ArrayIndex);
                                    bw.Write(culling.Studs[i].Indices[j].Value2);
                                    bw.Write(culling.Studs[i].Indices[j].Value3);
                                    bw.Write(culling.Studs[i].Indices[j].Value4);
                                }
                            });
                        }
                    });
                }

                if (extraDataVal > 1)
                {
                    WriteSizedBlock(bw, () =>
                    {
                        int itemCount = culling.AdjacentStuds?.Length ?? 0;
                        bw.Write(itemCount);
                        for (int i = 0; i < itemCount; i++)
                        {
                            WriteSizedBlock(bw, () =>
                            {
                                bw.Write(culling.AdjacentStuds[i].ConnectorIndex);
                                bw.Write(culling.AdjacentStuds[i].Indices.Length);
                                for (int j = 0; j < culling.AdjacentStuds[i].Indices.Length; j++)
                                {
                                    bw.Write(culling.AdjacentStuds[i].Indices[j].ArrayIndex);
                                    bw.Write(culling.AdjacentStuds[i].Indices[j].Value2);
                                    bw.Write(culling.AdjacentStuds[i].Indices[j].Value3);
                                    bw.Write(culling.AdjacentStuds[i].Indices[j].Value4);
                                }
                            });
                        }
                    });
                }

                if (culling.AlternateMesh != null)
                {
                    var cullingGeom        = culling.AlternateMesh.Value;
                    long currentPos        = bw.BaseStream.Position;
                    bw.BaseStream.Position = vertexOffsetPos;
                    bw.Write((int)(currentPos - startPos));
                    bw.BaseStream.Position = currentPos;

                    bw.WriteInt32(cullingGeom.Positions.Length);
                    bw.WriteInt32(cullingGeom.Indices.Length);

                    foreach (var pos in cullingGeom.Positions)
                    {
                        WriteVector3(pos);
                    }

                    foreach (var norm in cullingGeom.Normals)
                    {
                        WriteVector3(norm);
                    }

                    if (cullingGeom.UVs != null && cullingGeom.UVs.Length > 0)
                    {
                        foreach (var uv in cullingGeom.UVs)
                        {
                            WriteVector2(uv);
                        }
                    }

                    foreach (var index in cullingGeom.Indices)
                    {
                        bw.WriteInt32(index.VertexIndex);
                    }

                    foreach (var index in cullingGeom.Indices)
                    {
                        bw.WriteInt32(index.AverageNormalIndex);
                    }

                    foreach (var index in cullingGeom.Indices)
                    {
                        bw.WriteInt32(index.REShaderOffset);
                    }
                }
            });
        }
Exemple #6
0
 public virtual void Write(PackFileSerializer s, BinaryWriterEx bw)
 {
     s.WriteClassArray <hknpMotionProperties>(bw, m_elements);
     bw.WriteInt32(m_firstFree);
     bw.WriteUInt32(0);
 }