Example #1
0
            /// <summary></summary>
            public static Polygon Read(BinaryReader reader, Package package)
            {
                int     vertexCount = UIndex.Read(reader);
                Polygon result      = new Polygon()
                {
                    Vertices = new Vector3f[vertexCount],
                    Base     = reader.ReadVector3f(),
                    Normal   = reader.ReadVector3f(),
                    TextureU = reader.ReadVector3f(),
                    TextureV = reader.ReadVector3f()
                };

                for (var index = 0; index < vertexCount; index++)
                {
                    result.Vertices[index] = reader.ReadVector3f();
                }
                result.Flags            = reader.ReadInt32();
                result.ActorReference   = package.ReadReference(reader);
                result.TextureReference = package.ReadReference(reader);
                result.ItemName         = package.ReadNameValue(reader);
                result.Link             = UIndex.Read(reader);
                result.BrushPolygon     = UIndex.Read(reader);
                result.PanU             = reader.ReadUInt16();
                result.PanV             = reader.ReadUInt16();

                return(result);
            }
Example #2
0
            public override object Read(object target, Package package, System.IO.BinaryReader reader, long end)
            {
                var count = UIndex.Read(reader);
                var list  = new List <Bounds>(count);

                while (count-- > 0)
                {
                    list.Add(Alexandria.Engines.Unreal.Bounds.Read(reader));
                }
                return(list);
            }
Example #3
0
 public static void Serialize(this SerializingContainer2 sc, ref UIndex uidx)
 {
     if (sc.IsLoading)
     {
         uidx = new UIndex(sc.ms.ReadInt32());
     }
     else
     {
         sc.ms.WriteInt32(uidx?.value ?? 0);
     }
 }
        public override string Print()
        {
            string result = base.Print();

            result += $"UIndex: {UIndex.ToString()}\n";
            result += $"Id: {Id.ToString()}\n";
            result += $"Index: {Index.ToString()}\n";
            result += $"TimeStamp: {DateTimeToString(TimeStamp)}\n";
            result += $"Version: {Version}\n";
            result += $"NetworkId: {NetworkId}\n";
            result += $"ShardId: {ShardId}\n";
            result += $"BlockType: {BlockType.ToString()}\n";
            result += $"PreviousHash: {PreviousHash}\n";
            result += $"ServiceHash: {ServiceHash}\n";
            result += $"Tags: {JsonConvert.SerializeObject(Tags)}\n";
            result += $"Authorizations: {JsonConvert.SerializeObject(Authorizations)}\n";
            return(result);
        }
Example #5
0
            public override object Read(object target, Package package, System.IO.BinaryReader reader, long end)
            {
                int count = UIndex.Read(reader);

                if (count == 0)
                {
                    return(null);
                }
                var list = new Vertex[count];

                for (var index = 0; index < count; index++)
                {
                    list[index] = new Vertex()
                    {
                        VertexIndex = UIndex.Read(reader),
                        SideIndex   = UIndex.Read(reader)
                    }
                }
                ;
                return(list);
            }
        }
Example #6
0
        /// <summary>
        /// Creates a preview of the given <see cref="SkeletalMesh"/>.
        /// </summary>
        /// <param name="Device">The Direct3D device to use for buffer creation.</param>
        /// <param name="m">The mesh to generate a preview for.</param>
        /// <param name="texcache">The texture cache for loading textures.</param>
        public ModelPreview(Device Device, SkeletalMesh m, PreviewTextureCache texcache, PackageCache assetCache, PreloadedModelData preloadedData = null)
        {
            // STEP 1: MATERIALS
            if (preloadedData == null)
            {
                for (int i = 0; i < m.Materials.Length; i++)
                {
                    UIndex materialUIndex        = m.Materials[i];
                    MaterialInstanceConstant mat = null;
                    if (materialUIndex.value > 0)
                    {
                        mat = new MaterialInstanceConstant(m.Export.FileRef.GetUExport(materialUIndex.value));
                    }
                    else if (materialUIndex.value < 0)
                    {
                        // The material instance is an import!
                        ImportEntry matImport     = m.Export.FileRef.GetImport(materialUIndex.value);
                        var         externalAsset = EntryImporter.ResolveImport(matImport, null, assetCache);
                        if (externalAsset != null)
                        {
                            mat = new MaterialInstanceConstant(externalAsset);
                        }
                    }

                    if (mat != null)
                    {
                        ModelPreviewMaterial material;
                        // TODO: pick what material class best fits based on what properties the
                        // MaterialInstanceConstant mat has.
                        // For now, just use the default material.
                        material = new TexturedPreviewMaterial(texcache, mat, assetCache);
                        AddMaterial(material.Properties["Name"], material);
                    }
                }
            }
            else
            {
                //Preloaded
                //sections = preloadedData.sections;
                var uniqueMaterials = preloadedData.texturePreviewMaterials.Select(x => x.MaterialExport).Distinct();
                foreach (var mat in uniqueMaterials)
                {
                    var material = new TexturedPreviewMaterial(texcache, new MaterialInstanceConstant(mat), assetCache, preloadedData.texturePreviewMaterials);
                    AddMaterial(mat.ObjectName.Name, material);
                }
            }

            // STEP 2: LODS
            foreach (var lodmodel in m.LODModels)
            {
                // Vertices
                List <WorldVertex> vertices = new List <WorldVertex>(m.Export.Game == MEGame.ME1 ? lodmodel.ME1VertexBufferGPUSkin.Length : lodmodel.VertexBufferGPUSkin.VertexData.Length);
                if (m.Export.Game == MEGame.ME1)
                {
                    foreach (var vertex in lodmodel.ME1VertexBufferGPUSkin)
                    {
                        vertices.Add(new WorldVertex(new Vector3(-vertex.Position.X, vertex.Position.Z, vertex.Position.Y), Vector3.Zero, new Vector2(vertex.UV.X, vertex.UV.Y)));
                    }
                }
                else
                {
                    foreach (var vertex in lodmodel.VertexBufferGPUSkin.VertexData)
                    {
                        vertices.Add(new WorldVertex(new Vector3(-vertex.Position.X, vertex.Position.Z, vertex.Position.Y), Vector3.Zero, new Vector2(vertex.UV.X, vertex.UV.Y)));
                    }
                }
                // Triangles
                List <Triangle> triangles = new List <Triangle>(lodmodel.IndexBuffer.Length / 3);
                for (int i = 0; i < lodmodel.IndexBuffer.Length; i += 3)
                {
                    triangles.Add(new Triangle(lodmodel.IndexBuffer[i], lodmodel.IndexBuffer[i + 1], lodmodel.IndexBuffer[i + 2]));
                }
                WorldMesh mesh = new WorldMesh(Device, triangles, vertices);
                // Sections
                List <ModelPreviewSection> sections = new List <ModelPreviewSection>();
                foreach (var section in lodmodel.Sections)
                {
                    if (section.MaterialIndex < Materials.Count)
                    {
                        sections.Add(new ModelPreviewSection(Materials.Keys.ElementAt(section.MaterialIndex), section.BaseIndex, (uint)section.NumTriangles));
                    }
                }
                LODs.Add(new ModelPreviewLOD(mesh, sections));
            }
        }