Exemplo n.º 1
0
        private void ConvertMeshFrag(Zone zone, bool zoneConvert = false)
        {
            if (!byType.ContainsKey(54))
            {
                return;
            }

            foreach (FragMesh frag in byType[54])
            {
                var obj  = zone.AddObject(frag._name);
                var vbuf = new VertexBuffer(frag);

                var off = 0;

                foreach (var polytex in frag.Polytex)
                {
                    var count = polytex[0];
                    var index = polytex[1];

                    if (frag.Textures.Length > 1)
                    {
                        throw new IndexOutOfRangeException(
                                  "WldConverter.ConvertObjects -- frag.Textures.Length > 1");
                    }

                    var texnames = ((FragRef[])frag.Textures[0].Value)[index].Resolve().OfType <string>().ToList();
                    var texFlags = ((TexRef)((FragRef[])frag.Textures[0].Value)[index].Value).SaneFlags;

                    var tmpS3DData = texnames.Select(t => s3d[t.ToLower()]).ToList();

                    var material = new Entities.Material(texFlags, tmpS3DData);
                    var mesh     = new Entities.Mesh(material, vbuf, frag.Polys.Skip(off).Take(count).ToList());
                    obj.Meshes.Add(mesh);
                    off += count;
                }
            }
        }
Exemplo n.º 2
0
        public void ConvertZone(Zone zone)
        {
            if (!byType.ContainsKey(54))
            {
                return;
            }

            foreach (FragMesh frag in byType[54])
            {
                var vbuf = new VertexBuffer(frag);

                var off = 0;
                foreach (var polytex in frag.Polytex)
                {
                    var count = polytex[0];
                    var index = polytex[1];

                    if (frag.Textures.Length > 1)
                    {
                        throw new IndexOutOfRangeException(
                                  "WldConverter.ConvertObjects -- frag.Textures.Length > 1");
                    }

                    var texnames = ((FragRef[])frag.Textures[0].Value)[index].Resolve().OfType <string>().ToList();
                    var texFlags = ((TexRef)((FragRef[])frag.Textures[0].Value)[index].Value).SaneFlags;

                    var tmpS3DData = texnames.Select(t => s3d[t.ToLower()]).ToList();

                    // The first param was texFlags, but it was always set to 0, so I'm setting it to 0.
                    var material = new Entities.Material(texFlags, tmpS3DData);
                    var mesh     = new Entities.Mesh(material, vbuf, frag.Polys.Skip(off).Take(count).ToList());
                    zone.ZoneObj.Meshes.Add(mesh);
                    off += count;
                }
            }
        }